Skip to content

fix: settle the slug codec, and make the CLI agree with it (#123) - #139

Merged
jrosskopf merged 2 commits into
mainfrom
fix/slug-codec-transport-safe
Sep 23, 2026
Merged

jrosskopf merged 2 commits into
mainfrom
fix/slug-codec-transport-safe

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

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 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 → /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:

in the path in the slug
/ -
- ~1
~ ~0

Prefix-free, injective, 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 — my tolerant decoder reintroduced the ambiguity

I had made slugToPath prepend a leading / when the decode didn't start with one, so a percent-decoded url-path would also resolve. That made x and -x both 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 /. 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 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.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.

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.json is read by both the C++ suite and cli/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.md documented 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


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

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.
@jrosskopf
jrosskopf merged commit 8376f3c into main Sep 23, 2026
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant