The Pipeline Is the Trust Boundary: Shipping 300+ PRs with AI Coding Agents Under Solo Accountability
Engineering Leadership · 8 min
How to safely use AI coding assistants at high velocity without architectural drift: enforcing AST no-any tests, bidirectional OpenAPI parity checks, ADR synchronization tests, and immutable digest promotion.
AI coding agents dramatically compress implementation time, but they introduce a subtle failure mode: local plausibility with global architectural drift. Left unchecked, an agent will happily add an as any cast to silence a compiler error, register an Express route without updating the OpenAPI spec, edit an ADR in Markdown while forgetting the TypeScript data model, or loosen a Content Security Policy header in one file while leaving firebase.json out of sync.
Over 300+ pull requests on this codebase (ADR-028), I have operated under a simple governance rule: prompts are advisory; the CI pipeline is the trust boundary. Every architectural invariant is encoded as a deterministic Vitest suite that blocks merge if violated.
1. Banning `any` via TypeScript AST Scanning (`tests/backend/noAny.test.ts`)
Tell an AI agent "do not use any" in a system prompt and it will follow the instruction ~95% of the time. The remaining 5% happens when it hits a tricky third-party type definition. Instead of relying on prompt compliance, tests/backend/noAny.test.ts parses every .ts and .tsx file using the TypeScript compiler AST (ts.createSourceFile) and fails the build if ts.SyntaxKind.AnyKeyword appears anywhere:
function findAnyLines(filePath: string, sourceText: string): number[] {
const sf = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true);
const lines: number[] = [];
const visit = (node: ts.Node) => {
if (node.kind === ts.SyntaxKind.AnyKeyword) {
const { line } = sf.getLineAndCharacterOfPosition(node.getStart(sf));
lines.push(line + 1);
}
ts.forEachChild(node, visit);
};
visit(sf);
return lines;
}
When an agent tries to take a shortcut with as any, npm test immediately fails with the exact file and line number, forcing a proper narrowing helper or Zod schema.
2. Bidirectional Express-to-OpenAPI Parity (`tests/backend/api.test.ts`)
Documentation drift is the norm in fast-moving APIs. To guarantee that GET /api/openapi.json and /api/docs (ADR-018) never lie, my test suite introspects the live Express router stack at test time, normalizes Express :param segments to OpenAPI {param} syntax, and asserts bidirectional set equality against openApiSpec.paths:
- If a route is registered in Express but missing from
server/openapi.ts, the test fails. - If a route is documented in
server/openapi.tsbut not mounted in Express, the test fails. - Request body schemas are derived directly from the route's Zod schema via
zodToOpenApiSchema().
3. ADR & Documentation Synchronization (`tests/backend/adrsSync.test.ts`)
This site publishes 45 Architecture Decision Records in two places: long-form Markdown files under docs/adr/*.md (with Mermaid diagrams) and bilingual structured objects in src/data/adrs.ts (used by the interactive Architecture page, the AI Concierge's lookup_adr tool, the MCP server, and build-time Open Graph card generation). adrsSync.test.ts verifies that every ADR exists in both places with identical IDs and statuses (accepted vs superseded), is indexed in both docs/adr/README.md and README.md, and that every feature flag in FLAG_DEFS is documented in docs/feature-flags.md and .env.example.
4. Three-Way Security Header Lockstep (`tests/backend/securityHeaders.test.ts`)
Because static assets are served from Firebase Hosting's CDN edge while dynamic HTML and API routes are served by Cloud Run (ADR-019, ADR-027), security headers (Content-Security-Policy, Permissions-Policy, Strict-Transport-Security, X-Frame-Options) exist in three places: server.ts and the prod and dev targets of firebase.json. My test suite boots the Express app, reads firebase.json, and asserts that all three emit identical headers and full CSP directives.
5. Build Once, Verify Staging, Promote by Immutable Digest (`ADR-021`, `ADR-034`)
Finally, governance extends past merge into deployment:
- Push to
mainbuilds the container image once in staging, signs the digest with keyless Sigstorecosign(Fulcio OIDC certificate + Rekor transparency log), deploysportfolio-backend-dev, and runs live Playwright E2E checks. - Production never rebuilds from source. When a human clicks Publish on the release draft prepared by
release.yml, the resultingv*tag resolves the exact@sha256:...image digest verified on staging, verifies its keylesscosignsignature against this repository's OIDC identity, extracts the Firebase Hosting bundle from inside the verified image itself, and promotes that immutable digest toportfolio-backend-prod.