Skip to content

W0: generate schema/protocol-2.json with a stale test - #180

Merged
nofuturekid merged 3 commits into
rebuildfrom
fix/174-w0-3-schema
Nov 13, 2026
Merged

nofuturekid merged 3 commits into
rebuildfrom
fix/174-w0-3-schema

Conversation

@nofuturekid

@nofuturekid nofuturekid commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #174

Stacked on #179 (W0 task 1, protocol types): the diff against that branch is one commit. Land #179 first.

W0 task 3 of docs/superpowers/plans/2026-11-13-obsbot4linux-w0-contracts.md, put in place as the plan gives it.

What changed

  • crates/obsbot-proto/src/schema.rs: protocol_schema() (draft 2020-12, oneOf Request and ServerMessage, $defs including Description) and schema_text() (pretty JSON, final newline), replacing the stub.
  • crates/obsbot-proto/tests/schema.rs: schema_file_is_current compares the file and rewrites it when OBSBOT_REGENERATE is set; schema_names_every_envelope_and_the_description_format checks $defs for Request, Reply, Event, ErrorBody, ErrorCode, Device, Description, Setting, Action, State and that ErrorCode holds all 12 codes.
  • schema/protocol-2.json: generated (1001 lines).

No CHANGELOG line: nothing a user sees. No camera I/O, no byte sent to a device.

Adaptations to the plan

None needed. The stub schema.rs and the schemars dependency from task 1 were as the plan expects. The plan's known trap (mkdir -p schema before the first regenerate) was applied. Step 2 (expected failure) applied as written: with the task 1 stub in place the test file does not compile (E0432, unresolved imports protocol_schema and schema_text).

Verification

  • cargo test -p obsbot-proto --test schema: 2 passed.
  • Stale test, three mutations, each restored afterwards:
    • a trailing space appended to schema/protocol-2.json: schema_file_is_current FAILED, the other passed;
    • schema/protocol-2.json deleted: schema_file_is_current FAILED;
    • generator emits an empty $defs: both tests FAILED.
  • $defs of the generated file: Action, Description, Device, ErrorBody, ErrorCode, Event, Reply, Request, State and the rest of the plan's list; ErrorCode enum lists exactly the 12 codes (protocol, invalid, unknown_device, unsupported, unsupported_device, out_of_range, conflict, unavailable, asleep, busy, camera, internal) plus the forward-compatible catch-all string.
  • Gate: cargo fmt --check clean, cargo clippy --all-targets --locked -- -D warnings clean, cargo test --locked all green (whole workspace).

nofuturekid and others added 2 commits November 13, 2026 17:54
Adds the crate crates/obsbot-proto with the protocol 2 envelopes
(request, reply, event, error), the device and description types with
their builders, state and patch types with path helpers, the id and
value helpers, and stubs for client, validate (holding Refusal) and
schema. Maps are sorted, integral numbers are written without a
fraction, and public enums carry a catch-all variant so additive values
of a newer daemon still parse.

tests/types.rs round-trips every line of tests/golden/types.jsonl byte
for byte through its type.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…-check

validate_set, validate_do and validate_get check a request against a device
description and its state before anything reaches the camera. One refusal
order for the whole request: invalid, unsupported, out_of_range, conflict,
asleep, then path order. check_value covers Fit::Write and Fit::State;
check_description reports the flaws of an inconsistent description.

Fixes #173

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nofuturekid nofuturekid added the enhancement New feature or request label Nov 13, 2026
obsbot_proto::schema::protocol_schema builds the draft 2020-12 schema
(oneOf Request and ServerMessage, $defs including Description) from the
protocol types; schema_text is the file content. tests/schema.rs fails
when schema/protocol-2.json is missing or differs, and rewrites it when
OBSBOT_REGENERATE is set. A second test checks that $defs holds every
envelope, the description types and all 12 error codes.

Fixes #174

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nofuturekid
nofuturekid merged commit 272ac35 into rebuild Nov 13, 2026
21 checks passed
@nofuturekid
nofuturekid deleted the fix/174-w0-3-schema branch November 13, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant