@@ -147,3 +147,85 @@ def review(value, turn_id=turn, *, expected=0):
147147 refused = review (next_packet , next_turn , expected = 1 )
148148 assert "declared work" in refused ["error" ] and not refused .get ("appended" ), refused
149149 assert index .read_bytes () == before
150+
151+
152+ @pytest .mark .parametrize ("provider" , ["file" , "sqlite" ])
153+ def test_wide_result_page_replays_every_linked_outcome_at_writeback (tmp_path , monkeypatch , provider ):
154+ isolate_sqlite_runtime (tmp_path , monkeypatch )
155+ monkeypatch .setenv ("LOOPX_USAGE_PING" , "0" )
156+ monkeypatch .setenv ("PYTHONPATH" , str (fixture .REPO_ROOT ))
157+ project , runtime , registry = fixture ._write_fixture (tmp_path )
158+ monkeypatch .chdir (project )
159+ fixture ._initialize_fixture_authority (project , runtime , provider = provider )
160+
161+ def cli (* args , expected = 0 ):
162+ code , result = fixture ._run_cli (registry , runtime , * args , cwd = project )
163+ assert code == expected , result
164+ return result
165+
166+ identity = ("--goal-id" , fixture .GOAL_ID , "--agent-id" , fixture .AGENT_ID )
167+ cli ("configure-goal" , "--goal-id" , fixture .GOAL_ID , "--explore-mode" , "planning" ,
168+ "--execution-replan-after-turns" , "1" , "--execution-stride-strategy" , "evidence_conditioned_v1" , "--execute" )
169+ training = project / "training.json"
170+ training .write_text (json .dumps ([{"x" : 2 , "y" : 3 , "observed" : 6 }]))
171+ request = {"project" : str (project ), "registry" : str (registry ), "runtime" : str (runtime ),
172+ "goal_id" : fixture .GOAL_ID , "agent_id" : fixture .AGENT_ID , "todo_id" : fixture .TODO_ID ,
173+ "objective" : "Use the exact scoped measurement that informs the next experiment." ,
174+ "training" : str (training ), "budget" : 25 , "seed" : 17 }
175+ actor .probe (request , "retained" )
176+ for index in range (4 ):
177+ measurements = project / f"measurement-{ index } .json"
178+ measurements .write_text (json .dumps ([{"metric" : "quality" , "value" : index ,
179+ "unit" : "points" , "higher_is_better" : True ,
180+ "comparison_scope" : "validation:owned-v1" , "input_revision" : "owned-input-v1" ,
181+ "evaluation_ref" : "evaluator:owned-v1" , "candidate_ref" : f"candidate:scope-{ index } " ,
182+ "evidence_ref" : f"measured:scope-{ index } " }]))
183+ cli ("explore" , "finding" , * identity , "--finding-id" , f"wide-result-{ index } " ,
184+ "--node" , "comparison-retained" , "--title" , f"Observed input scope { index } " ,
185+ "--summary" , f"Only the recorded input scope { index } ; other inputs remain unknown." ,
186+ "--status" , "confirmed" , "--tag" , "writeback-result" , "--evidence-ref" , f"measured:scope-{ index } " ,
187+ "--measurements-json" , str (measurements ))
188+ turn = "wide-page-review"
189+ cli ("quota" , "should-run" , * identity , "--codex-app" , "--scan-path" , str (project ), "--turn-instance-id" , turn )
190+ guard = cli ("quota" , "should-run" , * identity , "--codex-app" , "--scan-path" , str (project ),
191+ "--turn-instance-id" , turn , "--todo-id" , fixture .TODO_ID )
192+ control = guard ["replan_action_packet" ]["stride_control" ]
193+ page = cli ("explore" , "turn-context" , * identity , "--result-limit" , "20" )
194+ [card ] = [row for row in page ["harness" ]["comparison_candidates" ] if row ["todo_id" ] == fixture .TODO_ID ]
195+ assert len (page ["graph" ]["writeback_results" ]) == len (card ["outcomes" ]) == 5
196+ # Choose a quantified outcome omitted by the default three-row view.
197+ visible = {row ["finding_id" ]: row for row in page ["graph" ]["writeback_results" ]}
198+ default_refs = {row ["finding_id" ] for row in control ["explore_basis" ]["comparison_candidates" ][0 ]["outcomes" ]}
199+ selected = {"todo_id" : fixture .TODO_ID , ** next (row for row in reversed (card ["outcomes" ])
200+ if row ["finding_id" ] not in default_refs and visible [row ["finding_id" ]].get ("measurements" ))}
201+ measurement = visible [selected ["finding_id" ]]["measurements" ][0 ]
202+ assert measurement ["evidence_ref" ] == visible [selected ["finding_id" ]]["evidence_refs" ][0 ]
203+ [feedback ] = page ["graph" ]["measurement_feedback" ]
204+ assert feedback ["measured_count" ] == 4
205+ assert feedback ["best" ]["candidate_ref" ] == "candidate:scope-3"
206+ decision = deepcopy (control ["minimal_example" ])
207+ decision ["explore_review" ] = {"revision" : control ["explore_basis" ]["revision" ],
208+ "disposition" : "used" , "considered_refs" : [selected ["finding_id" ]],
209+ "selected_candidate" : selected , "reason" : "This exact measured scope informs the next experiment." ,
210+ "result_pages" : [{k : page ["graph" ]["result_page" ][k ] for k in ("revision" , "offset" , "limit" )}]}
211+ packet = actor .vision (request , selected ["finding_id" ], outcome = "replan" )
212+ packet .update (stride_decision = decision , todo_delta = ["retain:" + fixture .TODO_ID ])
213+ path = project / "wide-review.json"
214+ command = ("refresh-state" , * identity , "--todo-id" , fixture .TODO_ID , "--turn-instance-id" , turn ,
215+ "--classification" , "scoped_page_review" , "--delivery-batch-scale" , "implementation" ,
216+ "--delivery-outcome" , "outcome_progress" , "--agent-vision-json" , str (path ),
217+ "--no-global-sync" , "--suppress-external-sinks" )
218+ bad = deepcopy (packet )
219+ bad ["stride_decision" ]["explore_review" ]["selected_candidate" ]["source_sha256" ] = "f" * 64
220+ path .write_text (json .dumps (bad ))
221+ index = runtime / "goals" / fixture .GOAL_ID / "runs/index.jsonl"
222+ before = index .read_bytes ()
223+ refused = cli (* command , expected = 1 )
224+ assert "exact scoped result" in refused ["error" ] and index .read_bytes () == before
225+ path .write_text (json .dumps (packet ))
226+ accepted = cli (* command )
227+ persisted = json .loads (Path (accepted ["json_path" ]).read_text ())
228+ assert persisted ["agent_vision" ]["stride_decision" ]["explore_review" ]["selected_candidate" ] == selected
229+ assert accepted ["autonomous_replan_ack" ]["semantic_delta" ]["accepted" ]
230+ readback = cli ("explore" , "turn-context" , * identity , "--result-limit" , "20" )
231+ assert readback ["graph" ]["measurement_feedback" ] == [feedback ]
0 commit comments