fix(8139): a shape the agent walked past at the end-of-turn check is named again in its next notes
The after phase answers `left`, the asked lines still unjudged; the Stop hook carries them as `earlier=` into the next checks, each up to two more asks, and the note names them apart from the last turn's writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,3 +91,37 @@ def test_the_window_counts_turns_asks_and_asks_walked_past():
|
||||
# A window that spans the end-of-turn hold this check once was still sums.
|
||||
mixed = summarise(["blocked", "left_after_block", "noted", "judged_after_note"])
|
||||
assert mixed == {"checked": 2, "asked": 2, "left": 1}
|
||||
|
||||
|
||||
def test_the_note_names_walked_past_shapes_apart_from_this_turns():
|
||||
from grimoire.services.shape_check import note_text
|
||||
|
||||
fresh = [{"path": "a.py", "kind": "sym", "symbol": "new_one", "status": "new", "evidence": {}}]
|
||||
old = [{"path": "b.py", "kind": "sym", "symbol": "old_one", "status": "unclassified",
|
||||
"evidence": {}}]
|
||||
both = note_text(fresh, project_id=2, repo="", earlier=old)
|
||||
assert "last turn wrote 1 definition " in both
|
||||
assert "Also: 1 definition you wrote earlier in this session is still unjudged" in both
|
||||
assert both.index("a.py · new_one") < both.index("b.py · old_one")
|
||||
alone = note_text([], project_id=2, repo="", earlier=old + old)
|
||||
assert "last turn" not in alone
|
||||
assert alone.startswith("2 definitions you wrote earlier in this session are still unjudged")
|
||||
assert "classify_shapes(project_id=2" in alone
|
||||
|
||||
|
||||
def test_the_after_phase_hands_back_ledger_lines():
|
||||
from grimoire.services.shape_check import ledger_lines
|
||||
|
||||
items = [{"path": "a.py", "kind": "sym", "symbol": "f"},
|
||||
{"path": "w/A.svelte", "kind": "file", "symbol": "A"}]
|
||||
assert ledger_lines(items) == "a.py\tsym\tf\nw/A.svelte\tfile\tA"
|
||||
assert ledger_lines([]) == ""
|
||||
|
||||
|
||||
async def test_a_repeat_is_counted_apart_in_the_outcome_record():
|
||||
from grimoire.services.shape_check import record_shape_check
|
||||
|
||||
session = make_mock_session()
|
||||
with patch("grimoire.services.shape_check.async_session", return_value=session):
|
||||
await record_shape_check(7, "noted", written=3, unjudged=2, project_id=2, earlier=1)
|
||||
assert json.loads(session.add.call_args.args[0].details)["earlier"] == 1
|
||||
|
||||
@@ -237,3 +237,61 @@ def test_an_unreachable_instance_keeps_the_question_for_later(tmp_path):
|
||||
ledger = _write_ledger(tmp_path, ["a.py\tsym\thelper"])
|
||||
assert _stop(env, _repo(tmp_path)) == ""
|
||||
assert ledger.exists()
|
||||
|
||||
|
||||
# ── what the agent walked past is asked again, a bounded number of times ──
|
||||
|
||||
def _earlier_file(tmp_path, session="s1"):
|
||||
return tmp_path / "grimoire-shapecheck" / f"{session}.earlier"
|
||||
|
||||
|
||||
def test_a_walked_past_shape_is_named_again_then_dropped(tmp_path):
|
||||
"""The after phase's `left` becomes the carried set: the next check sends
|
||||
it as `earlier` even on a turn that wrote nothing, and a shape walked
|
||||
past more than GRIMOIRE_EARLIER_MAX times stops being asked."""
|
||||
reply = json.dumps({"status": "ok", "outcome": "noted", "note": NOTE,
|
||||
"left": "a.py\tsym\tfirst"}).encode()
|
||||
with http_sink(reply) as (port, seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
repo = _repo(tmp_path)
|
||||
_write_ledger(tmp_path, ["a.py\tsym\tfirst"])
|
||||
_stop(env, repo)
|
||||
assert seen[-1]["phase"] == ["check"] and "earlier" not in seen[-1]
|
||||
|
||||
for walked_past in (1, 2):
|
||||
_prompt(env, repo)
|
||||
_stop(env, repo)
|
||||
after, check = seen[-2], seen[-1]
|
||||
assert after["phase"] == ["after"]
|
||||
assert check["phase"] == ["check"]
|
||||
assert check["earlier"] == ["a.py\tsym\tfirst"]
|
||||
assert "written" not in check, "this turn wrote nothing; the repeat is named apart"
|
||||
assert _earlier_file(tmp_path).read_text() == f"{walked_past}\ta.py\tsym\tfirst\n"
|
||||
|
||||
_prompt(env, repo)
|
||||
_stop(env, repo)
|
||||
assert seen[-1]["phase"] == ["after"], "walked past a third time: not asked again"
|
||||
assert seen[-1]["earlier"] == ["a.py\tsym\tfirst"]
|
||||
assert not _earlier_file(tmp_path).exists()
|
||||
|
||||
|
||||
def test_a_carried_shape_this_turn_rewrote_is_this_turns(tmp_path):
|
||||
reply = json.dumps({"status": "ok", "outcome": "noted", "note": NOTE}).encode()
|
||||
with http_sink(reply) as (port, seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
_earlier_file(tmp_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
_earlier_file(tmp_path).write_text("1\ta.py\tsym\tfirst\n1\tb.py\tsym\tother\n")
|
||||
_write_ledger(tmp_path, ["a.py\tsym\tfirst"])
|
||||
_stop(env, _repo(tmp_path))
|
||||
assert seen[-1]["written"] == ["a.py\tsym\tfirst"]
|
||||
assert seen[-1]["earlier"] == ["b.py\tsym\tother"]
|
||||
|
||||
|
||||
def test_a_check_with_nothing_unjudged_forgets_the_carried_set(tmp_path):
|
||||
with http_sink(b'{"status":"ok","outcome":"passed","unjudged":[]}') as (port, seen):
|
||||
env = _env(tmp_path, f"http://127.0.0.1:{port}")
|
||||
_earlier_file(tmp_path).parent.mkdir(parents=True, exist_ok=True)
|
||||
_earlier_file(tmp_path).write_text("1\ta.py\tsym\tfirst\n")
|
||||
_stop(env, _repo(tmp_path))
|
||||
assert seen[-1]["earlier"] == ["a.py\tsym\tfirst"]
|
||||
assert not _earlier_file(tmp_path).exists(), "judged since: nothing left to carry"
|
||||
|
||||
Reference in New Issue
Block a user