@vellumai/assistant 0.10.12-dev.202607272128.6a086ca → 0.10.12-dev.202607272227.bd2aa0b

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.
Files changed (29) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/document-tool-security.test.ts +95 -0
  3. package/src/__tests__/dynamic-skill-background-guard.test.ts +19 -6
  4. package/src/__tests__/gateway-threshold-reader-mock.ts +99 -0
  5. package/src/__tests__/require-fresh-approval.test.ts +37 -38
  6. package/src/__tests__/schedule-tools.test.ts +190 -0
  7. package/src/__tests__/tool-approval-handler.test.ts +528 -56
  8. package/src/__tests__/tool-execution-pipeline.benchmark.test.ts +4 -4
  9. package/src/__tests__/workspace-policy.test.ts +263 -0
  10. package/src/permissions/channel-permission-query.test.ts +69 -0
  11. package/src/permissions/channel-permission-query.ts +73 -1
  12. package/src/permissions/checker.ts +1 -1
  13. package/src/permissions/gateway-threshold-reader.test.ts +224 -17
  14. package/src/permissions/gateway-threshold-reader.ts +82 -10
  15. package/src/permissions/workspace-policy.ts +133 -12
  16. package/src/providers/model-catalog.ts +16 -0
  17. package/src/tools/__tests__/document-tool-input-schemas.test.ts +103 -0
  18. package/src/tools/__tests__/schedule-tool-input-schemas.test.ts +86 -0
  19. package/src/tools/__tests__/tool-schema-drift-harness.ts +142 -0
  20. package/src/tools/document/document-comment-tool.test.ts +49 -0
  21. package/src/tools/document/document-comment-tool.ts +45 -6
  22. package/src/tools/document/document-tool.ts +142 -24
  23. package/src/tools/policy-context.ts +20 -4
  24. package/src/tools/schedule/create.ts +80 -36
  25. package/src/tools/schedule/delete.ts +21 -2
  26. package/src/tools/schedule/list.ts +25 -3
  27. package/src/tools/schedule/update.ts +110 -50
  28. package/src/tools/shared/zod-tool-schema.ts +12 -0
  29. package/src/tools/tool-approval-handler.ts +259 -46
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.12-dev.202607272128.6a086ca",
3
+ "version": "0.10.12-dev.202607272227.bd2aa0b",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -3,9 +3,12 @@ import { beforeEach, describe, expect, test } from "bun:test";
3
3
  import { getDocumentById } from "../documents/document-store.js";
4
4
  import { getSqlite } from "../persistence/db-connection.js";
5
5
  import {
6
+ executeDocumentCreate,
6
7
  executeDocumentDelete,
8
+ executeDocumentFind,
7
9
  executeDocumentList,
8
10
  executeDocumentRead,
11
+ executeDocumentReplaceText,
9
12
  executeDocumentUpdate,
10
13
  } from "../tools/document/document-tool.js";
11
14
  import type { ToolContext, ToolExecutionResult } from "../tools/types.js";
@@ -338,3 +341,95 @@ describe("executeDocumentUpdate — input validation", () => {
338
341
  expect(body.error).toContain("Invalid input: surface_id is required");
339
342
  });
340
343
  });
