-
Notifications
You must be signed in to change notification settings - Fork 1
local testing #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
local testing #16
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c14fff3
add tests for unit and other tests packages as well
Anmol1696 dfe2520
fix template
Anmol1696 e07599f
Merge branch 'main' into feat/tests
Anmol1696 7c32225
update function registry plan
Anmol1696 e85a348
update docker-compose for local testing of functions
Anmol1696 a875439
add development doc
Anmol1696 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| workflow_dispatch: {} | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| unit: | ||
| name: Unit tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| - run: npm install -g pnpm@10.12.2 | ||
| - run: node --experimental-strip-types scripts/generate.ts | ||
| - run: pnpm install | ||
| - run: pnpm test:unit | ||
|
|
||
| integration: | ||
| name: Integration tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '22' | ||
| - run: npm install -g pnpm@10.12.2 | ||
| - run: node --experimental-strip-types scripts/generate.ts | ||
| - run: pnpm install | ||
| - run: pnpm build | ||
| - run: pnpm test:integration | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| # Development Guide | ||
|
|
||
| Local development setup for running functions against real infrastructure (Postgres, GraphQL, Mailpit). | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js >= 18.17.0 | ||
| - pnpm >= 10 | ||
| - Docker Desktop | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```bash | ||
| # 1. Generate workspace packages from function templates | ||
| pnpm generate | ||
|
|
||
| # 2. Install dependencies | ||
| pnpm install | ||
|
|
||
| # 3. Build everything (packages, job service, generated functions) | ||
| pnpm build | ||
|
|
||
| # 4. Start infrastructure (Postgres, DB migrations, GraphQL server, Mailpit) | ||
| make dev | ||
|
|
||
| # 5. Wait for db-setup to finish (watch logs) | ||
| make dev-logs | ||
|
|
||
| # 6. Start functions as local Node processes | ||
| make dev-fn | ||
| ``` | ||
|
|
||
| ## Step-by-Step | ||
|
|
||
| ### 1. Generate + Build | ||
|
|
||
| The generate step reads `functions/*/handler.json` manifests, resolves templates from `templates/node-graphql/`, and produces full workspace packages in `generated/`. | ||
|
|
||
| ```bash | ||
| pnpm generate # Generate all functions | ||
| pnpm install # Install dependencies (including generated packages) | ||
| pnpm build # Build all workspace packages | ||
| ``` | ||
|
|
||
| After this you should have built artifacts in: | ||
|
|
||
| | Package | Output | | ||
| |---------|--------| | ||
| | `generated/send-email-link/dist/` | Send-email-link function server | | ||
| | `generated/simple-email/dist/` | Simple-email function server | | ||
| | `generated/example/dist/` | Example function server | | ||
| | `job/service/dist/` | Knative job service (worker + scheduler) | | ||
| | `packages/fn-runtime/dist/` | Function runtime library | | ||
| | `packages/fn-app/dist/` | Function app framework | | ||
|
|
||
| ### 2. Start Infrastructure | ||
|
|
||
| ```bash | ||
| make dev | ||
| ``` | ||
|
|
||
| This runs `docker compose up -d` which starts: | ||
|
|
||
| | Service | Description | Port | | ||
| |---------|-------------|------| | ||
| | **postgres** | PostgreSQL 16 with pgvector + PostGIS | 5432 | | ||
| | **db-setup** | One-shot: creates DB, bootstraps roles, deploys pgpm packages | (exits on completion) | | ||
| | **graphql-server** | Constructive admin GraphQL API (header-based routing) | 3002 | | ||
| | **mailpit** | SMTP capture server with web UI | 1025 (SMTP), 8025 (UI) | | ||
|
|
||
| The `db-setup` container must finish before `graphql-server` starts (enforced by `service_completed_successfully`). Watch progress: | ||
|
|
||
| ```bash | ||
| make dev-logs | ||
| # or | ||
| docker compose logs -f db-setup | ||
| ``` | ||
|
|
||
| Verify everything is running: | ||
|
|
||
| ```bash | ||
| docker compose ps | ||
| ``` | ||
|
|
||
| You should see: | ||
| - `postgres` — running (healthy) | ||
| - `db-setup` — exited (0) | ||
| - `graphql-server` — running | ||
| - `mailpit` — running | ||
|
|
||
| ### 3. Start Functions Locally | ||
|
|
||
| ```bash | ||
| make dev-fn | ||
| ``` | ||
|
|
||
| This runs `scripts/dev.ts` which spawns local Node processes with env vars pointing to Docker services: | ||
|
|
||
| | Process | Port | Script | | ||
| |---------|------|--------| | ||
| | **job-service** | 8080 | `job/service/dist/run.js` | | ||
| | **simple-email** | 8081 | `generated/simple-email/dist/index.js` | | ||
| | **send-email-link** | 8082 | `generated/send-email-link/dist/index.js` | | ||
|
|
||
| To start a single function: | ||
|
|
||
| ```bash | ||
| pnpm dev:fn -- --only=send-email-link | ||
| ``` | ||
|
|
||
| ### 4. Test a Function | ||
|
|
||
| Send a request to `send-email-link`: | ||
|
|
||
| ```bash | ||
| curl -X POST http://localhost:8082 \ | ||
| -H 'Content-Type: application/json' \ | ||
| -H 'X-Database-Id: constructive' \ | ||
| -d '{"email_type":"invite_email","email":"test@example.com"}' | ||
| ``` | ||
|
|
||
| Check captured emails at http://localhost:8025 (Mailpit UI). | ||
|
|
||
| Query the GraphQL API directly: | ||
|
|
||
| ```bash | ||
| curl http://localhost:3002/graphql \ | ||
| -H 'Content-Type: application/json' \ | ||
| -H 'X-Database-Id: constructive' \ | ||
| -d '{"query":"{ __typename }"}' | ||
| ``` | ||
|
|
||
| ### 5. Shut Down | ||
|
|
||
| ```bash | ||
| make dev-down # Stop Docker infrastructure | ||
| ``` | ||
|
|
||
| `Ctrl+C` in the `make dev-fn` terminal stops the local function processes. | ||
|
|
||
| ## Commands Reference | ||
|
|
||
| | Command | Description | | ||
| |---------|-------------| | ||
| | `pnpm generate` | Generate workspace packages from function templates | | ||
| | `pnpm build` | Build all workspace packages | | ||
| | `make dev` | Start Docker infrastructure | | ||
| | `make dev-fn` | Start functions as local Node processes | | ||
| | `make dev-down` | Stop Docker infrastructure | | ||
| | `make dev-logs` | Follow Docker service logs | | ||
| | `pnpm test` | Run all tests | | ||
| | `pnpm test:unit` | Run unit tests only (`functions/*/__tests__/`) | | ||
| | `pnpm test:integration` | Run integration tests only (`tests/integration/`) | | ||
|
|
||
| ## Port Map | ||
|
|
||
| | Service | Port | | ||
| |---------|------| | ||
| | PostgreSQL | 5432 | | ||
| | GraphQL API | 3002 | | ||
| | Mailpit SMTP | 1025 | | ||
| | Mailpit UI | 8025 | | ||
| | Job Service | 8080 | | ||
| | simple-email | 8081 | | ||
| | send-email-link | 8082 | | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| Docker Compose (infrastructure): | ||
| postgres -> db-setup (migrations) -> graphql-server | ||
| mailpit | ||
|
|
||
| Local Node processes (functions): | ||
| job/service/dist/run.js (port 8080) | ||
| generated/simple-email/dist/index.js (port 8081) | ||
| generated/send-email-link/dist/index.js (port 8082) | ||
| ``` | ||
|
|
||
| Infrastructure runs in Docker. Functions run as local Node processes from `generated/` — no Docker rebuild needed when function code changes. Edit `functions/*/handler.ts`, rebuild (`pnpm build`), restart `make dev-fn`. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **db-setup fails or graphql-server won't start** | ||
|
|
||
| Check if the GHCR image is accessible: | ||
|
|
||
| ```bash | ||
| docker pull ghcr.io/constructive-io/constructive:latest | ||
| ``` | ||
|
|
||
| If authentication is required, log in first: | ||
|
|
||
| ```bash | ||
| echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin | ||
| ``` | ||
|
|
||
| **Port already in use** | ||
|
|
||
| Stop any existing services using the ports: | ||
|
|
||
| ```bash | ||
| make dev-down | ||
| lsof -ti:5432,3002,1025,8025,8080,8081,8082 | xargs kill -9 | ||
| ``` | ||
|
|
||
| **Functions can't connect to GraphQL** | ||
|
|
||
| Ensure infrastructure is fully up before starting functions: | ||
|
|
||
| ```bash | ||
| docker compose ps # db-setup should show "Exited (0)", graphql-server should be "running" | ||
| curl http://localhost:3002/graphql -H 'Content-Type: application/json' -d '{"query":"{ __typename }"}' | ||
| ``` | ||
|
|
||
| **Stale build artifacts** | ||
|
|
||
| Clean and rebuild from scratch: | ||
|
|
||
| ```bash | ||
| pnpm clean | ||
| pnpm generate | ||
| pnpm install | ||
| pnpm build | ||
| ``` |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integration test job builds everything ('pnpm build') but doesn't start the required infrastructure services (postgres, graphql-server, mailpit) that are defined in docker-compose.yml. Integration tests that depend on these services will fail. Consider adding docker-compose setup steps or documenting that integration tests only cover HTTP layer testing without external dependencies.