recallnest 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +222 -254
  3. package/README_CN.md +206 -243
  4. package/package.json +3 -2
  5. package/src/capture-engine.ts +26 -4
  6. package/src/context-composer-stable.ts +5 -1
  7. package/src/embedder.ts +24 -0
  8. package/src/env-config.ts +18 -0
  9. package/src/ingest.ts +225 -17
  10. package/src/kg-extractor.ts +17 -0
  11. package/src/memory-output.ts +35 -0
  12. package/src/pivot-apply.ts +52 -1
  13. package/src/pivot-evidence.ts +128 -0
  14. package/src/ppr-traversal.ts +25 -1
  15. package/src/runtime-config.ts +9 -0
  16. package/src/session-engine.ts +11 -4
  17. package/src/session-output.ts +9 -1
  18. package/src/session-store.ts +2 -3
  19. package/src/skill-promotion.ts +67 -1
  20. package/src/__tests__/access-tracker-novelty.test.ts +0 -324
  21. package/src/__tests__/activity-counter.test.ts +0 -125
  22. package/src/__tests__/adaptive-fidelity.test.ts +0 -102
  23. package/src/__tests__/admission-control.test.ts +0 -206
  24. package/src/__tests__/age-label.test.ts +0 -33
  25. package/src/__tests__/anchor-generator.test.ts +0 -67
  26. package/src/__tests__/api-server-security.test.ts +0 -102
  27. package/src/__tests__/auto-consolidation.test.ts +0 -168
  28. package/src/__tests__/auto-recall.test.ts +0 -131
  29. package/src/__tests__/babel-integration.test.ts +0 -144
  30. package/src/__tests__/batch-dedup.test.ts +0 -65
  31. package/src/__tests__/belief-history.test.ts +0 -220
  32. package/src/__tests__/canary-eval.test.ts +0 -114
  33. package/src/__tests__/capture-engine.test.ts +0 -1328
  34. package/src/__tests__/capture-heuristic.test.ts +0 -171
  35. package/src/__tests__/cascade-forget.test.ts +0 -210
  36. package/src/__tests__/category-min-scores.test.ts +0 -116
  37. package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
  38. package/src/__tests__/circuit-breaker.test.ts +0 -99
  39. package/src/__tests__/cluster-consolidation.test.ts +0 -1236
  40. package/src/__tests__/confidence-metadata.test.ts +0 -125
  41. package/src/__tests__/confidence-tracker.test.ts +0 -261
  42. package/src/__tests__/conflict-advisor.test.ts +0 -206
  43. package/src/__tests__/conflict-escalation.test.ts +0 -149
  44. package/src/__tests__/conflict-lifecycle.test.ts +0 -83
  45. package/src/__tests__/conflict-output.test.ts +0 -85
  46. package/src/__tests__/conflict-store.test.ts +0 -418
  47. package/src/__tests__/connector-v1.test.ts +0 -181
  48. package/src/__tests__/consolidation-engine.test.ts +0 -520
  49. package/src/__tests__/constructive-retrieval.test.ts +0 -509
  50. package/src/__tests__/context-collapse-renderer.test.ts +0 -214
  51. package/src/__tests__/context-composer-pins.test.ts +0 -64
  52. package/src/__tests__/context-composer-task-selection.test.ts +0 -24
  53. package/src/__tests__/context-reconstructor.test.ts +0 -65
  54. package/src/__tests__/context-renderer.test.ts +0 -91
  55. package/src/__tests__/continuity-eval.test.ts +0 -275
  56. package/src/__tests__/continuity-schema.test.ts +0 -97
  57. package/src/__tests__/contracts.test.ts +0 -262
  58. package/src/__tests__/conversation-importer.test.ts +0 -692
  59. package/src/__tests__/core-recall-eval.test.ts +0 -235
  60. package/src/__tests__/core-summary.test.ts +0 -109
  61. package/src/__tests__/data-checkup.test.ts +0 -304
  62. package/src/__tests__/decay-exemption.test.ts +0 -129
  63. package/src/__tests__/dedup-actions.test.ts +0 -58
  64. package/src/__tests__/dedup-guard.test.ts +0 -39
  65. package/src/__tests__/deterministic-id.test.ts +0 -39
  66. package/src/__tests__/distill-lock.test.ts +0 -305
  67. package/src/__tests__/distill-session-argshape.test.ts +0 -79
  68. package/src/__tests__/doctor.test.ts +0 -319
  69. package/src/__tests__/dream-pipeline.test.ts +0 -820
  70. package/src/__tests__/dream-scope-isolation.test.ts +0 -386
  71. package/src/__tests__/dream-write-batching.test.ts +0 -211
  72. package/src/__tests__/drill-down.test.ts +0 -108
  73. package/src/__tests__/embedder.test.ts +0 -122
  74. package/src/__tests__/emotion-decay.test.ts +0 -46
  75. package/src/__tests__/emotion-detector.test.ts +0 -56
  76. package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
  77. package/src/__tests__/emotion-retrieval.test.ts +0 -56
  78. package/src/__tests__/entity-resolver.test.ts +0 -58
  79. package/src/__tests__/env-config-invariant.test.ts +0 -80
  80. package/src/__tests__/env-config.test.ts +0 -211
  81. package/src/__tests__/error-signature-boost.test.ts +0 -87
  82. package/src/__tests__/error-signature.test.ts +0 -95
  83. package/src/__tests__/error-taxonomy.test.ts +0 -129
  84. package/src/__tests__/ethics-layer.test.ts +0 -476
  85. package/src/__tests__/event-segmenter.test.ts +0 -153
  86. package/src/__tests__/feature-flags-integration.test.ts +0 -54
  87. package/src/__tests__/frequency-tracker.test.ts +0 -113
  88. package/src/__tests__/freshness.test.ts +0 -186
  89. package/src/__tests__/graph-export.test.ts +0 -489
  90. package/src/__tests__/hotness-blend.test.ts +0 -283
  91. package/src/__tests__/ingest-chunking.test.ts +0 -44
  92. package/src/__tests__/ingest-scope-prefix.test.ts +0 -69
  93. package/src/__tests__/ingest.test.ts +0 -360
  94. package/src/__tests__/interference-detector.test.ts +0 -203
  95. package/src/__tests__/kg-extractor.test.ts +0 -192
  96. package/src/__tests__/kg-store.test.ts +0 -300
  97. package/src/__tests__/llm-client-pivot.test.ts +0 -628
  98. package/src/__tests__/llm-consolidation.test.ts +0 -226
  99. package/src/__tests__/maintenance-locks.test.ts +0 -197
  100. package/src/__tests__/mcp-efficiency.test.ts +0 -288
  101. package/src/__tests__/mcp-related-scopes.test.ts +0 -151
  102. package/src/__tests__/memory-boundaries.test.ts +0 -282
  103. package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -362
  104. package/src/__tests__/memory-evolution.test.ts +0 -271
  105. package/src/__tests__/memory-health-rebalance.test.ts +0 -144
  106. package/src/__tests__/memory-lint.test.ts +0 -421
  107. package/src/__tests__/memory-output.test.ts +0 -224
  108. package/src/__tests__/memory-promotion.test.ts +0 -315
  109. package/src/__tests__/memory-utility.test.ts +0 -256
  110. package/src/__tests__/migrate-dedup-ids.test.ts +0 -65
  111. package/src/__tests__/multi-vector.test.ts +0 -242
  112. package/src/__tests__/narrative-architecture.test.ts +0 -456
  113. package/src/__tests__/noise-filter.test.ts +0 -205
  114. package/src/__tests__/noise-prototype-bank.test.ts +0 -280
  115. package/src/__tests__/obsidian-connector.test.ts +0 -363
  116. package/src/__tests__/omitted-reporting.test.ts +0 -98
  117. package/src/__tests__/openai-contract.test.ts +0 -513
  118. package/src/__tests__/pending-review.test.ts +0 -77
  119. package/src/__tests__/pii-redact.test.ts +0 -333
  120. package/src/__tests__/pivot-apply.test.ts +0 -373
  121. package/src/__tests__/pivot-distill-supervisor.test.ts +0 -457
  122. package/src/__tests__/pivot-distill.test.ts +0 -1178
  123. package/src/__tests__/post-retrieval-filter.test.ts +0 -178
  124. package/src/__tests__/ppr-traversal.test.ts +0 -256
  125. package/src/__tests__/prediction-engine.test.ts +0 -349
  126. package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
  127. package/src/__tests__/preference-guard-smoke.test.ts +0 -211
  128. package/src/__tests__/preference-matcher.test.ts +0 -282
  129. package/src/__tests__/preference-slots.test.ts +0 -205
  130. package/src/__tests__/promotion-distinct-sources.test.ts +0 -162
  131. package/src/__tests__/prospective-memory.test.ts +0 -283
  132. package/src/__tests__/pull-from-macbook-sync-only.test.ts +0 -679
  133. package/src/__tests__/query-entity-detector.test.ts +0 -171
  134. package/src/__tests__/query-expander-alias.test.ts +0 -146
  135. package/src/__tests__/query-expander.test.ts +0 -34
  136. package/src/__tests__/recall-gate.test.ts +0 -266
  137. package/src/__tests__/recall-governor.test.ts +0 -227
  138. package/src/__tests__/recall-mode.test.ts +0 -64
  139. package/src/__tests__/resolve-db-path.test.ts +0 -130
  140. package/src/__tests__/resolve-tier.test.ts +0 -64
  141. package/src/__tests__/result-synthesizer.test.ts +0 -198
  142. package/src/__tests__/resume-context.test.ts +0 -4898
  143. package/src/__tests__/retrieval-eval.test.ts +0 -163
  144. package/src/__tests__/retrieval-trace.test.ts +0 -213
  145. package/src/__tests__/retrieve-audit-revision.test.ts +0 -255
  146. package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
  147. package/src/__tests__/retriever-lazy-init-dispatch.test.ts +0 -123
  148. package/src/__tests__/retroactive-boost.test.ts +0 -223
  149. package/src/__tests__/salience-scoring.test.ts +0 -106
  150. package/src/__tests__/scope-inventory.test.ts +0 -200
  151. package/src/__tests__/scope-policy.test.ts +0 -69
  152. package/src/__tests__/scope-suggester.test.ts +0 -80
  153. package/src/__tests__/session-checkpoint.test.ts +0 -291
  154. package/src/__tests__/session-distiller.test.ts +0 -640
  155. package/src/__tests__/session-gc.test.ts +0 -215
  156. package/src/__tests__/skill-engine.test.ts +0 -552
  157. package/src/__tests__/skill-promotion.test.ts +0 -654
  158. package/src/__tests__/skill-verifier.test.ts +0 -122
  159. package/src/__tests__/source-heartbeat.test.ts +0 -254
  160. package/src/__tests__/stable-context-length-contract.test.ts +0 -62
  161. package/src/__tests__/store-patch-metadata.test.ts +0 -235
  162. package/src/__tests__/store-read-consistency.test.ts +0 -122
  163. package/src/__tests__/store-schema-migration.test.ts +0 -87
  164. package/src/__tests__/store-scope-audit.test.ts +0 -81
  165. package/src/__tests__/store-upsert.test.ts +0 -201
  166. package/src/__tests__/supersede-chain.test.ts +0 -154
  167. package/src/__tests__/synthesis-contract.test.ts +0 -252
  168. package/src/__tests__/synthesis-promotion.test.ts +0 -369
  169. package/src/__tests__/temporal-parser.test.ts +0 -241
  170. package/src/__tests__/temporal-validity.test.ts +0 -160
  171. package/src/__tests__/term-registry-terminal-roster.test.ts +0 -127
  172. package/src/__tests__/term-registry.test.ts +0 -121
  173. package/src/__tests__/tool-error-surfacing.test.ts +0 -98
  174. package/src/__tests__/tool-output-compressor.test.ts +0 -160
  175. package/src/__tests__/topic-tag.test.ts +0 -113
  176. package/src/__tests__/trusted-memory.test.ts +0 -867
  177. package/src/__tests__/ui-server-security.test.ts +0 -93
  178. package/src/__tests__/usage-tracker.test.ts +0 -287
  179. package/src/__tests__/utility-weight.test.ts +0 -57
  180. package/src/__tests__/verbatim-self-recall.test.ts +0 -279
  181. package/src/__tests__/version-manager.test.ts +0 -248
  182. package/src/__tests__/workflow-observation-skill-outcome.test.ts +0 -352
  183. package/src/__tests__/workflow-observation.test.ts +0 -433
  184. package/src/__tests__/write-verifier.test.ts +0 -122
