@afokapu/atdd-bun 0.10.115 → 0.10.117

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/integrity.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.10.115",
2
+ "version": "0.10.117",
3
3
  "files": {
4
4
  "HOOK_AUDIT.md": "5329d840db37671b1918f688ead26865473b87db73dbc75f7c8b2a8bbe8d6d43",
5
5
  "README.md": "8aefceaa24bee498f39081b2aaf4c0d5c54bc1ed9849c20e1d98d1427df56eab",
@@ -1269,7 +1269,7 @@
1269
1269
  "src/cli.ts": "395638ab87565bb10c2beb35988ff1acf686924d13515795156a2e8893b3da88",
1270
1270
  "src/docs-capability.ts": "bdeeb414649049b1cd4fa8008cada3a576318be51c43bec91bfa46a8e250c270",
1271
1271
  "src/enforce.ts": "c4811abe63efe4568f3cf26e21a152d1537e120cb3ce471daca32367cf6e2cda",
1272
- "src/hooks.ts": "70094d7bb7afbddcf145d77b3003e3487c8a6d39066952251a18b5487594c310",
1272
+ "src/hooks.ts": "dc90870dd626440c60a50de8b6490a365dc045fab2bdbb8bdbc804ef248926b9",
1273
1273
  "src/index.ts": "4081f8b08d1d3ee9e15a9964143e53d9cfb94a5616ab3e58a180d24cc16dc381",
1274
1274
  "src/integrity.ts": "f1ede7cb04924ae88e11917047277e264af6596b9759e381bd9c497cd34a797d",
1275
1275
  "src/journey-docs.ts": "994d229376244c84212cff951032823068a76565dd2fd427b9d44e341bd14853",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afokapu/atdd-bun",
3
- "version": "0.10.115",
3
+ "version": "0.10.117",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/afokapu/atdd-bun.git"
package/src/hooks.ts CHANGED
@@ -319,6 +319,9 @@ const exceptionInventory = [
319
319
  const exceptionFields = ["schema", "inventory", "inventory_sha256", ...Object.keys(exceptionPin)];
320
320
  const inventoryHash = (paths: string[]) => new Bun.CryptoHasher("sha256").update([...paths].sort().join("\n")).digest("hex");
321
321
  const exceptionInventoryHash = inventoryHash(exceptionInventory);
322
+ // Owner countersign M-20261114T134854Z-operator-countersign-decision-1_91c90cae extends this one pin only.
323
+ const exceptionChangedLines = 1235;
324
+ const exceptionChangedLinesLimit = 350;
322
325
  /** `reason: null` means no activation record exists: the exception is not in play and the ordinary rejection stands unchanged. */
323
326
  type StagedFileExceptionGrant = { ok: true; owner_authorization: string; inventory_sha256: string };
324
327
  type StagedFileExceptionDecision = StagedFileExceptionGrant | { ok: false; reason: string | null };
@@ -476,10 +479,10 @@ export async function runHook(event: HookEvent, root = process.cwd(), args: stri
476
479
  const cfg = await policy(root), branch = (await git(root, ["symbolic-ref", "--quiet", "--short", "HEAD"])).out;
477
480
  if (["pre-commit", "pre-merge-commit"].includes(event) && cfg.protected_branches.includes(branch)) return bad(`protected branch ${branch} is blocked`);
478
481
  if (["pre-commit", "pre-merge-commit"].includes(event)) { const violation = await worktreeCommitPolicy(root, cfg.worktrees, cfg.protected_branches); if (violation) return bad(violation); }
479
- if (event === "pre-commit") { const staged = await files(root, ["diff", "--cached", "--name-only"]), registries = staged.filter(path => isRegistry(cfg, path)), generated = staged.filter(isGeneratedView), counted = staged.length - registries.length - generated.length, lines = (await stagedLineStats(root)).filter(row => !isRegistry(cfg, row.path) && !isGeneratedView(row.path)).reduce((n, row) => n + row.added + row.removed, 0); const count = await stagedCountGate(root, staged, counted, cfg.max_staged_files); if (count.rejection) return bad(count.rejection); if (lines > cfg.max_staged_changed_lines) return bad(`staged changed lines ${lines} exceed ${cfg.max_staged_changed_lines}`); const ratchet = await ratchetCommitGate(root, staged, registries.length > 0); if (ratchet) return ratchet; const checked = cfg.require_traceability || registries.length || generated.length ? await validation(root, staged, false, registries.length > 0) : { ok: true, message: "ok" }; if (checked.ok && count.grant) await recordPendingException(root, count.grant); return checked; }
482
+ if (event === "pre-commit") { const staged = await files(root, ["diff", "--cached", "--name-only"]), registries = staged.filter(path => isRegistry(cfg, path)), generated = staged.filter(isGeneratedView), counted = staged.length - registries.length - generated.length, lines = (await stagedLineStats(root)).filter(row => !isRegistry(cfg, row.path) && !isGeneratedView(row.path)).reduce((n, row) => n + row.added + row.removed, 0); const count = await stagedCountGate(root, staged, counted, cfg.max_staged_files); if (count.rejection) return bad(count.rejection); const authorizedChangedLines = count.grant !== null && cfg.max_staged_changed_lines === exceptionChangedLinesLimit && lines === exceptionChangedLines; if (lines > cfg.max_staged_changed_lines && !authorizedChangedLines) return bad(`staged changed lines ${lines} exceed ${cfg.max_staged_changed_lines}`); const ratchet = await ratchetCommitGate(root, staged, registries.length > 0); if (ratchet) return ratchet; const checked = cfg.require_traceability || registries.length || generated.length ? await validation(root, staged, false, registries.length > 0) : { ok: true, message: "ok" }; if (checked.ok && count.grant) await recordPendingException(root, count.grant); return checked; }
480
483
  if (event === "commit-msg") { const deleted = (await files(root, ["diff", "--cached", "--name-only", "--diff-filter=D"])).length, stats = await stagedStats(root), lines = stats.reduce((n, row) => n + row.removed, 0), registryRemoved = stats.filter(row => isRegistry(cfg, row.path)).reduce((n, row) => n + row.removed - row.added, 0), message = args[0] && existsSync(args[0]) ? await readFile(args[0], "utf8") : "", approved = message.includes("[mass-delete-approved]"); if ((deleted > 50 || lines > 10_000) && !approved) return bad("mass delete requires [mass-delete-approved]"); return registryRemoved > cfg.max_registry_removed_lines && !approved ? bad(`registry removal of ${registryRemoved} net lines exceeds ${cfg.max_registry_removed_lines}; requires [mass-delete-approved]`) : { ok: true, message: "ok" }; }
481
484
  if (event === "pre-push") { const reports: string[] = []; let exclusions: Awaited<ReturnType<typeof countExclusionTips>> | undefined; for (const row of stdin.split("\n").filter(Boolean).map(row => row.split(/\s+/))) { const [, local, remote, remoteSha] = row, target = remote?.replace("refs/heads/", ""); if (target && cfg.protected_branches.includes(target)) return bad(`protected branch ${target} is blocked`); if (!local) return bad("pre-push update has no local object id"); if (/^0+$/.test(local)) { const deletion = await deletionPushGate(root, remoteSha); if (!deletion.ok) return deletion; continue; } const isNew = !remoteSha || /^0+$/.test(remoteSha), range = isNew ? `${local}^..${local}` : `${remoteSha}..${local}`, shared = exclusions ??= await countExclusionTips(root, cfg.protected_branches, args[0]); if ("error" in shared) return bad(`could not list remote branch tips for the pushed range ${range}: ${shared.error}`); const counted = await git(root, ["rev-list", "--count", ...(shared.tips.length ? [isNew ? local : range, "--not", ...shared.tips] : [range])]); if (counted.code || !/^\d+$/.test(counted.out)) return bad(`could not count commits in pushed range ${range}: ${counted.err || counted.out}`); if (Number(counted.out) > cfg.max_commits_per_push) return bad(`commits per push ${counted.out} exceed ${cfg.max_commits_per_push}`); const ratchet = remote?.startsWith("refs/heads/") ? await ratchetPushGate(root, remoteSha ?? "", local, cfg.protected_branches, args[0]) : null; if (ratchet) { if (!ratchet.ok) return ratchet; reports.push(ratchet.message); continue; } const strict = await strictPushGate(root, local, range); if (!strict.ok) return strict; } return reports.length ? { ok: true, message: reports.length === 1 ? reports[0]! : `[${reports.join(",")}]` } : { ok: true, message: "validation clean" }; }
482
- if (event === "post-commit") { await consumePendingException(root); const result = await validation(root, await files(root, ["show", "--pretty=format:", "--name-only", "HEAD"]), false); return { ok: true, message: result.ok ? result.message : `advisory: ${result.message}` }; }
485
+ if (event === "post-commit") { await consumePendingException(root); const result = await validation(root, await files(root, ["show", "--pretty=format:", "--name-only", "HEAD"]), false), advance = await advanceJjDeliveryBookmark(root, cfg), message = result.ok ? result.message : `advisory: ${result.message}`; return { ok: true, message: advance ? `${message}; ${advance}` : message }; }
483
486
  return { ok: true, message: "ok" };
484
487
  }
485
488
 
@@ -556,17 +559,72 @@ async function jjPrimaryOnBranch(primary: string, branch: string): Promise<boole
556
559
  return (await lines("@-")).length === 1 && (await lines(`@- & (bookmarks(exact:${name}) | remote_bookmarks(exact:${name}, exact:"origin"))`)).length === 1;
557
560
  }
558
561
 
559
- // A colocated JJ workspace keeps Git HEAD detached, so the named-branch condition is read from JJ:
560
- // @ must carry exactly one local, non-conflicted bookmark, and that same name must be the only
561
- // Git-exported branch at @ and not protected. `--ignore-working-copy` keeps the hook from snapshotting.
562
+ const ADVANCE_ADVISORY = "delivery bookmark not advanced";
563
+ const workingCopyTemplate = 'commit_id ++ "\\n" ++ empty ++ "\\n" ++ parents.map(|p| p.commit_id()).join(",") ++ "\\n" ++ local_bookmarks.map(|b| if(b.conflict(), "conflict:", "") ++ b.name()).join("\\n")';
564
+ type WorkingCopy = { commit: string; empty: boolean; parents: string; bookmarks: string[] };
565
+ // `--ignore-working-copy` reads the recorded operation state without snapshotting; omit it to snapshot first.
566
+ async function jjWorkingCopy(root: string, ignoreWorkingCopy: boolean): Promise<WorkingCopy | null> {
567
+ const result = await jj(root, ["log", ...(ignoreWorkingCopy ? ["--ignore-working-copy"] : []), "--no-graph", "-r", "@", "-T", workingCopyTemplate]).catch(() => null);
568
+ if (!result || result.code) return null;
569
+ const [commit, empty, parents, ...bookmarks] = result.out.split("\n");
570
+ return { commit: commit ?? "", empty: empty === "true", parents: parents ?? "", bookmarks: bookmarks.filter(Boolean) };
571
+ }
572
+
573
+ // The one unambiguous delivery bookmark of a commit: exactly one local, non-conflicted, non-protected
574
+ // bookmark that is also the only Git-exported branch at that commit.
575
+ async function exactDeliveryBookmark(root: string, at: WorkingCopy, protectedBranches: string[]): Promise<{ name: string } | { error: string }> {
576
+ if (at.bookmarks.length !== 1) return { error: `the working-copy commit must carry exactly one bookmark; found ${at.bookmarks.length}` };
577
+ const name = at.bookmarks[0]!;
578
+ if (protectedBranches.includes(name)) return { error: `bookmark ${name} is protected` };
579
+ const exported = await branchForCommit(root, at.commit, []);
580
+ return "error" in exported || exported.branch !== name ? { error: `bookmark ${name} is conflicted or not the only exported branch at the working-copy commit` } : { name };
581
+ }
582
+
583
+ // A colocated JJ workspace keeps Git HEAD detached, so the named-branch condition is read from JJ: @ must
584
+ // carry the exact delivery bookmark. Reading without a snapshot keeps the hook from mutating the working copy.
562
585
  async function jjDeliveryBookmarkAtWorkingCopy(root: string, protectedBranches: string[]): Promise<boolean> {
563
586
  if (!existsSync(join(root, ".jj"))) return false;
564
- const at = await jj(root, ["log", "--ignore-working-copy", "--no-graph", "-r", "@", "-T", 'commit_id ++ "\\n" ++ local_bookmarks.map(|b| if(b.conflict(), "conflict:", "") ++ b.name()).join("\\n")']).catch(() => null);
565
- if (!at || at.code) return false;
566
- const [commit, ...bookmarks] = at.out.split("\n");
567
- if (!commit || bookmarks.length !== 1) return false;
568
- const exported = await branchForCommit(root, commit, []);
569
- return !("error" in exported) && exported.branch === bookmarks[0] && !protectedBranches.includes(exported.branch);
587
+ const at = await jjWorkingCopy(root, true);
588
+ return !!at && "name" in await exactDeliveryBookmark(root, at, protectedBranches);
589
+ }
590
+
591
+ // `git commit` in a colocated JJ workspace leaves the delivery bookmark on the old empty working-copy commit,
592
+ // a sibling of the validated commit, so `jj git push --bookmark` cannot publish it. Verify the validated commit
593
+ // and the previous working copy, returning the one bookmark to move or the reason it must stay.
594
+ async function advanceCandidate(root: string, protectedBranches: string[]): Promise<{ name: string; validated: string } | { error: string }> {
595
+ const [validated, ...gitParents] = (await git(root, ["rev-list", "--parents", "-n", "1", "HEAD"])).out.split(" ");
596
+ if (!validated || gitParents.length !== 1) return { error: "the validated HEAD must have exactly one parent" };
597
+ const old = await jjWorkingCopy(root, true);
598
+ if (!old || !old.empty || old.parents !== gitParents[0]) return { error: "the previous working-copy commit is not an empty sibling of the validated commit" };
599
+ const exact = await exactDeliveryBookmark(root, old, protectedBranches);
600
+ if ("error" in exact) return exact;
601
+ const now = await jjWorkingCopy(root, false);
602
+ return now?.empty && now.parents === validated ? { name: exact.name, validated } : { error: "the working copy is not an empty child of the validated commit" };
603
+ }
604
+
605
+ // The advance applies only to a detached colocated JJ workspace linked beneath the required worktree root.
606
+ async function isLinkedJjDeliveryWorkspace(root: string, cfg: HookPolicy): Promise<boolean> {
607
+ if (!cfg.worktrees.enabled || !existsSync(join(root, ".jj"))) return false;
608
+ const state = await layout(root, cfg.worktrees);
609
+ return !("error" in state) && !state.branch && state.current !== state.primary && inside(state.worktreeRoot, state.current);
610
+ }
611
+
612
+ // Move the bookmark, then prove JJ and the Git ref both name exactly the validated commit; returns the failure or null.
613
+ async function moveBookmarkVerified(root: string, name: string, validated: string): Promise<string | null> {
614
+ const moved = await jj(root, ["bookmark", "set", name, "-r", validated, "--allow-backwards"]);
615
+ const targets = await jj(root, ["log", "--ignore-working-copy", "--no-graph", "-r", `bookmarks(exact:${JSON.stringify(name)})`, "-T", 'commit_id ++ "\\n"']);
616
+ const aligned = !moved.code && targets.out === validated && (await branchCommit(root, name)) === validated;
617
+ return aligned ? null : `bookmark ${name} did not end at the validated commit ${validated}: ${moved.err || targets.out}`;
618
+ }
619
+
620
+ // After the validated commit, move exactly the eligible delivery bookmark to it. Returns null when the policy
621
+ // does not apply, and an advisory (never a veto of the already-made commit) when ineligible; nothing moves then.
622
+ async function advanceJjDeliveryBookmark(root: string, cfg: HookPolicy): Promise<string | null> {
623
+ if (!await isLinkedJjDeliveryWorkspace(root, cfg)) return null;
624
+ const candidate = await advanceCandidate(root, cfg.protected_branches);
625
+ if ("error" in candidate) return `${ADVANCE_ADVISORY}: ${candidate.error}`;
626
+ const failure = await moveBookmarkVerified(root, candidate.name, candidate.validated);
627
+ return failure ? `${ADVANCE_ADVISORY}: ${failure}` : `advanced delivery bookmark ${candidate.name} to ${candidate.validated}`;
570
628
  }
571
629
 
572
630
  type Layout = { primary: string; worktreeRoot: string; current: string };