344
+
345
+ // ── model-input schema validation (LUM-2854) ─────────────────────────
346
+
347
+ describe("document tools — model-input schema validation", () => {
348
+ beforeEach(() => {
349
+ bootstrapDocumentTables();
350
+ seedFixtureDocuments();
351
+ });
352
+
353
+ test("document_find rejects a non-string query instead of crashing downstream", () => {
354
+ const result = executeDocumentFind(
355
+ { surface_id: "doc-current", query: 42 },
356
+ makeContext(),
357
+ );
358
+ expect(result.isError).toBe(true);
359
+ expect(result.content).toContain('Invalid input for tool "document_find"');
360
+ expect(result.content).toContain("query");
361
+ });
362
+
363
+ test("document_find rejects a missing query cleanly", () => {
364
+ const result = executeDocumentFind(
365
+ { surface_id: "doc-current" },
366
+ makeContext(),
367
+ );
368
+ expect(result.isError).toBe(true);
369
+ expect(result.content).toContain('Invalid input for tool "document_find"');
370
+ });
371
+
372
+ test("document_find treats null option flags as omitted", () => {
373
+ const result = executeDocumentFind(
374
+ {
375
+ surface_id: "doc-current",
376
+ query: "current",
377
+ regex: null,
378
+ case_sensitive: null,
379
+ },
380
+ makeContext(),
381
+ );
382
+ expect(result.isError).toBe(false);
383
+ const body = parseResult<{ total_matches: number }>(result);
384
+ expect(body.total_matches).toBe(1);
385
+ });
386
+
387
+ test("document_create rejects a non-string title instead of persisting it", () => {
388
+ const result = executeDocumentCreate(
389
+ { title: 42, initial_content: "hello" },
390
+ makeContext({ conversationId: "conv-current" }),
391
+ );
392
+ expect(result.isError).toBe(true);
393
+ expect(result.content).toContain(
394
+ 'Invalid input for tool "document_create"',
395
+ );
396
+ expect(result.content).toContain("title");
397
+ });
398
+
399
+ test("document_update rejects a non-string content before the bespoke checks", () => {
400
+ const result = executeDocumentUpdate(
401
+ { surface_id: "doc-current", content: 42 },
402
+ makeContext(),
403
+ );
404
+ expect(result.isError).toBe(true);
405
+ expect(result.content).toContain(
406
+ 'Invalid input for tool "document_update"',
407
+ );
408
+ });
409
+
410
+ test("document_list still silently ignores a malformed query", () => {
411
+ const result = executeDocumentList({ query: 42 }, makeContext());
412
+ expect(result.isError).toBe(false);
413
+ const body = parseResult<{ documents: Array<{ surface_id: string }> }>(
414
+ result,
415
+ );
416
+ expect(body.documents.map((d) => d.surface_id)).toEqual(["doc-current"]);
417
+ });
418
+
419
+ test("document_replace_text rejects a non-number max_replacements", () => {
420
+ const result = executeDocumentReplaceText(
421
+ {
422
+ surface_id: "doc-current",
423
+ find: "current",
424
+ replace: "new",
425
+ max_replacements: "3",
426
+ },
427
+ makeContext(),
428
+ );
429
+ expect(result.isError).toBe(true);
430
+ expect(result.content).toContain(
431
+ 'Invalid input for tool "document_replace_text"',
432
+ );
433
+ expect(result.content).toContain("max_replacements");
434
+ });
435
+ });
@@ -19,6 +19,10 @@ import { afterAll, beforeEach, describe, expect, mock, test } from "bun:test";
19
19
 
20
20
  import { RiskLevel } from "../permissions/types.js";
21
21
  import type { ToolExecutionResult } from "../tools/types.js";
22
+ import {
23
+ installThresholdReaderMock,
24
+ thresholdReaderMock,
25
+ } from "./gateway-threshold-reader-mock.js";
22
26
 
23
27
  // ---------------------------------------------------------------------------
24
28
  // Mock setup — mirrors require-fresh-approval.test.ts patterns
@@ -37,8 +41,20 @@ let dynamicSkillLoad = false;
37
41
  */
38
42
  let checkDecision = "prompt";
39
43
 
44
+ // The real builder returns undefined for these contexts (guardian turns with
45
+ // no channel coordinates), which is what this suite wants. It is registered
46
+ // rather than hard-coded because `mock.module` is process-global: a stub that
47
+ // always returned undefined would also be the builder other test files see,
48
+ // silently stripping the channel coordinates their contexts supply. Captured
49
+ // by value first — `mock.module` swaps the module's exports in place, so
50
+ // reading it through the namespace inside the factory would recurse.
51
+ const realCellQueryModule =
52
+ await import("../permissions/channel-permission-query.js");
40
53
  mock.module("../permissions/channel-permission-query.js", () => ({
41
- buildChannelPermissionCellQuery: () => undefined,
54
+ buildChannelPermissionCellQuery:
55
+ realCellQueryModule.buildChannelPermissionCellQuery,
56
+ effectiveChannelCellThreshold:
57
+ realCellQueryModule.effectiveChannelCellThreshold,
42
58
  }));
43
59
 
44
60
  // The scenario under test is "no trust rule covers this load" (a covering rule
