nox-mem 3.4.0 → 3.5.1

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.
Files changed (68) hide show
  1. package/README.md +62 -33
  2. package/dist/api/answer.js +22 -0
  3. package/dist/api-server.js +4 -14
  4. package/dist/cli/answer.js +39 -1
  5. package/dist/db.js +31 -20
  6. package/dist/doctor.js +5 -4
  7. package/dist/embed.js +53 -3
  8. package/dist/index.js +16 -10
  9. package/dist/lib/answer/index.js +3 -2
  10. package/dist/lib/answer/retrieval.js +6 -4
  11. package/dist/lib/answer/temporal.js +51 -0
  12. package/dist/lib/api-port.js +16 -0
  13. package/dist/lib/db-path.js +13 -1
  14. package/dist/lib/ingest-many.js +49 -0
  15. package/dist/lib/query-params.js +19 -0
  16. package/dist/mcp/tools/answer.js +23 -0
  17. package/dist/mcp-server.js +36 -5
  18. package/dist/reflect.js +2 -2
  19. package/dist/reindex-errors.js +19 -0
  20. package/dist/reindex.js +12 -2
  21. package/dist/search.js +27 -6
  22. package/package.json +4 -1
  23. package/prompts/consolidate.txt +13 -0
  24. package/prompts/digest.txt +5 -0
  25. package/dist/__tests__/brief-diversity.test.js +0 -266
  26. package/dist/__tests__/brief.test.js +0 -287
  27. package/dist/__tests__/churn.test.js +0 -66
  28. package/dist/__tests__/edge-typing.test.js +0 -99
  29. package/dist/__tests__/fts-or-fallback.test.js +0 -115
  30. package/dist/__tests__/ingest-event.test.js +0 -151
  31. package/dist/__tests__/op-audit-e2e.test.js +0 -130
  32. package/dist/__tests__/pragma-alignment.test.js +0 -123
  33. package/dist/__tests__/reindex-dedup.test.js +0 -80
  34. package/dist/__tests__/reindex-safety.test.js +0 -116
  35. package/dist/__tests__/reranker.test.js +0 -326
  36. package/dist/__tests__/retention.test.js +0 -99
  37. package/dist/__tests__/search-track-access.test.js +0 -49
  38. package/dist/__tests__/session-distill-sources.test.js +0 -98
  39. package/dist/__tests__/spo-injection.test.js +0 -172
  40. package/dist/__tests__/telemetry-per-chunk.test.js +0 -110
  41. package/dist/__tests__/temporal-detector.test.js +0 -103
  42. package/dist/__tests__/temporal-filter.test.js +0 -117
  43. package/dist/lib/answer/__tests__/e2e-gemini.test.js +0 -229
  44. package/dist/lib/answer/__tests__/integration-sqlite.test.js +0 -388
  45. package/dist/lib/answer/__tests__/integration.test.js +0 -347
  46. package/dist/lib/answer/__tests__/prompt.test.js +0 -117
  47. package/dist/lib/answer/__tests__/t5-t10.test.js +0 -501
  48. package/dist/lib/api/__tests__/safe-error-message.test.js +0 -155
  49. package/dist/lib/auth/__tests__/localhost-guard.test.js +0 -144
  50. package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +0 -354
  51. package/dist/lib/events/__tests__/bus.test.js +0 -208
  52. package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +0 -109
  53. package/dist/lib/regex-extract/__tests__/extractor.test.js +0 -197
  54. package/dist/lib/regex-extract/__tests__/frontmatter.test.js +0 -75
  55. package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +0 -139
  56. package/dist/lib/regex-extract/__tests__/production-wire.test.js +0 -177
  57. package/dist/lib/regex-extract/__tests__/reconcile.test.js +0 -170
  58. package/dist/lib/regex-extract/__tests__/strip-code.test.js +0 -36
  59. package/dist/privacy/__tests__/filter.test.js +0 -352
  60. package/dist/providers/__tests__/conformance-extended.test.js +0 -249
  61. package/dist/providers/__tests__/conformance.test.js +0 -98
  62. package/dist/providers/__tests__/cost-cap.test.js +0 -151
  63. package/dist/providers/__tests__/e2e-real.test.js +0 -79
  64. package/dist/providers/__tests__/factory.test.js +0 -80
  65. package/dist/providers/__tests__/fallback.test.js +0 -223
  66. package/dist/providers/__tests__/gemini.test.js +0 -191
  67. package/dist/providers/__tests__/health.test.js +0 -128
  68. package/dist/providers/__tests__/telemetry.test.js +0 -219
