test(backend): establish test suite + fix bugs found along the way - #20
Merged
Merged
Conversation
- Updated pre-commit hook including test - Updated ci pipeline to include test
- fix stripBasePath false-matching prefix-like paths (e.g. /api/v10 vs /api/v1) - add unit tests for all mock-path utilities, drop unused VERCEL_URL branch
…r resolution and file operations
There was a problem hiding this comment.
Pull request overview
This PR establishes a backend test harness using Vitest and adds unit/integration coverage around core backend utilities (schema resolution, endpoint data persistence, and tRPC routers), alongside a small bug fix in path handling (stripBasePath) and some workflow/dev tooling updates to run tests in CI and pre-commit.
Changes:
- Add Vitest configuration plus unit and integration test suites covering backend routers and filesystem-backed endpoint data behavior.
- Fix
stripBasePathto enforce a segment boundary (and remove aVERCEL_URLorigin branch) with new tests. - Update developer/CI automation to run unit tests on pre-commit and full tests in CI.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
vitest.config.ts |
Adds Vitest config (node env, globals) and enables tsconfig path resolution for ~/* imports. |
tests/integration/test-context.ts |
Provides shared integration-test DB context and temp data-dir isolation helper. |
tests/integration/resolve-flow.test.ts |
Integration tests for endpoint.resolve basePath stripping behavior (including a documented known bug). |
tests/integration/project-lifecycle.test.ts |
End-to-end lifecycle tests verifying on-disk data creation/regeneration/cleanup. |
tests/integration/cascade-delete.test.ts |
Integration tests for folder cascade deletion across DB and filesystem artifacts. |
src/server/api/routers/project.test.ts |
Unit tests for projectRouter with mocked data-store side effects. |
src/server/api/routers/folder.test.ts |
Unit tests for folderRouter with mocked data invalidation behavior. |
src/server/api/routers/endpoint.test.ts |
Unit tests for endpointRouter including conflict checks and resolve behavior, with mocked data-store functions. |
src/lib/schema-resolver.test.ts |
Unit tests for schema resolution and response data generation (faker, arrays, nesting). |
src/lib/mock-path.ts |
Fixes stripBasePath boundary handling and removes VERCEL_URL origin behavior. |
src/lib/mock-path.test.ts |
Adds comprehensive unit tests for mock-path utilities and updated origin behavior. |
src/lib/endpoint-data-store.test.ts |
Adds unit tests for platform-aware data-dir resolution and real filesystem read/write/delete flows. |
package.json |
Adds test scripts (test, test:unit, test:integration, etc.) and Vitest dependency. |
pnpm-lock.yaml |
Locks new dev dependencies (Vitest and related transitive packages). |
.husky/pre-commit |
Runs check + typecheck + unit tests pre-commit with clearer failure output. |
.github/workflows/ci.yaml |
Modernizes CI actions (checkout/setup-node/pnpm) and adds pnpm test step. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+16
to
+18
| function createCtx() { | ||
| const sqlite = new Database(":memory:"); | ||
| const db = drizzle(sqlite, { schema }); |
Comment on lines
+57
to
+70
| describe("endpoint-data-store (file operations)", () => { | ||
| let tempDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| // Isolate real fs operations into a temp dir via XDG_DATA_HOME (linux path used in CI) | ||
| tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "voidend-test-")); | ||
| Object.defineProperty(process, "platform", { value: "linux" }); | ||
| process.env.XDG_DATA_HOME = tempDir; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tempDir, { recursive: true, force: true }); | ||
| vi.restoreAllMocks(); | ||
| }); |
Comment on lines
+63
to
+76
| /** Sets XDG_DATA_HOME to an isolated tmp dir so endpoint-data-store hits real fs, not the dev machine's real data. */ | ||
| export function setupIsolatedDataDir() { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), "voidend-test-")); | ||
| const original = process.env.XDG_DATA_HOME; | ||
| process.env.XDG_DATA_HOME = dir; | ||
| return { | ||
| dir, | ||
| cleanup: () => { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| if (original === undefined) delete process.env.XDG_DATA_HOME; | ||
| else process.env.XDG_DATA_HOME = original; | ||
| }, | ||
| }; | ||
| } |
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
Sets up Vitest across the backend and adds test coverage before building the
two remaining features (export/import, authenticated routes). Backend logic
had no tests until now — this establishes a safety net first.
What's included
schema-resolver.ts(resolveSchema,resolveResponseData)endpoint-data-store.ts(data dir resolution,file read/write/delete against real fs)
project,folder,endpoint) againstan in-memory SQLite db, with
endpoint-data-storemockedtests/integration/) exercising routers against realfs + real db together:
→ full cleanup on disk)
nested folder trees)
endpoint.resolvebasePath stripping, including a test documenting aknown bug (see below)
test:unitonly; CI (pnpm test) still runsthe full suite including integration tests
Bugs found and fixed
mock-path.ts—stripBasePath: naivestartsWithcheck strippedprefixes without enforcing a segment boundary (e.g. basePath
/apiwouldincorrectly strip from
/apiary/foo). Fixed and covered by tests.getMockOrigin: removed a misalignedVERCEL_URLbranch thatcontradicted the project's local-only design.