@pi-chamber/web 1.0.0 → 1.0.2-rc.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.
Files changed (78) hide show
  1. package/README.md +3 -1
  2. package/bin/cli.js +7 -32
  3. package/bin/dev-server.js +185 -0
  4. package/bin/dev-server.test.js +252 -0
  5. package/bin/lib/DOCUMENTATION.md +19 -0
  6. package/bin/lib/cli-startup.js +9 -1
  7. package/bin/lib/cli-startup.test.js +30 -0
  8. package/bin/lib/commands-serve.js +9 -5
  9. package/bin/lib/server-runtime.js +6 -0
  10. package/bin/lib/server-runtime.test.js +313 -0
  11. package/dist/assets/{DiagramView-CbSxUe1D.js → DiagramView-GUJij-1P.js} +1 -1
  12. package/dist/assets/{DiffView-VyBf4ilo.js → DiffView-BZ487Bhh.js} +1 -1
  13. package/dist/assets/{FileSaveConflictDialog-BCvbQ234.js → FileSaveConflictDialog-Ci6WdSiS.js} +1 -1
  14. package/dist/assets/{FilesView-DasA5EU2.js → FilesView-DBiWEo71.js} +1 -1
  15. package/dist/assets/{GitView-DU3mOECp.js → GitView-DVyhqN5s.js} +3 -3
  16. package/dist/assets/{JsonTreeView-xZiWDwua.js → JsonTreeView-BaU7aAUq.js} +1 -1
  17. package/dist/assets/{MarkdownRendererImpl-BBwdI2OF.js → MarkdownRendererImpl-6NBJLtEr.js} +1 -1
  18. package/dist/assets/{PatchDiff-BhKm_JPT.js → PatchDiff-CvptevA2.js} +1 -1
  19. package/dist/assets/{SessionSwitcherContent-DTGSP_RB.js → SessionSwitcherContent-Cqp5FVCP.js} +1 -1
  20. package/dist/assets/{SessionSwitcherDropdown-CedOB-xC.js → SessionSwitcherDropdown-CRVJU16x.js} +2 -2
  21. package/dist/assets/{SessionUnreadDot-CZSNKram.js → SessionUnreadDot-CsFxImPI.js} +1 -1
  22. package/dist/assets/SettingsView-ppaIrPry.js +2 -0
  23. package/dist/assets/{SettingsWindow-y33YrpBE.js → SettingsWindow-geMUhnxd.js} +1 -1
  24. package/dist/assets/{ToolOutputDialog-JqIXJWAH.js → ToolOutputDialog-BLGl2mNt.js} +1 -1
  25. package/dist/assets/{ToolPartDiffPreview-CRi_33jE.js → ToolPartDiffPreview-BVeL1IuE.js} +1 -1
  26. package/dist/assets/{VirtualizedFileDiff-ehLQSR5W.js → VirtualizedFileDiff-9kAZ96se.js} +1 -1
  27. package/dist/assets/{collapsible-Vypq-nMP.js → collapsible-BencOwkW.js} +1 -1
  28. package/dist/assets/{computeVirtualFileMetrics-BTfrj_fR.js → computeVirtualFileMetrics-C8vH0vcM.js} +1 -1
  29. package/dist/assets/{contextFileOpenGuard-Dl6mFfD1.js → contextFileOpenGuard-B6e3cTcl.js} +1 -1
  30. package/dist/assets/{gitStatusPredicates-LAsJAhCL.js → gitStatusPredicates-B6w5GMNU.js} +1 -1
  31. package/dist/assets/{index-OveFsNBm.js → index-BifnX1Mp.js} +1 -1
  32. package/dist/assets/{index-DvNeSFO9.js → index-CpSdU-d4.js} +7 -7
  33. package/dist/assets/index-Dwz16owi.css +1 -0
  34. package/dist/assets/{isDiffPlainText-CNZohQ4q.js → isDiffPlainText-BepQ1JHv.js} +1 -1
  35. package/dist/assets/{isFilePlainText-Dz8UubRT.js → isFilePlainText-CA1KFaTm.js} +1 -1
  36. package/dist/assets/{main-BsDkATRV.js → main-TzeSIx1W.js} +3 -3
  37. package/dist/assets/{main-C393Ywhx.js → main-dhVDQIHu.js} +2 -2
  38. package/dist/assets/{markdownCore-Bz9-Y75q.js → markdownCore-BztwD2c9.js} +1 -1
  39. package/dist/assets/{miniChat-CWEerp3c.js → miniChat-smqdx0Y7.js} +2 -2
  40. package/dist/assets/{mobile-YxV9KcxF.js → mobile-BV-WCEiE.js} +2 -2
  41. package/dist/assets/{renderElectronMiniChatApp-GrLmBQRb.js → renderElectronMiniChatApp-DKmb9oa7.js} +2 -2
  42. package/dist/assets/renderMobileApp-D3dtjeaE.js +11 -0
  43. package/dist/assets/runtimeEndpointReset-C1EENUlq.js +53 -0
  44. package/dist/assets/{runtimeSurface-DUXw4-oa.js → runtimeSurface-Bm6cRkok.js} +1 -1
  45. package/dist/assets/{useAppFontEffects-ad-lZJ6o.js → useAppFontEffects-Dq7xKVjh.js} +77 -77
  46. package/dist/assets/{useFilesViewSearch-C4oOHPml.js → useFilesViewSearch-Bvlo7C3a.js} +1 -1
  47. package/dist/assets/{usePushVisibilityBeacon-xd8Q10cI.js → usePushVisibilityBeacon-BY4xtozp.js} +1 -1
  48. package/dist/assets/{useSwitcherItems-B6VC7tug.js → useSwitcherItems-CkE242zK.js} +1 -1
  49. package/dist/assets/{vendor-codemirror-language-data-B4j3gkaT.js → vendor-codemirror-language-data-Bv6kN79m.js} +2 -2
  50. package/dist/assets/{web-components-B0RFakat.js → web-components-CCiRgoOw.js} +1 -1
  51. package/dist/index.html +4 -4
  52. package/dist/mini-chat.html +3 -3
  53. package/dist/mobile.html +3 -3
  54. package/package.json +8 -3
  55. package/server/index.js +48 -6
  56. package/server/lib/notifications/DOCUMENTATION.md +39 -0
  57. package/server/lib/notifications/delivery-runtime.js +314 -0
  58. package/server/lib/notifications/delivery-runtime.test.js +85 -0
  59. package/server/lib/notifications/pi-notification-watcher.js +154 -0
  60. package/server/lib/notifications/pi-notification-watcher.test.js +84 -0
  61. package/server/lib/notifications/routes.js +74 -0
  62. package/server/lib/package-manager.js +3 -2
  63. package/server/lib/package-manager.test.js +7 -2
  64. package/server/lib/pi/routes.test.js +24 -0
  65. package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -0
  66. package/server/lib/pi/session-daemon/pi-runtime-smoke.test.js +466 -0
  67. package/server/lib/pi/ui-settings-store.js +15 -2
  68. package/server/lib/pi/ui-settings-store.test.js +47 -1
  69. package/server/lib/server/core-routes.js +18 -0
  70. package/server/lib/server/linux-distribution.js +47 -0
  71. package/server/lib/server/linux-distribution.test.js +22 -0
  72. package/server/lib/server/runtime-requirements.js +193 -0
  73. package/server/lib/server/runtime-requirements.test.js +295 -0
  74. package/server/lib/server/tunnel-service.DOCUMENTATION.md +1 -1
  75. package/dist/assets/SettingsView-B5nmu8x4.js +0 -2
  76. package/dist/assets/index-BXX8l7mM.css +0 -1
  77. package/dist/assets/renderMobileApp-C29wquBe.js +0 -11
  78. package/dist/assets/runtimeEndpointReset-DHARMv9w.js +0 -53
