@vellumai/cli 0.8.2 → 0.8.4

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.
@@ -0,0 +1,206 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import {
4
+ type FetchLike,
5
+ HOST_IMAGE_LOADER_URL,
6
+ HostImageLoaderError,
7
+ isLocalBuildRef,
8
+ loadImageViaHost,
9
+ } from "../lib/host-image-loader.js";
10
+
11
+ describe("HOST_IMAGE_LOADER_URL", () => {
12
+ test("resolves to the well-known image-loader port/path", () => {
13
+ expect(HOST_IMAGE_LOADER_URL).toBe("http://127.0.0.1:5500/v1/images/load");
14
+ });
15
+ });
16
+
17
+ describe("isLocalBuildRef", () => {
18
+ test("recognizes the `vellum-local/` prefix as a local build", () => {
19
+ expect(isLocalBuildRef("vellum-local/assistant-server:sha-abc123")).toBe(
20
+ true,
21
+ );
22
+ expect(isLocalBuildRef("vellum-local/gateway:sha-def")).toBe(true);
23
+ });
24
+
25
+ test("treats external registry refs as pullable", () => {
26
+ expect(isLocalBuildRef("docker.io/example/image:v0.8.2")).toBe(false);
27
+ expect(
28
+ isLocalBuildRef("us-east1-docker.pkg.dev/example/image@sha256:deadbeef"),
29
+ ).toBe(false);
30
+ expect(isLocalBuildRef("postgres:17")).toBe(false);
31
+ });
32
+ });
33
+
34
+ function silentLog(_msg: string): void {
35
+ // intentionally swallow logs in test
36
+ }
37
+
38
+ function makeFetch(
39
+ responses: Array<{ url: string; body: unknown; status: number }>,
40
+ recordedRequests: Array<{ url: string; body: unknown }>,
41
+ ): FetchLike {
42
+ return async (input, init) => {
43
+ const url = typeof input === "string" ? input : input.toString();
44
+ const body = init?.body ? JSON.parse(init.body) : null;
45
+ recordedRequests.push({ url, body });
46
+ const planned = responses.shift();
47
+ if (!planned) throw new Error(`unexpected request to ${url}`);
48
+ return new Response(JSON.stringify(planned.body), {
49
+ status: planned.status,
50
+ headers: { "Content-Type": "application/json" },
51
+ });
52
+ };
53
+ }
54
+
55
+ describe("loadImageViaHost", () => {
56
+ test("POSTs {ref} to the URL and resolves on 200", async () => {
57
+ const recorded: Array<{ url: string; body: unknown }> = [];
58
+ const fetchImpl = makeFetch(
59
+ [
60
+ {
61
+ url: "http://127.0.0.1:5500/v1/images/load",
62
+ body: {
63
+ loaded: true,
64
+ ref: "vellum-local/assistant:sha-abc",
65
+ },
66
+ status: 200,
67
+ },
68
+ ],
69
+ recorded,
70
+ );
71
+
72
+ await loadImageViaHost(
73
+ "http://127.0.0.1:5500/v1/images/load",
74
+ "vellum-local/assistant:sha-abc",
75
+ silentLog,
76
+ { fetchImpl },
77
+ );
78
+
79
+ expect(recorded).toHaveLength(1);
80
+ expect(recorded[0].url).toBe("http://127.0.0.1:5500/v1/images/load");
81
+ expect(recorded[0].body).toEqual({
82
+ ref: "vellum-local/assistant:sha-abc",
83
+ });
84
+ });
85
+
86
+ test("throws HostImageLoaderError with status when server returns non-2xx", async () => {
87
+ const recorded: Array<{ url: string; body: unknown }> = [];
88
+ const fetchImpl = makeFetch(
89
+ [
90
+ {
91
+ url: "http://127.0.0.1:5500/v1/images/load",
92
+ body: { loaded: false, error: "docker save failed: image not found" },
93
+ status: 502,
94
+ },
95
+ ],
96
+ recorded,
97
+ );
98
+
99
+ await expect(
100
+ loadImageViaHost(
101
+ "http://127.0.0.1:5500/v1/images/load",
102
+ "vellum-local/nope:abc",
103
+ silentLog,
104
+ { fetchImpl },
105
+ ),
106
+ ).rejects.toBeInstanceOf(HostImageLoaderError);
107
+
108
+ // Re-run to inspect fields (one-shot fetchImpl, so build a new one)
109
+ const recorded2: Array<{ url: string; body: unknown }> = [];
110
+ const fetchImpl2 = makeFetch(
111
+ [
112
+ {
113
+ url: "http://127.0.0.1:5500/v1/images/load",
114
+ body: { loaded: false, error: "docker save failed: image not found" },
115
+ status: 502,
116
+ },
117
+ ],
118
+ recorded2,
119
+ );
120
+
121
+ let caught: HostImageLoaderError | null = null;
122
+ try {
123
+ await loadImageViaHost(
124
+ "http://127.0.0.1:5500/v1/images/load",
125
+ "vellum-local/nope:abc",
126
+ silentLog,
127
+ { fetchImpl: fetchImpl2 },
128
+ );
129
+ } catch (err) {
130
+ caught = err as HostImageLoaderError;
131
+ }
132
+ expect(caught).not.toBeNull();
133
+ expect(caught?.status).toBe(502);
134
+ expect(caught?.ref).toBe("vellum-local/nope:abc");
135
+ expect(caught?.message).toContain("502");
136
+ expect(caught?.message).toContain("docker save failed");
137
+ });
138
+
139
+ test("provides helpful guidance when the loader is unreachable", async () => {
140
+ const fetchImpl: FetchLike = async () => {
141
+ const err = new TypeError("fetch failed") as TypeError & {
142
+ cause?: { code?: string };
143
+ };
144
+ err.cause = { code: "ECONNREFUSED" };
145
+ throw err;
146
+ };
147
+
148
+ let caught: HostImageLoaderError | null = null;
149
+ try {
150
+ await loadImageViaHost(
151
+ "http://127.0.0.1:5500/v1/images/load",
152
+ "vellum-local/anything:xyz",
153
+ silentLog,
154
+ { fetchImpl },
155
+ );
156
+ } catch (err) {
157
+ caught = err as HostImageLoaderError;
158
+ }
159
+ expect(caught).not.toBeNull();
160
+ expect(caught?.message).toContain("loader running");
161
+ expect(caught?.message).toContain("VELLUM_ASSISTANT_IMAGE");
162
+ });
163
+
164
+ test("wraps generic fetch errors", async () => {
165
+ const fetchImpl: FetchLike = async () => {
166
+ throw new Error("ETIMEDOUT");
167
+ };
168
+
169
+ let caught: HostImageLoaderError | null = null;
170
+ try {
171
+ await loadImageViaHost(
172
+ "http://127.0.0.1:5500/v1/images/load",
173
+ "x",
174
+ silentLog,
175
+ { fetchImpl },
176
+ );
177
+ } catch (err) {
178
+ caught = err as HostImageLoaderError;
179
+ }
180
+ expect(caught).not.toBeNull();
181
+ expect(caught?.message).toContain("ETIMEDOUT");
182
+ });
183
+
184
+ test("handles non-JSON error bodies", async () => {
185
+ const fetchImpl: FetchLike = async () =>
186
+ new Response("<html>500 internal</html>", {
187
+ status: 500,
188
+ headers: { "Content-Type": "text/html" },
189
+ });
190
+
191
+ let caught: HostImageLoaderError | null = null;
192
+ try {
193
+ await loadImageViaHost(
194
+ "http://127.0.0.1:5500/v1/images/load",
195
+ "x",
196
+ silentLog,
197
+ { fetchImpl },
198
+ );
199
+ } catch (err) {
200
+ caught = err as HostImageLoaderError;
201
+ }
202
+ expect(caught).not.toBeNull();
203
+ expect(caught?.status).toBe(500);
204
+ expect(caught?.message).toContain("HTTP 500");
205
+ });
206
+ });
@@ -1,4 +1,12 @@
1
- import { afterAll, afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
1
+ import {
2
+ afterAll,
3
+ afterEach,
4
+ beforeEach,
5
+ describe,
6
+ expect,
7
+ spyOn,
8
+ test,
9
+ } from "bun:test";
2
10
  import { mkdtempSync, rmSync } from "node:fs";
3
11
  import { tmpdir } from "node:os";
4
12
  import { join } from "node:path";
@@ -16,6 +24,7 @@ process.env.VELLUM_LOCKFILE_DIR = testDir;
16
24
  // ---------------------------------------------------------------------------
17
25
 
18
26
  import * as assistantConfig from "../lib/assistant-config.js";
27
+ import * as healthCheck from "../lib/health-check.js";
19
28
  import * as orphanDetection from "../lib/orphan-detection.js";
20
29
  import * as platformClient from "../lib/platform-client.js";
21
30
 
@@ -57,6 +66,10 @@ const fetchPlatformAssistantsMock = spyOn(
57
66
  platformClient,
58
67
  "fetchPlatformAssistants",
59
68
  ).mockResolvedValue([]);
69
+ const checkManagedHealthMock = spyOn(
70
+ healthCheck,
71
+ "checkManagedHealth",
72
+ ).mockResolvedValue({ status: "healthy", detail: null });
60
73
 
61
74
  // ---------------------------------------------------------------------------
62
75
  // stdout / stderr capture
@@ -66,23 +79,32 @@ let stdout: string[];
66
79
  let stderr: string[];
67
80
  let originalLog: typeof console.log;
68
81
  let originalError: typeof console.error;
82
+ let originalStdoutWrite: typeof process.stdout.write;
69
83
 
70
84
  beforeEach(() => {
71
85
  stdout = [];
72
86
  stderr = [];
73
87
  originalLog = console.log;
74
88
  originalError = console.error;
89
+ originalStdoutWrite = process.stdout.write;
75
90
  console.log = ((...args: unknown[]) => {
76
91
  stdout.push(args.map((a) => String(a)).join(" "));
77
92
  }) as typeof console.log;
78
93
  console.error = ((...args: unknown[]) => {
79
94
  stderr.push(args.map((a) => String(a)).join(" "));
80
95
  }) as typeof console.error;
96
+ process.stdout.write = ((chunk: string | Uint8Array) => {
97
+ stdout.push(String(chunk));
98
+ return true;
99
+ }) as typeof process.stdout.write;
81
100
  });
82
101
 
83
102
  afterEach(() => {
84
103
  console.log = originalLog;
85
104
  console.error = originalError;
105
+ process.stdout.write = originalStdoutWrite;
106
+ loadAllAssistantsMock.mockReturnValue([]);
107
+ getActiveAssistantMock.mockReturnValue(null);
86
108
  readPlatformTokenMock.mockReturnValue(null);
87
109
  fetchCurrentUserMock.mockReset();
88
110
  fetchCurrentUserMock.mockResolvedValue({
@@ -92,6 +114,8 @@ afterEach(() => {
92
114
  });
93
115
  fetchPlatformAssistantsMock.mockReset();
94
116
  fetchPlatformAssistantsMock.mockResolvedValue([]);
117
+ checkManagedHealthMock.mockReset();
118
+ checkManagedHealthMock.mockResolvedValue({ status: "healthy", detail: null });
95
119
  });
96
120
 
97
121
  afterAll(() => {
@@ -102,6 +126,7 @@ afterAll(() => {
102
126
  readPlatformTokenMock.mockRestore();
103
127
  fetchCurrentUserMock.mockRestore();
104
128
  fetchPlatformAssistantsMock.mockRestore();
129
+ checkManagedHealthMock.mockRestore();
105
130
  rmSync(testDir, { recursive: true, force: true });
106
131
  });
107
132
 
@@ -125,12 +150,12 @@ describe("vellum ps — platform status line", () => {
125
150
  expect(stdout.filter((l) => l.startsWith("Platform:"))).toEqual([
126
151
  "Platform: not logged in",
127
152
  ]);
128
- expect(
129
- stderr.some((l) => l.includes("Failed to fetch organization")),
130
- ).toBe(false);
131
- expect(
132
- stdout.some((l) => l.includes("Failed to fetch organization")),
133
- ).toBe(false);
153
+ expect(stderr.some((l) => l.includes("Failed to fetch organization"))).toBe(
154
+ false,
155
+ );
156
+ expect(stdout.some((l) => l.includes("Failed to fetch organization"))).toBe(
157
+ false,
158
+ );
134
159
 
135
160
  // Structural guarantee: we never even tried to talk to the platform.
136
161
  expect(fetchCurrentUserMock).not.toHaveBeenCalled();
@@ -152,31 +177,84 @@ describe("vellum ps — platform status line", () => {
152
177
  expect(stdout.filter((l) => l.startsWith("Platform:"))).toEqual([
153
178
  "Platform: not logged in",
154
179
  ]);
155
- expect(
156
- stderr.some((l) => l.includes("Failed to fetch organization")),
157
- ).toBe(false);
158
- expect(
159
- stdout.some((l) => l.includes("Failed to fetch organization")),
160
- ).toBe(false);
161
- expect(
162
- stderr.some((l) => l.includes("Unable to connect")),
163
- ).toBe(false);
180
+ expect(stderr.some((l) => l.includes("Failed to fetch organization"))).toBe(
181
+ false,
182
+ );
183
+ expect(stdout.some((l) => l.includes("Failed to fetch organization"))).toBe(
184
+ false,
185
+ );
186
+ expect(stderr.some((l) => l.includes("Unable to connect"))).toBe(false);
164
187
  });
165
188
 
166
189
  test("local token present and platform reachable: prints 'Platform: logged in as <email>'", async () => {
167
190
  readPlatformTokenMock.mockReturnValue("session_abc123");
168
191
  fetchCurrentUserMock.mockResolvedValue({
169
192
  id: "u1",
170
- email: "vargas@vellum.ai",
171
- display: "Vargas",
193
+ email: "user@example.com",
194
+ display: "Example User",
172
195
  });
173
196
  fetchPlatformAssistantsMock.mockResolvedValue([]);
174
197
 
175
198
  await listAllAssistants(false);
176
199
 
177
- expect(stdout).toContain("Platform: logged in as vargas@vellum.ai");
178
- expect(
179
- stderr.some((l) => l.includes("Failed to fetch organization")),
180
- ).toBe(false);
200
+ expect(stdout).toContain("Platform: logged in as user@example.com");
201
+ expect(stderr.some((l) => l.includes("Failed to fetch organization"))).toBe(
202
+ false,
203
+ );
204
+ });
205
+
206
+ test("assistant rows use display name as primary label and keep id visible", async () => {
207
+ loadAllAssistantsMock.mockReturnValue([
208
+ {
209
+ assistantId: "assistant-123",
210
+ name: "Alice",
211
+ runtimeUrl: "https://platform.example",
212
+ cloud: "vellum",
213
+ species: "vellum",
214
+ },
215
+ ]);
216
+ getActiveAssistantMock.mockReturnValue("assistant-123");
217
+
218
+ await listAllAssistants(false);
219
+
220
+ const output = stdout.join("\n");
221
+ expect(output).toContain("* Alice");
222
+ expect(output).toContain("id: assistant-123");
223
+ expect(output).toContain("https://platform.example");
224
+ expect(output).not.toContain("* assistant-123");
225
+ });
226
+
227
+ test("assistant list renders one stable final row per assistant", async () => {
228
+ loadAllAssistantsMock.mockReturnValue([
229
+ {
230
+ assistantId: "assistant-123",
231
+ name: "Alice",
232
+ runtimeUrl: "https://platform.example/a",
233
+ cloud: "vellum",
234
+ species: "vellum",
235
+ },
236
+ {
237
+ assistantId: "assistant-456",
238
+ name: "Bob",
239
+ runtimeUrl: "https://platform.example/b",
240
+ cloud: "vellum",
241
+ species: "vellum",
242
+ },
243
+ ]);
244
+ getActiveAssistantMock.mockReturnValue("assistant-123");
245
+ checkManagedHealthMock.mockImplementation(async (_runtimeUrl, id) => ({
246
+ status: id === "assistant-123" ? "healthy" : "sleeping",
247
+ detail: null,
248
+ }));
249
+
250
+ await listAllAssistants(false);
251
+
252
+ const output = stdout.join("\n");
253
+ expect(output).not.toContain("\x1b[");
254
+ expect(output).not.toContain("checking...");
255
+ expect(output.match(/Alice/g)).toHaveLength(1);
256
+ expect(output.match(/Bob/g)).toHaveLength(1);
257
+ expect(output).toContain("healthy");
258
+ expect(output).toContain("sleeping");
181
259
  });
182
260
  });
@@ -75,7 +75,10 @@ function writeLockfile(entry: AssistantEntry): void {
75
75
  }
76
76
 
77
77
  function installFetchStub(
78
- options: { refreshedToken?: GuardianTokenData } = {},
78
+ options: {
79
+ leasedToken?: GuardianTokenData;
80
+ refreshedToken?: GuardianTokenData;
81
+ } = {},
79
82
  ) {
80
83
  fetchCalls = [];
81
84
  globalThis.fetch = (async (input, init) => {
@@ -103,6 +106,19 @@ function installFetchStub(
103
106
  });
104
107
  }
105
108
 
109
+ if (url.endsWith("/v1/guardian/init")) {
110
+ if (!options.leasedToken) {
111
+ return new Response(JSON.stringify({ error: "not allowed" }), {
112
+ status: 401,
113
+ headers: { "Content-Type": "application/json" },
114
+ });
115
+ }
116
+ return new Response(JSON.stringify(options.leasedToken), {
117
+ status: 200,
118
+ headers: { "Content-Type": "application/json" },
119
+ });
120
+ }
121
+
106
122
  if (url.endsWith("/v1/secrets/read")) {
107
123
  return new Response(JSON.stringify({ found: false }), {
108
124
  status: 200,
@@ -209,6 +225,54 @@ describe("setup command", () => {
209
225
  );
210
226
  });
211
227
 
228
+ test("leases a guardian token for local assistants when no token exists", async () => {
229
+ process.env.ANTHROPIC_API_KEY = "test-anthropic-key";
230
+ writeLockfile({
231
+ assistantId: "assistant-123",
232
+ runtimeUrl: "http://runtime.example",
233
+ localUrl: "http://127.0.0.1:3000",
234
+ cloud: "local",
235
+ });
236
+ installFetchStub({
237
+ leasedToken: guardianTokenFixture({
238
+ accessToken: "leased-guardian-token",
239
+ }),
240
+ });
241
+
242
+ await setup();
243
+
244
+ expect(fetchCalls[0].url).toBe("http://127.0.0.1:3000/v1/guardian/init");
245
+ expect(fetchCalls[1].url).toBe("http://127.0.0.1:3000/v1/secrets/read");
246
+ expect(fetchCalls[1].headers.get("Authorization")).toBe(
247
+ "Bearer leased-guardian-token",
248
+ );
249
+ });
250
+
251
+ test("uses saved bootstrap secret when leasing a Docker guardian token", async () => {
252
+ process.env.ANTHROPIC_API_KEY = "test-anthropic-key";
253
+ writeLockfile({
254
+ assistantId: "assistant-123",
255
+ runtimeUrl: "http://localhost:7831",
256
+ cloud: "docker",
257
+ guardianBootstrapSecret: "test-bootstrap-secret",
258
+ });
259
+ installFetchStub({
260
+ leasedToken: guardianTokenFixture({
261
+ accessToken: "leased-docker-token",
262
+ }),
263
+ });
264
+
265
+ await setup();
266
+
267
+ expect(fetchCalls[0].url).toBe("http://localhost:7831/v1/guardian/init");
268
+ expect(fetchCalls[0].headers.get("x-bootstrap-secret")).toBe(
269
+ "test-bootstrap-secret",
270
+ );
271
+ expect(fetchCalls[1].headers.get("Authorization")).toBe(
272
+ "Bearer leased-docker-token",
273
+ );
274
+ });
275
+
212
276
  test("falls back to runtime URL and lockfile bearer token", async () => {
213
277
  process.env.ANTHROPIC_API_KEY = "test-anthropic-key";
214
278
  writeLockfile({
@@ -779,6 +779,7 @@ describe("resolveOrHatchTarget", () => {
779
779
  "new-one",
780
780
  false,
781
781
  {},
782
+ { setupProviderCredentials: false },
782
783
  );
783
784
  expect(result).toBe(newEntry);
784
785
  });
@@ -0,0 +1,144 @@
1
+ import {
2
+ afterAll,
3
+ afterEach,
4
+ beforeEach,
5
+ describe,
6
+ expect,
7
+ spyOn,
8
+ test,
9
+ } from "bun:test";
10
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+
14
+ import {
15
+ getActiveAssistant,
16
+ type AssistantEntry,
17
+ } from "../lib/assistant-config.js";
18
+ import { use } from "../commands/use.js";
19
+
20
+ const testDir = mkdtempSync(join(tmpdir(), "cli-use-test-"));
21
+ const originalArgv = [...process.argv];
22
+ const originalExit = process.exit;
23
+ const originalLockfileDir = process.env.VELLUM_LOCKFILE_DIR;
24
+
25
+ let consoleLogSpy: ReturnType<typeof spyOn>;
26
+ let consoleErrorSpy: ReturnType<typeof spyOn>;
27
+
28
+ function makeEntry(
29
+ assistantId: string,
30
+ extra: Partial<AssistantEntry> = {},
31
+ ): AssistantEntry {
32
+ return {
33
+ assistantId,
34
+ runtimeUrl: `http://localhost:${7800 + assistantId.length}`,
35
+ cloud: "local",
36
+ ...extra,
37
+ };
38
+ }
39
+
40
+ function writeLockfile(
41
+ entries: AssistantEntry[],
42
+ activeAssistant?: string,
43
+ ): void {
44
+ mkdirSync(testDir, { recursive: true });
45
+ writeFileSync(
46
+ join(testDir, ".vellum.lock.json"),
47
+ JSON.stringify(
48
+ {
49
+ assistants: entries,
50
+ ...(activeAssistant ? { activeAssistant } : {}),
51
+ },
52
+ null,
53
+ 2,
54
+ ),
55
+ );
56
+ }
57
+
58
+ describe("vellum use", () => {
59
+ beforeEach(() => {
60
+ process.env.VELLUM_LOCKFILE_DIR = testDir;
61
+ rmSync(join(testDir, ".vellum.lock.json"), { force: true });
62
+ process.argv = ["bun", "vellum", "use"];
63
+ process.exit = ((code?: number) => {
64
+ throw new Error(`process.exit:${code}`);
65
+ }) as typeof process.exit;
66
+ consoleLogSpy = spyOn(console, "log").mockImplementation(() => {});
67
+ consoleErrorSpy = spyOn(console, "error").mockImplementation(() => {});
68
+ });
69
+
70
+ afterEach(() => {
71
+ process.argv = originalArgv;
72
+ process.exit = originalExit;
73
+ consoleLogSpy.mockRestore();
74
+ consoleErrorSpy.mockRestore();
75
+ });
76
+
77
+ afterAll(() => {
78
+ if (originalLockfileDir === undefined) {
79
+ delete process.env.VELLUM_LOCKFILE_DIR;
80
+ } else {
81
+ process.env.VELLUM_LOCKFILE_DIR = originalLockfileDir;
82
+ }
83
+ rmSync(testDir, { recursive: true, force: true });
84
+ });
85
+
86
+ test("sets active assistant by unique display name", async () => {
87
+ writeLockfile([
88
+ makeEntry("assistant-1", { name: "Alice" }),
89
+ makeEntry("assistant-2", { name: "Bob" }),
90
+ ]);
91
+ process.argv = ["bun", "vellum", "use", "Alice"];
92
+
93
+ await use();
94
+
95
+ expect(getActiveAssistant()).toBe("assistant-1");
96
+ expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
97
+ "Active assistant set to Alice (assistant-1).",
98
+ );
99
+ });
100
+
101
+ test("sets active assistant by unquoted multi-word display name", async () => {
102
+ writeLockfile([
103
+ makeEntry("assistant-1", { name: "Example Assistant" }),
104
+ makeEntry("assistant-2", { name: "Bob" }),
105
+ ]);
106
+ process.argv = ["bun", "vellum", "use", "Example", "Assistant"];
107
+
108
+ await use();
109
+
110
+ expect(getActiveAssistant()).toBe("assistant-1");
111
+ expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
112
+ "Active assistant set to Example Assistant (assistant-1).",
113
+ );
114
+ });
115
+
116
+ test("prints active assistant with display name and id", async () => {
117
+ writeLockfile([makeEntry("assistant-1", { name: "Alice" })], "assistant-1");
118
+
119
+ await use();
120
+
121
+ expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
122
+ "Active assistant: Alice (assistant-1)",
123
+ );
124
+ });
125
+
126
+ test("rejects ambiguous display names without changing active assistant", async () => {
127
+ writeLockfile(
128
+ [
129
+ makeEntry("assistant-1", { name: "Alice" }),
130
+ makeEntry("assistant-2", { name: "Alice" }),
131
+ ],
132
+ "assistant-2",
133
+ );
134
+ process.argv = ["bun", "vellum", "use", "Alice"];
135
+
136
+ await expect(use()).rejects.toThrow("process.exit:1");
137
+
138
+ expect(getActiveAssistant()).toBe("assistant-2");
139
+ const output = consoleErrorSpy.mock.calls.flat().join("\n");
140
+ expect(output).toContain("Multiple assistants match 'Alice'");
141
+ expect(output).toContain("assistant-1");
142
+ expect(output).toContain("assistant-2");
143
+ });
144
+ });