@cortexkit/opencode-magic-context 0.49.103 → 0.49.105

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 (166) hide show
  1. package/dist/auto-search-worker.js +5 -5
  2. package/dist/chunk-embedding-write-worker.js +8 -5
  3. package/dist/{context-jk7bgc3s.js → context-wtnrsjkp.js} +116 -139
  4. package/dist/{embedding-backfill-anty7zdf.js → embedding-backfill-kqwx0vhj.js} +6 -6
  5. package/dist/{v2/embedding-cache-dveynq4m.js → embedding-cache-fhdkn9nc.js} +3 -1
  6. package/dist/embedding-worker.js +1 -1
  7. package/dist/features/magic-context/chunk-embedding-write-worker-install-failure.fixture.d.ts +2 -0
  8. package/dist/features/magic-context/chunk-embedding-write-worker-install-failure.fixture.d.ts.map +1 -0
  9. package/dist/features/magic-context/chunk-scope-repair-revision.d.ts +16 -1
  10. package/dist/features/magic-context/chunk-scope-repair-revision.d.ts.map +1 -1
  11. package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
  12. package/dist/features/magic-context/dreamer/verify-checkout.d.ts +2 -0
  13. package/dist/features/magic-context/dreamer/verify-checkout.d.ts.map +1 -0
  14. package/dist/features/magic-context/memory/embedding-cache.d.ts +1 -0
  15. package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -1
  16. package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
  17. package/dist/features/magic-context/memory/embedding-worker-loop.d.ts +9 -1
  18. package/dist/features/magic-context/memory/embedding-worker-loop.d.ts.map +1 -1
  19. package/dist/features/magic-context/memory/embedding-worker-observer.fixture.d.ts +26 -0
  20. package/dist/features/magic-context/memory/embedding-worker-observer.fixture.d.ts.map +1 -0
  21. package/dist/features/magic-context/message-fts-rowid-map-startup-worker-test-support.d.ts +2 -0
  22. package/dist/features/magic-context/message-fts-rowid-map-startup-worker-test-support.d.ts.map +1 -0
  23. package/dist/features/magic-context/project-embedding-registry.d.ts +5 -0
  24. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  25. package/dist/features/magic-context/search-pool-fixture.d.ts +15 -0
  26. package/dist/features/magic-context/search-pool-fixture.d.ts.map +1 -1
  27. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  29. package/dist/hooks/magic-context/compartment-runner-types.d.ts +4 -1
  30. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  31. package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
  32. package/dist/hooks/magic-context/history-boundary-repair.d.ts +7 -2
  33. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/transform-compartment-phase.d.ts +1 -0
  35. package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/transform.d.ts +1 -0
  37. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  38. package/dist/{index-3nxhxeeg.js → index-1j4q0bd6.js} +4 -4
  39. package/dist/{index-fd3hkyk1.js → index-42fsf88t.js} +1 -1
  40. package/dist/{v2/server-qbydvfev.js → index-6xg55350.js} +15 -11
  41. package/dist/{index-jjxpmypb.js → index-7z5cvfpg.js} +1 -1
  42. package/dist/{index-jg5whyrd.js → index-8vv7axxg.js} +3 -3
  43. package/dist/{index-42fg6tzz.js → index-92p5yfpp.js} +4 -4
  44. package/dist/{index-7jvc0rhh.js → index-9m2b5mwf.js} +21 -8
  45. package/dist/{index-9mxkvdtp.js → index-a3t1ck7g.js} +8 -8
  46. package/dist/{index-vhx6yph7.js → index-as8bg7eh.js} +367 -115
  47. package/dist/{index-jyj9jg9f.js → index-cxh5g5bt.js} +2 -2
  48. package/dist/{index-vegw385y.js → index-cy5fn70d.js} +89 -1
  49. package/dist/{index-4dywj733.js → index-dzb1yc9w.js} +1 -1
  50. package/dist/{index-t2h3484a.js → index-edafv9d7.js} +5 -5
  51. package/dist/{index-6t6v8prs.js → index-ff1hqh4a.js} +3 -3
  52. package/dist/{index-ke0mkz7g.js → index-g1h1efr0.js} +1 -1
  53. package/dist/{index-f455a0g3.js → index-k37h4yrb.js} +5 -3
  54. package/dist/{index-mes48s7a.js → index-mg6cwqw2.js} +220 -27
  55. package/dist/{index-nyjztqyj.js → index-p5ey52j9.js} +32 -5
  56. package/dist/{index-pw1f07vg.js → index-srpghrje.js} +1 -1
  57. package/dist/{index-4536jdzj.js → index-xzs1fxzz.js} +2 -2
  58. package/dist/{index-hyvxmz3e.js → index-y1875y4h.js} +1 -1
  59. package/dist/{index-4v50y0jr.js → index-ydevzvfs.js} +1 -1
  60. package/dist/{index-ab86c21b.js → index-zj0ra8vs.js} +1 -1
  61. package/dist/index.js +53 -62
  62. package/dist/migration-worker.js +3 -3
  63. package/dist/{project-embedding-registry-4cv7n37m.js → project-embedding-registry-0z0nd73p.js} +5 -5
  64. package/dist/raw-ordinal-warmup-worker.js +2 -2
  65. package/dist/{recomp-orchestrator-vg4cxyp7.js → recomp-orchestrator-zagjzbz5.js} +15 -15
  66. package/dist/{render-f32trg2t.js → render-vwp72qd0.js} +6 -6
  67. package/dist/{search-ygtyb91s.js → search-7e1rcqb7.js} +12 -12
  68. package/dist/{search-archive-yh6xtvrx.js → search-archive-6tr0gcf7.js} +2 -2
  69. package/dist/shared/sqlite-busy-test-support.d.ts +21 -0
  70. package/dist/shared/sqlite-busy-test-support.d.ts.map +1 -0
  71. package/dist/shared/sqlite-write-locker-test-support.d.ts +12 -0
  72. package/dist/shared/sqlite-write-locker-test-support.d.ts.map +1 -1
  73. package/dist/{storage-memory-p91f7b5h.js → storage-memory-24hsvzy8.js} +2 -2
  74. package/dist/{store-wpx314rk.js → store-4eeezg83.js} +2 -2
  75. package/dist/{store-reader-c5fwa9qx.js → store-reader-g8w2wp88.js} +1 -1
  76. package/dist/{transform-postprocess-phase-958fmjs5.js → transform-postprocess-phase-v3p3q2gf.js} +16 -16
  77. package/dist/v2/auto-search-worker.js +5 -5
  78. package/dist/v2/chunk-embedding-write-worker.js +8 -5
  79. package/dist/v2/{context-3g3jvxg8.js → context-fbdac7qt.js} +166 -150
  80. package/dist/v2/{embedding-backfill-ra9gbbs4.js → embedding-backfill-e44pv5db.js} +6 -6
  81. package/dist/{embedding-cache-dveynq4m.js → v2/embedding-cache-fhdkn9nc.js} +3 -1
  82. package/dist/v2/embedding-worker.js +1 -1
  83. package/dist/v2/event-subscription.fixture.d.ts +9 -0
  84. package/dist/v2/event-subscription.fixture.d.ts.map +1 -0
  85. package/dist/v2/hidden-model-activity.d.ts +13 -0
  86. package/dist/v2/hidden-model-activity.d.ts.map +1 -1
  87. package/dist/v2/hooks/context.d.ts +1 -0
  88. package/dist/v2/hooks/context.d.ts.map +1 -1
  89. package/dist/v2/hooks/dream-trigger.d.ts +2 -1
  90. package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
  91. package/dist/v2/hooks/event-subscription-worker.d.ts +11 -0
  92. package/dist/v2/hooks/event-subscription-worker.d.ts.map +1 -0
  93. package/dist/v2/hooks/types.d.ts +1 -0
  94. package/dist/v2/hooks/types.d.ts.map +1 -1
  95. package/dist/v2/hooks/update-check.d.ts +1 -0
  96. package/dist/v2/hooks/update-check.d.ts.map +1 -1
  97. package/dist/v2/{message-index-bounded-j1sxtefe.js → message-index-bounded-nwqfb1p5.js} +3 -3
  98. package/dist/v2/migration-worker.js +3 -3
  99. package/dist/v2/{project-embedding-registry-gdaqb7h0.js → project-embedding-registry-rhzjnypp.js} +5 -5
  100. package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
  101. package/dist/v2/{read-session-chunk-p6z3kmdj.js → read-session-chunk-brqatg83.js} +2 -2
  102. package/dist/v2/{recomp-orchestrator-29m3cc5b.js → recomp-orchestrator-1ech6k2n.js} +17 -17
  103. package/dist/v2/{render-jpj43axy.js → render-pfe3smhx.js} +10 -10
  104. package/dist/v2/{search-archive-wbhxp0p1.js → search-archive-r8krrz47.js} +5 -5
  105. package/dist/v2/{search-ybyc7vmx.js → search-sffewrs4.js} +15 -15
  106. package/dist/v2/{server-kx5egpt7.js → server-16115spd.js} +4 -4
  107. package/dist/v2/server-28jqb7s0.js +6 -0
  108. package/dist/v2/{server-qg8jyfxa.js → server-5xx10mqe.js} +1 -1
  109. package/dist/{index-qbydvfev.js → v2/server-6xg55350.js} +15 -11
  110. package/dist/v2/{server-t45hgcsg.js → server-7jw608jk.js} +2 -2
  111. package/dist/v2/{server-8f92sd2r.js → server-7pxjk184.js} +6 -4
  112. package/dist/v2/{server-3mb205v9.js → server-83rjf4df.js} +1 -1
  113. package/dist/v2/{server-df5scn4q.js → server-9t4yjj20.js} +27 -12
  114. package/dist/v2/{server-ga6y57vh.js → server-c32505fr.js} +6 -4
  115. package/dist/v2/{server-8m5wk6aq.js → server-cpb7b1f9.js} +5 -5
  116. package/dist/v2/{server-qdpd8h27.js → server-fn6k1ack.js} +1 -1
  117. package/dist/v2/{server-1qxdyz4p.js → server-ghb2q1z9.js} +2 -2
  118. package/dist/v2/{server-pqgnjf38.js → server-gkb0y83n.js} +32 -5
  119. package/dist/v2/{server-r851hxn5.js → server-hqcdvs2n.js} +13 -13
  120. package/dist/v2/{server-9ms9b75c.js → server-j00jprwm.js} +4 -6
  121. package/dist/v2/{server-xpy46ddq.js → server-jtd5vq5e.js} +3 -3
  122. package/dist/v2/{server-b01a7dhj.js → server-kk2kbzq3.js} +1 -1
  123. package/dist/v2/{server-mc5t7k8v.js → server-ma0qhqg9.js} +1 -1
  124. package/dist/v2/{server-x22jtpna.js → server-n3bfqd0j.js} +4 -2
  125. package/dist/v2/{server-fagcnt6j.js → server-pjvqyg6g.js} +367 -115
  126. package/dist/v2/{server-jrs4gny6.js → server-qtajgx1e.js} +89 -1
  127. package/dist/v2/{server-pw1f07vg.js → server-srpghrje.js} +1 -1
  128. package/dist/v2/server-t104h957.js +177 -0
  129. package/dist/v2/{server-j09jx1n9.js → server-v2r04xds.js} +1 -1
  130. package/dist/v2/{server-7c5p0bh1.js → server-z77hman6.js} +1 -1
  131. package/dist/v2/server.js +31 -40
  132. package/dist/v2/{storage-memory-p91f7b5h.js → storage-memory-24hsvzy8.js} +2 -2
  133. package/dist/v2/{storage-tags-s7nvvyg8.js → storage-tags-ee72g2zv.js} +1 -1
  134. package/dist/v2/{store-mba47sxn.js → store-9rsrj5pt.js} +2 -2
  135. package/dist/v2/{store-reader-w7w8vfsy.js → store-reader-tb0f9621.js} +1 -1
  136. package/dist/v2/store-reader.d.ts +1 -1
  137. package/dist/v2/store-reader.d.ts.map +1 -1
  138. package/dist/v2/tui/index.d.ts.map +1 -1
  139. package/dist/v2/{v2-archive-reader-5njmg3a3.js → v2-archive-reader-0xysfgxh.js} +1 -1
  140. package/dist/v2/{wrapup-orchestrator-ahkq8a61.js → wrapup-orchestrator-8d4ak3x3.js} +17 -17
  141. package/dist/{v2-archive-reader-y38khjax.js → v2-archive-reader-fac1zmhj.js} +1 -1
  142. package/dist/{wrapup-orchestrator-gjqaac65.js → wrapup-orchestrator-wz10b94c.js} +16 -16
  143. package/package.json +1 -1
  144. package/src/config/migrate-config-location.test.ts +41 -29
  145. package/src/shared/model-suggestion-retry.test.ts +137 -90
  146. package/src/shared/off-thread-migration-clock.test.ts +19 -9
  147. package/src/shared/prompt-async-transport.test.ts +125 -42
  148. package/src/shared/rpc-async-probes.test.ts +56 -36
  149. package/src/shared/rpc-client.test.ts +51 -18
  150. package/src/shared/sqlite-acquisition-routing.test.ts +79 -22
  151. package/src/shared/sqlite-busy-budget-review.test.ts +129 -111
  152. package/src/shared/sqlite-busy-test-support.ts +154 -0
  153. package/src/shared/sqlite-foreground-wait.test.ts +213 -156
  154. package/src/shared/sqlite-pass-scope.test.ts +142 -105
  155. package/src/shared/sqlite-turn-deadline.test.ts +149 -124
  156. package/src/shared/sqlite-write-locker-test-support.ts +44 -12
  157. package/src/shared/stable-json-linear.test.ts +29 -11
  158. package/src/shared/startup-maintenance-policy.test.ts +72 -2
  159. package/src/shared/storage-busy.test.ts +45 -18
  160. package/src/shared/storage-file-mutex-review.test.ts +65 -51
  161. package/src/shared/tui-preferences.test.ts +15 -5
  162. package/src/shared/worker-shutdown.test.ts +26 -20
  163. package/src/tui/data/notification-socket.test.ts +220 -108
  164. package/src/v2/tui/index.ts +5 -1
  165. package/src/v2/tui/status-dialog-fallback.test.ts +23 -1
  166. package/dist/v2/server-84w6rvvf.js +0 -14
