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.
- package/README.md +62 -33
- package/dist/api/answer.js +22 -0
- package/dist/api-server.js +4 -14
- package/dist/cli/answer.js +39 -1
- package/dist/db.js +31 -20
- package/dist/doctor.js +5 -4
- package/dist/embed.js +53 -3
- package/dist/index.js +16 -10
- package/dist/lib/answer/index.js +3 -2
- package/dist/lib/answer/retrieval.js +6 -4
- package/dist/lib/answer/temporal.js +51 -0
- package/dist/lib/api-port.js +16 -0
- package/dist/lib/db-path.js +13 -1
- package/dist/lib/ingest-many.js +49 -0
- package/dist/lib/query-params.js +19 -0
- package/dist/mcp/tools/answer.js +23 -0
- package/dist/mcp-server.js +36 -5
- package/dist/reflect.js +2 -2
- package/dist/reindex-errors.js +19 -0
- package/dist/reindex.js +12 -2
- package/dist/search.js +27 -6
- package/package.json +4 -1
- package/prompts/consolidate.txt +13 -0
- package/prompts/digest.txt +5 -0
- package/dist/__tests__/brief-diversity.test.js +0 -266
- package/dist/__tests__/brief.test.js +0 -287
- package/dist/__tests__/churn.test.js +0 -66
- package/dist/__tests__/edge-typing.test.js +0 -99
- package/dist/__tests__/fts-or-fallback.test.js +0 -115
- package/dist/__tests__/ingest-event.test.js +0 -151
- package/dist/__tests__/op-audit-e2e.test.js +0 -130
- package/dist/__tests__/pragma-alignment.test.js +0 -123
- package/dist/__tests__/reindex-dedup.test.js +0 -80
- package/dist/__tests__/reindex-safety.test.js +0 -116
- package/dist/__tests__/reranker.test.js +0 -326
- package/dist/__tests__/retention.test.js +0 -99
- package/dist/__tests__/search-track-access.test.js +0 -49
- package/dist/__tests__/session-distill-sources.test.js +0 -98
- package/dist/__tests__/spo-injection.test.js +0 -172
- package/dist/__tests__/telemetry-per-chunk.test.js +0 -110
- package/dist/__tests__/temporal-detector.test.js +0 -103
- package/dist/__tests__/temporal-filter.test.js +0 -117
- package/dist/lib/answer/__tests__/e2e-gemini.test.js +0 -229
- package/dist/lib/answer/__tests__/integration-sqlite.test.js +0 -388
- package/dist/lib/answer/__tests__/integration.test.js +0 -347
- package/dist/lib/answer/__tests__/prompt.test.js +0 -117
- package/dist/lib/answer/__tests__/t5-t10.test.js +0 -501
- package/dist/lib/api/__tests__/safe-error-message.test.js +0 -155
- package/dist/lib/auth/__tests__/localhost-guard.test.js +0 -144
- package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +0 -354
- package/dist/lib/events/__tests__/bus.test.js +0 -208
- package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +0 -109
- package/dist/lib/regex-extract/__tests__/extractor.test.js +0 -197
- package/dist/lib/regex-extract/__tests__/frontmatter.test.js +0 -75
- package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +0 -139
- package/dist/lib/regex-extract/__tests__/production-wire.test.js +0 -177
- package/dist/lib/regex-extract/__tests__/reconcile.test.js +0 -170
- package/dist/lib/regex-extract/__tests__/strip-code.test.js +0 -36
- package/dist/privacy/__tests__/filter.test.js +0 -352
- package/dist/providers/__tests__/conformance-extended.test.js +0 -249
- package/dist/providers/__tests__/conformance.test.js +0 -98
- package/dist/providers/__tests__/cost-cap.test.js +0 -151
- package/dist/providers/__tests__/e2e-real.test.js +0 -79
- package/dist/providers/__tests__/factory.test.js +0 -80
- package/dist/providers/__tests__/fallback.test.js +0 -223
- package/dist/providers/__tests__/gemini.test.js +0 -191
- package/dist/providers/__tests__/health.test.js +0 -128
- package/dist/providers/__tests__/telemetry.test.js +0 -219
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* P5a Event Bus Tests
|
|
3
|
-
* 13 test cases covering:
|
|
4
|
-
* - Fire-forget (emit never blocks caller)
|
|
5
|
-
* - Listener receives data asynchronously
|
|
6
|
-
* - Typed payloads for all 9 EventKinds
|
|
7
|
-
* - Max-listeners set to 50 (no warning)
|
|
8
|
-
* - No listener leak after unsubscribe
|
|
9
|
-
* - Performance: <1ms overhead per emit (n=1000)
|
|
10
|
-
*/
|
|
11
|
-
import { describe, it } from "node:test";
|
|
12
|
-
import assert from "node:assert/strict";
|
|
13
|
-
import { bus, emit, EventKind, } from "../bus.js";
|
|
14
|
-
// Helper: wait for setImmediate to flush
|
|
15
|
-
function nextImmediate() {
|
|
16
|
-
return new Promise((resolve) => setImmediate(resolve));
|
|
17
|
-
}
|
|
18
|
-
// Helper: capture next event of a kind
|
|
19
|
-
function captureNext(kind) {
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
bus.once(kind, (data) => resolve(data));
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
describe("Event Bus — core", () => {
|
|
25
|
-
it("T01: emitAsync does not block caller (returns before listener fires)", (t, done) => {
|
|
26
|
-
let listenerFired = false;
|
|
27
|
-
bus.once(EventKind.HEALTH_WARNING, () => {
|
|
28
|
-
listenerFired = true;
|
|
29
|
-
});
|
|
30
|
-
bus.emitAsync(EventKind.HEALTH_WARNING, {
|
|
31
|
-
code: "test",
|
|
32
|
-
message: "test warning",
|
|
33
|
-
severity: "warn",
|
|
34
|
-
ts: Date.now(),
|
|
35
|
-
});
|
|
36
|
-
// Must be false immediately after emitAsync returns
|
|
37
|
-
assert.equal(listenerFired, false, "Listener must NOT have fired synchronously");
|
|
38
|
-
setImmediate(() => {
|
|
39
|
-
assert.equal(listenerFired, true, "Listener must fire after setImmediate");
|
|
40
|
-
done();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
it("T02: emit() helper fires via setImmediate (fire-forget)", (t, done) => {
|
|
44
|
-
let received = false;
|
|
45
|
-
bus.once(EventKind.CHUNK_CREATED, () => {
|
|
46
|
-
received = true;
|
|
47
|
-
});
|
|
48
|
-
emit(EventKind.CHUNK_CREATED, { chunk_id: 1, ts: Date.now() });
|
|
49
|
-
assert.equal(received, false, "Must not be synchronous");
|
|
50
|
-
setImmediate(() => {
|
|
51
|
-
assert.equal(received, true);
|
|
52
|
-
done();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
it("T03: listener receives correct typed payload", async () => {
|
|
56
|
-
const expected = {
|
|
57
|
-
chunk_id: 42,
|
|
58
|
-
source_file: "test.md",
|
|
59
|
-
type: "lesson",
|
|
60
|
-
section: "compiled",
|
|
61
|
-
token_count: 128,
|
|
62
|
-
ts: Date.now(),
|
|
63
|
-
};
|
|
64
|
-
const capture = captureNext(EventKind.CHUNK_CREATED);
|
|
65
|
-
emit(EventKind.CHUNK_CREATED, expected);
|
|
66
|
-
const received = await capture;
|
|
67
|
-
assert.deepEqual(received, expected);
|
|
68
|
-
});
|
|
69
|
-
it("T04: chunk.deleted payload round-trips", async () => {
|
|
70
|
-
const capture = captureNext(EventKind.CHUNK_DELETED);
|
|
71
|
-
emit(EventKind.CHUNK_DELETED, { chunk_id: 99, ts: 1234 });
|
|
72
|
-
const received = await capture;
|
|
73
|
-
assert.deepEqual(received, { chunk_id: 99, ts: 1234 });
|
|
74
|
-
});
|
|
75
|
-
it("T05: kg.entity.created payload round-trips", async () => {
|
|
76
|
-
const capture = captureNext(EventKind.KG_ENTITY_CREATED);
|
|
77
|
-
emit(EventKind.KG_ENTITY_CREATED, {
|
|
78
|
-
entity_id: 7,
|
|
79
|
-
name: "TestEntity",
|
|
80
|
-
entity_type: "person",
|
|
81
|
-
ts: Date.now(),
|
|
82
|
-
});
|
|
83
|
-
const received = await capture;
|
|
84
|
-
assert.equal(received.entity_id, 7);
|
|
85
|
-
assert.equal(received.name, "TestEntity");
|
|
86
|
-
});
|
|
87
|
-
it("T06: kg.relation.created payload round-trips", async () => {
|
|
88
|
-
const capture = captureNext(EventKind.KG_RELATION_CREATED);
|
|
89
|
-
emit(EventKind.KG_RELATION_CREATED, {
|
|
90
|
-
relation_id: 3,
|
|
91
|
-
source_entity_id: 1,
|
|
92
|
-
target_entity_id: 2,
|
|
93
|
-
relation_type: "WORKS_AT",
|
|
94
|
-
ts: Date.now(),
|
|
95
|
-
});
|
|
96
|
-
const received = await capture;
|
|
97
|
-
assert.equal(received.relation_type, "WORKS_AT");
|
|
98
|
-
});
|
|
99
|
-
it("T07: search.executed payload round-trips", async () => {
|
|
100
|
-
const capture = captureNext(EventKind.SEARCH_EXECUTED);
|
|
101
|
-
emit(EventKind.SEARCH_EXECUTED, {
|
|
102
|
-
query_hash: "abc123",
|
|
103
|
-
latency_ms: 45,
|
|
104
|
-
top_k: 10,
|
|
105
|
-
result_count: 8,
|
|
106
|
-
mode: "hybrid",
|
|
107
|
-
ts: Date.now(),
|
|
108
|
-
});
|
|
109
|
-
const received = await capture;
|
|
110
|
-
assert.equal(received.query_hash, "abc123");
|
|
111
|
-
assert.equal(received.mode, "hybrid");
|
|
112
|
-
});
|
|
113
|
-
it("T08: provider.call payload round-trips", async () => {
|
|
114
|
-
const capture = captureNext(EventKind.PROVIDER_CALL);
|
|
115
|
-
emit(EventKind.PROVIDER_CALL, {
|
|
116
|
-
provider: "gemini",
|
|
117
|
-
op_type: "embed",
|
|
118
|
-
latency_ms: 120,
|
|
119
|
-
cost_usd: 0.00001,
|
|
120
|
-
model: "gemini-embedding-001",
|
|
121
|
-
token_count: 512,
|
|
122
|
-
ts: Date.now(),
|
|
123
|
-
});
|
|
124
|
-
const received = await capture;
|
|
125
|
-
assert.equal(received.provider, "gemini");
|
|
126
|
-
assert.equal(received.op_type, "embed");
|
|
127
|
-
});
|
|
128
|
-
it("T09: op_audit.started and op_audit.completed round-trip", async () => {
|
|
129
|
-
const captureStart = captureNext(EventKind.OP_AUDIT_STARTED);
|
|
130
|
-
const captureEnd = captureNext(EventKind.OP_AUDIT_COMPLETED);
|
|
131
|
-
emit(EventKind.OP_AUDIT_STARTED, { op_id: 10, op_type: "reindex", ts: Date.now() });
|
|
132
|
-
emit(EventKind.OP_AUDIT_COMPLETED, {
|
|
133
|
-
op_id: 10,
|
|
134
|
-
op_type: "reindex",
|
|
135
|
-
status: "success",
|
|
136
|
-
duration_ms: 3200,
|
|
137
|
-
ts: Date.now(),
|
|
138
|
-
});
|
|
139
|
-
const [start, end] = await Promise.all([captureStart, captureEnd]);
|
|
140
|
-
assert.equal(start.op_id, 10);
|
|
141
|
-
assert.equal(end.status, "success");
|
|
142
|
-
assert.equal(end.duration_ms, 3200);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
describe("Event Bus — listener management", () => {
|
|
146
|
-
it("T10: max listeners is 50 (no EventEmitter leak warning)", () => {
|
|
147
|
-
// EventEmitter warns when maxListeners is exceeded; confirm it's 50
|
|
148
|
-
assert.equal(bus.getMaxListeners(), 50);
|
|
149
|
-
});
|
|
150
|
-
it("T11: subscribe() returns working unsubscribe — no leak", () => {
|
|
151
|
-
let callCount = 0;
|
|
152
|
-
const unsub = bus.subscribe(EventKind.HEALTH_WARNING, () => {
|
|
153
|
-
callCount++;
|
|
154
|
-
});
|
|
155
|
-
const beforeCount = bus.listenerCount(EventKind.HEALTH_WARNING);
|
|
156
|
-
unsub();
|
|
157
|
-
const afterCount = bus.listenerCount(EventKind.HEALTH_WARNING);
|
|
158
|
-
assert.equal(afterCount, beforeCount - 1, "Listener must be removed after unsub");
|
|
159
|
-
});
|
|
160
|
-
it("T12: multiple listeners on same kind all receive event", (t, done) => {
|
|
161
|
-
let fires = 0;
|
|
162
|
-
const target = 3;
|
|
163
|
-
const handlers = Array.from({ length: target }, () => () => {
|
|
164
|
-
fires++;
|
|
165
|
-
if (fires === target)
|
|
166
|
-
done();
|
|
167
|
-
});
|
|
168
|
-
handlers.forEach((h) => bus.once(EventKind.CHUNK_CREATED, h));
|
|
169
|
-
emit(EventKind.CHUNK_CREATED, { chunk_id: 0, ts: Date.now() });
|
|
170
|
-
});
|
|
171
|
-
it("T13: bus.stats() only includes kinds with active listeners", () => {
|
|
172
|
-
// Remove all listeners for a clean baseline on a rarely-used kind
|
|
173
|
-
bus.removeAllListeners(EventKind.KG_RELATION_CREATED);
|
|
174
|
-
const stats = bus.stats();
|
|
175
|
-
assert.equal(stats[EventKind.KG_RELATION_CREATED], undefined);
|
|
176
|
-
// Add one listener and verify it appears
|
|
177
|
-
const unsub = bus.subscribe(EventKind.KG_RELATION_CREATED, () => { });
|
|
178
|
-
const statsAfter = bus.stats();
|
|
179
|
-
assert.equal(statsAfter[EventKind.KG_RELATION_CREATED], 1);
|
|
180
|
-
unsub();
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
describe("Event Bus — performance", () => {
|
|
184
|
-
it("T14: 1000 emits overhead <1ms per emit (setImmediate scheduling only)", (t, done) => {
|
|
185
|
-
const N = 1000;
|
|
186
|
-
let received = 0;
|
|
187
|
-
// Register one listener to ensure event dispatching path is exercised
|
|
188
|
-
bus.on(EventKind.PROVIDER_CALL, () => {
|
|
189
|
-
received++;
|
|
190
|
-
if (received === N) {
|
|
191
|
-
bus.removeAllListeners(EventKind.PROVIDER_CALL);
|
|
192
|
-
done();
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const start = performance.now();
|
|
196
|
-
for (let i = 0; i < N; i++) {
|
|
197
|
-
emit(EventKind.PROVIDER_CALL, {
|
|
198
|
-
provider: "gemini",
|
|
199
|
-
op_type: "embed",
|
|
200
|
-
latency_ms: i,
|
|
201
|
-
ts: Date.now(),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
const emitDuration = performance.now() - start;
|
|
205
|
-
// All 1000 emitAsync calls must complete in <1ms total (just setImmediate scheduling)
|
|
206
|
-
assert.ok(emitDuration < 10, `emitAsync scheduling 1000 events took ${emitDuration.toFixed(2)}ms — expected <10ms`);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* G10 — Tests for ran_at server-side enforcement.
|
|
3
|
-
*
|
|
4
|
-
* 6 tests covering:
|
|
5
|
-
* 1. validateAuditTimestamp: accepts timestamp within 24h drift
|
|
6
|
-
* 2. validateAuditTimestamp: rejects backdated timestamp (>24h)
|
|
7
|
-
* 3. validateAuditTimestampIso: rejects backdated ISO string
|
|
8
|
-
* 4. overrideWithServerTime (ops_audit): forces started_at to server time
|
|
9
|
-
* 5. overrideWithServerTime (confidence_eval_log): forces ran_at to ISO
|
|
10
|
-
* 6. SQL trigger behavior: insert with backdated ran_at → trigger overrides
|
|
11
|
-
* (uses in-memory SQLite to verify v23 migration trigger logic)
|
|
12
|
-
*
|
|
13
|
-
* Run: node --test staged-G10/edits/src/lib/op-audit-extension/__tests__/ran-at-guard.test.ts
|
|
14
|
-
*/
|
|
15
|
-
import { describe, it } from "node:test";
|
|
16
|
-
import assert from "node:assert/strict";
|
|
17
|
-
import { validateAuditTimestamp, validateAuditTimestampIso, overrideWithServerTime, MAX_TIMESTAMP_DRIFT_MS, serverTimestampMs, } from "../ran-at-guard.js";
|
|
18
|
-
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
19
|
-
describe("G10 — ran-at-guard", () => {
|
|
20
|
-
// ── validateAuditTimestamp ─────────────────────────────────────────────────
|
|
21
|
-
it("accepts timestamp within 1 hour (well within 24h drift)", () => {
|
|
22
|
-
const now = Date.now();
|
|
23
|
-
const oneHourAgo = now - 60 * 60 * 1000;
|
|
24
|
-
const result = validateAuditTimestamp(oneHourAgo, now);
|
|
25
|
-
assert.equal(result.valid, true);
|
|
26
|
-
});
|
|
27
|
-
it("rejects backdated timestamp 48h in the past (>24h drift)", () => {
|
|
28
|
-
const now = Date.now();
|
|
29
|
-
const twoDaysAgo = now - 48 * 60 * 60 * 1000;
|
|
30
|
-
const result = validateAuditTimestamp(twoDaysAgo, now);
|
|
31
|
-
assert.equal(result.valid, false);
|
|
32
|
-
if (!result.valid) {
|
|
33
|
-
assert.ok(result.driftMs >= MAX_TIMESTAMP_DRIFT_MS, `expected driftMs >= ${MAX_TIMESTAMP_DRIFT_MS}, got ${result.driftMs}`);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
it("rejects backdated ISO string 25h in the past", () => {
|
|
37
|
-
const now = Date.now();
|
|
38
|
-
const twentyFiveHoursAgo = new Date(now - 25 * 60 * 60 * 1000).toISOString();
|
|
39
|
-
const result = validateAuditTimestampIso(twentyFiveHoursAgo, now);
|
|
40
|
-
assert.equal(result.valid, false);
|
|
41
|
-
});
|
|
42
|
-
// ── overrideWithServerTime ─────────────────────────────────────────────────
|
|
43
|
-
it("overrideWithServerTime (ops_audit): forces started_at to server time", () => {
|
|
44
|
-
const backdated = Date.now() - 7 * 24 * 60 * 60 * 1000; // 7 days ago
|
|
45
|
-
const row = {
|
|
46
|
-
op: "reindex",
|
|
47
|
-
started_at: backdated,
|
|
48
|
-
status: "started",
|
|
49
|
-
pid: 1234,
|
|
50
|
-
ran_by: "test",
|
|
51
|
-
};
|
|
52
|
-
const now = serverTimestampMs();
|
|
53
|
-
const result = overrideWithServerTime(row, "ops_audit");
|
|
54
|
-
assert.ok(typeof result.started_at === "number", "started_at should be a number");
|
|
55
|
-
assert.ok(result.started_at >= now - 1000 && result.started_at <= now + 1000, `started_at should be ~server time, got ${result.started_at}`);
|
|
56
|
-
assert.notEqual(result.started_at, backdated, "backdated value should be replaced");
|
|
57
|
-
});
|
|
58
|
-
it("overrideWithServerTime (confidence_eval_log): forces ran_at to ISO server time", () => {
|
|
59
|
-
const backdatedIso = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString();
|
|
60
|
-
const row = {
|
|
61
|
-
run_id: "test-run",
|
|
62
|
-
query_id: "Q-001",
|
|
63
|
-
variant: "A",
|
|
64
|
-
ndcg_at_10: 0.75,
|
|
65
|
-
delta_vs_baseline: 0.0,
|
|
66
|
-
ran_at: backdatedIso,
|
|
67
|
-
notes: "test",
|
|
68
|
-
};
|
|
69
|
-
const result = overrideWithServerTime(row, "confidence_eval_log");
|
|
70
|
-
assert.equal(typeof result.ran_at, "string");
|
|
71
|
-
// Should be a recent ISO string (within 5s of now)
|
|
72
|
-
const resultMs = new Date(result.ran_at).getTime();
|
|
73
|
-
const nowMs = Date.now();
|
|
74
|
-
assert.ok(Math.abs(resultMs - nowMs) < 5000, `ran_at should be ~server time, got ${result.ran_at}`);
|
|
75
|
-
assert.notEqual(result.ran_at, backdatedIso, "backdated ISO should be replaced");
|
|
76
|
-
});
|
|
77
|
-
// ── SQL trigger behavior ───────────────────────────────────────────────────
|
|
78
|
-
it("SQL trigger (v23): confidence_eval_log backdated ran_at is overridden", () => {
|
|
79
|
-
// This test verifies the trigger logic using better-sqlite3 if available,
|
|
80
|
-
// or documents the expected behavior if not installed in this test env.
|
|
81
|
-
//
|
|
82
|
-
// The trigger in v23 uses:
|
|
83
|
-
// WHEN NEW.ran_at < strftime('%Y-%m-%dT%H:%M:%SZ', datetime('now', '-1 day'))
|
|
84
|
-
// → UPDATE confidence_eval_log SET ran_at = strftime(...)
|
|
85
|
-
//
|
|
86
|
-
// We verify this logic at the application layer (overrideWithServerTime
|
|
87
|
-
// already covers this; SQL trigger is defence-in-depth).
|
|
88
|
-
// Simulate trigger: backdated ISO should be replaced
|
|
89
|
-
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString();
|
|
90
|
-
const row = {
|
|
91
|
-
run_id: "run-sql-trigger-test",
|
|
92
|
-
query_id: "Q-trigger",
|
|
93
|
-
variant: "B",
|
|
94
|
-
ndcg_at_10: 0.6,
|
|
95
|
-
delta_vs_baseline: -0.05,
|
|
96
|
-
ran_at: thirtyDaysAgo,
|
|
97
|
-
};
|
|
98
|
-
// Application layer override (mirrors trigger behavior)
|
|
99
|
-
const enforced = overrideWithServerTime(row, "confidence_eval_log");
|
|
100
|
-
const resultMs = new Date(enforced.ran_at).getTime();
|
|
101
|
-
// Verify the override is within the last 24h (not 30 days ago)
|
|
102
|
-
const check = validateAuditTimestampIso(enforced.ran_at);
|
|
103
|
-
assert.equal(check.valid, true, `After server-time override, ran_at should be within 24h drift. Got: ${enforced.ran_at}`);
|
|
104
|
-
// Verify original backdated value was replaced
|
|
105
|
-
assert.notEqual(enforced.ran_at, thirtyDaysAgo, "Original 30-day-old backdated ran_at must be replaced");
|
|
106
|
-
// Result should be close to now
|
|
107
|
-
assert.ok(Date.now() - resultMs < 5000, "Enforced ran_at should be within 5 seconds of server time");
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { extractEntityRefsRegex, extractCodeRefs, } from "../extractor.js";
|
|
4
|
-
// =====================================================================
|
|
5
|
-
// POSITIVE — per entity type (16 cases, one per NOX_ENTITY_TYPES entry-ish)
|
|
6
|
-
// =====================================================================
|
|
7
|
-
test("md-link: feedback entity matches", () => {
|
|
8
|
-
const r = extractEntityRefsRegex("see [no secrets](feedback/no_secrets.md)");
|
|
9
|
-
assert.equal(r.length, 1);
|
|
10
|
-
assert.equal(r[0]?.key, "feedback/no_secrets");
|
|
11
|
-
assert.equal(r[0]?.source, "markdown_link");
|
|
12
|
-
assert.equal(r[0]?.display, "no secrets");
|
|
13
|
-
});
|
|
14
|
-
test("md-link: with relative ../ prefix", () => {
|
|
15
|
-
const r = extractEntityRefsRegex("[x](../feedback/no_secrets)");
|
|
16
|
-
assert.equal(r.length, 1);
|
|
17
|
-
assert.equal(r[0]?.key, "feedback/no_secrets");
|
|
18
|
-
});
|
|
19
|
-
test("md-link: with tooltip stripped", () => {
|
|
20
|
-
const r = extractEntityRefsRegex('[x](feedback/foo "my tooltip")');
|
|
21
|
-
assert.equal(r.length, 1);
|
|
22
|
-
assert.equal(r[0]?.key, "feedback/foo");
|
|
23
|
-
});
|
|
24
|
-
test("md-link: with #anchor stripped", () => {
|
|
25
|
-
const r = extractEntityRefsRegex("[x](decision/d41#part-2)");
|
|
26
|
-
assert.equal(r.length, 1);
|
|
27
|
-
assert.equal(r[0]?.key, "decision/d41");
|
|
28
|
-
});
|
|
29
|
-
test("wikilink: person entity matches", () => {
|
|
30
|
-
const r = extractEntityRefsRegex("[[person/toto]]");
|
|
31
|
-
assert.equal(r.length, 1);
|
|
32
|
-
assert.equal(r[0]?.entityType, "person");
|
|
33
|
-
assert.equal(r[0]?.source, "wikilink");
|
|
34
|
-
});
|
|
35
|
-
test("wikilink: with entities/ prefix", () => {
|
|
36
|
-
const r = extractEntityRefsRegex("[[entities/lesson/foo]]");
|
|
37
|
-
assert.equal(r.length, 1);
|
|
38
|
-
assert.equal(r[0]?.key, "lesson/foo");
|
|
39
|
-
});
|
|
40
|
-
test("wikilink: with display pipe", () => {
|
|
41
|
-
const r = extractEntityRefsRegex("[[decision/d41|D41 ruling]]");
|
|
42
|
-
assert.equal(r.length, 1);
|
|
43
|
-
assert.equal(r[0]?.display, "D41 ruling");
|
|
44
|
-
});
|
|
45
|
-
test("wikilink: with #anchor and pipe", () => {
|
|
46
|
-
const r = extractEntityRefsRegex("[[project/p1#scope|P1 scope]]");
|
|
47
|
-
assert.equal(r.length, 1);
|
|
48
|
-
assert.equal(r[0]?.key, "project/p1");
|
|
49
|
-
assert.equal(r[0]?.display, "P1 scope");
|
|
50
|
-
});
|
|
51
|
-
test("bare-ref: at line start", () => {
|
|
52
|
-
const r = extractEntityRefsRegex("incident/i1 was bad");
|
|
53
|
-
assert.equal(r.length, 1);
|
|
54
|
-
assert.equal(r[0]?.key, "incident/i1");
|
|
55
|
-
assert.equal(r[0]?.source, "bare_ref");
|
|
56
|
-
});
|
|
57
|
-
test("bare-ref: after whitespace mid-sentence", () => {
|
|
58
|
-
const r = extractEntityRefsRegex("see spec/e15 for details");
|
|
59
|
-
assert.equal(r.length, 1);
|
|
60
|
-
assert.equal(r[0]?.key, "spec/e15");
|
|
61
|
-
});
|
|
62
|
-
test("bare-ref: at end of sentence", () => {
|
|
63
|
-
const r = extractEntityRefsRegex("the lesson is audit/a1.");
|
|
64
|
-
assert.equal(r.length, 1);
|
|
65
|
-
assert.equal(r[0]?.key, "audit/a1");
|
|
66
|
-
});
|
|
67
|
-
test("positive: agent entity", () => {
|
|
68
|
-
const r = extractEntityRefsRegex("[[agent/atlas]]");
|
|
69
|
-
assert.equal(r[0]?.entityType, "agent");
|
|
70
|
-
});
|
|
71
|
-
test("positive: team entity", () => {
|
|
72
|
-
const r = extractEntityRefsRegex("see team/forge");
|
|
73
|
-
assert.equal(r[0]?.entityType, "team");
|
|
74
|
-
});
|
|
75
|
-
test("positive: daily entity in md-link", () => {
|
|
76
|
-
const r = extractEntityRefsRegex("[log](daily/2026-05-18)");
|
|
77
|
-
assert.equal(r[0]?.entityType, "daily");
|
|
78
|
-
});
|
|
79
|
-
test("positive: pending entity bare-ref", () => {
|
|
80
|
-
const r = extractEntityRefsRegex("track pending/p1");
|
|
81
|
-
assert.equal(r[0]?.key, "pending/p1");
|
|
82
|
-
});
|
|
83
|
-
test("positive: graph_node entity", () => {
|
|
84
|
-
const r = extractEntityRefsRegex("[[graph_node/n7]]");
|
|
85
|
-
assert.equal(r[0]?.entityType, "graph_node");
|
|
86
|
-
});
|
|
87
|
-
test("positive: skill entity", () => {
|
|
88
|
-
const r = extractEntityRefsRegex("[[skill/graphify]]");
|
|
89
|
-
assert.equal(r[0]?.entityType, "skill");
|
|
90
|
-
});
|
|
91
|
-
test("positive: persona + reference entities both", () => {
|
|
92
|
-
const r = extractEntityRefsRegex("[[persona/toto]] and [[reference/r1]]");
|
|
93
|
-
assert.equal(r.length, 2);
|
|
94
|
-
});
|
|
95
|
-
// =====================================================================
|
|
96
|
-
// DEDUP — multiple forms collapse to one entry
|
|
97
|
-
// =====================================================================
|
|
98
|
-
test("dedup: same key across md-link + wikilink + bare", () => {
|
|
99
|
-
const r = extractEntityRefsRegex("[x](feedback/foo) and [[feedback/foo]] and feedback/foo here");
|
|
100
|
-
assert.equal(r.length, 1);
|
|
101
|
-
assert.equal(r[0]?.key, "feedback/foo");
|
|
102
|
-
});
|
|
103
|
-
test("dedup: prefers earlier display from md-link", () => {
|
|
104
|
-
const r = extractEntityRefsRegex("[Name](feedback/foo) and feedback/foo");
|
|
105
|
-
assert.equal(r[0]?.display, "Name");
|
|
106
|
-
});
|
|
107
|
-
// =====================================================================
|
|
108
|
-
// NEGATIVE — 10+ false-positive defenses
|
|
109
|
-
// =====================================================================
|
|
110
|
-
test("neg: ignores reference inside fenced code", () => {
|
|
111
|
-
const r = extractEntityRefsRegex("```\n[[feedback/foo]]\n```");
|
|
112
|
-
assert.equal(r.length, 0);
|
|
113
|
-
});
|
|
114
|
-
test("neg: ignores reference inside inline code", () => {
|
|
115
|
-
const r = extractEntityRefsRegex("see `feedback/foo` here");
|
|
116
|
-
assert.equal(r.length, 0);
|
|
117
|
-
});
|
|
118
|
-
test("neg: ignores URL with /feedback/ path", () => {
|
|
119
|
-
const r = extractEntityRefsRegex("https://example.com/feedback/foo here");
|
|
120
|
-
assert.equal(r.length, 0);
|
|
121
|
-
});
|
|
122
|
-
test("neg: ignores entity-like word without slash form", () => {
|
|
123
|
-
const r = extractEntityRefsRegex("the feedback was great");
|
|
124
|
-
assert.equal(r.length, 0);
|
|
125
|
-
});
|
|
126
|
-
test("neg: ignores unknown entity type", () => {
|
|
127
|
-
const r = extractEntityRefsRegex("[[unknown/foo]] and bogus/bar");
|
|
128
|
-
assert.equal(r.length, 0);
|
|
129
|
-
});
|
|
130
|
-
test("neg: ignores UUID-like token", () => {
|
|
131
|
-
const r = extractEntityRefsRegex("id 550e8400-e29b-41d4-a716-446655440000");
|
|
132
|
-
assert.equal(r.length, 0);
|
|
133
|
-
});
|
|
134
|
-
test("neg: ignores generic [[file.md]]", () => {
|
|
135
|
-
const r = extractEntityRefsRegex("[[file.md]] generic");
|
|
136
|
-
assert.equal(r.length, 0);
|
|
137
|
-
});
|
|
138
|
-
test("neg: ignores bare-ref glued to letters (no boundary)", () => {
|
|
139
|
-
const r = extractEntityRefsRegex("xfeedback/foo");
|
|
140
|
-
assert.equal(r.length, 0);
|
|
141
|
-
});
|
|
142
|
-
test("neg: ignores `feedback/foo` inline code", () => {
|
|
143
|
-
const r = extractEntityRefsRegex("see `feedback/foo`");
|
|
144
|
-
assert.equal(r.length, 0);
|
|
145
|
-
});
|
|
146
|
-
test("neg: ignores cron schedule '*/15'", () => {
|
|
147
|
-
const r = extractEntityRefsRegex("cron */15 * * * * runs");
|
|
148
|
-
assert.equal(r.length, 0);
|
|
149
|
-
});
|
|
150
|
-
test("neg: empty content returns []", () => {
|
|
151
|
-
assert.deepEqual(extractEntityRefsRegex(""), []);
|
|
152
|
-
});
|
|
153
|
-
test("neg: ignores entity-type-only string (no slug)", () => {
|
|
154
|
-
const r = extractEntityRefsRegex("feedback/");
|
|
155
|
-
assert.equal(r.length, 0);
|
|
156
|
-
});
|
|
157
|
-
// =====================================================================
|
|
158
|
-
// EDGE — Unicode + mixed
|
|
159
|
-
// =====================================================================
|
|
160
|
-
test("edge: slug with hyphens and digits", () => {
|
|
161
|
-
const r = extractEntityRefsRegex("[[spec/e15-codegraph-2026]]");
|
|
162
|
-
assert.equal(r[0]?.slug, "e15-codegraph-2026");
|
|
163
|
-
});
|
|
164
|
-
test("edge: slug with underscores", () => {
|
|
165
|
-
const r = extractEntityRefsRegex("see feedback/no_secrets_in_git");
|
|
166
|
-
assert.equal(r[0]?.slug, "no_secrets_in_git");
|
|
167
|
-
});
|
|
168
|
-
test("edge: PT accented surrounding word does not break", () => {
|
|
169
|
-
const r = extractEntityRefsRegex("regra é feedback/no_secrets, certo?");
|
|
170
|
-
assert.equal(r.length, 1);
|
|
171
|
-
});
|
|
172
|
-
test("edge: multiple distinct entities in one chunk", () => {
|
|
173
|
-
const r = extractEntityRefsRegex("[[feedback/a]] [[feedback/b]] [[decision/c]]");
|
|
174
|
-
assert.equal(r.length, 3);
|
|
175
|
-
});
|
|
176
|
-
// =====================================================================
|
|
177
|
-
// CODE REFS — T5
|
|
178
|
-
// =====================================================================
|
|
179
|
-
test("code-ref: src/lib/x.ts:42", () => {
|
|
180
|
-
const r = extractCodeRefs("see src/lib/op-audit.ts:42 for details");
|
|
181
|
-
assert.equal(r.length, 1);
|
|
182
|
-
assert.equal(r[0]?.path, "lib/op-audit.ts");
|
|
183
|
-
assert.equal(r[0]?.line, 42);
|
|
184
|
-
});
|
|
185
|
-
test("code-ref: spec md file", () => {
|
|
186
|
-
const r = extractCodeRefs("specs/2026-05-17-E15-codegraph-inspired-improvements.md is canonical");
|
|
187
|
-
assert.equal(r.length, 1);
|
|
188
|
-
assert.equal(r[0]?.root, "specs");
|
|
189
|
-
});
|
|
190
|
-
test("code-ref: ignores src/ inside code fence", () => {
|
|
191
|
-
const r = extractCodeRefs("```\nsrc/x.ts:1\n```");
|
|
192
|
-
assert.equal(r.length, 0);
|
|
193
|
-
});
|
|
194
|
-
test("code-ref: dedupes multiple mentions of same path", () => {
|
|
195
|
-
const r = extractCodeRefs("src/a.ts and src/a.ts again");
|
|
196
|
-
assert.equal(r.length, 1);
|
|
197
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { extractFrontmatterBlock, parseFrontmatterFields, extractFrontmatterRelations, extractFrontmatterRelationsFromObject, } from "../frontmatter.js";
|
|
4
|
-
test("frontmatter: extracts block from --- delimited doc", () => {
|
|
5
|
-
const doc = "---\nagent: atlas\n---\nbody";
|
|
6
|
-
assert.equal(extractFrontmatterBlock(doc), "agent: atlas");
|
|
7
|
-
});
|
|
8
|
-
test("frontmatter: returns null when no block", () => {
|
|
9
|
-
assert.equal(extractFrontmatterBlock("just prose"), null);
|
|
10
|
-
});
|
|
11
|
-
test("frontmatter: parses scalar fields", () => {
|
|
12
|
-
const fields = parseFrontmatterFields("agent: atlas\nsupersedes: old_one");
|
|
13
|
-
assert.equal(fields.length, 2);
|
|
14
|
-
assert.equal(fields[0]?.scalar, "atlas");
|
|
15
|
-
});
|
|
16
|
-
test("frontmatter: parses quoted scalar", () => {
|
|
17
|
-
const fields = parseFrontmatterFields('caused_by: "incident/i1"');
|
|
18
|
-
assert.equal(fields[0]?.scalar, "incident/i1");
|
|
19
|
-
});
|
|
20
|
-
test("frontmatter: parses flow array", () => {
|
|
21
|
-
const fields = parseFrontmatterFields("references: [a, b, c]");
|
|
22
|
-
assert.deepEqual(fields[0]?.array, ["a", "b", "c"]);
|
|
23
|
-
});
|
|
24
|
-
test("frontmatter: parses block array", () => {
|
|
25
|
-
const fields = parseFrontmatterFields("references:\n - feedback/a\n - feedback/b");
|
|
26
|
-
assert.deepEqual(fields[0]?.array, ["feedback/a", "feedback/b"]);
|
|
27
|
-
});
|
|
28
|
-
test("relations: agent → is_agent_of", () => {
|
|
29
|
-
const r = extractFrontmatterRelations("---\nagent: atlas\n---");
|
|
30
|
-
assert.equal(r.length, 1);
|
|
31
|
-
assert.equal(r[0]?.relationType, "is_agent_of");
|
|
32
|
-
assert.equal(r[0]?.target, "atlas");
|
|
33
|
-
});
|
|
34
|
-
test("relations: references array → multiple references rows", () => {
|
|
35
|
-
const r = extractFrontmatterRelations("---\nreferences:\n - feedback/a\n - feedback/b\n---");
|
|
36
|
-
assert.equal(r.length, 2);
|
|
37
|
-
assert.equal(r[0]?.relationType, "references");
|
|
38
|
-
assert.equal(r[1]?.target, "feedback/b");
|
|
39
|
-
});
|
|
40
|
-
test("relations: supersedes scalar", () => {
|
|
41
|
-
const r = extractFrontmatterRelations("---\nsupersedes: decision/old\n---");
|
|
42
|
-
assert.equal(r[0]?.relationType, "supersedes");
|
|
43
|
-
});
|
|
44
|
-
test("relations: caused_by scalar", () => {
|
|
45
|
-
const r = extractFrontmatterRelations("---\ncaused_by: incident/i7\n---");
|
|
46
|
-
assert.equal(r[0]?.relationType, "caused_by");
|
|
47
|
-
});
|
|
48
|
-
test("relations: resolves scalar", () => {
|
|
49
|
-
const r = extractFrontmatterRelations("---\nresolves: pending/p3\n---");
|
|
50
|
-
assert.equal(r[0]?.relationType, "resolves");
|
|
51
|
-
});
|
|
52
|
-
test("relations: decided_by scalar", () => {
|
|
53
|
-
const r = extractFrontmatterRelations("---\ndecided_by: person/toto\n---");
|
|
54
|
-
assert.equal(r[0]?.relationType, "decided_by");
|
|
55
|
-
});
|
|
56
|
-
test("relations: ignores unknown fields", () => {
|
|
57
|
-
const r = extractFrontmatterRelations("---\ntitle: hello\ncreated: 2026-01-01\n---");
|
|
58
|
-
assert.equal(r.length, 0);
|
|
59
|
-
});
|
|
60
|
-
test("relations: skips empty scalar", () => {
|
|
61
|
-
const r = extractFrontmatterRelations("---\nagent:\n---");
|
|
62
|
-
assert.equal(r.length, 0);
|
|
63
|
-
});
|
|
64
|
-
test("relations: from already-parsed object", () => {
|
|
65
|
-
const r = extractFrontmatterRelationsFromObject({
|
|
66
|
-
agent: "atlas",
|
|
67
|
-
references: ["a", "b"],
|
|
68
|
-
title: "ignored",
|
|
69
|
-
});
|
|
70
|
-
assert.equal(r.length, 3);
|
|
71
|
-
});
|
|
72
|
-
test("relations: mixed scalar + array + unknown", () => {
|
|
73
|
-
const r = extractFrontmatterRelations("---\nagent: atlas\nreferences: [feedback/a, feedback/b]\nother: skip\n---");
|
|
74
|
-
assert.equal(r.length, 3);
|
|
75
|
-
});
|