fix(panel): harden 2.33.0+ context window override injection and pending-restart status

- Inject backend pre-resolved MODEL_* fallback rules into syncHostContextWindows so
  context window overrides remain active even when window.__APP_CONFIG__.csrfToken is
  omitted, and extend request interception to cover StartCascade, URL inputs, Uint8Array
  JSON bodies, and application/connect+json 5-byte envelopes
- Trigger shortcut/launcher provisioning on modelContextWindows updates and surface the
  context-mode BridgeStatusNotice banner in App.js even when windowMountMode is 'sidebar'
- Show explicit '待重启生效' / 'Pending Restart' meta badge in SettingsOtherTab model
  dropdown and reveal ctxBridgeNotice immediately upon unlocking when CDP is inactive

Closes #27
This commit is contained in:
fish
2026-11-18 22:08:39 +09:00
parent 955dfeebb7
commit d665fb0c34
11 changed files with 293 additions and 37 deletions
+18 -3
View File
@@ -1544,6 +1544,7 @@ const I18N_MESSAGES_ZH_CN = Object.freeze({
'settings.oth.ctxUnavailable': '{name}(当前不可用)',
'settings.oth.ctxConfigured': '{name} · 已设置',
'settings.oth.ctxConfiguredReported': '{name} · 已设置 / 最近 {reported}',
'settings.oth.ctxPendingBridge': '{name} · 待重启生效',
'settings.oth.ctxDefaultReported': '默认 · 最近 {name}',
'settings.oth.ctxReported': '最近一次请求由宿主报告为 {name}。',
'settings.oth.ctxMixed': '各推理档设置不同',
@@ -2173,6 +2174,7 @@ const I18N_MESSAGES_EN_US = Object.freeze({
'settings.oth.ctxUnavailable': '{name} (currently unavailable)',
'settings.oth.ctxConfigured': '{name} · Set',
'settings.oth.ctxConfiguredReported': '{name} · Set / Last seen {reported}',
'settings.oth.ctxPendingBridge': '{name} · Pending Restart',
'settings.oth.ctxDefaultReported': 'Default · Last seen {name}',
'settings.oth.ctxReported': 'The host reported {name} on the latest request.',
'settings.oth.ctxMixed': 'Different limits by thinking level',
@@ -14110,7 +14112,7 @@ async function copyTextToClipboard(text) {
const BridgeStatusNotice = defineComponent({
name: 'BridgeStatusNotice',
setup({ props, onCleanup }) {
const contextMode = Boolean(props?.contextMode);
let contextMode = Boolean(props?.contextMode);
const dismissible = Boolean(props?.dismissible);
let lastPayload = {
visible: false,
@@ -14336,6 +14338,9 @@ const BridgeStatusNotice = defineComponent({
}
function update(next = {}) {
if (typeof next.contextMode === 'boolean') {
contextMode = next.contextMode;
}
lastPayload = {
...lastPayload,
...next,
@@ -16222,8 +16227,10 @@ const SettingsOtherTab = defineComponent({
patchAttr(ctxRiskAcceptBtn, 'disabled', acceptingContextRisk);
const saved = latestSettings?.modelContextWindows || {};
const wbState = String(latestWindowBridge?.state || '').trim();
const isBridgeMissing = wbState === 'no_devtools_port' || wbState === 'cdp_unreachable';
ctxBridgeNotice.refs.update({
visible: unlocked && Object.keys(saved).length > 0,
visible: unlocked,
windowBridge: latestWindowBridge,
hostPlatform: latestHostPlatform,
});
@@ -16271,6 +16278,7 @@ const SettingsOtherTab = defineComponent({
else if (value) {
const name = formatLimit(value);
if (!isAvailable(model, value)) meta = t('settings.oth.ctxUnavailable', { name });
else if (isBridgeMissing) meta = t('settings.oth.ctxPendingBridge', { name });
else if (/^\d+$/.test(value) && model.reportedLimitTokens && Number(value) !== model.reportedLimitTokens) {
meta = t('settings.oth.ctxConfiguredReported', {
name,
@@ -19163,10 +19171,16 @@ const App = defineComponent({
const mountMode = settings
? normalizeClientWindowMountMode(settings.windowMountMode, settings.enableWindowOverlay)
: 'sidebar';
const hasCtxOverrides = Boolean(
settings?.modelContextWindows && Object.keys(settings.modelContextWindows).length > 0
);
const shouldOfferGlobal =
!isWindowOverlayMode() && activeView !== 'settings' && mountMode !== 'sidebar';
!isWindowOverlayMode() &&
activeView !== 'settings' &&
(mountMode !== 'sidebar' || hasCtxOverrides);
globalBridgeNotice.refs.update({
visible: shouldOfferGlobal,
contextMode: mountMode === 'sidebar' && hasCtxOverrides,
windowBridge: telemetry?.windowBridge || null,
hostPlatform: telemetry?.hostPlatform || 'win32',
});
@@ -19240,6 +19254,7 @@ const App = defineComponent({
subagentCount: st.telemetry?.activeConversation?.subagentCount ?? 0,
windowMountMode: st.telemetry?.settings?.windowMountMode,
enableWindowOverlay: st.telemetry?.settings?.enableWindowOverlay,
modelContextWindows: st.telemetry?.settings?.modelContextWindows,
windowBridge: st.telemetry?.windowBridge,
hostPlatform: st.telemetry?.hostPlatform,
}),
+57 -21
View File
@@ -120,14 +120,21 @@ export function resolveContextWindowRules(models, preferences) {
export async function syncHostContextWindows(
rules,
bootId,
key = '__AGUsageMonitorContextWindows'
key = '__AGUsageMonitorContextWindows',
fallbackRules = {}
) {
let state = window[key];
const appConfig = window.__APP_CONFIG__;
const csrfToken = appConfig?.csrfToken;
if (!Object.keys(rules).length || !csrfToken || appConfig.isRemoteControl) {
const hasPrefs = Boolean(rules && Object.keys(rules).length > 0);
const safeFallback =
fallbackRules && typeof fallbackRules === 'object' && !Array.isArray(fallbackRules)
? fallbackRules
: {};
const hasFallback = Object.keys(safeFallback).length > 0;
if (!hasPrefs || appConfig?.isRemoteControl || (!csrfToken && !hasFallback)) {
state?.dispose();
return;
return { attached: false, ruleCount: 0 };
}
if (state && (state.bootId !== bootId || !state.isAttached?.())) {
state.dispose();
@@ -136,6 +143,8 @@ export async function syncHostContextWindows(
if (!state) {
const servicePath = '/exa.language_server_pb.LanguageServerService/';
const sendPath = servicePath + 'SendUserCascadeMessage';
const startPath = servicePath + 'StartCascade';
const isTargetProcedure = (p) => p === sendPath || p === startPath;
const nativeFetch = window.fetch;
const wsProto = window.WebSocket?.prototype;
const nativeSend = wsProto?.send;
@@ -160,11 +169,20 @@ export async function syncHostContextWindows(
}
function rewriteBody(body, contentType) {
if (contentType === 'application/json' && typeof body === 'string') {
const json = JSON.parse(body);
if (updatePayload(json)) return JSON.stringify(json);
} else if (contentType === 'application/grpc-web+json' && body instanceof Uint8Array &&
body.length >= 5 && body[0] === 0) {
if (contentType === 'application/json') {
if (typeof body === 'string') {
const json = JSON.parse(body);
if (updatePayload(json)) return JSON.stringify(json);
} else if (body instanceof Uint8Array) {
const json = JSON.parse(decoder.decode(body));
if (updatePayload(json)) return encoder.encode(JSON.stringify(json));
}
} else if (
(contentType === 'application/grpc-web+json' || contentType === 'application/connect+json') &&
body instanceof Uint8Array &&
body.length >= 5 &&
body[0] === 0
) {
const header = new DataView(body.buffer, body.byteOffset, body.byteLength);
if (header.getUint32(1) !== body.length - 5) return body;
const json = JSON.parse(decoder.decode(body.subarray(5)));
@@ -181,9 +199,15 @@ export async function syncHostContextWindows(
function fetchWithContextWindow(input, init) {
let nextInit = init;
try {
if (typeof input === 'string' && init?.method === 'POST') {
const url = new URL(input, window.location.href);
if (url.origin === window.location.origin && url.pathname === sendPath) {
const rawUrl =
typeof input === 'string'
? input
: input instanceof URL
? input.href
: '';
if (rawUrl && init?.method === 'POST') {
const url = new URL(rawUrl, window.location.href);
if (url.origin === window.location.origin && isTargetProcedure(url.pathname)) {
const type = new Headers(init.headers).get('content-type')?.split(';')[0].trim();
const body = rewriteBody(init.body, type);
if (body !== init.body) nextInit = { ...init, body };
@@ -200,13 +224,13 @@ export async function syncHostContextWindows(
function sendWithContextWindow(data) {
let nextData = data;
try {
if (typeof data === 'string' && data.includes(sendPath)) {
if (typeof data === 'string' && (data.includes(sendPath) || data.includes(startPath))) {
const url = new URL(this.url);
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
if (url.protocol === protocol && url.host === window.location.host &&
url.pathname === '/connect-websocket') {
const frame = JSON.parse(data);
if (frame.type === 'start' && frame.stream === false && frame.procedure === sendPath &&
if (frame.type === 'start' && frame.stream === false && isTargetProcedure(frame.procedure) &&
updatePayload(frame.payload)) {
nextData = JSON.stringify(frame);
}
@@ -220,7 +244,7 @@ export async function syncHostContextWindows(
state = window[key] = {
bootId,
rules: {},
rules: { ...safeFallback },
serviceUrl: window.location.origin + servicePath,
isAttached() {
return (typeof nativeFetch !== 'function' || window.fetch === fetchWithContextWindow) &&
@@ -238,12 +262,18 @@ export async function syncHostContextWindows(
if (typeof nativeSend === 'function') wsProto.send = sendWithContextWindow;
}
state.preferences = rules;
state.fallbackRules = safeFallback;
clearTimeout(state.timer);
state.timer = setTimeout(() => state.dispose(), 15000);
// App 和 IDE 同时打开时,各窗口只使用自身宿主上报的档位。
if (!csrfToken) {
state.rules = { ...safeFallback };
return { attached: Boolean(state.isAttached?.()), ruleCount: Object.keys(state.rules).length };
}
// App 和 IDE 同时打开时,各窗口优先使用自身宿主上报的档位;若窗口内查询异常则回退后端预解析规则。
if (state.csrfToken !== csrfToken || Date.now() >= state.refreshAt) {
if (state.csrfToken !== csrfToken) state.rules = {};
if (state.csrfToken !== csrfToken) state.rules = { ...safeFallback };
state.csrfToken = csrfToken;
state.refreshAt = Date.now() + 10000;
state.status = (async () => {
@@ -264,19 +294,25 @@ export async function syncHostContextWindows(
]);
const userStatus = status?.userStatus;
const configs = userStatus?.cascadeModelConfigData?.clientModelConfigs;
if (!Array.isArray(configs)) return null;
return getContextWindowModels(configs, catalog?.response?.models);
} catch {
return [];
return null;
}
})();
}
const status = state.status;
const models = await status;
if (window[key] !== state || state.status !== status) return;
state.rules = resolveContextWindowRules(models, state.preferences);
if (window[key] !== state || state.status !== status) {
return { attached: Boolean(state?.isAttached?.()), ruleCount: Object.keys(state?.rules || {}).length };
}
state.rules = Array.isArray(models)
? resolveContextWindowRules(models, state.preferences)
: { ...state.fallbackRules };
return { attached: Boolean(state.isAttached?.()), ruleCount: Object.keys(state.rules).length };
}
export function createContextWindowSyncExpression(preferences, bootId) {
export function createContextWindowSyncExpression(preferences, bootId, fallbackRules = {}) {
return `(() => {
${isContextWindowModelId.toString()}
${isContextWindowSettingId.toString()}
@@ -285,6 +321,6 @@ export function createContextWindowSyncExpression(preferences, bootId) {
${getContextWindowGroups.toString()}
${resolveContextWindowOption.toString()}
${resolveContextWindowRules.toString()}
return (${syncHostContextWindows.toString()})(${JSON.stringify(preferences)}, ${JSON.stringify(bootId)}, ${JSON.stringify(CONTEXT_WINDOWS_GLOBAL_KEY)});
return (${syncHostContextWindows.toString()})(${JSON.stringify(preferences)}, ${JSON.stringify(bootId)}, ${JSON.stringify(CONTEXT_WINDOWS_GLOBAL_KEY)}, ${JSON.stringify(fallbackRules || {})});
})()`;
}
+64 -3
View File
@@ -30,11 +30,16 @@ import {
normalizeWindowMountMode,
saveJson,
} from './config.mjs';
import { createContextWindowSyncExpression } from './context-windows.mjs';
import {
createContextWindowSyncExpression,
getContextWindowModels,
resolveContextWindowRules,
} from './context-windows.mjs';
import {
ensureDesktopLaunchEntriesConfigured,
resolveDesktopHostExecutable,
} from './desktop-launcher-config.mjs';
import { callLsRpc, getContextModelCatalog } from './ls-rpc.mjs';
const windowBridgeRef = `window[${JSON.stringify(WINDOW_BRIDGE_KEY)}]`;
const windowOverlayRef = `window[${JSON.stringify(WINDOW_OVERLAY_KEY)}]`;
@@ -768,6 +773,7 @@ export function createWindowBridgeController(options) {
};
let hadContextWindows = false;
let contextWindowBootId = `${process.pid}:${Date.now()}`;
let cachedBackendCtxModels = { expiresAt: 0, models: [] };
let nodeDepsPromise = null;
const allowedDynamicOrigins = new Set();
@@ -1367,11 +1373,42 @@ export function createWindowBridgeController(options) {
}
if (hasContextWindows || hadContextWindows) {
let fallbackRules = {};
if (
hasContextWindows &&
lsRuntimeEndpoint.baseUrl &&
lsRuntimeEndpoint.addr !== 'test.invalid'
) {
if (Date.now() >= cachedBackendCtxModels.expiresAt) {
try {
const [stRes, cat] = await Promise.all([
callLsRpc('GetUserStatus', {}, 1500),
getContextModelCatalog(),
]);
const cfgs = stRes?.userStatus?.cascadeModelConfigData?.clientModelConfigs;
if (Array.isArray(cfgs)) {
cachedBackendCtxModels = {
expiresAt: Date.now() + 10_000,
models: getContextWindowModels(cfgs, cat),
};
}
} catch {
// 忽略瞬态 LS 查询失败,保留上次缓存或交由窗口端解析
}
}
if (cachedBackendCtxModels.models.length > 0) {
fallbackRules = resolveContextWindowRules(cachedBackendCtxModels.models, contextWindows);
}
}
const chatUrls = [
...targets.filter((target) => !target.isIdeWorkbench).map((target) => target.webSocketDebuggerUrl),
...collectAllChatDebuggerUrls(targets),
];
const expression = createContextWindowSyncExpression(contextWindows, contextWindowBootId);
const expression = createContextWindowSyncExpression(
contextWindows,
contextWindowBootId,
fallbackRules
);
await Promise.allSettled([...new Set(chatUrls)].map((url) => evaluateOnTarget(url, expression)));
hadContextWindows = hasContextWindows;
}
@@ -1822,10 +1859,33 @@ export function createWindowBridgeController(options) {
return syncAllWindows({ forceReinject: false }).catch(() => ({ ok: false }));
}
function notifyContextWindowsChanged() {
const cur = getSettingsFn() || {};
const mountMode = normalizeWindowMountMode(cur.windowMountMode, cur.enableWindowOverlay);
const overlayOn = Boolean(cur.enableWindowOverlay !== false && mountMode !== 'sidebar');
const hasCtx = Object.keys(cur.modelContextWindows || {}).length > 0;
if (hasCtx) {
ideArgvProvisioned = false;
} else if (!overlayOn && autoConfigureIdeArgv) {
launcherConfigured = false;
void ensureDesktopLaunchEntriesConfigured({
enabled: false,
env,
platform,
homeDir,
execFileFn: launcherExecFileFn,
fsOps: launcherFsOps,
allowInTest: allowDesktopLauncherInTest,
}).catch(() => {});
}
return syncAllWindows({ forceReinject: false }).catch(() => ({ ok: false }));
}
return {
ensureBridgeServer,
syncAllWindows,
notifySettingChanged,
notifyContextWindowsChanged,
start,
stop,
getBridgeInfo: () => ({ port: bridgePort, token: bridgeToken, running: Boolean(server) }),
@@ -1882,5 +1942,6 @@ export function notifyWindowOverlaySetting(enabled) {
}
export function notifyModelContextWindowsChanged() {
return defaultBridgeController?.syncAllWindows().catch(() => {});
if (!defaultBridgeController) return Promise.resolve({ ok: false });
return defaultBridgeController.notifyContextWindowsChanged();
}
+2 -2
View File
@@ -4,11 +4,11 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用量监控</title>
<link rel="stylesheet" href="/styles.css?v=1795005324022">
<link rel="stylesheet" href="/styles.css?v=1795006728154">
<script src="/preload.js"></script>
</head>
<body>
<div id="app-root"></div>
<script src="/app.js?v=1795005324022"></script>
<script src="/app.js?v=1795006728154"></script>
</body>
</html>
+8 -1
View File
@@ -53,10 +53,16 @@ export const App = defineComponent({
const mountMode = settings
? normalizeClientWindowMountMode(settings.windowMountMode, settings.enableWindowOverlay)
: 'sidebar';
const hasCtxOverrides = Boolean(
settings?.modelContextWindows && Object.keys(settings.modelContextWindows).length > 0
);
const shouldOfferGlobal =
!isWindowOverlayMode() && activeView !== 'settings' && mountMode !== 'sidebar';
!isWindowOverlayMode() &&
activeView !== 'settings' &&
(mountMode !== 'sidebar' || hasCtxOverrides);
globalBridgeNotice.refs.update({
visible: shouldOfferGlobal,
contextMode: mountMode === 'sidebar' && hasCtxOverrides,
windowBridge: telemetry?.windowBridge || null,
hostPlatform: telemetry?.hostPlatform || 'win32',
});
@@ -130,6 +136,7 @@ export const App = defineComponent({
subagentCount: st.telemetry?.activeConversation?.subagentCount ?? 0,
windowMountMode: st.telemetry?.settings?.windowMountMode,
enableWindowOverlay: st.telemetry?.settings?.enableWindowOverlay,
modelContextWindows: st.telemetry?.settings?.modelContextWindows,
windowBridge: st.telemetry?.windowBridge,
hostPlatform: st.telemetry?.hostPlatform,
}),
@@ -41,7 +41,7 @@ async function copyTextToClipboard(text) {
export const BridgeStatusNotice = defineComponent({
name: 'BridgeStatusNotice',
setup({ props, onCleanup }) {
const contextMode = Boolean(props?.contextMode);
let contextMode = Boolean(props?.contextMode);
const dismissible = Boolean(props?.dismissible);
let lastPayload = {
visible: false,
@@ -267,6 +267,9 @@ export const BridgeStatusNotice = defineComponent({
}
function update(next = {}) {
if (typeof next.contextMode === 'boolean') {
contextMode = next.contextMode;
}
lastPayload = {
...lastPayload,
...next,
+1
View File
@@ -518,6 +518,7 @@ export const I18N_MESSAGES_EN_US = Object.freeze({
'settings.oth.ctxUnavailable': '{name} (currently unavailable)',
'settings.oth.ctxConfigured': '{name} · Set',
'settings.oth.ctxConfiguredReported': '{name} · Set / Last seen {reported}',
'settings.oth.ctxPendingBridge': '{name} · Pending Restart',
'settings.oth.ctxDefaultReported': 'Default · Last seen {name}',
'settings.oth.ctxReported': 'The host reported {name} on the latest request.',
'settings.oth.ctxMixed': 'Different limits by thinking level',
+1
View File
@@ -518,6 +518,7 @@ export const I18N_MESSAGES_ZH_CN = Object.freeze({
'settings.oth.ctxUnavailable': '{name}(当前不可用)',
'settings.oth.ctxConfigured': '{name} · 已设置',
'settings.oth.ctxConfiguredReported': '{name} · 已设置 / 最近 {reported}',
'settings.oth.ctxPendingBridge': '{name} · 待重启生效',
'settings.oth.ctxDefaultReported': '默认 · 最近 {name}',
'settings.oth.ctxReported': '最近一次请求由宿主报告为 {name}。',
'settings.oth.ctxMixed': '各推理档设置不同',
@@ -274,8 +274,10 @@ export const SettingsOtherTab = defineComponent({
patchAttr(ctxRiskAcceptBtn, 'disabled', acceptingContextRisk);
const saved = latestSettings?.modelContextWindows || {};
const wbState = String(latestWindowBridge?.state || '').trim();
const isBridgeMissing = wbState === 'no_devtools_port' || wbState === 'cdp_unreachable';
ctxBridgeNotice.refs.update({
visible: unlocked && Object.keys(saved).length > 0,
visible: unlocked,
windowBridge: latestWindowBridge,
hostPlatform: latestHostPlatform,
});
@@ -323,6 +325,7 @@ export const SettingsOtherTab = defineComponent({
else if (value) {
const name = formatLimit(value);
if (!isAvailable(model, value)) meta = t('settings.oth.ctxUnavailable', { name });
else if (isBridgeMissing) meta = t('settings.oth.ctxPendingBridge', { name });
else if (/^\d+$/.test(value) && model.reportedLimitTokens && Number(value) !== model.reportedLimitTokens) {
meta = t('settings.oth.ctxConfiguredReported', {
name,
@@ -210,3 +210,97 @@ test('host requests apply a rule only to the exact model across App and IDE tran
assert.equal(window.fetch, nativeFetch);
assert.equal(WebSocket.prototype.send, nativeSend);
});
test('Issue #27: syncHostContextWindows falls back to backend pre-resolved rules without __APP_CONFIG__.csrfToken and intercepts StartCascade + Uint8Array / connect+json frames', async () => {
const sendPath = '/exa.language_server_pb.LanguageServerService/SendUserCascadeMessage';
const startPath = '/exa.language_server_pb.LanguageServerService/StartCascade';
const host = 'https://127.0.0.1:26190';
const nativeFetch = async (_url, init) => init;
class WebSocket {
constructor(url) {
this.url = url;
}
send(data) {
return data;
}
}
const window = {
location: new URL(host),
fetch: nativeFetch,
WebSocket,
__APP_CONFIG__: {}, // Simulate 2.33.0+ environment without exposed csrfToken on window
};
const context = vm.createContext({
window,
URL,
TextEncoder,
TextDecoder,
Headers,
Uint8Array,
AbortSignal,
setTimeout,
clearTimeout,
});
const prefs = { [carbonGroup]: '256000' };
const fallbackRules = { [carbon]: 256000, [carbonLow]: 256000 };
const syncResult = await vm.runInContext(
createContextWindowSyncExpression(prefs, 'boot-233', fallbackRules),
context
);
assert.deepEqual({ ...syncResult }, { attached: true, ruleCount: 2 });
try {
// 1. StartCascade on new conversation creation with Uint8Array JSON body
const startPayload = {
cascadeConfig: {
plannerConfig: { planModel: carbon },
checkpointConfig: { maxTokenLimit: 512000 },
},
};
const uint8Body = new TextEncoder().encode(JSON.stringify(startPayload));
const startOut = await window.fetch(new URL(host + startPath), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: uint8Body,
});
assert.equal(startOut.body instanceof Uint8Array, true);
assert.equal(
JSON.parse(new TextDecoder().decode(startOut.body)).cascadeConfig.checkpointConfig
.maxTokenLimit,
256000
);
// 2. application/connect+json 5-byte envelope on SendUserCascadeMessage
const msgBytes = Buffer.from(JSON.stringify(startPayload), 'utf8');
const connectFrame = new Uint8Array(5 + msgBytes.length);
new DataView(connectFrame.buffer).setUint32(1, msgBytes.length);
connectFrame.set(msgBytes, 5);
const framedOut = await window.fetch(host + sendPath, {
method: 'POST',
headers: { 'Content-Type': 'application/connect+json' },
body: connectFrame,
});
const decodedJson = JSON.parse(
new TextDecoder().decode(framedOut.body.subarray(5))
);
assert.equal(decodedJson.cascadeConfig.checkpointConfig.maxTokenLimit, 256000);
// 3. WebSocket StartCascade frame
const ws = new WebSocket('wss://127.0.0.1:26190/connect-websocket');
const wsFrame = JSON.parse(
ws.send(
JSON.stringify({
type: 'start',
stream: false,
procedure: startPath,
payload: startPayload,
})
)
);
assert.equal(wsFrame.payload.cascadeConfig.checkpointConfig.maxTokenLimit, 256000);
} finally {
await vm.runInContext(createContextWindowSyncExpression({}, 'boot-233', {}), context);
}
assert.equal(window.fetch, nativeFetch);
});
+40 -5
View File
@@ -5306,26 +5306,61 @@ test('Issue #26: Antigravity Desktop 2.33.0+ automatic shortcut/launcher provisi
);
assert.equal(noticeEl.hasAttribute('hidden'), true);
// SettingsOtherTab context window override notice
// SettingsOtherTab context window override notice & pending-restart meta state (Issue #27)
setI18nLanguage('zh-CN');
const othTab = SettingsOtherTab({ onLayoutChange: () => {} });
const ctxNoticeEl = othTab.refs.ctxBridgeNotice.el;
const mockCtxModels = [
{
id: 'model:gemini-4-carbon',
label: 'Gemini 4 Carbon',
capacity: 786432,
members: ['MODEL_PLACEHOLDER_M427'],
options: [{ name: '256000', tokens: 256000 }, { name: '512000', tokens: 512000 }],
},
];
// Locked risk mask -> notice stays hidden
othTab.refs.renderSettings(
{ contextWindowRiskAccepted: true, modelContextWindows: { 'group:gemini-pro': '384000' } },
[],
{ contextWindowRiskAccepted: false, modelContextWindows: {} },
mockCtxModels,
{ state: 'no_devtools_port', launcherConfigured: true, canRelaunch: true },
'win32'
);
assert.equal(ctxNoticeEl.hasAttribute('hidden'), true);
// Unlocked + no_devtools_port -> notice immediately visible AND saved option meta shows "待重启生效" instead of "已设置"
othTab.refs.renderSettings(
{
contextWindowRiskAccepted: true,
modelContextWindows: { 'model:gemini-4-carbon': '256000' },
},
mockCtxModels,
{ state: 'no_devtools_port', launcherConfigured: true, canRelaunch: true },
'win32'
);
assert.equal(ctxNoticeEl.hasAttribute('hidden'), false);
assert.match(ctxNoticeEl.textContent, /激活上下文覆写/);
othTab.refs.ctxModelSelect.refs.triggerBtn.dispatchEvent({
type: 'click',
stopPropagation() {},
});
assert.match(
othTab.refs.ctxModelSelect.refs.menuEl.textContent,
/256,000 token · 待重启生效/
);
othTab.refs.renderSettings(
{ contextWindowRiskAccepted: true, modelContextWindows: { 'group:gemini-pro': '384000' } },
[],
{
contextWindowRiskAccepted: true,
modelContextWindows: { 'model:gemini-4-carbon': '256000' },
},
mockCtxModels,
{ state: 'active', aliveCount: 1, launcherConfigured: true, canRelaunch: true },
'win32'
);
assert.equal(ctxNoticeEl.hasAttribute('hidden'), true);
assert.match(othTab.refs.ctxModelSelect.refs.menuEl.textContent, /256,000 token · 已设置/);
globalBanner.destroy();
strTab.destroy();