@vellumai/assistant 0.11.2-dev.202608052227.261a826 → 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.
Files changed (33) hide show
  1. package/openapi.yaml +10 -5
  2. package/package.json +1 -1
  3. package/src/__tests__/conversation-agent-loop.test.ts +87 -0
  4. package/src/__tests__/file-read-container-boundary.test.ts +137 -0
  5. package/src/__tests__/file-read-tool.test.ts +21 -9
  6. package/src/__tests__/path-policy.test.ts +164 -1
  7. package/src/__tests__/profile-availability-incomplete.test.ts +113 -0
  8. package/src/__tests__/scaffold-managed-skill-tool.test.ts +166 -0
  9. package/src/__tests__/schedule-routes.test.ts +49 -8
  10. package/src/__tests__/schedule-store.test.ts +138 -0
  11. package/src/__tests__/scheduler-wake.test.ts +5 -0
  12. package/src/cli/commands/schedules.help.ts +14 -12
  13. package/src/cli/commands/schedules.ts +7 -2
  14. package/src/config/bundled-skills/schedule/SKILL.md +3 -1
  15. package/src/config/bundled-skills/schedule/TOOLS.json +2 -2
  16. package/src/daemon/conversation-agent-loop.ts +53 -29
  17. package/src/persistence/conversation-crud.ts +44 -0
  18. package/src/persistence/migrations/363-backfill-schedule-inference-profile.test.ts +229 -0
  19. package/src/persistence/migrations/363-backfill-schedule-inference-profile.ts +127 -0
  20. package/src/persistence/steps.ts +9 -0
  21. package/src/providers/inference/connection-availability.ts +48 -11
  22. package/src/runtime/routes/__tests__/conversation-management-routes.test.ts +57 -6
  23. package/src/runtime/routes/default-provider-routes.ts +7 -11
  24. package/src/runtime/routes/inference-profile-availability-guard.ts +6 -0
  25. package/src/runtime/routes/inference-profiles-routes.ts +2 -9
  26. package/src/runtime/routes/schedule-routes.ts +6 -4
  27. package/src/schedule/inference-profile.ts +64 -3
  28. package/src/schedule/schedule-store.ts +45 -6
  29. package/src/tools/filesystem/read.ts +4 -10
  30. package/src/tools/schedule/list.ts +2 -1
  31. package/src/tools/schedule/update.ts +10 -6
  32. package/src/tools/shared/filesystem/path-policy.ts +70 -5
  33. package/src/tools/skills/scaffold-managed.ts +82 -0
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
@@ -34596,13 +34599,14 @@ components:
34596
34599
  type: string
34597
34600
  enum:
34598
34601
  - ok
34599
- - missing_default
34602
+ - incomplete
34600
34603
  - missing_connection
34601
34604
  - missing_credential
34602
34605
  - provider_mismatch
34603
34606
  - unsupported_auth
34604
34607
  - vellum_unauthenticated
34605
34608
  - unknown
34609
+ - missing_default
34606
34610
  message:
34607
34611
  type: string
34608
34612
  required:
@@ -34828,6 +34832,7 @@ components:
34828
34832
  type: string
34829
34833
  enum:
34830
34834
  - ok
34835
+ - incomplete
34831
34836
  - missing_connection
34832
34837
  - missing_credential
34833
34838
  - provider_mismatch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.11.2-dev.202608052227.261a826",
3
+ "version": "0.11.2-dev.202608052357.8f326c2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -782,6 +782,7 @@ function makeCtx(
782
782
  channelCapabilities: undefined,
783
783
  commandIntent: undefined,
784
784
  trustContext: undefined,
785
+ toolsDisabledDepth: 0,
785
786
 
786
787
  allowedToolNames: undefined,
787
788
  preactivatedSkillIds: undefined,
@@ -1187,6 +1188,92 @@ describe("session-agent-loop", () => {
1187
1188
  runAgentLoopImpl(ctx, "hello", "msg-1", () => {}),
1188
1189
  ).rejects.toThrow("runAgentLoop called without prior persistUserMessage");
1189
1190
  });