@@ -1,16 +1,19 @@
1
- import { afterEach, describe, expect, test } from "bun:test";
1
+ import { afterEach, beforeEach, describe, expect, jest, spyOn, test } from "bun:test";
2
2
  import { mkdirSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
+ import * as rpcNotifications from "../../shared/rpc-notifications";
5
6
  import {
6
7
  __resetNotificationStateForTests,
7
8
  drainNotifications,
8
9
  isTuiConnected,
10
+ type NotificationSink,
9
11
  pushNotification,
10
12
  } from "../../shared/rpc-notifications";
11
13
  import { MagicContextRpcServer } from "../../shared/rpc-server";
12
14
  import { rpcPortFilePath } from "../../shared/rpc-utils";
13
15
  import { createTestTempDirFromPath } from "../../shared/test-temp-dir";
16
+ import * as contextDb from "./context-db";
14
17
  import { closeRpc, initRpcClient } from "./context-db";
15
18
  import {
16
19
  _resetNotificationSocketStateForTesting,
@@ -22,6 +25,12 @@ const originalXdgDataHome = process.env.XDG_DATA_HOME;
22
25
  const tempDirs: string[] = [];
23
26
  const servers: MagicContextRpcServer[] = [];
24
27
  const legacyServers: Array<ReturnType<typeof Bun.serve>> = [];
28
+ const restoreObservers: Array<() => void> = [];
29
+
30
+ beforeEach(() => {
31
+ // Let real loopback I/O run, but drive watcher and reconnect delays by hand.
32
+ jest.useFakeTimers({ doNotFake: ["setImmediate", "nextTick", "queueMicrotask"] });
33
+ });
25
34
 
26
35
  afterEach(() => {
27
36
  _resetNotificationSocketStateForTesting();
@@ -30,6 +39,8 @@ afterEach(() => {
30
39
  server.stop();
31
40
  }
32
41
  for (const server of legacyServers.splice(0)) server.stop(true);
42
+ for (const restore of restoreObservers.splice(0)) restore();
43
+ jest.useRealTimers();
33
44
  __resetNotificationStateForTests();
34
45
  for (const dir of tempDirs.splice(0)) {
35
46
  rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
@@ -59,19 +70,95 @@ async function startServer(dataHome: string, directory: string): Promise<MagicCo
59
70
  return server;
60
71
  }
61
72
 
73
+ function eventLog<T>() {
74
+ const values: T[] = [];
75
+ let update = Promise.withResolvers<void>();
76
+ return {
77
+ values,
78
+ emit(value: T) {
79
+ values.push(value);
80
+ const previous = update;
81
+ update = Promise.withResolvers<void>();
82
+ previous.resolve();
83
+ },
84
+ async at(index: number): Promise<T> {
85
+ // Only a new event wakes the waiter; already-recorded events can be read immediately.
86
+ while (values.length <= index) await update.promise;
87
+ return values[index]!;
88
+ },
89
+ };
90
+ }
91
+
92
+ function observeServer() {
93
+ const subscribed = eventLog<NotificationSink>();
94
+ const disconnected = eventLog<NotificationSink>();
95
+ const acknowledged = eventLog<readonly number[]>();
96
+ const { registerNotificationSink, acknowledgeNotifications } = rpcNotifications;
97
+ const register = spyOn(rpcNotifications, "registerNotificationSink").mockImplementation(
98
+ (sink) => {
99
+ const unregister = registerNotificationSink(sink);
100
+ subscribed.emit(sink);
101
+ let live = true;
102
+ return () => {
103
+ unregister();
104
+ if (live) disconnected.emit(sink);
105
+ live = false;
106
+ };
107
+ },
108
+ );
109
+ const acknowledge = spyOn(rpcNotifications, "acknowledgeNotifications").mockImplementation(
110
+ (ids) => {
111
+ acknowledgeNotifications(ids);
112
+ acknowledged.emit(ids);
113
+ },
114
+ );
115
+ restoreObservers.push(() => {
116
+ acknowledge.mockRestore();
117
+ register.mockRestore();
118
+ });
119
+ return { subscribed, disconnected, acknowledged };
120
+ }
121
+
122
+ function observeClient() {
123
+ const sockets = new Set<WebSocket>();
124
+ const hellos = eventLog<{ sessionId?: string; lastReceivedId: number }>();
125
+ const received = eventLog<SocketNotification>();
126
+ const closed = eventLog<WebSocket>();
127
+ const { send } = WebSocket.prototype;
128
+ const observer = spyOn(WebSocket.prototype, "send").mockImplementation(function (
129
+ this: WebSocket,
130
+ data,
131
+ ) {
132
+ if (!sockets.has(this)) {
133
+ sockets.add(this);
134
+ // The first client send is hello, after its protocol listeners have
135
+ // been installed. Our listeners see frames and closes after the client.
136
+ this.addEventListener("message", (event) => {
137
+ const frame = JSON.parse(String(event.data));
138
+ if (frame.type === "notification") received.emit(frame.notification);
139
+ });
140
+ this.addEventListener("close", () => closed.emit(this));
141
+ }
142
+ const frame = JSON.parse(String(data));
143
+ if (frame.type === "hello") {
144
+ hellos.emit({ sessionId: frame.sessionId, lastReceivedId: frame.lastReceivedId });
145
+ }
146
+ send.call(this, data);
147
+ });
148
+ restoreObservers.push(() => observer.mockRestore());
149
+ return { sockets, hellos, received, closed };
150
+ }
151
+
62
152
  function startLegacyServer(
63
153
  dataHome: string,
64
154
  directory: string,
65
155
  notifications: SocketNotification[],
66
- ): {
67
- sockets: Set<{ close(): void }>;
68
- helloCursors: number[];
69
- ackCursors: number[];
70
- } {
156
+ ) {
71
157
  const token = "v032-query-token";
72
158
  const sockets = new Set<{ close(): void }>();
73
- const helloCursors: number[] = [];
74
- const ackCursors: number[] = [];
159
+ const helloCursors = eventLog<number>();
160
+ const ackCursors = eventLog<number>();
161
+ const closed = eventLog<unknown>();
75
162
  const server = Bun.serve({
76
163
  hostname: "127.0.0.1",
77
164
  port: 0,
@@ -102,7 +189,7 @@ function startLegacyServer(
102
189
  };
103
190
  if (msg.type === "hello") {
104
191
  const cursor = Number(msg.lastReceivedId ?? 0);
105
- helloCursors.push(cursor);
192
+ helloCursors.emit(cursor);
106
193
  for (const notification of notifications) {
107
194
  if (notification.id > cursor) {
108
195
  ws.send(JSON.stringify({ type: "notification", notification }));
@@ -111,11 +198,12 @@ function startLegacyServer(
111
198
  // Frozen v0.32 acknowledgement: protocol epoch fields did not exist.
112
199
  ws.send(JSON.stringify({ type: "hello-ack" }));
113
200
  } else if (msg.type === "ack" && typeof msg.cursor === "number") {
114
- ackCursors.push(msg.cursor);
201
+ ackCursors.emit(msg.cursor);
115
202
  }
116
203
  },
117
204
  close(ws) {
118
205
  sockets.delete(ws);
206
+ closed.emit(ws);
119
207
  },
120
208
  },
121
209
  });
@@ -127,16 +215,7 @@ function startLegacyServer(
127
215
  portFile,
128
216
  JSON.stringify({ port: server.port, pid: process.pid, started_at: Date.now(), token }),
129
217
  );
130
- return { sockets, helloCursors, ackCursors };
131
- }
132
-
133
- async function waitFor(condition: () => boolean, label: string, timeoutMs = 4_000): Promise<void> {
134
- const start = Date.now();
135
- while (Date.now() - start < timeoutMs) {
136
- if (condition()) return;
137
- await new Promise((resolve) => setTimeout(resolve, 25));
138
- }
139
- throw new Error(`Timed out waiting for ${label}`);
218
+ return { sockets, helloCursors, ackCursors, closed };
140
219
  }
141
220
 
142
221
  describe("notification socket", () => {
@@ -144,6 +223,8 @@ describe("notification socket", () => {
144
223
  drainNotifications(Number.MAX_SAFE_INTEGER);
145
224
  const dataHome = makeDataHome();
146
225
  const directory = "/repo-home-screen";
226
+ const server = observeServer();
227
+ const client = observeClient();
147
228
  await startServer(dataHome, directory);
148
229
  initRpcClient(directory);
149
230
 
@@ -155,18 +236,17 @@ describe("notification socket", () => {
155
236
  return true;
156
237
  },
157
238
  });
158
- await waitFor(() => isTuiConnected(), "home-screen socket connection");
239
+ await server.subscribed.at(0);
240
+ expect(isTuiConnected()).toBe(true);
159
241
  expect(isTuiConnected("ses_hidden")).toBe(false);
160
242
 
161
243
  pushNotification("scoped", { action: "show-status-dialog" }, "ses_hidden");
162
244
  pushNotification("global", { action: "show-status-dialog" });
163
- await waitFor(
164
- () => received.some((notification) => notification.type === "global"),
165
- "global home-screen notification",
166
- );
167
- expect(received.some((notification) => notification.type === "scoped")).toBe(false);
245
+ await server.acknowledged.at(0);
246
+ expect(client.received.values.map(({ type }) => type)).toEqual(["global"]);
247
+ expect(received.map(({ type }) => type)).toEqual(["global"]);
168
248
  expect(drainNotifications(0, "ses_hidden", { sessionOnly: true })).toHaveLength(1);
169
- });
249
+ }, 30_000);
170
250
 
171
251
  test("subscribes to the server of the shown session's directory, not the startup one", async () => {
172
252
  // A TUI started in the home directory showing a session from a project
@@ -192,10 +272,16 @@ describe("notification socket", () => {
192
272
  return true;
193
273
  },
194
274
  });
195
- await waitFor(() => received.length === 1, "the project server's push");
275
+ const subscribedTo = await Promise.race([
276
+ project.helloCursors.at(0).then(() => "project"),
277
+ home.helloCursors.at(0).then(() => "home"),
278
+ ]);
279
+ expect(subscribedTo).toBe("project");
280
+ expect(await project.ackCursors.at(0)).toBe(1);
281
+ expect(received.map(({ type }) => type)).toEqual(["action"]);
196
282
  expect(project.sockets.size).toBe(1);
197
283
  expect(home.sockets.size).toBe(0);
198
- });
284
+ }, 30_000);
199
285
 
200
286
  test("moves the socket when the shown session changes directory", async () => {
201
287
  const dataHome = makeDataHome();
@@ -208,40 +294,61 @@ describe("notification socket", () => {
208
294
  getSessionDirectory: () => sessionDirectory,
209
295
  onNotification: () => true,
210
296
  });
211
- await waitFor(() => home.sockets.size === 1, "startup subscription");
297
+ await home.helloCursors.at(0);
212
298
  sessionDirectory = "/home-move/project";
213
- await waitFor(() => project.sockets.size === 1, "project subscription", 5_000);
214
- await waitFor(() => home.sockets.size === 0, "startup socket closed");
215
- });
299
+ jest.advanceTimersByTime(1_000);
300
+ const subscribedTo = await Promise.race([
301
+ project.helloCursors.at(0).then(() => "project"),
302
+ home.helloCursors.at(1).then(() => "home"),
303
+ ]);
304
+ expect(subscribedTo).toBe("project");
305
+ await home.closed.at(0);
306
+ expect(home.sockets.size).toBe(0);
307
+ expect(project.sockets.size).toBe(1);
308
+ }, 30_000);
216
309
 
