@vellumai/assistant 0.11.2-dev.202608052324.a11da34 → 0.11.2-dev.202608052357.8f326c2

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/openapi.yaml CHANGED
@@ -25679,8 +25679,10 @@ paths:
25679
25679
  - type: string
25680
25680
  - type: "null"
25681
25681
  description:
25682
- Inference profile (llm.profiles key) the schedule's runs use. Omitted or null = default, i.e. the mainAgent
25683
- call-site model selection.
25682
+ Inference profile (llm.profiles key) the schedule's runs use. Omitted or null pins the schedule to the
25683
+ currently resolved default profile, so its model does not move when that default changes.
25684
+ Workflow-mode schedules resolve a model per workflow step, so the pin is recorded but does not
25685
+ govern their runs.
25684
25686
  required:
25685
25687
  - name
25686
25688
  - expression
@@ -26231,8 +26233,9 @@ paths:
26231
26233
  - type: string
26232
26234
  - type: "null"
26233
26235
  description:
26234
- Inference profile (llm.profiles key) the schedule's runs use; null clears it back to the default mainAgent
26235
- call-site model selection
26236
+ Inference profile (llm.profiles key) the schedule's runs use; null re-pins the schedule to the currently
26237
+ resolved default profile. Workflow-mode schedules resolve a model per workflow step, so the pin is
26238
+ recorded but does not govern their runs.
26236
26239
  responses:
26237
26240
  "200":
26238
26241
  description: Successful response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.2-dev.202608052324.a11da34",
3
+ "version": "0.11.2-dev.202608052357.8f326c2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,137 @@
1
+ import {
2
+ existsSync,
3
+ mkdirSync,
4
+ mkdtempSync,
5
+ realpathSync,
6
+ rmSync,
7
+ writeFileSync,
8
+ } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import {
12
+ afterEach,
13
+ beforeAll,
14
+ beforeEach,
15
+ describe,
16
+ expect,
17
+ test,
18
+ } from "bun:test";
19
+
20
+ import { finalizeTool } from "../tools/tool-defaults.js";
21
+ import type { Tool, ToolContext } from "../tools/types.js";
22
+
23
+ let fileReadTool: Tool;
24
+ let fileWriteTool: Tool;
25
+
26
+ beforeAll(async () => {
27
+ const [read, write] = await Promise.all([
28
+ import("../tools/filesystem/read.js"),
29
+ import("../tools/filesystem/write.js"),
30
+ ]);
31
+ fileReadTool = finalizeTool(read.fileReadTool, "file_read");
32
+ fileWriteTool = finalizeTool(write.fileWriteTool, "file_write");
33
+ });
34
+
35
+ const testDirs: string[] = [];
36
+
37
+ function makeTempDir(prefix: string): string {
38
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
39
+ testDirs.push(dir);
40
+ return dir;
41
+ }
42
+
43
+ function makeContext(workingDir: string): ToolContext {
44
+ return {
45
+ workingDir,
46
+ conversationId: "test-conversation",
47
+ trustClass: "guardian",
48
+ };
49
+ }
50
+
51
+ /**
52
+ * A skill installed outside the workspace, mirroring a bundled skill in the
53
+ * container's install tree (`/app/assistant/src/config/bundled-skills/<id>`).
54
+ * Skill bodies point the model at these reference files by absolute path.
55
+ */
56
+ function makeInstalledSkill(id: string): string {
57
+ const installTree = makeTempDir("container-install-");
58
+ const directoryPath = join(installTree, id);
59
+ mkdirSync(join(directoryPath, "references"), { recursive: true });
60
+ writeFileSync(join(directoryPath, "SKILL.md"), `# ${id}\n`);
61
+ return directoryPath;
62
+ }
63
+
64
+ beforeEach(() => {
65
+ // The read allowance only changes behavior where the boundary is hard: on
66
+ // non-containerized installs out-of-workspace reads already fall back to
67
+ // host-style validation.
68
+ process.env.IS_CONTAINERIZED = "true";
69
+ });
70
+
71
+ afterEach(() => {
72
+ delete process.env.IS_CONTAINERIZED;
73
+ delete process.env.GATEWAY_SECURITY_DIR;
74
+ for (const dir of testDirs.splice(0)) {
75
+ rmSync(dir, { recursive: true, force: true });
76
+ }
77
+ });
78
+
79
+ describe("file_read outside the workspace in a container", () => {
80
+ test("reads a reference file from the install tree", async () => {
81
+ const workspace = makeTempDir("container-workspace-");
82
+ const skillDir = makeInstalledSkill("image-studio");
83
+ const referencePath = join(skillDir, "references", "guide.md");
84
+ writeFileSync(referencePath, "# Guide\nreference body\n");
85
+
86
+ const result = await fileReadTool.execute(
87
+ { path: referencePath },
88
+ makeContext(workspace),
89
+ );
90
+
91
+ expect(result.isError).toBe(false);
92
+ expect(result.content).toContain("reference body");
93
+ });
94
+
95
+ test("denies the service security directory", async () => {
96
+ const workspace = makeTempDir("container-workspace-");
97
+ const securityDir = makeTempDir("container-security-");
98
+ writeFileSync(join(securityDir, "trust.json"), "trust body\n");
99
+ process.env.GATEWAY_SECURITY_DIR = securityDir;
100
+
101
+ const result = await fileReadTool.execute(
102
+ { path: join(securityDir, "trust.json") },
103
+ makeContext(workspace),
104
+ );
105
+
106
+ expect(result.isError).toBe(true);
107
+ expect(result.content).toContain("service security directory");
108
+ expect(result.content).not.toContain("trust body");
109
+ });
110
+
111
+ test("denies the daemon's own process environment", async () => {
112
+ const workspace = makeTempDir("container-workspace-");
113
+
114
+ const result = await fileReadTool.execute(
115
+ { path: "/proc/self/environ" },
116
+ makeContext(workspace),
117
+ );
118
+
119
+ expect(result.isError).toBe(true);
120
+ expect(result.content).toContain("process environment");
121
+ });
122
+
123
+ test("denies file_write outside the workspace", async () => {
124
+ const workspace = makeTempDir("container-workspace-");
125
+ const skillDir = makeInstalledSkill("image-studio");
126
+ const targetPath = join(skillDir, "references", "injected.md");
127
+
128
+ const result = await fileWriteTool.execute(
129
+ { path: targetPath, content: "injected body\n" },
130
+ makeContext(workspace),
131
+ );
132
+
133
+ expect(result.isError).toBe(true);
134
+ expect(result.content).toContain("outside the working directory");
135
+ expect(existsSync(targetPath)).toBe(false);
136
+ });
137
+ });
@@ -103,16 +103,20 @@ describe("file_read tool (sandbox)", () => {
103
103
  expect(result.content).toContain("outside content");
104
104
  });