1191
+
1192
+ test("defers workspace Git work when tools are disabled", async () => {
1193
+ const ensureInitialized = mock(async () => {});
1194
+ const commitTurnChanges = mock(async () => {});
1195
+ const ctx = makeCtx({
1196
+ toolsDisabledDepth: 1,
1197
+ getWorkspaceGitService: () => ({ ensureInitialized }),
1198
+ commitTurnChanges,
1199
+ });
1200
+
1201
+ await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
1202
+
1203
+ expect(ensureInitialized).not.toHaveBeenCalled();
1204
+ expect(commitTurnChanges).not.toHaveBeenCalled();
1205
+
1206
+ await new Promise<void>((resolve) => setImmediate(resolve));
1207
+
1208
+ expect(commitTurnChanges).toHaveBeenCalledTimes(1);
1209
+ });
1210
+
1211
+ test("leaves a deferred commit to an immediate follow-up turn", async () => {
1212
+ const commitTurnChanges = mock(async () => {});
1213
+ const ctx = makeCtx({
1214
+ toolsDisabledDepth: 1,
1215
+ commitTurnChanges,
1216
+ });
1217
+
1218
+ await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
1219
+ ctx.setProcessing(true);
1220
+ await new Promise<void>((resolve) => setImmediate(resolve));
1221
+
1222
+ expect(commitTurnChanges).not.toHaveBeenCalled();
1223
+ ctx.setProcessing(false);
1224
+ });
1225
+
1226
+ test("initializes workspace Git before hooks when tools can run", async () => {
1227
+ let initialized = false;
1228
+ const ensureInitialized = mock(async () => {
1229
+ initialized = true;
1230
+ });
1231
+ const commitTurnChanges = mock(async () => {});
1232
+ const initializedDuringHook: boolean[] = [];
1233
+ registerPlugin({
1234
+ manifest: {
1235
+ name: "test-workspace-git-ready-before-hook",
1236
+ version: "1.0.0",
1237
+ },
1238
+ hooks: {
1239
+ "user-prompt-submit": async () => {
1240
+ initializedDuringHook.push(initialized);
1241
+ },
1242
+ },
1243
+ });
1244
+ const ctx = makeCtx({
1245
+ getWorkspaceGitService: () => ({ ensureInitialized }),
1246
+ commitTurnChanges,
1247
+ });
1248
+
1249
+ await runAgentLoopImpl(ctx, "hello", "msg-1", () => {});
1250
+
1251
+ expect(ensureInitialized).toHaveBeenCalledTimes(1);
1252
+ expect(commitTurnChanges).toHaveBeenCalledTimes(1);
1253
+ expect(initializedDuringHook).toEqual([true]);
1254
+ });
1255
+
1256
+ test("continues a tool-capable turn when workspace Git initialization fails", async () => {
1257
+ const ensureInitialized = mock(async () => {
1258
+ throw new Error("simulated Git initialization failure");
1259
+ });
1260
+ const events: AssistantEvent[] = [];
1261
+ const ctx = makeCtx({
1262
+ getWorkspaceGitService: () => ({ ensureInitialized }),
1263
+ });
1264
+
1265
+ await runAgentLoopImpl(ctx, "hello", "msg-1", (event) =>
1266
+ events.push(event),
1267
+ );
1268
+
1269
+ expect(ensureInitialized).toHaveBeenCalledTimes(1);
1270
+ expect(events.some((event) => event.type === "message_complete")).toBe(
1271
+ true,
1272
+ );
1273
+ expect(events.some((event) => event.type === "conversation_error")).toBe(
1274
+ false,
1275
+ );
1276
+ });
1190
1277
  });
1191
1278
 
1192
1279
  describe("disk pressure injection context", () => {
@@ -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
  });
