nox-mem 3.1.1 → 3.2.0
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 +24 -16
- package/dist/__tests__/brief-diversity.test.js +266 -0
- package/dist/__tests__/brief.test.js +287 -0
- package/dist/__tests__/churn.test.js +66 -0
- package/dist/__tests__/edge-typing.test.js +99 -0
- package/dist/__tests__/ingest-event.test.js +151 -0
- package/dist/__tests__/op-audit-e2e.test.js +130 -0
- package/dist/__tests__/pragma-alignment.test.js +123 -0
- package/dist/__tests__/reranker.test.js +326 -0
- package/dist/__tests__/retention.test.js +99 -0
- package/dist/__tests__/search-track-access.test.js +49 -0
- package/dist/__tests__/spo-injection.test.js +172 -0
- package/dist/__tests__/temporal-detector.test.js +103 -0
- package/dist/api/wire-up.js +12 -381
- package/dist/api-server.js +6 -102
- package/dist/db.js +61 -2
- package/dist/embed.js +23 -2
- package/dist/index.js +1 -22
- package/dist/knowledge-graph.js +20 -0
- package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
- package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
- package/dist/lib/answer/__tests__/integration.test.js +347 -0
- package/dist/lib/answer/__tests__/prompt.test.js +117 -0
- package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
- package/dist/lib/answer/provider.js +29 -4
- package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
- package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
- package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
- package/dist/lib/events/__tests__/bus.test.js +208 -0
- package/dist/lib/ingest-router.js +0 -43
- package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
- package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
- package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
- package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
- package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
- package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
- package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
- package/dist/privacy/__tests__/filter.test.js +352 -0
- package/dist/providers/__tests__/conformance-extended.test.js +249 -0
- package/dist/providers/__tests__/conformance.test.js +98 -0
- package/dist/providers/__tests__/cost-cap.test.js +151 -0
- package/dist/providers/__tests__/e2e-real.test.js +79 -0
- package/dist/providers/__tests__/factory.test.js +80 -0
- package/dist/providers/__tests__/fallback.test.js +223 -0
- package/dist/providers/__tests__/gemini.test.js +191 -0
- package/dist/providers/__tests__/health.test.js +128 -0
- package/dist/providers/__tests__/telemetry.test.js +219 -0
- package/dist/reindex.js +2 -2
- package/package.json +3 -4
- package/dist/api/answer.d.ts +0 -116
- package/dist/api/answer.validate-patch.d.ts +0 -72
- package/dist/api/brief-diversity.d.ts +0 -64
- package/dist/api/brief.d.ts +0 -114
- package/dist/api/conflict.d.ts +0 -33
- package/dist/api/conflict.js +0 -143
- package/dist/api/cors.d.ts +0 -73
- package/dist/api/events-stream-limited.d.ts +0 -133
- package/dist/api/events-stream-limited.js +0 -217
- package/dist/api/events-stream.d.ts +0 -53
- package/dist/api/events-stream.js +0 -125
- package/dist/api/export.d.ts +0 -42
- package/dist/api/export.js +0 -85
- package/dist/api/health-confidence-adapter.d.ts +0 -29
- package/dist/api/health-confidence-adapter.js +0 -73
- package/dist/api/health-confidence.d.ts +0 -36
- package/dist/api/health-confidence.js +0 -141
- package/dist/api/hooks.d.ts +0 -50
- package/dist/api/hooks.js +0 -115
- package/dist/api/import.d.ts +0 -38
- package/dist/api/import.js +0 -87
- package/dist/api/ingest-event.d.ts +0 -65
- package/dist/api/mark.d.ts +0 -42
- package/dist/api/mark.js +0 -127
- package/dist/api/server-deps-a2.d.ts +0 -55
- package/dist/api/server-deps-a2.js +0 -138
- package/dist/api/server-deps-l2-l3.d.ts +0 -68
- package/dist/api/server-deps-l2-l3.js +0 -123
- package/dist/api/server-deps-p1.d.ts +0 -84
- package/dist/api/server-deps-p2.d.ts +0 -32
- package/dist/api/server-deps-p2.js +0 -84
- package/dist/api/server-deps-p5.d.ts +0 -66
- package/dist/api/server-deps-p5.js +0 -139
- package/dist/api/viewer-static.d.ts +0 -30
- package/dist/api/viewer-static.js +0 -102
- package/dist/api/wire-up.d.ts +0 -54
- package/dist/api-impact.d.ts +0 -30
- package/dist/api-server.d.ts +0 -2
- package/dist/backfill-fts-anchor.d.ts +0 -15
- package/dist/backfill-source-type.d.ts +0 -20
- package/dist/churn.d.ts +0 -31
- package/dist/cli/answer.d.ts +0 -66
- package/dist/cli/conflict.d.ts +0 -38
- package/dist/cli/conflict.js +0 -282
- package/dist/cli/export.d.ts +0 -51
- package/dist/cli/export.js +0 -280
- package/dist/cli/hooks.d.ts +0 -54
- package/dist/cli/hooks.js +0 -133
- package/dist/cli/import.d.ts +0 -52
- package/dist/cli/import.js +0 -274
- package/dist/cli/mark.d.ts +0 -33
- package/dist/cli/mark.js +0 -130
- package/dist/cli/ocr-batch.d.ts +0 -12
- package/dist/cli/ocr-batch.js +0 -411
- package/dist/cli/snapshot-main.d.ts +0 -30
- package/dist/cli/snapshot-main.js +0 -47
- package/dist/cli/viewer.d.ts +0 -35
- package/dist/cli/viewer.js +0 -71
- package/dist/cli-telemetry.d.ts +0 -36
- package/dist/cli-telemetry.js +0 -150
- package/dist/compact.d.ts +0 -7
- package/dist/consolidate.d.ts +0 -18
- package/dist/consolidation.d.ts +0 -32
- package/dist/cross-agent-v2.d.ts +0 -45
- package/dist/cross-search.d.ts +0 -11
- package/dist/crystallize.d.ts +0 -43
- package/dist/db.d.ts +0 -11
- package/dist/dedup.d.ts +0 -1
- package/dist/detect-changes.d.ts +0 -29
- package/dist/digest.d.ts +0 -1
- package/dist/doctor.d.ts +0 -1
- package/dist/embed.d.ts +0 -57
- package/dist/evals.d.ts +0 -176
- package/dist/evals.js +0 -351
- package/dist/generate-user-profile.d.ts +0 -18
- package/dist/graphify-ingest.d.ts +0 -18
- package/dist/impact.d.ts +0 -39
- package/dist/index.d.ts +0 -2
- package/dist/ingest-entity.d.ts +0 -44
- package/dist/ingest.d.ts +0 -13
- package/dist/kg-llm.d.ts +0 -39
- package/dist/knowledge-graph.d.ts +0 -72
- package/dist/lib/answer/config.d.ts +0 -41
- package/dist/lib/answer/index.d.ts +0 -47
- package/dist/lib/answer/prompt.d.ts +0 -37
- package/dist/lib/answer/provider.d.ts +0 -47
- package/dist/lib/answer/retrieval.d.ts +0 -36
- package/dist/lib/answer/telemetry.d.ts +0 -99
- package/dist/lib/answer/types.d.ts +0 -108
- package/dist/lib/api/error-leak-fix.d.ts +0 -54
- package/dist/lib/api/safe-error-message.d.ts +0 -70
- package/dist/lib/archive/common-passwords.d.ts +0 -37
- package/dist/lib/archive/common-passwords.js +0 -753
- package/dist/lib/archive/encryption.d.ts +0 -81
- package/dist/lib/archive/encryption.js +0 -236
- package/dist/lib/archive/enforce-strength.d.ts +0 -54
- package/dist/lib/archive/enforce-strength.js +0 -70
- package/dist/lib/archive/entropy.d.ts +0 -34
- package/dist/lib/archive/entropy.js +0 -180
- package/dist/lib/archive/export-locking.d.ts +0 -102
- package/dist/lib/archive/export-locking.js +0 -202
- package/dist/lib/archive/format.d.ts +0 -20
- package/dist/lib/archive/format.js +0 -174
- package/dist/lib/archive/index.d.ts +0 -23
- package/dist/lib/archive/index.js +0 -17
- package/dist/lib/archive/manifest.d.ts +0 -53
- package/dist/lib/archive/manifest.js +0 -183
- package/dist/lib/archive/migration.d.ts +0 -36
- package/dist/lib/archive/migration.js +0 -100
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
- package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
- package/dist/lib/archive/orchestrator.d.ts +0 -166
- package/dist/lib/archive/orchestrator.js +0 -428
- package/dist/lib/archive/serializers/chunks.d.ts +0 -30
- package/dist/lib/archive/serializers/chunks.js +0 -113
- package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
- package/dist/lib/archive/serializers/embeddings.js +0 -115
- package/dist/lib/archive/serializers/kg.d.ts +0 -28
- package/dist/lib/archive/serializers/kg.js +0 -184
- package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
- package/dist/lib/archive/serializers/ops_audit.js +0 -97
- package/dist/lib/archive/server-deps.d.ts +0 -131
- package/dist/lib/archive/server-deps.js +0 -232
- package/dist/lib/archive/strength.d.ts +0 -50
- package/dist/lib/archive/strength.js +0 -77
- package/dist/lib/archive/types.d.ts +0 -159
- package/dist/lib/archive/types.js +0 -45
- package/dist/lib/archive/unpack-streaming.d.ts +0 -70
- package/dist/lib/archive/unpack-streaming.js +0 -255
- package/dist/lib/auth/localhost-guard.d.ts +0 -106
- package/dist/lib/confidence/config.d.ts +0 -37
- package/dist/lib/confidence/config.js +0 -107
- package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
- package/dist/lib/confidence/db-shim-singleton.js +0 -41
- package/dist/lib/confidence/db-shim.d.ts +0 -47
- package/dist/lib/confidence/db-shim.js +0 -141
- package/dist/lib/confidence/mark.d.ts +0 -58
- package/dist/lib/confidence/mark.js +0 -168
- package/dist/lib/confidence/ranking.d.ts +0 -69
- package/dist/lib/confidence/ranking.js +0 -101
- package/dist/lib/confidence/search-filter.d.ts +0 -44
- package/dist/lib/confidence/search-filter.js +0 -103
- package/dist/lib/confidence/types.d.ts +0 -146
- package/dist/lib/confidence/types.js +0 -20
- package/dist/lib/confidence/write-hooks.d.ts +0 -50
- package/dist/lib/confidence/write-hooks.js +0 -159
- package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
- package/dist/lib/conflict/audit-fk-check.js +0 -131
- package/dist/lib/conflict/audit-writer.d.ts +0 -39
- package/dist/lib/conflict/audit-writer.js +0 -133
- package/dist/lib/conflict/db-singleton.d.ts +0 -28
- package/dist/lib/conflict/db-singleton.js +0 -61
- package/dist/lib/conflict/db.d.ts +0 -27
- package/dist/lib/conflict/db.js +0 -20
- package/dist/lib/conflict/detector-direct.d.ts +0 -21
- package/dist/lib/conflict/detector-direct.js +0 -105
- package/dist/lib/conflict/evidence.d.ts +0 -24
- package/dist/lib/conflict/evidence.js +0 -76
- package/dist/lib/conflict/index.d.ts +0 -14
- package/dist/lib/conflict/index.js +0 -12
- package/dist/lib/conflict/scheduler.d.ts +0 -78
- package/dist/lib/conflict/scheduler.js +0 -111
- package/dist/lib/conflict/shadow.d.ts +0 -75
- package/dist/lib/conflict/shadow.js +0 -161
- package/dist/lib/conflict/types.d.ts +0 -133
- package/dist/lib/conflict/types.js +0 -19
- package/dist/lib/cost-cap.d.ts +0 -94
- package/dist/lib/deps/deps-registry.d.ts +0 -111
- package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
- package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
- package/dist/lib/eval-batch.d.ts +0 -34
- package/dist/lib/eval-batch.js +0 -103
- package/dist/lib/eval-metrics.d.ts +0 -36
- package/dist/lib/eval-metrics.js +0 -95
- package/dist/lib/eval.d.ts +0 -106
- package/dist/lib/eval.js +0 -343
- package/dist/lib/events/bus.d.ts +0 -135
- package/dist/lib/fts-anchor.d.ts +0 -1
- package/dist/lib/hooks/classifier.d.ts +0 -47
- package/dist/lib/hooks/classifier.js +0 -129
- package/dist/lib/hooks/config.d.ts +0 -49
- package/dist/lib/hooks/config.js +0 -106
- package/dist/lib/hooks/decorators.d.ts +0 -35
- package/dist/lib/hooks/decorators.js +0 -59
- package/dist/lib/hooks/pipeline.d.ts +0 -76
- package/dist/lib/hooks/pipeline.js +0 -213
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
- package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
- package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
- package/dist/lib/hooks/rate-limit.d.ts +0 -54
- package/dist/lib/hooks/rate-limit.js +0 -122
- package/dist/lib/hooks/server-deps.d.ts +0 -61
- package/dist/lib/hooks/server-deps.js +0 -92
- package/dist/lib/hooks/source-allowlist.d.ts +0 -26
- package/dist/lib/hooks/source-allowlist.js +0 -53
- package/dist/lib/hooks/types.d.ts +0 -129
- package/dist/lib/hooks/types.js +0 -24
- package/dist/lib/hooks/worker.d.ts +0 -56
- package/dist/lib/hooks/worker.js +0 -150
- package/dist/lib/ingest-router.d.ts +0 -25
- package/dist/lib/ocr-detector.d.ts +0 -61
- package/dist/lib/ocr-detector.js +0 -138
- package/dist/lib/ocr-engine-stub.d.ts +0 -48
- package/dist/lib/ocr-engine-stub.js +0 -190
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
- package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
- package/dist/lib/ocr-jobs.d.ts +0 -67
- package/dist/lib/ocr-jobs.js +0 -129
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
- package/dist/lib/op-audit.d.ts +0 -71
- package/dist/lib/privacy-br/detector.d.ts +0 -42
- package/dist/lib/privacy-br/detector.js +0 -130
- package/dist/lib/privacy-br/index.d.ts +0 -20
- package/dist/lib/privacy-br/index.js +0 -20
- package/dist/lib/privacy-br/integration.d.ts +0 -71
- package/dist/lib/privacy-br/integration.js +0 -74
- package/dist/lib/privacy-br/patterns.d.ts +0 -117
- package/dist/lib/privacy-br/patterns.js +0 -434
- package/dist/lib/privacy-br/redact.d.ts +0 -42
- package/dist/lib/privacy-br/redact.js +0 -103
- package/dist/lib/privacy-br/types.d.ts +0 -55
- package/dist/lib/privacy-br/types.js +0 -25
- package/dist/lib/regex-extract/extractor.d.ts +0 -30
- package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
- package/dist/lib/regex-extract/index.d.ts +0 -14
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
- package/dist/lib/regex-extract/patterns.d.ts +0 -61
- package/dist/lib/regex-extract/production-wire.d.ts +0 -128
- package/dist/lib/regex-extract/reconcile.d.ts +0 -162
- package/dist/lib/regex-extract/strip-code.d.ts +0 -24
- package/dist/lib/regex-extract/types.d.ts +0 -48
- package/dist/lib/reranker.d.ts +0 -80
- package/dist/lib/shadow-tracker.d.ts +0 -191
- package/dist/lib/shadow-tracker.js +0 -384
- package/dist/lib/spo-injection.d.ts +0 -52
- package/dist/lib/telemetry-collector.d.ts +0 -158
- package/dist/lib/telemetry-collector.js +0 -249
- package/dist/lib/temporal-detector.d.ts +0 -27
- package/dist/lib/viewer/auth.d.ts +0 -37
- package/dist/lib/viewer/auth.js +0 -70
- package/dist/lib/viewer/backpressure.d.ts +0 -59
- package/dist/lib/viewer/backpressure.js +0 -100
- package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
- package/dist/lib/viewer/broadcast-singleton.js +0 -49
- package/dist/lib/viewer/broadcast.d.ts +0 -66
- package/dist/lib/viewer/broadcast.js +0 -96
- package/dist/lib/viewer/event-types.d.ts +0 -132
- package/dist/lib/viewer/event-types.js +0 -74
- package/dist/lib/viewer/instrumentation.d.ts +0 -106
- package/dist/lib/viewer/instrumentation.js +0 -224
- package/dist/lib/viewer/migration.d.ts +0 -23
- package/dist/lib/viewer/migration.js +0 -56
- package/dist/lib/viewer/redaction.d.ts +0 -44
- package/dist/lib/viewer/redaction.js +0 -139
- package/dist/lib/viewer/session.d.ts +0 -51
- package/dist/lib/viewer/session.js +0 -87
- package/dist/mcp/tools/answer.d.ts +0 -94
- package/dist/mcp/tools/archive.d.ts +0 -152
- package/dist/mcp/tools/archive.js +0 -170
- package/dist/mcp/tools/conflict.d.ts +0 -44
- package/dist/mcp/tools/conflict.js +0 -130
- package/dist/mcp/tools/hooks.d.ts +0 -29
- package/dist/mcp/tools/hooks.js +0 -78
- package/dist/mcp/tools/mark.d.ts +0 -38
- package/dist/mcp/tools/mark.js +0 -82
- package/dist/mcp/tools/viewer.d.ts +0 -58
- package/dist/mcp/tools/viewer.js +0 -64
- package/dist/mcp-server.d.ts +0 -2
- package/dist/metrics.d.ts +0 -3
- package/dist/noise-filter.d.ts +0 -18
- package/dist/notion-sync.d.ts +0 -7
- package/dist/notion-sync.js +0 -97
- package/dist/observability/adapters/a3-adapter.d.ts +0 -63
- package/dist/observability/adapters/a3-adapter.js +0 -83
- package/dist/observability/adapters/p1-adapter.d.ts +0 -49
- package/dist/observability/adapters/p1-adapter.js +0 -63
- package/dist/observability/adapters/p5-adapter.d.ts +0 -36
- package/dist/observability/adapters/p5-adapter.js +0 -71
- package/dist/observability/cardinality.d.ts +0 -61
- package/dist/observability/cardinality.js +0 -300
- package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
- package/dist/observability/collectors/db-stats.collector.js +0 -88
- package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
- package/dist/observability/collectors/eventbus.collector.js +0 -50
- package/dist/observability/collectors/process.collector.d.ts +0 -7
- package/dist/observability/collectors/process.collector.js +0 -93
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
- package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
- package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
- package/dist/observability/collectors/search-telemetry.collector.js +0 -76
- package/dist/observability/exporter.d.ts +0 -30
- package/dist/observability/exporter.js +0 -182
- package/dist/observability/index.d.ts +0 -22
- package/dist/observability/index.js +0 -21
- package/dist/observability/metrics.d.ts +0 -53
- package/dist/observability/metrics.js +0 -213
- package/dist/observability/privacy-guard.d.ts +0 -32
- package/dist/observability/privacy-guard.js +0 -116
- package/dist/observability/record.d.ts +0 -83
- package/dist/observability/record.js +0 -217
- package/dist/observability/registry.d.ts +0 -60
- package/dist/observability/registry.js +0 -93
- package/dist/observability/types.d.ts +0 -115
- package/dist/observability/types.js +0 -235
- package/dist/observability.d.ts +0 -131
- package/dist/plugins/nox-hooks/index.d.ts +0 -61
- package/dist/plugins/nox-hooks/index.js +0 -99
- package/dist/primer.d.ts +0 -1
- package/dist/privacy/filter.d.ts +0 -27
- package/dist/privacy/patterns.d.ts +0 -29
- package/dist/privacy/tag-parser.d.ts +0 -24
- package/dist/project-context-gen.d.ts +0 -10
- package/dist/providers/embedding/gemini.d.ts +0 -73
- package/dist/providers/embedding/openai.d.ts +0 -76
- package/dist/providers/embedding/types.d.ts +0 -39
- package/dist/providers/embedding/voyage.d.ts +0 -36
- package/dist/providers/index.d.ts +0 -116
- package/dist/providers/llm/anthropic.d.ts +0 -29
- package/dist/providers/llm/chain.d.ts +0 -99
- package/dist/providers/llm/gemini.d.ts +0 -48
- package/dist/providers/llm/openai.d.ts +0 -64
- package/dist/providers/llm/types.d.ts +0 -47
- package/dist/providers/telemetry.d.ts +0 -87
- package/dist/providers/types.d.ts +0 -42
- package/dist/query-entity-count.d.ts +0 -54
- package/dist/reflect.d.ts +0 -26
- package/dist/reindex-errors.d.ts +0 -7
- package/dist/reindex.d.ts +0 -16
- package/dist/retention.d.ts +0 -40
- package/dist/salience.d.ts +0 -85
- package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
- package/dist/search-dedup.d.ts +0 -44
- package/dist/search-expansion.d.ts +0 -20
- package/dist/search.d.ts +0 -62
- package/dist/seh-detector.d.ts +0 -31
- package/dist/self-improve.d.ts +0 -1
- package/dist/session-distill.d.ts +0 -29
- package/dist/session-update.d.ts +0 -1
- package/dist/shared-memory.d.ts +0 -24
- package/dist/stats.d.ts +0 -1
- package/dist/temporal-retrieval.d.ts +0 -132
- package/dist/tier-manager.d.ts +0 -69
- package/dist/vectorize.d.ts +0 -16
- package/dist/version.d.ts +0 -1
- package/dist/watch.d.ts +0 -8
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
});
|