mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-31 14:06:50 +01:00
* feat(bin): gstack-decision-trail and gstack-worktree-audit, ported from pstack (GSTA-123)
Two MIT ports from Lauren Tan's pstack (licenses/MIT-pstack.txt, NOTICE.md):
a TSV decision trail with the header-once append, the formula guard, a start
row per run and a --run admission check; and a read-only worktree audit with
size, merge state, dirty, remote, PR, last chat and a suggested bucket.
Docs: docs/unattended.md (the decision trail and its end-of-run audit),
autoplan/DRIVER.md, docs/CONTRIBUTOR_REFERENCE.md, docs/standalone-binaries.md,
docs/troubleshooting.md, one line in landing-report.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* test(egress): reasoned scanner exemption for gstack-worktree-audit's base fetch
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: pre-landing review of the pstack ports
bin/gstack-worktree-audit: a worktree path with a space is read whole (sed
on the porcelain 'worktree ' line, not awk's second field); a registered
worktree whose directory is gone prints a 'prunable' row instead of being
skipped; 'safe' now requires a clean tree and either merged into the base
or a closed/merged PR with every commit pushed, so unpushed commits or
untracked files on a merged branch read 'review' (the port's rule called
them safe); fork PRs are dropped and an open PR wins over an older closed
one on a reused branch name; GIT_TERMINAL_PROMPT=0 on the base fetch.
bin/gstack-decision-trail: only a leading -h/--help is help, so a '-h'
cell is appended as data; a trail without a final newline, with CRLF rows
or with a repeated header line is appended to correctly; a run id is
limited to [A-Za-z0-9._:@/-] (exit 2) so a tab or quote cannot break the
start-row idempotence check.
Tests cover each case; the 'without gh' test resolves git from
'git --exec-path' instead of a PATH rebuilt from a tool list. Docs,
CHANGELOG and --help text describe the stricter buckets.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: pre-landing review fixes, pass 2
bin/gstack-worktree-audit: a worktree whose own .git link is gone (git
marks it prunable, or its toplevel is another repository) prints a 'broken'
row in 'review' instead of describing the containing repository as clean
and safe; a locked entry whose directory is gone reads 'review', not
'prunable', since prune would not touch it; a clean tree names its
gitignored entries as 'clean,ignored:<n>' without changing the bucket; the
branch name is read from refs/heads/ by hand so a tag of the same name
cannot hide the PR; porcelain blocks are read with IFS=tab so paths with
leading or trailing spaces survive; a failed git status reads 'unknown',
never 'clean'; the base fetch also sets GIT_ASKPASS=true and ssh BatchMode.
bin/gstack-decision-trail: a file whose first line is not the header (a
blank file, rows written by hand) gets the header appended, and a UTF-8
BOM before the header no longer turns it into a data row.
Tests: the fake gh records its argv and runs the audit's own --jq over
canned JSON with a fork PR when jq is installed; row counts are asserted
before the every() checks; each test starts from the same gh and closed
worktree; the snapshot includes the worktree registry; new fixtures for
locked, broken, tag-shadowed and ignored-only worktrees, a blank trail and
a BOM. Docs and CHANGELOG describe the new DIRTY values and buckets.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: pre-landing review fixes, pass 3
bin/gstack-decision-trail: hasHeader looks for a header line anywhere in
the file, so a blank or hand-written trail gets exactly one header rather
than one per append. bin/gstack-worktree-audit: the broken-worktree check
uses rev-parse --show-cdup and the presence of /.git instead of
comparing two spellings of the same path, which differ on Git for Windows.
Test: the blank-trail case appends twice and asserts a single header.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* fix: adversarial review, pass 5 (rule-23 grant, one finding)
bin/gstack-worktree-audit: git status runs with --untracked-files=normal
--ignore-submodules=none, so a user's status.showUntrackedFiles=no config
cannot hide untracked files and let a worktree holding them read clean and
safe. Test: the fresh worktree under that config via GIT_CONFIG_* still
reads scratch:1 / review (red before the fix).
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* docs: documentation audit corrections for the pstack ports
docs/standalone-binaries.md, docs/CONTRIBUTOR_REFERENCE.md,
docs/troubleshooting.md: the audit's safe condition is stated in full
(clean and merged, or PR closed/merged with every commit pushed), the
DIRTY list names missing, broken and unknown, start is a reserved phase
name, and 'read-only' names the base fetch as the one write --no-fetch
skips. CHANGELOG.md says the same (the audit's one decision item).
Audit id gsta123-docs-20261026T221657Z, status updated, no blockers.
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
* Stamp 1.91.268.0 for #3494 (train slot 1, base d9b0d600)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
---------
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
264 lines
15 KiB
TypeScript
264 lines
15 KiB
TypeScript
/**
|
|
* Fixture test for bin/gstack-worktree-audit: a bare origin, a main clone and
|
|
* worktrees in every bucket the script knows, with a fake gh on PATH and a
|
|
* Claude Code transcript directory under CLAUDE_CONFIG_DIR. The audit reads
|
|
* only: the fixture is byte-compared before and after.
|
|
*/
|
|
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
import { spawnSync } from "node:child_process";
|
|
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
|
|
const ROOT = path.resolve(import.meta.dir, "..");
|
|
const BIN = path.join(ROOT, "bin", "gstack-worktree-audit");
|
|
|
|
let tmp: string;
|
|
let repo: string;
|
|
let origin: string;
|
|
let fakeBin: string;
|
|
let claudeDir: string;
|
|
const wts: Record<string, string> = {};
|
|
|
|
function git(cwd: string, ...args: string[]): string {
|
|
const r = spawnSync("git", args, { cwd, encoding: "utf8", timeout: 30_000, env: { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t" } });
|
|
if (r.status !== 0) throw new Error(`git ${args.join(" ")} failed: ${r.stderr}`);
|
|
return r.stdout.trim();
|
|
}
|
|
function commit(cwd: string, file: string, text: string, msg: string): void {
|
|
fs.writeFileSync(path.join(cwd, file), text);
|
|
git(cwd, "add", file);
|
|
git(cwd, "commit", "-q", "-m", msg);
|
|
}
|
|
function audit(...args: string[]) {
|
|
const r = spawnSync("bash", [BIN, ...args], {
|
|
cwd: repo, encoding: "utf8", timeout: 60_000,
|
|
env: { ...process.env, PATH: `${fakeBin}:${process.env.PATH}`, CLAUDE_CONFIG_DIR: claudeDir, HOME: tmp },
|
|
});
|
|
const lines = r.stdout.split("\n").filter(Boolean);
|
|
const header = lines[1]?.split("\t") ?? [];
|
|
const rows = lines.slice(2).map(l => Object.fromEntries(l.split("\t").map((v, i) => [header[i]!, v])) as Record<string, string>);
|
|
return { status: r.status, stderr: r.stderr, base: lines[0], header, rows, byPath: Object.fromEntries(rows.map(r => [r.WORKTREE, r])) };
|
|
}
|
|
function snapshot(dir: string): string {
|
|
const r = spawnSync("bash", ["-c", "find . -path ./.git -prune -o -type f -print0 | sort -z | xargs -0 sha256sum; git -C . status --porcelain; git -C . for-each-ref; git -C . worktree list --porcelain"], { cwd: dir, encoding: "utf8", timeout: 30_000 });
|
|
return r.stdout;
|
|
}
|
|
// The fake gh records its argv and, when jq is installed, runs the audit's own --jq expression over
|
|
// canned JSON (so the fork-PR filter is exercised); without jq it prints the TSV that expression yields.
|
|
function fakeGh(prs: Array<{ number: number; state: string; headRefName: string; isCrossRepository: boolean }>): void {
|
|
fs.writeFileSync(path.join(fakeBin, "prs.json"), JSON.stringify(prs));
|
|
fs.writeFileSync(path.join(fakeBin, "prs.tsv"), prs.filter(p => !p.isCrossRepository).map(p => `${p.headRefName}\t${p.number}\t${p.state.toLowerCase()}`).join("\n") + "\n");
|
|
fs.writeFileSync(path.join(fakeBin, "gh"), `#!/usr/bin/env bash
|
|
printf '%s\\n' "$@" > "${fakeBin}/gh-args"
|
|
expr=""; while [ $# -gt 0 ]; do [ "$1" = --jq ] && expr="$2"; shift; done
|
|
if command -v jq >/dev/null 2>&1 && [ -n "$expr" ]; then jq -r "$expr" "${fakeBin}/prs.json"; else cat "${fakeBin}/prs.tsv"; fi
|
|
`, { mode: 0o755 });
|
|
}
|
|
|
|
beforeAll(() => {
|
|
tmp = fs.mkdtempSync(path.join(os.tmpdir(), "gstack-wt-audit-"));
|
|
origin = path.join(tmp, "origin.git");
|
|
repo = path.join(tmp, "repo");
|
|
fs.mkdirSync(origin);
|
|
git(origin, "init", "-q", "--bare", "--initial-branch=main");
|
|
git(tmp, "clone", "-q", origin, repo);
|
|
git(repo, "checkout", "-q", "-b", "main");
|
|
commit(repo, "README.md", "# fixture\n", "initial");
|
|
git(repo, "push", "-q", "-u", "origin", "main");
|
|
|
|
// merged: a branch whose commit was fast-forwarded into main and pushed; clean tree, branch never pushed.
|
|
wts.merged = path.join(tmp, "wt-merged");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/merged", wts.merged);
|
|
commit(wts.merged, "merged.txt", "done\n", "merged work");
|
|
git(repo, "merge", "-q", "--ff-only", "feat/merged");
|
|
git(repo, "push", "-q", "origin", "main");
|
|
|
|
// wip: pushed branch with a tracked edit on top; its PR is open.
|
|
wts.wip = path.join(tmp, "wt-wip");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/wip", wts.wip);
|
|
commit(wts.wip, "wip.txt", "v1\n", "wip work");
|
|
git(wts.wip, "push", "-q", "-u", "origin", "feat/wip");
|
|
fs.writeFileSync(path.join(wts.wip, "wip.txt"), "v2 edited\n");
|
|
|
|
// scratch: an unpushed branch, two untracked files, a chat from today → verify-recent-chat.
|
|
wts.scratch = path.join(tmp, "wt-scratch");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/scratch", wts.scratch);
|
|
commit(wts.scratch, "scratch.txt", "s\n", "scratch work");
|
|
fs.writeFileSync(path.join(wts.scratch, "notes.md"), "untracked\n");
|
|
fs.writeFileSync(path.join(wts.scratch, "tmp.log"), "untracked\n");
|
|
claudeDir = path.join(tmp, "claude");
|
|
const chat = path.join(claudeDir, "projects", wts.scratch.replace(/[^A-Za-z0-9]/g, "-"));
|
|
fs.mkdirSync(chat, { recursive: true });
|
|
fs.writeFileSync(path.join(chat, "session.jsonl"), "{}\n");
|
|
|
|
// stale: an unpushed branch nobody touched, no chat, no PR → review.
|
|
wts.stale = path.join(tmp, "wt-stale");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/stale", wts.stale);
|
|
commit(wts.stale, "stale.txt", "s\n", "stale work");
|
|
|
|
// closed: pushed branch whose PR was closed without merging → safe.
|
|
wts.closed = path.join(tmp, "wt-closed");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/closed", wts.closed);
|
|
commit(wts.closed, "closed.txt", "c\n", "closed work");
|
|
git(wts.closed, "push", "-q", "-u", "origin", "feat/closed");
|
|
|
|
fakeBin = path.join(tmp, "fakebin");
|
|
fs.mkdirSync(fakeBin);
|
|
|
|
// spaced: a worktree whose path has a space, merged into main, clean → safe.
|
|
wts.spaced = path.join(tmp, "wt with space");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/spaced", wts.spaced);
|
|
commit(wts.spaced, "spaced.txt", "s\n", "spaced work");
|
|
git(repo, "merge", "-q", "--ff-only", "feat/spaced");
|
|
git(repo, "push", "-q", "origin", "main");
|
|
|
|
// fresh: head is in main but an untracked file exists only here → review, not safe.
|
|
wts.fresh = path.join(tmp, "wt-fresh");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/fresh", wts.fresh);
|
|
fs.writeFileSync(path.join(wts.fresh, "newfeature.ts"), "export const x = 1;\n");
|
|
|
|
// gone: registered, directory deleted → prunable.
|
|
wts.gone = path.join(tmp, "wt-gone");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/gone", wts.gone);
|
|
fs.rmSync(wts.gone, { recursive: true, force: true });
|
|
|
|
// locked: registered and locked, directory gone → review (prune would not touch it).
|
|
wts.locked = path.join(tmp, "wt-locked");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/locked", wts.locked);
|
|
git(repo, "worktree", "lock", wts.locked);
|
|
fs.rmSync(wts.locked, { recursive: true, force: true });
|
|
|
|
// broken: a gitignored worktree inside the clone whose .git file is gone, with a
|
|
// precious file only there; git -C would describe the clone itself → review.
|
|
fs.appendFileSync(path.join(repo, ".git", "info", "exclude"), ".wt\n");
|
|
wts.broken = path.join(repo, ".wt", "broken");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/broken", wts.broken);
|
|
fs.writeFileSync(path.join(wts.broken, "precious.txt"), "only here\n");
|
|
fs.rmSync(path.join(wts.broken, ".git"));
|
|
|
|
// tagged: merged and clean, with a tag of the same name as its branch and an open PR → hold-open-pr.
|
|
wts.tagged = path.join(tmp, "wt-tagged");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/tagged", wts.tagged);
|
|
git(repo, "tag", "feat/tagged");
|
|
|
|
// ignored: merged and clean, with a gitignored .env → safe, DIRTY names the ignored entry.
|
|
wts.ignored = path.join(tmp, "wt-ignored");
|
|
git(repo, "worktree", "add", "-q", "-b", "feat/ignored", wts.ignored);
|
|
fs.writeFileSync(path.join(wts.ignored, ".gitignore"), ".env\n");
|
|
git(wts.ignored, "add", ".gitignore");
|
|
git(wts.ignored, "commit", "-q", "-m", "ignore .env");
|
|
git(repo, "merge", "-q", "--ff-only", "feat/ignored");
|
|
git(repo, "push", "-q", "origin", "main");
|
|
fs.writeFileSync(path.join(wts.ignored, ".env"), "SECRET=1\n");
|
|
});
|
|
// Each test starts from the same gh (one open, one closed, one fork PR on feat/stale that must be
|
|
// ignored) and the same closed worktree, whatever an earlier test changed.
|
|
beforeEach(() => {
|
|
fakeGh([
|
|
{ number: 41, state: "OPEN", headRefName: "feat/wip", isCrossRepository: false },
|
|
{ number: 40, state: "CLOSED", headRefName: "feat/closed", isCrossRepository: false },
|
|
{ number: 99, state: "OPEN", headRefName: "feat/stale", isCrossRepository: true },
|
|
{ number: 43, state: "OPEN", headRefName: "feat/tagged", isCrossRepository: false },
|
|
]);
|
|
git(wts.closed, "reset", "-q", "--hard", "origin/feat/closed");
|
|
});
|
|
afterAll(() => {
|
|
if (repo) spawnSync("git", ["worktree", "prune"], { cwd: repo, timeout: 30_000 });
|
|
if (tmp) fs.rmSync(tmp, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("gstack-worktree-audit", () => {
|
|
test("classifies every worktree, reads the PR column through gh, the chat through CLAUDE_CONFIG_DIR, and changes nothing", () => {
|
|
const live = Object.values(wts).filter(w => fs.existsSync(w));
|
|
const before = live.map(snapshot).join("\n") + snapshot(repo);
|
|
const r = audit();
|
|
expect(r.status).toBe(0);
|
|
expect(r.stderr).toContain("warn: no -b given; MERGED checks against origin/main");
|
|
expect(r.base).toBe("# base: origin/main");
|
|
expect(r.header).toEqual(["SIZE", "AGE", "MERGED", "DIRTY", "REMOTE", "PR", "LAST_CHAT", "BUCKET", "WORKTREE"]);
|
|
expect(r.rows).toHaveLength(12);
|
|
expect(r.byPath[repo]).toBeUndefined();
|
|
expect(r.byPath[wts.locked]).toMatchObject({ SIZE: "0", DIRTY: "missing", BUCKET: "review" });
|
|
expect(r.byPath[wts.broken]).toMatchObject({ DIRTY: "broken", BUCKET: "review" });
|
|
expect(r.byPath[wts.tagged]).toMatchObject({ MERGED: "YES", DIRTY: "clean", PR: "#43/open", BUCKET: "hold-open-pr" });
|
|
expect(r.byPath[wts.ignored]).toMatchObject({ MERGED: "YES", DIRTY: "clean,ignored:1", BUCKET: "safe" });
|
|
const ghArgs = fs.readFileSync(path.join(fakeBin, "gh-args"), "utf8").split("\n");
|
|
expect(ghArgs).toContain("number,state,headRefName,isCrossRepository");
|
|
expect(ghArgs.find(a => a.startsWith(".[]"))).toContain("select(.isCrossRepository | not)");
|
|
expect(r.byPath[wts.spaced]).toMatchObject({ MERGED: "YES", DIRTY: "clean", BUCKET: "safe" });
|
|
expect(r.byPath[wts.fresh]).toMatchObject({ MERGED: "YES", DIRTY: "scratch:1", REMOTE: "no-remote", BUCKET: "review" });
|
|
expect(r.byPath[wts.gone]).toMatchObject({ SIZE: "0", DIRTY: "missing", BUCKET: "prunable" });
|
|
expect(r.rows.slice(-2).map(row => row.WORKTREE).sort()).toEqual([wts.gone, wts.locked].sort());
|
|
|
|
const merged = r.byPath[wts.merged]!;
|
|
expect(merged).toMatchObject({ MERGED: "YES", DIRTY: "clean", REMOTE: "no-remote", PR: "-", LAST_CHAT: "-", BUCKET: "safe", AGE: "0d" });
|
|
expect(merged.SIZE).toMatch(/^\d+(\.\d+)?[KMG]?$/);
|
|
|
|
expect(r.byPath[wts.wip]).toMatchObject({ MERGED: "no", DIRTY: "wip:1", REMOTE: "pushed", PR: "#41/open", BUCKET: "hold-wip" });
|
|
const scratch = r.byPath[wts.scratch]!;
|
|
expect(scratch).toMatchObject({ MERGED: "no", DIRTY: "scratch:2", REMOTE: "no-remote", PR: "-", BUCKET: "verify-recent-chat" });
|
|
expect(scratch.LAST_CHAT).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
expect(r.byPath[wts.stale]).toMatchObject({ MERGED: "no", DIRTY: "clean", REMOTE: "no-remote", PR: "-", LAST_CHAT: "-", BUCKET: "review" });
|
|
expect(r.byPath[wts.closed]).toMatchObject({ MERGED: "no", DIRTY: "clean", REMOTE: "pushed", PR: "#40/closed", BUCKET: "safe" });
|
|
|
|
const after = live.map(snapshot).join("\n") + snapshot(repo);
|
|
expect(after).toBe(before);
|
|
});
|
|
|
|
test("status.showUntrackedFiles=no in the user's config does not hide untracked files", () => {
|
|
const r = spawnSync("bash", [BIN, "--no-fetch"], {
|
|
cwd: repo, encoding: "utf8", timeout: 60_000,
|
|
env: { ...process.env, PATH: `${fakeBin}:${process.env.PATH}`, CLAUDE_CONFIG_DIR: claudeDir, HOME: tmp, GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "status.showUntrackedFiles", GIT_CONFIG_VALUE_0: "no" },
|
|
});
|
|
expect(r.status).toBe(0);
|
|
const row = r.stdout.split("\n").find(l => l.endsWith("\t" + wts.fresh))!;
|
|
expect(row.split("\t").slice(3, 4)).toEqual(["scratch:1"]);
|
|
expect(row.split("\t")[7]).toBe("review");
|
|
});
|
|
|
|
test("an unpushed commit on a branch with a closed PR is review, an open PR on the same name wins and holds it, and -b picks the base", () => {
|
|
git(wts.closed, "commit", "-q", "--allow-empty", "-m", "one more");
|
|
const r1 = audit("-b", "origin/main", "--no-fetch", repo);
|
|
expect(r1.stderr).not.toContain("warn: no -b given");
|
|
expect(r1.byPath[wts.closed]).toMatchObject({ REMOTE: "ahead1", PR: "#40/closed", BUCKET: "review" });
|
|
fakeGh([
|
|
{ number: 40, state: "CLOSED", headRefName: "feat/closed", isCrossRepository: false },
|
|
{ number: 42, state: "OPEN", headRefName: "feat/closed", isCrossRepository: false },
|
|
]);
|
|
const r2 = audit("-b", "origin/main", "--no-fetch", repo);
|
|
expect(r2.byPath[wts.closed]).toMatchObject({ REMOTE: "ahead1", PR: "#42/open", BUCKET: "hold-open-pr" });
|
|
});
|
|
|
|
test("without gh the PR column is - with a warning, and a missing base ref or repo is an error", () => {
|
|
// A PATH with every tool the audit uses except gh. git goes in as the real binary from its
|
|
// exec path, since a distribution's /usr/bin/git may be a wrapper script that looks git up on PATH.
|
|
const noGh = path.join(tmp, "nogh");
|
|
fs.mkdirSync(noGh);
|
|
const onPath = (tool: string) => (process.env.PATH ?? "").split(path.delimiter).map(d => path.join(d, tool)).find(p => fs.existsSync(p));
|
|
const execPath = spawnSync("git", ["--exec-path"], { encoding: "utf8", timeout: 30_000 }).stdout.trim();
|
|
const realGit = [path.join(execPath, "git"), onPath("git")].find(p => p && fs.existsSync(p))!;
|
|
fs.symlinkSync(fs.realpathSync(realGit), path.join(noGh, "git"));
|
|
for (const tool of ["bash", "sh", "env", "du", "awk", "sed", "sort", "head", "find", "xargs", "stat", "date", "mktemp", "grep", "rm", "cat", "dirname", "basename", "uname", "tr", "cut", "wc"]) {
|
|
const found = onPath(tool);
|
|
if (found) fs.symlinkSync(fs.realpathSync(found), path.join(noGh, tool));
|
|
}
|
|
const r = spawnSync("bash", [BIN, "--no-fetch"], { cwd: repo, encoding: "utf8", timeout: 60_000, env: { ...process.env, PATH: noGh, CLAUDE_CONFIG_DIR: claudeDir, HOME: tmp } });
|
|
expect(r.status).toBe(0);
|
|
expect(r.stderr).toContain("PR column is -");
|
|
const rows = r.stdout.split("\n").filter(Boolean).slice(2);
|
|
expect(rows).toHaveLength(12);
|
|
expect(rows.every(l => l.split("\t")[5] === "-")).toBe(true);
|
|
fs.writeFileSync(path.join(fakeBin, "gh"), "#!/usr/bin/env bash\necho 'gh: not logged in' >&2; exit 4\n", { mode: 0o755 });
|
|
const failing = audit("--no-fetch");
|
|
expect(failing.status).toBe(0);
|
|
expect(failing.stderr).toContain("gh could not list this repository's PRs; PR column is -");
|
|
expect(failing.rows).toHaveLength(12);
|
|
expect(failing.rows.every(row => row.PR === "-")).toBe(true);
|
|
expect(audit("-b", "origin/nope", "--no-fetch").status).toBe(1);
|
|
expect(audit("--no-fetch", path.join(tmp, "not-a-repo")).status).toBe(1);
|
|
expect(audit("--bogus").status).toBe(2);
|
|
expect(audit("--help").status).toBe(0);
|
|
});
|
|
});
|