Add expected_text contract on screenshot evidence; wrapper enforces equality #172

Merged
romaine-life-app[bot] merged 1 commit from fix/expected-text-contract into main 2026-04-30 09:35:30 -07:00
romaine-life-app[bot] commented 2026-04-30 09:35:25 -07:00 (Migrated from github.com)

Closes items 2 and 3 of the PR #170 failure-chain triage. (Item 1 — agent misread the screenshot — landed in PR #171.)

Why

PR #170 verification passed and shipped a screenshot showing vigor gained: 88 for an Akabeko start-of-combat trigger that should have produced exactly 8. Two structural gaps after the agent's misread:

  • must_show was loose: "non-zero count, at minimum 8 after first combat-start trigger" accepts ≥ 8, so a literal-reading wrapper would pass 88 even with a perfectly-honest agent.
  • Apply-VerificationEvidenceGuard had no field to compare: it checks text_visible:true and non-empty observed_text, but never compares observed against any expected value the test plan declared.

What this PR does

Schema: screenshot required_evidence items with text_visible_required:true must now also carry a literal expected_text field. The wrapper does a case-insensitive, word-boundary-aware substring match between observed_text and expected_text and aborts with claimed_result_not_observed on mismatch.

Word-boundary matching matters: a naive .Contains() lets vigor gained: 8 match vigor gained: 88 as a prefix. Pattern is (?:^|[^A-Za-z0-9]) + escape(needle) + (?:[^A-Za-z0-9]|$) so the needle must sit between non-alphanumerics or string ends — a trailing digit can't extend without breaking the boundary rule.

Test-plan prompt now forbids loose phrasings ("non-zero", "at minimum N", "≥ N", "N or cumulative") and requires expected_text derived from scenario_setup × validation_plan, e.g. vigor gained: 8 for one combat-start of Akabeko. If the test plan can't pin a specific expected value because the implementation behavior is genuinely ambiguous, the rule is to abort with validation_plan_impossible rather than ship a loose contract.

Verification prompt now requires copying literal screenshot characters into observed_text — not paraphrased, not "cleaned up". If the agent can't read the value confidently, abort with target_evidence_missing rather than guess what the contract said it should show.

Tests

EvidenceGuard.Tests.ps1 exercises the comparison logic — including the specific PR #170 failure (8 must not match 88), digit-extension cases (8 must not match 80 or 800), full-string equality, start-anchor, end-anchor, missing-text, empty-observed, and case-insensitivity. Suite is 53/53.

Doc

docs/issue-agent.md: new "Expected-Value Contract on Required Evidence" section describing the rule, the derivation principle (compute from scenario × validation plan), and the forbidden loose phrasings.

What's still deferred

The Akabeko 11×-per-combat fire is a real implementation bug in PR #170. Worth a follow-up issue against that PR — but that's the bug this contract would have caught at verification time, not this PR's scope.

Closes items 2 and 3 of the PR #170 failure-chain triage. (Item 1 — agent misread the screenshot — landed in PR #171.) ## Why PR #170 verification passed and shipped a screenshot showing `vigor gained: 88` for an Akabeko start-of-combat trigger that should have produced exactly 8. Two structural gaps after the agent's misread: - **`must_show` was loose**: "non-zero count, at minimum 8 after first combat-start trigger" accepts ≥ 8, so a literal-reading wrapper would pass `88` even with a perfectly-honest agent. - **`Apply-VerificationEvidenceGuard` had no field to compare**: it checks `text_visible:true` and non-empty `observed_text`, but never compares observed against any expected value the test plan declared. ## What this PR does **Schema:** screenshot `required_evidence` items with `text_visible_required:true` must now also carry a literal `expected_text` field. The wrapper does a case-insensitive, word-boundary-aware substring match between `observed_text` and `expected_text` and aborts with `claimed_result_not_observed` on mismatch. **Word-boundary matching matters**: a naive `.Contains()` lets `vigor gained: 8` match `vigor gained: 88` as a prefix. Pattern is `(?:^|[^A-Za-z0-9]) + escape(needle) + (?:[^A-Za-z0-9]|$)` so the needle must sit between non-alphanumerics or string ends — a trailing digit can't extend without breaking the boundary rule. **Test-plan prompt** now forbids loose phrasings ("non-zero", "at minimum N", "≥ N", "N or cumulative") and requires `expected_text` derived from `scenario_setup × validation_plan`, e.g. `vigor gained: 8` for *one* combat-start of Akabeko. If the test plan can't pin a specific expected value because the implementation behavior is genuinely ambiguous, the rule is to abort with `validation_plan_impossible` rather than ship a loose contract. **Verification prompt** now requires copying literal screenshot characters into `observed_text` — not paraphrased, not "cleaned up". If the agent can't read the value confidently, abort with `target_evidence_missing` rather than guess what the contract said it should show. ## Tests `EvidenceGuard.Tests.ps1` exercises the comparison logic — including the specific PR #170 failure (`8` must not match `88`), digit-extension cases (`8` must not match `80` or `800`), full-string equality, start-anchor, end-anchor, missing-text, empty-observed, and case-insensitivity. Suite is 53/53. ## Doc `docs/issue-agent.md`: new "Expected-Value Contract on Required Evidence" section describing the rule, the derivation principle (compute from scenario × validation plan), and the forbidden loose phrasings. ## What's still deferred The Akabeko 11×-per-combat fire is a real implementation bug in PR #170. Worth a follow-up issue against that PR — but that's the bug this contract would have caught at verification time, not this PR's scope.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens!172
No description provided.