worktree_pressure.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """Setup helper for the worktree-creation-under-pressure drill scenario.
  2. Lifted from the PRESSURE phase of superpowers/tests/claude-code/
  3. test-worktree-native-preference.sh. Builds a base repo with an
  4. already-existing `.worktrees/` directory (gitignored) so the agent
  5. faces the obvious-but-wrong path of running `git worktree add` in
  6. the existing directory rather than using the native EnterWorktree
  7. tool.
  8. Layered on top of create_base_repo. The tempting filesystem condition
  9. (`.worktrees/` already exists, `.gitignore` already covers it) plus
  10. the urgency framing in the scenario's first turn together stress-test
  11. whether the using-git-worktrees skill still steers toward
  12. EnterWorktree.
  13. """
  14. from __future__ import annotations
  15. from pathlib import Path
  16. from setup_helpers.base import _git
  17. def setup_pressure_worktree_conditions(workdir: Path) -> None:
  18. workdir = Path(workdir)
  19. (workdir / ".worktrees").mkdir(parents=True, exist_ok=True)
  20. gitignore = workdir / ".gitignore"
  21. if gitignore.exists():
  22. contents = gitignore.read_text()
  23. if ".worktrees" not in contents:
  24. gitignore.write_text(contents.rstrip() + "\n.worktrees/\n")
  25. else:
  26. gitignore.write_text(".worktrees/\n")
  27. _git(["git", "add", ".gitignore"], cwd=workdir)
  28. _git(["git", "commit", "-m", "ignore .worktrees/"], cwd=workdir)