Part 5 of the fifth-protocol series. The connector has a rule: every fix leaves one test behind, and the test is checked by taking the fix out and watching it fail. On the day, a fix followed that rule exactly, and the terminal it was for still refused every read. Nothing was wrong with the rule. Something was wrong with what the test ran against.
The test machine
Most terminals the connector reads have never been on my desk, so each protocol has a pretend machine: a small Go server that answers the reader's requests the way the real one does. The testing post has the whole kit. For this protocol it is a few hundred lines that answer hello, count, log blocks and names, and can be told to misbehave: a password set, replies one byte at a time, a hang-up halfway through a block, something else on the port.
It was written from the same public write-up as the reader, by the same person, on the same day. So it read the download request the same way the reader did, with the fields two bytes early. Reader and simulator agreed. The terminal did not.
simulator v1 · our guesses
✓ whole log read
simulator v2 · live bytes
✕ read fails
code 3 / zero bytes, like the real one
the real terminal
✕ read fails
code 3 / zero bytes, like the real one
The fix that passed
The morning's theory was that the terminal wants a hello at the start of every connection. I made the simulator refuse anything before a hello, wrote the fix, and checked the test the right way:
# keep the fixed file, put the old one back, run, restore
cp internal/<reader>/reader.go /tmp/reader.go.fixed
git show origin/main:connector/internal/<reader>/reader.go > internal/<reader>/reader.go
go test ./internal/<reader>/... ./internal/runner/... # must FAIL
cp /tmp/reader.go.fixed internal/<reader>/reader.go
cmp /tmp/reader.go.fixed internal/<reader>/reader.go && go test ./... # must pass
Thirteen tests failed without the fix and passed with it. Then I ran the same code against the real terminal from my laptop, and it refused, code 3, exactly as before.
The revert check did its job. It proved the tests exercise the fix. It cannot prove the fix is the one the world needs, because the simulator was my theory of the world. A test against a model you wrote proves that the code and the model agree. When both come from the same reading, agreeing is cheap.
What a simulator has to be made of
The answer was not more tests. It was a different source for the simulator.
- Captured bytes, not a reading of a description. The rebuilt simulator has a mode for this terminal made from what the terminal actually sent: 20-byte records, the four-byte block ending with its checksum, the packet number echoed in the reply head, and a device number it answers to.
- It refuses what the real one refuses. A block request without the 1,024 size where the terminal looks for it gets code 3, as on site.
- Real records in the tests. One test decodes three records copied byte for byte from the terminal, with the staff numbers changed: a punch made for the test, the oldest record in the log, and an out punch.
- The old theory stays optional. "Hello first" is now a switch on the simulator, off by default, because the real terminal did not need it.
The hello change stayed in the reader. It costs one round trip and harms nothing. It just was not the fix.
Two separate programs
The simulator also runs as its own program, devsim, so the connector's real
runner can be tested end to end against a machine across a real TCP socket,
not a function call:
devsim fk --wide --listen 127.0.0.1:5005 --device-no 1 --every 5s
devsim fk --wide --listen 127.0.0.1:5006 --device-no 2 --every 7s
With two of these running, the audit after the site visit pointed one connector at both and walked it through what an office does: first read, live punches, older punches on request, the people list, a restart, and a port that was wrong and then fixed. Both terminals were read, nothing was uploaded twice, and nothing crossed from one to the other.
The same kind of gap, elsewhere
After the day, an audit went looking for more of the same: places where the code assumed something only one terminal had shown it. It found five, and each now has a test that fails without its fix:
- The device number was always 1. A second terminal set to device 2 would never answer. It now comes from the platform, 1 if unset.
- The refusal blamed a password even after the terminal had answered a hello. It now names the step that was refused.
- A fixed machine waited five minutes. After a long run of failures the connector tries a machine every five minutes. An update or an address change now ends that wait.
- "Look for it" could not find this terminal. The search matched machines by serial, and this terminal never sends one. At an address HR typed, the terminal's answer is now enough; on a network-wide search, only a terminal whose network ID or newest punch matches counts.
- More than 65,535 records. The count field is 32 bits but the request has 16 for it. A 20-byte terminal past that size now reads to the end.
And three things it could not settle without the real terminal, left as open questions rather than guesses:
- What the two-byte checksum is. One sample is not enough to enforce it.
- How to read or set the clock. That needs a command nobody has published.
- What a terminal does when asked with the wrong device number. The simulator assumes silence.
The rule, amended
Every fix still leaves a test that fails without it. Now there is a second half: the thing the test runs against must have been checked against the world at least once. For a protocol, that means captured bytes in the simulator and in the tests, and a run against the real device before anything ships. Part 8 is the release that followed, and the run against the real terminal that came before it.