@cortexkit/opencode-magic-context 0.49.7 → 0.49.9

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 (252) hide show
  1. package/dist/agents/hidden-agent-registrations.d.ts +5 -3
  2. package/dist/agents/hidden-agent-registrations.d.ts.map +1 -1
  3. package/dist/auto-search-worker.js +6 -6
  4. package/dist/compaction-marker-candidates-worker.js +2 -2
  5. package/dist/{compaction-marker-candidates-a0edbqrr.js → compaction-marker-candidates-xxz35vwp.js} +3 -3
  6. package/dist/config/schema/agent-overrides.d.ts +13 -13
  7. package/dist/config/schema/magic-context.d.ts +500 -500
  8. package/dist/{conflict-warning-hook-myk5hbt9.js → conflict-warning-hook-w3crzrar.js} +8 -8
  9. package/dist/{context-ffr7e0g7.js → context-ey3ap3cc.js} +81 -53
  10. package/dist/{derive-budgets-j4ry8j8n.js → derive-budgets-3nbxsyss.js} +2 -2
  11. package/dist/embedding-backfill-3h2m5n0q.js +21 -0
  12. package/dist/embedding-worker-process.js +6 -2
  13. package/dist/embedding-worker.js +6 -5
  14. package/dist/features/magic-context/compaction-marker-candidates.d.ts.map +1 -1
  15. package/dist/features/magic-context/dreamer/cron.d.ts +2 -0
  16. package/dist/features/magic-context/dreamer/cron.d.ts.map +1 -1
  17. package/dist/features/magic-context/dreamer/provider-output-failure.d.ts +1 -0
  18. package/dist/features/magic-context/dreamer/provider-output-failure.d.ts.map +1 -1
  19. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  20. package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
  21. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  22. package/dist/features/magic-context/migration-worker-client.d.ts.map +1 -1
  23. package/dist/features/magic-context/primer-clustering.d.ts.map +1 -1
  24. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  25. package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts +1 -1
  26. package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts.map +1 -1
  27. package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -1
  28. package/dist/features/magic-context/smart-notes/wake-plane.d.ts.map +1 -1
  29. package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
  30. package/dist/history-owner-ty29fz0f.js +244 -0
  31. package/dist/hooks/auto-update-checker/checker.d.ts.map +1 -1
  32. package/dist/hooks/magic-context/__fixtures__/tail-hygiene-refresh.d.ts +34 -0
  33. package/dist/hooks/magic-context/__fixtures__/tail-hygiene-refresh.d.ts.map +1 -0
  34. package/dist/hooks/magic-context/auto-search-worker-client.d.ts.map +1 -1
  35. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  37. package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
  38. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts +1 -0
  39. package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
  40. package/dist/hooks/magic-context/dropped-input-guard.d.ts.map +1 -1
  41. package/dist/hooks/magic-context/edit-marker.d.ts +2 -0
  42. package/dist/hooks/magic-context/edit-marker.d.ts.map +1 -1
  43. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +2 -0
  44. package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
  45. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/module-transport.d.ts +1 -0
  48. package/dist/hooks/magic-context/module-transport.d.ts.map +1 -1
  49. package/dist/hooks/magic-context/provider-visible-parts.d.ts +10 -4
  50. package/dist/hooks/magic-context/provider-visible-parts.d.ts.map +1 -1
  51. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
  52. package/dist/hooks/magic-context/read-session-chunk.d.ts +8 -4
  53. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/rust-mode-transform.d.ts +1 -0
  55. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  56. package/dist/hooks/magic-context/rust-refusal-recovery.d.ts.map +1 -1
  57. package/dist/hooks/magic-context/supersession-reclaim.d.ts +5 -3
  58. package/dist/hooks/magic-context/supersession-reclaim.d.ts.map +1 -1
  59. package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts +18 -0
  60. package/dist/hooks/magic-context/tail-hygiene-output-count.d.ts.map +1 -0
  61. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts +5 -1
  62. package/dist/hooks/magic-context/tail-hygiene-walk.d.ts.map +1 -1
  63. package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
  64. package/dist/hooks/magic-context/tool-reclaim.d.ts +5 -2
  65. package/dist/hooks/magic-context/tool-reclaim.d.ts.map +1 -1
  66. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +1 -0
  67. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  68. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  69. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts +5 -1
  70. package/dist/hooks/magic-context/unresolved-history-boundary.d.ts.map +1 -1
  71. package/dist/hooks/magic-context/wrapup-orchestrator.d.ts.map +1 -1
  72. package/dist/{index-g8qbdb03.js → index-0jz47061.js} +6 -3
  73. package/dist/{index-wq16ahsn.js → index-0x9cn9w1.js} +8 -8
  74. package/dist/{index-4mjhqadz.js → index-150zz6fh.js} +1 -1
  75. package/dist/{index-n7kwfw2r.js → index-16vwdyy5.js} +7 -7
  76. package/dist/{index-rwmpkss5.js → index-21919gcq.js} +4 -4
  77. package/dist/{index-5tbvdff4.js → index-3403gbzj.js} +200 -135
  78. package/dist/{index-0gyq3djm.js → index-4hb8nt93.js} +3 -3
  79. package/dist/{index-ebnngykq.js → index-6k86es2p.js} +142 -27
  80. package/dist/{index-ax2jhztn.js → index-7bjgyaj1.js} +4 -4
  81. package/dist/{index-h2wc01qk.js → index-9jvab89d.js} +2 -2
  82. package/dist/{index-w6bd03dc.js → index-a43xq1pg.js} +5 -5
  83. package/dist/{index-tqf7yg27.js → index-a4b0gbyg.js} +1 -1
  84. package/dist/{index-j5hce1ab.js → index-a865mj02.js} +5 -5
  85. package/dist/{index-37q80veb.js → index-angx1s0k.js} +4 -3
  86. package/dist/{index-z1tjp257.js → index-b64n4d0h.js} +1 -1
  87. package/dist/{index-gbmqa9x9.js → index-bmwfzz28.js} +9 -6
  88. package/dist/{index-tmtty2x5.js → index-f8cn4xqa.js} +290 -61
  89. package/dist/{index-j58gqrn2.js → index-ffa8x2as.js} +31 -24
  90. package/dist/{index-1bt88epp.js → index-g7jkrz0x.js} +36 -16
  91. package/dist/{index-qx53vezw.js → index-gjvjh960.js} +1 -1
  92. package/dist/{index-w23dh319.js → index-jw4gbfkv.js} +1 -1
  93. package/dist/index-knvkbfvh.js +25 -0
  94. package/dist/{index-vkbqdnkj.js → index-kvw6xew3.js} +6 -3
  95. package/dist/{index-rzmjkdd6.js → index-mp2kghkv.js} +3 -27
  96. package/dist/{index-nsjyysj0.js → index-mvvephtj.js} +5 -1
  97. package/dist/{index-9yyqq3mm.js → index-n78avt2p.js} +1 -1
  98. package/dist/{index-w6vr754t.js → index-nenz4gpb.js} +13 -9
  99. package/dist/{index-vt4sf4ep.js → index-pgy3h49n.js} +4 -4
  100. package/dist/{v2/server-1rfgbjfn.js → index-q28hsbpg.js} +15 -3
  101. package/dist/{index-a8acx4gc.js → index-q76br5zn.js} +3 -3
  102. package/dist/{index-sf94at64.js → index-rg1cezmj.js} +22 -22
  103. package/dist/{index-sh91t19a.js → index-s178h9z8.js} +4 -3
  104. package/dist/{index-4btknbqh.js → index-swgpe402.js} +48 -38
  105. package/dist/{index-k6xvbj2e.js → index-w28y7d0z.js} +2 -0
  106. package/dist/{index-j8epsc0g.js → index-wafzvyhg.js} +33 -10
  107. package/dist/{index-n5a170gs.js → index-wpwpn7nj.js} +166 -63
  108. package/dist/{index-tagss15p.js → index-x57ep4fp.js} +124 -63
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +84 -79
  111. package/dist/{logger-ewak5q1s.js → logger-wn328tfg.js} +1 -1
  112. package/dist/{message-index-rqtse28y.js → message-index-6r1x9cqh.js} +16 -16
  113. package/dist/{message-index-bounded-04rycpx4.js → message-index-bounded-fskdyc81.js} +16 -16
  114. package/dist/{message-time-backfill-a5ytnp53.js → message-time-backfill-nb5hhnrt.js} +3 -3
  115. package/dist/migration-worker.js +11 -11
  116. package/dist/plugin/boot-quiet.d.ts.map +1 -1
  117. package/dist/plugin/dream-timer.d.ts.map +1 -1
  118. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  119. package/dist/plugin/rpc-handlers.d.ts +2 -0
  120. package/dist/plugin/rpc-handlers.d.ts.map +1 -1
  121. package/dist/{project-embedding-registry-k0sd9k7v.js → project-embedding-registry-vy7sv9jt.js} +11 -11
  122. package/dist/raw-ordinal-warmup-worker.js +6 -6
  123. package/dist/{read-session-chunk-h1btx938.js → read-session-chunk-zgpvs423.js} +11 -11
  124. package/dist/{read-session-raw-vdf4wh78.js → read-session-raw-gm6xj30v.js} +3 -3
  125. package/dist/recomp-orchestrator-77xc8wpe.js +60 -0
  126. package/dist/{safe-notification-target-q0cyrx3x.js → safe-notification-target-jdynm677.js} +2 -2
  127. package/dist/{search-3rbdx6hw.js → search-72fkjwk2.js} +24 -24
  128. package/dist/{send-session-notification-2tp44tfa.js → send-session-notification-q8ngbap3.js} +6 -6
  129. package/dist/shared/hidden-zen-read.d.ts +24 -0
  130. package/dist/shared/hidden-zen-read.d.ts.map +1 -0
  131. package/dist/shared/history-owner.d.ts +12 -0
  132. package/dist/shared/history-owner.d.ts.map +1 -0
  133. package/dist/shared/off-thread-migration-clock.d.ts +8 -1
  134. package/dist/shared/off-thread-migration-clock.d.ts.map +1 -1
  135. package/dist/shared/reclaim-distance.d.ts +33 -0
  136. package/dist/shared/reclaim-distance.d.ts.map +1 -0
  137. package/dist/shared/redaction.d.ts.map +1 -1
  138. package/dist/shared/rpc-server.d.ts.map +1 -1
  139. package/dist/shared/sqlite.d.ts +2 -0
  140. package/dist/shared/sqlite.d.ts.map +1 -1
  141. package/dist/shared/stable-json.d.ts +7 -0
  142. package/dist/shared/stable-json.d.ts.map +1 -1
  143. package/dist/shared/tail-hygiene-json.d.ts +22 -0
  144. package/dist/shared/tail-hygiene-json.d.ts.map +1 -0
  145. package/dist/shared/transcript.d.ts +5 -0
  146. package/dist/shared/transcript.d.ts.map +1 -1
  147. package/dist/shared/user-facing-codes.d.ts +2 -2
  148. package/dist/{sqlite-j3tvg8r0.js → sqlite-4pqyynrs.js} +3 -1
  149. package/dist/{storage-memory-8168bgef.js → storage-memory-j3v3hc83.js} +2 -2
  150. package/dist/{storage-tags-61z5j2f9.js → storage-tags-35m4gms2.js} +5 -5
  151. package/dist/{transform-postprocess-phase-7qts7h54.js → transform-postprocess-phase-r8d406j0.js} +30 -30
  152. package/dist/v2/auto-search-worker.js +6 -6
  153. package/dist/v2/{compaction-marker-candidates-6nypjkpf.js → compaction-marker-candidates-a15w3mqh.js} +3 -3
  154. package/dist/v2/compaction-marker-candidates-worker.js +2 -2
  155. package/dist/v2/{context-xq4rtywr.js → context-z2yagwy4.js} +293 -91
  156. package/dist/v2/{derive-budgets-enckmg7y.js → derive-budgets-0rmpmxjw.js} +3 -3
  157. package/dist/v2/embedding-backfill-vr7wdtrf.js +20 -0
  158. package/dist/v2/embedding-worker-process.js +6 -2
  159. package/dist/v2/embedding-worker.js +6 -5
  160. package/dist/v2/hidden-completion.d.ts.map +1 -1
  161. package/dist/v2/history-owner-2cr9py37.js +243 -0
  162. package/dist/v2/hooks/context.d.ts.map +1 -1
  163. package/dist/v2/hooks/hidden-child.d.ts +2 -2
  164. package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
  165. package/dist/v2/hooks/store.d.ts +1 -0
  166. package/dist/v2/hooks/store.d.ts.map +1 -1
  167. package/dist/v2/{logger-pj02s7sr.js → logger-te6e1j72.js} +1 -1
  168. package/dist/v2/{message-index-8e5z2xx8.js → message-index-9ezq6wze.js} +16 -16
  169. package/dist/v2/{message-index-bounded-5vh1h2g7.js → message-index-bounded-rqc603f2.js} +16 -16
  170. package/dist/v2/{message-time-backfill-2z365239.js → message-time-backfill-rz1pnpaj.js} +3 -3
  171. package/dist/v2/migration-worker.js +11 -11
  172. package/dist/v2/{project-embedding-registry-b77awytr.js → project-embedding-registry-ja23aygk.js} +11 -11
  173. package/dist/v2/raw-ordinal-warmup-worker.js +6 -6
  174. package/dist/v2/{read-session-chunk-4sat83cx.js → read-session-chunk-7f87tg2q.js} +11 -11
  175. package/dist/v2/{read-session-raw-a3hw9jsp.js → read-session-raw-h4azh85b.js} +3 -3
  176. package/dist/v2/recomp-orchestrator-s5tdpsbs.js +59 -0
  177. package/dist/v2/{safe-notification-target-y3p1hce9.js → safe-notification-target-936374xx.js} +2 -2
  178. package/dist/v2/search-2td1b1wy.js +46 -0
  179. package/dist/v2/{send-session-notification-ppgc8qdz.js → send-session-notification-6n7chhyp.js} +6 -6
  180. package/dist/v2/{server-v4fwha43.js → server-23znwjqk.js} +48 -38
  181. package/dist/v2/{server-nfan6zb6.js → server-2hxypdx5.js} +31 -24
  182. package/dist/v2/{server-ras2sxnc.js → server-44ryn9rb.js} +9 -6
  183. package/dist/v2/{server-fw31krgq.js → server-4easnf78.js} +19 -19
  184. package/dist/v2/{server-d6g4whc2.js → server-4qr18rfg.js} +3 -3
  185. package/dist/v2/{server-sy4b1sra.js → server-4rs8sm06.js} +5 -5
  186. package/dist/v2/{server-jdwd03ep.js → server-4zwx20yg.js} +7 -7
  187. package/dist/v2/{server-brhj8qtd.js → server-63ha7f0f.js} +3 -27
  188. package/dist/v2/{server-3t0q2cqx.js → server-7dv9wt9r.js} +1 -1
  189. package/dist/v2/{server-cw6521wn.js → server-7e087rvk.js} +2 -0
  190. package/dist/v2/{server-6byqfbqf.js → server-89fcbe37.js} +36 -16
  191. package/dist/v2/{server-hb6xhh9q.js → server-988cqjme.js} +6 -3
  192. package/dist/v2/{server-fpqe39as.js → server-9a6bwc12.js} +4 -4
  193. package/dist/v2/{server-t4k4qexw.js → server-9e5r8y60.js} +5 -1
  194. package/dist/v2/{server-qcw43339.js → server-ak7w74j9.js} +4 -4
  195. package/dist/v2/{server-dd0nja67.js → server-bx59ezg6.js} +4 -3
  196. package/dist/v2/{server-mv1w7t6z.js → server-c9w52qss.js} +99 -43
  197. package/dist/v2/{server-676xw7at.js → server-ckrb5rm8.js} +1 -1
  198. package/dist/{index-w4mw92w3.js → v2/server-cxsr0ng6.js} +15 -3
  199. package/dist/v2/{server-hcvcxzx7.js → server-f27he3j1.js} +5 -5
  200. package/dist/v2/{server-gtv9wbhq.js → server-gc8x2xdb.js} +144 -63
  201. package/dist/v2/{server-t528t8qm.js → server-hn9fb3v0.js} +2 -2
  202. package/dist/v2/{server-w3zeywp1.js → server-kmapq3v0.js} +289 -60
  203. package/dist/v2/server-knvkbfvh.js +25 -0
  204. package/dist/v2/{server-9yyqq3mm.js → server-n78avt2p.js} +1 -1
  205. package/dist/v2/{server-kdrezdy0.js → server-njnx39q2.js} +6 -3
  206. package/dist/v2/{server-x08d1xf3.js → server-npm52h2q.js} +4 -3
  207. package/dist/v2/{server-vb7pbd9p.js → server-nveratm5.js} +1 -1
  208. package/dist/v2/{server-kzns2hbz.js → server-s6jqh8bj.js} +1 -1
  209. package/dist/v2/{server-j8epsc0g.js → server-wafzvyhg.js} +33 -10
  210. package/dist/v2/{server-7ekna9zs.js → server-xqf2d2mg.js} +2 -2
  211. package/dist/v2/{server-7srtwsa4.js → server-z0rjemg1.js} +9 -9
  212. package/dist/v2/{server-wkdgjjch.js → server-zrwaj29a.js} +2 -2
  213. package/dist/v2/server.js +7 -6
  214. package/dist/v2/{sqlite-j3tvg8r0.js → sqlite-4pqyynrs.js} +3 -1
  215. package/dist/v2/{storage-memory-8168bgef.js → storage-memory-j3v3hc83.js} +2 -2
  216. package/dist/v2/{storage-tags-j2fzq3sw.js → storage-tags-c4zfcxv4.js} +5 -5
  217. package/dist/v2/store-reader.d.ts.map +1 -1
  218. package/dist/v2/{wrapup-orchestrator-s92ebfzv.js → wrapup-orchestrator-wg8dmmm9.js} +38 -35
  219. package/dist/wrapup-orchestrator-b1z99yg5.js +47 -0
  220. package/package.json +1 -1
  221. package/src/agents/hidden-agent-registrations.ts +22 -4
  222. package/src/config/compaction-accessor-guard.test.ts +3 -0
  223. package/src/features/magic-context/dreamer/cron.ts +8 -0
  224. package/src/shared/hidden-zen-read.test.ts +99 -0
  225. package/src/shared/hidden-zen-read.ts +88 -0
  226. package/src/shared/history-owner.test.ts +60 -0
  227. package/src/shared/history-owner.ts +43 -0
  228. package/src/shared/host-stall-profiler-node.ts +3 -1
  229. package/src/shared/host-stall-profiler.ts +3 -1
  230. package/src/shared/off-thread-migration-clock.test.ts +80 -10
  231. package/src/shared/off-thread-migration-clock.ts +37 -13
  232. package/src/shared/reclaim-distance.test.ts +111 -0
  233. package/src/shared/reclaim-distance.ts +91 -0
  234. package/src/shared/redaction.test.ts +16 -0
  235. package/src/shared/redaction.ts +8 -1
  236. package/src/shared/root-async-context.probe.mjs +36 -0
  237. package/src/shared/root-async-context.test.ts +49 -0
  238. package/src/shared/rpc-server.ts +27 -23
  239. package/src/shared/sqlite-busy-budget-review.test.ts +291 -0
  240. package/src/shared/sqlite-foreground-wait.test.ts +253 -1
  241. package/src/shared/sqlite.ts +55 -14
  242. package/src/shared/stable-json.ts +56 -14
  243. package/src/shared/tail-hygiene-json.test.ts +117 -0
  244. package/src/shared/tail-hygiene-json.ts +217 -0
  245. package/src/shared/transcript.ts +7 -0
  246. package/src/shared/user-facing-codes.ts +2 -2
  247. package/dist/embedding-backfill-re16xncd.js +0 -21
  248. package/dist/recomp-orchestrator-trcgmm23.js +0 -60
  249. package/dist/v2/embedding-backfill-xd9ygzgd.js +0 -20
  250. package/dist/v2/recomp-orchestrator-n11zv1f1.js +0 -59
  251. package/dist/v2/search-mvgqtkkz.js +0 -46
  252. package/dist/wrapup-orchestrator-df61jmz9.js +0 -47
