Resolve decode_state's field types from string annotations too

This commit was merged in pull request #122.
This commit is contained in:
2026-09-29 10:29:08 +02:00
parent b69b37b334
commit d9058d2d7e
3 changed files with 12 additions and 3 deletions
+10 -1
View File
@@ -1,3 +1,4 @@
import dataclasses
import json
import os
import pathlib
@@ -7,7 +8,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from loop_claude import file_writes, main
from loop_claude import file_writes, main, reload
from loop_claude.claude_code import formats, transcript
from loop_claude.claude_runs import judge
from loop_claude.outcome import Failure, Stop
@@ -119,6 +120,14 @@ class LoopState(unittest.TestCase):
with self.subTest(handed=handed):
self.assertEqual(main.loop_state([main.RELOAD_FLAG, *handed], CWD), Stop(1, f"the reload cannot read the loop's state from {handed}; rerun loop-claude <task>"))
def test_decodes_a_state_whose_annotations_are_strings(self):
@dataclasses.dataclass(frozen=True)
class Stringly:
count: "int"
name: "str"
self.assertEqual(reload.decode_state('{"count": 1, "name": "n"}', Stringly), Stringly(1, "n"))
self.assertIsNone(reload.decode_state('{"count": "1", "name": "n"}', Stringly))
class ReplaceFile(unittest.TestCase):