@firstpick/pi-package-webui 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +236 -24
  2. package/bin/pi-webui-launcher.mjs +23 -12
  3. package/bin/pi-webui.mjs +493 -65
  4. package/lib/agent-run-adapters.mjs +500 -0
  5. package/lib/agent-run-protocol.mjs +262 -0
  6. package/lib/agent-run-registry.mjs +339 -0
  7. package/lib/app-runner-terminal.mjs +40 -0
  8. package/lib/git-workflow-preferences.mjs +11 -4
  9. package/lib/trust-boundaries.mjs +2 -0
  10. package/lib/ui-layout-settings.mjs +172 -28
  11. package/lib/update/package-layout.mjs +50 -0
  12. package/lib/update/plan.mjs +11 -0
  13. package/package.json +2 -2
  14. package/public/app.js +1376 -337
  15. package/public/index.html +113 -68
  16. package/public/service-worker.js +1 -1
  17. package/public/styles.css +371 -93
  18. package/tests/agent-run-adapters.test.mjs +217 -0
  19. package/tests/agent-run-launcher.test.mjs +41 -0
  20. package/tests/agent-run-protocol.test.mjs +82 -0
  21. package/tests/agent-run-registry.test.mjs +102 -0
  22. package/tests/app-runner-terminal-static.test.mjs +28 -0
  23. package/tests/app-runner-terminal.test.mjs +65 -0
  24. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  25. package/tests/browser/control-deck-side-panels.spec.mjs +354 -0
  26. package/tests/browser/controls-layout.spec.mjs +122 -0
  27. package/tests/browser/file-tree-git-ignored.spec.mjs +113 -0
  28. package/tests/browser/interaction-continuity.spec.mjs +159 -0
  29. package/tests/browser/mobile-foundation.spec.mjs +26 -0
  30. package/tests/browser/model-search-focus.spec.mjs +96 -0
  31. package/tests/browser/optimistic-prompt.spec.mjs +22 -0
  32. package/tests/browser/persistent-ui-layout.spec.mjs +224 -66
  33. package/tests/browser/subagent-observability.spec.mjs +87 -0
  34. package/tests/chat-scroll-intent-static.test.mjs +1 -1
  35. package/tests/codex-fast-mode-static.test.mjs +2 -2
  36. package/tests/component-update-api-static.test.mjs +2 -1
  37. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  38. package/tests/control-deck-component-updates-static.test.mjs +2 -0
  39. package/tests/control-deck-side-panels-static.test.mjs +68 -0
  40. package/tests/controls-layout-static.test.mjs +22 -0
  41. package/tests/fast-mode-client-static.test.mjs +1 -1
  42. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  43. package/tests/file-tree-git-ignored-static.test.mjs +152 -0
  44. package/tests/file-tree-search-layout-static.test.mjs +2 -1
  45. package/tests/fixtures/fake-pi.mjs +43 -7
  46. package/tests/footer-provider-usage-visual-static.test.mjs +10 -8
  47. package/tests/git-workflow-preferences.test.mjs +55 -6
  48. package/tests/http-endpoints-harness.test.mjs +173 -14
  49. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  50. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  51. package/tests/mobile-foundation-static.test.mjs +3 -3
  52. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  53. package/tests/mobile-static.test.mjs +18 -5
  54. package/tests/open-issue-wizard-static.test.mjs +2 -2
  55. package/tests/persistent-ui-layout-static.test.mjs +13 -13
  56. package/tests/questionnaire-dialog.test.mjs +3 -3
  57. package/tests/remote-auth-settings-harness.test.mjs +1 -1
  58. package/tests/session-sampling-ui-static.test.mjs +3 -3
  59. package/tests/side-panel-context-menu-static.test.mjs +1 -1
  60. package/tests/side-panel-resize-static.test.mjs +26 -16
  61. package/tests/side-panel-section-height-removal-static.test.mjs +4 -4
  62. package/tests/side-panel-section-reorder-static.test.mjs +16 -70
  63. package/tests/subagent-gate-visibility.test.mjs +2 -1
  64. package/tests/subagent-launch-slots.test.mjs +1 -1
  65. package/tests/subagent-observability-static.test.mjs +32 -0
  66. package/tests/subagent-reliability-integration.test.mjs +161 -0
  67. package/tests/subagents-helper.test.mjs +344 -4
  68. package/tests/terminal-tabs-resize-static.test.mjs +35 -0
  69. package/tests/theme-customizer-static.test.mjs +1 -1
  70. package/tests/ui-layout-settings.test.mjs +104 -32
  71. package/tests/update-api-harness.test.mjs +24 -10
  72. package/tests/update-package-layout.test.mjs +38 -0
  73. package/tests/update-plan.test.mjs +11 -1
  74. package/tests/webui-settings-locking.test.mjs +33 -3
  75. package/webui-rpc-helper.mjs +417 -28