@@ -1,4 +1,4 @@
1
- import { expect, test } from "bun:test";
1
+ import { expect, spyOn, test } from "bun:test";
2
2
  import { rmSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
@@ -113,6 +113,220 @@ for (const holdMs of [1000, 2500]) {
113
113
  }, 30_000);
114
114
  }
115
115
 
116
+ for (const holdMs of [1000, 2500]) {
117
+ test(`slow uncontended SQL preserves admission for a ${holdMs}ms autocommit lock`, async () => {
118
+ const { db, path, close } = fixture();
119
+ let locker: SqliteWriteLocker | undefined;
120
+ let served = false;
121
+ let refusals = 0;
122
+ const output = {
123
+ messages: [
124
+ {
125
+ info: { id: "u", sessionID: "slow", role: "user" },
126
+ parts: [{ type: "text", text: "raw" }],
127
+ },
128
+ ],
129
+ };
130
+ const handler = createMessagesTransformHandler({
131
+ onStorageBusyRefusal: async () => {
132
+ refusals++;
133
+ },
134
+ magicContext: {
135
+ "experimental.chat.messages.transform": async (_input, result) => {
136
+ // Spend three seconds inside successful SQL, not between writes.
137
+ // Recursive work keeps this independent of CPU speed and UDF APIs.
138
+ const cte =
139
+ "WITH RECURSIVE n(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM n WHERE x<1000000)";
140
+ const slowWrite = db.prepare(
141
+ `${cte} INSERT INTO result SELECT sum(x) FROM n RETURNING value`,
142
+ );
143
+ const slowRead = db.prepare(`${cte} SELECT sum(x) FROM n`);
144
+ const started = performance.now();
145
+ do {
146
+ slowWrite.all();
147
+ slowRead.all();
148
+ } while (performance.now() - started < 3000);
149
+ locker = await startSqliteWriteLocker(path, holdMs);
150
+ db.prepare("INSERT INTO result VALUES ('managed')").run();
151
+ (result.messages[0].parts[0] as { text: string }).text = "managed";
152
+ },
153
+ },
154
+ });
155
+ try {
156
+ const pass = handler({}, output as Parameters<typeof handler>[1]).then(() => {
157
+ served = true;
158
+ });
159
+ if (holdMs === 1000) {
160
+ await pass;
161
+ expect(served).toBe(true);
162
+ expect(refusals).toBe(0);
163
+ expect(output.messages[0].parts[0].text).toBe("managed");
164
+ } else {
165
+ await expect(pass).rejects.toBeInstanceOf(StorageBusyRefusalError);
166
+ expect(served).toBe(false);
167
+ expect(refusals).toBe(1);
168
+ expect(output.messages[0].parts[0].text).toBe("raw");
169
+ }
170
+ expect(
171
+ db.prepare("SELECT count(*) AS n FROM result WHERE value = 'managed'").get(),
172
+ ).toEqual({ n: holdMs === 1000 ? 1 : 0 });
173
+ } finally {
174
+ if (locker) expect(await locker.exited).toBe(0);
175
+ close();
176
+ }
177
+ }, 30_000);
178
+ }
179
+
180
+ test("BUSY autocommit probes do not double-apply INSERT OR IGNORE, UPSERT or RETURNING", async () => {
181
+ const { db, path, close } = fixture();
182
+ db.exec(
183
+ "CREATE TABLE counter(id INTEGER PRIMARY KEY, n INTEGER); INSERT INTO counter VALUES (1, 0)",
184
+ );
185
+ const forms = [
186
+ ["INSERT OR IGNORE INTO counter VALUES (2, 1)", "run"],
187
+ ["INSERT INTO counter VALUES (1, 1) ON CONFLICT(id) DO UPDATE SET n = n + 1", "run"],
188
+ ["UPDATE counter SET n = n + 1 WHERE id = 1 RETURNING n", "get"],
189
+ [
190
+ "INSERT INTO counter VALUES (1, 1) ON CONFLICT(id) DO UPDATE SET n = n + 1 RETURNING n",
191
+ "all",
192
+ ],
193
+ ] as const;
194
+ try {
195
+ for (const [sql, method] of forms) {
196
+ const blocker = new Database(path);
197
+ blocker.exec("BEGIN IMMEDIATE");
198
+ db.exec("PRAGMA busy_timeout=0");
199
+ const before = db.prepare("SELECT * FROM counter ORDER BY id").all();
200
+ try {
201
+ expect(() => db.prepare(sql)[method]()).toThrow("locked");
202
+ expect(db.prepare("SELECT * FROM counter ORDER BY id").all()).toEqual(before);
203
+ expect(db.inTransaction).toBe(false);
204
+ } finally {
205
+ blocker.exec("ROLLBACK");
206
+ blocker.close();
207
+ }
208
+ const locker = await startSqliteWriteLocker(path, 100);
209
+ try {
210
+ await withSqliteTransformPass(() => db.prepare(sql)[method]());
211
+ } finally {
212
+ expect(await locker.exited).toBe(0);
213
+ }
214
+ }
215
+ expect(db.prepare("SELECT * FROM counter ORDER BY id").all()).toEqual([
216
+ { id: 1, n: 3 },
217
+ { id: 2, n: 1 },
218
+ ]);
219
+ } finally {
220
+ close();
221
+ }
222
+ }, 30_000);
223
+
224
+ test("many contended autocommit writes share at most two seconds of lock waiting", async () => {
225
+ const { db, path, close } = fixture();
226
+ const blocker = new Database(path);
227
+ blocker.exec("BEGIN IMMEDIATE");
228
+ const timeouts: number[] = [];
229
+ const nativeExec = db.exec.bind(db);
230
+ const exec = spyOn(db, "exec").mockImplementation((sql) => {
231
+ const timeout = /^PRAGMA busy_timeout=(\d+)$/.exec(sql);
232
+ if (timeout) timeouts.push(Number(timeout[1]));
233
+ return nativeExec(sql);
234
+ });
235
+ try {
236
+ await withSqliteTransformPass(() => {
237
+ // Use real BUSY failures but a controlled accounting clock: each
238
+ // retry costs 400ms regardless of runner scheduling. The deadline
239
+ // keeps the real waits short without hiding lease exhaustion.
240
+ guardSqliteTransformPass({ assert() {}, remainingMs: () => 10 });
241
+ let now = 0;
242
+ const clock = spyOn(performance, "now").mockImplementation(() => (now += 400));
243
+ try {
244
+ for (let i = 0; i < 8; i++) {
245
+ expect(() => db.prepare("INSERT INTO result VALUES ('one')").run()).toThrow(
246
+ SqliteAcquisitionBusyError,
247
+ );
248
+ }
249
+ } finally {
250
+ clock.mockRestore();
251
+ }
252
+ // Five charged retries exhaust 2000ms. All later retries must have
253
+ // zero timeout even though the deadline still offers another 10ms.
254
+ expect(timeouts).toEqual([
255
+ ...Array.from({ length: 5 }, () => [0, 10, 5000]).flat(),
256
+ ...Array.from({ length: 3 }, () => [0, 0, 5000]).flat(),
257
+ ]);
258
+ blocker.exec("ROLLBACK");
259
+ db.prepare("INSERT INTO result VALUES ('uncontended')").run();
260
+ });
261
+ expect(db.prepare("SELECT * FROM result").all()).toEqual([{ value: "uncontended" }]);
262
+ } finally {
263
+ exec.mockRestore();
264
+ if (blocker.inTransaction) blocker.exec("ROLLBACK");
265
+ blocker.close();
266
+ close();
267
+ }
268
+ }, 30_000);
269
+
270
+ test("an exec script charges its single attempt without a zero-wait probe", () => {
271
+ const { db, path, close } = fixture();
272
+ const blocker = new Database(path);
273
+ const timeouts: number[] = [];
274
+ const nativeExec = db.exec.bind(db);
275
+ const exec = spyOn(db, "exec").mockImplementation((sql) => {
276
+ const timeout = /^PRAGMA busy_timeout=(\d+)$/.exec(sql);
277
+ if (timeout) timeouts.push(Number(timeout[1]));
278
+ return nativeExec(sql);
279
+ });
280
+ try {
281
+ withSqliteTransformPass(() => {
282
+ let now = 0;
283
+ const clock = spyOn(performance, "now").mockImplementation(() => (now += 2500));
284
+ try {
285
+ db.exec(
286
+ "INSERT INTO result VALUES ('prefix'); INSERT INTO result VALUES ('suffix')",
287
+ );
288
+ } finally {
289
+ clock.mockRestore();
290
+ }
291
+ blocker.exec("BEGIN IMMEDIATE");
292
+ expect(() => db.prepare("INSERT INTO result VALUES ('blocked')").run()).toThrow(
293
+ SqliteAcquisitionBusyError,
294
+ );
295
+ });
296
+ expect(timeouts).toEqual([2000, 5000, 0, 0, 5000]);
297
+ expect(db.prepare("SELECT * FROM result").all()).toEqual([
298
+ { value: "prefix" },
299
+ { value: "suffix" },
300
+ ]);
301
+ } finally {
302
+ exec.mockRestore();
303
+ if (blocker.inTransaction) blocker.exec("ROLLBACK");
304
+ blocker.close();
305
+ close();
306
+ }
307
+ });
308
+
309
+ test("an explicit transaction keeps its timeout and never probes or retries", () => {
310
+ const { db, path, close } = fixture();
311
+ const other = new Database(path);
312
+ db.exec("PRAGMA busy_timeout=0; BEGIN; SELECT * FROM result");
313
+ other.exec("INSERT INTO result VALUES ('other')");
314
+ const exec = spyOn(db, "exec");
315
+ try {
316
+ withSqliteTransformPass(() => {
317
+ expect(() => db.prepare("INSERT INTO result VALUES ('stale')").run()).toThrow("locked");
318
+ });
319
+ expect(exec).not.toHaveBeenCalled();
320
+ expect(db.inTransaction).toBe(true);
321
+ expect(db.prepare("PRAGMA busy_timeout").get()).toEqual({ timeout: 0 });
322
+ } finally {
323
+ exec.mockRestore();
324
+ if (db.inTransaction) db.exec("ROLLBACK");
325
+ other.close();
326
+ close();
327
+ }
328
+ });
329
+
116
330
  for (const mode of ["BEGIN", "autocommit"]) {
117
331
  test(`foreground ${mode} wait is capped by the pass deadline`, () => {
118
332
  const { db, path, close } = fixture();
@@ -138,3 +352,41 @@ for (const mode of ["BEGIN", "autocommit"]) {
138
352
  }
139
353
  });
140
354
  }