@@ -74,11 +90,8 @@ mock.module("../tools/registry.js", () => ({
74
90
 
75
91
  // Background threshold "medium" covers the medium-risk load — the guard,
76
92
  // not the threshold, must be what blocks the dynamic case.
77
- mock.module("../permissions/gateway-threshold-reader.js", () => ({
78
- getAutoApproveThreshold: async () => "medium",
79
- refreshAutoApproveThreshold: async () => null,
80
- _clearGlobalCacheForTesting: () => {},
81
- }));
93
+ installThresholdReaderMock();
94
+ thresholdReaderMock.threshold = "medium";
82
95
 
83
96
  mock.module("../tools/shared/filesystem/path-policy.js", () => ({
84
97
  sandboxPolicy: () => ({ ok: false }),
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Shared module mock for `permissions/gateway-threshold-reader`.
3
+ *
4
+ * `mock.module` registrations are process-global and last-one-wins, so files
5
+ * that each stubbed this module their own way overwrote each other depending
6
+ * on load order — a file could pass alone and fail in a batch (or worse, pass
7
+ * for the wrong reason) because a sibling's stub was the one actually live.
8
+ *
9
+ * Every file registers this same delegating mock instead and steers it by
10
+ * writing to {@link thresholdReaderMock}. Which registration wins no longer
11
+ * changes behaviour, so the stubs a test sets are the stubs it gets.
12
+ *
13
+ * Holds no production imports — only mutable state the mock reads — so it is
14
+ * safe to load from preload-time test machinery.
15
+ */
16
+ import { mock } from "bun:test";
17
+
18
+ /** What the mocked cell lookup resolves to. `ok: false` is a transport failure. */
19
+ export type MockCellResult =
20
+ | { ok: true; resolved: { threshold: string; scope: string } | null }
21
+ | { ok: false };
22
+
23
+ export interface ThresholdReaderMockState {
24
+ /** Resolved by `getAutoApproveThreshold`. */
25
+ threshold: string | undefined;
26
+ /** Resolved by `refreshAutoApproveThreshold`; `null` means "refresh failed". */
27
+ refreshed: string | null;
28
+ /** Resolved by `resolveChannelPermissionCell`. */
29
+ cell: MockCellResult;
30
+ /** The collapsed-global room default `channelNoCellDefault` derives. */
31
+ roomDefault: string | undefined;
32
+ /** Every `getAutoApproveThreshold` call, in order. */
33
+ thresholdReads: Array<{
34
+ conversationId?: string;
35
+ executionContext?: string;
36
+ cellQuery?: Record<string, unknown>;
37
+ }>;
38
+ /** How many times the cell was looked up. */
39
+ cellLookups: number;
40
+ }
41
+
42
+ export const thresholdReaderMock: ThresholdReaderMockState = {
43
+ threshold: undefined,
44
+ refreshed: null,
45
+ cell: { ok: true, resolved: null },
46
+ roomDefault: "low",
47
+ thresholdReads: [],
48
+ cellLookups: 0,
49
+ };
50
+
51
+ /**
52
+ * Restore the defaults: no cell anywhere, a Conservative room default,
53
+ * failed refresh, no recorded calls.
54
+ */
55
+ export function resetThresholdReaderMock(): void {
56
+ thresholdReaderMock.threshold = undefined;
57
+ thresholdReaderMock.refreshed = null;
58
+ thresholdReaderMock.cell = { ok: true, resolved: null };
59
+ thresholdReaderMock.roomDefault = "low";
60
+ thresholdReaderMock.thresholdReads.length = 0;
61
+ thresholdReaderMock.cellLookups = 0;
62
+ }
63
+
64
+ /**
65
+ * Register the mock. Call at module scope, before importing the code under
66
+ * test. Safe to call from several files in one run — each registration
67
+ * installs the same delegating stubs.
68
+ */
69
+ export function installThresholdReaderMock(): void {
70
+ mock.module("../permissions/gateway-threshold-reader.js", () => ({
71
+ getAutoApproveThreshold: async (
72
+ conversationId?: string,
73
+ executionContext?: string,
74
+ cellQuery?: Record<string, unknown>,
75
+ ) => {
76
+ thresholdReaderMock.thresholdReads.push({
77
+ conversationId,
78
+ executionContext,
79
+ cellQuery,
80
+ });
81
+ return thresholdReaderMock.threshold;
82
+ },
83
+ refreshAutoApproveThreshold: async () => thresholdReaderMock.refreshed,
84
+ resolveChannelPermissionCell: async () => {
85
+ thresholdReaderMock.cellLookups += 1;
86
+ return thresholdReaderMock.cell;
87
+ },
88
+ // Mirrors the production guard: only a successful no-cell walk for a
89
+ // non-guardian derives the default. Reimplemented here (three lines)
90
+ // because this file must hold no production imports.
91
+ channelNoCellDefault: async (cell: MockCellResult, contactType: string) => {
92
+ if (!cell.ok || cell.resolved || contactType === "guardian") {
93
+ return undefined;
94
+ }
95
+ return thresholdReaderMock.roomDefault;
96
+ },
97
+ _clearGlobalCacheForTesting: () => {},
98
+ }));
99
+ }
@@ -19,6 +19,10 @@ import {
19
19
 
20
20
  import { RiskLevel, type ScopeOption } from "../permissions/types.js";
21
21
  import type { ToolExecutionResult } from "../tools/types.js";
22
+ import {
23
+ installThresholdReaderMock,
24
+ thresholdReaderMock,
25
+ } from "./gateway-threshold-reader-mock.js";
22
26
 
23
27
  // ---------------------------------------------------------------------------
24
28
  // Terminal audit mock — the permission checker / executor call these directly
@@ -55,13 +59,6 @@ let riskOverride: string = "high";
55
59
  /** Scope options override — controls whether persistent decisions are offered. */
56
60
  let scopeOptionsOverride: ScopeOption[] | undefined;
57
61
 
58
- /**
59
- * Auto-approve threshold returned to the permission checker. "high" is the
60
- * full-access posture under which the requireFreshApproval promotion is
61
- * skipped; every lower value still promotes allow → prompt.
62
- */
63
- let thresholdOverride: "none" | "low" | "medium" | "high" = "medium";
64
-
65
62
  /**
66
63
  * Sentinel cell query the mocked builder returns. When set, the permission
67
64
  * checker must thread it into every gateway threshold read for the
@@ -69,8 +66,23 @@ let thresholdOverride: "none" | "low" | "medium" | "high" = "medium";
69
66
  */
70
67
  let cellQueryOverride: Record<string, unknown> | undefined;
71
68
 
69
+ // Falls through to the real builder when no sentinel is set. `mock.module` is
70
+ // process-global, so a hard-coded return here would also be the builder other
71
+ // test files see — and silently strip the channel coordinates their contexts
72
+ // supply, depending on which registration loaded last. The real function is
73
+ // captured by value first: `mock.module` swaps the module's exports in place,
74
+ // so reading it through the namespace inside the factory would resolve to this
75
+ // mock and recurse.
76
+ const realCellQueryModule =
77
+ await import("../permissions/channel-permission-query.js");
78
+ const realBuildCellQuery = realCellQueryModule.buildChannelPermissionCellQuery;
79
+ const realEffectiveCellThreshold =
80
+ realCellQueryModule.effectiveChannelCellThreshold;
72
81
  mock.module("../permissions/channel-permission-query.js", () => ({
73
- buildChannelPermissionCellQuery: () => cellQueryOverride,
82
+ buildChannelPermissionCellQuery: (
83
+ ...args: Parameters<typeof realBuildCellQuery>
84
+ ) => cellQueryOverride ?? realBuildCellQuery(...args),
85
+ effectiveChannelCellThreshold: realEffectiveCellThreshold,
74
86
  }));
75
87
 
76
88
  mock.module("../permissions/checker.js", () => ({
@@ -130,28 +142,15 @@ mock.module("../tools/registry.js", () => ({
130
142
  getAllTools: () => [],
131
143
  }));
132
144
 
133
- /** Records every getAutoApproveThreshold call so tests can assert the cell
134
- * query is threaded into each read (including the background auto-approve). */
135
- const thresholdReadLog: Array<{
136
- conversationId?: string;
137
- executionContext?: string;
138
- cellQuery?: Record<string, unknown>;
139
- }> = [];
140
-
141
- mock.module("../permissions/gateway-threshold-reader.js", () => ({
142
- getAutoApproveThreshold: async (
143
- conversationId?: string,
144
- executionContext?: string,
145
- cellQuery?: Record<string, unknown>,
146
- ) => {
147
- thresholdReadLog.push({ conversationId, executionContext, cellQuery });
148
- return thresholdOverride;
149
- },
150
- // Refresh failure ("null") keeps the original decision — these tests
151
- // exercise the cached-threshold paths only.
152
- refreshAutoApproveThreshold: async () => null,
153
- _clearGlobalCacheForTesting: () => {},
154
- }));
145
+ // The mock defaults leave no cell at any cascade level, so the sensitive-tool
146
+ // gate's capability floor stands on its own — these tests are about
147
+ // fresh-approval promotion, not the channel matrix. `thresholdReads` records
148
+ // every getAutoApproveThreshold call so tests can assert the cell query is
149
+ // threaded into each read (including the background auto-approve).
150
+ installThresholdReaderMock();
151
+
152
+ /** Records every getAutoApproveThreshold call. */
153
+ const thresholdReadLog = thresholdReaderMock.thresholdReads;
155
154
 
156
155
  // Stub the workflow run manager so the `manage_workflows` resume gate can read a
157
156
  // target run's STORED capabilities without a real journal/DB. Tests set
@@ -209,7 +208,7 @@ describe("requireFreshApproval: non-interactive guardian denial", () => {
209
208
  checkResultOverride = undefined;
210
209
  scopeOptionsOverride = undefined;
211
210
  riskOverride = "high";
212
- thresholdOverride = "medium";
211
+ thresholdReaderMock.threshold = "medium";
213
212
  cellQueryOverride = undefined;
214
213
  thresholdReadLog.length = 0;
215
214
  });
@@ -375,7 +374,7 @@ describe("requireFreshApproval: context flag propagation", () => {
375
374
  checkResultOverride = undefined;
376
375
  scopeOptionsOverride = undefined;
377
376
  riskOverride = "high";
378
- thresholdOverride = "medium";
377
+ thresholdReaderMock.threshold = "medium";
379
378
  });
380
379
 
381
380
  afterEach(() => {});
@@ -404,7 +403,7 @@ describe("requireFreshApproval: workflow capability grants", () => {
404
403
  checkResultOverride = undefined;
405
404
  scopeOptionsOverride = undefined;
406
405
  riskOverride = "low";
407
- thresholdOverride = "medium";
406
+ thresholdReaderMock.threshold = "medium";
408
407
  fakeWorkflowRun = null;
409
408
  });
410
409
 
@@ -445,7 +444,7 @@ describe("requireFreshApproval: workflow capability grants", () => {
445
444
  "run_workflow side-effecting launch prompts at the %s threshold (non-full-access posture)",
446
445
  async (threshold) => {
447
446
  checkResultOverride = { decision: "allow", reason: "allowed" };
448
- thresholdOverride = threshold;
447
+ thresholdReaderMock.threshold = threshold;
449
448
  const state = { prompted: false };
450
449
  const executor = new ToolExecutor(trackingPrompter(state));
451
450
  const ctx = makeContext();
@@ -466,7 +465,7 @@ describe("requireFreshApproval: workflow capability grants", () => {
466
465
  // Full-access posture auto-approves even high-risk tools, so the
467
466
  // requireFreshApproval promotion is skipped — the grant auto-allows.
468
467
  checkResultOverride = { decision: "allow", reason: "allowed" };
469
- thresholdOverride = "high";
468
+ thresholdReaderMock.threshold = "high";
470
469
  const state = { prompted: false };
471
470
  const executor = new ToolExecutor(trackingPrompter(state));
472
471
  const ctx = makeContext();
@@ -488,7 +487,7 @@ describe("requireFreshApproval: workflow capability grants", () => {
488
487
  // Full access skips the fresh-approval promotion but never overrides an
489
488
  // explicit deny — deny rules win regardless of posture.
490
489
  checkResultOverride = { decision: "deny", reason: "blocked by rule" };
491
- thresholdOverride = "high";
490
+ thresholdReaderMock.threshold = "high";
492
491
  const state = { prompted: false };
493
492
  const executor = new ToolExecutor(trackingPrompter(state));
494
493
  const ctx = makeContext();
@@ -505,7 +504,7 @@ describe("requireFreshApproval: workflow capability grants", () => {
505
504
 
506
505
  test("a deny rule still blocks a side-effecting launch at a normal threshold", async () => {
507
506
  checkResultOverride = { decision: "deny", reason: "blocked by rule" };
508
- thresholdOverride = "medium";
507
+ thresholdReaderMock.threshold = "medium";
509
508
  const state = { prompted: false };
510
509
  const executor = new ToolExecutor(trackingPrompter(state));
511
510
  const ctx = makeContext();
@@ -523,7 +522,7 @@ describe("requireFreshApproval: workflow capability grants", () => {
523
522
  test("a read-only launch (no requireFreshApproval) is unaffected by a normal threshold", async () => {
524
523
  // No requireFreshApproval means the allow stands untouched at any posture.
525
524
  checkResultOverride = { decision: "allow", reason: "allowed" };
526
- thresholdOverride = "medium";
525
+ thresholdReaderMock.threshold = "medium";
527
526
  const state = { prompted: false };
528
527
  const executor = new ToolExecutor(trackingPrompter(state));
529
528
  const ctx = makeContext();
@@ -2023,3 +2023,193 @@ describe("script handoff validation", () => {
2023
2023
  expect(row.skill_version_hash).toBeNull();
2024
2024
  });
2025
2025
  });
2026
+
2027
+ // ── model-input schema validation (LUM-2853) ────────────────────────
2028
+
2029
+ describe("schedule tools — model-input schema validation", () => {
2030
+ beforeEach(() => {
2031
+ getRawDb().run("DELETE FROM cron_runs");
2032
+ getRawDb().run("DELETE FROM cron_jobs");
2033
+ });
2034
+
2035
+ test("schedule_create rejects a mistyped field instead of persisting it", async () => {
2036
+ const result = await executeScheduleCreate(
2037
+ {
2038
+ name: "Bad timezone",
2039
+ expression: "0 9 * * *",
2040
+ message: "hi",
2041
+ timezone: 42,
2042
+ },
2043
+ ctx,
2044
+ );
2045
+
2046
+ expect(result.isError).toBe(true);
2047
+ expect(result.content).toContain(
2048
+ 'Invalid input for tool "schedule_create"',
2049
+ );
2050
+ expect(result.content).toContain("timezone");
2051
+ const count = getRawDb()
2052
+ .query("SELECT COUNT(*) as n FROM cron_jobs")
2053
+ .get() as { n: number };
2054
+ expect(count.n).toBe(0);
2055
+ });
2056
+
2057
+ test("schedule_create rejects a non-integer retry policy", async () => {
2058
+ const result = await executeScheduleCreate(
2059
+ {
2060
+ name: "Bad retries",
2061
+ expression: "0 9 * * *",
2062
+ message: "hi",
2063
+ max_retries: "five",
2064
+ },
2065
+ ctx,
2066
+ );
2067
+
2068
+ expect(result.isError).toBe(true);
2069
+ expect(result.content).toContain("max_retries");
2070
+ });
2071
+
2072
+ test("schedule_create rejects an unknown syntax value instead of persisting it", async () => {
2073
+ const result = await executeScheduleCreate(
2074
+ {
2075
+ name: "Bad syntax",
2076
+ expression: "0 9 * * *",
2077
+ syntax: "daily",
2078
+ message: "hi",
2079
+ },
2080
+ ctx,
2081
+ );
2082
+
2083
+ expect(result.isError).toBe(true);
2084
+ expect(result.content).toContain("syntax");
2085
+ });
2086
+
2087
+ test("schedule_create treats explicit null as an omitted optional", async () => {
2088
+ const result = await executeScheduleCreate(
2089
+ {
2090
+ name: "Null tolerance",
2091
+ expression: "0 9 * * *",
2092
+ message: "hi",
2093
+ timezone: null,
2094
+ enabled: null,
2095
+ quiet: null,
2096
+ },
2097
+ ctx,
2098
+ );
2099
+
2100
+ expect(result.isError).toBeFalsy();
2101
+ expect(result.content).toContain("Enabled: true");
2102
+ });
2103
+
2104
+ test("schedule_create still silently ignores a malformed skill_id", async () => {
2105
+ const result = await executeScheduleCreate(
2106
+ {
2107
+ name: "Ignored skill_id",
2108
+ expression: "0 9 * * *",
2109
+ message: "hi",
2110
+ skill_id: 42,
2111
+ },
2112
+ ctx,
2113
+ );
2114
+
2115
+ expect(result.isError).toBeFalsy();
2116
+ });
2117
+
2118
+ test("schedule_create keeps the bespoke error for a non-string mode", async () => {
2119
+ const result = await executeScheduleCreate(
2120
+ {
2121
+ name: "Bad mode",
2122
+ expression: "0 9 * * *",
2123
+ message: "hi",
2124
+ mode: 42,
2125
+ },
2126
+ ctx,
2127
+ );
2128
+
2129
+ expect(result.isError).toBe(true);
2130
+ expect(result.content).toContain("mode must be one of");
2131
+ });
2132
+
2133
+ test("schedule_create passes unknown keys through (loose schema)", async () => {
2134
+ const result = await executeScheduleCreate(
2135
+ {
2136
+ name: "Loose keys",
2137
+ expression: "0 9 * * *",
2138
+ message: "hi",
2139
+ activity: "creating a schedule",
2140
+ },
2141
+ ctx,
2142
+ );
2143
+
2144
+ expect(result.isError).toBeFalsy();
2145
+ });
2146
+
2147
+ test("schedule_update rejects a mistyped field", async () => {
2148
+ const create = await executeScheduleCreate(
2149
+ { name: "To update", expression: "0 9 * * *", message: "hi" },
2150
+ ctx,
2151
+ );
2152
+ expect(create.isError).toBeFalsy();
2153
+ const jobId = (
2154
+ getRawDb().query("SELECT id FROM cron_jobs").get() as { id: string }
2155
+ ).id;
2156
+
2157
+ const result = await executeScheduleUpdate(
2158
+ { job_id: jobId, max_retries: 2.5 },
2159
+ ctx,
2160
+ );
2161
+
2162
+ expect(result.isError).toBe(true);
2163
+ expect(result.content).toContain(
2164
+ 'Invalid input for tool "schedule_update"',
2165
+ );
2166
+ expect(result.content).toContain("max_retries");
2167
+ });
2168
+
2169
+ test("schedule_update still clears timezone with an explicit null", async () => {
2170
+ const create = await executeScheduleCreate(
2171
+ {
2172
+ name: "Tz clear",
2173
+ expression: "0 9 * * *",
2174
+ message: "hi",
2175
+ timezone: "America/Los_Angeles",
2176
+ },
2177
+ ctx,
2178
+ );
2179
+ expect(create.isError).toBeFalsy();
2180
+ const jobId = (
2181
+ getRawDb().query("SELECT id FROM cron_jobs").get() as { id: string }
2182
+ ).id;
2183
+
2184
+ const result = await executeScheduleUpdate(
2185
+ { job_id: jobId, timezone: null },
2186
+ ctx,
2187
+ );
2188
+
2189
+ expect(result.isError).toBeFalsy();
2190
+ const row = getRawDb()
2191
+ .query("SELECT timezone FROM cron_jobs WHERE id = ?")
2192
+ .get(jobId) as { timezone: string | null };
2193
+ expect(row.timezone).toBeNull();
2194
+ });
2195
+
2196
+ test("schedule_list rejects a mistyped enabled_only and tolerates null", async () => {
2197
+ const bad = await executeScheduleList({ enabled_only: "yes" }, ctx);
2198
+ expect(bad.isError).toBe(true);
2199
+ expect(bad.content).toContain('Invalid input for tool "schedule_list"');
2200
+
2201
+ const ok = await executeScheduleList(
2202
+ { enabled_only: null, job_id: null },
2203
+ ctx,
2204
+ );
2205
+ expect(ok.isError).toBeFalsy();
2206
+ });
2207
+
2208
+ test("schedule_delete rejects a mistyped job_id", async () => {
2209
+ const result = await executeScheduleDelete({ job_id: 42 }, ctx);
2210
+ expect(result.isError).toBe(true);
2211
+ expect(result.content).toContain(
2212
+ 'Invalid input for tool "schedule_delete"',
2213
+ );
2214
+ });
2215
+ });