Require explicit acknowledgement whenever operators enable TRACE and keep its active state visible until they restore normal logging.\n\nAdd an authenticated browser download for the complete retained logging snapshot, including runtime context and clear privacy guidance, while preserving the existing filtered-view export and memory-only TRACE boundary.\n\nCover the transition, snapshot, formatting, download, and client contracts with focused regression tests.
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
selectServerLogLevel,
|
|
TRACE_CONFIRMATION_WARNINGS,
|
|
} from '../src/lib/server-log-level';
|
|
|
|
describe('selectServerLogLevel', () => {
|
|
it('keeps every required warning in the TRACE confirmation', () => {
|
|
expect(TRACE_CONFIRMATION_WARNINGS).toEqual([
|
|
'TRACE 会产生非常大量的数据。',
|
|
'TRACE 可能包含未经脱敏的隐私数据和凭据。',
|
|
'TRACE 不适合长时间开启。',
|
|
'TRACE 仅用于小规模问题复现和 bug 反馈。',
|
|
]);
|
|
});
|
|
|
|
it('requires confirmation before entering TRACE from a normal level', () => {
|
|
const applyLevel = vi.fn();
|
|
const requestTraceConfirmation = vi.fn();
|
|
|
|
selectServerLogLevel({
|
|
currentLevel: 'info',
|
|
nextLevel: 'trace',
|
|
applyLevel,
|
|
requestTraceConfirmation,
|
|
});
|
|
|
|
expect(requestTraceConfirmation).toHaveBeenCalledOnce();
|
|
expect(applyLevel).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('applies ordinary level transitions immediately', () => {
|
|
const applyLevel = vi.fn();
|
|
const requestTraceConfirmation = vi.fn();
|
|
|
|
selectServerLogLevel({
|
|
currentLevel: 'trace',
|
|
nextLevel: 'info',
|
|
applyLevel,
|
|
requestTraceConfirmation,
|
|
});
|
|
|
|
expect(applyLevel).toHaveBeenCalledExactlyOnceWith('info');
|
|
expect(requestTraceConfirmation).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('requires confirmation each time TRACE is re-entered', () => {
|
|
const applyLevel = vi.fn();
|
|
const requestTraceConfirmation = vi.fn();
|
|
|
|
selectServerLogLevel({
|
|
currentLevel: 'debug',
|
|
nextLevel: 'trace',
|
|
applyLevel,
|
|
requestTraceConfirmation,
|
|
});
|
|
selectServerLogLevel({
|
|
currentLevel: 'info',
|
|
nextLevel: 'trace',
|
|
applyLevel,
|
|
requestTraceConfirmation,
|
|
});
|
|
|
|
expect(requestTraceConfirmation).toHaveBeenCalledTimes(2);
|
|
expect(applyLevel).not.toHaveBeenCalled();
|
|
});
|
|
});
|