@openchamber/web 1.20.0 → 1.21.1
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.test.js +35 -0
- package/bin/lib/DOCUMENTATION.md +12 -0
- package/bin/lib/cli-settings-accessors.js +111 -0
- package/bin/lib/cli-settings-accessors.test.js +189 -0
- package/bin/lib/cli-startup.js +29 -9
- package/bin/lib/commands-connect-url.js +12 -14
- package/dist/assets/{CodeMirrorCommentWidgets-C36E738Y.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
- package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
- package/dist/assets/DiffView-Db6bjVv1.js +4 -0
- package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
- package/dist/assets/GitView-CHzJxTi0.js +6 -0
- package/dist/assets/{JsonTreeView-KnXFN2A-.js → JsonTreeView-CggOsLot.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
- package/dist/assets/OnboardingScreen-C98d69Fp.js +1 -0
- package/dist/assets/{PatchDiff-BzVOVog8.js → PatchDiff-DJYMUiXA.js} +1 -1
- package/dist/assets/PierreDiffViewer-CY2bx_SB.js +157 -0
- package/dist/assets/PlanView-PkiOY_9H.js +5 -0
- package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
- package/dist/assets/SettingsWindow-oyOm2fHR.js +1 -0
- package/dist/assets/{ToolOutputDialog-BB1c--Zr.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-DaOIDISD.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-lESMT-2b.js → VirtualizedFileDiff-BP7ebDFF.js} +4 -4
- package/dist/assets/{Virtualizer-X_7XPoTH.js → Virtualizer-CZlLSacm.js} +1 -1
- package/dist/assets/Virtualizer-D_a8gKmg.js +1 -0
- package/dist/assets/{WalkthroughView-CaSYE0lw.js → WalkthroughView-MuJodAHD.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-DkRR5b75.js → computeVirtualFileMetrics-CZ0xPeaT.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-C9abMBTb.js +1 -0
- package/dist/assets/de-CEoCz3j6.js +9 -0
- package/dist/assets/es-DwyXCqaL.js +15 -0
- package/dist/assets/fr-CS7Csln9.js +13 -0
- package/dist/assets/index-CUKcHnUA.css +1 -0
- package/dist/assets/index-CaPAjwXQ.js +1 -0
- package/dist/assets/index-DIvDEKE-.js +7 -0
- package/dist/assets/{isDiffPlainText-BG53Ixxy.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
- package/dist/assets/{isFilePlainText-BbV-39jl.js → isFilePlainText-DiLRrkJr.js} +1 -1
- package/dist/assets/ja-vnwqLcx6.js +15 -0
- package/dist/assets/ko-CXuSfZv5.js +15 -0
- package/dist/assets/main-D5RWr6sJ.js +2 -0
- package/dist/assets/main-DLlfDjQ_.js +926 -0
- package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
- package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
- package/dist/assets/{miniChat-ldEghBLB.js → miniChat-CqR3icsk.js} +2 -2
- package/dist/assets/mobile-RN_UTTlB.js +2 -0
- package/dist/assets/{patchFileDiff-BcFaMtMu.js → patchFileDiff-CjRR5ESs.js} +1 -1
- package/dist/assets/pl-BJxry0Mi.js +15 -0
- package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-1wC94fQK.js +2 -0
- package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +1 -0
- package/dist/assets/{shikiHighlight-DCT2Sq_z.js → shikiHighlight-fGmFkxAM.js} +1 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
- package/dist/assets/uk-ClgQjmlw.js +15 -0
- package/dist/assets/{useAppFontEffects-B53Rb6m7.js → useAppFontEffects-KP8_yiGW.js} +176 -184
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +2 -0
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
- package/dist/assets/{vendor-base-ui-DsHmyMwp.js → vendor-base-ui-BeMD8X_w.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-vch3tJ4c.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
- package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
- package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
- package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
- package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
- package/dist/assets/{vendor-framer-motion-CRSgBxjL.js → vendor-framer-motion-livSKyyV.js} +1 -1
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +1 -0
- package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
- package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
- package/dist/assets/{vendor-motion-dom-DJLgZh4Q.js → vendor-motion-dom-D_o3BTI3.js} +1 -1
- package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
- package/dist/assets/vendor-zod-BLfBSgBh.js +39 -0
- package/dist/assets/{web-components-pcwCTWjC.js → web-components-DOXvU-tB.js} +4 -4
- package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
- package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
- package/dist/index.html +7 -7
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/dist/site.webmanifest +1 -1
- package/dist/sw.js +1 -1
- package/package.json +4 -4
- package/public/site.webmanifest +1 -1
- package/server/index.js +10 -2
- package/server/lib/client-auth/pairing.js +8 -7
- package/server/lib/client-auth/pairing.test.js +5 -1
- package/server/lib/client-auth/remote-clients.js +9 -1
- package/server/lib/client-auth/remote-clients.test.js +17 -0
- package/server/lib/cloudflare-tunnel.js +1 -1
- package/server/lib/fs/DOCUMENTATION.md +1 -0
- package/server/lib/fs/routes.js +21 -0
- package/server/lib/fs/routes.test.js +89 -3
- package/server/lib/git/DOCUMENTATION.md +4 -3
- package/server/lib/git/service.js +128 -6
- package/server/lib/git/service.test.js +191 -1
- package/server/lib/github/pr-status.js +10 -1
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +3 -1
- package/server/lib/markdown-image-grants/routes.test.js +14 -0
- package/server/lib/openchamber-sessions/routes.js +4 -1
- package/server/lib/openchamber-sessions/routes.test.js +23 -0
- package/server/lib/opencode/env-runtime.js +17 -1
- package/server/lib/opencode/env-runtime.test.js +56 -0
- package/server/lib/opencode/lifecycle.js +48 -9
- package/server/lib/opencode/lifecycle.test.js +125 -1
- package/server/lib/opencode/managed-process-registry.d.ts +13 -0
- package/server/lib/opencode/managed-process-registry.js +213 -163
- package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
- package/server/lib/opencode/project-directory-runtime.js +16 -11
- package/server/lib/opencode/project-directory-runtime.test.js +32 -12
- package/server/lib/opencode/pwa-manifest-routes.js +1 -1
- package/server/lib/opencode/routes-upgrade.test.js +96 -12
- package/server/lib/opencode/routes.js +53 -5
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +10 -0
- package/server/lib/opencode/theme-runtime.js +1 -1
- package/server/lib/opencode/theme-runtime.test.js +129 -0
- package/server/lib/quota/DOCUMENTATION.md +19 -0
- package/server/lib/quota/providers/copilot.js +26 -10
- package/server/lib/quota/providers/copilot.test.js +78 -0
- package/server/lib/quota/providers/index.js +4 -18
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/service.js +34 -2
- package/server/lib/relay/service.test.js +69 -0
- package/server/lib/session-goal/runtime.js +2 -1
- package/server/lib/session-goal/runtime.test.js +4 -2
- package/server/lib/small-model/DOCUMENTATION.md +11 -5
- package/server/lib/small-model/call.js +64 -20
- package/server/lib/small-model/call.test.js +184 -2
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +29 -1
- package/server/lib/terminal/runtime.test.js +26 -0
- package/server/lib/tunnels/install-help.js +2 -2
- package/server/lib/tunnels/install-help.test.js +9 -0
- package/server/lib/ui-auth/ui-auth.js +2 -2
- package/server/lib/ui-auth/ui-auth.test.js +2 -2
- package/server/lib/walkthrough/languages.js +1 -0
- package/dist/assets/CommitSection-C-F3AX6D.js +0 -1
- package/dist/assets/DiagramEditor-BPECg1jS.js +0 -1
- package/dist/assets/DiagramView-D0YNMix8.js +0 -1
- package/dist/assets/DiffView-BHWaMYCC.js +0 -4
- package/dist/assets/FilesView-NMBCW2Tm.js +0 -14
- package/dist/assets/GitView-Rp8P1KEI.js +0 -6
- package/dist/assets/MarkdownImageGallery-BMn3mtor.js +0 -1
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +0 -12
- package/dist/assets/OnboardingScreen-CenIeD4v.js +0 -1
- package/dist/assets/PierreDiffViewer-Dlby4XqT.js +0 -136
- package/dist/assets/PlanView-Czu1KMJa.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +0 -1
- package/dist/assets/SettingsView-B6vmuf-c.js +0 -28
- package/dist/assets/SettingsWindow-CauZpdD3.js +0 -1
- package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +0 -1
- package/dist/assets/de-DFdX3ABv.js +0 -9
- package/dist/assets/es-iC-FKvV9.js +0 -15
- package/dist/assets/fr-BBbi_1AL.js +0 -13
- package/dist/assets/index-BiEgzzkg.js +0 -1
- package/dist/assets/index-Cwmuwk3V.js +0 -7
- package/dist/assets/index-GNm1wgUH.css +0 -1
- package/dist/assets/ja-DQLQJL2J.js +0 -15
- package/dist/assets/ko-BeElEB4Y.js +0 -15
- package/dist/assets/main-Dpzo18z7.js +0 -2
- package/dist/assets/main-WMjtYzJs.js +0 -921
- package/dist/assets/markdownCore--tDmyI_v.js +0 -2
- package/dist/assets/mobile-Dk-VGreF.js +0 -2
- package/dist/assets/pl-CLHt2_vV.js +0 -15
- package/dist/assets/pt-BR-C_MPUq7e.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +0 -2
- package/dist/assets/renderMobileApp-CDfHS5rr.js +0 -25
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +0 -15
- package/dist/assets/scheduledTasksApi-BFSlqgnG.js +0 -1
- package/dist/assets/uk-PhsC-c4-.js +0 -15
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +0 -2
- package/dist/assets/vendor-zod-C9ioTTSo.js +0 -39
- package/dist/assets/zh-CN-wF-NOFHM.js +0 -15
- package/dist/assets/zh-TW-4m4-A7rT.js +0 -15
- package/server/lib/quota/providers/command-code.js +0 -90
- package/server/lib/quota/providers/command-code.test.js +0 -85
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createManagedProcessRegistry } from './managed-process-registry.js';
|
|
4
|
+
|
|
5
|
+
// The registry takes its filesystem and child-process helpers as dependencies,
|
|
6
|
+
// so these tests inject fakes instead of mocking node builtins.
|
|
7
|
+
const readdirMock = vi.fn();
|
|
8
|
+
const readFileMock = vi.fn();
|
|
9
|
+
const rmMock = vi.fn();
|
|
10
|
+
const mkdirMock = vi.fn();
|
|
11
|
+
const writeFileMock = vi.fn();
|
|
12
|
+
const renameMock = vi.fn();
|
|
13
|
+
|
|
14
|
+
// `execFileImpl` is the swappable per-test implementation, called with the same
|
|
15
|
+
// (cmd, args, opts, cb) shape the callback-style `execFile` uses; the injected
|
|
16
|
+
// `execFileAsync` adapts it to the `{ stdout, stderr }` promise the module awaits.
|
|
17
|
+
const execFileImpl = vi.fn();
|
|
18
|
+
|
|
19
|
+
const { registerManagedProcess, unregisterManagedProcess, reapOrphanedProcesses } = createManagedProcessRegistry({
|
|
20
|
+
fs: {
|
|
21
|
+
readdir: readdirMock,
|
|
22
|
+
readFile: readFileMock,
|
|
23
|
+
rm: rmMock,
|
|
24
|
+
mkdir: mkdirMock,
|
|
25
|
+
writeFile: writeFileMock,
|
|
26
|
+
rename: renameMock,
|
|
27
|
+
},
|
|
28
|
+
execFileAsync: (cmd, args, opts) =>
|
|
29
|
+
new Promise((resolve, reject) => {
|
|
30
|
+
execFileImpl(cmd, args, opts, (err, stdout, stderr) =>
|
|
31
|
+
err ? reject(err) : resolve({ stdout: stdout ?? '', stderr: stderr ?? '' }));
|
|
32
|
+
}),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const ORIGINAL_PLATFORM = Object.getOwnPropertyDescriptor(process, 'platform');
|
|
36
|
+
const ORIGINAL_KILL = process.kill;
|
|
37
|
+
const killMock = vi.fn();
|
|
38
|
+
|
|
39
|
+
const setPlatform = (platform) => {
|
|
40
|
+
Object.defineProperty(process, 'platform', { value: platform, configurable: true });
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const restorePlatform = () => {
|
|
44
|
+
if (ORIGINAL_PLATFORM) {
|
|
45
|
+
Object.defineProperty(process, 'platform', ORIGINAL_PLATFORM);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const installKillMock = () => {
|
|
50
|
+
Object.defineProperty(process, 'kill', { value: killMock, configurable: true });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const restoreKill = () => {
|
|
54
|
+
Object.defineProperty(process, 'kill', { value: ORIGINAL_KILL, configurable: true });
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Helper to make given pids look alive on signal-0 (returns true); any other
|
|
58
|
+
// pid throws ESRCH (dead). Non-zero signals always "succeed" so `killOrphan`'s
|
|
59
|
+
// signalTree is inert under test.
|
|
60
|
+
const killAliveFor = (alivePids) =>
|
|
61
|
+
killMock.mockImplementation((pid, signal) => {
|
|
62
|
+
if (signal === 0 || signal === undefined) {
|
|
63
|
+
if (alivePids.includes(pid)) return true;
|
|
64
|
+
const error = new Error('ESRCH');
|
|
65
|
+
error.code = 'ESRCH';
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Configure `execFileImpl` with a (cmd, args, opts, cb) dispatcher.
|
|
72
|
+
const execFileYields = (dispatch) =>
|
|
73
|
+
execFileImpl.mockImplementation((cmd, args, opts, cb) => dispatch(cmd, args, opts, cb));
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
readdirMock.mockReset();
|
|
77
|
+
readFileMock.mockReset();
|
|
78
|
+
rmMock.mockReset();
|
|
79
|
+
mkdirMock.mockReset();
|
|
80
|
+
writeFileMock.mockReset();
|
|
81
|
+
renameMock.mockReset();
|
|
82
|
+
execFileImpl.mockReset();
|
|
83
|
+
killMock.mockReset();
|
|
84
|
+
installKillMock();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
restoreKill();
|
|
89
|
+
restorePlatform();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('reapOrphanedProcesses', () => {
|
|
93
|
+
it('returns zero counts when the registry directory is missing', async () => {
|
|
94
|
+
readdirMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
|
|
95
|
+
|
|
96
|
+
const result = await reapOrphanedProcesses();
|
|
97
|
+
|
|
98
|
+
expect(result).toEqual({ inspected: 0, reaped: 0 });
|
|
99
|
+
expect(execFileImpl).not.toHaveBeenCalled();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('drops registry entries whose pid is already dead, without spawning anything', async () => {
|
|
103
|
+
readdirMock.mockResolvedValue(['99999.json']);
|
|
104
|
+
readFileMock.mockResolvedValue(
|
|
105
|
+
JSON.stringify({ pid: 99999, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
|
|
106
|
+
);
|
|
107
|
+
killMock.mockImplementation(() => {
|
|
108
|
+
const error = new Error('ESRCH');
|
|
109
|
+
error.code = 'ESRCH';
|
|
110
|
+
throw error;
|
|
111
|
+
});
|
|
112
|
+
rmMock.mockResolvedValue();
|
|
113
|
+
|
|
114
|
+
const result = await reapOrphanedProcesses();
|
|
115
|
+
|
|
116
|
+
expect(result).toEqual({ inspected: 1, reaped: 0 });
|
|
117
|
+
expect(rmMock).toHaveBeenCalledTimes(1);
|
|
118
|
+
expect(execFileImpl).not.toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('on Windows', () => {
|
|
122
|
+
beforeEach(() => setPlatform('win32'));
|
|
123
|
+
|
|
124
|
+
it('reaps an opencode image whose owner is gone', async () => {
|
|
125
|
+
readdirMock.mockResolvedValue(['777.json']);
|
|
126
|
+
readFileMock.mockResolvedValue(
|
|
127
|
+
JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: 'opencode.exe', runtime: 'desktop' }),
|
|
128
|
+
);
|
|
129
|
+
// pid 777 alive, owner 12345 dead.
|
|
130
|
+
killAliveFor([777]);
|
|
131
|
+
execFileYields((cmd, _args, _opts, cb) => {
|
|
132
|
+
if (cmd === 'tasklist') return cb(null, 'opencode.exe', '');
|
|
133
|
+
if (cmd === 'taskkill') return cb(null, '', '');
|
|
134
|
+
cb(new Error(`unexpected cmd: ${cmd}`));
|
|
135
|
+
});
|
|
136
|
+
rmMock.mockResolvedValue();
|
|
137
|
+
|
|
138
|
+
const result = await reapOrphanedProcesses({ log: () => {} });
|
|
139
|
+
|
|
140
|
+
expect(result).toEqual({ inspected: 1, reaped: 1 });
|
|
141
|
+
expect(execFileImpl).toHaveBeenCalledWith(
|
|
142
|
+
'tasklist',
|
|
143
|
+
expect.any(Array),
|
|
144
|
+
expect.objectContaining({ windowsHide: true }),
|
|
145
|
+
expect.any(Function),
|
|
146
|
+
);
|
|
147
|
+
expect(execFileImpl).toHaveBeenCalledWith(
|
|
148
|
+
'taskkill',
|
|
149
|
+
expect.any(Array),
|
|
150
|
+
expect.objectContaining({ windowsHide: true }),
|
|
151
|
+
expect.any(Function),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('leaves a non-opencode image alone even if the owner is gone', async () => {
|
|
156
|
+
readdirMock.mockResolvedValue(['777.json']);
|
|
157
|
+
readFileMock.mockResolvedValue(
|
|
158
|
+
JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: 'opencode.exe', runtime: 'desktop' }),
|
|
159
|
+
);
|
|
160
|
+
killAliveFor([777]);
|
|
161
|
+
execFileYields((_cmd, _args, _opts, cb) => cb(null, 'notepad.exe', ''));
|
|
162
|
+
rmMock.mockResolvedValue();
|
|
163
|
+
|
|
164
|
+
const result = await reapOrphanedProcesses({ log: () => {} });
|
|
165
|
+
|
|
166
|
+
expect(result).toEqual({ inspected: 1, reaped: 0 });
|
|
167
|
+
const calls = execFileImpl.mock.calls.filter(([cmd]) => cmd === 'taskkill');
|
|
168
|
+
expect(calls).toHaveLength(0);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('leaves an opencode image whose owner is still alive', async () => {
|
|
172
|
+
readdirMock.mockResolvedValue(['777.json']);
|
|
173
|
+
readFileMock.mockResolvedValue(
|
|
174
|
+
JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: 'opencode.exe', runtime: 'desktop' }),
|
|
175
|
+
);
|
|
176
|
+
// Both alive.
|
|
177
|
+
killAliveFor([777, 12345]);
|
|
178
|
+
execFileYields((_cmd, _args, _opts, cb) => cb(null, 'opencode.exe', ''));
|
|
179
|
+
|
|
180
|
+
const result = await reapOrphanedProcesses({ log: () => {} });
|
|
181
|
+
|
|
182
|
+
expect(result).toEqual({ inspected: 1, reaped: 0 });
|
|
183
|
+
const calls = execFileImpl.mock.calls.filter(([cmd]) => cmd === 'taskkill');
|
|
184
|
+
expect(calls).toHaveLength(0);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('on Unix', () => {
|
|
189
|
+
beforeEach(() => setPlatform('linux'));
|
|
190
|
+
|
|
191
|
+
it('reaps a reparented opencode serve matching the recorded port', async () => {
|
|
192
|
+
readdirMock.mockResolvedValue(['777.json']);
|
|
193
|
+
readFileMock.mockResolvedValue(
|
|
194
|
+
JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
|
|
195
|
+
);
|
|
196
|
+
// pid 777 stays "alive"; killOrphan's signalTree is inert (mock returns
|
|
197
|
+
// true for non-zero signals), and its wait loop sees isPidAlive true so
|
|
198
|
+
// it exhausts the SIGTERM wait then sends SIGKILL and sleeps 300ms.
|
|
199
|
+
killAliveFor([777]);
|
|
200
|
+
execFileYields((cmd, _args, _opts, cb) => {
|
|
201
|
+
if (cmd === 'ps') return cb(null, '1 /usr/bin/opencode serve --port 4096\n', '');
|
|
202
|
+
cb(new Error(`unexpected cmd: ${cmd}`));
|
|
203
|
+
});
|
|
204
|
+
rmMock.mockResolvedValue();
|
|
205
|
+
|
|
206
|
+
const result = await reapOrphanedProcesses({ log: () => {} });
|
|
207
|
+
|
|
208
|
+
expect(result).toEqual({ inspected: 1, reaped: 1 });
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('leaves a process whose command is not our opencode serve', async () => {
|
|
212
|
+
readdirMock.mockResolvedValue(['777.json']);
|
|
213
|
+
readFileMock.mockResolvedValue(
|
|
214
|
+
JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
|
|
215
|
+
);
|
|
216
|
+
killAliveFor([777]);
|
|
217
|
+
execFileYields((cmd, _args, _opts, cb) => {
|
|
218
|
+
if (cmd === 'ps') return cb(null, '1 /some/other/binary serve\n', '');
|
|
219
|
+
cb(new Error(`unexpected cmd: ${cmd}`));
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const result = await reapOrphanedProcesses({ log: () => {} });
|
|
223
|
+
|
|
224
|
+
expect(result).toEqual({ inspected: 1, reaped: 0 });
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('leaves a process still owned by a live owner (not reparented)', async () => {
|
|
228
|
+
readdirMock.mockResolvedValue(['777.json']);
|
|
229
|
+
readFileMock.mockResolvedValue(
|
|
230
|
+
JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
|
|
231
|
+
);
|
|
232
|
+
killAliveFor([777, 12345]);
|
|
233
|
+
execFileYields((cmd, _args, _opts, cb) => {
|
|
234
|
+
if (cmd === 'ps') return cb(null, '12345 /usr/bin/opencode serve --port 4096\n', '');
|
|
235
|
+
cb(new Error(`unexpected cmd: ${cmd}`));
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const result = await reapOrphanedProcesses({ log: () => {} });
|
|
239
|
+
|
|
240
|
+
expect(result).toEqual({ inspected: 1, reaped: 0 });
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe('registerManagedProcess', () => {
|
|
246
|
+
it('writes an entry file atomically via tmp + rename', async () => {
|
|
247
|
+
mkdirMock.mockResolvedValue();
|
|
248
|
+
writeFileMock.mockResolvedValue();
|
|
249
|
+
renameMock.mockResolvedValue();
|
|
250
|
+
|
|
251
|
+
await registerManagedProcess({ pid: 4242, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'desktop' });
|
|
252
|
+
|
|
253
|
+
expect(mkdirMock).toHaveBeenCalledWith(expect.any(String), { recursive: true });
|
|
254
|
+
expect(writeFileMock).toHaveBeenCalledWith(
|
|
255
|
+
expect.stringContaining('4242.json.tmp-'),
|
|
256
|
+
expect.any(String),
|
|
257
|
+
);
|
|
258
|
+
expect(renameMock).toHaveBeenCalledWith(
|
|
259
|
+
expect.stringContaining('4242.json.tmp-'),
|
|
260
|
+
expect.stringContaining('4242.json'),
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('is a no-op for a non-integer pid', async () => {
|
|
265
|
+
await registerManagedProcess({ pid: 'not-a-pid' });
|
|
266
|
+
|
|
267
|
+
expect(writeFileMock).not.toHaveBeenCalled();
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('unregisterManagedProcess', () => {
|
|
272
|
+
it('removes the entry file', async () => {
|
|
273
|
+
rmMock.mockResolvedValue();
|
|
274
|
+
|
|
275
|
+
await unregisterManagedProcess(4242);
|
|
276
|
+
|
|
277
|
+
expect(rmMock).toHaveBeenCalledWith(expect.stringContaining('4242.json'), { force: true });
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('is a no-op for a non-integer pid', async () => {
|
|
281
|
+
await unregisterManagedProcess(undefined);
|
|
282
|
+
|
|
283
|
+
expect(rmMock).not.toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -44,7 +44,12 @@ export const createProjectDirectoryRuntime = (dependencies) => {
|
|
|
44
44
|
return { ok: false, error: 'Specified path is not a directory' };
|
|
45
45
|
}
|
|
46
46
|
const realPath = await realpathCache.resolve(resolved);
|
|
47
|
-
|
|
47
|
+
// `requestedDirectory` is the pre-realpath candidate the caller asked
|
|
48
|
+
// for. Callers that address files in the user-visible path space (the
|
|
49
|
+
// file tree, the read-family FS routes) need it when the project root
|
|
50
|
+
// is itself a symlink and the canonical `directory` no longer contains
|
|
51
|
+
// the paths the client sends.
|
|
52
|
+
return { ok: true, directory: realPath, requestedDirectory: resolved };
|
|
48
53
|
} catch (error) {
|
|
49
54
|
const err = error;
|
|
50
55
|
if (err && typeof err === 'object' && err.code === 'ENOENT') {
|
|
@@ -71,11 +76,11 @@ export const createProjectDirectoryRuntime = (dependencies) => {
|
|
|
71
76
|
for (const candidate of requested) {
|
|
72
77
|
const validated = await validateDirectoryPath(candidate);
|
|
73
78
|
if (validated.ok) {
|
|
74
|
-
return { directory: validated.directory, error: null };
|
|
79
|
+
return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
|
|
75
80
|
}
|
|
76
81
|
lastError = validated.error;
|
|
77
82
|
}
|
|
78
|
-
return { directory: null, error: lastError };
|
|
83
|
+
return { directory: null, requestedDirectory: null, error: lastError };
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
const readSettings = typeof getReadSettingsFromDiskMigrated === 'function'
|
|
@@ -93,27 +98,27 @@ export const createProjectDirectoryRuntime = (dependencies) => {
|
|
|
93
98
|
if (typeof settings.lastDirectory === 'string' && settings.lastDirectory.trim()) {
|
|
94
99
|
const validated = await validateDirectoryPath(settings.lastDirectory);
|
|
95
100
|
if (validated.ok) {
|
|
96
|
-
return { directory: validated.directory, error: null };
|
|
101
|
+
return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
const projects = sanitizeProjects(settings.projects) || [];
|
|
101
106
|
if (projects.length === 0) {
|
|
102
|
-
return { directory: null, error: 'Directory parameter or active project is required' };
|
|
107
|
+
return { directory: null, requestedDirectory: null, error: 'Directory parameter or active project is required' };
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
const activeId = typeof settings.activeProjectId === 'string' ? settings.activeProjectId : '';
|
|
106
111
|
const active = projects.find((project) => project.id === activeId) || projects[0];
|
|
107
112
|
if (!active || !active.path) {
|
|
108
|
-
return { directory: null, error: 'Directory parameter or active project is required' };
|
|
113
|
+
return { directory: null, requestedDirectory: null, error: 'Directory parameter or active project is required' };
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
const validated = await validateDirectoryPath(active.path);
|
|
112
117
|
if (!validated.ok) {
|
|
113
|
-
return { directory: null, error: validated.error };
|
|
118
|
+
return { directory: null, requestedDirectory: null, error: validated.error };
|
|
114
119
|
}
|
|
115
120
|
|
|
116
|
-
return { directory: validated.directory, error: null };
|
|
121
|
+
return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
|
|
117
122
|
};
|
|
118
123
|
|
|
119
124
|
const resolveOptionalProjectDirectory = async (req) => {
|
|
@@ -126,18 +131,18 @@ export const createProjectDirectoryRuntime = (dependencies) => {
|
|
|
126
131
|
const requested = [headerDirectory, queryDirectory].filter(Boolean);
|
|
127
132
|
|
|
128
133
|
if (requested.length === 0) {
|
|
129
|
-
return { directory: null, error: null };
|
|
134
|
+
return { directory: null, requestedDirectory: null, error: null };
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
let lastError = null;
|
|
133
138
|
for (const candidate of requested) {
|
|
134
139
|
const validated = await validateDirectoryPath(candidate);
|
|
135
140
|
if (validated.ok) {
|
|
136
|
-
return { directory: validated.directory, error: null };
|
|
141
|
+
return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
|
|
137
142
|
}
|
|
138
143
|
lastError = validated.error;
|
|
139
144
|
}
|
|
140
|
-
return { directory: null, error: lastError };
|
|
145
|
+
return { directory: null, requestedDirectory: null, error: lastError };
|
|
141
146
|
};
|
|
142
147
|
|
|
143
148
|
return {
|
|
@@ -26,7 +26,7 @@ describe('project directory runtime', () => {
|
|
|
26
26
|
const runtime = createTestRuntime();
|
|
27
27
|
const result = await runtime.validateDirectoryPath('/home/user/project');
|
|
28
28
|
|
|
29
|
-
expect(result).toEqual({ ok: true, directory: '/home/user/project' });
|
|
29
|
+
expect(result).toEqual({ ok: true, directory: '/home/user/project', requestedDirectory: '/home/user/project' });
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it('resolves symlinks via fsPromises.realpath', async () => {
|
|
@@ -39,7 +39,7 @@ describe('project directory runtime', () => {
|
|
|
39
39
|
|
|
40
40
|
const result = await runtime.validateDirectoryPath('/symlink/path/to/project');
|
|
41
41
|
|
|
42
|
-
expect(result).toEqual({ ok: true, directory: '/real/path/to/project' });
|
|
42
|
+
expect(result).toEqual({ ok: true, directory: '/real/path/to/project', requestedDirectory: '/symlink/path/to/project' });
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
it('returns error when candidate is empty', async () => {
|
|
@@ -125,7 +125,11 @@ describe('project directory runtime', () => {
|
|
|
125
125
|
|
|
126
126
|
const result = await runtime.resolveProjectDirectory(req);
|
|
127
127
|
|
|
128
|
-
expect(result).toEqual({
|
|
128
|
+
expect(result).toEqual({
|
|
129
|
+
directory: '/real/workspace/project',
|
|
130
|
+
requestedDirectory: '/home/user/workspace/project',
|
|
131
|
+
error: null,
|
|
132
|
+
});
|
|
129
133
|
});
|
|
130
134
|
|
|
131
135
|
it('decodes marked x-opencode-directory header values', async () => {
|
|
@@ -153,7 +157,7 @@ describe('project directory runtime', () => {
|
|
|
153
157
|
const result = await runtime.resolveProjectDirectory(req);
|
|
154
158
|
|
|
155
159
|
expect(validatedPath).toBe(pathWithUnicode);
|
|
156
|
-
expect(result).toEqual({ directory: pathWithUnicode, error: null });
|
|
160
|
+
expect(result).toEqual({ directory: pathWithUnicode, requestedDirectory: pathWithUnicode, error: null });
|
|
157
161
|
});
|
|
158
162
|
|
|
159
163
|
it('preserves raw percent sequences without directory encoding marker', async () => {
|
|
@@ -177,7 +181,7 @@ describe('project directory runtime', () => {
|
|
|
177
181
|
const result = await runtime.resolveProjectDirectory(req);
|
|
178
182
|
|
|
179
183
|
expect(validatedPath).toBe(rawPath);
|
|
180
|
-
expect(result).toEqual({ directory: rawPath, error: null });
|
|
184
|
+
expect(result).toEqual({ directory: rawPath, requestedDirectory: rawPath, error: null });
|
|
181
185
|
});
|
|
182
186
|
|
|
183
187
|
it('falls back to query directory when an unmarked encoded header is invalid', async () => {
|
|
@@ -199,7 +203,7 @@ describe('project directory runtime', () => {
|
|
|
199
203
|
|
|
200
204
|
const result = await runtime.resolveProjectDirectory(req);
|
|
201
205
|
|
|
202
|
-
expect(result).toEqual({ directory: validPath, error: null });
|
|
206
|
+
expect(result).toEqual({ directory: validPath, requestedDirectory: validPath, error: null });
|
|
203
207
|
});
|
|
204
208
|
|
|
205
209
|
it('resolves symlinks in query directory parameter', async () => {
|
|
@@ -217,7 +221,11 @@ describe('project directory runtime', () => {
|
|
|
217
221
|
|
|
218
222
|
const result = await runtime.resolveProjectDirectory(req);
|
|
219
223
|
|
|
220
|
-
expect(result).toEqual({
|
|
224
|
+
expect(result).toEqual({
|
|
225
|
+
directory: '/real/workspace/project',
|
|
226
|
+
requestedDirectory: '/home/user/workspace/project',
|
|
227
|
+
error: null,
|
|
228
|
+
});
|
|
221
229
|
});
|
|
222
230
|
|
|
223
231
|
it('resolves symlinks in lastDirectory from settings', async () => {
|
|
@@ -238,7 +246,11 @@ describe('project directory runtime', () => {
|
|
|
238
246
|
|
|
239
247
|
const result = await runtime.resolveProjectDirectory(req);
|
|
240
248
|
|
|
241
|
-
expect(result).toEqual({
|
|
249
|
+
expect(result).toEqual({
|
|
250
|
+
directory: '/real/workspace/project',
|
|
251
|
+
requestedDirectory: '/home/user/workspace/project',
|
|
252
|
+
error: null,
|
|
253
|
+
});
|
|
242
254
|
});
|
|
243
255
|
|
|
244
256
|
it('resolves symlinks in active project path from settings', async () => {
|
|
@@ -261,7 +273,11 @@ describe('project directory runtime', () => {
|
|
|
261
273
|
|
|
262
274
|
const result = await runtime.resolveProjectDirectory(req);
|
|
263
275
|
|
|
264
|
-
expect(result).toEqual({
|
|
276
|
+
expect(result).toEqual({
|
|
277
|
+
directory: '/real/workspace/project',
|
|
278
|
+
requestedDirectory: '/home/user/workspace/project',
|
|
279
|
+
error: null,
|
|
280
|
+
});
|
|
265
281
|
});
|
|
266
282
|
});
|
|
267
283
|
|
|
@@ -276,7 +292,7 @@ describe('project directory runtime', () => {
|
|
|
276
292
|
|
|
277
293
|
const result = await runtime.resolveOptionalProjectDirectory(req);
|
|
278
294
|
|
|
279
|
-
expect(result).toEqual({ directory: null, error: null });
|
|
295
|
+
expect(result).toEqual({ directory: null, requestedDirectory: null, error: null });
|
|
280
296
|
});
|
|
281
297
|
|
|
282
298
|
it('resolves symlinks when directory is provided', async () => {
|
|
@@ -294,7 +310,11 @@ describe('project directory runtime', () => {
|
|
|
294
310
|
|
|
295
311
|
const result = await runtime.resolveOptionalProjectDirectory(req);
|
|
296
312
|
|
|
297
|
-
expect(result).toEqual({
|
|
313
|
+
expect(result).toEqual({
|
|
314
|
+
directory: '/real/workspace/project',
|
|
315
|
+
requestedDirectory: '/symlink/workspace/project',
|
|
316
|
+
error: null,
|
|
317
|
+
});
|
|
298
318
|
});
|
|
299
319
|
|
|
300
320
|
it('preserves raw percent sequences without directory encoding marker', async () => {
|
|
@@ -318,7 +338,7 @@ describe('project directory runtime', () => {
|
|
|
318
338
|
const result = await runtime.resolveOptionalProjectDirectory(req);
|
|
319
339
|
|
|
320
340
|
expect(validatedPath).toBe(rawPath);
|
|
321
|
-
expect(result).toEqual({ directory: rawPath, error: null });
|
|
341
|
+
expect(result).toEqual({ directory: rawPath, requestedDirectory: rawPath, error: null });
|
|
322
342
|
});
|
|
323
343
|
});
|
|
324
344
|
});
|
|
@@ -9,6 +9,13 @@ afterEach(() => {
|
|
|
9
9
|
globalThis.fetch = originalFetch;
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
const jsonResponse = (payload, status = 200) => new Response(JSON.stringify(payload), {
|
|
13
|
+
status,
|
|
14
|
+
headers: { 'Content-Type': 'application/json' },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const supportedCapability = { supported: true, manager: 'opencode', reason: null };
|
|
18
|
+
|
|
12
19
|
const createApp = (overrides = {}) => {
|
|
13
20
|
const app = express();
|
|
14
21
|
app.use(express.json());
|
|
@@ -67,22 +74,99 @@ describe('OpenCode upgrade routes', () => {
|
|
|
67
74
|
});
|
|
68
75
|
});
|
|
69
76
|
|
|
77
|
+
it('names the latest release as the upgrade target when the caller sends none', async () => {
|
|
78
|
+
const requests = [];
|
|
79
|
+
globalThis.fetch = vi.fn(async (url, init) => {
|
|
80
|
+
requests.push({ url: String(url), body: init?.body ? JSON.parse(init.body) : null });
|
|
81
|
+
if (String(url).includes('registry.npmjs.org')) {
|
|
82
|
+
return jsonResponse({ version: '1.18.23' });
|
|
83
|
+
}
|
|
84
|
+
if (String(url).includes('api.github.com')) {
|
|
85
|
+
return jsonResponse({ tag_name: 'v1.18.23' });
|
|
86
|
+
}
|
|
87
|
+
return jsonResponse({ success: true, version: '1.18.23' });
|
|
88
|
+
});
|
|
89
|
+
const { app } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
|
|
90
|
+
|
|
91
|
+
await request(app)
|
|
92
|
+
.post('/api/opencode/upgrade')
|
|
93
|
+
.send({})
|
|
94
|
+
.expect(200, { success: true, version: '1.18.23', restarted: true });
|
|
95
|
+
|
|
96
|
+
const upgradeRequest = requests.find((entry) => entry.url.includes('/global/upgrade'));
|
|
97
|
+
expect(upgradeRequest?.body).toEqual({ target: '1.18.23' });
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('keeps an explicitly requested target instead of resolving the latest release', async () => {
|
|
101
|
+
const requests = [];
|
|
102
|
+
globalThis.fetch = vi.fn(async (url, init) => {
|
|
103
|
+
requests.push({ url: String(url), body: init?.body ? JSON.parse(init.body) : null });
|
|
104
|
+
return jsonResponse({ success: true, version: '1.18.20' });
|
|
105
|
+
});
|
|
106
|
+
const { app } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
|
|
107
|
+
|
|
108
|
+
await request(app)
|
|
109
|
+
.post('/api/opencode/upgrade')
|
|
110
|
+
.send({ target: '1.18.20' })
|
|
111
|
+
.expect(200);
|
|
112
|
+
|
|
113
|
+
expect(requests).toHaveLength(1);
|
|
114
|
+
expect(requests[0].url).toContain('/global/upgrade');
|
|
115
|
+
expect(requests[0].body).toEqual({ target: '1.18.20' });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('fails without calling the updater when the latest release cannot be resolved', async () => {
|
|
119
|
+
globalThis.fetch = vi.fn(async (url) => {
|
|
120
|
+
if (String(url).includes('/global/upgrade')) {
|
|
121
|
+
throw new Error('the updater must not be called without a target');
|
|
122
|
+
}
|
|
123
|
+
return new Response('nope', { status: 503 });
|
|
124
|
+
});
|
|
125
|
+
const { app, dependencies } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
|
|
126
|
+
|
|
127
|
+
const response = await request(app)
|
|
128
|
+
.post('/api/opencode/upgrade')
|
|
129
|
+
.send({})
|
|
130
|
+
.expect(502);
|
|
131
|
+
|
|
132
|
+
expect(response.body.success).toBe(false);
|
|
133
|
+
expect(response.body.code).toBe('OPENCODE_UPGRADE_TARGET_UNRESOLVED');
|
|
134
|
+
expect(response.body.error).toContain('Could not determine which OpenCode version to install');
|
|
135
|
+
expect(dependencies.refreshOpenCodeAfterConfigChange).not.toHaveBeenCalled();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('surfaces the rejection OpenCode reported instead of the bare HTTP status', async () => {
|
|
139
|
+
globalThis.fetch = vi.fn(async (url) => {
|
|
140
|
+
if (String(url).includes('/global/upgrade')) {
|
|
141
|
+
return jsonResponse(
|
|
142
|
+
{ name: 'BadRequest', data: { message: 'Expected a semantic version', kind: 'Payload' } },
|
|
143
|
+
400,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return jsonResponse({ version: '1.18.23' });
|
|
147
|
+
});
|
|
148
|
+
const { app } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
|
|
149
|
+
|
|
150
|
+
await request(app)
|
|
151
|
+
.post('/api/opencode/upgrade')
|
|
152
|
+
.send({})
|
|
153
|
+
.expect(400, { success: false, error: 'Expected a semantic version' });
|
|
154
|
+
});
|
|
155
|
+
|
|
70
156
|
it('serializes supported upgrades and preserves the in-flight lock', async () => {
|
|
71
157
|
let releaseUpgrade;
|
|
72
158
|
const upstreamResponse = new Promise((resolve) => {
|
|
73
|
-
releaseUpgrade = () => resolve(
|
|
74
|
-
status: 200,
|
|
75
|
-
headers: { 'Content-Type': 'application/json' },
|
|
76
|
-
}));
|
|
159
|
+
releaseUpgrade = () => resolve(jsonResponse({ success: true, version: '1.18.9' }));
|
|
77
160
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
})
|
|
161
|
+
const upgradeCalls = vi.fn();
|
|
162
|
+
globalThis.fetch = vi.fn((url) => {
|
|
163
|
+
if (String(url).includes('/global/upgrade')) {
|
|
164
|
+
upgradeCalls();
|
|
165
|
+
return upstreamResponse;
|
|
166
|
+
}
|
|
167
|
+
return Promise.resolve(jsonResponse({ version: '1.18.9' }));
|
|
85
168
|
});
|
|
169
|
+
const { app, dependencies } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
|
|
86
170
|
|
|
87
171
|
const first = request(app)
|
|
88
172
|
.post('/api/opencode/upgrade')
|
|
@@ -94,7 +178,7 @@ describe('OpenCode upgrade routes', () => {
|
|
|
94
178
|
})
|
|
95
179
|
.then((response) => response);
|
|
96
180
|
await vi.waitFor(() => {
|
|
97
|
-
expect(
|
|
181
|
+
expect(upgradeCalls).toHaveBeenCalledTimes(1);
|
|
98
182
|
});
|
|
99
183
|
|
|
100
184
|
await request(app)
|