@pi-chamber/web 0.3.3 → 0.5.0
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 +1 -0
- package/bin/lib/cli-startup.js +1 -0
- package/dist/assets/CommitSection-Cz-ACBaD.js +1 -0
- package/dist/assets/DiagramEditor-BNUOrd9m.js +1 -0
- package/dist/assets/DiagramView-D4YR9YRt.js +1 -0
- package/dist/assets/{DiffView-DGD9DMS7.js → DiffView-DPW8dcg_.js} +3 -3
- package/dist/assets/FilesView-BFGIdY6b.js +14 -0
- package/dist/assets/GitView-CKtiKOfJ.js +6 -0
- package/dist/assets/JsonTreeView-c-UJUw3D.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-V1HMFCjr.js → MarkdownRendererImpl-CvC9eXoa.js} +2 -2
- package/dist/assets/PatchDiff-YGHsZUIR.js +1 -0
- package/dist/assets/PierreDiffViewer-CoXa-JJK.js +136 -0
- package/dist/assets/SessionSwitcherContent-B7eep3dO.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-CZOFeJHH.js +2 -0
- package/dist/assets/SessionUnreadDot-ClpeYFPz.js +1 -0
- package/dist/assets/SettingsView-CPmHHDbQ.js +4 -0
- package/dist/assets/SettingsWindow-2CBpoJ8H.js +1 -0
- package/dist/assets/{ToolOutputDialog-2zKUdGYL.js → ToolOutputDialog-HMW-Kh19.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-C3nbNbxk.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-UMgLcO4Q.js → VirtualizedFileDiff-DEX83nQ0.js} +3 -3
- package/dist/assets/{SessionSwitcherDropdown-o1RjhCfF.js → WindowsWindowControls-PPk5H89-.js} +172 -118
- package/dist/assets/collapsible-Dux-9hAC.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-Cy0nxMJB.js +3 -0
- package/dist/assets/contextFileOpenGuard-Dn_38hd9.js +1 -0
- package/dist/assets/index--zDkVFU6.css +1 -0
- package/dist/assets/index-DU2OBBy5.js +8 -0
- package/dist/assets/index-EN7MioVf.js +1 -0
- package/dist/assets/isDiffPlainText-DSWRVq-W.js +1 -0
- package/dist/assets/isFilePlainText-7RAjjrQ5.js +1 -0
- package/dist/assets/{main-CmkRaMOR.js → main-BGKjg-qW.js} +8 -8
- package/dist/assets/main-DGHrBx_u.js +2 -0
- package/dist/assets/markdownCore-BYPqQtbE.js +3 -0
- package/dist/assets/miniChat-DW2PVX49.js +2 -0
- package/dist/assets/mobile-0Gxc02iO.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-C-qpqp1i.js +2 -0
- package/dist/assets/renderMobileApp-UB9bhC1x.js +14 -0
- package/dist/assets/{runtimeSurface-CkHYYg0E.js → runtimeSurface-DefD-2Iv.js} +1 -1
- package/dist/assets/{useInlineCommentController-DD31jQNC.js → useInlineCommentController-B8p2XwXA.js} +2 -2
- package/dist/assets/usePanelSlide-CbqVf-y8.js +56 -0
- package/dist/assets/usePushVisibilityBeacon-CvjN-47R.js +10 -0
- package/dist/assets/useSwitcherItems-B6_F-J-z.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-Dp_Z-0GD.js → vendor-codemirror-language-data-BhBdEPsJ.js} +2 -2
- package/dist/assets/{vendor-katex-CHD9BdDO.js → vendor-katex-CNckGUMB.js} +1 -1
- package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
- package/dist/assets/{web-components-Cct1r-wn.js → web-components-C9yVPsWN.js} +2 -2
- package/dist/index.html +8 -5
- package/dist/mini-chat.html +7 -4
- package/dist/mobile.html +7 -4
- package/dist/sw.js +1 -1
- package/package.json +1 -1
- package/server/index.js +27 -5
- package/server/lib/fs/routes.js +0 -21
- package/server/lib/git/DOCUMENTATION.md +15 -5
- package/server/lib/git/issue-2746-longpaths.test.js +11 -11
- package/server/lib/git/routes.js +80 -4
- package/server/lib/git/routes.test.js +135 -0
- package/server/lib/git/service.js +144 -82
- package/server/lib/git/service.test.js +182 -36
- package/server/lib/pi/extension-protocol.js +62 -0
- package/server/lib/pi/extension-protocol.test.js +34 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +251 -0
- package/server/lib/pi/routes-extension-events.test.js +152 -0
- package/server/lib/pi/routes.js +345 -7
- package/server/lib/pi/routes.test.js +43 -28
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +8 -5
- package/server/lib/pi/session-daemon/extension-bridge.js +488 -0
- package/server/lib/pi/session-daemon/message-entry-aliases.js +53 -13
- package/server/lib/pi/session-daemon/message-entry-aliases.test.js +110 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +215 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +559 -0
- package/server/lib/pi/session-daemon/session-daemon.js +483 -54
- package/server/lib/pi/session-daemon/session-daemon.test.js +212 -4
- package/server/lib/pi/session-daemon/session-retry-limits.js +55 -0
- package/server/lib/pi/session-daemon/session-retry-limits.test.js +53 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.js +39 -0
- package/server/lib/pi/session-daemon/skill-read-classifier.test.js +41 -0
- package/server/lib/pi/session-daemon/supervisor.js +3 -0
- package/server/lib/pi/small-model-generation.js +104 -0
- package/server/lib/pi/small-model-generation.test.js +66 -0
- package/server/lib/preview/proxy-runtime.js +11 -1
- package/server/lib/preview/proxy-runtime.test.js +3 -0
- package/server/lib/relay/tunnel-host.js +1 -0
- package/server/lib/server/cors.js +0 -2
- package/server/lib/server/cors.test.js +4 -4
- package/server/lib/stt/DOCUMENTATION.md +38 -0
- package/server/lib/stt/audio.js +47 -0
- package/server/lib/stt/config-store.js +81 -0
- package/server/lib/stt/config-store.test.js +36 -0
- package/server/lib/stt/local/model-catalog.js +57 -0
- package/server/lib/stt/local/model-downloader.js +127 -0
- package/server/lib/stt/local/recognizer.js +64 -0
- package/server/lib/stt/local/sherpa-loader.js +43 -0
- package/server/lib/stt/local/worker-client.js +115 -0
- package/server/lib/stt/local/worker-process.js +64 -0
- package/server/lib/stt/protocol.js +38 -0
- package/server/lib/stt/protocol.test.js +17 -0
- package/server/lib/stt/providers/local-worker-provider.js +11 -0
- package/server/lib/stt/providers/openai-compatible-provider.js +31 -0
- package/server/lib/stt/providers/openai-compatible-provider.test.js +31 -0
- package/server/lib/stt/runtime.js +111 -0
- package/server/lib/stt/service.js +106 -0
- package/server/lib/stt/stream-manager.js +188 -0
- package/server/lib/stt/stream-manager.test.js +64 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +1 -1
- package/server/lib/ui-auth/ui-auth.js +8 -3
- package/server/lib/ui-auth/ui-auth.test.js +8 -0
- package/server/lib/workspace/host.js +19 -3
- package/dist/assets/CommitSection-BAYzLtBf.js +0 -1
- package/dist/assets/DiagramEditor-D1yc4joK.js +0 -1
- package/dist/assets/DiagramView-CAlJiG11.js +0 -1
- package/dist/assets/FilesView-DB5VI7EN.js +0 -14
- package/dist/assets/GitView-CFlPcSn9.js +0 -6
- package/dist/assets/JsonTreeView-CoX1ZscV.js +0 -1
- package/dist/assets/PatchDiff-D6Gs7K5B.js +0 -1
- package/dist/assets/PierreDiffViewer-COYd5Qr-.js +0 -136
- package/dist/assets/SettingsView-BYqvfMTS.js +0 -4
- package/dist/assets/SettingsWindow-CtNS0tQn.js +0 -1
- package/dist/assets/ToolPartDiffPreview-CBFC9min.js +0 -8
- package/dist/assets/collapsible-Kx4bmsQM.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DdOCbMyK.js +0 -3
- package/dist/assets/contextFileOpenGuard-BRldMp0d.js +0 -1
- package/dist/assets/index-BAqpUCjs.js +0 -8
- package/dist/assets/index-CuSNEV7s.js +0 -1
- package/dist/assets/index-riABQmQ_.css +0 -1
- package/dist/assets/isDiffPlainText-CGIf0q8p.js +0 -1
- package/dist/assets/isFilePlainText-D4hgTRxT.js +0 -1
- package/dist/assets/main-By_pvk90.js +0 -2
- package/dist/assets/markdownCore-CAVCyFnI.js +0 -2
- package/dist/assets/miniChat-_XK2gGZE.js +0 -2
- package/dist/assets/mobile-B4E4JqAf.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-Ca4hZgIz.js +0 -1
- package/dist/assets/renderMobileApp-ClA5Cnmw.js +0 -14
- package/dist/assets/usePanelSlide-a4c67FIY.js +0 -56
- package/dist/assets/useWindowTitle-DoHrUC5r.js +0 -10
- package/server/lib/pi/legacy-ui-model-defaults.js +0 -57
- package/server/lib/pi/legacy-ui-model-defaults.test.js +0 -65
|
@@ -6,10 +6,12 @@ import { afterEach, describe, expect, it } from 'vitest';
|
|
|
6
6
|
import simpleGit from 'simple-git';
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
+
checkoutBranch,
|
|
9
10
|
checkoutCommit,
|
|
10
11
|
cherryPick,
|
|
11
12
|
createWorktree,
|
|
12
13
|
getWorktreeBootstrapStatus,
|
|
14
|
+
getWorktrees,
|
|
13
15
|
getBranches,
|
|
14
16
|
getRangeDiff,
|
|
15
17
|
getRemotes,
|
|
@@ -449,6 +451,36 @@ describe('worktree root resolution', () => {
|
|
|
449
451
|
await expect(resolveWorktreeTopLevel(subdirectory)).resolves.toEqual({ root: fs.realpathSync(repo) });
|
|
450
452
|
});
|
|
451
453
|
|
|
454
|
+
it('lists primary and linked worktrees from either checkout', async () => {
|
|
455
|
+
if (!canRunGit()) return;
|
|
456
|
+
|
|
457
|
+
const repo = createTempDir();
|
|
458
|
+
const worktree = createTempDir();
|
|
459
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
460
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
461
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
462
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
463
|
+
runGit(repo, ['add', 'README.md']);
|
|
464
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
465
|
+
fs.rmSync(worktree, { recursive: true, force: true });
|
|
466
|
+
runGit(repo, ['worktree', 'add', '-b', 'feature/test', worktree, 'HEAD']);
|
|
467
|
+
|
|
468
|
+
const listed = await getWorktrees(worktree);
|
|
469
|
+
expect(listed).toHaveLength(2);
|
|
470
|
+
expect(listed.find((entry) => entry.isPrimary)).toMatchObject({
|
|
471
|
+
path: fs.realpathSync(repo),
|
|
472
|
+
branch: 'main',
|
|
473
|
+
detached: false,
|
|
474
|
+
});
|
|
475
|
+
expect(listed.find((entry) => !entry.isPrimary)).toMatchObject({
|
|
476
|
+
path: fs.realpathSync(worktree),
|
|
477
|
+
branch: 'feature/test',
|
|
478
|
+
detached: false,
|
|
479
|
+
locked: false,
|
|
480
|
+
prunable: false,
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
|
|
452
484
|
it('resolves the primary worktree root from a linked worktree', async () => {
|
|
453
485
|
if (!canRunGit()) return;
|
|
454
486
|
|
|
@@ -485,11 +517,11 @@ describe('createWorktree', () => {
|
|
|
485
517
|
it('reports directory, Git, and setup bootstrap phases while preserving legacy status', async () => {
|
|
486
518
|
if (!canRunGit()) return;
|
|
487
519
|
|
|
488
|
-
const
|
|
520
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
489
521
|
const dataHome = createTempDir();
|
|
490
522
|
const setupMarker = path.join(dataHome, 'setup-started');
|
|
491
523
|
const setupScript = path.join(dataHome, 'setup-phase.cjs');
|
|
492
|
-
process.env.
|
|
524
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
493
525
|
|
|
494
526
|
fs.writeFileSync(
|
|
495
527
|
setupScript,
|
|
@@ -536,14 +568,55 @@ describe('createWorktree', () => {
|
|
|
536
568
|
error: null,
|
|
537
569
|
});
|
|
538
570
|
} finally {
|
|
539
|
-
if (
|
|
540
|
-
delete process.env.
|
|
571
|
+
if (previousPiChamberDataDir === undefined) {
|
|
572
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
541
573
|
} else {
|
|
542
|
-
process.env.
|
|
574
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
543
575
|
}
|
|
544
576
|
}
|
|
545
577
|
});
|
|
546
578
|
|
|
579
|
+
it('reports setup command failure after Git becomes ready', async () => {
|
|
580
|
+
if (!canRunGit()) return;
|
|
581
|
+
|
|
582
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
583
|
+
const dataHome = createTempDir();
|
|
584
|
+
const setupScript = path.join(dataHome, 'setup-failure.cjs');
|
|
585
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
586
|
+
fs.writeFileSync(setupScript, 'process.exitCode = 1;\n');
|
|
587
|
+
|
|
588
|
+
try {
|
|
589
|
+
const repo = createTempDir();
|
|
590
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
591
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
592
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
593
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
594
|
+
runGit(repo, ['add', 'README.md']);
|
|
595
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
596
|
+
|
|
597
|
+
const created = await createWorktree(repo, {
|
|
598
|
+
mode: 'new',
|
|
599
|
+
branchName: 'feature/setup-failure',
|
|
600
|
+
worktreeName: 'setup-failure',
|
|
601
|
+
returnAfterDirectoryCreated: true,
|
|
602
|
+
startCommand: `${JSON.stringify(process.execPath)} ${JSON.stringify(setupScript)}`,
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
await expect.poll(
|
|
606
|
+
async () => (await getWorktreeBootstrapStatus(created.path)).status,
|
|
607
|
+
{ timeout: 5_000 },
|
|
608
|
+
).toBe('failed');
|
|
609
|
+
await expect(getWorktreeBootstrapStatus(created.path)).resolves.toMatchObject({
|
|
610
|
+
status: 'failed',
|
|
611
|
+
phase: 'git-ready',
|
|
612
|
+
error: 'Worktree setup command failed',
|
|
613
|
+
});
|
|
614
|
+
} finally {
|
|
615
|
+
if (previousPiChamberDataDir === undefined) delete process.env.PICHAMBER_DATA_DIR;
|
|
616
|
+
else process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
|
|
547
620
|
const installPostCheckoutHook = (repo, script, executable = true) => {
|
|
548
621
|
const hookPath = path.join(repo, '.git', 'hooks', 'post-checkout');
|
|
549
622
|
fs.writeFileSync(hookPath, script);
|
|
@@ -556,9 +629,9 @@ describe('createWorktree', () => {
|
|
|
556
629
|
it('runs the post-checkout hook after populating a created worktree', async () => {
|
|
557
630
|
if (!canRunGit()) return;
|
|
558
631
|
|
|
559
|
-
const
|
|
632
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
560
633
|
const dataHome = createTempDir();
|
|
561
|
-
process.env.
|
|
634
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
562
635
|
|
|
563
636
|
try {
|
|
564
637
|
const repo = createTempDir();
|
|
@@ -597,10 +670,10 @@ describe('createWorktree', () => {
|
|
|
597
670
|
expect(flag).toBe('1');
|
|
598
671
|
expect(cwd).toBe(fs.realpathSync(created.path));
|
|
599
672
|
} finally {
|
|
600
|
-
if (
|
|
601
|
-
delete process.env.
|
|
673
|
+
if (previousPiChamberDataDir === undefined) {
|
|
674
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
602
675
|
} else {
|
|
603
|
-
process.env.
|
|
676
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
604
677
|
}
|
|
605
678
|
}
|
|
606
679
|
});
|
|
@@ -608,9 +681,9 @@ describe('createWorktree', () => {
|
|
|
608
681
|
it('skips a non-executable post-checkout hook', async () => {
|
|
609
682
|
if (!canRunGit()) return;
|
|
610
683
|
|
|
611
|
-
const
|
|
684
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
612
685
|
const dataHome = createTempDir();
|
|
613
|
-
process.env.
|
|
686
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
614
687
|
|
|
615
688
|
try {
|
|
616
689
|
const repo = createTempDir();
|
|
@@ -641,10 +714,10 @@ describe('createWorktree', () => {
|
|
|
641
714
|
).toBe('ready');
|
|
642
715
|
expect(fs.existsSync(hookLog)).toBe(false);
|
|
643
716
|
} finally {
|
|
644
|
-
if (
|
|
645
|
-
delete process.env.
|
|
717
|
+
if (previousPiChamberDataDir === undefined) {
|
|
718
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
646
719
|
} else {
|
|
647
|
-
process.env.
|
|
720
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
648
721
|
}
|
|
649
722
|
}
|
|
650
723
|
});
|
|
@@ -652,9 +725,9 @@ describe('createWorktree', () => {
|
|
|
652
725
|
it('does not fail worktree bootstrap when the post-checkout hook fails', async () => {
|
|
653
726
|
if (!canRunGit()) return;
|
|
654
727
|
|
|
655
|
-
const
|
|
728
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
656
729
|
const dataHome = createTempDir();
|
|
657
|
-
process.env.
|
|
730
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
658
731
|
|
|
659
732
|
try {
|
|
660
733
|
const repo = createTempDir();
|
|
@@ -684,10 +757,10 @@ describe('createWorktree', () => {
|
|
|
684
757
|
).toBe('ready');
|
|
685
758
|
expect(fs.readFileSync(hookLog, 'utf8')).toBe('ran');
|
|
686
759
|
} finally {
|
|
687
|
-
if (
|
|
688
|
-
delete process.env.
|
|
760
|
+
if (previousPiChamberDataDir === undefined) {
|
|
761
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
689
762
|
} else {
|
|
690
|
-
process.env.
|
|
763
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
691
764
|
}
|
|
692
765
|
}
|
|
693
766
|
});
|
|
@@ -695,12 +768,12 @@ describe('createWorktree', () => {
|
|
|
695
768
|
it('waits for active bootstrap work before removing a worktree', async () => {
|
|
696
769
|
if (!canRunGit()) return;
|
|
697
770
|
|
|
698
|
-
const
|
|
771
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
699
772
|
const dataHome = createTempDir();
|
|
700
773
|
const setupStarted = path.join(dataHome, 'remove-race-started');
|
|
701
774
|
const setupCompleted = path.join(dataHome, 'remove-race-completed');
|
|
702
775
|
const setupScript = path.join(dataHome, 'remove-race.cjs');
|
|
703
|
-
process.env.
|
|
776
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
704
777
|
|
|
705
778
|
fs.writeFileSync(
|
|
706
779
|
setupScript,
|
|
@@ -741,10 +814,10 @@ describe('createWorktree', () => {
|
|
|
741
814
|
phase: 'setup-ready',
|
|
742
815
|
});
|
|
743
816
|
} finally {
|
|
744
|
-
if (
|
|
745
|
-
delete process.env.
|
|
817
|
+
if (previousPiChamberDataDir === undefined) {
|
|
818
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
746
819
|
} else {
|
|
747
|
-
process.env.
|
|
820
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
748
821
|
}
|
|
749
822
|
}
|
|
750
823
|
});
|
|
@@ -774,9 +847,9 @@ describe('createWorktree', () => {
|
|
|
774
847
|
it('preflights fast create branch-in-use failures before creating the candidate directory', async () => {
|
|
775
848
|
if (!canRunGit()) return;
|
|
776
849
|
|
|
777
|
-
const
|
|
850
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
778
851
|
const dataHome = createTempDir();
|
|
779
|
-
process.env.
|
|
852
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
780
853
|
|
|
781
854
|
try {
|
|
782
855
|
const repo = createTempDir();
|
|
@@ -801,13 +874,13 @@ describe('createWorktree', () => {
|
|
|
801
874
|
returnAfterDirectoryCreated: true,
|
|
802
875
|
})).rejects.toThrow(`Branch is already checked out in ${canonicalWorktree}`);
|
|
803
876
|
|
|
804
|
-
const candidateDirectory = path.join(dataHome, '
|
|
877
|
+
const candidateDirectory = path.join(dataHome, 'pi', 'worktree', projectID, 'feature-in-use');
|
|
805
878
|
expect(fs.existsSync(candidateDirectory)).toBe(false);
|
|
806
879
|
} finally {
|
|
807
|
-
if (
|
|
808
|
-
delete process.env.
|
|
880
|
+
if (previousPiChamberDataDir === undefined) {
|
|
881
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
809
882
|
} else {
|
|
810
|
-
process.env.
|
|
883
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
811
884
|
}
|
|
812
885
|
}
|
|
813
886
|
});
|
|
@@ -821,9 +894,9 @@ describe('removeWorktree', () => {
|
|
|
821
894
|
it('forgets unmanaged orphan worktree entries without deleting files', async () => {
|
|
822
895
|
if (!canRunGit()) return;
|
|
823
896
|
|
|
824
|
-
const
|
|
897
|
+
const previousPiChamberDataDir = process.env.PICHAMBER_DATA_DIR;
|
|
825
898
|
const dataHome = createTempDir();
|
|
826
|
-
process.env.
|
|
899
|
+
process.env.PICHAMBER_DATA_DIR = dataHome;
|
|
827
900
|
|
|
828
901
|
try {
|
|
829
902
|
const repo = createTempDir();
|
|
@@ -844,10 +917,10 @@ describe('removeWorktree', () => {
|
|
|
844
917
|
})).resolves.toBe(true);
|
|
845
918
|
expect(fs.existsSync(canary)).toBe(true);
|
|
846
919
|
} finally {
|
|
847
|
-
if (
|
|
848
|
-
delete process.env.
|
|
920
|
+
if (previousPiChamberDataDir === undefined) {
|
|
921
|
+
delete process.env.PICHAMBER_DATA_DIR;
|
|
849
922
|
} else {
|
|
850
|
-
process.env.
|
|
923
|
+
process.env.PICHAMBER_DATA_DIR = previousPiChamberDataDir;
|
|
851
924
|
}
|
|
852
925
|
}
|
|
853
926
|
});
|
|
@@ -1168,6 +1241,79 @@ describe('hash validation', () => {
|
|
|
1168
1241
|
});
|
|
1169
1242
|
});
|
|
1170
1243
|
|
|
1244
|
+
describe.runIf(canRunGit())('checkoutBranch', () => {
|
|
1245
|
+
const createBranchRepository = async () => {
|
|
1246
|
+
const { tmpDir, git } = await createTempRepo();
|
|
1247
|
+
fs.writeFileSync(path.join(tmpDir, 'tracked.txt'), 'main\n');
|
|
1248
|
+
await git.add('tracked.txt');
|
|
1249
|
+
await git.commit('main');
|
|
1250
|
+
await git.checkoutLocalBranch('feature');
|
|
1251
|
+
fs.writeFileSync(path.join(tmpDir, 'tracked.txt'), 'feature\n');
|
|
1252
|
+
await git.add('tracked.txt');
|
|
1253
|
+
await git.commit('feature');
|
|
1254
|
+
await git.checkout('main');
|
|
1255
|
+
return { repository: tmpDir, git };
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
it('conditionally checks out an exact local branch and returns the observed branches', async () => {
|
|
1259
|
+
const { repository } = await createBranchRepository();
|
|
1260
|
+
|
|
1261
|
+
await expect(checkoutBranch(repository, 'feature', {
|
|
1262
|
+
expectedCurrent: 'main',
|
|
1263
|
+
localOnly: true,
|
|
1264
|
+
})).resolves.toMatchObject({
|
|
1265
|
+
success: true,
|
|
1266
|
+
branch: 'feature',
|
|
1267
|
+
previousBranch: 'main',
|
|
1268
|
+
currentBranch: 'feature',
|
|
1269
|
+
});
|
|
1270
|
+
expect(runGit(repository, ['branch', '--show-current']).trim()).toBe('feature');
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
it('rejects a stale expected branch without changing the worktree', async () => {
|
|
1274
|
+
const { repository } = await createBranchRepository();
|
|
1275
|
+
|
|
1276
|
+
await expect(checkoutBranch(repository, 'feature', {
|
|
1277
|
+
expectedCurrent: 'release',
|
|
1278
|
+
localOnly: true,
|
|
1279
|
+
})).rejects.toMatchObject({
|
|
1280
|
+
code: 'BRANCH_CHANGED',
|
|
1281
|
+
statusCode: 409,
|
|
1282
|
+
currentBranch: 'main',
|
|
1283
|
+
});
|
|
1284
|
+
expect(runGit(repository, ['branch', '--show-current']).trim()).toBe('main');
|
|
1285
|
+
});
|
|
1286
|
+
|
|
1287
|
+
it('rejects a missing local branch before checkout', async () => {
|
|
1288
|
+
const { repository } = await createBranchRepository();
|
|
1289
|
+
|
|
1290
|
+
await expect(checkoutBranch(repository, 'origin/feature', {
|
|
1291
|
+
expectedCurrent: 'main',
|
|
1292
|
+
localOnly: true,
|
|
1293
|
+
})).rejects.toMatchObject({
|
|
1294
|
+
code: 'BRANCH_NOT_FOUND',
|
|
1295
|
+
statusCode: 409,
|
|
1296
|
+
currentBranch: 'main',
|
|
1297
|
+
});
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
it('preserves the current branch when local changes conflict with checkout', async () => {
|
|
1301
|
+
const { repository } = await createBranchRepository();
|
|
1302
|
+
fs.writeFileSync(path.join(repository, 'tracked.txt'), 'uncommitted main change\n');
|
|
1303
|
+
|
|
1304
|
+
await expect(checkoutBranch(repository, 'feature', {
|
|
1305
|
+
expectedCurrent: 'main',
|
|
1306
|
+
localOnly: true,
|
|
1307
|
+
})).rejects.toMatchObject({
|
|
1308
|
+
code: 'CHECKOUT_FAILED',
|
|
1309
|
+
statusCode: 409,
|
|
1310
|
+
currentBranch: 'main',
|
|
1311
|
+
});
|
|
1312
|
+
expect(runGit(repository, ['branch', '--show-current']).trim()).toBe('main');
|
|
1313
|
+
expect(fs.readFileSync(path.join(repository, 'tracked.txt'), 'utf8')).toBe('uncommitted main change\n');
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
|
|
1171
1317
|
describe.runIf(canRunGit())('getBranches', () => {
|
|
1172
1318
|
it('returns a remote default branch whose name is not a conventional fallback', async () => {
|
|
1173
1319
|
const { repository } = createRepositoryWithRemote({ remoteName: 'origin', defaultBranch: 'react' });
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export const MAX_EXTENSION_APP_HTML_CHARS = 200_000;
|
|
2
|
+
const MAX_EXTENSION_FORM_FIELDS = 12;
|
|
3
|
+
const MAX_EXTENSION_FORM_OPTIONS = 20;
|
|
4
|
+
|
|
5
|
+
const FORM_FIELD_TYPES = new Set(['text', 'textarea', 'number', 'select', 'checkbox']);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Normalize extension-authored form descriptors at both sides of the private
|
|
9
|
+
* daemon IPC seam. Keeping this in one module prevents the daemon bridge and
|
|
10
|
+
* public route projection from accepting different field shapes.
|
|
11
|
+
*/
|
|
12
|
+
export const sanitizeExtensionFormFields = (fields) => {
|
|
13
|
+
if (!Array.isArray(fields)) return [];
|
|
14
|
+
return fields.slice(0, MAX_EXTENSION_FORM_FIELDS).flatMap((field) => {
|
|
15
|
+
if (!field || typeof field !== 'object') return [];
|
|
16
|
+
const id = typeof field.id === 'string' ? field.id.slice(0, 128) : '';
|
|
17
|
+
const label = typeof field.label === 'string' ? field.label.slice(0, 256) : '';
|
|
18
|
+
if (!id || !label) return [];
|
|
19
|
+
return [{
|
|
20
|
+
id,
|
|
21
|
+
label,
|
|
22
|
+
type: FORM_FIELD_TYPES.has(field.type) ? field.type : 'text',
|
|
23
|
+
...(field.required === true ? { required: true } : {}),
|
|
24
|
+
...(typeof field.placeholder === 'string' ? { placeholder: field.placeholder.slice(0, 256) } : {}),
|
|
25
|
+
...(Array.isArray(field.options)
|
|
26
|
+
? {
|
|
27
|
+
options: field.options
|
|
28
|
+
.filter((option) => typeof option === 'string')
|
|
29
|
+
.map((option) => option.slice(0, 256))
|
|
30
|
+
.slice(0, MAX_EXTENSION_FORM_OPTIONS),
|
|
31
|
+
}
|
|
32
|
+
: {}),
|
|
33
|
+
...(typeof field.initial === 'string' ? { initial: field.initial.slice(0, 2_000) } : {}),
|
|
34
|
+
...(Number.isFinite(field.min) ? { min: field.min } : {}),
|
|
35
|
+
...(Number.isFinite(field.max) ? { max: field.max } : {}),
|
|
36
|
+
}];
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Validate a form answer against the exact descriptor sent to the client. */
|
|
41
|
+
export const validateExtensionFormValues = (fields, values) => {
|
|
42
|
+
if (!Array.isArray(fields) || !values || typeof values !== 'object' || Array.isArray(values)) return false;
|
|
43
|
+
const fieldsById = new Map(fields.map((field) => [field.id, field]));
|
|
44
|
+
for (const key of Object.keys(values)) if (!fieldsById.has(key)) return false;
|
|
45
|
+
for (const field of fields) {
|
|
46
|
+
const value = values[field.id];
|
|
47
|
+
if (field.required === true && (typeof value !== 'string' || value.length === 0)) return false;
|
|
48
|
+
if (value === undefined || value.length === 0) continue;
|
|
49
|
+
if (typeof value !== 'string') return false;
|
|
50
|
+
if (field.type === 'number') {
|
|
51
|
+
const number = Number(value);
|
|
52
|
+
if (!Number.isFinite(number)) return false;
|
|
53
|
+
if (typeof field.min === 'number' && number < field.min) return false;
|
|
54
|
+
if (typeof field.max === 'number' && number > field.max) return false;
|
|
55
|
+
} else if (field.type === 'select' && !field.options?.includes(value)) {
|
|
56
|
+
return false;
|
|
57
|
+
} else if (field.type === 'checkbox' && value !== 'true' && value !== 'false') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { sanitizeExtensionFormFields, validateExtensionFormValues } from './extension-protocol.js';
|
|
4
|
+
|
|
5
|
+
describe('extension form protocol', () => {
|
|
6
|
+
it('uses one bounded field projection for daemon and public routes', () => {
|
|
7
|
+
const fields = sanitizeExtensionFormFields([
|
|
8
|
+
{ id: 'name', label: 'Name', type: 'text', required: true, placeholder: 'x'.repeat(300) },
|
|
9
|
+
{ id: 'mode', label: 'Mode', type: 'select', options: ['fast', 'safe'] },
|
|
10
|
+
{ id: 'count', label: 'Count', type: 'number', min: 1, max: 3 },
|
|
11
|
+
{ id: '', label: 'Invalid' },
|
|
12
|
+
]);
|
|
13
|
+
expect(fields).toHaveLength(3);
|
|
14
|
+
expect(fields[0].placeholder).toHaveLength(256);
|
|
15
|
+
expect(fields[1].options).toEqual(['fast', 'safe']);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('rejects unknown, malformed, and out-of-range answers', () => {
|
|
19
|
+
const fields = sanitizeExtensionFormFields([
|
|
20
|
+
{ id: 'name', label: 'Name', type: 'text', required: true },
|
|
21
|
+
{ id: 'mode', label: 'Mode', type: 'select', options: ['fast', 'safe'] },
|
|
22
|
+
{ id: 'count', label: 'Count', type: 'number', min: 1, max: 3 },
|
|
23
|
+
{ id: 'enabled', label: 'Enabled', type: 'checkbox' },
|
|
24
|
+
]);
|
|
25
|
+
expect(validateExtensionFormValues(fields, {
|
|
26
|
+
name: 'worker', mode: 'safe', count: '2', enabled: 'true',
|
|
27
|
+
})).toBe(true);
|
|
28
|
+
expect(validateExtensionFormValues(fields, { name: 'worker', unknown: 'x' })).toBe(false);
|
|
29
|
+
expect(validateExtensionFormValues(fields, { name: '', mode: 'safe' })).toBe(false);
|
|
30
|
+
expect(validateExtensionFormValues(fields, { name: 'worker', mode: 'turbo' })).toBe(false);
|
|
31
|
+
expect(validateExtensionFormValues(fields, { name: 'worker', count: '4' })).toBe(false);
|
|
32
|
+
expect(validateExtensionFormValues(fields, { name: 'worker', enabled: 'yes' })).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
});
|