@vellumai/assistant 0.10.7-dev.202607092332.9deedf4 → 0.10.7-dev.202607100313.fffdfea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +1 -2
- package/docs/architecture/memory.md +1 -3
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/openapi.yaml +1 -222
- package/package.json +1 -1
- package/scripts/memory-inspect.ts +2 -8
- package/src/__tests__/approval-routes-http.test.ts +0 -8
- package/src/__tests__/background-workers-disk-pressure.test.ts +4 -2
- package/src/__tests__/compaction-events.test.ts +0 -4
- package/src/__tests__/context-search-memory-source.test.ts +0 -1
- package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +0 -1
- package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +0 -2
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +0 -2
- package/src/__tests__/conversation-agent-loop.test.ts +0 -4
- package/src/__tests__/conversation-app-control-lifecycle.test.ts +0 -4
- package/src/__tests__/conversation-fork-crud.test.ts +18 -5
- package/src/__tests__/conversation-fork-retrospective.test.ts +483 -0
- package/src/__tests__/conversation-routes-disk-view.test.ts +0 -4
- package/src/__tests__/conversation-store.test.ts +0 -10
- package/src/__tests__/conversation-summarize-up-to.test.ts +0 -4
- package/src/__tests__/credential-execution-api-key-propagation.test.ts +0 -40
- package/src/__tests__/credential-execution-client.test.ts +3 -3
- package/src/__tests__/credential-execution-managed-contract.test.ts +8 -104
- package/src/__tests__/file-write-tool.test.ts +9 -13
- package/src/__tests__/graph-extraction-event-date.test.ts +0 -9
- package/src/__tests__/injection-block.test.ts +0 -1
- package/src/__tests__/job-handler-registration-guard.test.ts +0 -1
- package/src/__tests__/lexical-index-dual-write.test.ts +2 -2
- package/src/__tests__/llm-resolver.test.ts +0 -1
- package/src/__tests__/messages-after-tiebreaker.test.ts +0 -1
- package/src/__tests__/playbook-execution.test.ts +2 -26
- package/src/__tests__/plugin-import-boundary-guard.test.ts +0 -4
- package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +318 -0
- package/src/__tests__/proxy-approval-callback.test.ts +0 -1
- package/src/__tests__/rebuild-index-graph-nodes.test.ts +0 -4
- package/src/__tests__/send-endpoint-busy.test.ts +0 -12
- package/src/__tests__/service-contracts-import-guard.test.ts +4 -9
- package/src/__tests__/subagent-fork-spawn.test.ts +0 -37
- package/src/__tests__/task-memory-cleanup.test.ts +0 -11
- package/src/__tests__/voice-scoped-grant-consumer.test.ts +0 -1
- package/src/__tests__/voice-session-bridge.test.ts +0 -56
- package/src/__tests__/workspace-migration-009-backfill-conversation-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-013-repair-conversation-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-028-recover-conversations-from-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-129-remove-analyze-conversation-config.test.ts +190 -0
- package/src/cli/commands/db/repair-step-conversation-backfill.ts +0 -1
- package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +0 -6
- package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-delete.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-list.ts +1 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +0 -4
- package/src/config/call-site-defaults.ts +0 -1
- package/src/config/feature-flag-registry.json +0 -16
- package/src/config/schema.ts +0 -3
- package/src/config/schemas/call-site-catalog.ts +0 -6
- package/src/config/schemas/llm.ts +0 -1
- package/src/conversations/job-handlers/summarization.ts +0 -2
- package/src/daemon/conversation-agent-loop-handlers.ts +0 -1
- package/src/daemon/conversation-agent-loop.ts +1 -6
- package/src/daemon/conversation-lifecycle.ts +0 -14
- package/src/daemon/conversation-turn-finalize.ts +0 -1
- package/src/daemon/handlers/shared.ts +1 -2
- package/src/export/transcript-formatter.ts +9 -39
- package/src/home/conversation-starter-checkpoints.ts +9 -5
- package/src/home/job-handlers/conversation-starters.ts +24 -54
- package/src/hooks/types.ts +2 -2
- package/src/ipc/routes/__tests__/memory-v2-backfill.test.ts +5 -7
- package/src/persistence/__tests__/bulk-write-gate.test.ts +165 -0
- package/src/persistence/__tests__/immediate-transaction-guard.test.ts +70 -0
- package/src/persistence/auto-analysis-constants.ts +4 -13
- package/src/persistence/bulk-write-gate.ts +82 -0
- package/src/persistence/conversation-bootstrap.ts +3 -3
- package/src/persistence/conversation-crud.ts +158 -80
- package/src/persistence/conversation-key-store.ts +0 -2
- package/src/persistence/conversation-row-batch-delete.ts +16 -1
- package/src/persistence/conversation-types.ts +12 -1
- package/src/persistence/db-async-query.ts +18 -9
- package/src/persistence/db-connection.ts +20 -4
- package/src/persistence/db-maintenance.ts +78 -6
- package/src/persistence/embeddings/qdrant-client.ts +2 -18
- package/src/persistence/fork-message-copy.ts +18 -4
- package/src/persistence/jobs-store.ts +3 -86
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.test.ts +148 -0
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.ts +35 -0
- package/src/persistence/schema/conversations.ts +0 -1
- package/src/persistence/schema/memory-core.ts +17 -28
- package/src/persistence/schema/memory-graph.ts +0 -4
- package/src/persistence/schema/tasks.ts +0 -1
- package/src/persistence/steps.ts +2 -0
- package/src/playbooks/playbook-compiler.ts +2 -10
- package/src/plugins/defaults/memory/__tests__/db-maintenance.test.ts +105 -11
- package/src/plugins/defaults/memory/__tests__/jobs-store-enqueue-gate.test.ts +7 -62
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +47 -5
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +29 -1
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-startup-cleanup.test.ts +133 -70
- package/src/plugins/defaults/memory/activation-session-store.ts +1 -1
- package/src/plugins/defaults/memory/config.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/memory.ts +1 -1
- package/src/plugins/defaults/memory/filing-jobs.ts +1 -1
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +8 -4
- package/src/plugins/defaults/memory/frontmatter.ts +1 -1
- package/src/plugins/defaults/memory/graph/__tests__/handle-remember-v2.test.ts +4 -25
- package/src/plugins/defaults/memory/graph/bootstrap.ts +12 -18
- package/src/plugins/defaults/memory/graph/capability-seed.ts +4 -18
- package/src/plugins/defaults/memory/graph/consolidation.ts +7 -14
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +1 -3
- package/src/plugins/defaults/memory/graph/decay.ts +5 -10
- package/src/plugins/defaults/memory/graph/extraction-job.ts +2 -3
- package/src/plugins/defaults/memory/graph/extraction.test.ts +1 -9
- package/src/plugins/defaults/memory/graph/extraction.ts +1 -8
- package/src/plugins/defaults/memory/graph/graph-search.ts +1 -2
- package/src/plugins/defaults/memory/graph/injection.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/injection.ts +1 -1
- package/src/plugins/defaults/memory/graph/narrative.ts +1 -3
- package/src/plugins/defaults/memory/graph/pattern-scan.ts +1 -4
- package/src/plugins/defaults/memory/graph/retriever.test.ts +0 -19
- package/src/plugins/defaults/memory/graph/retriever.ts +6 -14
- package/src/plugins/defaults/memory/graph/scoring.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/store.test.ts +6 -58
- package/src/plugins/defaults/memory/graph/store.ts +5 -43
- package/src/plugins/defaults/memory/graph/tool-handlers.test.ts +0 -4
- package/src/plugins/defaults/memory/graph/tool-handlers.ts +1 -11
- package/src/plugins/defaults/memory/graph/types.ts +0 -3
- package/src/plugins/defaults/memory/hooks/init.ts +1 -1
- package/src/plugins/defaults/memory/indexer.ts +2 -45
- package/src/plugins/defaults/memory/injectors.ts +2 -3
- package/src/plugins/defaults/memory/job-handler-registration.ts +0 -4
- package/src/plugins/defaults/memory/job-handlers/backfill.ts +0 -1
- package/src/plugins/defaults/memory/job-handlers/embedding.test.ts +0 -1
- package/src/plugins/defaults/memory/job-handlers/embedding.ts +0 -4
- package/src/plugins/defaults/memory/job-handlers/index-maintenance.ts +1 -1
- package/src/plugins/defaults/memory/job-handlers.ts +5 -9
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +1 -1
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.test.ts +41 -21
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.ts +10 -5
- package/src/plugins/defaults/memory/jobs-worker.ts +21 -9
- package/src/plugins/defaults/memory/logging.ts +17 -0
- package/src/plugins/defaults/memory/memory-retrospective-constants.ts +10 -7
- package/src/plugins/defaults/memory/memory-retrospective-enqueue.ts +5 -6
- package/src/plugins/defaults/memory/memory-retrospective-fork-boundary.ts +57 -20
- package/src/plugins/defaults/memory/memory-retrospective-job.ts +13 -15
- package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +2 -2
- package/src/plugins/defaults/memory/memory-retrospective-startup-cleanup.ts +52 -39
- package/src/plugins/defaults/memory/memory-retrospective-trigger-check.ts +1 -1
- package/src/plugins/defaults/memory/pkb/pkb-index.test.ts +25 -38
- package/src/plugins/defaults/memory/pkb/pkb-index.ts +7 -19
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.test.ts +46 -28
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.ts +4 -9
- package/src/plugins/defaults/memory/pkb/pkb-search.test.ts +3 -9
- package/src/plugins/defaults/memory/pkb/pkb-search.ts +2 -9
- package/src/plugins/defaults/memory/pkb/types.ts +0 -11
- package/src/plugins/defaults/memory/rerank-local.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +0 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.ts +3 -11
- package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-v3-routes.ts +1 -1
- package/src/plugins/defaults/memory/startup.ts +2 -3
- package/src/plugins/defaults/memory/task-memory-cleanup.ts +1 -1
- package/src/plugins/defaults/memory/tools.test.ts +1 -9
- package/src/plugins/defaults/memory/tools.ts +0 -1
- package/src/plugins/defaults/memory/v2/backfill-jobs.ts +1 -1
- package/src/plugins/defaults/memory/v2/cli-command-store.ts +1 -1
- package/src/plugins/defaults/memory/v2/consolidation-job.ts +1 -1
- package/src/plugins/defaults/memory/v2/frontmatter-sweep.ts +1 -1
- package/src/plugins/defaults/memory/v2/injection-events.ts +1 -1
- package/src/plugins/defaults/memory/v2/injection.ts +1 -1
- package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +1 -1
- package/src/plugins/defaults/memory/v2/migration.ts +1 -1
- package/src/plugins/defaults/memory/v2/page-index.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/router.ts +1 -1
- package/src/plugins/defaults/memory/v2/qdrant.ts +1 -1
- package/src/plugins/defaults/memory/v2/reranker.ts +1 -1
- package/src/plugins/defaults/memory/v2/router.ts +1 -1
- package/src/plugins/defaults/memory/v2/skill-store.ts +1 -1
- package/src/plugins/defaults/memory/v2/sweep-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
- package/src/plugins/defaults/memory/v3/dense.ts +1 -1
- package/src/plugins/defaults/memory/v3/injector.ts +1 -1
- package/src/plugins/defaults/memory/v3/maintain-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/orchestrate.ts +1 -1
- package/src/plugins/defaults/memory/v3/pool-select.ts +1 -1
- package/src/plugins/defaults/memory/v3/prune.ts +1 -1
- package/src/plugins/defaults/memory/v3/section-dense-store.ts +1 -1
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +1 -1
- package/src/plugins/defaults/memory/worker.ts +1 -1
- package/src/runtime/capabilities.ts +1 -1
- package/src/runtime/routes/__tests__/bookmark-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/conversation-management-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +0 -1
- package/src/runtime/routes/conversation-starter-routes.ts +12 -23
- package/src/runtime/routes/index.ts +0 -2
- package/src/runtime/services/__tests__/auto-analysis-guard.test.ts +1 -8
- package/src/runtime/services/__tests__/conversation-serializer.test.ts +0 -1
- package/src/runtime/services/auto-analysis-guard.ts +5 -5
- package/src/runtime/services/conversation-serializer.ts +2 -3
- package/src/tasks/SPEC.md +10 -17
- package/src/tools/executor.ts +1 -102
- package/src/tools/filesystem/write.ts +0 -2
- package/src/tools/tool-types.ts +0 -15
- package/src/tools/types.ts +0 -10
- package/src/workspace/migrations/028-recover-conversations-from-disk-view.ts +0 -1
- package/src/workspace/migrations/129-remove-analyze-conversation-config.ts +59 -0
- package/src/workspace/migrations/registry.ts +2 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/src/__tests__/auto-analysis-end-to-end.test.ts +0 -621
- package/src/__tests__/auto-analysis-prompt.test.ts +0 -50
- package/src/__tests__/config-analysis.test.ts +0 -83
- package/src/__tests__/conversation-analysis-routes.test.ts +0 -156
- package/src/__tests__/credential-execution-approval-bridge.test.ts +0 -297
- package/src/config/schemas/analysis.ts +0 -32
- package/src/credential-execution/approval-bridge.ts +0 -320
- package/src/daemon/__tests__/conversation-lifecycle-auto-analyze.test.ts +0 -449
- package/src/plugins/defaults/memory/__tests__/find-analysis-conversation.test.ts +0 -197
- package/src/runtime/routes/conversation-analysis-routes.ts +0 -75
- package/src/runtime/services/__tests__/analyze-conversation.test.ts +0 -477
- package/src/runtime/services/__tests__/auto-analysis-enqueue.test.ts +0 -386
- package/src/runtime/services/__tests__/auto-analysis-prompt.test.ts +0 -53
- package/src/runtime/services/__tests__/conversation-analyze-job.test.ts +0 -213
- package/src/runtime/services/__tests__/manual-analysis-prompt.test.ts +0 -41
- package/src/runtime/services/analyze-conversation.ts +0 -334
- package/src/runtime/services/auto-analysis-enqueue.ts +0 -130
- package/src/runtime/services/auto-analysis-prompt.ts +0 -55
- package/src/runtime/services/conversation-analyze-job.ts +0 -53
|
@@ -19,11 +19,14 @@ mock.module("../config/loader.js", () => ({
|
|
|
19
19
|
}),
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
+
import { eq } from "drizzle-orm";
|
|
23
|
+
|
|
22
24
|
import {
|
|
23
25
|
getAttachmentsForMessage,
|
|
24
26
|
linkAttachmentToMessage,
|
|
25
27
|
uploadAttachment,
|
|
26
28
|
} from "../persistence/attachments-store.js";
|
|
29
|
+
import { appendCompactionEvent } from "../persistence/compaction-ledger-store.js";
|
|
27
30
|
import {
|
|
28
31
|
addMessage,
|
|
29
32
|
createConversation,
|
|
@@ -43,17 +46,28 @@ import {
|
|
|
43
46
|
activationState,
|
|
44
47
|
channelInboundEvents,
|
|
45
48
|
conversationAssistantAttentionState,
|
|
49
|
+
conversationCompactionEvents,
|
|
46
50
|
conversationGraphMemoryState,
|
|
51
|
+
conversations,
|
|
47
52
|
externalConversationBindings,
|
|
48
53
|
llmRequestLogs,
|
|
49
54
|
memoryJobs,
|
|
50
55
|
memoryRetrospectiveState,
|
|
56
|
+
messages,
|
|
51
57
|
toolInvocations,
|
|
52
58
|
} from "../persistence/schema/index.js";
|
|
53
59
|
import {
|
|
54
60
|
loadGraphMemoryState,
|
|
55
61
|
saveGraphMemoryState,
|
|
56
62
|
} from "../plugins/defaults/memory/graph/graph-memory-state-store.js";
|
|
63
|
+
import {
|
|
64
|
+
MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
65
|
+
MEMORY_RETROSPECTIVE_INSTRUCTION_KIND,
|
|
66
|
+
} from "../plugins/defaults/memory/memory-retrospective-constants.js";
|
|
67
|
+
import {
|
|
68
|
+
findForkBoundaryCreatedAt,
|
|
69
|
+
loadRetrospectiveRunMessages,
|
|
70
|
+
} from "../plugins/defaults/memory/memory-retrospective-fork-boundary.js";
|
|
57
71
|
|
|
58
72
|
await initializeDb();
|
|
59
73
|
|
|
@@ -71,6 +85,7 @@ function resetTables(): void {
|
|
|
71
85
|
db.run("DELETE FROM memory_v3_ever_injected");
|
|
72
86
|
db.run("DELETE FROM message_attachments");
|
|
73
87
|
db.run("DELETE FROM attachments");
|
|
88
|
+
db.run("DELETE FROM conversation_compaction_events");
|
|
74
89
|
db.run("DELETE FROM messages");
|
|
75
90
|
db.run("DELETE FROM conversations");
|
|
76
91
|
}
|
|
@@ -248,3 +263,471 @@ describe("forkConversationForRetrospective", () => {
|
|
|
248
263
|
expect(countConversations()).toBe(before);
|
|
249
264
|
});
|
|
250
265
|
});
|
|
266
|
+
|
|
267
|
+
describe("forkConversationForRetrospective — compacted source", () => {
|
|
268
|
+
beforeEach(() => {
|
|
269
|
+
resetTables();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
interface CompactedSource {
|
|
273
|
+
id: string;
|
|
274
|
+
summary: string;
|
|
275
|
+
compactedAt: number;
|
|
276
|
+
compactedCount: number;
|
|
277
|
+
base: number;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Six-message source with a compaction covering the first four rows.
|
|
282
|
+
* Timestamps are pinned so the compaction event sits strictly between
|
|
283
|
+
* row 4 and row 5.
|
|
284
|
+
*/
|
|
285
|
+
async function seedCompactedSource(): Promise<CompactedSource> {
|
|
286
|
+
const source = createConversation("Compacted retro thread");
|
|
287
|
+
const rows = [
|
|
288
|
+
await addMessage(source.id, "user", "old question", {
|
|
289
|
+
skipIndexing: true,
|
|
290
|
+
}),
|
|
291
|
+
await addMessage(source.id, "assistant", "old answer", {
|
|
292
|
+
skipIndexing: true,
|
|
293
|
+
}),
|
|
294
|
+
await addMessage(source.id, "user", "older question", {
|
|
295
|
+
skipIndexing: true,
|
|
296
|
+
}),
|
|
297
|
+
await addMessage(source.id, "assistant", "older answer", {
|
|
298
|
+
skipIndexing: true,
|
|
299
|
+
}),
|
|
300
|
+
await addMessage(source.id, "user", "fresh question", {
|
|
301
|
+
skipIndexing: true,
|
|
302
|
+
}),
|
|
303
|
+
await addMessage(source.id, "assistant", "fresh answer", {
|
|
304
|
+
skipIndexing: true,
|
|
305
|
+
}),
|
|
306
|
+
];
|
|
307
|
+
const db = getDb();
|
|
308
|
+
const base = Date.now();
|
|
309
|
+
rows.forEach((row, index) => {
|
|
310
|
+
const createdAt = index < 4 ? base + index : base + index + 10;
|
|
311
|
+
db.update(messages)
|
|
312
|
+
.set({ createdAt })
|
|
313
|
+
.where(eq(messages.id, row.id))
|
|
314
|
+
.run();
|
|
315
|
+
});
|
|
316
|
+
const compactedAt = base + 5;
|
|
317
|
+
const summary = "Summary of the old exchange";
|
|
318
|
+
db.update(conversations)
|
|
319
|
+
.set({
|
|
320
|
+
contextSummary: summary,
|
|
321
|
+
contextCompactedMessageCount: 4,
|
|
322
|
+
contextCompactedAt: compactedAt,
|
|
323
|
+
})
|
|
324
|
+
.where(eq(conversations.id, source.id))
|
|
325
|
+
.run();
|
|
326
|
+
appendCompactionEvent(source.id, {
|
|
327
|
+
compactedAt,
|
|
328
|
+
summary,
|
|
329
|
+
compactedMessageCount: 4,
|
|
330
|
+
});
|
|
331
|
+
return { id: source.id, summary, compactedAt, compactedCount: 4, base };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function contentOf(m: { role: string; content: string; createdAt: number }) {
|
|
335
|
+
return { role: m.role, content: m.content, createdAt: m.createdAt };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
test("copies only the visible tail and renders identically to the source", async () => {
|
|
339
|
+
const source = await seedCompactedSource();
|
|
340
|
+
const sourceRows = getMessages(source.id);
|
|
341
|
+
const tip = sourceRows.at(-1)!;
|
|
342
|
+
|
|
343
|
+
const fork = await forkConversationForRetrospective({
|
|
344
|
+
conversationId: source.id,
|
|
345
|
+
throughMessageId: tip.id,
|
|
346
|
+
conversationType: "background",
|
|
347
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// Physical rows: the visible tail only, each stamped with its source id.
|
|
351
|
+
const forkRows = getMessages(fork.id);
|
|
352
|
+
expect(forkRows.map(contentOf)).toEqual(sourceRows.slice(4).map(contentOf));
|
|
353
|
+
expect(
|
|
354
|
+
forkRows.map(
|
|
355
|
+
(m) =>
|
|
356
|
+
(JSON.parse(m.metadata!) as { forkSourceMessageId: string })
|
|
357
|
+
.forkSourceMessageId,
|
|
358
|
+
),
|
|
359
|
+
).toEqual(sourceRows.slice(4).map((m) => m.id));
|
|
360
|
+
|
|
361
|
+
// Fork row: inherited summary + timestamp, fork-local count of 0.
|
|
362
|
+
expect(fork.contextSummary).toBe(source.summary);
|
|
363
|
+
expect(fork.contextCompactedMessageCount).toBe(0);
|
|
364
|
+
expect(fork.contextCompactedAt).toBe(source.compactedAt);
|
|
365
|
+
expect(fork.forkParentMessageId).toBe(tip.id);
|
|
366
|
+
|
|
367
|
+
// Rendered history — summary + post-slice rows, assembled the way
|
|
368
|
+
// `loadFromDb` does — is identical to the source's.
|
|
369
|
+
const render = (
|
|
370
|
+
summary: string | null,
|
|
371
|
+
rows: Array<{ role: string; content: string; createdAt: number }>,
|
|
372
|
+
count: number,
|
|
373
|
+
) => [summary, ...rows.slice(Math.min(count, rows.length)).map(contentOf)];
|
|
374
|
+
expect(
|
|
375
|
+
render(fork.contextSummary, forkRows, fork.contextCompactedMessageCount),
|
|
376
|
+
).toEqual(render(source.summary, sourceRows, source.compactedCount));
|
|
377
|
+
|
|
378
|
+
// The synchronous user fork keeps the full physical history.
|
|
379
|
+
const syncFork = forkConversation({
|
|
380
|
+
conversationId: source.id,
|
|
381
|
+
throughMessageId: tip.id,
|
|
382
|
+
});
|
|
383
|
+
expect(getMessages(syncFork.id)).toHaveLength(6);
|
|
384
|
+
expect(syncFork.contextCompactedMessageCount).toBe(4);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
test("carries per-conversation memory state wholesale on a tip fork", async () => {
|
|
388
|
+
const source = await seedCompactedSource();
|
|
389
|
+
const snapshot = JSON.stringify({ inContext: ["node-a"], currentTurn: 7 });
|
|
390
|
+
saveGraphMemoryState(source.id, snapshot);
|
|
391
|
+
const everInjected = JSON.stringify([{ slug: "page-a", turn: 1 }]);
|
|
392
|
+
const db = getDb();
|
|
393
|
+
db.insert(activationState)
|
|
394
|
+
.values({
|
|
395
|
+
conversationId: source.id,
|
|
396
|
+
messageId: "source-turn-marker",
|
|
397
|
+
stateJson: "{}",
|
|
398
|
+
everInjectedJson: everInjected,
|
|
399
|
+
currentTurn: 7,
|
|
400
|
+
updatedAt: Date.now(),
|
|
401
|
+
})
|
|
402
|
+
.run();
|
|
403
|
+
getSqlite()
|
|
404
|
+
.query(
|
|
405
|
+
`INSERT INTO memory_v3_ever_injected (conversation_id, slug, injected_at, bytes, pruned_at)
|
|
406
|
+
VALUES (?, 'card-a', ?, 12, NULL)`,
|
|
407
|
+
)
|
|
408
|
+
.run(source.id, Date.now());
|
|
409
|
+
|
|
410
|
+
const tip = getMessages(source.id).at(-1)!;
|
|
411
|
+
const fork = await forkConversationForRetrospective({
|
|
412
|
+
conversationId: source.id,
|
|
413
|
+
throughMessageId: tip.id,
|
|
414
|
+
conversationType: "background",
|
|
415
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// The fork's rendered window equals the source's, so activation,
|
|
419
|
+
// ever-injected, and graph state are carried as-is.
|
|
420
|
+
expect(loadGraphMemoryState(fork.id)).toBe(snapshot);
|
|
421
|
+
const forkActivation = db
|
|
422
|
+
.select()
|
|
423
|
+
.from(activationState)
|
|
424
|
+
.where(eq(activationState.conversationId, fork.id))
|
|
425
|
+
.get();
|
|
426
|
+
expect(forkActivation?.everInjectedJson).toBe(everInjected);
|
|
427
|
+
const v3Rows = getSqlite()
|
|
428
|
+
.query(
|
|
429
|
+
"SELECT slug FROM memory_v3_ever_injected WHERE conversation_id = ?",
|
|
430
|
+
)
|
|
431
|
+
.all(fork.id) as Array<{ slug: string }>;
|
|
432
|
+
expect(v3Rows.map((r) => r.slug)).toEqual(["card-a"]);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test("re-derives memory seeding from the copied tail on a truncated cutoff", async () => {
|
|
436
|
+
const source = await seedCompactedSource();
|
|
437
|
+
const db = getDb();
|
|
438
|
+
const sourceRows = getMessages(source.id);
|
|
439
|
+
// Injection blocks: one behind the summary, one on a visible tail row.
|
|
440
|
+
db.update(messages)
|
|
441
|
+
.set({
|
|
442
|
+
metadata: JSON.stringify({
|
|
443
|
+
memoryInjectedBlock: "# memory/concepts/prefix-slug.md",
|
|
444
|
+
}),
|
|
445
|
+
})
|
|
446
|
+
.where(eq(messages.id, sourceRows[0]!.id))
|
|
447
|
+
.run();
|
|
448
|
+
db.update(messages)
|
|
449
|
+
.set({
|
|
450
|
+
metadata: JSON.stringify({
|
|
451
|
+
memoryInjectedBlock: "# memory/concepts/tail-slug.md",
|
|
452
|
+
}),
|
|
453
|
+
})
|
|
454
|
+
.where(eq(messages.id, sourceRows[4]!.id))
|
|
455
|
+
.run();
|
|
456
|
+
const snapshot = JSON.stringify({ inContext: ["node-a"], currentTurn: 7 });
|
|
457
|
+
saveGraphMemoryState(source.id, snapshot);
|
|
458
|
+
|
|
459
|
+
// Cut off before the tip (a user row, so no display-turn extension): the
|
|
460
|
+
// fork is truncated and takes the derived-seeding branch.
|
|
461
|
+
const fork = await forkConversationForRetrospective({
|
|
462
|
+
conversationId: source.id,
|
|
463
|
+
throughMessageId: sourceRows[4]!.id,
|
|
464
|
+
conversationType: "background",
|
|
465
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// The compaction slice composes with the cutoff: source row 5 only.
|
|
469
|
+
const forkRows = getMessages(fork.id);
|
|
470
|
+
expect(forkRows.map((m) => m.content)).toEqual([sourceRows[4]!.content]);
|
|
471
|
+
expect(fork.forkParentMessageId).toBe(sourceRows[4]!.id);
|
|
472
|
+
|
|
473
|
+
// Derived seeding sees only the copied tail's slug; the wholesale graph
|
|
474
|
+
// carry is skipped for truncated forks.
|
|
475
|
+
const forkActivation = db
|
|
476
|
+
.select()
|
|
477
|
+
.from(activationState)
|
|
478
|
+
.where(eq(activationState.conversationId, fork.id))
|
|
479
|
+
.get();
|
|
480
|
+
expect(forkActivation?.everInjectedJson).toBe(
|
|
481
|
+
JSON.stringify([{ slug: "tail-slug", turn: 0 }]),
|
|
482
|
+
);
|
|
483
|
+
expect(loadGraphMemoryState(fork.id)).toBeNull();
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test("seeds a single count-adjusted ledger event instead of copying the source ledger", async () => {
|
|
487
|
+
const source = await seedCompactedSource();
|
|
488
|
+
// An older superseded event on the source; it must not be copied either.
|
|
489
|
+
appendCompactionEvent(source.id, {
|
|
490
|
+
compactedAt: source.base + 1,
|
|
491
|
+
summary: "Older summary",
|
|
492
|
+
compactedMessageCount: 2,
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
const tip = getMessages(source.id).at(-1)!;
|
|
496
|
+
const fork = await forkConversationForRetrospective({
|
|
497
|
+
conversationId: source.id,
|
|
498
|
+
throughMessageId: tip.id,
|
|
499
|
+
conversationType: "background",
|
|
500
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const forkEvents = getDb()
|
|
504
|
+
.select()
|
|
505
|
+
.from(conversationCompactionEvents)
|
|
506
|
+
.where(eq(conversationCompactionEvents.conversationId, fork.id))
|
|
507
|
+
.all();
|
|
508
|
+
expect(forkEvents).toHaveLength(1);
|
|
509
|
+
expect(forkEvents[0]).toMatchObject({
|
|
510
|
+
compactedAt: source.compactedAt,
|
|
511
|
+
summary: source.summary,
|
|
512
|
+
compactedMessageCount: 0,
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
// A fork of the fork at its tip inherits the summary with the fork-local
|
|
516
|
+
// count — no rows are hidden behind it.
|
|
517
|
+
const forkTip = getMessages(fork.id).at(-1)!;
|
|
518
|
+
const grandchild = forkConversation({
|
|
519
|
+
conversationId: fork.id,
|
|
520
|
+
throughMessageId: forkTip.id,
|
|
521
|
+
});
|
|
522
|
+
expect(grandchild.contextSummary).toBe(source.summary);
|
|
523
|
+
expect(grandchild.contextCompactedMessageCount).toBe(0);
|
|
524
|
+
expect(getMessages(grandchild.id)).toHaveLength(
|
|
525
|
+
getMessages(fork.id).length,
|
|
526
|
+
);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
test("post-fork tail extraction still detects the copied boundary", async () => {
|
|
530
|
+
const source = await seedCompactedSource();
|
|
531
|
+
const tip = getMessages(source.id).at(-1)!;
|
|
532
|
+
const fork = await forkConversationForRetrospective({
|
|
533
|
+
conversationId: source.id,
|
|
534
|
+
throughMessageId: tip.id,
|
|
535
|
+
conversationType: "background",
|
|
536
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
const boundary = findForkBoundaryCreatedAt(getMessages(fork.id));
|
|
540
|
+
expect(boundary).toBe(tip.createdAt);
|
|
541
|
+
|
|
542
|
+
// A run-authored message lands after the boundary and is the only row
|
|
543
|
+
// attributed to the run.
|
|
544
|
+
const runMessage = await addMessage(fork.id, "user", "retro instruction", {
|
|
545
|
+
skipIndexing: true,
|
|
546
|
+
});
|
|
547
|
+
getDb()
|
|
548
|
+
.update(messages)
|
|
549
|
+
.set({ createdAt: tip.createdAt + 100 })
|
|
550
|
+
.where(eq(messages.id, runMessage.id))
|
|
551
|
+
.run();
|
|
552
|
+
const runRows = await loadRetrospectiveRunMessages(
|
|
553
|
+
fork.id,
|
|
554
|
+
MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
555
|
+
);
|
|
556
|
+
expect(runRows?.map((m) => m.id)).toEqual([runMessage.id]);
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
test("succeeds with an empty tail when the compaction covers the whole cutoff range", async () => {
|
|
560
|
+
const source = await seedCompactedSource();
|
|
561
|
+
const db = getDb();
|
|
562
|
+
const sourceRows = getMessages(source.id);
|
|
563
|
+
const tip = sourceRows.at(-1)!;
|
|
564
|
+
// A later compaction covering every row, timestamped exactly at the tip.
|
|
565
|
+
db.update(conversations)
|
|
566
|
+
.set({
|
|
567
|
+
contextSummary: "Everything summarized",
|
|
568
|
+
contextCompactedMessageCount: sourceRows.length,
|
|
569
|
+
contextCompactedAt: tip.createdAt,
|
|
570
|
+
})
|
|
571
|
+
.where(eq(conversations.id, source.id))
|
|
572
|
+
.run();
|
|
573
|
+
appendCompactionEvent(source.id, {
|
|
574
|
+
compactedAt: tip.createdAt,
|
|
575
|
+
summary: "Everything summarized",
|
|
576
|
+
compactedMessageCount: sourceRows.length,
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
const fork = await forkConversationForRetrospective({
|
|
580
|
+
conversationId: source.id,
|
|
581
|
+
throughMessageId: tip.id,
|
|
582
|
+
conversationType: "background",
|
|
583
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
expect(getMessages(fork.id)).toHaveLength(0);
|
|
587
|
+
expect(fork.contextSummary).toBe("Everything summarized");
|
|
588
|
+
expect(fork.contextCompactedMessageCount).toBe(0);
|
|
589
|
+
expect(fork.contextCompactedAt).toBe(tip.createdAt);
|
|
590
|
+
expect(fork.forkParentMessageId).toBe(tip.id);
|
|
591
|
+
// Ageable despite copying no rows, so the startup orphan sweep (which
|
|
592
|
+
// skips null `lastMessageAt` rows) can reclaim it after a crash.
|
|
593
|
+
expect(fork.lastMessageAt).toBe(tip.createdAt);
|
|
594
|
+
|
|
595
|
+
// With no stamped copied rows and the run's instruction opening the
|
|
596
|
+
// conversation, every message is the run's own output — it still feeds
|
|
597
|
+
// the success bookkeeping (dedup baseline, skill cards).
|
|
598
|
+
const runMessage = await addMessage(fork.id, "user", "retro instruction", {
|
|
599
|
+
metadata: {
|
|
600
|
+
kind: MEMORY_RETROSPECTIVE_INSTRUCTION_KIND,
|
|
601
|
+
hidden: true,
|
|
602
|
+
},
|
|
603
|
+
skipIndexing: true,
|
|
604
|
+
});
|
|
605
|
+
const runRows = await loadRetrospectiveRunMessages(
|
|
606
|
+
fork.id,
|
|
607
|
+
MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
608
|
+
);
|
|
609
|
+
expect(runRows?.map((m) => m.id)).toEqual([runMessage.id]);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test("drops the render-hidden rows on createdAt ties, not the re-sort prefix", async () => {
|
|
613
|
+
const source = createConversation("Tie-boundary thread");
|
|
614
|
+
const first = await addMessage(source.id, "user", "hidden by compaction", {
|
|
615
|
+
skipIndexing: true,
|
|
616
|
+
});
|
|
617
|
+
const second = await addMessage(source.id, "assistant", "still visible", {
|
|
618
|
+
skipIndexing: true,
|
|
619
|
+
});
|
|
620
|
+
const tail = await addMessage(source.id, "user", "fresh tail", {
|
|
621
|
+
skipIndexing: true,
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
// The first two rows share a millisecond, with ids crafted so the cutoff
|
|
625
|
+
// re-sort's `(createdAt, id)` order REVERSES their insertion (= render)
|
|
626
|
+
// order. The compaction hides exactly one row: in render order that is
|
|
627
|
+
// `first`; a positional slice of the re-sorted array would drop `second`
|
|
628
|
+
// instead.
|
|
629
|
+
const db = getDb();
|
|
630
|
+
const base = Date.now();
|
|
631
|
+
db.update(messages)
|
|
632
|
+
.set({ id: "zz-tie-first", createdAt: base })
|
|
633
|
+
.where(eq(messages.id, first.id))
|
|
634
|
+
.run();
|
|
635
|
+
db.update(messages)
|
|
636
|
+
.set({ id: "aa-tie-second", createdAt: base })
|
|
637
|
+
.where(eq(messages.id, second.id))
|
|
638
|
+
.run();
|
|
639
|
+
db.update(messages)
|
|
640
|
+
.set({ createdAt: base + 10 })
|
|
641
|
+
.where(eq(messages.id, tail.id))
|
|
642
|
+
.run();
|
|
643
|
+
const compactedAt = base + 5;
|
|
644
|
+
db.update(conversations)
|
|
645
|
+
.set({
|
|
646
|
+
contextSummary: "Tie summary",
|
|
647
|
+
contextCompactedMessageCount: 1,
|
|
648
|
+
contextCompactedAt: compactedAt,
|
|
649
|
+
})
|
|
650
|
+
.where(eq(conversations.id, source.id))
|
|
651
|
+
.run();
|
|
652
|
+
appendCompactionEvent(source.id, {
|
|
653
|
+
compactedAt,
|
|
654
|
+
summary: "Tie summary",
|
|
655
|
+
compactedMessageCount: 1,
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
const fork = await forkConversationForRetrospective({
|
|
659
|
+
conversationId: source.id,
|
|
660
|
+
throughMessageId: tail.id,
|
|
661
|
+
conversationType: "background",
|
|
662
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
// The source renders ["still visible", "fresh tail"] after its slice;
|
|
666
|
+
// the fork must carry exactly those rows.
|
|
667
|
+
expect(getMessages(fork.id).map((m) => m.content)).toEqual([
|
|
668
|
+
"still visible",
|
|
669
|
+
"fresh tail",
|
|
670
|
+
]);
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
test("seeds the fork-local ledger event even when the hidden prefix falls outside the cutoff", async () => {
|
|
674
|
+
const source = createConversation("Tie-cutoff thread");
|
|
675
|
+
const hidden = await addMessage(source.id, "user", "hidden by compaction", {
|
|
676
|
+
skipIndexing: true,
|
|
677
|
+
});
|
|
678
|
+
const requested = await addMessage(source.id, "assistant", "visible", {
|
|
679
|
+
skipIndexing: true,
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
// Same-millisecond rows with ids crafted so the `(createdAt, id)` cutoff
|
|
683
|
+
// order puts the requested message BEFORE the render-hidden sibling: the
|
|
684
|
+
// cutoff range then contains no hidden row, so nothing is dropped, but
|
|
685
|
+
// the fork still inherits the compaction and must not copy the source's
|
|
686
|
+
// count-1 ledger event (a fork of this fork would hide a visible row).
|
|
687
|
+
const db = getDb();
|
|
688
|
+
const base = Date.now();
|
|
689
|
+
db.update(messages)
|
|
690
|
+
.set({ id: "zz-tie-hidden", createdAt: base })
|
|
691
|
+
.where(eq(messages.id, hidden.id))
|
|
692
|
+
.run();
|
|
693
|
+
db.update(messages)
|
|
694
|
+
.set({ id: "aa-tie-requested", createdAt: base })
|
|
695
|
+
.where(eq(messages.id, requested.id))
|
|
696
|
+
.run();
|
|
697
|
+
db.update(conversations)
|
|
698
|
+
.set({
|
|
699
|
+
contextSummary: "Tie summary",
|
|
700
|
+
contextCompactedMessageCount: 1,
|
|
701
|
+
contextCompactedAt: base,
|
|
702
|
+
})
|
|
703
|
+
.where(eq(conversations.id, source.id))
|
|
704
|
+
.run();
|
|
705
|
+
appendCompactionEvent(source.id, {
|
|
706
|
+
compactedAt: base,
|
|
707
|
+
summary: "Tie summary",
|
|
708
|
+
compactedMessageCount: 1,
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
const fork = await forkConversationForRetrospective({
|
|
712
|
+
conversationId: source.id,
|
|
713
|
+
throughMessageId: "aa-tie-requested",
|
|
714
|
+
conversationType: "background",
|
|
715
|
+
source: MEMORY_RETROSPECTIVE_FORK_SOURCE,
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
expect(getMessages(fork.id).map((m) => m.content)).toEqual(["visible"]);
|
|
719
|
+
expect(fork.contextSummary).toBe("Tie summary");
|
|
720
|
+
expect(fork.contextCompactedMessageCount).toBe(0);
|
|
721
|
+
const forkEvents = getDb()
|
|
722
|
+
.select()
|
|
723
|
+
.from(conversationCompactionEvents)
|
|
724
|
+
.where(eq(conversationCompactionEvents.conversationId, fork.id))
|
|
725
|
+
.all();
|
|
726
|
+
expect(forkEvents).toHaveLength(1);
|
|
727
|
+
expect(forkEvents[0]).toMatchObject({
|
|
728
|
+
compactedAt: base,
|
|
729
|
+
summary: "Tie summary",
|
|
730
|
+
compactedMessageCount: 0,
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
});
|
|
@@ -146,10 +146,6 @@ function createFakeConversation(conversationId: string): Conversation {
|
|
|
146
146
|
messages: [] as Array<unknown>,
|
|
147
147
|
hostCuProxy: undefined as unknown,
|
|
148
148
|
usageStats: { inputTokens: 0, outputTokens: 0, estimatedCost: 0 },
|
|
149
|
-
memoryPolicy: {
|
|
150
|
-
scopeId: "default",
|
|
151
|
-
includeDefaultFallback: false,
|
|
152
|
-
},
|
|
153
149
|
isProcessing(this: { processing: boolean }) {
|
|
154
150
|
return this.processing;
|
|
155
151
|
},
|
|
@@ -467,17 +467,11 @@ describe("conversation metadata defaults", () => {
|
|
|
467
467
|
expect(conv.conversationType).toBe("standard");
|
|
468
468
|
});
|
|
469
469
|
|
|
470
|
-
test("new conversation has memoryScopeId defaulting to default", () => {
|
|
471
|
-
const conv = createConversation("test");
|
|
472
|
-
expect(conv.memoryScopeId).toBe("default");
|
|
473
|
-
});
|
|
474
|
-
|
|
475
470
|
test("defaults are persisted and retrievable from DB", () => {
|
|
476
471
|
const conv = createConversation("test");
|
|
477
472
|
const loaded = getConversation(conv.id);
|
|
478
473
|
expect(loaded).not.toBeNull();
|
|
479
474
|
expect(loaded!.conversationType).toBe("standard");
|
|
480
|
-
expect(loaded!.memoryScopeId).toBe("default");
|
|
481
475
|
});
|
|
482
476
|
|
|
483
477
|
test("existing conversations without explicit values get defaults via migration", () => {
|
|
@@ -493,7 +487,6 @@ describe("conversation metadata defaults", () => {
|
|
|
493
487
|
const loaded = getConversation(id);
|
|
494
488
|
expect(loaded).not.toBeNull();
|
|
495
489
|
expect(loaded!.conversationType).toBe("standard");
|
|
496
|
-
expect(loaded!.memoryScopeId).toBe("default");
|
|
497
490
|
});
|
|
498
491
|
});
|
|
499
492
|
|
|
@@ -508,7 +501,6 @@ describe("createConversation with conversation type option", () => {
|
|
|
508
501
|
const conv = createConversation("hello");
|
|
509
502
|
expect(conv.title).toBe("hello");
|
|
510
503
|
expect(conv.conversationType).toBe("standard");
|
|
511
|
-
expect(conv.memoryScopeId).toBe("default");
|
|
512
504
|
});
|
|
513
505
|
|
|
514
506
|
test("standard create with options object uses defaults", () => {
|
|
@@ -517,13 +509,11 @@ describe("createConversation with conversation type option", () => {
|
|
|
517
509
|
conversationType: "standard",
|
|
518
510
|
});
|
|
519
511
|
expect(conv.conversationType).toBe("standard");
|
|
520
|
-
expect(conv.memoryScopeId).toBe("default");
|
|
521
512
|
});
|
|
522
513
|
|
|
523
514
|
test("no-arg create uses defaults", () => {
|
|
524
515
|
const conv = createConversation();
|
|
525
516
|
expect(conv.conversationType).toBe("standard");
|
|
526
|
-
expect(conv.memoryScopeId).toBe("default");
|
|
527
517
|
});
|
|
528
518
|
});
|
|
529
519
|
|
|
@@ -240,10 +240,6 @@ mock.module("../persistence/llm-usage-store.js", () => ({
|
|
|
240
240
|
listUsageEvents: () => [],
|
|
241
241
|
}));
|
|
242
242
|
|
|
243
|
-
mock.module("../runtime/services/auto-analysis-enqueue.js", () => ({
|
|
244
|
-
enqueueAutoAnalysisOnCompaction: () => {},
|
|
245
|
-
}));
|
|
246
|
-
|
|
247
243
|
mock.module("../agent/loop.js", () => ({
|
|
248
244
|
AgentLoop: class {
|
|
249
245
|
compactionCircuit = new CompactionCircuit("test-conv");
|
|
@@ -22,14 +22,6 @@
|
|
|
22
22
|
* isAlive/close) so the mock is trivial and cannot diverge from real
|
|
23
23
|
* behaviour.
|
|
24
24
|
*
|
|
25
|
-
* The **server-side** lazy `ApiKeyRef` pattern used in `main.ts`
|
|
26
|
-
* is tested directly in
|
|
27
|
-
* `credential-executor/src/__tests__/managed-lazy-getters.test.ts`
|
|
28
|
-
* against the production `buildLazyGetters` function. A structural guard
|
|
29
|
-
* below verifies that `main.ts` imports `buildLazyGetters` from
|
|
30
|
-
* `managed-lazy-getters.ts`, so these two test files stay coupled to
|
|
31
|
-
* production code.
|
|
32
|
-
*
|
|
33
25
|
* These tests mock the transport layer (no real processes or sockets)
|
|
34
26
|
* to verify the contract and wiring in isolation.
|
|
35
27
|
*/
|
|
@@ -275,35 +267,3 @@ describe("CesClient.updateAssistantApiKey()", () => {
|
|
|
275
267
|
client.close();
|
|
276
268
|
});
|
|
277
269
|
});
|
|
278
|
-
|
|
279
|
-
// ---------------------------------------------------------------------------
|
|
280
|
-
// Structural guard: main.ts uses production buildLazyGetters
|
|
281
|
-
// ---------------------------------------------------------------------------
|
|
282
|
-
|
|
283
|
-
describe("structural guard: main.ts uses production buildLazyGetters", () => {
|
|
284
|
-
test("main.ts imports buildLazyGetters from managed-lazy-getters", async () => {
|
|
285
|
-
// This guard ensures that main.ts exercises the production
|
|
286
|
-
// buildLazyGetters function (tested in managed-lazy-getters.test.ts),
|
|
287
|
-
// not a local reimplementation. If the import is removed or the source
|
|
288
|
-
// module changes, this test will fail and signal that the companion
|
|
289
|
-
// test coverage may no longer be wired to production code.
|
|
290
|
-
const { readFileSync } = await import("node:fs");
|
|
291
|
-
const { join, dirname } = await import("node:path");
|
|
292
|
-
|
|
293
|
-
// Resolve from the repo root (three levels up from __tests__/)
|
|
294
|
-
const repoRoot = join(dirname(import.meta.dir), "..", "..");
|
|
295
|
-
const managedMainPath = join(
|
|
296
|
-
repoRoot,
|
|
297
|
-
"credential-executor",
|
|
298
|
-
"src",
|
|
299
|
-
"main.ts",
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
const source = readFileSync(managedMainPath, "utf-8");
|
|
303
|
-
|
|
304
|
-
expect(source).toContain('from "./managed-lazy-getters.js"');
|
|
305
|
-
expect(source).toMatch(
|
|
306
|
-
/import\s+\{[^}]*buildLazyGetters[^}]*\}\s+from\s+["']\.\/managed-lazy-getters\.js["']/,
|
|
307
|
-
);
|
|
308
|
-
});
|
|
309
|
-
});
|
|
@@ -271,7 +271,7 @@ describe("CES client", () => {
|
|
|
271
271
|
const client = createCesClient(transport);
|
|
272
272
|
|
|
273
273
|
try {
|
|
274
|
-
await client.call("
|
|
274
|
+
await client.call("list_credentials", {});
|
|
275
275
|
expect(true).toBe(false);
|
|
276
276
|
} catch (err) {
|
|
277
277
|
expect(err).toBeInstanceOf(CesClientError);
|
|
@@ -304,7 +304,7 @@ describe("CES client", () => {
|
|
|
304
304
|
transport.alive = false;
|
|
305
305
|
|
|
306
306
|
try {
|
|
307
|
-
await client.call("
|
|
307
|
+
await client.call("list_credentials", {});
|
|
308
308
|
expect(true).toBe(false);
|
|
309
309
|
} catch (err) {
|
|
310
310
|
expect(err).toBeInstanceOf(CesTransportError);
|
|
@@ -334,7 +334,7 @@ describe("CES client", () => {
|
|
|
334
334
|
await handshakePromise;
|
|
335
335
|
|
|
336
336
|
// Start a call that will never complete
|
|
337
|
-
const callPromise = client.call("
|
|
337
|
+
const callPromise = client.call("list_credentials", {});
|
|
338
338
|
|
|
339
339
|
// Close the client
|
|
340
340
|
client.close();
|