@pi-chamber/web 0.9.0 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -8
- package/bin/cli.js +11 -1
- package/bin/cli.test.js +18 -0
- package/bin/lib/DOCUMENTATION.md +3 -3
- package/bin/lib/cli-args.js +7 -3
- package/bin/lib/cli-lifecycle.js +3 -0
- package/bin/lib/cli-paths.js +28 -6
- package/bin/lib/cli-process.js +1 -0
- package/bin/lib/cli-tunnel-profiles.js +15 -10
- package/bin/lib/commands-connect-url.js +9 -1
- package/bin/lib/commands-logs.js +22 -4
- package/bin/lib/commands-serve.js +10 -2
- package/bin/lib/commands-tunnel.js +14 -0
- package/bin/lib/commands-update.js +18 -14
- package/bin/lib/commands-update.test.js +2 -1
- package/dist/assets/{DiagramEditor-CcbnMl1H.js → DiagramEditor-DuGmiPZ5.js} +1 -1
- package/dist/assets/{DiagramView-DTW5jwK3.js → DiagramView-CV-iReyY.js} +1 -1
- package/dist/assets/{DiffView-CZyHHAOB.js → DiffView-DVd1MLPB.js} +6 -6
- package/dist/assets/{FilesView-BJYLFR3H.js → FilesView-CPnW4I90.js} +1 -1
- package/dist/assets/{GitView-Cg_5UU7E.js → GitView-Dj_7hgX_.js} +3 -3
- package/dist/assets/JsonTreeView-Cyy0lEZR.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-WqBwxlso.js → MarkdownRendererImpl-BXN78Wu_.js} +1 -1
- package/dist/assets/{PatchDiff-BRi23N1l.js → PatchDiff-C7dA3U29.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-7VAU5pwZ.js → SessionSwitcherContent-dr3g9DR7.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-BslRtccE.js → SessionSwitcherDropdown-C3zdd82V.js} +2 -2
- package/dist/assets/{SessionUnreadDot-1nV0Z2ZA.js → SessionUnreadDot-qeik5qtT.js} +1 -1
- package/dist/assets/SettingsView-C57uV1YS.js +2 -0
- package/dist/assets/{SettingsWindow-D4jZHl8X.js → SettingsWindow-Bbay2W76.js} +1 -1
- package/dist/assets/ToolOutputDialog-CRTiN1CH.js +8 -0
- package/dist/assets/{ToolPartDiffPreview-9FLv2fWD.js → ToolPartDiffPreview-CqnNcLPk.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-ywmPBXAG.js → VirtualizedFileDiff-iqwryMNU.js} +3 -3
- package/dist/assets/{collapsible-6mCYf7Ky.js → collapsible-szfZ0Syc.js} +1 -1
- package/dist/assets/computeVirtualFileMetrics-Bbugxxtp.js +3 -0
- package/dist/assets/{contextFileOpenGuard-CKyf-TZ7.js → contextFileOpenGuard-BC3ie230.js} +1 -1
- package/dist/assets/{gitStatusPredicates-UsytDMy_.js → gitStatusPredicates-DbThKVSf.js} +1 -1
- package/dist/assets/{index-C8NYcA8-.css → index-DNoEeZ2U.css} +1 -1
- package/dist/assets/{index-yWgKW2Fx.js → index-KIdiBFJs.js} +4 -4
- package/dist/assets/{index-D1IaU-Q7.js → index-v6K3L94m.js} +1 -1
- package/dist/assets/{isDiffPlainText-DPCilEx_.js → isDiffPlainText-Dl0RBjPZ.js} +1 -1
- package/dist/assets/{isFilePlainText-XdCAgm8R.js → isFilePlainText-CbrmvrM6.js} +1 -1
- package/dist/assets/{main-DcAMXRSi.js → main-4PkIvzf4.js} +7 -7
- package/dist/assets/{main-DhvLreEl.js → main-DMyWi0qs.js} +2 -2
- package/dist/assets/{markdownCore-BF0Dqwm4.js → markdownCore-BD5WkOKU.js} +1 -1
- package/dist/assets/{miniChat-DsCx0dsW.js → miniChat-CLMNhna4.js} +2 -2
- package/dist/assets/{mobile-C-IN49xX.js → mobile-rWMDwhtQ.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-BRhGNRJ8.js +2 -0
- package/dist/assets/{renderMobileApp-xCdVzvyf.js → renderMobileApp-DLy2YoQg.js} +3 -3
- package/dist/assets/{runtimeEndpointReset-CT3WShpj.js → runtimeEndpointReset-Z9YtcHxZ.js} +15 -15
- package/dist/assets/{runtimeSurface-C_3mcJ01.js → runtimeSurface-CySRuLbN.js} +1 -1
- package/dist/assets/{useAppFontEffects-BgK55NDM.js → useAppFontEffects-DfuJVB15.js} +102 -102
- package/dist/assets/{useFilesViewSearch-CWx24PZg.js → useFilesViewSearch-BZBHrZ90.js} +1 -1
- package/dist/assets/usePushVisibilityBeacon-BxTkEajM.js +10 -0
- package/dist/assets/{useSwitcherItems-CrS-F6DY.js → useSwitcherItems-jITqE8PV.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BzeePAPn.js → vendor-codemirror-language-data-CDdfwzlS.js} +2 -2
- package/dist/assets/{web-components-DAkBDXRk.js → web-components-C9wXMuCp.js} +2 -2
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +3 -3
- package/server/index.js +26 -7
- package/server/lib/client-auth/pairing.js +13 -2
- package/server/lib/client-auth/remote-clients.js +13 -2
- package/server/lib/fs/DOCUMENTATION.md +3 -1
- package/server/lib/fs/routes.test.js +74 -0
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/identity-storage.js +10 -1
- package/server/lib/package-manager.js +1 -1
- package/server/lib/package-manager.test.js +11 -0
- package/server/lib/pi/archive-store.js +3 -2
- package/server/lib/pi/model-config-store.js +6 -2
- package/server/lib/pi/routes.js +46 -3
- package/server/lib/pi/routes.test.js +53 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +15 -9
- package/server/lib/pi/session-daemon/daemon-process.js +48 -13
- package/server/lib/pi/session-daemon/ipc-client.js +20 -9
- package/server/lib/pi/session-daemon/ipc-client.test.js +88 -0
- package/server/lib/pi/session-daemon/ipc-protocol.js +9 -0
- package/server/lib/pi/session-daemon/session-daemon.js +353 -66
- package/server/lib/pi/session-daemon/session-daemon.test.js +348 -0
- package/server/lib/pi/session-daemon/session-lease.js +151 -0
- package/server/lib/pi/session-daemon/session-lease.test.js +108 -0
- package/server/lib/pi/session-daemon/supervisor.js +244 -54
- package/server/lib/pi/session-daemon/supervisor.test.js +202 -6
- package/server/lib/pi/session-folders-store.js +20 -2
- package/server/lib/pi/session-folders-store.test.js +17 -0
- package/server/lib/pi/settings-store.js +3 -2
- package/server/lib/pi/snippets-store.js +4 -1
- package/server/lib/pi/ui-settings-store.js +130 -24
- package/server/lib/pi/ui-settings-store.test.js +58 -7
- package/server/lib/server/cross-process-lock.js +112 -0
- package/server/lib/server/cross-process-lock.test.js +70 -0
- package/server/lib/server/server-profile.js +110 -0
- package/server/lib/server/server-profile.test.js +58 -0
- package/server/lib/server/tunnel-service.DOCUMENTATION.md +7 -8
- package/server/lib/server/tunnel-service.js +8 -1
- package/server/lib/stt/config-store.js +3 -2
- package/server/lib/terminal/DOCUMENTATION.md +1 -1
- package/server/lib/tunnels/DOCUMENTATION.md +38 -18
- package/server/lib/ui-auth/ui-auth.js +9 -2
- package/server/lib/ui-auth/ui-passkeys.js +9 -1
- package/dist/assets/JsonTreeView-GTdKGEdy.js +0 -1
- package/dist/assets/SettingsView-UIaAyjTo.js +0 -2
- package/dist/assets/ToolOutputDialog-BoeJONiR.js +0 -8
- package/dist/assets/computeVirtualFileMetrics-3H6mg13G.js +0 -3
- package/dist/assets/renderElectronMiniChatApp-C13HXGZL.js +0 -2
- package/dist/assets/usePushVisibilityBeacon-swMQLm-i.js +0 -10
|
@@ -103,6 +103,7 @@ describe('Pi session daemon supervisor', () => {
|
|
|
103
103
|
}
|
|
104
104
|
expect(JSON.stringify(await supervisor.health())).not.toContain(credential.trim());
|
|
105
105
|
|
|
106
|
+
await expect(supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
106
107
|
await expect(supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
107
108
|
await expect(supervisor.health()).resolves.toMatchObject({
|
|
108
109
|
state: 'unavailable',
|
|
@@ -191,13 +192,44 @@ describe('Pi session daemon supervisor', () => {
|
|
|
191
192
|
cwd: join(tmpdir(), 'pichamber-win-project'),
|
|
192
193
|
platform: 'win32',
|
|
193
194
|
});
|
|
194
|
-
expect(windowsSupervisor.paths.endpoint).toMatch(/^\\\\\.\\pipe\\pichamber-pi-session-daemon-[0-9a-f]{16}$/);
|
|
195
|
+
expect(windowsSupervisor.paths.endpoint).toMatch(/^\\\\\.\\pipe\\pichamber-pi-session-daemon-[0-9a-f]{16}-web$/);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('namespaces daemon sidecars per server profile', () => {
|
|
199
|
+
const root = join(tmpdir(), 'pichamber-pi-supervisor-profiles-');
|
|
200
|
+
const installed = createPiSessionDaemonSupervisor({
|
|
201
|
+
env: { PICHAMBER_DATA_DIR: join(root, 'data') },
|
|
202
|
+
cwd: join(root, 'project'),
|
|
203
|
+
port: 3000,
|
|
204
|
+
});
|
|
205
|
+
const dev = createPiSessionDaemonSupervisor({
|
|
206
|
+
env: { PICHAMBER_DATA_DIR: join(root, 'data'), PICHAMBER_SERVER_PROFILE_KIND: 'dev' },
|
|
207
|
+
cwd: join(root, 'project'),
|
|
208
|
+
port: 3000,
|
|
209
|
+
});
|
|
210
|
+
const otherPort = createPiSessionDaemonSupervisor({
|
|
211
|
+
env: { PICHAMBER_DATA_DIR: join(root, 'data') },
|
|
212
|
+
cwd: join(root, 'project'),
|
|
213
|
+
port: 3902,
|
|
214
|
+
});
|
|
215
|
+
expect(installed.paths.profileKey).toBe('web-p3000');
|
|
216
|
+
expect(dev.paths.profileKey).toBe('web-dev-p3000');
|
|
217
|
+
for (const supervisor of [installed, dev, otherPort]) {
|
|
218
|
+
expect(supervisor.paths.credentialFile).toContain(supervisor.paths.profileKey);
|
|
219
|
+
expect(supervisor.paths.stateFile).toContain(supervisor.paths.profileKey);
|
|
220
|
+
expect(supervisor.paths.lockFile).toContain(supervisor.paths.profileKey);
|
|
221
|
+
expect(supervisor.paths.logFile).toContain(supervisor.paths.profileKey);
|
|
222
|
+
}
|
|
223
|
+
const paths = [installed, dev, otherPort].map((item) => item.paths.stateFile);
|
|
224
|
+
expect(new Set(paths).size).toBe(3);
|
|
225
|
+
expect(installed.paths.endpoint).not.toBe(dev.paths.endpoint);
|
|
226
|
+
expect(installed.paths.credentialFile).not.toBe(otherPort.paths.credentialFile);
|
|
195
227
|
});
|
|
196
228
|
|
|
197
229
|
it('bounds an unresponsive Windows daemon probe by the supervisor operation timeout', async () => {
|
|
198
230
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-supervisor-hung-win-'));
|
|
199
231
|
const dataDir = join(root, 'data');
|
|
200
|
-
const piDataDir = join(dataDir, 'pi');
|
|
232
|
+
const piDataDir = join(dataDir, 'pi', 'daemons', 'web');
|
|
201
233
|
await mkdir(piDataDir, { recursive: true });
|
|
202
234
|
const daemonPid = 7_331;
|
|
203
235
|
const processLike = {
|
|
@@ -226,6 +258,9 @@ describe('Pi session daemon supervisor', () => {
|
|
|
226
258
|
protocolVersion: 1,
|
|
227
259
|
pid: daemonPid,
|
|
228
260
|
endpoint: windowsSupervisor.paths.endpoint,
|
|
261
|
+
profileKey: windowsSupervisor.paths.profileKey,
|
|
262
|
+
daemonId: 'daemon-hung',
|
|
263
|
+
serverInstanceId: windowsSupervisor.paths.serverInstanceId,
|
|
229
264
|
startedAt: new Date().toISOString(),
|
|
230
265
|
}));
|
|
231
266
|
|
|
@@ -242,8 +277,8 @@ describe('Pi session daemon supervisor', () => {
|
|
|
242
277
|
const cwd = join(root, 'project');
|
|
243
278
|
const agentDir = join(root, 'agent');
|
|
244
279
|
const dataDir = join(root, 'data');
|
|
245
|
-
await Promise.all([mkdir(cwd), mkdir(agentDir), mkdir(join(dataDir, 'pi'), { recursive: true })]);
|
|
246
|
-
const lockFile = join(dataDir, 'pi', '
|
|
280
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir), mkdir(join(dataDir, 'pi', 'daemons', 'web'), { recursive: true })]);
|
|
281
|
+
const lockFile = join(dataDir, 'pi', 'daemons', 'web', 'operation.lock');
|
|
247
282
|
await writeFile(lockFile, '');
|
|
248
283
|
const past = new Date(Date.now() - 1_000);
|
|
249
284
|
await utimes(lockFile, past, past);
|
|
@@ -264,8 +299,8 @@ describe('Pi session daemon supervisor', () => {
|
|
|
264
299
|
const cwd = join(root, 'project');
|
|
265
300
|
const agentDir = join(root, 'agent');
|
|
266
301
|
const dataDir = join(root, 'data');
|
|
267
|
-
await Promise.all([mkdir(cwd), mkdir(agentDir), mkdir(join(dataDir, 'pi'), { recursive: true })]);
|
|
268
|
-
const lockFile = join(dataDir, 'pi', '
|
|
302
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir), mkdir(join(dataDir, 'pi', 'daemons', 'web'), { recursive: true })]);
|
|
303
|
+
const lockFile = join(dataDir, 'pi', 'daemons', 'web', 'operation.lock');
|
|
269
304
|
await writeFile(lockFile, '{');
|
|
270
305
|
const past = new Date(Date.now() - 1_000);
|
|
271
306
|
await utimes(lockFile, past, past);
|
|
@@ -280,4 +315,165 @@ describe('Pi session daemon supervisor', () => {
|
|
|
280
315
|
supervisor = createPiSessionDaemonSupervisor({ env, cwd });
|
|
281
316
|
await expect(supervisor.start()).resolves.toMatchObject({ state: 'ready', reused: false });
|
|
282
317
|
}, 20_000);
|
|
318
|
+
|
|
319
|
+
it('keeps per-profile daemons independent across one data directory', async () => {
|
|
320
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-supervisor-profiles-run-'));
|
|
321
|
+
const cwd = join(root, 'project');
|
|
322
|
+
const agentDir = join(root, 'agent');
|
|
323
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir)]);
|
|
324
|
+
const baseEnv = {
|
|
325
|
+
...process.env,
|
|
326
|
+
PI_OFFLINE: '1',
|
|
327
|
+
PICHAMBER_DATA_DIR: join(root, 'data'),
|
|
328
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
329
|
+
XDG_RUNTIME_DIR: join(root, 'runtime'),
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const installed = createPiSessionDaemonSupervisor({ env: baseEnv, cwd, port: 3000 });
|
|
333
|
+
const dev = createPiSessionDaemonSupervisor({
|
|
334
|
+
env: { ...baseEnv, PICHAMBER_SERVER_PROFILE_KIND: 'dev' },
|
|
335
|
+
cwd,
|
|
336
|
+
port: 3000,
|
|
337
|
+
});
|
|
338
|
+
try {
|
|
339
|
+
await installed.start();
|
|
340
|
+
await dev.start();
|
|
341
|
+
const installedState = JSON.parse(await readFile(installed.paths.stateFile, 'utf8'));
|
|
342
|
+
const devState = JSON.parse(await readFile(dev.paths.stateFile, 'utf8'));
|
|
343
|
+
expect(installedState.pid).not.toBe(devState.pid);
|
|
344
|
+
expect(installedState.profileKey).toBe('web-p3000');
|
|
345
|
+
expect(devState.profileKey).toBe('web-dev-p3000');
|
|
346
|
+
|
|
347
|
+
const created = await installed.request('sessions.create', { cwd });
|
|
348
|
+
const sessionDirectory = getPiSessionDirectory({ cwd, agentDir });
|
|
349
|
+
await mkdir(sessionDirectory, { recursive: true });
|
|
350
|
+
await writeFile(join(sessionDirectory, `lease_${created.session.id}.jsonl`), `${JSON.stringify({
|
|
351
|
+
type: 'session',
|
|
352
|
+
version: 3,
|
|
353
|
+
id: created.session.id,
|
|
354
|
+
timestamp: new Date().toISOString(),
|
|
355
|
+
cwd,
|
|
356
|
+
})}\n`);
|
|
357
|
+
await expect(dev.request('sessions.open', { sessionId: created.session.id, directory: cwd }))
|
|
358
|
+
.rejects.toMatchObject({ code: 'SESSION_IN_USE' });
|
|
359
|
+
await expect(dev.request('sessions.delete', { sessionId: created.session.id, directory: cwd }))
|
|
360
|
+
.rejects.toMatchObject({ code: 'SESSION_IN_USE' });
|
|
361
|
+
|
|
362
|
+
// Stopping one profile must release only its own leases and leave the
|
|
363
|
+
// other daemon running.
|
|
364
|
+
await installed.stop();
|
|
365
|
+
await expect(dev.health()).resolves.toMatchObject({ state: 'ready' });
|
|
366
|
+
await expect(dev.request('sessions.open', { sessionId: created.session.id, directory: cwd }))
|
|
367
|
+
.resolves.toMatchObject({ session: { id: created.session.id } });
|
|
368
|
+
await dev.stop();
|
|
369
|
+
await expect(dev.health()).resolves.toMatchObject({ state: 'unavailable' });
|
|
370
|
+
} finally {
|
|
371
|
+
await installed.stop().catch(() => {});
|
|
372
|
+
await dev.stop().catch(() => {});
|
|
373
|
+
}
|
|
374
|
+
}, 60_000);
|
|
375
|
+
|
|
376
|
+
it('refuses to claim a same-profile daemon while its server owner is alive', async () => {
|
|
377
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-supervisor-live-owner-'));
|
|
378
|
+
const cwd = join(root, 'project');
|
|
379
|
+
const agentDir = join(root, 'agent');
|
|
380
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir)]);
|
|
381
|
+
const env = {
|
|
382
|
+
...process.env,
|
|
383
|
+
PI_OFFLINE: '1',
|
|
384
|
+
PICHAMBER_DATA_DIR: join(root, 'data'),
|
|
385
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
386
|
+
XDG_RUNTIME_DIR: join(root, 'runtime'),
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const first = createPiSessionDaemonSupervisor({ env, cwd, port: 3000 });
|
|
390
|
+
const peer = createPiSessionDaemonSupervisor({ env, cwd, port: 3000 });
|
|
391
|
+
try {
|
|
392
|
+
await first.start();
|
|
393
|
+
await expect(peer.start()).rejects.toMatchObject({ code: 'DAEMON_PROFILE_IN_USE' });
|
|
394
|
+
await expect(first.health()).resolves.toMatchObject({ state: 'ready' });
|
|
395
|
+
} finally {
|
|
396
|
+
await first.stop().catch(() => {});
|
|
397
|
+
await peer.stop().catch(() => {});
|
|
398
|
+
}
|
|
399
|
+
}, 30_000);
|
|
400
|
+
|
|
401
|
+
it('replaces a same-profile daemon when the PiChamber build changes', async () => {
|
|
402
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-supervisor-build-'));
|
|
403
|
+
const cwd = join(root, 'project');
|
|
404
|
+
const agentDir = join(root, 'agent');
|
|
405
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir)]);
|
|
406
|
+
const env = {
|
|
407
|
+
...process.env,
|
|
408
|
+
PI_OFFLINE: '1',
|
|
409
|
+
PICHAMBER_DATA_DIR: join(root, 'data'),
|
|
410
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
411
|
+
XDG_RUNTIME_DIR: join(root, 'runtime'),
|
|
412
|
+
};
|
|
413
|
+
const departedServerProcess = {
|
|
414
|
+
pid: 987_654_321,
|
|
415
|
+
execPath: process.execPath,
|
|
416
|
+
versions: process.versions,
|
|
417
|
+
kill(pid, signal) {
|
|
418
|
+
return process.kill(pid, signal);
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
const first = createPiSessionDaemonSupervisor({ env, cwd, port: 3000, version: '1.0.0', processLike: departedServerProcess });
|
|
422
|
+
const upgraded = createPiSessionDaemonSupervisor({ env, cwd, port: 3000, version: '2.0.0' });
|
|
423
|
+
try {
|
|
424
|
+
await first.start();
|
|
425
|
+
const firstState = JSON.parse(await readFile(first.paths.stateFile, 'utf8'));
|
|
426
|
+
await expect(upgraded.start()).resolves.toMatchObject({ state: 'ready', reused: false });
|
|
427
|
+
await waitForExit(firstState.pid);
|
|
428
|
+
const upgradedState = JSON.parse(await readFile(upgraded.paths.stateFile, 'utf8'));
|
|
429
|
+
expect(upgradedState.pid).not.toBe(firstState.pid);
|
|
430
|
+
expect(upgradedState.buildId).toBe('2.0.0');
|
|
431
|
+
} finally {
|
|
432
|
+
await first.stop().catch(() => {});
|
|
433
|
+
await upgraded.stop().catch(() => {});
|
|
434
|
+
}
|
|
435
|
+
}, 60_000);
|
|
436
|
+
|
|
437
|
+
it('refuses a stale same-profile server stop after a newer instance claims the daemon', async () => {
|
|
438
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-supervisor-claim-'));
|
|
439
|
+
const cwd = join(root, 'project');
|
|
440
|
+
const agentDir = join(root, 'agent');
|
|
441
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir)]);
|
|
442
|
+
const env = {
|
|
443
|
+
...process.env,
|
|
444
|
+
PI_OFFLINE: '1',
|
|
445
|
+
PICHAMBER_DATA_DIR: join(root, 'data'),
|
|
446
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
447
|
+
XDG_RUNTIME_DIR: join(root, 'runtime'),
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const departedServerProcess = {
|
|
451
|
+
pid: 987_654_321,
|
|
452
|
+
execPath: process.execPath,
|
|
453
|
+
versions: process.versions,
|
|
454
|
+
kill(pid, signal) {
|
|
455
|
+
return process.kill(pid, signal);
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
const first = createPiSessionDaemonSupervisor({ env, cwd, port: 3000, processLike: departedServerProcess });
|
|
459
|
+
const second = createPiSessionDaemonSupervisor({ env, cwd, port: 3000 });
|
|
460
|
+
try {
|
|
461
|
+
await first.start();
|
|
462
|
+
const firstState = JSON.parse(await readFile(first.paths.stateFile, 'utf8'));
|
|
463
|
+
|
|
464
|
+
// A restarted server on the same profile claims the live daemon.
|
|
465
|
+
await expect(second.start()).resolves.toMatchObject({ state: 'ready', reused: true });
|
|
466
|
+
const claimedState = JSON.parse(await readFile(second.paths.stateFile, 'utf8'));
|
|
467
|
+
expect(claimedState.pid).toBe(firstState.pid);
|
|
468
|
+
expect(claimedState.serverInstanceId).toBe(second.paths.serverInstanceId);
|
|
469
|
+
|
|
470
|
+
// The stale first server must not terminate the claimed daemon.
|
|
471
|
+
await expect(first.stop()).rejects.toMatchObject({ code: 'DAEMON_OWNERSHIP_MISMATCH' });
|
|
472
|
+
await expect(second.health()).resolves.toMatchObject({ state: 'ready' });
|
|
473
|
+
await expect(second.stop()).resolves.toEqual({ state: 'stopped' });
|
|
474
|
+
} finally {
|
|
475
|
+
await first.stop().catch(() => {});
|
|
476
|
+
await second.stop().catch(() => {});
|
|
477
|
+
}
|
|
478
|
+
}, 60_000);
|
|
283
479
|
});
|
|
@@ -3,6 +3,7 @@ import { chmod, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
|
|
5
5
|
import { resolvePiChamberDataDir } from '../pichamber-data-dir.js';
|
|
6
|
+
import { withCrossProcessLock } from '../server/cross-process-lock.js';
|
|
6
7
|
|
|
7
8
|
const MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
8
9
|
const MAX_KEY_LENGTH = 2_048;
|
|
@@ -57,7 +58,24 @@ export const createPiSessionFoldersStore = ({
|
|
|
57
58
|
|
|
58
59
|
const write = async (value) => {
|
|
59
60
|
const snapshot = validateSnapshot(value);
|
|
60
|
-
const operation = mutation.then(async () => {
|
|
61
|
+
const operation = mutation.then(async () => withCrossProcessLock(`${file}.lock`, async () => {
|
|
62
|
+
// Stale snapshots must not silently overwrite newer folders: concurrent
|
|
63
|
+
// servers share this file and only the lock serializes them.
|
|
64
|
+
try {
|
|
65
|
+
const raw = await fs.readFile(file, 'utf8');
|
|
66
|
+
const current = validateSnapshot(JSON.parse(raw));
|
|
67
|
+
const sameRevision = current.updatedAt === snapshot.updatedAt;
|
|
68
|
+
const sameSnapshot = sameRevision && JSON.stringify(current) === JSON.stringify(snapshot);
|
|
69
|
+
if (current.updatedAt > snapshot.updatedAt || (sameRevision && !sameSnapshot)) {
|
|
70
|
+
const stale = new Error('SESSION_FOLDERS_STALE');
|
|
71
|
+
stale.code = 'SESSION_FOLDERS_STALE';
|
|
72
|
+
throw stale;
|
|
73
|
+
}
|
|
74
|
+
if (sameSnapshot) return { exists: true, ...current };
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (error?.code === 'ENOENT') { /* first write wins */ } else if (error?.code === 'SESSION_FOLDERS_STALE') throw error;
|
|
77
|
+
else throw invalid();
|
|
78
|
+
}
|
|
61
79
|
const parent = dirname(file);
|
|
62
80
|
await fs.mkdir(parent, { recursive: true, mode: 0o700 });
|
|
63
81
|
const temporary = `${file}.tmp-${process.pid}-${randomUUID()}`;
|
|
@@ -65,7 +83,7 @@ export const createPiSessionFoldersStore = ({
|
|
|
65
83
|
await fs.rename(temporary, file);
|
|
66
84
|
if (process.platform !== 'win32') await fs.chmod(file, 0o600);
|
|
67
85
|
return { exists: true, ...snapshot };
|
|
68
|
-
});
|
|
86
|
+
}));
|
|
69
87
|
mutation = operation.catch(() => {});
|
|
70
88
|
return operation;
|
|
71
89
|
};
|
|
@@ -33,6 +33,23 @@ describe('Pi session folders store', () => {
|
|
|
33
33
|
expect(JSON.parse(await readFile(file, 'utf8'))).toEqual(snapshot);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
it('rejects stale and conflicting same-revision snapshots', async () => {
|
|
37
|
+
const directory = await mkdtemp(join(tmpdir(), 'pichamber-session-folders-'));
|
|
38
|
+
directories.push(directory);
|
|
39
|
+
const store = createPiSessionFoldersStore({ file: join(directory, 'session-folders.json') });
|
|
40
|
+
await store.write(snapshot);
|
|
41
|
+
|
|
42
|
+
await expect(store.write({ ...snapshot, updatedAt: 1 })).rejects.toMatchObject({ code: 'SESSION_FOLDERS_STALE' });
|
|
43
|
+
await expect(store.write({
|
|
44
|
+
...snapshot,
|
|
45
|
+
foldersMap: {
|
|
46
|
+
'/workspace': [{ ...snapshot.foldersMap['/workspace'][0], name: 'Conflicting' }],
|
|
47
|
+
},
|
|
48
|
+
})).rejects.toMatchObject({ code: 'SESSION_FOLDERS_STALE' });
|
|
49
|
+
await expect(store.write(snapshot)).resolves.toEqual({ exists: true, ...snapshot });
|
|
50
|
+
await expect(store.read()).resolves.toEqual({ exists: true, ...snapshot });
|
|
51
|
+
});
|
|
52
|
+
|
|
36
53
|
it('rejects malformed snapshots without replacing valid data', async () => {
|
|
37
54
|
const directory = await mkdtemp(join(tmpdir(), 'pichamber-session-folders-'));
|
|
38
55
|
directories.push(directory);
|
|
@@ -2,6 +2,7 @@ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { resolvePiChamberDataDir } from '../pichamber-data-dir.js';
|
|
5
|
+
import { withCrossProcessLock } from '../server/cross-process-lock.js';
|
|
5
6
|
import { isPiThinkingLevel } from './thinking-levels.js';
|
|
6
7
|
|
|
7
8
|
const invalidSettings = () => {
|
|
@@ -123,7 +124,7 @@ export const createPiSettingsStore = ({ file = join(resolvePiChamberDataDir(), '
|
|
|
123
124
|
|
|
124
125
|
const update = async (patch) => {
|
|
125
126
|
if (!patch || typeof patch !== 'object' || Array.isArray(patch)) throw invalidSettings();
|
|
126
|
-
const operation = writeChain.then(async () => {
|
|
127
|
+
const operation = writeChain.then(() => withCrossProcessLock(`${file}.lock`, async () => {
|
|
127
128
|
const current = await read();
|
|
128
129
|
const next = normalize({
|
|
129
130
|
...current,
|
|
@@ -141,7 +142,7 @@ export const createPiSettingsStore = ({ file = join(resolvePiChamberDataDir(), '
|
|
|
141
142
|
await writeFile(temporary, JSON.stringify(next), { mode: 0o600 });
|
|
142
143
|
await rename(temporary, file);
|
|
143
144
|
return next;
|
|
144
|
-
});
|
|
145
|
+
}));
|
|
145
146
|
writeChain = operation.catch(() => {});
|
|
146
147
|
return operation;
|
|
147
148
|
};
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { dirname, isAbsolute, join, normalize } from "node:path";
|
|
11
11
|
|
|
12
12
|
import { resolvePiChamberDataDir } from "../pichamber-data-dir.js";
|
|
13
|
+
import { withCrossProcessLock } from "../server/cross-process-lock.js";
|
|
13
14
|
|
|
14
15
|
const MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
15
16
|
const MAX_CONTENT_CHARS = 200_000;
|
|
@@ -238,7 +239,9 @@ export const createPiSnippetsStore = ({
|
|
|
238
239
|
};
|
|
239
240
|
|
|
240
241
|
const transact = (operation) => {
|
|
241
|
-
|
|
242
|
+
// The in-process chain orders one server; the file lock orders every
|
|
243
|
+
// server sharing this data directory.
|
|
244
|
+
const pending = mutation.then(() => withCrossProcessLock(`${file}.lock`, operation));
|
|
242
245
|
mutation = pending.catch(() => {});
|
|
243
246
|
return pending;
|
|
244
247
|
};
|
|
@@ -3,8 +3,61 @@ import { chmod, mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
|
|
5
5
|
import { resolvePiChamberDataDir } from '../pichamber-data-dir.js';
|
|
6
|
+
import { withCrossProcessLock } from '../server/cross-process-lock.js';
|
|
6
7
|
|
|
7
8
|
const MAX_SETTINGS_BYTES = 2 * 1024 * 1024;
|
|
9
|
+
const PORTABLE_SETTINGS_MARKER = '__pichamberSettingsScope';
|
|
10
|
+
const PORTABLE_SETTINGS_VERSION = 'portable-v1';
|
|
11
|
+
|
|
12
|
+
// Keep this list explicit. settings.json is intended to be copied between hosts.
|
|
13
|
+
const PORTABLE_FIELDS = new Set([
|
|
14
|
+
'themeId', 'useSystemTheme', 'themeVariant', 'lightThemeId', 'darkThemeId',
|
|
15
|
+
'splashBgLight', 'splashFgLight', 'splashBgDark', 'splashFgDark',
|
|
16
|
+
'showReasoningTraces', 'collapsibleThinkingBlocks', 'collapseThinkingByDefault',
|
|
17
|
+
'showDeletionDialog', 'nativeNotificationsEnabled', 'notificationMode',
|
|
18
|
+
'notifyOnSubtasks', 'notifyOnCompletion', 'notifyOnError', 'notifyOnQuestion',
|
|
19
|
+
'notificationTemplates', 'summarizeLastMessage', 'summaryThreshold', 'summaryLength',
|
|
20
|
+
'maxLastMessageLength', 'usageAutoRefresh', 'usageRefreshIntervalMs',
|
|
21
|
+
'usageDisplayMode', 'usageShowPredValues', 'usageDropdownProviders',
|
|
22
|
+
'usageSelectedModels', 'usageCollapsedFamilies', 'usageExpandedFamilies', 'usageModelGroups',
|
|
23
|
+
'autoDeleteEnabled', 'autoSaveEnabled', 'autoDeleteAfterDays', 'sessionRetentionAction',
|
|
24
|
+
'defaultModel', 'defaultVariant', 'smallModelUseDefault', 'smallModelOverride',
|
|
25
|
+
'walkthroughModelOverride', 'followUpBehavior', 'queueModeEnabled', 'gitmojiEnabled',
|
|
26
|
+
'defaultFileViewerPreview', 'zenModel', 'gitProviderId', 'gitModelId',
|
|
27
|
+
'inputSpellcheckEnabled', 'showToolFileIcons', 'codeBlockLineWrap', 'showTurnChangedFiles',
|
|
28
|
+
'showExpandedBashTools', 'showExpandedEditTools', 'timeFormatPreference',
|
|
29
|
+
'weekStartPreference', 'mermaidRenderingMode', 'userMessageRenderingMode',
|
|
30
|
+
'collapsibleUserMessages', 'stickyUserHeader', 'promptNavigatorEnabled',
|
|
31
|
+
'expandedEditorToolbar', 'wideChatLayoutEnabled', 'showSplitAssistantMessageActions',
|
|
32
|
+
'fontSize', 'terminalFontSize', 'editorFontSize', 'uiFont', 'monoFont', 'padding',
|
|
33
|
+
'cornerRadius', 'inputBarOffset', 'shortcutOverrides', 'commandTriggers',
|
|
34
|
+
'favoriteModels', 'hiddenModels', 'collapsedModelProviders', 'recentModels',
|
|
35
|
+
'recentAgents', 'recentEfforts', 'diffLayoutPreference', 'gitChangesViewMode',
|
|
36
|
+
'directoryShowHidden', 'filesViewShowGitignored', 'messageLimit',
|
|
37
|
+
'responseStyleEnabled', 'responseStylePreset', 'responseStyleCustomInstructions',
|
|
38
|
+
'draftStarters', 'draftStartersVisible', 'draftStartersScheduleTaskAdded',
|
|
39
|
+
'autoCreateWorktree', 'globalBehaviorPrompt', 'skillCatalogs', 'messageStreamTransport',
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
// These values describe one host or device. Secrets are local too, so they can
|
|
43
|
+
// still be consumed by the existing authenticated API without entering the
|
|
44
|
+
// portable file.
|
|
45
|
+
const LOCAL_FIELDS = new Set([
|
|
46
|
+
'lastDirectory', 'homeDirectory', 'projects', 'activeProjectId',
|
|
47
|
+
'securityScopedBookmarks', 'pinnedDirectories', 'defaultGitIdentityId', 'openInAppId',
|
|
48
|
+
'terminalShell', 'terminalLoginShells', 'desktopLanAccessEnabled',
|
|
49
|
+
'desktopKeepAwakeEnabled', 'desktopProcessPerformanceRecordingEnabled',
|
|
50
|
+
'desktopMinimizeToTrayEnabled', 'desktopMacMenuBarEnabled',
|
|
51
|
+
'desktopWindowControlsPosition', 'desktopWindowControlsStyle',
|
|
52
|
+
'desktopWindowState', 'desktopLocalPort', 'desktopInstallId', 'desktopHosts',
|
|
53
|
+
'desktopDefaultHostId', 'desktopInitialHostChoiceCompleted',
|
|
54
|
+
'pwaAppName', 'pwaOrientation', 'mobileKeyboardMode',
|
|
55
|
+
'tunnelProvider', 'tunnelMode', 'tunnelBootstrapTtlMs', 'tunnelSessionTtlMs',
|
|
56
|
+
'managedLocalTunnelConfigPath', 'managedRemoteTunnelHostname',
|
|
57
|
+
'managedRemoteTunnelPresets', 'managedRemoteTunnelSelectedPresetId',
|
|
58
|
+
'managedRemoteTunnelToken', 'managedRemoteTunnelPresetTokens',
|
|
59
|
+
'hasManagedRemoteTunnelToken', 'desktopUiPassword', 'desktopLocalClientToken',
|
|
60
|
+
]);
|
|
8
61
|
|
|
9
62
|
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
10
63
|
|
|
@@ -27,42 +80,95 @@ const validateRecord = (value) => {
|
|
|
27
80
|
return value;
|
|
28
81
|
};
|
|
29
82
|
|
|
83
|
+
const selectFields = (value, fields) => Object.fromEntries(
|
|
84
|
+
Object.entries(value).filter(([key]) => fields.has(key)),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const readRecord = async (file, fs) => {
|
|
88
|
+
try {
|
|
89
|
+
const raw = await fs.readFile(file, 'utf8');
|
|
90
|
+
if (Buffer.byteLength(raw) > MAX_SETTINGS_BYTES) throw new Error('UI_SETTINGS_INVALID');
|
|
91
|
+
return validateRecord(JSON.parse(raw));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (error?.code === 'ENOENT') return {};
|
|
94
|
+
if (error?.message === 'UI_SETTINGS_INVALID') throw error;
|
|
95
|
+
throw new Error('UI_SETTINGS_INVALID');
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const writeRecord = async (file, value, fs) => {
|
|
100
|
+
const serialized = `${JSON.stringify(value, null, 2)}\n`;
|
|
101
|
+
if (Buffer.byteLength(serialized) > MAX_SETTINGS_BYTES) throw new Error('UI_SETTINGS_INVALID');
|
|
102
|
+
const parent = dirname(file);
|
|
103
|
+
await fs.mkdir(parent, { recursive: true, mode: 0o700 });
|
|
104
|
+
const temporary = `${file}.tmp-${process.pid}-${randomUUID()}`;
|
|
105
|
+
await fs.writeFile(temporary, serialized, { encoding: 'utf8', mode: 0o600 });
|
|
106
|
+
await fs.rename(temporary, file);
|
|
107
|
+
if (process.platform !== 'win32') await fs.chmod(file, 0o600);
|
|
108
|
+
};
|
|
109
|
+
|
|
30
110
|
export const createPiUiSettingsStore = ({
|
|
31
111
|
file = join(resolvePiChamberDataDir(), 'settings.json'),
|
|
112
|
+
runtimeFile = join(dirname(file), 'runtime-state.json'),
|
|
32
113
|
fs = { chmod, mkdir, readFile, rename, writeFile },
|
|
33
114
|
} = {}) => {
|
|
34
115
|
let mutation = Promise.resolve();
|
|
35
116
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
117
|
+
const readLocked = async () => {
|
|
118
|
+
const portableRoot = await readRecord(file, fs);
|
|
119
|
+
const runtimeRoot = await readRecord(runtimeFile, fs);
|
|
120
|
+
const migrated = portableRoot[PORTABLE_SETTINGS_MARKER] === PORTABLE_SETTINGS_VERSION;
|
|
121
|
+
|
|
122
|
+
if (!migrated) {
|
|
123
|
+
const migratedRuntime = {
|
|
124
|
+
...selectFields(runtimeRoot, LOCAL_FIELDS),
|
|
125
|
+
...selectFields(portableRoot, LOCAL_FIELDS),
|
|
126
|
+
};
|
|
127
|
+
const migratedPortable = {
|
|
128
|
+
[PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
|
|
129
|
+
...selectFields(portableRoot, PORTABLE_FIELDS),
|
|
130
|
+
};
|
|
131
|
+
// Local state goes first. A failure cannot strand host state only in a
|
|
132
|
+
// portable file that a later successful write might replace.
|
|
133
|
+
await writeRecord(runtimeFile, migratedRuntime, fs);
|
|
134
|
+
await writeRecord(file, migratedPortable, fs);
|
|
135
|
+
return { ...selectFields(migratedPortable, PORTABLE_FIELDS), ...selectFields(migratedRuntime, LOCAL_FIELDS) };
|
|
45
136
|
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
...selectFields(portableRoot, PORTABLE_FIELDS),
|
|
140
|
+
...selectFields(runtimeRoot, LOCAL_FIELDS),
|
|
141
|
+
};
|
|
46
142
|
};
|
|
47
143
|
|
|
144
|
+
const runMutation = (operation) => {
|
|
145
|
+
const next = mutation.then(() => withCrossProcessLock(`${file}.lock`, operation));
|
|
146
|
+
mutation = next.catch(() => {});
|
|
147
|
+
return next;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const read = () => runMutation(readLocked);
|
|
151
|
+
|
|
48
152
|
const write = async (changes) => {
|
|
49
153
|
validateRecord(changes);
|
|
50
|
-
|
|
51
|
-
const current = await
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
154
|
+
return runMutation(async () => {
|
|
155
|
+
const current = await readLocked();
|
|
156
|
+
const portableChanges = selectFields(changes, PORTABLE_FIELDS);
|
|
157
|
+
const localChanges = selectFields(changes, LOCAL_FIELDS);
|
|
158
|
+
const nextPortable = {
|
|
159
|
+
[PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
|
|
160
|
+
...selectFields(current, PORTABLE_FIELDS),
|
|
161
|
+
...portableChanges,
|
|
162
|
+
};
|
|
163
|
+
const nextRuntime = {
|
|
164
|
+
...selectFields(current, LOCAL_FIELDS),
|
|
165
|
+
...localChanges,
|
|
166
|
+
};
|
|
167
|
+
await writeRecord(runtimeFile, nextRuntime, fs);
|
|
168
|
+
await writeRecord(file, nextPortable, fs);
|
|
169
|
+
return { ...selectFields(nextPortable, PORTABLE_FIELDS), ...selectFields(nextRuntime, LOCAL_FIELDS) };
|
|
62
170
|
});
|
|
63
|
-
mutation = operation.catch(() => {});
|
|
64
|
-
return operation;
|
|
65
171
|
};
|
|
66
172
|
|
|
67
|
-
return { file, read, write };
|
|
173
|
+
return { file, runtimeFile, read, write };
|
|
68
174
|
};
|
|
@@ -8,28 +8,79 @@ import { createPiUiSettingsStore } from './ui-settings-store.js';
|
|
|
8
8
|
const makeStore = async () => {
|
|
9
9
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-ui-settings-'));
|
|
10
10
|
const file = join(root, 'settings.json');
|
|
11
|
-
|
|
11
|
+
const runtimeFile = join(root, 'runtime-state.json');
|
|
12
|
+
return { file, runtimeFile, store: createPiUiSettingsStore({ file, runtimeFile }) };
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
const readJson = async (file) => JSON.parse(await readFile(file, 'utf8'));
|
|
16
|
+
|
|
14
17
|
describe('Pi UI settings store', () => {
|
|
15
|
-
it('distinguishes
|
|
18
|
+
it('distinguishes malformed persisted settings from a fresh store', async () => {
|
|
16
19
|
const { file, store } = await makeStore();
|
|
17
20
|
await expect(store.read()).resolves.toEqual({});
|
|
18
21
|
await writeFile(file, '{broken');
|
|
19
22
|
await expect(store.read()).rejects.toThrow('UI_SETTINGS_INVALID');
|
|
20
23
|
});
|
|
21
24
|
|
|
22
|
-
it('
|
|
23
|
-
const { file, store } = await makeStore();
|
|
25
|
+
it('migrates a flat settings file into portable and local allowlists', async () => {
|
|
26
|
+
const { file, runtimeFile, store } = await makeStore();
|
|
27
|
+
await writeFile(file, JSON.stringify({
|
|
28
|
+
themeId: 'nord',
|
|
29
|
+
homeDirectory: '/old-home',
|
|
30
|
+
projects: [{ id: 'old', path: '/old-home/project' }],
|
|
31
|
+
desktopUiPassword: 'secret',
|
|
32
|
+
unknownField: 'drop-me',
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
await expect(store.read()).resolves.toMatchObject({
|
|
36
|
+
themeId: 'nord',
|
|
37
|
+
homeDirectory: '/old-home',
|
|
38
|
+
projects: [{ id: 'old', path: '/old-home/project' }],
|
|
39
|
+
desktopUiPassword: 'secret',
|
|
40
|
+
});
|
|
41
|
+
await expect(readJson(file)).resolves.toEqual({
|
|
42
|
+
__pichamberSettingsScope: 'portable-v1',
|
|
43
|
+
themeId: 'nord',
|
|
44
|
+
});
|
|
45
|
+
await expect(readJson(runtimeFile)).resolves.toEqual({
|
|
46
|
+
homeDirectory: '/old-home',
|
|
47
|
+
projects: [{ id: 'old', path: '/old-home/project' }],
|
|
48
|
+
desktopUiPassword: 'secret',
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('does not apply local fields copied in from another home', async () => {
|
|
53
|
+
const source = await makeStore();
|
|
54
|
+
await source.store.write({ themeId: 'nord', homeDirectory: '/mnt/data', projects: [{ id: 'one', path: '/mnt/data/project' }] });
|
|
55
|
+
|
|
56
|
+
const target = await makeStore();
|
|
57
|
+
await target.store.write({ homeDirectory: '/root', projects: [{ id: 'two', path: '/root/project' }] });
|
|
58
|
+
await writeFile(target.file, await readFile(source.file));
|
|
59
|
+
|
|
60
|
+
await expect(target.store.read()).resolves.toEqual({
|
|
61
|
+
themeId: 'nord',
|
|
62
|
+
homeDirectory: '/root',
|
|
63
|
+
projects: [{ id: 'two', path: '/root/project' }],
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('serializes scoped merge writes without dropping unrelated fields', async () => {
|
|
68
|
+
const { file, runtimeFile, store } = await makeStore();
|
|
24
69
|
await Promise.all([
|
|
25
|
-
store.write({
|
|
70
|
+
store.write({ themeId: 'dark' }),
|
|
26
71
|
store.write({ projects: [{ id: 'one', path: '/one' }] }),
|
|
27
72
|
]);
|
|
28
73
|
await expect(store.read()).resolves.toEqual({
|
|
29
|
-
|
|
74
|
+
themeId: 'dark',
|
|
75
|
+
projects: [{ id: 'one', path: '/one' }],
|
|
76
|
+
});
|
|
77
|
+
await expect(readJson(file)).resolves.toEqual({
|
|
78
|
+
__pichamberSettingsScope: 'portable-v1',
|
|
79
|
+
themeId: 'dark',
|
|
80
|
+
});
|
|
81
|
+
await expect(readJson(runtimeFile)).resolves.toEqual({
|
|
30
82
|
projects: [{ id: 'one', path: '/one' }],
|
|
31
83
|
});
|
|
32
|
-
expect(JSON.parse(await readFile(file, 'utf8'))).toMatchObject({ themeMode: 'dark' });
|
|
33
84
|
});
|
|
34
85
|
|
|
35
86
|
it('rejects prototype-polluting keys', async () => {
|