mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(cli): never prompt or auto-install when nobody is at the terminal
publish and upgrade called the confirmation prompt with no terminal check.
With stdin from /dev/null, publish exited 13; with an open pipe it hung.
Unattended and without --yes, both now exit 2 before doing any work, and
stderr names --yes (upgrade also names --check).
All prompts and spinners now go through ui/prompts.ts, the only module allowed
to import @clack/prompts (a lint rule and a contract test enforce it). Its
confirm, select, text and password refuse to prompt in an unattended run, and
its spinner prints only the final line, on stderr. init, feedback, catalog and
cloud delete decide whether to ask with isUnattended() instead of a TTY check
of their own.
The background auto-install no longer starts in an unattended run, and the
update notice ("Run: npm install -g ...") is not shown while an install for
that version is pending. CI now counts as set for any value but "false" or "0".
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test(cli): neutralize agent detection in the catalog offer tests through isAgentDriven
Attendance now reads isAgentDriven(), so that is what the catalog tests stub to
stay independent of the agent running the suite.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
93 lines
3.0 KiB
TypeScript
93 lines
3.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const spinners: Array<{ running: boolean }> = [];
|
|
const logError = vi.fn();
|
|
// A person at a terminal: the prompts and spinners these tests drive are refused otherwise.
|
|
vi.mock("../utils/attendedTerminal.js", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("../utils/attendedTerminal.js")>()),
|
|
isUnattended: () => false,
|
|
}));
|
|
vi.mock("@clack/prompts", () => ({
|
|
intro: vi.fn(),
|
|
outro: vi.fn(),
|
|
log: { error: (...args: unknown[]) => logError(...args) },
|
|
spinner: () => {
|
|
const state = { running: false };
|
|
spinners.push(state);
|
|
return {
|
|
start: () => (state.running = true),
|
|
message: vi.fn(),
|
|
stop: () => (state.running = false),
|
|
};
|
|
},
|
|
}));
|
|
|
|
const ensureBrowser = vi.fn();
|
|
const findBrowser = vi.fn();
|
|
let linuxArm = false;
|
|
vi.mock("../browser/manager.js", () => ({
|
|
ensureBrowser: (...args: unknown[]) => ensureBrowser(...args),
|
|
findBrowser: (...args: unknown[]) => findBrowser(...args),
|
|
clearBrowser: vi.fn(),
|
|
managedChromeVersion: () => "152.0.7977.30",
|
|
CACHE_DIR: "/cache",
|
|
isLinuxArm: () => linuxArm,
|
|
}));
|
|
vi.mock("../telemetry/events.js", () => ({ trackBrowserInstall: vi.fn() }));
|
|
|
|
const { default: browserCommand } = await import("./browser.js");
|
|
|
|
function runEnsure(force: boolean) {
|
|
return browserCommand.run!({
|
|
args: { _: [], subcommand: "ensure", force },
|
|
rawArgs: [],
|
|
cmd: browserCommand,
|
|
});
|
|
}
|
|
|
|
// A spinner left running keeps Node's event loop alive, so the CLI never exits.
|
|
describe("browser ensure", () => {
|
|
beforeEach(() => {
|
|
spinners.length = 0;
|
|
logError.mockReset();
|
|
ensureBrowser.mockReset();
|
|
findBrowser.mockReset();
|
|
linuxArm = false;
|
|
vi.spyOn(console, "log").mockImplementation(() => {});
|
|
});
|
|
|
|
it.each([false, true])(
|
|
"stops its spinner and fails when ensure throws (force=%s)",
|
|
async (force) => {
|
|
ensureBrowser.mockRejectedValue(
|
|
new Error("chrome-headless-shell is missing after unzipping"),
|
|
);
|
|
|
|
await expect(runEnsure(force)).rejects.toThrow("Command failed");
|
|
|
|
expect(logError).toHaveBeenCalledWith("chrome-headless-shell is missing after unzipping");
|
|
expect(spinners.length).toBeGreaterThan(0);
|
|
expect(spinners.filter((s) => s.running)).toEqual([]);
|
|
},
|
|
);
|
|
|
|
it.each([false, true])("leaves no spinner running after success (force=%s)", async (force) => {
|
|
ensureBrowser.mockResolvedValue({ executablePath: "/chrome", source: "download" });
|
|
|
|
await runEnsure(force);
|
|
|
|
expect(spinners.length).toBeGreaterThan(0);
|
|
expect(spinners.filter((s) => s.running)).toEqual([]);
|
|
});
|
|
|
|
it("stops its spinner and fails when the Linux ARM64 lookup throws", async () => {
|
|
linuxArm = true;
|
|
findBrowser.mockRejectedValue(new Error("EACCES: permission denied"));
|
|
|
|
await expect(runEnsure(false)).rejects.toThrow("Command failed");
|
|
|
|
expect(logError).toHaveBeenCalledWith("EACCES: permission denied");
|
|
expect(spinners.filter((s) => s.running)).toEqual([]);
|
|
});
|
|
});
|