fix: 清理 trans 文本旧入口示例
This commit is contained in:
@@ -3,6 +3,7 @@ import { Readable, Writable } from "node:stream";
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import {
|
||||
ApplyPatchV2Error,
|
||||
applyPatchV2HelpPayload,
|
||||
runApplyPatchV2,
|
||||
type ApplyPatchV2BulkReplacementWritePlan,
|
||||
type ApplyPatchV2FileSystem,
|
||||
@@ -35,6 +36,34 @@ function applyReplacementPlan(original: string, plan: ApplyPatchV2BulkReplacemen
|
||||
}
|
||||
|
||||
describe("apply-patch v2 stdin preflight", () => {
|
||||
test("documents quoted heredoc input without a temporary patch file", () => {
|
||||
const help = applyPatchV2HelpPayload();
|
||||
const serialized = JSON.stringify(help);
|
||||
|
||||
expect(help.command).toContain("<<'PATCH'");
|
||||
expect(help.usage.every((example) => example.includes("<<'PATCH'"))).toBe(true);
|
||||
expect(serialized).not.toMatch(/<\s+patch[.]diff/);
|
||||
expect(serialized).not.toMatch(/\/tmp\/patch[.]diff/);
|
||||
});
|
||||
|
||||
test("malformed input hint points directly to a quoted heredoc", async () => {
|
||||
const stdout = new CaptureWritable();
|
||||
const stderr = new CaptureWritable();
|
||||
|
||||
const exitCode = await runApplyPatchV2({
|
||||
executor: {},
|
||||
stdin: Readable.from(["not a patch\n"]),
|
||||
stdout,
|
||||
stderr,
|
||||
});
|
||||
|
||||
expect(exitCode).toBe(1);
|
||||
expect(stdout.text()).toBe("");
|
||||
expect(stderr.text()).toContain("trans <route> apply-patch <<'PATCH'");
|
||||
expect(stderr.text()).toContain("without a temporary patch file");
|
||||
expect(stderr.text()).not.toMatch(/\/tmp\/patch[.]diff/);
|
||||
});
|
||||
|
||||
test("fails immediately on an interactive TTY and points to a quoted heredoc", async () => {
|
||||
const stdin = Readable.from([]) as Readable & { isTTY?: boolean };
|
||||
Object.defineProperty(stdin, "isTTY", { value: true });
|
||||
|
||||
Reference in New Issue
Block a user