Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

test: tighten real-LLM contracts to assert behavior, not just non-corruption

nash_su1aa29585017b
diff --git a/src/lib/enrich-wikilinks.real-llm.test.ts b/src/lib/enrich-wikilinks.real-llm.test.ts
index 6bd8a72a..41bb2cb2 100644
--- a/src/lib/enrich-wikilinks.real-llm.test.ts
+++ b/src/lib/enrich-wikilinks.real-llm.test.ts
@@ -142,6 +142,31 @@ describe("real-LLM enrich-wikilinks scenarios (4)", () => {
).toBe(true)
}
+ // ── Scenario-specific strict assertions ────────────────────────
+ // The generic contracts above just prevent corruption. These
+ // enforce that the feature actually added value.
+ if (scenario.name === "adds-wikilinks" && wasWritten) {
+ // The survey page mentions "Transformer" (3×) and "Attention" (1×).
+ // The wiki index has both. A functional enrichment should wrap
+ // at least BOTH first-mentions, i.e. 2 distinct [[wikilinks]].
+ const wikilinks = Array.from(finalContent.matchAll(/\[\[[^\]]+\]\]/g))
+ expect(
+ wikilinks.length,
+ `adds-wikilinks: expected ≥2 wikilinks (Transformer + Attention), got ${wikilinks.length}`,
+ ).toBeGreaterThanOrEqual(2)
+ }
+
+ if (scenario.name === "cjk-terms" && wasWritten) {
+ // Chinese-term scenario: must have at least 1 CJK [[wikilink]]
+ const cjkWikilinks = Array.from(
+ finalContent.matchAll(/\[\[[^\]]*[\u4E00-\u9FFF][^\]]*\]\]/g),
+ )
+ expect(
+ cjkWikilinks.length,
+ `cjk-terms: expected ≥1 CJK wikilink, got ${cjkWikilinks.length}`,
+ ).toBeGreaterThanOrEqual(1)
+ }
+
// Contract 4: if written AND the wiki index contained linkable terms,
// the enriched page should include at least one [[wikilink]]
if (wasWritten && scenario.expected.writeCalled) {
diff --git a/src/lib/sweep-reviews.real-llm.test.ts b/src/lib/sweep-reviews.real-llm.test.ts
index 05ba7565..dfe6a82c 100644
--- a/src/lib/sweep-reviews.real-llm.test.ts
+++ b/src/lib/sweep-reviews.real-llm.test.ts
@@ -168,6 +168,52 @@ describe("real-LLM sweep scenarios (LLM-judged only)", () => {
// Contract 4: Input item count preserved (nothing added, nothing lost)
expect(state.length).toBe(scenario.reviews.length)
+
+ // ── Scenario-specific strict assertions ────────────────────────
+ // These catch regressions that the generic contracts miss.
+ if (scenario.name === "mixed-batch/partial-resolution") {
+ // r-mix-rule is a rule-resolvable missing-page review — its
+ // target page DOES exist in the wiki, so rules must resolve it.
+ const ruleResolved = state.find((i) => i.id === "r-mix-rule")
+ expect(
+ ruleResolved?.resolved,
+ "r-mix-rule should ALWAYS be resolved by rule stage",
+ ).toBe(true)
+ expect(ruleResolved?.resolvedAction).toBe("auto-resolved")
+
+ // r-mix-contra is a contradiction — MUST stay pending regardless
+ // of LLM behavior. If this ever resolves, the conservative
+ // filter in sweep is broken.
+ const contraItem = state.find((i) => i.id === "r-mix-contra")
+ expect(
+ contraItem?.resolved,
+ "r-mix-contra (contradiction) must NEVER be auto-resolved",
+ ).toBe(false)
+
+ // r-mix-sugg is a suggestion — rule stage must NOT touch it
+ // (LLM stage might, conservatively). Check it's not resolved
+ // by rules specifically.
+ const suggItem = state.find((i) => i.id === "r-mix-sugg")
+ if (suggItem?.resolved) {
+ expect(
+ suggItem.resolvedAction,
+ "suggestion can only be resolved by LLM, not rules",
+ ).toBe("llm-judged")
+ }
+ }
+
+ if (scenario.name === "llm-judged/semantic-match") {
+ // LIMITATION: the sweep judge only sends page FILENAMES + TITLES
+ // to the LLM, not body content. Semantic matching of 'Context
+ // Window' to attention.md depends on the LLM's general knowledge
+ // that attention windows = context windows. This is best-effort;
+ // we assert the operation completes cleanly rather than demand
+ // the LLM always make the leap.
+ // If it ever resolves, the action must be llm-judged.
+ for (const item of resolved) {
+ expect(item.resolvedAction).toBe("llm-judged")
+ }
+ }
},
TEST_TIMEOUT_MS,
)