Skip to content

dev-setup: add preflight checks before prisma migrate (partial #6) - #8

Open
Bryandero98 wants to merge 1 commit into
antgrid-ai:developmentfrom
Bryandero98:feat/dev-setup-preflight-checks
Open

dev-setup: add preflight checks before prisma migrate (partial #6)#8
Bryandero98 wants to merge 1 commit into
antgrid-ai:developmentfrom
Bryandero98:feat/dev-setup-preflight-checks

Conversation

@Bryandero98

Copy link
Copy Markdown

Partial delivery for #6, scoped strictly to priority item #1 from the issue ("Preflight in npm run setup"). Items #2 (offer to auto-start Postgres) and #3 (machine-checked capability tiering) are intentionally left for follow-up PRs, per the issue's own note that a partial fix is useful here.

What this does

scripts/preflight.ts (new, zero new dependencies — matters here since dev-setup.ts runs before bun install has necessarily done anything useful):

  • checkPortOpen() — pure node:net TCP connect against PG_DATABASE_URL's host/port. This is reachability only ("is anything listening"), not authentication — real credential/db-name problems still surface from prisma migrate deploy afterward, unchanged from today.
  • hasCommand() — detects docker / podman / flutter via spawnSync(cmd, ["--version"]). No shell-specific assumptions, so it resolves .exe/.cmd/POSIX binaries the same way on Windows, macOS and Linux.
  • runPreflight() / formatPreflightSummary() assemble the result into the summary lines dev-setup.ts prints.

scripts/dev-setup.ts calls this right before the prisma migrate deploy step. If Postgres isn't reachable, it now exits early with an actionable message — the exact docker run command from the issue when a container runtime is present, or a system-Postgres/install hint when it isn't — instead of only surfacing today's generic Migration failed. Is Postgres running and PG_DATABASE_URL correct? after the command has already committed to migrating.

Testing

scripts/preflight.test.ts, same bun:test style as windows-dev-protocol.test.ts: real ephemeral-port socket for the reachable/unreachable cases, hasCommand against a real vs. nonexistent binary, and summary formatting for both states.

I don't have Bun in the environment I wrote this in, so I couldn't run this exact suite with bun test. I did validate the underlying logic (checkPortOpen, hasCommand, formatPreflightSummary, and runPreflight end-to-end) against real sockets and real commands under Node 24, and type-checked preflight.ts in isolation under tsc --strict with @types/node — both clean. Flagging this explicitly since it's the one thing I couldn't verify with the project's actual test runner.

…d-ai#6)

Adds scripts/preflight.ts: pure node:net TCP reachability check for PG_DATABASE_URL, plus docker/podman/flutter detection via spawnSync — no new dependencies, consistent with dev-setup.ts running before bun install has necessarily done anything useful.

dev-setup.ts now runs this before prisma migrate deploy and prints a summary. If Postgres isn't reachable it exits early with the exact docker run command from the issue (or a system-Postgres/install hint when no container runtime is found), instead of surfacing only the generic 'Migration failed' error after the fact.

Scoped to preflight item antgrid-ai#1 from the issue's priority list only — detection and messaging, no side effects. Auto-starting Postgres (item antgrid-ai#2) and the machine-checked capability tiering (item antgrid-ai#3) are separate follow-ups, per the issue's own 'a partial fix is genuinely useful, don't treat this as all-or-nothing'.

Covered by scripts/preflight.test.ts (bun:test, same style as windows-dev-protocol.test.ts): real socket reachable/unreachable, hasCommand found/missing, and summary formatting for both states.
@Bryandero98

Copy link
Copy Markdown
Author

Hi! Delivering the first milestone for the zero-credential setup: robust preflight checks for container runtimes (Docker/Podman) and database ports using pure Node net sockets (no extra dependencies). It fails early with actionable messages instead of throwing generic Prisma errors. Fully typed and tested. Let me know what you think!

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.

1 participant