Files
DeepTutor/web/tests/knowledge-helpers.test.ts
Bingxi Zhao (Frank) 96d6df9eb1 release: v1.5.13
Book is the bulk of this one. Compilation outlives the request that
started it, so a bus owned by that request dropped every background event
and "watch your book being written" degraded into a frozen page; the
stream is now owned per book by the process and survives a refresh or a
reconnect. Reading progress is finally recorded — `visited_page_ids` and
`bookmarked_page_ids` had been declared but never written for the life of
the feature — and rolls up into a completion score and weak chapters. A
book can also leave the app now, as one self-contained Markdown document,
with non-ASCII titles surviving the download.

Two scheduling defects that were invisible in production are fixed: the
same page compiled twice concurrently (billed twice, one result
discarded), and a book grinding on through a provider outage until every
chapter was half-generated. The source sweep is bounded and allocated
round-robin rather than spent on the first few knowledge bases, and
retrieval now tells indexed bases from connected pointers, so an Obsidian
vault or a remote IMA library no longer contributes zero while looking
like a source with nothing relevant. Confirming a spine shows a live
per-chapter estimate derived from the Section Architect's own templates.

Also here: three home starter suggestions built from memory recall,
mastery-path handoff moved into one module that changes lease, session
preference, and live turn together, and account-level Tencent IMA
credentials with the per-KB pair still winning.

Notes: assets/releases/ver1-5-13.md

This commit also carries the README prose sync, the eleven translated
READMEs, the release-notes archive sweep, and the version bump. Two gate
fixes ride along: the `Stamped` protocol is declared read-only so the
frozen `EntityStamp` satisfies it, and six GraphRAG adapter tests that
reached a deep `graphrag` import without guarding it now skip like their
four neighbours instead of failing where the extra is not installed.
2026-08-17 11:22:26 +08:00

173 lines
4.2 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
kbCanReindex,
resolveKnowledgeIndexFailure,
taskFailureMessage,
providerConnectionStatus,
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,
);
});
test("resolveKnowledgeIndexFailure preserves actionable backend metadata", () => {
assert.deepEqual(
resolveKnowledgeIndexFailure(
kb({
status: "error",
progress: {
stage: "error",
error: "Choose a chat model that supports structured output.",
error_code: "graphrag_model_incompatible",
retryable: false,
},
}),
),
{
code: "graphrag_model_incompatible",
message: "Choose a chat model that supports structured output.",
retryable: false,
requiresModelChange: true,
settingsHref: "/settings/models",
},
);
});
test("resolveKnowledgeIndexFailure distinguishes configuration from transient failures", () => {
const authentication = resolveKnowledgeIndexFailure(
kb({
status: "error",
progress: {
stage: "error",
error_code: "graphrag_model_authentication_failed",
retryable: false,
},
}),
);
const rateLimit = resolveKnowledgeIndexFailure(
kb({
status: "error",
progress: {
stage: "error",
error_code: "graphrag_model_rate_limited",
retryable: true,
},
}),
);
assert.equal(authentication?.requiresModelChange, true);
assert.equal(authentication?.settingsHref, "/settings/models");
assert.equal(rateLimit?.requiresModelChange, false);
assert.equal(rateLimit?.settingsHref, undefined);
assert.equal(rateLimit?.retryable, true);
});
test("resolveKnowledgeIndexFailure routes embedding configuration failures to embedding settings", () => {
const endpointFailure = resolveKnowledgeIndexFailure(
kb({
status: "error",
progress: {
stage: "error",
error_code: "graphrag_embedding_endpoint_failed",
retryable: false,
},
}),
);
assert.equal(endpointFailure?.requiresModelChange, true);
assert.equal(endpointFailure?.settingsHref, "/settings/embedding");
});
test("taskFailureMessage keeps trace details out of the primary error", () => {
assert.equal(
taskFailureMessage({
detail: "GraphRAG preflight failed.",
details: "Traceback: sensitive internal diagnostics",
}),
"GraphRAG preflight failed.",
);
});
test("engine status follows the credential and install state", () => {
// IMA holds one account credential pair, like PageIndex.
assert.equal(
providerConnectionStatus({
id: "ima",
configured: false,
requires_api_key: true,
}),
"needs_key",
);
assert.equal(
providerConnectionStatus({
id: "ima",
configured: true,
requires_api_key: true,
}),
"ready",
);
assert.equal(
providerConnectionStatus({ id: "llamaindex", configured: true }),
"ready",
);
assert.equal(
providerConnectionStatus({
id: "pageindex",
configured: false,
requires_api_key: true,
}),
"needs_key",
);
assert.equal(
providerConnectionStatus({ id: "graphrag", configured: false }),
"unavailable",
);
});