server: POST /api/build-complete — HMAC callback flips ready/failed, re-renders, emails (phase-3 plan Task 8) #75

Closed
opened 2026-08-31 05:20:33 +00:00 by ben · 3 comments
Owner

Plan

docs/superpowers/plans/2026-08-31-coa-phase-3.md Task 8.

Deliverable

server/src/webhook-signature.ts (signBody, verifySignature — sha256=<hex>, timingSafeEqual); server/src/routes/build-complete.ts mounted at /api/build-complete: no secret → 503 webhook-unconfigured; bad/missing signature → 401 signature; invalid body → 400 validation; unknown slug → 404 unknown-slug; stale build → 200 {ignored:'stale', build, current}; success → ready + assets/releaseUrl/buildRunUrl, re-render + writeHtml, publish, installers-ready email; failure → failed + buildRunUrl/error, re-render, publish, build-failed email to contact and notifyEmail; email/publish failures recorded, still 200. Tests webhook-signature.test.ts, build-complete.test.ts (plan text).

Acceptance

  • Plan tests pass verbatim; the raw body (not re-serialised JSON) is what is signed.
  • pnpm -r typecheck && pnpm -r test green.

depends_on

  • startBuild (Task 7), templates ready/failed (Task 5)

Phase gate

Feature toggles / nav order in builds are phase 4. Never delete or rewrite anything under communities/ (ADR 0002/0003); phase 3 rewrites only kit.json, status.json, index.html. No test reaches the real network, sends real mail, dispatches a real build or provisions a real tenant.

## Plan `docs/superpowers/plans/2026-08-31-coa-phase-3.md` **Task 8**. ## Deliverable `server/src/webhook-signature.ts` (`signBody`, `verifySignature` — `sha256=<hex>`, `timingSafeEqual`); `server/src/routes/build-complete.ts` mounted at `/api/build-complete`: no secret → 503 `webhook-unconfigured`; bad/missing signature → 401 `signature`; invalid body → 400 `validation`; unknown slug → 404 `unknown-slug`; stale build → 200 `{ignored:'stale', build, current}`; success → `ready` + assets/releaseUrl/buildRunUrl, re-render + `writeHtml`, publish, installers-ready email; failure → `failed` + buildRunUrl/error, re-render, publish, build-failed email to contact **and** `notifyEmail`; email/publish failures recorded, still 200. Tests `webhook-signature.test.ts`, `build-complete.test.ts` (plan text). ## Acceptance - Plan tests pass verbatim; the raw body (not re-serialised JSON) is what is signed. - `pnpm -r typecheck && pnpm -r test` green. ## depends_on - startBuild (Task 7), templates ready/failed (Task 5) ## Phase gate Feature toggles / nav order in builds are phase 4. Never delete or rewrite anything under `communities/` (ADR 0002/0003); phase 3 rewrites only `kit.json`, `status.json`, `index.html`. No test reaches the real network, sends real mail, dispatches a real build or provisions a real tenant.

This was generated by AI during triage.

Ruled by agent under ADR 0174 (two-way-door doctrine) — veto anytime

Ruling: ready-for-agent. POST /api/build-complete HMAC callback flips ready/failed, re-renders, emails.

Why this is a two-way door: it is revertible by a later commit or label change, and provable by the tests the plan specifies — which never reach the real network, send real mail, dispatch a real build or provision a real tenant. It is not on the one-way-door list: the credential bytes, real GitHub dispatch/release and live coa-shared tenant are already carved out into the human ticket #79 and the session tickets #80/#81; env-gated defaults keep the wired code inert (noop/static, 503/unconfigured) until those land.

What proves it: webhook-signature.test.ts + build-complete.test.ts (raw-body HMAC, stubbed mailer/publisher); pnpm -r test green.

The ticket body is a complete agent brief (Deliverable / Acceptance / depends_on). The native Forgejo dependency links already mirror the plan's graph, so the swarm ready-list filter holds this ticket until its blockers close.

