Skip to content

feat(broker-v2): ServiceDefinitionBuilder + write_service_definition_v2 (slice 22b of zccache#782) - #522

Merged
zackees merged 1 commit into
mainfrom
feat/v2-servicedef-builder-and-io
Jun 20, 2026
Merged

zackees merged 1 commit into
mainfrom
feat/v2-servicedef-builder-and-io

Conversation

@zackees

@zackees zackees commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the v2 consumer-side I/O surface that mirrors v1's builders::ServiceDefinitionBuilder, server::service_definition_dir, and server::write_service_definition. Unblocks zccache#782 slice 21 — zccache's cli/commands/service_definition.rs migration. With this landed the consumer-side rewrite is a literal s/broker::builders::/broker::protocol_v2::/ exercise.

What ships

broker::protocol_v2::io (new submodule, re-exported from protocol_v2):

  • SERVICE_DEF_V2_EXTENSION = "servicedef.v2" — distinct from v1's servicedef so a v1 broker never accidentally decodes a v2 file.
  • service_definition_dir_v2() — returns the same per-OS dir as v1 (extensions cohabit).
  • service_definition_path_v2(root, name) — validates the service name + computes the path.
  • write_service_definition_v2(root, def) — ensures the dir exists + has private permissions, writes the encoded bytes, returns the installed path.
  • ServiceDefinitionBuilder with constructors mirroring v1 (shared_broker, private_broker, explicit_instance), chainable setters, and terminal calls (build, install_in, install).

What's intentionally NOT here

A v2 loader. The v2 broker owns the load path; this PR is consumer-side write + layout only. A loader lands when the v2 broker binary needs to consume these files (separate slice).

Tests

11 inline tests in broker::protocol_v2::io::tests covering:

  • Extension constant
  • service_definition_path_v2 uses correct extension
  • Path validation rejects bad names (UPPERCASE, empty, slash)
  • Each constructor sets the expected isolation value
  • Chainable setters propagate to the underlying ServiceDefinition (every field)
  • install_in round-trips through disk → decode
  • write_service_definition_v2 rejects invalid names
  • Nested parent dir auto-create
  • Full-field round-trip via builder's install_in

Test plan

  • soldr cargo test -p running-process --features client --lib broker::protocol_v2 — 20 passed (11 new + 9 existing).
  • soldr cargo clippy --all-targets --features client -- -D warnings clean.

Closes the second upstream prerequisite for zccache#782 slice 21.

…v2 (slice 22b of zccache#782)

Adds the v2 consumer-side I/O surface that mirrors v1's
\`broker::builders::ServiceDefinitionBuilder\`,
\`broker::server::service_definition_dir\`, and
\`broker::server::write_service_definition\`. Unblocks zccache#782 slice
21 (zccache's \`cli/commands/service_definition.rs\` migration) — the
zccache CLI can now build + install a v2 \`.servicedef.v2\` file with a
single \`ServiceDefinitionBuilder::shared_broker(name, path).install()\`
call, mirroring the existing v1 surface byte-for-byte at the call site.

## What ships

\`broker::protocol_v2::io\` (new submodule, re-exported from
\`protocol_v2\`):

- \`SERVICE_DEF_V2_EXTENSION = "servicedef.v2"\` — distinct from v1's
  \`servicedef\` so a v1 broker never accidentally decodes a v2 file.
- \`service_definition_dir_v2()\` — returns the same per-OS dir as v1
  (the two extensions cohabit; the broker picks based on its mode).
- \`service_definition_path_v2(root, name)\` — validates the service
  name + computes the \`.servicedef.v2\` path.
- \`write_service_definition_v2(root, def)\` — ensures the dir exists +
  has private permissions, writes the encoded bytes, returns the
  installed path.
- \`ServiceDefinitionBuilder\` with constructors mirroring v1's
  (\`shared_broker\`, \`private_broker\`, \`explicit_instance\`), chainable
  setters (\`per_version_binary_dir\`, \`min_version\`, \`version_allow_list\`,
  \`label\`), and terminal calls (\`build\`, \`install_in\`, \`install\`).

## What's intentionally NOT here

- Loader (\`ServiceDefinitionLoader\` equivalent): the v2 broker owns
  the load path; this PR is consumer-side write + layout only. A v2
  loader lands when the v2 broker binary needs to consume these files.

## Tests

11 inline tests covering:

- Extension constant + path computation (with v1 \`validate_service_name\`
  enforcement)
- Each constructor (\`shared_broker\`, \`private_broker\`, \`explicit_instance\`)
- Chainable setters propagate to the underlying \`ServiceDefinition\`
- \`install_in\` round-trips through disk + decode
- Name validation fires on bad service names
- Parent dir auto-create when nested target doesn't exist
- Full-field round-trip via the builder's \`install_in\` (every field
  the builder can set survives encode → write → read → decode)

## Test plan

- [x] \`soldr cargo test -p running-process --features client --lib broker::protocol_v2\` — 20 passed (11 new + 9 existing)
- [x] \`soldr cargo clippy --all-targets --features client -- -D warnings\` clean

Closes the second upstream prerequisite for zccache#782 slice 21.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 7b08279 into main Jun 20, 2026
53 of 57 checks passed
@zackees
zackees deleted the feat/v2-servicedef-builder-and-io branch June 20, 2026 18:53
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rates/running-process/src/broker/protocol_v2/io.rs 95.74% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

zackees added a commit that referenced this pull request Jun 20, 2026
…v2 extensions (#524)

Auto-Release will publish this version to crates.io + PyPI on push to main.

## Since 4.5.5

**Broker v2 client hardening (#520)** — closes #517, #518, #519
- \`DEFAULT_HELLO_DEADLINE\` + \`connect_with_deadline\` (3s; mirrors v1)
- \`BrokerV2Error::Refused\` promotes \`retry_after_ms\` to top-level
- \`SocketCleanup\` RAII guard on \`spawn_stub_broker\` test helper

**ServiceDefinition v2 schema extension (#521)**
- v2 envelope now carries v1's launcher/isolation field set
  (binary_path, isolation, explicit_instance, per_version_binary_dir,
  min_version, version_allow_list, labels) — unblocks consumer-side
  v2 migrations
- New \`BrokerIsolation\` enum mirrors v1's
- 3 new round-trip tests (every new field + every enum variant +
  explicit_instance survives all isolation modes)

**ServiceDefinition v2 consumer I/O (#522)**
- \`protocol_v2::io::ServiceDefinitionBuilder\` mirrors v1's builder API
- \`write_service_definition_v2\`, \`service_definition_dir_v2\`,
  \`SERVICE_DEF_V2_EXTENSION\` (\`.servicedef.v2\`)
- 11 new tests including full builder→install→decode round-trip

Unblocks downstream forge-ci/zccache#782 slices 21-25 (consumer-side
v1 → v2 migration burn-down) and forge-ci/zccache#840 (bincode wire
retirement, which independently needs these v2 surfaces to be stable
in a published release before zccache can drop its git+rev patch pin).

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.

1 participant