Repository navigation
fix: settle the slug codec, and make the CLI agree with it (#123) - #139
Merged
Merged
Conversation
Three findings from the release review, fixed together because they are one problem: the codec, its strictness, and the client that has to match it. F7 - the escape alphabet collided with the transport. The first fix for #123 escaped literals as "%2D" and "%25". That is injective on its own, but it collides with percent-encoding itself. The CLI sends encodeURIComponent(slug), turning "%2D" into "%252D", and RFC 3986 6.2.2.2 permits any normaliser to decode "%2D" - an unreserved character - back to '-'. A proxy doing that turns "-order%2Ditems" into "-order-items", i.e. "/order/items", and #123's collision reappears behind ordinary infrastructure. It worked only because Crow does not decode req.url and the tavern client sends it raw. The alphabet now contains no '%' at all. JSON-pointer style: '/'->'-', '-'->"~1", '~'->"~0". Prefix-free, injective, and unchanged by encodeURIComponent or RFC normalisation. Verified exhaustively over every path up to length 5 drawn from "/-~01ab": 19,608 paths, no collisions, no round-trip failures. F8 - the tolerant decoder reintroduced the ambiguity. I had made slugToPath prepend a leading '/' when the decode did not start with one, so a percent-decoded url-path would also resolve. That made 'x' and '-x' both address '/x': every endpoint had two config-service names again, which is exactly what #123 set out to remove. The two forms are now explicit and told apart by a property that cannot overlap - a slug never contains '/', because every '/' is encoded as '-'. slugToPath is strict again; identifierToPath resolves either form. The justification for that tolerance was a set of tavern stages accepting [200, 404, 401] against `northwind/products/`, an endpoint this configuration does not contain - so they asserted nothing whatsoever. They now address real endpoints and expect one status each, including a hyphenated path, which is the case #123 was about. F2 - the CLI shipped the old codec. cli/src/lib/url.ts still carried the ORIGINAL scheme. `git diff v26.09.20..HEAD -- cli/` was empty: the codec changed and the client did not. buildEndpointUrl backs every endpoints/templates/cache/wizard command, and both binaries ship in the same flapi-io wheel, so the release would have broken its own CLI - every config command 404ing. Worth noting the two had ALREADY drifted before any of this: the CLI used '-slash-' and the server '-slash'. So the fix is not just to port the codec but to make drift fail a test. test/fixtures/slug_codec.json is read by both the C++ suite and cli/test/unit/url.spec.ts: 20 cases, each asserted in both directions in both languages, plus injectivity and the no-'%' property on both sides. docs/CONFIG_SERVICE_API_REFERENCE.md documented the original scheme and is rewritten: the table, why the alphabet avoids '%', the two accepted forms, and the fixture clients must match. 754 unit tests, 375 standalone integration tests, 46 CLI tests.
A release review found that several tests added with the recent fixes would
pass against the very defects they claimed to pin. Each is now checked
against the old behaviour and shown red before being accepted.
(c) The watermark test never called the product code.
It reimplemented the new per-table SQL inside the test and asserted
against its own copy - `grep -c CacheManager` on it returned 0 - so it
passed unchanged against the catalog-wide implementation it was meant to
pin. Its comment claimed it "pins the observable property rather than
the implementation", which was self-justification for a test that pinned
nothing.
Rewritten to drive the real CacheManager through a real DuckLake
catalog, with an adapter that executes queries for real and captures the
params handed to the renderer - which is where the chosen watermark
becomes observable. Asserts the chosen previous snapshot is the table's
OWN, and that the query CacheManager issued is table-scoped.
Verified red: restoring the catalog-wide query fails 2 of 12 assertions.
(b) The body-spoof test checked a table it never read.
It POSTed a spoofed identity to a write endpoint that stores
{{ auth.username }} into `seen`, then asserted on /who - which renders
the CURRENT request's context and is empty whatever the write did. The
spoofed value could have been sitting in the table and the test would
pass.
There is now a reader over `seen`, so the assertion is on what was
actually stored, plus a case for the write path's query-parameter
fallback, which is a fourth entry point that was guarded separately and
never covered.
Verified red: removing the body guard fails it.
(d) The retention test accepted zero events, and accepted failure.
It iterated GC audit events asserting status in ["success", "error"], so
it passed with no events at all and passed on failure when there were
any. That is how count-based retention shipped broken for its whole
life - emitting SQL DuckDB rejects as a parser error - while this test
stayed green.
The integration stage now fails on any GC event reporting an error. The
real assertion lives in a new C++ test against a real catalog: it
requires an expire CALL with real snapshot ids, rejects the ARRAY[0:N]
shape, and checks the snapshot count actually drops.
Verified red: restoring ARRAY[0:N] fails 2 of 10 assertions.
(a) was fixed in the previous commit: the offload test used the shipped
thread count, so the pre-offload server passed it.
755 unit tests, 376 standalone integration tests, 46 CLI tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three findings from the release review, fixed together because they are one problem: the codec, its strictness, and the client that has to match it.
F7 — the escape alphabet collided with the transport
My first fix for #123 escaped literals as
%2D/%25. Injective on its own, but it collides with percent-encoding itself: the CLI sendsencodeURIComponent(slug), turning%2Dinto%252D, and RFC 3986 §6.2.2.2 permits any normaliser to decode%2D— an unreserved character — back to-. A proxy doing that turns-order%2Ditemsinto-order-items→/order/items, and #123's collision reappears behind ordinary infrastructure. It worked only because Crow does not decodereq.urland the tavern client sends it raw.The alphabet now contains no
%at all — JSON-pointer style:/--~1~~0Prefix-free, injective, unchanged by
encodeURIComponentor RFC normalisation. Verified exhaustively over every path up to length 5 drawn from/-~01ab: 19,608 paths, no collisions, no round-trip failures.F8 — my tolerant decoder reintroduced the ambiguity
I had made
slugToPathprepend a leading/when the decode didn't start with one, so a percent-decoded url-path would also resolve. That madexand-xboth address/x— every endpoint had two names again, which is precisely what #123 removed.The two forms are now explicit, told apart by a property that cannot overlap: a slug never contains
/.slugToPathis strict again;identifierToPathresolves either form.The justification for that tolerance was a set of tavern stages accepting
[200, 404, 401]againstnorthwind/products/— an endpoint this configuration does not contain, so they asserted nothing at all. They now address real endpoints with one expected status each, including a hyphenated path.F2 — the CLI shipped the old codec
cli/src/lib/url.tsstill carried the original scheme.git diff v26.09.20..HEAD -- cli/was empty: the codec changed and the client did not.buildEndpointUrlbacks every endpoints/templates/cache/wizard command, and both binaries ship in the sameflapi-iowheel — so the release would have broken its own CLI, every config command 404ing.And they had already drifted before any of this: the CLI used
-slash-, the server-slash.So the fix is not just to port the codec but to make drift fail a test.
test/fixtures/slug_codec.jsonis read by both the C++ suite andcli/test/unit/url.spec.ts— 20 cases, asserted both directions in both languages, plus injectivity and the no-%property on each side.Docs
CONFIG_SERVICE_API_REFERENCE.mddocumented the original scheme. Rewritten: the table, why the alphabet avoids%, the two accepted forms, and the fixture clients must match.754 unit, 375 standalone integration, 46 CLI tests, all green.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.