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
import { beforeEach, describe, expect, it, vi } from "vitest"
const fsMocks = vi.hoisted(() => ({
createDirectory: vi.fn(),
fileExists: vi.fn(),
writeFile: vi.fn(),
}))
vi.mock("@/commands/fs", () => fsMocks)
import {
appendWikilink,
ensureBrokenLinkStub,
rewriteWikilinkTarget,
stubRelativePathFromBrokenTarget,
} from "./lint-fixes"
beforeEach(() => {
fsMocks.createDirectory.mockReset()
fsMocks.fileExists.mockReset()
fsMocks.writeFile.mockReset()
})
describe("rewriteWikilinkTarget", () => {
it("rewrites a matching wikilink and preserves aliases", () => {
const out = rewriteWikilinkTarget(
"See [[transfomer|the Transformer page]] and [[attention]].",
"transfomer",
"entities/transformer.md",
)
expect(out).toBe("See [[entities/transformer|the Transformer page]] and [[attention]].")
})
it("leaves non-matching wikilinks byte-identical", () => {
const input = "See [[attention|Attention]] only."
expect(rewriteWikilinkTarget(input, "transformer", "entities/transformer.md")).toBe(input)
})
})
describe("appendWikilink", () => {
it("does not duplicate an existing aliased wikilink", () => {
const input = "See [[entities/transformer|Transformer]]."
expect(appendWikilink(input, "entities/transformer.md")).toBe(input)
})
it("appends a related section when the target is absent", () => {
expect(appendWikilink("# Page\nBody", "entities/transformer.md")).toBe(
"# Page\nBody\n\n## Related\n- [[entities/transformer]]\n",
)
})
it("adds to an existing related section without duplicating the heading", () => {
const out = appendWikilink(
"# Page\n\n## Related\n- [[entities/attention]]\n",
"entities/transformer.md",
)
expect(out.match(/^## Related$/gm)).toHaveLength(1)
expect(out).toContain("## Related\n- [[entities/transformer]]\n- [[entities/attention]]")
})
})
describe("ensureBrokenLinkStub", () => {
it("reuses an existing slugified target instead of overwriting it", async () => {
fsMocks.fileExists.mockResolvedValue(true)
const result = await ensureBrokenLinkStub("/project", "Foo Bar")
expect(result).toEqual({
fullPath: "/project/wiki/queries/foo-bar.md",
relativePath: "queries/foo-bar.md",
created: false,
})
expect(fsMocks.writeFile).not.toHaveBeenCalled()
})
it("creates a safe stub path when no target exists", async () => {
fsMocks.fileExists.mockResolvedValue(false)
const result = await ensureBrokenLinkStub("/project", "Foo Bar")
expect(result.relativePath).toBe("queries/foo-bar.md")
expect(fsMocks.createDirectory).toHaveBeenCalledWith("/project/wiki/queries")
expect(fsMocks.writeFile).toHaveBeenCalledWith(
"/project/wiki/queries/foo-bar.md",
expect.stringContaining("type: query\ntitle: \"Foo Bar\""),
)
})
it("uses the destination folder type for explicit knowledge paths", async () => {
fsMocks.fileExists.mockResolvedValue(false)
await ensureBrokenLinkStub("/project", "concepts/Clash Detection")
expect(fsMocks.writeFile).toHaveBeenCalledWith(
"/project/wiki/concepts/clash-detection.md",
expect.stringContaining("type: concept\ntitle: \"Clash Detection\""),
)
})
it("singularizes known schema folders when creating stubs", async () => {
fsMocks.fileExists.mockResolvedValue(false)
await ensureBrokenLinkStub("/project", "standards/Release Gate")
expect(fsMocks.writeFile).toHaveBeenCalledWith(
"/project/wiki/standards/release-gate.md",
expect.stringContaining("type: standard\ntitle: \"Release Gate\""),
)
})
it("keeps explicit wiki subdirectories when building stub paths", () => {
expect(stubRelativePathFromBrokenTarget("concepts/Foo Bar")).toBe("concepts/foo-bar.md")
})
})