Files
hyperframes/packages/cli/src/commands/preview.missingBuild.test.ts
T
James RussoandClaude Fable 5.2 7a91dc9fe9 fix(cli): show control characters as text in sign-in, account status and preview lines (#8347)
* fix(cli): show control characters as text in sign-in, account status and preview lines

Account names, plan and billing values, device codes, failure reasons and
file paths printed by auth login, auth status and preview now go through
the shared text helper, so a control character is shown as \xNN instead
of being sent to the terminal. JSON output is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(cli): show control characters as text in the open-by-hand page address

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(cli): cover the sign-out path line; account status rows move to the reply-text change

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 06:27:41 +00:00

48 lines
1.8 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import { consumeCommandResult } from "../utils/commandResult.js";
import { runEmbeddedMode } from "./preview.js";
const ESC = String.fromCharCode(27);
const ODD = `od${ESC}[2Jd\x07`;
vi.mock("../utils/attendedTerminal.js", async (importOriginal) => ({
...(await importOriginal<typeof import("../utils/attendedTerminal.js")>()),
isUnattended: () => false,
}));
vi.mock("@clack/prompts", async (importOriginal) => ({
...(await importOriginal<typeof import("@clack/prompts")>()),
spinner: () => ({ start: vi.fn(), stop: vi.fn(), message: vi.fn() }),
intro: () => {},
}));
vi.mock("../server/studioServer.js", () => ({
resolveStudioBundle: () => ({ available: false, checkedPaths: [`/opt/${ODD}/studio`] }),
loadPreviewServerBuildSignature: async () => "test",
originForListeningAddress: () => undefined,
createStudioServer: () => {
throw new Error("the server is not started without a studio build");
},
}));
describe("preview with no studio build", () => {
afterEach(() => {
consumeCommandResult();
vi.restoreAllMocks();
});
// fails without the fix: the folder name is printed as it is on disk.
it("shows control characters in the folders it looked in as text", async () => {
const lines: string[] = [];
vi.spyOn(console, "error").mockImplementation((...args: unknown[]) => {
lines.push(args.join(" "));
});
await runEmbeddedMode("missing-build-project", 3057, { noOpen: true });
const text = lines.join("\n").replace(new RegExp(`${ESC}\\[[0-9;]*m`, "g"), "");
expect(text).toContain("/opt/od\\x1b[2Jd\\x07/studio");
expect(text).not.toContain(ESC);
expect(text).not.toContain("\x07");
expect(consumeCommandResult().exitCode).toBe(1);
});
});