@lynn123411/dsh-kimi-cu 0.3.4 → 0.3.6
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/README.md +4 -4
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -1
- package/docs/preview.svg +70 -157
- package/docs/preview.zh.svg +70 -157
- package/lib/client.js +57 -3
- package/lib/client.js.map +2 -2
- package/lib/index.js +30 -15
- package/lib/index.js.map +2 -2
- package/package.json +18 -18
- package/scripts/smoke-host.mjs +2 -0
- package/scripts/test-card.mjs +14 -0
- package/scripts/test-exclusivity.mjs +2 -0
- package/scripts/test-update.mjs +40 -4
package/scripts/test-update.mjs
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
|
|
25
25
|
import { createStatusRoute } from '../src/server/router.ts';
|
|
26
26
|
import { createUpdateRoute } from '../src/server/update-router.ts';
|
|
27
|
+
import { runUpgradeProcess } from '../src/server/update-runtime.ts';
|
|
27
28
|
|
|
28
29
|
const root = resolve(process.argv[2] ?? join(dirname(fileURLToPath(import.meta.url)), '..'));
|
|
29
30
|
|
|
@@ -259,7 +260,7 @@ await test('run:超时归类为 timeout', async () => {
|
|
|
259
260
|
runUpgrade: async () => ({ code: null, raw: '部分输出', timedOut: true, whenExited: Promise.resolve() }),
|
|
260
261
|
});
|
|
261
262
|
const events = await collect(updater);
|
|
262
|
-
assert.
|
|
263
|
+
assert.ok(events.some((event) => event.kind === 'timeout'));
|
|
263
264
|
});
|
|
264
265
|
|
|
265
266
|
await test('run:非零退出码按输出分类', async () => {
|
|
@@ -291,16 +292,50 @@ await test('run:超时后锁留到子进程真的退出', async () => {
|
|
|
291
292
|
return { code: null, raw: '部分输出', timedOut: true, whenExited };
|
|
292
293
|
},
|
|
293
294
|
});
|
|
294
|
-
const events =
|
|
295
|
-
|
|
295
|
+
const events = [];
|
|
296
|
+
const running = updater.run((event) => events.push(event));
|
|
297
|
+
while (!events.some((event) => event.kind === 'timeout')) await new Promise((done) => setTimeout(done, 0));
|
|
298
|
+
assert.equal(updater.status().state, 'running');
|
|
299
|
+
assert.equal(updater.status().timedOut, true);
|
|
296
300
|
const second = await collect(updater);
|
|
297
301
|
assert.deepEqual(second, [{ type: 'error', kind: 'busy', raw: '' }], '超时后进程还在跑,锁不能放');
|
|
298
302
|
exit();
|
|
299
|
-
await
|
|
303
|
+
await running;
|
|
300
304
|
const third = await collect(updater);
|
|
301
305
|
assert.equal(third.at(-1).kind, 'unconfirmed', '进程退出后锁要放');
|
|
302
306
|
});
|
|
303
307
|
|
|
308
|
+
await test('超时后进程退出时重新检测并重连,期间不可重复更新', async () => {
|
|
309
|
+
const exited = Promise.withResolvers();
|
|
310
|
+
const reconnectGate = Promise.withResolvers();
|
|
311
|
+
let version = '0.7.5';
|
|
312
|
+
const { updater } = harness({
|
|
313
|
+
current: async () => ({ path: '/fake/kimi-cu', version }),
|
|
314
|
+
runUpgrade: async () => ({ code: null, raw: 'waiting', timedOut: true, whenExited: exited.promise }),
|
|
315
|
+
reconnect: async () => { await reconnectGate.promise; return true; },
|
|
316
|
+
});
|
|
317
|
+
const events = [];
|
|
318
|
+
const running = updater.run((event) => events.push(event));
|
|
319
|
+
while (!events.some((event) => event.kind === 'timeout')) await new Promise((done) => setTimeout(done, 0));
|
|
320
|
+
version = '0.7.6';
|
|
321
|
+
exited.resolve({ code: 0, raw: 'complete' });
|
|
322
|
+
while (updater.status().stage !== 'restarting') await new Promise((done) => setTimeout(done, 0));
|
|
323
|
+
assert.equal((await collect(updater)).at(-1).kind, 'busy');
|
|
324
|
+
reconnectGate.resolve();
|
|
325
|
+
await running;
|
|
326
|
+
assert.equal(updater.status().state, 'finished');
|
|
327
|
+
assert.equal(updater.status().event.version, '0.7.6');
|
|
328
|
+
assert.equal(updater.status().event.reconnect, 'done');
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
await test('真实子进程超时后仍能取到退出码与完整输出', async () => {
|
|
332
|
+
const result = await runUpgradeProcess({ binaryPath: process.execPath, args: ['-e', "setTimeout(() => console.log('finished'), 80)"], onLine: () => {}, timeoutMs: 10 });
|
|
333
|
+
assert.equal(result.timedOut, true);
|
|
334
|
+
const exited = await result.whenExited;
|
|
335
|
+
assert.equal(exited.code, 0);
|
|
336
|
+
assert.match(exited.raw, /finished/);
|
|
337
|
+
});
|
|
338
|
+
|
|
304
339
|
await test('run:升级后版本读不出来不算确认变化,不重连', async () => {
|
|
305
340
|
let reads = 0;
|
|
306
341
|
const { updater, calls } = harness({
|
|
@@ -384,6 +419,7 @@ await test('Connection 精确路由仅允许已认证的 owner 读状态、重
|
|
|
384
419
|
[statusRoute.path, 'GET'],
|
|
385
420
|
[statusRoute.path + '?refresh=1', 'GET'],
|
|
386
421
|
[updateRoute.path, 'GET'],
|
|
422
|
+
[updateRoute.path + '?status=1', 'GET'],
|
|
387
423
|
[updateRoute.path, 'POST'],
|
|
388
424
|
];
|
|
389
425
|
for (const [path, method] of routes) {
|