okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ea2d565e6
main
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 ): 18def test_a_reviewed_attempt_can_be_applied_and_undone (self ): 19def revise (candidate :Path ,prompt :str ,index :int )-> str : 20 (candidate / "doc.txt" ).write_text ("one\ntwo\nthree\n" ,encoding = "utf-8" ) 21return "added three" 22 23run ,result = self .start (revise ,checks = []) 24self .assertTrue (result ["decision" ]["needs_user_review" ]) 25self .assertEqual ((self .ws / "doc.txt" ).read_text (encoding = "utf-8" ),"one\ntwo\n" ) 26outcome = run .apply (attempt = 1 ) 27self .assertTrue (outcome ["applied" ],outcome ) 28self .assertEqual ((self .ws / "doc.txt" ).read_text (encoding = "utf-8" ),"one\ntwo\nthree\n" ) 29run .restore_original () 30self .assertEqual ((self .ws / "doc.txt" ).read_text (encoding = "utf-8" ),"one\ntwo\n" ) 31 32def test_a_missing_attempt_is_refused (self ): 33run ,_ = self .start (lambda c ,p ,i :None ,checks = []) 34with self .assertRaises (ts .TimeSkipError ): 35run .apply (attempt = 9 ) 36 37def test_a_reviewed_attempt_is_still_refused_after_a_user_edit (self ): 38def revise (candidate :Path ,prompt :str ,index :int )-> str : 39 (candidate / "doc.txt" ).write_text ("changed\n" ,encoding = "utf-8" ) 40return "x" 41 42run ,_ = self .start (revise ,checks = []) 43 (self .ws / "doc.txt" ).write_text ("the user rewrote this\n" ,encoding = "utf-8" ) 44outcome = run .apply (attempt = 1 ) 45self .assertTrue (outcome ["conflict" ]) 46self .assertEqual ((self .ws / "doc.txt" ).read_text (encoding = "utf-8" ),"the user rewrote this\n" ) 47 48 49if __name__ == "__main__" : 50unittest .main ()