@@ -10,15 +10,15 @@ import {
10
10
 
11
11
  const defaults = defaultUiLayout();
12
12
  assert.deepEqual(normalizeUiLayout(undefined), defaults);
13
- assert.deepEqual(normalizeUiLayout({ version: 99, sidePanel: { collapsed: true } }), defaults, "unknown layout versions must fail soft to nullable defaults");
13
+ assert.deepEqual(normalizeUiLayout({ version: 99, sidePanel: { placement: "both" } }), defaults, "unknown layout versions must fail soft to nullable defaults");
14
14
 
15
- const valid = normalizeUiLayout({
15
+ const completeV1 = {
16
16
  version: 1,
17
17
  sidePanel: {
18
18
  sectionOrder: ["files", "controls", "git"],
19
19
  collapsedSectionIds: ["git"],
20
- hiddenSectionIds: [],
21
- collapsed: false,
20
+ hiddenSectionIds: ["files"],
21
+ collapsed: true,
22
22
  },
23
23
  composerActions: {
24
24
  order: ["new", "git", "send"],
@@ -28,48 +28,105 @@ const valid = normalizeUiLayout({
28
28
  terminalTabs: {
29
29
  layout: "left",
30
30
  customGroups: { version: 1, groups: [{ id: "group-1", title: "Group 1", tabIds: ["tab-a", "tab-b"] }] },
31
+ sidebarWidth: 284.6,
31
32
  },
32
33
  fileViewerWidth: 560.4,
34
+ };
35
+ const migrated = normalizeUiLayout(completeV1, { legacySidePanelWidth: 612.4 });
36
+ assert.equal(migrated.version, 2);
37
+ assert.equal(migrated.sidePanel.placement, "right", "v1 layouts must migrate to the existing right-side presentation");
38
+ assert.deepEqual(migrated.sidePanel.sectionLayout, { order: ["files", "controls", "git"], leftSectionIds: [] });
39
+ assert.deepEqual(migrated.sidePanel.collapsedSectionIds, ["git"]);
40
+ assert.deepEqual(migrated.sidePanel.hiddenSectionIds, ["files"]);
41
+ assert.deepEqual(migrated.sidePanel.collapsedPanels, { left: false, right: true });
42
+ assert.deepEqual(migrated.sidePanel.panelWidths, { left: 384, right: 612 });
43
+ assert.deepEqual(migrated.composerActions, completeV1.composerActions, "composer action order and grid must survive migration");
44
+ assert.deepEqual(migrated.footerScopedModelOrder, completeV1.footerScopedModelOrder);
45
+ assert.deepEqual(migrated.terminalTabs, { ...completeV1.terminalTabs, sidebarWidth: 285 }, "terminal placement, custom groups, and normalized sidebar width must survive migration");
46
+ assert.equal(migrated.fileViewerWidth, 560);
47
+
48
+ const malformedV1 = normalizeUiLayout({
49
+ ...completeV1,
50
+ sidePanel: {
51
+ sectionOrder: ["files", "files"],
52
+ collapsedSectionIds: ["git"],
53
+ hiddenSectionIds: ["files"],
54
+ collapsed: "yes",
55
+ },
56
+ composerActions: { ...completeV1.composerActions, grid: { version: 2, columns: 999, positions: {} } },
57
+ terminalTabs: { layout: "bottom", customGroups: completeV1.terminalTabs.customGroups },
58
+ fileViewerWidth: 200,
59
+ }, { legacySidePanelWidth: "bad" });
60
+ assert.deepEqual(malformedV1.sidePanel.sectionLayout, { order: null, leftSectionIds: null }, "a malformed v1 order must fail soft atomically");
61
+ assert.deepEqual(malformedV1.sidePanel.collapsedSectionIds, ["git"], "valid v1 sibling fields must survive malformed fields");
62
+ assert.deepEqual(malformedV1.sidePanel.hiddenSectionIds, ["files"]);
63
+ assert.deepEqual(malformedV1.sidePanel.collapsedPanels, { left: false, right: false });
64
+ assert.deepEqual(malformedV1.sidePanel.panelWidths, { left: 384, right: 384 });
65
+ assert.deepEqual(malformedV1.composerActions.order, completeV1.composerActions.order);
66
+ assert.equal(malformedV1.composerActions.grid, null);
67
+ assert.equal(malformedV1.terminalTabs.layout, null);
68
+ assert.deepEqual(malformedV1.terminalTabs.customGroups, completeV1.terminalTabs.customGroups);
69
+ assert.equal(malformedV1.fileViewerWidth, null);
70
+
71
+ const valid = normalizeUiLayout({
72
+ version: 2,
73
+ sidePanel: {
74
+ placement: "both",
75
+ sectionLayout: { order: ["files", "controls", "git", "future-section"], leftSectionIds: ["files", "future-section"] },
76
+ collapsedSectionIds: ["git"],
77
+ hiddenSectionIds: [],
78
+ collapsedPanels: { left: true, right: false },
79
+ panelWidths: { left: 420.4, right: 640.6 },
80
+ },
81
+ composerActions: completeV1.composerActions,
82
+ footerScopedModelOrder: completeV1.footerScopedModelOrder,
83
+ terminalTabs: completeV1.terminalTabs,
84
+ fileViewerWidth: 560,
33
85
  });
34
- assert.deepEqual(valid.sidePanel.sectionOrder, ["files", "controls", "git"]);
86
+ assert.equal(valid.sidePanel.placement, "both");
87
+ assert.deepEqual(valid.sidePanel.sectionLayout.leftSectionIds, ["files", "future-section"], "unknown historical section ids may be retained");
88
+ assert.deepEqual(valid.sidePanel.panelWidths, { left: 420, right: 641 });
35
89
  assert.equal(valid.fileViewerWidth, 560);
36
- const legacySectionHeights = normalizeUiLayout({
37
- version: 1,
38
- sidePanel: { ...valid.sidePanel, sectionHeights: { files: 360 } },
39
- });
40
- assert.equal("sectionHeights" in legacySectionHeights.sidePanel, false, "legacy saved section heights should be ignored during normalization");
41
90
  assert.equal(valid.terminalTabs.layout, "left");
91
+ assert.equal(valid.terminalTabs.sidebarWidth, 285);
42
92
 
43
93
  const partiallyMalformed = normalizeUiLayout({
44
94
  ...valid,
45
95
  sidePanel: {
46
96
  ...valid.sidePanel,
47
- sectionOrder: ["files", "files"],
48
- collapsed: true,
97
+ placement: "center",
98
+ sectionLayout: { order: ["files", "controls"], leftSectionIds: ["missing"] },
99
+ collapsedPanels: { left: "yes", right: true },
100
+ panelWidths: { left: 1, right: 700 },
49
101
  },
50
- composerActions: { ...valid.composerActions, grid: { version: 2, columns: 999, positions: {} } },
51
- terminalTabs: { layout: "bottom", customGroups: valid.terminalTabs.customGroups },
52
102
  });
53
- assert.equal(partiallyMalformed.sidePanel.sectionOrder, null, "a malformed disk field should fail soft independently");
54
- assert.equal(partiallyMalformed.sidePanel.collapsed, true, "valid sibling disk fields should survive");
55
- assert.equal(partiallyMalformed.composerActions.grid, null);
56
- assert.equal(partiallyMalformed.terminalTabs.layout, null);
57
- assert.deepEqual(partiallyMalformed.terminalTabs.customGroups, valid.terminalTabs.customGroups);
103
+ assert.equal(partiallyMalformed.sidePanel.placement, null);
104
+ assert.deepEqual(partiallyMalformed.sidePanel.sectionLayout, defaults.sidePanel.sectionLayout, "section layout must fail soft as one atomic field");
105
+ assert.deepEqual(partiallyMalformed.sidePanel.collapsedPanels, { left: null, right: true }, "malformed side values must not erase valid siblings on disk");
106
+ assert.deepEqual(partiallyMalformed.sidePanel.panelWidths, { left: null, right: 700 });
107
+ assert.deepEqual(partiallyMalformed.composerActions, valid.composerActions, "unrelated valid envelope fields must survive malformed side-panel fields");
58
108
 
59
109
  const merged = mergeUiLayout(valid, {
60
- sidePanel: { collapsed: true, hiddenSectionIds: null },
110
+ version: 2,
111
+ sidePanel: {
112
+ placement: "left",
113
+ collapsedPanels: { right: true },
114
+ panelWidths: { left: 500.2 },
115
+ hiddenSectionIds: null,
116
+ },
61
117
  footerScopedModelOrder: [],
62
118
  fileViewerWidth: null,
63
119
  });
64
- assert.equal(merged.sidePanel.collapsed, true);
65
- assert.deepEqual(merged.sidePanel.sectionOrder, valid.sidePanel.sectionOrder, "omitted fields must be preserved");
120
+ assert.equal(merged.sidePanel.placement, "left");
121
+ assert.deepEqual(merged.sidePanel.sectionLayout, valid.sidePanel.sectionLayout, "omitted atomic section layout must be preserved");
122
+ assert.deepEqual(merged.sidePanel.collapsedPanels, { left: true, right: true }, "side-specific partial state must preserve its sibling");
123
+ assert.deepEqual(merged.sidePanel.panelWidths, { left: 500, right: 641 });
66
124
  assert.equal(merged.sidePanel.hiddenSectionIds, null, "explicit null must clear only the named field");
67
125
  assert.deepEqual(merged.footerScopedModelOrder, [], "explicit empty arrays are valid resets");
68
126
  assert.equal(merged.fileViewerWidth, null);
69
127
 
70
128
  const sidePanelReset = mergeUiLayout(valid, { sidePanel: null });
71
129
  assert.deepEqual(sidePanelReset.sidePanel, defaults.sidePanel, "null sidePanel must reset all side-panel fields");
72
-
73
130
  const composerReset = mergeUiLayout(valid, { composerActions: { order: [], grid: null } });
74
131
  assert.deepEqual(composerReset.composerActions, { order: [], grid: null });
75
132
  const terminalReset = mergeUiLayout(valid, { terminalTabs: null });
@@ -77,15 +134,20 @@ assert.deepEqual(terminalReset.terminalTabs, defaults.terminalTabs);
77
134
 
78
135
  assert.throws(() => validateUiLayoutPatch({}), /at least one mutable field/);
79
136
  assert.throws(() => validateUiLayoutPatch({ unknown: true }), /unsupported field/);
80
- assert.throws(() => validateUiLayoutPatch({ version: 2, fileViewerWidth: 500 }), /version must be 1/);
137
+ assert.throws(() => validateUiLayoutPatch({ version: 1, fileViewerWidth: 500 }), /version must be 2/, "stale v1 writes must be rejected");
81
138
  assert.throws(() => validateUiLayoutPatch({ composerActions: { order: ["send"] } }), /order and grid together/);
82
- assert.throws(() => validateUiLayoutPatch({ sidePanel: { collapsed: "yes" } }), /boolean or null/);
83
- assert.throws(
84
- () => validateUiLayoutPatch({ sidePanel: { sectionHeights: { files: 240 } } }),
85
- /unsupported field: sectionHeights/,
86
- "removed section-height preferences must no longer be accepted",
87
- );
139
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { sectionOrder: ["files"] } }), /unsupported field: sectionOrder/);
140
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { collapsed: true } }), /unsupported field: collapsed/);
141
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { placement: "center" } }), /must be right, left, both/);
142
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { sectionLayout: { order: ["files"] } } }), /order and leftSectionIds together/);
143
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { sectionLayout: { order: ["files", "files"], leftSectionIds: [] } } }), /duplicate/);
144
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { sectionLayout: { order: ["files"], leftSectionIds: ["git"] } } }), /must occur in order/);
145
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { collapsedPanels: {} } }), /name at least one side/);
146
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { collapsedPanels: { left: "yes" } } }), /boolean or null/);
147
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { panelWidths: { left: UI_LAYOUT_LIMITS.panelWidthMin - 1 } } }), /must be between/);
148
+ assert.throws(() => validateUiLayoutPatch({ sidePanel: { panelWidths: { right: UI_LAYOUT_LIMITS.panelWidthMax + 1 } } }), /must be between/);
88
149
  assert.throws(() => validateUiLayoutPatch({ fileViewerWidth: UI_LAYOUT_LIMITS.fileViewerWidthMin - 1 }), /must be between/);
