Repository navigation
fix: make the endpoint slug codec injective (#123) - #136
Merged
Merged
Conversation
An endpoint is addressed in the config service as
/api/v1/_config/endpoints/{slug}. The codec that produced that slug was not
reversible, so the address did not identify the endpoint.
pathToSlug mapped every internal '/' to '-', every non-alphanumeric to '-',
collapsed runs of '-' and stripped the edges. slugToPath then mapped every
'-' back to '/'. So:
"/a-b" -> "a-b" -> "/a/b"
"/a/b" -> "a-b" -> "/a/b"
Both endpoints shared one config-service URL, and a GET -> edit -> PUT round
trip silently REWROTE "/order-items" to "/order/items". Hyphens in REST
paths are entirely ordinary, so this was reachable with a plain config.
"/" and "" both encoded to "empty" as well.
New encoding, chosen to keep the common case readable:
'/' -> '-' /sap/functions -> -sap-functions
'-' -> "%2D" a literal hyphen is escaped, which is what makes a '-'
'%' -> "%25" in a slug unambiguously mean '/'
"" -> "empty" unambiguous: every non-empty path starts with '/' and
therefore encodes to a leading '-'
Verified exhaustively over every path up to length 5 drawn from "/-%2Dab":
19,608 paths, zero collisions, zero round-trip failures.
Two earlier attempts are recorded in the source comment because both failed
on the same point and the next person should not repeat them: a
one-character escape for '/' cannot coexist with a two-character escape for
the literal, because the shorter is a prefix of the longer. "//x" and "_x"
both produced "__x".
BREAKING: slugs change. /api/v1/_config/endpoints/customers-slash is now
/api/v1/_config/endpoints/-customers-. Anything holding a slug URL must
re-resolve it. This is the clean-break option rather than accepting both
forms, so there is no legacy path to carry.
Twelve assertions in config_service_slug_test.cpp changed with the
encoding. They were pinning the defect - "customers-slash", and
pathToSlug("/") == "empty", which is the root/empty collision - not the
contract. What they test is unchanged: round trips, lookup by slug,
uniqueness across endpoints. A note at the top of the file says so.
Four new test cases cover what the old codec could not do: a hyphen is not
a slash, root and empty are distinct, everything round-trips including
"/a%b" and "/a--b", and distinct paths get distinct slugs.
751 unit tests, 362 standalone integration tests.
The integration suite failed on the slug branch in a way the unit tests
could not see, because both failures are in callers that address endpoints
by slug or path over HTTP.
1. slugToPath must tolerate a path-style identifier.
The config service also accepts a percent-encoded url-path in the {slug}
position - the tavern suite addresses an endpoint as
"northwind%2Fproducts%2F" - which arrives url-decoded as
"northwind/products/" and contains nothing this codec encodes.
The old decoder prepended the leading slash unconditionally, because it
stripped one when encoding. The new one encodes the leading '/' as '-',
so a slug from pathToSlug already decodes with it - and the
path-style identifier lost its leading slash and matched no endpoint.
The slash is now added only when absent. That cannot collide: every slug
pathToSlug produces for a non-empty path starts with '-' and therefore
already decodes to a leading '/'.
2. Four hardcoded slugs in the DuckLake tests.
test-cached-slash -> -test-cached-, and the same for append, merge and
invalid. Verified against the encoder rather than hand-derived.
Worth recording: the unit suite was green through both of these. The slug
codec has two classes of caller - one that round-trips through it, which
the unit tests cover, and one that hardcodes the output, which only the
integration suite exercises. A green unit run said nothing about the
second.
751 unit tests, 362 standalone integration tests; the tavern suite that
caught this runs on CI.
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.
Closes #123.
The defect
An endpoint is addressed as
/api/v1/_config/endpoints/{slug}. The codec producing that slug was not reversible, so the address did not identify the endpoint:Both shared one config-service URL, and a
GET → edit → PUTround trip silently rewrote/order-itemsto/order/items. Hyphens in REST paths are entirely ordinary, so this needed no unusual config./and""both encoded to"empty"as well.The new encoding
Chosen to keep the common case readable:
'/'→'-'/sap/functions→-sap-functions'-'→%2D'%'→%25-in a slug unambiguously a slash""→empty/, so it encodes to a leading-Verified exhaustively over every path up to length 5 drawn from
/-%2Dab— 19,608 paths, zero collisions, zero round-trip failures.Two earlier attempts are recorded in the source comment, because both failed on the same point: a one-character escape for
/cannot coexist with a two-character escape for the literal, since the shorter is a prefix of the longer.//xand_xboth produced__x. I only caught it by fuzzing rather than by inspection.Breaking
Slugs change:
…/endpoints/customers-slash→…/endpoints/-customers-. Anything holding a slug URL must re-resolve it. This is the clean-break option you chose, so there is no legacy form to carry.On the changed tests
Twelve assertions changed. They pinned
"customers-slash"andpathToSlug("/") == "empty"— that is, the defect, including the root/empty collision itself. What they test is unchanged: round trips, lookup by slug, uniqueness. A note at the top of the file explains why they moved, since the standing rule is to keep the test surface stable while the tests are correct.Four new cases cover what the old codec could not: a hyphen is not a slash, root and empty are distinct, everything round-trips including
/a%band/a--b, and distinct paths get distinct slugs.751 unit, 362 standalone integration, all green.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.