@@ -0,0 +1,22 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { detectLinuxDistribution, parseLinuxDistribution } from './linux-distribution.js';
4
+
5
+ describe('Linux distribution detection', () => {
6
+ it('reads known distribution IDs and aliases', () => {
7
+ expect(parseLinuxDistribution('ID=ubuntu\n')).toBe('ubuntu');
8
+ expect(parseLinuxDistribution('ID="archlinux"\n')).toBe('arch');
9
+ expect(parseLinuxDistribution('ID=nixos\n')).toBe('nixos');
10
+ expect(parseLinuxDistribution('ID=fedora\n')).toBe('fedora');
11
+ });
12
+
13
+ it('uses ID_LIKE for recognized derivatives', () => {
14
+ expect(parseLinuxDistribution('ID=custom\nID_LIKE="debian ubuntu"\n')).toBe('debian');
15
+ });
16
+
17
+ it('returns null for unknown, unavailable, and non-Linux systems', () => {
18
+ expect(parseLinuxDistribution('ID=gentoo\n')).toBeNull();
19
+ expect(detectLinuxDistribution({ platform: 'win32' })).toBeNull();
20
+ expect(detectLinuxDistribution({ platform: 'linux', readFile: () => { throw new Error('missing'); } })).toBeNull();
21
+ });
22
+ });
@@ -0,0 +1,193 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import path from 'node:path';
3
+
4
+ const MIN_NODE_VERSION = { major: 22, minor: 19, patch: 0 };
5
+ const MIN_BUN_VERSION = { major: 1, minor: 4, patch: 0 };
6
+ const MIN_NODE_VERSION_STRING = '22.19.0';
7
+ const MIN_BUN_VERSION_STRING = '1.4.0';
8
+ const RUNTIME_PROBE_TIMEOUT_MS = 5000;
9
+ export const NO_SUPPORTED_RUNTIME_MESSAGE =
10
+ `No supported server runtime found. Install Node.js ${MIN_NODE_VERSION_STRING} or newer, or Bun ${MIN_BUN_VERSION_STRING} or newer.`;
11
+ const NODE_PROBE_BIN = 'node';
12
+
13
+ export function getBunBinary(env = process.env) {
14
+ if (env && typeof env.BUN_BINARY === 'string' && env.BUN_BINARY.trim().length > 0) {
15
+ return env.BUN_BINARY.trim();
16
+ }
17
+ if (env && typeof env.BUN_INSTALL === 'string' && env.BUN_INSTALL.trim().length > 0) {
18
+ return path.join(env.BUN_INSTALL.trim(), 'bin', 'bun');
19
+ }
20
+ return 'bun';
21
+ }
22
+
23
+ function hasExplicitBunOverride(env = process.env) {
24
+ if (!env || typeof env !== 'object') return false;
25
+ return (typeof env.BUN_BINARY === 'string' && env.BUN_BINARY.trim().length > 0)
26
+ || (typeof env.BUN_INSTALL === 'string' && env.BUN_INSTALL.trim().length > 0);
27
+ }
28
+
29
+ function isBunRuntime(host = globalThis) {
30
+ return typeof host?.Bun !== 'undefined';
31
+ }
32
+
33
+ function compareVersion(parsed, minimum) {
34
+ if (parsed.major !== minimum.major) return parsed.major - minimum.major;
35
+ if (parsed.minor !== minimum.minor) return parsed.minor - minimum.minor;
36
+ return parsed.patch - minimum.patch;
37
+ }
38
+
39
+ // Strict stable parser: accepts only `X.Y.Z` with an optional leading `v`.
40
+ // Rejects empty, truncated, prerelease (`-rc.1`, `-canary`), and build
41
+ // metadata (`+build`) shapes so old/malformed/prerelease runtimes fail.
42
+ function parseStableVersion(value) {
43
+ if (typeof value !== 'string') return null;
44
+ const trimmed = value.trim();
45
+ if (trimmed.length === 0) return null;
46
+ const match = trimmed.match(/^v?(\d+)\.(\d+)\.(\d+)$/);
47
+ if (!match) return null;
48
+ const major = Number.parseInt(match[1], 10);
49
+ const minor = Number.parseInt(match[2], 10);
50
+ const patch = Number.parseInt(match[3], 10);
51
+ if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) return null;
52
+ return { major, minor, patch };
53
+ }
54
+
55
+ export function isSupportedNodeVersion(value) {
56
+ const parsed = parseStableVersion(value);
57
+ if (!parsed) return false;
58
+ return compareVersion(parsed, MIN_NODE_VERSION) >= 0;
59
+ }
60
+
61
+ export function isSupportedBunVersion(value) {
62
+ const parsed = parseStableVersion(value);
63
+ if (!parsed) return false;
64
+ return compareVersion(parsed, MIN_BUN_VERSION) >= 0;
65
+ }
66
+
67
+ function probeVersionOutput(bin, spawnSyncFn = spawnSync, timeoutMs = RUNTIME_PROBE_TIMEOUT_MS) {
68
+ if (typeof bin !== 'string' || bin.trim().length === 0) return null;
69
+ const runner = typeof spawnSyncFn === 'function' ? spawnSyncFn : spawnSync;
70
+ try {
71
+ const result = runner(bin.trim(), ['--version'], {
72
+ encoding: 'utf8',
73
+ stdio: 'pipe',
74
+ windowsHide: true,
75
+ timeout: timeoutMs,
76
+ });
77
+ if (!result || result.error || result.status !== 0) return null;
78
+ const output = typeof result.stdout === 'string' ? result.stdout.trim() : '';
79
+ return output.length > 0 ? output : null;
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+
85
+ function resolveProbeTimeout(options = {}) {
86
+ const candidate = options.probeTimeoutMs ?? options.timeoutMs ?? RUNTIME_PROBE_TIMEOUT_MS;
87
+ return Number.isFinite(candidate) && candidate > 0 ? candidate : RUNTIME_PROBE_TIMEOUT_MS;
88
+ }
89
+
90
+ function getCurrentNodeExecutable(options = {}) {
91
+ const isBun = options.isBun ?? isBunRuntime(options.globalRef ?? globalThis);
92
+ if (isBun) return null;
93
+ const nodeVersion = options.nodeVersion ?? process.version;
94
+ if (!isSupportedNodeVersion(nodeVersion)) return null;
95
+ const execPath = options.execPath ?? process.execPath;
96
+ if (typeof execPath !== 'string' || execPath.trim().length === 0) return null;
97
+ return execPath;
98
+ }
99
+
100
+ function getCurrentBunExecutable(options = {}) {
101
+ const globalRef = options.globalRef ?? globalThis;
102
+ const isBun = options.isBun ?? isBunRuntime(globalRef);
103
+ if (!isBun) return null;
104
+ const bunVersion = options.bunVersion ?? globalRef?.Bun?.version;
105
+ if (!isSupportedBunVersion(bunVersion)) return null;
106
+ const execPath = options.execPath ?? process.execPath;
107
+ if (typeof execPath !== 'string' || execPath.trim().length === 0) return null;
108
+ return execPath;
109
+ }
110
+
111
+ function findSupportedNodeExecutable(options = {}) {
112
+ const current = getCurrentNodeExecutable(options);
113
+ if (current) return current;
114
+ const nodeBin = options.nodeBin ?? NODE_PROBE_BIN;
115
+ const spawnSyncFn = options.spawnSyncFn ?? spawnSync;
116
+ // Bounded: probe errors (ENOENT, timeout, non-zero) return null so
117
+ // resolution falls through to Bun instead of throwing.
118
+ const probedVersion = probeVersionOutput(nodeBin, spawnSyncFn, resolveProbeTimeout(options));
119
+ if (probedVersion && isSupportedNodeVersion(probedVersion)) return nodeBin;
120
+ return null;
121
+ }
122
+
123
+ function isBunInstalled(options = {}) {
124
+ const bunBin = options.bunBin ?? getBunBinary(options.env ?? process.env);
125
+ const spawnSyncFn = options.spawnSyncFn ?? spawnSync;
126
+ const probedVersion = probeVersionOutput(bunBin, spawnSyncFn, resolveProbeTimeout(options));
127
+ if (!probedVersion) return false;
128
+ return isSupportedBunVersion(probedVersion);
129
+ }
130
+
131
+ function getCurrentRuntime(options = {}) {
132
+ const globalRef = options.globalRef ?? globalThis;
133
+ const isBun = options.isBun ?? isBunRuntime(globalRef);
134
+ const execPath = options.execPath ?? process.execPath;
135
+ const nodeVersion = options.nodeVersion ?? process.version;
136
+ const bunVersion = options.bunVersion ?? globalRef?.Bun?.version;
137
+ if (isBun) {
138
+ return { kind: 'bun', isBun: true, bunVersion, nodeVersion, execPath };
139
+ }
140
+ return { kind: 'node', isBun: false, nodeVersion, bunVersion: undefined, execPath };
141
+ }
142
+
143
+ export function resolveServerExecutable(options = {}) {
144
+ const nodeExecutable = findSupportedNodeExecutable(options);
145
+ if (nodeExecutable) return { runtime: 'node', executable: nodeExecutable };
146
+ const env = options.env ?? process.env;
147
+ const bunBin = options.bunBin ?? getBunBinary(env);
148
+ if (hasExplicitBunOverride(env)) {
149
+ if (isBunInstalled({ ...options, bunBin })) return { runtime: 'bun', executable: bunBin };
150
+ throw new Error(NO_SUPPORTED_RUNTIME_MESSAGE);
151
+ }
152
+ // No explicit override: prefer the current supported Bun executable before
153
+ // probing PATH. bin/cli.js always passes a default BUN_BIN (`bun`) even
154
+ // without overrides, so an explicit options.bunBin must not shadow a
155
+ // supported off-PATH current Bun here. Explicit BUN_BINARY/BUN_INSTALL
156
+ // already returned above.
157
+ const currentBun = getCurrentBunExecutable(options);
158
+ if (currentBun) return { runtime: 'bun', executable: currentBun };
159
+ if (isBunInstalled({ ...options, bunBin })) return { runtime: 'bun', executable: bunBin };
160
+ throw new Error(NO_SUPPORTED_RUNTIME_MESSAGE);
161
+ }
162
+
163
+ // Explicit foreground, startup enable, and in-process server startup validate
164
+ // only the current executable. They never probe PATH and never silently
165
+ // switch runtimes, so a supported absolute Bun exec works with an empty PATH
166
+ // and an old/malformed/prerelease current runtime fails deterministically.
167
+ export function assertCurrentRuntimeSupported(options = {}) {
168
+ const current = getCurrentRuntime(options);
169
+ const execPath = typeof current.execPath === 'string' ? current.execPath.trim() : '';
170
+ if (execPath.length === 0) {
171
+ throw new Error(`${NO_SUPPORTED_RUNTIME_MESSAGE} (missing runtime executable)`);
172
+ }
173
+ if (current.kind === 'bun') {
174
+ if (isSupportedBunVersion(current.bunVersion)) {
175
+ return { runtime: 'bun', executable: execPath };
176
+ }
177
+ const actual = typeof current.bunVersion === 'string' && current.bunVersion.trim().length > 0
178
+ ? current.bunVersion.trim()
179
+ : 'unknown';
180
+ throw new Error(
181
+ `Unsupported server runtime: Bun ${actual} is not supported. Install Bun ${MIN_BUN_VERSION_STRING} or newer, or Node.js ${MIN_NODE_VERSION_STRING} or newer.`,
182
+ );
183
+ }
184
+ if (isSupportedNodeVersion(current.nodeVersion)) {
185
+ return { runtime: 'node', executable: execPath };
186
+ }
187
+ const actual = typeof current.nodeVersion === 'string' && current.nodeVersion.trim().length > 0
188
+ ? current.nodeVersion.trim()
189
+ : 'unknown';
190
+ throw new Error(
191
+ `Unsupported server runtime: Node.js ${actual} is not supported. Install Node.js ${MIN_NODE_VERSION_STRING} or newer, or Bun ${MIN_BUN_VERSION_STRING} or newer.`,
192
+ );
193
+ }
@@ -0,0 +1,295 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import {
4
+ NO_SUPPORTED_RUNTIME_MESSAGE,
5
+ assertCurrentRuntimeSupported,
6
+ getBunBinary,
7
+ isSupportedBunVersion,
8
+ isSupportedNodeVersion,
9
+ resolveServerExecutable,
10
+ } from './runtime-requirements.js';
11
+
12
+ function fakeSpawnSync({ nodeVersion = null, nodeStatus = 0, bunVersion = '1.4.2', bunStatus = 0 } = {}) {
13
+ return (bin, _args, _options) => {
14
+ const normalized = String(bin);
15
+ if (normalized === 'node' || normalized.endsWith('/node') || normalized === '/mock/node') {
16
+ if (nodeVersion === null || nodeStatus !== 0) return { status: 1, stdout: '' };
17
+ return { status: 0, stdout: `${nodeVersion}\n` };
18
+ }
19
+ if (normalized.includes('bun')) {
20
+ if (bunStatus !== 0 || bunVersion === null) return { status: 1, stdout: '' };
21
+ return { status: 0, stdout: `${bunVersion}\n` };
22
+ }
23
+ return { status: 1, stdout: '' };
24
+ };
25
+ }
26
+
27
+ describe('stable version validation', () => {
28
+ it('enforces stable Node >= 22.19.0', () => {
29
+ expect(isSupportedNodeVersion('v22.19.0')).toBe(true);
30
+ expect(isSupportedNodeVersion('22.19.0')).toBe(true);
31
+ expect(isSupportedNodeVersion('v22.19.1')).toBe(true);
32
+ expect(isSupportedNodeVersion('v24.14.1')).toBe(true);
33
+ expect(isSupportedNodeVersion('v22.18.9')).toBe(false);
34
+ expect(isSupportedNodeVersion('v22.14.0')).toBe(false);
35
+ expect(isSupportedNodeVersion('v20.19.0')).toBe(false);
36
+ });
37
+
38
+ it('enforces stable Bun >= 1.4.0', () => {
39
+ expect(isSupportedBunVersion('1.4.0')).toBe(true);
40
+ expect(isSupportedBunVersion('1.4.2')).toBe(true);
41
+ expect(isSupportedBunVersion('2.0.0')).toBe(true);
42
+ expect(isSupportedBunVersion('1.3.14')).toBe(false);
43
+ });
44
+
45
+ it('rejects malformed, prerelease, and build metadata', () => {
46
+ for (const malformed of [
47
+ '',
48
+ ' ',
49
+ 'v22',
50
+ '22.19',
51
+ 'latest',
52
+ 'not-a-version',
53
+ 'v22.19.0-rc.1',
54
+ '1.4.2-canary',
55
+ 'v22.19.0+build',
56
+ '1.4.2+meta',
57
+ ]) {
58
+ expect(isSupportedNodeVersion(malformed)).toBe(false);
59
+ expect(isSupportedBunVersion(malformed)).toBe(false);
60
+ }
61
+ for (const nonString of [null, undefined, 42, {}, []]) {
62
+ expect(isSupportedNodeVersion(nonString)).toBe(false);
63
+ expect(isSupportedBunVersion(nonString)).toBe(false);
64
+ }
65
+ });
66
+ });
67
+
68
+ describe('Bun binary resolution', () => {
69
+ it('resolves BUN_BINARY and BUN_INSTALL with precedence', () => {
70
+ expect(getBunBinary({ BUN_BINARY: '/custom/bun' })).toBe('/custom/bun');
71
+ expect(getBunBinary({ BUN_INSTALL: '/home/user/.bun' })).toBe('/home/user/.bun/bin/bun');
72
+ expect(getBunBinary({ BUN_BINARY: '/custom/bun', BUN_INSTALL: '/home/user/.bun' })).toBe('/custom/bun');
73
+ expect(getBunBinary({})).toBe('bun');
74
+ });
75
+ });
76
+
77
+ describe('Node-first automatic resolution', () => {
78
+ it('prefers the current Node executable without probing PATH', () => {
79
+ const spawnSyncFn = () => {
80
+ throw new Error('should not probe when current Node is supported');
81
+ };
82
+ expect(resolveServerExecutable({
83
+ isBun: false,
84
+ nodeVersion: 'v24.14.1',
85
+ execPath: '/usr/bin/node',
86
+ spawnSyncFn,
87
+ env: {},
88
+ })).toEqual({ runtime: 'node', executable: '/usr/bin/node' });
89
+ });
90
+
91
+ it('prefers PATH Node when running under Bun', () => {
92
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: 'v24.14.1', bunVersion: '1.4.2' });
93
+ expect(resolveServerExecutable({
94
+ isBun: true,
95
+ nodeVersion: 'v26.3.0',
96
+ bunVersion: '1.4.2',
97
+ execPath: '/mock/bun',
98
+ bunBin: '/mock/bun',
99
+ spawnSyncFn,
100
+ env: {},
101
+ })).toEqual({ runtime: 'node', executable: 'node' });
102
+ });
103
+
104
+ it('falls back to the current Bun executable with no runtimes on PATH', () => {
105
+ const spawnSyncFn = () => ({ status: 1, stdout: '' });
106
+ expect(resolveServerExecutable({
107
+ isBun: true,
108
+ nodeVersion: 'v26.3.0',
109
+ bunVersion: '1.4.2',
110
+ execPath: '/mock/current-bun',
111
+ spawnSyncFn,
112
+ env: {},
113
+ })).toEqual({ runtime: 'bun', executable: '/mock/current-bun' });
114
+ });
115
+
116
+ it('falls back to PATH Bun when not running under Bun', () => {
117
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: null, bunVersion: '1.4.2' });
118
+ expect(resolveServerExecutable({
119
+ isBun: false,
120
+ nodeVersion: 'v20.19.0',
121
+ execPath: '/usr/bin/node',
122
+ bunBin: '/mock/bun',
123
+ spawnSyncFn,
124
+ env: {},
125
+ })).toEqual({ runtime: 'bun', executable: '/mock/bun' });
126
+ });
127
+
128
+ it('fails deterministically when neither runtime is usable', () => {
129
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: null, bunStatus: 1, bunVersion: null });
130
+ expect(() => resolveServerExecutable({
131
+ isBun: false,
132
+ nodeVersion: 'v20.19.0',
133
+ execPath: '/usr/bin/node',
134
+ bunBin: '/mock/bun',
135
+ spawnSyncFn,
136
+ env: {},
137
+ })).toThrow(NO_SUPPORTED_RUNTIME_MESSAGE);
138
+ });
139
+
140
+ it('rejects old probe output during resolution', () => {
141
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: 'v20.19.0', bunVersion: null, bunStatus: 1 });
142
+ expect(() => resolveServerExecutable({
143
+ isBun: false,
144
+ nodeVersion: 'v20.19.0',
145
+ execPath: '/usr/bin/node',
146
+ spawnSyncFn,
147
+ env: {},
148
+ })).toThrow(NO_SUPPORTED_RUNTIME_MESSAGE);
149
+ });
150
+
151
+ it('bounds Node probe errors to Bun fallback', () => {
152
+ const spawnSyncFn = (bin) => {
153
+ if (String(bin).includes('bun')) return { status: 0, stdout: '1.4.2\n' };
154
+ throw new Error('spawn ENOENT');
155
+ };
156
+ expect(resolveServerExecutable({
157
+ isBun: false,
158
+ nodeVersion: 'v20.19.0',
159
+ execPath: '/usr/bin/node',
160
+ bunBin: '/mock/bun',
161
+ spawnSyncFn,
162
+ env: {},
163
+ })).toEqual({ runtime: 'bun', executable: '/mock/bun' });
164
+ });
165
+ });
166
+
167
+ describe('explicit Bun overrides', () => {
168
+ it('fails instead of falling back when explicit BUN_BINARY is old', () => {
169
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: null, bunVersion: '1.3.14' });
170
+ expect(() => resolveServerExecutable({
171
+ isBun: true,
172
+ nodeVersion: 'v26.3.0',
173
+ bunVersion: '1.4.2',
174
+ execPath: '/mock/current-bun',
175
+ bunBin: '/mock/old-bun',
176
+ spawnSyncFn,
177
+ env: { BUN_BINARY: '/mock/old-bun' },
178
+ })).toThrow(NO_SUPPORTED_RUNTIME_MESSAGE);
179
+ });
180
+
181
+ it('honors a supported explicit BUN_BINARY', () => {
182
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: null, bunVersion: '1.4.2' });
183
+ expect(resolveServerExecutable({
184
+ isBun: false,
185
+ nodeVersion: 'v20.19.0',
186
+ execPath: '/usr/bin/node',
187
+ bunBin: '/mock/new-bun',
188
+ spawnSyncFn,
189
+ env: { BUN_BINARY: '/mock/new-bun' },
190
+ })).toEqual({ runtime: 'bun', executable: '/mock/new-bun' });
191
+ });
192
+ });
193
+
194
+ describe('old Bun emulating new Node', () => {
195
+ it('rejects old Bun even though emulated Node looks new', () => {
196
+ expect(() => assertCurrentRuntimeSupported({
197
+ isBun: true,
198
+ nodeVersion: 'v26.3.0',
199
+ bunVersion: '1.3.14',
200
+ execPath: '/mock/bun',
201
+ })).toThrow(/Bun 1\.3\.14/);
202
+ });
203
+
204
+ it('never reuses the current executable as Node when running under Bun', () => {
205
+ const spawnSyncFn = fakeSpawnSync({ nodeVersion: 'v24.14.1', bunVersion: '1.4.2' });
206
+ expect(resolveServerExecutable({
207
+ isBun: true,
208
+ nodeVersion: 'v26.3.0',
209
+ bunVersion: '1.3.14',
210
+ execPath: '/mock/bun-old',
211
+ bunBin: '/mock/bun',
212
+ spawnSyncFn,
213
+ env: {},
214
+ })).toEqual({ runtime: 'node', executable: 'node' });
215
+ });
216
+ });
217
+
218
+ describe('resolver probe timeout', () => {
219
+ it('passes a bounded timeout to spawnSync', () => {
220
+ const calls = [];
221
+ const spawnSyncFn = (bin, args, options) => {
222
+ calls.push(options);
223
+ return fakeSpawnSync({ nodeVersion: null, bunVersion: '1.4.2' })(bin, args, options);
224
+ };
225
+ resolveServerExecutable({
226
+ isBun: false,
227
+ nodeVersion: 'v20.19.0',
228
+ execPath: '/usr/bin/node',
229
+ bunBin: '/mock/bun',
230
+ spawnSyncFn,
231
+ env: {},
232
+ });
233
+ expect(calls.length).toBeGreaterThan(0);
234
+ for (const options of calls) {
235
+ expect(Number.isFinite(options.timeout)).toBe(true);
236
+ expect(options.timeout).toBeGreaterThan(0);
237
+ expect(options.windowsHide).toBe(true);
238
+ }
239
+ });
240
+
241
+ it('honors an explicit probe timeout', () => {
242
+ const calls = [];
243
+ const spawnSyncFn = (bin, args, options) => {
244
+ calls.push(options);
245
+ return { status: 1, stdout: '' };
246
+ };
247
+ expect(() => resolveServerExecutable({
248
+ isBun: false,
249
+ nodeVersion: 'v20.19.0',
250
+ execPath: '/usr/bin/node',
251
+ bunBin: '/mock/bun',
252
+ spawnSyncFn,
253
+ env: {},
254
+ probeTimeoutMs: 1234,
255
+ })).toThrow(NO_SUPPORTED_RUNTIME_MESSAGE);
256
+ expect(calls.length).toBeGreaterThan(0);
257
+ for (const options of calls) {
258
+ expect(options.timeout).toBe(1234);
259
+ }
260
+ });
261
+ });
262
+
263
+ describe('current runtime validation without PATH probing', () => {
264
+ it('validates supported Node and Bun executables', () => {
265
+ expect(assertCurrentRuntimeSupported({
266
+ isBun: false,
267
+ nodeVersion: 'v24.14.1',
268
+ execPath: '/usr/bin/node',
269
+ })).toEqual({ runtime: 'node', executable: '/usr/bin/node' });
270
+ expect(assertCurrentRuntimeSupported({
271
+ isBun: true,
272
+ nodeVersion: 'v26.3.0',
273
+ bunVersion: '1.4.2',
274
+ execPath: '/mock/bun',
275
+ })).toEqual({ runtime: 'bun', executable: '/mock/bun' });
276
+ });
277
+
278
+ it('rejects old, malformed, and prerelease current runtimes', () => {
279
+ expect(() => assertCurrentRuntimeSupported({
280
+ isBun: false, nodeVersion: 'v20.19.0', execPath: '/usr/bin/node',
281
+ })).toThrow(/Node\.js v20\.19\.0/);
282
+ expect(() => assertCurrentRuntimeSupported({
283
+ isBun: false, nodeVersion: 'not-a-version', execPath: '/usr/bin/node',
284
+ })).toThrow(/Unsupported server runtime/);
285
+ expect(() => assertCurrentRuntimeSupported({
286
+ isBun: false, nodeVersion: 'v22.19.0-rc.1', execPath: '/usr/bin/node',
287
+ })).toThrow(/Unsupported server runtime/);
288
+ expect(() => assertCurrentRuntimeSupported({
289
+ isBun: true, nodeVersion: 'v26.3.0', bunVersion: 'bad', execPath: '/mock/bun',
290
+ })).toThrow(/Unsupported server runtime/);
291
+ expect(() => assertCurrentRuntimeSupported({
292
+ isBun: false, nodeVersion: 'v24.14.1', execPath: ' ',
293
+ })).toThrow(/missing runtime executable/);
294
+ });
295
+ });
@@ -57,7 +57,7 @@ The PiChamber `pichamber.service` itself already supports both user (`~/.config/
57
57
 
58
58
  ## Upgrade considerations
59
59
 
60
- `pichamber update` detects the owning package manager, upgrades the global package, and restarts the relevant systemd service (`systemctl --user restart pichamber.service` or `systemctl restart pichamber.service` when running as root). The tunnel token file and PiChamber `pi/settings.json` sidecar are preserved across upgrades because they live under `PICHAMBER_DATA_DIR` (or `~/.pichamber`), not in the package directory. A Docker deployment is not upgraded in-place; it must be redeployed via `docker pull`.
60
+ `pichamber update` detects the owning package manager, upgrades the global package, and restarts the relevant systemd service (`systemctl --user restart pichamber.service` or `systemctl restart pichamber.service` when running as root). The tunnel token file and PiChamber `pi/settings.json` sidecar are preserved across upgrades because they live under `PICHAMBER_DATA_DIR` (or `~/.pichamber`), not in the package directory. A Docker deployment is not upgraded in-place; pull a newer image and recreate the container (`docker compose pull` then `docker compose up -d`) so volume-mounted config and tunnel tokens survive.
61
61
 
62
62
  ## Testing
63
63