@vellumai/cli 0.10.3-dev.202606301940.da6000c → 0.10.3-dev.202606302138.0f63073
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 {
|
|
17
|
+
export {
|
|
18
|
+
resolveLocalConfigFromEnv,
|
|
19
|
+
resolveLockfilePaths,
|
|
20
|
+
resolveConfigDir,
|
|
21
|
+
guardianTokenPath,
|
|
22
|
+
} from "./config";
|
|
18
23
|
export type { LocalEndpointConfig } from "./config";
|
|
19
|
-
export {
|
|
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";
|
|
@@ -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:
|
|
9
|
-
|
|
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
|
-
{
|
|
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({
|
|
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({
|
|
73
|
+
finish({
|
|
74
|
+
ok: false,
|
|
75
|
+
status: 500,
|
|
76
|
+
error: `Failed to spawn CLI: ${err.message}`,
|
|
77
|
+
});
|
|
56
78
|
});
|
|
57
79
|
});
|
|
58
80
|
}
|