"""Build the ten starting repositories for the time-to-green tasks, exactly as they were for the 30 October 2026 runs. Put these files in one folder, then run this script there: the scripts and suites under test (from /code/ on this site): build-a-cli-tool-with-an-agent-from-a-spec.py, build-a-cli-tool-with-an-agent-from-a-spec_test.py, add-tests-to-a-legacy-script-with-an-agent.py, add-tests-to-a-legacy-script-with-an-agent_test.py, refactor-with-an-agent-characterization-tests.py, refactor-with-an-agent-characterization-tests_test.py the ten acceptance tests: time-to-green-acceptance-t01_test.py ... time-to-green-acceptance-t10_test.py Output: ttg-repos/T01 ... ttg-repos/T10. Each is a repo root to copy fresh for every attempt: + (the agent may edit these) tasks/tNN_test.py the acceptance test; the green command is python -m unittest tasks.tNN_test tasks/regress_*.py a frozen copy of the shipped suite, so editing the root test file cannot weaken the check T06 and T07 (legacy logreport): the one characterization test that pins the old behaviour is replaced by the corrected expectation in the root test file, and the acceptance test is the frozen copy of that edited suite. The script checks that this reproduces the two published acceptance files byte for byte. Run: python time-to-green-make-task-repos.py Standard library only (Python 3.8+). """ from __future__ import annotations import os import shutil OUT = "ttg-repos" TALLY = "build-a-cli-tool-with-an-agent-from-a-spec.py" TALLY_T = "build-a-cli-tool-with-an-agent-from-a-spec_test.py" LEGACY = "add-tests-to-a-legacy-script-with-an-agent.py" LEGACY_T = "add-tests-to-a-legacy-script-with-an-agent_test.py" REFAC = "refactor-with-an-agent-characterization-tests.py" REFAC_T = "refactor-with-an-agent-characterization-tests_test.py" HERE_LINE = "HERE = os.path.dirname(os.path.abspath(__file__))" FROZEN_LINE = ("HERE = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))" " # frozen copy in tasks/: modules live in the repo root") # T06: the pinned month-boundary bug flips to the correct expectation. PINNED_BUG = ''' def test_last_seen_is_wrong_across_a_month_boundary_documented_bug(self): # 1 September sorts before 31 August once both are DD/MM/YY strings. out = run(["2026-08-31 23:59:59 INFO x\\n", "2026-09-01 00:00:01 INFO y\\n"]) self.assertIn("first: 01/09/26 00:00:01\\n", out) # wrong, pinned on purpose self.assertIn("last: 31/08/26 23:59:59\\n", out) # wrong, pinned on purpose ''' FIXED_BUG = ''' def test_first_and_last_are_correct_across_a_month_boundary(self): # Corrected expectation (time-to-green T06): 31 August is first, 1 September is last. out = run(["2026-08-31 23:59:59 INFO x\\n", "2026-09-01 00:00:01 INFO y\\n"]) self.assertIn("first: 31/08/26 23:59:59\\n", out) self.assertIn("last: 01/09/26 00:00:01\\n", out) ''' # T07: the case-sensitivity pin becomes "counted case-insensitively, printed upper-cased". PINNED_CASE = ''' def test_level_match_is_case_sensitive(self): out = run(["2026-01-01 00:00:00 error x\\n", "2026-01-01 00:00:00 ERROR x\\n"]) self.assertIn(" ERROR 1\\n", out) self.assertIn(" error 1\\n", out) ''' FIXED_CASE = ''' def test_level_match_is_case_insensitive_and_printed_upper_case(self): # Corrected expectation (time-to-green T07): levels counted case-insensitively, printed upper-cased. out = run(["2026-01-01 00:00:00 error x\\n", "2026-01-01 00:00:00 ERROR x\\n", "2026-01-01 00:00:00 Error x\\n"]) self.assertIn(" ERROR 3\\n", out) self.assertNotIn(" error", out) self.assertNotIn(" Error", out) ''' def read(name: str) -> str: with open(name, encoding="utf-8", newline="") as fh: return fh.read() def write(path: str, text: str) -> None: os.makedirs(os.path.dirname(path), exist_ok=True) with open(path, "w", encoding="utf-8", newline="") as fh: fh.write(text) def frozen(test_source: str, note: str) -> str: assert test_source.count(HERE_LINE) == 1 header = f"# FROZEN COPY for the time-to-green bench: {note}\n# Edits to tasks/ are denied to the agent.\n" return header + test_source.replace(HERE_LINE, FROZEN_LINE) def acceptance(n: int) -> str: return read(f"time-to-green-acceptance-t{n:02d}_test.py") def build() -> None: if os.path.isdir(OUT): shutil.rmtree(OUT) tally, tally_t = read(TALLY), read(TALLY_T) legacy, legacy_t = read(LEGACY), read(LEGACY_T) refac, refac_t = read(REFAC), read(REFAC_T) for n in range(1, 6): # T01-T05: the tally CSV tool root = os.path.join(OUT, f"T{n:02d}") write(os.path.join(root, TALLY), tally) write(os.path.join(root, TALLY_T), tally_t) write(os.path.join(root, "tasks", "regress_tally.py"), frozen(tally_t, f"{TALLY_T} as shipped.")) write(os.path.join(root, "tasks", f"t{n:02d}_test.py"), acceptance(n)) for n, old, new, what in ((6, PINNED_BUG, FIXED_BUG, "the month-boundary pin flipped to the correct expectation"), (7, PINNED_CASE, FIXED_CASE, "the case-sensitivity pin replaced by the case-insensitive expectation")): assert legacy_t.count(old) == 1, f"T{n:02d}: pinned test not found once in {LEGACY_T}" state_t = legacy_t.replace(old, new) acc = (f"# Acceptance test for time-to-green task T{n:02d} (written for the 2026-10-30 bench).\n" + frozen(state_t, f"acceptance test t{n:02d}: {LEGACY_T} with {what}; every other test as shipped.")) assert acc == acceptance(n), f"T{n:02d}: the swap does not reproduce the published acceptance test" root = os.path.join(OUT, f"T{n:02d}") write(os.path.join(root, LEGACY), legacy) write(os.path.join(root, LEGACY_T), state_t) write(os.path.join(root, "tasks", f"t{n:02d}_test.py"), acc) for n in range(8, 11): # T08-T10: the refactored logreport (its suite imports the legacy script too) root = os.path.join(OUT, f"T{n:02d}") write(os.path.join(root, LEGACY), legacy) write(os.path.join(root, REFAC), refac) write(os.path.join(root, REFAC_T), refac_t) write(os.path.join(root, "tasks", "regress_refactor.py"), frozen(refac_t, f"{REFAC_T} as shipped.")) write(os.path.join(root, "tasks", f"t{n:02d}_test.py"), acceptance(n)) print(f"ten starting repos written to {OUT}/ (T01-T10); each starts red on its acceptance test") if __name__ == "__main__": build()