Repository navigation
Add regression coverage for Database Explorer read-only query contract - #187
Open
karan-cspl wants to merge 1 commit into
Open
karan-cspl wants to merge 1 commit into
karan-cspl wants to merge 1 commit into
Conversation
Extract shared query validation, execution, HTTP server, and canvas definition factory into query-policy.mjs with injectable dependencies, add Vitest regression coverage across disposable SQLite fixtures and both entry points, and include extension tests in Vitest and tsgo discovery. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The rejection matrix omits SQLite-supported WITH-prefixed mutations that the shared validator accepts, allowing both entry points to modify data despite passing the no-execution and unchanged-state tests.
1 open issue
What changed in this PR
Adds isolated regression coverage for the Database Explorer’s read-only query contract, addressing issue #164 without requiring a hosted SDK session.
Changes:
- Extracts query handling, HTTP serving, and canvas actions into an importable module with injectable dependencies.
- Adds disposable SQLite tests for accepted queries, rejected inputs, unchanged database state, and HTTP/canvas consistency.
- Includes extension tests in Vitest discovery and TypeScript checks.
| File | Description |
|---|---|
vitest.config.ts |
Enables discovery of extension-local tests. |
tsconfig.tsgo.json |
Includes extension TypeScript files in type checks. |
.github/extensions/database-explorer/query-policy.test.ts |
Adds query-contract and entry-point regression coverage. |
.github/extensions/database-explorer/query-policy.mjs |
Extracts shared policy and runtime handlers for isolated testing. |
.github/extensions/database-explorer/query-policy.d.mts |
Declares types for the extracted module and injectable dependencies. |
.github/extensions/database-explorer/extension.mjs |
Delegates to the extracted module while retaining SDK registration. |
Review effort: Balanced
Comment on lines
+163
to
+165
| { label: 'INSERT statement', input: "INSERT INTO publishers (name) VALUES ('Rogue')", expectedError: 'Only read-only SELECT and WITH queries are allowed.' }, | ||
| { label: 'UPDATE statement', input: "UPDATE games SET funding_goal = 0 WHERE id = 1", expectedError: 'Only read-only SELECT and WITH queries are allowed.' }, | ||
| { label: 'DELETE statement', input: 'DELETE FROM games WHERE id = 1', expectedError: 'Only read-only SELECT and WITH queries are allowed.' }, |
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.

Description
Adds isolated Vitest regression coverage for the Database Explorer extension's read-only SQL query contract across both its HTTP (
/api/query,/api/tables) and canvas-action (run_query,list_tables) entry points. Previously,vitest.config.tsonly discovered tests underdb/andsrc/, and.github/extensions/database-explorer/extension.mjsexecuted top-levelawait joinSession(...)with host-only imports (@libsql/client,@github/copilot-sdk/extension), preventing direct unit and integration testing of the shared query validation and execution paths.Related Issue
Fixes: #164
Closes #164
Type of Change
Changes Made
stripCommentsAndValidateSingleStatement), validation (validateReadOnlyQuery), value formatting (normalizeValue), query execution (executeQuery,listTables), HTTP server (startServer), and canvas definition factory (createDatabaseExplorerCanvas) into.github/extensions/database-explorer/query-policy.mjs(with.d.mtsTypeScript declarations) using injectable client and SDK dependencies..github/extensions/database-explorer/extension.mjsto delegate to./query-policy.mjswhile preserving runtime behavior..github/extensions/database-explorer/query-policy.test.tscovering all five required scenarios against a disposablenode:sqlitefixture database:accepts supported read-only single-statement queriesrejects invalid input and requests outside the read-only contract(29 table-driven cases)does not invoke the query executor after validation rejects a requestpreserves fixture rows and schema while serving the read-only interfaceapplies the same policy through HTTP and canvas actionsvitest.config.tsandtsconfig.tsgo.jsonto include.github/extensions/**/*.test.tsand.github/extensions/**/*.ts.Testing
npm run test:unit -- --reporter=verbose- Passed (5 test files, 72 tests passed, including all 33 tests in.github/extensions/database-explorer/query-policy.test.ts)npm run lint- Passed (0 errors)npm run typecheck:all(npm run typecheck+npm run typecheck:astro) - Passed (0 errors, 0 warnings, 0 hints across 37 files)Data Layer Changes
npm run test:unit- all tests passnpm run db:generate) for any schema change (N/A - no schema changes)Frontend Changes
npm run test:e2e- all tests pass (N/A - no frontend UI changes)data-testidattributes to interactive elements (N/A - no frontend UI changes)npm run build) (N/A - no frontend UI changes)Checklist
Additional Notes
Discovered test names in
.github/extensions/database-explorer/query-policy.test.ts:Database Explorer read-only query contract > accepts supported read-only single-statement queriesDatabase Explorer read-only query contract > rejects invalid input and requests outside the read-only contract > rejects <case> with "<expectedError>"(29 table-driven policy cases)Database Explorer read-only query contract > does not invoke the query executor after validation rejects a requestDatabase Explorer read-only query contract > preserves fixture rows and schema while serving the read-only interfaceDatabase Explorer read-only query contract > applies the same policy through HTTP and canvas actions