mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
feat(panel): Antigravity IDE & composer mount, modular preferences, session charts, and per-model context windows (v1.5.0)
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtemp, readFile, rmdir, unlink } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import test from 'node:test';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { resolveGoogleCredential, retrieveCredentialQuota } from '../backend/account-oauth.mjs';
|
||||
import { handleAccountCredentialAction, normalizeAccountCredential, runWindowsCredentialStore } from '../backend/account-switch.mjs';
|
||||
|
||||
test('accepts a shared OAuth credential or refresh token, and rejects other credential types', () => {
|
||||
const refreshToken = '1//synthetic-refresh-token-for-test';
|
||||
assert.deepEqual(JSON.parse(normalizeAccountCredential(refreshToken)), {
|
||||
auth_method: 'consumer',
|
||||
token: { access_token: '', token_type: 'Bearer', refresh_token: refreshToken, expiry: '1970-01-01T00:00:00.000Z' },
|
||||
});
|
||||
const saved = JSON.parse(normalizeAccountCredential(JSON.stringify({
|
||||
token: { refresh_token: refreshToken, access_token: 'example-access', expiry_timestamp: 1800000000 },
|
||||
})));
|
||||
assert.equal(saved.token.access_token, 'example-access');
|
||||
assert.equal(saved.token.expiry, '2027-01-15T08:00:00.000Z');
|
||||
assert.equal(normalizeAccountCredential(JSON.stringify({ auth_method: 'enterprise', refresh_token: refreshToken })), null);
|
||||
assert.equal(normalizeAccountCredential('example-api-key'), null);
|
||||
});
|
||||
|
||||
test('import uses the verified email and switches only after checking the credential identity', async () => {
|
||||
const calls = [];
|
||||
const input = '1//synthetic-refresh-token-for-test';
|
||||
const credential = JSON.parse(normalizeAccountCredential(input));
|
||||
const saved = JSON.stringify(credential);
|
||||
let verifiedEmail = 'Next@example.com';
|
||||
const options = {
|
||||
platform: 'win32',
|
||||
resolveCredential: async (_credential, opts) => {
|
||||
calls.push(opts.refresh ? 'refresh-identity' : 'verify-identity');
|
||||
return { email: verifiedEmail, credential };
|
||||
},
|
||||
rpc: async (method) => {
|
||||
calls.push(method);
|
||||
return { userStatus: { email: 'Next@example.com' } };
|
||||
},
|
||||
store: async (request) => {
|
||||
calls.push(request.action);
|
||||
if (request.action === 'read') return { credential: saved };
|
||||
assert.equal(request.target, 'gemini:antigravity');
|
||||
assert.equal(request.email, 'next@example.com');
|
||||
if (request.action === 'switch') assert.equal(request.expectedCredential, saved);
|
||||
return { accounts: ['next@example.com'], selectedEmail: request.email, credential: saved };
|
||||
},
|
||||
};
|
||||
assert.deepEqual(await handleAccountCredentialAction({ action: 'save', email: 'ignored@example.com', credential: input }, options), {
|
||||
supported: true, accounts: ['next@example.com'], selectedEmail: 'next@example.com',
|
||||
});
|
||||
assert.deepEqual(calls.splice(0), ['refresh-identity', 'save']);
|
||||
const result = await handleAccountCredentialAction({ action: 'switch', email: 'NEXT@example.com' }, options);
|
||||
assert.deepEqual(result, { supported: true, accounts: ['next@example.com'], selectedEmail: 'next@example.com', confirmed: true });
|
||||
assert.deepEqual(calls.splice(0), ['read', 'verify-identity', 'switch', 'GetAuthStatus', 'GetUserStatus']);
|
||||
verifiedEmail = 'different@example.com';
|
||||
assert.deepEqual(await handleAccountCredentialAction({ action: 'switch', email: 'next@example.com' }, options), { error: 'identityMismatch' });
|
||||
assert.deepEqual(calls, ['read', 'verify-identity']);
|
||||
});
|
||||
|
||||
test('a saved credential can query its quota without replacing the active login', async () => {
|
||||
const credential = normalizeAccountCredential(JSON.stringify({ refresh_token: 'test', access_token: 'saved-access' }));
|
||||
const pools = [{ poolKey: 'Gemini', remainingPct: 0, weeklyRemainingPct: 29 }];
|
||||
const result = await handleAccountCredentialAction({ action: 'quota', email: 'next@example.com' }, {
|
||||
platform: 'win32',
|
||||
store: async (request) => {
|
||||
assert.equal(request.action, 'read');
|
||||
return { credential };
|
||||
},
|
||||
resolveCredential: async (stored) => ({ email: 'next@example.com', credential: stored }),
|
||||
getQuota: async (token) => {
|
||||
assert.equal(token, 'saved-access');
|
||||
return pools;
|
||||
},
|
||||
});
|
||||
assert.deepEqual(result, { email: 'next@example.com', pools });
|
||||
});
|
||||
|
||||
test('Google OAuth confirms the email and the same account token retrieves quota pools', async () => {
|
||||
const endpoints = [];
|
||||
const refreshToken = 'first-refresh';
|
||||
const token = { access_token: 'new-access', refresh_token: 'latest-refresh', expires_in: 3600 };
|
||||
const fetchFn = async (url, request) => {
|
||||
endpoints.push(url);
|
||||
assert.equal(request.redirect, 'error');
|
||||
if (url.endsWith('/token')) {
|
||||
assert.equal(request.body.get('refresh_token'), refreshToken);
|
||||
return { ok: true, json: async () => token };
|
||||
}
|
||||
assert.equal(request.headers.Authorization, 'Bearer new-access');
|
||||
if (url.endsWith('/userinfo')) return { ok: true, json: async () => ({ email: 'owner@example.com', verified_email: true }) };
|
||||
if (url.endsWith(':loadCodeAssist')) return { ok: true, json: async () => ({ cloudaicompanionProject: { id: 'test-project' } }) };
|
||||
assert.equal(JSON.parse(request.body).project, 'test-project');
|
||||
if (url.endsWith(':fetchAvailableModels')) return { ok: true, json: async () => ({ models: {} }) };
|
||||
assert.match(url, /:retrieveUserQuotaSummary$/);
|
||||
return { ok: true, json: async () => ({ response: { quotaSummary: { groups: [
|
||||
{ name: 'Gemini Models', buckets: [{ window: '5h', remaining_fraction: 0 }, { window: 'weekly', remainingFraction: 0.29 }] },
|
||||
] } } }) };
|
||||
};
|
||||
const resolved = await resolveGoogleCredential({ token: { refresh_token: refreshToken } }, {
|
||||
fetchFn, getClients: async () => [{ id: 'desktop-client', secret: 'test-config' }],
|
||||
});
|
||||
assert.equal(resolved.email, 'owner@example.com');
|
||||
assert.equal(resolved.credential.token.refresh_token, token.refresh_token);
|
||||
const pools = await retrieveCredentialQuota(resolved.credential.token.access_token, fetchFn);
|
||||
assert.deepEqual(pools.map(({ poolKey, remainingPct, weeklyRemainingPct }) => [poolKey, remainingPct, weeklyRemainingPct]), [['Gemini', 0, 29]]);
|
||||
assert.equal(endpoints.length, 5);
|
||||
});
|
||||
|
||||
test('Windows vault atomically saves, reloads and removes encrypted entries', { skip: process.platform !== 'win32' }, async () => {
|
||||
const directory = await mkdtemp(fileURLToPath(new URL('../.account-test-', import.meta.url)));
|
||||
const vault = join(directory, 'test.dpapi');
|
||||
const run = (action, email, credential) => runWindowsCredentialStore({ action, email, credential, vault });
|
||||
try {
|
||||
const credential = normalizeAccountCredential('1//synthetic-refresh-token-for-test');
|
||||
assert.deepEqual(await run('list'), { accounts: [], selectedEmail: '' });
|
||||
assert.deepEqual(await run('save', 'active@example.com', credential), { accounts: ['active@example.com'], selectedEmail: '' });
|
||||
assert.deepEqual(await run('save', 'next@example.com', credential), { accounts: ['active@example.com', 'next@example.com'], selectedEmail: '' });
|
||||
assert.deepEqual(await run('read', 'next@example.com'), { credential });
|
||||
assert.deepEqual(await runWindowsCredentialStore({ action: 'save', email: 'next@example.com', credential, expectedCredential: 'stale', vault }), { error: 'credentialChanged' });
|
||||
assert.equal((await readFile(vault)).includes('synthetic-refresh-token-for-test'), false);
|
||||
assert.deepEqual(await run('list'), { accounts: ['active@example.com', 'next@example.com'], selectedEmail: '' });
|
||||
assert.deepEqual(await run('remove', 'next@example.com'), { accounts: ['active@example.com'], selectedEmail: '' });
|
||||
} finally {
|
||||
await unlink(vault).catch((err) => { if (err.code !== 'ENOENT') throw err; });
|
||||
await rmdir(directory);
|
||||
}
|
||||
});
|
||||
@@ -15,6 +15,8 @@ const DEFAULT_BUNDLED_CATALOG = {
|
||||
|
||||
const BACKEND_MODULE_FILES = [
|
||||
'../backend/context-windows.mjs',
|
||||
'../backend/account-oauth.mjs',
|
||||
'../backend/account-switch.mjs',
|
||||
'../backend/settings-schema.mjs',
|
||||
'../backend/config.mjs',
|
||||
'../backend/ls-discovery.mjs',
|
||||
@@ -144,7 +146,7 @@ export function backendHarness({
|
||||
return {ok:true,json:async()=>data||{}};
|
||||
}
|
||||
if(method==='RetrieveUserQuotaSummary') {
|
||||
const qs=state.quotaSummary;
|
||||
const qs=await state.quotaSummary;
|
||||
if(qs instanceof Error) throw qs;
|
||||
return {ok:true,json:async()=>({response:qs})};
|
||||
}
|
||||
@@ -152,6 +154,6 @@ export function backendHarness({
|
||||
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,executeModelContextWindowAction,executeResetSettingsAction,executeRebuildCacheAction,clearRuntimeCaches,normalizeTopbarCapsuleSlots,normalizeHoverModules,normalizeOverviewModules,normalizeOverviewMetrics,normalizeStepTableColumns};',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,resolveMigratedGitRemoteUrl,loadSettings,executeSettingsAction,executeModelContextWindowAction,executeResetSettingsAction,executeRebuildCacheAction,clearRuntimeCaches,normalizeTopbarCapsuleSlots,normalizeHoverModules,normalizeOverviewModules,normalizeOverviewMetrics,normalizeStepTableColumns};',ctx);
|
||||
return {...ctx.api,state};
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ test('sanitizeCatalogPayload filters malformed/null/zero entries, untrusted URLs
|
||||
assert.ok(sanitized);
|
||||
assert.equal(sanitized.catalogVersion, '2026.11.03.9');
|
||||
assert.equal(sanitized.latestPluginVersion, '1.5.0');
|
||||
assert.ok(sanitized.downloadUrl.startsWith('https://github.com/yuhuan2498281558/'));
|
||||
assert.ok(sanitized.downloadUrl.startsWith('https://github.com/yuhuan-dev/'));
|
||||
assert.deepEqual(Object.keys(sanitized.pricing), ['gemini-4.5-ultra']);
|
||||
assert.deepEqual(Object.keys(sanitized.placeholders), ['MODEL_PLACEHOLDER_M999']);
|
||||
});
|
||||
@@ -94,7 +94,7 @@ test('cloud catalog sync fetches from GitHub raw URL and dynamically prices newl
|
||||
|
||||
// Sync cloud catalog from GitHub
|
||||
const syncStatus = await h.syncCloudCatalog({ force: true });
|
||||
assert.ok(fetchedUrl.startsWith('https://raw.githubusercontent.com/yuhuan2498281558/antigravity-usage-monitor/main/pricing-catalog.json'));
|
||||
assert.ok(fetchedUrl.startsWith('https://raw.githubusercontent.com/yuhuan-dev/antigravity-usage-monitor/main/pricing-catalog.json'));
|
||||
assert.equal(syncStatus.source, 'remote');
|
||||
assert.equal(syncStatus.catalogVersion, '2026.11.03.2');
|
||||
assert.equal(syncStatus.latestPluginVersion, '1.5.0');
|
||||
@@ -273,7 +273,103 @@ test('performPluginUpdate pulls fast-forward when git worktree is clean, on main
|
||||
assert.equal(res.mode, 'git');
|
||||
assert.equal(res.previousVersion, '1.3.1');
|
||||
assert.equal(res.currentVersion, '1.4.0');
|
||||
assert.equal(gitCalls.length, 6); // status, rev-parse, fetch, show, merge-base, pull
|
||||
assert.equal(gitCalls.length, 7); // status, rev-parse, remote get-url, fetch, show, merge-base, pull
|
||||
});
|
||||
|
||||
test('repository migration: scrubs legacy yuhuan2498281558 cache URLs/TTL and migrates git origin remote to yuhuan-dev', async () => {
|
||||
let fetchedNewRepoUrl = '';
|
||||
const cacheH = backendHarness({
|
||||
pluginManifest: { name: 'usage-monitor', version: '1.4.4' },
|
||||
remoteCatalog: {
|
||||
schemaVersion: 1,
|
||||
catalogVersion: '2026.11.11.4',
|
||||
updatedAt: '2026-11-11T23:20:00+09:00',
|
||||
latestPluginVersion: '1.4.4',
|
||||
releaseUrl: 'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest',
|
||||
downloadUrl: 'https://github.com/yuhuan2498281558/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip',
|
||||
archiveFallbackUrl: 'https://codeload.github.com/yuhuan2498281558/antigravity-usage-monitor/zip/refs/heads/main',
|
||||
sourceUrl: 'https://raw.githubusercontent.com/yuhuan2498281558/antigravity-usage-monitor/main/pricing-catalog.json',
|
||||
fetchedAtMs: Date.now() - 60_000,
|
||||
pricing: {
|
||||
'gemini-4-carbon-high': { input: 2.0, cache: 0.1, output: 10.0, short: 'carbon-4-high', family: 'Gemini' },
|
||||
},
|
||||
},
|
||||
remoteFetch: async (url) => {
|
||||
fetchedNewRepoUrl = String(url);
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
schemaVersion: 1,
|
||||
catalogVersion: '2026.11.12.1',
|
||||
updatedAt: '2026-11-12T10:00:00+09:00',
|
||||
latestPluginVersion: '1.4.5',
|
||||
pricing: {
|
||||
'gemini-4-carbon-high': { input: 2.0, cache: 0.1, output: 10.0, short: 'carbon-4-high', family: 'Gemini' },
|
||||
},
|
||||
}),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const initialStatus = cacheH.getCloudStatus();
|
||||
assert.equal(initialStatus.releaseUrl, 'https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest');
|
||||
assert.equal(initialStatus.downloadUrl, 'https://github.com/yuhuan-dev/antigravity-usage-monitor/releases/latest/download/usage-monitor.zip');
|
||||
assert.equal(initialStatus.lastSyncedAtMs, 0, 'legacy repo cache TTL must be invalidated so new repo syncs immediately');
|
||||
|
||||
const synced = await cacheH.syncCloudCatalog({ force: false });
|
||||
assert.equal(
|
||||
fetchedNewRepoUrl,
|
||||
'https://raw.githubusercontent.com/yuhuan-dev/antigravity-usage-monitor/main/pricing-catalog.json'
|
||||
);
|
||||
assert.equal(synced.catalogVersion, '2026.11.12.1');
|
||||
assert.equal(synced.latestPluginVersion, '1.4.5');
|
||||
|
||||
assert.equal(
|
||||
cacheH.resolveMigratedGitRemoteUrl('https://github.com/yuhuan2498281558/antigravity-usage-monitor.git'),
|
||||
'https://github.com/yuhuan-dev/antigravity-usage-monitor.git'
|
||||
);
|
||||
assert.equal(
|
||||
cacheH.resolveMigratedGitRemoteUrl('git@github.com:yuhuan2498281558/antigravity-usage-monitor.git'),
|
||||
'git@github.com:yuhuan-dev/antigravity-usage-monitor.git'
|
||||
);
|
||||
assert.equal(
|
||||
cacheH.resolveMigratedGitRemoteUrl('https://github.com/custom-fork/antigravity-usage-monitor.git'),
|
||||
''
|
||||
);
|
||||
|
||||
const gitCalls = [];
|
||||
const migrateH = backendHarness({
|
||||
hasGitDir: true,
|
||||
pluginRootPath: '/Users/test/.gemini/config/plugins/usage-monitor',
|
||||
pluginManifest: { name: 'usage-monitor', version: '1.4.3' },
|
||||
execFileImpl: (_cmd, args, opts, cb) => {
|
||||
const fn = typeof opts === 'function' ? opts : cb;
|
||||
gitCalls.push(args);
|
||||
if (args.includes('rev-parse')) {
|
||||
fn(null, 'main\n', '');
|
||||
return;
|
||||
}
|
||||
if (args.includes('remote') && args.includes('get-url')) {
|
||||
fn(null, 'https://github.com/yuhuan2498281558/antigravity-usage-monitor.git\n', '');
|
||||
return;
|
||||
}
|
||||
if (args.includes('show')) {
|
||||
fn(null, JSON.stringify({ name: 'usage-monitor', version: '1.4.4' }), '');
|
||||
return;
|
||||
}
|
||||
if (args.includes('pull')) {
|
||||
migrateH.state.pluginManifest = { name: 'usage-monitor', version: '1.4.4' };
|
||||
}
|
||||
fn(null, '', '');
|
||||
},
|
||||
});
|
||||
|
||||
const updRes = await migrateH.performPluginUpdate({ isAuto: false });
|
||||
assert.equal(updRes.ok, true);
|
||||
assert.equal(updRes.currentVersion, '1.4.4');
|
||||
const setUrlCall = gitCalls.find((args) => args.includes('remote') && args.includes('set-url'));
|
||||
assert.ok(setUrlCall, 'must run git remote set-url origin before fetching');
|
||||
assert.equal(setUrlCall[setUrlCall.length - 1], 'https://github.com/yuhuan-dev/antigravity-usage-monitor.git');
|
||||
});
|
||||
|
||||
test('pluginUpdateMode supports manual (default), auto, and off with legacy autoUpdatePlugin compatibility', async () => {
|
||||
|
||||
@@ -402,6 +402,36 @@ test('switching accounts within 10s immediately invalidates quotaSummaryCache',
|
||||
assert.equal(second.quotas.pools[0].weeklyRemainingPct, 8.7);
|
||||
});
|
||||
|
||||
test('late quota results from another account cannot replace the current account cache', async () => {
|
||||
const quota = (remainingFraction) => ({ groups: [{
|
||||
displayName: 'Gemini Models',
|
||||
buckets: [{ bucketId: 'gemini-weekly', window: 'weekly', remainingFraction }],
|
||||
}] });
|
||||
const pro = { name: 'Same name', userTier: { id: 'g1-pro-tier', name: 'Google AI Pro' } };
|
||||
let resolvePrevious;
|
||||
const h = backendHarness({
|
||||
userStatus: { ...pro, email: 'a@example.com' },
|
||||
quotaSummary: new Promise((resolve) => { resolvePrevious = resolve; }),
|
||||
});
|
||||
const previous = h.buildTelemetryPayloadInternal('none');
|
||||
while (!h.state.calls.some(({ method }) => method === 'RetrieveUserQuotaSummary')) {
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
}
|
||||
|
||||
h.state.userStatus = { ...pro, email: 'b@example.com' };
|
||||
h.state.quotaSummary = quota(0.24);
|
||||
const switched = await h.buildTelemetryPayloadInternal('none');
|
||||
assert.equal(switched.account.email, 'b@example.com');
|
||||
assert.equal(switched.quotas.pools.find(({ poolKey }) => poolKey === 'Gemini').weeklyRemainingPct, 24);
|
||||
|
||||
resolvePrevious(quota(0.75));
|
||||
const stale = await previous;
|
||||
assert.equal(stale.quotas.meta.hasOfficialData, false);
|
||||
const refreshed = await h.buildTelemetryPayloadInternal('none');
|
||||
assert.equal(refreshed.account.email, 'b@example.com');
|
||||
assert.equal(refreshed.quotas.pools.find(({ poolKey }) => poolKey === 'Gemini').weeklyRemainingPct, 24);
|
||||
});
|
||||
|
||||
test('Orchestrator quota pool binding follows active phase: Carbon/Argon while planning, Gemini when offloaded to Hydrogen', async () => {
|
||||
const ORCH_CARBON = 'MODEL_PLACEHOLDER_M667';
|
||||
const ORCH_ARGON = 'MODEL_PLACEHOLDER_M681';
|
||||
|
||||
@@ -317,9 +317,9 @@ test('CDP multi-window sync injects, skips healthy windows, hot-upgrades on vers
|
||||
}
|
||||
const ctx = windowContexts.get(this.targetId);
|
||||
const value = vm.runInContext(expr, 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 } } }),
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -337,11 +337,13 @@ test('CDP multi-window sync injects, skips healthy windows, hot-upgrades on vers
|
||||
res.end(
|
||||
JSON.stringify([
|
||||
{
|
||||
id: 'win1',
|
||||
type: 'page',
|
||||
url: 'https://127.0.0.1:61001/c/11111111-1111-1111-1111-111111111111',
|
||||
webSocketDebuggerUrl: `ws://127.0.0.1:${cdpPort}/devtools/page/win1`,
|
||||
},
|
||||
{
|
||||
id: 'win2',
|
||||
type: 'page',
|
||||
url: 'https://127.0.0.1:61002/c/22222222-2222-2222-2222-222222222222',
|
||||
webSocketDebuggerUrl: `ws://127.0.0.1:${cdpPort}/devtools/page/win2`,
|
||||
@@ -705,6 +707,7 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
|
||||
|
||||
let reloadCalled = false;
|
||||
let currentBundleVer = 'ver-100';
|
||||
let currentAccountEmail = 'test@example.com';
|
||||
let liveSubagentPollActive = false;
|
||||
const fetchedUrls = [];
|
||||
const fetchedHeaders = [];
|
||||
@@ -769,6 +772,8 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
|
||||
};
|
||||
const mockSettings = { ...defaultMockSettings };
|
||||
let cacheRebuildCalls = 0;
|
||||
let selectedEmail = '';
|
||||
const accountRequests = [];
|
||||
|
||||
const mockWindow = {
|
||||
innerWidth: 1440,
|
||||
@@ -796,6 +801,17 @@ 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.endsWith('/api/accounts') || urlStr.endsWith('/api/accounts/update')) {
|
||||
if (opts.method === 'POST') {
|
||||
const update = JSON.parse(opts.body);
|
||||
accountRequests.push(update);
|
||||
if (update.action === 'quota') {
|
||||
return { ok: true, status: 200, json: async () => ({ email: update.email, pools: [{ poolKey: 'Gemini', remainingPct: 70 }] }) };
|
||||
}
|
||||
if (update.action === 'switch') selectedEmail = update.email;
|
||||
}
|
||||
return { ok: true, status: 200, json: async () => ({ supported: true, accounts: ['next@example.com'], selectedEmail }) };
|
||||
}
|
||||
if (urlStr.includes('/api/settings/reset') && String(opts.method || '').toUpperCase() === 'POST') {
|
||||
for (const k of Object.keys(mockSettings)) delete mockSettings[k];
|
||||
Object.assign(mockSettings, {
|
||||
@@ -856,7 +872,7 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
|
||||
{ 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 },
|
||||
account: { status: 'signedIn', email: currentAccountEmail, tierName: 'Google AI Ultra', planName: 'Pro', totalConversations: 5 },
|
||||
runningConversations: [
|
||||
{
|
||||
cascadeId: 'bbbbbbbb-2222-3333-4444-cccccccccccc',
|
||||
@@ -1195,7 +1211,7 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
|
||||
poolKey: 'Gemini',
|
||||
poolLabel: 'Gemini',
|
||||
usedPct: 56,
|
||||
remainingPct: 44,
|
||||
remainingPct: currentAccountEmail === 'test@example.com' ? 44 : 0,
|
||||
resetTime: new Date(Date.now() + 2 * 3600_000).toISOString(),
|
||||
weeklyUsedPct: 74,
|
||||
weeklyRemainingPct: 26,
|
||||
@@ -1419,7 +1435,7 @@ 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 modular 3-tab SettingsView (常规 / 结构 / 其他) & decoupled registries
|
||||
// Verify modular 3-tab SettingsView (常规 / 结构 / 其他) with Account tab hidden
|
||||
const pillTabs = popoverEl.querySelectorAll('.pill-tab');
|
||||
pillTabs[pillTabs.length - 1].dispatchEvent({ type: 'click', stopPropagation() {} });
|
||||
await new Promise((r) => setTimeout(r, 15));
|
||||
@@ -1427,10 +1443,12 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
|
||||
const allPanes = popoverEl.querySelectorAll('.view-pane');
|
||||
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, '其他');
|
||||
assert.deepEqual(subNavBtns.map((button) => button.textContent), ['常规', '结构', '其他']);
|
||||
assert.match(
|
||||
stylesCss,
|
||||
/\.settings-subnav-bar\s+\.segmented\s*\{[^}]*grid-auto-flow:\s*column;[^}]*grid-auto-columns:\s*minmax\(0,\s*1fr\);/,
|
||||
'Settings subnav uses auto-sized equal columns regardless of visible tab count'
|
||||
);
|
||||
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);
|
||||
@@ -1746,7 +1764,7 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
|
||||
await new Promise((r) => setTimeout(r, 40));
|
||||
assert.equal(mockSettings.stepTableColumns.length, 7);
|
||||
|
||||
// --- Tab 2: 其他 (modelFormat, orchestratorId, contextBaseline reserved pill, cache rebuild, reset all) ---
|
||||
// --- 其他 (model format, context limits, cache rebuild, reset) ---
|
||||
subNavBtns[2].dispatchEvent({ type: 'click', stopPropagation() {} });
|
||||
await new Promise((r) => setTimeout(r, 15));
|
||||
assert.equal(otherPane.hasAttribute('hidden'), false);
|
||||
@@ -2179,6 +2197,7 @@ test('Compiled app.js mounts dual Shadow DOM hosts, tracks /c/<uuid> routes, pro
|
||||
|
||||
// Verify bundle version bump NEVER calls window.location.reload() in overlay mode
|
||||
currentBundleVer = 'ver-200';
|
||||
currentAccountEmail = 'next@example.com';
|
||||
mockLocation.pathname = '/c/cccccccc-4444-5555-6666-dddddddddddd';
|
||||
for (const fn of winListeners.get('popstate') || []) fn({});
|
||||
await new Promise((r) => setTimeout(r, 40));
|
||||
@@ -2369,6 +2388,7 @@ test('Multi-port CDP discovery tolerates stale 2.0 DevToolsActivePort while inje
|
||||
// Live Antigravity IDE CDP server exposing workbench.html + workbench-jetski-agent.html + ignored sharedProcess.html
|
||||
const ideContextObj = {
|
||||
location: { pathname: '/out/vs/code/electron-browser/workbench/workbench.html' },
|
||||
setTimeout,
|
||||
document: {
|
||||
querySelector(sel) {
|
||||
if (sel.includes('conversation-view')) {
|
||||
|
||||
Reference in New Issue
Block a user