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,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gemini.test.ts — Gemini providers mock-based tests (no real API).
|
|
3
|
+
*
|
|
4
|
+
* Cases (10):
|
|
5
|
+
* - GeminiEmbedding: happy path 1 input → 1 vector of dim 3072
|
|
6
|
+
* - GeminiEmbedding: batch 3 inputs → 3 vectors in order
|
|
7
|
+
* - GeminiEmbedding: HTTP 401 → throws with REDACTED key (T14.6 secret hygiene)
|
|
8
|
+
* - GeminiEmbedding: dim mismatch in response → throws clear error
|
|
9
|
+
* - GeminiEmbedding: healthCheck happy path → ok=true with latencyMs
|
|
10
|
+
* - GeminiEmbedding: healthCheck 503 → ok=false, error contains 503
|
|
11
|
+
* - GeminiLLM: happy path returns text + tokensIn + tokensOut + latencyMs
|
|
12
|
+
* - GeminiLLM: system+user combined into body correctly
|
|
13
|
+
* - GeminiLLM: throws when `user` empty
|
|
14
|
+
* - GeminiLLM: MissingKeyError when GEMINI_API_KEY absent
|
|
15
|
+
*/
|
|
16
|
+
import { test, describe } from "node:test";
|
|
17
|
+
import { strict as assert } from "node:assert";
|
|
18
|
+
import { GeminiEmbeddingProvider, redactSecrets } from "../embedding/gemini.js";
|
|
19
|
+
import { GeminiLLMProvider } from "../llm/gemini.js";
|
|
20
|
+
import { MissingKeyError } from "../types.js";
|
|
21
|
+
const FAKE_KEY = "AIzaTESTtestTESTtestTESTtestTESTtest";
|
|
22
|
+
/** Build a fake fetchFn that returns the given body or status. */
|
|
23
|
+
function makeFetch(opts) {
|
|
24
|
+
const status = opts.status ?? 200;
|
|
25
|
+
const statusText = opts.statusText ?? "OK";
|
|
26
|
+
return async () => ({
|
|
27
|
+
ok: status >= 200 && status < 300,
|
|
28
|
+
status,
|
|
29
|
+
statusText,
|
|
30
|
+
text: async () => opts.textBody ?? JSON.stringify(opts.body ?? {}),
|
|
31
|
+
json: async () => opts.body ?? {},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function vectorOfDim(d, fill = 0.1) {
|
|
35
|
+
const a = [];
|
|
36
|
+
for (let i = 0; i < d; i++)
|
|
37
|
+
a.push(fill);
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
describe("GeminiEmbeddingProvider (mock)", () => {
|
|
41
|
+
test("single embed returns Float32Array of dim 3072", async () => {
|
|
42
|
+
const p = new GeminiEmbeddingProvider({
|
|
43
|
+
apiKey: FAKE_KEY,
|
|
44
|
+
fetchFn: makeFetch({
|
|
45
|
+
body: { embeddings: [{ values: vectorOfDim(3072) }] },
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
const out = await p.embed(["hello world"]);
|
|
49
|
+
assert.equal(out.length, 1);
|
|
50
|
+
const v0 = out[0];
|
|
51
|
+
assert.ok(v0 instanceof Float32Array);
|
|
52
|
+
assert.equal(v0?.length, 3072);
|
|
53
|
+
// Float32 has 23-bit mantissa: 0.1 round-trips as 0.10000000149011612.
|
|
54
|
+
assert.equal(v0?.[0], Math.fround(0.1));
|
|
55
|
+
});
|
|
56
|
+
test("batch embed: 3 inputs → 3 vectors in order", async () => {
|
|
57
|
+
const p = new GeminiEmbeddingProvider({
|
|
58
|
+
apiKey: FAKE_KEY,
|
|
59
|
+
fetchFn: makeFetch({
|
|
60
|
+
body: {
|
|
61
|
+
embeddings: [
|
|
62
|
+
{ values: vectorOfDim(3072, 0.1) },
|
|
63
|
+
{ values: vectorOfDim(3072, 0.2) },
|
|
64
|
+
{ values: vectorOfDim(3072, 0.3) },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
const out = await p.embed(["a", "b", "c"]);
|
|
70
|
+
assert.equal(out.length, 3);
|
|
71
|
+
assert.equal(out[0]?.[0], Math.fround(0.1));
|
|
72
|
+
assert.equal(out[1]?.[0], Math.fround(0.2));
|
|
73
|
+
assert.equal(out[2]?.[0], Math.fround(0.3));
|
|
74
|
+
});
|
|
75
|
+
test("HTTP 401 surfaces redacted error (no API key in message)", async () => {
|
|
76
|
+
const upstream = `error: API_KEY_INVALID: AIza${"x".repeat(35)}`;
|
|
77
|
+
const p = new GeminiEmbeddingProvider({
|
|
78
|
+
apiKey: FAKE_KEY,
|
|
79
|
+
fetchFn: makeFetch({ status: 401, statusText: "Unauthorized", textBody: upstream }),
|
|
80
|
+
});
|
|
81
|
+
await assert.rejects(p.embed(["hi"]), (err) => {
|
|
82
|
+
assert.match(err.message, /HTTP 401/);
|
|
83
|
+
// CRITICAL: the redacted message MUST NOT contain the raw key.
|
|
84
|
+
assert.equal(err.message.includes(FAKE_KEY), false);
|
|
85
|
+
assert.match(err.message, /AIza<REDACTED>/);
|
|
86
|
+
return true;
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
test("dim mismatch in upstream → throws clear error", async () => {
|
|
90
|
+
const p = new GeminiEmbeddingProvider({
|
|
91
|
+
apiKey: FAKE_KEY,
|
|
92
|
+
fetchFn: makeFetch({
|
|
93
|
+
body: { embeddings: [{ values: vectorOfDim(1536) }] }, // wrong dim
|
|
94
|
+
}),
|
|
95
|
+
});
|
|
96
|
+
await assert.rejects(p.embed(["hi"]), /dim mismatch/);
|
|
97
|
+
});
|
|
98
|
+
test("healthCheck ok path", async () => {
|
|
99
|
+
const p = new GeminiEmbeddingProvider({
|
|
100
|
+
apiKey: FAKE_KEY,
|
|
101
|
+
fetchFn: makeFetch({ body: { name: "models/gemini-embedding-001" } }),
|
|
102
|
+
});
|
|
103
|
+
const s = await p.healthCheck();
|
|
104
|
+
assert.equal(s.ok, true);
|
|
105
|
+
assert.equal(typeof s.latencyMs, "number");
|
|
106
|
+
assert.equal(s.error, undefined);
|
|
107
|
+
});
|
|
108
|
+
test("healthCheck 503 → ok=false with HTTP 503 in error", async () => {
|
|
109
|
+
const p = new GeminiEmbeddingProvider({
|
|
110
|
+
apiKey: FAKE_KEY,
|
|
111
|
+
fetchFn: makeFetch({ status: 503, statusText: "Service Unavailable" }),
|
|
112
|
+
});
|
|
113
|
+
const s = await p.healthCheck();
|
|
114
|
+
assert.equal(s.ok, false);
|
|
115
|
+
assert.match(s.error ?? "", /503/);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("GeminiLLMProvider (mock)", () => {
|
|
119
|
+
test("happy path returns text + tokensIn/tokensOut + latencyMs", async () => {
|
|
120
|
+
const p = new GeminiLLMProvider({
|
|
121
|
+
apiKey: FAKE_KEY,
|
|
122
|
+
fetchFn: makeFetch({
|
|
123
|
+
body: {
|
|
124
|
+
candidates: [
|
|
125
|
+
{ content: { parts: [{ text: "Hello there!" }] } },
|
|
126
|
+
],
|
|
127
|
+
usageMetadata: { promptTokenCount: 5, candidatesTokenCount: 3 },
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
const out = await p.complete({ user: "Hi" });
|
|
132
|
+
assert.equal(out.text, "Hello there!");
|
|
133
|
+
assert.equal(out.tokensIn, 5);
|
|
134
|
+
assert.equal(out.tokensOut, 3);
|
|
135
|
+
assert.equal(typeof out.latencyMs, "number");
|
|
136
|
+
});
|
|
137
|
+
test("system+user assembled correctly (captured via fetch interceptor)", async () => {
|
|
138
|
+
let capturedBody;
|
|
139
|
+
const interceptor = async (_url, init) => {
|
|
140
|
+
capturedBody = init?.body;
|
|
141
|
+
return {
|
|
142
|
+
ok: true,
|
|
143
|
+
status: 200,
|
|
144
|
+
statusText: "OK",
|
|
145
|
+
text: async () => "{}",
|
|
146
|
+
json: async () => ({
|
|
147
|
+
candidates: [{ content: { parts: [{ text: "ok" }] } }],
|
|
148
|
+
usageMetadata: { promptTokenCount: 1, candidatesTokenCount: 1 },
|
|
149
|
+
}),
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const p = new GeminiLLMProvider({ apiKey: FAKE_KEY, fetchFn: interceptor });
|
|
153
|
+
await p.complete({ system: "be brief", user: "two plus two?" });
|
|
154
|
+
assert.ok(capturedBody, "fetch body must be captured");
|
|
155
|
+
const parsed = JSON.parse(capturedBody ?? "{}");
|
|
156
|
+
assert.equal(parsed.system_instruction?.parts?.[0]?.text, "be brief");
|
|
157
|
+
assert.equal(parsed.contents?.[0]?.parts?.[0]?.text, "two plus two?");
|
|
158
|
+
});
|
|
159
|
+
test("rejects empty `user` prompt with clear error", async () => {
|
|
160
|
+
const p = new GeminiLLMProvider({
|
|
161
|
+
apiKey: FAKE_KEY,
|
|
162
|
+
fetchFn: makeFetch({ body: {} }),
|
|
163
|
+
});
|
|
164
|
+
await assert.rejects(p.complete({ user: "" }), /`user` is required/);
|
|
165
|
+
});
|
|
166
|
+
test("MissingKeyError when GEMINI_API_KEY absent", () => {
|
|
167
|
+
const origKey = process.env.GEMINI_API_KEY;
|
|
168
|
+
delete process.env.GEMINI_API_KEY;
|
|
169
|
+
try {
|
|
170
|
+
assert.throws(() => new GeminiLLMProvider({ fetchFn: makeFetch({ body: {} }) }), MissingKeyError);
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
if (origKey !== undefined)
|
|
174
|
+
process.env.GEMINI_API_KEY = origKey;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe("redactSecrets", () => {
|
|
179
|
+
test("redacts gemini AIza..., openai sk-..., Bearer tokens, key= params", () => {
|
|
180
|
+
const inp = "AIzaABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi " +
|
|
181
|
+
"sk-AAABBBCCCDDDEEEFFFGGGHHHIII " +
|
|
182
|
+
"Bearer abcdefghijklmnopqrstuvwxyzABCDEF " +
|
|
183
|
+
"key=AAABBBCCCDDDEEEFFFGGGHHHIII";
|
|
184
|
+
const out = redactSecrets(inp);
|
|
185
|
+
assert.equal(out.includes("AIzaABCDEFG"), false);
|
|
186
|
+
assert.equal(out.includes("sk-AAA"), false);
|
|
187
|
+
assert.equal(out.includes("Bearer abcd"), false);
|
|
188
|
+
assert.equal(out.includes("key=AAAB"), false);
|
|
189
|
+
assert.match(out, /AIza<REDACTED>/);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* health.test.ts — T8 bootProviderHealth.
|
|
3
|
+
*
|
|
4
|
+
* Cases (6):
|
|
5
|
+
* 1. happy path: both providers OK → allOk=true, no throw
|
|
6
|
+
* 2. fail-fast on embedding down → throws ProviderHealthError
|
|
7
|
+
* 3. soft-warn on embedding down → no throw, onWarn invoked
|
|
8
|
+
* 4. fail-fast on LLM down → throws, mentions provider name
|
|
9
|
+
* 5. timeout: hung healthCheck → ok=false within timeoutMs
|
|
10
|
+
* 6. soft-warn from NOX_PROVIDER_HEALTH_FAIL_FAST=0 env override
|
|
11
|
+
*/
|
|
12
|
+
import { test, describe } from "node:test";
|
|
13
|
+
import { strict as assert } from "node:assert";
|
|
14
|
+
import { bootProviderHealth, ProviderHealthError } from "../index.js";
|
|
15
|
+
const FAKE_KEY = "AIzaTESTtestTESTtestTESTtestTESTtest";
|
|
16
|
+
/** Tiny in-memory stub that lets us control healthCheck outcome. */
|
|
17
|
+
class FakeEmbedding {
|
|
18
|
+
status;
|
|
19
|
+
name;
|
|
20
|
+
dimensions = 3072;
|
|
21
|
+
maxTokens = 2048;
|
|
22
|
+
costPerMillionTokens = 0.15;
|
|
23
|
+
constructor(name, status) {
|
|
24
|
+
this.status = status;
|
|
25
|
+
this.name = name;
|
|
26
|
+
}
|
|
27
|
+
async embed(_t) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
async healthCheck() {
|
|
31
|
+
return this.status;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class FakeLLM {
|
|
35
|
+
status;
|
|
36
|
+
name;
|
|
37
|
+
model = "fake-model";
|
|
38
|
+
contextWindow = 100_000;
|
|
39
|
+
constructor(name, status) {
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.name = name;
|
|
42
|
+
}
|
|
43
|
+
async complete() {
|
|
44
|
+
return { text: "", tokensIn: 0, tokensOut: 0, latencyMs: 0 };
|
|
45
|
+
}
|
|
46
|
+
async healthCheck() {
|
|
47
|
+
return this.status;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** A provider whose healthCheck never resolves — to test timeout. */
|
|
51
|
+
class HangingEmbedding {
|
|
52
|
+
name = "hanger";
|
|
53
|
+
dimensions = 3072;
|
|
54
|
+
maxTokens = 2048;
|
|
55
|
+
costPerMillionTokens = 0.15;
|
|
56
|
+
async embed(_t) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
healthCheck() {
|
|
60
|
+
return new Promise(() => {
|
|
61
|
+
/* never resolves */
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
describe("bootProviderHealth (T8)", () => {
|
|
66
|
+
test("happy path: both OK → allOk=true, report populated", async () => {
|
|
67
|
+
const e = new FakeEmbedding("gemini", { ok: true, latencyMs: 10 });
|
|
68
|
+
const l = new FakeLLM("gemini", { ok: true, latencyMs: 12 });
|
|
69
|
+
const report = await bootProviderHealth({
|
|
70
|
+
embedding: e,
|
|
71
|
+
llm: l,
|
|
72
|
+
failFast: true,
|
|
73
|
+
});
|
|
74
|
+
assert.equal(report.allOk, true);
|
|
75
|
+
assert.equal(report.embedding?.ok, true);
|
|
76
|
+
assert.equal(report.llm?.ok, true);
|
|
77
|
+
assert.equal(report.embedding?.providerName, "gemini");
|
|
78
|
+
assert.equal(report.llm?.providerName, "gemini");
|
|
79
|
+
});
|
|
80
|
+
test("fail-fast embedding down → throws ProviderHealthError", async () => {
|
|
81
|
+
const e = new FakeEmbedding("gemini", { ok: false, error: "401" });
|
|
82
|
+
const l = new FakeLLM("gemini", { ok: true });
|
|
83
|
+
await assert.rejects(bootProviderHealth({ embedding: e, llm: l, failFast: true }), ProviderHealthError);
|
|
84
|
+
});
|
|
85
|
+
test("soft-warn embedding down → no throw, onWarn invoked", async () => {
|
|
86
|
+
const e = new FakeEmbedding("openai", { ok: false, error: "stub" });
|
|
87
|
+
const l = new FakeLLM("gemini", { ok: true });
|
|
88
|
+
const warnings = [];
|
|
89
|
+
const report = await bootProviderHealth({
|
|
90
|
+
embedding: e,
|
|
91
|
+
llm: l,
|
|
92
|
+
failFast: false,
|
|
93
|
+
onWarn: (w) => warnings.push(w),
|
|
94
|
+
});
|
|
95
|
+
assert.equal(report.allOk, false);
|
|
96
|
+
assert.equal(warnings.length, 1);
|
|
97
|
+
assert.equal(warnings[0]?.providerName, "openai");
|
|
98
|
+
assert.equal(warnings[0]?.kind, "embedding");
|
|
99
|
+
});
|
|
100
|
+
test("fail-fast LLM down → throws and report includes llm.providerName", async () => {
|
|
101
|
+
const e = new FakeEmbedding("gemini", { ok: true });
|
|
102
|
+
const l = new FakeLLM("anthropic", { ok: false, error: "stub" });
|
|
103
|
+
await assert.rejects(bootProviderHealth({ embedding: e, llm: l, failFast: true }), ProviderHealthError);
|
|
104
|
+
});
|
|
105
|
+
test("timeout: hung healthCheck returns ok=false within budget", async () => {
|
|
106
|
+
const e = new HangingEmbedding();
|
|
107
|
+
const t0 = Date.now();
|
|
108
|
+
const report = await bootProviderHealth({
|
|
109
|
+
embedding: e,
|
|
110
|
+
failFast: false,
|
|
111
|
+
timeoutMs: 50,
|
|
112
|
+
});
|
|
113
|
+
const elapsed = Date.now() - t0;
|
|
114
|
+
assert.equal(report.embedding?.ok, false);
|
|
115
|
+
assert.match(report.embedding?.error ?? "", /timeout/i);
|
|
116
|
+
// Allow generous slack but assert nowhere near 5s default.
|
|
117
|
+
assert.ok(elapsed < 1000, `elapsed ${elapsed}ms should be < 1000`);
|
|
118
|
+
});
|
|
119
|
+
test("NOX_PROVIDER_HEALTH_FAIL_FAST=0 env → soft-warn mode", async () => {
|
|
120
|
+
const e = new FakeEmbedding("openai", { ok: false, error: "stub" });
|
|
121
|
+
const report = await bootProviderHealth({
|
|
122
|
+
embedding: e,
|
|
123
|
+
env: { NOX_PROVIDER_HEALTH_FAIL_FAST: "0", GEMINI_API_KEY: FAKE_KEY },
|
|
124
|
+
});
|
|
125
|
+
assert.equal(report.allOk, false);
|
|
126
|
+
// No throw because env disabled fail-fast.
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* telemetry.test.ts — ProviderTelemetry queue + aggregation (T12).
|
|
3
|
+
*
|
|
4
|
+
* Cases (9):
|
|
5
|
+
* 1. recordProviderCall enqueues a row with correct fields
|
|
6
|
+
* 2. row.error_kind has secrets redacted (API key pattern stripped)
|
|
7
|
+
* 3. row never contains prompt text (privacy invariant)
|
|
8
|
+
* 4. queue drain flushes all rows via writeFn
|
|
9
|
+
* 5. queue overflow: capacity exceeded → oldest entries dropped
|
|
10
|
+
* 6. writeFn error does NOT propagate to caller
|
|
11
|
+
* 7. aggregateCosts: last24h totals computed correctly
|
|
12
|
+
* 8. aggregateCosts: rows older than 24h excluded
|
|
13
|
+
* 9. aggregateCosts: per-provider breakdown populated
|
|
14
|
+
*/
|
|
15
|
+
import { test, describe } from "node:test";
|
|
16
|
+
import { strict as assert } from "node:assert";
|
|
17
|
+
import { TelemetryQueue, recordProviderCall, setDefaultQueue, getDefaultQueue, aggregateCosts, } from "../telemetry.js";
|
|
18
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
19
|
+
function makeQueue(rows = [], capacity) {
|
|
20
|
+
return new TelemetryQueue({
|
|
21
|
+
writeFn: async (row) => {
|
|
22
|
+
rows.push(row);
|
|
23
|
+
},
|
|
24
|
+
capacity,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// ─── Tests ────────────────────────────────────────────────────────────────────
|
|
28
|
+
describe("recordProviderCall — enqueue + field mapping", () => {
|
|
29
|
+
test("enqueues a row with correct fields", async () => {
|
|
30
|
+
const rows = [];
|
|
31
|
+
const q = makeQueue(rows);
|
|
32
|
+
const prevQueue = getDefaultQueue();
|
|
33
|
+
setDefaultQueue(q);
|
|
34
|
+
recordProviderCall({
|
|
35
|
+
provider_id: "gemini",
|
|
36
|
+
model: "gemini-2.5-flash-lite",
|
|
37
|
+
kind: "llm",
|
|
38
|
+
tokens_in: 100,
|
|
39
|
+
tokens_out: 50,
|
|
40
|
+
cost_usd: 0.00015,
|
|
41
|
+
latency_ms: 123,
|
|
42
|
+
ok: true,
|
|
43
|
+
caller: "kg-extract",
|
|
44
|
+
session_id: "sess-001",
|
|
45
|
+
});
|
|
46
|
+
await q.drain();
|
|
47
|
+
setDefaultQueue(prevQueue);
|
|
48
|
+
assert.equal(rows.length, 1);
|
|
49
|
+
const row = rows[0];
|
|
50
|
+
assert.ok(row, "row should exist");
|
|
51
|
+
assert.equal(row?.provider_id, "gemini");
|
|
52
|
+
assert.equal(row?.model, "gemini-2.5-flash-lite");
|
|
53
|
+
assert.equal(row?.kind, "llm");
|
|
54
|
+
assert.equal(row?.tokens_in, 100);
|
|
55
|
+
assert.equal(row?.tokens_out, 50);
|
|
56
|
+
assert.equal(row?.ok, 1);
|
|
57
|
+
assert.equal(row?.caller, "kg-extract");
|
|
58
|
+
assert.equal(row?.session_id, "sess-001");
|
|
59
|
+
assert.equal(typeof row?.ts, "number");
|
|
60
|
+
assert.ok((row?.ts ?? 0) > 0);
|
|
61
|
+
});
|
|
62
|
+
test("error_kind has secrets redacted (API key pattern stripped)", async () => {
|
|
63
|
+
const rows = [];
|
|
64
|
+
const q = makeQueue(rows);
|
|
65
|
+
const prevQueue = getDefaultQueue();
|
|
66
|
+
setDefaultQueue(q);
|
|
67
|
+
recordProviderCall({
|
|
68
|
+
provider_id: "gemini",
|
|
69
|
+
model: "gemini-2.5-flash-lite",
|
|
70
|
+
kind: "llm",
|
|
71
|
+
latency_ms: 50,
|
|
72
|
+
ok: false,
|
|
73
|
+
errorRaw: "401 Unauthorized: key=AIzaABCDEFGHIJKLMNOPQRSTUVWXYZ12345 is invalid",
|
|
74
|
+
});
|
|
75
|
+
await q.drain();
|
|
76
|
+
setDefaultQueue(prevQueue);
|
|
77
|
+
assert.equal(rows.length, 1);
|
|
78
|
+
const row = rows[0];
|
|
79
|
+
assert.ok(row?.error_kind, "error_kind should be set");
|
|
80
|
+
// Key should be redacted.
|
|
81
|
+
assert.equal(row?.error_kind?.includes("AIzaABCDEFGHIJKLMN"), false);
|
|
82
|
+
assert.match(row?.error_kind ?? "", /REDACTED|401/);
|
|
83
|
+
});
|
|
84
|
+
test("row does NOT contain prompt text (privacy invariant)", async () => {
|
|
85
|
+
const rows = [];
|
|
86
|
+
const q = makeQueue(rows);
|
|
87
|
+
const prevQueue = getDefaultQueue();
|
|
88
|
+
setDefaultQueue(q);
|
|
89
|
+
const secretPrompt = "CONFIDENTIAL_PROMPT_CONTENT_DO_NOT_LOG_XYZ";
|
|
90
|
+
recordProviderCall({
|
|
91
|
+
provider_id: "gemini",
|
|
92
|
+
model: "gemini-2.5-flash-lite",
|
|
93
|
+
kind: "llm",
|
|
94
|
+
latency_ms: 10,
|
|
95
|
+
ok: true,
|
|
96
|
+
caller: "reflect",
|
|
97
|
+
// NOTE: no `user` field — prompt is never passed here by design.
|
|
98
|
+
});
|
|
99
|
+
await q.drain();
|
|
100
|
+
setDefaultQueue(prevQueue);
|
|
101
|
+
const rowStr = JSON.stringify(rows[0] ?? {});
|
|
102
|
+
// The secret prompt was never passed so it cannot appear.
|
|
103
|
+
assert.equal(rowStr.includes(secretPrompt), false);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe("TelemetryQueue — drain + overflow + error isolation", () => {
|
|
107
|
+
test("drain flushes all rows via writeFn", async () => {
|
|
108
|
+
const rows = [];
|
|
109
|
+
const q = makeQueue(rows);
|
|
110
|
+
for (let i = 0; i < 10; i++) {
|
|
111
|
+
q.enqueue({
|
|
112
|
+
ts: Date.now(),
|
|
113
|
+
provider_id: "gemini",
|
|
114
|
+
model: "m",
|
|
115
|
+
kind: "embedding",
|
|
116
|
+
tokens_in: i,
|
|
117
|
+
tokens_out: 0,
|
|
118
|
+
cost_usd: 0,
|
|
119
|
+
latency_ms: 1,
|
|
120
|
+
ok: 1,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
await q.drain();
|
|
124
|
+
assert.equal(rows.length, 10);
|
|
125
|
+
});
|
|
126
|
+
test("queue overflow: oldest entries dropped when capacity exceeded", async () => {
|
|
127
|
+
const written = [];
|
|
128
|
+
const q = new TelemetryQueue({
|
|
129
|
+
writeFn: async (row) => { written.push(row); },
|
|
130
|
+
capacity: 3,
|
|
131
|
+
});
|
|
132
|
+
// Enqueue 5 items — oldest 2 should be dropped.
|
|
133
|
+
for (let i = 0; i < 5; i++) {
|
|
134
|
+
q.enqueue({
|
|
135
|
+
ts: i,
|
|
136
|
+
provider_id: `p${i}`,
|
|
137
|
+
model: "m",
|
|
138
|
+
kind: "llm",
|
|
139
|
+
tokens_in: 0,
|
|
140
|
+
tokens_out: 0,
|
|
141
|
+
cost_usd: 0,
|
|
142
|
+
latency_ms: 1,
|
|
143
|
+
ok: 1,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
await q.drain();
|
|
147
|
+
// capacity=3 means at most 3 survive; p0 and p1 were pushed out.
|
|
148
|
+
// Check that we didn't write more than 3 rows.
|
|
149
|
+
assert.ok(written.length <= 3, `expected ≤3 rows, got ${written.length}`);
|
|
150
|
+
// The surviving rows should be among the later-inserted ones.
|
|
151
|
+
const writtenIds = written.map((r) => r.provider_id);
|
|
152
|
+
// p0 or p1 may have been evicted; p4 must survive.
|
|
153
|
+
assert.ok(writtenIds.includes("p4"), "most recent entry should survive overflow");
|
|
154
|
+
});
|
|
155
|
+
test("writeFn error does NOT propagate to recordProviderCall", async () => {
|
|
156
|
+
let errorCaught = null;
|
|
157
|
+
const q = new TelemetryQueue({
|
|
158
|
+
writeFn: async () => {
|
|
159
|
+
throw new Error("DB write failed");
|
|
160
|
+
},
|
|
161
|
+
onError: (err) => {
|
|
162
|
+
errorCaught = err;
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const prevQueue = getDefaultQueue();
|
|
166
|
+
setDefaultQueue(q);
|
|
167
|
+
// Must not throw.
|
|
168
|
+
assert.doesNotThrow(() => {
|
|
169
|
+
recordProviderCall({
|
|
170
|
+
provider_id: "gemini",
|
|
171
|
+
model: "m",
|
|
172
|
+
kind: "llm",
|
|
173
|
+
latency_ms: 1,
|
|
174
|
+
ok: true,
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
await q.drain();
|
|
178
|
+
setDefaultQueue(prevQueue);
|
|
179
|
+
// Error was captured by onError, not propagated.
|
|
180
|
+
assert.ok(errorCaught instanceof Error);
|
|
181
|
+
assert.match(errorCaught.message, /DB write failed/);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
describe("aggregateCosts — statistics", () => {
|
|
185
|
+
const nowMs = 1_000_000_000_000;
|
|
186
|
+
const hour = 3_600_000;
|
|
187
|
+
test("last24h totals computed correctly", () => {
|
|
188
|
+
const rows = [
|
|
189
|
+
{ ts: nowMs - hour, provider_id: "gemini", model: "m", kind: "llm", tokens_in: 0, tokens_out: 0, cost_usd: 1.50, latency_ms: 10, ok: 1 },
|
|
190
|
+
{ ts: nowMs - 2 * hour, provider_id: "openai", model: "m", kind: "llm", tokens_in: 0, tokens_out: 0, cost_usd: 0.75, latency_ms: 10, ok: 1 },
|
|
191
|
+
];
|
|
192
|
+
const agg = aggregateCosts(rows, nowMs);
|
|
193
|
+
assert.ok(Math.abs(agg.last24hUsd - 2.25) < 0.001);
|
|
194
|
+
assert.equal(agg.last24hCalls, 2);
|
|
195
|
+
assert.equal(agg.last24hSuccessRate, 1);
|
|
196
|
+
});
|
|
197
|
+
test("rows older than 24h excluded", () => {
|
|
198
|
+
const rows = [
|
|
199
|
+
{ ts: nowMs - 25 * hour, provider_id: "gemini", model: "m", kind: "llm", tokens_in: 0, tokens_out: 0, cost_usd: 100.00, latency_ms: 10, ok: 1 },
|
|
200
|
+
{ ts: nowMs - hour, provider_id: "gemini", model: "m", kind: "llm", tokens_in: 0, tokens_out: 0, cost_usd: 0.10, latency_ms: 10, ok: 1 },
|
|
201
|
+
];
|
|
202
|
+
const agg = aggregateCosts(rows, nowMs);
|
|
203
|
+
assert.ok(Math.abs(agg.last24hUsd - 0.10) < 0.001, `expected ~0.10, got ${agg.last24hUsd}`);
|
|
204
|
+
assert.equal(agg.last24hCalls, 1);
|
|
205
|
+
});
|
|
206
|
+
test("per-provider breakdown populated", () => {
|
|
207
|
+
const rows = [
|
|
208
|
+
{ ts: nowMs - hour, provider_id: "gemini", model: "m", kind: "llm", tokens_in: 0, tokens_out: 0, cost_usd: 1.00, latency_ms: 10, ok: 1 },
|
|
209
|
+
{ ts: nowMs - hour, provider_id: "gemini", model: "m", kind: "llm", tokens_in: 0, tokens_out: 0, cost_usd: 2.00, latency_ms: 10, ok: 1 },
|
|
210
|
+
{ ts: nowMs - hour, provider_id: "openai", model: "m", kind: "llm", tokens_in: 0, tokens_out: 0, cost_usd: 0.50, latency_ms: 10, ok: 0 },
|
|
211
|
+
];
|
|
212
|
+
const agg = aggregateCosts(rows, nowMs);
|
|
213
|
+
assert.ok(agg.byProvider["gemini"], "gemini in byProvider");
|
|
214
|
+
assert.ok(Math.abs((agg.byProvider["gemini"]?.usd ?? 0) - 3.00) < 0.001);
|
|
215
|
+
assert.equal(agg.byProvider["gemini"]?.calls, 2);
|
|
216
|
+
assert.equal(agg.byProvider["openai"]?.calls, 1);
|
|
217
|
+
assert.ok(Math.abs(agg.last24hSuccessRate - (2 / 3)) < 0.01);
|
|
218
|
+
});
|
|
219
|
+
});
|
package/dist/reindex.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// - 2026-04-25: end-of-day cron reindex wiped section/retention metadata of 183 entities.
|
|
5
5
|
// Patched by switching cron to `consolidate`. Reindex CODE itself still buggy.
|
|
6
6
|
// - 2026-05-19: eval ingest cruzou pro main DB (~5828 chunks lost). PR #145 4-layer guard.
|
|
7
|
-
// - 2026-05-23 23:17 BRT: nightly reindex
|
|
8
|
-
//
|
|
7
|
+
// - 2026-05-23 23:17 BRT: nightly reindex overwrote chunks. Recovery via pre-op snapshot
|
|
8
|
+
// in /var/backups/nox-mem/pre-op/ (69032 chunks).
|
|
9
9
|
//
|
|
10
10
|
// ROOT CAUSE (3rd incident):
|
|
11
11
|
// Pre-fix flow was DESTRUCTIVE-THEN-REBUILD:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nox-mem",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Pain-weighted hybrid memory engine: FTS5 + semantic search + knowledge graph, self-hosted on any Linux VPS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,18 +48,17 @@
|
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsc",
|
|
50
50
|
"prepublishOnly": "npm run build",
|
|
51
|
-
"test": "node --test dist
|
|
51
|
+
"test": "rm -rf dist && npm run build && tsc -p tsconfig.test.json && node --test \"dist/**/*.test.js\"",
|
|
52
52
|
"test:retention": "node --test dist/__tests__/retention.test.js",
|
|
53
53
|
"test:op-audit": "node --test dist/__tests__/op-audit-e2e.test.js"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@google-cloud/documentai": "^9.6.1",
|
|
57
|
-
"@xenova/transformers": "^2.17.2",
|
|
58
56
|
"better-sqlite3": "^11.0.0",
|
|
59
57
|
"commander": "^12.0.0",
|
|
60
58
|
"sqlite-vec": "^0.1.10-alpha.1"
|
|
61
59
|
},
|
|
62
60
|
"optionalDependencies": {
|
|
61
|
+
"@xenova/transformers": "^2.17.2",
|
|
63
62
|
"sqlite-vec-darwin-arm64": "^0.1.10-alpha.1",
|
|
64
63
|
"sqlite-vec-darwin-x64": "^0.1.10-alpha.1",
|
|
65
64
|
"sqlite-vec-linux-arm64": "^0.1.10-alpha.1",
|