Repository navigation
feat(rag): Layer B changed-content replacement semantics - #117
Merged
Merged
Conversation
…cy, failure orders, partial batches, empty replacement, portals, two-user isolation, unscoped refusal, absent-id no-op
…ayer B replacement
…ssertion count to 251
…ment-delete assertions
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Layer B — Changed-content replacement semantics for private RAG imports
Gate-safe engineering only; no document is imported. The default
storeChunks/importDocumentPlanupsert path is unchanged.What was built
docs/adr/ADR-013-document-replacement-semantics.md(Proposed) — Specifies document identity (source_dir|file name), stale-id detection, write-then-delete order, failure consequences, parent-row consistency, empty-document rejection, idempotency, ownership/portal/USER_PRIVATE, persisted chunk-id handling, and non-atomic/concurrency limits.scripts/rag/governedImporter.ts— New explicitreplaceDocumentPlan. Writes all new chunks throughstoreChunksfirst; only after every write succeeds reads existing chunk ids and deletes stale ones viaDatabase.governedDeleteDocumentChunks. New-write failure aborts before any delete (old chunks preserved); stale-delete failure keeps new + undeleted stale chunks and throws. Empty replacement rejected before any write.src/infrastructure/database/index.ts—Database.governedDeleteDocumentChunks: requires owner + portal + document id, refuses unscoped calls and mismatched authenticated owner, de-duplicates ids, batches at most 100 per request. RLSet_owner_deleteremains the backstop; no migration needed.tests/utils/mockSupabase.ts— Delete tracking,failDeleteAfter,deletesarray, scoped delete failure injection.tests/rag/documentReplacement.test.ts— 16 tests: default path unchanged, same-plan replay, shrink, same-length change, new-write failure with preserved old chunks + retry convergence, stale-delete failure, partial batch failure + retry,[100, 20]batching, empty replacement, unlicensed/non-private refusal, all three portals, repeated-paragraph unique ids, two-user/two-document isolation, unscoped refusal, absent-id no-op, error hygiene.scripts/security/rls_matrix_rest.mjs—runScopedReplacementDelete(): proves owner + portal + document + id filter shape, cross-owner denial, wrong-portal denial, already-absent no-op.Red and green control
importDocumentPlanpath): 1 failed — expected 1 row, got 4 (3 stale + 1 new). Probe not shipped.tests/rag/documentReplacement.test.ts16/16; full suite 132 files / 738 tests.supabase db reset --no-seedexit 0;bash scripts/security/run_rls_matrix_local.sh→rows=251 pass=251 fail=0; unhardened negative control still reproduces defect (pass=73 fail=178).What was NOT done (honest blockers)
docs/rag-sources/intentionally empty; no licence-cleared documents supplied.Gates
Full local gate green: typecheck 0, lint 0 errors (129 pre-existing warnings), 132 files / 738 tests, boundaries 0, i18n 87 screens, no-raw-hex 330 files, architecture audit 0 violations, QA all systems verified, web export exported, audit 0 critical, guard:secrets passed, guard:public-env passed, guard:dist passed.
Suite ratchet moved by measurement from 131 files / 722 tests to 132 files / 738 tests.
Owner gate
Layer B real import remains blocked until the owner supplies: licence-cleared documents in
docs/rag-sources/, a written licence/rights basis, and a named human reviewer.