@agent-wiki/mcp 0.17.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +7 -0
- package/README.md +171 -0
- package/architecture.svg +58 -0
- package/dist/atlassian.d.ts +63 -0
- package/dist/atlassian.d.ts.map +1 -0
- package/dist/atlassian.js +596 -0
- package/dist/atlassian.js.map +1 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +391 -0
- package/dist/cli.js.map +1 -0
- package/dist/cobol/__tests__/call-boundary-lineage.test.d.ts +2 -0
- package/dist/cobol/__tests__/call-boundary-lineage.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/call-boundary-lineage.test.js +505 -0
- package/dist/cobol/__tests__/call-boundary-lineage.test.js.map +1 -0
- package/dist/cobol/__tests__/code-analysis.test.d.ts +2 -0
- package/dist/cobol/__tests__/code-analysis.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/code-analysis.test.js +465 -0
- package/dist/cobol/__tests__/code-analysis.test.js.map +1 -0
- package/dist/cobol/__tests__/db2-table-lineage.test.d.ts +2 -0
- package/dist/cobol/__tests__/db2-table-lineage.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/db2-table-lineage.test.js +182 -0
- package/dist/cobol/__tests__/db2-table-lineage.test.js.map +1 -0
- package/dist/cobol/__tests__/evidence-mapping.test.d.ts +2 -0
- package/dist/cobol/__tests__/evidence-mapping.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/evidence-mapping.test.js +49 -0
- package/dist/cobol/__tests__/evidence-mapping.test.js.map +1 -0
- package/dist/cobol/__tests__/extractors.test.d.ts +2 -0
- package/dist/cobol/__tests__/extractors.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/extractors.test.js +189 -0
- package/dist/cobol/__tests__/extractors.test.js.map +1 -0
- package/dist/cobol/__tests__/field-lineage.test.d.ts +2 -0
- package/dist/cobol/__tests__/field-lineage.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/field-lineage.test.js +329 -0
- package/dist/cobol/__tests__/field-lineage.test.js.map +1 -0
- package/dist/cobol/__tests__/graph.test.d.ts +2 -0
- package/dist/cobol/__tests__/graph.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/graph.test.js +456 -0
- package/dist/cobol/__tests__/graph.test.js.map +1 -0
- package/dist/cobol/__tests__/integration.test.d.ts +2 -0
- package/dist/cobol/__tests__/integration.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/integration.test.js +971 -0
- package/dist/cobol/__tests__/integration.test.js.map +1 -0
- package/dist/cobol/__tests__/lexer.test.d.ts +2 -0
- package/dist/cobol/__tests__/lexer.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/lexer.test.js +111 -0
- package/dist/cobol/__tests__/lexer.test.js.map +1 -0
- package/dist/cobol/__tests__/parser.test.d.ts +2 -0
- package/dist/cobol/__tests__/parser.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/parser.test.js +180 -0
- package/dist/cobol/__tests__/parser.test.js.map +1 -0
- package/dist/cobol/__tests__/variable-tracer.test.d.ts +2 -0
- package/dist/cobol/__tests__/variable-tracer.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/variable-tracer.test.js +256 -0
- package/dist/cobol/__tests__/variable-tracer.test.js.map +1 -0
- package/dist/cobol/__tests__/wiki-gen.test.d.ts +2 -0
- package/dist/cobol/__tests__/wiki-gen.test.d.ts.map +1 -0
- package/dist/cobol/__tests__/wiki-gen.test.js +76 -0
- package/dist/cobol/__tests__/wiki-gen.test.js.map +1 -0
- package/dist/cobol/call-boundary-lineage.d.ts +49 -0
- package/dist/cobol/call-boundary-lineage.d.ts.map +1 -0
- package/dist/cobol/call-boundary-lineage.js +159 -0
- package/dist/cobol/call-boundary-lineage.js.map +1 -0
- package/dist/cobol/db2-table-lineage.d.ts +45 -0
- package/dist/cobol/db2-table-lineage.d.ts.map +1 -0
- package/dist/cobol/db2-table-lineage.js +127 -0
- package/dist/cobol/db2-table-lineage.js.map +1 -0
- package/dist/cobol/evidence-mapping.d.ts +31 -0
- package/dist/cobol/evidence-mapping.d.ts.map +1 -0
- package/dist/cobol/evidence-mapping.js +27 -0
- package/dist/cobol/evidence-mapping.js.map +1 -0
- package/dist/cobol/extractors.d.ts +88 -0
- package/dist/cobol/extractors.d.ts.map +1 -0
- package/dist/cobol/extractors.js +297 -0
- package/dist/cobol/extractors.js.map +1 -0
- package/dist/cobol/field-lineage.d.ts +101 -0
- package/dist/cobol/field-lineage.d.ts.map +1 -0
- package/dist/cobol/field-lineage.js +603 -0
- package/dist/cobol/field-lineage.js.map +1 -0
- package/dist/cobol/graph.d.ts +182 -0
- package/dist/cobol/graph.d.ts.map +1 -0
- package/dist/cobol/graph.js +453 -0
- package/dist/cobol/graph.js.map +1 -0
- package/dist/cobol/lexer.d.ts +15 -0
- package/dist/cobol/lexer.d.ts.map +1 -0
- package/dist/cobol/lexer.js +251 -0
- package/dist/cobol/lexer.js.map +1 -0
- package/dist/cobol/parser.d.ts +13 -0
- package/dist/cobol/parser.d.ts.map +1 -0
- package/dist/cobol/parser.js +584 -0
- package/dist/cobol/parser.js.map +1 -0
- package/dist/cobol/plugin.d.ts +23 -0
- package/dist/cobol/plugin.d.ts.map +1 -0
- package/dist/cobol/plugin.js +507 -0
- package/dist/cobol/plugin.js.map +1 -0
- package/dist/cobol/types.d.ts +73 -0
- package/dist/cobol/types.d.ts.map +1 -0
- package/dist/cobol/types.js +9 -0
- package/dist/cobol/types.js.map +1 -0
- package/dist/cobol/variable-tracer.d.ts +31 -0
- package/dist/cobol/variable-tracer.d.ts.map +1 -0
- package/dist/cobol/variable-tracer.js +361 -0
- package/dist/cobol/variable-tracer.js.map +1 -0
- package/dist/cobol/wiki-gen.d.ts +18 -0
- package/dist/cobol/wiki-gen.d.ts.map +1 -0
- package/dist/cobol/wiki-gen.js +222 -0
- package/dist/cobol/wiki-gen.js.map +1 -0
- package/dist/code-analysis.d.ts +160 -0
- package/dist/code-analysis.d.ts.map +1 -0
- package/dist/code-analysis.js +53 -0
- package/dist/code-analysis.js.map +1 -0
- package/dist/evidence-search.d.ts +43 -0
- package/dist/evidence-search.d.ts.map +1 -0
- package/dist/evidence-search.js +112 -0
- package/dist/evidence-search.js.map +1 -0
- package/dist/evidence-search.test.d.ts +2 -0
- package/dist/evidence-search.test.d.ts.map +1 -0
- package/dist/evidence-search.test.js +98 -0
- package/dist/evidence-search.test.js.map +1 -0
- package/dist/evidence.d.ts +32 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +16 -0
- package/dist/evidence.js.map +1 -0
- package/dist/evidence.test.d.ts +2 -0
- package/dist/evidence.test.d.ts.map +1 -0
- package/dist/evidence.test.js +51 -0
- package/dist/evidence.test.js.map +1 -0
- package/dist/extraction.d.ts +40 -0
- package/dist/extraction.d.ts.map +1 -0
- package/dist/extraction.js +283 -0
- package/dist/extraction.js.map +1 -0
- package/dist/extraction.test.d.ts +5 -0
- package/dist/extraction.test.d.ts.map +1 -0
- package/dist/extraction.test.js +137 -0
- package/dist/extraction.test.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/queue.d.ts +52 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +139 -0
- package/dist/queue.js.map +1 -0
- package/dist/queue.test.d.ts +2 -0
- package/dist/queue.test.d.ts.map +1 -0
- package/dist/queue.test.js +161 -0
- package/dist/queue.test.js.map +1 -0
- package/dist/search.d.ts +163 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +653 -0
- package/dist/search.js.map +1 -0
- package/dist/search.test.d.ts +6 -0
- package/dist/search.test.d.ts.map +1 -0
- package/dist/search.test.js +551 -0
- package/dist/search.test.js.map +1 -0
- package/dist/server.d.ts +33 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +2530 -0
- package/dist/server.js.map +1 -0
- package/dist/server.test.d.ts +8 -0
- package/dist/server.test.d.ts.map +1 -0
- package/dist/server.test.js +2397 -0
- package/dist/server.test.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/dist/wiki.d.ts +496 -0
- package/dist/wiki.d.ts.map +1 -0
- package/dist/wiki.js +2677 -0
- package/dist/wiki.js.map +1 -0
- package/dist/wiki.test.d.ts +8 -0
- package/dist/wiki.test.d.ts.map +1 -0
- package/dist/wiki.test.js +1881 -0
- package/dist/wiki.test.js.map +1 -0
- package/docs/code-analysis-plugins.md +169 -0
- package/docs/configuration.md +135 -0
- package/docs/diagrams/cobol-analysis-flow.png +0 -0
- package/docs/diagrams/cobol-analysis-flow.svg +156 -0
- package/docs/evidence-envelope.md +176 -0
- package/docs/graph-1.gif +0 -0
- package/docs/legacy-code-knowledge-compiler-prd.md +511 -0
- package/docs/product-direction.md +120 -0
- package/docs/request-optimization.md +201 -0
- package/docs/search.md +266 -0
- package/docs/tools.md +269 -0
- package/graph-viewer/dist/cli.d.ts +3 -0
- package/graph-viewer/dist/cli.d.ts.map +1 -0
- package/graph-viewer/dist/cli.js +97 -0
- package/graph-viewer/dist/cli.js.map +1 -0
- package/graph-viewer/dist/graph.d.ts +14 -0
- package/graph-viewer/dist/graph.d.ts.map +1 -0
- package/graph-viewer/dist/graph.js +96 -0
- package/graph-viewer/dist/graph.js.map +1 -0
- package/graph-viewer/dist/index.d.ts +6 -0
- package/graph-viewer/dist/index.d.ts.map +1 -0
- package/graph-viewer/dist/index.js +4 -0
- package/graph-viewer/dist/index.js.map +1 -0
- package/graph-viewer/dist/parse.d.ts +10 -0
- package/graph-viewer/dist/parse.d.ts.map +1 -0
- package/graph-viewer/dist/parse.js +62 -0
- package/graph-viewer/dist/parse.js.map +1 -0
- package/graph-viewer/dist/server.d.ts +15 -0
- package/graph-viewer/dist/server.d.ts.map +1 -0
- package/graph-viewer/dist/server.js +168 -0
- package/graph-viewer/dist/server.js.map +1 -0
- package/graph-viewer/dist/types.d.ts +48 -0
- package/graph-viewer/dist/types.d.ts.map +1 -0
- package/graph-viewer/dist/types.js +2 -0
- package/graph-viewer/dist/types.js.map +1 -0
- package/graph-viewer/public/app.js +525 -0
- package/graph-viewer/public/index.html +68 -0
- package/graph-viewer/public/style.css +68 -0
- package/package.json +73 -0
- package/skills/aceclaw/SKILL.md +173 -0
- package/skills/agent-wiki/SKILL.md +184 -0
- package/skills/agent-wiki/references/tools-reference.md +368 -0
|
@@ -0,0 +1,1881 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for agent-wiki core engine.
|
|
3
|
+
*
|
|
4
|
+
* Covers: init, config, raw layer (add/list/read/verify), wiki CRUD,
|
|
5
|
+
* search, lint, classify, synthesize, schemas, log, index, timeline.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
8
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { Wiki, safePath } from "./wiki.js";
|
|
12
|
+
/** Helper: rawAdd for single file — asserts non-array return. */
|
|
13
|
+
function rawAddOne(wiki, filename, opts) {
|
|
14
|
+
const result = wiki.rawAdd(filename, opts);
|
|
15
|
+
if (Array.isArray(result))
|
|
16
|
+
throw new Error("Expected single RawDocument, got array");
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
// ── Test helpers ─────────────────────────────────────────────────
|
|
20
|
+
const TEST_ROOT = join(import.meta.dirname ?? ".", "__test_workspace__");
|
|
21
|
+
function freshWiki(workspace) {
|
|
22
|
+
return Wiki.init(TEST_ROOT, workspace);
|
|
23
|
+
}
|
|
24
|
+
function cleanUp() {
|
|
25
|
+
if (existsSync(TEST_ROOT)) {
|
|
26
|
+
rmSync(TEST_ROOT, { recursive: true, force: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
30
|
+
// INIT & CONFIG
|
|
31
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
32
|
+
describe("Wiki.init", () => {
|
|
33
|
+
beforeEach(cleanUp);
|
|
34
|
+
afterEach(cleanUp);
|
|
35
|
+
it("creates wiki/, raw/, schemas/ directories", () => {
|
|
36
|
+
freshWiki();
|
|
37
|
+
expect(existsSync(join(TEST_ROOT, "wiki"))).toBe(true);
|
|
38
|
+
expect(existsSync(join(TEST_ROOT, "raw"))).toBe(true);
|
|
39
|
+
expect(existsSync(join(TEST_ROOT, "schemas"))).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it("creates default system pages (index, log, timeline)", () => {
|
|
42
|
+
freshWiki();
|
|
43
|
+
expect(existsSync(join(TEST_ROOT, "wiki", "index.md"))).toBe(true);
|
|
44
|
+
expect(existsSync(join(TEST_ROOT, "wiki", "log.md"))).toBe(true);
|
|
45
|
+
expect(existsSync(join(TEST_ROOT, "wiki", "timeline.md"))).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it("creates .agent-wiki.yaml config", () => {
|
|
48
|
+
freshWiki();
|
|
49
|
+
expect(existsSync(join(TEST_ROOT, ".agent-wiki.yaml"))).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
it("creates default schema templates", () => {
|
|
52
|
+
freshWiki();
|
|
53
|
+
const schemasDir = join(TEST_ROOT, "schemas");
|
|
54
|
+
for (const name of ["person", "concept", "event", "artifact", "comparison", "summary", "how-to", "note", "synthesis"]) {
|
|
55
|
+
expect(existsSync(join(schemasDir, `${name}.md`))).toBe(true);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
it("creates .gitignore", () => {
|
|
59
|
+
freshWiki();
|
|
60
|
+
expect(existsSync(join(TEST_ROOT, ".gitignore"))).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("Wiki.init with separate workspace", () => {
|
|
64
|
+
const wsDir = join(TEST_ROOT, "data");
|
|
65
|
+
beforeEach(cleanUp);
|
|
66
|
+
afterEach(cleanUp);
|
|
67
|
+
it("puts data in workspace dir, config in root", () => {
|
|
68
|
+
Wiki.init(TEST_ROOT, wsDir);
|
|
69
|
+
expect(existsSync(join(TEST_ROOT, ".agent-wiki.yaml"))).toBe(true);
|
|
70
|
+
expect(existsSync(join(wsDir, "wiki"))).toBe(true);
|
|
71
|
+
expect(existsSync(join(wsDir, "raw"))).toBe(true);
|
|
72
|
+
expect(existsSync(join(wsDir, "schemas"))).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
it("creates .gitignore in workspace too", () => {
|
|
75
|
+
Wiki.init(TEST_ROOT, wsDir);
|
|
76
|
+
expect(existsSync(join(wsDir, ".gitignore"))).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("Wiki.loadConfig", () => {
|
|
80
|
+
beforeEach(cleanUp);
|
|
81
|
+
afterEach(cleanUp);
|
|
82
|
+
it("loads config from .agent-wiki.yaml", () => {
|
|
83
|
+
const wiki = freshWiki();
|
|
84
|
+
const cfg = wiki.config;
|
|
85
|
+
expect(cfg.configRoot).toBe(TEST_ROOT);
|
|
86
|
+
expect(cfg.wikiDir).toContain("wiki");
|
|
87
|
+
expect(cfg.rawDir).toContain("raw");
|
|
88
|
+
expect(cfg.schemasDir).toContain("schemas");
|
|
89
|
+
});
|
|
90
|
+
it("has default lint settings", () => {
|
|
91
|
+
const wiki = freshWiki();
|
|
92
|
+
expect(wiki.config.lint.checkOrphans).toBe(true);
|
|
93
|
+
expect(wiki.config.lint.checkStaleDays).toBe(30);
|
|
94
|
+
expect(wiki.config.lint.checkMissingSources).toBe(true);
|
|
95
|
+
expect(wiki.config.lint.checkContradictions).toBe(true);
|
|
96
|
+
expect(wiki.config.lint.checkIntegrity).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
it("workspace override takes priority over config", () => {
|
|
99
|
+
const wsDir = join(TEST_ROOT, "override_ws");
|
|
100
|
+
Wiki.init(TEST_ROOT);
|
|
101
|
+
const wiki = new Wiki(TEST_ROOT, wsDir);
|
|
102
|
+
expect(wiki.config.workspace).toBe(wsDir);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
106
|
+
// RAW LAYER
|
|
107
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
108
|
+
describe("rawAdd", () => {
|
|
109
|
+
beforeEach(cleanUp);
|
|
110
|
+
afterEach(cleanUp);
|
|
111
|
+
it("adds a text file with content", () => {
|
|
112
|
+
const wiki = freshWiki();
|
|
113
|
+
const doc = rawAddOne(wiki, "test.md", { content: "Hello world" });
|
|
114
|
+
expect(doc.path).toBe("test.md");
|
|
115
|
+
expect(doc.size).toBeGreaterThan(0);
|
|
116
|
+
expect(doc.sha256).toHaveLength(64);
|
|
117
|
+
expect(doc.mimeType).toBe("text/markdown");
|
|
118
|
+
});
|
|
119
|
+
it("creates .meta.yaml sidecar", () => {
|
|
120
|
+
const wiki = freshWiki();
|
|
121
|
+
wiki.rawAdd("data.json", { content: '{"key": "value"}' });
|
|
122
|
+
expect(existsSync(join(wiki.config.rawDir, "data.json.meta.yaml"))).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
it("stores correct SHA-256 hash", () => {
|
|
125
|
+
const wiki = freshWiki();
|
|
126
|
+
const content = "Test content for hashing";
|
|
127
|
+
const doc = rawAddOne(wiki, "hash-test.txt", { content });
|
|
128
|
+
const expected = createHash("sha256").update(content).digest("hex");
|
|
129
|
+
expect(doc.sha256).toBe(expected);
|
|
130
|
+
});
|
|
131
|
+
it("rejects duplicate filenames (immutability)", () => {
|
|
132
|
+
const wiki = freshWiki();
|
|
133
|
+
wiki.rawAdd("once.txt", { content: "first" });
|
|
134
|
+
expect(() => wiki.rawAdd("once.txt", { content: "second" }))
|
|
135
|
+
.toThrow(/immutable/i);
|
|
136
|
+
});
|
|
137
|
+
it("requires content or sourcePath", () => {
|
|
138
|
+
const wiki = freshWiki();
|
|
139
|
+
expect(() => wiki.rawAdd("empty.txt", {}))
|
|
140
|
+
.toThrow(/content|sourcePath/i);
|
|
141
|
+
});
|
|
142
|
+
it("accepts sourcePath (file copy)", () => {
|
|
143
|
+
const wiki = freshWiki();
|
|
144
|
+
const srcFile = join(TEST_ROOT, "src_file.txt");
|
|
145
|
+
writeFileSync(srcFile, "copied content");
|
|
146
|
+
const doc = rawAddOne(wiki, "copied.txt", { sourcePath: srcFile });
|
|
147
|
+
expect(doc.size).toBeGreaterThan(0);
|
|
148
|
+
const stored = readFileSync(join(wiki.config.rawDir, "copied.txt"), "utf-8");
|
|
149
|
+
expect(stored).toBe("copied content");
|
|
150
|
+
});
|
|
151
|
+
it("stores optional metadata (sourceUrl, description, tags)", () => {
|
|
152
|
+
const wiki = freshWiki();
|
|
153
|
+
const doc = rawAddOne(wiki, "meta.txt", {
|
|
154
|
+
content: "x",
|
|
155
|
+
sourceUrl: "https://example.com",
|
|
156
|
+
description: "A test file",
|
|
157
|
+
tags: ["test", "demo"],
|
|
158
|
+
});
|
|
159
|
+
expect(doc.sourceUrl).toBe("https://example.com");
|
|
160
|
+
expect(doc.description).toBe("A test file");
|
|
161
|
+
expect(doc.tags).toEqual(["test", "demo"]);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
describe("rawAdd with autoVersion", () => {
|
|
165
|
+
beforeEach(cleanUp);
|
|
166
|
+
afterEach(cleanUp);
|
|
167
|
+
it("auto-versions when file already exists", () => {
|
|
168
|
+
const wiki = freshWiki();
|
|
169
|
+
wiki.rawAdd("report.xlsx", { content: "v1 data" });
|
|
170
|
+
const doc2 = rawAddOne(wiki, "report.xlsx", { content: "v2 data", autoVersion: true });
|
|
171
|
+
expect(doc2.path).toBe("report_v2.xlsx");
|
|
172
|
+
});
|
|
173
|
+
it("increments to v3 when v2 exists", () => {
|
|
174
|
+
const wiki = freshWiki();
|
|
175
|
+
wiki.rawAdd("report.xlsx", { content: "v1" });
|
|
176
|
+
wiki.rawAdd("report.xlsx", { content: "v2", autoVersion: true });
|
|
177
|
+
const doc3 = rawAddOne(wiki, "report.xlsx", { content: "v3", autoVersion: true });
|
|
178
|
+
expect(doc3.path).toBe("report_v3.xlsx");
|
|
179
|
+
});
|
|
180
|
+
it("creates v1 normally when file does not exist", () => {
|
|
181
|
+
const wiki = freshWiki();
|
|
182
|
+
const doc = rawAddOne(wiki, "new-file.xlsx", { content: "first", autoVersion: true });
|
|
183
|
+
expect(doc.path).toBe("new-file.xlsx");
|
|
184
|
+
});
|
|
185
|
+
it("still rejects duplicates without autoVersion", () => {
|
|
186
|
+
const wiki = freshWiki();
|
|
187
|
+
wiki.rawAdd("once.txt", { content: "first" });
|
|
188
|
+
expect(() => wiki.rawAdd("once.txt", { content: "second" })).toThrow(/immutable/i);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe("rawVersions", () => {
|
|
192
|
+
beforeEach(cleanUp);
|
|
193
|
+
afterEach(cleanUp);
|
|
194
|
+
it("returns empty for non-existent file", () => {
|
|
195
|
+
const wiki = freshWiki();
|
|
196
|
+
const result = wiki.rawVersions("nope.xlsx");
|
|
197
|
+
expect(result.versions).toEqual([]);
|
|
198
|
+
expect(result.latest).toBeNull();
|
|
199
|
+
});
|
|
200
|
+
it("lists single version with latest", () => {
|
|
201
|
+
const wiki = freshWiki();
|
|
202
|
+
wiki.rawAdd("report.xlsx", { content: "v1" });
|
|
203
|
+
const result = wiki.rawVersions("report.xlsx");
|
|
204
|
+
expect(result.versions).toHaveLength(1);
|
|
205
|
+
expect(result.versions[0].version).toBe(1);
|
|
206
|
+
expect(result.versions[0].path).toBe("report.xlsx");
|
|
207
|
+
expect(result.latest).toBe("report.xlsx");
|
|
208
|
+
});
|
|
209
|
+
it("lists multiple versions sorted with latest pointing to highest", () => {
|
|
210
|
+
const wiki = freshWiki();
|
|
211
|
+
wiki.rawAdd("report.xlsx", { content: "v1" });
|
|
212
|
+
wiki.rawAdd("report.xlsx", { content: "v2", autoVersion: true });
|
|
213
|
+
wiki.rawAdd("report.xlsx", { content: "v3", autoVersion: true });
|
|
214
|
+
const result = wiki.rawVersions("report.xlsx");
|
|
215
|
+
expect(result.versions).toHaveLength(3);
|
|
216
|
+
expect(result.versions[0].version).toBe(1);
|
|
217
|
+
expect(result.versions[1].version).toBe(2);
|
|
218
|
+
expect(result.versions[2].version).toBe(3);
|
|
219
|
+
expect(result.versions[0].path).toBe("report.xlsx");
|
|
220
|
+
expect(result.versions[1].path).toBe("report_v2.xlsx");
|
|
221
|
+
expect(result.versions[2].path).toBe("report_v3.xlsx");
|
|
222
|
+
expect(result.latest).toBe("report_v3.xlsx");
|
|
223
|
+
});
|
|
224
|
+
it("each version has metadata", () => {
|
|
225
|
+
const wiki = freshWiki();
|
|
226
|
+
wiki.rawAdd("data.csv", { content: "aaa" });
|
|
227
|
+
wiki.rawAdd("data.csv", { content: "bbb", autoVersion: true });
|
|
228
|
+
const result = wiki.rawVersions("data.csv");
|
|
229
|
+
for (const v of result.versions) {
|
|
230
|
+
expect(v.sha256).toHaveLength(64);
|
|
231
|
+
expect(v.size).toBeGreaterThan(0);
|
|
232
|
+
expect(v.downloadedAt).toBeTruthy();
|
|
233
|
+
}
|
|
234
|
+
expect(result.latest).toBe("data_v2.csv");
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
describe("rawAdd with directory", () => {
|
|
238
|
+
beforeEach(cleanUp);
|
|
239
|
+
afterEach(cleanUp);
|
|
240
|
+
it("imports all files from a directory", () => {
|
|
241
|
+
const wiki = freshWiki();
|
|
242
|
+
// Create a test directory with files inside the workspace
|
|
243
|
+
const srcDir = join(TEST_ROOT, "import-src");
|
|
244
|
+
mkdirSync(srcDir, { recursive: true });
|
|
245
|
+
writeFileSync(join(srcDir, "page1.html"), "<h1>Page 1</h1>");
|
|
246
|
+
writeFileSync(join(srcDir, "page2.html"), "<h1>Page 2</h1>");
|
|
247
|
+
writeFileSync(join(srcDir, "style.css"), "body {}");
|
|
248
|
+
const docs = wiki.rawAdd("my-docs", { sourcePath: srcDir });
|
|
249
|
+
expect(Array.isArray(docs)).toBe(true);
|
|
250
|
+
expect(docs.length).toBe(3);
|
|
251
|
+
expect(existsSync(join(wiki.config.rawDir, "my-docs", "page1.html"))).toBe(true);
|
|
252
|
+
expect(existsSync(join(wiki.config.rawDir, "my-docs", "page2.html"))).toBe(true);
|
|
253
|
+
expect(existsSync(join(wiki.config.rawDir, "my-docs", "style.css"))).toBe(true);
|
|
254
|
+
});
|
|
255
|
+
it("filters by pattern", () => {
|
|
256
|
+
const wiki = freshWiki();
|
|
257
|
+
const srcDir = join(TEST_ROOT, "import-filtered");
|
|
258
|
+
mkdirSync(srcDir, { recursive: true });
|
|
259
|
+
writeFileSync(join(srcDir, "page.html"), "<h1>Page</h1>");
|
|
260
|
+
writeFileSync(join(srcDir, "data.json"), "{}");
|
|
261
|
+
writeFileSync(join(srcDir, "style.css"), "body {}");
|
|
262
|
+
const docs = wiki.rawAdd("filtered", { sourcePath: srcDir, pattern: "*.html" });
|
|
263
|
+
expect(Array.isArray(docs)).toBe(true);
|
|
264
|
+
expect(docs.length).toBe(1);
|
|
265
|
+
expect(docs[0].path).toBe(join("filtered", "page.html"));
|
|
266
|
+
});
|
|
267
|
+
it("supports brace expansion pattern", () => {
|
|
268
|
+
const wiki = freshWiki();
|
|
269
|
+
const srcDir = join(TEST_ROOT, "import-brace");
|
|
270
|
+
mkdirSync(srcDir, { recursive: true });
|
|
271
|
+
writeFileSync(join(srcDir, "page.html"), "<h1>Page</h1>");
|
|
272
|
+
writeFileSync(join(srcDir, "style.css"), "body {}");
|
|
273
|
+
writeFileSync(join(srcDir, "data.json"), "{}");
|
|
274
|
+
const docs = wiki.rawAdd("brace", { sourcePath: srcDir, pattern: "*.{html,css}" });
|
|
275
|
+
expect(Array.isArray(docs)).toBe(true);
|
|
276
|
+
expect(docs.length).toBe(2);
|
|
277
|
+
});
|
|
278
|
+
it("preserves subdirectory structure", () => {
|
|
279
|
+
const wiki = freshWiki();
|
|
280
|
+
const srcDir = join(TEST_ROOT, "import-nested");
|
|
281
|
+
mkdirSync(join(srcDir, "sub"), { recursive: true });
|
|
282
|
+
writeFileSync(join(srcDir, "index.html"), "<h1>Root</h1>");
|
|
283
|
+
writeFileSync(join(srcDir, "sub", "child.html"), "<h1>Child</h1>");
|
|
284
|
+
const docs = wiki.rawAdd("nested", { sourcePath: srcDir });
|
|
285
|
+
expect(Array.isArray(docs)).toBe(true);
|
|
286
|
+
expect(docs.length).toBe(2);
|
|
287
|
+
expect(existsSync(join(wiki.config.rawDir, "nested", "index.html"))).toBe(true);
|
|
288
|
+
expect(existsSync(join(wiki.config.rawDir, "nested", "sub", "child.html"))).toBe(true);
|
|
289
|
+
});
|
|
290
|
+
it("throws when directory is empty", () => {
|
|
291
|
+
const wiki = freshWiki();
|
|
292
|
+
const srcDir = join(TEST_ROOT, "import-empty");
|
|
293
|
+
mkdirSync(srcDir, { recursive: true });
|
|
294
|
+
expect(() => wiki.rawAdd("empty", { sourcePath: srcDir }))
|
|
295
|
+
.toThrow(/no files found/i);
|
|
296
|
+
});
|
|
297
|
+
it("throws when pattern matches nothing", () => {
|
|
298
|
+
const wiki = freshWiki();
|
|
299
|
+
const srcDir = join(TEST_ROOT, "import-nomatch");
|
|
300
|
+
mkdirSync(srcDir, { recursive: true });
|
|
301
|
+
writeFileSync(join(srcDir, "data.json"), "{}");
|
|
302
|
+
expect(() => wiki.rawAdd("nomatch", { sourcePath: srcDir, pattern: "*.html" }))
|
|
303
|
+
.toThrow(/no files found.*\*\.html/i);
|
|
304
|
+
});
|
|
305
|
+
it("respects security for directory imports", () => {
|
|
306
|
+
const wiki = freshWiki();
|
|
307
|
+
const outsideDir = join(TEST_ROOT, "..", "__outside_dir__");
|
|
308
|
+
mkdirSync(outsideDir, { recursive: true });
|
|
309
|
+
writeFileSync(join(outsideDir, "secret.txt"), "no");
|
|
310
|
+
try {
|
|
311
|
+
expect(() => wiki.rawAdd("stolen", { sourcePath: outsideDir }))
|
|
312
|
+
.toThrow(/outside allowed directories/i);
|
|
313
|
+
}
|
|
314
|
+
finally {
|
|
315
|
+
rmSync(outsideDir, { recursive: true, force: true });
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
it("generates metadata sidecar for each imported file", () => {
|
|
319
|
+
const wiki = freshWiki();
|
|
320
|
+
const srcDir = join(TEST_ROOT, "import-meta");
|
|
321
|
+
mkdirSync(srcDir, { recursive: true });
|
|
322
|
+
writeFileSync(join(srcDir, "a.txt"), "hello");
|
|
323
|
+
writeFileSync(join(srcDir, "b.txt"), "world");
|
|
324
|
+
wiki.rawAdd("meta-dir", { sourcePath: srcDir, tags: ["test"] });
|
|
325
|
+
expect(existsSync(join(wiki.config.rawDir, "meta-dir", "a.txt.meta.yaml"))).toBe(true);
|
|
326
|
+
expect(existsSync(join(wiki.config.rawDir, "meta-dir", "b.txt.meta.yaml"))).toBe(true);
|
|
327
|
+
});
|
|
328
|
+
it("single file still works with sourcePath", () => {
|
|
329
|
+
const wiki = freshWiki();
|
|
330
|
+
const srcFile = join(TEST_ROOT, "single.txt");
|
|
331
|
+
writeFileSync(srcFile, "just a file");
|
|
332
|
+
const doc = wiki.rawAdd("single.txt", { sourcePath: srcFile });
|
|
333
|
+
expect(Array.isArray(doc)).toBe(false);
|
|
334
|
+
expect(doc.path).toBe("single.txt");
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
describe("rawList", () => {
|
|
338
|
+
beforeEach(cleanUp);
|
|
339
|
+
afterEach(cleanUp);
|
|
340
|
+
it("returns empty array when no raw files", () => {
|
|
341
|
+
const wiki = freshWiki();
|
|
342
|
+
expect(wiki.rawList()).toEqual([]);
|
|
343
|
+
});
|
|
344
|
+
it("lists added raw documents", () => {
|
|
345
|
+
const wiki = freshWiki();
|
|
346
|
+
wiki.rawAdd("a.txt", { content: "aaa" });
|
|
347
|
+
wiki.rawAdd("b.md", { content: "bbb" });
|
|
348
|
+
const docs = wiki.rawList();
|
|
349
|
+
expect(docs).toHaveLength(2);
|
|
350
|
+
expect(docs.map(d => d.path).sort()).toEqual(["a.txt", "b.md"]);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
describe("rawCoverage", () => {
|
|
354
|
+
beforeEach(cleanUp);
|
|
355
|
+
afterEach(cleanUp);
|
|
356
|
+
it("reports full coverage when all raw files are referenced via frontmatter", () => {
|
|
357
|
+
const wiki = freshWiki();
|
|
358
|
+
wiki.rawAdd("paper.pdf", { content: "pdf bytes" });
|
|
359
|
+
wiki.rawAdd("notes.md", { content: "notes" });
|
|
360
|
+
wiki.write("concept-x.md", "---\ntitle: X\ntype: concept\nsources: [raw/paper.pdf, notes.md]\n---\nBody");
|
|
361
|
+
const r = wiki.rawCoverage();
|
|
362
|
+
expect(r.totalRaw).toBe(2);
|
|
363
|
+
expect(r.coveredRaw).toBe(2);
|
|
364
|
+
expect(r.uncoveredRaw).toBe(0);
|
|
365
|
+
expect(r.coverageRatio).toBe(1);
|
|
366
|
+
expect(r.uncovered).toEqual([]);
|
|
367
|
+
});
|
|
368
|
+
it("lists uncovered raw files", () => {
|
|
369
|
+
const wiki = freshWiki();
|
|
370
|
+
wiki.rawAdd("covered.pdf", { content: "x" });
|
|
371
|
+
wiki.rawAdd("orphan-a.pdf", { content: "y" });
|
|
372
|
+
wiki.rawAdd("orphan-b.txt", { content: "z" });
|
|
373
|
+
wiki.write("p.md", "---\ntitle: P\ntype: concept\nsources: [raw/covered.pdf]\n---\n");
|
|
374
|
+
const r = wiki.rawCoverage();
|
|
375
|
+
expect(r.totalRaw).toBe(3);
|
|
376
|
+
expect(r.coveredRaw).toBe(1);
|
|
377
|
+
expect(r.uncoveredRaw).toBe(2);
|
|
378
|
+
expect(r.uncovered.map(u => u.path).sort()).toEqual(["orphan-a.pdf", "orphan-b.txt"]);
|
|
379
|
+
});
|
|
380
|
+
it("matches inline body references to raw/", () => {
|
|
381
|
+
const wiki = freshWiki();
|
|
382
|
+
wiki.rawAdd("inline.pdf", { content: "x" });
|
|
383
|
+
wiki.write("p.md", "---\ntitle: P\ntype: concept\n---\nSee raw/inline.pdf for details.");
|
|
384
|
+
const r = wiki.rawCoverage();
|
|
385
|
+
expect(r.uncoveredRaw).toBe(0);
|
|
386
|
+
});
|
|
387
|
+
it("strips trailing punctuation from inline raw/ references", () => {
|
|
388
|
+
const wiki = freshWiki();
|
|
389
|
+
wiki.rawAdd("a.pdf", { content: "a" });
|
|
390
|
+
wiki.rawAdd("b.pdf", { content: "b" });
|
|
391
|
+
wiki.rawAdd("c.md", { content: "c" });
|
|
392
|
+
wiki.write("p.md", "---\ntitle: P\ntype: concept\n---\nSee raw/a.pdf, raw/b.pdf. And raw/c.md:");
|
|
393
|
+
const r = wiki.rawCoverage();
|
|
394
|
+
expect(r.uncoveredRaw).toBe(0);
|
|
395
|
+
});
|
|
396
|
+
it("matches by sourceUrl when frontmatter source is a URL", () => {
|
|
397
|
+
const wiki = freshWiki();
|
|
398
|
+
wiki.rawAdd("article.md", { content: "x", sourceUrl: "https://example.com/article" });
|
|
399
|
+
wiki.write("p.md", "---\ntitle: P\ntype: concept\nsources: [https://example.com/article]\n---\n");
|
|
400
|
+
const r = wiki.rawCoverage();
|
|
401
|
+
expect(r.coveredRaw).toBe(1);
|
|
402
|
+
expect(r.uncoveredRaw).toBe(0);
|
|
403
|
+
});
|
|
404
|
+
it("matches URLs that differ only by trailing slash or scheme/host case", () => {
|
|
405
|
+
const wiki = freshWiki();
|
|
406
|
+
wiki.rawAdd("a.md", { content: "a", sourceUrl: "https://Example.com/Article/" });
|
|
407
|
+
wiki.rawAdd("b.md", { content: "b", sourceUrl: "https://example.com/other" });
|
|
408
|
+
wiki.write("p.md", "---\ntitle: P\ntype: concept\nsources: [https://example.com/Article, HTTPS://example.com/other/]\n---\n");
|
|
409
|
+
const r = wiki.rawCoverage();
|
|
410
|
+
expect(r.coveredRaw).toBe(2);
|
|
411
|
+
expect(r.uncoveredRaw).toBe(0);
|
|
412
|
+
});
|
|
413
|
+
it("excludes raw/parsed/ artifacts from coverage", () => {
|
|
414
|
+
const wiki = freshWiki();
|
|
415
|
+
wiki.rawAdd("source.cbl", { content: "PROGRAM-ID. X." });
|
|
416
|
+
// Simulate a parsed artifact by writing directly under raw/parsed/
|
|
417
|
+
const parsedDir = join(wiki.config.rawDir, "parsed", "cobol");
|
|
418
|
+
mkdirSync(parsedDir, { recursive: true });
|
|
419
|
+
writeFileSync(join(parsedDir, "X.ast.json"), "{}");
|
|
420
|
+
wiki.write("p.md", "---\ntitle: P\ntype: concept\nsources: [raw/source.cbl]\n---\n");
|
|
421
|
+
const r = wiki.rawCoverage();
|
|
422
|
+
expect(r.totalRaw).toBe(1);
|
|
423
|
+
expect(r.uncoveredRaw).toBe(0);
|
|
424
|
+
});
|
|
425
|
+
it("respects limit and sets truncated flag", () => {
|
|
426
|
+
const wiki = freshWiki();
|
|
427
|
+
for (let i = 0; i < 5; i++)
|
|
428
|
+
wiki.rawAdd(`f${i}.txt`, { content: String(i) });
|
|
429
|
+
const r = wiki.rawCoverage({ limit: 2 });
|
|
430
|
+
expect(r.uncoveredRaw).toBe(5);
|
|
431
|
+
expect(r.uncovered).toHaveLength(2);
|
|
432
|
+
expect(r.truncated).toBe(true);
|
|
433
|
+
});
|
|
434
|
+
it("sorts by largest when requested", () => {
|
|
435
|
+
const wiki = freshWiki();
|
|
436
|
+
wiki.rawAdd("small.txt", { content: "a" });
|
|
437
|
+
wiki.rawAdd("big.txt", { content: "a".repeat(1000) });
|
|
438
|
+
wiki.rawAdd("medium.txt", { content: "a".repeat(100) });
|
|
439
|
+
const r = wiki.rawCoverage({ sort: "largest" });
|
|
440
|
+
expect(r.uncovered.map(u => u.path)).toEqual(["big.txt", "medium.txt", "small.txt"]);
|
|
441
|
+
});
|
|
442
|
+
it("filters by tag", () => {
|
|
443
|
+
const wiki = freshWiki();
|
|
444
|
+
wiki.rawAdd("tagged.txt", { content: "x", tags: ["keep"] });
|
|
445
|
+
wiki.rawAdd("untagged.txt", { content: "y" });
|
|
446
|
+
const r = wiki.rawCoverage({ tag: "keep" });
|
|
447
|
+
expect(r.totalRaw).toBe(1);
|
|
448
|
+
expect(r.uncovered.map(u => u.path)).toEqual(["tagged.txt"]);
|
|
449
|
+
});
|
|
450
|
+
it("returns coverageRatio 1 on empty raw/", () => {
|
|
451
|
+
const wiki = freshWiki();
|
|
452
|
+
const r = wiki.rawCoverage();
|
|
453
|
+
expect(r.totalRaw).toBe(0);
|
|
454
|
+
expect(r.coverageRatio).toBe(1);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
describe("rawRead", () => {
|
|
458
|
+
beforeEach(cleanUp);
|
|
459
|
+
afterEach(cleanUp);
|
|
460
|
+
it("reads text file content", async () => {
|
|
461
|
+
const wiki = freshWiki();
|
|
462
|
+
wiki.rawAdd("readme.md", { content: "# Hello" });
|
|
463
|
+
const result = await wiki.rawRead("readme.md");
|
|
464
|
+
expect(result).not.toBeNull();
|
|
465
|
+
expect(result.binary).toBe(false);
|
|
466
|
+
expect(result.content).toBe("# Hello");
|
|
467
|
+
expect(result.meta).not.toBeNull();
|
|
468
|
+
});
|
|
469
|
+
it("returns null for non-existent file", async () => {
|
|
470
|
+
const wiki = freshWiki();
|
|
471
|
+
const result = await wiki.rawRead("nonexistent.md");
|
|
472
|
+
expect(result).toBeNull();
|
|
473
|
+
});
|
|
474
|
+
it("handles JSON as text", async () => {
|
|
475
|
+
const wiki = freshWiki();
|
|
476
|
+
wiki.rawAdd("data.json", { content: '{"x":1}' });
|
|
477
|
+
const result = await wiki.rawRead("data.json");
|
|
478
|
+
expect(result.binary).toBe(false);
|
|
479
|
+
expect(result.content).toBe('{"x":1}');
|
|
480
|
+
});
|
|
481
|
+
it("returns binary=true with imageData for image files", async () => {
|
|
482
|
+
const wiki = freshWiki();
|
|
483
|
+
// Write a fake PNG (just bytes, not a real image)
|
|
484
|
+
const rawPath = join(wiki.config.rawDir, "photo.png");
|
|
485
|
+
const imageBytes = Buffer.from([0x89, 0x50, 0x4e, 0x47]);
|
|
486
|
+
writeFileSync(rawPath, imageBytes);
|
|
487
|
+
writeFileSync(rawPath + ".meta.yaml", `path: photo.png\ndownloadedAt: "2024-01-01"\nsha256: abcd\nsize: 4\nmimeType: image/png\n`);
|
|
488
|
+
const result = await wiki.rawRead("photo.png");
|
|
489
|
+
expect(result.binary).toBe(true);
|
|
490
|
+
expect(result.content).toBeNull();
|
|
491
|
+
expect(result.imageData).toBeDefined();
|
|
492
|
+
expect(result.imageData.mimeType).toBe("image/png");
|
|
493
|
+
expect(result.imageData.data).toBe(imageBytes.toString("base64"));
|
|
494
|
+
});
|
|
495
|
+
it("returns note for oversized image files", async () => {
|
|
496
|
+
const wiki = freshWiki();
|
|
497
|
+
const rawPath = join(wiki.config.rawDir, "big.jpg");
|
|
498
|
+
// Write a minimal file but fake the size in meta to exceed 10MB
|
|
499
|
+
writeFileSync(rawPath, Buffer.from([0xff, 0xd8]));
|
|
500
|
+
const bigSize = 11 * 1024 * 1024;
|
|
501
|
+
writeFileSync(rawPath + ".meta.yaml", `path: big.jpg\ndownloadedAt: "2024-01-01"\nsha256: abcd\nsize: ${bigSize}\nmimeType: image/jpeg\n`);
|
|
502
|
+
// Overwrite with actual large buffer to trigger size check
|
|
503
|
+
writeFileSync(rawPath, Buffer.alloc(bigSize));
|
|
504
|
+
const result = await wiki.rawRead("big.jpg");
|
|
505
|
+
expect(result.binary).toBe(true);
|
|
506
|
+
expect(result.imageData).toBeUndefined();
|
|
507
|
+
expect(result.note).toMatch(/too large/i);
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
// ── PDF extraction & pages parameter ──────────────────────────────
|
|
511
|
+
/** Generate a minimal valid PDF with N pages, each containing "Page X" text. */
|
|
512
|
+
function makePdf(numPages) {
|
|
513
|
+
const objects = [];
|
|
514
|
+
let objNum = 1;
|
|
515
|
+
const catalogNum = objNum++;
|
|
516
|
+
const pagesNum = objNum++;
|
|
517
|
+
const fontNum = objNum++;
|
|
518
|
+
const pageNums = [];
|
|
519
|
+
const contentNums = [];
|
|
520
|
+
for (let i = 0; i < numPages; i++) {
|
|
521
|
+
pageNums.push(objNum++);
|
|
522
|
+
contentNums.push(objNum++);
|
|
523
|
+
}
|
|
524
|
+
objects.push({ num: catalogNum, body: `<< /Type /Catalog /Pages ${pagesNum} 0 R >>` });
|
|
525
|
+
objects.push({ num: pagesNum, body: `<< /Type /Pages /Kids [${pageNums.map(n => n + " 0 R").join(" ")}] /Count ${numPages} >>` });
|
|
526
|
+
objects.push({ num: fontNum, body: `<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>` });
|
|
527
|
+
for (let i = 0; i < numPages; i++) {
|
|
528
|
+
const text = `Page ${i + 1}`;
|
|
529
|
+
const stream = `BT /F1 12 Tf 100 700 Td (${text}) Tj ET`;
|
|
530
|
+
objects.push({ num: pageNums[i], body: `<< /Type /Page /Parent ${pagesNum} 0 R /MediaBox [0 0 612 792] /Contents ${contentNums[i]} 0 R /Resources << /Font << /F1 ${fontNum} 0 R >> >> >>` });
|
|
531
|
+
objects.push({ num: contentNums[i], body: `<< /Length ${stream.length} >>\nstream\n${stream}\nendstream` });
|
|
532
|
+
}
|
|
533
|
+
objects.sort((a, b) => a.num - b.num);
|
|
534
|
+
let pdf = "%PDF-1.4\n";
|
|
535
|
+
const offsets = [];
|
|
536
|
+
for (const obj of objects) {
|
|
537
|
+
offsets.push({ num: obj.num, offset: pdf.length });
|
|
538
|
+
pdf += `${obj.num} 0 obj\n${obj.body}\nendobj\n`;
|
|
539
|
+
}
|
|
540
|
+
const xrefOffset = pdf.length;
|
|
541
|
+
pdf += `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`;
|
|
542
|
+
for (const { offset } of offsets) {
|
|
543
|
+
pdf += `${String(offset).padStart(10, "0")} 00000 n \n`;
|
|
544
|
+
}
|
|
545
|
+
pdf += `trailer\n<< /Size ${objects.length + 1} /Root ${catalogNum} 0 R >>\nstartxref\n${xrefOffset}\n%%EOF\n`;
|
|
546
|
+
return Buffer.from(pdf, "binary");
|
|
547
|
+
}
|
|
548
|
+
/** Write a synthetic PDF into the wiki's raw/ directory with a .meta.yaml sidecar. */
|
|
549
|
+
function placePdf(wiki, filename, numPages) {
|
|
550
|
+
const buf = makePdf(numPages);
|
|
551
|
+
const rawPath = join(wiki.config.rawDir, filename);
|
|
552
|
+
writeFileSync(rawPath, buf);
|
|
553
|
+
const sha = createHash("sha256").update(buf).digest("hex");
|
|
554
|
+
writeFileSync(rawPath + ".meta.yaml", `path: ${filename}\ndownloadedAt: "2024-01-01"\nsha256: ${sha}\nsize: ${buf.length}\nmimeType: application/pdf\n`);
|
|
555
|
+
}
|
|
556
|
+
describe("rawRead — PDF extraction", () => {
|
|
557
|
+
beforeEach(cleanUp);
|
|
558
|
+
afterEach(cleanUp);
|
|
559
|
+
it("extracts text from a small PDF", async () => {
|
|
560
|
+
const wiki = freshWiki();
|
|
561
|
+
placePdf(wiki, "small.pdf", 3);
|
|
562
|
+
const result = await wiki.rawRead("small.pdf");
|
|
563
|
+
expect(result).not.toBeNull();
|
|
564
|
+
expect(result.binary).toBe(false);
|
|
565
|
+
expect(result.content).toContain("Page 1");
|
|
566
|
+
expect(result.content).toContain("Page 2");
|
|
567
|
+
expect(result.content).toContain("Page 3");
|
|
568
|
+
});
|
|
569
|
+
it("extracts specific pages with pages parameter", async () => {
|
|
570
|
+
const wiki = freshWiki();
|
|
571
|
+
placePdf(wiki, "multi.pdf", 5);
|
|
572
|
+
const result = await wiki.rawRead("multi.pdf", { pages: "2-3" });
|
|
573
|
+
expect(result.binary).toBe(false);
|
|
574
|
+
expect(result.content).toContain("Page 2");
|
|
575
|
+
expect(result.content).toContain("Page 3");
|
|
576
|
+
expect(result.content).not.toContain("Page 1");
|
|
577
|
+
expect(result.content).not.toContain("Page 4");
|
|
578
|
+
expect(result.content).not.toContain("Page 5");
|
|
579
|
+
});
|
|
580
|
+
it("extracts a single page with pages parameter", async () => {
|
|
581
|
+
const wiki = freshWiki();
|
|
582
|
+
placePdf(wiki, "single.pdf", 5);
|
|
583
|
+
const result = await wiki.rawRead("single.pdf", { pages: "3" });
|
|
584
|
+
expect(result.binary).toBe(false);
|
|
585
|
+
expect(result.content).toContain("Page 3");
|
|
586
|
+
expect(result.content).not.toContain("Page 1");
|
|
587
|
+
expect(result.content).not.toContain("Page 5");
|
|
588
|
+
});
|
|
589
|
+
it("supports comma-separated page ranges", async () => {
|
|
590
|
+
const wiki = freshWiki();
|
|
591
|
+
placePdf(wiki, "combo.pdf", 10);
|
|
592
|
+
const result = await wiki.rawRead("combo.pdf", { pages: "1-2,5,8-9" });
|
|
593
|
+
expect(result.binary).toBe(false);
|
|
594
|
+
for (const p of [1, 2, 5, 8, 9]) {
|
|
595
|
+
expect(result.content).toContain(`Page ${p}`);
|
|
596
|
+
}
|
|
597
|
+
for (const p of [3, 4, 6, 7, 10]) {
|
|
598
|
+
expect(result.content).not.toContain(`Page ${p}`);
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
it("returns 'no pages matched' for out-of-range page", async () => {
|
|
602
|
+
const wiki = freshWiki();
|
|
603
|
+
placePdf(wiki, "bounds.pdf", 3);
|
|
604
|
+
const result = await wiki.rawRead("bounds.pdf", { pages: "999" });
|
|
605
|
+
expect(result.binary).toBe(false);
|
|
606
|
+
expect(result.content).toContain("no pages matched");
|
|
607
|
+
});
|
|
608
|
+
it("clamps range end beyond total pages", async () => {
|
|
609
|
+
const wiki = freshWiki();
|
|
610
|
+
placePdf(wiki, "clamp.pdf", 3);
|
|
611
|
+
const result = await wiki.rawRead("clamp.pdf", { pages: "2-100" });
|
|
612
|
+
expect(result.binary).toBe(false);
|
|
613
|
+
expect(result.content).toContain("Page 2");
|
|
614
|
+
expect(result.content).toContain("Page 3");
|
|
615
|
+
expect(result.content).not.toContain("Page 1");
|
|
616
|
+
});
|
|
617
|
+
it("returns 'no pages matched' for completely invalid range", async () => {
|
|
618
|
+
const wiki = freshWiki();
|
|
619
|
+
placePdf(wiki, "invalid.pdf", 3);
|
|
620
|
+
const result = await wiki.rawRead("invalid.pdf", { pages: "abc" });
|
|
621
|
+
expect(result.binary).toBe(false);
|
|
622
|
+
expect(result.content).toContain("no pages matched");
|
|
623
|
+
});
|
|
624
|
+
it("includes page header when pages parameter is used", async () => {
|
|
625
|
+
const wiki = freshWiki();
|
|
626
|
+
placePdf(wiki, "header.pdf", 5);
|
|
627
|
+
const result = await wiki.rawRead("header.pdf", { pages: "1-2" });
|
|
628
|
+
expect(result.content).toMatch(/\[Pages 1-2 of 5\]/);
|
|
629
|
+
});
|
|
630
|
+
it("omits page header when reading all pages", async () => {
|
|
631
|
+
const wiki = freshWiki();
|
|
632
|
+
placePdf(wiki, "noheader.pdf", 3);
|
|
633
|
+
const result = await wiki.rawRead("noheader.pdf");
|
|
634
|
+
expect(result.content).not.toContain("[Pages");
|
|
635
|
+
});
|
|
636
|
+
it("extracts all pages from a 25-page PDF without pages parameter", async () => {
|
|
637
|
+
const wiki = freshWiki();
|
|
638
|
+
placePdf(wiki, "large.pdf", 25);
|
|
639
|
+
const result = await wiki.rawRead("large.pdf");
|
|
640
|
+
expect(result.binary).toBe(false);
|
|
641
|
+
for (let p = 1; p <= 25; p++) {
|
|
642
|
+
expect(result.content).toContain(`Page ${p}`);
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
it("preserves page ordering in output", async () => {
|
|
646
|
+
const wiki = freshWiki();
|
|
647
|
+
placePdf(wiki, "order.pdf", 5);
|
|
648
|
+
const result = await wiki.rawRead("order.pdf", { pages: "3,1,5" });
|
|
649
|
+
const content = result.content;
|
|
650
|
+
const pos1 = content.indexOf("Page 1");
|
|
651
|
+
const pos3 = content.indexOf("Page 3");
|
|
652
|
+
const pos5 = content.indexOf("Page 5");
|
|
653
|
+
// Pages should appear in ascending order regardless of input order
|
|
654
|
+
expect(pos1).toBeLessThan(pos3);
|
|
655
|
+
expect(pos3).toBeLessThan(pos5);
|
|
656
|
+
});
|
|
657
|
+
it("handles whitespace in page range", async () => {
|
|
658
|
+
const wiki = freshWiki();
|
|
659
|
+
placePdf(wiki, "ws.pdf", 5);
|
|
660
|
+
const result = await wiki.rawRead("ws.pdf", { pages: " 2 - 4 " });
|
|
661
|
+
expect(result.content).toContain("Page 2");
|
|
662
|
+
expect(result.content).toContain("Page 3");
|
|
663
|
+
expect(result.content).toContain("Page 4");
|
|
664
|
+
expect(result.content).not.toContain("Page 1");
|
|
665
|
+
expect(result.content).not.toContain("Page 5");
|
|
666
|
+
});
|
|
667
|
+
it("clamps page 0 to page 1", async () => {
|
|
668
|
+
const wiki = freshWiki();
|
|
669
|
+
placePdf(wiki, "zero.pdf", 3);
|
|
670
|
+
const result = await wiki.rawRead("zero.pdf", { pages: "0-2" });
|
|
671
|
+
expect(result.content).toContain("Page 1");
|
|
672
|
+
expect(result.content).toContain("Page 2");
|
|
673
|
+
});
|
|
674
|
+
it("pages parameter is ignored for non-PDF documents", async () => {
|
|
675
|
+
const wiki = freshWiki();
|
|
676
|
+
wiki.rawAdd("text.md", { content: "# Hello" });
|
|
677
|
+
const result = await wiki.rawRead("text.md", { pages: "1-2" });
|
|
678
|
+
expect(result.binary).toBe(false);
|
|
679
|
+
expect(result.content).toBe("# Hello");
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
describe("rawVerify", () => {
|
|
683
|
+
beforeEach(cleanUp);
|
|
684
|
+
afterEach(cleanUp);
|
|
685
|
+
it("returns empty for empty raw dir", () => {
|
|
686
|
+
const wiki = freshWiki();
|
|
687
|
+
expect(wiki.rawVerify()).toEqual([]);
|
|
688
|
+
});
|
|
689
|
+
it("reports ok for valid files", () => {
|
|
690
|
+
const wiki = freshWiki();
|
|
691
|
+
wiki.rawAdd("valid.txt", { content: "intact" });
|
|
692
|
+
const results = wiki.rawVerify();
|
|
693
|
+
expect(results).toHaveLength(1);
|
|
694
|
+
expect(results[0].status).toBe("ok");
|
|
695
|
+
});
|
|
696
|
+
it("detects corrupted files", () => {
|
|
697
|
+
const wiki = freshWiki();
|
|
698
|
+
wiki.rawAdd("tamper.txt", { content: "original" });
|
|
699
|
+
// Tamper with the file
|
|
700
|
+
writeFileSync(join(wiki.config.rawDir, "tamper.txt"), "modified!");
|
|
701
|
+
const results = wiki.rawVerify();
|
|
702
|
+
expect(results[0].status).toBe("corrupted");
|
|
703
|
+
});
|
|
704
|
+
it("detects missing metadata", () => {
|
|
705
|
+
const wiki = freshWiki();
|
|
706
|
+
// Write a raw file without using rawAdd (no meta sidecar)
|
|
707
|
+
writeFileSync(join(wiki.config.rawDir, "orphan.txt"), "no meta");
|
|
708
|
+
const results = wiki.rawVerify();
|
|
709
|
+
const orphan = results.find(r => r.path === "orphan.txt");
|
|
710
|
+
expect(orphan).toBeDefined();
|
|
711
|
+
expect(orphan.status).toBe("missing-meta");
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
715
|
+
// WIKI LAYER — CRUD
|
|
716
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
717
|
+
describe("wiki.write & wiki.read", () => {
|
|
718
|
+
beforeEach(cleanUp);
|
|
719
|
+
afterEach(cleanUp);
|
|
720
|
+
it("writes and reads a page with frontmatter", () => {
|
|
721
|
+
const wiki = freshWiki();
|
|
722
|
+
const content = `---
|
|
723
|
+
title: Test Page
|
|
724
|
+
type: concept
|
|
725
|
+
tags: [test, demo]
|
|
726
|
+
---
|
|
727
|
+
|
|
728
|
+
# Test Page
|
|
729
|
+
|
|
730
|
+
This is a test.
|
|
731
|
+
`;
|
|
732
|
+
wiki.write("concept-test.md", content);
|
|
733
|
+
const page = wiki.read("concept-test.md");
|
|
734
|
+
expect(page).not.toBeNull();
|
|
735
|
+
expect(page.title).toBe("Test Page");
|
|
736
|
+
expect(page.type).toBe("concept");
|
|
737
|
+
expect(page.tags).toEqual(["test", "demo"]);
|
|
738
|
+
expect(page.content).toContain("This is a test.");
|
|
739
|
+
});
|
|
740
|
+
it("auto-injects created/updated timestamps", () => {
|
|
741
|
+
const wiki = freshWiki();
|
|
742
|
+
wiki.write("timestamped.md", "---\ntitle: Time\n---\nBody");
|
|
743
|
+
const page = wiki.read("timestamped.md");
|
|
744
|
+
expect(page.created).toBeDefined();
|
|
745
|
+
expect(page.updated).toBeDefined();
|
|
746
|
+
});
|
|
747
|
+
it("preserves created time on update", () => {
|
|
748
|
+
const wiki = freshWiki();
|
|
749
|
+
wiki.write("update-me.md", "---\ntitle: V1\n---\nFirst version");
|
|
750
|
+
const v1 = wiki.read("update-me.md");
|
|
751
|
+
const created1 = v1.created;
|
|
752
|
+
// Wait a tick so timestamps differ
|
|
753
|
+
wiki.write("update-me.md", "---\ntitle: V2\n---\nSecond version");
|
|
754
|
+
const v2 = wiki.read("update-me.md");
|
|
755
|
+
expect(v2.created).toBe(created1);
|
|
756
|
+
expect(v2.title).toBe("V2");
|
|
757
|
+
});
|
|
758
|
+
it("returns null for non-existent page", () => {
|
|
759
|
+
const wiki = freshWiki();
|
|
760
|
+
expect(wiki.read("nonexistent.md")).toBeNull();
|
|
761
|
+
});
|
|
762
|
+
it("auto-appends .md when reading", () => {
|
|
763
|
+
const wiki = freshWiki();
|
|
764
|
+
wiki.write("auto-ext.md", "---\ntitle: Auto\n---\nBody");
|
|
765
|
+
const page = wiki.read("auto-ext");
|
|
766
|
+
expect(page).not.toBeNull();
|
|
767
|
+
expect(page.title).toBe("Auto");
|
|
768
|
+
});
|
|
769
|
+
it("extracts [[links]] from body", () => {
|
|
770
|
+
const wiki = freshWiki();
|
|
771
|
+
wiki.write("linker.md", "---\ntitle: Linker\n---\nSee [[concept-a]] and [[concept-b]].");
|
|
772
|
+
const page = wiki.read("linker.md");
|
|
773
|
+
expect(page.links).toEqual(["concept-a", "concept-b"]);
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
describe("wiki.delete", () => {
|
|
777
|
+
beforeEach(cleanUp);
|
|
778
|
+
afterEach(cleanUp);
|
|
779
|
+
it("deletes an existing page", () => {
|
|
780
|
+
const wiki = freshWiki();
|
|
781
|
+
wiki.write("to-delete.md", "---\ntitle: Delete Me\n---\nGone");
|
|
782
|
+
const existed = wiki.delete("to-delete.md");
|
|
783
|
+
expect(existed).toBe(true);
|
|
784
|
+
expect(wiki.read("to-delete.md")).toBeNull();
|
|
785
|
+
});
|
|
786
|
+
it("returns false for non-existent page", () => {
|
|
787
|
+
const wiki = freshWiki();
|
|
788
|
+
expect(wiki.delete("nope.md")).toBe(false);
|
|
789
|
+
});
|
|
790
|
+
it("refuses to delete system pages", () => {
|
|
791
|
+
const wiki = freshWiki();
|
|
792
|
+
expect(() => wiki.delete("index.md")).toThrow();
|
|
793
|
+
expect(() => wiki.delete("log.md")).toThrow();
|
|
794
|
+
expect(() => wiki.delete("timeline.md")).toThrow();
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
describe("wiki.list", () => {
|
|
798
|
+
beforeEach(cleanUp);
|
|
799
|
+
afterEach(cleanUp);
|
|
800
|
+
it("lists all non-system pages", () => {
|
|
801
|
+
const wiki = freshWiki();
|
|
802
|
+
wiki.write("concept-a.md", "---\ntitle: A\ntype: concept\ntags: [x]\n---\nA");
|
|
803
|
+
wiki.write("person-b.md", "---\ntitle: B\ntype: person\ntags: [y]\n---\nB");
|
|
804
|
+
const pages = wiki.list();
|
|
805
|
+
// Should include our pages + system pages
|
|
806
|
+
expect(pages.length).toBeGreaterThanOrEqual(2);
|
|
807
|
+
expect(pages).toContain("concept-a.md");
|
|
808
|
+
expect(pages).toContain("person-b.md");
|
|
809
|
+
});
|
|
810
|
+
it("filters by type", () => {
|
|
811
|
+
const wiki = freshWiki();
|
|
812
|
+
wiki.write("concept-x.md", "---\ntitle: X\ntype: concept\n---\nX");
|
|
813
|
+
wiki.write("person-y.md", "---\ntitle: Y\ntype: person\n---\nY");
|
|
814
|
+
const concepts = wiki.list("concept");
|
|
815
|
+
expect(concepts).toContain("concept-x.md");
|
|
816
|
+
expect(concepts).not.toContain("person-y.md");
|
|
817
|
+
});
|
|
818
|
+
it("filters by tag", () => {
|
|
819
|
+
const wiki = freshWiki();
|
|
820
|
+
wiki.write("tagged-a.md", "---\ntitle: A\ntags: [ml, python]\n---\nA");
|
|
821
|
+
wiki.write("tagged-b.md", "---\ntitle: B\ntags: [rust]\n---\nB");
|
|
822
|
+
const mlPages = wiki.list(undefined, "ml");
|
|
823
|
+
expect(mlPages).toContain("tagged-a.md");
|
|
824
|
+
expect(mlPages).not.toContain("tagged-b.md");
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
828
|
+
// SEARCH
|
|
829
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
830
|
+
describe("wiki.search", () => {
|
|
831
|
+
beforeEach(cleanUp);
|
|
832
|
+
afterEach(cleanUp);
|
|
833
|
+
it("finds pages by keyword", () => {
|
|
834
|
+
const wiki = freshWiki();
|
|
835
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO Overview\ntype: concept\ntags: [detection]\n---\nYOLO is a real-time object detection model.");
|
|
836
|
+
wiki.write("concept-bert.md", "---\ntitle: BERT Overview\ntype: concept\ntags: [nlp]\n---\nBERT is a language model.");
|
|
837
|
+
const results = wiki.search("YOLO");
|
|
838
|
+
expect(results.length).toBeGreaterThan(0);
|
|
839
|
+
expect(results[0].path).toBe("concept-yolo.md");
|
|
840
|
+
});
|
|
841
|
+
it("returns empty for no matches", () => {
|
|
842
|
+
const wiki = freshWiki();
|
|
843
|
+
wiki.write("page.md", "---\ntitle: Page\n---\nSome content");
|
|
844
|
+
expect(wiki.search("nonexistent_xyz_12345")).toEqual([]);
|
|
845
|
+
});
|
|
846
|
+
it("boosts title matches", () => {
|
|
847
|
+
const wiki = freshWiki();
|
|
848
|
+
wiki.write("a.md", "---\ntitle: Python Guide\n---\nLearn Python programming.");
|
|
849
|
+
wiki.write("b.md", "---\ntitle: JavaScript Guide\n---\nPython is mentioned here too.");
|
|
850
|
+
const results = wiki.search("python");
|
|
851
|
+
// Title match should rank higher
|
|
852
|
+
expect(results[0].path).toBe("a.md");
|
|
853
|
+
});
|
|
854
|
+
it("respects limit", () => {
|
|
855
|
+
const wiki = freshWiki();
|
|
856
|
+
for (let i = 0; i < 5; i++) {
|
|
857
|
+
wiki.write(`page-${i}.md`, `---\ntitle: Page ${i}\n---\nCommon keyword here.`);
|
|
858
|
+
}
|
|
859
|
+
const results = wiki.search("keyword", 2);
|
|
860
|
+
expect(results.length).toBeLessThanOrEqual(2);
|
|
861
|
+
});
|
|
862
|
+
it("returns snippets", () => {
|
|
863
|
+
const wiki = freshWiki();
|
|
864
|
+
wiki.write("snippet.md", "---\ntitle: Snippet Test\n---\nThe quick brown fox jumps over the lazy dog.");
|
|
865
|
+
const results = wiki.search("fox");
|
|
866
|
+
expect(results[0].snippet).toBeTruthy();
|
|
867
|
+
expect(results[0].snippet.toLowerCase()).toContain("fox");
|
|
868
|
+
});
|
|
869
|
+
it("rebuild invalidates search cache so new pages are found", () => {
|
|
870
|
+
const wiki = freshWiki();
|
|
871
|
+
wiki.write("concept-a.md", "---\ntitle: Alpha Concept\ntype: concept\n---\nAlpha.");
|
|
872
|
+
// Warm the search cache
|
|
873
|
+
wiki.search("Alpha");
|
|
874
|
+
// Rebuild writes index.md which should invalidate the cache
|
|
875
|
+
wiki.rebuildIndex();
|
|
876
|
+
// Now search for content in the rebuilt index
|
|
877
|
+
const results = wiki.search("Knowledge Base Index");
|
|
878
|
+
expect(results.some((r) => r.path === "index.md")).toBe(true);
|
|
879
|
+
});
|
|
880
|
+
it("write invalidates search cache", () => {
|
|
881
|
+
const wiki = freshWiki();
|
|
882
|
+
wiki.write("a.md", "---\ntitle: Old\n---\nOld content.");
|
|
883
|
+
// Warm cache
|
|
884
|
+
expect(wiki.search("Old").length).toBeGreaterThan(0);
|
|
885
|
+
// Write new page
|
|
886
|
+
wiki.write("b.md", "---\ntitle: Brand New Page\n---\nBrand new unique content.");
|
|
887
|
+
// Must find the new page without manual invalidation
|
|
888
|
+
const results = wiki.search("Brand New Page");
|
|
889
|
+
expect(results.some((r) => r.path === "b.md")).toBe(true);
|
|
890
|
+
});
|
|
891
|
+
});
|
|
892
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
893
|
+
// LINT
|
|
894
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
895
|
+
describe("wiki.lint", () => {
|
|
896
|
+
beforeEach(cleanUp);
|
|
897
|
+
afterEach(cleanUp);
|
|
898
|
+
it("runs without errors on fresh wiki", () => {
|
|
899
|
+
const wiki = freshWiki();
|
|
900
|
+
const report = wiki.lint();
|
|
901
|
+
expect(report.pagesChecked).toBeGreaterThan(0);
|
|
902
|
+
expect(report.contradictions).toEqual([]);
|
|
903
|
+
});
|
|
904
|
+
it("detects broken links", () => {
|
|
905
|
+
const wiki = freshWiki();
|
|
906
|
+
wiki.write("broken.md", "---\ntitle: Broken Links\ntype: note\n---\nSee [[nonexistent-page]].");
|
|
907
|
+
const report = wiki.lint();
|
|
908
|
+
const brokenLink = report.issues.find(i => i.category === "broken-link" && i.page === "broken.md");
|
|
909
|
+
expect(brokenLink).toBeDefined();
|
|
910
|
+
expect(brokenLink.message).toContain("nonexistent-page");
|
|
911
|
+
});
|
|
912
|
+
it("detects orphan pages", () => {
|
|
913
|
+
const wiki = freshWiki();
|
|
914
|
+
wiki.write("orphan.md", "---\ntitle: Lonely Page\ntype: note\n---\nNo one links here.");
|
|
915
|
+
const report = wiki.lint();
|
|
916
|
+
const orphan = report.issues.find(i => i.category === "orphan" && i.page === "orphan.md");
|
|
917
|
+
expect(orphan).toBeDefined();
|
|
918
|
+
});
|
|
919
|
+
it("detects missing sources", () => {
|
|
920
|
+
const wiki = freshWiki();
|
|
921
|
+
wiki.write("no-sources.md", "---\ntitle: No Sources\ntype: concept\ntags: [x]\n---\nClaims without evidence.");
|
|
922
|
+
const report = wiki.lint();
|
|
923
|
+
const missing = report.issues.find(i => i.category === "missing-source" && i.page === "no-sources.md");
|
|
924
|
+
expect(missing).toBeDefined();
|
|
925
|
+
});
|
|
926
|
+
it("detects corrupted raw files", () => {
|
|
927
|
+
const wiki = freshWiki();
|
|
928
|
+
wiki.rawAdd("integrity.txt", { content: "original" });
|
|
929
|
+
// Corrupt the file
|
|
930
|
+
writeFileSync(join(wiki.config.rawDir, "integrity.txt"), "tampered");
|
|
931
|
+
const report = wiki.lint();
|
|
932
|
+
const corruption = report.issues.find(i => i.category === "integrity" && i.message.includes("corrupted"));
|
|
933
|
+
expect(corruption).toBeDefined();
|
|
934
|
+
});
|
|
935
|
+
it("detects missing frontmatter", () => {
|
|
936
|
+
const wiki = freshWiki();
|
|
937
|
+
// Write a page with no frontmatter
|
|
938
|
+
writeFileSync(join(wiki.config.wikiDir, "bare.md"), "Just text, no frontmatter.");
|
|
939
|
+
const report = wiki.lint();
|
|
940
|
+
const noFm = report.issues.find(i => i.category === "structure" && i.page === "bare.md" && i.message.includes("frontmatter"));
|
|
941
|
+
expect(noFm).toBeDefined();
|
|
942
|
+
});
|
|
943
|
+
it("detects contradictions between related pages (shared tag)", () => {
|
|
944
|
+
const wiki = freshWiki();
|
|
945
|
+
// Pages share "yolo" tag → topic isolation allows comparison
|
|
946
|
+
wiki.write("page-a.md", "---\ntitle: YOLO Facts A\ntype: concept\ntags: [yolo]\n---\nYOLO was released in 2015.");
|
|
947
|
+
wiki.write("page-b.md", "---\ntitle: YOLO Facts B\ntype: concept\ntags: [yolo]\n---\nYOLO was released in 2018.");
|
|
948
|
+
const report = wiki.lint();
|
|
949
|
+
expect(report.contradictions.length).toBeGreaterThan(0);
|
|
950
|
+
});
|
|
951
|
+
it("does NOT report contradictions for unrelated pages (no shared tag/link)", () => {
|
|
952
|
+
const wiki = freshWiki();
|
|
953
|
+
// Pages have no shared tags and no links between them
|
|
954
|
+
wiki.write("alpha.md", "---\ntitle: Alpha\ntype: concept\ntags: [alpha]\n---\nAlpha was released in 2015.");
|
|
955
|
+
wiki.write("beta.md", "---\ntitle: Beta\ntype: concept\ntags: [beta]\n---\nBeta was released in 2018.");
|
|
956
|
+
const report = wiki.lint();
|
|
957
|
+
expect(report.contradictions).toHaveLength(0);
|
|
958
|
+
});
|
|
959
|
+
it("detects contradictions between linked pages", () => {
|
|
960
|
+
const wiki = freshWiki();
|
|
961
|
+
// page-b links to page-a → they are related
|
|
962
|
+
wiki.write("fact-a.md", "---\ntitle: Fact A\ntype: concept\ntags: [x]\n---\nFoo was released in 2015.");
|
|
963
|
+
wiki.write("fact-b.md", "---\ntitle: Fact B\ntype: concept\ntags: [y]\n---\nFoo was released in 2020. See [[fact-a]].");
|
|
964
|
+
const report = wiki.lint();
|
|
965
|
+
expect(report.contradictions.length).toBeGreaterThan(0);
|
|
966
|
+
});
|
|
967
|
+
it("does not flag same-value numeric claims as contradictions", () => {
|
|
968
|
+
const wiki = freshWiki();
|
|
969
|
+
wiki.write("p1.md", "---\ntitle: P1\ntype: concept\ntags: [ml]\n---\nAchieves 76% accuracy.");
|
|
970
|
+
wiki.write("p2.md", "---\ntitle: P2\ntype: concept\ntags: [ml]\n---\nAchieves 76% accuracy.");
|
|
971
|
+
const report = wiki.lint();
|
|
972
|
+
// Same value → no contradiction
|
|
973
|
+
const numericContradictions = report.contradictions.filter(c => c.claim.includes("accuracy") || c.claim.includes("%"));
|
|
974
|
+
expect(numericContradictions).toHaveLength(0);
|
|
975
|
+
});
|
|
976
|
+
it("normalizes units — 1000 ms vs 1 s not a contradiction", () => {
|
|
977
|
+
const wiki = freshWiki();
|
|
978
|
+
wiki.write("fast-a.md", "---\ntitle: Fast A\ntype: concept\ntags: [perf]\n---\nLatency is 1000 ms.");
|
|
979
|
+
wiki.write("fast-b.md", "---\ntitle: Fast B\ntype: concept\ntags: [perf]\n---\nLatency is 1 s.");
|
|
980
|
+
const report = wiki.lint();
|
|
981
|
+
const latencyContradictions = report.contradictions.filter(c => c.claim.includes("latenc") || c.claim.includes("s"));
|
|
982
|
+
// 1000 ms = 1 s after normalization → no contradiction
|
|
983
|
+
expect(latencyContradictions).toHaveLength(0);
|
|
984
|
+
});
|
|
985
|
+
it("auto-fixes missing frontmatter when apply_fixes is true", () => {
|
|
986
|
+
const wiki = freshWiki();
|
|
987
|
+
// Write a page with no frontmatter directly
|
|
988
|
+
writeFileSync(join(wiki.config.wikiDir, "bare.md"), "Neural networks are deep learning models used for classification.");
|
|
989
|
+
const report = wiki.lint(true);
|
|
990
|
+
expect(report.fixed).toBe(1);
|
|
991
|
+
expect(report.fixedPages).toContain("bare.md");
|
|
992
|
+
// Page should now have frontmatter
|
|
993
|
+
const fixedPage = wiki.read("bare.md");
|
|
994
|
+
expect(fixedPage).not.toBeNull();
|
|
995
|
+
expect(Object.keys(fixedPage.frontmatter).length).toBeGreaterThan(0);
|
|
996
|
+
expect(fixedPage.title).not.toBe(""); // title injected
|
|
997
|
+
});
|
|
998
|
+
it("returns fixed:0 when apply_fixes is false (default)", () => {
|
|
999
|
+
const wiki = freshWiki();
|
|
1000
|
+
writeFileSync(join(wiki.config.wikiDir, "bare2.md"), "Some content.");
|
|
1001
|
+
const report = wiki.lint(false);
|
|
1002
|
+
expect(report.fixed).toBe(0);
|
|
1003
|
+
expect(report.fixedPages).toHaveLength(0);
|
|
1004
|
+
// Issue still reported
|
|
1005
|
+
const issue = report.issues.find(i => i.page === "bare2.md" && i.category === "structure");
|
|
1006
|
+
expect(issue).toBeDefined();
|
|
1007
|
+
});
|
|
1008
|
+
it("broken link suggestion includes did-you-mean from BM25", () => {
|
|
1009
|
+
const wiki = freshWiki();
|
|
1010
|
+
// Create a real page that should be suggested
|
|
1011
|
+
wiki.write("concept-neural-nets.md", "---\ntitle: Neural Nets\ntype: concept\ntags: [ml]\n---\nDeep learning.");
|
|
1012
|
+
// Broken link that is close to existing page name
|
|
1013
|
+
wiki.write("linker.md", "---\ntitle: Linker\ntype: note\n---\nSee [[concept-neural-network]].");
|
|
1014
|
+
const report = wiki.lint();
|
|
1015
|
+
const brokenLink = report.issues.find(i => i.category === "broken-link" && i.page === "linker.md");
|
|
1016
|
+
expect(brokenLink).toBeDefined();
|
|
1017
|
+
// suggestion should mention the similar existing page
|
|
1018
|
+
expect(brokenLink.suggestion).toMatch(/did you mean|concept-neural-nets/i);
|
|
1019
|
+
});
|
|
1020
|
+
it("checks synthesis page integrity", () => {
|
|
1021
|
+
const wiki = freshWiki();
|
|
1022
|
+
wiki.write("synthesis-x.md", `---
|
|
1023
|
+
title: Synthesis X
|
|
1024
|
+
type: synthesis
|
|
1025
|
+
derived_from:
|
|
1026
|
+
- missing-source-page
|
|
1027
|
+
---
|
|
1028
|
+
Combined insights.`);
|
|
1029
|
+
const report = wiki.lint();
|
|
1030
|
+
const synthIssue = report.issues.find(i => i.category === "integrity" && i.page === "synthesis-x.md");
|
|
1031
|
+
expect(synthIssue).toBeDefined();
|
|
1032
|
+
expect(synthIssue.message).toContain("missing-source-page");
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
describe("wiki.lint — integrity cache", () => {
|
|
1036
|
+
beforeEach(cleanUp);
|
|
1037
|
+
afterEach(cleanUp);
|
|
1038
|
+
it("creates .lint-cache.json after lint", () => {
|
|
1039
|
+
const wiki = freshWiki();
|
|
1040
|
+
wiki.rawAdd("cached.txt", { content: "hello" });
|
|
1041
|
+
wiki.lint();
|
|
1042
|
+
expect(existsSync(join(wiki.config.workspace, ".lint-cache.json"))).toBe(true);
|
|
1043
|
+
});
|
|
1044
|
+
it("returns same results on second lint (cache hit)", () => {
|
|
1045
|
+
const wiki = freshWiki();
|
|
1046
|
+
wiki.rawAdd("stable.txt", { content: "stable content" });
|
|
1047
|
+
const report1 = wiki.lint();
|
|
1048
|
+
const report2 = wiki.lint();
|
|
1049
|
+
expect(report2.rawChecked).toBe(report1.rawChecked);
|
|
1050
|
+
expect(report2.issues.filter(i => i.category === "integrity"))
|
|
1051
|
+
.toEqual(report1.issues.filter(i => i.category === "integrity"));
|
|
1052
|
+
});
|
|
1053
|
+
it("detects corruption even with stale cache", () => {
|
|
1054
|
+
const wiki = freshWiki();
|
|
1055
|
+
wiki.rawAdd("will-corrupt.txt", { content: "original" });
|
|
1056
|
+
wiki.lint(); // populates cache with "ok"
|
|
1057
|
+
writeFileSync(join(wiki.config.rawDir, "will-corrupt.txt"), "tampered");
|
|
1058
|
+
const report = wiki.lint();
|
|
1059
|
+
const corruption = report.issues.find(i => i.category === "integrity" && i.message.includes("corrupted"));
|
|
1060
|
+
expect(corruption).toBeDefined();
|
|
1061
|
+
});
|
|
1062
|
+
it("re-checks when meta.yaml changes", () => {
|
|
1063
|
+
const wiki = freshWiki();
|
|
1064
|
+
wiki.rawAdd("meta-change.txt", { content: "content" });
|
|
1065
|
+
wiki.lint(); // populates cache
|
|
1066
|
+
// Corrupt the expected hash in meta
|
|
1067
|
+
const metaPath = join(wiki.config.rawDir, "meta-change.txt.meta.yaml");
|
|
1068
|
+
const metaContent = readFileSync(metaPath, "utf-8");
|
|
1069
|
+
writeFileSync(metaPath, metaContent.replace(/sha256: [a-f0-9]+/, "sha256: 0000000000000000000000000000000000000000000000000000000000000000"));
|
|
1070
|
+
const report = wiki.lint();
|
|
1071
|
+
const corruption = report.issues.find(i => i.category === "integrity" && i.message.includes("corrupted"));
|
|
1072
|
+
expect(corruption).toBeDefined();
|
|
1073
|
+
});
|
|
1074
|
+
it("handles corrupt cache file gracefully", () => {
|
|
1075
|
+
const wiki = freshWiki();
|
|
1076
|
+
wiki.rawAdd("robust.txt", { content: "data" });
|
|
1077
|
+
writeFileSync(join(wiki.config.workspace, ".lint-cache.json"), "not json!!!");
|
|
1078
|
+
const report = wiki.lint();
|
|
1079
|
+
expect(report.rawChecked).toBeGreaterThan(0);
|
|
1080
|
+
});
|
|
1081
|
+
it("ignores cache with wrong version", () => {
|
|
1082
|
+
const wiki = freshWiki();
|
|
1083
|
+
wiki.rawAdd("versioned.txt", { content: "data" });
|
|
1084
|
+
writeFileSync(join(wiki.config.workspace, ".lint-cache.json"), JSON.stringify({ version: 999, entries: {} }));
|
|
1085
|
+
const report = wiki.lint();
|
|
1086
|
+
expect(report.rawChecked).toBeGreaterThan(0);
|
|
1087
|
+
});
|
|
1088
|
+
});
|
|
1089
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1090
|
+
// CLASSIFY
|
|
1091
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1092
|
+
describe("wiki.classify", () => {
|
|
1093
|
+
beforeEach(cleanUp);
|
|
1094
|
+
afterEach(cleanUp);
|
|
1095
|
+
it("classifies a person page", () => {
|
|
1096
|
+
const wiki = freshWiki();
|
|
1097
|
+
const result = wiki.classify("---\ntitle: Albert Einstein\n---\nBorn in 1879, researcher, professor of physics.");
|
|
1098
|
+
expect(result.type).toBe("person");
|
|
1099
|
+
expect(result.confidence).toBeGreaterThan(0);
|
|
1100
|
+
});
|
|
1101
|
+
it("classifies a concept page", () => {
|
|
1102
|
+
const wiki = freshWiki();
|
|
1103
|
+
const result = wiki.classify("---\ntitle: GIL\n---\nDefinition: The Global Interpreter Lock is a concept in Python.");
|
|
1104
|
+
expect(result.type).toBe("concept");
|
|
1105
|
+
});
|
|
1106
|
+
it("classifies a how-to page", () => {
|
|
1107
|
+
const wiki = freshWiki();
|
|
1108
|
+
const result = wiki.classify("---\ntitle: How to Install Docker\n---\nStep 1: Install Docker. Step 2: Setup containers.");
|
|
1109
|
+
expect(result.type).toBe("how-to");
|
|
1110
|
+
});
|
|
1111
|
+
it("respects existing type in frontmatter", () => {
|
|
1112
|
+
const wiki = freshWiki();
|
|
1113
|
+
const result = wiki.classify("---\ntitle: My Artifact\ntype: artifact\n---\nSome body text.");
|
|
1114
|
+
expect(result.type).toBe("artifact");
|
|
1115
|
+
expect(result.confidence).toBe(1.0);
|
|
1116
|
+
});
|
|
1117
|
+
it("classifies a COBOL code page", () => {
|
|
1118
|
+
const wiki = freshWiki();
|
|
1119
|
+
const result = wiki.classify("---\ntitle: CALC-INTEREST\n---\nIDENTIFICATION DIVISION.\nPROGRAM-ID. CALC-INTEREST.\nDATA DIVISION.\nWORKING-STORAGE SECTION.\nPROCEDURE DIVISION.\nEVALUATE WS-CREDIT-GRADE.");
|
|
1120
|
+
expect(result.type).toBe("code");
|
|
1121
|
+
expect(result.confidence).toBeGreaterThan(0);
|
|
1122
|
+
});
|
|
1123
|
+
it("classifies code page with code blocks", () => {
|
|
1124
|
+
const wiki = freshWiki();
|
|
1125
|
+
const result = wiki.classify("---\ntitle: Batch Process\n---\n## 源代码\n\n```cobol\nPROCEDURE DIVISION.\nPERFORM VALIDATE-INPUT.\n```\n\n## 调用关系\n\nCalls VALIDATE-INPUT.");
|
|
1126
|
+
expect(result.type).toBe("code");
|
|
1127
|
+
});
|
|
1128
|
+
it("classifies Python code page", () => {
|
|
1129
|
+
const wiki = freshWiki();
|
|
1130
|
+
const result = wiki.classify("---\ntitle: Data Pipeline\n---\n## 源代码\n\n```python\ndef process_data():\n import pandas\n class DataPipeline:\n pass\n```");
|
|
1131
|
+
expect(result.type).toBe("code");
|
|
1132
|
+
});
|
|
1133
|
+
it("defaults to note for ambiguous content", () => {
|
|
1134
|
+
const wiki = freshWiki();
|
|
1135
|
+
const result = wiki.classify("---\ntitle: Random Notes\n---\nJust some random text without clear signals.");
|
|
1136
|
+
expect(result.type).toBe("note");
|
|
1137
|
+
});
|
|
1138
|
+
it("suggests tags", () => {
|
|
1139
|
+
const wiki = freshWiki();
|
|
1140
|
+
const result = wiki.classify("---\ntitle: PyTorch CNN\n---\nA CNN model built with PyTorch and Python for detection.");
|
|
1141
|
+
expect(result.tags.length).toBeGreaterThan(0);
|
|
1142
|
+
expect(result.tags).toEqual(expect.arrayContaining(["python"]));
|
|
1143
|
+
});
|
|
1144
|
+
});
|
|
1145
|
+
describe("wiki.autoClassifyContent", () => {
|
|
1146
|
+
beforeEach(cleanUp);
|
|
1147
|
+
afterEach(cleanUp);
|
|
1148
|
+
it("enriches content missing type and tags", () => {
|
|
1149
|
+
const wiki = freshWiki();
|
|
1150
|
+
const input = "---\ntitle: Docker Guide\n---\nStep 1: Install Docker. Step 2: run containers.";
|
|
1151
|
+
const enriched = wiki.autoClassifyContent(input);
|
|
1152
|
+
expect(enriched).toContain("type:");
|
|
1153
|
+
expect(enriched).toContain("tags:");
|
|
1154
|
+
});
|
|
1155
|
+
it("does not overwrite existing type", () => {
|
|
1156
|
+
const wiki = freshWiki();
|
|
1157
|
+
const input = "---\ntitle: My Page\ntype: artifact\n---\nSome body.";
|
|
1158
|
+
const enriched = wiki.autoClassifyContent(input);
|
|
1159
|
+
expect(enriched).toContain("type: artifact");
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1162
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1163
|
+
// AUTO-LINK
|
|
1164
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1165
|
+
describe("wiki.autoLink", () => {
|
|
1166
|
+
beforeEach(cleanUp);
|
|
1167
|
+
afterEach(cleanUp);
|
|
1168
|
+
it("injects [[slug|text]] link for matching title", () => {
|
|
1169
|
+
const wiki = freshWiki();
|
|
1170
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO Object Detection\ntags: [yolo]\n---\nBody.");
|
|
1171
|
+
const content = "---\ntitle: Survey\n---\nWe use YOLO Object Detection here.";
|
|
1172
|
+
const { content: out, linksAdded } = wiki.autoLink(content, "survey.md");
|
|
1173
|
+
expect(out).toContain("[[concept-yolo|YOLO Object Detection]]");
|
|
1174
|
+
expect(linksAdded).toBe(1);
|
|
1175
|
+
});
|
|
1176
|
+
it("returns unchanged content when no titles match", () => {
|
|
1177
|
+
const wiki = freshWiki();
|
|
1178
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO\ntags: [yolo]\n---\nBody.");
|
|
1179
|
+
const content = "---\ntitle: Survey\n---\nNo related content here.";
|
|
1180
|
+
const { content: out, linksAdded } = wiki.autoLink(content, "survey.md");
|
|
1181
|
+
expect(out).toBe(content);
|
|
1182
|
+
expect(linksAdded).toBe(0);
|
|
1183
|
+
});
|
|
1184
|
+
it("skips self-references", () => {
|
|
1185
|
+
const wiki = freshWiki();
|
|
1186
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO Object Detection\ntags: [yolo]\n---\nBody.");
|
|
1187
|
+
const content = "---\ntitle: YOLO Object Detection\n---\nThis page covers YOLO Object Detection.";
|
|
1188
|
+
const { linksAdded } = wiki.autoLink(content, "concept-yolo.md");
|
|
1189
|
+
expect(linksAdded).toBe(0);
|
|
1190
|
+
});
|
|
1191
|
+
it("links only the first occurrence of each slug", () => {
|
|
1192
|
+
const wiki = freshWiki();
|
|
1193
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO\ntags: [yolo]\n---\nBody.");
|
|
1194
|
+
const content = "---\ntitle: Survey\n---\nYOLO is fast. YOLO is popular.";
|
|
1195
|
+
const { content: out, linksAdded } = wiki.autoLink(content, "survey.md");
|
|
1196
|
+
expect(linksAdded).toBe(1);
|
|
1197
|
+
// Only first occurrence linked
|
|
1198
|
+
const matches = [...out.matchAll(/\[\[concept-yolo\|/g)];
|
|
1199
|
+
expect(matches).toHaveLength(1);
|
|
1200
|
+
});
|
|
1201
|
+
it("skips mentions inside fenced code blocks", () => {
|
|
1202
|
+
const wiki = freshWiki();
|
|
1203
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO\ntags: [yolo]\n---\nBody.");
|
|
1204
|
+
const content = "---\ntitle: Survey\n---\n```\nYOLO is a model\n```";
|
|
1205
|
+
const { linksAdded } = wiki.autoLink(content, "survey.md");
|
|
1206
|
+
expect(linksAdded).toBe(0);
|
|
1207
|
+
});
|
|
1208
|
+
it("skips mentions inside inline code", () => {
|
|
1209
|
+
const wiki = freshWiki();
|
|
1210
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO\ntags: [yolo]\n---\nBody.");
|
|
1211
|
+
const content = "---\ntitle: Survey\n---\nUse `YOLO` for detection.";
|
|
1212
|
+
const { linksAdded } = wiki.autoLink(content, "survey.md");
|
|
1213
|
+
expect(linksAdded).toBe(0);
|
|
1214
|
+
});
|
|
1215
|
+
it("skips mentions inside existing [[wiki links]]", () => {
|
|
1216
|
+
const wiki = freshWiki();
|
|
1217
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO\ntags: [yolo]\n---\nBody.");
|
|
1218
|
+
const content = "---\ntitle: Survey\n---\nSee [[concept-yolo]] for details.";
|
|
1219
|
+
const { linksAdded } = wiki.autoLink(content, "survey.md");
|
|
1220
|
+
expect(linksAdded).toBe(0);
|
|
1221
|
+
});
|
|
1222
|
+
it("skips mentions inside bare URLs", () => {
|
|
1223
|
+
const wiki = freshWiki();
|
|
1224
|
+
wiki.write("concept-docker.md", "---\ntitle: Docker\ntags: [docker]\n---\nBody.");
|
|
1225
|
+
const content = "---\ntitle: Dev\n---\nSee https://docs.docker.com for Docker setup.";
|
|
1226
|
+
const { content: out, linksAdded } = wiki.autoLink(content, "dev.md");
|
|
1227
|
+
// "Docker" after the URL should be linked, but the URL itself should not be touched
|
|
1228
|
+
expect(out).not.toContain("https://docs.[[");
|
|
1229
|
+
// The standalone "Docker" mention should be linked
|
|
1230
|
+
expect(linksAdded).toBe(1);
|
|
1231
|
+
});
|
|
1232
|
+
it("prefers longer title over shorter when both match (longest-first)", () => {
|
|
1233
|
+
const wiki = freshWiki();
|
|
1234
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO\ntags: [yolo]\n---\nBody.");
|
|
1235
|
+
wiki.write("concept-yolo-full.md", "---\ntitle: YOLO Object Detection\ntags: [yolo]\n---\nBody.");
|
|
1236
|
+
const content = "---\ntitle: Survey\n---\nYOLO Object Detection is key.";
|
|
1237
|
+
const { content: out } = wiki.autoLink(content, "survey.md");
|
|
1238
|
+
// Longer title wins — should link to the full page, not the short one
|
|
1239
|
+
expect(out).toContain("[[concept-yolo-full|YOLO Object Detection]]");
|
|
1240
|
+
expect(out).not.toContain("[[concept-yolo|YOLO Object Detection]]");
|
|
1241
|
+
});
|
|
1242
|
+
it("skips titles shorter than 4 chars", () => {
|
|
1243
|
+
const wiki = freshWiki();
|
|
1244
|
+
wiki.write("concept-ml.md", "---\ntitle: ML\ntags: [ml]\n---\nBody.");
|
|
1245
|
+
const content = "---\ntitle: Survey\n---\nML is important.";
|
|
1246
|
+
const { linksAdded } = wiki.autoLink(content, "survey.md");
|
|
1247
|
+
expect(linksAdded).toBe(0);
|
|
1248
|
+
});
|
|
1249
|
+
it("parsePage correctly extracts slug from [[slug|display text]] links", () => {
|
|
1250
|
+
const wiki = freshWiki();
|
|
1251
|
+
wiki.write("concept-yolo.md", "---\ntitle: YOLO\ntags: [yolo]\n---\nBody.");
|
|
1252
|
+
wiki.write("note-survey.md", "---\ntitle: Survey\n---\nWe use [[concept-yolo|YOLO Object Detection]] daily.");
|
|
1253
|
+
const page = wiki.read("note-survey.md");
|
|
1254
|
+
expect(page.links).toContain("concept-yolo");
|
|
1255
|
+
// Should not contain the display text part
|
|
1256
|
+
expect(page.links.some(l => l.includes("|"))).toBe(false);
|
|
1257
|
+
});
|
|
1258
|
+
it("cache: second write is visible to subsequent autoLink calls", () => {
|
|
1259
|
+
const wiki = freshWiki();
|
|
1260
|
+
// First page written before any autoLink call
|
|
1261
|
+
wiki.write("concept-alpha.md", "---\ntitle: Alpha System\ntags: [alpha]\n---\nBody.");
|
|
1262
|
+
// autoLink primes the cache (O(n) build)
|
|
1263
|
+
const { linksAdded: first } = wiki.autoLink("---\ntitle: T\n---\nAlpha System is key.", "other.md");
|
|
1264
|
+
expect(first).toBe(1);
|
|
1265
|
+
// Write a second page — cache should be updated incrementally
|
|
1266
|
+
wiki.write("concept-beta.md", "---\ntitle: Beta Framework\ntags: [beta]\n---\nBody.");
|
|
1267
|
+
// autoLink should now pick up both pages without a full rebuild
|
|
1268
|
+
const { content: out, linksAdded: second } = wiki.autoLink("---\ntitle: T\n---\nAlpha System and Beta Framework work together.", "other.md");
|
|
1269
|
+
expect(second).toBe(2);
|
|
1270
|
+
expect(out).toContain("[[concept-alpha|Alpha System]]");
|
|
1271
|
+
expect(out).toContain("[[concept-beta|Beta Framework]]");
|
|
1272
|
+
});
|
|
1273
|
+
it("config.autoLink.enabled defaults to true and is mutable", () => {
|
|
1274
|
+
// The flag is enforced by the server handler (not autoLink() itself).
|
|
1275
|
+
// This test verifies the config field is correctly shaped for the handler to read.
|
|
1276
|
+
const wiki = freshWiki();
|
|
1277
|
+
expect(wiki.config.autoLink.enabled).toBe(true);
|
|
1278
|
+
wiki.config.autoLink.enabled = false;
|
|
1279
|
+
expect(wiki.config.autoLink.enabled).toBe(false);
|
|
1280
|
+
});
|
|
1281
|
+
});
|
|
1282
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1283
|
+
// SYNTHESIZE
|
|
1284
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1285
|
+
describe("wiki.synthesizeContext", () => {
|
|
1286
|
+
beforeEach(cleanUp);
|
|
1287
|
+
afterEach(cleanUp);
|
|
1288
|
+
it("returns content from multiple pages", () => {
|
|
1289
|
+
const wiki = freshWiki();
|
|
1290
|
+
wiki.write("concept-a.md", "---\ntitle: Concept A\ntags: [ml]\n---\nContent A.");
|
|
1291
|
+
wiki.write("concept-b.md", "---\ntitle: Concept B\ntags: [nlp]\n---\nContent B.");
|
|
1292
|
+
const ctx = wiki.synthesizeContext(["concept-a.md", "concept-b.md"]);
|
|
1293
|
+
expect(ctx.pages).toHaveLength(2);
|
|
1294
|
+
expect(ctx.pages[0].title).toBe("Concept A");
|
|
1295
|
+
expect(ctx.pages[1].title).toBe("Concept B");
|
|
1296
|
+
});
|
|
1297
|
+
it("generates suggestions for multiple pages", () => {
|
|
1298
|
+
const wiki = freshWiki();
|
|
1299
|
+
wiki.write("p1.md", "---\ntitle: P1\n---\nX");
|
|
1300
|
+
wiki.write("p2.md", "---\ntitle: P2\n---\nY");
|
|
1301
|
+
const ctx = wiki.synthesizeContext(["p1.md", "p2.md"]);
|
|
1302
|
+
expect(ctx.suggestions.length).toBeGreaterThan(0);
|
|
1303
|
+
});
|
|
1304
|
+
it("skips missing pages gracefully", () => {
|
|
1305
|
+
const wiki = freshWiki();
|
|
1306
|
+
wiki.write("exists.md", "---\ntitle: Exists\n---\nHere");
|
|
1307
|
+
const ctx = wiki.synthesizeContext(["exists.md", "nope.md"]);
|
|
1308
|
+
expect(ctx.pages).toHaveLength(1);
|
|
1309
|
+
});
|
|
1310
|
+
});
|
|
1311
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1312
|
+
// SCHEMAS
|
|
1313
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1314
|
+
describe("wiki.schemas", () => {
|
|
1315
|
+
beforeEach(cleanUp);
|
|
1316
|
+
afterEach(cleanUp);
|
|
1317
|
+
it("lists all 10 default schemas", () => {
|
|
1318
|
+
const wiki = freshWiki();
|
|
1319
|
+
const schemas = wiki.schemas();
|
|
1320
|
+
expect(schemas.length).toBe(10);
|
|
1321
|
+
const names = schemas.map(s => s.name).sort();
|
|
1322
|
+
expect(names).toEqual([
|
|
1323
|
+
"artifact", "code", "comparison", "concept", "event",
|
|
1324
|
+
"how-to", "note", "person", "summary", "synthesis",
|
|
1325
|
+
]);
|
|
1326
|
+
});
|
|
1327
|
+
it("each schema has name, description, and template", () => {
|
|
1328
|
+
const wiki = freshWiki();
|
|
1329
|
+
for (const schema of wiki.schemas()) {
|
|
1330
|
+
expect(schema.name).toBeTruthy();
|
|
1331
|
+
expect(schema.description).toBeTruthy();
|
|
1332
|
+
expect(schema.template).toContain("template:");
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
});
|
|
1336
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1337
|
+
// LOG
|
|
1338
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1339
|
+
describe("wiki.getLog", () => {
|
|
1340
|
+
beforeEach(cleanUp);
|
|
1341
|
+
afterEach(cleanUp);
|
|
1342
|
+
it("has init entry after fresh init", () => {
|
|
1343
|
+
const wiki = freshWiki();
|
|
1344
|
+
const log = wiki.getLog();
|
|
1345
|
+
expect(log.length).toBeGreaterThan(0);
|
|
1346
|
+
});
|
|
1347
|
+
it("records write operations", () => {
|
|
1348
|
+
const wiki = freshWiki();
|
|
1349
|
+
wiki.write("logged.md", "---\ntitle: Logged\n---\nBody");
|
|
1350
|
+
const log = wiki.getLog();
|
|
1351
|
+
const writeEntry = log.find(e => e.operation === "write" || e.operation === "create");
|
|
1352
|
+
expect(writeEntry).toBeDefined();
|
|
1353
|
+
});
|
|
1354
|
+
it("records raw-add operations", () => {
|
|
1355
|
+
const wiki = freshWiki();
|
|
1356
|
+
wiki.rawAdd("log-test.txt", { content: "data" });
|
|
1357
|
+
const log = wiki.getLog();
|
|
1358
|
+
const rawEntry = log.find(e => e.operation === "raw-add");
|
|
1359
|
+
expect(rawEntry).toBeDefined();
|
|
1360
|
+
});
|
|
1361
|
+
it("respects limit", () => {
|
|
1362
|
+
const wiki = freshWiki();
|
|
1363
|
+
for (let i = 0; i < 10; i++) {
|
|
1364
|
+
wiki.write(`bulk-${i}.md`, `---\ntitle: Bulk ${i}\n---\nBody ${i}`);
|
|
1365
|
+
}
|
|
1366
|
+
const log = wiki.getLog(3);
|
|
1367
|
+
expect(log.length).toBeLessThanOrEqual(3);
|
|
1368
|
+
});
|
|
1369
|
+
});
|
|
1370
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1371
|
+
// INDEX & TIMELINE REBUILD
|
|
1372
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1373
|
+
describe("wiki.rebuildIndex", () => {
|
|
1374
|
+
beforeEach(cleanUp);
|
|
1375
|
+
afterEach(cleanUp);
|
|
1376
|
+
it("rebuilds index with page counts (flat mode)", () => {
|
|
1377
|
+
const wiki = freshWiki();
|
|
1378
|
+
wiki.write("concept-a.md", "---\ntitle: A\ntype: concept\n---\nA");
|
|
1379
|
+
wiki.write("person-b.md", "---\ntitle: B\ntype: person\n---\nB");
|
|
1380
|
+
wiki.rebuildIndex();
|
|
1381
|
+
const index = readFileSync(join(wiki.config.wikiDir, "index.md"), "utf-8");
|
|
1382
|
+
expect(index).toContain("concept-a");
|
|
1383
|
+
expect(index).toContain("person-b");
|
|
1384
|
+
expect(index).toContain("2 pages");
|
|
1385
|
+
});
|
|
1386
|
+
it("generates topic sub-indexes when subdirectories exist", () => {
|
|
1387
|
+
const wiki = freshWiki();
|
|
1388
|
+
wiki.write("cobol/concept-cobol.md", "---\ntitle: COBOL Basics\ntype: concept\n---\nCOBOL.");
|
|
1389
|
+
wiki.write("cobol/how-to-cobol-modernization.md", "---\ntitle: COBOL Modernization\ntype: how-to\n---\nModernize.");
|
|
1390
|
+
wiki.write("yolo/concept-yolo-overview.md", "---\ntitle: YOLO Overview\ntype: concept\n---\nYOLO.");
|
|
1391
|
+
wiki.rebuildIndex();
|
|
1392
|
+
// Top-level index should list topics
|
|
1393
|
+
const index = readFileSync(join(wiki.config.wikiDir, "index.md"), "utf-8");
|
|
1394
|
+
expect(index).toContain("3 pages");
|
|
1395
|
+
expect(index).toContain("2 topics");
|
|
1396
|
+
expect(index).toContain("[[cobol/index]]");
|
|
1397
|
+
expect(index).toContain("[[yolo/index]]");
|
|
1398
|
+
expect(index).toContain("cobol (2 pages)");
|
|
1399
|
+
expect(index).toContain("yolo (1 pages)");
|
|
1400
|
+
// COBOL sub-index should exist and list its pages
|
|
1401
|
+
const cobolIndex = readFileSync(join(wiki.config.wikiDir, "cobol/index.md"), "utf-8");
|
|
1402
|
+
expect(cobolIndex).toContain("COBOL Basics");
|
|
1403
|
+
expect(cobolIndex).toContain("COBOL Modernization");
|
|
1404
|
+
expect(cobolIndex).toContain("[[cobol/concept-cobol]]");
|
|
1405
|
+
expect(cobolIndex).toContain("2 pages");
|
|
1406
|
+
// YOLO sub-index
|
|
1407
|
+
const yoloIndex = readFileSync(join(wiki.config.wikiDir, "yolo/index.md"), "utf-8");
|
|
1408
|
+
expect(yoloIndex).toContain("YOLO Overview");
|
|
1409
|
+
expect(yoloIndex).toContain("1 pages");
|
|
1410
|
+
});
|
|
1411
|
+
it("mixes topic dirs with root-level pages", () => {
|
|
1412
|
+
const wiki = freshWiki();
|
|
1413
|
+
wiki.write("cobol/concept-cobol.md", "---\ntitle: COBOL Basics\ntype: concept\n---\nCOBOL.");
|
|
1414
|
+
wiki.write("note-misc.md", "---\ntitle: Misc Note\ntype: note\n---\nMisc.");
|
|
1415
|
+
wiki.rebuildIndex();
|
|
1416
|
+
const index = readFileSync(join(wiki.config.wikiDir, "index.md"), "utf-8");
|
|
1417
|
+
expect(index).toContain("2 pages");
|
|
1418
|
+
expect(index).toContain("[[cobol/index]]");
|
|
1419
|
+
expect(index).toContain("[[note-misc]]");
|
|
1420
|
+
});
|
|
1421
|
+
it("generates multi-level nested indexes", () => {
|
|
1422
|
+
const wiki = freshWiki();
|
|
1423
|
+
wiki.write("lang/js/concept-closures.md", "---\ntitle: JS Closures\ntype: concept\n---\nClosures.");
|
|
1424
|
+
wiki.write("lang/js/frameworks/concept-react.md", "---\ntitle: React Overview\ntype: concept\n---\nReact.");
|
|
1425
|
+
wiki.write("lang/python/concept-decorators.md", "---\ntitle: Python Decorators\ntype: concept\n---\nDecorators.");
|
|
1426
|
+
wiki.rebuildIndex();
|
|
1427
|
+
// Top-level index should list "lang" topic
|
|
1428
|
+
const index = readFileSync(join(wiki.config.wikiDir, "index.md"), "utf-8");
|
|
1429
|
+
expect(index).toContain("3 pages");
|
|
1430
|
+
expect(index).toContain("[[lang/index]]");
|
|
1431
|
+
expect(index).toContain("lang (3 pages)");
|
|
1432
|
+
// lang/index.md should list sub-topics js and python
|
|
1433
|
+
const langIndex = readFileSync(join(wiki.config.wikiDir, "lang/index.md"), "utf-8");
|
|
1434
|
+
expect(langIndex).toContain("3 pages");
|
|
1435
|
+
expect(langIndex).toContain("## Sub-topics");
|
|
1436
|
+
expect(langIndex).toContain("[[lang/js/index]]");
|
|
1437
|
+
expect(langIndex).toContain("[[lang/python/index]]");
|
|
1438
|
+
// lang/js/index.md should list sub-topic frameworks + direct page
|
|
1439
|
+
const jsIndex = readFileSync(join(wiki.config.wikiDir, "lang/js/index.md"), "utf-8");
|
|
1440
|
+
expect(jsIndex).toContain("2 pages");
|
|
1441
|
+
expect(jsIndex).toContain("## Sub-topics");
|
|
1442
|
+
expect(jsIndex).toContain("[[lang/js/frameworks/index]]");
|
|
1443
|
+
expect(jsIndex).toContain("[[lang/js/concept-closures]]");
|
|
1444
|
+
expect(jsIndex).toContain("JS Closures");
|
|
1445
|
+
// lang/js/frameworks/index.md should list the React page
|
|
1446
|
+
const fwIndex = readFileSync(join(wiki.config.wikiDir, "lang/js/frameworks/index.md"), "utf-8");
|
|
1447
|
+
expect(fwIndex).toContain("1 pages");
|
|
1448
|
+
expect(fwIndex).toContain("[[lang/js/frameworks/concept-react]]");
|
|
1449
|
+
expect(fwIndex).toContain("React Overview");
|
|
1450
|
+
// lang/python/index.md should list the decorators page
|
|
1451
|
+
const pyIndex = readFileSync(join(wiki.config.wikiDir, "lang/python/index.md"), "utf-8");
|
|
1452
|
+
expect(pyIndex).toContain("1 pages");
|
|
1453
|
+
expect(pyIndex).toContain("[[lang/python/concept-decorators]]");
|
|
1454
|
+
});
|
|
1455
|
+
it("treats nested */index.md as system pages", () => {
|
|
1456
|
+
const wiki = freshWiki();
|
|
1457
|
+
wiki.write("a/b/c/page.md", "---\ntitle: Deep Page\ntype: note\n---\nDeep.");
|
|
1458
|
+
wiki.rebuildIndex();
|
|
1459
|
+
// All intermediate index files should exist
|
|
1460
|
+
expect(existsSync(join(wiki.config.wikiDir, "a/index.md"))).toBe(true);
|
|
1461
|
+
expect(existsSync(join(wiki.config.wikiDir, "a/b/index.md"))).toBe(true);
|
|
1462
|
+
expect(existsSync(join(wiki.config.wikiDir, "a/b/c/index.md"))).toBe(true);
|
|
1463
|
+
// Nested indexes are system pages — cannot be deleted or written to
|
|
1464
|
+
expect(() => wiki.delete("a/b/index.md")).toThrow("Cannot delete system page");
|
|
1465
|
+
expect(() => wiki.write("a/b/index.md", "---\ntitle: X\n---\nX")).toThrow("Cannot write to reserved path");
|
|
1466
|
+
});
|
|
1467
|
+
it("overwrites pre-existing user-authored nested index.md on rebuild", () => {
|
|
1468
|
+
const wiki = freshWiki();
|
|
1469
|
+
// Simulate a repo that already has a hand-written lang/js/index.md
|
|
1470
|
+
// (e.g. created before upgrading to the multi-level index feature)
|
|
1471
|
+
const jsDir = join(wiki.config.wikiDir, "lang/js");
|
|
1472
|
+
mkdirSync(jsDir, { recursive: true });
|
|
1473
|
+
writeFileSync(join(jsDir, "index.md"), "---\ntitle: My Hand-Written JS Guide\ntype: concept\n---\n\nCurated content that predates the feature.\n");
|
|
1474
|
+
writeFileSync(join(jsDir, "concept-closures.md"), "---\ntitle: Closures\ntype: concept\n---\nClosures.\n");
|
|
1475
|
+
// First rebuild should overwrite the legacy user-authored index
|
|
1476
|
+
wiki.rebuildIndex();
|
|
1477
|
+
const jsIndex = readFileSync(join(jsDir, "index.md"), "utf-8");
|
|
1478
|
+
expect(jsIndex).not.toContain("My Hand-Written JS Guide");
|
|
1479
|
+
expect(jsIndex).not.toContain("Curated content");
|
|
1480
|
+
expect(jsIndex).toContain("[[lang/js/concept-closures]]");
|
|
1481
|
+
expect(jsIndex).toContain("type: index");
|
|
1482
|
+
// Subsequent rebuilds keep it consistent
|
|
1483
|
+
wiki.rebuildIndex();
|
|
1484
|
+
const jsIndex2 = readFileSync(join(jsDir, "index.md"), "utf-8");
|
|
1485
|
+
expect(jsIndex2).toContain("[[lang/js/concept-closures]]");
|
|
1486
|
+
});
|
|
1487
|
+
it("cleans up stale indexes after deleting last page in subtree", () => {
|
|
1488
|
+
const wiki = freshWiki();
|
|
1489
|
+
wiki.write("lang/js/concept-js.md", "---\ntitle: JS Basics\ntype: concept\n---\nJS.");
|
|
1490
|
+
wiki.write("lang/python/concept-py.md", "---\ntitle: Python Basics\ntype: concept\n---\nPython.");
|
|
1491
|
+
wiki.rebuildIndex();
|
|
1492
|
+
// Both sub-indexes should exist
|
|
1493
|
+
expect(existsSync(join(wiki.config.wikiDir, "lang/js/index.md"))).toBe(true);
|
|
1494
|
+
expect(existsSync(join(wiki.config.wikiDir, "lang/python/index.md"))).toBe(true);
|
|
1495
|
+
// Delete the only page under lang/python/
|
|
1496
|
+
wiki.delete("lang/python/concept-py.md");
|
|
1497
|
+
wiki.rebuildIndex();
|
|
1498
|
+
// lang/python/ index should be gone, lang/js/ should remain
|
|
1499
|
+
expect(existsSync(join(wiki.config.wikiDir, "lang/python/index.md"))).toBe(false);
|
|
1500
|
+
expect(existsSync(join(wiki.config.wikiDir, "lang/python"))).toBe(false);
|
|
1501
|
+
expect(existsSync(join(wiki.config.wikiDir, "lang/js/index.md"))).toBe(true);
|
|
1502
|
+
// lang/index.md should still exist and only reference js
|
|
1503
|
+
const langIndex = readFileSync(join(wiki.config.wikiDir, "lang/index.md"), "utf-8");
|
|
1504
|
+
expect(langIndex).toContain("[[lang/js/index]]");
|
|
1505
|
+
expect(langIndex).not.toContain("python");
|
|
1506
|
+
});
|
|
1507
|
+
});
|
|
1508
|
+
describe("wiki.rebuildTimeline", () => {
|
|
1509
|
+
beforeEach(cleanUp);
|
|
1510
|
+
afterEach(cleanUp);
|
|
1511
|
+
it("rebuilds timeline with entries", () => {
|
|
1512
|
+
const wiki = freshWiki();
|
|
1513
|
+
wiki.write("event-x.md", "---\ntitle: Event X\ntype: event\n---\nSomething happened.");
|
|
1514
|
+
wiki.rebuildTimeline();
|
|
1515
|
+
const timeline = readFileSync(join(wiki.config.wikiDir, "timeline.md"), "utf-8");
|
|
1516
|
+
expect(timeline).toContain("Event X");
|
|
1517
|
+
expect(timeline).toContain("[event]");
|
|
1518
|
+
});
|
|
1519
|
+
it("uses full paths in timeline for subdirectory pages", () => {
|
|
1520
|
+
const wiki = freshWiki();
|
|
1521
|
+
wiki.write("cobol/concept-cobol.md", "---\ntitle: COBOL Basics\ntype: concept\n---\nCOBOL.");
|
|
1522
|
+
wiki.rebuildTimeline();
|
|
1523
|
+
const timeline = readFileSync(join(wiki.config.wikiDir, "timeline.md"), "utf-8");
|
|
1524
|
+
expect(timeline).toContain("[[cobol/concept-cobol]]");
|
|
1525
|
+
expect(timeline).toContain("COBOL Basics");
|
|
1526
|
+
});
|
|
1527
|
+
it("handles unquoted dates parsed as Date objects by js-yaml", () => {
|
|
1528
|
+
const wiki = freshWiki();
|
|
1529
|
+
// Write frontmatter with unquoted ISO date — js-yaml parses this as a Date object
|
|
1530
|
+
const rawContent = "---\ntitle: Date Bug\ntype: note\ncreated: 2025-06-15T10:00:00.000Z\n---\nBody.";
|
|
1531
|
+
writeFileSync(join(wiki.config.wikiDir, "date-bug.md"), rawContent);
|
|
1532
|
+
// rebuildTimeline calls .slice(0,10) on created — should not throw
|
|
1533
|
+
expect(() => wiki.rebuildTimeline()).not.toThrow();
|
|
1534
|
+
const timeline = readFileSync(join(wiki.config.wikiDir, "timeline.md"), "utf-8");
|
|
1535
|
+
expect(timeline).toContain("2025-06-15");
|
|
1536
|
+
expect(timeline).toContain("Date Bug");
|
|
1537
|
+
});
|
|
1538
|
+
});
|
|
1539
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1540
|
+
// AUTO-ROUTE (resolvePagePath)
|
|
1541
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1542
|
+
describe("wiki.resolvePagePath", () => {
|
|
1543
|
+
beforeEach(cleanUp);
|
|
1544
|
+
afterEach(cleanUp);
|
|
1545
|
+
it("keeps path as-is if already in a subdirectory", () => {
|
|
1546
|
+
const wiki = freshWiki();
|
|
1547
|
+
wiki.write("cobol/concept-cobol.md", "---\ntitle: COBOL\ntype: concept\n---\nCOBOL.");
|
|
1548
|
+
const resolved = wiki.resolvePagePath("cobol/new-page.md", "---\ntitle: New\n---\nContent");
|
|
1549
|
+
expect(resolved).toBe("cobol/new-page.md");
|
|
1550
|
+
});
|
|
1551
|
+
it("routes via explicit topic frontmatter field", () => {
|
|
1552
|
+
const wiki = freshWiki();
|
|
1553
|
+
wiki.write("cobol/concept-cobol.md", "---\ntitle: COBOL\ntype: concept\n---\nCOBOL.");
|
|
1554
|
+
const resolved = wiki.resolvePagePath("new-page.md", "---\ntitle: New\ntopic: cobol\n---\nContent");
|
|
1555
|
+
expect(resolved).toBe("cobol/new-page.md");
|
|
1556
|
+
});
|
|
1557
|
+
it("routes via tag matching against existing topic dirs", () => {
|
|
1558
|
+
const wiki = freshWiki();
|
|
1559
|
+
wiki.write("yolo/concept-yolo.md", "---\ntitle: YOLO\ntype: concept\n---\nYOLO.");
|
|
1560
|
+
// Content about YOLO should be routed to the yolo/ directory
|
|
1561
|
+
const resolved = wiki.resolvePagePath("yolo-v8.md", "---\ntitle: YOLOv8 Architecture\ntype: concept\n---\nYOLO v8 object detection model.");
|
|
1562
|
+
expect(resolved).toBe("yolo/yolo-v8.md");
|
|
1563
|
+
});
|
|
1564
|
+
it("keeps at root when no matching topic dir exists", () => {
|
|
1565
|
+
const wiki = freshWiki();
|
|
1566
|
+
wiki.write("cobol/concept-cobol.md", "---\ntitle: COBOL\ntype: concept\n---\nCOBOL.");
|
|
1567
|
+
const resolved = wiki.resolvePagePath("rust-basics.md", "---\ntitle: Rust Basics\ntype: concept\n---\nRust programming.");
|
|
1568
|
+
expect(resolved).toBe("rust-basics.md");
|
|
1569
|
+
});
|
|
1570
|
+
it("returns original path when no topic dirs exist", () => {
|
|
1571
|
+
const wiki = freshWiki();
|
|
1572
|
+
wiki.write("concept-a.md", "---\ntitle: A\ntype: concept\n---\nA.");
|
|
1573
|
+
const resolved = wiki.resolvePagePath("new-page.md", "---\ntitle: New\n---\nContent");
|
|
1574
|
+
expect(resolved).toBe("new-page.md");
|
|
1575
|
+
});
|
|
1576
|
+
it("routes to nested directory via tag/title matching (deepest wins)", () => {
|
|
1577
|
+
const wiki = freshWiki();
|
|
1578
|
+
wiki.write("lang/js/concept-js.md", "---\ntitle: JS\ntype: concept\n---\nJS.");
|
|
1579
|
+
wiki.write("lang/python/concept-py.md", "---\ntitle: Python\ntype: concept\n---\nPython.");
|
|
1580
|
+
// A page about JS should route to lang/js/, not lang/
|
|
1581
|
+
const resolved = wiki.resolvePagePath("js-closures.md", "---\ntitle: JS Closures\ntype: concept\n---\nJavaScript closures.");
|
|
1582
|
+
expect(resolved).toBe("lang/js/js-closures.md");
|
|
1583
|
+
});
|
|
1584
|
+
it("routes to nested directory via explicit topic matching last segment", () => {
|
|
1585
|
+
const wiki = freshWiki();
|
|
1586
|
+
wiki.write("lang/js/concept-js.md", "---\ntitle: JS\ntype: concept\n---\nJS.");
|
|
1587
|
+
// topic: "js" should match lang/js/ not create a new js/ at root
|
|
1588
|
+
const resolved = wiki.resolvePagePath("new-page.md", "---\ntitle: New\ntopic: js\n---\nContent");
|
|
1589
|
+
expect(resolved).toBe("lang/js/new-page.md");
|
|
1590
|
+
});
|
|
1591
|
+
it("routes via explicit topic with full nested path", () => {
|
|
1592
|
+
const wiki = freshWiki();
|
|
1593
|
+
wiki.write("lang/js/concept-js.md", "---\ntitle: JS\ntype: concept\n---\nJS.");
|
|
1594
|
+
const resolved = wiki.resolvePagePath("new-page.md", "---\ntitle: New\ntopic: lang/js\n---\nContent");
|
|
1595
|
+
expect(resolved).toBe("lang/js/new-page.md");
|
|
1596
|
+
});
|
|
1597
|
+
});
|
|
1598
|
+
describe("wiki.listTopicDirs", () => {
|
|
1599
|
+
beforeEach(cleanUp);
|
|
1600
|
+
afterEach(cleanUp);
|
|
1601
|
+
it("lists existing topic subdirectories", () => {
|
|
1602
|
+
const wiki = freshWiki();
|
|
1603
|
+
wiki.write("cobol/a.md", "---\ntitle: A\n---\nA");
|
|
1604
|
+
wiki.write("yolo/b.md", "---\ntitle: B\n---\nB");
|
|
1605
|
+
const dirs = wiki.listTopicDirs();
|
|
1606
|
+
expect(dirs).toContain("cobol");
|
|
1607
|
+
expect(dirs).toContain("yolo");
|
|
1608
|
+
});
|
|
1609
|
+
it("returns empty when no subdirectories", () => {
|
|
1610
|
+
const wiki = freshWiki();
|
|
1611
|
+
wiki.write("concept-a.md", "---\ntitle: A\n---\nA");
|
|
1612
|
+
const dirs = wiki.listTopicDirs();
|
|
1613
|
+
expect(dirs).toEqual([]);
|
|
1614
|
+
});
|
|
1615
|
+
});
|
|
1616
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1617
|
+
// EDGE CASES & ROBUSTNESS
|
|
1618
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1619
|
+
describe("edge cases", () => {
|
|
1620
|
+
beforeEach(cleanUp);
|
|
1621
|
+
afterEach(cleanUp);
|
|
1622
|
+
it("handles unicode content correctly", () => {
|
|
1623
|
+
const wiki = freshWiki();
|
|
1624
|
+
const content = "---\ntitle: 中文测试\ntags: [中文]\n---\n这是一个中文页面。";
|
|
1625
|
+
wiki.write("chinese.md", content);
|
|
1626
|
+
const page = wiki.read("chinese.md");
|
|
1627
|
+
expect(page.title).toBe("中文测试");
|
|
1628
|
+
expect(page.content).toContain("中文页面");
|
|
1629
|
+
});
|
|
1630
|
+
it("handles empty search query", () => {
|
|
1631
|
+
const wiki = freshWiki();
|
|
1632
|
+
expect(wiki.search("")).toEqual([]);
|
|
1633
|
+
expect(wiki.search(" ")).toEqual([]);
|
|
1634
|
+
});
|
|
1635
|
+
it("handles pages with no body", () => {
|
|
1636
|
+
const wiki = freshWiki();
|
|
1637
|
+
wiki.write("empty-body.md", "---\ntitle: Empty\ntype: note\n---\n");
|
|
1638
|
+
const page = wiki.read("empty-body.md");
|
|
1639
|
+
expect(page).not.toBeNull();
|
|
1640
|
+
expect(page.title).toBe("Empty");
|
|
1641
|
+
});
|
|
1642
|
+
it("handles raw file with subdirectory", () => {
|
|
1643
|
+
const wiki = freshWiki();
|
|
1644
|
+
const doc = rawAddOne(wiki, "papers/test.txt", { content: "nested" });
|
|
1645
|
+
expect(doc.path).toBe("papers/test.txt");
|
|
1646
|
+
const result = wiki.rawList();
|
|
1647
|
+
expect(result.find(d => d.path === "papers/test.txt")).toBeDefined();
|
|
1648
|
+
});
|
|
1649
|
+
});
|
|
1650
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1651
|
+
// PATH SAFETY — Directory Traversal Prevention
|
|
1652
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1653
|
+
describe("safePath", () => {
|
|
1654
|
+
it("allows simple filenames", () => {
|
|
1655
|
+
const result = safePath("/base/dir", "file.txt");
|
|
1656
|
+
expect(result).toBe("/base/dir/file.txt");
|
|
1657
|
+
});
|
|
1658
|
+
it("allows subdirectories", () => {
|
|
1659
|
+
const result = safePath("/base/dir", "sub/file.txt");
|
|
1660
|
+
expect(result).toBe("/base/dir/sub/file.txt");
|
|
1661
|
+
});
|
|
1662
|
+
it("rejects parent traversal (../)", () => {
|
|
1663
|
+
expect(() => safePath("/base/dir", "../etc/passwd")).toThrow(/traversal/i);
|
|
1664
|
+
});
|
|
1665
|
+
it("rejects deep traversal (../../)", () => {
|
|
1666
|
+
expect(() => safePath("/base/dir", "../../etc/shadow")).toThrow(/traversal/i);
|
|
1667
|
+
});
|
|
1668
|
+
it("rejects traversal disguised in subpath", () => {
|
|
1669
|
+
expect(() => safePath("/base/dir", "sub/../../etc/passwd")).toThrow(/traversal/i);
|
|
1670
|
+
});
|
|
1671
|
+
it("rejects absolute paths", () => {
|
|
1672
|
+
expect(() => safePath("/base/dir", "/etc/passwd")).toThrow(/absolute/i);
|
|
1673
|
+
});
|
|
1674
|
+
it("rejects null bytes", () => {
|
|
1675
|
+
expect(() => safePath("/base/dir", "file\0.txt")).toThrow(/null/i);
|
|
1676
|
+
});
|
|
1677
|
+
it("rejects empty path", () => {
|
|
1678
|
+
expect(() => safePath("/base/dir", "")).toThrow();
|
|
1679
|
+
});
|
|
1680
|
+
});
|
|
1681
|
+
describe("path traversal via wiki methods", () => {
|
|
1682
|
+
beforeEach(cleanUp);
|
|
1683
|
+
afterEach(cleanUp);
|
|
1684
|
+
it("rawAdd rejects traversal", () => {
|
|
1685
|
+
const wiki = freshWiki();
|
|
1686
|
+
expect(() => wiki.rawAdd("../escape.txt", { content: "evil" })).toThrow(/traversal/i);
|
|
1687
|
+
});
|
|
1688
|
+
it("rawRead rejects traversal", async () => {
|
|
1689
|
+
const wiki = freshWiki();
|
|
1690
|
+
await expect(wiki.rawRead("../../etc/passwd")).rejects.toThrow(/traversal/i);
|
|
1691
|
+
});
|
|
1692
|
+
it("wiki.read rejects traversal", () => {
|
|
1693
|
+
const wiki = freshWiki();
|
|
1694
|
+
expect(() => wiki.read("../../../etc/passwd")).toThrow(/traversal/i);
|
|
1695
|
+
});
|
|
1696
|
+
it("wiki.write rejects traversal", () => {
|
|
1697
|
+
const wiki = freshWiki();
|
|
1698
|
+
expect(() => wiki.write("../../.bashrc", "---\ntitle: Evil\n---\nHacked")).toThrow(/traversal/i);
|
|
1699
|
+
});
|
|
1700
|
+
it("wiki.delete rejects traversal", () => {
|
|
1701
|
+
const wiki = freshWiki();
|
|
1702
|
+
expect(() => wiki.delete("../important.conf")).toThrow(/traversal/i);
|
|
1703
|
+
});
|
|
1704
|
+
it("allows legitimate subdirectory paths", () => {
|
|
1705
|
+
const wiki = freshWiki();
|
|
1706
|
+
// These should NOT throw
|
|
1707
|
+
wiki.rawAdd("papers/deep/file.txt", { content: "nested ok" });
|
|
1708
|
+
wiki.write("topics/concept-a.md", "---\ntitle: Nested\n---\nOk");
|
|
1709
|
+
expect(wiki.read("topics/concept-a.md")).not.toBeNull();
|
|
1710
|
+
});
|
|
1711
|
+
});
|
|
1712
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1713
|
+
// sourcePath restriction (security boundary for file copy)
|
|
1714
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1715
|
+
describe("sourcePath allowed directory restriction", () => {
|
|
1716
|
+
beforeEach(cleanUp);
|
|
1717
|
+
afterEach(cleanUp);
|
|
1718
|
+
it("allows sourcePath inside workspace (default)", () => {
|
|
1719
|
+
const wiki = freshWiki();
|
|
1720
|
+
const srcFile = join(TEST_ROOT, "local.txt");
|
|
1721
|
+
writeFileSync(srcFile, "ok");
|
|
1722
|
+
const doc = rawAddOne(wiki, "imported.txt", { sourcePath: srcFile });
|
|
1723
|
+
expect(doc.size).toBeGreaterThan(0);
|
|
1724
|
+
});
|
|
1725
|
+
it("rejects sourcePath outside workspace", () => {
|
|
1726
|
+
const wiki = freshWiki();
|
|
1727
|
+
// /tmp is outside the test workspace
|
|
1728
|
+
const outsideFile = join("/tmp", `agent-wiki-test-${Date.now()}.txt`);
|
|
1729
|
+
writeFileSync(outsideFile, "secret");
|
|
1730
|
+
try {
|
|
1731
|
+
expect(() => wiki.rawAdd("stolen.txt", { sourcePath: outsideFile }))
|
|
1732
|
+
.toThrow(/outside allowed directories/i);
|
|
1733
|
+
}
|
|
1734
|
+
finally {
|
|
1735
|
+
rmSync(outsideFile, { force: true });
|
|
1736
|
+
}
|
|
1737
|
+
});
|
|
1738
|
+
it("rejects sourcePath with traversal to escape workspace", () => {
|
|
1739
|
+
const wiki = freshWiki();
|
|
1740
|
+
// Even if file exists, ../../../etc/passwd must be blocked
|
|
1741
|
+
expect(() => wiki.rawAdd("etc.txt", { sourcePath: join(TEST_ROOT, "../../../etc/passwd") }))
|
|
1742
|
+
.toThrow(/outside allowed directories/i);
|
|
1743
|
+
});
|
|
1744
|
+
it("respects custom allowedSourceDirs from config", () => {
|
|
1745
|
+
const wiki = freshWiki();
|
|
1746
|
+
const externalDir = join(TEST_ROOT, "..", "__allowed_external__");
|
|
1747
|
+
mkdirSync(externalDir, { recursive: true });
|
|
1748
|
+
const extFile = join(externalDir, "ext.txt");
|
|
1749
|
+
writeFileSync(extFile, "external ok");
|
|
1750
|
+
// Manually widen the config
|
|
1751
|
+
wiki.config.allowedSourceDirs.push(externalDir);
|
|
1752
|
+
try {
|
|
1753
|
+
const doc = rawAddOne(wiki, "from-ext.txt", { sourcePath: extFile });
|
|
1754
|
+
expect(doc.size).toBeGreaterThan(0);
|
|
1755
|
+
}
|
|
1756
|
+
finally {
|
|
1757
|
+
rmSync(externalDir, { recursive: true, force: true });
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
it("config defaults to workspace only", () => {
|
|
1761
|
+
const wiki = freshWiki();
|
|
1762
|
+
expect(wiki.config.allowedSourceDirs).toEqual([wiki.config.workspace]);
|
|
1763
|
+
});
|
|
1764
|
+
});
|
|
1765
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1766
|
+
// ATLASSIAN — Confluence & Jira (unit tests, no live API)
|
|
1767
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
1768
|
+
import { parseConfluenceUrl, parseJiraUrl, slugify, resolveAuth, validateHost, } from "./atlassian.js";
|
|
1769
|
+
describe("Confluence URL parsing", () => {
|
|
1770
|
+
it("parses Cloud URL with /wiki/ segment and tags it as cloud", () => {
|
|
1771
|
+
const result = parseConfluenceUrl("https://acme.atlassian.net/wiki/spaces/ENG/pages/12345/Architecture-Overview");
|
|
1772
|
+
expect(result.host).toBe("acme.atlassian.net");
|
|
1773
|
+
expect(result.pageId).toBe("12345");
|
|
1774
|
+
expect(result.deployment).toBe("cloud");
|
|
1775
|
+
});
|
|
1776
|
+
it("parses Server / Data Center URL without /wiki/ and tags it as server", () => {
|
|
1777
|
+
const result = parseConfluenceUrl("https://confluence.example.com/spaces/ENG/pages/12345/Architecture-Overview");
|
|
1778
|
+
expect(result.host).toBe("confluence.example.com");
|
|
1779
|
+
expect(result.pageId).toBe("12345");
|
|
1780
|
+
expect(result.deployment).toBe("server");
|
|
1781
|
+
});
|
|
1782
|
+
it("rejects invalid URL with both shapes mentioned in the error", () => {
|
|
1783
|
+
expect(() => parseConfluenceUrl("https://example.com/not-confluence")).toThrow(/Cannot parse/);
|
|
1784
|
+
expect(() => parseConfluenceUrl("https://example.com/not-confluence")).toThrow(/Cloud[\s\S]+Server/);
|
|
1785
|
+
});
|
|
1786
|
+
});
|
|
1787
|
+
describe("Jira URL parsing", () => {
|
|
1788
|
+
it("parses Cloud URL on *.atlassian.net and tags it as cloud", () => {
|
|
1789
|
+
const result = parseJiraUrl("https://acme.atlassian.net/browse/PROJ-123");
|
|
1790
|
+
expect(result.host).toBe("acme.atlassian.net");
|
|
1791
|
+
expect(result.issueKey).toBe("PROJ-123");
|
|
1792
|
+
expect(result.deployment).toBe("cloud");
|
|
1793
|
+
});
|
|
1794
|
+
it("parses Server / Data Center URL on a self-hosted domain and tags it as server", () => {
|
|
1795
|
+
const result = parseJiraUrl("https://jira.example.com/browse/PROJ-456");
|
|
1796
|
+
expect(result.host).toBe("jira.example.com");
|
|
1797
|
+
expect(result.issueKey).toBe("PROJ-456");
|
|
1798
|
+
expect(result.deployment).toBe("server");
|
|
1799
|
+
});
|
|
1800
|
+
it("rejects invalid URL", () => {
|
|
1801
|
+
expect(() => parseJiraUrl("https://example.com/not-jira")).toThrow(/Cannot parse/);
|
|
1802
|
+
});
|
|
1803
|
+
});
|
|
1804
|
+
describe("slugify", () => {
|
|
1805
|
+
it("converts title to safe filename", () => {
|
|
1806
|
+
expect(slugify("Architecture Overview")).toBe("architecture-overview");
|
|
1807
|
+
});
|
|
1808
|
+
it("handles special characters", () => {
|
|
1809
|
+
expect(slugify("API Design (v2) — Draft")).toBe("api-design-v2-draft");
|
|
1810
|
+
});
|
|
1811
|
+
it("truncates long titles", () => {
|
|
1812
|
+
const long = "a".repeat(200);
|
|
1813
|
+
expect(slugify(long).length).toBeLessThanOrEqual(80);
|
|
1814
|
+
});
|
|
1815
|
+
});
|
|
1816
|
+
describe("resolveAuth", () => {
|
|
1817
|
+
it("throws when env var is not set", () => {
|
|
1818
|
+
expect(() => resolveAuth("NONEXISTENT_VAR_12345")).toThrow(/not set/);
|
|
1819
|
+
});
|
|
1820
|
+
it("auto-encodes email:token as Basic auth", () => {
|
|
1821
|
+
process.env.__TEST_AUTH__ = "user@example.com:token123";
|
|
1822
|
+
try {
|
|
1823
|
+
const auth = resolveAuth("__TEST_AUTH__");
|
|
1824
|
+
expect(auth).toMatch(/^Basic /);
|
|
1825
|
+
const decoded = Buffer.from(auth.replace("Basic ", ""), "base64").toString();
|
|
1826
|
+
expect(decoded).toBe("user@example.com:token123");
|
|
1827
|
+
}
|
|
1828
|
+
finally {
|
|
1829
|
+
delete process.env.__TEST_AUTH__;
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
it("passes through Bearer token as-is", () => {
|
|
1833
|
+
process.env.__TEST_AUTH__ = "Bearer abc123";
|
|
1834
|
+
try {
|
|
1835
|
+
expect(resolveAuth("__TEST_AUTH__")).toBe("Bearer abc123");
|
|
1836
|
+
}
|
|
1837
|
+
finally {
|
|
1838
|
+
delete process.env.__TEST_AUTH__;
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1841
|
+
it("auto-prefixes Bearer for a bare PAT (no colon, no prefix)", () => {
|
|
1842
|
+
process.env.__TEST_AUTH__ = "abc123-personal-access-token";
|
|
1843
|
+
try {
|
|
1844
|
+
expect(resolveAuth("__TEST_AUTH__")).toBe("Bearer abc123-personal-access-token");
|
|
1845
|
+
}
|
|
1846
|
+
finally {
|
|
1847
|
+
delete process.env.__TEST_AUTH__;
|
|
1848
|
+
}
|
|
1849
|
+
});
|
|
1850
|
+
it("error message lists all three accepted forms", () => {
|
|
1851
|
+
expect(() => resolveAuth("DEFINITELY_NOT_SET_VAR")).toThrow(/email:api-token/);
|
|
1852
|
+
expect(() => resolveAuth("DEFINITELY_NOT_SET_VAR")).toThrow(/Bearer/);
|
|
1853
|
+
expect(() => resolveAuth("DEFINITELY_NOT_SET_VAR")).toThrow(/Server.*Data Center/);
|
|
1854
|
+
});
|
|
1855
|
+
it("error message points to authEnv as the customization escape hatch", () => {
|
|
1856
|
+
expect(() => resolveAuth("DEFINITELY_NOT_SET_VAR")).toThrow(/authEnv/);
|
|
1857
|
+
});
|
|
1858
|
+
});
|
|
1859
|
+
describe("validateHost", () => {
|
|
1860
|
+
it("allows any host when allowlist is empty", () => {
|
|
1861
|
+
expect(() => validateHost("evil.com", [])).not.toThrow();
|
|
1862
|
+
});
|
|
1863
|
+
it("allows host in allowlist", () => {
|
|
1864
|
+
expect(() => validateHost("acme.atlassian.net", ["acme.atlassian.net"])).not.toThrow();
|
|
1865
|
+
});
|
|
1866
|
+
it("rejects host not in allowlist", () => {
|
|
1867
|
+
expect(() => validateHost("evil.com", ["acme.atlassian.net"])).toThrow(/not in the allowed/);
|
|
1868
|
+
});
|
|
1869
|
+
});
|
|
1870
|
+
describe("atlassian config in WikiConfig", () => {
|
|
1871
|
+
beforeEach(cleanUp);
|
|
1872
|
+
afterEach(cleanUp);
|
|
1873
|
+
it("has default atlassian config", () => {
|
|
1874
|
+
const wiki = freshWiki();
|
|
1875
|
+
expect(wiki.config.atlassian).toBeDefined();
|
|
1876
|
+
expect(wiki.config.atlassian.maxPages).toBe(100);
|
|
1877
|
+
expect(wiki.config.atlassian.maxAttachmentSize).toBe(10 * 1024 * 1024);
|
|
1878
|
+
expect(wiki.config.atlassian.allowedHosts).toEqual([]);
|
|
1879
|
+
});
|
|
1880
|
+
});
|
|
1881
|
+
//# sourceMappingURL=wiki.test.js.map
|