@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
|
@@ -1,449 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for the auto-analysis enqueue branch in `disposeConversation()`.
|
|
3
|
-
*
|
|
4
|
-
* `disposeConversation` fires two end-of-conversation enqueues for guardian
|
|
5
|
-
* conversations: the existing `graph_extract` job (memory extraction) and the
|
|
6
|
-
* new `conversation_analyze` job (auto-analysis loop, gated by the
|
|
7
|
-
* `auto-analyze` feature flag and source-type guard).
|
|
8
|
-
*
|
|
9
|
-
* We stub the downstream enqueue helpers and the side-effecting lifecycle
|
|
10
|
-
* deps (notifier/skill cleanup, browser-screencast) so the test can invoke
|
|
11
|
-
* `disposeConversation` with a minimal `DisposeContext` and assert on the
|
|
12
|
-
* enqueue bookkeeping alone.
|
|
13
|
-
*
|
|
14
|
-
* Two recursion guards apply when the source conversation is itself an
|
|
15
|
-
* auto-analysis conversation:
|
|
16
|
-
* 1. `enqueueAutoAnalysisIfEnabled` short-circuits internally,
|
|
17
|
-
* preventing the analyzer from analyzing its own output.
|
|
18
|
-
* 2. `disposeConversation` skips `graph_extract` directly via
|
|
19
|
-
* `isAutoAnalysisConversation()`, mirroring the guard the indexer
|
|
20
|
-
* applies on the per-message path. The analysis agent writes memory
|
|
21
|
-
* directly via tools, so extracting its reflective musings would
|
|
22
|
-
* double-write the graph.
|
|
23
|
-
* We stub both the helper and the guard so the test can simulate "flag
|
|
24
|
-
* enabled / flag disabled / source is auto-analysis" states.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
28
|
-
|
|
29
|
-
import { createMockLoggerModule } from "../../__tests__/helpers/mock-logger.js";
|
|
30
|
-
|
|
31
|
-
mock.module("../../util/logger.js", () => createMockLoggerModule());
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// Mock state — reset between tests.
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
const memoryJobCalls: Array<{
|
|
38
|
-
type: string;
|
|
39
|
-
payload: Record<string, unknown>;
|
|
40
|
-
}> = [];
|
|
41
|
-
const autoAnalyzeCalls: Array<{
|
|
42
|
-
conversationId: string;
|
|
43
|
-
trigger: "batch" | "idle" | "lifecycle";
|
|
44
|
-
}> = [];
|
|
45
|
-
|
|
46
|
-
// Simulates the helper's "flag off / recursion guard" behavior by no-op-ing
|
|
47
|
-
// when `autoAnalyzeEnabled` is false. When true, we record the call so the
|
|
48
|
-
// test can assert the trigger and conversation id.
|
|
49
|
-
let autoAnalyzeEnabled = true;
|
|
50
|
-
|
|
51
|
-
// Tracks whether the conversation under test should be treated as an
|
|
52
|
-
// auto-analysis source by `isAutoAnalysisConversation`. When true,
|
|
53
|
-
// `disposeConversation` must skip the `graph_extract` enqueue.
|
|
54
|
-
const autoAnalysisConversations = new Set<string>();
|
|
55
|
-
|
|
56
|
-
// Toggles the `memory.v2.enabled` flag the disposal code reads via
|
|
57
|
-
// `getConfig()`. Defaults to false so the bulk of the suite — which asserts
|
|
58
|
-
// v1 graph_extract still fires — keeps its semantics. The dedicated v2 cases
|
|
59
|
-
// flip this to true.
|
|
60
|
-
let v2Enabled = false;
|
|
61
|
-
|
|
62
|
-
const realLoader = await import("../../config/loader.js");
|
|
63
|
-
mock.module("../../config/loader.js", () => ({
|
|
64
|
-
...realLoader,
|
|
65
|
-
getConfig: () => ({ memory: { v2: { enabled: v2Enabled } } }),
|
|
66
|
-
loadConfig: () => ({ memory: { v2: { enabled: v2Enabled } } }),
|
|
67
|
-
}));
|
|
68
|
-
|
|
69
|
-
mock.module("../../runtime/services/auto-analysis-guard.js", () => ({
|
|
70
|
-
AUTO_ANALYSIS_SOURCE: "auto-analysis",
|
|
71
|
-
isAutoAnalysisConversation: (conversationId: string) =>
|
|
72
|
-
autoAnalysisConversations.has(conversationId),
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
const realJobsStore = await import("../../persistence/jobs-store.js");
|
|
76
|
-
mock.module("../../persistence/jobs-store.js", () => ({
|
|
77
|
-
...realJobsStore,
|
|
78
|
-
enqueueMemoryJob: (type: string, payload: Record<string, unknown>) => {
|
|
79
|
-
memoryJobCalls.push({ type, payload });
|
|
80
|
-
return "job-id";
|
|
81
|
-
},
|
|
82
|
-
}));
|
|
83
|
-
|
|
84
|
-
const realAutoAnalysisEnqueue =
|
|
85
|
-
await import("../../runtime/services/auto-analysis-enqueue.js");
|
|
86
|
-
mock.module("../../runtime/services/auto-analysis-enqueue.js", () => ({
|
|
87
|
-
...realAutoAnalysisEnqueue,
|
|
88
|
-
enqueueAutoAnalysisIfEnabled: (args: {
|
|
89
|
-
conversationId: string;
|
|
90
|
-
trigger: "batch" | "idle" | "lifecycle";
|
|
91
|
-
}) => {
|
|
92
|
-
if (!autoAnalyzeEnabled) return;
|
|
93
|
-
autoAnalyzeCalls.push(args);
|
|
94
|
-
},
|
|
95
|
-
}));
|
|
96
|
-
|
|
97
|
-
const memoryRetroCalls: Array<{
|
|
98
|
-
conversationId: string;
|
|
99
|
-
trigger: string;
|
|
100
|
-
}> = [];
|
|
101
|
-
|
|
102
|
-
mock.module(
|
|
103
|
-
"../../plugins/defaults/memory/memory-retrospective-enqueue.js",
|
|
104
|
-
() => ({
|
|
105
|
-
enqueueMemoryRetrospectiveIfEnabled: (args: {
|
|
106
|
-
conversationId: string;
|
|
107
|
-
trigger: string;
|
|
108
|
-
}) => {
|
|
109
|
-
memoryRetroCalls.push(args);
|
|
110
|
-
},
|
|
111
|
-
// Also export sibling functions other modules import from this file, so
|
|
112
|
-
// mocking it here doesn't break transitive imports loaded during the
|
|
113
|
-
// `disposeConversation` dynamic-import chain.
|
|
114
|
-
enqueueMemoryRetrospectiveOnCompaction: () => {},
|
|
115
|
-
isMemoryRetrospectiveConversation: (_id: string) => false,
|
|
116
|
-
}),
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// Stub all side-effecting cleanup helpers that disposeConversation chains
|
|
120
|
-
// into after the enqueue block. We assert on enqueue behavior only.
|
|
121
|
-
const realBrowserScreencast =
|
|
122
|
-
await import("../../tools/browser/browser-screencast.js");
|
|
123
|
-
mock.module("../../tools/browser/browser-screencast.js", () => ({
|
|
124
|
-
...realBrowserScreencast,
|
|
125
|
-
unregisterConversationSender: () => {},
|
|
126
|
-
}));
|
|
127
|
-
|
|
128
|
-
const realConversationNotifiers = await import("../conversation-notifiers.js");
|
|
129
|
-
mock.module("../conversation-notifiers.js", () => ({
|
|
130
|
-
...realConversationNotifiers,
|
|
131
|
-
unregisterCallNotifiers: () => {},
|
|
132
|
-
}));
|
|
133
|
-
|
|
134
|
-
const realConversationSkillTools =
|
|
135
|
-
await import("../conversation-skill-tools.js");
|
|
136
|
-
mock.module("../conversation-skill-tools.js", () => ({
|
|
137
|
-
...realConversationSkillTools,
|
|
138
|
-
resetSkillToolProjection: () => {},
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
// Dynamic import after mock.module calls so stubs take effect.
|
|
142
|
-
const { disposeConversation } = await import("../conversation-lifecycle.js");
|
|
143
|
-
type DisposeContext = import("../conversation-lifecycle.js").DisposeContext;
|
|
144
|
-
type TrustClass = import("../../runtime/actor-trust-resolver.js").TrustClass;
|
|
145
|
-
|
|
146
|
-
// ---------------------------------------------------------------------------
|
|
147
|
-
// Fixture builder — minimal DisposeContext satisfying the interface shape.
|
|
148
|
-
// ---------------------------------------------------------------------------
|
|
149
|
-
|
|
150
|
-
function makeDisposeContext(
|
|
151
|
-
overrides: {
|
|
152
|
-
conversationId?: string;
|
|
153
|
-
trustClass?: TrustClass;
|
|
154
|
-
} = {},
|
|
155
|
-
): DisposeContext {
|
|
156
|
-
const eventBus = { dispose: () => {} };
|
|
157
|
-
const profiler = { clear: () => {} };
|
|
158
|
-
const abortController = { abort: () => {} };
|
|
159
|
-
const queue = {
|
|
160
|
-
clear: () => {},
|
|
161
|
-
[Symbol.iterator]: function* () {
|
|
162
|
-
// empty queue — no queued messages to cancel during disposal.
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
const prompter = { dispose: () => {} };
|
|
166
|
-
const secretPrompter = { dispose: () => {} };
|
|
167
|
-
|
|
168
|
-
const ctx = {
|
|
169
|
-
conversationId: overrides.conversationId ?? "conv-1",
|
|
170
|
-
processing: false,
|
|
171
|
-
isProcessing(this: { processing: boolean }) {
|
|
172
|
-
return this.processing;
|
|
173
|
-
},
|
|
174
|
-
setProcessing(this: { processing: boolean }, value: boolean) {
|
|
175
|
-
this.processing = value;
|
|
176
|
-
},
|
|
177
|
-
abortController,
|
|
178
|
-
prompter,
|
|
179
|
-
secretPrompter,
|
|
180
|
-
pendingSurfaceActions: new Map(),
|
|
181
|
-
surfaceActionRequestIds: new Set<string>(),
|
|
182
|
-
surfaceState: new Map(),
|
|
183
|
-
accumulatedSurfaceState: new Map(),
|
|
184
|
-
queue,
|
|
185
|
-
eventBus,
|
|
186
|
-
skillProjectionState: new Map<string, string>(),
|
|
187
|
-
profiler,
|
|
188
|
-
messages: [],
|
|
189
|
-
surfaceUndoStacks: new Map<string, string[]>(),
|
|
190
|
-
currentTurnSurfaces: [] as Array<unknown>,
|
|
191
|
-
lastSurfaceAction: new Map<string, unknown>(),
|
|
192
|
-
workspaceTopLevelContext: null,
|
|
193
|
-
...(overrides.trustClass
|
|
194
|
-
? { trustContext: { trustClass: overrides.trustClass } }
|
|
195
|
-
: {}),
|
|
196
|
-
abort(): void {},
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
return ctx as unknown as DisposeContext;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ---------------------------------------------------------------------------
|
|
203
|
-
// Tests
|
|
204
|
-
// ---------------------------------------------------------------------------
|
|
205
|
-
|
|
206
|
-
describe("disposeConversation — auto-analysis enqueue", () => {
|
|
207
|
-
beforeEach(() => {
|
|
208
|
-
memoryJobCalls.length = 0;
|
|
209
|
-
autoAnalyzeCalls.length = 0;
|
|
210
|
-
memoryRetroCalls.length = 0;
|
|
211
|
-
autoAnalyzeEnabled = true;
|
|
212
|
-
autoAnalysisConversations.clear();
|
|
213
|
-
v2Enabled = false;
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
test("guardian conversation with auto-analyze ON — enqueues both graph_extract and conversation_analyze (via helper)", () => {
|
|
217
|
-
autoAnalyzeEnabled = true;
|
|
218
|
-
const ctx = makeDisposeContext({
|
|
219
|
-
conversationId: "conv-guardian",
|
|
220
|
-
trustClass: "guardian",
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
disposeConversation(ctx);
|
|
224
|
-
|
|
225
|
-
// graph_extract fires unchanged.
|
|
226
|
-
expect(memoryJobCalls).toHaveLength(1);
|
|
227
|
-
expect(memoryJobCalls[0]!.type).toBe("graph_extract");
|
|
228
|
-
expect(memoryJobCalls[0]!.payload).toMatchObject({
|
|
229
|
-
conversationId: "conv-guardian",
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// Auto-analysis helper is invoked with trigger "lifecycle".
|
|
233
|
-
expect(autoAnalyzeCalls).toHaveLength(1);
|
|
234
|
-
expect(autoAnalyzeCalls[0]).toEqual({
|
|
235
|
-
conversationId: "conv-guardian",
|
|
236
|
-
trigger: "lifecycle",
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
test("untrusted conversation — enqueues neither graph_extract nor conversation_analyze", () => {
|
|
241
|
-
// `unknown` is the trust class used for untrusted actors. The disposal
|
|
242
|
-
// code short-circuits when `resolveCapabilities(trustClass).canAccessMemory`
|
|
243
|
-
// is false, so neither enqueue path should fire. This preserves the
|
|
244
|
-
// memory trust boundary.
|
|
245
|
-
const ctx = makeDisposeContext({
|
|
246
|
-
conversationId: "conv-untrusted",
|
|
247
|
-
trustClass: "unknown",
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
disposeConversation(ctx);
|
|
251
|
-
|
|
252
|
-
expect(memoryJobCalls).toHaveLength(0);
|
|
253
|
-
expect(autoAnalyzeCalls).toHaveLength(0);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("auto-analysis conversation — neither graph_extract nor conversation_analyze is enqueued", () => {
|
|
257
|
-
// Two recursion guards apply when the source conversation is itself an
|
|
258
|
-
// auto-analysis conversation:
|
|
259
|
-
// 1. `disposeConversation` skips the `graph_extract` enqueue directly
|
|
260
|
-
// via `isAutoAnalysisConversation()` — mirroring the indexer's
|
|
261
|
-
// per-message guard. Without this, evicting an auto-analysis
|
|
262
|
-
// conversation from the LRU would double-write the memory graph
|
|
263
|
-
// because the analysis agent already writes memory via tools.
|
|
264
|
-
// 2. `enqueueAutoAnalysisIfEnabled` no-ops internally for
|
|
265
|
-
// auto-analysis conversations (its own recursion guard). We
|
|
266
|
-
// simulate that by flipping `autoAnalyzeEnabled` off.
|
|
267
|
-
autoAnalysisConversations.add("conv-auto");
|
|
268
|
-
autoAnalyzeEnabled = false;
|
|
269
|
-
const ctx = makeDisposeContext({
|
|
270
|
-
conversationId: "conv-auto",
|
|
271
|
-
trustClass: "guardian",
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
disposeConversation(ctx);
|
|
275
|
-
|
|
276
|
-
expect(memoryJobCalls).toHaveLength(0);
|
|
277
|
-
expect(autoAnalyzeCalls).toHaveLength(0);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
test("auto-analyze flag OFF — helper no-ops, so only graph_extract is enqueued", () => {
|
|
281
|
-
// When the `auto-analyze` feature flag is disabled, the helper returns
|
|
282
|
-
// early without enqueuing. We simulate that by flipping the shared flag.
|
|
283
|
-
autoAnalyzeEnabled = false;
|
|
284
|
-
const ctx = makeDisposeContext({
|
|
285
|
-
conversationId: "conv-flag-off",
|
|
286
|
-
trustClass: "guardian",
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
disposeConversation(ctx);
|
|
290
|
-
|
|
291
|
-
expect(memoryJobCalls).toHaveLength(1);
|
|
292
|
-
expect(memoryJobCalls[0]!.type).toBe("graph_extract");
|
|
293
|
-
expect(autoAnalyzeCalls).toHaveLength(0);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
test("isAutoAnalysisConversation throws — fails open, still enqueues graph_extract and continues disposal", () => {
|
|
297
|
-
// If the DB read inside `isAutoAnalysisConversation` throws (e.g. SQLite
|
|
298
|
-
// unavailable during teardown), disposal must not abort. We fail open:
|
|
299
|
-
// default to NOT skipping, so graph_extract still fires and the rest of
|
|
300
|
-
// the cleanup chain runs.
|
|
301
|
-
autoAnalyzeEnabled = true;
|
|
302
|
-
|
|
303
|
-
mock.module("../../runtime/services/auto-analysis-guard.js", () => ({
|
|
304
|
-
AUTO_ANALYSIS_SOURCE: "auto-analysis",
|
|
305
|
-
isAutoAnalysisConversation: () => {
|
|
306
|
-
throw new Error("db closed");
|
|
307
|
-
},
|
|
308
|
-
}));
|
|
309
|
-
|
|
310
|
-
const ctx = makeDisposeContext({
|
|
311
|
-
conversationId: "conv-guard-throws",
|
|
312
|
-
trustClass: "guardian",
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
expect(() => disposeConversation(ctx)).not.toThrow();
|
|
316
|
-
|
|
317
|
-
// Fail-open: graph_extract fires even though the guard threw.
|
|
318
|
-
expect(memoryJobCalls).toHaveLength(1);
|
|
319
|
-
expect(memoryJobCalls[0]!.type).toBe("graph_extract");
|
|
320
|
-
// The auto-analyze helper also still runs (separate try/catch).
|
|
321
|
-
expect(autoAnalyzeCalls).toHaveLength(1);
|
|
322
|
-
|
|
323
|
-
// Restore the non-throwing stub for subsequent tests.
|
|
324
|
-
mock.module("../../runtime/services/auto-analysis-guard.js", () => ({
|
|
325
|
-
AUTO_ANALYSIS_SOURCE: "auto-analysis",
|
|
326
|
-
isAutoAnalysisConversation: (conversationId: string) =>
|
|
327
|
-
autoAnalysisConversations.has(conversationId),
|
|
328
|
-
}));
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test("helper throws — disposal continues (best-effort semantics)", () => {
|
|
332
|
-
// The try/catch around `enqueueAutoAnalysisIfEnabled` must swallow
|
|
333
|
-
// errors so a broken helper never blocks disposal. We verify by
|
|
334
|
-
// swapping in a throwing stub for a single call and confirming
|
|
335
|
-
// disposeConversation itself does not throw.
|
|
336
|
-
const originalEnabled = autoAnalyzeEnabled;
|
|
337
|
-
autoAnalyzeEnabled = true;
|
|
338
|
-
|
|
339
|
-
// Temporarily re-mock the helper to throw.
|
|
340
|
-
mock.module("../../runtime/services/auto-analysis-enqueue.js", () => ({
|
|
341
|
-
enqueueAutoAnalysisIfEnabled: () => {
|
|
342
|
-
throw new Error("boom");
|
|
343
|
-
},
|
|
344
|
-
}));
|
|
345
|
-
|
|
346
|
-
const ctx = makeDisposeContext({
|
|
347
|
-
conversationId: "conv-throw",
|
|
348
|
-
trustClass: "guardian",
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
expect(() => disposeConversation(ctx)).not.toThrow();
|
|
352
|
-
|
|
353
|
-
// graph_extract still fired before the throw.
|
|
354
|
-
expect(memoryJobCalls).toHaveLength(1);
|
|
355
|
-
|
|
356
|
-
// Restore the non-throwing stub so other tests aren't affected.
|
|
357
|
-
mock.module("../../runtime/services/auto-analysis-enqueue.js", () => ({
|
|
358
|
-
enqueueAutoAnalysisIfEnabled: (args: {
|
|
359
|
-
conversationId: string;
|
|
360
|
-
trigger: "batch" | "idle" | "lifecycle";
|
|
361
|
-
}) => {
|
|
362
|
-
if (!autoAnalyzeEnabled) return;
|
|
363
|
-
autoAnalyzeCalls.push(args);
|
|
364
|
-
},
|
|
365
|
-
}));
|
|
366
|
-
autoAnalyzeEnabled = originalEnabled;
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
test("memory v2 enabled — graph_extract enqueue is suppressed (auto-analysis still runs)", () => {
|
|
370
|
-
// Under memory v2, the v1 graph has no readers (retrieval is bypassed at
|
|
371
|
-
// conversation-graph-memory.ts), so producing extraction jobs just fills
|
|
372
|
-
// the queue with stale work. Auto-analysis is orthogonal and must keep
|
|
373
|
-
// running.
|
|
374
|
-
v2Enabled = true;
|
|
375
|
-
const ctx = makeDisposeContext({
|
|
376
|
-
conversationId: "conv-v2-on",
|
|
377
|
-
trustClass: "guardian",
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
disposeConversation(ctx);
|
|
381
|
-
|
|
382
|
-
expect(memoryJobCalls).toHaveLength(0);
|
|
383
|
-
expect(autoAnalyzeCalls).toHaveLength(1);
|
|
384
|
-
expect(autoAnalyzeCalls[0]).toEqual({
|
|
385
|
-
conversationId: "conv-v2-on",
|
|
386
|
-
trigger: "lifecycle",
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
describe("disposeConversation — memory-retrospective lifecycle safety net", () => {
|
|
392
|
-
beforeEach(() => {
|
|
393
|
-
memoryJobCalls.length = 0;
|
|
394
|
-
autoAnalyzeCalls.length = 0;
|
|
395
|
-
memoryRetroCalls.length = 0;
|
|
396
|
-
autoAnalyzeEnabled = false;
|
|
397
|
-
autoAnalysisConversations.clear();
|
|
398
|
-
v2Enabled = false;
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
test("guardian conversation — enqueues memory-retrospective with trigger 'lifecycle'", () => {
|
|
402
|
-
const ctx = makeDisposeContext({
|
|
403
|
-
conversationId: "conv-retro",
|
|
404
|
-
trustClass: "guardian",
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
disposeConversation(ctx);
|
|
408
|
-
|
|
409
|
-
expect(memoryRetroCalls).toHaveLength(1);
|
|
410
|
-
expect(memoryRetroCalls[0]).toEqual({
|
|
411
|
-
conversationId: "conv-retro",
|
|
412
|
-
trigger: "lifecycle",
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
test("untrusted actor — no memory-retrospective enqueue", () => {
|
|
417
|
-
const ctx = makeDisposeContext({
|
|
418
|
-
conversationId: "conv-retro-untrusted",
|
|
419
|
-
trustClass: "unknown",
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
disposeConversation(ctx);
|
|
423
|
-
|
|
424
|
-
// The outer trust-class guard in disposeConversation gates ALL three
|
|
425
|
-
// enqueues (graph_extract, auto-analyze, memory-retrospective). When
|
|
426
|
-
// the actor is untrusted, none of them fire.
|
|
427
|
-
expect(memoryRetroCalls).toHaveLength(0);
|
|
428
|
-
expect(autoAnalyzeCalls).toHaveLength(0);
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
// Regression test: the retrospective lifecycle enqueue was previously
|
|
432
|
-
// outside the `!isAutoAnalysis` guard, so it fired even for auto-analysis
|
|
433
|
-
// conversations. Mirrors the indexer-time gate in `indexer.ts` and
|
|
434
|
-
// matches the existing graph_extract recursion-guard semantics.
|
|
435
|
-
test("auto-analysis conversation — does NOT enqueue memory-retrospective", () => {
|
|
436
|
-
autoAnalysisConversations.add("conv-auto-retro");
|
|
437
|
-
const ctx = makeDisposeContext({
|
|
438
|
-
conversationId: "conv-auto-retro",
|
|
439
|
-
trustClass: "guardian",
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
disposeConversation(ctx);
|
|
443
|
-
|
|
444
|
-
expect(memoryRetroCalls).toHaveLength(0);
|
|
445
|
-
// graph_extract is also recursion-guarded by the same `!isAutoAnalysis`
|
|
446
|
-
// block, so it should be skipped here too.
|
|
447
|
-
expect(memoryJobCalls).toHaveLength(0);
|
|
448
|
-
});
|
|
449
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { eq } from "drizzle-orm";
|
|
4
|
-
|
|
5
|
-
mock.module("../../../../util/logger.js", () => ({
|
|
6
|
-
getLogger: () =>
|
|
7
|
-
new Proxy({} as Record<string, unknown>, {
|
|
8
|
-
get: () => () => {},
|
|
9
|
-
}),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
createConversation,
|
|
14
|
-
findAnalysisConversationFor,
|
|
15
|
-
getConversationSource,
|
|
16
|
-
} from "../../../../persistence/conversation-crud.js";
|
|
17
|
-
import { getDb } from "../../../../persistence/db-connection.js";
|
|
18
|
-
import { initializeDb } from "../../../../persistence/db-init.js";
|
|
19
|
-
import { conversations } from "../../../../persistence/schema/index.js";
|
|
20
|
-
|
|
21
|
-
await initializeDb();
|
|
22
|
-
|
|
23
|
-
function resetTables(): void {
|
|
24
|
-
const db = getDb();
|
|
25
|
-
db.run(`DELETE FROM messages`);
|
|
26
|
-
db.run(`DELETE FROM conversations`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function setForkParent(conversationId: string, parentId: string): void {
|
|
30
|
-
const db = getDb();
|
|
31
|
-
db.update(conversations)
|
|
32
|
-
.set({ forkParentConversationId: parentId })
|
|
33
|
-
.where(eq(conversations.id, conversationId))
|
|
34
|
-
.run();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function setUpdatedAt(conversationId: string, updatedAt: number): void {
|
|
38
|
-
const db = getDb();
|
|
39
|
-
db.update(conversations)
|
|
40
|
-
.set({ updatedAt })
|
|
41
|
-
.where(eq(conversations.id, conversationId))
|
|
42
|
-
.run();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe("findAnalysisConversationFor", () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
resetTables();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("returns null when no analysis conversation exists for the parent", () => {
|
|
51
|
-
const parent = createConversation("parent");
|
|
52
|
-
expect(findAnalysisConversationFor(parent.id)).toBeNull();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("returns null when an unrelated analysis conversation exists", () => {
|
|
56
|
-
const parent = createConversation("parent");
|
|
57
|
-
const other = createConversation("other");
|
|
58
|
-
const analysisForOther = createConversation({
|
|
59
|
-
title: "analysis of other",
|
|
60
|
-
source: "auto-analysis",
|
|
61
|
-
});
|
|
62
|
-
setForkParent(analysisForOther.id, other.id);
|
|
63
|
-
|
|
64
|
-
expect(findAnalysisConversationFor(parent.id)).toBeNull();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("returns the only matching analysis conversation when one exists", () => {
|
|
68
|
-
const parent = createConversation("parent");
|
|
69
|
-
const analysis = createConversation({
|
|
70
|
-
title: "rolling analysis",
|
|
71
|
-
source: "auto-analysis",
|
|
72
|
-
});
|
|
73
|
-
setForkParent(analysis.id, parent.id);
|
|
74
|
-
|
|
75
|
-
expect(findAnalysisConversationFor(parent.id)).toEqual({ id: analysis.id });
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("when multiple match, returns the most recently updated one", () => {
|
|
79
|
-
const parent = createConversation("parent");
|
|
80
|
-
|
|
81
|
-
const older = createConversation({
|
|
82
|
-
title: "older analysis",
|
|
83
|
-
source: "auto-analysis",
|
|
84
|
-
});
|
|
85
|
-
setForkParent(older.id, parent.id);
|
|
86
|
-
setUpdatedAt(older.id, 1_000);
|
|
87
|
-
|
|
88
|
-
const newer = createConversation({
|
|
89
|
-
title: "newer analysis",
|
|
90
|
-
source: "auto-analysis",
|
|
91
|
-
});
|
|
92
|
-
setForkParent(newer.id, parent.id);
|
|
93
|
-
setUpdatedAt(newer.id, 2_000);
|
|
94
|
-
|
|
95
|
-
const middle = createConversation({
|
|
96
|
-
title: "middle analysis",
|
|
97
|
-
source: "auto-analysis",
|
|
98
|
-
});
|
|
99
|
-
setForkParent(middle.id, parent.id);
|
|
100
|
-
setUpdatedAt(middle.id, 1_500);
|
|
101
|
-
|
|
102
|
-
expect(findAnalysisConversationFor(parent.id)).toEqual({ id: newer.id });
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test("does not return regular user conversations whose forkParentConversationId matches", () => {
|
|
106
|
-
const parent = createConversation("parent");
|
|
107
|
-
|
|
108
|
-
// A regular user-forked conversation (source defaults to "user").
|
|
109
|
-
const userFork = createConversation("user fork");
|
|
110
|
-
setForkParent(userFork.id, parent.id);
|
|
111
|
-
|
|
112
|
-
expect(findAnalysisConversationFor(parent.id)).toBeNull();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("ignores user forks even when an analysis conversation also exists", () => {
|
|
116
|
-
const parent = createConversation("parent");
|
|
117
|
-
|
|
118
|
-
const userFork = createConversation("user fork");
|
|
119
|
-
setForkParent(userFork.id, parent.id);
|
|
120
|
-
// Force the user fork to have the most recent updatedAt — it should
|
|
121
|
-
// still be ignored because its source is "user".
|
|
122
|
-
setUpdatedAt(userFork.id, 9_999);
|
|
123
|
-
|
|
124
|
-
const analysis = createConversation({
|
|
125
|
-
title: "analysis",
|
|
126
|
-
source: "auto-analysis",
|
|
127
|
-
});
|
|
128
|
-
setForkParent(analysis.id, parent.id);
|
|
129
|
-
setUpdatedAt(analysis.id, 1_000);
|
|
130
|
-
|
|
131
|
-
expect(findAnalysisConversationFor(parent.id)).toEqual({ id: analysis.id });
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test("createConversation persists forkParentConversationId when supplied", () => {
|
|
135
|
-
const parent = createConversation("parent");
|
|
136
|
-
|
|
137
|
-
// Auto-analyze path creates the rolling analysis conversation with
|
|
138
|
-
// source + forkParentConversationId in the same call.
|
|
139
|
-
const analysis = createConversation({
|
|
140
|
-
title: "rolling analysis",
|
|
141
|
-
source: "auto-analysis",
|
|
142
|
-
forkParentConversationId: parent.id,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
expect(findAnalysisConversationFor(parent.id)).toEqual({ id: analysis.id });
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test("finds rolling analysis conversation regardless of group_id (backward-compat across the dedicated-group migration)", () => {
|
|
149
|
-
const parent = createConversation("parent");
|
|
150
|
-
|
|
151
|
-
const legacyAnalysis = createConversation({
|
|
152
|
-
title: "legacy rolling analysis",
|
|
153
|
-
source: "auto-analysis",
|
|
154
|
-
forkParentConversationId: parent.id,
|
|
155
|
-
});
|
|
156
|
-
setUpdatedAt(legacyAnalysis.id, 1_000);
|
|
157
|
-
|
|
158
|
-
expect(findAnalysisConversationFor(parent.id)).toEqual({
|
|
159
|
-
id: legacyAnalysis.id,
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const newAnalysis = createConversation({
|
|
163
|
-
title: "new rolling analysis",
|
|
164
|
-
source: "auto-analysis",
|
|
165
|
-
groupId: "system:background",
|
|
166
|
-
forkParentConversationId: parent.id,
|
|
167
|
-
});
|
|
168
|
-
setUpdatedAt(newAnalysis.id, 2_000);
|
|
169
|
-
|
|
170
|
-
expect(findAnalysisConversationFor(parent.id)).toEqual({
|
|
171
|
-
id: newAnalysis.id,
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe("getConversationSource", () => {
|
|
177
|
-
beforeEach(() => {
|
|
178
|
-
resetTables();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test("returns the source string for an existing conversation", () => {
|
|
182
|
-
const conv = createConversation("user conv");
|
|
183
|
-
expect(getConversationSource(conv.id)).toBe("user");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test("returns the custom source for an analysis conversation", () => {
|
|
187
|
-
const conv = createConversation({
|
|
188
|
-
title: "analysis",
|
|
189
|
-
source: "auto-analysis",
|
|
190
|
-
});
|
|
191
|
-
expect(getConversationSource(conv.id)).toBe("auto-analysis");
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test("returns null for a non-existent conversation ID", () => {
|
|
195
|
-
expect(getConversationSource("does-not-exist")).toBeNull();
|
|
196
|
-
});
|
|
197
|
-
});
|