217
310
  test("overlapping starts create one socket and one delivery", async () => {
218
311
  drainNotifications(Number.MAX_SAFE_INTEGER);
219
312
  const dataHome = makeDataHome();
220
313
  const directory = "/repo-overlapping-start";
314
+ const server = observeServer();
315
+ const client = observeClient();
316
+ const resolveTarget = spyOn(contextDb, "resolveNotificationTarget");
317
+ restoreObservers.push(() => resolveTarget.mockRestore());
221
318
  await startServer(dataHome, directory);
222
319
  initRpcClient(directory);
223
320
 
224
- let deliveries = 0;
321
+ const deliveries: string[] = [];
225
322
  const options = {
226
323
  getSessionId: () => "ses_once",
227
- onNotification: () => {
228
- deliveries += 1;
324
+ onNotification: (notification: SocketNotification) => {
325
+ deliveries.push(notification.type);
229
326
  return true;
230
327
  },
231
328
  };
232
329
  startNotificationSocket(options);
233
330
  startNotificationSocket(options);
234
- await waitFor(() => isTuiConnected("ses_once"), "single overlapping connection");
331
+ expect(resolveTarget).toHaveBeenCalledTimes(1);
332
+ await server.subscribed.at(0);
333
+ expect(isTuiConnected("ses_once")).toBe(true);
235
334
  pushNotification("once", { ok: true }, "ses_once");
236
- await waitFor(() => deliveries === 1, "single notification delivery");
237
- await new Promise((resolve) => setTimeout(resolve, 75));
238
- expect(deliveries).toBe(1);
239
- });
335
+ // The second push is an in-order barrier for the first push's frames
336
+ // and handlers. Acknowledging it drains both without a quiet period.
337
+ pushNotification("barrier", {}, "ses_once");
338
+ const barrier = await client.received.at(1);
339
+ expect(barrier.type).toBe("barrier");
340
+ expect(await server.acknowledged.at(1)).toEqual([barrier.id]);
341
+ expect(server.subscribed.values).toHaveLength(1);
342
+ expect(client.sockets.size).toBe(1);
343
+ expect(deliveries).toEqual(["once", "barrier"]);
344
+ }, 30_000);
240
345
 
241
346
  test("uses the active session cursor when switching sessions", async () => {
242
347
  drainNotifications(Number.MAX_SAFE_INTEGER);
243
348
  const dataHome = makeDataHome();
244
349
  const directory = "/repo-session-cursors";
350
+ const server = observeServer();
351
+ const client = observeClient();
245
352
  await startServer(dataHome, directory);
246
353
  initRpcClient(directory);
247
354
 
@@ -255,28 +362,26 @@ describe("notification socket", () => {
255
362
  },
256
363
  });
257
364
 
258
- await waitFor(() => isTuiConnected("ses_A"), "socket connected to session A");
365
+ expect((await server.subscribed.at(0)).sessionId).toBe("ses_A");
259
366
  pushNotification("for-b", { action: "show-status-dialog" }, "ses_B");
260
367
  pushNotification("for-a", { action: "show-status-dialog" }, "ses_A");
261
- await waitFor(
262
- () => received.some((notification) => notification.type === "for-a"),
263
- "session A notification",
264
- );
368
+ await server.acknowledged.at(0);
369
+ expect(received.map(({ type }) => type)).toEqual(["for-a"]);
265
370
 
266
371
  activeSession = "ses_B";
267
- await waitFor(
268
- () => received.some((notification) => notification.type === "for-b"),
269
- "session B backlog after switching sessions",
270
- );
271
-
272
- expect(received.map((notification) => notification.type)).toContain("for-a");
273
- expect(received.map((notification) => notification.type)).toContain("for-b");
274
- });
372
+ jest.advanceTimersByTime(1_000);
373
+ expect(await client.hellos.at(1)).toMatchObject({ sessionId: "ses_B", lastReceivedId: 0 });
374
+ expect((await server.subscribed.at(1)).sessionId).toBe("ses_B");
375
+ await server.acknowledged.at(1);
376
+ expect(received.map(({ type }) => type)).toEqual(["for-a", "for-b"]);
377
+ }, 30_000);
275
378
 
276
379
  test("clears cursors and deduplication when a fresh server reuses notification ids", async () => {
277
380
  __resetNotificationStateForTests();
278
381
  const dataHome = makeDataHome();
279
382
  const directory = "/repo-reconnect";
383
+ const server = observeServer();
384
+ const client = observeClient();
280
385
  const first = await startServer(dataHome, directory);
281
386
  initRpcClient(directory);
282
387
 
@@ -288,46 +393,43 @@ describe("notification socket", () => {
288
393
  return true;
289
394
  },
290
395
  });
291
- await waitFor(() => isTuiConnected("ses_R"), "initial websocket connection");
396
+ await server.subscribed.at(0);
292
397
 
293
398
  pushNotification("before-restart", { action: "show-status-dialog" }, "ses_R");
294
- await waitFor(() => received.length === 1, "first notification acknowledgement");
295
- await waitFor(
296
- () => drainNotifications(0, "ses_R").length === 0,
297
- "first server queue to empty",
298
- );
299
- expect(received[0].id).toBe(1);
399
+ expect(await server.acknowledged.at(0)).toEqual([1]);
400
+ expect(drainNotifications(0, "ses_R")).toEqual([]);
401
+ expect(received.map(({ id }) => id)).toEqual([1]);
300
402
 
301
403
  first.stop();
302
- await waitFor(() => !isTuiConnected("ses_R"), "old websocket sink removed");
404
+ await client.closed.at(0);
405
+ expect(isTuiConnected("ses_R")).toBe(false);
303
406
  // A process restart recreates module state as well as the RPC server. The
304
407
  // client state intentionally survives so reused ids exercise epoch reset.
305
408
  __resetNotificationStateForTests();
306
409
  pushNotification("queued-after-restart", { action: "show-status-dialog" }, "ses_R");
307
- const second = await startServer(dataHome, directory);
308
- expect(second).toBeDefined();
309
-
310
- await waitFor(
311
- () => received.some((notification) => notification.type === "queued-after-restart"),
312
- "reused id from replacement server backlog",
313
- );
314
- const restarted = received.find(
315
- (notification) => notification.type === "queued-after-restart",
316
- );
317
- expect(restarted?.id).toBe(received[0].id);
318
- });
410
+ // A fresh id after the reused one proves the replacement backlog has
411
+ // drained even if a stale deduplication entry suppressed the reused id.
412
+ pushNotification("end-of-backlog", {}, "ses_R");
413
+ await startServer(dataHome, directory);
414
+ jest.advanceTimersByTime(500);
415
+ expect(await server.acknowledged.at(2)).toEqual([2]);
416
+ expect(received.map(({ type, id }) => [type, id])).toEqual([
417
+ ["before-restart", 1],
418
+ ["queued-after-restart", 1],
419
+ ["end-of-backlog", 2],
420
+ ]);
421
+ }, 30_000);
319
422
 
320
423
  test("acknowledges only consumed ids and redelivers a failed earlier notification", async () => {
321
424
  __resetNotificationStateForTests();
322
425
  const dataHome = makeDataHome();
323
426
  const directory = "/repo-exact-ack";
427
+ const server = observeServer();
428
+ const client = observeClient();
324
429
  await startServer(dataHome, directory);
325
430
  initRpcClient(directory);
326
431
 
327
- let releaseFirst: ((consumed: boolean) => void) | undefined;
328
- const firstResult = new Promise<boolean>((resolve) => {
329
- releaseFirst = resolve;
330
- });
432
+ const firstResult = Promise.withResolvers<boolean>();
331
433
  let slowCalls = 0;
332
434
  let fastCalls = 0;
333
435
  startNotificationSocket({
@@ -335,27 +437,29 @@ describe("notification socket", () => {
335
437
  onNotification: (notification) => {
336
438
  if (notification.type === "slow") {
337
439
  slowCalls += 1;
338
- return slowCalls === 1 ? firstResult : true;
440
+ return slowCalls === 1 ? firstResult.promise : true;
339
441
  }
340
442
  fastCalls += 1;
341
443
  return true;
342
444
  },
343
445
  });
344
- await waitFor(() => isTuiConnected("ses_exact"), "exact ack socket connection");
446
+ await server.subscribed.at(0);
345
447
 
346
448
  pushNotification("slow", { action: "show-status-dialog" }, "ses_exact");
347
449
  pushNotification("fast", { action: "show-toast" }, "ses_exact");
348
- await waitFor(() => slowCalls === 1, "blocked first handler");
450
+ const fast = await client.received.at(1);
451
+ expect(fast.type).toBe("fast");
452
+ expect(slowCalls).toBe(1);
349
453
  expect(fastCalls).toBe(0);
350
- releaseFirst?.(false);
351
- await waitFor(() => fastCalls === 1, "later handler completion");
352
- await waitFor(() => {
353
- const pending = drainNotifications(0, "ses_exact");
354
- return pending.length === 1 && pending[0].type === "slow";
355
- }, "only failed notification to remain queued");
454
+ firstResult.resolve(false);
455
+ expect(await server.acknowledged.at(0)).toEqual([fast.id]);
456
+ expect(fastCalls).toBe(1);
457
+ const pending = drainNotifications(0, "ses_exact");
458
+ expect(pending.map(({ type }) => type)).toEqual(["slow"]);
356
459
 
357
460
  _resetNotificationSocketStateForTesting();
358
- await waitFor(() => !isTuiConnected("ses_exact"), "socket disconnect before redelivery");
461
+ await server.disconnected.at(0);
462
+ expect(isTuiConnected("ses_exact")).toBe(false);
359
463
  startNotificationSocket({
360
464
  getSessionId: () => "ses_exact",
361
465
  onNotification: (notification) => {
@@ -364,14 +468,16 @@ describe("notification socket", () => {
364
468
  return true;
365
469
  },
366
470
  });
367
- await waitFor(() => slowCalls === 2, "failed notification redelivery");
471
+ expect(await server.acknowledged.at(1)).toEqual([pending[0]!.id]);
472
+ expect(slowCalls).toBe(2);
368
473
  expect(fastCalls).toBe(1);
369
- });
474
+ }, 30_000);
370
475
 
371
476
  test("legacy mode keeps its watermark behind a declined notification across reconnect", async () => {
372
477
  const dataHome = makeDataHome();
373
478
  const directory = "/repo-v032-notifications";
374
479
  const sessionId = "ses_v032";
480
+ const client = observeClient();
375
481
  const legacy = startLegacyServer(dataHome, directory, [
376
482
  { id: 1, type: "declined", payload: {}, sessionId },
377
483
  { id: 2, type: "consumed", payload: {}, sessionId },
@@ -392,53 +498,59 @@ describe("notification socket", () => {
392
498
  },
393
499
  });
394
500
 
395
- await waitFor(() => declinedCalls === 1 && consumedCalls === 1, "legacy backlog handling");
396
- expect(Math.max(0, ...legacy.ackCursors)).toBe(0);
501
+ expect(await legacy.ackCursors.at(0)).toBe(0);
502
+ expect(declinedCalls).toBe(1);
503
+ expect(consumedCalls).toBe(1);
397
504
  for (const ws of legacy.sockets) ws.close();
398
505
 
399
- await waitFor(() => legacy.helloCursors.length >= 2, "legacy reconnect hello");
400
- await waitFor(() => declinedCalls === 2, "declined notification redelivery");
401
- expect(legacy.helloCursors[1]).toBe(0);
506
+ await client.closed.at(0);
507
+ jest.advanceTimersByTime(500);
508
+ expect(await legacy.helloCursors.at(1)).toBe(0);
509
+ // The redelivered first notification and the deduplicated second each
510
+ // acknowledge the same cursor, now safe because both were consumed.
511
+ expect(await legacy.ackCursors.at(1)).toBe(2);
512
+ expect(await legacy.ackCursors.at(2)).toBe(2);
513
+ expect(declinedCalls).toBe(2);
402
514
  expect(consumedCalls).toBe(1);
403
- await waitFor(() => legacy.ackCursors.includes(2), "gap-safe legacy watermark advance");
404
- });
515
+ }, 30_000);
405
516
 
406
517
  test("serializes back-to-back dialog notification handlers", async () => {
407
518
  __resetNotificationStateForTests();
408
519
  const dataHome = makeDataHome();
409
520
  const directory = "/repo-serialized-dialogs";
521
+ const server = observeServer();
522
+ const client = observeClient();
410
523
  await startServer(dataHome, directory);
411
524
  initRpcClient(directory);
412
525
 
413
- let releaseFirst: (() => void) | undefined;
414
- const firstSettled = new Promise<void>((resolve) => {
415
- releaseFirst = resolve;
416
- });
526
+ const firstSettled = Promise.withResolvers<void>();
417
527
  const events: string[] = [];
418
528
  startNotificationSocket({
419
529
  getSessionId: () => "ses_dialogs",
420
530
  onNotification: async (notification) => {
421
531
  events.push(`start:${notification.type}`);
422
- if (notification.type === "dialog-one") await firstSettled;
532
+ if (notification.type === "dialog-one") await firstSettled.promise;
423
533
  events.push(`finish:${notification.type}`);
424
534
  return true;
425
535
  },
426
536
  });
427
- await waitFor(() => isTuiConnected("ses_dialogs"), "dialog socket connection");
537
+ await server.subscribed.at(0);
428
538
 
429
539
  pushNotification("dialog-one", { action: "show-status-dialog" }, "ses_dialogs");
430
540
  pushNotification("dialog-two", { action: "show-upgrade-dialog" }, "ses_dialogs");
431
- await waitFor(() => events.includes("start:dialog-one"), "first dialog handler start");
432
- await new Promise((resolve) => setTimeout(resolve, 75));
541
+ // The client has received the second frame while the first handler is
542
+ // still gated. It may queue it but must not start its dialog yet.
543
+ const second = await client.received.at(1);
544
+ expect(second.type).toBe("dialog-two");
433
545
  expect(events).toEqual(["start:dialog-one"]);
434
546
 
435
- releaseFirst?.();
436
- await waitFor(() => events.includes("finish:dialog-two"), "second dialog handler finish");
547
+ firstSettled.resolve();
548
+ expect(await server.acknowledged.at(1)).toEqual([second.id]);
437
549
  expect(events).toEqual([
438
550
  "start:dialog-one",
439
551
  "finish:dialog-one",
440
552
  "start:dialog-two",
441
553
  "finish:dialog-two",
442
554
  ]);
443
- });
555
+ }, 30_000);
444
556
  });
