okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221merge f-split-agent2 c7b65c7f7 (/loop, /goal, /time-skip, keyless search, system-browser tool, Settings Tools, Plan refuses connected tools) into f-split-intea2d565e6

main
2.0 KiB50 linesraw
1"""Applying a revision attempt the person chose after review (a run with no deciding checks keeps the baseline)."""
2
3from __future__ import annotations
4
5import sys
6import unittest
7from pathlib import Path
8
9sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
10sys.path.insert(0, str(Path(__file__).resolve().parent))
11
12from strata_control import time_skip as ts  # noqa: E402
13
14from test_time_skip import TimeSkipCase  # noqa: E402
15
16
17class TestApplyChosenAttempt(TimeSkipCase):
18    def test_a_reviewed_attempt_can_be_applied_and_undone(self):
19        def revise(candidate: Path, prompt: str, index: int) -> str:
20            (candidate / "doc.txt").write_text("one\ntwo\nthree\n", encoding="utf-8")
21            return "added three"
22
23        run, result = self.start(revise, checks=[])
24        self.assertTrue(result["decision"]["needs_user_review"])
25        self.assertEqual((self.ws / "doc.txt").read_text(encoding="utf-8"), "one\ntwo\n")
26        outcome = run.apply(attempt=1)
27        self.assertTrue(outcome["applied"], outcome)
28        self.assertEqual((self.ws / "doc.txt").read_text(encoding="utf-8"), "one\ntwo\nthree\n")
29        run.restore_original()
30        self.assertEqual((self.ws / "doc.txt").read_text(encoding="utf-8"), "one\ntwo\n")
31
32    def test_a_missing_attempt_is_refused(self):
33        run, _ = self.start(lambda c, p, i: None, checks=[])
34        with self.assertRaises(ts.TimeSkipError):
35            run.apply(attempt=9)
36
37    def test_a_reviewed_attempt_is_still_refused_after_a_user_edit(self):
38        def revise(candidate: Path, prompt: str, index: int) -> str:
39            (candidate / "doc.txt").write_text("changed\n", encoding="utf-8")
40            return "x"
41
42        run, _ = self.start(revise, checks=[])
43        (self.ws / "doc.txt").write_text("the user rewrote this\n", encoding="utf-8")
44        outcome = run.apply(attempt=1)
45        self.assertTrue(outcome["conflict"])
46        self.assertEqual((self.ws / "doc.txt").read_text(encoding="utf-8"), "the user rewrote this\n")
47
48
49if __name__ == "__main__":
50    unittest.main()