150
+ assert.throws(() => validateUiLayoutPatch({ terminalTabs: { sidebarWidth: UI_LAYOUT_LIMITS.terminalTabsSidebarWidthMin - 1 } }), /must be between/);
89
151
  assert.throws(() => validateUiLayoutPatch({ footerScopedModelOrder: Array(UI_LAYOUT_LIMITS.listItems + 1).fill("model") }), /at most/);
90
152
  assert.throws(() => validateUiLayoutPatch({
91
153
  composerActions: { order: ["a", "b"], grid: { version: 2, columns: 2, positions: { a: 0, b: 0 } } },
@@ -103,7 +165,17 @@ assert.throws(() => validateUiLayoutPatch({
103
165
  }), /only one group/);
104
166
 
105
167
  assert.match(uiLayoutRevision(defaults), /^[a-f0-9]{64}$/);
106
- assert.equal(uiLayoutRevision(defaults), uiLayoutRevision(normalizeUiLayout({ version: 1 })), "equivalent normalized layouts need stable revisions");
107
- assert.notEqual(uiLayoutRevision(defaults), uiLayoutRevision(merged), "layout changes must change the revision");
168
+ assert.equal(uiLayoutRevision(defaults), uiLayoutRevision(normalizeUiLayout({ version: 2 })), "equivalent normalized layouts need stable revisions");
169
+ assert.equal(
170
+ uiLayoutRevision(completeV1),
171
+ uiLayoutRevision(normalizeUiLayout(completeV1)),
172
+ "a migrated v1 envelope and its canonical v2 representation need the same revision",
173
+ );
174
+ assert.notEqual(uiLayoutRevision(valid), uiLayoutRevision(merged), "placement, collapse, and width changes must change the revision");
175
+ assert.notEqual(
176
+ uiLayoutRevision(valid),
177
+ uiLayoutRevision(mergeUiLayout(valid, { sidePanel: { sectionLayout: { order: ["controls", "files", "git", "future-section"], leftSectionIds: ["files"] } } })),
178
+ "atomic assignment/order changes must change the revision",
179
+ );
108
180
 
109
181
  console.log("ui-layout-settings.test.mjs passed");
@@ -2,13 +2,15 @@ import assert from "node:assert/strict";
2
2
  import { spawn } from "node:child_process";
3
3
  import { createServer as createHttpServer } from "node:http";
4
4
  import { createServer as createNetServer } from "node:net";
5
- import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
5
+ import { mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
6
6
  import { tmpdir } from "node:os";
7
7
  import path from "node:path";
8
8
  import { setTimeout as delay } from "node:timers/promises";
9
9
  import { fileURLToPath, pathToFileURL } from "node:url";
10
10
  import { validateUpdateApplyRequest, validateUpdatePlanRequest } from "../lib/component-update-state.mjs";
11
11
  import { exactNpmInstallArgs, exactPackageSpec, updatePlanConfirmationText } from "../lib/update-commands.mjs";
12
+ import { createUpdateJournal } from "../lib/update/journal.mjs";
13
+ import { createUpdatePlan } from "../lib/update/plan.mjs";
12
14
 
13
15
  assert.deepEqual(validateUpdatePlanRequest({ targets: ["pi", "webui"] }), { ok: true, targets: ["pi", "webui"] });
14
16
  for (const invalid of [{}, { targets: [] }, { targets: ["all"] }, { targets: ["pi", "pi"] }, { targets: ["pi"], registry: "https://evil.test" }]) {
@@ -88,18 +90,30 @@ try {
88
90
  assert.doesNotMatch(plan.targets[0].command.args.join(" "), /@latest/);
89
91
  assert.deepEqual(plan.refusals.map((item) => item.id), ["webui"]);
90
92
 
93
+ const updatesDir = path.join(temp, "agent", "webui", "updates");
94
+ const journalsBeforeRefusal = await readdir(updatesDir);
91
95
  const sourcePlanResponse = await fetch(`http://127.0.0.1:${webuiPort}/api/update/plan`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ targets: ["webui"] }) });
92
96
  const sourcePlanPayload = await sourcePlanResponse.json();
93
- assert.equal(sourcePlanResponse.status, 201, JSON.stringify(sourcePlanPayload));
94
- const sourcePlan = sourcePlanPayload.data.plan;
95
- assert.equal(sourcePlan.targets.length, 0);
96
- assert.deepEqual(sourcePlan.refusals.map((item) => item.id), ["webui"]);
97
- const tampered = await fetch(`http://127.0.0.1:${webuiPort}/api/update/apply`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ transactionId: sourcePlan.transactionId, planDigest: "0".repeat(64) }) });
97
+ assert.equal(sourcePlanResponse.status, 409, JSON.stringify(sourcePlanPayload));
98
+ assert.match(sourcePlanPayload.error || "", /no accepted targets/i, "a refused-only plan must fail before confirmation or persistence");
99
+ assert.deepEqual(await readdir(updatesDir), journalsBeforeRefusal, "a refused-only plan must not create an update journal");
100
+
101
+ const legacyRefusedPlan = await createUpdatePlan({
102
+ transactionId: "legacy-refused-only",
103
+ createdAt: "2026-08-14T00:00:00.000Z",
104
+ registry: `http://127.0.0.1:${registryPort}`,
105
+ identities: [],
106
+ candidates: [{ id: "pi", packageName: "@earendil-works/pi-coding-agent", owner: { manager: "unknown" } }],
107
+ resolveExactTarget: () => assert.fail("refused targets must not resolve"),
108
+ });
109
+ await createUpdateJournal(path.join(temp, "agent"), legacyRefusedPlan);
110
+ const refusedApply = await fetch(`http://127.0.0.1:${webuiPort}/api/update/apply`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ transactionId: legacyRefusedPlan.transactionId, planDigest: legacyRefusedPlan.digest }) });
111
+ const refusedApplyPayload = await refusedApply.json();
112
+ assert.equal(refusedApply.status, 409, JSON.stringify(refusedApplyPayload));
113
+ assert.match(refusedApplyPayload.error || "", /no accepted targets/i, "persisted legacy empty plans must also fail before apply");
114
+
115
+ const tampered = await fetch(`http://127.0.0.1:${webuiPort}/api/update/apply`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ transactionId: plan.transactionId, planDigest: "0".repeat(64) }) });
98
116
  assert.equal(tampered.status, 500);
