mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-22 08:01:32 +01:00
On Capy, /ship hands its pull request edits and comments to Capy's PR tool, always naming the right repository (GST-3183) (#4518)
On Capy, /ship's PR body edits, comments and new PRs no longer go out through `gh` under the machine owner's GitHub account. Each write runs its checks, saves the exact text to a private file and prints a `HOST_PUBLISH:` line that names the repository (and host, off github.com) it belongs to, so Capy's PR tool sends it to the same place `gh` would have. Nothing changes outside Capy (`GSTACK_CAPY` unset). Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=specialist-batched Review-Finding: p1/specialist-batched#3 reader=specialist-batched Review-Finding: p1/red-team#6 reader=red-team Review-Finding: p1/specialist-batched#1 reader=testing Review-Finding: p1/specialist-batched#2 reader=testing
This commit is contained in:
1 parent
ed267248d3
commit
e95cea8404
15 files changed
+479
-18
No files matched your search
+5
-1
@@ -10,12 +10,15 @@
|
||||
* to gh/glab as an argv element or on stdin, never through a shell string.
|
||||
* Exit: 0 posted · 1 HIGH refused · 2 MEDIUM needs --confirm <token> ·
|
||||
* 3 gh/glab failed · 4 title not plain words (PLAIN_TITLE: lines) · 64 usage.
|
||||
* On Capy (GSTACK_CAPY=1) a write that passes every check is not sent: exit 0
|
||||
* prints HOST_PUBLISH: naming the files for the host's PR tool (lib/host-publish.ts).
|
||||
* Logic and full usage: lib/gstack-post.ts.
|
||||
*/
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import { spawnSync } from "../lib/spawn-sync";
|
||||
import { runPost } from "../lib/gstack-post";
|
||||
import { runPost, type HostDest } from "../lib/gstack-post";
|
||||
import { handOff, hostPublishes } from "../lib/host-publish";
|
||||
|
||||
const code = runPost(process.argv.slice(2), {
|
||||
run(cmd, args, input) {
|
||||
@@ -31,5 +34,6 @@ const code = runPost(process.argv.slice(2), {
|
||||
readFile: (p) => fs.readFileSync(p, "utf8"),
|
||||
out: (t) => process.stdout.write(t),
|
||||
err: (t) => process.stderr.write(t),
|
||||
...(hostPublishes() ? { hostPublish: (op: string, target: string | undefined, parts: Array<["title" | "body", string]>, dest: HostDest) => handOff({ op, target, parts, ...dest }) } : {}),
|
||||
}, path.join(import.meta.dir, "gstack-config"));
|
||||
process.exitCode = code;
|
||||
+18
-11
@@ -39,6 +39,7 @@ import * as fs from 'node:fs';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
import { ghSpawnSync } from '../lib/gh-poll';
|
||||
import { handOff, hostPublishes } from '../lib/host-publish';
|
||||
import { EXIT, exitTableHelp, NO_STOP_CLASSES, type ShipReceipt } from '../lib/headless-artifacts';
|
||||
import { resultLine, resultLineWithDocs } from '../lib/result-codes';
|
||||
import { versionAtRef } from '../lib/restamp';
|
||||
@@ -89,7 +90,7 @@ const HELP = `gstack-ship-receipt — the \`\`\`gstack-ship-receipt\`\`\` block
|
||||
carry the receipt to HEAD when only a base merge, tests, release metadata or registered
|
||||
outputs the --pregate regen check proved (recreated them) changed since its head (product patch-id
|
||||
unchanged), or after a rebase onto a tree the receipt covers with the recorded product
|
||||
patch-id: rewrites the receipt with a \`carry\` record, posts the body (gh pr edit) and
|
||||
patch-id: rewrites the receipt with a \`carry\` record, posts the body (gh pr edit; on Capy a HOST_PUBLISH: hand-off) and
|
||||
prints GSTACK_RESULT: skill=ship status=complete; RECEIPT_CARRY_PRODUCT_CHANGED /
|
||||
RECEIPT_CARRY_TREE_MISMATCH / RECEIPT_CARRY_REFUSED leave the body unchanged (exit 3);
|
||||
a receipt that records a pregate needs --pregate current for HEAD (RECEIPT_CARRY_PREGATE_STALE);
|
||||
@@ -109,7 +110,8 @@ const HELP = `gstack-ship-receipt — the \`\`\`gstack-ship-receipt\`\`\` block
|
||||
stub --pr <n> | --body <file> --run <id> [--head <sha>] [--review-loop <json|@file>] [--void]
|
||||
Step 9: record this /ship run's rounds so far in the runs block before its receipt exists, so a
|
||||
run that stops still counts; the run's receipt write (same --run) replaces it; --void marks an
|
||||
infrastructure failure that counts nothing
|
||||
infrastructure failure that counts nothing. stub, stop, claim and carry with --pr edit the PR body
|
||||
through gh; on Capy (GSTACK_CAPY=1) they print HOST_PUBLISH: with the body file instead (GST-3183)
|
||||
stop --pr <n> | --body <file> --run <id> --since <REVIEW_SINCE>
|
||||
Step 9, on NEXT: stop: record the review this run stopped on (its commit and tree, from the newest
|
||||
via:ship review row bound to one committed tree) as a stop record in the runs block, and print the
|
||||
@@ -971,14 +973,8 @@ function cmdCarry(rest: string[], json: boolean): number {
|
||||
process.stdout.write(json ? JSON.stringify({ skill: 'ship', status: 'dry-run', head, carry: plan.carry }) + '\n' : `CARRY: would carry from ${from.slice(0, 12)} to ${head.slice(0, 12)} (${plan.carry.reason}); nothing written\n`);
|
||||
return EXIT.ok;
|
||||
}
|
||||
if (bodyFile) fs.writeFileSync(bodyFile, newBody);
|
||||
else {
|
||||
const tmp = path.join(fs.mkdtempSync(path.join(process.env.TMPDIR ?? '/tmp', 'gstack-carry-')), 'body.md');
|
||||
fs.writeFileSync(tmp, newBody, { mode: 0o600 });
|
||||
const edit = gh(['pr', 'edit', pr!, ...(repo ? ['--repo', repo] : []), '--body-file', tmp]);
|
||||
fs.rmSync(path.dirname(tmp), { recursive: true, force: true });
|
||||
if (!edit.ok) return incomplete(`gh pr edit failed: ${edit.err}; the receipt was not carried`);
|
||||
}
|
||||
const posted = postBody(rest, pr, newBody);
|
||||
if (posted) return incomplete(`${posted}; the receipt was not carried`);
|
||||
process.stdout.write(`CARRY: carried from ${from.slice(0, 12)} to ${head.slice(0, 12)} (${plan.carry.reason})\n`);
|
||||
return writeRunRecord({ receipt: carried, head, pr, source, repoRoot, out: flag(rest, '--out'), json, line, incomplete, extra: { carried_from: carried.carry!.from, carry_reason: carried.carry!.reason } });
|
||||
}
|
||||
@@ -1069,10 +1065,20 @@ function readBody(rest: string[]): { ok: true; body: string; pr?: string } | { o
|
||||
try { return { ok: true, body: JSON.parse(r.out).body ?? '', pr }; } catch { return { ok: false, why: 'gh returned no JSON body', fix: 'rerun; check gh auth status' }; }
|
||||
}
|
||||
|
||||
/** Write the body back: to --body, to a HOST_PUBLISH hand-off on Capy (GST-3183), else through gh pr edit. */
|
||||
function postBody(rest: string[], pr: string | undefined, body: string): string | null {
|
||||
const bodyFile = flag(rest, '--body');
|
||||
if (bodyFile) { fs.writeFileSync(bodyFile, body); return null; }
|
||||
const repo = flag(rest, '--repo');
|
||||
if (hostPublishes()) {
|
||||
const view = gh(['repo', 'view', ...(repo ? [repo] : []), '--json', 'nameWithOwner,url']);
|
||||
let dest: { repo: string; host: string } | undefined;
|
||||
try { const v = JSON.parse(view.out); dest = { repo: String(v.nameWithOwner ?? ''), host: new URL(String(v.url)).host }; } catch { dest = undefined; }
|
||||
if (!view.ok || !dest?.repo) return `cannot resolve the repository gh pr edit would have edited (gh repo view${repo ? ` ${repo}` : ''} --json nameWithOwner,url: ${view.err.split('\n')[0] || 'no repository'}); pass --repo <owner/repo>, nothing was handed off`;
|
||||
try { process.stdout.write(handOff({ op: 'pr-body', target: pr, ...dest, parts: [['body', body]] })); }
|
||||
catch (e) { return `cannot write the hand-off for the host's PR tool (${(e as Error).message}), nothing was handed off`; }
|
||||
return null;
|
||||
}
|
||||
const tmp = path.join(fs.mkdtempSync(path.join(process.env.TMPDIR ?? '/tmp', 'gstack-runs-')), 'body.md');
|
||||
fs.writeFileSync(tmp, body, { mode: 0o600 });
|
||||
const edit = gh(['pr', 'edit', pr!, ...(repo ? ['--repo', repo] : []), '--body-file', tmp]);
|
||||
@@ -1143,7 +1149,8 @@ function cmdClaim(rest: string[]): number {
|
||||
if (other) { process.stderr.write(`${resultLine('gstack-ship-receipt claim', 'GRANT_SPENT', `grant ${id} was claimed by run ${other.run}: a grant buys one round; the lane or its Captain records a new one`)}\n`); return EXIT.refused; }
|
||||
const err = postBody(rest, read.pr, placeRunEntry(read.body, grantMarker({ head: g.head, run, grant: id })));
|
||||
if (err) { process.stderr.write(`gstack-ship-receipt claim: ${err}; not claimed, so do not dispatch\n`); return EXIT.fail; }
|
||||
const again = readBody(rest);
|
||||
const handedOff = !flag(rest, '--body') && hostPublishes();
|
||||
const again = handedOff ? { ok: true as const, body: placeRunEntry(read.body, grantMarker({ head: g.head, run, grant: id })) } : readBody(rest);
|
||||
if (!again.ok) { process.stderr.write(`gstack-ship-receipt claim: ${again.why}; the claim is unconfirmed, so do not dispatch\n`); return EXIT.fail; }
|
||||
const first = receiptRuns(again.body).find(r => r.mark === 'grant' && r.grant === id);
|
||||
if (first?.run !== run) { process.stderr.write(`${resultLine('gstack-ship-receipt claim', 'GRANT_SPENT', `grant ${id} was claimed by run ${first?.run ?? 'another run'} while this run claimed it: a grant buys one round; the lane or its Captain records a new one`)}\n`); return EXIT.refused; }
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
important: security
|
||||
---
|
||||
- **On Capy, /ship no longer edits or comments on pull requests as you.** On a Capy machine, `gh` is signed in as the machine owner's own GitHub account, so when /ship recorded its review rounds in a PR body (`gstack-ship-receipt stub`, `stop`, `claim` and `carry`) or posted a body, title, comment or new PR through `gstack-post`, the change showed up under the owner's name, even on someone else's PR. Under `GSTACK_CAPY=1` these commands now run every check they ran before, write the exact text they would have sent to a private file, and print a `HOST_PUBLISH:` line naming it and the repository (and host, when it isn't github.com) it was meant for, so the agent publishes it through Capy's own PR tool instead. Nothing changes outside Capy.
|
||||
@@ -3309,6 +3309,32 @@ the same digits with a `+`, spaces, dashes, dots or parentheses still report.
|
||||
using the `TOKEN:` line the refusal printed; MEDIUM findings do not block
|
||||
pushes.
|
||||
|
||||
<a id="host-publish"></a>
|
||||
### Host publish
|
||||
|
||||
**Meaning.** A `HOST_PUBLISH:` line means nothing was sent through gh. On Capy (`GSTACK_CAPY=1`) the machine's `gh` is signed in as the owner's own GitHub
|
||||
account, so gstack never writes to GitHub through it there (GST-3183). `gstack-post` (every write
|
||||
op) and `gstack-ship-receipt stub`, `stop`, `claim` and `carry` with `--pr` run all their checks as
|
||||
before, then write the exact title and body they would have sent to
|
||||
a new private directory `<state root>/publish/<op>-<target>-<random>/<part>.md` (mode 0600, so one
|
||||
hand-off never overwrites another still waiting to be published) and print one line:
|
||||
`HOST_PUBLISH: <op> <target> repo=<owner/name> [host=<host>] [to=<comment id>] [base=<branch>] [head=<branch>] [draft] body-file=<path> [title-file=<path>] (...)`,
|
||||
which names everything gh would have worked out from the checkout: `repo=` always (read with `gh repo view
|
||||
--json nameWithOwner,url`, so a fork checkout's `gh repo set-default` or `GH_REPO` is honoured as gh's write
|
||||
would have; `gstack-post` on GitLab uses the origin remote), `host=` when it is not
|
||||
github.com, a reply's comment, and a new PR's base, head (the current branch when `--head` is not passed) and draft
|
||||
state. Nothing reached GitHub yet. When the repository cannot be resolved the command refuses and prints no line,
|
||||
because a hand-off without one would land on whatever repository the host tool defaults to.
|
||||
|
||||
**Fix.** Publish the named files with the host's PR tool before the next gstack step, always passing `repo=`
|
||||
(Capy's `repo` argument) so a multi-repo or fork thread edits the right pull request; a `host=` the host tool
|
||||
cannot reach goes to whoever owns the work. Use `pr-body` and
|
||||
`pr-title` with Capy's `tools.pr.edit`, `pr-comment` and `reply` with `tools.pr.comment`, `pr-create`
|
||||
with `tools.pr.create`. Capy has no GitHub issue tool, so an `issue-create` or an `issue-comment` on an
|
||||
issue goes to whoever owns the work. Never run the `gh` write yourself. `claim` cannot read its own
|
||||
marker back before you publish, so a second run that claims the same grant is caught by the next
|
||||
`gstack-ship-receipt history` instead (`PR_REVIEW_GRANT: not applied`).
|
||||
|
||||
<a id="gstack-post-pr-body-merge"></a>
|
||||
### `gstack-post pr-body` kept sections the body file did not contain
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ function open(env: EarlyEnv, args: string[]): number {
|
||||
env.out(created.stdout);
|
||||
if (created.status !== 0) { env.err(created.stderr); return created.status; }
|
||||
const url = /^https?:\/\/\S+\/pull\/(\d+)\s*$/m.exec(created.stdout);
|
||||
if (!url && /^HOST_PUBLISH: /m.test(created.stdout)) { env.err("gstack-post handed the draft to the host's PR tool (HOST_PUBLISH above), so there is no PR to trigger yet; open it there or continue without early review.\n"); return 3; }
|
||||
if (!url) { env.err("gstack-post did not print the new PR URL.\n"); return 3; }
|
||||
env.out(`EARLY_PR: ${url[1]}\nEARLY_PR_URL: ${url[0].trim()}\nEARLY_PR_OPENED_AT: ${Math.floor(env.now() / 1000)}\n`);
|
||||
if (ready) { env.out("GREPTILE_TRIGGER: not needed (ready PR; Greptile reviews it when opened)\n"); return 0; }
|
||||
|
||||
+25
-1
@@ -54,8 +54,13 @@ export interface PostEnv {
|
||||
readFile(path: string): string;
|
||||
out(text: string): void;
|
||||
err(text: string): void;
|
||||
/** On Capy (GSTACK_CAPY=1): write the checked parts for the host's PR tool and return its HOST_PUBLISH: line; gh is never called to write (GST-3183). */
|
||||
hostPublish?(op: Op, target: string | undefined, parts: Array<[Part, string]>, dest: HostDest): string;
|
||||
}
|
||||
|
||||
/** Where the gh write would have gone, so the host's PR tool can send the hand-off to the same place. */
|
||||
export interface HostDest { repo: string; host: string; to?: string; base?: string; head?: string; draft: boolean }
|
||||
|
||||
export const EXIT = { posted: 0, refused: 1, confirm: 2, cliFailed: 3, plainTitle: 4, usage: 64 } as const;
|
||||
|
||||
export const USAGE = `usage: gstack-post <op> [<target>] [options]
|
||||
@@ -473,7 +478,7 @@ function visibility(env: PostEnv, req: Request, kind: HostKind, configBin: strin
|
||||
try { return norm(String(JSON.parse(gl.stdout).visibility ?? "")) ?? "unknown"; } catch { return "unknown"; }
|
||||
}
|
||||
|
||||
type Part = "title" | "body";
|
||||
export type Part = "title" | "body";
|
||||
interface Located { part: Part; finding: Finding }
|
||||
|
||||
/**
|
||||
@@ -835,6 +840,25 @@ export function runPost(argv: string[], env: PostEnv, configBin = "gstack-config
|
||||
return EXIT.confirm;
|
||||
}
|
||||
}
|
||||
if (env.hostPublish) {
|
||||
let head = req.head;
|
||||
if (req.op === "pr-create" && !head) {
|
||||
const b = env.run("git", ["branch", "--show-current"]);
|
||||
head = b.status === 0 ? b.stdout.trim() : "";
|
||||
if (!head) throw new UsageError("pr-create on Capy needs --head <branch> when HEAD is detached: the host's PR tool cannot infer it");
|
||||
}
|
||||
let dest = { repo: remote.segments.join("/"), host: remote.host };
|
||||
if (remote.kind === "github") {
|
||||
const view = env.run("gh", ["repo", "view", "--json", "nameWithOwner,url"]);
|
||||
try { const v = JSON.parse(view.stdout); dest = { repo: String(v.nameWithOwner ?? ""), host: new URL(String(v.url)).host }; } catch { dest = { repo: "", host: "" }; }
|
||||
if (view.status !== 0 || !dest.repo) { env.err(`gstack-post: cannot resolve the repository gh would have written to (gh repo view --json nameWithOwner,url: ${view.stderr.trim().split("\n")[0] || "no repository"}); nothing was handed off\n`); return EXIT.cliFailed; }
|
||||
}
|
||||
let line: string;
|
||||
try { line = env.hostPublish(req.op, n, parts, { ...dest, to: req.to, base: req.base, head, draft: req.draft }); }
|
||||
catch (e) { env.err(`gstack-post: could not write the hand-off for the host's PR tool: ${(e as Error).message}; nothing was handed off\n`); return EXIT.cliFailed; }
|
||||
env.out(line);
|
||||
return EXIT.posted;
|
||||
}
|
||||
return send(env, remote.kind, req, n, title, body);
|
||||
} catch (e) {
|
||||
if (!(e instanceof UsageError)) throw e;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* host-publish — GitHub writes on Capy go through the host's PR tool, never gh (GST-3183).
|
||||
*
|
||||
* On Capy (GSTACK_CAPY=1) the machine's gh is signed in as the owner's personal GitHub account, so an edit, comment or
|
||||
* new PR sent through gh lands under their name (GBEV-105, 2026-11-19: `gstack-ship-receipt stub` edited an outside
|
||||
* system's PR body as the owner during an unattended /ship). Each /ship command that would write through gh asks
|
||||
* hostPublishes() first; when it answers true the command writes the exact bytes it would have sent to a private file
|
||||
* under the state root and prints the one HOST_PUBLISH: line handOff() returns, and the agent publishes that file with
|
||||
* its host's PR tool (Capy's tools.pr.edit, tools.pr.comment or tools.pr.create). Reads through gh are unchanged.
|
||||
*/
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { resolveStateRoot, type StateRootEnv } from './state-root';
|
||||
|
||||
export const hostPublishes = (env: StateRootEnv = process.env): boolean => env.GSTACK_CAPY === '1';
|
||||
|
||||
/** What the host's PR tool does with each operation's files, as the HOST_PUBLISH: line says it. */
|
||||
const HOST_TOOL: Record<string, string> = {
|
||||
'pr-body': "replace the PR's body with body-file (Capy: tools.pr.edit body)",
|
||||
'pr-title': "set the PR's title to title-file (Capy: tools.pr.edit title)",
|
||||
'pr-comment': 'post body-file as a PR comment (Capy: tools.pr.comment)',
|
||||
'issue-comment': 'post body-file as a comment on that issue or PR (Capy: tools.pr.comment on a PR; an issue goes to whoever owns the work)',
|
||||
reply: 'post body-file as a reply in that review thread (Capy: tools.pr.comment reply_to)',
|
||||
'pr-create': 'open the PR from title-file and body-file (Capy: tools.pr.create)',
|
||||
'issue-create': 'open the issue from title-file and body-file, or hand both files to whoever owns the work (Capy has no GitHub issue tool)',
|
||||
};
|
||||
|
||||
/** A repository path the host tool can be pointed at: owner/name, or a GitLab group path. */
|
||||
const REPO_PATH = /^[\w.-]+(\/[\w.-]+)+$/;
|
||||
|
||||
/**
|
||||
* Write each part to a new private directory <state root>/publish/<op>-<target>-<random>/<part>.md (mode 0600), so no
|
||||
* hand-off ever overwrites another one still waiting to be published (another repo's PR #7, a second pr-create), and return the HOST_PUBLISH: line naming them and the destination the gh write would have used
|
||||
* (repo= always, host= unless github.com, reply's to=, pr-create's base=, head= and draft), with a newline. The host tool
|
||||
* has nothing else to go on and would fall back to the thread's primary repository, so a hand-off without a resolved
|
||||
* repo throws before any file is written.
|
||||
*/
|
||||
export function handOff(o: { op: string; target?: string; repo: string; host?: string; to?: string; base?: string; head?: string; draft?: boolean; parts: Array<[string, string]>; env?: StateRootEnv }): string {
|
||||
if (!REPO_PATH.test(o.repo ?? '')) throw new Error(`HOST_PUBLISH needs the destination repository (owner/name), got ${JSON.stringify(o.repo ?? '')}`);
|
||||
if (o.host !== undefined && !/^[\w.-]+(:\d+)?$/.test(o.host)) throw new Error(`HOST_PUBLISH host ${JSON.stringify(o.host)} is not a hostname`);
|
||||
const host = o.host && o.host.toLowerCase() !== 'github.com' ? o.host.toLowerCase() : undefined;
|
||||
const dir = path.join(resolveStateRoot(o.env ?? process.env), 'publish');
|
||||
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
||||
const own = fs.mkdtempSync(path.join(dir, `${o.op}-${(o.target ?? 'new').replace(/[^\w.-]/g, '_')}-`));
|
||||
fs.chmodSync(own, 0o700);
|
||||
const files = o.parts.map(([part, text]) => {
|
||||
const file = path.join(own, `${part}.md`);
|
||||
fs.writeFileSync(file, text, { mode: 0o600 });
|
||||
fs.chmodSync(file, 0o600);
|
||||
return `${part}-file=${file}`;
|
||||
});
|
||||
const dest = [`repo=${o.repo}`, host && `host=${host}`, o.to && `to=${o.to}`, o.base && `base=${o.base}`, o.head && `head=${o.head}`, o.draft && 'draft'].filter(Boolean).map((d) => ` ${d}`).join('');
|
||||
return `HOST_PUBLISH: ${o.op} ${o.target ?? 'new'}${dest} ${files.join(' ')} (gh was not called: on Capy it signs in as the owner's own GitHub account; ${HOST_TOOL[o.op] ?? 'publish these files with the host PR tool'}, before the next gstack step; docs/troubleshooting.md#host-publish)\n`;
|
||||
}
|
||||
@@ -452,6 +452,10 @@ export const KNOWN_WINDOWS_INCOMPATIBLE: Array<{ file: string; reason: string }>
|
||||
file: 'test/ship-base-side-masks.test.ts',
|
||||
reason: 'drives bin/gstack-ship-release, gstack-docs-candidate and gstack-wtree (shebangs) through test/helpers/ship-bin-fixture.ts like test/ship-rereview-triggers.test.ts; windows-latest fails every case at the first bin spawn (windows-scoped-shard, run 41950236362)',
|
||||
},
|
||||
{
|
||||
file: 'test/capy-host-publish.test.ts',
|
||||
reason: 'drives bin/gstack-ship-receipt, gstack-post, gstack-approvals and gstack-review-log (shebangs) plus a #!/bin/sh gh shim through test/helpers/ship-bin-fixture.ts and restamp-fixture.ts, like test/round-cap-granted-stop.test.ts',
|
||||
},
|
||||
{
|
||||
file: 'test/round-cap-granted-stop.test.ts',
|
||||
reason: 'drives bin/gstack-ship-receipt, gstack-approvals, gstack-review-plan, gstack-review-log, gstack-review-scope and gstack-ship-release (shebangs) through test/helpers/ship-bin-fixture.ts like test/ship-finish-fixed-links.test.ts; a bin spawn fails on windows-latest the same way (first-bin-spawn failure class of test/ship-uid-sidecar.test.ts)',
|
||||
|
||||
@@ -12,7 +12,9 @@ repeating the captions. gstack-post folds each into a collapsed section. `## App
|
||||
Agent notes section, where `gstack-ship-receipt write` also puts the receipt. A body posted any other way,
|
||||
Capy's PR tool included, is folded first: pass the output of
|
||||
`~/.claude/skills/gstack/bin/gstack-post fold --body-file "$PR_BODY_FILE"` (it posts nothing, and exit 4
|
||||
with `PLAIN_BODY:` lines means rewrite the body file first).
|
||||
with `PLAIN_BODY:` lines means rewrite the body file first). Under Capy `gstack-post` and the receipt
|
||||
commands never write through `gh`, which signs in as the owner: each prints `HOST_PUBLISH:` with the files to
|
||||
publish through the host's PR tool before the next step, to the `repo=` it names.
|
||||
|
||||
1. **Pick the evidence:** one to three before/after pairs, highest-signal first. The first is the
|
||||
key image.
|
||||
|
||||
@@ -10,7 +10,9 @@ repeating the captions. gstack-post folds each into a collapsed section. `## App
|
||||
Agent notes section, where `gstack-ship-receipt write` also puts the receipt. A body posted any other way,
|
||||
Capy's PR tool included, is folded first: pass the output of
|
||||
`~/.claude/skills/gstack/bin/gstack-post fold --body-file "$PR_BODY_FILE"` (it posts nothing, and exit 4
|
||||
with `PLAIN_BODY:` lines means rewrite the body file first).
|
||||
with `PLAIN_BODY:` lines means rewrite the body file first). Under Capy `gstack-post` and the receipt
|
||||
commands never write through `gh`, which signs in as the owner: each prints `HOST_PUBLISH:` with the files to
|
||||
publish through the host's PR tool before the next step, to the `repo=` it names.
|
||||
|
||||
1. **Pick the evidence:** one to three before/after pairs, highest-signal first. The first is the
|
||||
key image.
|
||||
|
||||
@@ -309,7 +309,7 @@ It updates the body, then the title, retries a retired-GraphQL edit through REST
|
||||
reads the title back. Then resolve the draft state from Step 9's gate findings:
|
||||
|
||||
1. Step 6.5 opened this PR as an early draft, the user did not ask for a draft, and no
|
||||
gate finding is `open`: mark it ready now with `gh pr ready <pr-number>`.
|
||||
gate finding is `open`: mark it ready now with `gh pr ready <pr-number>` (on Capy, with the host's PR tool instead).
|
||||
2. Step 6.5 opened it as an early draft and any gate finding is `open`: leave it a
|
||||
draft; print `Draft kept: Gate edits: N open` and the open findings' `gate` and path.
|
||||
3. The PR was already ready (not a draft) and any gate finding is `open`: publish only
|
||||
|
||||
@@ -292,7 +292,7 @@ It updates the body, then the title, retries a retired-GraphQL edit through REST
|
||||
reads the title back. Then resolve the draft state from Step 9's gate findings:
|
||||
|
||||
1. Step 6.5 opened this PR as an early draft, the user did not ask for a draft, and no
|
||||
gate finding is `open`: mark it ready now with `gh pr ready <pr-number>`.
|
||||
gate finding is `open`: mark it ready now with `gh pr ready <pr-number>` (on Capy, with the host's PR tool instead).
|
||||
2. Step 6.5 opened it as an early draft and any gate finding is `open`: leave it a
|
||||
draft; print `Draft kept: Gate edits: N open` and the open findings' `gate` and path.
|
||||
3. The PR was already ready (not a draft) and any gate finding is `open`: publish only
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
/**
|
||||
* GST-3183: on Capy (GSTACK_CAPY=1) the machine's gh is signed in as the owner's personal GitHub account, so a gh write
|
||||
* from /ship lands under their name. GBEV-105 (2026-11-19) saw `gstack-ship-receipt stub` edit an outside system's PR
|
||||
* body that way during an unattended /ship. Every /ship write path now hands the exact bytes to the host's PR tool
|
||||
* instead: it writes them to a private file and prints one HOST_PUBLISH: line. A recording gh shim proves no write call
|
||||
* reaches gh, and the negative control proves the shim does record one when GSTACK_CAPY is unset.
|
||||
*/
|
||||
import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { placeReceipt } from '../lib/ship-receipt';
|
||||
import { cleanup, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/restamp-fixture';
|
||||
import { RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';
|
||||
|
||||
setDefaultTimeout(90_000);
|
||||
const BIN = path.dirname(RELEASE);
|
||||
const fxs: ShipFx[] = [];
|
||||
const repos: FixtureRepo[] = [];
|
||||
afterEach(() => { while (fxs.length) fxs.pop()!.cleanup(); while (repos.length) cleanup(repos.pop()!); });
|
||||
|
||||
const WRITE = /^(pr\t(edit|comment|create|ready|close|merge|review)|issue\t(comment|create|edit|close))\t/;
|
||||
/** A recorded gh call that changes GitHub: a pr or issue edit, comment, create, ready or close, or an api call that is not a GET. */
|
||||
const isWrite = (call: string) => WRITE.test(call + '\t')
|
||||
|| (/^api\t/.test(call) && (/\t(--method|-X)(=|\t)(POST|PATCH|PUT|DELETE)\t/.test(call + '\t') || (/\t(-f|-F|--field|--raw-field|--input)(=|\t)/.test(call + '\t') && !/\tgraphql\t/.test(call + '\t'))));
|
||||
|
||||
/**
|
||||
* A gh on PATH that appends each call's argv (tab-separated) to calls.log and answers the reads /ship makes. `repo` is
|
||||
* what `gh repo view --json nameWithOwner,url` answers for the checkout (null: the read fails); a named repository answers
|
||||
* as itself on github.com.
|
||||
*/
|
||||
function recordingGh(dir: string, pr: { body: string; head?: string }, repo: { nameWithOwner: string; url: string } | null = { nameWithOwner: 'fx/fx', url: 'https://github.com/fx/fx' }) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
const log = path.join(dir, 'calls.log');
|
||||
fs.writeFileSync(log, '');
|
||||
fs.writeFileSync(path.join(dir, 'body.md'), pr.body);
|
||||
fs.writeFileSync(path.join(dir, 'pr.json'), JSON.stringify({ body: pr.body, headRefOid: pr.head ?? 'f'.repeat(40) }));
|
||||
if (repo) fs.writeFileSync(path.join(dir, 'repo.json'), JSON.stringify(repo));
|
||||
fs.writeFileSync(path.join(dir, 'gh'), [
|
||||
'#!/bin/sh',
|
||||
`for a in "$@"; do printf '%s\\t' "$a"; done >> "${log}"; printf '\\n' >> "${log}"`,
|
||||
'case "$*" in',
|
||||
` "pr view "*"--jq .body"*) cat "${path.join(dir, 'body.md')}"; exit 0 ;;`,
|
||||
' "pr view "*"--jq .createdAt"*) echo 2026-11-19T00:00:00Z; exit 0 ;;',
|
||||
` "pr view "*) cat "${path.join(dir, 'pr.json')}"; exit 0 ;;`,
|
||||
' "pr list "*) echo "[]"; exit 0 ;;',
|
||||
` "repo view --json nameWithOwner"*) cat "${path.join(dir, 'repo.json')}" 2>/dev/null || { echo "no git remotes found" >&2; exit 1; }; exit 0 ;;`,
|
||||
' "repo view "*"--json nameWithOwner"*) printf \'{"nameWithOwner":"%s","url":"https://github.com/%s"}\\n\' "$3" "$3"; exit 0 ;;',
|
||||
' "repo view "*) echo PUBLIC; exit 0 ;;',
|
||||
' "pr create "*) cat >/dev/null; echo https://github.com/fx/fx/pull/7; exit 0 ;;',
|
||||
' "pr "*|"issue "*|"api "*) cat >/dev/null; echo "{}"; exit 0 ;;',
|
||||
'esac',
|
||||
'exit 0', '',
|
||||
].join('\n'), { mode: 0o755 });
|
||||
const calls = () => fs.readFileSync(log, 'utf8').split('\n').filter(Boolean);
|
||||
return { calls, writes: () => calls().filter(isWrite) };
|
||||
}
|
||||
|
||||
/** The files the HOST_PUBLISH: lines name, by part. */
|
||||
function handedOff(stdout: string): Array<Record<string, string>> {
|
||||
return stdout.split('\n').filter(l => l.startsWith('HOST_PUBLISH: ')).map(l => Object.fromEntries([...l.matchAll(/\b(body|title)-file=(\S+)/g)].map(m => [m[1]!, fs.readFileSync(m[2]!, 'utf8')])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Where each HOST_PUBLISH: line sends its write: op, target, and every key=value (or bare draft) before the first file.
|
||||
* The host tool has nothing else to go on, so a missing repo= sends the write to whatever repository it defaults to.
|
||||
*/
|
||||
function destinations(stdout: string): Array<Record<string, string | true>> {
|
||||
return stdout.split('\n').filter(l => l.startsWith('HOST_PUBLISH: ')).map(l => {
|
||||
const [op, target, ...rest] = l.slice('HOST_PUBLISH: '.length).split(' ');
|
||||
const d: Record<string, string | true> = { op: op!, target: target! };
|
||||
for (const t of rest) {
|
||||
if (/^\w+-file=/.test(t) || t.startsWith('(')) break;
|
||||
const eq = t.indexOf('=');
|
||||
d[eq < 0 ? t : t.slice(0, eq)] = eq < 0 ? true : t.slice(eq + 1);
|
||||
}
|
||||
return d;
|
||||
});
|
||||
}
|
||||
|
||||
function capyRepo(repo?: { nameWithOwner: string; url: string } | null) {
|
||||
const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' });
|
||||
fxs.push(f);
|
||||
const gh = recordingGh(path.join(f.root, 'gh'), { body: 'Fixes a thing.\n' }, repo);
|
||||
const env = { PATH: `${path.join(f.root, 'gh')}:${process.env.PATH}`, GSTACK_APPROVALS_MIRROR: '0', GSTACK_CAPY: '1', GIT_CONFIG_NOSYSTEM: '1' };
|
||||
const run = (bin: string, args: string[], extra: Record<string, string> = {}) => f.run(path.join(BIN, bin), args, { ...env, ...extra });
|
||||
/** gstack-post reads the origin URL itself, so drop the fixture's insteadOf mapping (it would show the bare path). */
|
||||
const githubOrigin = () => f.git('config', '--unset', `url.${f.origin}.insteadOf`);
|
||||
return { f, gh, run, githubOrigin, head: () => f.git('rev-parse', 'HEAD').stdout.trim() };
|
||||
}
|
||||
|
||||
describe('on Capy, /ship calls no gh write (GST-3183)', () => {
|
||||
test('the negative control: without GSTACK_CAPY the shim records gstack-post pr-comment as a gh write', () => {
|
||||
const r = capyRepo();
|
||||
r.githubOrigin();
|
||||
fs.writeFileSync(path.join(r.f.root, 'c.md'), 'A plain comment.\n');
|
||||
const out = r.run('gstack-post', ['pr-comment', '7', '--body-file', path.join(r.f.root, 'c.md')], { GSTACK_CAPY: '' });
|
||||
expect(out.status, out.stderr).toBe(0);
|
||||
expect(r.gh.writes().map(c => c.split('\t').slice(0, 2).join(' '))).toEqual(['pr comment']);
|
||||
});
|
||||
|
||||
test('gstack-ship-receipt stub writes the body with its run entry to a file and prints HOST_PUBLISH', () => {
|
||||
const r = capyRepo();
|
||||
const out = r.run('gstack-ship-receipt', ['stub', '--pr', '7', '--run', 'r1']);
|
||||
expect(out.status, out.stderr).toBe(0);
|
||||
expect(out.stdout).toContain('RUN_STUB: run=r1 status=started');
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
const [h] = handedOff(out.stdout);
|
||||
expect(h!.body).toStartWith('Fixes a thing.');
|
||||
expect(h!.body).toContain('"run":"r1"');
|
||||
expect(destinations(out.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'fx/fx' }]);
|
||||
const again = r.run('gstack-ship-receipt', ['stub', '--pr', '7', '--repo', 'other/repo', '--run', 'r2']);
|
||||
expect(again.status, again.stderr).toBe(0);
|
||||
expect(destinations(again.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'other/repo' }]);
|
||||
const file = (o: string) => /body-file=(\S+)/.exec(o)![1]!;
|
||||
expect(file(again.stdout)).not.toBe(file(out.stdout));
|
||||
expect(fs.readFileSync(file(out.stdout), 'utf8')).toContain('"run":"r1"');
|
||||
expect(fs.readFileSync(file(out.stdout), 'utf8')).not.toContain('"run":"r2"');
|
||||
});
|
||||
|
||||
test('gstack-ship-receipt stop and claim hand their body edits off too', () => {
|
||||
const r = capyRepo();
|
||||
const start = r.run('gstack-review-log', ['--start', 'review']);
|
||||
expect(start.status, start.stderr).toBe(0);
|
||||
const logged = r.run('gstack-review-log', [JSON.stringify({ skill: 'review', timestamp: new Date().toISOString(), via: 'ship', pass: 1, review_scope: 'frozen', completed: true, converged: false, status: 'issues_found', issues_found: 1, critical: 1, informational: 0, findings: [{ fingerprint: 'src/x.ts:1:outside-voice', severity: 'CRITICAL', action: 'open', blocking: true, ledger_id: 'p1/outside-voice#1', raised_by: 'outside-voice' }] }), '--finish', start.stdout.trim()]);
|
||||
expect(logged.status, logged.stderr).toBe(0);
|
||||
const stop = r.run('gstack-ship-receipt', ['stop', '--pr', '7', '--run', 'ro', '--since', '2000-01-01T00:00:00Z']);
|
||||
expect(stop.status, stop.stderr).toBe(0);
|
||||
expect(stop.stdout).toContain('STOP_RECORD: run=ro head=' + r.head());
|
||||
expect(handedOff(stop.stdout)[0]!.body).toContain('"mark":"stop"');
|
||||
expect(destinations(stop.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'fx/fx' }]);
|
||||
const g = /APPROVAL_RECORDED: (a-[0-9a-f]{12})/.exec(r.run('gstack-approvals', ['round-grant', '--pr', '7', '--head', r.head(), '--kind', 'extra-round', '--reason', 'x', '--by', 'Captain GStack Minder']).stdout)?.[1];
|
||||
expect(g).toBeDefined();
|
||||
const claim = r.run('gstack-ship-receipt', ['claim', '--pr', '7', '--run', 'r1', '--grant', g!]);
|
||||
expect(claim.status, claim.stderr).toBe(0);
|
||||
expect(claim.stdout).toContain('GRANT_CLAIMED: grant=' + g);
|
||||
expect(handedOff(claim.stdout)[0]!.body).toContain('"mark":"grant"');
|
||||
expect(destinations(claim.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'fx/fx' }]);
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
test('in a two-repo thread, stub without --repo names the checkout\'s repository, not the primary one', () => {
|
||||
const primary = capyRepo({ nameWithOwner: 'acme/primary', url: 'https://github.com/acme/primary' });
|
||||
const second = capyRepo({ nameWithOwner: 'acme/widgets', url: 'https://github.com/acme/widgets' });
|
||||
const a = primary.run('gstack-ship-receipt', ['stub', '--pr', '7', '--run', 'r1']);
|
||||
const b = second.run('gstack-ship-receipt', ['stub', '--pr', '7', '--run', 'r1']);
|
||||
expect([a.status, b.status], a.stderr + b.stderr).toEqual([0, 0]);
|
||||
expect(destinations(a.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'acme/primary' }]);
|
||||
expect(destinations(b.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'acme/widgets' }]);
|
||||
expect([...primary.gh.writes(), ...second.gh.writes()]).toEqual([]);
|
||||
});
|
||||
|
||||
test('stub names a GitHub Enterprise host beside the repo', () => {
|
||||
const r = capyRepo({ nameWithOwner: 'acme/tools', url: 'https://ghe.acme.test/acme/tools' });
|
||||
const out = r.run('gstack-ship-receipt', ['stub', '--pr', '7', '--run', 'r1']);
|
||||
expect(out.status, out.stderr).toBe(0);
|
||||
expect(destinations(out.stdout)).toEqual([{ op: 'pr-body', target: '7', repo: 'acme/tools', host: 'ghe.acme.test' }]);
|
||||
});
|
||||
|
||||
test('stub refuses, with no hand-off and no write, when the repository cannot be resolved', () => {
|
||||
const r = capyRepo(null);
|
||||
const out = r.run('gstack-ship-receipt', ['stub', '--pr', '7', '--run', 'r1']);
|
||||
expect(out.status).not.toBe(0);
|
||||
expect(out.stdout).not.toContain('HOST_PUBLISH:');
|
||||
expect(out.stderr).toContain('repo');
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
test('gstack-post hands every write op to the host PR tool after its checks, with the bytes it would have sent', () => {
|
||||
const r = capyRepo();
|
||||
r.githubOrigin();
|
||||
const file = (name: string, text: string) => { const p = path.join(r.f.root, name); fs.writeFileSync(p, text); return p; };
|
||||
const body = file('body.md', 'Adds a thing for users.\n\n## Why\n\nBecause.\n');
|
||||
const title = file('title.txt', 'Add a thing for users\n');
|
||||
const comment = file('comment.md', 'A plain comment.\n');
|
||||
const ops: Array<[string, string[], string, Record<string, string | true>]> = [
|
||||
['pr-body', ['pr-body', '7', '--body-file', body], 'body', { target: '7', repo: 'fx/fx' }],
|
||||
['pr-title', ['pr-title', '7', '--title-file', title], 'title', { target: '7', repo: 'fx/fx' }],
|
||||
['pr-comment', ['pr-comment', '7', '--body-file', comment], 'body', { target: '7', repo: 'fx/fx' }],
|
||||
['issue-comment', ['issue-comment', '7', '--body-file', comment], 'body', { target: '7', repo: 'fx/fx' }],
|
||||
['reply', ['reply', '7', '--to', '99', '--body-file', comment], 'body', { target: '7', repo: 'fx/fx', to: '99' }],
|
||||
['pr-create', ['pr-create', '--base', 'main', '--head', 'feat', '--draft', '--title-file', title, '--body-file', body], 'title', { target: 'new', repo: 'fx/fx', base: 'main', head: 'feat', draft: true }],
|
||||
['issue-create', ['issue-create', '--title-file', title, '--body-file', comment], 'title', { target: 'new', repo: 'fx/fx' }],
|
||||
];
|
||||
for (const [op, args, part, dest] of ops) {
|
||||
const out = r.run('gstack-post', args);
|
||||
expect([op, out.status, out.stderr]).toEqual([op, 0, expect.any(String)]);
|
||||
expect(out.stdout).not.toContain('POSTED:');
|
||||
expect(destinations(out.stdout)).toEqual([{ op, ...dest }]);
|
||||
expect(handedOff(out.stdout)[0]![part]).toBeDefined();
|
||||
}
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
const pb = r.run('gstack-post', ['pr-body', '7', '--body-file', body]);
|
||||
expect(handedOff(pb.stdout)[0]!.body).toContain('<summary>Why</summary>');
|
||||
});
|
||||
|
||||
test('in a fork checkout gstack-post names the repository gh resolves (gh repo set-default, GH_REPO), not origin', () => {
|
||||
const r = capyRepo({ nameWithOwner: 'upstream/fx', url: 'https://github.com/upstream/fx' });
|
||||
r.githubOrigin();
|
||||
r.f.git('remote', 'set-url', 'origin', 'https://github.com/forker/fx.git');
|
||||
const body = path.join(r.f.root, 'b.md');
|
||||
fs.writeFileSync(body, 'Adds a thing for users.\n\n## Why\n\nBecause.\n');
|
||||
const comment = path.join(r.f.root, 'c.md');
|
||||
fs.writeFileSync(comment, 'A plain comment.\n');
|
||||
for (const [op, args] of [['pr-body', ['pr-body', '7', '--body-file', body]], ['pr-comment', ['pr-comment', '7', '--body-file', comment]]] as const) {
|
||||
const out = r.run('gstack-post', [...args]);
|
||||
expect(out.status, out.stderr).toBe(0);
|
||||
expect(destinations(out.stdout)).toEqual([{ op, target: '7', repo: 'upstream/fx' }]);
|
||||
}
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
test('gstack-post refuses, with no hand-off and no write, when gh cannot resolve the repository', () => {
|
||||
const r = capyRepo(null);
|
||||
r.githubOrigin();
|
||||
const comment = path.join(r.f.root, 'c.md');
|
||||
fs.writeFileSync(comment, 'A plain comment.\n');
|
||||
const out = r.run('gstack-post', ['pr-comment', '7', '--body-file', comment]);
|
||||
expect(out.status).toBe(3);
|
||||
expect(out.stdout).not.toContain('HOST_PUBLISH:');
|
||||
expect(out.stderr).toContain('cannot resolve the repository');
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
test('gstack-post names a GitHub Enterprise host, and the branch gh pr create would have used as head', () => {
|
||||
const r = capyRepo({ nameWithOwner: 'acme/tools', url: 'https://github.acme.test/acme/tools' });
|
||||
r.githubOrigin();
|
||||
r.f.git('remote', 'set-url', 'origin', 'https://github.acme.test/acme/tools.git');
|
||||
const comment = path.join(r.f.root, 'c.md');
|
||||
fs.writeFileSync(comment, 'A plain comment.\n');
|
||||
const title = path.join(r.f.root, 't.txt');
|
||||
fs.writeFileSync(title, 'Add a thing for users\n');
|
||||
const body = path.join(r.f.root, 'b.md');
|
||||
fs.writeFileSync(body, 'Adds a thing for users.\n\n## Why\n\nBecause.\n');
|
||||
const c = r.run('gstack-post', ['pr-comment', '7', '--body-file', comment]);
|
||||
expect(c.status, c.stderr).toBe(0);
|
||||
expect(destinations(c.stdout)).toEqual([{ op: 'pr-comment', target: '7', repo: 'acme/tools', host: 'github.acme.test' }]);
|
||||
const branch = r.f.git('branch', '--show-current').stdout.trim();
|
||||
expect(branch).not.toBe('');
|
||||
const n = r.run('gstack-post', ['pr-create', '--base', 'main', '--title-file', title, '--body-file', body]);
|
||||
expect(n.status, n.stderr).toBe(0);
|
||||
expect(destinations(n.stdout)).toEqual([{ op: 'pr-create', target: 'new', repo: 'acme/tools', host: 'github.acme.test', base: 'main', head: branch }]);
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
test('gstack-post still refuses a HIGH finding on Capy and writes no hand-off file', () => {
|
||||
const r = capyRepo();
|
||||
r.githubOrigin();
|
||||
const p = path.join(r.f.root, 'leak.md');
|
||||
fs.writeFileSync(p, 'key AKIA' + '1234567890ABCDEF\n');
|
||||
const out = r.run('gstack-post', ['pr-comment', '7', '--body-file', p]);
|
||||
expect(out.status).toBe(1);
|
||||
expect(out.stdout).not.toContain('HOST_PUBLISH:');
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
test('gstack-post pr-create on Capy with a detached HEAD and no --head refuses with no hand-off', () => {
|
||||
const r = capyRepo();
|
||||
r.githubOrigin();
|
||||
const title = path.join(r.f.root, 't.txt');
|
||||
fs.writeFileSync(title, 'Add a thing for users\n');
|
||||
const body = path.join(r.f.root, 'b.md');
|
||||
fs.writeFileSync(body, 'Adds a thing for users.\n\n## Why\n\nBecause.\n');
|
||||
r.f.git('checkout', '-q', '--detach');
|
||||
const out = r.run('gstack-post', ['pr-create', '--base', 'main', '--title-file', title, '--body-file', body]);
|
||||
expect(out.status).toBe(64);
|
||||
expect(out.stderr).toContain('--head <branch>');
|
||||
expect(out.stdout).not.toContain('HOST_PUBLISH:');
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
|
||||
test('a hand-off that cannot be written is a failure with no HOST_PUBLISH line, never a HIGH refusal', () => {
|
||||
const r = capyRepo();
|
||||
r.githubOrigin();
|
||||
const blocked = path.join(r.f.root, 'not-a-dir');
|
||||
fs.writeFileSync(blocked, '');
|
||||
const comment = path.join(r.f.root, 'c.md');
|
||||
fs.writeFileSync(comment, 'A plain comment.\n');
|
||||
const post = r.run('gstack-post', ['pr-comment', '7', '--body-file', comment], { GSTACK_STATE_ROOT: blocked });
|
||||
expect(post.status).toBe(3);
|
||||
expect(post.stderr).toContain('could not write the hand-off');
|
||||
expect(post.stdout).not.toContain('HOST_PUBLISH:');
|
||||
const stub = r.run('gstack-ship-receipt', ['stub', '--pr', '7', '--run', 'r1'], { GSTACK_STATE_ROOT: blocked });
|
||||
expect(stub.status).not.toBe(0);
|
||||
expect(stub.stderr).toContain('cannot write the hand-off');
|
||||
expect(stub.stdout).not.toContain('HOST_PUBLISH:');
|
||||
expect(r.gh.writes()).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('on Capy, gstack-ship-receipt carry calls no gh write (GST-3183)', () => {
|
||||
test('carry across a conflict-only base merge hands the carried body off instead of gh pr edit', () => {
|
||||
const repo = makeFixtureRepo({ prefix: 'capy-carry-' });
|
||||
repos.push(repo);
|
||||
fs.mkdirSync(path.join(repo.work, 'src'), { recursive: true });
|
||||
fs.writeFileSync(path.join(repo.work, 'src', 'app.ts'), 'export const a = 1;\n');
|
||||
fs.writeFileSync(path.join(repo.work, 'src', 'other.ts'), 'export const o = 1;\n');
|
||||
repo.git('add', '.'); repo.git('commit', '-qm', 'seed app'); repo.git('push', '-q', 'origin', 'main');
|
||||
repo.git('checkout', '-qb', 'feat');
|
||||
fs.writeFileSync(path.join(repo.work, 'src', 'app.ts'), 'export const a = 2;\n');
|
||||
repo.git('commit', '-qam', 'feat: a=2');
|
||||
const reviewed = repo.git('rev-parse', 'HEAD');
|
||||
repo.git('checkout', '-q', 'main');
|
||||
fs.writeFileSync(path.join(repo.work, 'src', 'other.ts'), 'export const o = 2;\n');
|
||||
repo.git('commit', '-qam', 'main: o=2'); repo.git('push', '-q', 'origin', 'main');
|
||||
repo.git('checkout', '-q', 'feat');
|
||||
repo.git('merge', '-q', '--no-edit', 'origin/main');
|
||||
const head = repo.git('rev-parse', 'HEAD');
|
||||
const shim = path.join(repo.root, 'gh');
|
||||
const gh = recordingGh(shim, { body: placeReceipt('## Summary\n\nProse.\n', { schema_version: 1, pr: 8, head: reviewed, base: 'main' } as any), head }, { nameWithOwner: 'acme/tools', url: 'https://ghe.acme.test/acme/tools' });
|
||||
const out = runBin(repo, 'gstack-ship-receipt', ['carry', '--pr', '8', '--out', path.join(repo.root, 'run')],
|
||||
{ GSTACK_STATE_ROOT: path.join(repo.root, 'state'), GSTACK_SESSION_KIND: 'unattended', GSTACK_CAPY: '1', PATH: `${shim}:${process.env.PATH}` });
|
||||
expect(out.status, out.err).toBe(0);
|
||||
expect(out.out).toContain(`CARRY: carried from ${reviewed.slice(0, 12)} to ${head.slice(0, 12)}`);
|
||||
expect(gh.writes()).toEqual([]);
|
||||
expect(destinations(out.out)).toEqual([{ op: 'pr-body', target: '8', repo: 'acme/tools', host: 'ghe.acme.test' }]);
|
||||
const [h] = handedOff(out.out);
|
||||
expect(h!.body).toContain('## Summary\n\nProse.\n');
|
||||
expect(h!.body).toContain(head);
|
||||
});
|
||||
});
|
||||
@@ -27,6 +27,7 @@ function fixture(opts: {
|
||||
reviews?: Array<{ login: string; commit: string }>;
|
||||
summaries?: string[];
|
||||
config?: string;
|
||||
createdStdout?: string;
|
||||
} = {}) {
|
||||
const root = fs.mkdtempSync(path.join(tmp, "repo-"));
|
||||
const state = fs.mkdtempSync(path.join(tmp, "state-"));
|
||||
@@ -68,7 +69,7 @@ function fixture(opts: {
|
||||
if (cmd === "gh" && joined.includes("/check-runs")) return ok(JSON.stringify(opts.checks ?? []));
|
||||
if (cmd === "gh" && joined.includes("/reviews")) return ok(JSON.stringify(opts.reviews ?? []));
|
||||
if (cmd === "gh" && joined.includes("/issues/12/comments")) return ok(JSON.stringify(opts.summaries ?? []));
|
||||
if (cmd === "bun" && args[1] === "pr-create") return ok("REPO_VISIBILITY: private\nhttps://github.com/acme/widget/pull/12\nPOSTED: pr-create\n");
|
||||
if (cmd === "bun" && args[1] === "pr-create") return ok(opts.createdStdout ?? "REPO_VISIBILITY: private\nhttps://github.com/acme/widget/pull/12\nPOSTED: pr-create\n");
|
||||
if (cmd === "bun") return ok("POSTED\n");
|
||||
return { status: 1, stdout: "", stderr: "unexpected" };
|
||||
},
|
||||
@@ -207,6 +208,14 @@ describe("opening the early PR (CEO-8)", () => {
|
||||
expect(r.out).toContain("EARLY_PR: none (PR 5 is already open");
|
||||
expect(f.posts()).toEqual([]);
|
||||
});
|
||||
|
||||
test("on Capy, a HOST_PUBLISH hand-off with no PR URL exits 3 and prints no EARLY_PR", () => {
|
||||
const f = fixture({ files: { "greptile.json": "{}" }, createdStdout: "HOST_PUBLISH: pr-create new repo=acme/widget head=feature/x draft title-file=/x/title.md body-file=/x/body.md (gh was not called)\n" });
|
||||
const r = f.run("open", "--base", "main", "--title-file", "/t");
|
||||
expect(r.code).toBe(3);
|
||||
expect(r.out).toContain("handed the draft to the host's PR tool");
|
||||
expect(r.out).not.toContain("EARLY_PR:");
|
||||
});
|
||||
});
|
||||
|
||||
describe("waiting for the review (CEO-8 completion signal)", () => {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"bytes": 276,
|
||||
"why": "GST-3183: on Capy, gh writes become HOST_PUBLISH hand-offs to the host PR tool, naming the repo they go to"
|
||||
}
|
||||
Reference in new issue
Block a user