test: add coverage for retryOrQuit and skipCloudInit auto-detection (#2810)

Both functions were added in recent commits but had zero test coverage:
- retryOrQuit (ed127cf): non-interactive mode now verified to throw
- skipCloudInit (2280550): 4 cases verify correct tier/cloud/mode conditions

1468 tests pass, 0 failures.

Agent: test-engineer

Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
A 2026-03-19 23:45:04 -07:00 committed by GitHub
parent 69b6f8aa66
commit 0ea0d5bb61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 104 additions and 3 deletions

View file

@ -802,4 +802,75 @@ describe("runOrchestration", () => {
exitSpy.mockRestore();
});
});
// ── skipCloudInit auto-detection ────────────────────────────────────────
describe("skipCloudInit auto-detection", () => {
it("sets skipCloudInit=true for minimal-tier agent with tarball on non-local cloud", async () => {
process.env.SPAWN_FAST = "1";
const cloud = createMockCloud({
cloudName: "hetzner",
});
const agent = createMockAgent({
cloudInitTier: "minimal",
});
await runOrchestrationSafe(cloud, agent, "testagent");
expect(cloud.skipCloudInit).toBe(true);
delete process.env.SPAWN_FAST;
stderrSpy.mockRestore();
exitSpy.mockRestore();
});
it("sets skipCloudInit=true for agent with no cloudInitTier (defaults to minimal)", async () => {
process.env.SPAWN_FAST = "1";
const cloud = createMockCloud({
cloudName: "hetzner",
});
// No cloudInitTier set — should behave like minimal
const agent = createMockAgent();
await runOrchestrationSafe(cloud, agent, "testagent");
expect(cloud.skipCloudInit).toBe(true);
delete process.env.SPAWN_FAST;
stderrSpy.mockRestore();
exitSpy.mockRestore();
});
it("does NOT set skipCloudInit for full-tier agent even with tarball", async () => {
process.env.SPAWN_FAST = "1";
const cloud = createMockCloud({
cloudName: "hetzner",
});
const agent = createMockAgent({
cloudInitTier: "full",
});
await runOrchestrationSafe(cloud, agent, "testagent");
expect(cloud.skipCloudInit).toBeUndefined();
delete process.env.SPAWN_FAST;
stderrSpy.mockRestore();
exitSpy.mockRestore();
});
it("does NOT set skipCloudInit for local cloud even with minimal-tier agent", async () => {
process.env.SPAWN_FAST = "1";
const cloud = createMockCloud({
cloudName: "local",
});
const agent = createMockAgent({
cloudInitTier: "minimal",
});
await runOrchestrationSafe(cloud, agent, "testagent");
expect(cloud.skipCloudInit).toBeUndefined();
delete process.env.SPAWN_FAST;
stderrSpy.mockRestore();
exitSpy.mockRestore();
});
});
});

View file

@ -1,7 +1,14 @@
import { describe, expect, it } from "bun:test";
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
const { validateServerName, validateRegionName, validateModelId, toKebabCase, sanitizeTermValue, jsonEscape } =
await import("../shared/ui.js");
const {
validateServerName,
validateRegionName,
validateModelId,
toKebabCase,
sanitizeTermValue,
jsonEscape,
retryOrQuit,
} = await import("../shared/ui.js");
// ── validateServerName ──────────────────────────────────────────────
@ -204,3 +211,26 @@ describe("jsonEscape", () => {
expect(jsonEscape("path\\to\\file")).toBe('"path\\\\to\\\\file"');
});
});
// ── retryOrQuit ──────────────────────────────────────────────────────────
describe("retryOrQuit", () => {
let savedNonInteractive: string | undefined;
beforeEach(() => {
savedNonInteractive = process.env.SPAWN_NON_INTERACTIVE;
});
afterEach(() => {
if (savedNonInteractive !== undefined) {
process.env.SPAWN_NON_INTERACTIVE = savedNonInteractive;
} else {
delete process.env.SPAWN_NON_INTERACTIVE;
}
});
it("throws immediately in non-interactive mode", async () => {
process.env.SPAWN_NON_INTERACTIVE = "1";
await expect(retryOrQuit("Retry?")).rejects.toThrow("Non-interactive mode: cannot retry");
});
});