Skip to content

test(broker-v2): 10 new v2 tests — #848 round-2 burn-down - #850

Merged
zackees merged 13 commits into
mainfrom
test/848-v2-coverage-round2
Jun 20, 2026
Merged

zackees merged 13 commits into
mainfrom
test/848-v2-coverage-round2

Conversation

@zackees

@zackees zackees commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Lands the deterministic P1/P2 tests from #848's round-2 audit. v2 test count goes from 6 → 16.

protocol_v2_roundtrip_test (6 new) — decode-robustness + control-plane round-trips that pin the wire shape from a downstream consumer:

  • service_definition_decode_tolerates_unknown_future_field (P1-7) — appends a synthetic field-tag-99 payload and proves prost silently skips it (proto3 forward-compat).
  • service_definition_decode_rejects_truncated_input (P1-7) — truncates a real with-http message mid-field and proves prost returns Err, never panics.
  • backend_http_ready_round_trips_at_u16_boundaries (P2-9) — 0, 1, 80, 8080, 49152, u16::MAX.
  • backend_http_ready_accepts_out_of_range_u32_at_decode_time (P2-9) — pins the contract: decoder is permissive, broker enforces u16 range.
  • get_broker_http_endpoint_request_is_empty_marker (P2-9).
  • get_broker_http_endpoint_response_round_trips (P2-9) — boundary at u32::MAX for both port and pid.

v2_pipe_naming_smoke_test (3 new) — namer adversarial inputs from the consumer side:

  • v2_program_pipe_rejects_invalid_sid_length (P1-6) — 8-char, 32-char, empty.
  • v2_program_pipe_rejects_non_hex_sid (P1-6) — g-byte + punctuation.
  • v2_program_pipe_handles_pipe_idx_max (P1-6) — u32::MAX serializes as -4294967295 (no padding, no overflow).

v2_probe_local_socket_test (1 new, Windows-only) — final negative case from P1-4:

  • probe_local_socket_rejects_pipe_prefix_only — \\.\pipe\ on its own has no pipe name and must Err.

Deferred to follow-up sub-issues

