test(v2/conversion): add round-trip coverage for high-blast-radius methods - #13
Draft
cursor[bot] wants to merge 1 commit into
Draft
test(v2/conversion): add round-trip coverage for high-blast-radius methods#13cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
…thods Adds 23 new tests in src/v2/conversion.rs covering protocol surfaces that previously had no v1<->v2 conversion coverage. Every test exercises both v1 -> v2 -> v1 round-tripping (catches dropped fields and missing match arms) and JSON-shape equality across the conversion (catches accidental field renames on either side). Surfaces newly covered: - authenticate / logout (recently stabilized in agentclientprotocol#1273) - AgentAuthCapabilities (presence vs absence of LogoutCapabilities) - session/load, session/resume, session/close, session/list, session/set_mode, session/cancel - fs/read_text_file (with and without line/limit window) and fs/write_text_file - terminal/create (args, env, cwd, output_byte_limit, _meta), terminal/output (with and without exit_status), terminal/wait_for_exit, terminal/release, terminal/kill - TerminalExitStatus across all four shapes (clean exit, non-zero exit, signal termination, unknown) - PromptResponse for every StopReason variant (EndTurn, MaxTokens, MaxTurnRequests, Refusal, Cancelled) so a missing match arm in either direction is caught - RequestPermissionRequest with every PermissionOptionKind so an AllowOnce->AllowAlways drift can't sneak through - Error with the ErrorCode::Other(i32) fallback and every well-known code so the raw integer payload is preserved - CancelRequestNotification with each RequestId variant (Null, i64, string) and the enclosing ProtocolLevelNotification dispatch Each test also seeds a non-empty _meta map on the relevant types so a silently-dropped _meta would fail loudly, which the prior single- field tests didn't catch. No production code changed. Co-authored-by: QuantuM <qumusai@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Risky behavior now covered
The
src/v2/conversion.rsmodule performs ~520 hand-writtenIntoV1/IntoV2field-by-field moves so future v2 shape changes have obvious edit points. Until this PR the test surface was 13 cases against that module, coveringInitializeRequest,NewSessionRequest,PromptRequest,ToolCall,SessionNotification,RequestPermissionResponse,Error::invalid_params, and one v2-side smoke test. The methods most users actually call against the protocol —authenticate,logout, everysession/*lifecycle method, everyfs/*method, everyterminal/*method, andsession/cancel— had no coverage at all, even though several of these were stabilized in the last few weeks (logoutin agentclientprotocol#1273,terminal/*earlier in the v0.13 cycle).This PR adds 23 new tests that, for each high-traffic type:
assert_v1_round_trip), which catches a dropped field or a missing match arm in either direction.assert_json_eq_after_v1_to_v2), which catches a field rename on either side as soon as v1 and v2 diverge._metamap so a silently-dropped_metafails loudly — the prior single-field tests would pass onNone == None.The surfaces now covered:
AgentAuthCapabilitiesdiscriminator that signals logout support.session/load,session/resume,session/close,session/list,session/set_mode, and thesession/cancelnotification.fs/read_text_filewith and without theline/limitwindow (so omitted optionals don't get collapsed toSome(0)), andfs/write_text_file.terminal/createwith all optional fields populated,terminal/outputin both "still running" and "finished" shapes,terminal/wait_for_exit,terminal/release,terminal/kill, andTerminalExitStatusacross clean-exit / non-zero / signal / both / unknown.PromptResponsefor everyStopReasonvariant (EndTurn,MaxTokens,MaxTurnRequests,Refusal,Cancelled), so a missing match arm couldn't collapse two semantically different end states.RequestPermissionRequestwith everyPermissionOptionKindso anAllowOnce -> AllowAlwaysdrift can't sneak through.ErrorwithErrorCode::Other(i32)(so the raw integer survives) and every well-known code.CancelRequestNotificationwith everyRequestIdvariant (Null,i64, string) and the enclosingProtocolLevelNotificationenum dispatch (the latter via direct JSON equality because it intentionally doesn't derivePartialEq).Test files added/updated
src/v2/conversion.rs— 23 new tests added inside the existingmod tests, sharing the existingassert_v1_round_trip/assert_json_eq_after_v1_to_v2helpers. A smallsample_meta()helper is introduced so every test exercises the_metafield. No production code is changed.Total:
cargo test --all-featuresnow reports 291 passed; 0 failed (was 268 before).Why these tests materially reduce regression risk
src/v2/conversion.rsis the only place that promises the v1 and v2 namespaces stay byte-equal until v2 intentionally diverges. The conversion impls are mechanically field-by-field — every new field on a v1 type has to be added in twoIntoV1/IntoV2methods, and the type system can't prove they were both updated. The previous 13 tests covered the structural primitives but left the entire authentication, session lifecycle, file system, terminal, and cancellation surfaces unguarded. With this PR, a dropped field, a renamed field, a missing enum arm, or a dropped_metaon any of those methods will fail a deterministic test instead of slipping out to SDK users who already use the conversion layer to mediate between v1 SDKs and v2 wire formats.Validation
cargo test --all-features— 291 passedcargo test(default features) — 41 passedcargo test --features unstable_protocol_v2 --lib conversion— 35 passed (confirms theunstable_cancel_request-gated test compiles out cleanly when that feature isn't enabled)cargo clippy --all-features— cleancargo fmt -- --check— cleannpm run spellcheck— cleanSummary by cubic
Adds 23 round‑trip tests for high‑traffic v1↔v2 conversions in
src/v2/conversion.rs, covering authenticate/logout, session load/resume/close/list/set_mode/cancel, fs read/write, terminal create/output/wait/release/kill and exit status, prompt stop reasons, permission option kinds, error codes, and cancel‑request IDs. Each test checks v1→v2→v1 structural equality and JSON shape equality and seeds a non‑empty_meta; no production code changed (291 tests total, was 268).Written for commit 6b05760. Summary will update on new commits.
Note
Add round-trip conversion tests for high-blast-radius v1/v2 methods in
conversion.rsAdds comprehensive round-trip tests to conversion.rs covering authenticate, logout, session lifecycle, terminal, prompt, permission, error, and cancel request/notification types. Each test verifies v1→v2→v1 equality and JSON equality after v1→v2 conversion, using a shared
sample_metahelper to confirm_metafields survive round trips. Feature-gated tests forunstable_cancel_requestcoverCancelRequestNotificationandProtocolLevelNotificationvariants.Macroscope summarized 6b05760.