99
- const apply = await fetch(`http://127.0.0.1:${webuiPort}/api/update/apply`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ transactionId: sourcePlan.transactionId, planDigest: sourcePlan.digest }) });
100
- const applyPayload = await apply.json();
101
- assert.equal(apply.status, 200, JSON.stringify(applyPayload));
102
- assert.equal(applyPayload.data.outcome, "failed");
103
117
  const legacy = await fetch(`http://127.0.0.1:${webuiPort}/api/update`, { method: "POST", headers: { "content-type": "application/json" }, body: "{}" });
104
118
  assert.equal(legacy.status, 410);
105
119
  } finally {
@@ -0,0 +1,38 @@
1
+ import assert from "node:assert/strict";
2
+ import path from "node:path";
3
+ import { bundledPackageOwnership, packageOwnerRoot } from "../lib/update/package-layout.mjs";
4
+
5
+ const posixInstall = "/opt/pi-runtime";
6
+ const posixWebui = path.posix.join(posixInstall, "node_modules", "@firstpick", "pi-package-webui");
7
+ const posixPi = path.posix.join(posixInstall, "node_modules", "@earendil-works", "pi-coding-agent");
8
+ assert.equal(packageOwnerRoot(posixWebui, { platform: "linux" }), posixInstall);
9
+ assert.deepEqual(bundledPackageOwnership({ hostPackageRoot: posixWebui, packageRoot: posixPi, source: "bundled" }, { platform: "linux" }), {
10
+ ownerRoot: posixInstall,
11
+ packageRoot: posixPi,
12
+ layout: "hoisted",
13
+ }, "npm-hoisted sibling packages should share one proven installation owner");
14
+
15
+ const nestedPi = path.posix.join(posixWebui, "node_modules", "@earendil-works", "pi-coding-agent");
16
+ assert.deepEqual(bundledPackageOwnership({ hostPackageRoot: posixWebui, packageRoot: nestedPi, source: "bundled" }, { platform: "linux" }), {
17
+ ownerRoot: posixWebui,
18
+ packageRoot: nestedPi,
19
+ layout: "nested",
20
+ }, "package-local bundled Pi remains supported");
21
+
22
+ for (const source of ["explicit", "path", ""]) {
23
+ assert.equal(bundledPackageOwnership({ hostPackageRoot: posixWebui, packageRoot: posixPi, source }, { platform: "linux" }), null, `${source || "empty"} identities must not inherit bundled npm ownership`);
24
+ }
25
+ assert.equal(bundledPackageOwnership({
26
+ hostPackageRoot: posixWebui,
27
+ packageRoot: "/other/node_modules/@earendil-works/pi-coding-agent",
28
+ source: "bundled",
29
+ }, { platform: "linux" }), null, "unrelated package roots must fail closed");
30
+
31
+ const windowsInstall = "C:\\Users\\dev\\.pi\\agent\\webui\\runtimes\\txn-1";
32
+ const windowsWebui = path.win32.join(windowsInstall, "node_modules", "@firstpick", "pi-package-webui");
33
+ const windowsPi = path.win32.join(windowsInstall.toUpperCase(), "node_modules", "@earendil-works", "pi-coding-agent");
34
+ const windowsOwnership = bundledPackageOwnership({ hostPackageRoot: windowsWebui, packageRoot: windowsPi, source: "bundled" }, { platform: "win32" });
35
+ assert.equal(windowsOwnership?.layout, "hoisted");
36
+ assert.equal(windowsOwnership?.ownerRoot.toLowerCase(), windowsInstall.toLowerCase(), "Windows ownership comparison should tolerate path casing differences");
37
+
38
+ console.log("update-package-layout.test.mjs passed");
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import path from "node:path";
3
- import { assertPlanIdentity, assertUpdatePlanDigest, createUpdatePlan, digestUpdatePlan } from "../lib/update/plan.mjs";
3
+ import { assertActionableUpdatePlan, assertPlanIdentity, assertUpdatePlanDigest, createUpdatePlan, digestUpdatePlan } from "../lib/update/plan.mjs";
4
4
 
5
5
  const ownerRoot = path.resolve("tmp", "agent", "npm", "node_modules");
6
6
  let movingLatest = "2.0.0";
@@ -50,6 +50,16 @@ assert.equal(plan.refusals[0].code, "source");
50
50
  assertUpdatePlanDigest(plan, plan.digest);
51
51
  assert.equal(plan.digest, digestUpdatePlan(plan));
52
52
  assertPlanIdentity(plan.targets[0], identity);
53
+ assert.equal(assertActionableUpdatePlan(plan), true);
54
+ const refusedOnlyPlan = await createUpdatePlan({
55
+ transactionId: "refused-only",
56
+ createdAt: "2026-08-07T00:00:00.000Z",
57
+ registry: "https://registry.example.invalid/",
58
+ identities: [],
59
+ candidates: [{ id: "pi", packageName: "@earendil-works/pi-coding-agent", owner: { manager: "unknown" } }],
60
+ resolveExactTarget: () => assert.fail("refused plans must not resolve moving targets"),
61
+ });
62
+ assert.throws(() => assertActionableUpdatePlan(refusedOnlyPlan), { code: "UPDATE_PLAN_NO_TARGETS", statusCode: 409 });
53
63
 
54
64
  movingLatest = "3.0.0";
55
65
  assert.equal(plan.targets[0].targetVersion, "2.0.0", "confirmation remains bound to the originally resolved exact target");
@@ -36,7 +36,7 @@ try {
36
36
  assert.equal(await migrateLegacyWebuiSettings(migratedFile, legacyFile), true);
37
37
  assert.equal(await migrateLegacyWebuiSettings(migratedFile, legacyFile), false, "an existing new target must always win");
38
38
  const migrated = JSON.parse(await readFile(migratedFile, "utf8"));
39
- assert.equal(migrated.version, 6);
39
+ assert.equal(migrated.version, 7);
40
40
  assert.equal(migrated.remoteAuthEnabled, true);
41
41
  assert.deepEqual(migrated.retained, { value: 7 }, "migration must preserve unrelated top-level settings");
42
42
  assert.equal((await readFile(legacyFile, "utf8")).includes('"retained"'), true, "migration must leave the legacy file untouched");
@@ -119,13 +119,43 @@ try {
119
119
  assert.equal(queued.interfacePreferences.sidePanelWidth, 611);
120
120
  assert.equal(queued.gitWorkflow.deliveryMode, "current");
121
121
 
122
- const futureLayout = { version: 2, futureSurface: { order: ["keep-this"] } };
122
+ const futureLayout = { version: 3, futureSurface: { order: ["keep-this"] } };
123
123
  const futureSettings = JSON.parse(await readFile(settingsFile, "utf8"));
124
124
  futureSettings.uiLayout = futureLayout;
125
125
  await writeFile(settingsFile, `${JSON.stringify(futureSettings, null, 2)}\n`, "utf8");
126
126
  await writeWebuiSettings({ remoteAuthEnabled: false }, settingsFile);
127
127
  assert.deepEqual(JSON.parse(await readFile(settingsFile, "utf8")).uiLayout, futureLayout, "unrelated writes must preserve an unknown future layout envelope");
128
- assert.deepEqual((await readWebuiSettings(settingsFile)).uiLayout.sidePanel.sectionOrder, null, "unknown layout versions must still read as safe nullable defaults");
128
+ assert.deepEqual((await readWebuiSettings(settingsFile)).uiLayout.sidePanel.sectionLayout, { order: null, leftSectionIds: null }, "unknown layout versions must still read as safe nullable defaults");
129
+
130
+ const atomicWidthFile = path.join(root, "atomic-width", "settings.json");
131
+ await writeWebuiSettings({
132
+ interfacePreferences: { sidePanelWidth: 612 },
133
+ uiLayout: {
134
+ version: 2,
135
+ sidePanel: {
136
+ placement: "right",
137
+ sectionLayout: { order: ["files", "controls", "git"], leftSectionIds: [] },
138
+ collapsedSectionIds: [],
139
+ hiddenSectionIds: [],
140
+ collapsedPanels: { left: false, right: false },
141
+ panelWidths: { left: 384, right: 612 },
142
+ },
143
+ },
144
+ }, atomicWidthFile);
145
+ await updateWebuiSettings((current) => ({
146
+ interfacePreferences: { sidePanelWidth: 700 },
147
+ uiLayout: {
148
+ ...current.uiLayout,
149
+ sidePanel: {
150
+ ...current.uiLayout.sidePanel,
151
+ panelWidths: { ...current.uiLayout.sidePanel.panelWidths, right: 700 },
152
+ },
153
+ },
154
+ }), atomicWidthFile);
155
+ const atomicWidth = JSON.parse(await readFile(atomicWidthFile, "utf8"));
156
+ assert.equal(atomicWidth.interfacePreferences.sidePanelWidth, 700);
157
+ assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.right, 700, "one locked settings update must atomically persist the v2 right width and legacy mirror");
158
+ assert.equal(atomicWidth.uiLayout.sidePanel.panelWidths.left, 384);
129
159
 
130
160
  const liveLockTarget = path.join(root, "live-lock", "settings.json");
131
161
  const liveLockDirectory = `${liveLockTarget}.lock`;