@firstpick/pi-package-webui 0.8.5 → 0.8.7
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 +18 -584
- package/bin/pi-webui-launcher.mjs +22 -0
- package/bin/pi-webui-update-supervisor.mjs +86 -0
- package/bin/pi-webui.mjs +933 -554
- package/index.ts +16 -6
- package/lib/component-update-state.mjs +21 -0
- package/lib/git-workflow-preferences.mjs +20 -2
- package/lib/optional-feature-catalog.mjs +1 -0
- package/lib/sampling-parameter-capabilities.mjs +160 -0
- package/lib/session-summary-core.mjs +4 -3
- package/lib/session-summary-preferences.mjs +16 -1
- package/lib/subagent-launch-slots.mjs +14 -2
- package/lib/trust-boundaries.mjs +16 -0
- package/lib/update/executor.mjs +99 -0
- package/lib/update/journal.mjs +175 -0
- package/lib/update/owners.mjs +70 -0
- package/lib/update/plan.mjs +134 -0
- package/lib/update/resolver.mjs +168 -0
- package/lib/update/supervisor.mjs +238 -0
- package/lib/update/verify.mjs +52 -0
- package/lib/update-commands.mjs +25 -13
- package/lib/webui-workspaces.mjs +17 -1
- package/lib/workspace-session-summaries.mjs +400 -0
- package/package.json +4 -4
- package/public/app.js +2487 -349
- package/public/index.html +200 -51
- package/public/middle-button-drag-scroll.mjs +154 -0
- package/public/sampling-parameter-controls.mjs +361 -0
- package/public/service-worker.js +5 -1
- package/public/stream-output-controller.mjs +327 -0
- package/public/styles.css +666 -71
- package/public/theme-contract.mjs +244 -0
- package/session-summary.ts +164 -4
- package/tests/aur-review-widget-static.test.mjs +2 -1
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/control-deck-component-updates.spec.mjs +20 -22
- package/tests/browser/interaction-continuity.spec.mjs +2 -2
- package/tests/browser/middle-button-drag-scroll.spec.mjs +145 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +68 -23
- package/tests/browser/sampling-tooltip.spec.mjs +228 -0
- package/tests/browser/session-summary.spec.mjs +131 -3
- package/tests/browser/stream-output-isolation.spec.mjs +510 -0
- package/tests/browser/update-reconnect.spec.mjs +92 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/common-options-submenus-interaction-static.test.mjs +172 -0
- package/tests/common-options-submenus-markup-static.test.mjs +152 -0
- package/tests/component-update-api-static.test.mjs +22 -61
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-deck-component-updates-static.test.mjs +13 -237
- package/tests/durable-rpc-supervisor-harness.test.mjs +3 -1
- package/tests/fast-mode-client-static.test.mjs +3 -2
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/feature-system-prompt-optional-feature-static.test.mjs +49 -0
- package/tests/fixtures/fake-pi.mjs +269 -2
- package/tests/fixtures/update/tree-timeout-descendant.mjs +6 -0
- package/tests/fixtures/update/tree-timeout-parent.mjs +11 -0
- package/tests/git-footer-context-menu-static.test.mjs +58 -0
- package/tests/git-workflow-preferences.test.mjs +7 -1
- package/tests/guided-git-aur-review.test.mjs +4 -3
- package/tests/http-endpoints-harness.test.mjs +274 -23
- package/tests/middle-button-drag-scroll-static.test.mjs +24 -0
- package/tests/middle-button-drag-scroll.test.mjs +170 -0
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +5 -6
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +85 -50
- package/tests/native-parity.test.mjs +1 -1
- package/tests/open-issue-wizard-static.test.mjs +2 -3
- package/tests/optional-feature-migration-frontend.test.mjs +9 -5
- package/tests/persistent-ui-layout-static.test.mjs +13 -2
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +43 -0
- package/tests/rpc-supervisor-host.test.mjs +11 -2
- package/tests/safety-guard-auto-review-harness.test.mjs +117 -0
- package/tests/safety-guard-auto-review-static.test.mjs +34 -0
- package/tests/sampling-native-controls-user-flow.test.mjs +752 -0
- package/tests/sampling-parameter-capabilities.test.mjs +167 -0
- package/tests/sampling-parameter-controls.test.mjs +241 -0
- package/tests/session-sampling-helper.test.mjs +228 -0
- package/tests/session-sampling-http.test.mjs +168 -0
- package/tests/session-sampling-ui-static.test.mjs +370 -0
- package/tests/session-summary-core.test.mjs +205 -10
- package/tests/side-panel-section-height-removal-static.test.mjs +34 -0
- package/tests/side-panel-section-reorder-static.test.mjs +3 -3
- package/tests/staged-content-hash-contract.test.mjs +52 -11
- package/tests/stream-lifecycle-core.test.mjs +134 -0
- package/tests/stream-output-controller.test.mjs +252 -0
- package/tests/stream-output-isolation-static.test.mjs +89 -0
- package/tests/streaming-ui-coupling.test.mjs +50 -0
- package/tests/subagent-gate-visibility.test.mjs +1 -1
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagent-launch-slots.test.mjs +18 -1
- package/tests/theme-contract.test.mjs +104 -0
- package/tests/theme-customizer-static.test.mjs +82 -0
- package/tests/theme-scheme-mode.test.mjs +15 -0
- package/tests/ui-layout-settings.test.mjs +18 -1
- package/tests/update-api-harness.test.mjs +111 -0
- package/tests/update-commands.test.mjs +15 -45
- package/tests/update-executor-process-tree-harness.test.mjs +22 -0
- package/tests/update-journal-harness.test.mjs +59 -0
- package/tests/update-lock-multiprocess-harness.test.mjs +46 -0
- package/tests/update-owners.test.mjs +27 -0
- package/tests/update-plan.test.mjs +58 -0
- package/tests/update-resolver.test.mjs +56 -0
- package/tests/update-supervisor-harness.test.mjs +57 -0
- package/tests/update-tab-restore-harness.test.mjs +24 -0
- package/tests/update-verify.test.mjs +31 -0
- package/tests/workspace-files-live-updates-static.test.mjs +13 -4
- package/tests/workspace-session-summaries.test.mjs +288 -0
- package/webui-rpc-helper.mjs +119 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import vm from "node:vm";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import {
|
|
7
|
+
SAMPLING_PARAMETER_CATALOG,
|
|
8
|
+
buildSamplingParametersFromDraft,
|
|
9
|
+
createSamplingControlDraft,
|
|
10
|
+
samplingControlDraftEquals,
|
|
11
|
+
samplingParameterCapability,
|
|
12
|
+
samplingParameterSliderValue,
|
|
13
|
+
splitSamplingParameters,
|
|
14
|
+
summarizePreservedSamplingParameters,
|
|
15
|
+
validateSamplingControlDraft,
|
|
16
|
+
} from "../public/sampling-parameter-controls.mjs";
|
|
17
|
+
|
|
18
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
19
|
+
const appJs = await readFile(join(root, "public", "app.js"), "utf8");
|
|
20
|
+
|
|
21
|
+
// Extract the sampling parameter control block from app.js
|
|
22
|
+
const blockStart = appJs.indexOf("function samplingParametersPath(");
|
|
23
|
+
const blockEnd = appJs.indexOf("\nfunction sessionCopyButton(", blockStart);
|
|
24
|
+
assert.ok(blockStart >= 0 && blockEnd > blockStart, "sampling browser state block must be present in app.js");
|
|
25
|
+
const samplingBlock = appJs.slice(blockStart, blockEnd);
|
|
26
|
+
|
|
27
|
+
// MockElement class for full DOM event and hierarchy simulation
|
|
28
|
+
class MockElement {
|
|
29
|
+
constructor(tagName = "div") {
|
|
30
|
+
this.tagName = String(tagName).toUpperCase();
|
|
31
|
+
this.children = [];
|
|
32
|
+
this.listeners = new Map();
|
|
33
|
+
this.attributes = new Map();
|
|
34
|
+
this.classList = {
|
|
35
|
+
_set: new Set(),
|
|
36
|
+
add: (...names) => names.forEach((n) => this.classList._set.add(n)),
|
|
37
|
+
remove: (...names) => names.forEach((n) => this.classList._set.delete(n)),
|
|
38
|
+
toggle: (name, force) => {
|
|
39
|
+
if (force === undefined) force = !this.classList._set.has(name);
|
|
40
|
+
if (force) this.classList._set.add(name);
|
|
41
|
+
else this.classList._set.delete(name);
|
|
42
|
+
return force;
|
|
43
|
+
},
|
|
44
|
+
contains: (name) => this.classList._set.has(name),
|
|
45
|
+
};
|
|
46
|
+
this.dataset = {};
|
|
47
|
+
this._value = "";
|
|
48
|
+
this._checked = false;
|
|
49
|
+
this._disabled = false;
|
|
50
|
+
this._hidden = false;
|
|
51
|
+
this._hovered = false;
|
|
52
|
+
this._textContent = "";
|
|
53
|
+
this.id = "";
|
|
54
|
+
this.type = "";
|
|
55
|
+
this.htmlFor = "";
|
|
56
|
+
this.tabIndex = -1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get value() { return this._value; }
|
|
60
|
+
set value(v) { this._value = String(v ?? ""); }
|
|
61
|
+
|
|
62
|
+
get checked() { return Boolean(this._checked); }
|
|
63
|
+
set checked(v) { this._checked = Boolean(v); }
|
|
64
|
+
|
|
65
|
+
get disabled() { return Boolean(this._disabled); }
|
|
66
|
+
set disabled(v) { this._disabled = Boolean(v); }
|
|
67
|
+
|
|
68
|
+
get hidden() { return Boolean(this._hidden); }
|
|
69
|
+
set hidden(v) { this._hidden = Boolean(v); }
|
|
70
|
+
|
|
71
|
+
get textContent() { return this._textContent; }
|
|
72
|
+
set textContent(v) { this._textContent = String(v ?? ""); }
|
|
73
|
+
|
|
74
|
+
get className() { return Array.from(this.classList._set).join(" "); }
|
|
75
|
+
set className(v) {
|
|
76
|
+
this.classList._set.clear();
|
|
77
|
+
if (v) String(v).split(/\s+/).forEach((n) => this.classList._set.add(n));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
append(...nodes) {
|
|
81
|
+
for (const child of nodes) {
|
|
82
|
+
if (child) this.children.push(child);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setAttribute(name, value) { this.attributes.set(name, String(value)); }
|
|
87
|
+
getAttribute(name) { return this.attributes.get(name) ?? null; }
|
|
88
|
+
removeAttribute(name) { this.attributes.delete(name); }
|
|
89
|
+
|
|
90
|
+
addEventListener(type, listener) {
|
|
91
|
+
if (!this.listeners.has(type)) this.listeners.set(type, []);
|
|
92
|
+
this.listeners.get(type).push(listener);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
contains(node) {
|
|
96
|
+
return node === this || this.children.some((child) => child?.contains?.(node));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
matches(selector) {
|
|
100
|
+
return selector === ":hover" ? this._hovered : false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
dispatchEvent(eventOrType) {
|
|
104
|
+
const event = typeof eventOrType === "string" ? { type: eventOrType } : eventOrType;
|
|
105
|
+
if (event.type === "pointerenter") this._hovered = true;
|
|
106
|
+
if (event.type === "pointerleave") this._hovered = false;
|
|
107
|
+
event.target ||= this;
|
|
108
|
+
event.currentTarget = this;
|
|
109
|
+
event.defaultPrevented ||= false;
|
|
110
|
+
event.propagationStopped ||= false;
|
|
111
|
+
event.preventDefault ||= () => { event.defaultPrevented = true; };
|
|
112
|
+
event.stopPropagation ||= () => { event.propagationStopped = true; };
|
|
113
|
+
const list = this.listeners.get(event.type) || [];
|
|
114
|
+
for (const listener of list) listener(event);
|
|
115
|
+
return !event.defaultPrevented;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function createHarness() {
|
|
120
|
+
const elements = {
|
|
121
|
+
samplingParametersControls: new MockElement("div"),
|
|
122
|
+
samplingParametersPreserved: new MockElement("p"),
|
|
123
|
+
applySamplingParametersButton: new MockElement("button"),
|
|
124
|
+
resetSamplingParametersButton: new MockElement("button"),
|
|
125
|
+
reloadSamplingParametersButton: new MockElement("button"),
|
|
126
|
+
samplingParametersSupport: new MockElement("p"),
|
|
127
|
+
samplingParametersStatus: new MockElement("p"),
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const requests = [];
|
|
131
|
+
let sectionActive = true;
|
|
132
|
+
let nextResponse = null;
|
|
133
|
+
let nextError = null;
|
|
134
|
+
let responseGate = null;
|
|
135
|
+
|
|
136
|
+
const mockDocument = {
|
|
137
|
+
createElement(tagName) {
|
|
138
|
+
return new MockElement(tagName);
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const plain = (v) => JSON.parse(JSON.stringify(v ?? null));
|
|
143
|
+
const hostValue = (value, fallback = undefined) => (value === undefined ? fallback : JSON.parse(JSON.stringify(value)));
|
|
144
|
+
|
|
145
|
+
const context = {
|
|
146
|
+
console,
|
|
147
|
+
document: mockDocument,
|
|
148
|
+
elements,
|
|
149
|
+
SAMPLING_PARAMETER_CATALOG,
|
|
150
|
+
buildSamplingParametersFromDraft: (draft) => buildSamplingParametersFromDraft(hostValue(draft, null)),
|
|
151
|
+
createSamplingControlDraft: (parameters, options) => createSamplingControlDraft(hostValue(parameters, {}), hostValue(options, {})),
|
|
152
|
+
samplingControlDraftEquals: (left, right) => samplingControlDraftEquals(hostValue(left, null), hostValue(right, null)),
|
|
153
|
+
samplingParameterCapability: (parameters, key) => samplingParameterCapability(hostValue(parameters, undefined), key),
|
|
154
|
+
samplingParameterSliderValue,
|
|
155
|
+
splitSamplingParameters: (parameters) => splitSamplingParameters(hostValue(parameters, {})),
|
|
156
|
+
summarizePreservedSamplingParameters: (parameters) => summarizePreservedSamplingParameters(hostValue(parameters, {})),
|
|
157
|
+
validateSamplingControlDraft: (draft) => validateSamplingControlDraft(hostValue(draft, null)),
|
|
158
|
+
sidePanelSectionRecords: () => [{
|
|
159
|
+
id: "sampling",
|
|
160
|
+
section: { hidden: !sectionActive, classList: { contains: () => !sectionActive } },
|
|
161
|
+
}],
|
|
162
|
+
api: async (path, options = {}) => {
|
|
163
|
+
requests.push({ path, method: options.method || "GET", body: plain(options.body), scoped: options.scoped });
|
|
164
|
+
if (responseGate) await responseGate;
|
|
165
|
+
if (nextError) throw nextError;
|
|
166
|
+
return { data: plain(nextResponse) };
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
vm.runInNewContext(`
|
|
171
|
+
let samplingParametersState = null;
|
|
172
|
+
let samplingParametersStateTabId = null;
|
|
173
|
+
const samplingParametersDrafts = new Map();
|
|
174
|
+
let samplingParametersLoading = false;
|
|
175
|
+
let samplingParametersBusy = false;
|
|
176
|
+
let samplingParametersError = "";
|
|
177
|
+
let samplingParametersNotice = "";
|
|
178
|
+
let samplingParametersFeedbackTabId = null;
|
|
179
|
+
let samplingParametersRequestSerial = 0;
|
|
180
|
+
let activeTabId = "tab-a";
|
|
181
|
+
function activeTabContext(tabId = activeTabId) { return { tabId: tabId || null, generation: 0 }; }
|
|
182
|
+
${samplingBlock}
|
|
183
|
+
globalThis.samplingHarness = {
|
|
184
|
+
setActiveTab(value) { activeTabId = value; },
|
|
185
|
+
setDraft(value, tabId = activeTabId) { setSamplingParametersDraft(value, tabId); },
|
|
186
|
+
draft(tabId = activeTabId) { return samplingParametersDraft(tabId); },
|
|
187
|
+
editable(tabId = activeTabId) { return samplingParametersEditableDraft(tabId); },
|
|
188
|
+
dirty: samplingParametersDraftIsDirty,
|
|
189
|
+
state() { return samplingParametersState; },
|
|
190
|
+
stateTabId() { return samplingParametersStateTabId; },
|
|
191
|
+
render: renderSamplingParameters,
|
|
192
|
+
load: loadSamplingParameters,
|
|
193
|
+
refresh: refreshSamplingParametersForTabContext,
|
|
194
|
+
apply: applySamplingParameters,
|
|
195
|
+
reset: resetSamplingParameters,
|
|
196
|
+
ensureLoaded: ensureSamplingParametersLoaded,
|
|
197
|
+
getControlsMap() { return samplingParameterControlElements; },
|
|
198
|
+
};
|
|
199
|
+
`, context);
|
|
200
|
+
|
|
201
|
+
const harness = context.samplingHarness;
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
harness,
|
|
205
|
+
elements,
|
|
206
|
+
requests,
|
|
207
|
+
getControl(key) {
|
|
208
|
+
return harness.getControlsMap().get(key);
|
|
209
|
+
},
|
|
210
|
+
setNextResponse(res) { nextResponse = res; },
|
|
211
|
+
setNextError(err) { nextError = err; },
|
|
212
|
+
setResponseGate(gate) { responseGate = gate; },
|
|
213
|
+
setSectionActive(active) { sectionActive = active; },
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function capabilitiesFor(supportedKeys, api = "fixture-api") {
|
|
218
|
+
const supported = new Set(supportedKeys);
|
|
219
|
+
return Object.fromEntries(SAMPLING_PARAMETER_CATALOG.map(({ key, label }) => [key, {
|
|
220
|
+
supported: supported.has(key),
|
|
221
|
+
reason: supported.has(key) ? `Supported by ${api}.` : `${api} does not declare ${label} support.`,
|
|
222
|
+
source: supported.has(key) ? "api" : "unsupported",
|
|
223
|
+
}]));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const supportedState = (session = {}, defaults = { temperature: 1, top_p: 0.95 }) => ({
|
|
227
|
+
session,
|
|
228
|
+
defaults,
|
|
229
|
+
effective: { ...defaults, ...session },
|
|
230
|
+
support: {
|
|
231
|
+
supported: true,
|
|
232
|
+
api: "openai-completions",
|
|
233
|
+
model: { provider: "openai", id: "gpt-5", name: "GPT-5" },
|
|
234
|
+
parameters: capabilitiesFor(SAMPLING_PARAMETER_CATALOG.map(({ key }) => key), "openai-completions"),
|
|
235
|
+
compatibleApis: ["openai-completions", "openai-responses", "azure-openai-responses"],
|
|
236
|
+
message: "Session sampling parameters apply to subsequent provider requests.",
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// --- Test 1: Enable / Disable Semantics ---
|
|
241
|
+
{
|
|
242
|
+
const { harness, elements, requests, getControl, setNextResponse } = createHarness();
|
|
243
|
+
setNextResponse(supportedState({}, { temperature: 1 }));
|
|
244
|
+
await harness.load({ tabId: "tab-a" });
|
|
245
|
+
|
|
246
|
+
const tempControl = getControl("temperature");
|
|
247
|
+
assert.equal(tempControl.enable.checked, false, "initially temperature is disabled");
|
|
248
|
+
assert.equal(tempControl.tooltip.hidden, true, "supported controls should hide unused tooltip nodes");
|
|
249
|
+
assert.equal(tempControl.tooltip.textContent, "", "supported controls should clear unused tooltip text");
|
|
250
|
+
assert.equal(tempControl.row.getAttribute("aria-describedby"), null, "supported controls should not reference an unsupported reason");
|
|
251
|
+
|
|
252
|
+
// User checks enable checkbox for temperature
|
|
253
|
+
tempControl.enable.checked = true;
|
|
254
|
+
tempControl.enable.dispatchEvent("change");
|
|
255
|
+
|
|
256
|
+
// User types 0.7 into exact value number input
|
|
257
|
+
tempControl.number.value = "0.7";
|
|
258
|
+
tempControl.number.dispatchEvent("input");
|
|
259
|
+
|
|
260
|
+
assert.equal(harness.dirty("tab-a"), true, "draft should be marked dirty after user interaction");
|
|
261
|
+
|
|
262
|
+
requests.length = 0;
|
|
263
|
+
setNextResponse(supportedState({ temperature: 0.7 }));
|
|
264
|
+
await harness.apply();
|
|
265
|
+
|
|
266
|
+
assert.equal(requests.length, 1);
|
|
267
|
+
assert.equal(requests[0].method, "PUT");
|
|
268
|
+
assert.deepEqual(requests[0].body, { temperature: 0.7 }, "Apply should include enabled temperature in payload");
|
|
269
|
+
|
|
270
|
+
// User unchecks enable checkbox for temperature
|
|
271
|
+
tempControl.enable.checked = false;
|
|
272
|
+
tempControl.enable.dispatchEvent("change");
|
|
273
|
+
|
|
274
|
+
requests.length = 0;
|
|
275
|
+
setNextResponse(supportedState({}));
|
|
276
|
+
await harness.apply();
|
|
277
|
+
|
|
278
|
+
assert.equal(requests.length, 1);
|
|
279
|
+
assert.deepEqual(requests[0].body, {}, "Disabling temperature should exclude key from payload");
|
|
280
|
+
console.log("✓ Test 1: Enable / Disable Semantics passed");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// --- Test 2: Number / Range Synchronization ---
|
|
284
|
+
{
|
|
285
|
+
const { harness, getControl, setNextResponse } = createHarness();
|
|
286
|
+
setNextResponse(supportedState({ temperature: 1 }));
|
|
287
|
+
await harness.load({ tabId: "tab-a" });
|
|
288
|
+
|
|
289
|
+
const tempControl = getControl("temperature");
|
|
290
|
+
|
|
291
|
+
// Entering value into number input updates draft and syncs range slider
|
|
292
|
+
tempControl.number.value = "0.45";
|
|
293
|
+
tempControl.number.dispatchEvent("input");
|
|
294
|
+
|
|
295
|
+
assert.equal(tempControl.range.value, "0.45", "range input visual value should mirror number input");
|
|
296
|
+
assert.equal(harness.editable("tab-a").controls.temperature.value, "0.45");
|
|
297
|
+
|
|
298
|
+
// Sliding range input updates draft and number input
|
|
299
|
+
tempControl.range.value = "1.2";
|
|
300
|
+
tempControl.range.dispatchEvent("input");
|
|
301
|
+
|
|
302
|
+
assert.equal(tempControl.number.value, "1.2", "number input value should mirror range slider movement");
|
|
303
|
+
assert.equal(harness.editable("tab-a").controls.temperature.value, "1.2");
|
|
304
|
+
console.log("✓ Test 2: Number / Range Synchronization passed");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// --- Test 3: Exact Values Outside Soft Slider Bounds ---
|
|
308
|
+
{
|
|
309
|
+
const { harness, requests, getControl, setNextResponse } = createHarness();
|
|
310
|
+
setNextResponse(supportedState({}));
|
|
311
|
+
await harness.load({ tabId: "tab-a" });
|
|
312
|
+
|
|
313
|
+
const topKControl = getControl("top_k");
|
|
314
|
+
topKControl.enable.checked = true;
|
|
315
|
+
topKControl.enable.dispatchEvent("change");
|
|
316
|
+
|
|
317
|
+
// Setting top_k = 1000 via exact number input (soft slider max is 200)
|
|
318
|
+
topKControl.number.value = "1000";
|
|
319
|
+
topKControl.number.dispatchEvent("input");
|
|
320
|
+
|
|
321
|
+
assert.equal(topKControl.number.value, "1000");
|
|
322
|
+
assert.equal(topKControl.range.value, "200", "slider position should clamp visually to common max 200");
|
|
323
|
+
|
|
324
|
+
requests.length = 0;
|
|
325
|
+
setNextResponse(supportedState({ top_k: 1000 }));
|
|
326
|
+
await harness.apply();
|
|
327
|
+
|
|
328
|
+
assert.equal(requests[0].body.top_k, 1000, "authoritative exact number 1000 must be sent in PUT body");
|
|
329
|
+
|
|
330
|
+
// Setting seed = -1 (soft slider min is 0)
|
|
331
|
+
const seedControl = getControl("seed");
|
|
332
|
+
seedControl.enable.checked = true;
|
|
333
|
+
seedControl.enable.dispatchEvent("change");
|
|
334
|
+
seedControl.number.value = "-1";
|
|
335
|
+
seedControl.number.dispatchEvent("input");
|
|
336
|
+
|
|
337
|
+
assert.equal(seedControl.number.value, "-1");
|
|
338
|
+
assert.equal(seedControl.range.value, "0", "slider position for seed -1 should clamp visually to 0");
|
|
339
|
+
|
|
340
|
+
requests.length = 0;
|
|
341
|
+
setNextResponse(supportedState({ top_k: 1000, seed: -1 }));
|
|
342
|
+
await harness.apply();
|
|
343
|
+
|
|
344
|
+
assert.equal(requests[0].body.seed, -1, "exact seed value -1 must be sent in PUT body");
|
|
345
|
+
console.log("✓ Test 3: Exact Values Outside Soft Slider Bounds passed");
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// --- Test 4: Invalid Value Blocking and Accessible Error State ---
|
|
349
|
+
{
|
|
350
|
+
const { harness, elements, requests, getControl, setNextResponse } = createHarness();
|
|
351
|
+
setNextResponse(supportedState({}));
|
|
352
|
+
await harness.load({ tabId: "tab-a" });
|
|
353
|
+
|
|
354
|
+
const topPControl = getControl("top_p");
|
|
355
|
+
topPControl.enable.checked = true;
|
|
356
|
+
topPControl.enable.dispatchEvent("change");
|
|
357
|
+
|
|
358
|
+
// Enter invalid top_p = 0 (top_p must be > 0 and <= 1)
|
|
359
|
+
topPControl.number.value = "0";
|
|
360
|
+
topPControl.number.dispatchEvent("input");
|
|
361
|
+
|
|
362
|
+
assert.equal(topPControl.number.getAttribute("aria-invalid"), "true", "invalid field must set aria-invalid=true");
|
|
363
|
+
assert.ok(topPControl.row.classList.contains("invalid"), "invalid row must have .invalid class");
|
|
364
|
+
assert.match(topPControl.error.textContent, /greater than 0/, "field error paragraph must explain the restriction");
|
|
365
|
+
assert.equal(topPControl.error.hidden, false, "field error element must be visible");
|
|
366
|
+
assert.equal(elements.applySamplingParametersButton.disabled, true, "Apply button must be disabled for invalid draft");
|
|
367
|
+
|
|
368
|
+
requests.length = 0;
|
|
369
|
+
await harness.apply();
|
|
370
|
+
assert.equal(requests.length, 0, "applySamplingParameters must not make HTTP request when draft is invalid");
|
|
371
|
+
|
|
372
|
+
// Fix the invalid value
|
|
373
|
+
topPControl.number.value = "0.95";
|
|
374
|
+
topPControl.number.dispatchEvent("input");
|
|
375
|
+
|
|
376
|
+
assert.equal(topPControl.number.getAttribute("aria-invalid"), "false");
|
|
377
|
+
assert.equal(topPControl.row.classList.contains("invalid"), false);
|
|
378
|
+
assert.equal(elements.applySamplingParametersButton.disabled, false, "Apply button should be enabled once valid");
|
|
379
|
+
console.log("✓ Test 4: Invalid Value Blocking and Accessible Error State passed");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// --- Test 5: Unknown-Key Preservation ---
|
|
383
|
+
{
|
|
384
|
+
const { harness, elements, requests, getControl, setNextResponse } = createHarness();
|
|
385
|
+
// Server state has unknown keys: custom_vendor_key and llama_mirostat
|
|
386
|
+
setNextResponse(supportedState(
|
|
387
|
+
{ temperature: 0.5, custom_vendor_key: "special_value", llama_mirostat: 2 },
|
|
388
|
+
{ temperature: 1 },
|
|
389
|
+
));
|
|
390
|
+
await harness.load({ tabId: "tab-a" });
|
|
391
|
+
|
|
392
|
+
assert.match(
|
|
393
|
+
elements.samplingParametersPreserved.textContent,
|
|
394
|
+
/2 additional parameters are preserved outside this editor/,
|
|
395
|
+
"preservation element should report correct unknown key count",
|
|
396
|
+
);
|
|
397
|
+
assert.doesNotMatch(elements.samplingParametersPreserved.textContent, /custom_vendor_key/);
|
|
398
|
+
|
|
399
|
+
// User edits a known parameter (enables min_p = 0.05)
|
|
400
|
+
const minPControl = getControl("min_p");
|
|
401
|
+
minPControl.enable.checked = true;
|
|
402
|
+
minPControl.enable.dispatchEvent("change");
|
|
403
|
+
minPControl.number.value = "0.05";
|
|
404
|
+
minPControl.number.dispatchEvent("input");
|
|
405
|
+
|
|
406
|
+
requests.length = 0;
|
|
407
|
+
setNextResponse(supportedState({ temperature: 0.5, custom_vendor_key: "special_value", llama_mirostat: 2, min_p: 0.05 }));
|
|
408
|
+
await harness.apply();
|
|
409
|
+
|
|
410
|
+
assert.equal(requests.length, 1);
|
|
411
|
+
assert.deepEqual(requests[0].body, {
|
|
412
|
+
custom_vendor_key: "special_value",
|
|
413
|
+
llama_mirostat: 2,
|
|
414
|
+
temperature: 0.5,
|
|
415
|
+
min_p: 0.05,
|
|
416
|
+
}, "PUT body must preserve unknown keys alongside updated known parameter controls");
|
|
417
|
+
console.log("✓ Test 5: Unknown-Key Preservation passed");
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// --- Test 6: Reset Semantics ---
|
|
421
|
+
{
|
|
422
|
+
const { harness, elements, requests, setNextResponse } = createHarness();
|
|
423
|
+
setNextResponse(supportedState({ temperature: 0.8, vendor_key: "preserved" }));
|
|
424
|
+
await harness.load({ tabId: "tab-a" });
|
|
425
|
+
|
|
426
|
+
requests.length = 0;
|
|
427
|
+
setNextResponse(supportedState({}, { temperature: 1 }));
|
|
428
|
+
await harness.reset();
|
|
429
|
+
|
|
430
|
+
assert.equal(requests.length, 1);
|
|
431
|
+
assert.equal(requests[0].method, "PUT");
|
|
432
|
+
assert.deepEqual(requests[0].body, {}, "Reset must send empty object {} to clear both known and unknown session overrides");
|
|
433
|
+
assert.match(elements.samplingParametersStatus.textContent, /Session override cleared/);
|
|
434
|
+
assert.match(elements.samplingParametersPreserved.textContent, /No additional parameters/);
|
|
435
|
+
console.log("✓ Test 6: Reset Semantics passed");
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// --- Test 7: Tab-Isolated Drafts Including Delayed Responses ---
|
|
439
|
+
{
|
|
440
|
+
const { harness, requests, getControl, setNextResponse, setResponseGate } = createHarness();
|
|
441
|
+
setNextResponse(supportedState({ temperature: 0.5 }));
|
|
442
|
+
await harness.load({ tabId: "tab-a" });
|
|
443
|
+
|
|
444
|
+
// User edits temperature on tab-a
|
|
445
|
+
const tempControl = getControl("temperature");
|
|
446
|
+
tempControl.number.value = "0.2";
|
|
447
|
+
tempControl.number.dispatchEvent("input");
|
|
448
|
+
|
|
449
|
+
// Switch to tab-b
|
|
450
|
+
harness.setActiveTab("tab-b");
|
|
451
|
+
setNextResponse(supportedState({ top_p: 0.9 }));
|
|
452
|
+
await harness.load({ tabId: "tab-b", force: true });
|
|
453
|
+
|
|
454
|
+
const topPControl = getControl("top_p");
|
|
455
|
+
assert.equal(topPControl.enable.checked, true, "tab-b should reflect tab-b's state");
|
|
456
|
+
assert.equal(getControl("temperature").enable.checked, false, "tab-a draft should not bleed into tab-b controls");
|
|
457
|
+
|
|
458
|
+
// Refresh tab-a beneath its preserved draft before starting a delayed write.
|
|
459
|
+
harness.setActiveTab("tab-a");
|
|
460
|
+
setNextResponse(supportedState({ temperature: 0.5 }));
|
|
461
|
+
await harness.load({ tabId: "tab-a" });
|
|
462
|
+
|
|
463
|
+
let releaseGate;
|
|
464
|
+
setResponseGate(new Promise((resolve) => { releaseGate = resolve; }));
|
|
465
|
+
setNextResponse(supportedState({ temperature: 0.2 }));
|
|
466
|
+
const inFlightWrite = harness.apply();
|
|
467
|
+
await Promise.resolve();
|
|
468
|
+
|
|
469
|
+
// Switch to tab-b while tab-a PUT is in-flight. The completed write clears only tab-a's draft.
|
|
470
|
+
harness.setActiveTab("tab-b");
|
|
471
|
+
releaseGate();
|
|
472
|
+
await inFlightWrite;
|
|
473
|
+
setResponseGate(null);
|
|
474
|
+
setNextResponse(supportedState({ top_p: 0.9 }));
|
|
475
|
+
await harness.load({ tabId: "tab-b", force: true });
|
|
476
|
+
assert.equal(topPControl.enable.checked, true, "tab-b controls must reload intact after tab-a's delayed PUT resolves");
|
|
477
|
+
|
|
478
|
+
// Switch back to tab-a: tab-a's draft was cleared by successful Apply, and loading tab-a fetches tab-a's updated state
|
|
479
|
+
harness.setActiveTab("tab-a");
|
|
480
|
+
setNextResponse(supportedState({ temperature: 0.2 }));
|
|
481
|
+
await harness.load({ tabId: "tab-a", force: true });
|
|
482
|
+
assert.equal(getControl("temperature").enable.checked, true);
|
|
483
|
+
assert.equal(getControl("temperature").number.value, "0.2");
|
|
484
|
+
assert.equal(harness.draft("tab-a"), null, "successful PUT should clear tab-a's draft");
|
|
485
|
+
console.log("✓ Test 7: Tab-Isolated Drafts Including Delayed Responses passed");
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// --- Test 8: Unsupported Model Behavior ---
|
|
489
|
+
{
|
|
490
|
+
const { harness, elements, requests, getControl, setNextResponse } = createHarness();
|
|
491
|
+
const unsupportedState = {
|
|
492
|
+
session: { temperature: 0.7 },
|
|
493
|
+
defaults: {},
|
|
494
|
+
effective: {},
|
|
495
|
+
support: {
|
|
496
|
+
supported: false,
|
|
497
|
+
api: "anthropic-messages",
|
|
498
|
+
model: { provider: "anthropic", id: "claude-sonnet-3.5", name: "Claude Sonnet" },
|
|
499
|
+
parameters: capabilitiesFor([], "anthropic-messages"),
|
|
500
|
+
compatibleApis: ["openai-completions", "openai-responses", "azure-openai-responses"],
|
|
501
|
+
message: "Session sampling parameters are stored but not applied to anthropic-messages.",
|
|
502
|
+
},
|
|
503
|
+
};
|
|
504
|
+
setNextResponse(unsupportedState);
|
|
505
|
+
await harness.load({ tabId: "tab-a" });
|
|
506
|
+
|
|
507
|
+
assert.equal(elements.applySamplingParametersButton.disabled, true, "Apply button must be disabled for unsupported model API");
|
|
508
|
+
assert.match(elements.samplingParametersSupport.textContent, /anthropic-messages/);
|
|
509
|
+
assert.match(elements.samplingParametersStatus.textContent, /no verified sampling parameters/);
|
|
510
|
+
|
|
511
|
+
const tempControl = getControl("temperature");
|
|
512
|
+
assert.equal(tempControl.enable.checked, true, "stored controls must remain visible and checked");
|
|
513
|
+
assert.equal(tempControl.number.value, "0.7", "stored values must be readable");
|
|
514
|
+
assert.equal(tempControl.enable.disabled, true, "an unsupported checkbox must be disabled without clearing its checked state");
|
|
515
|
+
assert.equal(tempControl.number.disabled, true, "an unsupported exact input must be disabled");
|
|
516
|
+
assert.equal(tempControl.range.disabled, true, "an unsupported range input must be disabled");
|
|
517
|
+
assert.equal(tempControl.row.tabIndex, 0, "the unsupported row must remain keyboard focusable");
|
|
518
|
+
assert.equal(tempControl.row.getAttribute("aria-disabled"), "true");
|
|
519
|
+
assert.equal(tempControl.row.getAttribute("aria-describedby"), tempControl.tooltip.id, "the focusable row must expose the tooltip reason as its accessible description");
|
|
520
|
+
assert.equal(tempControl.enable.getAttribute("aria-describedby"), tempControl.tooltip.id, "the disabled checkbox must expose the same reason");
|
|
521
|
+
assert.equal(tempControl.tooltip.getAttribute("role"), "tooltip");
|
|
522
|
+
assert.equal(tempControl.tooltip.hidden, false, "the unsupported reason must remain available to pointer, focus, and assistive technology");
|
|
523
|
+
assert.match(tempControl.tooltip.textContent, /does not declare Temperature support/);
|
|
524
|
+
assert.match(elements.samplingParametersSupport.textContent, /Sampling-capable APIs:/, "the diagnostic list should describe API-level sampling capability");
|
|
525
|
+
assert.doesNotMatch(elements.samplingParametersSupport.textContent, /Compatible APIs:/, "the diagnostic label must not imply universal per-parameter support");
|
|
526
|
+
|
|
527
|
+
const escapeEvent = { type: "keydown", key: "Escape" };
|
|
528
|
+
assert.equal(tempControl.row.dispatchEvent(escapeEvent), false, "Escape dismissal should consume the scoped key event");
|
|
529
|
+
assert.equal(tempControl.row.classList.contains("sampling-tooltip-dismissed"), true);
|
|
530
|
+
tempControl.row.dispatchEvent("pointerleave");
|
|
531
|
+
assert.equal(tempControl.row.classList.contains("sampling-tooltip-dismissed"), true, "dismissal-induced pointerleave must not immediately restore the tooltip");
|
|
532
|
+
tempControl.row.dispatchEvent("pointerenter");
|
|
533
|
+
assert.equal(tempControl.row.classList.contains("sampling-tooltip-dismissed"), false, "a new pointer lifecycle should restore tooltip availability");
|
|
534
|
+
tempControl.row.dispatchEvent({ type: "keydown", key: "Escape" });
|
|
535
|
+
tempControl.row.dispatchEvent({ type: "focusout", relatedTarget: null });
|
|
536
|
+
assert.equal(tempControl.row.classList.contains("sampling-tooltip-dismissed"), true, "focus dismissal should persist while the pointer remains over the row");
|
|
537
|
+
tempControl.row.dispatchEvent("pointerleave");
|
|
538
|
+
assert.equal(tempControl.row.classList.contains("sampling-tooltip-dismissed"), true, "dismissal should remain stable after the active pointer lifecycle ends");
|
|
539
|
+
tempControl.row.dispatchEvent("pointerenter");
|
|
540
|
+
assert.equal(tempControl.row.classList.contains("sampling-tooltip-dismissed"), false, "the next pointer lifecycle should reset a completed dismissal");
|
|
541
|
+
|
|
542
|
+
requests.length = 0;
|
|
543
|
+
await harness.apply();
|
|
544
|
+
assert.equal(requests.length, 0, "Apply click must not trigger HTTP request for unsupported models");
|
|
545
|
+
console.log("✓ Test 8: Unsupported Model Behavior passed");
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// --- Test 9: Status / Default / Effective Rendering ---
|
|
549
|
+
{
|
|
550
|
+
const { harness, elements, getControl, setNextResponse } = createHarness();
|
|
551
|
+
setNextResponse(supportedState({ temperature: 0.3 }, { temperature: 1, top_p: 0.95 }));
|
|
552
|
+
await harness.load({ tabId: "tab-a" });
|
|
553
|
+
|
|
554
|
+
const tempControl = getControl("temperature");
|
|
555
|
+
const topPControl = getControl("top_p");
|
|
556
|
+
|
|
557
|
+
assert.equal(tempControl.defaultValue.textContent, "1", "temperature default should display 1");
|
|
558
|
+
assert.equal(tempControl.effectiveValue.textContent, "0.3", "temperature effective value should display 0.3");
|
|
559
|
+
|
|
560
|
+
assert.equal(topPControl.defaultValue.textContent, "0.95", "top_p default should display 0.95");
|
|
561
|
+
assert.equal(topPControl.effectiveValue.textContent, "0.95", "top_p effective value should fall back to model default");
|
|
562
|
+
|
|
563
|
+
// Status message in clean state
|
|
564
|
+
assert.equal(elements.samplingParametersStatus.textContent, "Saved for this Pi session · unchecked parameters inherit model defaults.");
|
|
565
|
+
|
|
566
|
+
// Make draft dirty
|
|
567
|
+
tempControl.number.value = "0.4";
|
|
568
|
+
tempControl.number.dispatchEvent("input");
|
|
569
|
+
|
|
570
|
+
assert.equal(elements.samplingParametersStatus.textContent, "Unsaved controls · Apply stores enabled values for this session only.");
|
|
571
|
+
console.log("✓ Test 9: Status / Default / Effective Rendering passed");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
// --- Test 10: Controls Stay Locked Until Loaded Unknown Keys Are Available ---
|
|
575
|
+
{
|
|
576
|
+
const { harness, elements, requests, getControl, setNextResponse, setResponseGate } = createHarness();
|
|
577
|
+
let releaseLoad;
|
|
578
|
+
setResponseGate(new Promise((resolve) => { releaseLoad = resolve; }));
|
|
579
|
+
setNextResponse(supportedState({ vendor_mode: "strict" }));
|
|
580
|
+
|
|
581
|
+
const inFlightLoad = harness.load({ tabId: "tab-a" });
|
|
582
|
+
await Promise.resolve();
|
|
583
|
+
|
|
584
|
+
const minPControl = getControl("min_p");
|
|
585
|
+
assert.equal(minPControl.enable.disabled, true, "controls must stay disabled until the active tab state has loaded");
|
|
586
|
+
minPControl.enable.checked = true;
|
|
587
|
+
minPControl.enable.dispatchEvent("change");
|
|
588
|
+
assert.equal(harness.draft("tab-a"), null, "defensive event handling must ignore edits before a base draft exists");
|
|
589
|
+
|
|
590
|
+
releaseLoad();
|
|
591
|
+
await inFlightLoad;
|
|
592
|
+
setResponseGate(null);
|
|
593
|
+
assert.match(elements.samplingParametersPreserved.textContent, /1 additional parameter is preserved/);
|
|
594
|
+
|
|
595
|
+
minPControl.enable.checked = true;
|
|
596
|
+
minPControl.enable.dispatchEvent("change");
|
|
597
|
+
minPControl.number.value = "0.05";
|
|
598
|
+
minPControl.number.dispatchEvent("input");
|
|
599
|
+
requests.length = 0;
|
|
600
|
+
setNextResponse(supportedState({ vendor_mode: "strict", min_p: 0.05 }));
|
|
601
|
+
await harness.apply();
|
|
602
|
+
assert.deepEqual(requests[0].body, { vendor_mode: "strict", min_p: 0.05 }, "the first editable draft must retain hidden keys loaded from the server");
|
|
603
|
+
console.log("✓ Test 10: Pre-load Editing Guard and Unknown-Key Preservation passed");
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// --- Test 11: Dirty Draft Survives Tab Round-Trip and Remains Applicable ---
|
|
607
|
+
{
|
|
608
|
+
const { harness, elements, requests, getControl, setNextResponse } = createHarness();
|
|
609
|
+
setNextResponse(supportedState({ temperature: 0.5, vendor_mode: "strict" }));
|
|
610
|
+
await harness.load({ tabId: "tab-a" });
|
|
611
|
+
|
|
612
|
+
const temperature = getControl("temperature");
|
|
613
|
+
temperature.number.value = "0.2";
|
|
614
|
+
temperature.number.dispatchEvent("input");
|
|
615
|
+
assert.equal(harness.dirty("tab-a"), true);
|
|
616
|
+
|
|
617
|
+
harness.setActiveTab("tab-b");
|
|
618
|
+
setNextResponse(supportedState({ top_p: 0.9 }));
|
|
619
|
+
await harness.load({ tabId: "tab-b" });
|
|
620
|
+
|
|
621
|
+
harness.setActiveTab("tab-a");
|
|
622
|
+
setNextResponse(supportedState({ temperature: 0.5, vendor_mode: "strict" }));
|
|
623
|
+
await harness.load({ tabId: "tab-a" });
|
|
624
|
+
|
|
625
|
+
assert.equal(harness.draft("tab-a").controls.temperature.value, "0.2", "the tab-a draft must survive a non-forced tab round-trip");
|
|
626
|
+
assert.equal(elements.applySamplingParametersButton.disabled, false, "Apply must be available after active-tab state refreshes beneath a dirty draft");
|
|
627
|
+
assert.equal(elements.resetSamplingParametersButton.disabled, false, "Reset must remain available after the round-trip");
|
|
628
|
+
assert.match(elements.samplingParametersStatus.textContent, /Unsaved controls/);
|
|
629
|
+
|
|
630
|
+
requests.length = 0;
|
|
631
|
+
setNextResponse(supportedState({ temperature: 0.2, vendor_mode: "strict" }));
|
|
632
|
+
await harness.apply();
|
|
633
|
+
assert.deepEqual(requests[0].body, { vendor_mode: "strict", temperature: 0.2 }, "applying the restored draft must retain refreshed hidden keys");
|
|
634
|
+
console.log("✓ Test 11: Dirty Draft Tab Round-Trip passed");
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// --- Test 12: Tab Refresh During Apply Cannot Strand Busy State or Leak Defaults ---
|
|
638
|
+
{
|
|
639
|
+
const { harness, elements, requests, getControl, setNextResponse, setResponseGate } = createHarness();
|
|
640
|
+
setNextResponse(supportedState({ temperature: 0.5 }, { temperature: 1.7 }));
|
|
641
|
+
await harness.load({ tabId: "tab-a" });
|
|
642
|
+
|
|
643
|
+
const temperature = getControl("temperature");
|
|
644
|
+
temperature.number.value = "0.2";
|
|
645
|
+
temperature.number.dispatchEvent("input");
|
|
646
|
+
|
|
647
|
+
let releaseRequests;
|
|
648
|
+
setResponseGate(new Promise((resolve) => { releaseRequests = resolve; }));
|
|
649
|
+
setNextResponse(supportedState({ temperature: 0.2 }, { temperature: 1.7 }));
|
|
650
|
+
const inFlightWrite = harness.apply();
|
|
651
|
+
await Promise.resolve();
|
|
652
|
+
|
|
653
|
+
harness.setActiveTab("tab-b");
|
|
654
|
+
setNextResponse(supportedState({ top_p: 0.9 }, { top_p: 1 }));
|
|
655
|
+
const inFlightLoad = harness.load({ tabId: "tab-b" });
|
|
656
|
+
await Promise.resolve();
|
|
657
|
+
|
|
658
|
+
assert.equal(getControl("temperature").number.value, "", "an unloaded tab must not display the previous tab's default suggestion");
|
|
659
|
+
assert.equal(elements.reloadSamplingParametersButton.disabled, true, "Reload remains disabled while the write/load pair is active");
|
|
660
|
+
|
|
661
|
+
releaseRequests();
|
|
662
|
+
await Promise.all([inFlightWrite, inFlightLoad]);
|
|
663
|
+
setResponseGate(null);
|
|
664
|
+
|
|
665
|
+
assert.equal(harness.stateTabId(), "tab-b", "the superseding load must install the active tab's state");
|
|
666
|
+
assert.equal(elements.reloadSamplingParametersButton.disabled, false, "a superseded write must always clear the global busy state");
|
|
667
|
+
assert.doesNotMatch(elements.samplingParametersStatus.textContent, /Applying sampling parameters/, "status must not remain stuck in Applying");
|
|
668
|
+
assert.equal(getControl("top_p").enable.checked, true, "tab-b controls remain usable after the interleaving");
|
|
669
|
+
assert.equal(harness.draft("tab-a"), null, "the successful write still clears only its originating draft");
|
|
670
|
+
assert.equal(requests.filter(({ method }) => method === "PUT").length, 1);
|
|
671
|
+
console.log("✓ Test 12: Write/Refresh Busy-State Recovery and Default Isolation passed");
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// --- Test 13: Codex Per-Key Refresh, Draft Preservation, and Missing-Map Fail-Closed ---
|
|
675
|
+
{
|
|
676
|
+
const { harness, elements, requests, getControl, setNextResponse } = createHarness();
|
|
677
|
+
setNextResponse({
|
|
678
|
+
session: { temperature: 0.6, top_p: 0.9 },
|
|
679
|
+
defaults: {},
|
|
680
|
+
effective: { temperature: 0.6, top_p: 0.9 },
|
|
681
|
+
support: {
|
|
682
|
+
supported: true,
|
|
683
|
+
api: "openai-completions",
|
|
684
|
+
model: { provider: "openai", id: "gpt-5", name: "GPT-5" },
|
|
685
|
+
parameters: capabilitiesFor(["temperature", "top_p", "frequency_penalty", "presence_penalty", "seed"], "openai-completions"),
|
|
686
|
+
message: "Session sampling parameters apply to subsequent provider requests.",
|
|
687
|
+
},
|
|
688
|
+
});
|
|
689
|
+
await harness.load({ tabId: "tab-a" });
|
|
690
|
+
const temperature = getControl("temperature");
|
|
691
|
+
temperature.number.value = "0.25";
|
|
692
|
+
temperature.number.dispatchEvent("input");
|
|
693
|
+
|
|
694
|
+
setNextResponse({
|
|
695
|
+
session: { temperature: 0.6, top_p: 0.9 },
|
|
696
|
+
defaults: {},
|
|
697
|
+
effective: { temperature: 0.6 },
|
|
698
|
+
support: {
|
|
699
|
+
supported: true,
|
|
700
|
+
api: "openai-codex-responses",
|
|
701
|
+
model: { provider: "openai-codex", id: "gpt-5.6-sol", name: "GPT-5.6 Sol" },
|
|
702
|
+
parameters: capabilitiesFor(["temperature"], "openai-codex-responses"),
|
|
703
|
+
message: "Session sampling parameters apply to subsequent provider requests.",
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
await harness.refresh({ tabId: "tab-a", generation: 1 });
|
|
707
|
+
|
|
708
|
+
assert.equal(temperature.number.value, "0.25", "a model capability refresh must not discard an unsaved Temperature draft");
|
|
709
|
+
assert.equal(temperature.enable.disabled, false, "Codex Temperature must remain enabled");
|
|
710
|
+
assert.equal(temperature.row.getAttribute("aria-disabled"), null, "supported rows must remove unsupported accessibility state");
|
|
711
|
+
assert.equal(temperature.tooltip.hidden, true, "supported rows must hide tooltip nodes after a capability transition");
|
|
712
|
+
assert.equal(temperature.tooltip.textContent, "", "supported rows must clear stale unsupported reasons after a capability transition");
|
|
713
|
+
const topP = getControl("top_p");
|
|
714
|
+
assert.equal(topP.enable.checked, true, "a stored unsupported value must remain checked and preserved");
|
|
715
|
+
assert.equal(topP.enable.disabled, true, "Codex Top P is unverified and must be disabled");
|
|
716
|
+
assert.equal(topP.tooltip.hidden, false);
|
|
717
|
+
assert.equal(topP.row.getAttribute("aria-describedby"), topP.tooltip.id);
|
|
718
|
+
assert.match(topP.tooltip.textContent, /openai-codex-responses does not declare Top P support/);
|
|
719
|
+
for (const key of ["top_p", "frequency_penalty", "presence_penalty", "seed", "top_k", "min_p"]) {
|
|
720
|
+
assert.equal(getControl(key).enable.disabled, true, `Codex ${key} must fail closed when unverified`);
|
|
721
|
+
}
|
|
722
|
+
assert.equal(elements.applySamplingParametersButton.disabled, false, "a draft remains applicable when at least one parameter is supported");
|
|
723
|
+
requests.length = 0;
|
|
724
|
+
setNextResponse({
|
|
725
|
+
session: { temperature: 0.25, top_p: 0.9 },
|
|
726
|
+
defaults: {},
|
|
727
|
+
effective: { temperature: 0.25 },
|
|
728
|
+
support: {
|
|
729
|
+
supported: true,
|
|
730
|
+
api: "openai-codex-responses",
|
|
731
|
+
model: { provider: "openai-codex", id: "gpt-5.6-sol", name: "GPT-5.6 Sol" },
|
|
732
|
+
parameters: capabilitiesFor(["temperature"], "openai-codex-responses"),
|
|
733
|
+
message: "Session sampling parameters apply to subsequent provider requests.",
|
|
734
|
+
},
|
|
735
|
+
});
|
|
736
|
+
await harness.apply();
|
|
737
|
+
assert.deepEqual(requests[0].body, { temperature: 0.25, top_p: 0.9 }, "applying a supported edit must preserve the stored unsupported value for backend filtering");
|
|
738
|
+
|
|
739
|
+
setNextResponse({
|
|
740
|
+
session: { temperature: 0.25, top_p: 0.9 },
|
|
741
|
+
defaults: {},
|
|
742
|
+
effective: {},
|
|
743
|
+
support: { supported: true, api: "legacy-fixture-without-parameters", message: "Legacy whole-API support only." },
|
|
744
|
+
});
|
|
745
|
+
await harness.load({ tabId: "tab-a", force: true });
|
|
746
|
+
assert.ok(SAMPLING_PARAMETER_CATALOG.every(({ key }) => getControl(key).enable.disabled), "missing support.parameters must disable every control even when legacy support.supported is true");
|
|
747
|
+
assert.equal(elements.applySamplingParametersButton.disabled, true);
|
|
748
|
+
assert.match(getControl("temperature").tooltip.textContent, /support was not reported/);
|
|
749
|
+
console.log("✓ Test 13: Codex Per-Key Refresh and Missing-Map Fail-Closed passed");
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
console.log("All native sampling parameter control user-flow acceptance tests passed!");
|