@vellumai/assistant 0.10.3-dev.202606300917.a9da5f8 → 0.10.3-dev.202606301252.4a9d173
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/package.json +1 -1
- package/src/__tests__/background-workers-disk-pressure.test.ts +2 -1
- package/src/__tests__/conversation-fork-crud.test.ts +3 -0
- package/src/__tests__/conversation-fork-retrospective.test.ts +2 -0
- package/src/__tests__/conversation-wipe.test.ts +2 -0
- package/src/__tests__/credential-security-invariants.test.ts +0 -2
- package/src/__tests__/filing-service.test.ts +2 -1
- package/src/__tests__/job-handler-registry-guard.test.ts +21 -0
- package/src/__tests__/persistence-layering-guard.test.ts +1 -11
- package/src/__tests__/plugin-bootstrap.test.ts +4 -1
- package/src/__tests__/plugin-disabled-state.test.ts +64 -0
- package/src/__tests__/plugin-import-boundary-guard.test.ts +4 -0
- package/src/__tests__/schedule-retry.test.ts +38 -14
- package/src/__tests__/scheduler-disk-pressure.test.ts +17 -6
- package/src/__tests__/scheduler-recurrence.test.ts +57 -107
- package/src/__tests__/scheduler-reuse-conversation.test.ts +51 -46
- package/src/__tests__/scheduler-wake.test.ts +13 -23
- package/src/__tests__/task-scheduler.test.ts +68 -89
- package/src/background-wake/wake-intent-hooks.test.ts +13 -7
- package/src/config/schemas/services.ts +0 -37
- package/src/daemon/external-plugins-bootstrap.ts +7 -0
- package/src/daemon/lifecycle.ts +2 -100
- package/src/daemon/providers-setup.ts +0 -14
- package/src/daemon/shutdown-handlers.ts +3 -7
- package/src/jobs/register-job-handlers.ts +10 -1
- package/src/persistence/conversation-crud.ts +27 -113
- package/src/persistence/conversation-row-batch-delete.ts +8 -1
- package/src/persistence/jobs-worker.ts +2 -2
- package/src/persistence/memory-lifecycle-hooks.test.ts +81 -0
- package/src/persistence/memory-lifecycle-hooks.ts +120 -0
- package/src/plugins/defaults/index.ts +64 -0
- package/src/{filing → plugins/defaults/memory}/filing-service.ts +8 -27
- package/src/plugins/defaults/memory/hooks/init.ts +26 -0
- package/src/plugins/defaults/memory/hooks/shutdown.ts +14 -0
- package/src/plugins/defaults/memory/persistence-hooks.ts +119 -0
- package/src/runtime/routes/filing-routes.ts +1 -1
- package/src/schedule/scheduler.ts +129 -65
- package/src/daemon/__tests__/meet-host-supervisor.test.ts +0 -584
- package/src/daemon/__tests__/meet-manifest-loader.test.ts +0 -476
- package/src/daemon/meet-host-startup.ts +0 -51
- package/src/daemon/meet-host-supervisor.ts +0 -755
- package/src/daemon/meet-manifest-loader.ts +0 -396
- package/src/ipc/__tests__/skill-server-bidirectional.test.ts +0 -253
- package/src/ipc/__tests__/skill-server.test.ts +0 -182
- package/src/ipc/skill-ipc-types.ts +0 -54
- package/src/ipc/skill-routes/__tests__/config.test.ts +0 -146
- package/src/ipc/skill-routes/__tests__/events-ipc.test.ts +0 -448
- package/src/ipc/skill-routes/__tests__/identity.test.ts +0 -62
- package/src/ipc/skill-routes/__tests__/log.test.ts +0 -133
- package/src/ipc/skill-routes/__tests__/memory.test.ts +0 -203
- package/src/ipc/skill-routes/__tests__/platform.test.ts +0 -111
- package/src/ipc/skill-routes/__tests__/providers.test.ts +0 -265
- package/src/ipc/skill-routes/__tests__/registries.test.ts +0 -400
- package/src/ipc/skill-routes/config.ts +0 -47
- package/src/ipc/skill-routes/events.ts +0 -147
- package/src/ipc/skill-routes/identity.ts +0 -21
- package/src/ipc/skill-routes/index.ts +0 -37
- package/src/ipc/skill-routes/log.ts +0 -40
- package/src/ipc/skill-routes/memory.ts +0 -92
- package/src/ipc/skill-routes/platform.ts +0 -39
- package/src/ipc/skill-routes/providers.ts +0 -162
- package/src/ipc/skill-routes/registries.ts +0 -340
- package/src/ipc/skill-server.ts +0 -831
- package/src/ipc/skill-socket-path.ts +0 -20
package/package.json
CHANGED
|
@@ -213,7 +213,8 @@ mock.module("../persistence/cleanup-schedule-state.js", () => ({
|
|
|
213
213
|
}));
|
|
214
214
|
|
|
215
215
|
const { runMemoryJobsOnce } = await import("../persistence/jobs-worker.js");
|
|
216
|
-
const { FilingService } =
|
|
216
|
+
const { FilingService } =
|
|
217
|
+
await import("../plugins/defaults/memory/filing-service.js");
|
|
217
218
|
const { WorkspaceHeartbeatService } =
|
|
218
219
|
await import("../workspace/heartbeat-service.js");
|
|
219
220
|
|
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
memoryRetrospectiveState,
|
|
56
56
|
toolInvocations,
|
|
57
57
|
} from "../persistence/schema/index.js";
|
|
58
|
+
import { registerDefaultPluginPersistenceHooks } from "../plugins/defaults/index.js";
|
|
58
59
|
import {
|
|
59
60
|
loadGraphMemoryState,
|
|
60
61
|
saveGraphMemoryState,
|
|
@@ -100,6 +101,7 @@ function parseMetadata(metadata: string | null): unknown {
|
|
|
100
101
|
describe("forkConversation", () => {
|
|
101
102
|
beforeEach(() => {
|
|
102
103
|
resetTables();
|
|
104
|
+
registerDefaultPluginPersistenceHooks();
|
|
103
105
|
});
|
|
104
106
|
|
|
105
107
|
test("forks a full transcript with copied history and lineage", async () => {
|
|
@@ -1391,6 +1393,7 @@ describe("forkConversation", () => {
|
|
|
1391
1393
|
describe("forkConversation + memory_retrospective_state", () => {
|
|
1392
1394
|
beforeEach(() => {
|
|
1393
1395
|
resetTables();
|
|
1396
|
+
registerDefaultPluginPersistenceHooks();
|
|
1394
1397
|
});
|
|
1395
1398
|
|
|
1396
1399
|
test("does not seed state when the source has none", async () => {
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
memoryRetrospectiveState,
|
|
51
51
|
toolInvocations,
|
|
52
52
|
} from "../persistence/schema/index.js";
|
|
53
|
+
import { registerDefaultPluginPersistenceHooks } from "../plugins/defaults/index.js";
|
|
53
54
|
import {
|
|
54
55
|
loadGraphMemoryState,
|
|
55
56
|
saveGraphMemoryState,
|
|
@@ -110,6 +111,7 @@ async function seedSource(title: string): Promise<{ id: string }> {
|
|
|
110
111
|
describe("forkConversationForRetrospective", () => {
|
|
111
112
|
beforeEach(() => {
|
|
112
113
|
resetTables();
|
|
114
|
+
registerDefaultPluginPersistenceHooks();
|
|
113
115
|
});
|
|
114
116
|
|
|
115
117
|
test("full fork is row-identical to the synchronous fork", async () => {
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
import { getDb, getLogsDb, getMemoryDb } from "../persistence/db-connection.js";
|
|
18
18
|
import { initializeDb } from "../persistence/db-init.js";
|
|
19
19
|
import { enqueueMemoryJob } from "../persistence/jobs-store.js";
|
|
20
|
+
import { registerDefaultPluginPersistenceHooks } from "../plugins/defaults/index.js";
|
|
20
21
|
|
|
21
22
|
// Initialize db once before all tests
|
|
22
23
|
await initializeDb();
|
|
@@ -34,6 +35,7 @@ describe("wipeConversation", () => {
|
|
|
34
35
|
getLogsDb()!.run(`DELETE FROM llm_request_logs`);
|
|
35
36
|
db.run(`DELETE FROM messages`);
|
|
36
37
|
db.run(`DELETE FROM conversations`);
|
|
38
|
+
registerDefaultPluginPersistenceHooks();
|
|
37
39
|
});
|
|
38
40
|
|
|
39
41
|
test("wipes conversation and all messages", async () => {
|
|
@@ -221,13 +221,11 @@ describe("Invariant 2: no generic plaintext secret read API", () => {
|
|
|
221
221
|
"runtime/routes/credential-routes.ts", // CLI credential management routes (CLI-migrated to IPC)
|
|
222
222
|
"runtime/routes/sanity-routes.ts", // Sanity connect/discover routes (reads stored api_token from credential store)
|
|
223
223
|
"runtime/routes/platform-routes.ts", // CLI platform connect/disconnect/status routes (CLI-migrated to IPC)
|
|
224
|
-
"ipc/skill-routes/providers.ts", // host.providers.secureKeys.getProviderKey IPC route (out-of-process SkillHost companion)
|
|
225
224
|
"inbound/platform-callback-registration.ts", // managed credential lookup for platform base URL, assistant ID, and API key
|
|
226
225
|
"tts/providers/elevenlabs-provider.ts", // ElevenLabs TTS API key lookup
|
|
227
226
|
"tts/providers/deepgram-provider.ts", // Deepgram TTS API key lookup
|
|
228
227
|
"tts/providers/xai-provider.ts", // xAI TTS API key lookup
|
|
229
228
|
"credential-health/credential-health-service.ts", // credential health check reads access tokens for liveness pings
|
|
230
|
-
"ipc/skill-routes/providers.ts", // skill IPC route exposes provider key lookup to hosted skills
|
|
231
229
|
"runtime/routes/avatar-routes.ts", // avatar generate route reads platform_base_url from credential store
|
|
232
230
|
"cli/commands/keys.ts", // CLI provider key management
|
|
233
231
|
"cli/commands/oauth/connect.ts", // CLI OAuth connect stored-secret verification
|
|
@@ -132,7 +132,8 @@ function setTestProcessMessage(
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// Import after mocks are set up
|
|
135
|
-
const { FilingService } =
|
|
135
|
+
const { FilingService } =
|
|
136
|
+
await import("../plugins/defaults/memory/filing-service.js");
|
|
136
137
|
|
|
137
138
|
describe("FilingService", () => {
|
|
138
139
|
let processMessageCalls: Array<{
|
|
@@ -2,6 +2,10 @@ import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
|
|
|
2
2
|
|
|
3
3
|
import { registerMemoryJobHandlers } from "../jobs/register-job-handlers.js";
|
|
4
4
|
import * as jobsWorker from "../persistence/jobs-worker.js";
|
|
5
|
+
import {
|
|
6
|
+
getMemoryPersistenceHooks,
|
|
7
|
+
resetMemoryPersistenceHooksForTests,
|
|
8
|
+
} from "../persistence/memory-lifecycle-hooks.js";
|
|
5
9
|
import { registerDefaultPluginJobHandlers } from "../plugins/defaults/index.js";
|
|
6
10
|
import {
|
|
7
11
|
clearJobHandlerRegistry,
|
|
@@ -61,6 +65,7 @@ describe("job-handler registry — memory plugin contribution", () => {
|
|
|
61
65
|
});
|
|
62
66
|
afterEach(() => {
|
|
63
67
|
clearJobHandlerRegistry();
|
|
68
|
+
resetMemoryPersistenceHooksForTests();
|
|
64
69
|
});
|
|
65
70
|
|
|
66
71
|
it("default-memory contributes exactly the memory job types", () => {
|
|
@@ -91,6 +96,22 @@ describe("job-handler registry — memory plugin contribution", () => {
|
|
|
91
96
|
expect(new Set(captured).size).toBe(captured.length);
|
|
92
97
|
});
|
|
93
98
|
|
|
99
|
+
it("registerMemoryJobHandlers also wires the persistence-lifecycle seam (the standalone worker has no bootstrap)", () => {
|
|
100
|
+
resetMemoryPersistenceHooksForTests();
|
|
101
|
+
const before = getMemoryPersistenceHooks();
|
|
102
|
+
const spy = spyOn(jobsWorker, "registerJobHandler").mockImplementation(
|
|
103
|
+
() => {},
|
|
104
|
+
);
|
|
105
|
+
try {
|
|
106
|
+
registerMemoryJobHandlers();
|
|
107
|
+
} finally {
|
|
108
|
+
spy.mockRestore();
|
|
109
|
+
}
|
|
110
|
+
// The seam must move off the no-op default — otherwise the standalone
|
|
111
|
+
// worker's fork-based retrospectives silently drop carried memory state.
|
|
112
|
+
expect(getMemoryPersistenceHooks()).not.toBe(before);
|
|
113
|
+
});
|
|
114
|
+
|
|
94
115
|
it("rejects a duplicate job-handler type across plugins", () => {
|
|
95
116
|
registerPluginJobHandlers("plugin-a", [
|
|
96
117
|
{ type: "graph_extract", handler: () => undefined },
|
|
@@ -53,19 +53,9 @@ const MEMORY_DIR = join(ASSISTANT_SRC, "plugins", "defaults", "memory");
|
|
|
53
53
|
*/
|
|
54
54
|
const PERSISTENCE_TO_MEMORY_ALLOWLIST: Record<string, ReadonlySet<string>> = {
|
|
55
55
|
"assistant/src/persistence/conversation-crud.ts": new Set([
|
|
56
|
-
"graph/graph-memory-state-store",
|
|
57
|
-
"indexer",
|
|
58
56
|
"memory-retrospective-constants",
|
|
59
|
-
"memory-retrospective-state",
|
|
60
|
-
"task-memory-cleanup",
|
|
61
|
-
"v2/activation-store",
|
|
62
|
-
"v2/injected-block-slugs",
|
|
63
|
-
"v3/ever-injected-store",
|
|
64
|
-
]),
|
|
65
|
-
"assistant/src/persistence/jobs-worker.ts": new Set([
|
|
66
|
-
"memory-retrospective-startup-cleanup",
|
|
67
|
-
"v2/consolidation-job",
|
|
68
57
|
]),
|
|
58
|
+
"assistant/src/persistence/jobs-worker.ts": new Set(["v2/consolidation-job"]),
|
|
69
59
|
"assistant/src/persistence/steps.ts": new Set(["graph/bootstrap"]),
|
|
70
60
|
};
|
|
71
61
|
|
|
@@ -504,9 +504,12 @@ describe("plugin bootstrap", () => {
|
|
|
504
504
|
const names = getRegisteredPlugins().map((p) => p.manifest.name);
|
|
505
505
|
expect(names).toContain("sentinel-off");
|
|
506
506
|
// But its hooks are filtered out at read time by `isPluginDisabled`.
|
|
507
|
+
// Enabled default plugins (e.g. default-memory) contribute their own init
|
|
508
|
+
// hook, so assert specifically that the disabled plugin's hook is absent
|
|
509
|
+
// rather than that the list is empty.
|
|
507
510
|
const { getHooksFor } = await import("../hooks/registry.js");
|
|
508
511
|
const hooks = await getHooksFor("init");
|
|
509
|
-
expect(hooks).
|
|
512
|
+
expect(hooks).not.toContain(plugin.hooks?.init);
|
|
510
513
|
|
|
511
514
|
await rm(sentinelDir, { recursive: true, force: true });
|
|
512
515
|
});
|
|
@@ -17,6 +17,8 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
|
17
17
|
|
|
18
18
|
import { getHooksFor } from "../hooks/registry.js";
|
|
19
19
|
import { RiskLevel } from "../permissions/types.js";
|
|
20
|
+
import type { MessagePersistedEvent } from "../persistence/memory-lifecycle-hooks.js";
|
|
21
|
+
import { guardPersistenceHooksByDisabledState } from "../plugins/defaults/index.js";
|
|
20
22
|
import {
|
|
21
23
|
clearInjectorRegistry,
|
|
22
24
|
getRegisteredInjectors,
|
|
@@ -256,4 +258,66 @@ describe("per-surface disabled-state filtering", () => {
|
|
|
256
258
|
hooks = await getHooksFor("user-prompt-submit");
|
|
257
259
|
expect(hooks).toHaveLength(0);
|
|
258
260
|
});
|
|
261
|
+
|
|
262
|
+
test("persistence hooks no-op while the memory plugin is disabled", async () => {
|
|
263
|
+
let calls = 0;
|
|
264
|
+
const guarded = guardPersistenceHooksByDisabledState("default-memory", {
|
|
265
|
+
onMessagePersisted() {
|
|
266
|
+
calls++;
|
|
267
|
+
},
|
|
268
|
+
onConversationForked() {},
|
|
269
|
+
onConversationWiped() {
|
|
270
|
+
return 0;
|
|
271
|
+
},
|
|
272
|
+
onWorkerStartup() {},
|
|
273
|
+
});
|
|
274
|
+
const event: MessagePersistedEvent = {
|
|
275
|
+
messageId: "msg-1",
|
|
276
|
+
conversationId: "conv-1",
|
|
277
|
+
role: "user",
|
|
278
|
+
content: "[]",
|
|
279
|
+
createdAt: 0,
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// Enabled: the wrapped handler runs.
|
|
283
|
+
await guarded.onMessagePersisted(event);
|
|
284
|
+
expect(calls).toBe(1);
|
|
285
|
+
|
|
286
|
+
// Disable via sentinel — checked at call time, no restart needed.
|
|
287
|
+
await createSentinel("default-memory");
|
|
288
|
+
await guarded.onMessagePersisted(event);
|
|
289
|
+
expect(calls).toBe(1);
|
|
290
|
+
|
|
291
|
+
// Re-enable.
|
|
292
|
+
await removeSentinel("default-memory");
|
|
293
|
+
await guarded.onMessagePersisted(event);
|
|
294
|
+
expect(calls).toBe(2);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("cleanup persistence hooks run even while the memory plugin is disabled", async () => {
|
|
298
|
+
let wiped = 0;
|
|
299
|
+
let swept = 0;
|
|
300
|
+
const guarded = guardPersistenceHooksByDisabledState("default-memory", {
|
|
301
|
+
onMessagePersisted() {},
|
|
302
|
+
onConversationForked() {},
|
|
303
|
+
onConversationWiped() {
|
|
304
|
+
wiped++;
|
|
305
|
+
return 7;
|
|
306
|
+
},
|
|
307
|
+
onWorkerStartup() {
|
|
308
|
+
swept++;
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
await createSentinel("default-memory");
|
|
313
|
+
|
|
314
|
+
// Cleanup hooks are NOT gated: they must still run (and return real values)
|
|
315
|
+
// while disabled, or state created while enabled would be orphaned.
|
|
316
|
+
expect(guarded.onConversationWiped("conv-1")).toBe(7);
|
|
317
|
+
guarded.onWorkerStartup();
|
|
318
|
+
expect(wiped).toBe(1);
|
|
319
|
+
expect(swept).toBe(1);
|
|
320
|
+
|
|
321
|
+
await removeSentinel("default-memory");
|
|
322
|
+
});
|
|
259
323
|
});
|
|
@@ -166,6 +166,7 @@ const BASELINE: Record<string, readonly string[]> = {
|
|
|
166
166
|
"../../../context/strip-injections.js",
|
|
167
167
|
"../../../context/token-estimator.js",
|
|
168
168
|
"../../../daemon/date-context.js",
|
|
169
|
+
"../../../daemon/disk-pressure-background-gate.js",
|
|
169
170
|
"../../../daemon/pkb-context-tracker.js",
|
|
170
171
|
"../../../daemon/pkb-reminder-builder.js",
|
|
171
172
|
"../../../daemon/tool-setup-types.js",
|
|
@@ -178,6 +179,7 @@ const BASELINE: Record<string, readonly string[]> = {
|
|
|
178
179
|
"../../../persistence/embeddings/embedding-runtime-manager.js",
|
|
179
180
|
"../../../persistence/embeddings/embedding-types.js",
|
|
180
181
|
"../../../persistence/jobs-store.js",
|
|
182
|
+
"../../../persistence/memory-lifecycle-hooks.js",
|
|
181
183
|
"../../../persistence/message-content.js",
|
|
182
184
|
"../../../persistence/raw-query.js",
|
|
183
185
|
"../../../persistence/schema/index.js",
|
|
@@ -185,6 +187,7 @@ const BASELINE: Record<string, readonly string[]> = {
|
|
|
185
187
|
"../../../prompts/system-prompt.js",
|
|
186
188
|
"../../../runtime/actor-trust-resolver.js",
|
|
187
189
|
"../../../runtime/agent-wake.js",
|
|
190
|
+
"../../../runtime/background-job-runner.js",
|
|
188
191
|
"../../../runtime/capabilities.js",
|
|
189
192
|
"../../../runtime/services/auto-analysis-enqueue.js",
|
|
190
193
|
"../../../runtime/services/auto-analysis-guard.js",
|
|
@@ -194,6 +197,7 @@ const BASELINE: Record<string, readonly string[]> = {
|
|
|
194
197
|
"../../../util/platform.js",
|
|
195
198
|
"../../../util/promise-guard.js",
|
|
196
199
|
"../../../util/sqlite-retry.js",
|
|
200
|
+
"../../../util/strip-comment-lines.js",
|
|
197
201
|
"../../types.js",
|
|
198
202
|
"../injection-presence.js",
|
|
199
203
|
"../injector-order.js",
|
|
@@ -43,6 +43,27 @@ mock.module("../runtime/background-job-runner.js", () => ({
|
|
|
43
43
|
},
|
|
44
44
|
}));
|
|
45
45
|
|
|
46
|
+
// The scheduler's conversation-reuse path dispatches through `processMessage`;
|
|
47
|
+
// route it to the same per-test delegate the runner mock uses.
|
|
48
|
+
let processMessageImpl: (
|
|
49
|
+
conversationId: string,
|
|
50
|
+
message: string,
|
|
51
|
+
) => Promise<unknown> = async () => {};
|
|
52
|
+
mock.module("../daemon/process-message.js", () => ({
|
|
53
|
+
processMessage: (conversationId: string, message: string) =>
|
|
54
|
+
processMessageImpl(conversationId, message),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
// Notify-mode firings dispatch through `emitNotificationSignal`; a per-test
|
|
58
|
+
// delegate lets a scenario make the notification throw to drive failure paths.
|
|
59
|
+
let emitNotificationSignalImpl: (
|
|
60
|
+
payload: unknown,
|
|
61
|
+
) => Promise<unknown> = async () => {};
|
|
62
|
+
mock.module("../notifications/emit-signal.js", () => ({
|
|
63
|
+
emitNotificationSignal: (payload: unknown) =>
|
|
64
|
+
emitNotificationSignalImpl(payload),
|
|
65
|
+
}));
|
|
66
|
+
|
|
46
67
|
import { getDb } from "../persistence/db-connection.js";
|
|
47
68
|
import { initializeDb } from "../persistence/db-init.js";
|
|
48
69
|
import { applyRetryDecision, decideRetry } from "../schedule/retry-policy.js";
|
|
@@ -62,24 +83,23 @@ import { startScheduler as startSchedulerReal } from "../schedule/scheduler.js";
|
|
|
62
83
|
import type { ScheduleMessageProcessor } from "../schedule/scheduler-types.js";
|
|
63
84
|
|
|
64
85
|
/**
|
|
65
|
-
* Wrap `startScheduler` so
|
|
66
|
-
*
|
|
67
|
-
* `
|
|
68
|
-
*
|
|
69
|
-
*
|
|
86
|
+
* Wrap `startScheduler` so a single per-test `processMessage` callback drives
|
|
87
|
+
* both scheduler dispatch paths: the conversation-reuse path (which calls the
|
|
88
|
+
* mocked `daemon/process-message`) and the fresh-bootstrap path (which calls
|
|
89
|
+
* the mocked `runBackgroundJob`). Tests exercise both deterministically through
|
|
90
|
+
* this one callback.
|
|
70
91
|
*/
|
|
71
92
|
function startScheduler(
|
|
72
93
|
processMessage: ScheduleMessageProcessor,
|
|
73
|
-
|
|
74
|
-
|
|
94
|
+
_notifyScheduleOneShot?: unknown,
|
|
95
|
+
_options?: unknown,
|
|
75
96
|
): SchedulerHandle {
|
|
76
|
-
|
|
77
|
-
conversationId: string,
|
|
78
|
-
message: string,
|
|
79
|
-
) => {
|
|
97
|
+
const dispatch = async (conversationId: string, message: string) => {
|
|
80
98
|
await processMessage(conversationId, message, { trustClass: "guardian" });
|
|
81
99
|
};
|
|
82
|
-
|
|
100
|
+
processMessageImpl = dispatch;
|
|
101
|
+
injectedProcessMessageForRunner = dispatch;
|
|
102
|
+
return startSchedulerReal();
|
|
83
103
|
}
|
|
84
104
|
|
|
85
105
|
await initializeDb();
|
|
@@ -102,6 +122,7 @@ function forceScheduleDue(scheduleId: string): void {
|
|
|
102
122
|
|
|
103
123
|
describe("schedule retry store", () => {
|
|
104
124
|
beforeEach(() => {
|
|
125
|
+
emitNotificationSignalImpl = async () => {};
|
|
105
126
|
const db = getDb();
|
|
106
127
|
db.run("DELETE FROM cron_runs");
|
|
107
128
|
db.run("DELETE FROM cron_jobs");
|
|
@@ -203,6 +224,7 @@ describe("scheduler retry integration", () => {
|
|
|
203
224
|
let scheduler: SchedulerHandle;
|
|
204
225
|
|
|
205
226
|
beforeEach(() => {
|
|
227
|
+
emitNotificationSignalImpl = async () => {};
|
|
206
228
|
const db = getDb();
|
|
207
229
|
db.run("DELETE FROM cron_runs");
|
|
208
230
|
db.run("DELETE FROM cron_jobs");
|
|
@@ -389,11 +411,11 @@ describe("scheduler retry integration", () => {
|
|
|
389
411
|
maxRetries: 2,
|
|
390
412
|
});
|
|
391
413
|
|
|
392
|
-
|
|
414
|
+
emitNotificationSignalImpl = async () => {
|
|
393
415
|
throw new Error("notify failed");
|
|
394
416
|
};
|
|
395
417
|
|
|
396
|
-
scheduler = startScheduler(async () => {}
|
|
418
|
+
scheduler = startScheduler(async () => {});
|
|
397
419
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
398
420
|
scheduler.stop();
|
|
399
421
|
|
|
@@ -439,6 +461,7 @@ describe("scheduler retry integration", () => {
|
|
|
439
461
|
|
|
440
462
|
describe("crash recovery", () => {
|
|
441
463
|
beforeEach(() => {
|
|
464
|
+
emitNotificationSignalImpl = async () => {};
|
|
442
465
|
const db = getDb();
|
|
443
466
|
db.run("DELETE FROM cron_runs");
|
|
444
467
|
db.run("DELETE FROM cron_jobs");
|
|
@@ -574,6 +597,7 @@ describe("scheduler-recovery equivalence", () => {
|
|
|
574
597
|
let scheduler: SchedulerHandle;
|
|
575
598
|
|
|
576
599
|
beforeEach(() => {
|
|
600
|
+
emitNotificationSignalImpl = async () => {};
|
|
577
601
|
const db = getDb();
|
|
578
602
|
db.run("DELETE FROM cron_runs");
|
|
579
603
|
db.run("DELETE FROM cron_jobs");
|
|
@@ -89,6 +89,18 @@ mock.module("../daemon/disk-pressure-background-gate.js", () => ({
|
|
|
89
89
|
shouldLogDiskPressureBackgroundSkip: () => true,
|
|
90
90
|
}));
|
|
91
91
|
|
|
92
|
+
const mockProcessMessage = mock((..._args: unknown[]) => Promise.resolve());
|
|
93
|
+
mock.module("../daemon/process-message.js", () => ({
|
|
94
|
+
processMessage: mockProcessMessage,
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
const mockEmitNotificationSignal = mock((..._args: unknown[]) =>
|
|
98
|
+
Promise.resolve(),
|
|
99
|
+
);
|
|
100
|
+
mock.module("../notifications/emit-signal.js", () => ({
|
|
101
|
+
emitNotificationSignal: mockEmitNotificationSignal,
|
|
102
|
+
}));
|
|
103
|
+
|
|
92
104
|
import { getDb } from "../persistence/db-connection.js";
|
|
93
105
|
import { initializeDb } from "../persistence/db-init.js";
|
|
94
106
|
import { createSchedule } from "../schedule/schedule-store.js";
|
|
@@ -104,6 +116,8 @@ function rawDb(): import("bun:sqlite").Database {
|
|
|
104
116
|
describe("scheduler disk pressure gate", () => {
|
|
105
117
|
beforeEach(() => {
|
|
106
118
|
locked = true;
|
|
119
|
+
mockProcessMessage.mockClear();
|
|
120
|
+
mockEmitNotificationSignal.mockClear();
|
|
107
121
|
const db = getDb();
|
|
108
122
|
db.run("DELETE FROM cron_runs");
|
|
109
123
|
db.run("DELETE FROM cron_jobs");
|
|
@@ -122,14 +136,11 @@ describe("scheduler disk pressure gate", () => {
|
|
|
122
136
|
nextRunAt: dueAt,
|
|
123
137
|
});
|
|
124
138
|
|
|
125
|
-
const
|
|
126
|
-
const notify = mock(() => Promise.resolve());
|
|
127
|
-
|
|
128
|
-
const processed = await runScheduleOnce(processMessage, notify);
|
|
139
|
+
const processed = await runScheduleOnce();
|
|
129
140
|
|
|
130
141
|
expect(processed).toBe(0);
|
|
131
|
-
expect(
|
|
132
|
-
expect(
|
|
142
|
+
expect(mockProcessMessage).not.toHaveBeenCalled();
|
|
143
|
+
expect(mockEmitNotificationSignal).not.toHaveBeenCalled();
|
|
133
144
|
|
|
134
145
|
const row = rawDb()
|
|
135
146
|
.query("SELECT status, next_run_at FROM cron_jobs WHERE id = ?")
|