fix(sandbox): correlate mediation by test case - #327
Conversation
sandbox-action-mediation resolve built its MockCall with no case_id and
had no way to supply one, so once case-bound mocks existed the tool
reported the uncorrelated-run branch for every call. That is worse than
missing: it confidently prints a mock the run will not use.
- add --case-id and thread it into both the find() and resolve() calls
- echo the case being resolved as
- name the matched rule's case binding when one applies
- when no --case-id is given but the setup declares case-bound rules,
say so instead of passing the default branch off as the answer
Also document the case_id precedence rule in the example README. It is a
tier, not another matcher: a case-bound rule outranks every unbound rule
regardless of argument specificity, which is deliberate but surprising if
you assume it just adds a condition.
Chang Liu (changliu2)
left a comment
There was a problem hiding this comment.
Two blockers on exact head 46d583a:
- Endpoint sandbox targets do not receive the per-test-case ID. The endpoint session still posts only
messageandhistory, so case-bound mocks cannot vary correctly across an already-running endpoint. ScenarioBackend.current_state()now accepts an optional case ID, but callers always pass it; legacy subclasses that override the prior one-argument method raiseTypeError.
Please also align wildcard/no-case matching and evidence case-ID precedence so mock selection and recorded evidence cannot disagree.
Chang Liu (changliu2)
left a comment
There was a problem hiding this comment.
The endpoint propagation, legacy ScenarioBackend.current_state() compatibility, conflict handling, concurrency isolation, and evidence case-proof fixes now look resolved. One blocker remains: a mock rule with case_id: "*" still matches a call with no case ID because the missing ID is matched as an empty string and * succeeds. This contradicts the CLI/README guarantee that case-bound rules cannot match uncorrelated calls and can select the wrong mock. Please explicitly skip every case-bound rule when call.case_id is absent, and add library and CLI coverage for case_id: "*".
|
Fixed the remaining wildcard case-binding issue in |
Chang Liu (changliu2)
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 5781f1e. The wildcard case-binding blocker is resolved: every case-bound rule, including case_id: "*", is now rejected when the call has no case ID, and the library/CLI coverage exercises both uncorrelated and correlated wildcard paths. The earlier endpoint propagation, legacy backend compatibility, conflict handling, concurrency isolation, and evidence case-proof fixes remain intact. Approved.
Problem
ASSERT carried a
case_id, but the sandbox path did not propagate and enforce one consistent identity end to end. That made case-bound mocks incomplete, allowed ambiguous rule selection, and left evidence unable to prove which case rule fired.Fix
SandboxedEndpointSession, the stock container environment, and the optional JSON request sent to an already-running sandbox endpoint;target.endpointrequest shape when no case ID is configured;current_state(scenario)extension contract;mock_source, replay detail, andmatched_case_idin judge-visible evidence; andVerification
124 passed.1461 passed, 23 skipped, 840 subtests passed.main, including the merged host-owned egress ledger correction.Risk
The endpoint
case_idfield is optional. Existing ordinary endpoints and mock rules without a case binding retain their previous behavior. Legacy custom scenario backends remain usable, but cannot gain per-case state isolation until they adopt the new case-aware contract.A clean local stock-image rebuild remains blocked by the local Docker builder's external PyPI TLS failure. The final combined correction tree was separately exercised with the exact branch source overlaid onto the existing stock image; clean-image CI is owned by #328.