355
+
356
+ test("an autocommit exec script never replays a committed prefix after BUSY", () => {
357
+ const main = fixture();
358
+ const auxiliary = fixture();
359
+ const free = fixture();
360
+ try {
361
+ main.db.prepare("ATTACH DATABASE ? AS aux").run(auxiliary.path);
362
+ main.db.prepare("ATTACH DATABASE ? AS free").run(free.path);
363
+ auxiliary.db.exec("BEGIN IMMEDIATE");
364
+ withSqliteTransformPass(() => {
365
+ guardSqliteTransformPass({ assert() {}, remainingMs: () => 100 });
366
+ expect(() =>
367
+ main.db.exec(
368
+ "INSERT INTO main.result VALUES ('prefix'); INSERT INTO aux.result VALUES ('blocked')",
369
+ ),
370
+ ).toThrow(SqliteAcquisitionBusyError);
371
+ expect(() =>
372
+ main.db.exec(
373
+ "CREATE TABLE applied_once(id); INSERT INTO aux.result VALUES ('blocked')",
374
+ ),
375
+ ).toThrow(SqliteAcquisitionBusyError);
376
+ expect(() =>
377
+ main.db.exec(
378
+ "CREATE TABLE free.applied_once(id); INSERT INTO aux.result VALUES ('blocked')",
379
+ ),
380
+ ).toThrow(SqliteAcquisitionBusyError);
381
+ });
382
+ expect(main.db.prepare("SELECT * FROM main.result").all()).toEqual([{ value: "prefix" }]);
383
+ expect(
384
+ main.db.prepare("SELECT name FROM sqlite_schema WHERE name='applied_once'").all(),
385
+ ).toHaveLength(1);
386
+ } finally {
387
+ auxiliary.db.exec("ROLLBACK");
388
+ auxiliary.close();
389
+ main.close();
390
+ free.close();
391
+ }
392
+ });
@@ -39,7 +39,7 @@
39
39
  * `run()` → {changes,lastInsertRowid}) is identical and was verified directly.
