chore: crush git history - reborn from consolidation on 2026-03-10

This commit is contained in:
John Dvorak
2026-03-10 00:00:00 -07:00
commit d278c4b105
313 changed files with 87549 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
/**
* Tests for APOPHIS_DEBUG mode.
*/
import { test } from 'node:test'
import assert from 'node:assert'
import Fastify from 'fastify'
import apophisPlugin from '../index.js'
test('APOPHIS_DEBUG=1 logs requests and responses', async () => {
const fastify = Fastify() as any
const originalEnv = process.env.APOPHIS_DEBUG
const logs: string[] = []
try {
process.env.APOPHIS_DEBUG = '1'
await fastify.register(await import('@fastify/swagger'), {})
await fastify.register(apophisPlugin, { validateRuntime: false })
fastify.get('/test', {
schema: {
'x-category': 'observer',
'x-ensures': ['status:200'],
response: { 200: { type: 'object', properties: { ok: { type: 'boolean' } } } }
}
}, async () => ({ ok: true }))
await fastify.ready()
// Monkey-patch log.debug to capture logs
const { log } = await import('../infrastructure/logger.js')
const originalDebug = log.debug.bind(log)
log.debug = (msg: string, _obj?: Record<string, unknown>) => {
logs.push(msg)
originalDebug(msg, _obj)
}
const result = await fastify.apophis.contract({ depth: 'quick' })
assert.ok(result.tests.length > 0, 'should have tests')
// Should have logged at least one request and one response
const requestLogs = logs.filter(l => l.startsWith('→'))
const responseLogs = logs.filter(l => l.startsWith('←'))
assert.ok(requestLogs.length > 0, 'should log requests')
assert.ok(responseLogs.length > 0, 'should log responses')
} finally {
process.env.APOPHIS_DEBUG = originalEnv
await fastify.close()
}
})
test('APOPHIS_DEBUG=0 does not log requests', async () => {
const fastify = Fastify() as any
const originalEnv = process.env.APOPHIS_DEBUG
const logs: string[] = []
try {
process.env.APOPHIS_DEBUG = '0'
await fastify.register(await import('@fastify/swagger'), {})
await fastify.register(apophisPlugin, { validateRuntime: false })
fastify.get('/test', {
schema: {
'x-category': 'observer',
'x-ensures': ['status:200'],
response: { 200: { type: 'object', properties: { ok: { type: 'boolean' } } } }
}
}, async () => ({ ok: true }))
await fastify.ready()
// Monkey-patch log.debug to capture logs
const { log } = await import('../infrastructure/logger.js')
const originalDebug = log.debug.bind(log)
log.debug = (msg: string, _obj?: Record<string, unknown>) => {
logs.push(msg)
originalDebug(msg, _obj)
}
const result = await fastify.apophis.contract({ depth: 'quick' })
assert.ok(result.tests.length > 0, 'should have tests')
// Should not have any request/response logs
const debugLogs = logs.filter(l => l.startsWith('→') || l.startsWith('←'))
assert.strictEqual(debugLogs.length, 0, 'should not log requests when APOPHIS_DEBUG=0')
} finally {
process.env.APOPHIS_DEBUG = originalEnv
await fastify.close()
}
})