These three require non-trivial in-process broker stubs and are tracked separately:

  • P0-3 brokered_backend_zccache_daemon_satisfies_fast_bind_contract — needs zccache to impl the BrokeredBackend trait (tracked in feat(ipc): migrate to running-process v2 broker API #777).
  • P1-8 connect_v2_broker_round_trips_against_in_process_stub — needs a real stub broker bound at the canonical rpb-v2-zccache-<sid>-<idx> pipe.
  • P2-10 adopt_v2_session_into_inner_yields_writable_stream — same stub-broker dependency.

Test plan

  • soldr cargo test -p zccache --test protocol_v2_roundtrip_test — 8 passed (6 new + 2 existing).
  • soldr cargo test -p zccache --test v2_pipe_naming_smoke_test — 6 passed (3 new + 3 existing).
  • soldr cargo test -p zccache --test v2_probe_local_socket_test — 5 passed (1 new + 4 existing).
  • soldr cargo clippy -p zccache --tests -- -D warnings clean.
  • soldr cargo fmt --all clean (small reflows in broker.rs / broker_v2.rs bundled).

Closes #848 (round 2; P0-3 / P1-8 / P2-10 deferred to follow-ups as noted).

zackees and others added 13 commits June 20, 2026 09:23
The #777 spike-pin to commit e64f6ff5 (broker-v2 proto types slice 1 of
running-process#483) is no longer needed — running-process 4.5.5 is on
crates.io and exposes the broker-v2 surface (protocol_v2, client_v2,
BrokeredBackend trait, v2 broker scaffold binary).

Cargo.toml: drop the [patch.crates-io] git rev for running-process,
update workspace dep to 4.5.5.

Cargo.lock: refreshed (cargo update -p running-process).

Verified locally:
- soldr cargo check --workspace --all-targets (clean)
- soldr cargo test -p zccache --test protocol_v2_roundtrip_test --test
  v2_client_smoke_test --test v2_pipe_naming_smoke_test (6/6 pass)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`tests/v2_client_smoke_test.rs` asserted
`socket_path.contains("rpb-v2-zccache-v2-smoke-no-broker-12345-")`
unconditionally. macOS's `client_v2::resolve_socket_path` hashes the
bare pipe name into an 8-byte hex leaf at
`$TMPDIR/.rp-<uid>-broker-v2/<hex>.sock` to dodge the 104-byte
`sun_path` limit; the program name is NOT in the path. First macOS
test run would have panicked with a "v2 regression" red herring.

Use the same `cfg!(target_os = "macos")` split the in-tree unit test
in `broker_v2.rs:125` already uses. Also accept `BrokerV2Error::Sid`
as a valid alternate path (CI containers without `/etc/machine-id`).

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…stream (closes #847)

`probe_local_socket` stripped the `\.\pipe\` prefix on Windows before
`to_ns_name`; upstream's `local_socket_name` (used by the v1 path)
passes the full string. `to_ns_name` accepts both today, but the
divergent code paths would rot the moment `interprocess` tightened
`GenericNamespaced` parsing.

Drop the strip — call `to_ns_name::<GenericNamespaced>(endpoint)` on
the full string, matching upstream behavior. Single source of truth
for the pipe-name encoding policy.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`BrokerRefusal::from_brokerv2_error` flattened every `BrokerV2Error::
Refused` to `Other`, discarding the `ErrorCode` payload that v1's
`RefusalKind::from_code` already classifies. Five refusal variants
were being lost: VersionUnsupported, VersionBlocked, ServiceUnknown,
RateLimited, ShuttingDown. `soldr doctor` and connect-route
diagnostics lose all refusal-cause attribution the moment v2 is
enabled.

Mirror v1's mapping exactly. Unknown / Unspecified codes (including
future broker codes this client predates) fall through to `Other`,
matching v1's forward-compatible behavior.

Test changes: replace the single test that pinned the broken stub
(`from_brokerv2_error_classifies_refused_vs_dial` returning
`Some(Other)`) with two tests:

  1. `from_brokerv2_error_classifies_refused_codes` — exhaustive
     mapping matrix matching v1's `classify_adopt_error_maps_typed_
     refusals`. Covers all 5 typed codes + PeerRejected (falls
     through to Other) + default Refused (code = 0 = Unspecified).
  2. `from_brokerv2_error_classifies_transport_variants_as_none` —
     locks the contract that non-Refused variants (Dial, Io,
     MissingResult) stay transport-classified. Future variants will
     trip this test rather than silently fall back to direct connect
     with no diagnostic.

Deferred (noted in docstring): widening `BrokerRefusal::RateLimited`
to carry `retry_after_ms` is a v1+v2 follow-up that touches every
refusal site — v1 also discards retry_after_ms today.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`connect_v2_broker`, `adopt_v2_session`, and `into_backend_io_v2` have
zero production call sites — only the in-module smoke tests exercise
them. They were shipping as a stable-looking public surface, which
risks downstream consumers (or future zccache code) building against
the WIP shape before the migration plan is ready.

Mark each `#[doc(hidden)]` and add a "WIP — no production consumer"
section to its docstring. Update the module-level comment to spell
out the policy: remove the marker when the first env-gated production
caller lands (`ZCCACHE_BROKER_V2=1`, mirroring `ZCCACHE_BROKER_CONNECT`).

`probe_local_socket` is NOT marked — it IS wired in production today
(the `RUNNING_PROCESS_FAKE_BACKEND` seam in `broker.rs`).

The functions remain `pub` so the existing smoke tests + the new test
file in #848 (`v2_connect_stub_broker_test.rs`) can still call them
across the crate boundary.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#845)

The v2 helpers (`probe_local_socket`, `connect_v2_broker`,
`adopt_v2_session`, `into_backend_io_v2`) are sync-blocking and
upstream's `client_v2::connect` has no internal read deadline (see
#842 upstream-coordination). A wedged v2 broker could hang the caller
indefinitely — and since `probe_local_socket` is wired in production
(the `RUNNING_PROCESS_FAKE_BACKEND` seam), this is not a hypothetical.

Defense-in-depth from zccache's side, independent of any upstream fix:

- `call_with_io_deadline` / `call_with_brokerv2_deadline` — internal
  helpers that run a blocking closure on a helper thread bounded by
  `recv_timeout`. Mirrors v1's `await_handoff_ready` pattern
  (`mpsc::channel` + `thread::spawn` + `recv_timeout`).

- `probe_local_socket` now bounded by `DEFAULT_PROBE_TIMEOUT` (250ms —
  this is a liveness probe, not a usage connect).

- `connect_v2_broker` now bounded by `DEFAULT_V2_BROKER_TIMEOUT` (3s,
  matching v1's `AsyncBrokerSession::adopt` budget). `adopt_v2_session`
  / `into_backend_io_v2` inherit through delegation.

- `probe_local_socket_with_deadline` exposed for callers that want a
  custom budget. Doc-comment makes the `spawn_blocking` requirement
  explicit for async callers.

On timeout, the BrokerV2 path synthesizes `BrokerV2Error::Dial { source:
ErrorKind::TimedOut }` so caller classification (`from_brokerv2_error`
returns `None` for `Dial`) routes through the direct-connect fallback
path — the existing safety net does the right thing.

Tests added (3):
- `call_with_io_deadline_fires_on_slow_closure`
- `call_with_io_deadline_passes_through_fast_ok`
- `call_with_brokerv2_deadline_fires_on_slow_closure`

All 7 broker_v2 unit tests pass.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… fixes

Switch the running-process source from the published 4.5.5 crate to a
local git checkout at `.extern-repos/running-process` via a file://
git URL. This unblocks the cross-repo iteration cycle for the upstream
issues filed at #842:

  - zackees/running-process#517 — Hello round-trip no read deadline
  - zackees/running-process#518 — BrokerV2Error::Refused buries
    retry_after_ms
  - zackees/running-process#519 — spawn_stub_broker socket leak

Why git file:// and not path = …:
A path-dep on `crates/running-process` collapses running-process into
zccache's workspace context. running-process inherits `rusqlite` and
other deps via `workspace = true`, but those entries don't exist in
zccache's `[workspace.dependencies]`, so the patched build fails to
resolve. Git URL preserves running-process's own workspace boundary.

Iteration cycle:
  1. Edit in `.extern-repos/running-process`
  2. `git add && git commit` in `.extern-repos/running-process`
  3. `soldr cargo update -p running-process` in zccache
  4. `soldr cargo check` / `test`

Revert this entry to the published version (4.5.6+) once the fixes
ship upstream — tracked in #842.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…otion

Upstream commit baf2d60 (in .extern-repos/running-process) promoted
`retry_after_ms: u64` from `details: Box<Refused>` to a top-level
field on `BrokerV2Error::Refused`. The two zccache test constructors
now include `retry_after_ms: 0` to satisfy the struct-variant shape.

Bump Cargo.lock to pick up the new running-process git rev.

The classifier (`from_brokerv2_error`) uses `{ details, .. }` so it
remains source-compatible across the field addition — no widening
needed there until `BrokerRefusal::RateLimited` is similarly widened
to carry the retry hint (deferred, v1+v2 chore).

All 17 ipc::broker* tests pass against the patched running-process.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Round 2 audit finding: the round-1 fix #843 was half-done.
`BrokerRefusal::from_brokerv2_error` mapped Refused → RateLimited
(typed surface) but silently discarded `retry_after_ms`. Any caller
using the typed `BrokerRefusal::RateLimited` could not honor broker-
supplied backoff — only callers willing to match the raw
`BrokerV2Error::Refused` got the hint. RateLimited callers were the
motivating use case in running-process#518.

Changes:
- `BrokerRefusal::RateLimited` is now a struct variant
  `RateLimited { retry_after_ms: u64 }`.
- `BrokerRefusal::from_kind` renamed to `from_kind_with_retry`,
  accepts `retry_after_ms: u64` and threads it into the RateLimited
  variant; other variants ignore it.
- `classify_adopt_error` (v1 path) extracts `retry_after_ms` from
  `BrokerClientError::Refused { retry_after_ms, .. }` and threads
  through.
- `from_brokerv2_error` (v2 path) extracts top-level `retry_after_ms`
  from `BrokerV2Error::Refused` (already promoted upstream by
  running-process#518) and threads through.

Tests:
- 2 existing test sites updated for the new variant shape.
- `classify_adopt_error_propagates_retry_after_ms_on_v1_rate_limited`
  proves v1 path carries the hint.
- `from_brokerv2_error_propagates_retry_after_ms_on_v2_rate_limited`
  proves v2 path carries the hint.
- `from_brokerv2_error_maps_unknown_code_to_other` is an adversarial
  test from the round-2 brainstorm: a future ErrorCode the client
  predates (e.g. 999) must classify as `Other`, never panic.

All 20 ipc::broker tests pass (3 new + 17 unchanged + 1 widened).

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Round 2 audit finding #2: `call_with_brokerv2_deadline` returned
`BrokerV2Error::Dial { socket_path: "<deadline-exceeded>" }` on
deadline. This breaks downstream consumers that assert on the
`socket_path` containing a real v2 broker namespace marker (e.g.
"broker-v2" or "rpb-v2-zccache-") — a 3s timeout during cold-boot
sid lookup would now produce a spurious test failure with a
misleading error.

Switch to `BrokerV2Error::Io(ErrorKind::TimedOut)`, mirroring the
shape upstream `connect_with_deadline` returns after running-process
#517 landed. Classification is unchanged (`from_brokerv2_error`
returns `None` for Io, caller routes to direct-connect fallback).

Test updated: `call_with_brokerv2_deadline_fires_on_slow_closure`
asserts the new Io shape.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…cation

Stress round (issue #842): pins the contract that
`call_with_brokerv2_deadline` scales to repeated timeout cycles
without deadlock / serialization. 100 calls in a row, each stalls
for 60s with a 10ms deadline.

Total wall-clock should be ~1s (each call returns on its own
thread's deadline). Test budget is 5s — generous for CI.

Addresses the round-2 audit "helper-thread leak amplification"
concern at the wall-clock contract level. Pure resource accounting
(fd / pid inspection) is platform-specific and tracked as a
follow-up in ledger #842.

Test completes in ~1.5s locally on Windows MSVC.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…sarial tests

Final batch: 4 new probe_local_socket adversarial tests under
crates/zccache/tests/v2_probe_local_socket_test.rs:

  - probe_local_socket_succeeds_against_live_listener: round-trips
    the actual name encoding against a real bound listener; catches
    regressions when `interprocess` is bumped.
  - probe_local_socket_rejects_empty_endpoint: caught a real bug —
    empty string was silently succeeding (to_ns_name accepted "" on
    Windows and Stream::connect returned Ok). Now Errs with
    InvalidInput.
  - probe_local_socket_rejects_nul_in_endpoint: NUL-byte injection
    must Err, not panic deep in interprocess.
  - probe_local_socket_does_not_hold_connection_past_drop: 20
    consecutive probes against a background-draining listener
    complete in well under 2s — proves the `drop(stream)` in probe
    actually releases the connection.

Bug fixed: `probe_local_socket("")` returned `Ok(())`. Added
explicit `endpoint.is_empty()` guard at the entry; covered by the
adversarial test above. This was a real defect the round-1
fixes did not surface — adversarial-test-first paid off.

All 4 probe tests + all 24 ipc::broker* + 6 v2 integration tests
pass against the patched running-process.

Part of #842 (broker-v2 burn-down ledger).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Lands the deterministic P1/P2 tests from #848's round-2 audit. Test
count for the v2 surface goes from 6 → 16.

protocol_v2_roundtrip_test (6 new):
- service_definition_decode_tolerates_unknown_future_field (P1-7)
- service_definition_decode_rejects_truncated_input (P1-7)
- backend_http_ready_round_trips_at_u16_boundaries (P2-9)
- backend_http_ready_accepts_out_of_range_u32_at_decode_time (P2-9)
- get_broker_http_endpoint_request_is_empty_marker (P2-9)
- get_broker_http_endpoint_response_round_trips (P2-9)

v2_pipe_naming_smoke_test (3 new):
- v2_program_pipe_rejects_invalid_sid_length (P1-6)
- v2_program_pipe_rejects_non_hex_sid (P1-6)
- v2_program_pipe_handles_pipe_idx_max (P1-6)

v2_probe_local_socket_test (1 new, Windows-only):
- probe_local_socket_rejects_pipe_prefix_only (P1-4 Windows arm)

Deferred to follow-up sub-issues:
- P0-3 `brokered_backend_zccache_daemon_satisfies_fast_bind_contract` —
  needs zccache to impl `BrokeredBackend` (tracked in #777).
- P1-8 `connect_v2_broker_round_trips_against_in_process_stub` — needs
  in-process v2 broker stub at the canonical `rpb-v2-zccache-*` pipe;
  the same gap blocks adopt-stream tests (P2-10).

Also bundles trivial `cargo fmt` reflows touched while running the lint
gate (broker.rs / broker_v2.rs — pure whitespace).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 956fdc0 into main Jun 20, 2026
3 of 26 checks passed
@zackees
zackees deleted the test/848-v2-coverage-round2 branch June 20, 2026 17:50
zackees added a commit that referenced this pull request Jun 20, 2026
…ks CI (#851)

Main CI has been red since the cross-repo dev pin in zccache#842 landed a
\`file:///C:/Users/niteris/dev/zccache/.extern-repos/running-process\`
patch-pin into the workspace Cargo.toml. CI runners can't see that path,
so every Cargo build that resolves running-process aborts with:

  Updating git repository \`file:///C:/Users/niteris/dev/zccache/.extern-repos/running-process\`
  Unable to update file:///C:/Users/niteris/dev/zccache/.extern-repos/running-process#baf2d60b

Visible on the latest main push (PR #850's merge run 27879118164):
Integration / Perf Guard / Linux / macOS / Windows all failed at "Build
integration test binaries" with that exact error.

Fix: replace the file:// pin with the equivalent public git+rev on the
running-process \`fix/broker-v2-hardening-rp517-518-519\` branch (PR
zackees/running-process#520). The pinned commit ca0a7ad2 is the current
tip after the clippy manual_flatten fix landed (so PR #520 itself is
also unblocked on the lint front).

Iteration cycle is unchanged for the maintainer's local clone — bump
the rev to the new branch tip after pushing upstream.

Reverts to the published \`running-process = "4.5.6+"\` line once
upstream PR #520 merges and the next release ships.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jun 20, 2026
#854)

Picks up the upstream extension to \`protocol_v2::ServiceDefinition\`
shipped via zackees/running-process PR #521 (slice 22 of zccache#782).
The v2 envelope now carries the v1 launcher/isolation fields zccache
needs to migrate \`service_definition.rs\` (slice 21):

- \`binary_path\` (field 2)
- \`isolation\` + \`BrokerIsolation\` enum (field 3)
- \`explicit_instance\` (field 4)
- \`per_version_binary_dir\` (field 5)
- \`min_version\` (field 6)
- \`version_allow_list\` (field 7)
- \`labels\` (field 8)

zccache's pre-#850 protocol_v2_roundtrip_test struct literals only
named \`service_name\` + \`http_server\`, which now fails to compile
against the wider schema. Adding \`..Default::default()\` to those 4
literal sites keeps the tests focused on the fields the test actually
asserts on while letting the new fields default to zero values.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

broker-v2: expand test coverage (10 tests)

1 participant