40
40
  */
41
41
 
42
- import { AsyncLocalStorage } from "node:async_hooks";
42
+ import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
43
43
  import { statSync } from "node:fs";
44
44
 
45
45
  // Type import only — runtime is loaded dynamically below. @types/better-sqlite3
@@ -48,6 +48,16 @@ import { statSync } from "node:fs";
48
48
  // node:sqlite at runtime (both expose prepare/run/get/all/exec/close).
49
49
  import type BetterSqlite3 from "better-sqlite3";
50
50
 
51
+ // Capture the root before creating request-local AsyncLocalStorage scopes.
52
+ // Shared workers and timers must not inherit callbacks that reject stale
53
+ // database writes: those callbacks can retain an obsolete request's inputs.
54
+ const resourceRoot = new AsyncResource("magic-context:root");
55
+
56
+ /** Create host-owned resources without inheriting request-local state. */
57
+ export function inRootAsyncContext<T>(operation: () => T): T {
58
+ return resourceRoot.runInAsyncScope(operation);
59
+ }
60
+
51
61
  /**
52
62
  * Slow-write reporting is injected rather than imported: this module is also
53
63
  * executed directly by Node (the `node:sqlite` smoke in CI, Pi, Desktop), and
@@ -420,7 +430,9 @@ function installTransactionRouting(db: BetterSqlite3.Database, readonly: boolean
420
430
  !/^\s*(?:SELECT|EXPLAIN|PRAGMA|COMMIT|END|ROLLBACK|SAVEPOINT|RELEASE)\b/i.test(sql)
421
431
  ) {
422
432
  try {
423
- return withAutocommitTimeout(db, () => nativeExec(sql));
433
+ // exec can commit a script prefix before BUSY. Run it once;
434
+ // only prepared statements are safe to probe and retry.
435
+ return withAutocommitTimeout(db, () => nativeExec(sql), false);
424
436
  } finally {
425
437
  if (mayChangeTagIdentity(sql)) tagIdentityWriteGeneration += 1;
426
438
  }
@@ -587,7 +599,9 @@ function trackSqliteConnection(
587
599
 
588
600
  const TrackedDatabase = new Proxy(DatabaseImpl, {
589
601
  construct(target, args) {
590
- const db = Reflect.construct(target, args, target) as BetterSqlite3.Database;
602
+ const db = inRootAsyncContext(
603
+ () => Reflect.construct(target, args, target) as BetterSqlite3.Database,
604
+ );
591
605
  return trackSqliteConnection(db, args[0], args[1]);
592
606
  },
593
607
  }) as typeof BetterSqlite3;
@@ -1000,33 +1014,60 @@ function foregroundWaitLease() {
1000
1014
  : undefined;
1001
1015
  }
1002
1016
 
1003
- /** Bound implicit writer admission too, including prepared INSERT OR IGNORE and
1004
- * writes with RETURNING. Charge successful execution time conservatively: the
1005
- * native API cannot separate lock waiting from statement execution. Exhaustion
1006
- * switches to zero-wait acquisition, not a refusal when the writer is free. */
1007
- function withAutocommitTimeout<T>(db: Database, operation: () => T): T {
1017
+ /** Probe a prepared statement's writer lock without charging uncontended work
1018
+ * against the foreground lock-wait budget. An exec script may commit some of
1019
+ * its statements before failing, so it cannot be retried without duplicating
1020
+ * writes; conservatively charge its single attempt's full execution time. */
1021
+ function withAutocommitTimeout<T>(db: Database, operation: () => T, singleStatement = true): T {
1008
1022
  assertTransformWrite();
1009
1023
  const lease = foregroundWaitLease();
1010
1024
  if (isInTransaction(db)) return operation();
1011
1025
  const scoped = lease || backgroundWriterScope.getStore();
1012
1026
  const previous = scoped ? pragmaNumber(db, "busy_timeout") : null;
1013
- if (scoped)
1014
- db.exec(
1015
- `PRAGMA busy_timeout=${lease ? Math.floor(Math.min(lease.remainingWaitMs, lease.guard?.remainingMs() ?? Infinity)) : SHORT_BUSY_TIMEOUT_MS}`,
1016
- );
1017
1027
  const started = performance.now();
1018
1028
  let completed = false;
1019
- try {
1029
+ const execute = () => {
1020
1030
  const result = operation();
1021
1031
  completed = true;
1022
1032
  return result;
1033
+ };
1034
+ try {
1035
+ if (!scoped) return execute();
1036
+ if (singleStatement) {
1037
+ db.exec("PRAGMA busy_timeout=0");
1038
+ try {
1039
+ return execute();
1040
+ } catch (error) {
1041
+ if (!isTransientSqliteError(error) || isInTransaction(db)) throw error;
1042
+ }
1043
+ assertTransformWrite();
1044
+ }
1045
+ const timeout = Math.floor(
1046
+ Math.min(
1047
+ lease?.remainingWaitMs ?? SHORT_BUSY_TIMEOUT_MS,
1048
+ lease?.guard?.remainingMs() ?? Infinity,
1049
+ ),
1050
+ );
1051
+ db.exec(`PRAGMA busy_timeout=${timeout}`);
1052
+ const waitStarted = performance.now();
1053
+ try {
1054
+ return execute();
1055
+ } finally {
1056
+ // Deduct the prepared statement's contended retry or the exec
1057
+ // script's execution from the remaining foreground wait budget;
1058
+ // the native API cannot separate lock waiting from execution.
1059
+ if (lease)
1060
+ lease.remainingWaitMs = Math.max(
1061
+ 0,
1062
+ lease.remainingWaitMs - (performance.now() - waitStarted),
1063
+ );
1064
+ }
1023
1065
  } catch (error) {
1024
1066
  if (lease && isTransientSqliteError(error))
1025
1067
  throw new SqliteAcquisitionBusyError(error, "autocommit");
1026
1068
  throw error;
1027
1069
  } finally {
1028
1070
  const elapsed = performance.now() - started;
1029
- if (lease) lease.remainingWaitMs = Math.max(0, lease.remainingWaitMs - elapsed);
1030
1071
  if (previous !== null) db.exec(`PRAGMA busy_timeout=${previous}`);
1031
1072
  // Native autocommit does not expose the instant its lock was acquired.
1032
1073
  // Label the upper bound so a waiting statement is not blamed as a holder.
@@ -22,33 +22,33 @@ export function stableStringify(value: unknown, seen = new WeakSet<object>()): s
22
22
  // value's text once per enclosing level, so a large value N levels deep cost
23
23
  // N copies of itself.
24
24
  const pieces: string[] = [];
25
- writeStable(value, seen, pieces);
25
+ writeStable(value, seen, (piece) => pieces.push(piece));
26
26
  return pieces.join("");
27
27
  }
28
28
 
29
- function writeStable(value: unknown, seen: WeakSet<object>, pieces: string[]): void {
29
+ function writeStable(value: unknown, seen: WeakSet<object>, write: (piece: string) => void): void {
30
30
  if (value === undefined) {
31
- pieces.push("undefined");
31
+ write("undefined");
32
32
  return;
33
33
  }
34
34
  if (value === null || typeof value !== "object") {
35
- pieces.push(JSON.stringify(value) ?? String(value));
35
+ write(JSON.stringify(value) ?? String(value));
36
36
  return;
37
37
  }
38
38
  // Any object met a second time, shared or cyclic, is written as "[Circular]".
39
39
  if (seen.has(value)) {
40
- pieces.push('"[Circular]"');
40
+ write('"[Circular]"');
41
41
  return;
42
42
  }
43
43
  seen.add(value);
44
44
  if (Array.isArray(value)) {
45
- pieces.push("[");
45
+ write("[");
46
46
  for (let index = 0; index < value.length; index += 1) {
47
- if (index > 0) pieces.push(",");
47
+ if (index > 0) write(",");
48
48
  // A hole writes nothing between its commas, as joining a mapped array did.
49
- if (index in value) writeStable(value[index], seen, pieces);
49
+ if (index in value) writeStable(value[index], seen, write);
50
50
  }
51
- pieces.push("]");
51
+ write("]");
52
52
  return;
53
53
  }
54
54
  // Code-point sort (NOT localeCompare). Stable across runtimes/locales.
@@ -57,11 +57,53 @@ function writeStable(value: unknown, seen: WeakSet<object>, pieces: string[]): v
57
57
  if (a > b) return 1;
58
58
  return 0;
59
59
  });
60
- pieces.push("{");
60
+ // Native JSON can emit a small scalar-only object in one operation. Larger
61
+ // containers still stream; undefined and integer keys need the writer's
62
+ // non-native spelling/order. Bound chunks so hashing never builds a large JSON string.
63
+ if (
64
+ entries.length > 0 &&
65
+ entries.length <= 16 &&
66
+ entries.every(
67
+ ([key, child]) =>
68
+ key.length <= 4096 &&
69
+ !/^(0|[1-9]\d*)$/.test(key) &&
70
+ (child === null ||
71
+ typeof child === "number" ||
72
+ typeof child === "boolean" ||
73
+ (typeof child === "string" && child.length <= 4096)),
74
+ )
75
+ ) {
76
+ write(JSON.stringify(Object.fromEntries(entries)));
77
+ return;
78
+ }
79
+ write("{");
61
80
  entries.forEach(([key, child], index) => {
62
- if (index > 0) pieces.push(",");
63
- pieces.push(JSON.stringify(key), ":");
64
- writeStable(child, seen, pieces);
81
+ if (index > 0) write(",");
82
+ write(JSON.stringify(key));
83
+ write(":");
84
+ writeStable(child, seen, write);
65
85
  });
66
- pieces.push("}");
86
+ write("}");
87
+ }
88
+
89
+ /** The existing UTF-16 FNV fingerprint, without retaining the serialized JSON. */
90
+ export function stableStringifyHash(value: unknown, prefix = ""): string {
91
+ const sink = jsonHashSink(prefix);
92
+ writeStable(value, new WeakSet(), sink.write);
93
+ return sink.digest();
94
+ }
95
+
96
+ /** Hash the same code units as the content memo, including lone surrogates. */
97
+ export function jsonHashSink(prefix = ""): {
98
+ write: (piece: string) => void;
99
+ digest: () => string;
100
+ } {
101
+ let hash = 0x811c9dc5;
102
+ const write = (piece: string): void => {
103
+ for (let index = 0; index < piece.length; index++) {
104
+ hash = Math.imul(hash ^ piece.charCodeAt(index), 0x01000193);
105
+ }
106
+ };
107
+ write(prefix);
108
+ return { write, digest: () => (hash >>> 0).toString(16).padStart(8, "0") };
67
109
  }
@@ -0,0 +1,117 @@
1
+ import { expect, test } from "bun:test";
2
+ import { jsonHashSink, stableStringify, stableStringifyHash } from "./stable-json";
3
+ import { piJsonHash, TailHygieneJsonMemo } from "./tail-hygiene-json";
4
+
5
+ function hash(text: string): string {
6
+ const sink = jsonHashSink("excluded\0");
7
+ sink.write(text);
8
+ return sink.digest();
9
+ }
10
+
11
+ function piStringify(value: unknown): string {
12
+ const seen = new Set<object>();
13
+ try {
14
+ return (
15
+ JSON.stringify(value, (_key, current) => {
16
+ if (!current || typeof current !== "object" || Array.isArray(current))
17
+ return current;
18
+ if (seen.has(current)) return "[Circular]";
19
+ seen.add(current);
20
+ return Object.fromEntries(
21
+ Object.entries(current).sort(([a], [b]) => a.localeCompare(b)),
22
+ );
23
+ }) ?? ""
24
+ );
25
+ } catch {
26
+ return "";
27
+ }
28
+ }
29
+
30
+ test("streamed excluded fingerprints equal both original serializers on randomized values", () => {
31
+ let state = 704;
32
+ const random = (n: number): number => {
33
+ state = (Math.imul(state, 1664525) + 1013904223) | 0;
34
+ return (state >>> 0) % n;
35
+ };
36
+ const leaves = [
37
+ undefined,
38
+ null,
39
+ -0,
40
+ NaN,
41
+ Infinity,
42
+ 1e-7,
43
+ 1e23,
44
+ false,
45
+ "\ud800",
46
+ "é😀\n\u2028",
47
+ '"\\',
48
+ ];
49
+ const generate = (depth: number): unknown => {
50
+ if (!depth || random(3) === 0) return leaves[random(leaves.length)];
51
+ if (random(2)) {
52
+ const array = new Array(4);
53
+ array[0] = generate(depth - 1);
54
+ array[2] = undefined;
55
+ array[3] = generate(depth - 1);
56
+ return array;
57
+ }
58
+ const value: Record<string, unknown> = {};
59
+ const keys = ["10", "2", "Z", "ä", "a", "e\u0301", "é"];
60
+ for (let i = 0; i < 4; i++) value[keys[random(keys.length)]] = generate(depth - 1);
61
+ if (random(5) === 0) value.self = value;
62
+ return value;
63
+ };
64
+ const shared = { a: undefined, z: "shared" };
65
+ const cycle: unknown[] = [];
66
+ cycle.push(cycle);
67
+ const samples: unknown[] = [
68
+ cycle,
69
+ { a: shared, b: shared },
70
+ 1n,
71
+ new Date(0),
72
+ { toJSON: () => "date" },
73
+ ];
74
+ for (let i = 0; i < 2_000; i++) samples.push(generate(4));
75
+ for (const value of samples) {
76
+ try {
77
+ const expected = stableStringify(value);
78
+ expect(stableStringifyHash(value, "excluded\0")).toBe(hash(expected));
79
+ } catch {
80
+ expect(() => stableStringifyHash(value, "excluded\0")).toThrow();
81
+ }
82
+ expect(piJsonHash(value, () => piStringify(value))).toBe(hash(piStringify(value)));
83
+ }
84
+ console.log(`excluded fingerprint differential: ${samples.length} values per serializer`);
85
+ });
86
+
87
+ test("part memo catches in-place edits, alias changes, key order and accessor values", () => {
88
+ const memo = new TailHygieneJsonMemo();
89
+ let calls = 0;
90
+ const get = (value: unknown): string => {
91
+ memo.beginPass();
92
+ return memo.get("part", value, () => {
93
+ calls++;
94
+ return stableStringify(value);
95
+ });
96
+ };
97
+ const shared = { value: "first" };
98
+ const value = { a: shared, b: shared };
99
+ expect(get(value)).toBe(get(structuredClone(value)));
100
+ expect(calls).toBe(1);
101
+ shared.value = "other";
102
+ expect(get(value)).toContain("other");
103
+ expect(calls).toBe(2);
104
+ value.b = { value: "other" };
105
+ expect(get(value)).not.toContain("Circular");
106
+ expect(calls).toBe(3);
107
+ expect(get({ b: value.b, a: value.a })).toBe(get(value));
108
+ expect(calls).toBe(5);
109
+ let changing = 0;
110
+ const accessor = {
111
+ get value() {
112
+ return ++changing;
113
+ },
114
+ };
115
+ expect(get(accessor)).not.toBe(get(accessor));
116
+ expect(calls).toBe(7);
117
+ });