feat(logging): establish trace diagnostics contract

Make short-lived TRACE sessions complete and correlatable without adding a persistent trace channel or changing the existing file-log safety boundary.

Protect ordinary console, subscriber, and file logs from authentication material while preserving the one documented first-start credential notice. Keep action breadcrumbs useful through bounded summaries and a narrow diagnostic name for the emoji-like pagination offset.

Lock the contract with regressions for byte-complete rendering, lazy execution, request-context reuse, credential redaction, unredacted TRACE data, and non-persistence of TRACE records.
This commit is contained in:
DrSmoothl committed 2026-07-30 12:07:32 +08:00
1 parent 1d65623475
commit b9104f0a5b
8 files changed
+712 -87

No files matched your search

@@ -93,6 +93,47 @@ describe('ApiHandler dispatch logging', () => {
expect(entry!.message).toContain('message=[len=3]');
});
it('logs the parsed emoji-like offset without exposing its cookie cursor', async () => {
const handler = createCompiledTestHandler(emptyContext(), [
testAction('fetch_emoji_like', async () => ({ status: 'ok', retcode: 0, data: null })),
], 12345);
await handler.handle('fetch_emoji_like', {
message_id: 1,
emojiId: '66',
cookie: '40',
});
const entry = captured.find((e) => e.scope === 'Bridge.Action' && e.level === 'debug');
expect(entry?.message).toContain('emoji_like_offset=40');
expect(entry?.message).not.toContain('cookie=');
});
it('keeps malformed emoji-like cookies redacted instead of parsing prefixes', async () => {
const handler = createCompiledTestHandler(emptyContext(), [
testAction('fetch_emoji_like', async () => ({ status: 'ok', retcode: 0, data: null })),
], 12345);
await handler.handle('fetch_emoji_like', { cookie: '123.session=secret' });
const entry = captured.find((e) => e.scope === 'Bridge.Action' && e.level === 'debug');
expect(entry?.message).toContain('cookie=***');
expect(entry?.message).not.toContain('emoji_like_offset=');
expect(entry?.message).not.toContain('session=secret');
});
it('keeps cookie parameters redacted for every other action', async () => {
const handler = createCompiledTestHandler(emptyContext(), [
testAction('other_action', async () => ({ status: 'ok', retcode: 0, data: null })),
], 12345);
await handler.handle('other_action', { cookie: '40' });
const entry = captured.find((e) => e.scope === 'Bridge.Action' && e.level === 'debug');
expect(entry?.message).toContain('cookie=***');
expect(entry?.message).not.toContain('cookie=40');
});
it('emits a warn line with the error stack when the handler throws', async () => {
const handler = createCompiledTestHandler(emptyContext(), [
testAction('boom', async () => { throw new Error('kapow'); }),