@@ -0,0 +1,113 @@
1
+ /**
2
+ * `computeProfileAvailability` on profiles that carry no dispatchable pair.
3
+ *
4
+ * A rung only wins if its profile carries both a provider and a model
5
+ * (`usableEntry` in config/llm-resolver.ts). A profile missing either is
6
+ * skipped and the call site resolves elsewhere, so the profiles read has to
7
+ * report that state rather than returning "nothing to judge", which clients
8
+ * render as healthy.
9
+ */
10
+
11
+ import { describe, expect, test } from "bun:test";
12
+
13
+ import {
14
+ computeProfileAvailability,
15
+ isUnavailable,
16
+ } from "../providers/inference/connection-availability.js";
17
+ import { describeUnavailableProfile } from "../runtime/routes/inference-profile-availability-guard.js";
18
+
19
+ describe("incomplete profiles", () => {
20
+ test("no provider and no model reports both as missing", async () => {
21
+ const availability = await computeProfileAvailability({});
22
+ expect(availability?.status).toBe("incomplete");
23
+ expect(availability?.message).toContain("a provider and a model");
24
+ });
25
+
26
+ test("a model with no provider names the provider", async () => {
27
+ const availability = await computeProfileAvailability({
28
+ model: "claude-opus-5",
29
+ });
30
+ expect(availability?.status).toBe("incomplete");
31
+ expect(availability?.message).toContain("a provider");
32
+ expect(availability?.message).not.toContain("a provider and a model");
33
+ });
34
+
35
+ test("a provider with no model names the model", async () => {
36
+ const availability = await computeProfileAvailability({
37
+ provider: "anthropic",
38
+ });
39
+ expect(availability?.status).toBe("incomplete");
40
+ expect(availability?.message).toContain("a model");
41
+ });
42
+
43
+ // The destination is deliberately unnamed: which profile a call site falls
44
+ // back to depends on the call site, so the message states the effect only.
45
+ test("the message names the effect without naming a destination", async () => {
46
+ const availability = await computeProfileAvailability({});
47
+ expect(availability?.message).toContain("fall back to another profile");
48
+ });
49
+ });
50
+
51
+ describe("mix profiles", () => {
52
+ // A mix carries no provider or model of its own: the resolver expands it to
53
+ // a seeded arm and judges that arm. Reporting a mix as incomplete would put
54
+ // a warning on every working mix profile.
55
+ test("a mix still reports nothing to judge", async () => {
56
+ const availability = await computeProfileAvailability({
57
+ mix: [
58
+ { profile: "balanced", weight: 1 },
59
+ { profile: "quality", weight: 1 },
60
+ ],
61
+ });
62
+ expect(availability).toBeNull();
63
+ });
64
+
65
+ test("a mix that also names a provider and model is judged normally", async () => {
66
+ const availability = await computeProfileAvailability({
67
+ mix: [{ profile: "balanced", weight: 1 }],
68
+ provider: "anthropic",
69
+ model: "claude-opus-5",
70
+ });
71
+ expect(availability?.status).not.toBe("incomplete");
72
+ });
73
+ });
74
+
75
+ describe("selection guards", () => {
76
+ // The resolver skips an incomplete profile on every turn, so pinning one
77
+ // means the user's selection is not what runs. Before `incomplete` existed,
78
+ // a provider without a model reached the auto-resolve branch and could
79
+ // return `missing_connection`, which these guards already rejected; the new
80
+ // verdict has to keep that door shut rather than open it.
81
+ test("an incomplete profile counts as unavailable", async () => {
82
+ expect(isUnavailable(await computeProfileAvailability({}))).toBe(true);
83
+ expect(
84
+ isUnavailable(
85
+ await computeProfileAvailability({ provider: "anthropic" }),
86
+ ),
87
+ ).toBe(true);
88
+ });
89
+
90
+ test("a mix is still not judged, so it is not blocked", async () => {
91
+ expect(
92
+ isUnavailable(
93
+ await computeProfileAvailability({
94
+ mix: [{ profile: "balanced", weight: 1 }],
95
+ }),
96
+ ),
97
+ ).toBe(false);
98
+ });
99
+
100
+ // `describeUnavailableProfile` interpolates the provider, which an
101
+ // incomplete profile may not have. Its guidance must not leak "undefined".
102
+ test("the repair guidance names the fix without inventing a provider", async () => {
103
+ const availability = await computeProfileAvailability({});
104
+ const message = await describeUnavailableProfile({
105
+ availability: availability!,
106
+ provider: String(undefined),
107
+ repair: { kind: "repoint", profileName: "half-made" },
108
+ escapeHatch: false,
109
+ });
110
+ expect(message).not.toContain("undefined");
111
+ expect(message).toContain("provider and a model");
112
+ });
113
+ });