feat: SQL parser vs Proxy#16
Conversation
Create `createTestDb` and `createMockDOStorage` helpers to support testing with better-sqlite3 and Drizzle ORM.
Extract `recordMutationWithCascades` into a new `createTrackedClient.ts` module as `recordCascades`, and add `createTrackedClient` function to wrap DurableObjectStorage with SQL tracking via Proxy. Include comprehensive test coverage for cascade propagation and table tracking.
Table tracking has been moved to the client-level SQL proxy (`createTrackedClient`), which is more reliable and captures all operations regardless of how the ORM is called. This eliminates redundant tracking logic and simplifies the proxy signatures. Also add TypeScript type casts to fix type inference issues in `mockDOStorage.ts` and remove unused test fixtures.
Expose raw database instance in test setup and add comprehensive test suite verifying that unsafeRawDb operations are tracked for read/write access while bypassing safety enforcement constraints.
Greptile SummaryThis PR replaces proxy-layer table tracking (via
Confidence Score: 5/5Safe to merge — the architectural shift from proxy-layer to SQL-parser-based tracking is well-tested by both unit and integration tests, cascade handling is now correct, and the old silent tracking failures now emit warnings. All changed paths are covered by tests that exercise the new SQL-interception path end-to-end. The simplification of mutation proxies (dropping table-name coupling) is clean. The one non-blocking finding — whereIds being computed but not yet consumed — does not affect correctness of any current feature. No files require special attention beyond the whereIds dead-computation note in createTrackedClient.ts. Important Files Changed
|
Restructured `parseSqlTracking` to explicitly collect WHERE clauses from SELECT/UPDATE/DELETE statements before traversing them. This prevents parameter extraction from JOIN ON and HAVING clauses, which should not be treated as row-level scoping conditions. Also relaxed the file size guideline in AGENTS.md (150–200 lines soft, 250 hard) and added console warnings when SQL tracking cannot be wired due to missing `realDb.$client` or `realDb.session`.
No description provided.