Skip to content

W0: trait Camera, trait Transport, trait Bus and the registry types - #182

Merged
nofuturekid merged 5 commits into
rebuildfrom
fix/176-w0-5-device-contract
Nov 13, 2026
Merged

nofuturekid merged 5 commits into
rebuildfrom
fix/176-w0-5-device-contract

Conversation

@nofuturekid

Copy link
Copy Markdown
Collaborator

Fixes #176

Stacked on #179 (branch fix/178-w0-1-proto-types): the diff of this PR is only the one commit on top of it. Land #179 first.

What changed

Plan task 5 of docs/superpowers/plans/2026-11-13-obsbot4linux-w0-contracts.md, exactly as written. New module obsbot_device::contract:

  • camera.rs: Camera, CameraError, Tier, Group, LiveTier, Need, Identity, Target, Ctx, Motion, Frame, SendEntry, SendTable
  • transport.rs: Transport, ControlRange, OnAir
  • bus.rs: UsbId, IdentitySource, ModelEntry, Registry, Lookup, Found, Bus
  • conformance.rs: empty stub, filled by task 7
  • tests/contract.rs: 5 tests

Also: obsbot-proto added to crates/obsbot-device/Cargo.toml (and Cargo.lock), pub mod contract; in lib.rs. The carried code is untouched. No byte sent to a camera, no ioctl, no timing and no read path changes; no test opens a device.

Adaptations to the real tree

Two, both only placement:

  • lib.rs: stage G's file has no "module lines" block in the plan's sense, so pub mod contract; sits first in the alphabetical list of pub mod lines.
  • Cargo.toml: serde_json.workspace = true was already there from stage G; only obsbot-proto.workspace = true was added (kept in alphabetical order, after nix).

The first cargo test after adding the dependency ran without --locked once to write the new obsbot-device -> obsbot-proto line into Cargo.lock; the gate runs below use --locked.

Verification

  • cargo test -p obsbot-device --test contract: 5 passed.
  • cargo fmt --check: clean. cargo clippy --all-targets --locked -j 3 -- -D warnings: clean.
  • cargo test --locked -j 3 (workspace): all ok, none skipped. obsbot-device lib 171 passed, byte_guard 1, contract 5, obsbot-proto 10 + types 4, obsbot4linux 25 + cli_surface 2.
  • Acceptance 3: the files changed are Cargo.lock, crates/obsbot-device/Cargo.toml, src/lib.rs, src/contract/* and tests/contract.rs, nothing else.
  • The new tests can fail. Each mutation below was applied alone, the test run, then the file restored (checked with diff -r):
    • Tier::Minute period 60 s to 30 s: tiers_and_send_tables fails
    • Ctx::check ignores the deadline: a_context_cuts_at_its_deadline_or_when_interrupted fails
    • Ctx::check ignores the interrupt flag: same test fails
    • shared_pairs dedup replaced by clear: a_pair_of_two_models_is_found fails
    • UsbId::from_usb parses the vendor as decimal: usb_ids_come_from_the_hex_strings_of_sysfs fails
    • Registry::lookup ignores the vendor table: lookup_uses_the_vendor_table_and_the_usb_pairs_only fails
    • SendTable::allows always true: tiers_and_send_tables fails

No CHANGELOG line: nothing a user can see changes.

🤖 Generated with Claude Code

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
nofuturekid and others added 3 commits November 13, 2026 18:18
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>
…nd hand-over

Adds tests/golden/session.jsonl, errors.jsonl and hotplug.jsonl ("> " client
lines, "< " daemon lines, "#" comments) and tests/transcripts.rs. The test
round-trips every line byte for byte, checks that errors.jsonl holds the 12
error codes in the order of 4.1, that revs only go up per entry and a state
event names a listed device, that the hand-over is devices with replaced_by,
devices without the old entry, then state, and that no golden file names a
product id other than fef9 or the synthetic fa0x ids.

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

Adds obsbot_device::contract (design spec 8.2, 10.3 W0, plan task 5):
camera.rs (Camera, CameraError, Tier, Group, LiveTier, Need, Identity,
Target, Ctx, Motion, Frame, SendEntry, SendTable), transport.rs
(Transport, ControlRange, OnAir), bus.rs (UsbId, IdentitySource,
ModelEntry, Registry, Lookup, Found, Bus) and the conformance stub
that task 7 fills. The carried code is untouched.

Fixes #176

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nofuturekid
nofuturekid force-pushed the fix/176-w0-5-device-contract branch from 928d05d to eca8d30 Compare November 13, 2026 17:19
@nofuturekid
nofuturekid merged commit eca8d30 into rebuild Nov 13, 2026
21 checks passed
@nofuturekid
nofuturekid deleted the fix/176-w0-5-device-contract 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