fix(cli): preserve unsupported historical-source imports (#795)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect } from "vitest";
|
||||
@@ -13,6 +13,62 @@ const invalidRootOutput = {
|
||||
"Reference source directory could not be opened. Check that the path exists, is readable, and points to a directory.",
|
||||
};
|
||||
|
||||
const unsupportedHostOutput = {
|
||||
error: "Import failed",
|
||||
category: "unsupported_host",
|
||||
message:
|
||||
"Safe no-follow file opens are unavailable on this host. Import the source tree with REA on Linux (including WSL) or macOS.",
|
||||
};
|
||||
|
||||
describe("compiled Windows reference-source import", () => {
|
||||
for (const fullOutput of [false, true]) {
|
||||
for (const logging of [false, true]) {
|
||||
cliTest.runIf(process.platform === "win32")(
|
||||
`readable root, ${fullOutput ? "full-output" : "JSON"}, logging ${String(logging)}`,
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-reference-host-");
|
||||
const source = join(root, "source.js");
|
||||
const bytes = "export const answer = 42;\n";
|
||||
await writeFile(source, bytes);
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"import-reference-source",
|
||||
root,
|
||||
"--json",
|
||||
...(fullOutput ? ["--full-output"] : []),
|
||||
],
|
||||
cwd: root,
|
||||
environment: {
|
||||
USERPROFILE: root,
|
||||
XDG_CONFIG_HOME: root,
|
||||
XDG_CACHE_HOME: root,
|
||||
...(logging ? { REA_LOG_LEVEL: "info" } : {}),
|
||||
},
|
||||
});
|
||||
expect(result.json).toEqual(
|
||||
fullOutput
|
||||
? expect.objectContaining({
|
||||
ok: true,
|
||||
data: unsupportedHostOutput,
|
||||
})
|
||||
: unsupportedHostOutput,
|
||||
);
|
||||
expect.soft(result.exitCode).toBe(1);
|
||||
expect(await readFile(source, "utf8")).toBe(bytes);
|
||||
if (logging) {
|
||||
expect(JSON.parse(result.stderr.trim())).toMatchObject({
|
||||
command: "import-reference-source",
|
||||
status: "error",
|
||||
level: 50,
|
||||
msg: "CLI command failed",
|
||||
});
|
||||
} else expect(result.stderr).toBe("");
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe("compiled reference-source import preflight failures", () => {
|
||||
for (const rootKind of ["missing", "regular-file"] as const) {
|
||||
for (const fullOutput of [false, true]) {
|
||||
|
||||
Reference in New Issue
Block a user