Repository navigation
453 lines (401 loc) · 19.2 KB
/
Copy pathci.yml
File metadata and controls
453 lines (401 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
name: CI
on:
push:
# dev is the branch that actually deploys, so it must be tested. It was
# absent here, which is how untested code reached master through it.
branches: [master, dev]
pull_request:
branches: [master, dev]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: '22.16.0'
jobs:
# ──────────────────────────────────────────────
# Stage 1: Lint + Type Check (fast-fail gate)
# ──────────────────────────────────────────────
lint-and-typecheck:
name: Lint & Type Check
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
run: cd web && npm ci
- name: Install backend dependencies
run: cd web/backend && npm ci
# Lint is scoped to the architecturally-controlled frontend surface.
# Warning budget: ~90 are unused-vars from workspace context destructuring
# (architectural — both pages consume the full context), ~25 are Matrix
# chat hook exhaustive-deps, ~4 are img→Image, rest are minor.
# 0 errors enforced. Warnings ratchet as cleanup lands.
# Build tRPC first so the frontend tsc step can resolve
# `lib/trpc.ts`'s import of `../backend/dist/trpc/routers/index.js`.
# Previously this ran AFTER tsc, guaranteeing tsc would fail on a
# cold checkout with TS2307 even when the rest of the build was fine.
- name: Build tRPC (backend TypeScript)
run: cd web/backend && npm run build:trpc
- name: Lint frontend
run: cd web && npx eslint app components lib --max-warnings 135
- name: Test custom eslint rules
run: cd web && npm run test:eslint-rules
# Runs fumadocs codegen first: .source/ is gitignored, so on a fresh
# clone the docs route has no generated types and tsc fails.
- name: Type check frontend
run: cd web && npm run typecheck
# Prompt-library census. Advisory until Group 6 of
# `feature-prompts-library-expansion.md` flips PROMPTS_FLOOR_ENFORCING
# to 'true' (set as a repo variable). When enforcing, any tracked leaf
# tag below 500 prompts fails CI. --validate is always on so a missing
# or invalid `Prompt.scaffold` field fails immediately, advisory or not.
- name: Prompt library census
run: |
cd web
if [ "${{ vars.PROMPTS_FLOOR_ENFORCING }}" = "true" ]; then
npx tsx scripts/check-category-floors.ts --enforce --validate
else
npx tsx scripts/check-category-floors.ts --validate
fi
- name: Upload prompt census snapshot
if: always()
uses: actions/upload-artifact@v4
with:
name: prompts-census
path: web/scripts/.prompts-census.json
retention-days: 30
if-no-files-found: warn
# ──────────────────────────────────────────────
# Stage 2a: Unit Tests (frontend + backend)
# ──────────────────────────────────────────────
unit-tests:
name: Unit Tests
# The pinned Playwright release does not support Ubuntu 26 yet.
runs-on: ubuntu-24.04
needs: lint-and-typecheck
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
run: cd web && npm ci
- name: Install backend dependencies
run: cd web/backend && npm ci
- name: Run frontend unit tests
run: cd web && npx vitest run --config vitest.config.ts
- name: Run Convex tests
run: cd web && npx vitest run --config convex/vitest.config.ts
# Browser-QA tests drive a real Chromium (previewSmokeTest, content
# audits). Without the browser binary every one of them fails with
# "Executable doesn't exist" — which is why this job has been red on
# the deploy branch since 2026-08-30.
- name: Install Playwright Chromium
run: cd web/backend && npx playwright install --with-deps chromium
- name: Run backend tests
run: cd web/backend && npm test
# The MCP server is a standalone package with its own lockfile and a
# node:test runner, so it is outside every vitest config above.
- name: Install MCP server dependencies
run: cd web/mcp-server && npm ci
- name: Run MCP server tests
run: cd web/mcp-server && npm test
# Host operations scripts (retention, pruning) are plain node:test files
# at the repo root; nothing else runs them.
- name: Run ops script tests
run: node --test scripts/*.test.mjs
- name: Upload coverage
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage
path: |
web/coverage/
web/backend/coverage/
retention-days: 30
# ──────────────────────────────────────────────
# Stage 3: Build (validates production build)
# ──────────────────────────────────────────────
build:
name: Production Build
runs-on: ubuntu-latest
needs: [unit-tests]
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
run: cd web && npm ci
- name: Install backend dependencies
run: cd web/backend && npm ci
- name: Build tRPC
run: cd web/backend && npm run build:trpc
- name: Compute release identifier
id: release
run: echo "version=$(git rev-parse --short=12 HEAD)" >> "$GITHUB_OUTPUT"
- name: Build Next.js
run: cd web && npm run build
env:
NEXT_TELEMETRY_DISABLED: 1
# Next/Sentry webpack compilation can exceed Node's default ~2 GB
# old-space cap on dev; keep the cap below hosted-runner RAM.
# The package.json `build` script also pins --max-old-space-size on
# the node invocation directly so child workers inherit it without
# relying on env propagation through npm.
NODE_OPTIONS: --max-old-space-size=6144
# Minimal env vars to satisfy build (no real keys). Placeholders
# below override the dotenvx-encrypted values that Next.js would
# otherwise read from .env.production — those are stored as
# `encrypted:<base64>` and break URL/SDK constructors at
# prerender time (e.g. new URL()).
# Real values come from the host's environment at runtime.
NEXT_PUBLIC_APP_URL: http://localhost:3000
NEXT_PUBLIC_BACKEND_HOST: localhost
NEXT_PUBLIC_BACKEND_HTTP_PORT: 3001
NEXT_PUBLIC_BACKEND_WS_PORT: 3001
NEXT_PUBLIC_BACKEND_PROTOCOL: http
NEXT_PUBLIC_BACKEND_WS_PROTOCOL: ws
NEXT_PUBLIC_BACKEND_URL: http://localhost:3001
NEXT_PUBLIC_BACKEND_WS_URL: ws://localhost:3001/ws
NEXT_PUBLIC_BACKEND_HTTP_BASE: http://localhost:3001
NEXT_PUBLIC_CONVEX_URL: https://placeholder-deployment-123.convex.cloud
NEXT_PUBLIC_CONVEX_SITE_URL: https://placeholder-deployment-123.convex.site
NEXT_PUBLIC_BASE_URL: https://codebase.design
NEXT_PUBLIC_API_BASE_URL: http://localhost:3001
NEXT_PUBLIC_BASE_RPC_URL: https://mainnet.base.org
NEXT_PUBLIC_SPEECH_API_HTTP_URL: http://localhost:3002
NEXT_PUBLIC_SPEECH_API_WS_URL: ws://localhost:3002
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: pk_test_build_placeholder
# Server-side URLs / OAuth IDs read at module init or prerender.
# NEXTAUTH_URL must be a valid URL — next-auth feeds it through
# new URL() during /_not-found prerender. The others are mostly
# static-not-evaluated at build time but still matter if any
# SDK constructor touches them.
NEXTAUTH_URL: http://localhost:3000
AUTH_URL: http://localhost:3000
AUTH_SECRET: build-only-not-a-secret
NEXTAUTH_SECRET: build-only-not-a-secret
CONVEX_URL: https://placeholder-deployment-123.convex.cloud
CONVEX_SELF_HOSTED_URL: https://placeholder-deployment-123.convex.cloud
# Sentry source-map upload — no-op when SENTRY_AUTH_TOKEN is unset
# (withSentryConfig sets silent: !authToken). Required secrets:
# SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT, SENTRY_PROJECT_FRONTEND,
# NEXT_PUBLIC_SENTRY_DSN. See .settings/features/feature-error-monitoring.md.
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT_FRONTEND || secrets.SENTRY_PROJECT }}
NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
APP_VERSION: ${{ steps.release.outputs.version }}
NEXT_PUBLIC_APP_VERSION: ${{ steps.release.outputs.version }}
- name: Package build artifact
run: tar -czf nextjs-build.tar.gz -C web .next
# The artifact is a convenience for E2E; it is not the build's verdict.
# An exhausted org-wide artifact quota failed this job — and skipped
# E2E — on every PR while `next build` itself succeeded. Keep the job's
# result tied to the build, and let E2E rebuild if the upload failed.
- name: Upload build artifact
id: upload
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: nextjs-build
path: nextjs-build.tar.gz
if-no-files-found: error
retention-days: 1
# ──────────────────────────────────────────────
# Stage 4: E2E Tests (Cypress)
# ──────────────────────────────────────────────
e2e-tests:
name: E2E Tests
runs-on: ubuntu-24.04
needs: build
timeout-minutes: 20
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 3s
--health-retries 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
run: cd web && npm ci
- name: Install backend dependencies
run: cd web/backend && npm ci
- name: Build tRPC
run: cd web/backend && npm run build:trpc
# Prefer the build job's artifact; when the org artifact quota is
# exhausted (upload is non-fatal upstream) rebuild here with the same
# placeholder env so E2E still runs instead of being skipped.
- name: Download build
id: download
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: nextjs-build
path: .
- name: Extract build
if: steps.download.outcome == 'success'
run: tar -xzf nextjs-build.tar.gz -C web
- name: Rebuild Next.js (artifact unavailable)
if: steps.download.outcome != 'success'
run: cd web && npm run build
env:
NEXT_TELEMETRY_DISABLED: 1
# Next/Sentry webpack compilation can exceed Node's default ~2 GB
# old-space cap on dev; keep the cap below hosted-runner RAM.
# The package.json `build` script also pins --max-old-space-size on
# the node invocation directly so child workers inherit it without
# relying on env propagation through npm.
NODE_OPTIONS: --max-old-space-size=6144
# Minimal env vars to satisfy build (no real keys). Placeholders
# below override the dotenvx-encrypted values that Next.js would
# otherwise read from .env.production — those are stored as
# `encrypted:<base64>` and break URL/SDK constructors at
# prerender time (e.g. new URL()).
# Real values come from the host's environment at runtime.
NEXT_PUBLIC_APP_URL: http://localhost:3000
NEXT_PUBLIC_BACKEND_HOST: localhost
NEXT_PUBLIC_BACKEND_HTTP_PORT: 3001
NEXT_PUBLIC_BACKEND_WS_PORT: 3001
NEXT_PUBLIC_BACKEND_PROTOCOL: http
NEXT_PUBLIC_BACKEND_WS_PROTOCOL: ws
NEXT_PUBLIC_BACKEND_URL: http://localhost:3001
NEXT_PUBLIC_BACKEND_WS_URL: ws://localhost:3001/ws
NEXT_PUBLIC_BACKEND_HTTP_BASE: http://localhost:3001
NEXT_PUBLIC_CONVEX_URL: https://placeholder-deployment-123.convex.cloud
NEXT_PUBLIC_CONVEX_SITE_URL: https://placeholder-deployment-123.convex.site
NEXT_PUBLIC_BASE_URL: https://codebase.design
NEXT_PUBLIC_API_BASE_URL: http://localhost:3001
NEXT_PUBLIC_BASE_RPC_URL: https://mainnet.base.org
NEXT_PUBLIC_SPEECH_API_HTTP_URL: http://localhost:3002
NEXT_PUBLIC_SPEECH_API_WS_URL: ws://localhost:3002
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: pk_test_build_placeholder
# Server-side URLs / OAuth IDs read at module init or prerender.
# NEXTAUTH_URL must be a valid URL — next-auth feeds it through
# new URL() during /_not-found prerender. The others are mostly
# static-not-evaluated at build time but still matter if any
# SDK constructor touches them.
NEXTAUTH_URL: http://localhost:3000
AUTH_URL: http://localhost:3000
AUTH_SECRET: build-only-not-a-secret
NEXTAUTH_SECRET: build-only-not-a-secret
CONVEX_URL: https://placeholder-deployment-123.convex.cloud
CONVEX_SELF_HOSTED_URL: https://placeholder-deployment-123.convex.cloud
# Sentry source-map upload — no-op when SENTRY_AUTH_TOKEN is unset
# (withSentryConfig sets silent: !authToken). Required secrets:
# SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT, SENTRY_PROJECT_FRONTEND,
# NEXT_PUBLIC_SENTRY_DSN. See .settings/features/feature-error-monitoring.md.
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT_FRONTEND || secrets.SENTRY_PROJECT }}
NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
APP_VERSION: ${{ github.sha }}
NEXT_PUBLIC_APP_VERSION: ${{ github.sha }}
- uses: cypress-io/github-action@v6
with:
working-directory: web
start: |
npx next start -p 3000
npm --prefix backend start
wait-on: 'http://localhost:3000, http://localhost:3001/health/live'
wait-on-timeout: 120
config-file: cypress.config.ts
env:
CYPRESS_BASE_URL: http://localhost:3000
NEXT_PUBLIC_APP_URL: http://localhost:3000
NEXT_PUBLIC_BACKEND_HOST: localhost
NEXT_PUBLIC_BACKEND_HTTP_PORT: 3001
NEXT_PUBLIC_BACKEND_WS_PORT: 3001
NEXT_PUBLIC_BACKEND_PROTOCOL: http
NEXT_PUBLIC_BACKEND_WS_PROTOCOL: ws
NEXT_PUBLIC_BACKEND_URL: http://localhost:3001
NEXT_PUBLIC_BACKEND_WS_URL: ws://localhost:3001/ws
NEXT_PUBLIC_BACKEND_HTTP_BASE: http://localhost:3001
NEXT_PUBLIC_BASE_URL: https://codebase.design
NEXT_PUBLIC_CONVEX_URL: https://placeholder-deployment-123.convex.cloud
NEXT_PUBLIC_CONVEX_SITE_URL: https://placeholder-deployment-123.convex.site
NEXT_PUBLIC_API_BASE_URL: http://localhost:3001
NEXTAUTH_URL: http://localhost:3000
AUTH_URL: http://localhost:3000
AUTH_SECRET: e2e-only-not-a-secret
NEXTAUTH_SECRET: e2e-only-not-a-secret
CONVEX_URL: https://placeholder-deployment-123.convex.cloud
CONVEX_SELF_HOSTED_URL: https://placeholder-deployment-123.convex.cloud
REDIS_URL: redis://127.0.0.1:6379
- name: Upload Cypress screenshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: cypress-screenshots
path: web/cypress/screenshots/
retention-days: 7
- name: Upload Cypress videos
if: failure()
uses: actions/upload-artifact@v4
with:
name: cypress-videos
path: web/cypress/videos/
retention-days: 7
# ──────────────────────────────────────────────
# Stage 6: Security Audit (runs in parallel)
# ──────────────────────────────────────────────
security-audit:
name: Security Audit
runs-on: ubuntu-latest
timeout-minutes: 10
# Runs in parallel with lint and blocks release on high/critical findings.
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: web/package-lock.json
- name: Install dependencies
run: |
cd web && npm ci
cd backend && npm ci
cd ../mcp-server && npm ci
- name: Frontend dependency audit
run: cd web && npm audit --omit=dev --audit-level=high
- name: Backend dependency audit
run: cd web/backend && npm audit --omit=dev --audit-level=high
- name: MCP server dependency audit
run: cd web/mcp-server && npm audit --omit=dev --audit-level=high
- name: Check for hardcoded secrets
run: |
# Search for common secret patterns in source files
RESULTS=$(grep -rn --include='*.ts' --include='*.tsx' --include='*.js' --include='*.mjs' \
-E '(sk-[a-zA-Z0-9]{20,}|sk_live_|pk_live_|ghp_[a-zA-Z0-9]{36}|gsk_[a-zA-Z0-9]{20,})' \
web/app web/backend/agent web/backend/services web/backend/routes web/backend/ws \
web/components web/lib \
| grep -v -E 'web/backend/services/(workspaceSanitize|sastScanner)\.js:.*\/sk_live_' \
| grep -v -E 'web/backend/services/stripeService\.js:.*sk_test_… or sk_live_…' \
|| true)
if [ -n "$RESULTS" ]; then
echo "::error::Potential hardcoded secrets detected:"
echo "$RESULTS"
exit 1
fi