@elvis1513/auto-coding-skill 4.1.9 → 4.2.1

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.
@@ -127,9 +127,9 @@ def find_config(repo: Path) -> Path:
127
127
 
128
128
 
129
129
  def run_shell(command: str, cwd: Optional[Path] = None, timeout_s: Optional[float] = None) -> None:
130
- """Run a shell command and terminate its process group on timeout."""
130
+ """Run in the caller's environment and terminate the process group on timeout."""
131
131
  p = subprocess.Popen(
132
- ["bash", "-lc", command],
132
+ ["bash", "-c", command],
133
133
  cwd=str(cwd) if cwd else None,
134
134
  text=True,
135
135
  start_new_session=True,
@@ -360,6 +360,23 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
360
360
  hook.chmod(0o755)
361
361
  return hook
362
362
 
363
+ def update_config(self, repo: Path, update) -> None:
364
+ engineering = repo / "docs" / "ENGINEERING.md"
365
+ raw = engineering.read_text(encoding="utf-8")
366
+ _, frontmatter, body = raw.split("---", 2)
367
+ config = yaml.safe_load(frontmatter)
368
+ update(config)
369
+ engineering.write_text(
370
+ "---\n"
371
+ + yaml.safe_dump(config, allow_unicode=True, sort_keys=False)
372
+ + "---"
373
+ + body,
374
+ encoding="utf-8",
375
+ )
376
+ git(repo, "add", "docs/ENGINEERING.md")
377
+ git(repo, "commit", "-qm", "update test workflow config")
378
+ git(repo, "push", "-q", "origin", "dev")
379
+
363
380
  def test_task_start_creates_external_worktree_manifest_and_status(self) -> None:
364
381
  _, repo, _ = self.make_repo()
365
382
  worktree = self.start_task(repo, "START-1")
@@ -431,6 +448,294 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
431
448
  self.assertEqual(before, git_output(repo, "rev-parse", "HEAD"))
432
449
  self.assertFalse(self.registry_manifest_path(repo, "DIRECT-NOOP").exists())
433
450
 
451
+ def test_commit_push_accepts_already_staged_deletion(self) -> None:
452
+ _, repo, remote = self.make_repo()
453
+ worktree = self.start_task(repo, "STAGED-DELETE", "shared.txt")
454
+ (worktree / "shared.txt").unlink()
455
+ git(worktree, "add", "-A", "--", "shared.txt")
456
+ self.approve_task(worktree, "STAGED-DELETE")
457
+
458
+ result = self.ap(
459
+ worktree,
460
+ "commit-push",
461
+ "STAGED-DELETE",
462
+ "--msg",
463
+ "STAGED-DELETE: remove shared file",
464
+ )
465
+
466
+ self.assertIn("commit-push", result.stdout)
467
+ self.assertNotEqual(
468
+ 0,
469
+ git(
470
+ remote,
471
+ "cat-file",
472
+ "-e",
473
+ "refs/heads/codex/STAGED-DELETE:shared.txt",
474
+ check=False,
475
+ ).returncode,
476
+ )
477
+ self.assertEqual("", git_output(worktree, "status", "--short"))
478
+
479
+ def test_staged_rename_requires_ownership_of_both_paths(self) -> None:
480
+ _, repo, remote = self.make_repo()
481
+ worktree = self.start_task(repo, "RENAME-DENY", "renamed.txt")
482
+ git(worktree, "mv", "shared.txt", "renamed.txt")
483
+ status = json.loads(self.ap(worktree, "task-status", "RENAME-DENY", "--json").stdout)
484
+ fingerprint = status["tasks"][0]["current_diff_fingerprint"]
485
+
486
+ denied = self.ap(
487
+ worktree,
488
+ "task-review",
489
+ "RENAME-DENY",
490
+ "--verdict",
491
+ "approved",
492
+ "--diff-fingerprint",
493
+ fingerprint,
494
+ "--reviewer",
495
+ "test-reviewer",
496
+ check=False,
497
+ )
498
+
499
+ self.assertNotEqual(0, denied.returncode)
500
+ self.assertIn("shared.txt", denied.stdout + denied.stderr)
501
+ self.assert_remote_branch(remote, "codex/RENAME-DENY", False)
502
+
503
+ _, allowed_repo, allowed_remote = self.make_repo()
504
+ started = self.ap(
505
+ allowed_repo,
506
+ "task-start",
507
+ "RENAME-ALLOW",
508
+ "--base",
509
+ "origin/dev",
510
+ "--owned-path",
511
+ "shared.txt",
512
+ "--owned-path",
513
+ "renamed.txt",
514
+ "--isolated",
515
+ "--review-required",
516
+ )
517
+ self.assertIn("RENAME-ALLOW", started.stdout)
518
+ allowed_worktree = self.task_worktree(allowed_repo, "RENAME-ALLOW")
519
+ git(allowed_worktree, "mv", "shared.txt", "renamed.txt")
520
+ self.commit_push(allowed_worktree, "RENAME-ALLOW", "RENAME-ALLOW: rename shared file")
521
+ self.assertEqual(
522
+ "baseline",
523
+ git_output(allowed_remote, "show", "refs/heads/codex/RENAME-ALLOW:renamed.txt"),
524
+ )
525
+ self.assertNotEqual(
526
+ 0,
527
+ git(
528
+ allowed_remote,
529
+ "cat-file",
530
+ "-e",
531
+ "refs/heads/codex/RENAME-ALLOW:shared.txt",
532
+ check=False,
533
+ ).returncode,
534
+ )
535
+
536
+ def test_commit_push_stages_mixed_index_and_worktree_state(self) -> None:
537
+ _, repo, remote = self.make_repo()
538
+ worktree = self.start_task(repo, "MIXED-STAGE")
539
+ (worktree / "shared.txt").write_text("staged-v1\n", encoding="utf-8")
540
+ git(worktree, "add", "shared.txt")
541
+ (worktree / "shared.txt").write_text("worktree-v2\n", encoding="utf-8")
542
+ (worktree / "new-file.txt").write_text("new\n", encoding="utf-8")
543
+
544
+ self.commit_push(worktree, "MIXED-STAGE", "MIXED-STAGE: commit final task state")
545
+
546
+ ref = "refs/heads/codex/MIXED-STAGE"
547
+ self.assertEqual("worktree-v2", git_output(remote, "show", f"{ref}:shared.txt"))
548
+ self.assertEqual("new", git_output(remote, "show", f"{ref}:new-file.txt"))
549
+
550
+ def test_final_gate_receipt_reuses_manual_pass_and_commit_retry(self) -> None:
551
+ root, repo, remote = self.make_repo()
552
+ gate_count = root / "gate-count"
553
+ self.update_config(
554
+ repo,
555
+ lambda config: config["commands"].update(
556
+ {"gate_changed": f"printf x >> {gate_count}"}
557
+ ),
558
+ )
559
+ worktree = self.start_task(repo, "GATE-REUSE", "shared.txt")
560
+ (worktree / "shared.txt").write_text("validated\n", encoding="utf-8")
561
+ self.ap(worktree, "light-gate", "--scope", "changed")
562
+ self.assertEqual("x", gate_count.read_text(encoding="utf-8"))
563
+ self.approve_task(worktree, "GATE-REUSE")
564
+ common_dir = Path(git_output(worktree, "rev-parse", "--git-common-dir"))
565
+ if not common_dir.is_absolute():
566
+ common_dir = (worktree / common_dir).resolve()
567
+ fail_once = common_dir / "precommit-failed-once"
568
+ self.install_hook(
569
+ repo,
570
+ "pre-commit",
571
+ f'if [ ! -f "{fail_once}" ]; then touch "{fail_once}"; exit 1; fi\n',
572
+ )
573
+
574
+ first = self.ap(
575
+ worktree,
576
+ "commit-push",
577
+ "GATE-REUSE",
578
+ "--msg",
579
+ "GATE-REUSE: validated change",
580
+ check=False,
581
+ )
582
+ self.assertNotEqual(0, first.returncode)
583
+ self.assertIn("REUSED", first.stdout + first.stderr)
584
+ second = self.ap(
585
+ worktree,
586
+ "commit-push",
587
+ "GATE-REUSE",
588
+ "--msg",
589
+ "GATE-REUSE: validated change",
590
+ )
591
+ self.assertIn("REUSED", second.stdout + second.stderr)
592
+ self.assertEqual("x", gate_count.read_text(encoding="utf-8"))
593
+ self.assertEqual(
594
+ "validated",
595
+ git_output(remote, "show", "refs/heads/codex/GATE-REUSE:shared.txt"),
596
+ )
597
+
598
+ def test_final_gate_receipt_invalidates_when_content_changes(self) -> None:
599
+ root, repo, _ = self.make_repo()
600
+ gate_count = root / "gate-count-invalidated"
601
+ self.update_config(
602
+ repo,
603
+ lambda config: config["commands"].update(
604
+ {"gate_changed": f"printf x >> {gate_count}"}
605
+ ),
606
+ )
607
+ worktree = self.start_task(repo, "GATE-INVALIDATE", "shared.txt")
608
+ (worktree / "shared.txt").write_text("first\n", encoding="utf-8")
609
+ self.ap(worktree, "light-gate", "--scope", "changed")
610
+ (worktree / "shared.txt").write_text("second\n", encoding="utf-8")
611
+ self.approve_task(worktree, "GATE-INVALIDATE")
612
+
613
+ result = self.ap(
614
+ worktree,
615
+ "commit-push",
616
+ "GATE-INVALIDATE",
617
+ "--msg",
618
+ "GATE-INVALIDATE: use current content",
619
+ )
620
+
621
+ self.assertNotIn("REUSED", result.stdout + result.stderr)
622
+ self.assertEqual("xx", gate_count.read_text(encoding="utf-8"))
623
+
624
+ def test_task_scope_add_expands_direct_scope_idempotently(self) -> None:
625
+ _, repo, remote = self.make_repo("adaptive", require_review=False)
626
+ self.ap(
627
+ repo,
628
+ "task-start",
629
+ "SCOPE-DIRECT",
630
+ "--owned-path",
631
+ "shared.txt",
632
+ "--force-lifecycle",
633
+ )
634
+ expanded = self.ap(
635
+ repo,
636
+ "task-scope-add",
637
+ "SCOPE-DIRECT",
638
+ "--owned-path",
639
+ "future.txt",
640
+ "--json",
641
+ )
642
+ payload = json.loads(expanded.stdout)
643
+ self.assertEqual("expanded", payload["status"])
644
+ self.assertEqual(2, payload["scope_revision"])
645
+ noop = json.loads(
646
+ self.ap(
647
+ repo,
648
+ "task-scope-add",
649
+ "SCOPE-DIRECT",
650
+ "--owned-path",
651
+ "future.txt",
652
+ "--json",
653
+ ).stdout
654
+ )
655
+ self.assertEqual("noop", noop["status"])
656
+ self.assertEqual(2, noop["scope_revision"])
657
+
658
+ (repo / "future.txt").write_text("future\n", encoding="utf-8")
659
+ self.ap(
660
+ repo,
661
+ "commit-push",
662
+ "SCOPE-DIRECT",
663
+ "--msg",
664
+ "SCOPE-DIRECT: add future file",
665
+ )
666
+ self.assertEqual("future", git_output(remote, "show", "refs/heads/dev:future.txt"))
667
+
668
+ def test_task_scope_add_invalidates_review_and_blocks_conflicts(self) -> None:
669
+ _, repo, _ = self.make_repo()
670
+ first = self.start_task(repo, "SCOPE-FIRST", "shared.txt")
671
+ self.start_task(repo, "SCOPE-SECOND", "second-owned.txt")
672
+ (first / "shared.txt").write_text("reviewed\n", encoding="utf-8")
673
+ old_fingerprint = self.approve_task(first, "SCOPE-FIRST")
674
+
675
+ expanded = json.loads(
676
+ self.ap(
677
+ first,
678
+ "task-scope-add",
679
+ "SCOPE-FIRST",
680
+ "--owned-path",
681
+ "future.txt",
682
+ "--json",
683
+ ).stdout
684
+ )
685
+ self.assertEqual(2, expanded["scope_revision"])
686
+ status = json.loads(self.ap(first, "task-status", "SCOPE-FIRST", "--json").stdout)["tasks"][0]
687
+ self.assertEqual("pending", status["review"]["verdict"])
688
+ self.assertNotEqual(old_fingerprint, status["current_diff_fingerprint"])
689
+ stale = self.ap(
690
+ first,
691
+ "task-review",
692
+ "SCOPE-FIRST",
693
+ "--verdict",
694
+ "approved",
695
+ "--diff-fingerprint",
696
+ old_fingerprint,
697
+ "--reviewer",
698
+ "test-reviewer",
699
+ check=False,
700
+ )
701
+ self.assertNotEqual(0, stale.returncode)
702
+
703
+ conflict = self.ap(
704
+ first,
705
+ "task-scope-add",
706
+ "SCOPE-FIRST",
707
+ "--owned-path",
708
+ "second-owned.txt",
709
+ check=False,
710
+ )
711
+ self.assertNotEqual(0, conflict.returncode)
712
+ self.assertIn("SCOPE-SECOND", conflict.stdout + conflict.stderr)
713
+
714
+ def test_task_scope_add_escalates_risk_without_moving_worktrees(self) -> None:
715
+ _, repo, _ = self.make_repo("adaptive", require_review=False)
716
+ self.ap(
717
+ repo,
718
+ "task-start",
719
+ "SCOPE-RISK",
720
+ "--owned-path",
721
+ "shared.txt",
722
+ "--force-lifecycle",
723
+ )
724
+ before = git_output(repo, "worktree", "list", "--porcelain")
725
+ expanded = json.loads(
726
+ self.ap(
727
+ repo,
728
+ "task-scope-add",
729
+ "SCOPE-RISK",
730
+ "--owned-path",
731
+ "backend/auth/token.go",
732
+ "--json",
733
+ ).stdout
734
+ )
735
+ self.assertEqual("high-risk", expanded["effective_profile"])
736
+ self.assertTrue(expanded["review_required"])
737
+ self.assertEqual(before, git_output(repo, "worktree", "list", "--porcelain"))
738
+
434
739
  def test_unnecessary_lifecycle_rejects_before_access_or_fetch_checks(self) -> None:
435
740
  _, repo, _ = self.make_repo("adaptive", require_review=False)
436
741
  engineering = repo / "docs" / "ENGINEERING.md"
@@ -1782,13 +2087,13 @@ class AutoCodingConcurrencyTests(unittest.TestCase):
1782
2087
 
1783
2088
  def test_gate_mutation_aborts_before_staging_or_commit(self) -> None:
1784
2089
  _, repo, remote = self.make_repo()
2090
+ self.update_config(
2091
+ repo,
2092
+ lambda config: config["commands"].update(
2093
+ {"gate_changed": "printf gate-change >> shared.txt"}
2094
+ ),
2095
+ )
1785
2096
  worktree = self.start_task(repo, "MUTATE-1")
1786
- engineering = worktree / "docs" / "ENGINEERING.md"
1787
- text = engineering.read_text(encoding="utf-8")
1788
- text = text.replace("gate_changed: 'true'", "gate_changed: 'printf gate-change >> shared.txt'")
1789
- engineering.write_text(text, encoding="utf-8")
1790
- git(worktree, "add", "docs/ENGINEERING.md")
1791
- git(worktree, "commit", "-qm", "configure mutating gate")
1792
2097
  before = git_output(worktree, "rev-parse", "HEAD")
1793
2098
  (worktree / "task.txt").write_text("task\n", encoding="utf-8")
1794
2099
  self.approve_task(worktree, "MUTATE-1")