105
105
 
106
- test("rejects path traversal outside working dir when containerized", async () => {
106
+ test("reads a file outside the workspace boundary when containerized", async () => {
107
107
  const dir = makeTempDir();
108
+ const outside = makeTempDir();
109
+ const target = join(outside, "reference.md");
110
+ writeFileSync(target, "install tree content");
108
111
  process.env.IS_CONTAINERIZED = "true";
109
112
  try {
110
113
  const result = await fileReadTool.execute(
111
- { path: "../../../etc/passwd" },
114
+ { path: target },
112
115
  makeContext(dir),
113
116
  );
114
- expect(result.isError).toBe(true);
115
- expect(result.content).toContain("outside the working directory");
117
+
118
+ expect(result.isError).toBe(false);
119
+ expect(result.content).toContain("install tree content");
116
120
  } finally {
117
121
  delete process.env.IS_CONTAINERIZED;
118
122
  }
@@ -206,32 +210,40 @@ describe("file_read image support", () => {
206
210
  expect(result.content).toContain("Image loaded");
207
211
  });
208
212
 
209
- test("blocks image path traversal outside working dir when containerized", async () => {
213
+ test("reads an image outside the workspace boundary when containerized", async () => {
210
214
  const dir = makeTempDir();
215
+ const outside = makeTempDir();
216
+ writeFileSync(join(outside, "diagram.jpg"), JPEG_HEADER);
211
217
  process.env.IS_CONTAINERIZED = "true";
212
218
  try {
213
219
  const result = await fileReadTool.execute(
214
- { path: "../../etc/secret.png" },
220
+ { path: join(outside, "diagram.jpg") },
215
221
  makeContext(dir),
216
222
  );
217
223
 
218
- expect(result.isError).toBe(true);
219
- expect(result.content).toContain("outside the working directory");
224
+ expect(result.isError).toBe(false);
225
+ expect(result.content).toContain("Image loaded");
220
226
  } finally {
221
227
  delete process.env.IS_CONTAINERIZED;
222
228
  }
223
229
  });
224
230
  });
225
231
 
226
- // ── Out-of-bounds hint for host_file_read (containerized) ─────────────
232
+ // ── Out-of-bounds hint for host_file_read ─────────────────────────────
233
+ //
234
+ // Reads leave the workspace freely, so the boundary only holds when the
235
+ // service security deny set cannot be mirrored: a relative override resolves
236
+ // against the owning service's cwd, so the policy fails closed.
227
237
 
228
238
  describe("file_read out-of-bounds hint", () => {
229
239
  beforeEach(() => {
230
240
  process.env.IS_CONTAINERIZED = "true";
241
+ process.env.GATEWAY_SECURITY_DIR = "relative/security-dir";
231
242
  });
232
243
 
233
244
  afterEach(() => {
234
245
  delete process.env.IS_CONTAINERIZED;
246
+ delete process.env.GATEWAY_SECURITY_DIR;
235
247
  });
236
248
 
237
249
  test("suggests host_file_read for out-of-bounds text file path", async () => {
@@ -15,6 +15,7 @@ import {
15
15
  resolveRealPath,
16
16
  sandboxPolicy,
17
17
  sandboxPolicyWithHostFallback,
18
+ sandboxReadPolicy,
18
19
  } from "../tools/shared/filesystem/path-policy.js";
19
20
  import { getDotEnvPath } from "../util/platform.js";
20
21
 
@@ -506,6 +507,162 @@ describe("sandboxPolicyWithHostFallback", () => {
506
507
  });
507
508
  });
508
509
 
510
+ // ---------------------------------------------------------------------------
511
+ // Sandbox read policy
512
+ // ---------------------------------------------------------------------------
513
+
514
+ describe("sandboxReadPolicy", () => {
515
+ afterEach(() => {
516
+ delete process.env.IS_CONTAINERIZED;
517
+ delete process.env.GATEWAY_SECURITY_DIR;
518
+ delete process.env.CREDENTIAL_SECURITY_DIR;
519
+ });
520
+
521
+ test("matches sandboxPolicy for in-bounds paths", () => {
522
+ const boundary = makeTempDir();
523
+ mkdirSync(join(boundary, "sub"));
524
+
525
+ const result = sandboxReadPolicy("sub/file.txt", boundary);
526
+ expect(result).toEqual(sandboxPolicy("sub/file.txt", boundary));
527
+ expect(result.ok).toBe(true);
528
+ });
529
+
530
+ test("reads outside the boundary when containerized", () => {
531
+ const boundary = makeTempDir();
532
+ const installTree = makeTempDir();
533
+ const target = join(installTree, "SKILL.md");
534
+ writeFileSync(target, "# skill");
535
+ process.env.IS_CONTAINERIZED = "true";
536
+
537
+ const result = sandboxReadPolicy(target, boundary);
538
+ expect(result.ok).toBe(true);
539
+ if (result.ok) {
540
+ expect(result.resolved).toBe(target);
541
+ }
542
+ });
543
+
544
+ test("follows an in-boundary symlink that points outside", () => {
545
+ const boundary = makeTempDir();
546
+ const outside = makeTempDir();
547
+ const target = join(outside, "reference.md");
548
+ writeFileSync(target, "reference body");
549
+ symlinkSync(target, join(boundary, "link.md"));
550
+ process.env.IS_CONTAINERIZED = "true";
551
+
552
+ const result = sandboxReadPolicy(join(boundary, "link.md"), boundary);
553
+ expect(result.ok).toBe(true);
554
+ });
555
+
556
+ test("denies the gateway security dir when containerized", () => {
557
+ const boundary = makeTempDir();
558
+ const securityDir = makeTempDir();
559
+ writeFileSync(join(securityDir, "trust.json"), "{}");
560
+ process.env.GATEWAY_SECURITY_DIR = securityDir;
561
+ process.env.IS_CONTAINERIZED = "true";
562
+
563
+ const result = sandboxReadPolicy(join(securityDir, "trust.json"), boundary);
564
+ expect(result.ok).toBe(false);
565
+ if (!result.ok) {
566
+ expect(result.reason).toBe("denied");
567
+ }
568
+ });
569
+
570
+ test("denies a symlink that resolves into the credential security dir", () => {
571
+ const boundary = makeTempDir();
572
+ const securityDir = makeTempDir();
573
+ writeFileSync(join(securityDir, "keys.enc"), "cipher");
574
+ symlinkSync(join(securityDir, "keys.enc"), join(boundary, "innocent.txt"));
575
+ process.env.CREDENTIAL_SECURITY_DIR = securityDir;
576
+ process.env.IS_CONTAINERIZED = "true";
577
+
578
+ const result = sandboxReadPolicy(join(boundary, "innocent.txt"), boundary);
579
+ expect(result.ok).toBe(false);
580
+ if (!result.ok) {
581
+ expect(result.reason).toBe("denied");
582
+ }
583
+ });
584
+
585
+ test("denies a denylisted basename outside the boundary", () => {
586
+ const boundary = makeTempDir();
587
+ const outside = makeTempDir();
588
+ writeFileSync(join(outside, "backup.key"), "key");
589
+ process.env.IS_CONTAINERIZED = "true";
590
+
591
+ const result = sandboxReadPolicy(join(outside, "backup.key"), boundary);
592
+ expect(result.ok).toBe(false);
593
+ if (!result.ok) {
594
+ expect(result.reason).toBe("denied");
595
+ }
596
+ });
597
+
598
+ test("fails closed to the hard boundary when a security-dir override is relative", () => {
599
+ const boundary = makeTempDir();
600
+ const outside = makeTempDir();
601
+ writeFileSync(join(outside, "file.txt"), "x");
602
+ // Unmirrorable deny set: the real security dir could be anywhere, so the
603
+ // read allowance must not widen past the boundary.
604
+ process.env.GATEWAY_SECURITY_DIR = "relative/security-dir";
605
+ process.env.IS_CONTAINERIZED = "true";
606
+
607
+ const result = sandboxReadPolicy(join(outside, "file.txt"), boundary);
608
+ expect(result.ok).toBe(false);
609
+ if (!result.ok) {
610
+ expect(result.reason).toBe("out_of_bounds");
611
+ }
612
+ });
613
+
614
+ // The daemon's own environment carries the actor token signing key, the CES
615
+ // service token, the guardian bootstrap secret, and forwarded provider API
616
+ // keys, so no policy may serve a process environment block.
617
+ test.each([
618
+ "/proc/self/environ",
619
+ "/proc/thread-self/environ",
620
+ "/proc/1/environ",
621
+ "/proc/4242/environ",
622
+ ])("denies %s", (path) => {
623
+ const boundary = makeTempDir();
624
+ process.env.IS_CONTAINERIZED = "true";
625
+
626
+ const result = sandboxReadPolicy(path, boundary, { mustExist: false });
627
+ expect(result.ok).toBe(false);
628
+ if (!result.ok) {
629
+ expect(result.reason).toBe("denied");
630
+ }
631
+ });
632
+
633
+ test("denies a process environ path reached through a symlink", () => {
634
+ const boundary = makeTempDir();
635
+ symlinkSync("/proc/self/environ", join(boundary, "innocent.txt"));
636
+ process.env.IS_CONTAINERIZED = "true";
637
+
638
+ const result = sandboxReadPolicy(join(boundary, "innocent.txt"), boundary, {
639
+ mustExist: false,
640
+ });
641
+ expect(result.ok).toBe(false);
642
+ if (!result.ok) {
643
+ expect(result.reason).toBe("denied");
644
+ }
645
+ });
646
+
647
+ test("still allows other /proc entries", () => {
648
+ const boundary = makeTempDir();
649
+ process.env.IS_CONTAINERIZED = "true";
650
+
651
+ const result = sandboxReadPolicy("/proc/self/status", boundary, {
652
+ mustExist: false,
653
+ });
654
+ expect(result.ok).toBe(true);
655
+ });
656
+
657
+ test("does not deny an unrelated file named environ", () => {
658
+ const boundary = makeTempDir();
659
+ writeFileSync(join(boundary, "environ"), "notes");
660
+
661
+ const result = sandboxReadPolicy("environ", boundary);
662
+ expect(result.ok).toBe(true);
663
+ });
664
+ });
665
+
509
666
  // ---------------------------------------------------------------------------
510
667
  // Host policy
511
668
  // ---------------------------------------------------------------------------
@@ -575,7 +732,13 @@ describe("resolveRealPath", () => {
575
732
  });
576
733
 
577
734
  test("falls back to the lexical path when nothing on it exists", () => {
578
- const phantom = join(tmpdir(), "definitely-not-here-12345", "nope.txt");
735
+ // realpath the temp root so a symlinked prefix (macOS /var -> /private/var)
736
+ // is not mistaken for the resolution under test.
737
+ const phantom = join(
738
+ realpathSync(tmpdir()),
739
+ "definitely-not-here-12345",
740
+ "nope.txt",
741
+ );
579
742
  expect(resolveRealPath(phantom)).toBe(phantom);
580
743
  });
581
744
  });
@@ -58,6 +58,7 @@ import { BadRequestError, NotFoundError } from "../runtime/routes/errors.js";
58
58
  import { ROUTES as HEARTBEAT_ROUTES } from "../runtime/routes/heartbeat-routes.js";
59
59
  import { ROUTES as SCHEDULE_ROUTES } from "../runtime/routes/schedule-routes.js";
60
60
  import type { RouteDefinition } from "../runtime/routes/types.js";
61
+ import { resolveDefaultScheduleInferenceProfile } from "../schedule/inference-profile.js";
61
62
  import {
62
63
  completeScheduleRun,
63
64
  createSchedule,
@@ -1230,14 +1231,50 @@ describe("POST /schedules — create", () => {
1230
1231
  expect(listSchedules()[0].inferenceProfile).toBe("cost-optimized");
1231
1232
  });
1232
1233
 
1233
- test("defaults inferenceProfile to null when omitted", async () => {
1234
+ // The endpoint validates inferenceProfile once, before branching on mode, so
1235
+ // every mode it accepts has to honour the value it just validated.
1236
+ test("persists a valid inferenceProfile on a workflow-mode create", async () => {
1237
+ const result = await postCreate({
1238
+ name: "Cheap triage",
1239
+ description: "Workflow run on a cheap model",
1240
+ expression: "0 * * * *",
1241
+ message: "trigger",
1242
+ mode: "workflow",
1243
+ workflowName: "triage-inbox",
1244
+ inferenceProfile: "cost-optimized",
1245
+ });
1246
+ expect(result.schedule.inferenceProfile).toBe("cost-optimized");
1247
+ expect(listSchedules()[0].inferenceProfile).toBe("cost-optimized");
1248
+ });
1249
+
1250
+ test("persists a valid inferenceProfile on a script-mode create", async () => {
1251
+ const result = await postCreate({
1252
+ name: "Cheap script",
1253
+ description: "Script run on a cheap model",
1254
+ expression: "0 * * * *",
1255
+ message: "trigger",
1256
+ mode: "script",
1257
+ script: "console.log('hi')",
1258
+ inferenceProfile: "cost-optimized",
1259
+ });
1260
+ expect(result.schedule.inferenceProfile).toBe("cost-optimized");
1261
+ expect(listSchedules()[0].inferenceProfile).toBe("cost-optimized");
1262
+ });
1263
+
1264
+ test("pins inferenceProfile to the resolved default when omitted", async () => {
1265
+ const expected = resolveDefaultScheduleInferenceProfile();
1266
+ // A schedule that followed the global default would change model whenever
1267
+ // the user changed that default, so creation snapshots it instead.
1268
+ expect(expected).not.toBeNull();
1269
+
1234
1270
  const result = await postCreate({
1235
1271
  name: "Default profile",
1236
- description: "Runs on the main-agent selection",
1272
+ description: "Runs on the resolved default profile",
1237
1273
  expression: "0 9 * * *",
1238
1274
  message: "hi",
1239
1275
  });
1240
- expect(result.schedule.inferenceProfile).toBeNull();
1276
+ expect(result.schedule.inferenceProfile).toBe(expected!);
1277
+ expect(listSchedules()[0].inferenceProfile).toBe(expected!);
1241
1278
  });
1242
1279
 
1243
1280
  test("rejects an unknown inferenceProfile", async () => {
@@ -1296,7 +1333,10 @@ describe("PATCH /schedules/:id — description", () => {
1296
1333
  expect(listSchedules()[0].description).toBe("Updated description");
1297
1334
  });
1298
1335
 
1299
- test("sets, validates, and clears inferenceProfile", async () => {
1336
+ test("sets, validates, and re-snapshots inferenceProfile", async () => {
1337
+ const resolvedDefault = resolveDefaultScheduleInferenceProfile();
1338
+ expect(resolvedDefault).not.toBe("cost-optimized");
1339
+
1300
1340
  const schedule = await createSchedule({
1301
1341
  name: "Profile pin",
1302
1342
  description: "Pinned profile schedule",
@@ -1308,9 +1348,9 @@ describe("PATCH /schedules/:id — description", () => {
1308
1348
 
1309
1349
  await route.handler({
1310
1350
  pathParams: { id: schedule.id },
1311
- body: { inferenceProfile: "balanced" },
1351
+ body: { inferenceProfile: "cost-optimized" },
1312
1352
  });
1313
- expect(listSchedules()[0].inferenceProfile).toBe("balanced");
1353
+ expect(listSchedules()[0].inferenceProfile).toBe("cost-optimized");
1314
1354
 
1315
1355
  await expect(
1316
1356
  route.handler({
@@ -1318,13 +1358,14 @@ describe("PATCH /schedules/:id — description", () => {
1318
1358
  body: { inferenceProfile: "does-not-exist" },
1319
1359
  }),
1320
1360
  ).rejects.toThrow('Inference profile "does-not-exist" is not defined');
1321
- expect(listSchedules()[0].inferenceProfile).toBe("balanced");
1361
+ expect(listSchedules()[0].inferenceProfile).toBe("cost-optimized");
1322
1362
 
1363
+ // Null is a reset to the current default, not an unpin.
1323
1364
  await route.handler({
1324
1365
  pathParams: { id: schedule.id },
1325
1366
  body: { inferenceProfile: null },
1326
1367
  });
1327
- expect(listSchedules()[0].inferenceProfile).toBeNull();
1368
+ expect(listSchedules()[0].inferenceProfile).toBe(resolvedDefault);
1328
1369
  });
1329
1370
 
1330
1371
  test("re-derives syntax when the expression switches cron to rrule", async () => {
@@ -14,6 +14,11 @@ mock.module("../background-wake/publisher.js", () => ({
14
14
 
15
15
  import type { AssistantEventEnvelope } from "../api/index.js";
16
16
  import { SYNC_TAGS } from "../daemon/message-types/sync.js";
17
+ import {
18
+ createConversation,
19
+ setConversationInferenceProfile,
20
+ setConversationInferenceProfileSession,
21
+ } from "../persistence/conversation-crud.js";
17
22
  import { getDb } from "../persistence/db-connection.js";
18
23
  import { initializeDb } from "../persistence/db-init.js";
19
24
  import { assistantEventHub } from "../runtime/assistant-event-hub.js";
@@ -22,6 +27,7 @@ import {
22
27
  LEGACY_DEFER_CREATED_BY,
23
28
  OWNER_DEFER_CREATED_BY,
24
29
  } from "../schedule/defer-provenance.js";
30
+ import { resolveDefaultScheduleInferenceProfile } from "../schedule/inference-profile.js";
25
31
  import {
26
32
  cancelSchedule,
27
33
  claimDueSchedules,
@@ -1506,3 +1512,135 @@ describe("owner-defer provenance", () => {
1506
1512
  expect(hasOwnerDeferProvenance(updated!.createdBy)).toBe(false);
1507
1513
  });
1508
1514
  });
1515
+
1516
+ // ── Inference-profile pinning ─────────────────────────────────────────────
1517
+
1518
+ /**
1519
+ * Every assertion below compares against the live resolution rather than a
1520
+ * literal key, so the tests describe the invariant (a schedule is pinned to
1521
+ * whatever the default resolves to at write time) instead of freezing this
1522
+ * workspace's shipped profile catalog.
1523
+ */
1524
+ describe("inference-profile pinning", () => {
1525
+ beforeEach(() => {
1526
+ getDb().run("DELETE FROM cron_runs");
1527
+ getDb().run("DELETE FROM cron_jobs");
1528
+ getDb().run("DELETE FROM conversations");
1529
+ });
1530
+
1531
+ test("creation with no profile pins the resolved default", async () => {
1532
+ const expected = resolveDefaultScheduleInferenceProfile();
1533
+ expect(expected).not.toBeNull();
1534
+
1535
+ const job = await createSchedule({
1536
+ name: "Unpinned",
1537
+ message: "hi",
1538
+ cronExpression: "0 9 * * *",
1539
+ });
1540
+
1541
+ expect(job.inferenceProfile).toBe(expected!);
1542
+ expect(getSchedule(job.id)!.inferenceProfile).toBe(expected!);
1543
+ });
1544
+
1545
+ test("creation with an explicit profile keeps it", async () => {
1546
+ expect(resolveDefaultScheduleInferenceProfile()).not.toBe("cost-optimized");
1547
+
1548
+ const job = await createSchedule({
1549
+ name: "Pinned",
1550
+ message: "hi",
1551
+ cronExpression: "0 9 * * *",
1552
+ inferenceProfile: "cost-optimized",
1553
+ });
1554
+
1555
+ expect(job.inferenceProfile).toBe("cost-optimized");
1556
+ });
1557
+
1558
+ test("updating to null re-snapshots the default instead of unpinning", async () => {
1559
+ const job = await createSchedule({
1560
+ name: "Repinned",
1561
+ message: "hi",
1562
+ cronExpression: "0 9 * * *",
1563
+ inferenceProfile: "cost-optimized",
1564
+ });
1565
+
1566
+ const updated = await updateSchedule(job.id, { inferenceProfile: null });
1567
+
1568
+ expect(updated!.inferenceProfile).toBe(
1569
+ resolveDefaultScheduleInferenceProfile()!,
1570
+ );
1571
+ });
1572
+
1573
+ test("a defer seeds the source conversation's pinned profile", async () => {
1574
+ const conversation = createConversation({ id: "conv-pinned" });
1575
+ setConversationInferenceProfile(conversation.id, "cost-optimized");
1576
+ expect(resolveDefaultScheduleInferenceProfile()).not.toBe("cost-optimized");
1577
+
1578
+ const job = await createOwnerDeferredWake({
1579
+ conversationId: conversation.id,
1580
+ hint: "check back",
1581
+ fireAt: Date.now() + 60_000,
1582
+ });
1583
+
1584
+ // The wake resumes this conversation and forces the row's pin as the
1585
+ // turn's override, so seeding from the global default would move a pinned
1586
+ // conversation's own follow-up onto a different model.
1587
+ expect(job.inferenceProfile).toBe("cost-optimized");
1588
+ });
1589
+
1590
+ test("a defer does not freeze the source conversation's profile session", async () => {
1591
+ const conversation = createConversation({ id: "conv-session" });
1592
+ setConversationInferenceProfileSession(
1593
+ conversation.id,
1594
+ "cost-optimized",
1595
+ "session-1",
1596
+ Date.now() + 10 * 60_000,
1597
+ );
1598
+
1599
+ const job = await createOwnerDeferredWake({
1600
+ conversationId: conversation.id,
1601
+ hint: "check back",
1602
+ fireAt: Date.now() + 7 * 24 * 60 * 60_000,
1603
+ });
1604
+
1605
+ // A profile session is a deliberately temporary choice. Snapshotting it
1606
+ // into the row would keep billing that model every time the wake fires,
1607
+ // long after the ten-minute session lapsed.
1608
+ expect(job.inferenceProfile).toBe(
1609
+ resolveDefaultScheduleInferenceProfile()!,
1610
+ );
1611
+ });
1612
+
1613
+ test("a defer from an unpinned conversation seeds the default", async () => {
1614
+ const conversation = createConversation({ id: "conv-unpinned" });
1615
+
1616
+ const job = await createOwnerDeferredWake({
1617
+ conversationId: conversation.id,
1618
+ hint: "check back",
1619
+ fireAt: Date.now() + 60_000,
1620
+ });
1621
+
1622
+ expect(job.inferenceProfile).toBe(
1623
+ resolveDefaultScheduleInferenceProfile()!,
1624
+ );
1625
+ });
1626
+
1627
+ test("any wake row seeds its target's pin, not just a defer", async () => {
1628
+ const conversation = createConversation({ id: "conv-wake-target" });
1629
+ setConversationInferenceProfile(conversation.id, "cost-optimized");
1630
+ expect(resolveDefaultScheduleInferenceProfile()).not.toBe("cost-optimized");
1631
+
1632
+ // Seeding is keyed on `mode: "wake"` at the insert chokepoint rather than
1633
+ // on defer provenance: every wake row forces its pin as the woken turn's
1634
+ // override, so a wake minted any other way must not flatten its target's
1635
+ // choice onto the global default either.
1636
+ const job = await createSchedule({
1637
+ name: "Wake pinned conversation",
1638
+ message: "resume",
1639
+ nextRunAt: Date.now() + 60_000,
1640
+ mode: "wake",
1641
+ wakeConversationId: conversation.id,
1642
+ });
1643
+
1644
+ expect(job.inferenceProfile).toBe("cost-optimized");
1645
+ });
1646
+ });