@vellumai/cli 0.10.4 → 0.10.5-dev.202607022248.91fa053

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,79 @@
1
+ import { afterEach, beforeAll, describe, expect, mock, test } from "bun:test";
2
+ import { EventEmitter } from "node:events";
3
+
4
+ import type { CliInvocation } from "../util";
5
+
6
+ class FakeChild extends EventEmitter {
7
+ stdout = new EventEmitter();
8
+ stderr = new EventEmitter();
9
+ kill = mock(() => true);
10
+ }
11
+
12
+ let lastChild: FakeChild;
13
+ const spawnArgs: Array<
14
+ [string, string[], { env?: NodeJS.ProcessEnv; stdio?: unknown }]
15
+ > = [];
16
+ const spawnMock = mock(
17
+ (
18
+ command: string,
19
+ args: string[],
20
+ options: { env?: NodeJS.ProcessEnv; stdio?: unknown },
21
+ ) => {
22
+ spawnArgs.push([command, args, options]);
23
+ lastChild = new FakeChild();
24
+ return lastChild;
25
+ },
26
+ );
27
+
28
+ mock.module("node:child_process", () => ({ spawn: spawnMock }));
29
+
30
+ let runRetire: typeof import("../retire").runRetire;
31
+
32
+ beforeAll(async () => {
33
+ ({ runRetire } = await import("../retire"));
34
+ });
35
+
36
+ afterEach(() => {
37
+ spawnArgs.length = 0;
38
+ spawnMock.mockClear();
39
+ delete process.env.VELLUM_PLATFORM_TOKEN;
40
+ });
41
+
42
+ const invocation: CliInvocation = { command: "bun", baseArgs: ["run", "cli"] };
43
+
44
+ describe("runRetire", () => {
45
+ test("spawns the CLI retire command", async () => {
46
+ const pending = runRetire(invocation, "asst-42");
47
+ lastChild.emit("close", 0);
48
+
49
+ expect(await pending).toEqual({ ok: true });
50
+ expect(spawnArgs[0]).toEqual([
51
+ "bun",
52
+ ["run", "cli", "retire", "asst-42", "--yes"],
53
+ { stdio: ["ignore", "pipe", "pipe"] },
54
+ ]);
55
+ });
56
+
57
+ test("passes a host platform token to the CLI subprocess", async () => {
58
+ const pending = runRetire(invocation, "asst-42", {
59
+ platformToken: "session-token",
60
+ });
61
+ lastChild.emit("close", 0);
62
+
63
+ expect(await pending).toEqual({ ok: true });
64
+ expect(spawnArgs[0]?.[2].env?.VELLUM_PLATFORM_TOKEN).toBe("session-token");
65
+ expect(process.env.VELLUM_PLATFORM_TOKEN).toBeUndefined();
66
+ });
67
+
68
+ test("a non-zero exit resolves to a failure carrying the CLI output", async () => {
69
+ const pending = runRetire(invocation, "asst-42");
70
+ lastChild.stderr.emit("data", Buffer.from("retire failed"));
71
+ lastChild.emit("close", 1);
72
+
73
+ expect(await pending).toEqual({
74
+ ok: false,
75
+ status: 500,
76
+ error: "retire failed",
77
+ });
78
+ });
79
+ });
@@ -14,9 +14,18 @@ export {
14
14
  resolveDevCliInvocation,
15
15
  } from "./util";
16
16
  export type { CliInvocation } from "./util";
17
- export { resolveLocalConfigFromEnv, resolveLockfilePaths, resolveConfigDir, guardianTokenPath } from "./config";
17
+ export {
18
+ resolveLocalConfigFromEnv,
19
+ resolveLockfilePaths,
20
+ resolveConfigDir,
21
+ guardianTokenPath,
22
+ } from "./config";
18
23
  export type { LocalEndpointConfig } from "./config";
