Files
DeepTutor/web/tests/knowledge-helpers.test.ts
Bingxi Zhao (Frank) 144c90f3f7 prepare v1.3.4 release
Made-with: Cursor
2026-05-01 13:51:45 +08:00

53 lines
1.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { kbCanReindex, type KnowledgeBase } from "../lib/knowledge-helpers";
function kb(overrides: Partial<KnowledgeBase>): KnowledgeBase {
return {
name: "kb",
status: "ready",
statistics: { raw_documents: 1 },
...overrides,
};
}
test("kbCanReindex allows failed knowledge bases with source files", () => {
assert.equal(
kbCanReindex(
kb({
status: "error",
statistics: { raw_documents: 1, active_match: true },
}),
),
true,
);
});
test("kbCanReindex keeps empty failed knowledge bases disabled", () => {
assert.equal(
kbCanReindex(
kb({
status: "error",
statistics: { raw_documents: 0, active_match: false },
}),
),
false,
);
});
test("kbCanReindex preserves mismatch and needs-reindex behavior", () => {
assert.equal(
kbCanReindex(kb({ statistics: { raw_documents: 1, needs_reindex: true } })),
true,
);
assert.equal(
kbCanReindex(kb({ statistics: { raw_documents: 1, active_match: false } })),
true,
);
assert.equal(
kbCanReindex(kb({ statistics: { raw_documents: 1, active_match: true } })),
false,
);
});