import { expect, spyOn, test } from "bun:test"; import * as cp from "node:child_process"; import * as packaging from "../../../packaging/runtime.js"; import * as skill from "../../../packaging/embedded-skill.js"; import { parseArgs } from "../../parser.js"; import { handleUpdateCommand } from "./index.js"; test("source and binary update previews do not fetch, spawn or install skills", async () => { const spawn = spyOn(cp, "spawnSync").mockImplementation(() => { throw new Error("unexpected spawn"); }); const sync = spyOn(skill, "syncGlobalSkillIfPresent").mockImplementation(() => { throw new Error("unexpected install"); }); const compiled = spyOn(packaging, "isCompiledBinary"); const oldFetch = globalThis.fetch; let requests = 0; globalThis.fetch = (async () => { requests++; throw new Error("unexpected fetch"); }) as any; try { for (const binary of [false, true]) { compiled.mockReturnValue(binary); const result = await handleUpdateCommand(parseArgs(["update", "--dry-run"]), { jsonMode: true } as any, { appRoot: "/tmp/update-preview" }); const preview = JSON.parse(result.stdout); expect(preview.dryRun).toBe(true); expect(preview.changes.mode).toBe(binary ? "binary" : "source"); expect(result.exitCode).toBe(0); } expect(requests).toBe(0); expect(spawn).not.toHaveBeenCalled(); expect(sync).not.toHaveBeenCalled(); } finally { globalThis.fetch = oldFetch; spawn.mockRestore(); sync.mockRestore(); compiled.mockRestore(); } });