mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 03:49:31 +00:00
refactor(test): extract shouldSkipCloudInit helper and add unit tests (#2958)
Extracts the inline docker-mode condition from hetzner/main.ts and gcp/main.ts into a testable exported function in shared/cloud-init.ts, then adds real unit tests that import from the source. Fixes #2952. 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:
parent
6c742bdd11
commit
65320abf05
5 changed files with 102 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@openrouter/spawn",
|
||||
"version": "0.25.27",
|
||||
"version": "0.25.28",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"spawn": "cli.js"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, it } from "bun:test";
|
||||
import { getPackagesForTier, needsBun, needsNode } from "../shared/cloud-init.js";
|
||||
import { getPackagesForTier, needsBun, needsNode, shouldSkipCloudInit } from "../shared/cloud-init.js";
|
||||
|
||||
describe("getPackagesForTier", () => {
|
||||
const MINIMAL_PACKAGES = [
|
||||
|
|
@ -113,3 +113,76 @@ describe("needsBun", () => {
|
|||
expect(needsBun()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldSkipCloudInit", () => {
|
||||
it("returns true when useDocker is true", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true when snapshotId is a non-null string", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: false,
|
||||
snapshotId: "snap-123",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true when skipCloudInit is true", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: false,
|
||||
skipCloudInit: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false when all flags are off", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when snapshotId is null", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: false,
|
||||
snapshotId: null,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when snapshotId is undefined", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: false,
|
||||
snapshotId: undefined,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false when skipCloudInit is false", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: false,
|
||||
skipCloudInit: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true when multiple flags are set", () => {
|
||||
expect(
|
||||
shouldSkipCloudInit({
|
||||
useDocker: true,
|
||||
snapshotId: "snap-1",
|
||||
skipCloudInit: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
import type { CloudOrchestrator } from "../shared/orchestrate.js";
|
||||
|
||||
import { getErrorMessage } from "@openrouter/spawn-shared";
|
||||
import { shouldSkipCloudInit } from "../shared/cloud-init.js";
|
||||
import { DOCKER_CONTAINER_NAME, DOCKER_REGISTRY, runOrchestration } from "../shared/orchestrate.js";
|
||||
import { logInfo, logStep, shellQuote } from "../shared/ui.js";
|
||||
import { agents, resolveAgent } from "./agents.js";
|
||||
|
|
@ -85,7 +86,12 @@ async function main() {
|
|||
},
|
||||
getServerName,
|
||||
async waitForReady() {
|
||||
if (useDocker || cloud.skipCloudInit) {
|
||||
if (
|
||||
shouldSkipCloudInit({
|
||||
useDocker,
|
||||
skipCloudInit: cloud.skipCloudInit,
|
||||
})
|
||||
) {
|
||||
await waitForSshOnly();
|
||||
} else {
|
||||
await waitForCloudInit();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
import type { CloudOrchestrator } from "../shared/orchestrate.js";
|
||||
|
||||
import { getErrorMessage } from "@openrouter/spawn-shared";
|
||||
import { shouldSkipCloudInit } from "../shared/cloud-init.js";
|
||||
import { DOCKER_CONTAINER_NAME, DOCKER_REGISTRY, runOrchestration } from "../shared/orchestrate.js";
|
||||
import { logInfo, logStep, shellQuote } from "../shared/ui.js";
|
||||
import { agents, resolveAgent } from "./agents.js";
|
||||
|
|
@ -98,7 +99,13 @@ async function main() {
|
|||
},
|
||||
getServerName,
|
||||
async waitForReady() {
|
||||
if (useDocker || snapshotId || cloud.skipCloudInit) {
|
||||
if (
|
||||
shouldSkipCloudInit({
|
||||
useDocker,
|
||||
snapshotId,
|
||||
skipCloudInit: cloud.skipCloudInit,
|
||||
})
|
||||
) {
|
||||
await waitForSshOnly();
|
||||
} else {
|
||||
await waitForCloudInit();
|
||||
|
|
|
|||
|
|
@ -46,3 +46,15 @@ export function needsNode(tier: CloudInitTier = "full"): boolean {
|
|||
export function needsBun(tier: CloudInitTier = "full"): boolean {
|
||||
return tier === "bun" || tier === "full";
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether cloud-init wait should be skipped in favor of SSH-only wait.
|
||||
* Extracted from the inline condition in hetzner/main.ts and gcp/main.ts.
|
||||
*/
|
||||
export function shouldSkipCloudInit(opts: {
|
||||
useDocker: boolean;
|
||||
snapshotId?: string | null | undefined;
|
||||
skipCloudInit?: boolean;
|
||||
}): boolean {
|
||||
return opts.useDocker || opts.snapshotId != null || (opts.skipCloudInit ?? false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue