Repository navigation
fix: ask the name grammar before the class question (#109) - #133
VendettaGamesHQ wants to merge 2 commits into
Conversation
Closes flop-labs#109. A room class is a name PREFIX, so `room_classes` reads a class marker off a string this service will never store. Both write gates asked their class question before anything read the grammar, so a name the grammar refuses got answered on class grounds — and the correction the answer named then contradicted it: GET /r/mb-FOO/say/bot/hi 403 ... it takes signed writes only, send: GET /r/mb-FOO/say-signed/... GET /r/mb-FOO/say-signed/... 400 bad name 'mb-FOO' The ownership lane split the same way on the identical key: `room-owners` asked `store.ownable` first (403 "cannot be owned"), while `room-allow` reached `note_get`, which validates (400 "bad name"). Both gates now validate first. `valid_name` raises `StoreError`, which is already mapped to the same 400 the storage layer produces, so this borrows that message rather than restating it — no new error text, and the signed lane's answer becomes every lane's answer. Folded into existing statements rather than added as new ones, so app.py grows by one code line rather than three. `ns, key = valid_name(ns), valid_name(key)` is deliberately not the shorter `and` form: `and` short-circuits, so the key would only be validated when ns happened to be the nonce namespace — a validation that does not run, which is the bug being fixed. The one line puts core/app.py at 942 and the core total at 1903, so both caps move by exactly one. Flagging that rather than golfing it: the readable form seemed the better trade against "no code golf ... unreadability is a reject even when the line count goes down". Happy to take a different shape if you would rather the cap held. Tests go in tests/http/test_lane_parity.py because that is precisely what this bug is: one logical write, several lanes, disagreeing. Five bad names across four lanes, both ownership lanes on one key, and the mirror — a name the grammar ACCEPTS must still get its class answer, or the fix would pass just as happily by refusing every mailbox. Verified: ruff check, ruff format --check, sz.py --check and sz.py --caps all pass locally. The pytest suite needs POSIX `fcntl`, which this machine does not have, so the suite is verified in CI rather than claimed here.
CI caught it: 330 passed and my 5 failed, all on the same line. The signed lane runs _signer BEFORE the gate, so a placeholder did:key is answered on the DID and the name check is never reached. The test would have asserted nothing about names while appearing to cover the lane. Reuses _client's _keypair/_say_signed rather than re-implementing the signing construction, so the parity test agrees with the service and not with itself.
|
Closing this — #108 got here first and is the better version. Entirely my fault: I read the issue and went straight to the code without checking the open PR queue, which is a thing I should have done in a repo with sixty-odd of them. Apologies for the noise. #108 covers the same two gates and also carries the CHANGELOG and AGENTS entries this was missing. One thing from here that may be worth folding in if you want it, and may equally not be:
Both are three lines each against #108 if useful. Happy either way — the fix is the point and it is already in a better PR. One note for anyone hitting the same thing: the signed lane needs a real signature to reach the name check, because |
Closes #109.
The change
A room class is a name prefix, so
room_classesreads a class marker off a string this service will never store. Both write gates asked their class question before anything read the grammar, so the correction the answer named then contradicted it:The ownership lane split the same way on the identical key:
room-ownersasksstore.ownablefirst (403 "cannot be owned"), whileroom-allowreachesnote_get, which validates (400 "bad name").Both gates now validate first.
valid_nameraisesStoreError, which is already mapped to the same 400 the storage layer produces, so this borrows that message rather than restating it — no new error text, and the signed lane's answer becomes every lane's answer.Two things worth flagging rather than burying
The core cap moves by one. Folding the calls into existing statements kept it to a single added code line, which puts
core/app.pyat 942 and the core total at 1903. I did not golf it further:ns, key = store.valid_name(ns), store.valid_name(key)is deliberately not the shorterandform, becauseandshort-circuits and the key would then only be validated whennshappened to be the nonce namespace — a validation that does not run, which is the bug being fixed. Happy to take a different shape if you would rather the cap held.The tests go in
tests/http/test_lane_parity.py, because that is precisely what this bug is: one logical write, several lanes, disagreeing — invisible to any single-lane test. They reuse_client's_keypair/_say_signedrather than re-implementing the signing construction.The signed lane is really signed, and that mattered:
_signerruns before the gate, so a placeholderdid:keyis answered on the DID and never reaches the name check. My first version did exactly that and CI caught it — the test would have asserted nothing about names while appearing to cover the lane.There is also a mirror test: a name the grammar accepts must still get its class answer, or the whole thing would pass just as happily if the gate started refusing every mailbox.
Verification
ruff check,ruff format --check,sz.py --checkandsz.py --capspass. The pytest suite needs POSIXfcntl, which the machine I wrote this on does not have, so it was verified in CI rather than claimed here:app.py: red, with exactly the reported symptoms —mb-FOOandmb-p-FOOanswering 403 on the unsigned lane andD-FOOanswering 403 onroom-owners— https://github.com/VendettaGamesHQ/technocore-chat/actions/runs/32808378645The
d-,e-andp-parameters do not reproduce the bug (no gate fires on those classes); they are there for the consistency the file exists to assert.