fix(put): lowercase caller-supplied slug in importFromContent (#200)#207
Open
sharziki wants to merge 1 commit intogarrytan:masterfrom
Open
fix(put): lowercase caller-supplied slug in importFromContent (#200)#207sharziki wants to merge 1 commit intogarrytan:masterfrom
sharziki wants to merge 1 commit intogarrytan:masterfrom
Conversation
putPage runs validateSlug internally and stores the page at the lowercased slug, but the same-transaction tx.upsertChunks/getTags/addTag lookups use whatever slug the caller passed in. When a user ran `gbrain put claude-memory/TestUpper/test ...` the put_page handler forwarded the uppercase slug straight through and upsertChunks failed with "Page not found: claude-memory/TestUpper/test" — the same message `get_page` emits for a genuinely missing page, so users debugging a failing bulk put chased phantom "did the page get deleted?" paths instead of the real cause (issue garrytan#200). Normalize once at the top of importFromContent so putPage, getTags, addTag, removeTag, and upsertChunks all operate on the same lowercased slug. Added a regression test covering the mock-engine call arguments. Fixes garrytan#200
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.
Summary
Fixes #200 —
gbrain put <slug>with uppercase letters failed with the misleading errorPage not found: <slug>, identical to thegbrain geterror for a genuinely missing page.Root cause
putPagerunsvalidateSluginternally and stores the page at the lowercased slug. However, the same-transaction calls that follow (tx.upsertChunks,tx.getTags,tx.addTag,tx.removeTag) use whatever slug the caller handed toimportFromContent. Withclaude-memory/TestUpper/testtheupsertChunkslookup hitsSELECT id FROM pages WHERE slug = 'claude-memory/TestUpper/test', finds nothing, and throwsPage not found: claude-memory/TestUpper/test— the exact messageget_pageemits for a genuine miss.The bug reporter's 236-file bulk migration silently dropped 30 writes under
claude-memory/DogskinMap/*andclaude-memory/SolarPower/*until they A/B-testedTestUppervstestlower.Fix
Lowercase the slug once at the top of
importFromContentsoputPage,getTags,addTag,removeTag, andupsertChunksall operate on the same normalized slug.Test plan
test/import-file.test.tsthat feeds an uppercase slug throughimportFromContentand asserts bothputPageandupsertChunksare called with the lowercased slug.bun test test/import-file.test.ts— 17 pass, 0 fail.🤖 Generated with Claude Code