Repository navigation
test(database-explorer): add read-only query contract regression tests - #199
Open
Harshitha-0111 wants to merge 1 commit into
Conversation
Extract the query policy and HTTP server from extension.mjs into importable modules, share one runQuery path between HTTP and canvas entry points, and include extension tests in Vitest and tsgo. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical finding remains: the test’s TODO and title disclose a privately tracked policy gap, contrary to the repository’s restrictions on public vulnerability reporting.
1 open issue
What changed in this PR
This PR adds isolated regression coverage for Database Explorer’s existing read-only query interface, addressing #164 without requiring a hosted Copilot session.
Changes:
- Extract query handling and HTTP serving into importable modules shared by HTTP and canvas actions.
- Add disposable-database tests for accepted queries, rejected inputs, unchanged database state, and entry-point consistency.
- Include extension tests in test discovery and type checking, and update documentation.
| File | Description |
|---|---|
vitest.config.ts |
Adds extension-local test discovery. |
tsconfig.tsgo.json |
Includes extension TypeScript files in type checking. |
README.md |
Documents expanded unit-test coverage. |
.github/extensions/database-explorer/server.mjs |
Extracts HTTP serving with an injectable executor. |
.github/extensions/database-explorer/query-policy.test.ts |
Adds query-contract and entry-point regression tests. |
.github/extensions/database-explorer/query-policy.mjs |
Extracts validation, execution, and shared query handlers. |
.github/extensions/database-explorer/extension.mjs |
Connects the extension to the extracted modules. |
.github/copilot-instructions.md |
Documents extension tests in the unit-test command. |
Review effort: Balanced
Comment on lines
+162
to
+163
| // Tracked privately per SECURITY.md; enable once the policy gap is resolved. | ||
| it.todo('rejects statements that begin with WITH but are not read-only queries'); |
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
The Database Explorer extension has a documented read-only query interface, but nothing in the repository's test suite exercised it, and Vitest did not discover tests under
.github/extensions/. This adds regression coverage for the existing contract without adding new query capabilities.To make the production policy importable without joining a Copilot SDK session, the validator/executor and the HTTP server were moved out of
extension.mjsintoquery-policy.mjsandserver.mjs. Both the HTTP endpoint and the canvasrun_queryaction now go through one sharedrunQuery(validate, then execute).Related Issue
Relates to #164
Type of Change
Changes Made
query-policy.mjs(validation, execution, sharedrunQuery, canvas handler factory) andserver.mjs(HTTP server);extension.mjsimports them.@libsql/clientlazily insideexecuteQueryso tests can inject an executor.query-policy.test.ts: accepted queries with expected rows, a table of rejected inputs, executor never called on rejection, fixture rows/schema unchanged (disposable temp SQLite DB), and identical outcomes via HTTP and canvas action..github/extensions/**in Vitest andtsconfig.tsgo.json.Testing
Validated with
NODE_OPTIONS=--experimental-sqlite(local Node is 22.11).npx vitest run: 5 files passed, 67 tests passed, 1 todonpm run lint: passednpm run typecheck: passedData Layer Changes
npm run test:unit- all tests passnpm run db:generate) for any schema changeFrontend Changes
npm run test:e2e- all tests passdata-testidattributes to interactive elementsnpm run build)Checklist
Additional Notes
run_queryhandler now awaits execution, so execution errors are also wrapped asCanvasError(previously only validation errors were).it.todois left for a possible policy gap that should be handled perSECURITY.mdrather than in this PR.node:sqliteexecutor, not libsql, so they never touch the project database.