From 5921b1437f71f6c1685f940d19e3367a63ae6f49 Mon Sep 17 00:00:00 2001 From: John Dvorak Date: Thu, 30 Apr 2026 12:47:40 -0700 Subject: [PATCH] trim: remove dead code and move large spec docs to attic - Remove unused exports: renderProgress, formatTripleBoundaryCounterexample, clearCapturedRoutes - Remove dead BUILTIN_PLUGIN_CONTRACTS constant (auto-registration removed earlier) - Fix app-loader error messages to mention multiple export patterns - Move to attic: protocol-extensions-spec, OUTBOUND_CONTRACT_MOCKING_SPEC, PLUGIN_CONTRACTS_SPEC, fastify-structure - Build: clean | Tests: 849 pass, 0 fail --- README.md | 2 +- SKILL.md | 2 +- .../OUTBOUND_CONTRACT_MOCKING_SPEC.md | 0 docs/{ => attic}/PLUGIN_CONTRACTS_SPEC.md | 0 docs/{ => attic}/fastify-structure.md | 0 docs/{ => attic}/protocol-extensions-spec.md | 0 docs/auth-patterns.md | 2 +- src/cli/commands/doctor/checks/routes.ts | 4 +- src/cli/commands/qualify/index.ts | 2 +- src/cli/commands/verify/index.ts | 2 +- src/cli/renderers/human.ts | 23 ---------- src/domain/discovery.ts | 6 --- src/domain/plugin-contracts.ts | 40 ----------------- src/domain/triple-boundary-testing.ts | 44 ------------------- 14 files changed, 7 insertions(+), 120 deletions(-) rename docs/{ => attic}/OUTBOUND_CONTRACT_MOCKING_SPEC.md (100%) rename docs/{ => attic}/PLUGIN_CONTRACTS_SPEC.md (100%) rename docs/{ => attic}/fastify-structure.md (100%) rename docs/{ => attic}/protocol-extensions-spec.md (100%) diff --git a/README.md b/README.md index 7ebf9de..2f29b57 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ See [docs/llm-safe-adoption.md](docs/llm-safe-adoption.md) for templates and CI - [Qualify Mode](docs/qualify.md) — Scenarios, stateful testing, chaos - [Performance](docs/performance.md) — Repeatable benchmarks and CPU profiling - [LLM-Safe Adoption](docs/llm-safe-adoption.md) — Scaffolds and CI guards -- [Protocol Extensions](docs/protocol-extensions-spec.md) — JWT, X.509, SPIFFE, WIMSE +- [Protocol Extensions](docs/attic/protocol-extensions-spec.md) — JWT, X.509, SPIFFE, WIMSE ## License diff --git a/SKILL.md b/SKILL.md index f61af95..3acf37e 100644 --- a/SKILL.md +++ b/SKILL.md @@ -407,7 +407,7 @@ Then execute APOPHIS from the project test harness or CLI as appropriate. For mo 1. `README.md` for canonical usage. 2. `docs/getting-started.md` for quick setup. 3. `docs/cli.md` and command docs for CLI flags and machine output. -4. `docs/protocol-extensions-spec.md` for protocol-specific direction. +4. `docs/attic/protocol-extensions-spec.md` for protocol-specific direction. ## Final Check diff --git a/docs/OUTBOUND_CONTRACT_MOCKING_SPEC.md b/docs/attic/OUTBOUND_CONTRACT_MOCKING_SPEC.md similarity index 100% rename from docs/OUTBOUND_CONTRACT_MOCKING_SPEC.md rename to docs/attic/OUTBOUND_CONTRACT_MOCKING_SPEC.md diff --git a/docs/PLUGIN_CONTRACTS_SPEC.md b/docs/attic/PLUGIN_CONTRACTS_SPEC.md similarity index 100% rename from docs/PLUGIN_CONTRACTS_SPEC.md rename to docs/attic/PLUGIN_CONTRACTS_SPEC.md diff --git a/docs/fastify-structure.md b/docs/attic/fastify-structure.md similarity index 100% rename from docs/fastify-structure.md rename to docs/attic/fastify-structure.md diff --git a/docs/protocol-extensions-spec.md b/docs/attic/protocol-extensions-spec.md similarity index 100% rename from docs/protocol-extensions-spec.md rename to docs/attic/protocol-extensions-spec.md diff --git a/docs/auth-patterns.md b/docs/auth-patterns.md index 804b24a..549eae6 100644 --- a/docs/auth-patterns.md +++ b/docs/auth-patterns.md @@ -135,7 +135,7 @@ fastify.get('/wimse/wit', { }) ``` -See `docs/protocol-extensions-spec.md` for full JWT extension configuration. +See `docs/attic/protocol-extensions-spec.md` for full JWT extension configuration. --- diff --git a/src/cli/commands/doctor/checks/routes.ts b/src/cli/commands/doctor/checks/routes.ts index a18728c..7cc67f8 100644 --- a/src/cli/commands/doctor/checks/routes.ts +++ b/src/cli/commands/doctor/checks/routes.ts @@ -116,8 +116,8 @@ export async function checkRouteDiscovery(options: RouteCheckOptions): Promise app; or module.exports = app;', mode: 'all', }; } diff --git a/src/cli/commands/qualify/index.ts b/src/cli/commands/qualify/index.ts index 41c980d..99f93de 100644 --- a/src/cli/commands/qualify/index.ts +++ b/src/cli/commands/qualify/index.ts @@ -642,7 +642,7 @@ export async function qualifyCommand( } return { exitCode: USAGE_ERROR, - message: 'No Fastify app found. Ensure app.js exports a Fastify instance.', + message: 'No Fastify app found. Ensure app.js exports a Fastify instance or a factory function.\n\nSupported patterns:\n export default app\n export const createApp = () => app\n module.exports = app', } } diff --git a/src/cli/commands/verify/index.ts b/src/cli/commands/verify/index.ts index c4ba133..f59cc57 100644 --- a/src/cli/commands/verify/index.ts +++ b/src/cli/commands/verify/index.ts @@ -468,7 +468,7 @@ export async function verifyCommand( const errorMessage = err instanceof Error ? err.message : String(err) return { exitCode: USAGE_ERROR, - message: `No Fastify app found. Ensure app.js exports a Fastify instance.\n\nError: ${errorMessage}\n\nNext:\n Run \`apophis init\` to scaffold a working app.js and config.`, + message: `No Fastify app found. Ensure app.js exports a Fastify instance or a factory function.\n\nSupported patterns:\n export default app\n export const createApp = () => app\n module.exports = app\n\nError: ${errorMessage}\n\nNext:\n Run \`apophis init\` to scaffold a working app.js and config.`, } } diff --git a/src/cli/renderers/human.ts b/src/cli/renderers/human.ts index 7470677..7bd3326 100644 --- a/src/cli/renderers/human.ts +++ b/src/cli/renderers/human.ts @@ -183,29 +183,6 @@ function generateNextSteps(failure: FailureRecord): string { // Progress and summary rendering // --------------------------------------------------------------------------- -/** - * Render progress for a running command. - * Safe for CI (no spinners, just text updates). - */ -export function renderProgress( - current: number, - total: number, - label: string, - ctx: OutputContext, -): string { - const c = getColorizer(ctx); - const pct = total > 0 ? Math.round((current / total) * 100) : 0; - - if (ctx.isCI || !ctx.isTTY) { - // CI mode: simple text, no spinner - return `${label} [${current}/${total}] ${pct}%`; - } - - // TTY mode: with color - const bar = renderProgressBar(current, total, 20, ctx); - return `${c.dim(label)} ${bar} ${c.bold(`${pct}%`)}`; -} - /** * Render a simple ASCII progress bar. */ diff --git a/src/domain/discovery.ts b/src/domain/discovery.ts index 88bee07..f8edf93 100644 --- a/src/domain/discovery.ts +++ b/src/domain/discovery.ts @@ -87,9 +87,3 @@ export const discoverRoutes = (instance: { routes?: Array<{ method: string; url: // Fastify 5 fallback: routes registered before plugin return discoverRoutesFallback(instance) } -/** - * Clear captured routes for an instance (useful for testing). - */ -export const clearCapturedRoutes = (instance: object): void => { - capturedRoutes.delete(instance) -} diff --git a/src/domain/plugin-contracts.ts b/src/domain/plugin-contracts.ts index 6aec0ed..22c579e 100644 --- a/src/domain/plugin-contracts.ts +++ b/src/domain/plugin-contracts.ts @@ -143,46 +143,6 @@ export class PluginContractRegistry { } } // ============================================================================ -// Built-in Plugin Contracts -// ============================================================================ -export const BUILTIN_PLUGIN_CONTRACTS: Record = { - '@fastify/auth': { - appliesTo: '**', - hooks: { - onRequest: { - requires: ['request_headers(this).authorization != null'], - }, - }, - }, - '@fastify/compress': { - appliesTo: '**', - hooks: { - onSend: { - ensures: ['response_headers(this).content-encoding != null'], - }, - }, - }, - '@fastify/cors': { - appliesTo: '**', - hooks: { - onRequest: { - ensures: ['response_headers(this).access-control-allow-origin != null'], - }, - }, - }, - '@fastify/rate-limit': { - appliesTo: '**', - hooks: { - onRequest: { - ensures: [ - 'response_headers(this).x-ratelimit-limit != null', - 'response_headers(this).x-ratelimit-remaining != null', - ], - }, - }, - }, -} -// ============================================================================ // Factory // ============================================================================ export function createPluginContractRegistry(): PluginContractRegistry { diff --git a/src/domain/triple-boundary-testing.ts b/src/domain/triple-boundary-testing.ts index 65f6edd..60c976b 100644 --- a/src/domain/triple-boundary-testing.ts +++ b/src/domain/triple-boundary-testing.ts @@ -360,47 +360,3 @@ export function applyChaosToAllResponses( ) }) } -// ============================================================================ -// Formatting -// ============================================================================ -export function formatTripleBoundaryCounterexample(result: TripleBoundaryResult): string { - const lines: string[] = [] - lines.push('Triple-boundary counterexample:') - lines.push('') - lines.push(`Route: ${result.command.route.method} ${result.command.route.path}`) - lines.push('') - lines.push('Request:') - lines.push(JSON.stringify(result.command.request, null, 2)) - lines.push('') - if (result.command.dependencyResponses.length > 0) { - lines.push('Dependency responses:') - for (const dep of result.command.dependencyResponses) { - lines.push(` ${dep.contractName}: ${dep.statusCode}`) - lines.push(` ${JSON.stringify(dep.body)}`) - } - lines.push('') - } - if (result.command.chaosEvents.length > 0) { - lines.push('Chaos events:') - for (const chaos of result.command.chaosEvents) { - if (chaos.type === 'none') continue - lines.push(` ${chaos.type}`) - if (chaos.contractName) lines.push(` Target: ${chaos.contractName}`) - if (chaos.delayMs) lines.push(` Delay: ${chaos.delayMs}ms`) - if (chaos.statusCode) lines.push(` Status: ${chaos.statusCode}`) - if (chaos.corruptionStrategy) lines.push(` Corruption: ${chaos.corruptionStrategy}`) - if (chaos.corruptionField) lines.push(` Field: ${chaos.corruptionField}`) - } - lines.push('') - } - if (result.failureBoundary) { - lines.push(`Failure boundary: ${result.failureBoundary}`) - } - if (result.failureDescription) { - lines.push(`Description: ${result.failureDescription}`) - } - if (result.error) { - lines.push(`Error: ${result.error}`) - } - return lines.join('\n') -}