diff --git a/tests/edge_protocol.test.ts b/tests/edge_protocol.test.ts index 685849c..9b241c2 100644 --- a/tests/edge_protocol.test.ts +++ b/tests/edge_protocol.test.ts @@ -10,6 +10,7 @@ import "../src/validation/formats"; import currentCapture from "./fixtures/gateway_frames.json"; import legacyCapture from "./fixtures/gateway_frames_legacy_nulls.json"; +import discoveryCapture from "./fixtures/gateway_discovery_frame.json"; /** * A contract test, not a unit test: it checks that what continuum-proxy @@ -152,6 +153,23 @@ describe("gateway -> backend frames", () => { driver_ready: true, }; + it("accepts the real scan captured from a live LAN", () => { + // The one case a hand-written example cannot cover. Everything below + // agrees with how this test file imagines the gateway behaves; this + // agrees with what the gateway actually emitted, through its own serde + // enum, about two real printers. The two halves of this message are + // hand-synced, so a capture is the only thing that catches a drift. + for (const frame of discoveryCapture.frames) { + check(EdgeClientMessageSchema, frame); + } + // Guards against a fixture that validates because it is empty. + const printers = discoveryCapture.frames[0].printers; + expect(printers.length).toBeGreaterThan(0); + // And against one that validates because every field is absent: the + // address is the entire reason this message exists. + expect(printers.every((p) => p.address.length > 0 && p.vendor.length > 0)).toBe(true); + }); + it("accepts a scan result", () => { check(EdgeClientMessageSchema, { type: "discovered_printers", diff --git a/tests/fixtures/gateway_discovery_frame.json b/tests/fixtures/gateway_discovery_frame.json new file mode 100644 index 0000000..8dfcc22 --- /dev/null +++ b/tests/fixtures/gateway_discovery_frame.json @@ -0,0 +1,25 @@ +{ + "_note": "A real `discovered_printers` frame, captured on 2026-10-19 by running `cargo run --example discover_printers -- wire 192.168.0.0/24` against a live LAN with a Bambu P1P and H2C on it, with the gateway's fleet file pointed at an empty file so nothing was filtered out. The addresses and the message shape are exactly as captured. The two `serial` values are PLACEHOLDERS of the captured shape (15 alphanumeric characters) rather than the real ones: the serials identify someone's physical hardware, nothing in this test depends on their value, and no other fixture here carries one. Note what the frame does not contain, which is the point of the format: no access code, no API key. Re-capture with the `wire` subcommand above when the message changes.", + "frames": [ + { + "type": "discovered_printers", + "printers": [ + { + "vendor": "bambu", + "address": "192.168.0.20", + "serial": "01S00A000000000", + "source": "certificate", + "driver_ready": true + }, + { + "vendor": "bambu", + "address": "192.168.0.21", + "serial": "31B0BP0A0000000", + "source": "certificate", + "driver_ready": true + } + ], + "scanned_at": "2026-10-19T08:20:03Z" + } + ] +}