@@ -1,333 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
-
3
- import { redactSecrets, redactForLog, scanForPII } from "../pii-detector.js";
4
- import { persistMemory } from "../capture-engine.js";
5
- import type { AuditEntry } from "../audit-log.js";
6
-
7
- const TEST_SCOPE = "project:test";
8
-
9
- // ============================================================================
10
- // redactSecrets — rule coverage
11
- // ============================================================================
12
-
13
- describe("redactSecrets", () => {
14
- it("scrubs Anthropic API keys with the specific type", () => {
15
- const r = redactSecrets("my key is sk-ant-api03-AbCdEf12345678 ok");
16
- expect(r.text).toBe("my key is [REDACTED:anthropic_key] ok");
17
- expect(r.redacted).toBe(1);
18
- });
19
-
20
- it("does not scrub the sk tail of hyphenated slugs (task-, risk-)", () => {
21
- for (const slug of [
22
- "pivot-decision-task-assignment-worker-stability-fix",
23
- "pivot-judgment-shift-risk-gated-review-decision-process",
24
- "note about task-ant-colony-simulation-experiment-log",
25
- ]) {
26
- const r = redactSecrets(slug);
27
- expect(r.redacted).toBe(0);
28
- expect(r.text).toBe(slug);
29
- }
30
- });
31
-
32
- it("still scrubs sk- keys that start their own token", () => {
33
- const quoted = redactSecrets('key="sk-AbCdEfGhIjKlMnOpQrStUvWx1234"');
34
- expect(quoted.redacted).toBe(1);
35
- const lineStart = redactSecrets("sk-AbCdEfGhIjKlMnOpQrStUvWx1234 trailing");
36
- expect(lineStart.redacted).toBe(1);
37
- });
38
-
39
- it("scrubs GitHub tokens", () => {
40
- const r = redactSecrets("push with ghp_ABCDEFGHIJKLMNOPQRSTUV1234567890");
41
- expect(r.text).toContain("[REDACTED:github_token]");
42
- expect(r.text).not.toContain("ghp_");
43
- });
44
-
45
- it("scrubs Slack tokens", () => {
46
- const r = redactSecrets("xoxb-123456789-abcdefghij is the bot token");
47
- expect(r.text).toContain("[REDACTED:slack_token]");
48
- });
49
-
50
- it("scrubs AWS access key IDs", () => {
51
- const r = redactSecrets("aws AKIAIOSFODNN7EXAMPLE used");
52
- expect(r.text).toContain("[REDACTED:aws_access_key]");
53
- expect(r.text).not.toContain("AKIA");
54
- });
55
-
56
- it("scrubs Google API keys", () => {
57
- // Real Google API keys are exactly "AIza" + 35 chars
58
- const r = redactSecrets(`key ${"AIzaSyB" + "x".repeat(32)} in config`);
59
- expect(r.text).toContain("[REDACTED:google_api_key]");
60
- });
61
-
62
- it("scrubs JWTs", () => {
63
- const jwt = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U";
64
- const r = redactSecrets(`token: bearer-less ${jwt} end`);
65
- expect(r.text).toContain("[REDACTED:jwt]");
66
- expect(r.text).not.toContain("eyJhbGci");
67
- });
68
-
69
- it("scrubs Bearer headers", () => {
70
- const r = redactSecrets("Authorization: Bearer abcdef1234567890XYZ_token");
71
- expect(r.text).toContain("[REDACTED:bearer_token]");
72
- });
73
-
74
- it("scrubs PEM private key blocks including the body", () => {
75
- const pem = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEA\nsecretbody\n-----END RSA PRIVATE KEY-----";
76
- const r = redactSecrets(`config:\n${pem}\ndone`);
77
- expect(r.text).toContain("[REDACTED:pem_private_key]");
78
- expect(r.text).not.toContain("MIIEowIBAAKCAQEA");
79
- expect(r.text).not.toContain("secretbody");
80
- });
81
-
82
- it("keeps the key name for password assignments, scrubs only the value", () => {
83
- const r = redactSecrets("db config password=SuperSecret99 in env");
84
- expect(r.text).toContain("password=[REDACTED:password]");
85
- expect(r.text).not.toContain("SuperSecret99");
86
- });
87
-
88
- it("keeps the key name for api_key/token/secret assignments", () => {
89
- const r = redactSecrets("set api_key=abcdefghij1234567890XYZAB then restart");
90
- expect(r.text).toContain("api_key=[REDACTED:api_key]");
91
- expect(r.text).not.toContain("abcdefghij1234567890XYZAB");
92
- });
93
-
94
- it("scrubs Chinese national ID numbers (checksum-valid)", () => {
95
- const r = redactSecrets("身份证 11010519491231002X 登记");
96
- expect(r.text).toContain("[REDACTED:id_number]");
97
- expect(r.text).not.toContain("11010519491231002X");
98
- });
99
-
100
- it("scrubs credit card numbers (Luhn-valid)", () => {
101
- const r = redactSecrets("card 4111 1111 1111 1111 charged");
102
- expect(r.text).toContain("[REDACTED:credit_card]");
103
- });
104
-
105
- // codex review 2026-07-10: JSON/YAML/config credential forms must be caught
106
- it("scrubs JSON-style quoted credential keys", () => {
107
- const r = redactSecrets('config: {"password": "SuperSecret99", "region": "us"}');
108
- expect(r.text).not.toContain("SuperSecret99");
109
- expect(r.text).toContain("[REDACTED:password]");
110
- });
111
-
112
- it("scrubs JSON-style quoted api_key", () => {
113
- const r = redactSecrets('{"api_key": "abcdefghij1234567890XYZAB"}');
114
- expect(r.text).not.toContain("abcdefghij1234567890XYZAB");
115
- expect(r.text).toContain("[REDACTED:api_key]");
116
- });
117
-
118
- it("scrubs YAML/config assignments with spaces around the separator", () => {
119
- const r = redactSecrets("password = SuperSecret99\nsecret : abcdefghij1234567890XYZAB");
120
- expect(r.text).not.toContain("SuperSecret99");
121
- expect(r.text).not.toContain("abcdefghij1234567890XYZAB");
122
- });
123
- });
124
-
125
- // ============================================================================
126
- // redactSecrets — false-positive guards
127
- // ============================================================================
128
-
129
- describe("redactSecrets false-positive guards", () => {
130
- it("does NOT scrub git commit hashes (40-char hex)", () => {
131
- const sha = "699bea8f3d2c1a0b9e8d7c6b5a4f3e2d1c0b9a87";
132
- const r = redactSecrets(`fixed in commit ${sha} on main`);
133
- expect(r.text).toContain(sha);
134
- expect(r.redacted).toBe(0);
135
- });
136
-
137
- it("does NOT scrub phone numbers or emails (detection-only)", () => {
138
- const r = redactSecrets("联系 13812345678 或 alice@example.com");
139
- expect(r.text).toContain("13812345678");
140
- expect(r.text).toContain("alice@example.com");
141
- expect(r.redacted).toBe(0);
142
- });
143
-
144
- // codex review 2026-07-10: broad numeric patterns must checksum before scrub
145
- it("does NOT scrub 19-digit snowflake IDs (boundary guard)", () => {
146
- const id = "1891234567890123456";
147
- const r = redactSecrets(`tweet id ${id} archived`);
148
- expect(r.text).toContain(id);
149
- expect(r.redacted).toBe(0);
150
- });
151
-
152
- it("does NOT scrub 18-digit numbers failing the ID checksum", () => {
153
- const fake = "110105194912310020"; // checksum digit wrong on purpose
154
- const r = redactSecrets(`订单号 ${fake} 已发货`);
155
- expect(r.text).toContain(fake);
156
- expect(r.redacted).toBe(0);
157
- });
158
-
159
- it("does NOT scrub 16-digit numbers failing Luhn", () => {
160
- const orderNo = "1234567890123456"; // Luhn-invalid
161
- const r = redactSecrets(`订单 ${orderNo} 状态正常`);
162
- expect(r.text).toContain(orderNo);
163
- expect(r.redacted).toBe(0);
164
- });
165
-
166
- it("leaves ordinary Chinese engineering notes untouched", () => {
167
- const text = "修复 admission 门控:noise-filter 英文 greeting 加词边界 + rejection reason 透传";
168
- const r = redactSecrets(text);
169
- expect(r.text).toBe(text);
170
- expect(r.redacted).toBe(0);
171
- });
172
-
173
- it("leaves ordinary English text untouched", () => {
174
- const text = "The dream pipeline gathers active memories and consolidates clusters.";
175
- const r = redactSecrets(text);
176
- expect(r.text).toBe(text);
177
- expect(r.redacted).toBe(0);
178
- });
179
- });
180
-
181
- // ============================================================================
182
- // redactForLog — redact-then-truncate ordering
183
- // ============================================================================
184
-
185
- describe("redactForLog", () => {
186
- it("redacts before truncating so a cut cannot leak a secret prefix", () => {
187
- // Secret starts inside the 60-char window; naive slice-then-redact would leak its head
188
- const text = "x".repeat(50) + " sk-ant-api03-SECRETSECRETSECRET tail";
189
- const logged = redactForLog(text, 60);
190
- expect(logged).not.toContain("sk-ant");
191
- expect(logged.length).toBeLessThanOrEqual(60);
192
- });
193
-
194
- it("keeps clean text as-is within the limit", () => {
195
- expect(redactForLog("short clean text", 60)).toBe("short clean text");
196
- });
197
- });
198
-
199
- // ============================================================================
200
- // scanForPII — backward compatibility
201
- // ============================================================================
202
-
203
- describe("scanForPII backward compatibility", () => {
204
- it("still detects and masks without altering behavior", () => {
205
- const result = scanForPII("password=SuperSecret99");
206
- expect(result.hasPII).toBe(true);
207
- expect(result.detections[0].type).toBe("password");
208
- // masked match must not contain the full secret
209
- expect(result.detections[0].match).not.toBe("password=SuperSecret99");
210
- });
211
-
212
- it("reports new vendor token types", () => {
213
- const result = scanForPII("sk-ant-api03-AbCdEf12345678");
214
- expect(result.hasPII).toBe(true);
215
- expect(result.detections.some((d) => d.type === "anthropic_key")).toBe(true);
216
- });
217
- });
218
-
219
- // ============================================================================
220
- // persistMemory integration — redaction reaches every surface
221
- // ============================================================================
222
-
223
- function createDeps() {
224
- const storedEntries: any[] = [];
225
- const embeddedTexts: string[] = [];
226
- const auditEntries: Array<Omit<AuditEntry, "timestamp">> = [];
227
- let seq = 1;
228
-
229
- return {
230
- storedEntries,
231
- embeddedTexts,
232
- auditEntries,
233
- deps: {
234
- embedder: {
235
- async embedPassage(text: string) {
236
- embeddedTexts.push(text);
237
- return [text.length, 1, 0];
238
- },
239
- },
240
- store: {
241
- async store(entry: any) {
242
- const stored = {
243
- ...entry,
244
- id: `00000000-0000-0000-0000-${String(seq).padStart(12, "0")}`,
245
- timestamp: 1_700_000_000_000 + seq,
246
- };
247
- seq += 1;
248
- storedEntries.push(stored);
249
- return stored;
250
- },
251
- async list() {
252
- return [];
253
- },
254
- async update() {
255
- return null;
256
- },
257
- async getById() {
258
- return null;
259
- },
260
- async get() {
261
- return null;
262
- },
263
- },
264
- auditLogger: {
265
- log(entry: Omit<AuditEntry, "timestamp">) {
266
- auditEntries.push(entry);
267
- },
268
- getRecent: () => [],
269
- exportAll: () => [],
270
- count: () => 0,
271
- },
272
- },
273
- };
274
- }
275
-
276
- describe("persistMemory redaction integration", () => {
277
- it("embeds, stores, and audit-logs the scrubbed text, never the raw secret", async () => {
278
- const h = createDeps();
279
- const result = await persistMemory(h.deps as any, {
280
- text: "部署踩坑:用了 password=SuperSecret99 连测试库,改环境变量后修复,教训是配置不进代码",
281
- category: "cases",
282
- importance: 0.9,
283
- scope: TEST_SCOPE,
284
- source: "manual",
285
- });
286
-
287
- expect(result.disposition).not.toBe("rejected");
288
- // Embedding API never saw the secret
289
- expect(h.embeddedTexts.length).toBeGreaterThan(0);
290
- for (const t of h.embeddedTexts) {
291
- expect(t).not.toContain("SuperSecret99");
292
- }
293
- // Stored text is scrubbed but keeps the key name for readability
294
- expect(h.storedEntries[0].text).toContain("password=[REDACTED:password]");
295
- expect(h.storedEntries[0].text).not.toContain("SuperSecret99");
296
- // Audit log details are scrubbed too
297
- for (const e of h.auditEntries) {
298
- expect(e.details ?? "").not.toContain("SuperSecret99");
299
- }
300
- });
301
-
302
- it("records piiWarning with redacted count in metadata", async () => {
303
- const h = createDeps();
304
- await persistMemory(h.deps as any, {
305
- text: "记录一下:测试环境 token=abcdefghij1234567890XYZAB 已经轮换过了,流程要固化下来",
306
- category: "cases",
307
- importance: 0.9,
308
- scope: TEST_SCOPE,
309
- source: "manual",
310
- });
311
-
312
- const meta = JSON.parse(h.storedEntries[0].metadata ?? "{}");
313
- expect(meta.piiWarning).toBeDefined();
314
- expect(meta.piiWarning.redacted).toBeGreaterThan(0);
315
- });
316
-
317
- it("writes a reject entry to the audit log when admission rejects", async () => {
318
- const h = createDeps();
319
- const result = await persistMemory(h.deps as any, {
320
- text: "ok", // below minTextLength → admission reject
321
- category: "cases",
322
- importance: 0.9,
323
- scope: TEST_SCOPE,
324
- source: "manual",
325
- });
326
-
327
- expect(result.disposition).toBe("rejected");
328
- const rejects = h.auditEntries.filter((e) => e.operation === "reject");
329
- expect(rejects.length).toBe(1);
330
- expect(rejects[0].scope).toBe(TEST_SCOPE);
331
- expect(rejects[0].details ?? "").toContain("ok");
332
- });
333
- });