@openchamber/web 1.13.3 → 1.13.4
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/bin/cli-output.js +0 -7
- package/bin/cli.js +132 -5548
- package/bin/cli.test.js +674 -0
- package/bin/lib/DOCUMENTATION.md +121 -0
- package/bin/lib/cli-args.js +726 -0
- package/bin/lib/cli-errors.js +18 -0
- package/bin/lib/cli-executables.js +54 -0
- package/bin/lib/cli-http.js +215 -0
- package/bin/lib/cli-lifecycle.js +421 -0
- package/bin/lib/cli-log-files.js +93 -0
- package/bin/lib/cli-network.js +153 -0
- package/bin/lib/cli-paths.js +111 -0
- package/bin/lib/cli-ports.js +51 -0
- package/bin/lib/cli-process.js +292 -0
- package/bin/lib/cli-startup.js +370 -0
- package/bin/lib/cli-tunnel-capabilities.js +9 -0
- package/bin/lib/cli-tunnel-profiles.js +366 -0
- package/bin/lib/cli-tunnel-utils.js +300 -0
- package/bin/lib/commands-connect-url.js +173 -0
- package/bin/lib/commands-lifecycle.js +396 -0
- package/bin/lib/commands-logs.js +110 -0
- package/bin/lib/commands-serve.js +396 -0
- package/bin/lib/commands-startup.js +64 -0
- package/bin/lib/commands-status.js +114 -0
- package/bin/lib/commands-tunnel.js +1757 -0
- package/bin/lib/commands-update.js +141 -0
- package/dist/assets/{DiagramView-BmHROYsX.js → DiagramView-BAoYIAGR.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DiJE-v5Q.js → MarkdownRendererImpl-B0NE4mIY.js} +3 -3
- package/dist/assets/MultiRunWindow-BT4kt6aB.js +1 -0
- package/dist/assets/NewWorktreeDialog-Bx-zQyBp.js +167 -0
- package/dist/assets/{OnboardingScreen-DpBF8dKJ.js → OnboardingScreen-CbJOPUxm.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-1xaHUxPK.js → SessionSwitcherDropdown-BbUzUNEi.js} +1 -1
- package/dist/assets/{SettingsWindow-ChwLyQAe.js → SettingsWindow-CSb8eo8p.js} +1 -1
- package/dist/assets/{TerminalView-DGEBNuAp.js → TerminalView-ME5MOz7S.js} +1 -1
- package/dist/assets/es-Bk-yR0w-.js +15 -0
- package/dist/assets/fr-f1ibV7QU.js +13 -0
- package/dist/assets/index-B82A6jBD.css +1 -0
- package/dist/assets/index-BsXkdBYx.js +3 -0
- package/dist/assets/ja-D9mS3zWP.js +15 -0
- package/dist/assets/ko-Cpl1IA3D.js +15 -0
- package/dist/assets/{main-fm_8J7Lk.js → main-D6eC2bnV.js} +2 -2
- package/dist/assets/main-fsOGbLGZ.js +214 -0
- package/dist/assets/miniChat-DKGU29GZ.js +2 -0
- package/dist/assets/mobile-YHQHMYWC.js +2 -0
- package/dist/assets/pl-CYke_fxL.js +15 -0
- package/dist/assets/pt-BR-Clb6Z8up.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-3vxeddJO.js +2 -0
- package/dist/assets/{renderMobileApp-6s0G1iIJ.js → renderMobileApp-BrvLHYCY.js} +5 -5
- package/dist/assets/uk-CXn8cxXa.js +15 -0
- package/dist/assets/{useAppFontEffects-CV5C5O0r.js → useAppFontEffects-b7bqtGFf.js} +124 -119
- package/dist/assets/{vendor-.bun-CC_Xso_s.js → vendor-.bun-By2L9XvG.js} +1 -1
- package/dist/assets/zh-CN-BRwwlEdG.js +15 -0
- package/dist/assets/zh-TW-D5pg5Z8l.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +1 -1
- package/server/lib/cloudflare-tunnel.js +2 -2
- package/server/lib/event-stream/global-hub.js +1 -1
- package/server/lib/event-stream/index.js +0 -12
- package/server/lib/event-stream/runtime.js +1 -1
- package/server/lib/git/service.js +18 -0
- package/server/lib/git/service.test.js +48 -0
- package/server/lib/notifications/index.js +1 -4
- package/server/lib/opencode/agents.js +0 -6
- package/server/lib/opencode/commands.js +0 -5
- package/server/lib/opencode/config-entity-routes.js +39 -21
- package/server/lib/opencode/feature-routes-runtime.js +27 -62
- package/server/lib/opencode/lifecycle.js +13 -1
- package/server/lib/opencode/npm-registry.js +3 -3
- package/server/lib/opencode/proxy.js +3 -3
- package/server/lib/opencode/shared.js +0 -6
- package/server/lib/opencode/skills.js +0 -2
- package/server/lib/opencode/snippets.js +0 -2
- package/server/lib/package-manager.js +5 -5
- package/server/lib/projects/project-config.js +0 -8
- package/server/lib/quota/DOCUMENTATION.md +3 -1
- package/server/lib/quota/providers/claude.js +1 -1
- package/server/lib/quota/providers/codex.js +1 -1
- package/server/lib/quota/providers/copilot.js +1 -1
- package/server/lib/quota/providers/cursor.js +1 -1
- package/server/lib/quota/providers/google/auth.js +2 -2
- package/server/lib/quota/providers/google/index.js +0 -27
- package/server/lib/quota/providers/google/transforms.js +1 -1
- package/server/lib/quota/providers/index.js +1 -1
- package/server/lib/quota/providers/kimi.js +1 -1
- package/server/lib/quota/providers/minimax-cn-coding-plan.js +1 -1
- package/server/lib/quota/providers/minimax-coding-plan.js +1 -1
- package/server/lib/quota/providers/nanogpt.js +1 -1
- package/server/lib/quota/providers/ollama-cloud.js +1 -1
- package/server/lib/quota/providers/openai.js +4 -4
- package/server/lib/quota/providers/openrouter.js +1 -1
- package/server/lib/quota/providers/wafer.js +1 -1
- package/server/lib/quota/providers/zai.js +1 -1
- package/server/lib/quota/providers/zhipuai-coding-plan.js +1 -1
- package/server/lib/skills-catalog/cache.js +0 -4
- package/server/lib/skills-catalog/clawdhub/api.js +0 -32
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -52
- package/server/lib/skills-catalog/curated-sources.js +1 -1
- package/server/lib/skills-catalog/source.js +5 -0
- package/server/lib/terminal/runtime.js +11 -9
- package/server/lib/text/summarization.js +1 -1
- package/server/lib/tunnels/providers/ngrok.js +1 -1
- package/server/lib/tunnels/types.js +2 -2
- package/dist/assets/MultiRunWindow-yZoCT7F7.js +0 -1
- package/dist/assets/NewWorktreeDialog-CTMiE7Xd.js +0 -167
- package/dist/assets/es-CTE-E8we.js +0 -15
- package/dist/assets/fr-TVkZpyEo.js +0 -13
- package/dist/assets/index-B4pCDMbq.css +0 -1
- package/dist/assets/index-D9uMvTQF.js +0 -3
- package/dist/assets/ko-D_UCJIIL.js +0 -15
- package/dist/assets/main-eAd3a6tx.js +0 -214
- package/dist/assets/miniChat-Bbjg31IC.js +0 -2
- package/dist/assets/mobile-B3_j_DsB.js +0 -2
- package/dist/assets/pl-nDEkk-GZ.js +0 -15
- package/dist/assets/pt-BR-B_g2RcgU.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-CB13zs6N.js +0 -2
- package/dist/assets/uk-CWLhnPGW.js +0 -15
- package/dist/assets/zh-CN-BFxe1b5m.js +0 -15
- package/dist/assets/zh-TW-n-d-xbGV.js +0 -15
- package/server/lib/opencode/index.js +0 -95
- package/server/lib/quota/providers/interface.js +0 -55
- package/server/lib/skills-catalog/clawdhub/index.js +0 -30
- package/server/lib/skills-catalog/index.js +0 -42
- package/server/lib/terminal/index.js +0 -31
package/bin/cli.test.js
CHANGED
|
@@ -1,16 +1,177 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
2
4
|
import path from 'path';
|
|
5
|
+
import { createServer } from 'http';
|
|
6
|
+
import net from 'net';
|
|
3
7
|
import { spawn } from 'child_process';
|
|
4
8
|
import { pathToFileURL } from 'url';
|
|
5
9
|
|
|
6
10
|
import { isModuleCliExecution, normalizeCliEntryPath } from './cli-entry.js';
|
|
11
|
+
import { requestJson } from './lib/cli-http.js';
|
|
12
|
+
import { inspectTunnelAttachability } from './lib/cli-lifecycle.js';
|
|
7
13
|
import {
|
|
8
14
|
assertAuthenticatedNetworkExposure,
|
|
15
|
+
commands,
|
|
16
|
+
discoverOpenChamberInstanceOnPort,
|
|
17
|
+
discoverLifecycleInstances,
|
|
18
|
+
discoverRunningInstances,
|
|
19
|
+
discoverUnconfirmedRegistryInstanceOnPort,
|
|
20
|
+
ensureTunnelProfilesMigrated,
|
|
21
|
+
getInstanceFilePath,
|
|
22
|
+
getPidFilePath,
|
|
9
23
|
isOpenchamberCmdline,
|
|
10
24
|
isOpenchamberProcessRunning,
|
|
11
25
|
parseArgs,
|
|
26
|
+
resolveServeHost,
|
|
12
27
|
} from './cli.js';
|
|
13
28
|
|
|
29
|
+
async function withTempOpenChamberDataDir(fn) {
|
|
30
|
+
const previous = process.env.OPENCHAMBER_DATA_DIR;
|
|
31
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-cli-test-'));
|
|
32
|
+
process.env.OPENCHAMBER_DATA_DIR = dir;
|
|
33
|
+
try {
|
|
34
|
+
return await fn(dir);
|
|
35
|
+
} finally {
|
|
36
|
+
if (typeof previous === 'string') {
|
|
37
|
+
process.env.OPENCHAMBER_DATA_DIR = previous;
|
|
38
|
+
} else {
|
|
39
|
+
delete process.env.OPENCHAMBER_DATA_DIR;
|
|
40
|
+
}
|
|
41
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function createMockJsonResponse(body, ok = true) {
|
|
46
|
+
return {
|
|
47
|
+
ok,
|
|
48
|
+
json: async () => body,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function captureStdout(fn) {
|
|
53
|
+
const originalWrite = process.stdout.write;
|
|
54
|
+
let output = '';
|
|
55
|
+
process.stdout.write = (chunk, encoding, callback) => {
|
|
56
|
+
output += Buffer.isBuffer(chunk) ? chunk.toString('utf8') : String(chunk);
|
|
57
|
+
if (typeof encoding === 'function') encoding();
|
|
58
|
+
if (typeof callback === 'function') callback();
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
try {
|
|
62
|
+
await fn();
|
|
63
|
+
return output;
|
|
64
|
+
} finally {
|
|
65
|
+
process.stdout.write = originalWrite;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function startMockOpenChamberServer(options = {}) {
|
|
70
|
+
const runtime = options.runtime || 'web';
|
|
71
|
+
const pid = Number.isFinite(options.pid) ? options.pid : null;
|
|
72
|
+
let shutdownRequested = false;
|
|
73
|
+
let closed = false;
|
|
74
|
+
const server = createServer((req, res) => {
|
|
75
|
+
if (req.method === 'GET' && req.url === '/api/system/info') {
|
|
76
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
77
|
+
res.end(JSON.stringify({ runtime, pid }));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (req.method === 'POST' && req.url === '/api/system/shutdown') {
|
|
82
|
+
shutdownRequested = true;
|
|
83
|
+
res.writeHead(200, { 'content-type': 'application/json', connection: 'close' });
|
|
84
|
+
res.end(JSON.stringify({ ok: true }));
|
|
85
|
+
try {
|
|
86
|
+
server.close(() => {
|
|
87
|
+
closed = true;
|
|
88
|
+
});
|
|
89
|
+
} catch {
|
|
90
|
+
closed = true;
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
res.writeHead(404);
|
|
96
|
+
res.end('not found');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
100
|
+
const address = server.address();
|
|
101
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
102
|
+
return {
|
|
103
|
+
port,
|
|
104
|
+
get shutdownRequested() {
|
|
105
|
+
return shutdownRequested;
|
|
106
|
+
},
|
|
107
|
+
close: async () => {
|
|
108
|
+
if (closed || !server.listening) return;
|
|
109
|
+
await new Promise((resolve) => {
|
|
110
|
+
try {
|
|
111
|
+
server.close(() => {
|
|
112
|
+
closed = true;
|
|
113
|
+
resolve();
|
|
114
|
+
});
|
|
115
|
+
} catch {
|
|
116
|
+
closed = true;
|
|
117
|
+
resolve();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function allocateLoopbackPort() {
|
|
125
|
+
const server = net.createServer();
|
|
126
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
127
|
+
const address = server.address();
|
|
128
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
129
|
+
await new Promise((resolve) => server.close(resolve));
|
|
130
|
+
return port;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function waitForTcpPort(port, timeoutMs = 3000) {
|
|
134
|
+
const deadline = Date.now() + timeoutMs;
|
|
135
|
+
while (Date.now() < deadline) {
|
|
136
|
+
const connected = await new Promise((resolve) => {
|
|
137
|
+
const socket = net.createConnection({ port, host: '127.0.0.1' });
|
|
138
|
+
socket.once('connect', () => {
|
|
139
|
+
socket.destroy();
|
|
140
|
+
resolve(true);
|
|
141
|
+
});
|
|
142
|
+
socket.once('error', () => {
|
|
143
|
+
socket.destroy();
|
|
144
|
+
resolve(false);
|
|
145
|
+
});
|
|
146
|
+
socket.setTimeout(250, () => {
|
|
147
|
+
socket.destroy();
|
|
148
|
+
resolve(false);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
if (connected) return true;
|
|
152
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function spawnOpenChamberLikeIdleProcess() {
|
|
158
|
+
return spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)', 'openchamber-idle'], { stdio: 'ignore' });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function spawnOpenChamberLikeHungServer(port) {
|
|
162
|
+
const script = `
|
|
163
|
+
const net = require('net');
|
|
164
|
+
const sockets = new Set();
|
|
165
|
+
const server = net.createServer((socket) => {
|
|
166
|
+
sockets.add(socket);
|
|
167
|
+
socket.on('close', () => sockets.delete(socket));
|
|
168
|
+
});
|
|
169
|
+
server.listen(${port}, '127.0.0.1');
|
|
170
|
+
setInterval(() => {}, 1000);
|
|
171
|
+
`;
|
|
172
|
+
return spawn(process.execPath, ['-e', script, 'openchamber-hung-server'], { stdio: 'ignore' });
|
|
173
|
+
}
|
|
174
|
+
|
|
14
175
|
describe('cli args', () => {
|
|
15
176
|
it('accepts legacy daemon flags as no-ops', () => {
|
|
16
177
|
expect(parseArgs(['serve', '--daemon']).removedFlagErrors).toEqual([]);
|
|
@@ -111,6 +272,128 @@ describe('network-exposed auth validation', () => {
|
|
|
111
272
|
});
|
|
112
273
|
});
|
|
113
274
|
|
|
275
|
+
describe('serve host resolution', () => {
|
|
276
|
+
it('uses OPENCHAMBER_HOST when --host is not provided', () => {
|
|
277
|
+
const previous = process.env.OPENCHAMBER_HOST;
|
|
278
|
+
process.env.OPENCHAMBER_HOST = '192.0.2.20';
|
|
279
|
+
try {
|
|
280
|
+
expect(resolveServeHost(undefined)).toBe('192.0.2.20');
|
|
281
|
+
} finally {
|
|
282
|
+
if (typeof previous === 'string') {
|
|
283
|
+
process.env.OPENCHAMBER_HOST = previous;
|
|
284
|
+
} else {
|
|
285
|
+
delete process.env.OPENCHAMBER_HOST;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('prefers explicit --host over OPENCHAMBER_HOST', () => {
|
|
291
|
+
const previous = process.env.OPENCHAMBER_HOST;
|
|
292
|
+
process.env.OPENCHAMBER_HOST = '192.0.2.20';
|
|
293
|
+
try {
|
|
294
|
+
expect(resolveServeHost('192.0.2.21')).toBe('192.0.2.21');
|
|
295
|
+
} finally {
|
|
296
|
+
if (typeof previous === 'string') {
|
|
297
|
+
process.env.OPENCHAMBER_HOST = previous;
|
|
298
|
+
} else {
|
|
299
|
+
delete process.env.OPENCHAMBER_HOST;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe('compatibility exports', () => {
|
|
306
|
+
it('allows tunnel profile migration before command options are initialized', async () => {
|
|
307
|
+
await withTempOpenChamberDataDir(async () => {
|
|
308
|
+
const store = ensureTunnelProfilesMigrated();
|
|
309
|
+
|
|
310
|
+
expect(store).toEqual({ version: 1, profiles: [] });
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('includes ngrok in fallback tunnel providers when no server is reachable', async () => {
|
|
315
|
+
await withTempOpenChamberDataDir(async () => {
|
|
316
|
+
const output = await captureStdout(async () => {
|
|
317
|
+
await commands.tunnel({ json: true }, 'providers');
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const body = JSON.parse(output);
|
|
321
|
+
expect(body.source).toBe('fallback');
|
|
322
|
+
expect(body.providers.map((entry) => entry.provider)).toContain('ngrok');
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('supports ngrok quick dry-run with an explicit port', async () => {
|
|
327
|
+
await withTempOpenChamberDataDir(async () => {
|
|
328
|
+
const output = await captureStdout(async () => {
|
|
329
|
+
await commands.tunnel({
|
|
330
|
+
json: true,
|
|
331
|
+
dryRun: true,
|
|
332
|
+
explicitPort: true,
|
|
333
|
+
port: 3003,
|
|
334
|
+
provider: 'ngrok',
|
|
335
|
+
mode: 'quick',
|
|
336
|
+
}, 'start');
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
const body = JSON.parse(output);
|
|
340
|
+
expect(body).toEqual(expect.objectContaining({
|
|
341
|
+
ok: true,
|
|
342
|
+
dryRun: true,
|
|
343
|
+
provider: 'ngrok',
|
|
344
|
+
mode: 'quick',
|
|
345
|
+
}));
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
describe('CLI HTTP helpers', () => {
|
|
351
|
+
it('retries UI-authenticated API requests with the stored instance password', async () => {
|
|
352
|
+
await withTempOpenChamberDataDir(async () => {
|
|
353
|
+
const port = 45678;
|
|
354
|
+
fs.writeFileSync(await getInstanceFilePath(port), JSON.stringify({ port, uiPassword: 'secret' }, null, 2));
|
|
355
|
+
const originalFetch = globalThis.fetch;
|
|
356
|
+
const calls = [];
|
|
357
|
+
globalThis.fetch = async (url, options = {}) => {
|
|
358
|
+
calls.push({ url: String(url), options });
|
|
359
|
+
if (String(url).endsWith('/auth/session')) {
|
|
360
|
+
expect(JSON.parse(options.body)).toEqual({ password: 'secret' });
|
|
361
|
+
return {
|
|
362
|
+
ok: true,
|
|
363
|
+
headers: { get: (name) => name.toLowerCase() === 'set-cookie' ? 'oc_ui_session=session-token; Path=/; HttpOnly' : null },
|
|
364
|
+
json: async () => ({ authenticated: true }),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
if (options.headers?.Cookie === 'oc_ui_session=session-token') {
|
|
368
|
+
return createMockJsonResponse({ ok: true });
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
ok: false,
|
|
372
|
+
status: 401,
|
|
373
|
+
json: async () => ({ error: 'UI authentication required', locked: true }),
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
try {
|
|
378
|
+
const { response, body } = await requestJson(port, '/api/openchamber/tunnel/start', {
|
|
379
|
+
method: 'POST',
|
|
380
|
+
body: JSON.stringify({ provider: 'ngrok', mode: 'quick' }),
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
expect(response.ok).toBe(true);
|
|
384
|
+
expect(body).toEqual({ ok: true });
|
|
385
|
+
expect(calls.map((call) => new URL(call.url).pathname)).toEqual([
|
|
386
|
+
'/api/openchamber/tunnel/start',
|
|
387
|
+
'/auth/session',
|
|
388
|
+
'/api/openchamber/tunnel/start',
|
|
389
|
+
]);
|
|
390
|
+
} finally {
|
|
391
|
+
globalThis.fetch = originalFetch;
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
114
397
|
describe('cli entry detection', () => {
|
|
115
398
|
const modulePath = '/tmp/openchamber/bin/cli.js';
|
|
116
399
|
const moduleUrl = pathToFileURL(modulePath).href;
|
|
@@ -198,3 +481,394 @@ describe('isOpenchamberProcessRunning', () => {
|
|
|
198
481
|
}
|
|
199
482
|
);
|
|
200
483
|
});
|
|
484
|
+
|
|
485
|
+
describe('lifecycle instance discovery', () => {
|
|
486
|
+
it('does not attribute a desktop runtime response to a different explicit port', async () => {
|
|
487
|
+
await withTempOpenChamberDataDir(async (dir) => {
|
|
488
|
+
fs.writeFileSync(path.join(dir, 'settings.json'), JSON.stringify({ desktopLocalPort: 57123 }, null, 2));
|
|
489
|
+
|
|
490
|
+
const instance = await discoverOpenChamberInstanceOnPort(3003, {
|
|
491
|
+
fetchImpl: async () => createMockJsonResponse({ runtime: 'desktop', pid: 934 }),
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
expect(instance).toBeNull();
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('attributes a desktop runtime response to its configured desktop port', async () => {
|
|
499
|
+
await withTempOpenChamberDataDir(async (dir) => {
|
|
500
|
+
fs.writeFileSync(path.join(dir, 'settings.json'), JSON.stringify({ desktopLocalPort: 57123 }, null, 2));
|
|
501
|
+
|
|
502
|
+
const instance = await discoverOpenChamberInstanceOnPort(57123, {
|
|
503
|
+
fetchImpl: async () => createMockJsonResponse({ runtime: 'desktop', pid: 934 }),
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
expect(instance).toEqual(expect.objectContaining({
|
|
507
|
+
port: 57123,
|
|
508
|
+
pid: 934,
|
|
509
|
+
runtime: 'desktop',
|
|
510
|
+
}));
|
|
511
|
+
});
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it('does not mark tunnel attachability as desktop for a different explicit port', async () => {
|
|
515
|
+
await withTempOpenChamberDataDir(async (dir) => {
|
|
516
|
+
fs.writeFileSync(path.join(dir, 'settings.json'), JSON.stringify({ desktopLocalPort: 57123 }, null, 2));
|
|
517
|
+
const originalFetch = globalThis.fetch;
|
|
518
|
+
globalThis.fetch = async () => createMockJsonResponse({ runtime: 'desktop', pid: 934 });
|
|
519
|
+
try {
|
|
520
|
+
const attachability = await inspectTunnelAttachability(3004, { requireHealthy: false });
|
|
521
|
+
|
|
522
|
+
expect(attachability.reason).not.toBe('desktop');
|
|
523
|
+
} finally {
|
|
524
|
+
globalThis.fetch = originalFetch;
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it('keeps pid and instance files when live port probe confirms a cmdline mismatch', async () => {
|
|
530
|
+
await withTempOpenChamberDataDir(async () => {
|
|
531
|
+
const port = 45123;
|
|
532
|
+
const pid = 12345;
|
|
533
|
+
const pidFile = await getPidFilePath(port);
|
|
534
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
535
|
+
fs.writeFileSync(pidFile, String(pid));
|
|
536
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, launchMode: 'daemon', startedAt: 123 }, null, 2));
|
|
537
|
+
|
|
538
|
+
const instances = await discoverRunningInstances({
|
|
539
|
+
fetchImpl: async () => createMockJsonResponse({ runtime: 'web', pid }),
|
|
540
|
+
getOpenchamberProcessState: () => 'mismatched',
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
expect(instances).toEqual([
|
|
544
|
+
expect.objectContaining({ port, pid, runtime: 'web', source: 'registry+probe' }),
|
|
545
|
+
]);
|
|
546
|
+
expect(fs.existsSync(pidFile)).toBe(true);
|
|
547
|
+
expect(fs.existsSync(instanceFile)).toBe(true);
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
it('removes stale pid and instance files when a cmdline mismatch is not confirmed by live probe', async () => {
|
|
552
|
+
await withTempOpenChamberDataDir(async () => {
|
|
553
|
+
const port = 45124;
|
|
554
|
+
const pid = 12346;
|
|
555
|
+
const pidFile = await getPidFilePath(port);
|
|
556
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
557
|
+
fs.writeFileSync(pidFile, String(pid));
|
|
558
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, launchMode: 'daemon' }, null, 2));
|
|
559
|
+
|
|
560
|
+
const instances = await discoverRunningInstances({
|
|
561
|
+
fetchImpl: async () => createMockJsonResponse(null, false),
|
|
562
|
+
getOpenchamberProcessState: () => 'mismatched',
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
expect(instances).toEqual([]);
|
|
566
|
+
expect(fs.existsSync(pidFile)).toBe(false);
|
|
567
|
+
expect(fs.existsSync(instanceFile)).toBe(false);
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
it('preserves matched pid and instance files when the recorded port probe is inconclusive', async () => {
|
|
572
|
+
await withTempOpenChamberDataDir(async () => {
|
|
573
|
+
const port = 45126;
|
|
574
|
+
const pid = 12347;
|
|
575
|
+
const pidFile = await getPidFilePath(port);
|
|
576
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
577
|
+
fs.writeFileSync(pidFile, String(pid));
|
|
578
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, launchMode: 'daemon' }, null, 2));
|
|
579
|
+
|
|
580
|
+
const instances = await discoverRunningInstances({
|
|
581
|
+
fetchImpl: async () => createMockJsonResponse(null, false),
|
|
582
|
+
getOpenchamberProcessState: () => 'matched',
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
expect(instances).toEqual([]);
|
|
586
|
+
expect(fs.existsSync(pidFile)).toBe(true);
|
|
587
|
+
expect(fs.existsSync(instanceFile)).toBe(true);
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
it('preserves unknown-identity pid and instance files when the recorded port probe is inconclusive', async () => {
|
|
592
|
+
await withTempOpenChamberDataDir(async () => {
|
|
593
|
+
const port = 45129;
|
|
594
|
+
const pid = 12350;
|
|
595
|
+
const pidFile = await getPidFilePath(port);
|
|
596
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
597
|
+
fs.writeFileSync(pidFile, String(pid));
|
|
598
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, launchMode: 'daemon' }, null, 2));
|
|
599
|
+
|
|
600
|
+
const instances = await discoverRunningInstances({
|
|
601
|
+
fetchImpl: async () => createMockJsonResponse(null, false),
|
|
602
|
+
getOpenchamberProcessState: () => 'unknown',
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
expect(instances).toEqual([]);
|
|
606
|
+
expect(fs.existsSync(pidFile)).toBe(true);
|
|
607
|
+
expect(fs.existsSync(instanceFile)).toBe(true);
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
it('uses the live system-info pid instead of a stale OpenChamber-looking pid-file pid', async () => {
|
|
612
|
+
await withTempOpenChamberDataDir(async () => {
|
|
613
|
+
const port = 45127;
|
|
614
|
+
const stalePid = 12348;
|
|
615
|
+
const livePid = 54321;
|
|
616
|
+
const pidFile = await getPidFilePath(port);
|
|
617
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
618
|
+
fs.writeFileSync(pidFile, String(stalePid));
|
|
619
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, launchMode: 'daemon' }, null, 2));
|
|
620
|
+
|
|
621
|
+
const instances = await discoverRunningInstances({
|
|
622
|
+
fetchImpl: async () => createMockJsonResponse({ runtime: 'web', pid: livePid }),
|
|
623
|
+
getOpenchamberProcessState: () => 'matched',
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
expect(instances).toEqual([
|
|
627
|
+
expect.objectContaining({ port, pid: livePid, runtime: 'web', source: 'registry+probe' }),
|
|
628
|
+
]);
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('uses the explicit host when probing a pid-file entry without a stored host', async () => {
|
|
633
|
+
await withTempOpenChamberDataDir(async () => {
|
|
634
|
+
const port = 45128;
|
|
635
|
+
const pid = 12349;
|
|
636
|
+
const host = '192.0.2.10';
|
|
637
|
+
const urls = [];
|
|
638
|
+
fs.writeFileSync(await getPidFilePath(port), String(pid));
|
|
639
|
+
fs.writeFileSync(await getInstanceFilePath(port), JSON.stringify({ port, launchMode: 'daemon' }, null, 2));
|
|
640
|
+
|
|
641
|
+
const instances = await discoverLifecycleInstances(
|
|
642
|
+
{ explicitPort: true, port, host },
|
|
643
|
+
{
|
|
644
|
+
fetchImpl: async (url) => {
|
|
645
|
+
urls.push(String(url));
|
|
646
|
+
return createMockJsonResponse({ runtime: 'web', pid });
|
|
647
|
+
},
|
|
648
|
+
getOpenchamberProcessState: () => 'matched',
|
|
649
|
+
},
|
|
650
|
+
);
|
|
651
|
+
|
|
652
|
+
expect(instances).toEqual([
|
|
653
|
+
expect.objectContaining({ port, pid, runtime: 'web', source: 'registry+probe' }),
|
|
654
|
+
]);
|
|
655
|
+
expect(new URL(urls[0]).hostname).toBe(host);
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('tries loopback before treating an explicit-host pid-file probe as inconclusive', async () => {
|
|
660
|
+
await withTempOpenChamberDataDir(async () => {
|
|
661
|
+
const port = 45130;
|
|
662
|
+
const pid = 12351;
|
|
663
|
+
const host = '192.0.2.11';
|
|
664
|
+
const urls = [];
|
|
665
|
+
fs.writeFileSync(await getPidFilePath(port), String(pid));
|
|
666
|
+
fs.writeFileSync(await getInstanceFilePath(port), JSON.stringify({ port, launchMode: 'daemon' }, null, 2));
|
|
667
|
+
|
|
668
|
+
const instances = await discoverLifecycleInstances(
|
|
669
|
+
{ explicitPort: true, port, host },
|
|
670
|
+
{
|
|
671
|
+
fetchImpl: async (url) => {
|
|
672
|
+
urls.push(String(url));
|
|
673
|
+
return new URL(String(url)).hostname === '127.0.0.1'
|
|
674
|
+
? createMockJsonResponse({ runtime: 'web', pid })
|
|
675
|
+
: createMockJsonResponse(null, false);
|
|
676
|
+
},
|
|
677
|
+
getOpenchamberProcessState: () => 'matched',
|
|
678
|
+
},
|
|
679
|
+
);
|
|
680
|
+
|
|
681
|
+
expect(urls.map((url) => new URL(url).hostname)).toContain(host);
|
|
682
|
+
expect(urls.map((url) => new URL(url).hostname)).toContain('127.0.0.1');
|
|
683
|
+
expect(instances).toEqual([
|
|
684
|
+
expect.objectContaining({ port, pid, runtime: 'web', source: 'registry+probe' }),
|
|
685
|
+
]);
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it('does not accept a fallback loopback probe with a different pid for a concrete host registry', async () => {
|
|
690
|
+
await withTempOpenChamberDataDir(async () => {
|
|
691
|
+
const port = 45131;
|
|
692
|
+
const pid = 12352;
|
|
693
|
+
const otherPid = 54322;
|
|
694
|
+
const host = '192.0.2.12';
|
|
695
|
+
const pidFile = await getPidFilePath(port);
|
|
696
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
697
|
+
fs.writeFileSync(pidFile, String(pid));
|
|
698
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, host, launchMode: 'daemon' }, null, 2));
|
|
699
|
+
|
|
700
|
+
const instances = await discoverLifecycleInstances(
|
|
701
|
+
{ explicitPort: true, port, host },
|
|
702
|
+
{
|
|
703
|
+
fetchImpl: async (url) => {
|
|
704
|
+
return new URL(String(url)).hostname === '127.0.0.1'
|
|
705
|
+
? createMockJsonResponse({ runtime: 'web', pid: otherPid })
|
|
706
|
+
: createMockJsonResponse(null, false);
|
|
707
|
+
},
|
|
708
|
+
getOpenchamberProcessState: () => 'matched',
|
|
709
|
+
},
|
|
710
|
+
);
|
|
711
|
+
|
|
712
|
+
expect(instances).toEqual([]);
|
|
713
|
+
expect(fs.existsSync(pidFile)).toBe(true);
|
|
714
|
+
expect(fs.existsSync(instanceFile)).toBe(true);
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
it('discovers an explicit live OpenChamber port without a pid-file registry entry', async () => {
|
|
719
|
+
await withTempOpenChamberDataDir(async () => {
|
|
720
|
+
const port = 45125;
|
|
721
|
+
const instances = await discoverLifecycleInstances(
|
|
722
|
+
{ explicitPort: true, port },
|
|
723
|
+
{ fetchImpl: async () => createMockJsonResponse({ runtime: 'web', pid: null }) },
|
|
724
|
+
);
|
|
725
|
+
|
|
726
|
+
expect(instances).toEqual([
|
|
727
|
+
expect.objectContaining({ port, pid: null, runtime: 'web', source: 'probe' }),
|
|
728
|
+
]);
|
|
729
|
+
});
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
it('cleans a matched pid-file entry without stopping it when the recorded port is free', async () => {
|
|
733
|
+
await withTempOpenChamberDataDir(async () => {
|
|
734
|
+
const port = await allocateLoopbackPort();
|
|
735
|
+
const child = spawnOpenChamberLikeIdleProcess();
|
|
736
|
+
const pidFile = await getPidFilePath(port);
|
|
737
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
738
|
+
try {
|
|
739
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
740
|
+
fs.writeFileSync(pidFile, String(child.pid));
|
|
741
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, host: '127.0.0.1', launchMode: 'daemon' }, null, 2));
|
|
742
|
+
|
|
743
|
+
const instance = await discoverUnconfirmedRegistryInstanceOnPort(port, { host: '127.0.0.1' });
|
|
744
|
+
|
|
745
|
+
expect(instance).toBeNull();
|
|
746
|
+
expect(fs.existsSync(pidFile)).toBe(false);
|
|
747
|
+
expect(fs.existsSync(instanceFile)).toBe(false);
|
|
748
|
+
expect(child.exitCode).toBeNull();
|
|
749
|
+
} finally {
|
|
750
|
+
child.kill('SIGKILL');
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
describe('lifecycle commands with unmanaged explicit ports', () => {
|
|
757
|
+
it('serve refuses to start on a live OpenChamber port without requiring pid files', async () => {
|
|
758
|
+
await withTempOpenChamberDataDir(async () => {
|
|
759
|
+
const server = await startMockOpenChamberServer();
|
|
760
|
+
try {
|
|
761
|
+
await expect(commands.serve({ explicitPort: true, port: server.port, quiet: true })).rejects.toThrow(
|
|
762
|
+
/already running on port/
|
|
763
|
+
);
|
|
764
|
+
} finally {
|
|
765
|
+
await server.close();
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
it('status --port reports a live unmanaged server when the registry is empty', async () => {
|
|
771
|
+
await withTempOpenChamberDataDir(async () => {
|
|
772
|
+
const server = await startMockOpenChamberServer();
|
|
773
|
+
try {
|
|
774
|
+
const output = await captureStdout(() => commands.status({ explicitPort: true, port: server.port, json: true }));
|
|
775
|
+
const payload = JSON.parse(output);
|
|
776
|
+
expect(payload.state).toBe('running');
|
|
777
|
+
expect(payload.runningCount).toBe(1);
|
|
778
|
+
expect(payload.instances).toEqual([
|
|
779
|
+
expect.objectContaining({ runtime: 'unmanaged', port: server.port, pid: null }),
|
|
780
|
+
]);
|
|
781
|
+
} finally {
|
|
782
|
+
await server.close();
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
it('stop --port reaches unmanaged shutdown when the registry is empty', async () => {
|
|
788
|
+
await withTempOpenChamberDataDir(async () => {
|
|
789
|
+
const server = await startMockOpenChamberServer();
|
|
790
|
+
try {
|
|
791
|
+
await commands.stop({ explicitPort: true, port: server.port, quiet: true, suppressQuietOutput: true });
|
|
792
|
+
expect(server.shutdownRequested).toBe(true);
|
|
793
|
+
} finally {
|
|
794
|
+
await server.close();
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
it('stop --port can recover a matched pid-file instance whose HTTP endpoint is unresponsive', async () => {
|
|
800
|
+
await withTempOpenChamberDataDir(async () => {
|
|
801
|
+
const port = await allocateLoopbackPort();
|
|
802
|
+
const child = spawnOpenChamberLikeHungServer(port);
|
|
803
|
+
const pidFile = await getPidFilePath(port);
|
|
804
|
+
const instanceFile = await getInstanceFilePath(port);
|
|
805
|
+
try {
|
|
806
|
+
expect(await waitForTcpPort(port)).toBe(true);
|
|
807
|
+
fs.writeFileSync(pidFile, String(child.pid));
|
|
808
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port, host: '127.0.0.1', launchMode: 'daemon' }, null, 2));
|
|
809
|
+
|
|
810
|
+
await commands.stop({ explicitPort: true, port, host: '127.0.0.1', quiet: true, suppressQuietOutput: true });
|
|
811
|
+
|
|
812
|
+
expect(fs.existsSync(pidFile)).toBe(false);
|
|
813
|
+
expect(fs.existsSync(instanceFile)).toBe(false);
|
|
814
|
+
expect(child.exitCode !== null || child.signalCode !== null).toBe(true);
|
|
815
|
+
} finally {
|
|
816
|
+
child.kill('SIGKILL');
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
it('plain stop ignores a stale CLI registry entry that resolves to desktop runtime', async () => {
|
|
822
|
+
await withTempOpenChamberDataDir(async () => {
|
|
823
|
+
const server = await startMockOpenChamberServer({ runtime: 'desktop' });
|
|
824
|
+
const child = spawn('sleep', ['30'], { stdio: 'ignore' });
|
|
825
|
+
const pidFile = await getPidFilePath(server.port);
|
|
826
|
+
const instanceFile = await getInstanceFilePath(server.port);
|
|
827
|
+
try {
|
|
828
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
829
|
+
fs.writeFileSync(pidFile, String(child.pid));
|
|
830
|
+
fs.writeFileSync(instanceFile, JSON.stringify({ port: server.port, launchMode: 'daemon' }, null, 2));
|
|
831
|
+
|
|
832
|
+
await commands.stop({ quiet: true, suppressQuietOutput: true });
|
|
833
|
+
|
|
834
|
+
expect(server.shutdownRequested).toBe(false);
|
|
835
|
+
expect(fs.existsSync(pidFile)).toBe(false);
|
|
836
|
+
expect(fs.existsSync(instanceFile)).toBe(false);
|
|
837
|
+
} finally {
|
|
838
|
+
child.kill('SIGKILL');
|
|
839
|
+
await server.close();
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it('restart --port restarts a live unmanaged server through the shared explicit-port discovery path', async () => {
|
|
845
|
+
await withTempOpenChamberDataDir(async () => {
|
|
846
|
+
const server = await startMockOpenChamberServer();
|
|
847
|
+
const calls = [];
|
|
848
|
+
const host = '127.0.0.1';
|
|
849
|
+
try {
|
|
850
|
+
const output = await captureStdout(() => commands.restart.call({
|
|
851
|
+
stop: async (options) => {
|
|
852
|
+
calls.push(['stop', options.port, options.host]);
|
|
853
|
+
},
|
|
854
|
+
serve: async (options) => {
|
|
855
|
+
calls.push(['serve', options.port, options.host]);
|
|
856
|
+
return options.port;
|
|
857
|
+
},
|
|
858
|
+
}, { explicitPort: true, port: server.port, host, json: true }));
|
|
859
|
+
|
|
860
|
+
const payload = JSON.parse(output);
|
|
861
|
+
expect(calls).toEqual([
|
|
862
|
+
['stop', server.port, host],
|
|
863
|
+
['serve', server.port, host],
|
|
864
|
+
]);
|
|
865
|
+
expect(payload.restartedCount).toBe(1);
|
|
866
|
+
expect(payload.results).toEqual([
|
|
867
|
+
expect.objectContaining({ fromPort: server.port, toPort: server.port, ok: true }),
|
|
868
|
+
]);
|
|
869
|
+
} finally {
|
|
870
|
+
await server.close();
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
});
|