> *This was generated by AI during triage.* ## Ruled by agent under ADR 0174 (two-way-door doctrine) — veto anytime **Ruling:** `ready-for-agent`. POST /api/build-complete HMAC callback flips ready/failed, re-renders, emails. **Why this is a two-way door:** it is revertible by a later commit or label change, and provable by the tests the plan specifies — which never reach the real network, send real mail, dispatch a real build or provision a real tenant. It is not on the one-way-door list: the credential bytes, real GitHub dispatch/release and live coa-shared tenant are already carved out into the human ticket #79 and the session tickets #80/#81; env-gated defaults keep the wired code inert (noop/static, 503/unconfigured) until those land. **What proves it:** `webhook-signature.test.ts` + `build-complete.test.ts` (raw-body HMAC, stubbed mailer/publisher); `pnpm -r test` green. The ticket body is a complete agent brief (Deliverable / Acceptance / depends_on). The native Forgejo dependency links already mirror the plan's graph, so the swarm ready-list filter holds this ticket until its blockers close.

swarm-claim host=matou-dev-server-01 run=1464
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=1464 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #75 — status success

✅ close-report gates passed — every claim verified against main; PR #106 (#106) was already merged (a reconcile pass landed it before this close-report ran) and the merge closed this issue via closes #75.

envelope
{
  "issue": 75,
  "status": "success",
  "commits": [
    "79f980086dff94f09c6f17e7718ee35f78411c2b"
  ],
  "changed_files": [
    "server/src/webhook-signature.ts",
    "server/src/routes/build-complete.ts",
    "server/src/app.ts",
    "server/test/webhook-signature.test.ts",
    "server/test/build-complete.test.ts",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "pnpm -r typecheck",
      "exit_code": 0
    },
    {
      "command": "pnpm -r test",
      "exit_code": 0
    }
  ],
  "criteria": {
    "webhook-signature.ts signBody/verifySignature (sha256=<hex>, timingSafeEqual)": "server/src/webhook-signature.ts — createHmac sha256 hex with PREFIX 'sha256='; verifySignature uses Buffer.from(hex) + timingSafeEqual, false on prefix/length mismatch or missing header; proven by server/test/webhook-signature.test.ts (2 tests)",
    "route mounted at /api/build-complete": "server/src/app.ts app.route('/api/build-complete', buildComplete(deps)); route in server/src/routes/build-complete.ts",
    "no secret -> 503 webhook-unconfigured": "build-complete.ts: `if (!deps.webhookSecret) return c.json({error:'webhook-unconfigured'},503)`; test '503s when no secret is configured'",
    "bad/missing signature -> 401 signature": "build-complete.ts verifySignature guard -> 401 {error:'signature'}; test '401s on a bad or missing signature and changes nothing'",
    "invalid body -> 400 validation": "BuildCompleteSchema.safeParse failure -> 400 {error:'validation',issues} (dotted paths); test '400s on a malformed body'",
    "unknown slug -> 404 unknown-slug": "store.read undefined -> 404 {error:'unknown-slug',slug}; test '404s on an unknown slug'",
    "stale build -> 200 {ignored:'stale',build,current}": "community.status.build !== body.build -> c.json({ignored:'stale',build,current}); test 'ignores a stale build number' expects {ignored:'stale',build:7,current:1}",
    "success -> ready + assets/releaseUrl/buildRunUrl, re-render+writeHtml, publish, installers-ready email": "build-complete.ts success branch: patchStatus state ready + assets/releaseUrl/buildRunUrl, deps.render + writeHtml, publisher.publish, mailer.sendInstallersReady; test 'success -> ready, page re-rendered with links, published, emailed'",
    "failure -> failed + buildRunUrl/error, re-render, publish, build-failed email to contact AND notifyEmail": "build-complete.ts failure branch: patchStatus state failed + buildRunUrl/error, render+writeHtml, publish, sendBuildFailed to contactEmail and deps.notifyEmail; test 'failure -> failed, page stays pending, both emails'",
    "email/publish failures recorded, still 200": "try/catch patches emailError; publishError patched from publish result; both return 200; test 'records an email failure and still answers 200'",
    "raw body (not re-serialised) is what is signed": "route calls c.req.text() and verifies/parses that same raw string; test signs JSON.stringify(body) and route validates over the raw bytes",
    "pnpm -r typecheck && pnpm -r test green": "both ran exit 0; server suite 14 files / 69 tests pass incl. webhook-signature.test.ts and build-complete.test.ts"
  },
  "summary": "Added POST /api/build-complete HMAC callback (raw-body sha256 verify) that flips ready/failed, re-renders + writeHtml, publishes and emails, with all plan Task 8 tests passing.",
  "reason": "Implements phase-3 plan Task 8 verbatim against the merged Task 1-7 interfaces; publisher test stub carries publishStatus to satisfy the already-merged GitPublisher interface.",
  "blockers": []
}
**close-report** for #75 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; PR #106 (https://git.matou.nz/Matou/coa/pulls/106) was already merged (a reconcile pass landed it before this close-report ran) and the merge closed this issue via `closes #75`. <details><summary>envelope</summary> ```json { "issue": 75, "status": "success", "commits": [ "79f980086dff94f09c6f17e7718ee35f78411c2b" ], "changed_files": [ "server/src/webhook-signature.ts", "server/src/routes/build-complete.ts", "server/src/app.ts", "server/test/webhook-signature.test.ts", "server/test/build-complete.test.ts", "STATUS.md" ], "tests": [ { "command": "pnpm -r typecheck", "exit_code": 0 }, { "command": "pnpm -r test", "exit_code": 0 } ], "criteria": { "webhook-signature.ts signBody/verifySignature (sha256=<hex>, timingSafeEqual)": "server/src/webhook-signature.ts — createHmac sha256 hex with PREFIX 'sha256='; verifySignature uses Buffer.from(hex) + timingSafeEqual, false on prefix/length mismatch or missing header; proven by server/test/webhook-signature.test.ts (2 tests)", "route mounted at /api/build-complete": "server/src/app.ts app.route('/api/build-complete', buildComplete(deps)); route in server/src/routes/build-complete.ts", "no secret -> 503 webhook-unconfigured": "build-complete.ts: `if (!deps.webhookSecret) return c.json({error:'webhook-unconfigured'},503)`; test '503s when no secret is configured'", "bad/missing signature -> 401 signature": "build-complete.ts verifySignature guard -> 401 {error:'signature'}; test '401s on a bad or missing signature and changes nothing'", "invalid body -> 400 validation": "BuildCompleteSchema.safeParse failure -> 400 {error:'validation',issues} (dotted paths); test '400s on a malformed body'", "unknown slug -> 404 unknown-slug": "store.read undefined -> 404 {error:'unknown-slug',slug}; test '404s on an unknown slug'", "stale build -> 200 {ignored:'stale',build,current}": "community.status.build !== body.build -> c.json({ignored:'stale',build,current}); test 'ignores a stale build number' expects {ignored:'stale',build:7,current:1}", "success -> ready + assets/releaseUrl/buildRunUrl, re-render+writeHtml, publish, installers-ready email": "build-complete.ts success branch: patchStatus state ready + assets/releaseUrl/buildRunUrl, deps.render + writeHtml, publisher.publish, mailer.sendInstallersReady; test 'success -> ready, page re-rendered with links, published, emailed'", "failure -> failed + buildRunUrl/error, re-render, publish, build-failed email to contact AND notifyEmail": "build-complete.ts failure branch: patchStatus state failed + buildRunUrl/error, render+writeHtml, publish, sendBuildFailed to contactEmail and deps.notifyEmail; test 'failure -> failed, page stays pending, both emails'", "email/publish failures recorded, still 200": "try/catch patches emailError; publishError patched from publish result; both return 200; test 'records an email failure and still answers 200'", "raw body (not re-serialised) is what is signed": "route calls c.req.text() and verifies/parses that same raw string; test signs JSON.stringify(body) and route validates over the raw bytes", "pnpm -r typecheck && pnpm -r test green": "both ran exit 0; server suite 14 files / 69 tests pass incl. webhook-signature.test.ts and build-complete.test.ts" }, "summary": "Added POST /api/build-complete HMAC callback (raw-body sha256 verify) that flips ready/failed, re-renders + writeHtml, publishes and emails, with all plan Task 8 tests passing.", "reason": "Implements phase-3 plan Task 8 verbatim against the merged Task 1-7 interfaces; publisher test stub carries publishStatus to satisfy the already-merged GitPublisher interface.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Matou/coa#75
No description provided.