@firstpick/pi-package-webui 0.11.1 → 0.11.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/DEVELOPMENT.md +151 -12
- package/README.md +34 -6
- package/TECHNICAL.md +75 -8
- package/bin/pi-webui.mjs +5390 -11423
- package/index.ts +10 -3
- package/lib/component-update-state.mjs +2 -2
- package/lib/git-workflow-preference-values.mjs +122 -0
- package/lib/git-workflow-preferences.mjs +35 -563
- package/lib/package-updates.mjs +260 -0
- package/lib/rpc-supervisor-client.mjs +8 -4
- package/lib/server/app-runners.mjs +1667 -0
- package/lib/server/codex-fast-mode.mjs +161 -0
- package/lib/server/conversation-mode.mjs +218 -0
- package/lib/server/conversation-voice.mjs +318 -0
- package/lib/server/extension-ui-requests.mjs +114 -0
- package/lib/server/git-generation.mjs +459 -0
- package/lib/server/git-mutations.mjs +1827 -0
- package/lib/server/git-reads.mjs +608 -0
- package/lib/server/git-worktree-sessions.mjs +408 -0
- package/lib/server/helper-requests.mjs +82 -0
- package/lib/server/no-project-workspaces.mjs +103 -0
- package/lib/server/rpc-transports.mjs +394 -0
- package/lib/server/settings-store.mjs +544 -0
- package/lib/server/sse-delivery.mjs +138 -0
- package/lib/server/workspace-files.mjs +563 -0
- package/lib/update/supervisor.mjs +4 -0
- package/lib/webui-workspaces.mjs +2 -0
- package/package.json +4 -4
- package/public/activity-agents-controller.mjs +269 -0
- package/public/activity-events-controller.mjs +236 -0
- package/public/activity-intercom-controller.mjs +627 -0
- package/public/activity-queue-controller.mjs +534 -0
- package/public/activity-todo-view.mjs +89 -0
- package/public/activity-usage-controller.mjs +589 -0
- package/public/app.js +3761 -3886
- package/public/conversation-overview.css +84 -0
- package/public/conversation-overview.mjs +193 -0
- package/public/draft-conversations.mjs +135 -0
- package/public/focused-composer-controls.css +111 -0
- package/public/focused-composer-controls.mjs +143 -0
- package/public/focused-composer-disclosure.mjs +223 -0
- package/public/focused-shell-adapter.css +264 -0
- package/public/focused-shell-adapter.mjs +257 -0
- package/public/index.html +137 -80
- package/public/model-catalog-order.mjs +63 -0
- package/public/platform-event-stream.mjs +64 -0
- package/public/project-artifact-controller.mjs +218 -0
- package/public/project-file-viewer-controller.mjs +383 -0
- package/public/project-git-tools-controller.mjs +181 -0
- package/public/project-runners-controller.mjs +220 -0
- package/public/service-worker.js +52 -1
- package/public/session-attention-scheduler.mjs +182 -0
- package/public/session-composer-store.mjs +56 -0
- package/public/session-context.mjs +51 -0
- package/public/session-extension-requests.mjs +63 -0
- package/public/session-shelf-state.mjs +151 -0
- package/public/session-shelves.css +171 -0
- package/public/session-shelves.mjs +95 -0
- package/public/settings-navigation-controller.mjs +249 -0
- package/public/settings-navigation.css +61 -0
- package/public/settings-resource-controller.mjs +232 -0
- package/public/settings-workspace.css +19 -0
- package/public/settings-workspace.mjs +175 -0
- package/public/shell-actions.mjs +87 -0
- package/public/shell-attention-inbox.css +72 -0
- package/public/shell-attention-inbox.mjs +198 -0
- package/public/shell-context-actions.css +61 -0
- package/public/shell-context-actions.mjs +168 -0
- package/public/shell-inspector-resize.mjs +124 -0
- package/public/shell-navigation-resize.mjs +107 -0
- package/public/shell-navigation.mjs +127 -0
- package/public/shell-preferences.mjs +108 -0
- package/public/shell-surfaces.mjs +99 -0
- package/public/shell-tools-launcher.css +97 -0
- package/public/shell-tools-launcher.mjs +222 -0
- package/public/shell-view-host.mjs +115 -0
- package/public/shell-workspace.css +266 -0
- package/public/shell-workspace.mjs +402 -0
- package/public/sidebar-update-menu.css +190 -0
- package/public/sidebar-update-menu.mjs +512 -0
- package/public/styles.css +322 -169
- package/public/subagent-launch-slot-state.mjs +2 -2
- package/public/themed-selects.css +156 -0
- package/public/workspace-choices.mjs +104 -0
- package/tests/activity-agents-controller.test.mjs +652 -0
- package/tests/activity-events-controller.test.mjs +511 -0
- package/tests/app-runner-terminal-static.test.mjs +3 -3
- package/tests/append-system-http.test.mjs +7 -6
- package/tests/append-system-selector-static.test.mjs +6 -6
- package/tests/aur-review-widget-static.test.mjs +11 -3
- package/tests/boot-failure-diagnostics.test.mjs +8 -3
- package/tests/browser/action-feedback-gutter.spec.mjs +251 -0
- package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
- package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
- package/tests/browser/activity-owner-integration.spec.mjs +201 -0
- package/tests/browser/activity-queue-controller.spec.mjs +405 -0
- package/tests/browser/activity-section-picker.spec.mjs +294 -0
- package/tests/browser/activity-todo-view.spec.mjs +60 -0
- package/tests/browser/activity-usage-controller.spec.mjs +416 -0
- package/tests/browser/compact-layout-integration.spec.mjs +58 -0
- package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
- package/tests/browser/composer-disclosure.spec.mjs +389 -0
- package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
- package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
- package/tests/browser/control-visibility.spec.mjs +5 -0
- package/tests/browser/controls-layout.spec.mjs +21 -2
- package/tests/browser/conversation-overview.spec.mjs +251 -0
- package/tests/browser/draft-conversations.spec.mjs +276 -0
- package/tests/browser/empty-startup-fixture.mjs +135 -0
- package/tests/browser/empty-startup.spec.mjs +282 -0
- package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
- package/tests/browser/focused-composer-more.spec.mjs +127 -0
- package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
- package/tests/browser/focused-navigation-fixture.mjs +32 -0
- package/tests/browser/focused-project-activity.spec.mjs +111 -0
- package/tests/browser/focused-shell-integration.spec.mjs +208 -0
- package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
- package/tests/browser/folder-picker-layout.spec.mjs +302 -0
- package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
- package/tests/browser/git-setup-cancel.spec.mjs +251 -0
- package/tests/browser/guided-git-fallback.spec.mjs +40 -21
- package/tests/browser/inspector-header.spec.mjs +221 -0
- package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
- package/tests/browser/inspector-resize.spec.mjs +227 -0
- package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
- package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
- package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
- package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
- package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
- package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
- package/tests/browser/interaction-continuity.spec.mjs +50 -26
- package/tests/browser/interaction-model-picker.spec.mjs +86 -0
- package/tests/browser/last-terminal-close.spec.mjs +280 -0
- package/tests/browser/mobile-foundation.spec.mjs +172 -20
- package/tests/browser/model-catalog-groups.spec.mjs +104 -0
- package/tests/browser/more-row-menus.spec.mjs +258 -0
- package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
- package/tests/browser/no-project-conversation.spec.mjs +113 -0
- package/tests/browser/optimistic-prompt.spec.mjs +3 -0
- package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
- package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
- package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
- package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
- package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
- package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
- package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
- package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
- package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
- package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
- package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
- package/tests/browser/project-artifact-controller.spec.mjs +324 -0
- package/tests/browser/project-artifact-integration.spec.mjs +103 -0
- package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
- package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
- package/tests/browser/session-fixture.mjs +118 -0
- package/tests/browser/session-ownership.spec.mjs +175 -0
- package/tests/browser/session-shelves-integration.spec.mjs +219 -0
- package/tests/browser/session-shelves.spec.mjs +340 -0
- package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
- package/tests/browser/session-summary.spec.mjs +17 -12
- package/tests/browser/settings-complete-home.spec.mjs +463 -0
- package/tests/browser/settings-entrypoint.spec.mjs +104 -0
- package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
- package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
- package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
- package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
- package/tests/browser/shell-ownership.spec.mjs +398 -0
- package/tests/browser/shell-rollout-fixture.mjs +259 -0
- package/tests/browser/shell-rollout.spec.mjs +357 -0
- package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
- package/tests/browser/shell-workspace.spec.mjs +433 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
- package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
- package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
- package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
- package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
- package/tests/browser/stream-output-isolation.spec.mjs +6 -3
- package/tests/browser/themed-selects.spec.mjs +297 -0
- package/tests/browser/thread-start-flow.spec.mjs +481 -0
- package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
- package/tests/browser/ui-polish-features.spec.mjs +85 -0
- package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
- package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
- package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
- package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
- package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
- package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
- package/tests/browser/windows-drive-parent.spec.mjs +4 -2
- package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
- package/tests/codex-fast-mode-static.test.mjs +16 -11
- package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
- package/tests/codex-usage-source.test.mjs +4 -3
- package/tests/component-update-api-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +9 -4
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +5 -5
- package/tests/conversation-overview-adapter.test.mjs +100 -0
- package/tests/document-artifact-static.test.mjs +2 -1
- package/tests/draft-conversations.test.mjs +205 -0
- package/tests/empty-startup-launcher.test.mjs +197 -0
- package/tests/events-tree-context-menu-static.test.mjs +22 -18
- package/tests/fake-pi-session-ownership.test.mjs +302 -0
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
- package/tests/file-viewer-image-static.test.mjs +15 -11
- package/tests/file-viewer-search-static.test.mjs +5 -5
- package/tests/fixtures/fake-pi.mjs +41 -9
- package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
- package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
- package/tests/git-footer-context-menu-static.test.mjs +1 -1
- package/tests/git-panel-file-preview-static.test.mjs +41 -48
- package/tests/git-panel-live-updates-static.test.mjs +2 -1
- package/tests/git-workflow-dispatch.test.mjs +66 -0
- package/tests/git-workflow-preferences.test.mjs +9 -1
- package/tests/guided-git-activation-static.test.mjs +14 -11
- package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
- package/tests/guided-git-message-reliability-static.test.mjs +10 -6
- package/tests/guided-git-publication-backend-static.test.mjs +16 -11
- package/tests/http-endpoints-harness.test.mjs +21 -9
- package/tests/interaction-state-stability-static.test.mjs +4 -3
- package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
- package/tests/intercom-tag-layout-static.test.mjs +13 -12
- package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
- package/tests/main-output-loading-static.test.mjs +4 -4
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-compact-layout.test.mjs +2 -2
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +10 -7
- package/tests/mobile-phone-experience-static.test.mjs +3 -2
- package/tests/mobile-static.test.mjs +173 -135
- package/tests/model-catalog-order.test.mjs +103 -0
- package/tests/native-parity.test.mjs +6 -4
- package/tests/native-session-choice-owner.test.mjs +102 -0
- package/tests/native-update-lifecycle.test.mjs +10 -5
- package/tests/no-project-http-harness.test.mjs +328 -0
- package/tests/no-project-navigation.test.mjs +54 -0
- package/tests/no-project-workspaces.test.mjs +77 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-migration-frontend.test.mjs +4 -4
- package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
- package/tests/package-updates.test.mjs +630 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/platform-event-stream.test.mjs +253 -0
- package/tests/project-file-viewer-controller.test.mjs +652 -0
- package/tests/project-git-tools-adapter.test.mjs +103 -0
- package/tests/project-git-tools-controller.test.mjs +577 -0
- package/tests/project-runners-controller.test.mjs +453 -0
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
- package/tests/questionnaire-dialog.test.mjs +6 -6
- package/tests/queue-edit-reorder-static.test.mjs +48 -51
- package/tests/rpc-supervisor-host.test.mjs +4 -1
- package/tests/safety-guard-auto-review-static.test.mjs +1 -1
- package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
- package/tests/server-app-runners.test.mjs +536 -0
- package/tests/server-codex-fast-mode.test.mjs +346 -0
- package/tests/server-conversation-mode.test.mjs +386 -0
- package/tests/server-conversation-voice.test.mjs +426 -0
- package/tests/server-extension-ui-requests.test.mjs +357 -0
- package/tests/server-git-generation.test.mjs +558 -0
- package/tests/server-git-mutations.test.mjs +729 -0
- package/tests/server-git-reads.test.mjs +381 -0
- package/tests/server-git-worktree-sessions.test.mjs +502 -0
- package/tests/server-helper-requests.test.mjs +364 -0
- package/tests/server-rpc-transports.test.mjs +553 -0
- package/tests/server-settings-store.test.mjs +132 -0
- package/tests/server-shell-rollout.test.mjs +478 -0
- package/tests/server-sse-delivery.test.mjs +410 -0
- package/tests/server-workspace-files.test.mjs +546 -0
- package/tests/session-attention-scheduler.test.mjs +514 -0
- package/tests/session-composer-store.test.mjs +153 -0
- package/tests/session-context.test.mjs +134 -0
- package/tests/session-extension-requests.test.mjs +193 -0
- package/tests/session-ownership-adapter.test.mjs +130 -0
- package/tests/session-sampling-ui-static.test.mjs +10 -4
- package/tests/session-send-lifetime.test.mjs +140 -0
- package/tests/session-shelf-state.test.mjs +348 -0
- package/tests/session-shelves-adapter.test.mjs +79 -0
- package/tests/session-summary-lifetime.test.mjs +54 -0
- package/tests/settings-resource-controller.test.mjs +548 -0
- package/tests/shell-action-adapter.test.mjs +169 -0
- package/tests/shell-actions.test.mjs +182 -0
- package/tests/shell-navigation.test.mjs +348 -0
- package/tests/shell-preferences.test.mjs +367 -0
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/stream-output-isolation-static.test.mjs +1 -1
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slot-state.test.mjs +2 -2
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/subagent-reliability-integration.test.mjs +13 -30
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/tab-close-continuity-static.test.mjs +1 -1
- package/tests/tab-metadata-ordering.test.mjs +99 -0
- package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
- package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
- package/tests/terminal-tab-workspace-static.test.mjs +5 -4
- package/tests/terminal-tabs-resize-static.test.mjs +1 -1
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/thread-display-title.test.mjs +44 -0
- package/tests/update-api-harness.test.mjs +15 -14
- package/tests/update-tab-restore-harness.test.mjs +3 -0
- package/tests/webui-settings-locking.test.mjs +2 -2
- package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
- package/tests/workspace-choices.test.mjs +114 -0
- package/tests/workspace-save-load-static.test.mjs +7 -4
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import vm from 'node:vm';
|
|
4
|
+
import { test } from 'node:test';
|
|
5
|
+
import { createSessionContext } from '../public/session-context.mjs';
|
|
6
|
+
import { createProjectGitToolsController } from '../public/project-git-tools-controller.mjs';
|
|
7
|
+
|
|
8
|
+
const source = readFileSync(new URL('../public/app.js', import.meta.url), 'utf8');
|
|
9
|
+
const functions = ['activeTabContext', 'projectTargetFromContext', 'captureGitToolsTarget',
|
|
10
|
+
'isCurrentGitToolsTarget', 'resetGitToolsState', 'loadGitToolsSection', 'runGitToolAction',
|
|
11
|
+
'loadGitChangesDialog', 'closeGitChangesDialog', 'confirmGitStashActionWithPreview', 'runGitOperationRequest']
|
|
12
|
+
.map(name => {
|
|
13
|
+
const start = source.search(new RegExp(`^(?:async )?function ${name}\\(`, 'm'));
|
|
14
|
+
assert.ok(start >= 0, name);
|
|
15
|
+
return source.slice(start, source.indexOf('\n}', start) + 2);
|
|
16
|
+
}).join('\n');
|
|
17
|
+
const controllerStart = source.indexOf('let gitToolsDialogEpoch =');
|
|
18
|
+
const controller = source.slice(controllerStart, source.indexOf('\nlet gitPanelState', controllerStart));
|
|
19
|
+
function fixture() {
|
|
20
|
+
const context = vm.createContext({ assert, createSessionContext, createProjectGitToolsController });
|
|
21
|
+
vm.runInContext(`
|
|
22
|
+
const sessionContext=createSessionContext();
|
|
23
|
+
let activeTabId='a'; sessionContext.activate(activeTabId);
|
|
24
|
+
let activeTabGeneration=sessionContext.generation;
|
|
25
|
+
const tabs=[{id:'a',cwd:'/a'},{id:'b',cwd:'/b'}];
|
|
26
|
+
let gitChangesState={tabId:'a',data:{root:'/a'},loading:false};
|
|
27
|
+
let gitChangesRequestSerial=0;
|
|
28
|
+
const gitChangesUntrackedContentRequests=new Set(), gitChangesCollapsedFiles=new Set();
|
|
29
|
+
const network=[],confirmations=[],events=[],footers=[];
|
|
30
|
+
const api=(url,options)=>new Promise(resolve=>network.push({url,options,resolve}));
|
|
31
|
+
const appConfirmText=(text,options)=>new Promise(resolve=>confirmations.push({text,options,resolve}));
|
|
32
|
+
const addEvent=(...args)=>events.push(args);
|
|
33
|
+
const requestGitFooterWebuiPayload=(...args)=>footers.push(args);
|
|
34
|
+
const renderGitChangesDialog=()=>{};
|
|
35
|
+
const elements={gitChangesDialog:{open:true,close(){this.open=false}}};
|
|
36
|
+
${controller}
|
|
37
|
+
${functions}
|
|
38
|
+
resetGitToolsState('a');
|
|
39
|
+
`, context);
|
|
40
|
+
return code => vm.runInContext(code, context);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test('Git may target a background project while retaining its session and dialog identity', () => {
|
|
44
|
+
const run=fixture();
|
|
45
|
+
run(`
|
|
46
|
+
gitChangesState.tabId='b'; resetGitToolsState('b');
|
|
47
|
+
const target=captureGitToolsTarget();
|
|
48
|
+
assert.equal(target.tabId,'b');
|
|
49
|
+
assert.equal(isCurrentGitToolsTarget(target),true);
|
|
50
|
+
tabs[1].cwd='/moved'; assert.equal(isCurrentGitToolsTarget(target),false);
|
|
51
|
+
tabs[1].cwd='/b'; sessionContext.invalidate('b');
|
|
52
|
+
assert.equal(isCurrentGitToolsTarget(target),false);
|
|
53
|
+
`);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('old Changes loads cannot repaint a reopened dialog or a replacement session', async () => {
|
|
57
|
+
const run=fixture();
|
|
58
|
+
await run(`(async()=>{
|
|
59
|
+
const old=loadGitChangesDialog();
|
|
60
|
+
closeGitChangesDialog(); elements.gitChangesDialog.open=true; resetGitToolsState('a');
|
|
61
|
+
gitChangesState={tabId:'a',data:{root:'/new'},loading:false};
|
|
62
|
+
network[0].resolve({ok:true,data:{root:'/old'}});network[1].resolve({ok:true,data:{}});
|
|
63
|
+
await old; assert.equal(gitChangesState.data.root,'/new');
|
|
64
|
+
const replacement=loadGitChangesDialog();
|
|
65
|
+
sessionContext.invalidate('a');
|
|
66
|
+
network[2].resolve({ok:true,data:{root:'/retired'}});network[3].resolve({ok:true,data:{}});
|
|
67
|
+
await replacement; assert.equal(gitChangesState.data.root,'/new');
|
|
68
|
+
})()`);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('retired stash preview cannot present confirmation in the new dialog', async () => {
|
|
72
|
+
const run=fixture();
|
|
73
|
+
await run(`(async()=>{
|
|
74
|
+
const old=confirmGitStashActionWithPreview({ref:'stash@{0}'},'Apply?');
|
|
75
|
+
resetGitToolsState('a');
|
|
76
|
+
network[0].resolve({ok:true,data:{stat:'old files'}});
|
|
77
|
+
assert.equal(await old,false);assert.equal(confirmations.length,0);
|
|
78
|
+
})()`);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('accepted delayed confirmation keeps its captured token and cannot dispatch after reopening', async () => {
|
|
82
|
+
const run=fixture();
|
|
83
|
+
await run(`(async()=>{
|
|
84
|
+
const token=projectGitTools.capture();
|
|
85
|
+
const old=runGitToolAction('tags',{url:'/api/git-tags/create',confirm:'Create?',body:{name:'v1'}},token);
|
|
86
|
+
assert.equal(confirmations.length,1);
|
|
87
|
+
resetGitToolsState('a'); confirmations[0].resolve(true);
|
|
88
|
+
assert.equal(await old,false);assert.equal(network.length,0);
|
|
89
|
+
})()`);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('late operation failure cannot overwrite a new owner or clear its busy state', async () => {
|
|
93
|
+
const run=fixture();
|
|
94
|
+
await run(`(async()=>{
|
|
95
|
+
const old=runGitOperationRequest('/api/git-operation/continue',{},'Continued');
|
|
96
|
+
resetGitToolsState('a');projectGitTools.setBusy('operation',true);
|
|
97
|
+
gitChangesState.error='new owner';
|
|
98
|
+
network[0].resolve({ok:false,error:'old failure'}); await old;
|
|
99
|
+
assert.equal(gitChangesState.error,'new owner');
|
|
100
|
+
assert.equal(projectGitTools.getState().busy.has('operation'),true);
|
|
101
|
+
assert.equal(footers.length,0);assert.equal(events.length,0);
|
|
102
|
+
})()`);
|
|
103
|
+
});
|
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
GIT_TOOLS_ENDPOINTS,
|
|
5
|
+
GIT_TOOLS_SECTIONS,
|
|
6
|
+
createProjectGitToolsController,
|
|
7
|
+
} from "../public/project-git-tools-controller.mjs";
|
|
8
|
+
|
|
9
|
+
function deferred() {
|
|
10
|
+
let resolve;
|
|
11
|
+
let reject;
|
|
12
|
+
const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
|
|
13
|
+
return { promise, resolve, reject };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function harness(overrides = {}) {
|
|
17
|
+
const target = { tabId: "origin-tab", root: "/repo/origin", generation: 1 };
|
|
18
|
+
let current = target;
|
|
19
|
+
const calls = [];
|
|
20
|
+
const effects = [];
|
|
21
|
+
const confirmations = [];
|
|
22
|
+
let captures = 0;
|
|
23
|
+
const controller = createProjectGitToolsController({
|
|
24
|
+
api: (url, options) => {
|
|
25
|
+
calls.push({ url, ...options });
|
|
26
|
+
return overrides.api?.(url, options) ?? Promise.resolve({ ok: true, data: { root: target.root } });
|
|
27
|
+
},
|
|
28
|
+
captureTarget: () => { captures += 1; return current; },
|
|
29
|
+
isTargetCurrent: (captured) => captured === current,
|
|
30
|
+
confirm: (text, options) => {
|
|
31
|
+
confirmations.push({ text, ...options });
|
|
32
|
+
return overrides.confirm?.(text, options) ?? Promise.resolve(true);
|
|
33
|
+
},
|
|
34
|
+
addEvent: (message, level) => {
|
|
35
|
+
effects.push({ kind: "event", message, level });
|
|
36
|
+
overrides.addEvent?.(message, level);
|
|
37
|
+
},
|
|
38
|
+
onChange: () => {
|
|
39
|
+
effects.push({ kind: "change" });
|
|
40
|
+
overrides.onChange?.();
|
|
41
|
+
},
|
|
42
|
+
onRefreshChanges: (captured) => {
|
|
43
|
+
effects.push({ kind: "changes", target: captured });
|
|
44
|
+
return overrides.onRefreshChanges?.(captured);
|
|
45
|
+
},
|
|
46
|
+
onRefreshFooter: (captured) => {
|
|
47
|
+
effects.push({ kind: "footer", target: captured });
|
|
48
|
+
return overrides.onRefreshFooter?.(captured);
|
|
49
|
+
},
|
|
50
|
+
onMessage: (message, captured) => {
|
|
51
|
+
effects.push({ kind: "message", message, target: captured });
|
|
52
|
+
overrides.onMessage?.(message, captured);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
controller.reset(target);
|
|
56
|
+
return {
|
|
57
|
+
controller, target, calls, effects, confirmations,
|
|
58
|
+
get captures() { return captures; },
|
|
59
|
+
replace(next = { ...target, generation: 2 }) {
|
|
60
|
+
current = next;
|
|
61
|
+
controller.reset(next);
|
|
62
|
+
return next;
|
|
63
|
+
},
|
|
64
|
+
invalidate() { current = null; },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const action = {
|
|
69
|
+
url: "/api/git-stash/save", body: { includeUntracked: true },
|
|
70
|
+
success: "Stashed tracked and untracked changes.", refreshChanges: true,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function nonRenderEffects(h) {
|
|
74
|
+
return h.effects.filter((effect) => effect.kind !== "change");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
test("metadata preserves the existing six sections and lazy endpoints", () => {
|
|
78
|
+
assert.deepEqual(GIT_TOOLS_SECTIONS.map(({ key, title }) => [key, title]), [
|
|
79
|
+
["stash", "Stash"], ["undo", "Undo & recovery"], ["worktrees", "Worktrees"],
|
|
80
|
+
["submodules", "Submodules"], ["tags", "Tags"], ["signing", "Signing"],
|
|
81
|
+
]);
|
|
82
|
+
assert.deepEqual(GIT_TOOLS_ENDPOINTS, {
|
|
83
|
+
stash: "/api/git-stash", undo: "/api/git-undo", worktrees: "/api/git-worktrees",
|
|
84
|
+
submodules: "/api/git-submodules", tags: "/api/git-tags", signing: "/api/git-signing",
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("opening and setters stay lazy; projections cannot change owned state", async () => {
|
|
89
|
+
const h = harness({ api: async () => ({ ok: true, data: { stashes: [{ ref: "stash@{0}" }] } }) });
|
|
90
|
+
const c = h.controller;
|
|
91
|
+
assert.equal(c.setSectionOpen("stash", true), true);
|
|
92
|
+
c.setBusy("operation", true);
|
|
93
|
+
c.setBusy("conflict-agent", true);
|
|
94
|
+
c.setNotice("stash", "Preview unavailable.");
|
|
95
|
+
assert.equal(h.calls.length, 0);
|
|
96
|
+
assert.equal(await c.load("stash"), true);
|
|
97
|
+
const projection = c.getState();
|
|
98
|
+
projection.openSections.clear();
|
|
99
|
+
projection.busy.clear();
|
|
100
|
+
projection.notice.stash = "tampered";
|
|
101
|
+
projection.cache.stash.stashes[0].ref = "tampered";
|
|
102
|
+
assert.equal(c.getState().openSections.has("stash"), true);
|
|
103
|
+
assert.equal(c.getState().busy.has("operation"), true);
|
|
104
|
+
assert.equal(c.getState().busy.has("conflict-agent"), true);
|
|
105
|
+
assert.equal(c.getState().notice.stash, "");
|
|
106
|
+
assert.equal(c.getState().cache.stash.stashes[0].ref, "stash@{0}");
|
|
107
|
+
c.setSectionOpen("stash", false);
|
|
108
|
+
c.setBusy("operation", false);
|
|
109
|
+
assert.equal(c.getState().openSections.size, 0);
|
|
110
|
+
assert.equal(c.getState().busy.has("operation"), false);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("reset captures once when omitted, clears all owned state, and rejects foreign tokens", async () => {
|
|
114
|
+
const h = harness();
|
|
115
|
+
const foreign = harness().controller.capture();
|
|
116
|
+
const old = h.controller.capture();
|
|
117
|
+
h.controller.setSectionOpen("tags", true);
|
|
118
|
+
h.controller.setNotice("tags", "old notice");
|
|
119
|
+
h.controller.setBusy("operation", true);
|
|
120
|
+
await h.controller.load("tags");
|
|
121
|
+
h.controller.reset();
|
|
122
|
+
assert.equal(h.captures, 1);
|
|
123
|
+
assert.deepEqual(h.controller.getState(), {
|
|
124
|
+
tabId: h.target.tabId, openSections: new Set(), cache: {}, busy: new Set(), notice: {},
|
|
125
|
+
});
|
|
126
|
+
assert.equal(h.controller.isCurrent(old), false);
|
|
127
|
+
assert.equal(h.controller.isCurrent(foreign), false);
|
|
128
|
+
assert.equal(await h.controller.run("stash", action, foreign), false);
|
|
129
|
+
h.replace(null);
|
|
130
|
+
assert.equal(h.controller.getState().tabId, null);
|
|
131
|
+
assert.equal(h.controller.isCurrent(h.controller.capture()), false);
|
|
132
|
+
assert.equal(await h.controller.load("tags"), false);
|
|
133
|
+
assert.equal(h.calls.length, 1);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("unknown and prototype section keys are rejected without dispatch", async () => {
|
|
137
|
+
const h = harness();
|
|
138
|
+
for (const key of ["unknown", "reflog", "toString", "__proto__", "operation"]) {
|
|
139
|
+
await assert.rejects(h.controller.load(key), RangeError);
|
|
140
|
+
await assert.rejects(h.controller.run(key, action), RangeError);
|
|
141
|
+
assert.throws(() => h.controller.setSectionOpen(key, true), RangeError);
|
|
142
|
+
assert.throws(() => h.controller.setNotice(key, "error"), RangeError);
|
|
143
|
+
}
|
|
144
|
+
assert.throws(() => h.controller.setBusy("load:unknown", true), RangeError);
|
|
145
|
+
assert.equal(h.calls.length, 0);
|
|
146
|
+
assert.equal(h.confirmations.length, 0);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("loads coalesce during a request, use cache afterwards, and force a fresh read", async () => {
|
|
150
|
+
const request = deferred();
|
|
151
|
+
const h = harness({ api: () => request.promise });
|
|
152
|
+
const pending = h.controller.load("tags");
|
|
153
|
+
assert.equal(h.controller.getState().busy.has("load:tags"), true);
|
|
154
|
+
assert.equal(await h.controller.load("tags", { force: true }), false);
|
|
155
|
+
assert.equal(h.calls.length, 1);
|
|
156
|
+
request.resolve({ ok: true, data: { tags: [{ name: "v1" }] } });
|
|
157
|
+
assert.equal(await pending, true);
|
|
158
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
159
|
+
assert.equal(await h.controller.load("tags"), true);
|
|
160
|
+
assert.equal(h.calls.length, 1);
|
|
161
|
+
assert.equal(await h.controller.load("tags", { force: true }), true);
|
|
162
|
+
assert.equal(h.calls.length, 2);
|
|
163
|
+
assert.ok(h.calls.every(({ tabId }) => tabId === h.target.tabId));
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("load failures preserve cached data, display errors and allow retry", async () => {
|
|
167
|
+
const responses = [
|
|
168
|
+
{ ok: false, error: "Signing unavailable" },
|
|
169
|
+
new Error("network failed"),
|
|
170
|
+
{ ok: false },
|
|
171
|
+
{ ok: true, data: { signingKey: "key-id" } },
|
|
172
|
+
{ ok: false, error: "refresh failed" },
|
|
173
|
+
];
|
|
174
|
+
const h = harness({ api: async () => {
|
|
175
|
+
const response = responses.shift();
|
|
176
|
+
if (response instanceof Error) throw response;
|
|
177
|
+
return response;
|
|
178
|
+
} });
|
|
179
|
+
for (const message of ["Signing unavailable", "network failed", "Failed to load signing"]) {
|
|
180
|
+
assert.equal(await h.controller.load("signing"), false);
|
|
181
|
+
assert.equal(h.controller.getState().notice.signing, message);
|
|
182
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
183
|
+
}
|
|
184
|
+
assert.equal(await h.controller.load("signing"), true);
|
|
185
|
+
assert.equal(h.controller.getState().notice.signing, "");
|
|
186
|
+
assert.equal(await h.controller.load("signing", { force: true }), false);
|
|
187
|
+
assert.deepEqual(h.controller.getState().cache.signing, { signingKey: "key-id" });
|
|
188
|
+
assert.equal(h.controller.getState().notice.signing, "refresh failed");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("undo loads optional reflog for the captured tab and tolerates reflog failure", async (t) => {
|
|
192
|
+
for (const mode of ["success", "false", "error"]) {
|
|
193
|
+
await t.test(mode, async () => {
|
|
194
|
+
const h = harness({ api: async (url) => {
|
|
195
|
+
if (url === "/api/git-undo") return { ok: true, data: { canUndoLastCommit: true } };
|
|
196
|
+
if (mode === "error") throw new Error("reflog unavailable");
|
|
197
|
+
return mode === "false" ? { ok: false } : { ok: true, data: { entries: [{ hash: "abc" }] } };
|
|
198
|
+
} });
|
|
199
|
+
assert.equal(await h.controller.load("undo"), true);
|
|
200
|
+
assert.deepEqual(h.calls, [
|
|
201
|
+
{ url: "/api/git-undo", tabId: "origin-tab" },
|
|
202
|
+
{ url: "/api/git-reflog", tabId: "origin-tab" },
|
|
203
|
+
]);
|
|
204
|
+
assert.deepEqual(h.controller.getState().cache.reflog, mode === "success" ? { entries: [{ hash: "abc" }] } : null);
|
|
205
|
+
assert.equal(h.controller.getState().notice.undo, "");
|
|
206
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("confirmation preserves text/root/label and declined or failed prompts do not dispatch", async () => {
|
|
212
|
+
const choice = deferred();
|
|
213
|
+
const h = harness({ confirm: () => choice.promise });
|
|
214
|
+
const options = { ...action, confirm: "Stash all changes?\n\nIncludes untracked files." };
|
|
215
|
+
const pending = h.controller.run("stash", options);
|
|
216
|
+
assert.deepEqual(h.confirmations, [{
|
|
217
|
+
text: options.confirm, affected: "/repo/origin", confirmLabel: action.success,
|
|
218
|
+
}]);
|
|
219
|
+
assert.equal(await h.controller.run("stash", options), false);
|
|
220
|
+
assert.equal(h.confirmations.length, 1);
|
|
221
|
+
choice.resolve(false);
|
|
222
|
+
assert.equal(await pending, false);
|
|
223
|
+
assert.equal(h.calls.length, 0);
|
|
224
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
225
|
+
assert.deepEqual(nonRenderEffects(h), []);
|
|
226
|
+
|
|
227
|
+
const error = harness({ confirm: async () => { throw new Error("prompt failed"); } });
|
|
228
|
+
assert.equal(await error.controller.run("stash", options), false);
|
|
229
|
+
assert.equal(error.controller.getState().notice.stash, "prompt failed");
|
|
230
|
+
assert.equal(error.calls.length, 0);
|
|
231
|
+
|
|
232
|
+
const fallback = harness({ confirm: async () => false });
|
|
233
|
+
fallback.replace({ tabId: "fallback-tab", root: "" });
|
|
234
|
+
await fallback.controller.run("tags", { url: "/unused", confirm: "Continue?" });
|
|
235
|
+
assert.deepEqual(fallback.confirmations, [{ text: "Continue?", affected: "the current repository", confirmLabel: "Continue" }]);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("confirmation names the loaded repository without replacing its captured target", async () => {
|
|
239
|
+
const h = harness({
|
|
240
|
+
api: async () => ({ ok: true, data: { root: "/repo/resolved" } }),
|
|
241
|
+
confirm: async () => false,
|
|
242
|
+
});
|
|
243
|
+
const token = h.controller.capture();
|
|
244
|
+
await h.controller.load("tags");
|
|
245
|
+
await h.controller.run("tags", { url: "/unused", confirm: "Create tag?", confirmLabel: "Create tag" }, token);
|
|
246
|
+
assert.equal(h.confirmations[0].affected, "/repo/resolved");
|
|
247
|
+
assert.equal(h.confirmations[0].confirmLabel, "Create tag");
|
|
248
|
+
assert.equal(h.controller.capture(), token);
|
|
249
|
+
assert.equal(h.target.root, "/repo/origin");
|
|
250
|
+
assert.equal(h.calls.length, 1);
|
|
251
|
+
|
|
252
|
+
h.replace({ tabId: "replacement-tab", root: "/repo/replacement" });
|
|
253
|
+
assert.equal(await h.controller.run("tags", { url: "/unused", confirm: "Create tag?" }, token), false);
|
|
254
|
+
await h.controller.run("tags", { url: "/unused", confirm: "Create tag?" });
|
|
255
|
+
assert.equal(h.confirmations[1].affected, "/repo/replacement");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("successful actions preserve method/body and refresh with the originating target", async () => {
|
|
259
|
+
const response = { ok: true, data: { removed: "/repo/other" } };
|
|
260
|
+
const h = harness({ api: async () => response });
|
|
261
|
+
h.controller.setNotice("worktrees", "old error");
|
|
262
|
+
assert.equal(await h.controller.run("worktrees", {
|
|
263
|
+
url: "/api/git-worktrees", method: "DELETE", body: { path: "/repo/other", confirmed: true },
|
|
264
|
+
confirm: "Remove worktree?", success: "Removed worktree.",
|
|
265
|
+
successMessage: (result) => { assert.equal(result, response); return `Removed ${result.data.removed}.`; },
|
|
266
|
+
refreshChanges: true,
|
|
267
|
+
}), true);
|
|
268
|
+
assert.deepEqual(h.calls, [
|
|
269
|
+
{ url: "/api/git-worktrees", method: "DELETE", body: { path: "/repo/other", confirmed: true }, tabId: "origin-tab" },
|
|
270
|
+
{ url: "/api/git-worktrees", tabId: "origin-tab" },
|
|
271
|
+
]);
|
|
272
|
+
assert.deepEqual(nonRenderEffects(h), [
|
|
273
|
+
{ kind: "event", message: "Removed /repo/other.", level: "success" },
|
|
274
|
+
{ kind: "changes", target: h.target },
|
|
275
|
+
{ kind: "message", message: "Removed /repo/other.", target: h.target },
|
|
276
|
+
{ kind: "footer", target: h.target },
|
|
277
|
+
]);
|
|
278
|
+
assert.equal(nonRenderEffects(h).at(-1).target, h.target);
|
|
279
|
+
assert.equal(h.captures, 0, "actions never recapture the active tab after an await");
|
|
280
|
+
assert.equal(h.controller.getState().notice.worktrees, "");
|
|
281
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("default POST, fallback success message and optional Changes refresh retain existing semantics", async () => {
|
|
285
|
+
const h = harness();
|
|
286
|
+
assert.equal(await h.controller.run("stash", { ...action, successMessage: () => "", refreshChanges: false }), true);
|
|
287
|
+
assert.deepEqual(h.calls[0], { url: action.url, method: "POST", body: action.body, tabId: "origin-tab" });
|
|
288
|
+
assert.deepEqual(nonRenderEffects(h).map(({ kind }) => kind), ["event", "message", "footer"]);
|
|
289
|
+
assert.equal(nonRenderEffects(h)[0].message, action.success);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("actions reject duplicate dispatch through both mutation and section-refresh waits", async () => {
|
|
293
|
+
const mutation = deferred();
|
|
294
|
+
const refresh = deferred();
|
|
295
|
+
const enteredRefresh = deferred();
|
|
296
|
+
const h = harness({ api: (url) => {
|
|
297
|
+
if (url === action.url) return mutation.promise;
|
|
298
|
+
enteredRefresh.resolve();
|
|
299
|
+
return refresh.promise;
|
|
300
|
+
} });
|
|
301
|
+
const pending = h.controller.run("stash", action);
|
|
302
|
+
assert.equal(h.controller.getState().busy.has("stash"), true);
|
|
303
|
+
assert.equal(await h.controller.run("stash", action), false);
|
|
304
|
+
mutation.resolve({ ok: true });
|
|
305
|
+
await enteredRefresh.promise;
|
|
306
|
+
assert.equal(h.controller.getState().busy.has("stash"), false);
|
|
307
|
+
assert.equal(h.controller.getState().busy.has("load:stash"), true);
|
|
308
|
+
assert.equal(await h.controller.run("stash", action), false);
|
|
309
|
+
refresh.resolve({ ok: true, data: { stashes: [] } });
|
|
310
|
+
assert.equal(await pending, true);
|
|
311
|
+
assert.equal(h.calls.length, 2);
|
|
312
|
+
assert.equal(await h.controller.run("stash", action), true, "admission is released after completion");
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("action false responses, hints and thrown errors stay visible and release busy admission", async (t) => {
|
|
316
|
+
for (const [response, message] of [
|
|
317
|
+
[{ ok: false, error: "Cannot undo", hint: "Push is already published" }, "Cannot undo\nPush is already published"],
|
|
318
|
+
[{ ok: false }, "git action failed"],
|
|
319
|
+
[new Error("offline"), "offline"],
|
|
320
|
+
]) {
|
|
321
|
+
await t.test(message, async () => {
|
|
322
|
+
const h = harness({ api: async () => {
|
|
323
|
+
if (response instanceof Error) throw response;
|
|
324
|
+
return response;
|
|
325
|
+
} });
|
|
326
|
+
assert.equal(await h.controller.run("stash", action), false);
|
|
327
|
+
assert.equal(h.controller.getState().notice.stash, message);
|
|
328
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
329
|
+
assert.deepEqual(nonRenderEffects(h), []);
|
|
330
|
+
assert.equal(h.calls.length, 1);
|
|
331
|
+
await h.controller.run("stash", action);
|
|
332
|
+
assert.equal(h.calls.length, 2, "failed action can be retried");
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("failed section refresh remains visible while successful action still refreshes Changes and footer", async () => {
|
|
338
|
+
const h = harness({ api: async (url) => url === action.url ? { ok: true } : { ok: false, error: "List refresh failed" } });
|
|
339
|
+
assert.equal(await h.controller.run("stash", action), true);
|
|
340
|
+
assert.equal(h.controller.getState().notice.stash, "List refresh failed");
|
|
341
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
342
|
+
assert.deepEqual(nonRenderEffects(h).map(({ kind }) => kind), ["event", "changes", "message", "footer"]);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test("refresh callback errors become notices without skipping busy cleanup", async (t) => {
|
|
346
|
+
for (const callback of ["onRefreshChanges", "onRefreshFooter"]) {
|
|
347
|
+
await t.test(callback, async () => {
|
|
348
|
+
const h = harness({ [callback]: async () => { throw new Error("Refresh failed"); } });
|
|
349
|
+
assert.equal(await h.controller.run("stash", action), false);
|
|
350
|
+
assert.equal(h.controller.getState().notice.stash, "Refresh failed");
|
|
351
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
352
|
+
if (callback === "onRefreshChanges") assert.equal(h.effects.some(({ kind }) => kind === "message" || kind === "footer"), false);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test("reset during confirmation and a token from an earlier preview cannot authorize a replacement", async () => {
|
|
358
|
+
const choice = deferred();
|
|
359
|
+
const h = harness({ confirm: () => choice.promise });
|
|
360
|
+
const oldToken = h.controller.capture();
|
|
361
|
+
const pending = h.controller.run("stash", { ...action, confirm: "Continue?" });
|
|
362
|
+
h.replace(h.target);
|
|
363
|
+
h.controller.setBusy("stash", true);
|
|
364
|
+
const replacement = h.controller.getState();
|
|
365
|
+
const effectCount = h.effects.length;
|
|
366
|
+
choice.resolve(true);
|
|
367
|
+
assert.equal(await pending, false);
|
|
368
|
+
assert.equal(h.controller.isCurrent(oldToken), false);
|
|
369
|
+
assert.equal(await h.controller.run("stash", action, oldToken), false);
|
|
370
|
+
assert.equal(h.calls.length, 0);
|
|
371
|
+
assert.deepEqual(h.controller.getState(), replacement);
|
|
372
|
+
assert.equal(h.effects.length, effectCount);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("old load completion and cleanup cannot overwrite a newer same-section request", async (t) => {
|
|
376
|
+
for (const failure of [false, true]) {
|
|
377
|
+
await t.test(failure ? "rejected old load" : "successful old load", async () => {
|
|
378
|
+
const old = deferred();
|
|
379
|
+
const next = deferred();
|
|
380
|
+
let requests = 0;
|
|
381
|
+
const h = harness({ api: () => ++requests === 1 ? old.promise : next.promise });
|
|
382
|
+
const pending = h.controller.load("stash");
|
|
383
|
+
h.replace();
|
|
384
|
+
h.controller.setNotice("stash", "replacement notice");
|
|
385
|
+
const replacementLoad = h.controller.load("stash");
|
|
386
|
+
const replacement = h.controller.getState();
|
|
387
|
+
const effectCount = h.effects.length;
|
|
388
|
+
if (failure) old.reject(new Error("old failure"));
|
|
389
|
+
else old.resolve({ ok: true, data: { stashes: ["old"] } });
|
|
390
|
+
assert.equal(await pending, false);
|
|
391
|
+
assert.deepEqual(h.controller.getState(), replacement);
|
|
392
|
+
assert.equal(h.effects.length, effectCount);
|
|
393
|
+
next.resolve({ ok: true, data: { stashes: ["new"] } });
|
|
394
|
+
assert.equal(await replacementLoad, true);
|
|
395
|
+
assert.deepEqual(h.controller.getState().cache.stash, { stashes: ["new"] });
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
test("undo cannot start or publish reflog across reset", async (t) => {
|
|
401
|
+
for (const stage of ["primary", "reflog"]) {
|
|
402
|
+
await t.test(stage, async () => {
|
|
403
|
+
const wait = deferred();
|
|
404
|
+
const entered = deferred();
|
|
405
|
+
const h = harness({ api: (url) => {
|
|
406
|
+
if (stage === "primary" || url === "/api/git-reflog") {
|
|
407
|
+
entered.resolve();
|
|
408
|
+
return wait.promise;
|
|
409
|
+
}
|
|
410
|
+
return Promise.resolve({ ok: true, data: { canUndoLastCommit: true } });
|
|
411
|
+
} });
|
|
412
|
+
const pending = h.controller.load("undo");
|
|
413
|
+
await entered.promise;
|
|
414
|
+
h.replace();
|
|
415
|
+
const effectCount = h.effects.length;
|
|
416
|
+
wait.resolve({ ok: true, data: { entries: ["old"] } });
|
|
417
|
+
assert.equal(await pending, false);
|
|
418
|
+
assert.deepEqual(h.controller.getState().cache, {});
|
|
419
|
+
assert.equal(h.effects.length, effectCount);
|
|
420
|
+
assert.equal(h.calls.length, stage === "primary" ? 1 : 2);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
test("old action completion cannot clear a replacement action or start follow-ups", async (t) => {
|
|
426
|
+
for (const failure of [false, true]) {
|
|
427
|
+
await t.test(failure ? "old action error" : "old action success", async () => {
|
|
428
|
+
const old = deferred();
|
|
429
|
+
const next = deferred();
|
|
430
|
+
let requests = 0;
|
|
431
|
+
const h = harness({ api: (url) => {
|
|
432
|
+
if (url !== action.url) return Promise.resolve({ ok: true, data: {} });
|
|
433
|
+
return ++requests === 1 ? old.promise : next.promise;
|
|
434
|
+
} });
|
|
435
|
+
const pending = h.controller.run("stash", action);
|
|
436
|
+
h.replace();
|
|
437
|
+
const replacementAction = h.controller.run("stash", action);
|
|
438
|
+
const replacement = h.controller.getState();
|
|
439
|
+
const effectCount = h.effects.length;
|
|
440
|
+
if (failure) old.reject(new Error("old action failure"));
|
|
441
|
+
else old.resolve({ ok: true });
|
|
442
|
+
assert.equal(await pending, false);
|
|
443
|
+
assert.deepEqual(h.controller.getState(), replacement);
|
|
444
|
+
assert.equal(h.effects.length, effectCount);
|
|
445
|
+
assert.equal(h.calls.length, 2);
|
|
446
|
+
next.resolve({ ok: true });
|
|
447
|
+
assert.equal(await replacementAction, true);
|
|
448
|
+
assert.equal(h.controller.getState().busy.size, 0);
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
test("reset during an action's section reload prevents Changes, message and footer follow-ups", async () => {
|
|
454
|
+
const reload = deferred();
|
|
455
|
+
const entered = deferred();
|
|
456
|
+
const h = harness({ api: (url) => {
|
|
457
|
+
if (url === action.url) return Promise.resolve({ ok: true });
|
|
458
|
+
entered.resolve();
|
|
459
|
+
return reload.promise;
|
|
460
|
+
} });
|
|
461
|
+
const pending = h.controller.run("stash", action);
|
|
462
|
+
await entered.promise;
|
|
463
|
+
h.replace();
|
|
464
|
+
h.controller.setNotice("stash", "new owner");
|
|
465
|
+
const replacement = h.controller.getState();
|
|
466
|
+
const effectCount = h.effects.length;
|
|
467
|
+
reload.resolve({ ok: true, data: { stashes: ["old"] } });
|
|
468
|
+
assert.equal(await pending, false);
|
|
469
|
+
assert.deepEqual(h.controller.getState(), replacement);
|
|
470
|
+
assert.equal(h.effects.length, effectCount);
|
|
471
|
+
assert.deepEqual(nonRenderEffects(h).map(({ kind }) => kind), ["event"]);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
test("reset during Changes or footer refresh suppresses all remaining continuation writes", async (t) => {
|
|
475
|
+
for (const callback of ["onRefreshChanges", "onRefreshFooter"]) {
|
|
476
|
+
for (const failure of [false, true]) {
|
|
477
|
+
await t.test(`${callback}, ${failure ? "failure" : "success"}`, async () => {
|
|
478
|
+
const wait = deferred();
|
|
479
|
+
const entered = deferred();
|
|
480
|
+
const h = harness({ [callback]: () => { entered.resolve(); return wait.promise; } });
|
|
481
|
+
const pending = h.controller.run("stash", action);
|
|
482
|
+
await entered.promise;
|
|
483
|
+
assert.equal(await h.controller.run("stash", action), false, "refresh keeps action admission reserved");
|
|
484
|
+
h.replace();
|
|
485
|
+
h.controller.setBusy("stash", true);
|
|
486
|
+
const replacement = h.controller.getState();
|
|
487
|
+
const effectCount = h.effects.length;
|
|
488
|
+
if (failure) wait.reject(new Error("old refresh failed"));
|
|
489
|
+
else wait.resolve();
|
|
490
|
+
assert.equal(await pending, false);
|
|
491
|
+
assert.deepEqual(h.controller.getState(), replacement);
|
|
492
|
+
assert.equal(h.effects.length, effectCount);
|
|
493
|
+
if (callback === "onRefreshChanges") {
|
|
494
|
+
assert.equal(h.effects.some(({ kind }) => kind === "message" || kind === "footer"), false);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test("external operation/conflict-agent cleanup is guarded by its original owner token", () => {
|
|
502
|
+
const h = harness();
|
|
503
|
+
const old = h.controller.capture();
|
|
504
|
+
h.controller.setBusy("operation", true, old);
|
|
505
|
+
h.controller.setBusy("conflict-agent", true, old);
|
|
506
|
+
h.replace(h.target);
|
|
507
|
+
const current = h.controller.capture();
|
|
508
|
+
h.controller.setBusy("operation", true, current);
|
|
509
|
+
h.controller.setBusy("conflict-agent", true, current);
|
|
510
|
+
const effectCount = h.effects.length;
|
|
511
|
+
for (const key of ["operation", "conflict-agent"]) assert.equal(h.controller.setBusy(key, false, old), false);
|
|
512
|
+
assert.equal(h.controller.setNotice("worktrees", "old preview failure", old), false);
|
|
513
|
+
assert.equal(h.controller.setSectionOpen("worktrees", true, old), false);
|
|
514
|
+
assert.equal(h.effects.length, effectCount);
|
|
515
|
+
assert.deepEqual(h.controller.getState().busy, new Set(["operation", "conflict-agent"]));
|
|
516
|
+
assert.equal(h.controller.setBusy("operation", false, current), true);
|
|
517
|
+
assert.equal(h.controller.getState().busy.has("conflict-agent"), true);
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
test("target invalidation alone prevents completion and dispatch, without recapturing an active tab", async () => {
|
|
521
|
+
const request = deferred();
|
|
522
|
+
const h = harness({ api: () => request.promise });
|
|
523
|
+
const token = h.controller.capture();
|
|
524
|
+
const pending = h.controller.run("stash", action);
|
|
525
|
+
h.invalidate();
|
|
526
|
+
const snapshot = h.controller.getState();
|
|
527
|
+
const effectCount = h.effects.length;
|
|
528
|
+
request.resolve({ ok: true });
|
|
529
|
+
assert.equal(await pending, false);
|
|
530
|
+
assert.equal(h.controller.isCurrent(token), false);
|
|
531
|
+
assert.equal(await h.controller.load("tags"), false);
|
|
532
|
+
assert.equal(await h.controller.run("tags", action), false);
|
|
533
|
+
assert.equal(h.controller.setBusy("operation", true, token), false);
|
|
534
|
+
assert.deepEqual(h.controller.getState(), snapshot);
|
|
535
|
+
assert.equal(h.effects.length, effectCount);
|
|
536
|
+
assert.equal(h.calls.length, 1);
|
|
537
|
+
assert.equal(h.captures, 0);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
test("a replacement tab/root cannot inherit an old confirmation or its follow-up requests", async () => {
|
|
541
|
+
const choice = deferred();
|
|
542
|
+
const h = harness({ confirm: () => choice.promise });
|
|
543
|
+
const pending = h.controller.run("worktrees", {
|
|
544
|
+
url: "/api/git-worktrees", method: "DELETE", body: { path: "/repo/other", confirmed: true },
|
|
545
|
+
confirm: "Remove the selected worktree?", success: "Removed worktree.",
|
|
546
|
+
});
|
|
547
|
+
const replacement = h.replace({ tabId: "replacement-tab", root: "/repo/replacement", generation: 1 });
|
|
548
|
+
choice.resolve(true);
|
|
549
|
+
assert.equal(await pending, false);
|
|
550
|
+
assert.equal(h.calls.length, 0);
|
|
551
|
+
assert.equal(h.confirmations[0].affected, h.target.root);
|
|
552
|
+
assert.equal(await h.controller.run("stash", action), true);
|
|
553
|
+
assert.ok(h.calls.every(({ tabId }) => tabId === replacement.tabId));
|
|
554
|
+
assert.equal(nonRenderEffects(h).find(({ kind }) => kind === "changes").target, replacement);
|
|
555
|
+
assert.equal(nonRenderEffects(h).find(({ kind }) => kind === "footer").target, replacement);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
test("synchronous callbacks that reset the owner cannot launch the next request or repaint", async () => {
|
|
559
|
+
let h;
|
|
560
|
+
let resetOnRender = false;
|
|
561
|
+
h = harness({ onChange: () => {
|
|
562
|
+
if (resetOnRender) { resetOnRender = false; h.replace(); }
|
|
563
|
+
} });
|
|
564
|
+
resetOnRender = true;
|
|
565
|
+
assert.equal(await h.controller.run("stash", action), false);
|
|
566
|
+
assert.equal(h.calls.length, 0);
|
|
567
|
+
resetOnRender = true;
|
|
568
|
+
assert.equal(await h.controller.load("undo"), false);
|
|
569
|
+
assert.equal(h.calls.length, 0);
|
|
570
|
+
|
|
571
|
+
let eventHarness;
|
|
572
|
+
eventHarness = harness({ addEvent: () => eventHarness.replace() });
|
|
573
|
+
assert.equal(await eventHarness.controller.run("stash", action), false);
|
|
574
|
+
assert.equal(eventHarness.calls.length, 1);
|
|
575
|
+
assert.deepEqual(eventHarness.controller.getState().cache, {});
|
|
576
|
+
assert.deepEqual(nonRenderEffects(eventHarness).map(({ kind }) => kind), ["event"]);
|
|
577
|
+
});
|