benignswarm 0.12.140 → 0.12.141

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/git.js CHANGED
@@ -575,24 +575,40 @@ export function remoteHead(branch, remote = "origin", cwd = process.cwd()) {
575
575
  const line = r.stdout.split("\n").find((l) => l.trim().endsWith(`refs/heads/${branch}`));
576
576
  return line ? line.split(/\s+/)[0] : null;
577
577
  }
578
+ /** Verify ancestry against the immutable advertised tip, after proving its object is fetched. */
579
+ export function remoteTrackingRefContainsCommit(branch, advertisedTip, sha, cwd = process.cwd()) {
580
+ if (fullSha(`refs/remotes/${branch}`, cwd) !== advertisedTip)
581
+ return false;
582
+ return isAncestor(sha, advertisedTip, cwd) === true;
583
+ }
578
584
  /** Fetch origin, then report a remote branch containing the submitted commit. */
579
585
  export function findRemoteCommitBranch(sha, localBranch, cwd = process.cwd(), remote = "origin") {
580
586
  const checkedRef = `${remote}/${localBranch}`;
581
- const fetched = spawnSync("git", ["fetch", "--prune", remote], { cwd, encoding: "utf8", timeout: 120_000 });
587
+ // Submission only needs current remote-tracking refs. Force pruning off even when user/repo
588
+ // config enables it: pruning stale refs takes .git/packed-refs.lock in the shared Git dir.
589
+ const fetched = spawnSync("git", ["-c", "fetch.prune=false", "-c", `remote.${remote}.prune=false`, "fetch", remote], { cwd, encoding: "utf8", timeout: 120_000 });
582
590
  if (fetched.status !== 0) {
583
591
  const detail = (fetched.stderr || fetched.stdout || `git fetch ${remote} exited with status ${fetched.status ?? "unknown"}`).trim();
584
592
  return { remoteBranch: null, checkedRef, checked: false, reason: `git fetch ${remote} failed: ${detail}` };
585
593
  }
586
- const listed = spawnSync("git", ["branch", "-r", "--contains", sha, "--format=%(refname:short)"], { cwd, encoding: "utf8" });
587
- if (listed.status !== 0) {
588
- const detail = (listed.stderr || listed.stdout || `git branch -r --contains ${sha} exited with status ${listed.status ?? "unknown"}`).trim();
589
- return { remoteBranch: null, checkedRef, checked: true, reason: `git branch -r --contains ${sha} failed: ${detail}` };
594
+ const advertised = spawnSync("git", ["ls-remote", "--heads", remote], { cwd, encoding: "utf8", timeout: 30_000 });
595
+ if (advertised.status !== 0) {
596
+ const detail = (advertised.stderr || advertised.stdout || `git ls-remote ${remote} exited with status ${advertised.status ?? "unknown"}`).trim();
597
+ return { remoteBranch: null, checkedRef, checked: false, reason: `git ls-remote ${remote} failed: ${detail}` };
598
+ }
599
+ const advertisedTips = new Map();
600
+ for (const line of advertised.stdout.split("\n")) {
601
+ const [tip, ref] = line.trim().split(/\s+/);
602
+ if (ref?.startsWith("refs/heads/") && tip)
603
+ advertisedTips.set(`${remote}/${ref.slice("refs/heads/".length)}`, tip);
590
604
  }
591
- const branches = listed.stdout.split("\n").map((line) => line.trim()).filter((line) => line.startsWith(`${remote}/`) && line !== `${remote}/HEAD`).sort();
605
+ // Check ancestry against the advertised object ID, not a mutable tracking ref. A concurrent
606
+ // fetch can move that ref between checking its tip and asking Git about containment.
607
+ const branches = [...advertisedTips].filter(([branch, tip]) => branch !== `${remote}/HEAD` && remoteTrackingRefContainsCommit(branch, tip, sha, cwd)).map(([branch]) => branch).sort();
592
608
  const remoteBranch = branches.includes(checkedRef) ? checkedRef : branches[0] ?? null;
593
609
  return remoteBranch
594
610
  ? { remoteBranch, checkedRef, checked: true, reason: null }
595
- : { remoteBranch: null, checkedRef, checked: true, reason: `git branch -r --contains ${sha} found no ${remote} branch containing the submitted commit` };
611
+ : { remoteBranch: null, checkedRef, checked: true, reason: `no advertised ${remote} branch contains the submitted commit ${sha}` };
596
612
  }
597
613
  export function formatRemoteCommitFailure(localBranch, checkedRef, reason) {
598
614
  return `Could not verify the submitted commit for local branch ${localBranch}: checked ${checkedRef} and other origin branches; ${reason}`;
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = "0.12.140";
1
+ export const CLI_VERSION = "0.12.141";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "benignswarm",
3
- "version": "0.12.140",
3
+ "version": "0.12.141",
4
4
  "description": "b9s: chat, status board and evidence store for coding agents (benignswarm.org)",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {