Files
finance-app/AGENTS.md
T
siddharthd b958d05287
ci / lint-test (push) Successful in 1m5s
test(db): resolve the integration DSN at run time instead of storing an IP (#161)
setup-test-db.sh wrote .env.test once with the Postgres container's bridge IP
baked in, and Docker reassigns those on recreation. The file rotted silently:
its stored 172.22.0.18 belongs to **gitea** as of today, and an earlier drift
had the suite pointing its TRUNCATE at **postgres-pantry** — which it would
have wiped had the credentials happened to match.

Root-cause fix: stop persisting a host at all.

- scripts/resolve-test-db.sh re-derives the DSN from the live container and
  rewrites .env.test. Resolution order is TEST_DATABASE_URL, then the
  container's published host port, then the bridge IP. `docker port
  postgres-personal` reports 127.0.0.1:5432 since the 2026-08-17 PG17
  migration, so loopback is what gets used here — and a loopback address
  cannot be reassigned to another container, which is the whole point.
  (Note this supersedes the smarthome CLAUDE.md's "postgres-personal publishes
  no host port"; that is now stale.) The bridge-IP fallback is kept for a host
  where the port is not published, and the script never prints the password.
- Wired as `pretest:integration`, so npm runs it before every integration run.
  .env.test becomes a generated artifact rather than stored configuration.
- setup-test-db.sh now only creates the database and copies the schema, then
  delegates to the resolver.
- helpers.ts::assertTestDatabase stays and its message now points at the
  resolver rather than at `docker inspect`. It still earns its place: running
  vitest directly bypasses the pretest hook, and a stale .env.test would then
  still be read.

Docs: CLAUDE.md gains a Testing section carrying this, the prisma-generate
trap for a fresh checkout or worktree, and the frozen-clock rule for tests
whose subject is defined relative to "now". AGENTS.md updated for the same, and
for lint now being blocking.
2026-08-21 00:52:54 +10:00

3.5 KiB

Repository Guidelines

Project Structure & Module Organization

Application code lives in src/. Next.js App Router pages and API route handlers belong in src/app/; reusable UI components are in src/components/; database access, query functions, hooks, authentication, and domain helpers are in src/lib/. Tests are separated into src/__tests__/unit/ and src/__tests__/integration/. PostgreSQL schema and numbered SQL migrations live under prisma/, static assets under public/, operational scripts under scripts/, and design notes under docs/.

Keep data flow consistent: API routes call query functions in src/lib/queries.ts, which use queryRaw() from src/lib/db.ts; client components access APIs through TanStack Query hooks in src/lib/hooks.ts.

Task tracking is the Vikunja board at https://tasks.bosecamp.com (project Work, saved filter finance-app), which replaced the smarthome repo's ACTIONS.md on 2026-07-30. Update the ticket in the same change as the code. See CLAUDE.md → "Work tracking".

Build, Test, and Development Commands

  • npm ci installs the locked dependency set (Node 22 is used in CI).
  • npm run dev starts the local Next.js development server.
  • npm run build creates a production build; npm start serves it.
  • npm run lint runs the Next.js ESLint configuration. Blocking in CI since #79 — the pre-existing debt is cleared, so it must stay at zero errors (warnings are still allowed).
  • npx tsc --noEmit typechecks, including the test files. Also blocking in CI.
  • npm test runs fast unit tests.
  • npm run test:setup creates/refreshes the personal_test database (run it once, and after any migration).
  • npm run test:integration runs database-backed tests. It re-resolves the DSN from the live container first (scripts/resolve-test-db.sh), so .env.test must never carry a hand-written host — see CLAUDE.md → Testing.
  • npm run test:all runs both test suites.

Coding Style & Naming Conventions

Use strict TypeScript, two-space indentation, semicolons, and double quotes, matching existing files. Name React components and types in PascalCase, functions and variables in camelCase, and files/routes in kebab-case. Use the @/ alias for imports from src/. Preserve owner scoping and prefer transaction overrides with COALESCE in financial queries. Every API route must authenticate before accessing data.

Testing Guidelines

Vitest is the test framework. Name tests *.test.ts and place pure logic tests under unit/; put PostgreSQL-dependent behavior under integration/. Add regression coverage for query, rule, reconciliation, and category changes. No numeric coverage threshold is configured; focus on meaningful edge cases and run npm run test:all before submitting database-related changes.

Database, Security & Configuration

Add schema changes as the next numbered prisma/migrations/NNNN_description/migration.sql. Never commit .env, .env.test, raw statements in dump/, or other financial data. Consult CLAUDE.md and relevant docs/ notes before changing splits, settlements, loans, reconciliation, or statement accounting.

Commits & Pull Requests

History follows concise Conventional Commit-style subjects such as feat(rules): preview rule changes, fix(trips): ..., and docs: .... Keep commits focused. Pull requests should explain behavior and data-model impact, link related issues, list validation commands, and include screenshots for UI changes. Ensure lint, typecheck, unit tests and the production build pass; call out any migration steps.