recallnest 2.3.0 → 2.6.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.
Files changed (258) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/README.md +49 -38
  3. package/README_CN.md +46 -31
  4. package/assets/ui/app.js +1031 -0
  5. package/assets/ui/index.html +224 -0
  6. package/assets/ui/styles.css +781 -0
  7. package/config.json.example +4 -1
  8. package/docs/api-reference.md +1291 -0
  9. package/docs/architecture.md +168 -0
  10. package/docs/connector-spec.md +126 -0
  11. package/eval/cases-canary.json +58 -0
  12. package/eval/cases-scope-robustness.json +278 -0
  13. package/eval/cases.json +117 -20
  14. package/package.json +25 -4
  15. package/src/__tests__/access-tracker-novelty.test.ts +304 -0
  16. package/src/__tests__/activity-counter.test.ts +125 -0
  17. package/src/__tests__/adaptive-fidelity.test.ts +102 -0
  18. package/src/__tests__/admission-control.test.ts +206 -0
  19. package/src/__tests__/anchor-generator.test.ts +67 -0
  20. package/src/__tests__/api-server-security.test.ts +102 -0
  21. package/src/__tests__/auto-consolidation.test.ts +168 -0
  22. package/src/__tests__/auto-recall.test.ts +131 -0
  23. package/src/__tests__/babel-integration.test.ts +144 -0
  24. package/src/__tests__/batch-dedup.test.ts +65 -0
  25. package/src/__tests__/belief-history.test.ts +220 -0
  26. package/src/__tests__/canary-eval.test.ts +114 -0
  27. package/src/__tests__/capture-engine.test.ts +1328 -0
  28. package/src/__tests__/capture-heuristic.test.ts +171 -0
  29. package/src/__tests__/cascade-forget.test.ts +210 -0
  30. package/src/__tests__/category-min-scores.test.ts +116 -0
  31. package/src/__tests__/cc8-cc1-essential-context.test.ts +298 -0
  32. package/src/__tests__/circuit-breaker.test.ts +99 -0
  33. package/src/__tests__/cluster-consolidation.test.ts +945 -0
  34. package/src/__tests__/confidence-metadata.test.ts +125 -0
  35. package/src/__tests__/confidence-tracker.test.ts +261 -0
  36. package/src/__tests__/conflict-advisor.test.ts +206 -0
  37. package/src/__tests__/conflict-escalation.test.ts +149 -0
  38. package/src/__tests__/conflict-lifecycle.test.ts +83 -0
  39. package/src/__tests__/conflict-output.test.ts +85 -0
  40. package/src/__tests__/conflict-store.test.ts +418 -0
  41. package/src/__tests__/connector-v1.test.ts +181 -0
  42. package/src/__tests__/consolidation-engine.test.ts +430 -0
  43. package/src/__tests__/constructive-retrieval.test.ts +509 -0
  44. package/src/__tests__/context-collapse-renderer.test.ts +214 -0
  45. package/src/__tests__/context-composer-pins.test.ts +64 -0
  46. package/src/__tests__/context-composer-task-selection.test.ts +24 -0
  47. package/src/__tests__/context-reconstructor.test.ts +65 -0
  48. package/src/__tests__/context-renderer.test.ts +91 -0
  49. package/src/__tests__/continuity-eval.test.ts +275 -0
  50. package/src/__tests__/continuity-schema.test.ts +97 -0
  51. package/src/__tests__/contracts.test.ts +262 -0
  52. package/src/__tests__/conversation-importer.test.ts +692 -0
  53. package/src/__tests__/core-recall-eval.test.ts +235 -0
  54. package/src/__tests__/core-summary.test.ts +109 -0
  55. package/src/__tests__/data-checkup.test.ts +276 -0
  56. package/src/__tests__/decay-exemption.test.ts +129 -0
  57. package/src/__tests__/dedup-actions.test.ts +58 -0
  58. package/src/__tests__/dedup-guard.test.ts +39 -0
  59. package/src/__tests__/deterministic-id.test.ts +39 -0
  60. package/src/__tests__/distill-lock.test.ts +305 -0
  61. package/src/__tests__/distill-session-argshape.test.ts +79 -0
  62. package/src/__tests__/doctor.test.ts +319 -0
  63. package/src/__tests__/dream-pipeline.test.ts +780 -0
  64. package/src/__tests__/drill-down.test.ts +108 -0
  65. package/src/__tests__/embedder.test.ts +122 -0
  66. package/src/__tests__/emotion-decay.test.ts +46 -0
  67. package/src/__tests__/emotion-detector.test.ts +56 -0
  68. package/src/__tests__/emotion-phase1-integration.test.ts +153 -0
  69. package/src/__tests__/emotion-retrieval.test.ts +56 -0
  70. package/src/__tests__/entity-resolver.test.ts +58 -0
  71. package/src/__tests__/env-config.test.ts +151 -0
  72. package/src/__tests__/error-signature-boost.test.ts +87 -0
  73. package/src/__tests__/error-signature.test.ts +95 -0
  74. package/src/__tests__/error-taxonomy.test.ts +129 -0
  75. package/src/__tests__/ethics-layer.test.ts +476 -0
  76. package/src/__tests__/event-segmenter.test.ts +153 -0
  77. package/src/__tests__/feature-flags-integration.test.ts +54 -0
  78. package/src/__tests__/frequency-tracker.test.ts +113 -0
  79. package/src/__tests__/freshness.test.ts +186 -0
  80. package/src/__tests__/graph-export.test.ts +489 -0
  81. package/src/__tests__/hotness-blend.test.ts +283 -0
  82. package/src/__tests__/ingest-chunking.test.ts +44 -0
  83. package/src/__tests__/ingest.test.ts +360 -0
  84. package/src/__tests__/interference-detector.test.ts +203 -0
  85. package/src/__tests__/kg-extractor.test.ts +192 -0
  86. package/src/__tests__/kg-store.test.ts +300 -0
  87. package/src/__tests__/llm-client-pivot.test.ts +628 -0
  88. package/src/__tests__/llm-consolidation.test.ts +226 -0
  89. package/src/__tests__/maintenance-locks.test.ts +189 -0
  90. package/src/__tests__/mcp-efficiency.test.ts +288 -0
  91. package/src/__tests__/mcp-related-scopes.test.ts +151 -0
  92. package/src/__tests__/memory-boundaries.test.ts +282 -0
  93. package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +345 -0
  94. package/src/__tests__/memory-evolution.test.ts +271 -0
  95. package/src/__tests__/memory-health-rebalance.test.ts +144 -0
  96. package/src/__tests__/memory-lint.test.ts +421 -0
  97. package/src/__tests__/memory-output.test.ts +215 -0
  98. package/src/__tests__/memory-promotion.test.ts +315 -0
  99. package/src/__tests__/migrate-dedup-ids.test.ts +65 -0
  100. package/src/__tests__/multi-vector.test.ts +242 -0
  101. package/src/__tests__/narrative-architecture.test.ts +456 -0
  102. package/src/__tests__/noise-filter.test.ts +205 -0
  103. package/src/__tests__/noise-prototype-bank.test.ts +280 -0
  104. package/src/__tests__/obsidian-connector.test.ts +363 -0
  105. package/src/__tests__/omitted-reporting.test.ts +98 -0
  106. package/src/__tests__/pending-review.test.ts +77 -0
  107. package/src/__tests__/pii-redact.test.ts +333 -0
  108. package/src/__tests__/pivot-apply.test.ts +373 -0
  109. package/src/__tests__/pivot-distill-supervisor.test.ts +457 -0
  110. package/src/__tests__/pivot-distill.test.ts +1178 -0
  111. package/src/__tests__/post-retrieval-filter.test.ts +178 -0
  112. package/src/__tests__/ppr-traversal.test.ts +256 -0
  113. package/src/__tests__/prediction-engine.test.ts +349 -0
  114. package/src/__tests__/predictive-prospective-memory.test.ts +416 -0
  115. package/src/__tests__/preference-guard-smoke.test.ts +211 -0
  116. package/src/__tests__/preference-matcher.test.ts +282 -0
  117. package/src/__tests__/preference-slots.test.ts +205 -0
  118. package/src/__tests__/prospective-memory.test.ts +283 -0
  119. package/src/__tests__/pull-from-macbook-sync-only.test.ts +679 -0
  120. package/src/__tests__/query-entity-detector.test.ts +171 -0
  121. package/src/__tests__/query-expander-alias.test.ts +146 -0
  122. package/src/__tests__/query-expander.test.ts +34 -0
  123. package/src/__tests__/recall-gate.test.ts +266 -0
  124. package/src/__tests__/recall-governor.test.ts +227 -0
  125. package/src/__tests__/recall-mode.test.ts +64 -0
  126. package/src/__tests__/resolve-db-path.test.ts +130 -0
  127. package/src/__tests__/resolve-tier.test.ts +64 -0
  128. package/src/__tests__/result-synthesizer.test.ts +198 -0
  129. package/src/__tests__/resume-context.test.ts +4898 -0
  130. package/src/__tests__/retrieval-eval.test.ts +163 -0
  131. package/src/__tests__/retrieval-trace.test.ts +213 -0
  132. package/src/__tests__/retriever-boundary-weight.test.ts +136 -0
  133. package/src/__tests__/retriever-lazy-init-dispatch.test.ts +123 -0
  134. package/src/__tests__/retroactive-boost.test.ts +223 -0
  135. package/src/__tests__/salience-scoring.test.ts +106 -0
  136. package/src/__tests__/scope-inventory.test.ts +200 -0
  137. package/src/__tests__/scope-policy.test.ts +69 -0
  138. package/src/__tests__/scope-suggester.test.ts +80 -0
  139. package/src/__tests__/session-checkpoint.test.ts +291 -0
  140. package/src/__tests__/session-distiller.test.ts +640 -0
  141. package/src/__tests__/session-gc.test.ts +215 -0
  142. package/src/__tests__/skill-engine.test.ts +552 -0
  143. package/src/__tests__/skill-promotion.test.ts +654 -0
  144. package/src/__tests__/skill-verifier.test.ts +122 -0
  145. package/src/__tests__/source-heartbeat.test.ts +250 -0
  146. package/src/__tests__/stable-context-length-contract.test.ts +62 -0
  147. package/src/__tests__/store-patch-metadata.test.ts +205 -0
  148. package/src/__tests__/store-read-consistency.test.ts +122 -0
  149. package/src/__tests__/store-schema-migration.test.ts +87 -0
  150. package/src/__tests__/store-scope-audit.test.ts +81 -0
  151. package/src/__tests__/store-upsert.test.ts +201 -0
  152. package/src/__tests__/supersede-chain.test.ts +154 -0
  153. package/src/__tests__/temporal-parser.test.ts +241 -0
  154. package/src/__tests__/temporal-validity.test.ts +160 -0
  155. package/src/__tests__/term-registry-terminal-roster.test.ts +127 -0
  156. package/src/__tests__/term-registry.test.ts +121 -0
  157. package/src/__tests__/tool-error-surfacing.test.ts +98 -0
  158. package/src/__tests__/tool-output-compressor.test.ts +160 -0
  159. package/src/__tests__/topic-tag.test.ts +113 -0
  160. package/src/__tests__/trusted-memory.test.ts +839 -0
  161. package/src/__tests__/ui-server-security.test.ts +93 -0
  162. package/src/__tests__/usage-tracker.test.ts +287 -0
  163. package/src/__tests__/version-manager.test.ts +213 -0
  164. package/src/__tests__/workflow-observation-skill-outcome.test.ts +352 -0
  165. package/src/__tests__/workflow-observation.test.ts +433 -0
  166. package/src/__tests__/write-verifier.test.ts +122 -0
  167. package/src/access-tracker.ts +90 -34
  168. package/src/activity-counter.ts +46 -18
  169. package/src/adaptive-retrieval.ts +11 -0
  170. package/src/aliases.ts +133 -0
  171. package/src/api-server.ts +36 -9
  172. package/src/audit-log.ts +4 -2
  173. package/src/auto-consolidation.ts +8 -3
  174. package/src/auto-gc.ts +85 -21
  175. package/src/auto-recall.ts +61 -1
  176. package/src/belief-history.ts +164 -0
  177. package/src/capture-engine.ts +142 -32
  178. package/src/cli.ts +268 -41
  179. package/src/confidence-tracker.ts +36 -18
  180. package/src/conflict-engine.ts +24 -3
  181. package/src/consolidation-engine.ts +255 -23
  182. package/src/context-composer-stable-selection.ts +7 -1
  183. package/src/context-composer.ts +8 -1
  184. package/src/data-checkup.ts +96 -7
  185. package/src/decay-engine.ts +59 -7
  186. package/src/distill-lock.ts +194 -15
  187. package/src/doctor.ts +13 -4
  188. package/src/dream-pipeline.ts +473 -41
  189. package/src/env-config.ts +118 -0
  190. package/src/error-signature.ts +153 -0
  191. package/src/error-taxonomy.ts +115 -0
  192. package/src/eval.ts +402 -14
  193. package/src/freshness.ts +192 -0
  194. package/src/http-request-policy.ts +148 -0
  195. package/src/idempotency.ts +8 -0
  196. package/src/ingest.ts +308 -12
  197. package/src/kg-extractor.ts +13 -3
  198. package/src/kg-store.ts +236 -44
  199. package/src/llm-client.ts +106 -11
  200. package/src/llm-consolidation.ts +2 -1
  201. package/src/mcp-server.ts +87 -1800
  202. package/src/mcp-tool-deps.ts +48 -0
  203. package/src/mcp-tools-advanced.ts +954 -0
  204. package/src/mcp-tools-core.ts +637 -0
  205. package/src/mcp-tools-governance.ts +475 -0
  206. package/src/memory-boundaries.ts +26 -3
  207. package/src/memory-evolution.ts +73 -1
  208. package/src/memory-health-rebalance.ts +4 -0
  209. package/src/memory-lint.ts +183 -10
  210. package/src/memory-output.ts +129 -4
  211. package/src/memory-promotion.ts +246 -0
  212. package/src/memory-schema.ts +25 -2
  213. package/src/memory-store-port.ts +46 -0
  214. package/src/multi-vector.ts +2 -1
  215. package/src/narrative-schema.ts +2 -1
  216. package/src/noise-filter.ts +57 -6
  217. package/src/noise-prototype-bank.ts +408 -0
  218. package/src/pii-detector.ts +207 -5
  219. package/src/pivot-apply.ts +399 -0
  220. package/src/preference-matcher.ts +37 -3
  221. package/src/query-expander.ts +90 -9
  222. package/src/recall-gate.ts +305 -0
  223. package/src/result-synthesizer.ts +2 -1
  224. package/src/retention-policy.ts +2 -1
  225. package/src/retrieval-profiles.ts +46 -4
  226. package/src/retriever.ts +354 -157
  227. package/src/retroactive-boost.ts +6 -2
  228. package/src/runtime-config.ts +78 -6
  229. package/src/scope-suggester.ts +113 -0
  230. package/src/session-distiller.ts +23 -2
  231. package/src/session-engine.ts +2 -1
  232. package/src/session-schema.ts +1 -0
  233. package/src/session-store.ts +5 -0
  234. package/src/skill-engine.ts +78 -0
  235. package/src/skill-promotion.ts +304 -48
  236. package/src/skill-schema.ts +16 -3
  237. package/src/skill-verifier.ts +152 -0
  238. package/src/store.ts +321 -57
  239. package/src/term-registry.ts +35 -0
  240. package/src/tool-output-compressor.ts +3 -1
  241. package/src/ui-server.ts +9 -1
  242. package/src/usage-tracker.ts +242 -0
  243. package/src/version-manager.ts +3 -2
  244. package/src/version.ts +19 -0
  245. package/src/workflow-observation-engine.ts +2 -1
  246. package/src/workflow-observation-schema.ts +2 -1
  247. package/src/workflow-observation-store.ts +6 -2
  248. package/.env +0 -4
  249. package/CLAUDE.md +0 -46
  250. package/config.json +0 -55
  251. package/daily-recall.sh +0 -110
  252. package/logs/daily-recall.error.log +0 -0
  253. package/logs/daily-recall.log +0 -60
  254. package/logs/ingest-2026-04-11.log +0 -110
  255. package/logs/ingest-2026-04-12.log +0 -90
  256. package/logs/ingest-2026-04-13.log +0 -87
  257. package/logs/launchagent-stderr.log +0 -0
  258. package/logs/launchagent-stdout.log +0 -0
