Skip to content

Commit a580ba9

Browse files
committed
test(test-suite): add comprehensive unit tests for Bun CLI
Add 57 new tests (65 total) covering utils, artifacts, CLI argument validation, command error paths, compat policy edge cases, and version resolution. Extract shared test helpers to reduce duplication and ensure safe cleanup of global state (process.exitCode, console captures).
1 parent a651dc5 commit a580ba9

File tree

4 files changed

+567
-157
lines changed

4 files changed

+567
-157
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { describe, expect, test } from "bun:test";
2+
3+
import { resolvedComposeEnv, serviceNameList } from "./artifacts";
4+
import { stubState } from "./test-helpers";
5+
6+
describe("resolvedComposeEnv", () => {
7+
test("includes version env and COMPOSE_IGNORE_ORPHANS", () => {
8+
const env = resolvedComposeEnv(stubState());
9+
expect(env.GATEWAY_VERSION).toBe("v0.11.0");
10+
expect(env.CORE_VERSION).toBe("v0.13.0");
11+
expect(env.COMPOSE_IGNORE_ORPHANS).toBe("true");
12+
});
13+
14+
test("defaults FHEVM_CARGO_PROFILE to release", () => {
15+
const env = resolvedComposeEnv(stubState());
16+
expect(env.FHEVM_CARGO_PROFILE).toBe("release");
17+
});
18+
19+
test("uses override profile when present", () => {
20+
const env = resolvedComposeEnv(stubState({ overrides: [{ group: "coprocessor", profile: "debug" }] }));
21+
expect(env.FHEVM_CARGO_PROFILE).toBe("debug");
22+
});
23+
24+
test("uses first override profile found", () => {
25+
const env = resolvedComposeEnv(
26+
stubState({
27+
overrides: [
28+
{ group: "coprocessor", profile: "custom" },
29+
{ group: "test-suite", profile: "other" },
30+
],
31+
}),
32+
);
33+
expect(env.FHEVM_CARGO_PROFILE).toBe("custom");
34+
});
35+
36+
test("falls back to release when override has no profile", () => {
37+
const env = resolvedComposeEnv(stubState({ overrides: [{ group: "coprocessor" }] }));
38+
expect(env.FHEVM_CARGO_PROFILE).toBe("release");
39+
});
40+
});
41+
42+
describe("serviceNameList", () => {
43+
const state = stubState();
44+
45+
test("returns empty for non-coprocessor components", () => {
46+
expect(serviceNameList(state, "relayer")).toEqual([]);
47+
expect(serviceNameList(state, "database")).toEqual([]);
48+
expect(serviceNameList(state, "minio")).toEqual([]);
49+
});
50+
51+
test("returns single-instance service names for count=1", () => {
52+
const names = serviceNameList(state, "coprocessor");
53+
expect(names).toEqual([
54+
"coprocessor-db-migration",
55+
"coprocessor-host-listener",
56+
"coprocessor-host-listener-poller",
57+
"coprocessor-gw-listener",
58+
"coprocessor-tfhe-worker",
59+
"coprocessor-zkproof-worker",
60+
"coprocessor-sns-worker",
61+
"coprocessor-transaction-sender",
62+
]);
63+
});
64+
65+
test("returns multi-instance service names for count=2", () => {
66+
const names = serviceNameList(stubState({ count: 2 }), "coprocessor");
67+
expect(names).toContain("coprocessor-db-migration");
68+
expect(names).toContain("coprocessor-host-listener");
69+
expect(names).toContain("coprocessor1-db-migration");
70+
expect(names).toContain("coprocessor1-host-listener");
71+
expect(names).toContain("coprocessor1-tfhe-worker");
72+
expect(names.length).toBe(16);
73+
});
74+
75+
test("returns multi-instance service names for count=3", () => {
76+
const names = serviceNameList(stubState({ count: 3 }), "coprocessor");
77+
expect(names).toContain("coprocessor-db-migration");
78+
expect(names).toContain("coprocessor1-db-migration");
79+
expect(names).toContain("coprocessor2-db-migration");
80+
expect(names.length).toBe(24);
81+
});
82+
});

0 commit comments

Comments
 (0)