feat(authority): add diagnostics artifact manifest UX

This commit is contained in:
Youzini-afk
2026-04-28 18:11:46 +08:00
parent 97d380ab82
commit 7f3ea4f36f
5 changed files with 676 additions and 0 deletions

View File

@@ -3,16 +3,23 @@ import assert from "node:assert/strict";
import {
buildAuthorityDiagnosticsBundle,
buildAuthorityDiagnosticsBundlePath,
buildAuthorityDiagnosticsManifestPath,
buildAuthorityPerformanceBaseline,
readAuthorityDiagnosticsManifest,
removeAuthorityDiagnosticsManifestEntry,
sanitizeDiagnosticsSettings,
upsertAuthorityDiagnosticsManifestEntry,
writeAuthorityDiagnosticsBundle,
} from "../maintenance/authority-diagnostics-bundle.js";
function createMockAdapter() {
const calls = [];
const storage = new Map();
return {
calls,
storage,
async writeJson(path, payload, options = {}) {
storage.set(path, structuredClone(payload));
calls.push([path, payload, options]);
return {
ok: true,
@@ -20,6 +27,28 @@ function createMockAdapter() {
size: JSON.stringify(payload).length,
};
},
async readJson(path) {
if (!storage.has(path)) {
return {
exists: false,
path,
};
}
return {
exists: true,
path,
payload: structuredClone(storage.get(path)),
};
},
async delete(path) {
const existed = storage.delete(path);
return {
ok: true,
path,
deleted: existed,
missing: !existed,
};
},
};
}
@@ -204,6 +233,14 @@ function createMockAdapter() {
);
}
{
const manifestPath = buildAuthorityDiagnosticsManifestPath("chat/main");
assert.match(
manifestPath,
/^user\/files\/ST-BME_diagnostics_manifest_chat_main-[a-z0-9]+\.json$/,
);
}
{
const adapter = createMockAdapter();
const bundle = buildAuthorityDiagnosticsBundle({
@@ -225,4 +262,38 @@ function createMockAdapter() {
assert.equal(adapter.calls[0][2]?.metadata?.chatId, "chat-main");
}
{
const adapter = createMockAdapter();
await upsertAuthorityDiagnosticsManifestEntry(adapter, {
chatId: "chat-main",
path: "user/files/diag-a.json",
reason: "manual-export",
size: 100,
updatedAt: "2026-01-01T00:00:00.000Z",
});
await upsertAuthorityDiagnosticsManifestEntry(adapter, {
chatId: "chat-main",
path: "user/files/diag-b.json",
reason: "scheduled-export",
size: 120,
updatedAt: "2026-01-02T00:00:00.000Z",
});
const readResult = await readAuthorityDiagnosticsManifest(adapter, {
chatId: "chat-main",
});
assert.equal(readResult.exists, true);
assert.equal(readResult.entries.length, 2);
assert.equal(readResult.entries[0].path, "user/files/diag-b.json");
assert.equal(readResult.entries[1].path, "user/files/diag-a.json");
const removeResult = await removeAuthorityDiagnosticsManifestEntry(
adapter,
"user/files/diag-a.json",
{ chatId: "chat-main" },
);
assert.equal(removeResult.removed, true);
assert.equal(removeResult.entries.length, 1);
assert.equal(removeResult.entries[0].path, "user/files/diag-b.json");
}
console.log("authority-diagnostics-bundle tests passed");