Skip to content

Development

Chuck edited this page Nov 15, 2026 · 5 revisions

How to work on Glint's code: local setup, tests, conventions and the contribution workflow. The short version is in CONTRIBUTING.md.


Local setup

Requires Node.js 22+, and gitleaks for the pre-commit hook.

git clone https://github.com/smith8ca/Glint.git
cd Glint

cd webhook-receiver && npm install
cd ../e2e-test && npm install
cd ..

cp webhook-receiver/.env.example webhook-receiver/.env   # then edit it
git config core.hooksPath .githooks                      # enable the secret-scan hook

Run the receiver

cd webhook-receiver
npm run dev      # ts-node, straight from src/ (no file watching: restart after edits)
npm run build    # compile to dist/ (tsconfig.build.json: tests excluded)
npm start        # run dist/index.js

Logs are JSON lines. For readable output while developing, pipe them through pino-pretty: npm run dev | npx pino-pretty.

To try it without GitLab, send a request by hand:

curl -i http://localhost:3000/webhook \
  -H 'Content-Type: application/json' \
  -H 'X-Gitlab-Event: Merge Request Hook' \
  -H "X-Gitlab-Token: $WEBHOOK_SECRET" \
  -d '{"object_kind":"merge_request","project":{"id":1},"object_attributes":{"iid":1,"action":"update"}}'
# HTTP/1.1 200 OK … {"message":"Ignored: action 'update'"}

Unit tests

cd webhook-receiver
npm test                # Vitest, run once
npm run test:coverage   # with V8 coverage; LCOV in coverage/
npm run typecheck       # tsc --noEmit over source and tests

The suite (100+ tests, about 99% line coverage) covers config loading, both authentication modes, payload validation, routing, the GitLab, Claude and OpenAI-compatible clients (mocked), private-CA trust and error formatting. It needs no network access and no credentials. CI runs it on every pull request.

Tests live in webhook-receiver/src/__tests__/, mirroring the src/ layout. The build skips them (they never reach dist/ or the image), so npm run typecheck is what type-checks them; CI runs it before the build. src/__tests__/setup.ts silences the logger during tests, and tests that assert on logging mock the logger module (see routes/webhook.test.ts).


End-to-end test

cd e2e-test
npm test

This builds both packages, starts a mock GitLab API on port 4000, spawns the real receiver on port 3001 pointed at it, sends the fixture Merge Request Hook, and waits up to 60 seconds for a note to be posted. It prints the note and exits 0 on success.

  • It calls the real AI provider: by default the Anthropic API (a few cents per run).
  • It reads webhook-receiver/.env and needs ANTHROPIC_API_KEY, WEBHOOK_SECRET and a non-empty GITLAB_TOKEN there (the mock accepts any value).
  • To test the OpenAI-compatible provider, set its variables in .env or the shell; no Anthropic key is needed then. For a local Ollama: AI_PROVIDER=openai-compatible OPENAI_BASE_URL=http://localhost:11434/v1 OPENAI_MODEL=llama3.2 NOTE_TIMEOUT_MS=240000 npm test.
  • It authenticates with X-Gitlab-Token, so comment out WEBHOOK_SIGNING_TOKEN while running it, or every request is rejected with 401.
  • Ports and timeout can be changed with MOCK_GITLAB_PORT, RECEIVER_PORT and NOTE_TIMEOUT_MS.
  • Only the MR flow is covered end to end; release notes are covered by unit tests.

CI only type-checks the harness, because it needs an API key.


Conventions

  • TypeScript strict mode stays on. No any without a good reason.
  • Never pass override: true to dotenv. The e2e harness and container platforms set variables in the process environment; .env must not overwrite them.
  • Never log raw HTTP client errors. Use describeError() from utils/errors.ts, which strips the PRIVATE-TOKEN header.
  • Background work catches its own errors. After the 202 there is no response left to fail; log and move on.
  • Keep dependencies minimal and explain any new one in the PR.
  • Files use CRLF line endings, except .githooks/* (LF, enforced by .gitattributes).
  • No linter is configured yet; match the surrounding style.

Adding a webhook event

  1. In routes/webhook.ts, add a branch on the X-Gitlab-Event value and a payload interface for the fields you need.
  2. Validate every payload field you use before calling GitLab.
  3. Respond 202 before the slow work; run the work in an async function with a .catch that logs describeError(err).
  4. Add GitLab calls to services/gitlab.ts, the prompt to services/prompts.ts, and a method to the AiClient interface in services/ai.ts, implemented in both claude.ts and openaiCompatible.ts.
  5. Write unit tests alongside the existing ones, and a mock route and fixture in e2e-test/ if it should be covered end to end.
  6. Document it on API Reference and in the README.

Branches and pull requests

Branch Purpose
main Released code only. Every merge cuts a release.
dev Integration branch. All pull requests target dev.
feature/…, fix/…, chore/… Work branches, created from dev
  1. Branch from an up-to-date dev.
  2. Commit in focused steps with Conventional Commit-style messages (feat:, fix:, ci:, docs:, chore:). Glint's own release notes rely on these prefixes.
  3. Add a line under [Unreleased] in CHANGELOG.md for user-visible changes.
  4. Open a pull request into dev. CI must pass: Secret scan, Build and test, Typecheck e2e harness, Docker build.

Releases are covered in CI/CD and Releases.


Where to change what

To change… Edit
Webhook authentication webhook-receiver/src/middleware/validateSecret.ts
Event routing, validation, comment wrapper webhook-receiver/src/routes/webhook.ts
Prompts and truncation webhook-receiver/src/services/prompts.ts
Provider selection, request parameters webhook-receiver/src/services/ai.ts, claude.ts, openaiCompatible.ts
GitLab API calls, TLS trust webhook-receiver/src/services/gitlab.ts
Environment variables webhook-receiver/src/config.ts (and .env.example, README, Configuration)
End-to-end orchestration e2e-test/src/index.ts, e2e-test/src/mockGitlab.ts

Clone this wiki locally