mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 03:49:31 +00:00
refactor: remove dead code and stale references (#2832)
Deduplicate identical mockBunSpawn helper that was copy-pasted across five test files (aws-cov, gcp-cov, do-cov, hetzner-cov, sprite-cov). Centralise it in test-helpers.ts and import from there instead. -- qa/code-quality Co-authored-by: spawn-qa-bot <qa@openrouter.ai> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5e263dd12f
commit
3551995aa1
6 changed files with 60 additions and 249 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
|
||||
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
||||
import { mockClackPrompts } from "./test-helpers";
|
||||
import { mockBunSpawn, mockClackPrompts } from "./test-helpers";
|
||||
|
||||
// Must mock clack before importing aws module
|
||||
mockClackPrompts();
|
||||
|
|
@ -29,54 +29,6 @@ function mockSpawnSync(exitCode: number, stdout = "", stderr = "") {
|
|||
} satisfies ReturnType<typeof Bun.spawnSync>);
|
||||
}
|
||||
|
||||
function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
||||
const mockProc = {
|
||||
pid: 1234,
|
||||
exitCode: Promise.resolve(exitCode),
|
||||
exited: Promise.resolve(exitCode),
|
||||
stdout: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stdout));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
stderr: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stderr));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
kill: mock(() => {}),
|
||||
ref: () => {},
|
||||
unref: () => {},
|
||||
stdin: new WritableStream(),
|
||||
resourceUsage: () =>
|
||||
({
|
||||
cpuTime: {
|
||||
system: 0,
|
||||
user: 0,
|
||||
total: 0,
|
||||
},
|
||||
maxRSS: 0,
|
||||
sharedMemorySize: 0,
|
||||
unsharedDataSize: 0,
|
||||
unsharedStackSize: 0,
|
||||
minorPageFaults: 0,
|
||||
majorPageFaults: 0,
|
||||
swapCount: 0,
|
||||
inBlock: 0,
|
||||
outBlock: 0,
|
||||
ipcMessagesSent: 0,
|
||||
ipcMessagesReceived: 0,
|
||||
signalsReceived: 0,
|
||||
voluntaryContextSwitches: 0,
|
||||
involuntaryContextSwitches: 0,
|
||||
}) satisfies ReturnType<ReturnType<typeof Bun.spawn>["resourceUsage"]>,
|
||||
};
|
||||
// biome-ignore lint: test mock
|
||||
return spyOn(Bun, "spawn").mockReturnValue(mockProc as ReturnType<typeof Bun.spawn>);
|
||||
}
|
||||
|
||||
let origFetch: typeof global.fetch;
|
||||
let origEnv: NodeJS.ProcessEnv;
|
||||
let stderrSpy: ReturnType<typeof spyOn>;
|
||||
|
|
|
|||
|
|
@ -1,60 +1,10 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
|
||||
import { mockClackPrompts } from "./test-helpers";
|
||||
import { mockBunSpawn, mockClackPrompts } from "./test-helpers";
|
||||
|
||||
mockClackPrompts();
|
||||
|
||||
import { DEFAULT_DO_REGION, DEFAULT_DROPLET_SIZE, getConnectionInfo } from "../digitalocean/digitalocean";
|
||||
|
||||
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
||||
const mockProc = {
|
||||
pid: 1234,
|
||||
exitCode: Promise.resolve(exitCode),
|
||||
exited: Promise.resolve(exitCode),
|
||||
stdout: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stdout));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
stderr: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stderr));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
kill: mock(() => {}),
|
||||
ref: () => {},
|
||||
unref: () => {},
|
||||
stdin: new WritableStream(),
|
||||
resourceUsage: () =>
|
||||
({
|
||||
cpuTime: {
|
||||
system: 0,
|
||||
user: 0,
|
||||
total: 0,
|
||||
},
|
||||
maxRSS: 0,
|
||||
sharedMemorySize: 0,
|
||||
unsharedDataSize: 0,
|
||||
unsharedStackSize: 0,
|
||||
minorPageFaults: 0,
|
||||
majorPageFaults: 0,
|
||||
swapCount: 0,
|
||||
inBlock: 0,
|
||||
outBlock: 0,
|
||||
ipcMessagesSent: 0,
|
||||
ipcMessagesReceived: 0,
|
||||
signalsReceived: 0,
|
||||
voluntaryContextSwitches: 0,
|
||||
involuntaryContextSwitches: 0,
|
||||
}) satisfies ReturnType<ReturnType<typeof Bun.spawn>["resourceUsage"]>,
|
||||
};
|
||||
// biome-ignore lint: test mock
|
||||
return spyOn(Bun, "spawn").mockReturnValue(mockProc as ReturnType<typeof Bun.spawn>);
|
||||
}
|
||||
|
||||
let origFetch: typeof global.fetch;
|
||||
let origEnv: NodeJS.ProcessEnv;
|
||||
let stderrSpy: ReturnType<typeof spyOn>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
|
||||
import { mockClackPrompts } from "./test-helpers";
|
||||
import { mockBunSpawn, mockClackPrompts } from "./test-helpers";
|
||||
|
||||
mockClackPrompts();
|
||||
|
||||
|
|
@ -53,54 +53,6 @@ function mockWhichGcloud() {
|
|||
return spyOn(Bun, "spawnSync").mockReturnValue(WHICH_GCLOUD_OK);
|
||||
}
|
||||
|
||||
function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
||||
const mockProc = {
|
||||
pid: 1234,
|
||||
exitCode: Promise.resolve(exitCode),
|
||||
exited: Promise.resolve(exitCode),
|
||||
stdout: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stdout));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
stderr: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stderr));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
kill: mock(() => {}),
|
||||
ref: () => {},
|
||||
unref: () => {},
|
||||
stdin: new WritableStream(),
|
||||
resourceUsage: () =>
|
||||
({
|
||||
cpuTime: {
|
||||
system: 0,
|
||||
user: 0,
|
||||
total: 0,
|
||||
},
|
||||
maxRSS: 0,
|
||||
sharedMemorySize: 0,
|
||||
unsharedDataSize: 0,
|
||||
unsharedStackSize: 0,
|
||||
minorPageFaults: 0,
|
||||
majorPageFaults: 0,
|
||||
swapCount: 0,
|
||||
inBlock: 0,
|
||||
outBlock: 0,
|
||||
ipcMessagesSent: 0,
|
||||
ipcMessagesReceived: 0,
|
||||
signalsReceived: 0,
|
||||
voluntaryContextSwitches: 0,
|
||||
involuntaryContextSwitches: 0,
|
||||
}) satisfies ReturnType<ReturnType<typeof Bun.spawn>["resourceUsage"]>,
|
||||
};
|
||||
// biome-ignore lint: test mock
|
||||
return spyOn(Bun, "spawn").mockReturnValue(mockProc as ReturnType<typeof Bun.spawn>);
|
||||
}
|
||||
|
||||
let origFetch: typeof global.fetch;
|
||||
let origEnv: NodeJS.ProcessEnv;
|
||||
let stderrSpy: ReturnType<typeof spyOn>;
|
||||
|
|
|
|||
|
|
@ -1,60 +1,10 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
|
||||
import { mockClackPrompts } from "./test-helpers";
|
||||
import { mockBunSpawn, mockClackPrompts } from "./test-helpers";
|
||||
|
||||
mockClackPrompts();
|
||||
|
||||
import { DEFAULT_LOCATION, DEFAULT_SERVER_TYPE, getConnectionInfo } from "../hetzner/hetzner";
|
||||
|
||||
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
||||
const mockProc = {
|
||||
pid: 1234,
|
||||
exitCode: Promise.resolve(exitCode),
|
||||
exited: Promise.resolve(exitCode),
|
||||
stdout: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stdout));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
stderr: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stderr));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
kill: mock(() => {}),
|
||||
ref: () => {},
|
||||
unref: () => {},
|
||||
stdin: new WritableStream(),
|
||||
resourceUsage: () =>
|
||||
({
|
||||
cpuTime: {
|
||||
system: 0,
|
||||
user: 0,
|
||||
total: 0,
|
||||
},
|
||||
maxRSS: 0,
|
||||
sharedMemorySize: 0,
|
||||
unsharedDataSize: 0,
|
||||
unsharedStackSize: 0,
|
||||
minorPageFaults: 0,
|
||||
majorPageFaults: 0,
|
||||
swapCount: 0,
|
||||
inBlock: 0,
|
||||
outBlock: 0,
|
||||
ipcMessagesSent: 0,
|
||||
ipcMessagesReceived: 0,
|
||||
signalsReceived: 0,
|
||||
voluntaryContextSwitches: 0,
|
||||
involuntaryContextSwitches: 0,
|
||||
}) satisfies ReturnType<ReturnType<typeof Bun.spawn>["resourceUsage"]>,
|
||||
};
|
||||
// biome-ignore lint: test mock
|
||||
return spyOn(Bun, "spawn").mockReturnValue(mockProc as ReturnType<typeof Bun.spawn>);
|
||||
}
|
||||
|
||||
let origFetch: typeof global.fetch;
|
||||
let origEnv: NodeJS.ProcessEnv;
|
||||
let stderrSpy: ReturnType<typeof spyOn>;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test";
|
||||
import { mockClackPrompts } from "./test-helpers";
|
||||
import { mockBunSpawn, mockClackPrompts } from "./test-helpers";
|
||||
|
||||
mockClackPrompts();
|
||||
|
||||
|
|
@ -19,54 +19,6 @@ function mockSpawnSync(exitCode: number, stdout = "", stderr = "") {
|
|||
} satisfies ReturnType<typeof Bun.spawnSync>);
|
||||
}
|
||||
|
||||
function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
||||
const mockProc = {
|
||||
pid: 1234,
|
||||
exitCode: Promise.resolve(exitCode),
|
||||
exited: Promise.resolve(exitCode),
|
||||
stdout: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stdout));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
stderr: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stderr));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
kill: mock(() => {}),
|
||||
ref: () => {},
|
||||
unref: () => {},
|
||||
stdin: new WritableStream(),
|
||||
resourceUsage: () =>
|
||||
({
|
||||
cpuTime: {
|
||||
system: 0,
|
||||
user: 0,
|
||||
total: 0,
|
||||
},
|
||||
maxRSS: 0,
|
||||
sharedMemorySize: 0,
|
||||
unsharedDataSize: 0,
|
||||
unsharedStackSize: 0,
|
||||
minorPageFaults: 0,
|
||||
majorPageFaults: 0,
|
||||
swapCount: 0,
|
||||
inBlock: 0,
|
||||
outBlock: 0,
|
||||
ipcMessagesSent: 0,
|
||||
ipcMessagesReceived: 0,
|
||||
signalsReceived: 0,
|
||||
voluntaryContextSwitches: 0,
|
||||
involuntaryContextSwitches: 0,
|
||||
}) satisfies ReturnType<ReturnType<typeof Bun.spawn>["resourceUsage"]>,
|
||||
};
|
||||
// biome-ignore lint: test mock
|
||||
return spyOn(Bun, "spawn").mockReturnValue(mockProc as ReturnType<typeof Bun.spawn>);
|
||||
}
|
||||
|
||||
let origEnv: NodeJS.ProcessEnv;
|
||||
let stderrSpy: ReturnType<typeof spyOn>;
|
||||
|
||||
|
|
|
|||
|
|
@ -175,6 +175,61 @@ export function mockClackPrompts(overrides?: Partial<ClackPromptsMock>): ClackPr
|
|||
return mocks;
|
||||
}
|
||||
|
||||
// ── Bun.spawn Mock ─────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Mocks Bun.spawn to return a fake process with the given exit code, stdout, and stderr.
|
||||
* Identical helper was previously duplicated across aws-cov, gcp-cov, do-cov, hetzner-cov,
|
||||
* and sprite-cov test files. Centralised here to avoid repetition.
|
||||
*/
|
||||
export function mockBunSpawn(exitCode = 0, stdout = "", stderr = "") {
|
||||
const mockProc = {
|
||||
pid: 1234,
|
||||
exitCode: Promise.resolve(exitCode),
|
||||
exited: Promise.resolve(exitCode),
|
||||
stdout: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stdout));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
stderr: new ReadableStream({
|
||||
start(c) {
|
||||
c.enqueue(new TextEncoder().encode(stderr));
|
||||
c.close();
|
||||
},
|
||||
}),
|
||||
kill: mock(() => {}),
|
||||
ref: () => {},
|
||||
unref: () => {},
|
||||
stdin: new WritableStream(),
|
||||
resourceUsage: () =>
|
||||
({
|
||||
cpuTime: {
|
||||
system: 0,
|
||||
user: 0,
|
||||
total: 0,
|
||||
},
|
||||
maxRSS: 0,
|
||||
sharedMemorySize: 0,
|
||||
unsharedDataSize: 0,
|
||||
unsharedStackSize: 0,
|
||||
minorPageFaults: 0,
|
||||
majorPageFaults: 0,
|
||||
swapCount: 0,
|
||||
inBlock: 0,
|
||||
outBlock: 0,
|
||||
ipcMessagesSent: 0,
|
||||
ipcMessagesReceived: 0,
|
||||
signalsReceived: 0,
|
||||
voluntaryContextSwitches: 0,
|
||||
involuntaryContextSwitches: 0,
|
||||
}) satisfies ReturnType<ReturnType<typeof Bun.spawn>["resourceUsage"]>,
|
||||
};
|
||||
// biome-ignore lint: test mock
|
||||
return spyOn(Bun, "spawn").mockReturnValue(mockProc as ReturnType<typeof Bun.spawn>);
|
||||
}
|
||||
|
||||
// ── Fetch Mocks ────────────────────────────────────────────────────────────────
|
||||
|
||||
export function mockSuccessfulFetch(data: unknown) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue