返回 DeepSeek-Reasonix
diagnostics.test.ts
根目录 / desktop / electron / src / main / browser / diagnostics.test.ts
1 import assert from "node:assert/strict";
2 import { test } from "node:test";
3 import { DiagnosticBuffer } from "./diagnostics.js";
4
5 test("diagnostic buffers bound size, redact credentials and retain honest cursors", () => {
6 const buffer = new DiagnosticBuffer();
7 buffer.add({ kind: "network", message: "Authorization: xyz Bearer abc password=secret https://user:pass@example.test/a?token=private#secret", url: "https://user:pass@example.test/a?token=private#secret", status: 401 });
8 const text = JSON.stringify(buffer.read());
9 for (const secret of ["xyz", "abc", "private", "user:pass", "=secret"]) assert.equal(text.includes(secret), false);
10 buffer.add({ kind: "console", message: 'Cookie: session=hidden-one; secret=hidden-two\n{"password":"hidden-three","token":"hidden-four"}' });
11 for (const secret of ["hidden-one", "hidden-two", "hidden-three", "hidden-four"]) assert.equal(JSON.stringify(buffer.read()).includes(secret), false);
12 for (let i = 0; i < 300; i++) buffer.add({ kind: "console", message: "x".repeat(4096) });
13 const result = buffer.read(1);
14 assert.ok(result.entries.length <= 200);
15 assert.ok(Buffer.byteLength(JSON.stringify(result.entries)) <= 256 * 1024 + 200);
16 assert.equal(result.truncated, true);
17 assert.equal(buffer.read().truncated, true, "initial export must also disclose eviction");
18 assert.equal(buffer.read(result.cursor).entries.length, 0);
19 assert.equal(buffer.read(0, "network").entries.length, 0);
20 });
21
21 lines TYPESCRIPT