@afokapu/atdd-bun 0.10.111 → 0.10.112

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.111",
2
+ "version": "0.10.112",
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": "fce67a102fe61c15b4100daddf842ce7264d9e0d0e79ec89c4ed4a0b188967b7",
1272
+ "src/hooks.ts": "bdfc4560351a414741c8a5c94404570522033a92dbaac8079af09fa3847e82bc",
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.111",
3
+ "version": "0.10.112",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/afokapu/atdd-bun.git"
package/src/hooks.ts CHANGED
@@ -411,14 +411,14 @@ async function branchCommit(root: string, branch: string) {
411
411
 
412
412
  // A delivery commit must have one unambiguous non-protected exported bookmark.
413
413
  // Ref ordering is never used as ownership authority.
414
- async function branchForCommit(root: string, commit: string, protectedBranches: string[]): Promise<{ error: string } | { branch: string }> {
414
+ async function branchForCommit(root: string, commit: string, protectedBranches: string[]): Promise<{ error: string; count?: number } | { branch: string }> {
415
415
  const refs = await git(root, ["for-each-ref", "--format=%(refname:short)", "--points-at", commit, "refs/heads/"]);
416
416
  if (refs.code) return { error: refs.err || refs.out };
417
417
  const candidates = refs.out.split("\n").map(line => line.trim()).filter(Boolean)
418
418
  .filter(name => !protectedBranches.includes(name));
419
419
  return candidates.length === 1
420
420
  ? { branch: candidates[0]! }
421
- : { error: `current Jujutsu revision must have exactly one non-protected exported bookmark; found ${candidates.length}` };
421
+ : { error: `current Jujutsu revision must have exactly one non-protected exported bookmark; found ${candidates.length}`, count: candidates.length };
422
422
  }
423
423
 
424
424
  // A JJ-colocated primary keeps Git HEAD detached at its working-copy parent, so JJ state decides:
@@ -482,13 +482,16 @@ async function createWorkspace(state: Layout, target: { leaf: string; target: st
482
482
  return bad(bookmark.err || bookmark.out || `bookmark ${branch} was not exported to the colocated Git repository`);
483
483
  }
484
484
 
485
- async function finishCandidate(state: Layout, cfg: HookPolicy): Promise<{ error: string } | { branch: string; tip: string }> {
485
+ // A branch of null means the delivery bookmark is already gone and the revision is merged.
486
+ type FinishCandidate = { branch: string | null; tip: string };
487
+ async function finishCandidate(state: Layout, cfg: HookPolicy): Promise<{ error: string } | FinishCandidate> {
486
488
  if (state.current === state.primary || !inside(state.worktreeRoot, state.current)) return { error: `finish must run from a linked workspace beneath ${state.worktreeRoot}` };
487
489
  const conflict = await noConflicts(state.current);
488
490
  if (conflict.error !== undefined) return conflict;
489
491
  const current = await currentCommit(state.current);
490
492
  if (!current) return { error: "could not resolve the current Jujutsu revision" };
491
493
  let delivery = current, found = await branchForCommit(state.current, current, cfg.protected_branches);
494
+ if ("error" in found && found.count === 0 && await mergedIntoPrimary(state, current, cfg)) return { branch: null, tip: current };
492
495
  if ("error" in found) {
493
496
  const changed = await jj(state.current, ["diff", "-r", "@", "--name-only"]);
494
497
  const parent = await jj(state.current, ["log", "-r", "@-", "--no-graph", "-T", "commit_id"]);
@@ -504,6 +507,11 @@ async function finishCandidate(state: Layout, cfg: HookPolicy): Promise<{ error:
504
507
  return undelivered ? { error: undelivered } : { branch: found.branch, tip };
505
508
  }
506
509
 
510
+ // Zero-bookmark retirement is safe only for a revision already equal to or an ancestor of protected main.
511
+ async function mergedIntoPrimary(state: Layout, commit: string, cfg: HookPolicy) {
512
+ return !(await git(state.primary, ["merge-base", "--is-ancestor", commit, cfg.worktrees.primary_branch])).code;
513
+ }
514
+
507
515
  async function jjRevision(root: string, commit: string): Promise<{ error: string } | { empty: boolean; conflict: boolean; parents: string[] }> {
508
516
  const info = await jj(root, ["log", "-r", commit, "--no-graph", "-T", 'if(empty, "empty", "content") ++ " " ++ if(conflict, "conflict", "clean") ++ " " ++ parents.map(|p| p.commit_id()).join(" ")']);
509
517
  if (info.code || !info.out) return { error: `could not inspect Jujutsu revision ${commit}: ${info.err || info.out}` };
@@ -520,7 +528,7 @@ async function deliveryError(state: Layout, branch: string, tip: string, cfg: Ho
520
528
  const info = await jjRevision(state.primary, commit);
521
529
  if ("error" in info) return info.error;
522
530
  if (info.conflict) return `bookmark ${branch} has unresolved conflicts`;
523
- if (!(await git(state.primary, ["merge-base", "--is-ancestor", commit, cfg.worktrees.primary_branch])).code) return null;
531
+ if (await mergedIntoPrimary(state, commit, cfg)) return null;
524
532
  if (!info.empty || info.parents.length !== 1) return `branch ${branch} is not merged into ${cfg.worktrees.primary_branch} in the primary checkout`;
525
533
  commit = info.parents[0]!;
526
534
  }
@@ -573,9 +581,10 @@ async function finishJjWorktree(root: string, deleteBranch: boolean, cfg: HookPo
573
581
  if ("error" in workspace) return bad(workspace.error);
574
582
  const removed = await jj(state.primary, ["workspace", "remove", workspace.name]);
575
583
  if (removed.code) return bad(removed.err || removed.out);
576
- if (!deleteBranch) return { ok: true, message: `removed merged Jujutsu workspace ${state.current}` };
577
- const deletionError = await deleteBookmark(state, candidate, cfg);
578
- return deletionError ? bad(deletionError) : { ok: true, message: `removed merged Jujutsu workspace ${state.current} and bookmark ${candidate.branch}` };
584
+ const { branch } = candidate;
585
+ if (!deleteBranch || branch === null) return { ok: true, message: `removed merged Jujutsu workspace ${state.current}` };
586
+ const deletionError = await deleteBookmark(state, { branch, tip: candidate.tip }, cfg);
587
+ return deletionError ? bad(deletionError) : { ok: true, message: `removed merged Jujutsu workspace ${state.current} and bookmark ${branch}` };
579
588
  }
580
589
 
581
590