mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-16 18:34:18 +00:00
test: use sqlite locators in context maintenance
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createSqliteSessionTranscriptLocator } from "../../config/sessions/paths.js";
|
||||
import type { ContextEngineRuntimeContext } from "../../context-engine/types.js";
|
||||
import { peekSystemEvents, resetSystemEventsForTest } from "../../infra/system-events.js";
|
||||
import {
|
||||
@@ -37,6 +38,10 @@ let runContextEngineMaintenance: typeof import("./context-engine-maintenance.js"
|
||||
// import reloading, so they cannot safely import the constant directly.
|
||||
const TURN_MAINTENANCE_TASK_KIND = "context_engine_turn_maintenance";
|
||||
|
||||
function sqliteTranscript(sessionId: string): string {
|
||||
return createSqliteSessionTranscriptLocator({ agentId: "main", sessionId });
|
||||
}
|
||||
|
||||
async function flushAsyncWork(times = 4): Promise<void> {
|
||||
for (let index = 0; index < times; index += 1) {
|
||||
await Promise.resolve();
|
||||
@@ -114,7 +119,7 @@ describe("buildContextEngineMaintenanceRuntimeContext", () => {
|
||||
const runtimeContext = buildContextEngineMaintenanceRuntimeContext({
|
||||
sessionId: "session-1",
|
||||
sessionKey: "agent:main:session-1",
|
||||
sessionFile: "/tmp/session.jsonl",
|
||||
sessionFile: sqliteTranscript("session-1"),
|
||||
runtimeContext: { workspaceDir: "/tmp/workspace" },
|
||||
});
|
||||
|
||||
@@ -135,7 +140,7 @@ describe("buildContextEngineMaintenanceRuntimeContext", () => {
|
||||
rewrittenEntries: 2,
|
||||
});
|
||||
expect(rewriteTranscriptEntriesInSqliteTranscriptMock).toHaveBeenCalledWith({
|
||||
transcriptPath: "/tmp/session.jsonl",
|
||||
transcriptPath: sqliteTranscript("session-1"),
|
||||
sessionId: "session-1",
|
||||
sessionKey: "agent:main:session-1",
|
||||
config: undefined,
|
||||
@@ -154,7 +159,7 @@ describe("buildContextEngineMaintenanceRuntimeContext", () => {
|
||||
const runtimeContext = buildContextEngineMaintenanceRuntimeContext({
|
||||
sessionId: "session-1",
|
||||
sessionKey: "agent:main:session-1",
|
||||
sessionFile: "/tmp/session.jsonl",
|
||||
sessionFile: sqliteTranscript("session-1"),
|
||||
sessionManager,
|
||||
});
|
||||
|
||||
@@ -209,7 +214,7 @@ describe("buildContextEngineMaintenanceRuntimeContext", () => {
|
||||
const runtimeContext = buildContextEngineMaintenanceRuntimeContext({
|
||||
sessionId: "session-rewrite-handoff",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-rewrite-handoff.jsonl",
|
||||
sessionFile: sqliteTranscript("session-rewrite-handoff"),
|
||||
deferTranscriptRewriteToSessionLane: true,
|
||||
});
|
||||
|
||||
@@ -314,7 +319,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
},
|
||||
sessionId: "session-1",
|
||||
sessionKey: "agent:main:session-1",
|
||||
sessionFile: "/tmp/session.jsonl",
|
||||
sessionFile: sqliteTranscript("session-1"),
|
||||
reason: "turn",
|
||||
runtimeContext: { workspaceDir: "/tmp/workspace" },
|
||||
});
|
||||
@@ -328,7 +333,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
expectRecordFields(maintainParams, {
|
||||
sessionId: "session-1",
|
||||
sessionKey: "agent:main:session-1",
|
||||
sessionFile: "/tmp/session.jsonl",
|
||||
sessionFile: sqliteTranscript("session-1"),
|
||||
});
|
||||
expect(
|
||||
requireRecord(maintainParams.runtimeContext, "maintain runtime context").workspaceDir,
|
||||
@@ -387,7 +392,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
},
|
||||
sessionId: "session-background-file-rewrite",
|
||||
sessionKey: "agent:main:session-background-file-rewrite",
|
||||
sessionFile: "/tmp/session-background-file-rewrite.jsonl",
|
||||
sessionFile: sqliteTranscript("session-background-file-rewrite"),
|
||||
reason: "turn",
|
||||
executionMode: "background",
|
||||
sessionManager,
|
||||
@@ -395,7 +400,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
|
||||
expect(rewriteTranscriptEntriesInSessionManagerMock).not.toHaveBeenCalled();
|
||||
expect(rewriteTranscriptEntriesInSqliteTranscriptMock).toHaveBeenCalledWith({
|
||||
transcriptPath: "/tmp/session-background-file-rewrite.jsonl",
|
||||
transcriptPath: sqliteTranscript("session-background-file-rewrite"),
|
||||
sessionId: "session-background-file-rewrite",
|
||||
sessionKey: "agent:main:session-background-file-rewrite",
|
||||
config: undefined,
|
||||
@@ -473,7 +478,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-1",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session.jsonl",
|
||||
sessionFile: sqliteTranscript("session-1"),
|
||||
reason: "turn",
|
||||
runtimeContext: {
|
||||
workspaceDir: "/tmp/workspace",
|
||||
@@ -509,7 +514,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
expectRecordFields(maintainParams, {
|
||||
sessionId: "session-1",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session.jsonl",
|
||||
sessionFile: sqliteTranscript("session-1"),
|
||||
});
|
||||
expectRecordFields(requireRecord(maintainParams.runtimeContext, "runtime context"), {
|
||||
workspaceDir: "/tmp/workspace",
|
||||
@@ -518,7 +523,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
currentTokenCount: 1536,
|
||||
});
|
||||
expect(rewriteTranscriptEntriesInSqliteTranscriptMock).toHaveBeenCalledWith({
|
||||
transcriptPath: "/tmp/session.jsonl",
|
||||
transcriptPath: sqliteTranscript("session-1"),
|
||||
sessionId: "session-1",
|
||||
sessionKey,
|
||||
config: undefined,
|
||||
@@ -594,14 +599,14 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-2",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-2.jsonl",
|
||||
sessionFile: sqliteTranscript("session-2"),
|
||||
reason: "turn",
|
||||
}),
|
||||
runContextEngineMaintenance({
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-2",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-2.jsonl",
|
||||
sessionFile: sqliteTranscript("session-2"),
|
||||
reason: "turn",
|
||||
}),
|
||||
]);
|
||||
@@ -673,7 +678,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-rerun",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-rerun.jsonl",
|
||||
sessionFile: sqliteTranscript("session-rerun"),
|
||||
reason: "turn",
|
||||
});
|
||||
|
||||
@@ -683,7 +688,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-rerun",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-rerun.jsonl",
|
||||
sessionFile: sqliteTranscript("session-rerun"),
|
||||
reason: "turn",
|
||||
});
|
||||
|
||||
@@ -751,7 +756,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-legacy",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-legacy.jsonl",
|
||||
sessionFile: sqliteTranscript("session-legacy"),
|
||||
reason: "turn",
|
||||
});
|
||||
|
||||
@@ -812,7 +817,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-enqueue-reject",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-enqueue-reject.jsonl",
|
||||
sessionFile: sqliteTranscript("session-enqueue-reject"),
|
||||
reason: "turn",
|
||||
});
|
||||
await flushAsyncWork();
|
||||
@@ -881,7 +886,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-3",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-3.jsonl",
|
||||
sessionFile: sqliteTranscript("session-3"),
|
||||
reason: "turn",
|
||||
});
|
||||
|
||||
@@ -982,7 +987,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-rewrite-priority",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-rewrite-priority.jsonl",
|
||||
sessionFile: sqliteTranscript("session-rewrite-priority"),
|
||||
reason: "turn",
|
||||
});
|
||||
|
||||
@@ -1055,7 +1060,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-fast",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-fast.jsonl",
|
||||
sessionFile: sqliteTranscript("session-fast"),
|
||||
reason: "turn",
|
||||
});
|
||||
await waitForAssertion(() => expect(maintain).toHaveBeenCalledTimes(1));
|
||||
@@ -1110,7 +1115,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-long",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-long.jsonl",
|
||||
sessionFile: sqliteTranscript("session-long"),
|
||||
reason: "turn",
|
||||
});
|
||||
|
||||
@@ -1182,7 +1187,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-throttle",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-throttle.jsonl",
|
||||
sessionFile: sqliteTranscript("session-throttle"),
|
||||
reason: "turn",
|
||||
});
|
||||
|
||||
@@ -1251,7 +1256,7 @@ describe("runContextEngineMaintenance", () => {
|
||||
contextEngine: backgroundEngine,
|
||||
sessionId: "session-fail",
|
||||
sessionKey,
|
||||
sessionFile: "/tmp/session-fail.jsonl",
|
||||
sessionFile: sqliteTranscript("session-fail"),
|
||||
reason: "turn",
|
||||
});
|
||||
await waitForAssertion(() =>
|
||||
|
||||
Reference in New Issue
Block a user