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=37&format=json
83 linesFirst import 88% · pinch 11% · infra-split 1%Last change infra-split in version 37, 4 versions changed it

You're reading version 37. The newest is 318, and 1 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");
19const ISSUE = { comment: "string", description: "string", title: "string", drop: "boolean" } as const;
20const parse = (command: string, spec: Record<string, "string" | "boolean">, words: string[], stdin?: string) =>
21 readBodyFiles(command, parseArgs(command, words, withBodyFiles(command, spec)), dir, () => stdin ?? "");
23describe("bodies from a file or stdin", () => {
24 it("--comment-file and --description-file read the whole file, dropping one trailing new line", () => {
25 const a = parse("issue", ISSUE, ["5", "--comment-file", "body.md"]);
26 assert.equal(a.flags.get("comment"), BODY);
27 assert.equal(a.flags.has("comment-file"), false);
28 assert.deepEqual(a.positionals, ["5"]);
29 assert.equal(parse("issue", ISSUE, ["new", "T", "--description-file", "body.md"]).flags.get("description"), BODY);
30 });
32 it("- reads stdin, once", () => {
33 assert.equal(
34 parse("issue", ISSUE, ["5", "--comment-file", "-"], "from\nstdin\n").flags.get("comment"),
35 "from\nstdin",
36 );
37 assert.throws(
38 () => parse("issue", ISSUE, ["5", "--comment-file", "-", "--description-file", "-"], "x"),
39 /only one of the -file flags can read stdin/,
40 );
41 });
43 it("--file gives ask's question, answer's words and announce's text", () => {
44 assert.deepEqual(parse("ask", { issue: "string" }, ["alice", "--file", "body.md"]).positionals, ["alice", BODY]);
45 assert.deepEqual(parse("answer", { note: "string" }, ["12", "--file", "body.md"]).positionals, ["12", BODY]);
46 assert.deepEqual(parse("announce", { to: "string" }, ["--file", "body.md"]).positionals, [BODY]);
47 assert.throws(
48 () => parse("answer", { note: "string" }, ["12", "words", "--file", "body.md"]),
49 /--file gives answer's text, so leave the words off the command line/,
50 );
51 });
53 it("refuses both forms at once, a missing file and an empty one", () => {
54 assert.throws(() => parse("issue", ISSUE, ["5", "--comment", "x", "--comment-file", "body.md"]), /not both/);
55 assert.throws(() => parse("issue", ISSUE, ["5", "--comment-file", "nope.md"]), /no such file to read/);
56 assert.throws(() => parse("issue", ISSUE, ["5", "--comment-file", "empty.md"]), /the text is empty/);
57 });
59 it("refuses a lone - as the text, pointing at the -file flag (abso issue 182)", () => {
60 assert.throws(() => parse("issue", ISSUE, ["5", "--comment", "-"]), /--comment-file - reads the text from stdin/);
61 assert.throws(() => parse("issue", ISSUE, ["new", "T", "--description", "-"]), /--description-file -/);
62 assert.equal(parse("issue", ISSUE, ["5", "--comment", "- one item"]).flags.get("comment"), "- one item");
63 });
65 it("adds -file twins only for the text flags a command has, and says so in --help", () => {
66 assert.deepEqual(Object.keys(withBodyFiles("issue", ISSUE)).sort(), [
67 "comment",
68 "comment-file",
69 "description",
70 "description-file",
71 "drop",
72 "title",
73 ]);
74 assert.deepEqual(withBodyFiles("status", { short: "boolean" }), { short: "boolean" });
75 assert.throws(
76 () => parseArgs("status", ["--file", "x"], withBodyFiles("status", { short: "boolean" })),
77 /unknown option/,
78 );
79 assert.match(bodyFilesHelp("issue", ISSUE)!, /^--comment-file, --description-file <path> read that text/);
80 assert.match(bodyFilesHelp("answer", { note: "string" })!, /--note-file, --file <path>/);
81 assert.equal(bodyFilesHelp("status", { short: "boolean" }), undefined);
82 });
83});