@@ -0,0 +1,679 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import {
3
+ chmodSync,
4
+ existsSync,
5
+ mkdirSync,
6
+ mkdtempSync,
7
+ readFileSync,
8
+ renameSync,
9
+ statSync,
10
+ symlinkSync,
11
+ writeFileSync,
12
+ } from "node:fs";
13
+ import { tmpdir } from "node:os";
14
+ import { dirname, join, resolve } from "node:path";
15
+ import { spawnSync } from "node:child_process";
16
+
17
+ const REPO_ROOT = resolve(import.meta.dir, "../..");
18
+ const SCRIPT = join(REPO_ROOT, "scripts", "pull-from-macbook.sh");
19
+ const TEST_TIMEOUT_MS = 30_000;
20
+
21
+ interface Harness {
22
+ root: string;
23
+ home: string;
24
+ remoteHome: string;
25
+ report: string;
26
+ rsyncLog: string;
27
+ sshLog: string;
28
+ registrarMarker: string;
29
+ ingestMarker: string;
30
+ env: NodeJS.ProcessEnv;
31
+ }
32
+
33
+ interface RsyncCall {
34
+ args: string[];
35
+ sourceArg: string;
36
+ targetArg: string;
37
+ dryRun: boolean;
38
+ ignoreTimes: boolean;
39
+ }
40
+
41
+ function executable(path: string, source: string): void {
42
+ writeFileSync(path, source, { mode: 0o700 });
43
+ chmodSync(path, 0o700);
44
+ }
45
+
46
+ function fixture(path: string, content: string): void {
47
+ mkdirSync(dirname(path), { recursive: true });
48
+ writeFileSync(path, content);
49
+ }
50
+
51
+ function fakeRsyncSource(): string {
52
+ return [
53
+ "#!/usr/bin/env bun",
54
+ 'import { appendFileSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, statSync, symlinkSync, writeFileSync } from "node:fs";',
55
+ 'import { basename, dirname, extname, join, relative, sep } from "node:path";',
56
+ 'const args = process.argv.slice(2);',
57
+ 'const sourceArg = args.at(-2) || "";',
58
+ 'const targetArg = args.at(-1) || "";',
59
+ 'const dryRun = args.includes("--dry-run");',
60
+ 'const ignoreTimes = args.includes("--ignore-times");',
61
+ 'const optionValues = new Set(["-e", "--exclude", "--include", "--out-format", "--rsync-path", "--timeout"]);',
62
+ 'for (let index = 0; index < args.length - 2; index += 1) {',
63
+ ' const arg = args[index];',
64
+ ' if (optionValues.has(arg)) { if (index + 1 >= args.length - 2) process.exit(64); index += 1; continue; }',
65
+ ' if (!arg.startsWith("-")) process.exit(64);',
66
+ '}',
67
+ 'appendFileSync(process.env.FAKE_RSYNC_LOG, JSON.stringify({ args: args.slice(0, -2), sourceArg, targetArg, dryRun, ignoreTimes }) + "\\n");',
68
+ 'if (!dryRun && process.env.FAKE_CREATE_REPORT_DURING_SYNC && !existsSync(process.env.FAKE_CREATE_REPORT_DURING_SYNC)) writeFileSync(process.env.FAKE_CREATE_REPORT_DURING_SYNC, "racing-writer");',
69
+ 'if (!dryRun && process.env.FAKE_BREAK_MAPPING_TMP) {',
70
+ ' const report = process.env.FAKE_BREAK_MAPPING_TMP;',
71
+ ' const prefix = basename(report) + ".tmp.";',
72
+ ' const temporary = readdirSync(dirname(report))',
73
+ ' .filter((name) => name.startsWith(prefix) && !name.endsWith(".saved"))',
74
+ ' .map((name) => join(dirname(report), name))',
75
+ ' .find((path) => statSync(path).isFile());',
76
+ ' if (temporary) { renameSync(temporary, temporary + ".saved"); mkdirSync(temporary); }',
77
+ '}',
78
+ 'if (!sourceArg.startsWith("mac:")) process.exit(64);',
79
+ 'const remoteHome = process.env.FAKE_REMOTE_HOME;',
80
+ 'let remoteRaw = sourceArg.slice(4);',
81
+ 'let sourcePath = remoteRaw;',
82
+ 'if (remoteRaw === "~") sourcePath = remoteHome;',
83
+ 'else if (remoteRaw.startsWith("~/")) sourcePath = join(remoteHome, remoteRaw.slice(2));',
84
+ 'else if (!remoteRaw.startsWith("/")) sourcePath = join(remoteHome, remoteRaw);',
85
+ 'if (!existsSync(sourcePath)) process.exit(23);',
86
+ 'function walk(root) {',
87
+ ' const files = [];',
88
+ ' for (const entry of readdirSync(root, { withFileTypes: true })) {',
89
+ ' const path = join(root, entry.name);',
90
+ ' if (entry.isDirectory()) files.push(...walk(path));',
91
+ ' else if (entry.isFile() || entry.isSymbolicLink()) files.push(path);',
92
+ ' }',
93
+ ' return files.sort();',
94
+ '}',
95
+ 'function included(path) {',
96
+ ' const normalizedSource = sourcePath.split(sep).join("/");',
97
+ ' const name = basename(path);',
98
+ ' if (statSync(sourcePath).isFile()) return true;',
99
+ ' if (normalizedSource.includes("/.gemini/tmp")) return name.startsWith("session-") && extname(name) === ".json";',
100
+ ' if (normalizedSource.includes("/local-agent-mode-sessions")) return extname(name) === ".jsonl" && name !== "audit.jsonl";',
101
+ ' if (normalizedSource.includes("/antigravity-cli/brain")) return name === "transcript_full.jsonl";',
102
+ ' if (normalizedSource.includes("/antigravity-rescue/conversations")) return extname(name) === ".pb";',
103
+ ' return extname(name) === ".jsonl";',
104
+ '}',
105
+ 'const sourceIsDirectory = statSync(sourcePath).isDirectory();',
106
+ 'const files = (sourceIsDirectory ? walk(sourcePath) : [sourcePath]).filter(included);',
107
+ 'if (dryRun && !ignoreTimes && process.env.FAKE_RSYNC_MUTATE_ON_VERIFY_SOURCE && sourceArg.includes(process.env.FAKE_RSYNC_MUTATE_ON_VERIFY_SOURCE) && files.length > 0) appendFileSync(files[0], "late-change");',
108
+ 'const prefix = args.some((arg) => arg.includes("__RN_MAP__")) ? "__RN_MAP__" : "__RN_CHANGE__";',
109
+ 'function copySource(source, destination) {',
110
+ ' mkdirSync(dirname(destination), { recursive: true });',
111
+ ' if (lstatSync(source).isSymbolicLink()) symlinkSync(readlinkSync(source), destination);',
112
+ ' else copyFileSync(source, destination);',
113
+ '}',
114
+ 'const forcedFailure = Boolean(process.env.FAKE_RSYNC_FAIL_SOURCE && sourceArg.includes(process.env.FAKE_RSYNC_FAIL_SOURCE));',
115
+ 'if (!dryRun && forcedFailure && files.length > 0) {',
116
+ ' const source = files[0];',
117
+ ' const rel = sourceIsDirectory ? relative(sourcePath, source).split(sep).join("/") : basename(source);',
118
+ ' const destination = sourceIsDirectory ? join(targetArg, rel) : targetArg;',
119
+ ' copySource(source, destination);',
120
+ ' process.exit(23);',
121
+ '}',
122
+ 'for (const source of files) {',
123
+ ' const rel = sourceIsDirectory ? relative(sourcePath, source).split(sep).join("/") : basename(source);',
124
+ ' const destination = sourceIsDirectory ? join(targetArg, rel) : targetArg;',
125
+ ' if (dryRun) {',
126
+ ' const changed = !existsSync(destination) || !readFileSync(source).equals(readFileSync(destination));',
127
+ ' const item = lstatSync(source).isSymbolicLink() ? "cL+++++++++" : ">f+++++++++";',
128
+ ' if (ignoreTimes || changed) process.stdout.write(prefix + item + "|" + rel + "\\n");',
129
+ ' continue;',
130
+ ' }',
131
+ ' copySource(source, destination);',
132
+ '}',
133
+ ].join("\n") + "\n";
134
+ }
135
+
136
+ function fakeSshSource(): string {
137
+ return [
138
+ "#!/usr/bin/env bun",
139
+ 'import { appendFileSync, existsSync, statSync } from "node:fs";',
140
+ 'import { join } from "node:path";',
141
+ 'const args = process.argv.slice(2);',
142
+ 'const command = args.join(" ");',
143
+ 'appendFileSync(process.env.FAKE_SSH_LOG, command + "\\n");',
144
+ 'if (process.env.FAKE_SSH_ONLINE !== "1") process.exit(255);',
145
+ 'if (command.includes("echo online")) { console.log("online"); process.exit(0); }',
146
+ 'if (process.env.FAKE_SSH_FAIL_PROBE && command.includes(process.env.FAKE_SSH_FAIL_PROBE)) process.exit(255);',
147
+ 'if (command.includes("$HOME/.codex") && command.includes("session_index.jsonl")) { const path = join(process.env.FAKE_REMOTE_HOME, ".codex/session_index.jsonl"); process.exit(!existsSync(path) ? 2 : statSync(path).isFile() ? 0 : 3); }',
148
+ 'if (command.includes("$HOME/.kimi-code") && command.includes("session_index.jsonl")) { const path = join(process.env.FAKE_REMOTE_HOME, ".kimi-code/session_index.jsonl"); process.exit(!existsSync(path) ? 2 : statSync(path).isFile() ? 0 : 3); }',
149
+ 'if (command.includes("antigravity-rescue")) { const path = join(process.env.FAKE_REMOTE_HOME, "Downloads/antigravity-rescue/conversations"); process.exit(!existsSync(path) ? 2 : statSync(path).isDirectory() ? 0 : 3); }',
150
+ 'process.exit(0);',
151
+ ].join("\n") + "\n";
152
+ }
153
+
154
+ function makeHarness(): Harness {
155
+ const root = mkdtempSync(join(tmpdir(), "pull-sync-only-"));
156
+ const home = join(root, "home");
157
+ const remoteHome = join(root, "remote-home");
158
+ const fakeBin = join(root, "bin");
159
+ const report = join(root, "mapping.tsv");
160
+ const rsyncLog = join(root, "rsync.jsonl");
161
+ const sshLog = join(root, "ssh.log");
162
+ const registrarMarker = join(root, "registrar-called");
163
+ const ingestMarker = join(root, "ingest-called");
164
+
165
+ mkdirSync(fakeBin, { recursive: true });
166
+ mkdirSync(join(home, "recallnest", "scripts"), { recursive: true });
167
+ executable(join(fakeBin, "rsync"), fakeRsyncSource());
168
+ executable(join(fakeBin, "ssh"), fakeSshSource());
169
+ executable(
170
+ join(home, "recallnest", "scripts", "codex-projectless-register.py"),
171
+ [
172
+ "#!/bin/bash",
173
+ 'printf "called\\n" > "$FAKE_REGISTRAR_MARKER"',
174
+ ].join("\n") + "\n",
175
+ );
176
+ executable(
177
+ join(home, "recallnest", "scripts", "incremental-ingest.sh"),
178
+ [
179
+ "#!/bin/bash",
180
+ 'printf "called\\n" > "$FAKE_INGEST_MARKER"',
181
+ ].join("\n") + "\n",
182
+ );
183
+
184
+ fixture(join(remoteHome, ".claude", "projects", "p", "cc.jsonl"), "{\"source\":\"cc\"}\n");
185
+ fixture(join(remoteHome, ".codex", "sessions", "2026", "codex.jsonl"), "{\"source\":\"codex\"}\n");
186
+ fixture(join(remoteHome, ".codex", "archived_sessions", "archived.jsonl"), "{\"source\":\"archive\"}\n");
187
+ fixture(
188
+ join(remoteHome, ".codex", "session_index.jsonl"),
189
+ "{\"id\":\"mac-codex\",\"updated_at\":\"2026-08-03T00:00:00Z\"}\n",
190
+ );
191
+ fixture(join(remoteHome, ".kimi-code", "sessions", "k1", "wire.jsonl"), "{\"source\":\"kimi\"}\n");
192
+ fixture(join(remoteHome, ".kimi-code", "session_index.jsonl"), "{\"sessionId\":\"mac-kimi\"}\n");
193
+ fixture(join(remoteHome, ".gemini", "tmp", "g1", "chats", "session-g.json"), "{\"source\":\"gemini\"}\n");
194
+ fixture(
195
+ join(
196
+ remoteHome,
197
+ "Library",
198
+ "Application Support",
199
+ "Claude",
200
+ "local-agent-mode-sessions",
201
+ "d1",
202
+ ".claude",
203
+ "projects",
204
+ "p",
205
+ "desktop-one.jsonl",
206
+ ),
207
+ "{\"source\":\"desktop\"}\n",
208
+ );
209
+ fixture(
210
+ join(remoteHome, ".gemini", "antigravity-cli", "brain", "b1", "transcript_full.jsonl"),
211
+ "{\"source\":\"agy-brain\"}\n",
212
+ );
213
+ fixture(
214
+ join(remoteHome, "Downloads", "antigravity-rescue", "conversations", "legacy.pb"),
215
+ "legacy-original",
216
+ );
217
+ fixture(
218
+ join(remoteHome, ".gemini", "antigravity-cli", "conversations", "remote-cli.db"),
219
+ "remote-cli-original",
220
+ );
221
+ fixture(
222
+ join(remoteHome, ".gemini", "antigravity", "conversations", "remote-app.db"),
223
+ "remote-app-original",
224
+ );
225
+
226
+ for (let index = 1; index <= 24; index += 1) {
227
+ fixture(
228
+ join(home, "machine-data", "macbook-agy", "conversations", "existing-" + index + ".db"),
229
+ "mini-existing-" + index,
230
+ );
231
+ }
232
+
233
+ const env: NodeJS.ProcessEnv = {
234
+ ...process.env,
235
+ LC_ALL: "C",
236
+ PULL_FROM_MACBOOK_HOME: home,
237
+ PULL_FROM_MACBOOK_RSYNC: join(fakeBin, "rsync"),
238
+ PULL_FROM_MACBOOK_SSH: join(fakeBin, "ssh"),
239
+ FAKE_REMOTE_HOME: remoteHome,
240
+ FAKE_RSYNC_LOG: rsyncLog,
241
+ FAKE_SSH_LOG: sshLog,
242
+ FAKE_SSH_ONLINE: "1",
243
+ FAKE_REGISTRAR_MARKER: registrarMarker,
244
+ FAKE_INGEST_MARKER: ingestMarker,
245
+ PULL_FROM_MACBOOK_LOG: join(root, "pull.log"),
246
+ PULL_FROM_MACBOOK_LOG_DIR: join(root, "logs"),
247
+ };
248
+
249
+ return {
250
+ root,
251
+ home,
252
+ remoteHome,
253
+ report,
254
+ rsyncLog,
255
+ sshLog,
256
+ registrarMarker,
257
+ ingestMarker,
258
+ env,
259
+ };
260
+ }
261
+
262
+ function run(harness: Harness, args: string[], extraEnv: NodeJS.ProcessEnv = {}) {
263
+ return spawnSync("/bin/bash", [SCRIPT, ...args], {
264
+ env: { ...harness.env, ...extraEnv },
265
+ encoding: "utf8",
266
+ timeout: 30_000,
267
+ });
268
+ }
269
+
270
+ function syncOnly(harness: Harness) {
271
+ return run(harness, ["--sync-only", "--mapping-report", harness.report]);
272
+ }
273
+
274
+ function rsyncCalls(harness: Harness): RsyncCall[] {
275
+ if (!existsSync(harness.rsyncLog)) return [];
276
+ return readFileSync(harness.rsyncLog, "utf8")
277
+ .trim()
278
+ .split("\n")
279
+ .filter(Boolean)
280
+ .map((line) => JSON.parse(line) as RsyncCall);
281
+ }
282
+
283
+ function normalizedRsyncArgs(args: string[]): string[] {
284
+ return args.filter(
285
+ (arg) =>
286
+ arg !== "--dry-run"
287
+ && arg !== "--ignore-times"
288
+ && arg !== "--itemize-changes"
289
+ && !arg.startsWith("--out-format="),
290
+ );
291
+ }
292
+
293
+ function unexpectedPositionalArgs(args: string[]): string[] {
294
+ const valueOptions = new Set(["-e", "--exclude", "--include", "--out-format", "--rsync-path", "--timeout"]);
295
+ const unexpected: string[] = [];
296
+ for (let index = 0; index < args.length; index += 1) {
297
+ const arg = args[index];
298
+ if (valueOptions.has(arg)) {
299
+ index += 1;
300
+ continue;
301
+ }
302
+ if (!arg.startsWith("-")) unexpected.push(arg);
303
+ }
304
+ return unexpected;
305
+ }
306
+
307
+ function dbContents(directory: string): Record<string, string> {
308
+ const result: Record<string, string> = {};
309
+ for (let index = 1; index <= 24; index += 1) {
310
+ const name = "existing-" + index + ".db";
311
+ result[name] = readFileSync(join(directory, name), "utf8");
312
+ }
313
+ return result;
314
+ }
315
+
316
+ describe("pull-from-macbook --sync-only", () => {
317
+ it("syncs allowed sources, verifies identical rsync arguments, and emits per-file mappings without ingest", () => {
318
+ const harness = makeHarness();
319
+ expect(harness.env.HOME).toBe(process.env.HOME);
320
+ const localDbDir = join(harness.home, "machine-data", "macbook-agy", "conversations");
321
+ const localDbBefore = dbContents(localDbDir);
322
+ const remoteCliDb = join(harness.remoteHome, ".gemini", "antigravity-cli", "conversations", "remote-cli.db");
323
+ const remoteAppDb = join(harness.remoteHome, ".gemini", "antigravity", "conversations", "remote-app.db");
324
+ const remoteCliBefore = readFileSync(remoteCliDb, "utf8");
325
+ const remoteAppBefore = readFileSync(remoteAppDb, "utf8");
326
+
327
+ const result = syncOnly(harness);
328
+
329
+ expect(result.status).toBe(0);
330
+ expect(existsSync(harness.ingestMarker)).toBe(false);
331
+ expect(existsSync(harness.registrarMarker)).toBe(false);
332
+ expect(readFileSync(join(harness.home, ".claude", "projects", "p", "cc.jsonl"), "utf8")).toContain("cc");
333
+ expect(
334
+ readFileSync(
335
+ join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl"),
336
+ "utf8",
337
+ ),
338
+ ).toContain("desktop");
339
+ expect(readFileSync(join(harness.home, ".codex", "session_index.jsonl"), "utf8")).toContain("mac-codex");
340
+ expect(readFileSync(join(harness.home, ".kimi-code", "session_index.jsonl"), "utf8")).toContain("mac-kimi");
341
+
342
+ const mapping = readFileSync(harness.report, "utf8");
343
+ expect(mapping.split("\n")[0]).toBe(
344
+ "source_kind\tsource_file\tlocal_target\tderived_target\tstatus",
345
+ );
346
+ expect(mapping).toContain("claude-code\tmac:~/.claude/projects/p/cc.jsonl");
347
+ expect(mapping).toContain(
348
+ join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl"),
349
+ );
350
+ expect(mapping).toContain("desktop-flat\t");
351
+ expect(mapping).toContain("codex-index-merge\t");
352
+ for (const line of mapping.trim().split("\n").slice(1)) {
353
+ expect(line.split("\t")).toHaveLength(5);
354
+ }
355
+ const desktopTransportRows = mapping
356
+ .trim()
357
+ .split("\n")
358
+ .slice(1)
359
+ .map((line) => line.split("\t"))
360
+ .filter(([sourceKind]) => sourceKind === "claude-desktop");
361
+ expect(desktopTransportRows.length).toBeGreaterThan(0);
362
+ expect(
363
+ desktopTransportRows.every((fields) => fields[4] === "local-verified:derived-pending"),
364
+ ).toBe(true);
365
+ expect(statSync(harness.report).mode & 0o777).toBe(0o600);
366
+ expect(existsSync(join(harness.home, ".codex", ".codex-global-state.json"))).toBe(false);
367
+
368
+ const calls = rsyncCalls(harness);
369
+ const grouped = new Map<string, RsyncCall[]>();
370
+ for (const call of calls) {
371
+ grouped.set(call.sourceArg, [...(grouped.get(call.sourceArg) || []), call]);
372
+ }
373
+ expect(grouped.size).toBe(10);
374
+ for (const sourceCalls of grouped.values()) {
375
+ expect(sourceCalls).toHaveLength(3);
376
+ const real = sourceCalls.find((call) => !call.dryRun);
377
+ const verify = sourceCalls.find((call) => call.dryRun && !call.ignoreTimes);
378
+ const inventory = sourceCalls.find((call) => call.dryRun && call.ignoreTimes);
379
+ expect(real).toBeDefined();
380
+ expect(verify).toBeDefined();
381
+ expect(inventory).toBeDefined();
382
+ expect(normalizedRsyncArgs(verify!.args)).toEqual(real!.args);
383
+ expect(normalizedRsyncArgs(inventory!.args)).toEqual(real!.args);
384
+ expect(verify!.targetArg).toBe(real!.targetArg);
385
+ expect(inventory!.targetArg).toBe(real!.targetArg);
386
+ expect(unexpectedPositionalArgs(real!.args)).toEqual([]);
387
+ }
388
+ const desktopSource = "mac:Library/Application Support/Claude/local-agent-mode-sessions/";
389
+ const desktopCalls = grouped.get(desktopSource);
390
+ expect(desktopCalls).toHaveLength(3);
391
+ expect(desktopCalls!.every((call) => call.args.includes("-s"))).toBe(true);
392
+ expect(
393
+ calls.some((call) =>
394
+ call.sourceArg.includes("/.gemini/antigravity-cli/conversations/")
395
+ || call.sourceArg.includes("/.gemini/antigravity/conversations/")
396
+ ),
397
+ ).toBe(false);
398
+ const wrapperSource = readFileSync(SCRIPT, "utf8");
399
+ expect(wrapperSource).not.toContain("mac:~/.gemini/antigravity-cli/conversations/");
400
+ expect(wrapperSource).not.toContain("mac:~/.gemini/antigravity/conversations/");
401
+
402
+ expect(dbContents(localDbDir)).toEqual(localDbBefore);
403
+ expect(readFileSync(remoteCliDb, "utf8")).toBe(remoteCliBefore);
404
+ expect(readFileSync(remoteAppDb, "utf8")).toBe(remoteAppBefore);
405
+ const sshCalls = readFileSync(harness.sshLog, "utf8");
406
+ expect(sshCalls).toContain("echo online");
407
+ expect(sshCalls).toContain("$HOME/.codex");
408
+ expect(sshCalls).toContain("$HOME/.kimi-code");
409
+ expect(sshCalls).toContain("antigravity-rescue");
410
+ }, TEST_TIMEOUT_MS);
411
+
412
+ it("fails offline in sync-only mode but keeps the routine offline run successful", () => {
413
+ const syncHarness = makeHarness();
414
+ const syncResult = run(
415
+ syncHarness,
416
+ ["--sync-only", "--mapping-report", syncHarness.report],
417
+ { FAKE_SSH_ONLINE: "0" },
418
+ );
419
+ expect(syncResult.status).not.toBe(0);
420
+ expect(readFileSync(syncHarness.report, "utf8")).toContain("transport\tmac\t-\t-\toffline");
421
+ expect(existsSync(syncHarness.registrarMarker)).toBe(false);
422
+ expect(existsSync(syncHarness.ingestMarker)).toBe(false);
423
+ expect(rsyncCalls(syncHarness)).toHaveLength(0);
424
+
425
+ const routineHarness = makeHarness();
426
+ const routineResult = run(routineHarness, [], { FAKE_SSH_ONLINE: "0" });
427
+ expect(routineResult.status).toBe(0);
428
+ expect(existsSync(routineHarness.registrarMarker)).toBe(true);
429
+ expect(existsSync(routineHarness.ingestMarker)).toBe(false);
430
+
431
+ const existingReportHarness = makeHarness();
432
+ fixture(existingReportHarness.report, "keep-existing-report");
433
+ const existingReportResult = syncOnly(existingReportHarness);
434
+ expect(existingReportResult.status).not.toBe(0);
435
+ expect(readFileSync(existingReportHarness.report, "utf8")).toBe("keep-existing-report");
436
+ expect(existsSync(existingReportHarness.sshLog)).toBe(false);
437
+
438
+ const racingReportHarness = makeHarness();
439
+ const racingReportResult = run(
440
+ racingReportHarness,
441
+ ["--sync-only", "--mapping-report", racingReportHarness.report],
442
+ { FAKE_CREATE_REPORT_DURING_SYNC: racingReportHarness.report },
443
+ );
444
+ expect(racingReportResult.status).not.toBe(0);
445
+ expect(readFileSync(racingReportHarness.report, "utf8")).toBe("racing-writer");
446
+ }, TEST_TIMEOUT_MS);
447
+
448
+ it("fails before flattening when Desktop basenames collide", () => {
449
+ const harness = makeHarness();
450
+ fixture(
451
+ join(
452
+ harness.remoteHome,
453
+ "Library",
454
+ "Application Support",
455
+ "Claude",
456
+ "local-agent-mode-sessions",
457
+ "d2",
458
+ ".claude",
459
+ "projects",
460
+ "other",
461
+ "Desktop-One.jsonl",
462
+ ),
463
+ "{\"source\":\"collision\"}\n",
464
+ );
465
+
466
+ const result = syncOnly(harness);
467
+
468
+ expect(result.status).not.toBe(0);
469
+ expect(readFileSync(harness.report, "utf8")).toContain("basename-collision");
470
+ expect(
471
+ existsSync(join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl")),
472
+ ).toBe(false);
473
+ expect(existsSync(harness.ingestMarker)).toBe(false);
474
+
475
+ const symlinkHarness = makeHarness();
476
+ const linkedContent = join(symlinkHarness.remoteHome, "linked-content.jsonl");
477
+ fixture(linkedContent, "{\"source\":\"must-not-follow\"}\n");
478
+ const linkedSession = join(
479
+ symlinkHarness.remoteHome,
480
+ "Library",
481
+ "Application Support",
482
+ "Claude",
483
+ "local-agent-mode-sessions",
484
+ "d2",
485
+ ".claude",
486
+ "projects",
487
+ "other",
488
+ "linked.jsonl",
489
+ );
490
+ mkdirSync(dirname(linkedSession), { recursive: true });
491
+ symlinkSync(linkedContent, linkedSession);
492
+
493
+ const symlinkResult = syncOnly(symlinkHarness);
494
+
495
+ expect(symlinkResult.status).not.toBe(0);
496
+ expect(readFileSync(symlinkHarness.report, "utf8")).toContain("unsafe-symlink");
497
+ expect(
498
+ existsSync(join(symlinkHarness.home, "recallnest", "data", "desktop-import", "linked.jsonl")),
499
+ ).toBe(false);
500
+
501
+ const destinationHarness = makeHarness();
502
+ const outsideTarget = join(destinationHarness.root, "outside-target.jsonl");
503
+ fixture(outsideTarget, "outside-must-not-be-ingested");
504
+ const destinationLink = join(
505
+ destinationHarness.home,
506
+ "recallnest",
507
+ "data",
508
+ "desktop-import",
509
+ "desktop-one.jsonl",
510
+ );
511
+ mkdirSync(dirname(destinationLink), { recursive: true });
512
+ symlinkSync(outsideTarget, destinationLink);
513
+
514
+ const destinationResult = syncOnly(destinationHarness);
515
+
516
+ expect(destinationResult.status).not.toBe(0);
517
+ expect(readFileSync(destinationHarness.report, "utf8")).toContain(
518
+ "unsafe-destination-symlink",
519
+ );
520
+ expect(readFileSync(outsideTarget, "utf8")).toBe("outside-must-not-be-ingested");
521
+ }, TEST_TIMEOUT_MS);
522
+
523
+ it("surfaces a Desktop copy failure and does not ingest", () => {
524
+ const harness = makeHarness();
525
+ mkdirSync(
526
+ join(harness.home, "recallnest", "data", "desktop-import", "desktop-one.jsonl"),
527
+ { recursive: true },
528
+ );
529
+
530
+ const result = syncOnly(harness);
531
+
532
+ expect(result.status).not.toBe(0);
533
+ expect(readFileSync(harness.report, "utf8")).toContain("copy-failed:IsADirectoryError");
534
+ expect(existsSync(harness.ingestMarker)).toBe(false);
535
+ }, TEST_TIMEOUT_MS);
536
+
537
+ it("does not derive from a failed or partial source sync", () => {
538
+ const desktopHarness = makeHarness();
539
+ const desktopImport = join(
540
+ desktopHarness.home,
541
+ "recallnest",
542
+ "data",
543
+ "desktop-import",
544
+ "desktop-one.jsonl",
545
+ );
546
+ fixture(desktopImport, "known-good-desktop");
547
+
548
+ const desktopResult = run(
549
+ desktopHarness,
550
+ ["--sync-only", "--mapping-report", desktopHarness.report],
551
+ { FAKE_RSYNC_FAIL_SOURCE: "local-agent-mode-sessions" },
552
+ );
553
+
554
+ expect(desktopResult.status).not.toBe(0);
555
+ expect(readFileSync(desktopImport, "utf8")).toBe("known-good-desktop");
556
+ expect(readFileSync(desktopHarness.report, "utf8")).toContain(
557
+ "derived-skipped:source-sync-failed",
558
+ );
559
+
560
+ const indexHarness = makeHarness();
561
+ const kimiIndex = join(indexHarness.home, ".kimi-code", "session_index.jsonl");
562
+ fixture(kimiIndex, "{\"sessionId\":\"mini-only\"}\n");
563
+
564
+ const indexResult = run(
565
+ indexHarness,
566
+ ["--sync-only", "--mapping-report", indexHarness.report],
567
+ { FAKE_RSYNC_FAIL_SOURCE: ".kimi-code/session_index.jsonl" },
568
+ );
569
+
570
+ expect(indexResult.status).not.toBe(0);
571
+ expect(readFileSync(kimiIndex, "utf8")).toContain("mini-only");
572
+ expect(readFileSync(kimiIndex, "utf8")).not.toContain("mac-kimi");
573
+ expect(readFileSync(indexHarness.report, "utf8")).toContain(
574
+ "kimi-index-merge\t" + join(indexHarness.home, ".kimi-code", "session_index.macbook.jsonl"),
575
+ );
576
+ expect(readFileSync(indexHarness.report, "utf8")).toContain(
577
+ "derived-skipped:source-sync-failed",
578
+ );
579
+ }, TEST_TIMEOUT_MS);
580
+
581
+ it("distinguishes absent probes from partial, transport, and wrong-type failures", () => {
582
+ const legacyHarness = makeHarness();
583
+ const legacyResult = run(
584
+ legacyHarness,
585
+ ["--sync-only", "--mapping-report", legacyHarness.report],
586
+ { FAKE_RSYNC_FAIL_SOURCE: "antigravity-rescue/conversations" },
587
+ );
588
+ const legacyMapping = readFileSync(legacyHarness.report, "utf8");
589
+ expect(legacyResult.status).not.toBe(0);
590
+ expect(legacyMapping).toContain("agy-legacy-pb\t");
591
+ expect(legacyMapping).toContain("sync-failed:23");
592
+ expect(legacyMapping).not.toContain(
593
+ "agy-legacy-pb\tmac:~/Downloads/antigravity-rescue/conversations/\t"
594
+ + join(legacyHarness.home, "machine-data", "macbook-agy", "legacy-pb")
595
+ + "/\t"
596
+ + join(legacyHarness.home, "machine-data", "macbook-agy", "legacy-pb")
597
+ + "/\tsource-absent",
598
+ );
599
+
600
+ const probeHarness = makeHarness();
601
+ const probeResult = run(
602
+ probeHarness,
603
+ ["--sync-only", "--mapping-report", probeHarness.report],
604
+ { FAKE_SSH_FAIL_PROBE: "$HOME/.codex" },
605
+ );
606
+ expect(probeResult.status).not.toBe(0);
607
+ expect(readFileSync(probeHarness.report, "utf8")).toContain("probe-failed:255");
608
+ expect(
609
+ rsyncCalls(probeHarness).some((call) =>
610
+ call.sourceArg === "mac:~/.codex/session_index.jsonl"
611
+ ),
612
+ ).toBe(false);
613
+
614
+ const wrongTypeHarness = makeHarness();
615
+ const wrongTypeIndex = join(
616
+ wrongTypeHarness.remoteHome,
617
+ ".codex",
618
+ "session_index.jsonl",
619
+ );
620
+ renameSync(wrongTypeIndex, wrongTypeIndex + ".saved");
621
+ mkdirSync(wrongTypeIndex);
622
+ const wrongTypeResult = syncOnly(wrongTypeHarness);
623
+ const wrongTypeMapping = readFileSync(wrongTypeHarness.report, "utf8");
624
+ expect(wrongTypeResult.status).not.toBe(0);
625
+ expect(wrongTypeMapping).toContain("probe-failed:3");
626
+ expect(wrongTypeMapping).not.toContain(
627
+ "codex-session-index\tmac:~/.codex/session_index.jsonl\t"
628
+ + join(wrongTypeHarness.home, ".codex", "session_index.macbook.jsonl")
629
+ + "\t"
630
+ + join(wrongTypeHarness.home, ".codex", "session_index.jsonl")
631
+ + "\tsource-absent",
632
+ );
633
+
634
+ const absentHarness = makeHarness();
635
+ const absentIndex = join(absentHarness.remoteHome, ".codex", "session_index.jsonl");
636
+ renameSync(absentIndex, absentIndex + ".saved");
637
+ const absentResult = syncOnly(absentHarness);
638
+ expect(absentResult.status).toBe(0);
639
+ expect(readFileSync(absentHarness.report, "utf8")).toContain(
640
+ "codex-session-index\tmac:~/.codex/session_index.jsonl\t"
641
+ + join(absentHarness.home, ".codex", "session_index.macbook.jsonl")
642
+ + "\t"
643
+ + join(absentHarness.home, ".codex", "session_index.jsonl")
644
+ + "\tsource-absent",
645
+ );
646
+ }, TEST_TIMEOUT_MS);
647
+
648
+ it("surfaces mapping append failures without installing a report or ingesting", () => {
649
+ const harness = makeHarness();
650
+ const result = run(
651
+ harness,
652
+ ["--sync-only", "--mapping-report", harness.report],
653
+ { FAKE_BREAK_MAPPING_TMP: harness.report },
654
+ );
655
+
656
+ expect(result.status).not.toBe(0);
657
+ expect(result.stdout + result.stderr).toContain("sync-only 映射报告追加失败");
658
+ expect(existsSync(harness.report)).toBe(false);
659
+ expect(existsSync(harness.ingestMarker)).toBe(false);
660
+ }, TEST_TIMEOUT_MS);
661
+
662
+ it("marks files pending when a live source changes after inventory", () => {
663
+ const liveSourceHarness = makeHarness();
664
+ const liveSourceResult = run(
665
+ liveSourceHarness,
666
+ ["--sync-only", "--mapping-report", liveSourceHarness.report],
667
+ { FAKE_RSYNC_MUTATE_ON_VERIFY_SOURCE: ".claude/projects/" },
668
+ );
669
+ const liveSourceRows = readFileSync(liveSourceHarness.report, "utf8")
670
+ .trim()
671
+ .split("\n")
672
+ .slice(1)
673
+ .map((line) => line.split("\t"))
674
+ .filter(([sourceKind]) => sourceKind === "claude-code");
675
+ expect(liveSourceResult.status).not.toBe(0);
676
+ expect(liveSourceRows.some((fields) => fields[4] === "pending:1")).toBe(true);
677
+ expect(liveSourceRows.some((fields) => fields[4] === "verified")).toBe(false);
678
+ }, TEST_TIMEOUT_MS);
679
+ });