[grade=A] DC-065: Sweep 15 console.* calls to process.stderr.write
Replace all non-logger console.error/warn calls with process.stderr.write using tagged prefixes ([AuditLogger], [CSRF], [DNS Registry], etc.) for grep-ability. All in fallback/catch paths where structured logger may be unavailable. Test updated to use jest.spyOn with try/finally for clean mock restoration. Codex grade: pass (22,402 tokens). All 1539 tests pass.
This commit is contained in:
@@ -156,18 +156,19 @@ describe('Error Handler', () => {
|
||||
});
|
||||
|
||||
it('logs non-operational errors as FATAL', () => {
|
||||
const origError = console.error;
|
||||
console.error = jest.fn();
|
||||
const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
||||
|
||||
const err = new Error('programming bug');
|
||||
errorMiddleware(err, req, res, next);
|
||||
try {
|
||||
const err = new Error('programming bug');
|
||||
errorMiddleware(err, req, res, next);
|
||||
|
||||
expect(console.error).toHaveBeenCalledWith(
|
||||
'FATAL: Non-operational error detected',
|
||||
expect.any(Object)
|
||||
);
|
||||
|
||||
console.error = origError;
|
||||
const calls = stderrSpy.mock.calls.map(c => String(c[0]));
|
||||
const fatalLine = calls.find(l => l.includes('FATAL'));
|
||||
expect(fatalLine).toBeDefined();
|
||||
expect(fatalLine).toContain('programming bug');
|
||||
} finally {
|
||||
stderrSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user