19
- export { defaultEnvironmentFilePath, readDefaultEnvironment, resolveEnvironmentName } from "./environment";
24
+ export {
25
+ defaultEnvironmentFilePath,
26
+ readDefaultEnvironment,
27
+ resolveEnvironmentName,
28
+ } from "./environment";
20
29
  export {
21
30
  getLockfileData,
22
31
  upsertLockfileAssistant,
@@ -34,7 +43,7 @@ export type {
34
43
  export { runHatch } from "./hatch";
35
44
  export type { HatchResult } from "./hatch";
36
45
  export { runRetire } from "./retire";
37
- export type { RetireResult } from "./retire";
46
+ export type { RetireOptions, RetireResult } from "./retire";
38
47
  export { runSleep } from "./sleep";
39
48
  export type { SleepResult } from "./sleep";
40
49
  export { runWake } from "./wake";
@@ -21,6 +21,9 @@ describe("parseLockfile", () => {
21
21
  species: "vellum",
22
22
  hatchedAt: "2026-01-01T00:00:00.000Z",
23
23
  organizationId: "org_1",
24
+ platformAssistantId: "platform-assistant-1",
25
+ platformBaseUrl: "https://platform.example.com",
26
+ platformOrganizationId: "org_1",
24
27
  resources: { gatewayPort: 7777, daemonPort: 7778 },
25
28
  },
26
29
  ],
@@ -274,13 +277,19 @@ describe("parseLockfile", () => {
274
277
  expect(parseLockfile(raw).assistants).toEqual([
275
278
  { assistantId: "gcp_1", cloud: "gcp", runtimeUrl: "https://a" },
276
279
  { assistantId: "ssh_1", cloud: "custom", runtimeUrl: "https://b" },
277
- { assistantId: "local_1", cloud: "local", runtimeUrl: "http://localhost:7830" },
280
+ {
281
+ assistantId: "local_1",
282
+ cloud: "local",
283
+ runtimeUrl: "http://localhost:7830",
284
+ },
278
285
  ]);
279
286
  });
280
287
 
281
288
  test("prefers an explicit cloud over legacy remote markers", () => {
282
289
  const raw = {
283
- assistants: [{ assistantId: "a", cloud: "vellum", project: "stale-proj" }],
290
+ assistants: [
291
+ { assistantId: "a", cloud: "vellum", project: "stale-proj" },
292
+ ],
284
293
  activeAssistant: null,
285
294
  };
286
295
  expect(parseLockfile(raw).assistants).toEqual([
@@ -109,6 +109,12 @@ export const LockfileAssistantSchema = z.object({
109
109
  hatchedAt: z.string().optional(),
110
110
  /** Owning org for platform assistants; absent for local ones. */
111
111
  organizationId: z.string().optional(),
112
+ /** Platform assistant UUID for a self-hosted local assistant registration. */
113
+ platformAssistantId: z.string().optional(),
114
+ /** Platform base URL used for a self-hosted local assistant registration. */
115
+ platformBaseUrl: z.string().optional(),
116
+ /** Platform organization UUID used for a self-hosted local assistant registration. */
117
+ platformOrganizationId: z.string().optional(),
112
118
  resources: LocalAssistantResourcesSchema.optional(),
113
119
  });
114
120
 
@@ -171,6 +171,32 @@ describe("upsertLockfileAssistant", () => {
171
171
  name: "Renamed",
172
172
  });
173
173
  });
174
+
175
+ test("preserves activeAssistant when no active id is provided", () => {
176
+ writeOnDisk({
177
+ activeAssistant: "asst_active",
178
+ assistants: [
179
+ {
180
+ assistantId: "asst_active",
181
+ cloud: "local",
182
+ runtimeUrl: "http://active",
183
+ },
184
+ { assistantId: "asst_1", cloud: "local", runtimeUrl: "http://a" },
185
+ ],
186
+ });
187
+
188
+ const result = upsertLockfileAssistant(
189
+ [lockfilePath],
190
+ { assistantId: "asst_1", name: "Renamed" },
191
+ undefined,
192
+ );
193
+
194
+ expect(result.ok).toBe(true);
195
+ expect(readOnDisk().activeAssistant).toBe("asst_active");
196
+ if (result.ok) {
197
+ expect(result.lockfile.activeAssistant).toBe("asst_active");
198
+ }
199
+ });
174
200
  });
175
201
 
176
202
  describe("replacePlatformAssistants", () => {
@@ -270,7 +296,9 @@ describe("replacePlatformAssistants", () => {
270
296
  "org_a",
271
297
  );
272
298
 
273
- const assistants = readOnDisk().assistants as Array<Record<string, unknown>>;
299
+ const assistants = readOnDisk().assistants as Array<
300
+ Record<string, unknown>
301
+ >;
274
302
  expect(assistants).toHaveLength(1);
275
303
  expect(assistants[0]).toMatchObject({
276
304
  assistantId: "asst_dup",
@@ -5,18 +5,32 @@ import type { CliInvocation } from "./util";
5
5
  const RETIRE_TIMEOUT_MS = 60_000;
6
6
 
7
7
  export type RetireResult =
8
- | { ok: true }
9
- | { ok: false; status: number; error: string };
8
+ { ok: true } | { ok: false; status: number; error: string };
9
+
10
+ export interface RetireOptions {
11
+ platformToken?: string;
12
+ }
10
13
 
11
14
  export function runRetire(
12
15
  invocation: CliInvocation,
13
16
  assistantId: string,
17
+ options: RetireOptions = {},
14
18
  ): Promise<RetireResult> {
15
19
  return new Promise((resolve) => {
16
20
  const child = spawn(
17
21
  invocation.command,
18
22
  [...invocation.baseArgs, "retire", assistantId, "--yes"],
19
- { stdio: ["ignore", "pipe", "pipe"] },
23
+ {
24
+ ...(options.platformToken
25
+ ? {
26
+ env: {
27
+ ...process.env,
28
+ VELLUM_PLATFORM_TOKEN: options.platformToken,
29
+ },
30
+ }
31
+ : {}),
32
+ stdio: ["ignore", "pipe", "pipe"],
33
+ },
20
34
  );
21
35
 
22
36
  let stdout = "";
@@ -32,7 +46,11 @@ export function runRetire(
32
46
 
33
47
  const timeout = setTimeout(() => {
34
48
  child.kill("SIGTERM");
35
- finish({ ok: false, status: 500, error: "Retire timed out after 60 seconds" });
49
+ finish({
50
+ ok: false,
51
+ status: 500,
52
+ error: "Retire timed out after 60 seconds",
53
+ });
36
54
  }, RETIRE_TIMEOUT_MS);
37
55
 
38
56
  child.stdout.on("data", (data: Buffer) => {
@@ -52,7 +70,11 @@ export function runRetire(
52
70
  });
53
71
 
54
72
  child.on("error", (err) => {
55
- finish({ ok: false, status: 500, error: `Failed to spawn CLI: ${err.message}` });
73
+ finish({
74
+ ok: false,
75
+ status: 500,
76
+ error: `Failed to spawn CLI: ${err.message}`,
77
+ });
56
78
  });
57
79
  });
58
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/cli",
3
- "version": "0.10.4",
3
+ "version": "0.10.5-dev.202607022248.91fa053",
4
4
  "description": "CLI tools for vellum-assistant",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,7 @@
1
1
  import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2
2
 
3
3
  import {
4
+ fetchLatestVersion,
4
5
  fetchReleases,
5
6
  resolveImageRefsDetailed,
6
7
  } from "../lib/platform-releases.js";
@@ -114,4 +115,45 @@ describe("resolveImageRefsDetailed", () => {
114
115
  const result = await resolveImageRefsDetailed("0.7.0");
115
116
  expect(result.status).toBe("dockerhub-fallback");
116
117
  });
118
+
119
+ test("requests the preview channel when channel=preview", async () => {
120
+ const fetchMock = mockFetchJson([RELEASE]);
121
+ await resolveImageRefsDetailed("v0.7.0", undefined, "preview");
122
+ const url = String(fetchMock.mock.calls[0][0]);
123
+ expect(url).toContain("channel=preview");
124
+ expect(url).not.toContain("stable=true");
125
+ });
126
+
127
+ test("keeps the stable filter when channel=stable (default)", async () => {
128
+ const fetchMock = mockFetchJson([RELEASE]);
129
+ await resolveImageRefsDetailed("v0.7.0", undefined, "stable");
130
+ const url = String(fetchMock.mock.calls[0][0]);
131
+ expect(url).toContain("stable=true");
132
+ expect(url).not.toContain("channel=");
133
+ });
134
+ });
135
+
136
+ describe("fetchLatestVersion", () => {
137
+ test("defaults to the stable channel", async () => {
138
+ const fetchMock = mockFetchJson([RELEASE]);
139
+ const version = await fetchLatestVersion();
140
+ expect(version).toBe("0.7.0");
141
+ const url = String(fetchMock.mock.calls[0][0]);
142
+ expect(url).toContain("stable=true");
143
+ expect(url).not.toContain("channel=");
144
+ });
145
+
146
+ test("requests the preview channel when asked", async () => {
147
+ const preview = { ...RELEASE, version: "0.8.0-preview.3" };
148
+ const fetchMock = mockFetchJson([preview]);
149
+ const version = await fetchLatestVersion("preview");
150
+ expect(version).toBe("0.8.0-preview.3");
151
+ const url = String(fetchMock.mock.calls[0][0]);
152
+ expect(url).toContain("channel=preview");
153
+ });
154
+
155
+ test("returns null when the channel has no releases", async () => {
156
+ mockFetchJson([]);
157
+ expect(await fetchLatestVersion("preview")).toBeNull();
158
+ });
117
159
  });