fix: prevent test data from leaking into production DB#320
Merged
Conversation
Add ensureProject() guard that rejects synthetic test paths (/test/...) when LORE_DB_PATH is unset (production DB). This catches the case where a test file is run directly with `bun run` instead of `bun test`, bypassing the bunfig.toml preload that sets up the temp test DB. Also: - Harden bunfig.toml with explicit NODE_ENV=test in [test.env] - Expose `lore data delete project <path|id>` via CLI for cleanup - Add unit tests for the guard
…, comments - Fix misleading test comment about ensureProject not being called - Add boundary test: /testing/... and /test (no slash) don't trigger guard - Validate project existence before confirmation prompt in CLI delete - Show project name and counts in confirmation prompt - Clarify LORE_DB_PATH assumption in guard comment
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
ensureProject()guard that rejects synthetic test paths (/test/...) whenLORE_DB_PATHis unset (production DB), preventing test data leaks when test files are run directly withbun runinstead ofbun testbunfig.tomlwith explicitNODE_ENV=testin[test.env]as belt-and-suspenderslore data delete project <path|id>via CLI so leaked test projects can be cleaned upContext
A test project
/test/ltm/debug-forsessionleaked into the production DB. Root cause: running a test file directly withbun run(for debugging) bypasses thebunfig.tomlpreload that setsLORE_DB_PATHto a temp DB. The existingNODE_ENV=testguard indb()doesn't help becauseNODE_ENVisn't set when the test runner isn't involved.The new guard in
ensureProject()catches this by detecting that paths starting with/test/are synthetic test paths that should never exist in the production DB. No real project path on any OS starts with/test/.Changes
packages/core/src/db.tsensureProject()— rejects/test/paths whenLORE_DB_PATHunsetbunfig.toml[test.env]withNODE_ENV = "test"packages/core/bunfig.toml[test.env]withNODE_ENV = "test"packages/gateway/src/cli/data.tsprojecttype tolore data delete, update help textpackages/core/test/db.test.tsTesting
lore data delete project /test/ltm/debug-forsessionto clean up the leaked project