Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/test/body-files.test.ts?version=285&format=json
90 linesFirst import 80% · pinch 19% · infra-split 1%Last change pinch in version 281, 5 versions changed it

You're reading version 285. The newest is 318, and no version since then changed this file. Go to the newestCompare with 318

1// Bodies from a file or stdin (body-files.ts): text with several lines arrives
2// whole, whatever shell passed the command.
3
4import assert from "node:assert/strict";
5import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
6import { tmpdir } from "node:os";
7import { join } from "node:path";
8import { after, describe, it } from "node:test";
9import { parseArgs } from "../src/args.ts";
10import { bodyFilesHelp, readBodyFiles, withBodyFiles } from "../src/body-files.ts";
12const dir = mkdtempSync(join(tmpdir(), "abso-body-"));
13after(() => rmSync(dir, { recursive: true, force: true }));
14const BODY = "First line:\n\n- one\n- two\n\nLast line.";
15// Written with one Windows line ending inside, which arrives as LF.
16writeFileSync(join(dir, "body.md"), `${BODY.replace("- two\n", "- two\r\n")}\r\n`);
17writeFileSync(join(dir, "empty.md"), "\n \n");
18// A reply as agents write them: prose, a code block and a Windows path, which no shell quoting mangles here.
19const REPLY = 'Checked it:\n\n```ts\nconst x = "a\\tb";\n```\n\nThe log is in C:\\Users\\me\\repo\\out.txt.';
20writeFileSync(join(dir, "reply.md"), `${REPLY}\n`);
22const ISSUE = { comment: "string", description: "string", title: "string", drop: "boolean" } as const;
23const parse = (command: string, spec: Record<string, "string" | "boolean">, words: string[], stdin?: string) =>
24 readBodyFiles(command, parseArgs(command, words, withBodyFiles(command, spec)), dir, () => stdin ?? "");
26describe("bodies from a file or stdin", () => {
27 it("--comment-file and --description-file read the whole file, dropping one trailing new line", () => {
28 const a = parse("issue", ISSUE, ["5", "--comment-file", "body.md"]);
29 assert.equal(a.flags.get("comment"), BODY);
30 assert.equal(a.flags.has("comment-file"), false);
31 assert.deepEqual(a.positionals, ["5"]);
32 assert.equal(parse("issue", ISSUE, ["new", "T", "--description-file", "body.md"]).flags.get("description"), BODY);
33 });
35 it("- reads stdin, once", () => {
36 assert.equal(
37 parse("issue", ISSUE, ["5", "--comment-file", "-"], "from\nstdin\n").flags.get("comment"),
38 "from\nstdin",
39 );
40 assert.throws(
41 () => parse("issue", ISSUE, ["5", "--comment-file", "-", "--description-file", "-"], "x"),
42 /only one of the -file flags can read stdin/,
43 );
44 });
46 it("--file gives ask's question, answer's and reply's words, and announce's text", () => {
47 assert.deepEqual(parse("ask", { issue: "string" }, ["alice", "--file", "body.md"]).positionals, ["alice", BODY]);
48 assert.deepEqual(parse("answer", { note: "string" }, ["12", "--file", "body.md"]).positionals, ["12", BODY]);
49 assert.deepEqual(parse("announce", { to: "string" }, ["--file", "body.md"]).positionals, [BODY]);
50 const reply = parse("reply", { question: "boolean" }, ["648", "--file", "reply.md", "--question"]);
51 assert.deepEqual(reply.positionals, ["648", REPLY]);
52 assert.equal(reply.flags.get("question"), true);
53 assert.match(bodyFilesHelp("reply", { question: "boolean" })!, /--file <path>/);
54 assert.throws(
55 () => parse("answer", { note: "string" }, ["12", "words", "--file", "body.md"]),
56 /--file gives answer's text, so leave the words off the command line/,
57 );
58 });
60 it("refuses both forms at once, a missing file and an empty one", () => {
61 assert.throws(() => parse("issue", ISSUE, ["5", "--comment", "x", "--comment-file", "body.md"]), /not both/);
62 assert.throws(() => parse("issue", ISSUE, ["5", "--comment-file", "nope.md"]), /no such file to read/);
63 assert.throws(() => parse("issue", ISSUE, ["5", "--comment-file", "empty.md"]), /the text is empty/);
64 });
66 it("refuses a lone - as the text, pointing at the -file flag (abso issue 182)", () => {
67 assert.throws(() => parse("issue", ISSUE, ["5", "--comment", "-"]), /--comment-file - reads the text from stdin/);
68 assert.throws(() => parse("issue", ISSUE, ["new", "T", "--description", "-"]), /--description-file -/);
69 assert.equal(parse("issue", ISSUE, ["5", "--comment", "- one item"]).flags.get("comment"), "- one item");
70 });
72 it("adds -file twins only for the text flags a command has, and says so in --help", () => {
73 assert.deepEqual(Object.keys(withBodyFiles("issue", ISSUE)).sort(), [
74 "comment",
75 "comment-file",
76 "description",
77 "description-file",
78 "drop",
79 "title",
80 ]);
81 assert.deepEqual(withBodyFiles("status", { short: "boolean" }), { short: "boolean" });
82 assert.throws(
83 () => parseArgs("status", ["--file", "x"], withBodyFiles("status", { short: "boolean" })),
84 /unknown option/,
85 );
86 assert.match(bodyFilesHelp("issue", ISSUE)!, /^--comment-file, --description-file <path> read that text/);
87 assert.match(bodyFilesHelp("answer", { note: "string" })!, /--note-file, --file <path>/);
88 assert.equal(bodyFilesHelp("status", { short: "boolean" }), undefined);
89 });
90});