Skip to content

test(backend): establish test suite + fix bugs found along the way - #20

Merged
Gr1shma merged 8 commits into
mainfrom
test/backend
Jul 25, 2026
Merged

Gr1shma merged 8 commits into
mainfrom
test/backend

Conversation

@Gr1shma

@Gr1shma Gr1shma commented Jul 25, 2026

Copy link
Copy Markdown
Owner

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

  • Vitest configured with native tsconfig path resolution
  • Unit tests for schema-resolver.ts (resolveSchema, resolveResponseData)
  • Unit + integration tests for endpoint-data-store.ts (data dir resolution,
    file read/write/delete against real fs)
  • Unit tests for all tRPC routers (project, folder, endpoint) against
    an in-memory SQLite db, with endpoint-data-store mocked
  • Integration tests (tests/integration/) exercising routers against real
    fs + real db together:
    • project lifecycle (create → data file generation/regeneration → delete
      → full cleanup on disk)
    • folder cascade delete (db FK cascade + on-disk file cleanup across
      nested folder trees)
    • endpoint.resolve basePath stripping, including a test documenting a
      known bug (see below)
  • Husky pre-commit now runs test:unit only; CI (pnpm test) still runs
    the full suite including integration tests

Bugs found and fixed

  • mock-path.ts — stripBasePath: naive startsWith check stripped
    prefixes without enforcing a segment boundary (e.g. basePath /api would
    incorrectly strip from /apiary/foo). Fixed and covered by tests.
  • getMockOrigin: removed a misaligned VERCEL_URL branch that
    contradicted the project's local-only design.

Gr1shma added 7 commits July 25, 2026 10:01
- 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stripBasePath to enforce a segment boundary (and remove a VERCEL_URL origin 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 thread tests/integration/test-context.ts Outdated
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;
},
};
}
@Gr1shma
Gr1shma merged commit 648c76f into main Jul 25, 2026
2 checks passed
@Gr1shma
Gr1shma deleted the test/backend branch July 25, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants