@cortexkit/opencode-magic-context 0.49.104 → 0.49.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +8 -5
- package/dist/{context-7hbmnpe8.js → context-ywdwfzg5.js} +116 -136
- package/dist/{embedding-backfill-aratv25b.js → embedding-backfill-kqwx0vhj.js} +4 -4
- package/dist/features/magic-context/chunk-embedding-write-worker-install-failure.fixture.d.ts +2 -0
- package/dist/features/magic-context/chunk-embedding-write-worker-install-failure.fixture.d.ts.map +1 -0
- package/dist/features/magic-context/chunk-scope-repair-revision.d.ts +16 -1
- package/dist/features/magic-context/chunk-scope-repair-revision.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify-checkout.d.ts +2 -0
- package/dist/features/magic-context/dreamer/verify-checkout.d.ts.map +1 -0
- package/dist/features/magic-context/memory/embedding-worker-observer.fixture.d.ts +26 -0
- package/dist/features/magic-context/memory/embedding-worker-observer.fixture.d.ts.map +1 -0
- package/dist/features/magic-context/message-fts-rowid-map-startup-worker-test-support.d.ts +2 -0
- package/dist/features/magic-context/message-fts-rowid-map-startup-worker-test-support.d.ts.map +1 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts +5 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search-pool-fixture.d.ts +15 -0
- package/dist/features/magic-context/search-pool-fixture.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +4 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/history-boundary-repair.d.ts +7 -2
- package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +1 -0
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-persist.d.ts +1 -0
- package/dist/hooks/magic-context/lkg-persist.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts +7 -0
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +1 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +3 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-8gzmeyae.js → index-20e7w8v8.js} +3 -3
- package/dist/{index-a9wn0d9h.js → index-3p08zzfq.js} +3 -3
- package/dist/{index-fd3hkyk1.js → index-42fsf88t.js} +1 -1
- package/dist/{index-tvh3y650.js → index-5phmpcme.js} +5 -5
- package/dist/{index-8yj4vd7k.js → index-92p5yfpp.js} +1 -1
- package/dist/{index-mwjvjn0p.js → index-a3t1ck7g.js} +6 -6
- package/dist/{index-4ba3zp54.js → index-as8bg7eh.js} +365 -113
- package/dist/{index-8eke8yh2.js → index-cxh5g5bt.js} +1 -1
- package/dist/{index-vegw385y.js → index-cy5fn70d.js} +89 -1
- package/dist/{index-4dywj733.js → index-dzb1yc9w.js} +1 -1
- package/dist/{index-3rp2b482.js → index-e4szqthq.js} +299 -37
- package/dist/{index-jjxpmypb.js → index-e7awy9eb.js} +1 -1
- package/dist/{index-ke0mkz7g.js → index-g1h1efr0.js} +1 -1
- package/dist/{index-f455a0g3.js → index-k37h4yrb.js} +5 -3
- package/dist/{index-3nxhxeeg.js → index-sfgz2h7y.js} +4 -4
- package/dist/{index-sqvkh5d0.js → index-xa8jgw6w.js} +20 -7
- package/dist/{index-hyvxmz3e.js → index-y1875y4h.js} +1 -1
- package/dist/{index-4v50y0jr.js → index-ydevzvfs.js} +1 -1
- package/dist/{index-4536jdzj.js → index-ze1t940p.js} +68 -25
- package/dist/{index-ab86c21b.js → index-zj0ra8vs.js} +1 -1
- package/dist/index.js +50 -59
- package/dist/migration-worker.js +3 -3
- package/dist/plugin/hooks/create-session-hooks.d.ts +2 -0
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{project-embedding-registry-1n4cexsv.js → project-embedding-registry-0z0nd73p.js} +3 -3
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{recomp-orchestrator-16rs8aty.js → recomp-orchestrator-7sf94073.js} +12 -12
- package/dist/{render-f32trg2t.js → render-93qzv0vk.js} +6 -6
- package/dist/{search-v9ywqb4f.js → search-7e1rcqb7.js} +9 -9
- package/dist/{search-archive-yh6xtvrx.js → search-archive-dv483a5c.js} +2 -2
- package/dist/shared/sqlite-busy-test-support.d.ts +21 -0
- package/dist/shared/sqlite-busy-test-support.d.ts.map +1 -0
- package/dist/shared/sqlite-write-locker-test-support.d.ts +12 -0
- package/dist/shared/sqlite-write-locker-test-support.d.ts.map +1 -1
- package/dist/{store-wpx314rk.js → store-4eeezg83.js} +2 -2
- package/dist/{store-reader-c5fwa9qx.js → store-reader-g8w2wp88.js} +1 -1
- package/dist/{transform-postprocess-phase-yef4mxk3.js → transform-postprocess-phase-vd9rckyd.js} +13 -13
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +8 -5
- package/dist/v2/{context-mk2h2ven.js → context-6g9j3tq9.js} +248 -160
- package/dist/v2/{embedding-backfill-kyn5sv0f.js → embedding-backfill-e44pv5db.js} +4 -4
- package/dist/v2/event-subscription.fixture.d.ts +9 -0
- package/dist/v2/event-subscription.fixture.d.ts.map +1 -0
- package/dist/v2/hidden-model-activity.d.ts +13 -0
- package/dist/v2/hidden-model-activity.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts +1 -0
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/dream-trigger.d.ts +2 -1
- package/dist/v2/hooks/dream-trigger.d.ts.map +1 -1
- package/dist/v2/hooks/event-subscription-worker.d.ts +11 -0
- package/dist/v2/hooks/event-subscription-worker.d.ts.map +1 -0
- package/dist/v2/hooks/types.d.ts +1 -0
- package/dist/v2/hooks/types.d.ts.map +1 -1
- package/dist/v2/hooks/update-check.d.ts +1 -0
- package/dist/v2/hooks/update-check.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-j1sxtefe.js → message-index-bounded-nwqfb1p5.js} +3 -3
- package/dist/v2/migration-worker.js +3 -3
- package/dist/v2/{project-embedding-registry-1jv2rxhb.js → project-embedding-registry-rhzjnypp.js} +3 -3
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-p6z3kmdj.js → read-session-chunk-brqatg83.js} +2 -2
- package/dist/v2/{recomp-orchestrator-5t2csd46.js → recomp-orchestrator-j84xfa80.js} +14 -14
- package/dist/v2/{render-jpj43axy.js → render-tzs5r2pg.js} +10 -10
- package/dist/v2/{search-archive-wbhxp0p1.js → search-archive-31dpm5zs.js} +5 -5
- package/dist/v2/{search-w9m2fd5c.js → search-sffewrs4.js} +12 -12
- package/dist/v2/{server-47ajg9xc.js → server-16115spd.js} +1 -1
- package/dist/v2/server-28jqb7s0.js +6 -0
- package/dist/v2/{server-qg8jyfxa.js → server-5xx10mqe.js} +1 -1
- package/dist/v2/{server-t45hgcsg.js → server-7jw608jk.js} +2 -2
- package/dist/v2/{server-3mb205v9.js → server-83rjf4df.js} +1 -1
- package/dist/v2/{server-xpy46ddq.js → server-af25mmb6.js} +3 -3
- package/dist/v2/{server-ga6y57vh.js → server-c32505fr.js} +6 -4
- package/dist/v2/{server-qdpd8h27.js → server-fn6k1ack.js} +1 -1
- package/dist/v2/{server-8m5wk6aq.js → server-ggs7sxp6.js} +5 -5
- package/dist/v2/{server-zsbc0n4v.js → server-ghb2q1z9.js} +1 -1
- package/dist/v2/{server-af51b1zg.js → server-hqcdvs2n.js} +11 -11
- package/dist/v2/{server-9ms9b75c.js → server-j00jprwm.js} +4 -6
- package/dist/v2/{server-8f92sd2r.js → server-jqk6g663.js} +72 -27
- package/dist/v2/{server-b01a7dhj.js → server-kk2kbzq3.js} +1 -1
- package/dist/v2/{server-mc5t7k8v.js → server-ma0qhqg9.js} +1 -1
- package/dist/v2/{server-x22jtpna.js → server-n3bfqd0j.js} +4 -2
- package/dist/v2/{server-wmpgvvc4.js → server-pjvqyg6g.js} +365 -113
- package/dist/v2/{server-jrs4gny6.js → server-qtajgx1e.js} +89 -1
- package/dist/v2/server-t104h957.js +177 -0
- package/dist/v2/{server-j09jx1n9.js → server-v2r04xds.js} +1 -1
- package/dist/v2/{server-3gnpqjez.js → server-v60f6dk3.js} +26 -11
- package/dist/v2/{server-7c5p0bh1.js → server-z77hman6.js} +1 -1
- package/dist/v2/server.js +31 -40
- package/dist/v2/{storage-tags-s7nvvyg8.js → storage-tags-ee72g2zv.js} +1 -1
- package/dist/v2/{store-mba47sxn.js → store-9rsrj5pt.js} +2 -2
- package/dist/v2/{store-reader-w7w8vfsy.js → store-reader-tb0f9621.js} +1 -1
- package/dist/v2/store-reader.d.ts +1 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/tui/index.d.ts.map +1 -1
- package/dist/v2/{v2-archive-reader-5njmg3a3.js → v2-archive-reader-7vrma2dm.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-ykgx8hw8.js → wrapup-orchestrator-m1ymvccg.js} +14 -14
- package/dist/{v2-archive-reader-y38khjax.js → v2-archive-reader-aqck4zea.js} +1 -1
- package/dist/{wrapup-orchestrator-a9tshrp4.js → wrapup-orchestrator-k7azmnym.js} +13 -13
- package/package.json +1 -1
- package/src/config/migrate-config-location.test.ts +41 -29
- package/src/shared/model-suggestion-retry.test.ts +137 -90
- package/src/shared/off-thread-migration-clock.test.ts +19 -9
- package/src/shared/prompt-async-transport.test.ts +125 -42
- package/src/shared/rpc-async-probes.test.ts +56 -36
- package/src/shared/rpc-client.test.ts +51 -18
- package/src/shared/sqlite-acquisition-routing.test.ts +79 -22
- package/src/shared/sqlite-busy-budget-review.test.ts +129 -111
- package/src/shared/sqlite-busy-test-support.ts +154 -0
- package/src/shared/sqlite-foreground-wait.test.ts +213 -156
- package/src/shared/sqlite-pass-scope.test.ts +142 -105
- package/src/shared/sqlite-turn-deadline.test.ts +149 -124
- package/src/shared/sqlite-write-locker-test-support.ts +44 -12
- package/src/shared/stable-json-linear.test.ts +29 -11
- package/src/shared/startup-maintenance-policy.test.ts +72 -2
- package/src/shared/storage-busy.test.ts +45 -18
- package/src/shared/storage-file-mutex-review.test.ts +65 -51
- package/src/shared/tui-preferences.test.ts +15 -5
- package/src/shared/worker-shutdown.test.ts +26 -20
- package/src/tui/data/notification-socket.test.ts +220 -108
- package/src/v2/tui/index.ts +5 -1
- package/src/v2/tui/status-dialog-fallback.test.ts +23 -1
- 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
|
|
74
|
-
const ackCursors
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
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
|
|
297
|
+
await home.helloCursors.at(0);
|
|
212
298
|
sessionDirectory = "/home-move/project";
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
321
|
+
const deliveries: string[] = [];
|
|
225
322
|
const options = {
|
|
226
323
|
getSessionId: () => "ses_once",
|
|
227
|
-
onNotification: () => {
|
|
228
|
-
deliveries
|
|
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
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
|
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
|
|
262
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
|
|
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
|
|
396
|
+
await server.subscribed.at(0);
|
|
292
397
|
|
|
293
398
|
pushNotification("before-restart", { action: "show-status-dialog" }, "ses_R");
|
|
294
|
-
await
|
|
295
|
-
|
|
296
|
-
|
|
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
|
|
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
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
await
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
)
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
351
|
-
await
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
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
|
|
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
|
|
396
|
-
expect(
|
|
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
|
|
400
|
-
|
|
401
|
-
expect(legacy.helloCursors
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
432
|
-
|
|
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
|
-
|
|
436
|
-
await
|
|
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
|
});
|
package/src/v2/tui/index.ts
CHANGED
|
@@ -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
|
|
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 {
|
|
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 };
|