mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-14 08:30:36 +00:00
refactor: Remove dead code and stale references (#2132)
* refactor: Remove dead code and stale references
- Remove unused variables and functions in test files:
- cmdlast.test.ts: remove unused cmdRunMock and consoleOutput function
- cmdlist-integration.test.ts: remove unused resolveDisplayName import and consoleErrorOutput function
- cmd-listing-output.test.ts: remove unused getTerminalWidth import
- commands-update-download.test.ts: remove unused callIndex variable
- download-and-failure.test.ts: remove unused callCount variable and unused init parameter
- manifest-cache-lifecycle.test.ts: remove unused m1 variable
- manifest-integrity.test.ts: fix unused key in for-loop destructuring
- manifest-type-contracts.test.ts: fix 9 unused loop variables, remove implicit any let,
replace while-exec loop with matchAll to resolve noAssignInExpressions error
- Fixes biome lint errors from 22 down to 0
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* style: apply biome format to fix CI check
Agent: pr-maintainer
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
---------
Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
This commit is contained in:
parent
6881719b1a
commit
8de2c17c99
7 changed files with 19 additions and 33 deletions
|
|
@ -132,7 +132,7 @@ const multiTypeManifest: Manifest = {
|
|||
|
||||
const { spinnerStart: mockSpinnerStart, spinnerStop: mockSpinnerStop } = mockClackPrompts();
|
||||
|
||||
const { cmdMatrix, cmdAgents, cmdClouds, getTerminalWidth } = await import("../commands.js");
|
||||
const { cmdMatrix, cmdAgents, cmdClouds } = await import("../commands.js");
|
||||
|
||||
// ── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ describe("cmdLast", () => {
|
|||
let consoleMocks: ReturnType<typeof createConsoleMocks>;
|
||||
let originalFetch: typeof global.fetch;
|
||||
let processExitSpy: ReturnType<typeof spyOn>;
|
||||
let cmdRunMock: ReturnType<typeof mock>;
|
||||
|
||||
function writeHistory(records: SpawnRecord[]) {
|
||||
writeFileSync(join(testDir, "history.json"), JSON.stringify(records));
|
||||
|
|
@ -53,10 +52,6 @@ describe("cmdLast", () => {
|
|||
return mockLogStep.mock.calls.map((c: any[]) => c.join(" ")).join("\n");
|
||||
}
|
||||
|
||||
function consoleOutput(): string {
|
||||
return consoleMocks.log.mock.calls.map((c: any[]) => c.join(" ")).join("\n");
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
testDir = join(homedir(), `spawn-cmdlast-test-${Date.now()}-${Math.random()}`);
|
||||
mkdirSync(testDir, {
|
||||
|
|
@ -77,9 +72,6 @@ describe("cmdLast", () => {
|
|||
|
||||
originalFetch = global.fetch;
|
||||
|
||||
// Mock cmdRun to avoid actually spawning a process
|
||||
cmdRunMock = mock(() => Promise.resolve());
|
||||
|
||||
// Prime the manifest cache with mock data
|
||||
global.fetch = mock(() => Promise.resolve(new Response(JSON.stringify(mockManifest))));
|
||||
await loadManifest(true);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ const {
|
|||
} = mockClackPrompts();
|
||||
|
||||
// Import after mock setup
|
||||
const { cmdList, resolveDisplayName } = await import("../commands.js");
|
||||
const { cmdList } = await import("../commands.js");
|
||||
const { loadManifest, _resetCacheForTesting } = await import("../manifest.js");
|
||||
|
||||
// ── Test Setup ──────────────────────────────────────────────────────────────────
|
||||
|
|
@ -61,10 +61,6 @@ describe("cmdList integration", () => {
|
|||
return mockLogInfo.mock.calls.map((c: any[]) => c.join(" ")).join("\n");
|
||||
}
|
||||
|
||||
function consoleErrorOutput(): string {
|
||||
return consoleMocks.error.mock.calls.map((c: any[]) => c.join(" ")).join("\n");
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
testDir = join(homedir(), `spawn-cmdlist-test-${Date.now()}-${Math.random()}`);
|
||||
mkdirSync(testDir, {
|
||||
|
|
|
|||
|
|
@ -372,7 +372,6 @@ describe("Script download and execution", () => {
|
|||
});
|
||||
|
||||
it("should show network error message when primary 500 and fallback 502", async () => {
|
||||
const callIndex = 0;
|
||||
global.fetch = mock(async (url: string) => {
|
||||
if (isString(url) && url.includes("manifest.json")) {
|
||||
return new Response(JSON.stringify(mockManifest));
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ describe("Download and Failure Pipeline", () => {
|
|||
|
||||
/** Set up fetch to return manifest from manifest URLs and custom responses for script URLs */
|
||||
function setupFetch(scriptHandler: (url: string) => Promise<Response>) {
|
||||
global.fetch = mock(async (url: string | URL | Request, init?: RequestInit) => {
|
||||
global.fetch = mock(async (url: string | URL | Request) => {
|
||||
const urlStr = isString(url) ? url : url instanceof URL ? url.toString() : url.url;
|
||||
if (urlStr.includes("manifest.json")) {
|
||||
return new Response(JSON.stringify(mockManifest));
|
||||
|
|
@ -280,9 +280,7 @@ describe("Download and Failure Pipeline", () => {
|
|||
});
|
||||
|
||||
it("should show mixed error for primary 404 and fallback 500", async () => {
|
||||
let callCount = 0;
|
||||
await setupFetch(async (url) => {
|
||||
callCount++;
|
||||
if (url.includes("openrouter.ai")) {
|
||||
return new Response("Not Found", {
|
||||
status: 404,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ describe("Manifest Integrity", () => {
|
|||
"implemented",
|
||||
"missing",
|
||||
];
|
||||
for (const [key, status] of matrixEntries) {
|
||||
for (const [, status] of matrixEntries) {
|
||||
expect(validStatuses).toContain(status);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ describe("Agent required field types", () => {
|
|||
});
|
||||
|
||||
it("env values should all be strings", () => {
|
||||
for (const [envKey, envVal] of Object.entries(agent.env)) {
|
||||
for (const [, envVal] of Object.entries(agent.env)) {
|
||||
expect(typeof envVal).toBe("string");
|
||||
}
|
||||
});
|
||||
|
|
@ -219,7 +219,7 @@ describe("Cloud optional field types (when present)", () => {
|
|||
describe("Cloud type values", () => {
|
||||
const validTypes = new Set<string>();
|
||||
|
||||
for (const [key, cloud] of allClouds) {
|
||||
for (const [, cloud] of allClouds) {
|
||||
validTypes.add(cloud.type);
|
||||
}
|
||||
|
||||
|
|
@ -241,11 +241,12 @@ describe("Cloud type values", () => {
|
|||
|
||||
describe("Env var interpolation patterns", () => {
|
||||
it("env values with ${...} should reference valid-looking env var names", () => {
|
||||
const varRefPattern = /\$\{([^}]+)\}/g;
|
||||
for (const [key, agent] of allAgents) {
|
||||
for (const [envKey, envVal] of Object.entries(agent.env)) {
|
||||
let match;
|
||||
while ((match = varRefPattern.exec(envVal)) !== null) {
|
||||
for (const [, agent] of allAgents) {
|
||||
for (const [, envVal] of Object.entries(agent.env)) {
|
||||
const matches = [
|
||||
...envVal.matchAll(/\$\{([^}]+)\}/g),
|
||||
];
|
||||
for (const match of matches) {
|
||||
const refName = match[1];
|
||||
// Referenced env var names should look like valid env vars
|
||||
expect(refName).toMatch(/^[A-Z][A-Z0-9_]*$/);
|
||||
|
|
@ -255,8 +256,8 @@ describe("Env var interpolation patterns", () => {
|
|||
});
|
||||
|
||||
it("env values should not contain unmatched ${", () => {
|
||||
for (const [key, agent] of allAgents) {
|
||||
for (const [envKey, envVal] of Object.entries(agent.env)) {
|
||||
for (const [, agent] of allAgents) {
|
||||
for (const [, envVal] of Object.entries(agent.env)) {
|
||||
// Count ${ and } occurrences
|
||||
const opens = (envVal.match(/\$\{/g) || []).length;
|
||||
const closes = (envVal.match(/\}/g) || []).length;
|
||||
|
|
@ -271,7 +272,7 @@ describe("Env var interpolation patterns", () => {
|
|||
|
||||
describe("Agent launch command consistency", () => {
|
||||
it("launch commands should not contain dangerous shell metacharacters", () => {
|
||||
for (const [key, agent] of allAgents) {
|
||||
for (const [, agent] of allAgents) {
|
||||
// Launch commands shouldn't have pipe-to-bash or command substitution
|
||||
expect(agent.launch).not.toMatch(/\|\s*bash/);
|
||||
expect(agent.launch).not.toMatch(/\|\s*sh/);
|
||||
|
|
@ -281,7 +282,7 @@ describe("Agent launch command consistency", () => {
|
|||
});
|
||||
|
||||
it("install commands should be strings (can contain pipe for curl|bash)", () => {
|
||||
for (const [key, agent] of allAgents) {
|
||||
for (const [, agent] of allAgents) {
|
||||
expect(typeof agent.install).toBe("string");
|
||||
expect(agent.install.trim().length).toBeGreaterThan(0);
|
||||
}
|
||||
|
|
@ -292,11 +293,11 @@ describe("Agent launch command consistency", () => {
|
|||
|
||||
describe("Interactive prompts structure", () => {
|
||||
it("all interactive_prompts entries should have non-empty prompt text and string defaults", () => {
|
||||
for (const [key, agent] of allAgents) {
|
||||
for (const [, agent] of allAgents) {
|
||||
if (agent.interactive_prompts === undefined) {
|
||||
continue;
|
||||
}
|
||||
for (const [promptKey, entry] of Object.entries(agent.interactive_prompts)) {
|
||||
for (const [, entry] of Object.entries(agent.interactive_prompts)) {
|
||||
expect(entry.prompt.trim().length).toBeGreaterThan(0);
|
||||
expect(entry.default).toBeDefined();
|
||||
expect(typeof entry.default).toBe("string");
|
||||
|
|
@ -386,7 +387,7 @@ describe("Agent metadata field types", () => {
|
|||
|
||||
describe("Config files structure", () => {
|
||||
it("config file paths should look like file paths and values should be objects", () => {
|
||||
for (const [key, agent] of allAgents) {
|
||||
for (const [, agent] of allAgents) {
|
||||
if (agent.config_files === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue