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>
64 lines
2.5 KiB
TypeScript
64 lines
2.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { runCommand } from "citty";
|
|
|
|
const prompts = vi.hoisted(() => ({ errors: [] as string[], typedName: "" }));
|
|
|
|
// 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: () => undefined,
|
|
cancel: () => undefined,
|
|
isCancel: () => false,
|
|
text: async () => prompts.typedName,
|
|
log: { error: (message: string) => prompts.errors.push(message) },
|
|
}));
|
|
vi.mock("../ui/banner.js", () => ({ printBanner: () => undefined }));
|
|
|
|
describe("interactive init with a name too long for a folder", () => {
|
|
let dir: string;
|
|
let stdoutTty: PropertyDescriptor | undefined;
|
|
const unit = process.platform === "linux" ? "bytes" : "characters";
|
|
|
|
beforeEach(() => {
|
|
dir = mkdtempSync(join(tmpdir(), "hf-init-interactive-"));
|
|
prompts.errors = [];
|
|
stdoutTty = Object.getOwnPropertyDescriptor(process.stdout, "isTTY");
|
|
Object.defineProperty(process.stdout, "isTTY", { value: true, configurable: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (stdoutTty) Object.defineProperty(process.stdout, "isTTY", stdoutTty);
|
|
else delete (process.stdout as { isTTY?: boolean }).isTTY;
|
|
rmSync(dir, { recursive: true, force: true });
|
|
});
|
|
|
|
const runInit = async (rawArgs: string[]) => {
|
|
const command = (await import("./init.js")).default;
|
|
await runCommand(command, { rawArgs });
|
|
};
|
|
|
|
it("shows the plain sentence for a name given on the command line, before any folder is made", async () => {
|
|
const target = `${dir}/${"z".repeat(257)}/../${"a".repeat(256)}`;
|
|
await expect(runInit([target])).rejects.toThrow("Command failed");
|
|
expect(prompts.errors).toEqual([
|
|
`That name is 256 ${unit} long; a folder name can be at most 255 ${unit}.`,
|
|
]);
|
|
expect(readdirSync(dir)).toEqual([]);
|
|
});
|
|
|
|
it("shows the plain sentence for a name typed into the prompt", async () => {
|
|
prompts.typedName = `${dir}/${"z".repeat(301)}/../${"b".repeat(300)}`;
|
|
await expect(runInit([])).rejects.toThrow("Command failed");
|
|
expect(prompts.errors).toEqual([
|
|
`That name is 300 ${unit} long; a folder name can be at most 255 ${unit}.`,
|
|
]);
|
|
expect(readdirSync(dir)).toEqual([]);
|
|
});
|
|
});
|