comisai 1.0.11 → 1.0.12
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/node_modules/@comis/agent/dist/executor/pi-executor.d.ts +1 -4
- package/node_modules/@comis/agent/package.json +1 -1
- package/node_modules/@comis/channels/package.json +1 -1
- package/node_modules/@comis/cli/package.json +1 -1
- package/node_modules/@comis/core/package.json +1 -1
- package/node_modules/@comis/daemon/package.json +1 -1
- package/node_modules/@comis/gateway/package.json +1 -1
- package/node_modules/@comis/infra/package.json +1 -1
- package/node_modules/@comis/memory/package.json +1 -1
- package/node_modules/@comis/scheduler/package.json +1 -1
- package/node_modules/@comis/shared/package.json +1 -1
- package/node_modules/@comis/skills/package.json +1 -1
- package/package.json +18 -18
- package/node_modules/@comis/core/dist/approval/approval-gate.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/approval/approval-gate.test.js +0 -1003
- package/node_modules/@comis/core/dist/bootstrap.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/bootstrap.test.js +0 -150
- package/node_modules/@comis/core/dist/config/backup.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/backup.test.js +0 -160
- package/node_modules/@comis/core/dist/config/env-substitution.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/env-substitution.test.js +0 -259
- package/node_modules/@comis/core/dist/config/field-metadata.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/field-metadata.test.js +0 -72
- package/node_modules/@comis/core/dist/config/git-manager.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/git-manager.test.js +0 -1042
- package/node_modules/@comis/core/dist/config/immutable-keys.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/immutable-keys.test.js +0 -283
- package/node_modules/@comis/core/dist/config/include-resolver.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/include-resolver.test.js +0 -292
- package/node_modules/@comis/core/dist/config/layered.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/layered.test.js +0 -211
- package/node_modules/@comis/core/dist/config/loader.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/loader.test.js +0 -300
- package/node_modules/@comis/core/dist/config/migrate.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/migrate.test.js +0 -244
- package/node_modules/@comis/core/dist/config/partial-validator.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/partial-validator.test.js +0 -98
- package/node_modules/@comis/core/dist/config/schema-agent-model.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-agent-model.test.js +0 -279
- package/node_modules/@comis/core/dist/config/schema-agent-session.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-agent-session.test.js +0 -242
- package/node_modules/@comis/core/dist/config/schema-agent.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-agent.test.js +0 -645
- package/node_modules/@comis/core/dist/config/schema-channel.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-channel.test.js +0 -341
- package/node_modules/@comis/core/dist/config/schema-coalescer.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-coalescer.test.js +0 -51
- package/node_modules/@comis/core/dist/config/schema-context-engine.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-context-engine.test.js +0 -797
- package/node_modules/@comis/core/dist/config/schema-context-guard.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-context-guard.test.js +0 -111
- package/node_modules/@comis/core/dist/config/schema-daemon.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-daemon.test.js +0 -107
- package/node_modules/@comis/core/dist/config/schema-delivery-timing.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-delivery-timing.test.js +0 -51
- package/node_modules/@comis/core/dist/config/schema-documentation.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-documentation.test.js +0 -63
- package/node_modules/@comis/core/dist/config/schema-gateway.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-gateway.test.js +0 -219
- package/node_modules/@comis/core/dist/config/schema-gemini-cache.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-gemini-cache.test.js +0 -41
- package/node_modules/@comis/core/dist/config/schema-integrations.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-integrations.test.js +0 -92
- package/node_modules/@comis/core/dist/config/schema-lifecycle-reactions.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-lifecycle-reactions.test.js +0 -61
- package/node_modules/@comis/core/dist/config/schema-misc.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-misc.test.js +0 -394
- package/node_modules/@comis/core/dist/config/schema-observability.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-observability.test.js +0 -76
- package/node_modules/@comis/core/dist/config/schema-providers.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-providers.test.js +0 -294
- package/node_modules/@comis/core/dist/config/schema-queue.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-queue.test.js +0 -234
- package/node_modules/@comis/core/dist/config/schema-response-prefix.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-response-prefix.test.js +0 -36
- package/node_modules/@comis/core/dist/config/schema-security.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-security.test.js +0 -54
- package/node_modules/@comis/core/dist/config/schema-sender-trust-display.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-sender-trust-display.test.js +0 -60
- package/node_modules/@comis/core/dist/config/schema-serializer.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-serializer.test.js +0 -73
- package/node_modules/@comis/core/dist/config/schema-telegram-file-guard.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/config/schema-telegram-file-guard.test.js +0 -39
- package/node_modules/@comis/core/dist/context/context.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/context/context.test.js +0 -276
- package/node_modules/@comis/core/dist/domain/agent-response.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/agent-response.test.js +0 -159
- package/node_modules/@comis/core/dist/domain/credential-mapping.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/credential-mapping.test.js +0 -135
- package/node_modules/@comis/core/dist/domain/delivery-origin.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/delivery-origin.test.js +0 -68
- package/node_modules/@comis/core/dist/domain/execution-graph.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/execution-graph.test.js +0 -441
- package/node_modules/@comis/core/dist/domain/memory-entry.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/memory-entry.test.js +0 -193
- package/node_modules/@comis/core/dist/domain/normalized-message.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/normalized-message.test.js +0 -255
- package/node_modules/@comis/core/dist/domain/session-key.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/session-key.test.js +0 -291
- package/node_modules/@comis/core/dist/domain/subagent-context-config.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/subagent-context-config.test.js +0 -131
- package/node_modules/@comis/core/dist/domain/subagent-context-types.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/domain/subagent-context-types.test.js +0 -182
- package/node_modules/@comis/core/dist/event-bus/bus.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/event-bus/bus.test.js +0 -152
- package/node_modules/@comis/core/dist/event-bus/events-agent.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/event-bus/events-agent.test.js +0 -409
- package/node_modules/@comis/core/dist/event-bus/events-channel.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/event-bus/events-channel.test.js +0 -240
- package/node_modules/@comis/core/dist/event-bus/events-infra.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/event-bus/events-infra.test.js +0 -416
- package/node_modules/@comis/core/dist/event-bus/events-messaging.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/event-bus/events-messaging.test.js +0 -433
- package/node_modules/@comis/core/dist/event-bus/events.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/event-bus/events.test.js +0 -93
- package/node_modules/@comis/core/dist/hooks/hook-runner-global.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/hooks/hook-runner-global.test.js +0 -29
- package/node_modules/@comis/core/dist/hooks/hook-runner.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/hooks/hook-runner.test.js +0 -490
- package/node_modules/@comis/core/dist/hooks/hook-strategies.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/hooks/hook-strategies.test.js +0 -209
- package/node_modules/@comis/core/dist/hooks/integration.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/hooks/integration.test.js +0 -235
- package/node_modules/@comis/core/dist/hooks/plugin-registry.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/hooks/plugin-registry.test.js +0 -470
- package/node_modules/@comis/core/dist/load-env.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/load-env.test.js +0 -21
- package/node_modules/@comis/core/dist/security/action-classifier.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/action-classifier.test.js +0 -298
- package/node_modules/@comis/core/dist/security/audit-aggregator.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/audit-aggregator.test.js +0 -128
- package/node_modules/@comis/core/dist/security/audit.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/audit.test.js +0 -154
- package/node_modules/@comis/core/dist/security/canary-token.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/canary-token.test.js +0 -45
- package/node_modules/@comis/core/dist/security/config-redaction.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/config-redaction.test.js +0 -107
- package/node_modules/@comis/core/dist/security/external-content.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/external-content.test.js +0 -210
- package/node_modules/@comis/core/dist/security/injection-patterns.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/injection-patterns.test.js +0 -213
- package/node_modules/@comis/core/dist/security/injection-rate-limiter.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/injection-rate-limiter.test.js +0 -194
- package/node_modules/@comis/core/dist/security/input-guard.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/input-guard.test.js +0 -215
- package/node_modules/@comis/core/dist/security/input-security-guard.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/input-security-guard.test.js +0 -215
- package/node_modules/@comis/core/dist/security/input-validator.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/input-validator.test.js +0 -133
- package/node_modules/@comis/core/dist/security/log-sanitizer.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/log-sanitizer.test.js +0 -260
- package/node_modules/@comis/core/dist/security/memory-write-validator.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/memory-write-validator.test.js +0 -62
- package/node_modules/@comis/core/dist/security/output-guard.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/output-guard.test.js +0 -397
- package/node_modules/@comis/core/dist/security/safe-path.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/safe-path.test.js +0 -95
- package/node_modules/@comis/core/dist/security/scoped-secret-manager.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/scoped-secret-manager.test.js +0 -231
- package/node_modules/@comis/core/dist/security/secret-access.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/secret-access.test.js +0 -41
- package/node_modules/@comis/core/dist/security/secret-crypto.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/secret-crypto.test.js +0 -113
- package/node_modules/@comis/core/dist/security/secret-manager.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/secret-manager.test.js +0 -394
- package/node_modules/@comis/core/dist/security/secret-ref-resolver.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/secret-ref-resolver.test.js +0 -268
- package/node_modules/@comis/core/dist/security/secrets-audit.test.d.ts +0 -10
- package/node_modules/@comis/core/dist/security/secrets-audit.test.js +0 -295
- package/node_modules/@comis/core/dist/security/ssrf-guard.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/ssrf-guard.test.js +0 -127
- package/node_modules/@comis/core/dist/security/token-generator.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/security/token-generator.test.js +0 -35
- package/node_modules/@comis/core/dist/tool-metadata.test.d.ts +0 -1
- package/node_modules/@comis/core/dist/tool-metadata.test.js +0 -112
- package/node_modules/@comis/memory/dist/compaction.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/compaction.test.js +0 -298
- package/node_modules/@comis/memory/dist/context-schema.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/context-schema.test.js +0 -246
- package/node_modules/@comis/memory/dist/context-store.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/context-store.test.js +0 -708
- package/node_modules/@comis/memory/dist/credential-mapping-schema.test.d.ts +0 -7
- package/node_modules/@comis/memory/dist/credential-mapping-schema.test.js +0 -73
- package/node_modules/@comis/memory/dist/credential-mapping-store.test.d.ts +0 -8
- package/node_modules/@comis/memory/dist/credential-mapping-store.test.js +0 -340
- package/node_modules/@comis/memory/dist/delivery-mirror-adapter.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/delivery-mirror-adapter.test.js +0 -165
- package/node_modules/@comis/memory/dist/delivery-queue-adapter.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/delivery-queue-adapter.test.js +0 -263
- package/node_modules/@comis/memory/dist/embedding-batch-indexer.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/embedding-batch-indexer.test.js +0 -202
- package/node_modules/@comis/memory/dist/embedding-cache-lru.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/embedding-cache-lru.test.js +0 -241
- package/node_modules/@comis/memory/dist/embedding-cache-sqlite.test.d.ts +0 -8
- package/node_modules/@comis/memory/dist/embedding-cache-sqlite.test.js +0 -678
- package/node_modules/@comis/memory/dist/embedding-cache.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/embedding-cache.test.js +0 -213
- package/node_modules/@comis/memory/dist/embedding-fingerprint.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/embedding-fingerprint.test.js +0 -87
- package/node_modules/@comis/memory/dist/embedding-hash.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/embedding-hash.test.js +0 -31
- package/node_modules/@comis/memory/dist/embedding-integration.test.d.ts +0 -8
- package/node_modules/@comis/memory/dist/embedding-integration.test.js +0 -232
- package/node_modules/@comis/memory/dist/embedding-provider-factory.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/embedding-provider-factory.test.js +0 -176
- package/node_modules/@comis/memory/dist/embedding-provider-local.test.d.ts +0 -8
- package/node_modules/@comis/memory/dist/embedding-provider-local.test.js +0 -76
- package/node_modules/@comis/memory/dist/embedding-provider-openai.test.d.ts +0 -8
- package/node_modules/@comis/memory/dist/embedding-provider-openai.test.js +0 -100
- package/node_modules/@comis/memory/dist/embedding-queue.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/embedding-queue.test.js +0 -236
- package/node_modules/@comis/memory/dist/hybrid-search.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/hybrid-search.test.js +0 -476
- package/node_modules/@comis/memory/dist/identity-link-store.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/identity-link-store.test.js +0 -88
- package/node_modules/@comis/memory/dist/memory-api.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/memory-api.test.js +0 -495
- package/node_modules/@comis/memory/dist/memory-concurrency.test.d.ts +0 -20
- package/node_modules/@comis/memory/dist/memory-concurrency.test.js +0 -222
- package/node_modules/@comis/memory/dist/named-graph-store.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/named-graph-store.test.js +0 -227
- package/node_modules/@comis/memory/dist/observability-store.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/observability-store.test.js +0 -704
- package/node_modules/@comis/memory/dist/row-mapper.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/row-mapper.test.js +0 -409
- package/node_modules/@comis/memory/dist/schema.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/schema.test.js +0 -240
- package/node_modules/@comis/memory/dist/secret-store-schema.test.d.ts +0 -7
- package/node_modules/@comis/memory/dist/secret-store-schema.test.js +0 -90
- package/node_modules/@comis/memory/dist/session-store.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/session-store.test.js +0 -262
- package/node_modules/@comis/memory/dist/setup-secrets.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/setup-secrets.test.js +0 -140
- package/node_modules/@comis/memory/dist/sqlite-memory-adapter.test.d.ts +0 -1
- package/node_modules/@comis/memory/dist/sqlite-memory-adapter.test.js +0 -888
- package/node_modules/@comis/memory/dist/sqlite-secret-store.test.d.ts +0 -8
- package/node_modules/@comis/memory/dist/sqlite-secret-store.test.js +0 -245
- package/node_modules/@comis/shared/dist/abort.test.d.ts +0 -1
- package/node_modules/@comis/shared/dist/abort.test.js +0 -71
- package/node_modules/@comis/shared/dist/result.test.d.ts +0 -1
- package/node_modules/@comis/shared/dist/result.test.js +0 -178
- package/node_modules/@comis/shared/dist/suppress-error.test.d.ts +0 -1
- package/node_modules/@comis/shared/dist/suppress-error.test.js +0 -50
- package/node_modules/@comis/shared/dist/timeout.test.d.ts +0 -1
- package/node_modules/@comis/shared/dist/timeout.test.js +0 -75
- package/node_modules/@comis/shared/dist/ttl-cache.test.d.ts +0 -1
- package/node_modules/@comis/shared/dist/ttl-cache.test.js +0 -81
|
@@ -1,888 +0,0 @@
|
|
|
1
|
-
import { ok } from "@comis/shared";
|
|
2
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { isVecAvailable } from "./schema.js";
|
|
5
|
-
import { SqliteMemoryAdapter } from "./sqlite-memory-adapter.js";
|
|
6
|
-
/** Default test config using in-memory SQLite. */
|
|
7
|
-
const testConfig = {
|
|
8
|
-
dbPath: ":memory:",
|
|
9
|
-
walMode: false, // WAL not supported on :memory:
|
|
10
|
-
embeddingModel: "test-model",
|
|
11
|
-
embeddingDimensions: 4,
|
|
12
|
-
compaction: { enabled: false, threshold: 1000, targetSize: 500 },
|
|
13
|
-
retention: { maxAgeDays: 0, maxEntries: 0 },
|
|
14
|
-
};
|
|
15
|
-
/** Create a minimal valid MemoryEntry for testing. */
|
|
16
|
-
function makeEntry(overrides) {
|
|
17
|
-
return {
|
|
18
|
-
id: overrides?.id ?? crypto.randomUUID(),
|
|
19
|
-
tenantId: overrides?.tenantId ?? "default",
|
|
20
|
-
agentId: overrides?.agentId ?? "default",
|
|
21
|
-
userId: overrides?.userId ?? "user-1",
|
|
22
|
-
content: overrides?.content ?? "test memory content",
|
|
23
|
-
trustLevel: overrides?.trustLevel ?? "learned",
|
|
24
|
-
source: overrides?.source ?? { who: "agent", channel: "telegram" },
|
|
25
|
-
tags: overrides?.tags ?? [],
|
|
26
|
-
createdAt: overrides?.createdAt ?? Date.now(),
|
|
27
|
-
...(overrides?.updatedAt !== undefined ? { updatedAt: overrides.updatedAt } : {}),
|
|
28
|
-
...(overrides?.expiresAt !== undefined ? { expiresAt: overrides.expiresAt } : {}),
|
|
29
|
-
...(overrides?.embedding ? { embedding: overrides.embedding } : {}),
|
|
30
|
-
...(overrides?.memoryType ? { memoryType: overrides.memoryType } : {}),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/** Create a mock EmbeddingPort for testing. */
|
|
34
|
-
function createMockEmbeddingPort(dimensions = 4) {
|
|
35
|
-
return {
|
|
36
|
-
provider: "test",
|
|
37
|
-
dimensions,
|
|
38
|
-
modelId: "test-embed-model",
|
|
39
|
-
async embed(text) {
|
|
40
|
-
// Simple deterministic embedding based on text length
|
|
41
|
-
const vec = new Array(dimensions).fill(0);
|
|
42
|
-
for (let i = 0; i < text.length && i < dimensions; i++) {
|
|
43
|
-
vec[i] = text.charCodeAt(i) / 256;
|
|
44
|
-
}
|
|
45
|
-
return ok(vec);
|
|
46
|
-
},
|
|
47
|
-
async embedBatch(texts) {
|
|
48
|
-
const vecs = [];
|
|
49
|
-
for (const text of texts) {
|
|
50
|
-
const result = await this.embed(text);
|
|
51
|
-
if (result.ok)
|
|
52
|
-
vecs.push(result.value);
|
|
53
|
-
}
|
|
54
|
-
return ok(vecs);
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
const testSessionKey = {
|
|
59
|
-
tenantId: "default",
|
|
60
|
-
userId: "user-1",
|
|
61
|
-
channelId: "test-channel",
|
|
62
|
-
};
|
|
63
|
-
describe("SqliteMemoryAdapter", () => {
|
|
64
|
-
let adapter;
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
adapter = new SqliteMemoryAdapter(testConfig);
|
|
67
|
-
});
|
|
68
|
-
afterEach(() => {
|
|
69
|
-
adapter.close();
|
|
70
|
-
});
|
|
71
|
-
// ── Constructor / setup ────────────────────────────────────────
|
|
72
|
-
describe("constructor", () => {
|
|
73
|
-
it("creates adapter with in-memory database", () => {
|
|
74
|
-
expect(adapter).toBeDefined();
|
|
75
|
-
expect(adapter.getDb()).toBeDefined();
|
|
76
|
-
});
|
|
77
|
-
it("enables WAL mode when configured", () => {
|
|
78
|
-
const walAdapter = new SqliteMemoryAdapter({
|
|
79
|
-
...testConfig,
|
|
80
|
-
dbPath: ":memory:",
|
|
81
|
-
walMode: true,
|
|
82
|
-
});
|
|
83
|
-
// WAL mode on :memory: may not fully apply, but pragma should not error
|
|
84
|
-
expect(walAdapter).toBeDefined();
|
|
85
|
-
walAdapter.close();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
// ── store ──────────────────────────────────────────────────────
|
|
89
|
-
describe("store", () => {
|
|
90
|
-
it("stores a memory entry and returns ok result", async () => {
|
|
91
|
-
const entry = makeEntry();
|
|
92
|
-
const result = await adapter.store(entry);
|
|
93
|
-
expect(result.ok).toBe(true);
|
|
94
|
-
if (result.ok) {
|
|
95
|
-
expect(result.value.id).toBe(entry.id);
|
|
96
|
-
expect(result.value.content).toBe(entry.content);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
it("persists full provenance (who, channel, trust level)", async () => {
|
|
100
|
-
const entry = makeEntry({
|
|
101
|
-
trustLevel: "external",
|
|
102
|
-
source: { who: "web-scraper", channel: "api", sessionKey: "sess-123" },
|
|
103
|
-
});
|
|
104
|
-
await adapter.store(entry);
|
|
105
|
-
const result = await adapter.retrieve(entry.id);
|
|
106
|
-
expect(result.ok).toBe(true);
|
|
107
|
-
if (result.ok && result.value) {
|
|
108
|
-
expect(result.value.trustLevel).toBe("external");
|
|
109
|
-
expect(result.value.source.who).toBe("web-scraper");
|
|
110
|
-
expect(result.value.source.channel).toBe("api");
|
|
111
|
-
expect(result.value.source.sessionKey).toBe("sess-123");
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
it("stores entry with tags", async () => {
|
|
115
|
-
const entry = makeEntry({ tags: ["important", "project-x"] });
|
|
116
|
-
await adapter.store(entry);
|
|
117
|
-
const result = await adapter.retrieve(entry.id);
|
|
118
|
-
expect(result.ok).toBe(true);
|
|
119
|
-
if (result.ok && result.value) {
|
|
120
|
-
expect(result.value.tags).toEqual(["important", "project-x"]);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
it("stores entry with embedding when vec is available", async () => {
|
|
124
|
-
if (!isVecAvailable())
|
|
125
|
-
return;
|
|
126
|
-
const entry = makeEntry({ embedding: [0.1, 0.2, 0.3, 0.4] });
|
|
127
|
-
const result = await adapter.store(entry);
|
|
128
|
-
expect(result.ok).toBe(true);
|
|
129
|
-
// Verify embedding was stored
|
|
130
|
-
const retrieved = await adapter.retrieve(entry.id);
|
|
131
|
-
expect(retrieved.ok).toBe(true);
|
|
132
|
-
if (retrieved.ok && retrieved.value) {
|
|
133
|
-
expect(retrieved.value.embedding).toBeDefined();
|
|
134
|
-
expect(retrieved.value.embedding.length).toBe(4);
|
|
135
|
-
expect(retrieved.value.embedding[0]).toBeCloseTo(0.1, 4);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
it("defaults memory_type to semantic", async () => {
|
|
139
|
-
const entry = makeEntry();
|
|
140
|
-
await adapter.store(entry);
|
|
141
|
-
// Query raw DB to check memory_type
|
|
142
|
-
const row = adapter
|
|
143
|
-
.getDb()
|
|
144
|
-
.prepare("SELECT memory_type FROM memories WHERE id = ?")
|
|
145
|
-
.get(entry.id);
|
|
146
|
-
expect(row.memory_type).toBe("semantic");
|
|
147
|
-
});
|
|
148
|
-
it("returns error for duplicate ID", async () => {
|
|
149
|
-
const entry = makeEntry();
|
|
150
|
-
await adapter.store(entry);
|
|
151
|
-
const result = await adapter.store(entry);
|
|
152
|
-
expect(result.ok).toBe(false);
|
|
153
|
-
});
|
|
154
|
-
it("stores entry with expiresAt", async () => {
|
|
155
|
-
const expires = Date.now() + 86400000; // 1 day
|
|
156
|
-
const entry = makeEntry({ expiresAt: expires });
|
|
157
|
-
await adapter.store(entry);
|
|
158
|
-
const result = await adapter.retrieve(entry.id);
|
|
159
|
-
expect(result.ok).toBe(true);
|
|
160
|
-
if (result.ok && result.value) {
|
|
161
|
-
expect(result.value.expiresAt).toBe(expires);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
// ── storeWithType ──────────────────────────────────────────────
|
|
166
|
-
describe("storeWithType", () => {
|
|
167
|
-
it("stores entry with explicit memory type", async () => {
|
|
168
|
-
const entry = makeEntry();
|
|
169
|
-
await adapter.storeWithType(entry, "episodic");
|
|
170
|
-
const row = adapter
|
|
171
|
-
.getDb()
|
|
172
|
-
.prepare("SELECT memory_type FROM memories WHERE id = ?")
|
|
173
|
-
.get(entry.id);
|
|
174
|
-
expect(row.memory_type).toBe("episodic");
|
|
175
|
-
});
|
|
176
|
-
it("supports all memory types", async () => {
|
|
177
|
-
const types = ["working", "episodic", "semantic", "procedural"];
|
|
178
|
-
for (const type of types) {
|
|
179
|
-
const entry = makeEntry();
|
|
180
|
-
const result = await adapter.storeWithType(entry, type);
|
|
181
|
-
expect(result.ok).toBe(true);
|
|
182
|
-
const row = adapter
|
|
183
|
-
.getDb()
|
|
184
|
-
.prepare("SELECT memory_type FROM memories WHERE id = ?")
|
|
185
|
-
.get(entry.id);
|
|
186
|
-
expect(row.memory_type).toBe(type);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
// ── retrieve ───────────────────────────────────────────────────
|
|
191
|
-
describe("retrieve", () => {
|
|
192
|
-
it("retrieves stored entry with all fields intact", async () => {
|
|
193
|
-
const entry = makeEntry({
|
|
194
|
-
content: "remember this important fact",
|
|
195
|
-
trustLevel: "system",
|
|
196
|
-
source: { who: "admin", channel: "cli" },
|
|
197
|
-
tags: ["fact", "important"],
|
|
198
|
-
});
|
|
199
|
-
await adapter.store(entry);
|
|
200
|
-
const result = await adapter.retrieve(entry.id);
|
|
201
|
-
expect(result.ok).toBe(true);
|
|
202
|
-
if (result.ok && result.value) {
|
|
203
|
-
expect(result.value.id).toBe(entry.id);
|
|
204
|
-
expect(result.value.content).toBe("remember this important fact");
|
|
205
|
-
expect(result.value.trustLevel).toBe("system");
|
|
206
|
-
expect(result.value.source.who).toBe("admin");
|
|
207
|
-
expect(result.value.source.channel).toBe("cli");
|
|
208
|
-
expect(result.value.tags).toEqual(["fact", "important"]);
|
|
209
|
-
expect(result.value.tenantId).toBe("default");
|
|
210
|
-
expect(result.value.userId).toBe("user-1");
|
|
211
|
-
expect(result.value.createdAt).toBe(entry.createdAt);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
it("returns undefined for non-existent ID", async () => {
|
|
215
|
-
const result = await adapter.retrieve("non-existent-id");
|
|
216
|
-
expect(result.ok).toBe(true);
|
|
217
|
-
if (result.ok) {
|
|
218
|
-
expect(result.value).toBeUndefined();
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
it("scopes by tenantId", async () => {
|
|
222
|
-
const entry = makeEntry({ tenantId: "tenant-a" });
|
|
223
|
-
await adapter.store(entry);
|
|
224
|
-
// Should not find with different tenant
|
|
225
|
-
const result = await adapter.retrieve(entry.id, "tenant-b");
|
|
226
|
-
expect(result.ok).toBe(true);
|
|
227
|
-
if (result.ok) {
|
|
228
|
-
expect(result.value).toBeUndefined();
|
|
229
|
-
}
|
|
230
|
-
// Should find with correct tenant
|
|
231
|
-
const result2 = await adapter.retrieve(entry.id, "tenant-a");
|
|
232
|
-
expect(result2.ok).toBe(true);
|
|
233
|
-
if (result2.ok) {
|
|
234
|
-
expect(result2.value).toBeDefined();
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
// ── search ─────────────────────────────────────────────────────
|
|
239
|
-
describe("search", () => {
|
|
240
|
-
it("finds entries by text query via FTS5", async () => {
|
|
241
|
-
await adapter.store(makeEntry({ content: "dentist appointment on Tuesday" }));
|
|
242
|
-
await adapter.store(makeEntry({ content: "grocery list for the week" }));
|
|
243
|
-
const result = await adapter.search(testSessionKey, "dentist");
|
|
244
|
-
expect(result.ok).toBe(true);
|
|
245
|
-
if (result.ok) {
|
|
246
|
-
expect(result.value.length).toBe(1);
|
|
247
|
-
expect(result.value[0].entry.content).toBe("dentist appointment on Tuesday");
|
|
248
|
-
expect(result.value[0].score).toBeDefined();
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
it("finds entries by vector query", async () => {
|
|
252
|
-
if (!isVecAvailable())
|
|
253
|
-
return;
|
|
254
|
-
const e1 = makeEntry({ content: "entry one", embedding: [1, 0, 0, 0] });
|
|
255
|
-
const e2 = makeEntry({ content: "entry two", embedding: [0, 1, 0, 0] });
|
|
256
|
-
await adapter.store(e1);
|
|
257
|
-
await adapter.store(e2);
|
|
258
|
-
const result = await adapter.search(testSessionKey, [0.9, 0.1, 0, 0], { limit: 5 });
|
|
259
|
-
expect(result.ok).toBe(true);
|
|
260
|
-
if (result.ok) {
|
|
261
|
-
expect(result.value.length).toBeGreaterThanOrEqual(1);
|
|
262
|
-
// e1 should be closest
|
|
263
|
-
expect(result.value[0].entry.id).toBe(e1.id);
|
|
264
|
-
expect(result.value[0].score).toBeDefined();
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
it("respects limit option", async () => {
|
|
268
|
-
for (let i = 0; i < 5; i++) {
|
|
269
|
-
await adapter.store(makeEntry({ content: `cat memory number ${i}` }));
|
|
270
|
-
}
|
|
271
|
-
const result = await adapter.search(testSessionKey, "cat", { limit: 2 });
|
|
272
|
-
expect(result.ok).toBe(true);
|
|
273
|
-
if (result.ok) {
|
|
274
|
-
expect(result.value.length).toBe(2);
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
it("filters by trustLevel", async () => {
|
|
278
|
-
await adapter.store(makeEntry({ content: "system cat fact", trustLevel: "system" }));
|
|
279
|
-
await adapter.store(makeEntry({ content: "external cat data", trustLevel: "external" }));
|
|
280
|
-
const result = await adapter.search(testSessionKey, "cat", {
|
|
281
|
-
trustLevel: "system",
|
|
282
|
-
});
|
|
283
|
-
expect(result.ok).toBe(true);
|
|
284
|
-
if (result.ok) {
|
|
285
|
-
expect(result.value.length).toBe(1);
|
|
286
|
-
expect(result.value[0].entry.trustLevel).toBe("system");
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
it("filters by tags", async () => {
|
|
290
|
-
await adapter.store(makeEntry({
|
|
291
|
-
content: "tagged cat memory",
|
|
292
|
-
tags: ["important", "cat-facts"],
|
|
293
|
-
}));
|
|
294
|
-
await adapter.store(makeEntry({ content: "untagged cat memory", tags: [] }));
|
|
295
|
-
const result = await adapter.search(testSessionKey, "cat", {
|
|
296
|
-
tags: ["important"],
|
|
297
|
-
});
|
|
298
|
-
expect(result.ok).toBe(true);
|
|
299
|
-
if (result.ok) {
|
|
300
|
-
expect(result.value.length).toBe(1);
|
|
301
|
-
expect(result.value[0].entry.tags).toContain("important");
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
it("returns empty for no matches", async () => {
|
|
305
|
-
await adapter.store(makeEntry({ content: "the quick brown fox" }));
|
|
306
|
-
const result = await adapter.search(testSessionKey, "elephant");
|
|
307
|
-
expect(result.ok).toBe(true);
|
|
308
|
-
if (result.ok) {
|
|
309
|
-
expect(result.value).toHaveLength(0);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
it("uses embedding port for hybrid search when available", async () => {
|
|
313
|
-
if (!isVecAvailable())
|
|
314
|
-
return;
|
|
315
|
-
const embeddingPort = createMockEmbeddingPort(4);
|
|
316
|
-
const adapterWithEmbed = new SqliteMemoryAdapter(testConfig, embeddingPort);
|
|
317
|
-
try {
|
|
318
|
-
const e1 = makeEntry({
|
|
319
|
-
content: "dentist appointment",
|
|
320
|
-
embedding: [0.25, 0.39, 0.43, 0.4],
|
|
321
|
-
});
|
|
322
|
-
await adapterWithEmbed.store(e1);
|
|
323
|
-
const result = await adapterWithEmbed.search(testSessionKey, "dentist");
|
|
324
|
-
expect(result.ok).toBe(true);
|
|
325
|
-
if (result.ok) {
|
|
326
|
-
expect(result.value.length).toBeGreaterThanOrEqual(1);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
finally {
|
|
330
|
-
adapterWithEmbed.close();
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
it("truncates long search queries before embedding", async () => {
|
|
334
|
-
const embeddingPort = createMockEmbeddingPort(4);
|
|
335
|
-
const embedSpy = vi.spyOn(embeddingPort, "embed");
|
|
336
|
-
const adapterWithEmbed = new SqliteMemoryAdapter(testConfig, embeddingPort);
|
|
337
|
-
try {
|
|
338
|
-
// Store a memory so search has something to work with
|
|
339
|
-
await adapterWithEmbed.store(makeEntry({ content: "some memory content" }));
|
|
340
|
-
// Create a query longer than the truncation threshold (1536 tokens * 4 chars/token = 6144 chars)
|
|
341
|
-
const longQuery = "a".repeat(8000);
|
|
342
|
-
const result = await adapterWithEmbed.search(testSessionKey, longQuery);
|
|
343
|
-
expect(result.ok).toBe(true);
|
|
344
|
-
// Verify embed was called with a truncated string (<= 6144 chars)
|
|
345
|
-
expect(embedSpy).toHaveBeenCalledOnce();
|
|
346
|
-
const passedQuery = embedSpy.mock.calls[0][0];
|
|
347
|
-
expect(passedQuery.length).toBeLessThanOrEqual(6144);
|
|
348
|
-
expect(passedQuery.length).toBe(6144);
|
|
349
|
-
}
|
|
350
|
-
finally {
|
|
351
|
-
adapterWithEmbed.close();
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
// ── update ─────────────────────────────────────────────────────
|
|
356
|
-
describe("update", () => {
|
|
357
|
-
it("updates content field", async () => {
|
|
358
|
-
const entry = makeEntry({ content: "original content" });
|
|
359
|
-
await adapter.store(entry);
|
|
360
|
-
const result = await adapter.update(entry.id, { content: "updated content" });
|
|
361
|
-
expect(result.ok).toBe(true);
|
|
362
|
-
if (result.ok) {
|
|
363
|
-
expect(result.value.content).toBe("updated content");
|
|
364
|
-
expect(result.value.updatedAt).toBeDefined();
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
it("updates tags", async () => {
|
|
368
|
-
const entry = makeEntry({ tags: ["old-tag"] });
|
|
369
|
-
await adapter.store(entry);
|
|
370
|
-
const result = await adapter.update(entry.id, {
|
|
371
|
-
tags: ["new-tag", "another"],
|
|
372
|
-
});
|
|
373
|
-
expect(result.ok).toBe(true);
|
|
374
|
-
if (result.ok) {
|
|
375
|
-
expect(result.value.tags).toEqual(["new-tag", "another"]);
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
it("updates trustLevel", async () => {
|
|
379
|
-
const entry = makeEntry({ trustLevel: "external" });
|
|
380
|
-
await adapter.store(entry);
|
|
381
|
-
const result = await adapter.update(entry.id, { trustLevel: "learned" });
|
|
382
|
-
expect(result.ok).toBe(true);
|
|
383
|
-
if (result.ok) {
|
|
384
|
-
expect(result.value.trustLevel).toBe("learned");
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
it("updates expiresAt", async () => {
|
|
388
|
-
const entry = makeEntry();
|
|
389
|
-
await adapter.store(entry);
|
|
390
|
-
const newExpiry = Date.now() + 999999;
|
|
391
|
-
const result = await adapter.update(entry.id, { expiresAt: newExpiry });
|
|
392
|
-
expect(result.ok).toBe(true);
|
|
393
|
-
if (result.ok) {
|
|
394
|
-
expect(result.value.expiresAt).toBe(newExpiry);
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
it("updates embedding when vec is available", async () => {
|
|
398
|
-
if (!isVecAvailable())
|
|
399
|
-
return;
|
|
400
|
-
const entry = makeEntry({ embedding: [0.1, 0.2, 0.3, 0.4] });
|
|
401
|
-
await adapter.store(entry);
|
|
402
|
-
const result = await adapter.update(entry.id, {
|
|
403
|
-
embedding: [0.9, 0.8, 0.7, 0.6],
|
|
404
|
-
});
|
|
405
|
-
expect(result.ok).toBe(true);
|
|
406
|
-
// Verify new embedding
|
|
407
|
-
const retrieved = await adapter.retrieve(entry.id);
|
|
408
|
-
expect(retrieved.ok).toBe(true);
|
|
409
|
-
if (retrieved.ok && retrieved.value) {
|
|
410
|
-
expect(retrieved.value.embedding[0]).toBeCloseTo(0.9, 4);
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
it("returns error for non-existent entry", async () => {
|
|
414
|
-
const result = await adapter.update("non-existent", { content: "nope" });
|
|
415
|
-
expect(result.ok).toBe(false);
|
|
416
|
-
});
|
|
417
|
-
it("sets updatedAt timestamp on update", async () => {
|
|
418
|
-
const entry = makeEntry();
|
|
419
|
-
await adapter.store(entry);
|
|
420
|
-
const before = Date.now();
|
|
421
|
-
const result = await adapter.update(entry.id, { content: "modified" });
|
|
422
|
-
const after = Date.now();
|
|
423
|
-
expect(result.ok).toBe(true);
|
|
424
|
-
if (result.ok) {
|
|
425
|
-
expect(result.value.updatedAt).toBeGreaterThanOrEqual(before);
|
|
426
|
-
expect(result.value.updatedAt).toBeLessThanOrEqual(after);
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
});
|
|
430
|
-
// ── delete ─────────────────────────────────────────────────────
|
|
431
|
-
describe("delete", () => {
|
|
432
|
-
it("deletes existing entry and returns true", async () => {
|
|
433
|
-
const entry = makeEntry();
|
|
434
|
-
await adapter.store(entry);
|
|
435
|
-
const result = await adapter.delete(entry.id);
|
|
436
|
-
expect(result.ok).toBe(true);
|
|
437
|
-
if (result.ok) {
|
|
438
|
-
expect(result.value).toBe(true);
|
|
439
|
-
}
|
|
440
|
-
// Verify gone
|
|
441
|
-
const retrieved = await adapter.retrieve(entry.id);
|
|
442
|
-
expect(retrieved.ok).toBe(true);
|
|
443
|
-
if (retrieved.ok) {
|
|
444
|
-
expect(retrieved.value).toBeUndefined();
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
it("returns false for non-existent entry", async () => {
|
|
448
|
-
const result = await adapter.delete("non-existent");
|
|
449
|
-
expect(result.ok).toBe(true);
|
|
450
|
-
if (result.ok) {
|
|
451
|
-
expect(result.value).toBe(false);
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
it("scopes by tenantId", async () => {
|
|
455
|
-
const entry = makeEntry({ tenantId: "tenant-x" });
|
|
456
|
-
await adapter.store(entry);
|
|
457
|
-
// Delete with wrong tenant should not remove
|
|
458
|
-
const result = await adapter.delete(entry.id, "tenant-y");
|
|
459
|
-
expect(result.ok).toBe(true);
|
|
460
|
-
if (result.ok) {
|
|
461
|
-
expect(result.value).toBe(false);
|
|
462
|
-
}
|
|
463
|
-
// Entry should still exist
|
|
464
|
-
const retrieved = await adapter.retrieve(entry.id, "tenant-x");
|
|
465
|
-
expect(retrieved.ok).toBe(true);
|
|
466
|
-
if (retrieved.ok) {
|
|
467
|
-
expect(retrieved.value).toBeDefined();
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
it("removes entry from FTS5 index", async () => {
|
|
471
|
-
const entry = makeEntry({ content: "findable by keyword searchterm" });
|
|
472
|
-
await adapter.store(entry);
|
|
473
|
-
// Verify it's searchable
|
|
474
|
-
const before = await adapter.search(testSessionKey, "searchterm");
|
|
475
|
-
expect(before.ok).toBe(true);
|
|
476
|
-
if (before.ok) {
|
|
477
|
-
expect(before.value.length).toBe(1);
|
|
478
|
-
}
|
|
479
|
-
await adapter.delete(entry.id);
|
|
480
|
-
// Should no longer be searchable
|
|
481
|
-
const after = await adapter.search(testSessionKey, "searchterm");
|
|
482
|
-
expect(after.ok).toBe(true);
|
|
483
|
-
if (after.ok) {
|
|
484
|
-
expect(after.value.length).toBe(0);
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
it("removes entry from vec_memories when vec is available", async () => {
|
|
488
|
-
if (!isVecAvailable())
|
|
489
|
-
return;
|
|
490
|
-
const entry = makeEntry({ embedding: [0.5, 0.5, 0.5, 0.5] });
|
|
491
|
-
await adapter.store(entry);
|
|
492
|
-
await adapter.delete(entry.id);
|
|
493
|
-
// Check vec_memories directly
|
|
494
|
-
const vecRow = adapter
|
|
495
|
-
.getDb()
|
|
496
|
-
.prepare("SELECT * FROM vec_memories WHERE memory_id = ?")
|
|
497
|
-
.get(entry.id);
|
|
498
|
-
expect(vecRow).toBeUndefined();
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
// ── clear ──────────────────────────────────────────────────────
|
|
502
|
-
describe("clear", () => {
|
|
503
|
-
it("removes all entries for the tenant", async () => {
|
|
504
|
-
await adapter.store(makeEntry({ content: "entry one" }));
|
|
505
|
-
await adapter.store(makeEntry({ content: "entry two" }));
|
|
506
|
-
await adapter.store(makeEntry({ content: "entry three" }));
|
|
507
|
-
const result = await adapter.clear(testSessionKey);
|
|
508
|
-
expect(result.ok).toBe(true);
|
|
509
|
-
if (result.ok) {
|
|
510
|
-
expect(result.value).toBe(3);
|
|
511
|
-
}
|
|
512
|
-
// Verify all gone
|
|
513
|
-
const search = await adapter.search(testSessionKey, "entry");
|
|
514
|
-
expect(search.ok).toBe(true);
|
|
515
|
-
if (search.ok) {
|
|
516
|
-
expect(search.value).toHaveLength(0);
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
it("only clears entries for the specified tenant", async () => {
|
|
520
|
-
await adapter.store(makeEntry({ tenantId: "tenant-a", content: "keep this cat" }));
|
|
521
|
-
await adapter.store(makeEntry({ tenantId: "tenant-b", content: "delete this cat" }));
|
|
522
|
-
const sessionB = {
|
|
523
|
-
tenantId: "tenant-b",
|
|
524
|
-
userId: "user-1",
|
|
525
|
-
channelId: "test",
|
|
526
|
-
};
|
|
527
|
-
const result = await adapter.clear(sessionB);
|
|
528
|
-
expect(result.ok).toBe(true);
|
|
529
|
-
if (result.ok) {
|
|
530
|
-
expect(result.value).toBe(1);
|
|
531
|
-
}
|
|
532
|
-
// Tenant A entry should remain
|
|
533
|
-
const sessionA = {
|
|
534
|
-
tenantId: "tenant-a",
|
|
535
|
-
userId: "user-1",
|
|
536
|
-
channelId: "test",
|
|
537
|
-
};
|
|
538
|
-
const search = await adapter.search(sessionA, "cat");
|
|
539
|
-
expect(search.ok).toBe(true);
|
|
540
|
-
if (search.ok) {
|
|
541
|
-
expect(search.value).toHaveLength(1);
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
it("returns 0 when no entries exist", async () => {
|
|
545
|
-
const result = await adapter.clear(testSessionKey);
|
|
546
|
-
expect(result.ok).toBe(true);
|
|
547
|
-
if (result.ok) {
|
|
548
|
-
expect(result.value).toBe(0);
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
});
|
|
552
|
-
// ── multi-agent memory isolation ─────────────────────────────
|
|
553
|
-
describe("multi-agent memory isolation", () => {
|
|
554
|
-
it("stores and retrieves memory with agentId", async () => {
|
|
555
|
-
const e1 = makeEntry({ agentId: "coder", content: "coder memory about compilers" });
|
|
556
|
-
const e2 = makeEntry({ agentId: "dash", content: "dash memory about dashboards" });
|
|
557
|
-
await adapter.store(e1);
|
|
558
|
-
await adapter.store(e2);
|
|
559
|
-
const coderResults = await adapter.search(testSessionKey, "memory", {
|
|
560
|
-
agentId: "coder",
|
|
561
|
-
});
|
|
562
|
-
expect(coderResults.ok).toBe(true);
|
|
563
|
-
if (coderResults.ok) {
|
|
564
|
-
expect(coderResults.value.length).toBe(1);
|
|
565
|
-
expect(coderResults.value[0].entry.content).toContain("compilers");
|
|
566
|
-
expect(coderResults.value[0].entry.agentId).toBe("coder");
|
|
567
|
-
}
|
|
568
|
-
const dashResults = await adapter.search(testSessionKey, "memory", {
|
|
569
|
-
agentId: "dash",
|
|
570
|
-
});
|
|
571
|
-
expect(dashResults.ok).toBe(true);
|
|
572
|
-
if (dashResults.ok) {
|
|
573
|
-
expect(dashResults.value.length).toBe(1);
|
|
574
|
-
expect(dashResults.value[0].entry.content).toContain("dashboards");
|
|
575
|
-
expect(dashResults.value[0].entry.agentId).toBe("dash");
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
it("agentId defaults to 'default' when not specified", async () => {
|
|
579
|
-
const entry = makeEntry({ content: "default agent memory content" });
|
|
580
|
-
await adapter.store(entry);
|
|
581
|
-
// Check raw DB to verify agent_id column
|
|
582
|
-
const row = adapter
|
|
583
|
-
.getDb()
|
|
584
|
-
.prepare("SELECT agent_id FROM memories WHERE id = ?")
|
|
585
|
-
.get(entry.id);
|
|
586
|
-
expect(row.agent_id).toBe("default");
|
|
587
|
-
// Also verify via retrieve
|
|
588
|
-
const result = await adapter.retrieve(entry.id);
|
|
589
|
-
expect(result.ok).toBe(true);
|
|
590
|
-
if (result.ok && result.value) {
|
|
591
|
-
expect(result.value.agentId).toBe("default");
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
it("search without agentId returns all agents' memories", async () => {
|
|
595
|
-
await adapter.store(makeEntry({ agentId: "agent-a", content: "agent alpha cucumber data" }));
|
|
596
|
-
await adapter.store(makeEntry({ agentId: "agent-b", content: "agent bravo cucumber data" }));
|
|
597
|
-
await adapter.store(makeEntry({ agentId: "default", content: "default agent cucumber data" }));
|
|
598
|
-
// Search without agentId filter should return all
|
|
599
|
-
const results = await adapter.search(testSessionKey, "cucumber");
|
|
600
|
-
expect(results.ok).toBe(true);
|
|
601
|
-
if (results.ok) {
|
|
602
|
-
expect(results.value.length).toBe(3);
|
|
603
|
-
}
|
|
604
|
-
});
|
|
605
|
-
});
|
|
606
|
-
// ── hybrid search tenant isolation (DATA-01) ──────────────────
|
|
607
|
-
describe("hybrid search tenant isolation", () => {
|
|
608
|
-
it("hybrid/text search row fetch filters by tenant_id", async () => {
|
|
609
|
-
// Create entries for two tenants with matching FTS content
|
|
610
|
-
await adapter.store(makeEntry({
|
|
611
|
-
tenantId: "tenant-alpha",
|
|
612
|
-
content: "secret recipe for pancakes",
|
|
613
|
-
}));
|
|
614
|
-
await adapter.store(makeEntry({
|
|
615
|
-
tenantId: "tenant-beta",
|
|
616
|
-
content: "secret recipe for waffles",
|
|
617
|
-
}));
|
|
618
|
-
// Search as tenant-alpha
|
|
619
|
-
const sessionA = {
|
|
620
|
-
tenantId: "tenant-alpha",
|
|
621
|
-
userId: "user-1",
|
|
622
|
-
channelId: "test",
|
|
623
|
-
};
|
|
624
|
-
const results = await adapter.search(sessionA, "recipe");
|
|
625
|
-
expect(results.ok).toBe(true);
|
|
626
|
-
if (results.ok) {
|
|
627
|
-
// Should only see tenant-alpha's entry, not tenant-beta's
|
|
628
|
-
expect(results.value.length).toBe(1);
|
|
629
|
-
expect(results.value[0].entry.content).toBe("secret recipe for pancakes");
|
|
630
|
-
expect(results.value[0].entry.tenantId).toBe("tenant-alpha");
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
it("hybrid search returns empty for tenant with no matching entries", async () => {
|
|
634
|
-
await adapter.store(makeEntry({
|
|
635
|
-
tenantId: "tenant-x",
|
|
636
|
-
content: "unique keyword xylophone",
|
|
637
|
-
}));
|
|
638
|
-
const sessionY = {
|
|
639
|
-
tenantId: "tenant-y",
|
|
640
|
-
userId: "user-1",
|
|
641
|
-
channelId: "test",
|
|
642
|
-
};
|
|
643
|
-
const results = await adapter.search(sessionY, "xylophone");
|
|
644
|
-
expect(results.ok).toBe(true);
|
|
645
|
-
if (results.ok) {
|
|
646
|
-
expect(results.value.length).toBe(0);
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
});
|
|
650
|
-
// ── DATA-06: expiry filtering ──────────────────────────────────
|
|
651
|
-
describe("expiry filtering", () => {
|
|
652
|
-
it("retrieve returns undefined for expired entry", async () => {
|
|
653
|
-
const entry = makeEntry({ expiresAt: Date.now() - 1000 }); // expired 1s ago
|
|
654
|
-
await adapter.store(entry);
|
|
655
|
-
const result = await adapter.retrieve(entry.id);
|
|
656
|
-
expect(result.ok).toBe(true);
|
|
657
|
-
if (result.ok) {
|
|
658
|
-
expect(result.value).toBeUndefined();
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
it("retrieve returns entry with future expiresAt", async () => {
|
|
662
|
-
const entry = makeEntry({ expiresAt: Date.now() + 60000 }); // expires in 60s
|
|
663
|
-
await adapter.store(entry);
|
|
664
|
-
const result = await adapter.retrieve(entry.id);
|
|
665
|
-
expect(result.ok).toBe(true);
|
|
666
|
-
if (result.ok) {
|
|
667
|
-
expect(result.value).toBeDefined();
|
|
668
|
-
expect(result.value.id).toBe(entry.id);
|
|
669
|
-
}
|
|
670
|
-
});
|
|
671
|
-
it("retrieve returns entry with null expiresAt (no expiry)", async () => {
|
|
672
|
-
const entry = makeEntry(); // no expiresAt
|
|
673
|
-
await adapter.store(entry);
|
|
674
|
-
const result = await adapter.retrieve(entry.id);
|
|
675
|
-
expect(result.ok).toBe(true);
|
|
676
|
-
if (result.ok) {
|
|
677
|
-
expect(result.value).toBeDefined();
|
|
678
|
-
expect(result.value.id).toBe(entry.id);
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
it("search excludes expired entries from text results", async () => {
|
|
682
|
-
await adapter.store(makeEntry({ content: "expired banana fact", expiresAt: Date.now() - 1000 }));
|
|
683
|
-
await adapter.store(makeEntry({ content: "fresh banana fact", expiresAt: Date.now() + 60000 }));
|
|
684
|
-
const result = await adapter.search(testSessionKey, "banana");
|
|
685
|
-
expect(result.ok).toBe(true);
|
|
686
|
-
if (result.ok) {
|
|
687
|
-
expect(result.value.length).toBe(1);
|
|
688
|
-
expect(result.value[0].entry.content).toBe("fresh banana fact");
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
it("search excludes expired entries from vector results", async () => {
|
|
692
|
-
if (!isVecAvailable())
|
|
693
|
-
return;
|
|
694
|
-
const expired = makeEntry({
|
|
695
|
-
content: "expired vec entry",
|
|
696
|
-
embedding: [1, 0, 0, 0],
|
|
697
|
-
expiresAt: Date.now() - 1000,
|
|
698
|
-
});
|
|
699
|
-
const fresh = makeEntry({
|
|
700
|
-
content: "fresh vec entry",
|
|
701
|
-
embedding: [0.9, 0.1, 0, 0],
|
|
702
|
-
expiresAt: Date.now() + 60000,
|
|
703
|
-
});
|
|
704
|
-
await adapter.store(expired);
|
|
705
|
-
await adapter.store(fresh);
|
|
706
|
-
const result = await adapter.search(testSessionKey, [1, 0, 0, 0], { limit: 10 });
|
|
707
|
-
expect(result.ok).toBe(true);
|
|
708
|
-
if (result.ok) {
|
|
709
|
-
// Only the fresh entry should appear
|
|
710
|
-
expect(result.value.length).toBe(1);
|
|
711
|
-
expect(result.value[0].entry.content).toBe("fresh vec entry");
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
// ── edge cases ─────────────────────────────────────────────────
|
|
716
|
-
describe("edge cases", () => {
|
|
717
|
-
it("handles embedding dimension mismatch at runtime", async () => {
|
|
718
|
-
if (!isVecAvailable())
|
|
719
|
-
return;
|
|
720
|
-
// Adapter is initialized with embeddingDimensions: 4 (testConfig)
|
|
721
|
-
// Attempt to store an entry with an 8-dimensional embedding
|
|
722
|
-
const entry = makeEntry({
|
|
723
|
-
embedding: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
|
|
724
|
-
});
|
|
725
|
-
const result = await adapter.store(entry);
|
|
726
|
-
// sqlite-vec throws a dimension mismatch error, which the adapter
|
|
727
|
-
// catches and returns as err() (not an unhandled crash)
|
|
728
|
-
expect(result.ok).toBe(false);
|
|
729
|
-
if (!result.ok) {
|
|
730
|
-
expect(result.error.message).toContain("Dimension mismatch");
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
it("handles database error when DB is closed", async () => {
|
|
734
|
-
// Close the underlying DB directly
|
|
735
|
-
adapter.getDb().close();
|
|
736
|
-
// Attempt to store -- should return err(), not crash
|
|
737
|
-
const entry = makeEntry();
|
|
738
|
-
const storeResult = await adapter.store(entry);
|
|
739
|
-
expect(storeResult.ok).toBe(false);
|
|
740
|
-
if (!storeResult.ok) {
|
|
741
|
-
expect(storeResult.error.message).toContain("not open");
|
|
742
|
-
}
|
|
743
|
-
// Attempt to retrieve -- should return err(), not crash
|
|
744
|
-
const retrieveResult = await adapter.retrieve("any-id");
|
|
745
|
-
expect(retrieveResult.ok).toBe(false);
|
|
746
|
-
if (!retrieveResult.ok) {
|
|
747
|
-
expect(retrieveResult.error.message).toContain("not open");
|
|
748
|
-
}
|
|
749
|
-
// Attempt to search -- should return err(), not crash
|
|
750
|
-
const searchResult = await adapter.search(testSessionKey, "test");
|
|
751
|
-
expect(searchResult.ok).toBe(false);
|
|
752
|
-
if (!searchResult.ok) {
|
|
753
|
-
expect(searchResult.error.message).toContain("not open");
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
it("creates parent directory automatically for non-existent path", () => {
|
|
757
|
-
const badPath = `/tmp/comis-nonexist-${Date.now()}/test.db`;
|
|
758
|
-
const { rmSync, existsSync } = require("node:fs");
|
|
759
|
-
const parentDir = badPath.substring(0, badPath.lastIndexOf("/"));
|
|
760
|
-
// openSqliteDatabase creates the parent directory automatically
|
|
761
|
-
const tempAdapter = new SqliteMemoryAdapter({ ...testConfig, dbPath: badPath });
|
|
762
|
-
try {
|
|
763
|
-
expect(existsSync(parentDir)).toBe(true);
|
|
764
|
-
}
|
|
765
|
-
finally {
|
|
766
|
-
tempAdapter.close();
|
|
767
|
-
rmSync(parentDir, { recursive: true, force: true });
|
|
768
|
-
}
|
|
769
|
-
});
|
|
770
|
-
});
|
|
771
|
-
// ── close ──────────────────────────────────────────────────────
|
|
772
|
-
describe("close", () => {
|
|
773
|
-
it("closes the database connection without error", () => {
|
|
774
|
-
const tempAdapter = new SqliteMemoryAdapter(testConfig);
|
|
775
|
-
expect(() => tempAdapter.close()).not.toThrow();
|
|
776
|
-
});
|
|
777
|
-
});
|
|
778
|
-
// ── logging ─────────────────────────────────────────────────────
|
|
779
|
-
describe("logging", () => {
|
|
780
|
-
it("logs database open at DEBUG", () => {
|
|
781
|
-
const mockLogger = { info: vi.fn(), warn: vi.fn(), debug: vi.fn() };
|
|
782
|
-
const loggedAdapter = new SqliteMemoryAdapter(testConfig, undefined, mockLogger);
|
|
783
|
-
expect(mockLogger.debug).toHaveBeenCalledWith(expect.objectContaining({ dbPath: expect.any(String) }), "Memory database opened");
|
|
784
|
-
loggedAdapter.close();
|
|
785
|
-
});
|
|
786
|
-
it("logs search queries at DEBUG with durationMs", async () => {
|
|
787
|
-
const mockLogger = { info: vi.fn(), warn: vi.fn(), debug: vi.fn() };
|
|
788
|
-
const loggedAdapter = new SqliteMemoryAdapter(testConfig, undefined, mockLogger);
|
|
789
|
-
try {
|
|
790
|
-
await loggedAdapter.store(makeEntry({ content: "searchable content" }));
|
|
791
|
-
await loggedAdapter.search(testSessionKey, "searchable");
|
|
792
|
-
expect(mockLogger.debug).toHaveBeenCalledWith(expect.objectContaining({ durationMs: expect.any(Number), op: "search" }), "Memory search complete");
|
|
793
|
-
}
|
|
794
|
-
finally {
|
|
795
|
-
loggedAdapter.close();
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
});
|
|
799
|
-
// ── PERM-04: file permission hardening ──────────────────────────
|
|
800
|
-
describe("file permission hardening (PERM-04)", () => {
|
|
801
|
-
it("applies 0o600 chmod to file-based database", () => {
|
|
802
|
-
const tmpDir = `/tmp/comis-test-perm-${Date.now()}`;
|
|
803
|
-
const { mkdirSync } = require("node:fs");
|
|
804
|
-
mkdirSync(tmpDir, { recursive: true });
|
|
805
|
-
const dbPath = `${tmpDir}/test-perms.db`;
|
|
806
|
-
const fileAdapter = new SqliteMemoryAdapter({
|
|
807
|
-
...testConfig,
|
|
808
|
-
dbPath,
|
|
809
|
-
walMode: true,
|
|
810
|
-
});
|
|
811
|
-
try {
|
|
812
|
-
// Verify the DB file has 0o600 permissions
|
|
813
|
-
const { statSync } = require("node:fs");
|
|
814
|
-
const stats = statSync(dbPath);
|
|
815
|
-
const mode = stats.mode & 0o777;
|
|
816
|
-
expect(mode).toBe(0o600);
|
|
817
|
-
}
|
|
818
|
-
finally {
|
|
819
|
-
fileAdapter.close();
|
|
820
|
-
// Clean up
|
|
821
|
-
const { rmSync } = require("node:fs");
|
|
822
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
823
|
-
}
|
|
824
|
-
});
|
|
825
|
-
it("does not call chmodSync for :memory: databases", () => {
|
|
826
|
-
// Verify source code skips chmod for in-memory DBs via static analysis.
|
|
827
|
-
// The guard is now in the shared sqlite-adapter-base.ts utility.
|
|
828
|
-
const fs = require("node:fs");
|
|
829
|
-
const url = require("node:url");
|
|
830
|
-
const sourcePath = url.fileURLToPath(new URL("./sqlite-adapter-base.ts", import.meta.url));
|
|
831
|
-
const source = fs.readFileSync(sourcePath, "utf-8");
|
|
832
|
-
// The guard condition should check for :memory:
|
|
833
|
-
expect(source).toContain('dbPath !== ":memory:"');
|
|
834
|
-
});
|
|
835
|
-
it("handles chmod failure gracefully (best-effort)", () => {
|
|
836
|
-
// The adapter constructor wraps chmod in try/catch, so creating
|
|
837
|
-
// an in-memory adapter should work without any chmod issues
|
|
838
|
-
const memAdapter = new SqliteMemoryAdapter(testConfig);
|
|
839
|
-
expect(memAdapter).toBeDefined();
|
|
840
|
-
memAdapter.close();
|
|
841
|
-
});
|
|
842
|
-
it("applies chmod to WAL/SHM companions when they exist", () => {
|
|
843
|
-
const tmpDir = `/tmp/comis-test-wal-${Date.now()}`;
|
|
844
|
-
const { mkdirSync: mkDir, statSync: stat, rmSync: rm } = require("node:fs");
|
|
845
|
-
mkDir(tmpDir, { recursive: true });
|
|
846
|
-
const dbPath = `${tmpDir}/test-wal.db`;
|
|
847
|
-
// Create adapter with WAL mode to generate WAL/SHM files
|
|
848
|
-
const walAdapter = new SqliteMemoryAdapter({
|
|
849
|
-
...testConfig,
|
|
850
|
-
dbPath,
|
|
851
|
-
walMode: true,
|
|
852
|
-
});
|
|
853
|
-
try {
|
|
854
|
-
// Force a write to trigger WAL file creation
|
|
855
|
-
walAdapter.getDb().prepare("CREATE TABLE IF NOT EXISTS perm_test (id TEXT)").run();
|
|
856
|
-
walAdapter.getDb().prepare("INSERT INTO perm_test VALUES ('x')").run();
|
|
857
|
-
// WAL file should exist after write (WAL mode)
|
|
858
|
-
const walPath = dbPath + "-wal";
|
|
859
|
-
if (existsSync(walPath)) {
|
|
860
|
-
// Re-create adapter to trigger chmod on WAL/SHM
|
|
861
|
-
walAdapter.close();
|
|
862
|
-
const walAdapter2 = new SqliteMemoryAdapter({
|
|
863
|
-
...testConfig,
|
|
864
|
-
dbPath,
|
|
865
|
-
walMode: true,
|
|
866
|
-
});
|
|
867
|
-
try {
|
|
868
|
-
if (existsSync(walPath)) {
|
|
869
|
-
const walStats = stat(walPath);
|
|
870
|
-
const walMode = walStats.mode & 0o777;
|
|
871
|
-
expect(walMode).toBe(0o600);
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
finally {
|
|
875
|
-
walAdapter2.close();
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
finally {
|
|
880
|
-
try {
|
|
881
|
-
walAdapter.close();
|
|
882
|
-
}
|
|
883
|
-
catch { /* already closed */ }
|
|
884
|
-
rm(tmpDir, { recursive: true, force: true });
|
|
885
|
-
}
|
|
886
|
-
});
|
|
887
|
-
});
|
|
888
|
-
});
|