@@ -1,139 +0,0 @@
1
- import { test } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { decideExtraction, mergeRelations } from "../ingest-router-l4.js";
4
- test("router: compiled section + 1 ref → skipGemini=true (regex_only)", () => {
5
- const d = decideExtraction({
6
- section: "compiled",
7
- type: "entity",
8
- content: "see [[feedback/no_secrets]] always",
9
- });
10
- assert.equal(d.skipGemini, true);
11
- assert.equal(d.telemetry.extraction_method, "regex_only");
12
- assert.equal(d.regexRelationsCount, 1);
13
- });
14
- test("router: frontmatter section + agent → skipGemini=true", () => {
15
- const d = decideExtraction({
16
- section: "frontmatter",
17
- type: "entity",
18
- content: "---\nagent: atlas\n---",
19
- });
20
- assert.equal(d.skipGemini, true);
21
- assert.equal(d.regex.frontmatterRelations.length, 1);
22
- });
23
- test("router: timeline section + ref → skipGemini=true", () => {
24
- const d = decideExtraction({
25
- section: "timeline",
26
- type: "entity",
27
- content: "[[decision/d41]] decided",
28
- });
29
- assert.equal(d.skipGemini, true);
30
- });
31
- test("router: prose section → never skip (gemini_only path)", () => {
32
- // prose ∉ SKIP_ELIGIBLE_SECTIONS, so even with regex hits we fall to gemini_only.
33
- // regex_primary_gemini_secondary is reserved for section-eligible chunks that
34
- // still need Gemini for some other gate reason (e.g. mixed structured+prose,
35
- // not modeled here in v1).
36
- const d = decideExtraction({
37
- section: "prose",
38
- type: "spec",
39
- content: "see [[feedback/foo]]",
40
- });
41
- assert.equal(d.skipGemini, false);
42
- assert.equal(d.telemetry.extraction_method, "gemini_only");
43
- });
44
- test("router: conversation chunk type forces Gemini even with refs", () => {
45
- const d = decideExtraction({
46
- section: "compiled",
47
- type: "conversation",
48
- content: "user said [[feedback/foo]]",
49
- });
50
- assert.equal(d.skipGemini, false);
51
- });
52
- test("router: daily_log type forces Gemini", () => {
53
- const d = decideExtraction({
54
- section: "compiled",
55
- type: "daily_log",
56
- content: "today [[decision/d1]]",
57
- });
58
- assert.equal(d.skipGemini, false);
59
- });
60
- test("router: zero regex matches → gemini_only_after_regex_zero", () => {
61
- const d = decideExtraction({
62
- section: "compiled",
63
- type: "entity",
64
- content: "pure prose with no entity refs at all here",
65
- });
66
- assert.equal(d.skipGemini, false);
67
- assert.equal(d.telemetry.extraction_method, "gemini_only_after_regex_zero");
68
- });
69
- test("router: null section → gemini_only (no skip eligibility)", () => {
70
- const d = decideExtraction({
71
- section: null,
72
- type: "other",
73
- content: "[[feedback/foo]] reference",
74
- });
75
- assert.equal(d.skipGemini, false);
76
- assert.equal(d.telemetry.extraction_method, "gemini_only");
77
- });
78
- test("router: telemetry latency populated", () => {
79
- const d = decideExtraction({
80
- section: "compiled",
81
- type: "entity",
82
- content: "[[feedback/x]]",
83
- });
84
- assert.ok(d.telemetry.latency_ms.regex >= 0);
85
- assert.equal(d.telemetry.latency_ms.gemini, null);
86
- });
87
- test("router: code refs counted toward regexRelationsCount", () => {
88
- const d = decideExtraction({
89
- section: "compiled",
90
- type: "entity",
91
- content: "see src/lib/op-audit.ts:42 important",
92
- });
93
- assert.equal(d.regex.codeRefs.length, 1);
94
- assert.equal(d.regexRelationsCount, 1);
95
- assert.equal(d.skipGemini, true);
96
- });
97
- test("merge: dedupes (source|target|type) across regex+gemini", () => {
98
- const merged = mergeRelations([
99
- {
100
- source: "feedback/a",
101
- target: "feedback/b",
102
- relationType: "references",
103
- extraction_method: "regex",
104
- },
105
- ], [
106
- {
107
- source: "feedback/a",
108
- target: "feedback/b",
109
- relationType: "references",
110
- extraction_method: "gemini",
111
- },
112
- {
113
- source: "feedback/a",
114
- target: "feedback/c",
115
- relationType: "references",
116
- extraction_method: "gemini",
117
- },
118
- ]);
119
- assert.equal(merged.length, 2);
120
- assert.equal(merged[0]?.extraction_method, "regex"); // regex wins (earlier in input)
121
- });
122
- test("merge: case-insensitive dedup", () => {
123
- const merged = mergeRelations([
124
- {
125
- source: "Feedback/A",
126
- target: "Feedback/B",
127
- relationType: "References",
128
- extraction_method: "regex",
129
- },
130
- ], [
131
- {
132
- source: "feedback/a",
133
- target: "feedback/b",
134
- relationType: "references",
135
- extraction_method: "gemini",
136
- },
137
- ]);
138
- assert.equal(merged.length, 1);
139
- });
@@ -1,177 +0,0 @@
1
- /**
2
- * T9 — Integration tests for production wire-up (production-wire.ts).
3
- *
4
- * 11 tests covering:
5
- * - Confidence scoring per relation type
6
- * - Fast-path skip decision (threshold=0.8)
7
- * - Bare-ref falls through to LLM (confidence=0.75 < 0.8)
8
- * - Frontmatter typed links skip LLM (confidence=0.95 ≥ 0.8)
9
- * - Wikilink/md-link skip LLM (confidence=0.90 ≥ 0.8)
10
- * - Dedup merge: regex wins over LLM for same triple
11
- * - filterHighConfidence filters below threshold
12
- * - Env flags isRegexEnabled / isSkipGeminiEnabled
13
- * - Telemetry extraction_method propagated correctly
14
- */
15
- import { test } from "node:test";
16
- import assert from "node:assert/strict";
17
- import { runProductionFastPath, filterHighConfidence, mergeWithLlmRelations, isRegexEnabled, CONFIDENCE_THRESHOLD, CONFIDENCE_FRONTMATTER, CONFIDENCE_EXPLICIT_LINK, CONFIDENCE_BARE_REF, scoreEntityRef, scoreFrontmatterRelation, } from "../production-wire.js";
18
- // ---------------------------------------------------------------------------
19
- // scoreEntityRef / scoreFrontmatterRelation
20
- // ---------------------------------------------------------------------------
21
- test("score: wikilink → CONFIDENCE_EXPLICIT_LINK (0.90)", () => {
22
- const ref = {
23
- entityType: "feedback",
24
- slug: "no_secrets",
25
- key: "feedback/no_secrets",
26
- source: "wikilink",
27
- };
28
- assert.equal(scoreEntityRef(ref), CONFIDENCE_EXPLICIT_LINK);
29
- assert.ok(CONFIDENCE_EXPLICIT_LINK >= CONFIDENCE_THRESHOLD);
30
- });
31
- test("score: markdown_link → CONFIDENCE_EXPLICIT_LINK (0.90)", () => {
32
- const ref = {
33
- entityType: "decision",
34
- slug: "d41",
35
- key: "decision/d41",
36
- source: "markdown_link",
37
- };
38
- assert.equal(scoreEntityRef(ref), CONFIDENCE_EXPLICIT_LINK);
39
- });
40
- test("score: bare_ref → CONFIDENCE_BARE_REF (0.75) — below gate threshold", () => {
41
- const ref = {
42
- entityType: "feedback",
43
- slug: "bare_slug",
44
- key: "feedback/bare_slug",
45
- source: "bare_ref",
46
- };
47
- assert.equal(scoreEntityRef(ref), CONFIDENCE_BARE_REF);
48
- assert.ok(CONFIDENCE_BARE_REF < CONFIDENCE_THRESHOLD);
49
- });
50
- test("score: frontmatter relation → CONFIDENCE_FRONTMATTER (0.95)", () => {
51
- const rel = {
52
- relationType: "is_agent_of",
53
- target: "agent/atlas",
54
- raw: "atlas",
55
- };
56
- assert.equal(scoreFrontmatterRelation(rel), CONFIDENCE_FRONTMATTER);
57
- assert.ok(CONFIDENCE_FRONTMATTER >= CONFIDENCE_THRESHOLD);
58
- });
59
- // ---------------------------------------------------------------------------
60
- // runProductionFastPath — skip logic
61
- // ---------------------------------------------------------------------------
62
- test("fast-path: wikilink in compiled section → skipLlm=true", () => {
63
- const result = runProductionFastPath({
64
- section: "compiled",
65
- type: "entity",
66
- content: "see [[feedback/no_secrets]] always",
67
- }, "decision/d41");
68
- assert.equal(result.skipLlm, true);
69
- assert.ok(result.maxConfidence >= CONFIDENCE_THRESHOLD);
70
- assert.equal(result.regexRelations.length, 1);
71
- assert.equal(result.regexRelations[0]?.targetSlug, "feedback/no_secrets");
72
- });
73
- test("fast-path: frontmatter typed link in frontmatter section → skipLlm=true", () => {
74
- const result = runProductionFastPath({
75
- section: "frontmatter",
76
- type: "entity",
77
- content: "---\nagent: atlas\n---",
78
- }, "feedback/src");
79
- assert.equal(result.skipLlm, true);
80
- assert.ok(result.maxConfidence >= CONFIDENCE_THRESHOLD);
81
- const rel = result.regexRelations[0];
82
- assert.equal(rel?.relationType, "is_agent_of");
83
- assert.equal(rel?.relation_reason, "regex_extracted");
84
- });
85
- test("fast-path: bare_ref only → skipLlm=false (confidence 0.75 < threshold 0.8)", () => {
86
- // Bare refs have confidence 0.75. But the section gate also matters:
87
- // in compiled section with ≥1 ref, decideExtraction says skipGemini=true.
88
- // However our confidence gate overrides: maxConfidence must also be ≥ 0.8.
89
- // Bare refs produce 0.75 → combined gate fails → skipLlm=false.
90
- const result = runProductionFastPath({
91
- section: "compiled",
92
- type: "entity",
93
- content: "see feedback/no_secrets here", // bare_ref only
94
- }, "decision/src");
95
- // Max confidence = 0.75 (bare_ref) < 0.80 threshold → skipLlm=false.
96
- assert.equal(result.skipLlm, false);
97
- assert.equal(result.maxConfidence, CONFIDENCE_BARE_REF);
98
- });
99
- test("fast-path: prose section forces LLM even with explicit links", () => {
100
- const result = runProductionFastPath({
101
- section: "prose",
102
- type: "spec",
103
- content: "[[feedback/foo]] explicit link",
104
- }, "decision/src");
105
- // prose section is not eligible for skip (decideExtraction returns skipGemini=false).
106
- assert.equal(result.skipLlm, false);
107
- });
108
- test("fast-path: no relations at all → skipLlm=false, maxConfidence=0", () => {
109
- const result = runProductionFastPath({
110
- section: "compiled",
111
- type: "entity",
112
- content: "pure prose with no entity links whatsoever",
113
- }, "feedback/src");
114
- assert.equal(result.skipLlm, false);
115
- assert.equal(result.maxConfidence, 0);
116
- assert.equal(result.regexRelations.length, 0);
117
- });
118
- test("fast-path: telemetry extraction_method set correctly when skipLlm=true", () => {
119
- const result = runProductionFastPath({
120
- section: "compiled",
121
- type: "entity",
122
- content: "[[decision/d1]]",
123
- }, "feedback/src");
124
- assert.equal(result.telemetry.extraction_method, "regex_only");
125
- assert.equal(result.telemetry.gemini_call_skipped, true);
126
- });
127
- // ---------------------------------------------------------------------------
128
- // filterHighConfidence + mergeWithLlmRelations
129
- // ---------------------------------------------------------------------------
130
- test("filterHighConfidence: removes below-threshold, keeps above", () => {
131
- const rels = [
132
- { sourceSlug: "s", targetSlug: "t1", relationType: "r", confidence: 0.95, extraction_method: "regex", relation_reason: "regex_extracted" },
133
- { sourceSlug: "s", targetSlug: "t2", relationType: "r", confidence: 0.75, extraction_method: "regex", relation_reason: "regex_extracted" },
134
- ];
135
- const filtered = filterHighConfidence(rels);
136
- assert.equal(filtered.length, 1);
137
- assert.equal(filtered[0]?.targetSlug, "t1");
138
- });
139
- test("mergeWithLlmRelations: regex wins dedup for same triple", () => {
140
- const regexRels = [
141
- { sourceSlug: "s", targetSlug: "t1", relationType: "references", confidence: 0.9, extraction_method: "regex", relation_reason: "regex_extracted" },
142
- ];
143
- const llmRels = [
144
- { sourceSlug: "s", targetSlug: "t1", relationType: "references" },
145
- { sourceSlug: "s", targetSlug: "t2", relationType: "references" },
146
- ];
147
- const merged = mergeWithLlmRelations(regexRels, llmRels);
148
- // t1 deduped → regex wins, t2 added from LLM
149
- assert.equal(merged.length, 2);
150
- const t1 = merged.find((r) => r.targetSlug === "t1");
151
- assert.equal(t1?.extraction_method, "regex");
152
- const t2 = merged.find((r) => r.targetSlug === "t2");
153
- assert.equal(t2?.extraction_method, "llm");
154
- assert.equal(t2?.relation_reason, "gemini_extracted");
155
- });
156
- // ---------------------------------------------------------------------------
157
- // Env flags
158
- // ---------------------------------------------------------------------------
159
- test("env flags: isRegexEnabled reads NOX_L4_REGEX_ENABLED", () => {
160
- const originalEnv = process.env["NOX_L4_REGEX_ENABLED"];
161
- try {
162
- process.env["NOX_L4_REGEX_ENABLED"] = "1";
163
- assert.equal(isRegexEnabled(), true);
164
- process.env["NOX_L4_REGEX_ENABLED"] = "0";
165
- assert.equal(isRegexEnabled(), false);
166
- delete process.env["NOX_L4_REGEX_ENABLED"];
167
- assert.equal(isRegexEnabled(), false);
168
- }
169
- finally {
170
- if (originalEnv === undefined) {
171
- delete process.env["NOX_L4_REGEX_ENABLED"];
172
- }
173
- else {
174
- process.env["NOX_L4_REGEX_ENABLED"] = originalEnv;
175
- }
176
- }
177
- });
@@ -1,170 +0,0 @@
1
- /**
2
- * T7 — Tests for stale-link reconciliation (reconcile.ts).
3
- *
4
- * 12 tests covering:
5
- * - Rename detection
6
- * - Auto-rename mode (NOX_L4_AUTO_RENAME=1)
7
- * - Stale-mark mode (default)
8
- * - Edge cases: multiple renames, circular detection, noop
9
- */
10
- import { test } from "node:test";
11
- import assert from "node:assert/strict";
12
- import { reconcileEntityLinks, extractTargetSlugsFromContent, detectSlugChange, rewriteChunksForRename, detectCircularRename, STALE_CONFIDENCE, STALE_REASON, } from "../reconcile.js";
13
- // ---------------------------------------------------------------------------
14
- // Helpers
15
- // ---------------------------------------------------------------------------
16
- function makeRel(targetSlug, overrides = {}) {
17
- return {
18
- key: `feedback/src|${targetSlug}|references`,
19
- sourceSlug: "feedback/src",
20
- targetSlug,
21
- relationType: "references",
22
- extraction_method: "regex",
23
- confidence: 0.9,
24
- superseded: false,
25
- ...overrides,
26
- };
27
- }
28
- // ---------------------------------------------------------------------------
29
- // extractTargetSlugsFromContent
30
- // ---------------------------------------------------------------------------
31
- test("extractTargetSlugs: wikilinks extracted", () => {
32
- const slugs = extractTargetSlugsFromContent("see [[feedback/foo]] and [[decision/d1]]");
33
- assert.ok(slugs.has("feedback/foo"));
34
- assert.ok(slugs.has("decision/d1"));
35
- assert.equal(slugs.size, 2);
36
- });
37
- test("extractTargetSlugs: frontmatter references field included", () => {
38
- const content = "---\nreferences: [feedback/a, lesson/b]\n---\n\nbody";
39
- const slugs = extractTargetSlugsFromContent(content);
40
- assert.ok(slugs.has("feedback/a"));
41
- assert.ok(slugs.has("lesson/b"));
42
- });
43
- test("extractTargetSlugs: empty content returns empty set", () => {
44
- const slugs = extractTargetSlugsFromContent("");
45
- assert.equal(slugs.size, 0);
46
- });
47
- // ---------------------------------------------------------------------------
48
- // detectSlugChange
49
- // ---------------------------------------------------------------------------
50
- test("detectSlugChange: detects slug change via frontmatter", () => {
51
- const oldContent = "---\nslug: old-slug\n---\n# Old content";
52
- const newContent = "---\nslug: new-slug\n---\n# New content";
53
- const result = detectSlugChange(oldContent, newContent);
54
- assert.equal(result.changed, true);
55
- assert.equal(result.oldSlug, "old-slug");
56
- assert.equal(result.newSlug, "new-slug");
57
- });
58
- test("detectSlugChange: no change when slugs match", () => {
59
- const content = "---\nslug: same\n---\n# Same";
60
- const result = detectSlugChange(content, content);
61
- assert.equal(result.changed, false);
62
- });
63
- test("detectSlugChange: falls back to H1 heading when no frontmatter slug", () => {
64
- const old = "# My Old Title";
65
- const fresh = "# My New Title";
66
- const result = detectSlugChange(old, fresh);
67
- assert.equal(result.changed, true);
68
- assert.equal(result.oldSlug, "My Old Title");
69
- assert.equal(result.newSlug, "My New Title");
70
- });
71
- // ---------------------------------------------------------------------------
72
- // reconcileEntityLinks — stale-mark mode (default)
73
- // ---------------------------------------------------------------------------
74
- test("reconcile stale-mark: removed link gets mark_stale action with STALE_CONFIDENCE", () => {
75
- const existing = [makeRel("decision/d1")];
76
- // New content no longer references decision/d1.
77
- const result = reconcileEntityLinks("feedback/src", "nothing here", existing);
78
- assert.equal(result.mode, "stale_mark");
79
- assert.equal(result.removed.length, 1);
80
- assert.equal(result.removed[0], "decision/d1");
81
- const action = result.actions.find((a) => a.type === "mark_stale");
82
- assert.ok(action, "expected mark_stale action");
83
- if (action?.type === "mark_stale") {
84
- assert.equal(action.newConfidence, STALE_CONFIDENCE);
85
- assert.equal(action.supersededReason, STALE_REASON);
86
- }
87
- });
88
- test("reconcile stale-mark: unchanged link gets noop action", () => {
89
- const existing = [makeRel("feedback/foo")];
90
- const result = reconcileEntityLinks("feedback/src", "see [[feedback/foo]]", existing);
91
- assert.equal(result.unchanged.length, 1);
92
- assert.equal(result.actions.find((a) => a.type === "noop")?.targetSlug, "feedback/foo");
93
- });
94
- test("reconcile stale-mark: new link gets add action", () => {
95
- const result = reconcileEntityLinks("feedback/src", "see [[decision/new]]", []);
96
- assert.equal(result.added.length, 1);
97
- const addAction = result.actions.find((a) => a.type === "add");
98
- assert.ok(addAction);
99
- if (addAction?.type === "add") {
100
- assert.equal(addAction.targetSlug, "decision/new");
101
- }
102
- });
103
- test("reconcile stale-mark: gemini relations are NOT touched", () => {
104
- const existing = [
105
- makeRel("feedback/gemini-only", { extraction_method: "gemini" }),
106
- makeRel("decision/regex-link"),
107
- ];
108
- // New content only has decision/regex-link; feedback/gemini-only not present.
109
- const result = reconcileEntityLinks("feedback/src", "[[decision/regex-link]]", existing);
110
- // Only the regex relation gets reconciled; gemini relation is invisible to reconciler.
111
- assert.ok(!result.removed.includes("feedback/gemini-only"), "gemini relation must not be marked stale");
112
- assert.equal(result.unchanged.includes("decision/regex-link"), true);
113
- });
114
- // ---------------------------------------------------------------------------
115
- // reconcileEntityLinks — auto-rename mode
116
- // ---------------------------------------------------------------------------
117
- test("reconcile auto-rename: emits auto_rename action with old→new slug", () => {
118
- const existing = [makeRel("feedback/old-slug")];
119
- const result = reconcileEntityLinks("feedback/src", "content with no explicit links", existing, { autoRename: true, newSlug: "feedback/new-slug" });
120
- assert.equal(result.mode, "auto_rename");
121
- const renameAction = result.actions.find((a) => a.type === "auto_rename");
122
- assert.ok(renameAction, "expected auto_rename action");
123
- if (renameAction?.type === "auto_rename") {
124
- assert.equal(renameAction.oldTargetSlug, "feedback/old-slug");
125
- assert.equal(renameAction.newTargetSlug, "feedback/new-slug");
126
- }
127
- });
128
- test("reconcile auto-rename: falls back to stale-mark when newSlug not provided", () => {
129
- const existing = [makeRel("feedback/old")];
130
- const result = reconcileEntityLinks("feedback/src", "no links here", existing, { autoRename: true });
131
- // Without newSlug, even with autoRename=true, mode is stale_mark.
132
- assert.equal(result.mode, "stale_mark");
133
- assert.ok(result.actions.find((a) => a.type === "mark_stale"));
134
- });
135
- // ---------------------------------------------------------------------------
136
- // rewriteChunksForRename
137
- // ---------------------------------------------------------------------------
138
- test("rewriteChunks: rewrites wikilink in chunk content", () => {
139
- const chunks = [{ chunkId: "c1", content: "see [[feedback/old-slug]] here" }];
140
- const results = rewriteChunksForRename(chunks, "feedback/old-slug", "feedback/new-slug");
141
- assert.equal(results.length, 1);
142
- assert.equal(results[0]?.changed, true);
143
- assert.ok(results[0]?.rewritten.includes("feedback/new-slug"));
144
- assert.ok(!results[0]?.rewritten.includes("feedback/old-slug"));
145
- });
146
- test("rewriteChunks: identical oldSlug=newSlug returns unchanged", () => {
147
- const chunks = [{ chunkId: "c1", content: "[[feedback/slug]]" }];
148
- const results = rewriteChunksForRename(chunks, "feedback/slug", "feedback/slug");
149
- assert.equal(results[0]?.changed, false);
150
- });
151
- // ---------------------------------------------------------------------------
152
- // detectCircularRename
153
- // ---------------------------------------------------------------------------
154
- test("detectCircularRename: A→B→C no cycle → null", () => {
155
- const renames = [
156
- { from: "feedback/a", to: "feedback/b" },
157
- { from: "feedback/b", to: "feedback/c" },
158
- ];
159
- const result = detectCircularRename(renames);
160
- assert.equal(result, null);
161
- });
162
- test("detectCircularRename: A→B→A cycle detected", () => {
163
- const renames = [
164
- { from: "feedback/a", to: "feedback/b" },
165
- { from: "feedback/b", to: "feedback/a" },
166
- ];
167
- const result = detectCircularRename(renames);
168
- assert.ok(result !== null, "expected cycle error");
169
- assert.ok(result?.includes("Circular rename detected"));
170
- });
@@ -1,36 +0,0 @@
1
- import { test } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { stripCodeBlocks } from "../strip-code.js";
4
- test("strip: keeps plain prose untouched", () => {
5
- const { stripped, hadFences } = stripCodeBlocks("Hello [[feedback/x]]");
6
- assert.equal(stripped, "Hello [[feedback/x]]");
7
- assert.equal(hadFences, false);
8
- });
9
- test("strip: nukes fenced ``` block but preserves newlines", () => {
10
- const text = "before\n```ts\n[[feedback/bad]]\n```\nafter";
11
- const { stripped, hadFences } = stripCodeBlocks(text);
12
- assert.equal(hadFences, true);
13
- assert.ok(!stripped.includes("[[feedback/bad]]"));
14
- assert.equal(stripped.split("\n").length, text.split("\n").length);
15
- });
16
- test("strip: blanks inline `code`", () => {
17
- const { stripped, hadFences } = stripCodeBlocks("see `feedback/foo` ok");
18
- assert.equal(hadFences, true);
19
- assert.ok(!stripped.includes("feedback/foo"));
20
- assert.equal(stripped.length, "see `feedback/foo` ok".length);
21
- });
22
- test("strip: handles fenced block without language tag", () => {
23
- const { stripped } = stripCodeBlocks("```\n[[feedback/x]]\n```");
24
- assert.ok(!stripped.includes("[[feedback/x]]"));
25
- });
26
- test("strip: preserves length character-for-character", () => {
27
- const text = "a `b` c";
28
- const { stripped } = stripCodeBlocks(text);
29
- assert.equal(stripped.length, text.length);
30
- });
31
- test("strip: handles indented 4-space code block", () => {
32
- const text = "ok\n [[feedback/x]]\n more code\nback to prose";
33
- const { stripped, hadFences } = stripCodeBlocks(text);
34
- assert.equal(hadFences, true);
35
- assert.ok(!stripped.includes("[[feedback/x]]"));
36
- });