Fix Module 25 command injection + lab integrity (#24–#27) (#54)
Co-authored-by: claude <claude@jpaul.io> Co-committed-by: claude <claude@jpaul.io>
This commit was merged in pull request #54.
This commit is contained in:
@@ -146,6 +146,13 @@ def simulate_fix(variant: str, attempt: int) -> None:
|
||||
DEMO_SRC.write_text("def discount(price, pct):\n return price - price * pct / 100\n")
|
||||
|
||||
|
||||
def simulate_cleanup() -> None:
|
||||
"""Discard the simulator's demo artifacts. These are UNTRACKED new files, so `git restore`
|
||||
(which only touches tracked files) can't remove them — the simulator cleans up after itself."""
|
||||
for path in (DEMO_SRC, DEMO_TEST):
|
||||
path.unlink(missing_ok=True)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------------------------------
|
||||
# The endpoint every path shares: a PR PROPOSAL. Never a merge.
|
||||
# --------------------------------------------------------------------------------------------------
|
||||
@@ -173,12 +180,20 @@ def propose_pr(message: str) -> None:
|
||||
print("\nThe agent stops here. It cannot merge. That is the whole safety model.")
|
||||
|
||||
|
||||
def reject(reason: str, gate_output: str) -> None:
|
||||
def reject(reason: str, gate_output: str, *, simulated: bool = False) -> None:
|
||||
print(gate_output)
|
||||
print("\n" + "=" * 80)
|
||||
print(f"GATE FAILED: {reason}")
|
||||
print("No PR proposed. The branch is left as-is for you to inspect or discard:")
|
||||
print(" git restore . # throw the agent's change away (Module 2)")
|
||||
print("No PR proposed.")
|
||||
if simulated:
|
||||
# The simulated agent's change is the UNTRACKED demo files, which `git restore` can't touch.
|
||||
# Discard them directly so the failed attempt leaves a clean tree.
|
||||
simulate_cleanup()
|
||||
print("Discarded the simulated agent's demo files (agent_demo.py, test_agent_demo.py).")
|
||||
print("(With a real agent editing tracked files, you'd discard with: git restore . # Module 2)")
|
||||
else:
|
||||
print("The branch is left as-is for you to inspect or discard:")
|
||||
print(" git restore . # throw the agent's change away (Module 2)")
|
||||
print("=" * 80)
|
||||
|
||||
|
||||
@@ -198,7 +213,7 @@ def cmd_issue_to_pr(issue_path: Path, simulate: str | None) -> int:
|
||||
print(gate_output)
|
||||
propose_pr(f"Agent: implement {issue_path.stem}")
|
||||
return 0
|
||||
reject("the agent's change does not pass the gate", gate_output)
|
||||
reject("the agent's change does not pass the gate", gate_output, simulated=bool(simulate))
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user