feat(panel): modularize 3-tab preferences, add model context windows, and optimize telemetry

- Refactor Preferences into decoupled General, Structure, and Other tabs with unified settings schema, factory reset, and trajectory cache rebuild endpoints
- Extract standalone widget, metric, and step-table column registries to customize topbar/composer slots, hover popup modules, live overview layout, and step detail columns
- Add bilingual zh-CN/en-US i18n dictionaries, theme accent presets, and font scale controls across Shadow DOM overlay and sidebar views
- Support per-model host-advertised context window rules across App and IDE transports
- Preserve CLEARED step generation timings, memoize per-poll model resolution, optimize LOESS sorted-x fitting, and update bilingual READMEs and test suites
This commit is contained in:
fish
2026-11-15 01:18:29 +09:00
parent ad33e9cc62
commit 18c608ae63
63 changed files with 16614 additions and 5873 deletions
+10 -4
View File
@@ -14,6 +14,8 @@ const DEFAULT_BUNDLED_CATALOG = {
};
const BACKEND_MODULE_FILES = [
'../backend/context-windows.mjs',
'../backend/settings-schema.mjs',
'../backend/config.mjs',
'../backend/ls-discovery.mjs',
'../backend/pricing-catalog.mjs',
@@ -47,6 +49,7 @@ export function backendHarness({
trajectories={},
summaries={},
userStatus={},
availableModels={},
quotaSummary={groups:[]},
localCatalog=DEFAULT_BUNDLED_CATALOG,
remoteCatalog=null,
@@ -61,7 +64,7 @@ export function backendHarness({
const mainUrl = pluginRootPath ? `file://${pluginRootPath}/sidecars/panel/main.mjs` : 'file:///test/sidecars/panel/main.mjs';
const mainPath = pluginRootPath ? `${pluginRootPath}/sidecars/panel/main.mjs` : '/test/sidecars/panel/main.mjs';
const source = stripEsmSyntax(sourceText ?? loadCombinedBackendSource(), mainUrl);
const state={calls:[],errors:[],saves:[],trajectories,transcripts,transcriptMtimeMs:1,userStatus,quotaSummary,localCatalog,remoteCatalog,pluginManifest,hasGitDir,deepStats,deepStatsMtimeMs:1};
const state={calls:[],errors:[],saves:[],settings,trajectories,transcripts,transcriptMtimeMs:1,userStatus,quotaSummary,localCatalog,remoteCatalog,pluginManifest,hasGitDir,deepStats,deepStatsMtimeMs:1};
const ctx={
...metricsImplementation, URL, AbortSignal, Buffer,
process:{platform:'win32',env:{ANTIGRAVITY_EXECUTABLE_DATA_DIR:'/test-data',ANTIGRAVITY_LS_ADDRESS:'test.invalid',ANTIGRAVITY_CSRF_TOKEN:'test'}},
@@ -109,7 +112,7 @@ export function backendHarness({
const lines = m && state.transcripts?.[m[1]];
return Array.isArray(lines) ? lines.map(x => JSON.stringify(x)).join('\n') : String(lines || '');
}
if (norm.endsWith('settings.json')) return JSON.stringify(settings);
if (norm.endsWith('settings.json')) return JSON.stringify(state.settings);
if (norm.endsWith('/antigravity/brain/.deep_stats_cache.json')) return JSON.stringify(state.deepStats);
if (norm.endsWith('pricing-catalog.json')) return JSON.stringify(state.localCatalog);
if (norm.endsWith('remote_pricing_cache.json')) return JSON.stringify(state.remoteCatalog);
@@ -120,6 +123,9 @@ export function backendHarness({
const norm = String(p).replace(/\\/g, '/');
const parsed = typeof s === 'string' ? JSON.parse(s) : s;
state.saves.push({path:p,data:parsed});
if (norm.endsWith('settings.json')) {
state.settings = parsed;
}
if (norm.endsWith('remote_pricing_cache.json')) {
state.remoteCatalog = parsed;
}
@@ -142,10 +148,10 @@ export function backendHarness({
if(qs instanceof Error) throw qs;
return {ok:true,json:async()=>({response:qs})};
}
const data={GetUserStatus:{userStatus:state.userStatus},GetAllCascadeTrajectories:{trajectorySummaries:summaries}}[method];
const data={GetUserStatus:{userStatus:state.userStatus},GetAvailableModels:{response:{models:availableModels}},GetAllCascadeTrajectories:{trajectorySummaries:summaries}}[method];
return {ok:true,json:async()=>data};
},
};
vm.runInNewContext(source+'\n globalThis.api={buildTelemetryPayloadInternal,computeStepCost,resolveModelInfo,inferFamilyFromProviderOrKey,isArgonModelIdentifier,isCarbonModelIdentifier,getBaseModelLabel,formatUpstreamModelId,PLACEHOLDER_MAP,normalizeQuotaFraction,classifyOfficialBucketWindow,classifyQuotaPoolIdentity,buildOfficialQuotaPools,resolveTimeWindow,sanitizeCatalogPayload,rebuildActiveCatalog,syncCloudCatalog,getCloudStatus,isValidSemver,compareSemver,performPluginUpdate,loadSettings,executeSettingsAction};',ctx);
vm.runInNewContext(source+'\n globalThis.api={buildTelemetryPayloadInternal,computeStepCost,resolveModelInfo,inferFamilyFromProviderOrKey,isArgonModelIdentifier,isCarbonModelIdentifier,getBaseModelLabel,formatUpstreamModelId,PLACEHOLDER_MAP,normalizeQuotaFraction,classifyOfficialBucketWindow,classifyQuotaPoolIdentity,buildOfficialQuotaPools,resolveTimeWindow,sanitizeCatalogPayload,rebuildActiveCatalog,syncCloudCatalog,getCloudStatus,isValidSemver,compareSemver,performPluginUpdate,loadSettings,executeSettingsAction,executeModelContextWindowAction,executeResetSettingsAction,executeRebuildCacheAction,clearRuntimeCaches,normalizeTopbarCapsuleSlots,normalizeHoverModules,normalizeOverviewModules,normalizeOverviewMetrics,normalizeStepTableColumns};',ctx);
return {...ctx.api,state};
}
+119
View File
@@ -616,6 +616,38 @@ test('trendSeries preserves 1-day-per-slot granularity for >90 day spans and rec
assert.equal(steps[1].responseTokens, 280);
});
test('cached incomplete timing is refreshed once without invalidating completed historical steps', async () => {
const time = '2026-01-01T00:00:12Z';
const summary = { stepCount: 1, lastModifiedTime: time, status: 'IDLE' };
const incompleteStep = {
...structuredClone(raw.trajectory.steps[0]),
status: 'CORTEX_STEP_STATUS_CLEARED',
};
const { extractModelSteps } = await import('../speed-metrics.mjs');
const [completed] = extractModelSteps(raw.trajectory.steps, raw.trajectory.generatorMetadata);
const [incomplete] = extractModelSteps([{ ...incompleteStep, status: 'CORTEX_STEP_STATUS_GENERATING' }]);
const cacheEntry = (step) => ({
signature: `v10-model-identity:1:${time}`,
steps: [step],
contextLimitTelemetry: true,
subagentRefs: [],
});
const h = backendHarness({
cache: { repaired: cacheEntry(incomplete), stable: cacheEntry(completed) },
summaries: { repaired: summary, stable: summary },
trajectories: { repaired: { trajectory: { ...raw.trajectory, steps: [incompleteStep] } } },
});
for (let i = 0; i < 2; i++) {
const result = await h.buildTelemetryPayloadInternal('repaired');
assert.equal(result.activeConversation.latestTokPerSec, Math.round(completed.totalTokPerSec * 10) / 10);
}
assert.deepEqual(
h.state.calls.filter((c) => c.method === 'GetCascadeTrajectory').map((c) => c.body.cascadeId),
['repaired']
);
});
test('modelBreakdown exposes avgTtftSec, cacheHitPct, and subagent scoped breakdowns + fit math helpers', async () => {
const {
computeLinearFit,
@@ -768,3 +800,90 @@ test('modelBreakdown exposes avgTtftSec, cacheHitPct, and subagent scoped breakd
const aggMb = payload.activeConversation.aggregated.modelBreakdown;
assert.equal(aggMb.length, 2);
});
test('preferences schema defaults match pre-refactor UI, migrate legacy none slots, and support reset & cache rebuild', async () => {
// 1. Default schema matches pre-refactor out-of-box UI 100%
const hDefault = backendHarness({});
const def = hDefault.loadSettings();
assert.equal(def.language, 'zh-CN');
assert.equal(def.themeAccent, 'host');
assert.equal(def.fontScale, 'md');
assert.equal(def.pluginUpdateMode, 'manual');
assert.equal(def.windowMountMode, 'dual');
assert.equal(def.enableWindowOverlay, true);
assert.equal(def.showTopbarMultiSession, true);
assert.deepEqual([...def.topbarCapsuleSlots], ['context', 'tps', 'quota_auto']);
assert.deepEqual([...def.hoverModules], ['metrics', 'context', 'quotas']);
assert.deepEqual([...def.overviewModules], ['metrics', 'context', 'quotas', 'live_tasks']);
assert.deepEqual([...def.overviewMetrics], ['tps', 'ttft', 'avg_tps', 'step_cost']);
assert.deepEqual([...def.stepTableColumns], ['step', 'model', 'tps', 'ttft', 'tokens_combo', 'cache', 'cost']);
assert.deepEqual({ ...def.modelContextWindows }, {});
// 2. Legacy 3-slot ['context', 'none', 'quota_auto'] migrates cleanly to 2-item ['context', 'quota_auto']
assert.deepEqual(
[...hDefault.normalizeTopbarCapsuleSlots(['context', 'none', 'quota_auto'])],
['context', 'quota_auto']
);
// Up to 5 unique items supported, duplicates stripped, empty falls back to ['context']
assert.deepEqual(
[...hDefault.normalizeTopbarCapsuleSlots(['tps', 'ttft', 'cost', 'cache_hit', 'session_tokens', 'gemini_5h'])],
['tps', 'ttft', 'cost', 'cache_hit', 'session_tokens']
);
assert.deepEqual([...hDefault.normalizeTopbarCapsuleSlots(['none', 'none', 'none'])], ['context']);
// 3. Hover modules allow 0 items (explicit []), overviewModules & overviewMetrics require >= 1, stepTableColumns require >= 2
assert.deepEqual([...hDefault.normalizeHoverModules([])], []);
assert.deepEqual([...hDefault.normalizeOverviewModules([])], ['metrics']);
assert.deepEqual([...hDefault.normalizeOverviewMetrics([])], ['tps']);
assert.deepEqual([...hDefault.normalizeStepTableColumns(['cost'])], ['cost', 'step']);
// 4. Updating preferences must not apply legacy global limits or bulk model updates
const saveRes = hDefault.executeSettingsAction({
language: 'en-US',
themeAccent: 'emerald',
fontScale: 'lg',
topbarCapsuleSlots: ['context', 'tps', 'ttft', 'cost'],
hoverModules: ['metrics', 'context'],
overviewModules: ['quotas', 'metrics'],
overviewMetrics: ['avg_tps', 'cache_hit'],
stepTableColumns: ['step', 'time', 'model', 'duration', 'input_tokens', 'output_tokens', 'cost'],
contextLimitOverrideTokens: 128000,
modelContextWindows: { MODEL_PLACEHOLDER_M418: '900K' },
});
assert.equal(saveRes.ok, true);
assert.equal(saveRes.updated.language, 'en-US');
assert.equal(saveRes.updated.themeAccent, 'emerald');
assert.equal(saveRes.updated.fontScale, 'lg');
assert.equal(saveRes.updated.topbarCapsuleSlots.length, 4);
assert.deepEqual([...saveRes.updated.hoverModules], ['metrics', 'context']);
assert.deepEqual([...saveRes.updated.overviewModules], ['quotas', 'metrics']);
assert.deepEqual([...saveRes.updated.overviewMetrics], ['avg_tps', 'cache_hit']);
assert.equal(saveRes.updated.contextLimitOverrideTokens, undefined);
assert.deepEqual({ ...saveRes.updated.modelContextWindows }, {});
const hWithSteps = backendHarness({
settings: {
contextLimitOverrideTokens: 128000,
modelContextWindows: { MODEL_PLACEHOLDER_M418: '900K' },
},
cache: { c1: old },
trajectories: { c1: raw },
summaries: { c1: { stepCount: 1, lastModifiedTime: '2026-01-01T00:00:10Z', status: 'IDLE' } },
});
const telemetry = await hWithSteps.buildTelemetryPayloadInternal('c1');
assert.equal(telemetry.activeConversation.context.compactionLimitTokens, 256000);
assert.equal(telemetry.activeConversation.context.limitTokens, 256000);
// 5. executeRebuildCacheAction clears trajectoryCache & writes empty cache object
const rebuildRes = hWithSteps.executeRebuildCacheAction();
assert.equal(rebuildRes.ok, true);
const lastCacheSave = hWithSteps.state.saves[hWithSteps.state.saves.length - 1];
assert.deepEqual(JSON.parse(JSON.stringify(lastCacheSave.data)), {});
// 6. executeResetSettingsAction restores full defaults cleanly
const resetRes = hDefault.executeResetSettingsAction();
assert.equal(resetRes.ok, true);
assert.equal(resetRes.updated.language, 'zh-CN');
assert.equal(resetRes.updated.themeAccent, 'host');
assert.deepEqual([...resetRes.updated.topbarCapsuleSlots], ['context', 'tps', 'quota_auto']);
});
@@ -0,0 +1,210 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import vm from 'node:vm';
import { createContextWindowSyncExpression } from '../backend/context-windows.mjs';
import { backendHarness } from './backend-harness.mjs';
const argon = 'MODEL_PLACEHOLDER_M430';
const flash = 'MODEL_PLACEHOLDER_M431';
const other = 'MODEL_PLACEHOLDER_M432';
const carbon = 'MODEL_PLACEHOLDER_M427';
const carbonLow = 'MODEL_PLACEHOLDER_M438';
const newCarbonLow = 'MODEL_PLACEHOLDER_M439';
const carbonGroup = 'model:gemini-4-carbon';
const availableModels = {
'gemini-4-carbon-high': { model: carbon, maxTokens: 1048576, maxOutputTokens: 262144 },
'gemini-4-carbon-low': { model: carbonLow, maxTokens: 700000, maxOutputTokens: 64000 },
'gemini-other': { model: other, maxTokens: 250000, maxOutputTokens: 64000 },
};
const carbonModels = [
{ label: 'Gemini 4 Carbon (High)', modelId: 'gemini-4-carbon-high', modelOrAlias: { model: carbon } },
{ label: 'Gemini 4 Carbon (Low)', modelId: 'gemini-4-carbon-low', modelOrAlias: { model: carbonLow } },
];
test('saves and restores one model at a time using host presets or verified model capacity', async () => {
const h = backendHarness({
settings: { contextLimitOverrideTokens: 900000 },
availableModels,
userStatus: {
cascadeModelConfigData: {
clientModelConfigs: [
{ label: 'Argon', modelOrAlias: { model: argon },
contextWindowOptions: [{ name: '512K' }, { name: '900K', expensive: true }] },
{ label: 'Flash', modelOrAlias: { model: flash }, contextWindowOptions: [{ name: '256K' }] },
{ label: 'Other', modelOrAlias: { model: other } },
...carbonModels,
],
},
},
});
const update = h.executeModelContextWindowAction;
const { contextWindowModels } = await h.buildTelemetryPayloadInternal('');
const [argonModel, flashModel, otherModel, carbonModel] = JSON.parse(JSON.stringify(contextWindowModels));
assert.deepEqual(argonModel.options, [{ name: '512K', expensive: false }, { name: '900K', expensive: true }]);
assert.deepEqual(flashModel.options, [{ name: '256K', expensive: false }]);
assert.deepEqual(otherModel.options.map(({ tokens }) => tokens), [128000, 186000]);
assert.equal(carbonModel.id, carbonGroup);
assert.equal(carbonModel.label, 'Gemini 4 Carbon');
assert.deepEqual(carbonModel.members, [carbon, carbonLow]);
assert.equal(carbonModel.options.at(-1).tokens, 636000);
assert.equal((await update({ modelId: carbonGroup, option: '768000' })).status, 400);
h.state.settings.modelContextWindows = { [carbon]: '768000', [carbonLow]: '256000' };
assert.equal((await update({ modelId: carbonGroup, option: '512000' })).status, 200);
assert.deepEqual({ ...h.loadSettings().modelContextWindows }, { [carbonGroup]: '512000' });
assert.equal((await update({ modelId: carbonGroup, option: null })).status, 200);
assert.equal((await update({ modelId: flash, option: '900K' })).status, 400);
assert.equal((await update({ modelId: other, option: '900K' })).status, 400);
assert.equal((await update({ modelId: '__proto__', option: null })).status, 400);
assert.deepEqual({ ...h.loadSettings().modelContextWindows }, {});
const [a, b] = await Promise.all([
update({ modelId: argon, option: '900K' }),
update({ modelId: flash, option: '256K' }),
]);
assert.equal(a.status, 200);
assert.equal(b.status, 200);
assert.deepEqual({ ...h.loadSettings().modelContextWindows }, { [argon]: '900K', [flash]: '256K' });
assert.equal((await update({ modelId: argon, option: null })).status, 200);
assert.deepEqual({ ...h.loadSettings().modelContextWindows }, { [flash]: '256K' });
h.executeResetSettingsAction();
assert.deepEqual({ ...h.loadSettings().modelContextWindows }, {});
});
test('reports the latest observed threshold separately from the saved group preference', async () => {
const h = backendHarness({
availableModels,
settings: { modelContextWindows: { [carbonGroup]: '512000' } },
userStatus: { cascadeModelConfigData: { clientModelConfigs: carbonModels } },
summaries: { active: { stepCount: 1, lastModifiedTime: '2026-01-01T00:00:01Z', status: 'IDLE' } },
trajectories: {
active: { trajectory: {
steps: [{ metadata: {
createdAt: '2026-01-01T00:00:00Z',
finishedGeneratingAt: '2026-01-01T00:00:01Z',
modelUsage: { model: carbonLow, inputTokens: 20, outputTokens: 20 },
}, plannerResponse: { response: 'ok' } }],
generatorMetadata: [{ stepIndices: [0], chatModel: {
chatStartMetadata: { contextWindowMetadata: { maxContextTokens: 256000 } },
} }],
} },
},
});
const result = await h.buildTelemetryPayloadInternal('active');
assert.equal(result.contextWindowModels.find(({ id }) => id === carbonGroup).reportedLimitTokens, 256000);
assert.equal(result.settings.modelContextWindows[carbonGroup], '512000');
const previouslyCached = h.state.saves.find(({ data }) => data.active?.contextLimitTelemetry).data.active;
const cached = structuredClone(previouslyCached);
delete cached.contextLimitTelemetry;
delete cached.steps[0].reportedContextLimitTokens;
const upgraded = backendHarness({
availableModels,
userStatus: h.state.userStatus,
cache: { active: cached },
summaries: { active: { stepCount: 1, lastModifiedTime: '2026-01-01T00:00:01Z', status: 'IDLE' } },
trajectories: h.state.trajectories,
});
const reloaded = await upgraded.buildTelemetryPayloadInternal('active');
assert.equal(reloaded.contextWindowModels[0].reportedLimitTokens, 256000);
});
test('host requests apply a rule only to the exact model across App and IDE transports', async () => {
const sendPath = '/exa.language_server_pb.LanguageServerService/SendUserCascadeMessage';
const statusPath = sendPath.replace('SendUserCascadeMessage', 'GetUserStatus');
const host = 'https://127.0.0.1:25190';
let catalog = availableModels;
let variants = carbonModels;
const nativeFetch = async (url, init) => {
if (url === host + statusPath.replace('GetUserStatus', 'GetAvailableModels')) {
return { ok: true, json: async () => ({ response: { models: catalog } }) };
}
if (url !== host + statusPath || init.body !== '{}') return init;
assert.equal(init.headers['x-codeium-csrf-token'], 'local-test');
return { ok: true, json: async () => ({ userStatus: { cascadeModelConfigData: { clientModelConfigs: [
{ modelOrAlias: { model: argon }, contextWindowOptions: [{ name: '900K' }] },
{ modelOrAlias: { model: flash }, contextWindowOptions: [{ name: '256K' }] },
...variants,
{ modelOrAlias: { model: other } },
] } } }) };
};
class WebSocket {
constructor(url) { this.url = url; }
send(data) { return data; }
}
const nativeSend = WebSocket.prototype.send;
const window = { location: new URL(host), fetch: nativeFetch, WebSocket, __APP_CONFIG__: { csrfToken: 'local-test' } };
const context = vm.createContext({ window, URL, TextEncoder, TextDecoder, Headers, Uint8Array, AbortSignal, setTimeout, clearTimeout });
const install = (rules, boot = 'first') => vm.runInContext(createContextWindowSyncExpression(rules, boot), context);
const request = (model) => ({
cascadeId: 'conversation-1',
items: [{ text: 'Keep the request intact' }],
cascadeConfig: {
plannerConfig: { planModel: model },
checkpointConfig: { maxTokenLimit: 128000, checkpointIntervalTokens: 20000 },
},
});
const options = (body, type = 'application/json') => ({
method: 'POST', headers: { 'Content-Type': type }, body,
});
const preferences = { [argon]: '900K', [flash]: '900K', [carbonGroup]: '512000', [other]: '512000' };
await install(preferences);
try {
const payload = request(argon);
const input = options(JSON.stringify(payload));
const edited = JSON.parse((await window.fetch(host + sendPath, input)).body);
assert.deepEqual(edited, {
...payload,
cascadeConfig: {
...payload.cascadeConfig,
checkpointConfig: { contextWindow: '900K', checkpointIntervalTokens: 20000 },
},
});
const untouched = options(JSON.stringify(request(flash)));
assert.equal(await window.fetch(host + sendPath, untouched), untouched);
const lowCapacity = options(JSON.stringify(request(other)));
assert.equal(await window.fetch(host + sendPath, lowCapacity), lowCapacity);
const carbonPayload = request(carbon);
carbonPayload.cascadeConfig.checkpointConfig.contextWindow = 'default';
const carbonBody = (await window.fetch(host + sendPath, options(JSON.stringify(carbonPayload)))).body;
assert.deepEqual(JSON.parse(carbonBody).cascadeConfig.checkpointConfig,
{ maxTokenLimit: 512000, checkpointIntervalTokens: 20000 });
const lowPayload = options(JSON.stringify(request(carbonLow)));
assert.equal(JSON.parse((await window.fetch(host + sendPath, lowPayload)).body).cascadeConfig.checkpointConfig.maxTokenLimit, 512000);
assert.equal(await window.fetch('https://127.0.0.1:25191' + sendPath, input), input);
assert.equal(await window.fetch(host + statusPath, input), input);
const frame = Buffer.alloc(5 + Buffer.byteLength(input.body));
frame.writeUInt32BE(frame.length - 5, 1);
frame.write(input.body, 5);
const framed = await window.fetch(host + sendPath, options(frame, 'application/grpc-web+json'));
assert.equal(Buffer.from(framed.body).readUInt32BE(1), framed.body.length - 5);
assert.deepEqual(JSON.parse(Buffer.from(framed.body.subarray(5)).toString()), edited);
const socket = new WebSocket('wss://127.0.0.1:25190/connect-websocket');
const msg = { type: 'start', stream: false, procedure: sendPath, streamId: 'request-1', payload };
assert.deepEqual(JSON.parse(socket.send(JSON.stringify(msg))), { ...msg, payload: edited });
const unrelated = JSON.stringify({ ...msg, payload: request(flash) });
assert.equal(socket.send(unrelated), unrelated);
const external = new WebSocket('wss://127.0.0.1:25191/connect-websocket');
assert.equal(external.send(JSON.stringify(msg)), JSON.stringify(msg));
const firstHook = window.fetch;
variants = [carbonModels[0], { ...carbonModels[1], modelOrAlias: { model: newCarbonLow } }];
catalog = { ...availableModels, 'gemini-4-carbon-low': { ...availableModels['gemini-4-carbon-low'], model: newCarbonLow } };
await install(preferences, 'second');
assert.notEqual(window.fetch, firstHook);
assert.equal(await window.fetch(host + sendPath, lowPayload), lowPayload);
window.fetch = nativeFetch;
await install(preferences, 'second');
const newLowPayload = options(JSON.stringify(request(newCarbonLow)));
assert.equal(JSON.parse((await window.fetch(host + sendPath, newLowPayload)).body).cascadeConfig.checkpointConfig.maxTokenLimit, 512000);
catalog['gemini-4-carbon-low'] = { model: newCarbonLow, maxTokens: 300000, maxOutputTokens: 64000 };
await install(preferences, 'third');
assert.equal(await window.fetch(host + sendPath, newLowPayload), newLowPayload);
assert.equal(await window.fetch(host + sendPath, options(JSON.stringify(carbonPayload))).then(({ body }) => body), JSON.stringify(carbonPayload));
} finally {
await install({});
}
assert.equal(window.fetch, nativeFetch);
assert.equal(WebSocket.prototype.send, nativeSend);
});
@@ -72,6 +72,20 @@ test('unfinished, missing-completion and reversed-time requests cannot fabricate
assert.equal(parse({total:0}).totalTokPerSec,null);
assert.equal(parse({status:'CORTEX_STEP_STATUS_GENERATING'}).totalTokPerSec,null);
});
test('cleared steps with a recorded generation end retain their original request speed',()=>{
const {s,gm}=sample({status:'CORTEX_STEP_STATUS_CLEARED'});
s.metadata.completedAt='2026-01-01T00:04:00Z';
const [cleared]=extractModelSteps([s],[gm]);
assert.equal(cleared.totalDurationSec,12);
assert.equal(cleared.totalTokPerSec,1100/12);
assert.equal(cleared.isComplete,true);
for(const status of ['CORTEX_STEP_STATUS_CANCELED','CORTEX_STEP_STATUS_ERROR','CORTEX_STEP_STATUS_GENERATING']){
assert.equal(extractModelSteps([{...s,status}],[gm])[0].totalTokPerSec,null);
}
delete s.metadata.finishedGeneratingAt;
assert.equal(extractModelSteps([s],[gm])[0].totalTokPerSec,null);
});
test('zero output is a real zero; malformed or missing output counts cannot produce rates',()=>{
const zero=parse({output:0,response:0,thinking:0});
assert.equal(zero.totalTokPerSec,0);assert.equal(zero.responseTokens,0);
+445 -153
View File
@@ -491,11 +491,24 @@ test('Capsule 4-stage responsive hysteresis and backend settings default/overrid
settings: { topbarCapsuleSlots: ['none', 'none', 'none'] },
});
const allNonePayload = await allNoneEnv.buildTelemetryPayloadInternal('', false, {});
assert.deepEqual(Array.from(allNonePayload.settings.topbarCapsuleSlots), [
assert.deepEqual(Array.from(allNonePayload.settings.topbarCapsuleSlots), ['context']);
// Dynamic 5-slot configuration & hysteresis width threshold scaling (+58px per slot beyond 3)
const fiveSlotEnv = backendHarness({
settings: {
topbarCapsuleSlots: ['context', 'tps', 'ttft', 'session_cost', 'claude_weekly'],
},
});
const fiveSlotPayload = await fiveSlotEnv.buildTelemetryPayloadInternal('', false, {});
assert.deepEqual(Array.from(fiveSlotPayload.settings.topbarCapsuleSlots), [
'context',
'none',
'none',
'tps',
'ttft',
'session_cost',
'claude_weekly',
]);
assert.equal(computeCapsuleLayoutMode(340, 'wide', { slotCount: 5 }), 'compact');
assert.equal(computeCapsuleLayoutMode(400, 'compact', { slotCount: 5 }), 'wide');
});
test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, protects host reload, and supports composedPath()', async () => {
@@ -515,6 +528,7 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
_vars: new Map(),
setProperty(k, v) { this._vars.set(k, String(v)); },
getPropertyValue(k) { return this._vars.get(k) || ''; },
removeProperty(k) { this._vars.delete(k); },
};
this.dataset = {};
this.attributes = new Map();
@@ -732,17 +746,29 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
},
};
const mockSettings = {
weeklyLimitMode: 'official',
weeklyTokenBudget: 150000000,
weeklyCostBudget: 100,
showUpstreamModel: false,
orchestratorIdMode: 'compact',
const defaultMockSettings = {
language: 'zh-CN',
themeAccent: 'host',
fontScale: 'md',
pluginUpdateMode: 'manual',
autoUpdatePlugin: false,
windowMountMode: 'dual',
enableWindowOverlay: true,
showTopbarMultiSession: true,
topbarCapsuleSlots: ['context', 'tps', 'quota_auto'],
hoverModules: ['metrics', 'context', 'quotas'],
overviewModules: ['metrics', 'context', 'quotas', 'live_tasks'],
overviewMetrics: ['tps', 'ttft', 'avg_tps', 'step_cost'],
stepTableColumns: ['step', 'model', 'tps', 'ttft', 'tokens_combo', 'cache', 'cost'],
showUpstreamModel: false,
orchestratorIdMode: 'compact',
weeklyLimitMode: 'official',
weeklyTokenBudget: 150000000,
weeklyCostBudget: 100,
modelContextWindows: {},
};
const mockSettings = { ...defaultMockSettings };
let cacheRebuildCalls = 0;
const mockWindow = {
innerWidth: 1440,
@@ -770,9 +796,47 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
const urlStr = String(url);
fetchedUrls.push(urlStr);
fetchedHeaders.push(opts.headers || {});
if (urlStr.includes('/api/settings/reset') && String(opts.method || '').toUpperCase() === 'POST') {
for (const k of Object.keys(mockSettings)) delete mockSettings[k];
Object.assign(mockSettings, {
...defaultMockSettings,
topbarCapsuleSlots: [...defaultMockSettings.topbarCapsuleSlots],
hoverModules: [...defaultMockSettings.hoverModules],
overviewModules: [...defaultMockSettings.overviewModules],
overviewMetrics: [...defaultMockSettings.overviewMetrics],
stepTableColumns: [...defaultMockSettings.stepTableColumns],
});
return {
ok: true,
status: 200,
json: async () => ({ ok: true, settings: { ...mockSettings } }),
};
}
if (urlStr.includes('/api/cache/rebuild') && String(opts.method || '').toUpperCase() === 'POST') {
cacheRebuildCalls += 1;
return {
ok: true,
status: 200,
json: async () => ({ ok: true, clearedEntries: 12 }),
};
}
if (urlStr.includes('/api/context-window') && opts.method === 'POST') {
const { modelId, option } = JSON.parse(opts.body);
const modelContextWindows = { ...mockSettings.modelContextWindows };
if (option === null) delete modelContextWindows[modelId];
else modelContextWindows[modelId] = option;
mockSettings.modelContextWindows = modelContextWindows;
return { ok: true, status: 200, json: async () => ({ modelContextWindows }) };
}
if (urlStr.includes('/api/settings') && String(opts.method || '').toUpperCase() === 'POST') {
const patch = opts.body ? JSON.parse(opts.body) : {};
Object.assign(mockSettings, patch);
if (patch.windowMountMode !== undefined && patch.enableWindowOverlay === undefined) {
mockSettings.enableWindowOverlay = patch.windowMountMode !== 'sidebar';
}
if (patch.pluginUpdateMode !== undefined && patch.autoUpdatePlugin === undefined) {
mockSettings.autoUpdatePlugin = patch.pluginUpdateMode === 'auto';
}
return {
ok: true,
status: 200,
@@ -785,6 +849,12 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
json: async () => ({
uiBundleVersion: currentBundleVer,
settings: { ...mockSettings },
contextWindowModels: [
{ id: 'model:gemini-4-argon', label: 'Argon', members: ['MODEL_PLACEHOLDER_M430', 'MODEL_PLACEHOLDER_M417'],
reportedLimitTokens: 256000, options: [{ name: '512000', tokens: 512000 }] },
{ id: 'model:gemini-3.8-flash', label: 'Flash', options: [{ name: '256K' }] },
{ id: 'MODEL_PLACEHOLDER_M432', label: 'Other', options: [] },
],
cloudStatus: { updateAvailable: true, currentPluginVersion: '1.4.2', latestPluginVersion: '1.5.0' },
account: { tierName: 'Google AI Ultra', planName: 'Pro', totalConversations: 5 },
runningConversations: [
@@ -1257,16 +1327,22 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
assert.equal(liveDotSvg.attributes.get('width'), '11', 'Enlarged live activity SVG dot size is 11');
assert.equal(liveDotSvg.children[0].attributes.get('r'), '5', 'Enlarged dot circle radius is 5');
assert.match(stylesCss, /\.wm-multi-dot\s*\{\s*width:\s*8px;\s*height:\s*8px;/, 'Topbar multi-session dot enlarged to 8px');
assert.match(stylesCss, /\.wm-hover-tip\s*\{[^}]*width:\s*min\(542px,\s*calc\(100vw - 24px\)\);/, 'Hover floating card widened by 50px to 542px');
assert.match(stylesCss, /\.wm-hover-tip\s*\{[^}]*width:\s*min\(522px,\s*calc\(100vw - 24px\)\);/, 'Hover floating card width is 522px');
assert.equal(multiPanelEl.querySelector('.wm-recent-list'), null, 'Recent sessions list removed so panel shows online sessions only');
assert.equal(multiPanelEl.querySelector('.panel'), null, 'Single-layer multi-session panel without nested .panel box');
// Verify hovering right capsule closes unpinned multi-session panel and opens rich 3-card hover overview HUD (.wm-hover-tip)
// Verify hovering right capsule closes unpinned multi-session panel and opens decoupled 3-widget hover HUD (.wm-hover-tip)
assert.ok(hoverTipEl, 'Hover overview HUD mounted in portal shadow root');
assert.equal(
hoverTipEl.children.length,
4,
'Hover HUD has optional update banner + 3 signature cards (matrix + context + quotas)'
2,
'Hover HUD has optional update banner + decoupled .wm-hover-widgets host'
);
const hoverWidgetsHost = hoverTipEl.querySelector('.wm-hover-widgets');
assert.equal(
hoverWidgetsHost.children.length,
3,
'Default hoverModules mounts 3 standalone widgets (metrics + context + quotas)'
);
assert.equal(
multiPanelEl.querySelector('.wm-multi-empty-hint'),
@@ -1343,152 +1419,78 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
assert.equal(selectRoot.classList.contains('is-open'), true, 'CustomSelect stays open via composedPath');
selectTrigger.dispatchEvent({ type: 'click', stopPropagation() {} });
// Verify SettingsView: weekly budget UI removed; topbar multi-session switch & 3-slot customization work live
// Verify modular 3-tab SettingsView (常规 / 结构 / 其他) & decoupled registries
const pillTabs = popoverEl.querySelectorAll('.pill-tab');
pillTabs[pillTabs.length - 1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
const allPanes = popoverEl.querySelectorAll('.view-pane');
const settingsPane = allPanes[allPanes.length - 1];
assert.equal(settingsPane.querySelectorAll('.number-input').length, 0, 'Obsolete weekly budget number inputs removed');
const settingsSelects = settingsPane.querySelectorAll('.custom-select');
assert.equal(
settingsSelects.length,
7,
'SettingsView renders 7 CustomSelect controls (mount, modelFormat, orchestratorIdFormat, 3 topbar slots, autoUpdate)'
);
const mountSelectEl = settingsSelects[0];
const modelFormatSelectEl = settingsSelects[1];
const orchestratorIdSelectEl = settingsSelects[2];
const slot0SelectEl = settingsSelects[3];
const slot1SelectEl = settingsSelects[4];
const slot2SelectEl = settingsSelects[5];
const settingsRoot = popoverEl.querySelector('.settings-view-root');
const subNavBtns = settingsRoot.querySelector('.settings-subnav-bar').querySelectorAll('.seg-btn');
assert.equal(subNavBtns.length, 3, 'SettingsView renders 3 sub-tabs: 常规 / 结构 / 其他');
assert.equal(subNavBtns[0].textContent, '常规');
assert.equal(subNavBtns[1].textContent, '结构');
assert.equal(subNavBtns[2].textContent, '其他');
const [generalPane, structurePane, otherPane] = settingsRoot.querySelectorAll('.settings-tab-stack');
assert.equal(generalPane.hasAttribute('hidden'), false, 'General tab active by default');
assert.equal(structurePane.hasAttribute('hidden'), true);
assert.equal(otherPane.hasAttribute('hidden'), true);
// Toggle windowMountSelect: dual -> composer -> sidebar -> dual
assert.ok(mountSelectEl.querySelector('.select-label').textContent.includes('顶部栏 + 侧边栏'));
mountSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
mountSelectEl.querySelectorAll('.select-option')[1].dispatchEvent({ type: 'click', stopPropagation() {} });
// --- Tab 0: 常规 (languageSwitch, themeAccent, fontScaleSwitch, pluginUpdateMode) ---
const generalSegControls = generalPane.querySelectorAll('.segmented');
assert.equal(generalSegControls.length, 2, 'General tab has Language and FontScale segmented controls');
const langBtns = generalSegControls[0].querySelectorAll('.seg-btn');
const fontScaleBtns = generalSegControls[1].querySelectorAll('.seg-btn');
assert.equal(langBtns.length, 3, 'Language switch has 简体中文 / English / 跟随宿主');
assert.equal(langBtns[0].textContent, '简体中文');
assert.equal(langBtns[0].classList.contains('is-active'), true, 'Default language is zh-CN');
const generalSelects = generalPane.querySelectorAll('.custom-select');
assert.equal(generalSelects.length, 1, 'General tab has Update Mode select');
const updateModeSelectEl = generalSelects[0];
// Theme accent picker: switch to emerald, verify CSS vars injected on both hosts, then restore host
const swatchBtns = generalPane.querySelectorAll('.theme-swatch-btn');
assert.equal(swatchBtns.length, 6, '6 curated theme swatches rendered');
const emeraldBtn = swatchBtns.find((b) => b.getAttribute('data-accent-key') === 'emerald');
emeraldBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.windowMountMode, 'composer', 'windowMountMode persisted as composer');
assert.equal(mockSettings.enableWindowOverlay, true, 'enableWindowOverlay stays true in composer mode');
assert.ok(mountSelectEl.querySelector('.select-label').textContent.includes('输入框挂载'), 'UI reflects composer mode');
mountSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
mountSelectEl.querySelectorAll('.select-option')[2].dispatchEvent({ type: 'click', stopPropagation() {} });
assert.equal(mockSettings.themeAccent, 'emerald');
assert.equal(portalHost.style.getPropertyValue('--user-accent-primary'), 'hsl(152 66% 39%)', 'Portal host gets emerald accent');
assert.equal(capsuleHost.style.getPropertyValue('--user-accent-primary'), 'hsl(152 66% 39%)', 'Capsule host gets emerald accent');
const hostChipBtn = generalPane.querySelector('.theme-host-chip');
hostChipBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.windowMountMode, 'sidebar', 'windowMountMode persisted as sidebar');
assert.equal(mockSettings.enableWindowOverlay, false, 'enableWindowOverlay persisted as false');
assert.ok(mountSelectEl.querySelector('.select-label').textContent.includes('仅侧边栏'), 'UI reflects sidebar mode');
assert.equal(mockSettings.themeAccent, 'host');
assert.equal(portalHost.style.getPropertyValue('--user-accent-primary'), '', 'Host accent clears override');
mountSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
mountSelectEl.querySelectorAll('.select-option')[0].dispatchEvent({ type: 'click', stopPropagation() {} });
// Font scale: switch to xl (1.15), verify portalHost scales while capsuleHost NEVER scales
assert.equal(fontScaleBtns.length, 4, 'Font scale segmented control has sm / md / lg / xl');
fontScaleBtns[3].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.windowMountMode, 'dual', 'windowMountMode persisted back to dual');
assert.equal(mockSettings.enableWindowOverlay, true, 'enableWindowOverlay persisted back to true');
assert.ok(mountSelectEl.querySelector('.select-label').textContent.includes('顶部栏 + 侧边栏'), 'UI reflects dual mode');
// Toggle stepModelSelect: short -> upstream -> short
assert.ok(modelFormatSelectEl.querySelector('.select-label').textContent.includes('精简代号'));
modelFormatSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
modelFormatSelectEl.querySelectorAll('.select-option')[1].dispatchEvent({ type: 'click', stopPropagation() {} });
assert.equal(mockSettings.fontScale, 'xl');
assert.equal(portalHost.style.getPropertyValue('--ui-font-scale'), '1.15', 'Portal host scales to 1.15');
assert.equal(capsuleHost.style.getPropertyValue('--ui-font-scale'), '', 'Capsule host strictly excludes font scale');
assert.equal(capsuleHost.hasAttribute('data-font-scale'), false);
fontScaleBtns[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showUpstreamModel, true);
assert.ok(modelFormatSelectEl.querySelector('.select-label').textContent.includes('原始模型 ID'));
assert.equal(mockSettings.fontScale, 'md');
assert.equal(portalHost.style.getPropertyValue('--ui-font-scale'), '');
assert.equal(portalHost.getAttribute('data-font-scale'), 'md');
modelFormatSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
modelFormatSelectEl.querySelectorAll('.select-option')[0].dispatchEvent({ type: 'click', stopPropagation() {} });
// Live i18n switch: zh-CN -> en-US -> zh-CN without page reload
langBtns[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showUpstreamModel, false);
assert.ok(modelFormatSelectEl.querySelector('.select-label').textContent.includes('精简代号'));
// Toggle orchestratorIdSelect: compact -> full -> compact
assert.ok(orchestratorIdSelectEl.querySelector('.select-label').textContent.includes('精简代号'));
orchestratorIdSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
orchestratorIdSelectEl.querySelectorAll('.select-option')[1].dispatchEvent({ type: 'click', stopPropagation() {} });
assert.equal(mockSettings.language, 'en-US');
assert.equal(pillTabs[0].querySelector('.pill-tab-label').textContent, 'Live');
assert.equal(pillTabs[3].querySelector('.pill-tab-label').textContent, 'Settings');
assert.equal(subNavBtns[0].textContent, 'General');
assert.equal(subNavBtns[1].textContent, 'Structure');
assert.equal(subNavBtns[2].textContent, 'Other');
langBtns[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.orchestratorIdMode, 'full');
assert.ok(orchestratorIdSelectEl.querySelector('.select-label').textContent.includes('原始完整 ID'));
orchestratorIdSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
orchestratorIdSelectEl.querySelectorAll('.select-option')[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.orchestratorIdMode, 'compact');
assert.ok(orchestratorIdSelectEl.querySelector('.select-label').textContent.includes('精简代号'));
// Toggle topbar multi-session switch: show -> hide -> show
const topbarSegBtns = settingsPane.querySelectorAll('.seg-btn');
assert.equal(topbarSegBtns.length, 2, 'Topbar multi-session toggle has 显示 / 隐藏 buttons');
topbarSegBtns[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showTopbarMultiSession, false);
assert.equal(multiBtn.hasAttribute('hidden'), true, 'Topbar multi-session button hidden immediately');
assert.equal(capsuleHost.getAttribute('data-multi'), 'off');
topbarSegBtns[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showTopbarMultiSession, true);
assert.equal(multiBtn.hasAttribute('hidden'), false, 'Topbar multi-session button restored immediately');
// Customize 3 topbar capsule slots: [gemini_5h, ttft, cost], then swap order, test claude_weekly + none, then reset default
const capSlots = capsuleHost.shadowRoot.querySelectorAll('.wm-cap-slot');
const capSeps = capsuleHost.shadowRoot.querySelectorAll('.wm-sep');
assert.equal(capSlots.length, 3);
assert.equal(capSeps.length, 2);
// Slot 0 -> Gemini 5h (option index 5)
slot0SelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
slot0SelectEl.querySelectorAll('.select-option')[5].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(capSlots[0].getAttribute('data-metric'), 'gemini_5h');
assert.equal(capSlots[0].children.length, 1, 'Ring SVG detached cleanly when slot leaves context');
assert.equal(capSlots[0].children[0].textContent, '余 44%');
// Slot 1 -> TTFT (option index 2)
slot1SelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
slot1SelectEl.querySelectorAll('.select-option')[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(capSlots[1].getAttribute('data-metric'), 'ttft');
assert.equal(capSlots[1].children[0].textContent, '0.85s');
// Slot 2 -> Cost (option index 3)
slot2SelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
slot2SelectEl.querySelectorAll('.select-option')[3].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(capSlots[2].getAttribute('data-metric'), 'cost');
assert.equal(capSlots[2].children[0].textContent, '$0.040');
assert.deepEqual(mockSettings.topbarCapsuleSlots, ['gemini_5h', 'ttft', 'cost']);
// Swap Slot 1 up (left) so order becomes ['ttft', 'gemini_5h', 'cost']
const slotMoveBtns = settingsPane.querySelectorAll('.slot-move-btn');
// Row 1 up button is index 2 ([row0Up, row0Down, row1Up, row1Down, row2Up, row2Down])
slotMoveBtns[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.deepEqual(mockSettings.topbarCapsuleSlots, ['ttft', 'gemini_5h', 'cost']);
assert.equal(capSlots[0].children[0].textContent, '0.85s');
assert.equal(capSlots[1].children[0].textContent, '余 44%');
// Test hiding middle slot ('none', option index 9) and setting Slot 2 to Claude Weekly (option index 8)
slot1SelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
slot1SelectEl.querySelectorAll('.select-option')[9].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
slot2SelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
slot2SelectEl.querySelectorAll('.select-option')[8].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(capSlots[1].hasAttribute('hidden'), true, 'Middle slot hidden when set to none');
assert.equal(capSeps[0].hasAttribute('hidden'), true, 'Separator before hidden middle slot collapses');
assert.equal(capSeps[1].hasAttribute('hidden'), false, 'Single separator remains between Slot 0 and Slot 2');
assert.equal(capSeps[1].getAttribute('data-sep-for-rank'), '2');
assert.equal(capSlots[2].getAttribute('data-vis-rank'), '2');
assert.equal(capSlots[2].children[0].textContent, '余 91%');
// Reset default restores ['context', 'tps', 'quota_auto'] with ring SVG re-attached on Slot 0
const resetTopbarBtn = settingsPane.querySelector('.btn-ghost-sm');
resetTopbarBtn.dispatchEvent({ type: 'click' });
await new Promise((r) => setTimeout(r, 260));
assert.deepEqual(mockSettings.topbarCapsuleSlots, ['context', 'tps', 'quota_auto']);
assert.equal(capSlots[0].getAttribute('data-metric'), 'context');
assert.equal(capSlots[0].children.length, 2, 'Ring SVG re-attached on Slot 0');
assert.equal(capSlots[0].querySelector('.wm-ctx-pct').textContent, '50%');
assert.equal(mockSettings.language, 'zh-CN');
assert.equal(pillTabs[0].querySelector('.pill-tab-label').textContent, '实时监控');
assert.equal(subNavBtns[0].textContent, '常规');
// Verify 3-tier update mode select (manual default -> off hides topbar/hover prompts -> auto -> manual)
const topbarUpdateBtn = capsuleHost.shadowRoot.querySelector('.wm-update-btn');
@@ -1520,7 +1522,6 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
);
assert.equal(headerUpdateBtn.hasAttribute('hidden'), false);
const updateModeSelectEl = settingsSelects[6];
assert.equal(updateModeSelectEl.querySelector('.select-label').textContent, '仅提示新版本,手动更新');
updateModeSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
const updateOpts = updateModeSelectEl.querySelectorAll('.select-option');
@@ -1551,6 +1552,271 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
assert.equal(mockSettings.autoUpdatePlugin, false);
assert.equal(topbarUpdateBtn.hasAttribute('hidden'), false, 'Topbar update pill visible when mode=manual');
// --- Tab 1: 结构 (4 accordion sections: capsule 1..5, hover 0..4, overview 1..4 + 1..4, step columns 2..12) ---
subNavBtns[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
assert.equal(structurePane.hasAttribute('hidden'), false);
const accordionSections = structurePane.querySelectorAll('.collapsible-section');
assert.equal(accordionSections.length, 4, 'Structure tab has 4 collapsible sections');
assert.equal(accordionSections[0].classList.contains('is-expanded'), true, 'Section 1 expanded by default');
assert.equal(accordionSections[1].classList.contains('is-expanded'), false, 'Section 2 collapsed by default');
const sec0 = accordionSections[0];
const mountSelectEl = sec0.querySelectorAll('.custom-select')[0];
// Toggle windowMountSelect: dual -> composer -> sidebar -> dual
assert.ok(mountSelectEl.querySelector('.select-label').textContent.includes('顶部栏 + 侧边栏'));
mountSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
mountSelectEl.querySelectorAll('.select-option')[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.windowMountMode, 'composer', 'windowMountMode persisted as composer');
assert.equal(mockSettings.enableWindowOverlay, true, 'enableWindowOverlay stays true in composer mode');
assert.ok(mountSelectEl.querySelector('.select-label').textContent.includes('输入框挂载'), 'UI reflects composer mode');
mountSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
mountSelectEl.querySelectorAll('.select-option')[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.windowMountMode, 'sidebar', 'windowMountMode persisted as sidebar');
assert.equal(mockSettings.enableWindowOverlay, false, 'enableWindowOverlay persisted as false');
assert.ok(mountSelectEl.querySelector('.select-label').textContent.includes('仅侧边栏'), 'UI reflects sidebar mode');
// Re-open popover after sidebar closed it and switch back to dual
ov.open();
mountSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
mountSelectEl.querySelectorAll('.select-option')[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.windowMountMode, 'dual', 'windowMountMode persisted back to dual');
assert.equal(mockSettings.enableWindowOverlay, true, 'enableWindowOverlay persisted back to true');
// Toggle topbar multi-session switch: show -> hide -> show
const topbarSegBtns = sec0.querySelectorAll('.seg-btn');
assert.equal(topbarSegBtns.length, 2, 'Topbar multi-session toggle has 显示 / 隐藏 buttons');
topbarSegBtns[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showTopbarMultiSession, false);
assert.equal(multiBtn.hasAttribute('hidden'), true, 'Topbar multi-session button hidden immediately');
assert.equal(capsuleHost.getAttribute('data-multi'), 'off');
topbarSegBtns[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showTopbarMultiSession, true);
assert.equal(multiBtn.hasAttribute('hidden'), false, 'Topbar multi-session button restored immediately');
// Dynamic 1..5 capsule slots via EditableSlotList (+ / - / ↑ / ↓)
const capSlots = capsuleHost.shadowRoot.querySelectorAll('.wm-cap-slot');
const capSeps = capsuleHost.shadowRoot.querySelectorAll('.wm-sep');
assert.equal(capSlots.length, 5, '5 capsule slot nodes pre-reserved');
assert.equal(capSeps.length, 4, '4 capsule separators pre-reserved');
assert.equal(capSlots[3].hasAttribute('hidden'), true, 'Slot 4 hidden by default (3 slots)');
assert.equal(capSlots[4].hasAttribute('hidden'), true, 'Slot 5 hidden by default (3 slots)');
const capSlotWrap = sec0.querySelector('.editable-slot-wrap');
let capRowSelects = capSlotWrap.querySelectorAll('.custom-select');
assert.equal(capRowSelects.length, 3, 'Default 3 capsule slot rows in EditableSlotList');
// Slot 0 -> Gemini 5h (index 9), Slot 1 -> TTFT (index 2), Slot 2 -> Cost (index 4)
capRowSelects[0].querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
capRowSelects[0].querySelectorAll('.select-option')[9].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(capSlots[0].getAttribute('data-metric'), 'gemini_5h');
assert.equal(capSlots[0].children.length, 1, 'Ring SVG detached cleanly when slot leaves context');
assert.equal(capSlots[0].children[0].textContent, '余 44%');
capRowSelects[1].querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
capRowSelects[1].querySelectorAll('.select-option')[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(capSlots[1].getAttribute('data-metric'), 'ttft');
assert.equal(capSlots[1].children[0].textContent, '0.85s');
capRowSelects[2].querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
capRowSelects[2].querySelectorAll('.select-option')[4].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(capSlots[2].getAttribute('data-metric'), 'cost');
assert.equal(capSlots[2].children[0].textContent, '$0.040');
assert.deepEqual(mockSettings.topbarCapsuleSlots, ['gemini_5h', 'ttft', 'cost']);
// Move Row 1 up (left): each row has [up, down, remove], so Row 1 up is index 3
capSlotWrap.querySelectorAll('.slot-move-btn')[3].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.deepEqual(mockSettings.topbarCapsuleSlots, ['ttft', 'gemini_5h', 'cost']);
assert.equal(capSlots[0].children[0].textContent, '0.85s');
assert.equal(capSlots[1].children[0].textContent, '余 44%');
// Click `+ 添加指标` twice to expand from 3 -> 5 slots
const capAddBtn = capSlotWrap.querySelector('.slot-add-btn');
capAddBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
capAddBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.topbarCapsuleSlots.length, 5, 'Expanded to maximum 5 capsule slots');
assert.equal(capAddBtn.hasAttribute('disabled'), true, '+ button disabled at max 5 slots');
assert.equal(capSlots[3].hasAttribute('hidden'), false, 'Slot 4 now visible');
assert.equal(capSlots[4].hasAttribute('hidden'), false, 'Slot 5 now visible');
assert.equal(capSeps[3].hasAttribute('hidden'), false, 'Separator 4 now visible');
// Remove down to 1 slot using `-` button, verifying min=1 protection
for (let r = 0; r < 4; r += 1) {
const remBtns = capSlotWrap.querySelectorAll('.slot-remove-btn');
remBtns[remBtns.length - 1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 25));
}
assert.equal(mockSettings.topbarCapsuleSlots.length, 1, 'Shrunk to minimum 1 capsule slot');
assert.equal(capSlotWrap.querySelector('.slot-remove-btn').hasAttribute('disabled'), true, '- button disabled at min 1 slot');
assert.equal(capSeps[0].hasAttribute('hidden'), true, 'All separators hidden when 1 slot');
// Reset Section 0 restores default 3 slots ['context', 'tps', 'quota_auto']
sec0.querySelector('.btn-ghost-sm').dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 40));
assert.deepEqual(mockSettings.topbarCapsuleSlots, ['context', 'tps', 'quota_auto']);
assert.equal(capSlots[0].getAttribute('data-metric'), 'context');
assert.equal(capSlots[0].children.length, 2, 'Ring SVG re-attached on Slot 0');
assert.equal(capSlots[0].querySelector('.wm-ctx-pct').textContent, '50%');
// Section 1: Hover Popup Modules (0..4) — removing all 3 suppresses hover popup while click popover still works
const sec1 = accordionSections[1];
sec1.querySelector('.collapsible-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
const hoverSlotWrap = sec1.querySelector('.editable-slot-wrap');
for (let r = 0; r < 3; r += 1) {
const remBtns = hoverSlotWrap.querySelectorAll('.slot-remove-btn');
remBtns[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 25));
}
assert.deepEqual(mockSettings.hoverModules, [], 'Hover modules emptied to 0 items');
assert.equal(hoverSlotWrap.querySelector('.editable-slot-empty').hasAttribute('hidden'), false, '0-module empty hint visible');
// Temporarily set pluginUpdateMode=off via Settings UI so update banner is also absent, then close popover and hover capsuleBtn
updateModeSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
updateModeSelectEl.querySelectorAll('.select-option')[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
ov.close();
capsuleBtn.dispatchEvent({ type: 'mouseenter', clientX: 960, clientY: 18 });
assert.equal(ov.isHoverOpen(), false, 'Hover popup stays suppressed when hoverModules=[] and no update banner');
// Click popover still opens cleanly!
capsuleBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
assert.equal(ov.isOpen(), true, 'Click full monitor popover still opens when hoverModules=[]');
updateModeSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
updateModeSelectEl.querySelectorAll('.select-option')[0].dispatchEvent({ type: 'click', stopPropagation() {} });
sec1.querySelector('.btn-ghost-sm').dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 40));
assert.deepEqual(mockSettings.hoverModules, ['metrics', 'context', 'quotas']);
// Section 2: Live Overview Layout (overviewModules 1..4 + overviewMetrics 1..4)
const sec2 = accordionSections[2];
sec2.querySelector('.collapsible-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
const [ovModWrap, ovMetricWrap] = sec2.querySelectorAll('.editable-slot-wrap');
// Move row 2 ('quotas') up above 'context' -> ['metrics', 'quotas', 'context', 'live_tasks']
ovModWrap.querySelectorAll('.slot-move-btn')[6].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.deepEqual(mockSettings.overviewModules, ['metrics', 'quotas', 'context', 'live_tasks']);
// Remove 2 metrics from first-row matrix -> 2 columns ['tps', 'ttft']
ovMetricWrap.querySelectorAll('.slot-remove-btn')[3].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 25));
ovMetricWrap.querySelectorAll('.slot-remove-btn')[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 25));
assert.deepEqual(mockSettings.overviewMetrics, ['tps', 'ttft']);
pillTabs[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
const overviewHostEl = allPanes[0].querySelector('.overview-modules-host');
assert.equal(overviewHostEl.children[0].getAttribute('data-cols'), '2', 'MetricMatrixWidget adapts to 2 columns');
assert.ok(
overviewHostEl.children[1].querySelector('.panel-title').children[1].textContent.includes('可用额度'),
'QuotaPoolsWidget moved above ContextWindowWidget in LiveOverviewView'
);
pillTabs[3].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
sec2.querySelector('.btn-ghost-sm').dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 40));
assert.deepEqual(mockSettings.overviewModules, ['metrics', 'context', 'quotas', 'live_tasks']);
assert.deepEqual(mockSettings.overviewMetrics, ['tps', 'ttft', 'avg_tps', 'step_cost']);
// Section 3: Step Table Columns (2..12) — add optional 'time' and 'duration' columns
const sec3 = accordionSections[3];
sec3.querySelector('.collapsible-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
const stepColWrap = sec3.querySelector('.editable-slot-wrap');
stepColWrap.querySelector('.slot-add-btn').dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 25));
stepColWrap.querySelector('.slot-add-btn').dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 25));
assert.equal(mockSettings.stepTableColumns.length, 9, 'Added time and duration columns (7 -> 9)');
pillTabs[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
const stepHeaderThs = allPanes[2].querySelector('.data-table').children[0].children[0].children;
assert.equal(stepHeaderThs.length, 9, 'StepsDetailView thead dynamically renders 9 columns');
pillTabs[3].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
sec3.querySelector('.btn-ghost-sm').dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 40));
assert.equal(mockSettings.stepTableColumns.length, 7);
// --- Tab 2: 其他 (modelFormat, orchestratorId, contextBaseline reserved pill, cache rebuild, reset all) ---
subNavBtns[2].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
assert.equal(otherPane.hasAttribute('hidden'), false);
const otherSelects = otherPane.querySelectorAll('.custom-select');
assert.equal(otherSelects.length, 4);
const modelFormatSelectEl = otherSelects[0];
const orchestratorIdSelectEl = otherSelects[1];
// Toggle stepModelSelect: short -> upstream -> short
assert.ok(modelFormatSelectEl.querySelector('.select-label').textContent.includes('精简代号'));
modelFormatSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
modelFormatSelectEl.querySelectorAll('.select-option')[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showUpstreamModel, true);
assert.ok(modelFormatSelectEl.querySelector('.select-label').textContent.includes('原始模型 ID'));
modelFormatSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
modelFormatSelectEl.querySelectorAll('.select-option')[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.showUpstreamModel, false);
// Toggle orchestratorIdSelect: compact -> full
assert.ok(orchestratorIdSelectEl.querySelector('.select-label').textContent.includes('精简代号'));
orchestratorIdSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
orchestratorIdSelectEl.querySelectorAll('.select-option')[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(mockSettings.orchestratorIdMode, 'full');
assert.ok(orchestratorIdSelectEl.querySelector('.select-label').textContent.includes('原始完整 ID'));
const [contextModel, contextWindow] = otherSelects.slice(2);
const selectOption = (select, index) => {
select.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
select.querySelectorAll('.select-option')[index].dispatchEvent({ type: 'click', stopPropagation() {} });
};
assert.equal(contextWindow.parentNode.hasAttribute('hidden'), true);
contextModel.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
assert.match(contextModel.querySelectorAll('.select-option')[1].querySelector('.select-option-meta').textContent, /默认.*256,000/);
contextModel.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
selectOption(contextModel, 1);
selectOption(contextWindow, 1);
await new Promise((r) => setTimeout(r, 30));
assert.deepEqual(mockSettings.modelContextWindows, { 'model:gemini-4-argon': '512000' });
contextModel.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
assert.match(contextModel.querySelectorAll('.select-option')[1].querySelector('.select-option-meta').textContent, /512,000.*已设置/);
contextModel.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
selectOption(contextModel, 2);
assert.equal(contextWindow.querySelector('.select-label').textContent, '跟随宿主设置');
selectOption(contextWindow, 1);
await new Promise((r) => setTimeout(r, 30));
selectOption(contextModel, 1);
selectOption(contextWindow, 0);
await new Promise((r) => setTimeout(r, 30));
assert.deepEqual(mockSettings.modelContextWindows, { 'model:gemini-3.8-flash': '256K' });
selectOption(contextModel, 3);
assert.equal(contextWindow.querySelector('.select-trigger').hasAttribute('disabled'), true);
const maintBtns = otherPane.querySelectorAll('.btn-secondary');
const rebuildBtn = maintBtns[0];
const resetAllBtn = maintBtns[1];
rebuildBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));
assert.equal(cacheRebuildCalls, 1, 'POST /api/cache/rebuild invoked cleanly');
// Two-step confirm for Reset All Settings: 1st click arms confirm, 2nd click resets all settings
resetAllBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
assert.equal(resetAllBtn.classList.contains('btn-danger-confirm'), true, '1st click arms confirmation state');
assert.equal(mockSettings.orchestratorIdMode, 'full', 'Not yet reset on 1st click');
resetAllBtn.dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 260));
assert.equal(mockSettings.orchestratorIdMode, 'compact', '2nd click resets orchestratorIdMode to default');
// Verify ConsumptionView omits "+ 待定" / "3993 步费用待定" and StepsDetailView protects header title
pillTabs[1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
@@ -2125,9 +2391,20 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
jetskiObj.globalThis = jetskiObj;
const jetskiVm = vm.createContext(jetskiObj);
const modelId = 'MODEL_PLACEHOLDER_M430';
const chat = {
location: new URL('http://127.0.0.1:50234/?extensionView=true'),
__APP_CONFIG__: { csrfToken: 'chat-test' },
fetch: async () => ({ ok: true, json: async () => ({ userStatus: { cascadeModelConfigData: {
clientModelConfigs: [{ modelOrAlias: { model: modelId }, contextWindowOptions: [{ name: '900K' }] }],
} } }) }),
};
chat.window = chat;
const chatVm = vm.createContext({ ...chat, window: chat, TextEncoder, TextDecoder, AbortSignal, setTimeout, clearTimeout });
const vmMap = new Map([
['ide-main', ideVm],
['ide-jetski', jetskiVm],
['ide-chat', chatVm],
]);
class MockIdeWebSocket {
@@ -2145,9 +2422,9 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
if (msg.method === 'Runtime.evaluate') {
const ctx = vmMap.get(this.targetId);
const value = vm.runInContext(msg.params.expression, ctx);
queueMicrotask(() =>
Promise.resolve(value).then((result) =>
this._emit('message', {
data: JSON.stringify({ id: msg.id, result: { result: { value } } }),
data: JSON.stringify({ id: msg.id, result: { result: { value: result } } }),
})
);
}
@@ -2165,6 +2442,7 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
res.end(
JSON.stringify([
{
id: 'ide-main',
type: 'page',
url: 'vscode-file://vscode-app/c:/Program%20Files/Antigravity%20IDE/resources/app/out/vs/code/electron-browser/workbench/workbench.html',
webSocketDebuggerUrl: `ws://127.0.0.1:${p}/devtools/page/ide-main`,
@@ -2179,6 +2457,12 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
url: 'vscode-file://vscode-app/c:/Program%20Files/Antigravity%20IDE/resources/app/out/vs/code/electron-browser/sharedProcess/sharedProcess.html',
webSocketDebuggerUrl: `ws://127.0.0.1:${p}/devtools/page/shared`,
},
{
type: 'iframe',
parentId: 'ide-main',
url: chat.location.href,
webSocketDebuggerUrl: `ws://127.0.0.1:${p}/devtools/page/ide-chat`,
},
])
);
return;
@@ -2195,6 +2479,7 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
);
const prefetchedConvIds = [];
const settings = { enableWindowOverlay: true, modelContextWindows: { [modelId]: '900K' } };
const mockAppJs = `
(() => {
const br = window.__AGUsageMonitorBridge;
@@ -2215,7 +2500,7 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
return { status: 200, contentType: 'application/json', body: JSON.stringify({ ok: true }) };
},
readAssetFn: async (rel) => (rel === 'styles.css' ? ':host{}' : mockAppJs),
getSettingsFn: () => ({ enableWindowOverlay: true }),
getSettingsFn: () => settings,
getBundleVersionFn: () => 'ide-v1',
env: { APPDATA: roamingDir, LOCALAPPDATA: localDir },
platform: 'win32',
@@ -2228,6 +2513,8 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
assert.equal(syncRes.ok, true, 'Stale 2.0 port did not block live Antigravity IDE port');
assert.equal(syncRes.targets, 2, 'Matched workbench.html and workbench-jetski-agent.html while excluding sharedProcess.html');
assert.equal(syncRes.injected, 2);
assert.equal(chat.__AGUsageMonitorContextWindows?.rules[modelId], '900K');
assert.equal(ideContextObj.__AGUsageMonitorContextWindows, undefined);
assert.ok(
prefetchedConvIds.includes('99999999-aaaa-bbbb-cccc-888888888888'),
'Initial telemetry prefetch extracted active IDE conversation UUID from DOM'
@@ -2242,6 +2529,10 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
},
});
assert.equal(ideOriginRes.status, 200);
settings.modelContextWindows = {};
await controller.syncAllWindows();
assert.equal(chat.__AGUsageMonitorContextWindows, undefined);
} finally {
await controller.stop({ disposeWindows: true });
await new Promise((resolve) => ideCdpServer.close(resolve));
@@ -3353,13 +3644,14 @@ test('Composer mount mode (输入框挂载) docks capsule immediately left of Au
const popTop = parseInt(popoverEl.style.top, 10);
assert.ok(Number.isFinite(popTop) && popTop < 810 - 200, `Popover opens above composer (top=${popTop})`);
// 4. Live hot-switch inside SettingsView from composer -> dual moves capsule back to topbar immediately
// 4. Live hot-switch inside SettingsView (结构 sub-tab) from composer -> dual moves capsule back to topbar immediately
const pillTabs = popoverEl.querySelectorAll('.pill-tab');
pillTabs[pillTabs.length - 1].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 15));
const allPanes = popoverEl.querySelectorAll('.view-pane');
const settingsPane = allPanes[allPanes.length - 1];
const mountSelectEl = settingsPane.querySelectorAll('.custom-select')[0];
const settingsRoot = popoverEl.querySelector('.settings-view-root');
settingsRoot.querySelector('.settings-subnav-bar').querySelectorAll('.seg-btn')[1].dispatchEvent({ type: 'click', stopPropagation() {} });
const structurePane = settingsRoot.querySelectorAll('.settings-tab-stack')[1];
const mountSelectEl = structurePane.querySelectorAll('.custom-select')[0];
mountSelectEl.querySelector('.select-trigger').dispatchEvent({ type: 'click', stopPropagation() {} });
mountSelectEl.querySelectorAll('.select-option')[0].dispatchEvent({ type: 'click', stopPropagation() {} });
await new Promise((r) => setTimeout(r, 30));