@@ -169,7 +169,11 @@ export function statusTextFor(status: StatusDetailResult): string {
169
169
  historianRunning: status.extras.historianRunning,
170
170
  lastTransformError: status.extras.lastTransformError,
171
171
  });
172
- return notice ? `${notice}\n${text}` : text;
172
+ return [
173
+ ...(notice ? [notice] : []),
174
+ text,
175
+ ...(status.source.dreamerSkipped ?? []).map((reason) => `Dreamer skipped: ${reason}`),
176
+ ].join("\n");
173
177
  }
174
178
 
175
179
  function currentSessionID(context: V2TuiContext): string | null {
@@ -12,7 +12,8 @@
12
12
  */
13
13
  import { expect, test } from "bun:test";
14
14
  import type { StatusDetail } from "../../shared/rpc-types";
15
- import { statusText } from "./index";
15
+ import type { CheckedStatusViewSource } from "../../shared/status-view";
16
+ import { statusText, statusTextFor } from "./index";
16
17
  import { loadCompiledStatusDialog } from "./load-compiled-status-dialog.mjs";
17
18
  import { isMissingOpenTuiRuntime } from "./sidebar-mount";
18
19
  import { mountV1StatusDialog } from "./status-dialog-mount";
@@ -94,6 +95,27 @@ test("the text dialog carries the status a component dialog would have drawn", (
94
95
  "Harness: opencode2",
95
96
  ].join("\n"),
96
97
  );
98
+ expect(
99
+ statusTextFor({
100
+ state: "ready",
101
+ source: {
102
+ ...detail,
103
+ dreamerSkipped: [
104
+ "verify-broad: project checkout is 11 commits behind its upstream branch",
105
+ ],
106
+ } as CheckedStatusViewSource,
107
+ versions: null,
108
+ ignoredFields: [],
109
+ extras: {
110
+ recompProgress: null,
111
+ hostBackendsModuleSide: false,
112
+ historianRunning: false,
113
+ lastTransformError: null,
114
+ },
115
+ }),
116
+ ).toContain(
117
+ "Dreamer skipped: verify-broad: project checkout is 11 commits behind its upstream branch",
118
+ );
97
119
  });
98
120
 
99
121
  test("OpenCode 2 text status explains how to remove instruction update rows", () => {
@@ -1,14 +0,0 @@
1
- // src/hooks/auto-update-checker/semver.ts
2
- function isValidSemver(version) {
3
- return /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version);
4
- }
5
- function compareSemverCore(a, b) {
6
- if (!isValidSemver(a) || !isValidSemver(b))
7
- return null;
8
- const core = (v) => v.split(/[-+]/, 1)[0].split(".").map((n) => Number.parseInt(n, 10));
9
- const [a0, a1, a2] = core(a);
10
- const [b0, b1, b2] = core(b);
11
- return a0 - b0 || a1 - b1 || a2 - b2;
12
- }
13
-
14
- export { compareSemverCore };