mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
feat(panel): restore IDE mount compatibility, add composer dock mode, and refine chart tooltips
This commit is contained in:
@@ -70,7 +70,7 @@ test('BUG-01 & INCON-01: Google-proxied Claude/GPT/o-series never misclassify as
|
||||
const m20 = h.resolveModelInfo('MODEL_PLACEHOLDER_M20', new Map(), 'API_PROVIDER_GOOGLE_GEMINI');
|
||||
assert.equal(m20.modelId, 'gemini-3.5-flash');
|
||||
|
||||
// Gemini Hydrogen (3.8 Flash pricing) & Helix (3.5 Flash Lite pricing), shared Gemini pool
|
||||
// Gemini Hydrogen ($1.50/$0.15/$7.50 unified pricing) & Helix (3.5 Flash Lite pricing), shared Gemini pool
|
||||
const dynHydrogenMap = new Map([
|
||||
['MODEL_PLACEHOLDER_M480', { modelId: '', label: 'Gemini 4 Hydrogen (High)' }],
|
||||
['MODEL_PLACEHOLDER_M481', { modelId: '', label: 'Gemini 4 Hydrogen (Low)' }],
|
||||
@@ -81,18 +81,19 @@ test('BUG-01 & INCON-01: Google-proxied Claude/GPT/o-series never misclassify as
|
||||
assert.equal(hydroHigh.shortName, 'hydrogen-4-high');
|
||||
assert.deepEqual(
|
||||
{ i: hydroHigh.pricing?.input, c: hydroHigh.pricing?.cache, o: hydroHigh.pricing?.output },
|
||||
{ i: 0.75, c: 0.075, o: 3.75 }
|
||||
{ i: 1.5, c: 0.15, o: 7.5 }
|
||||
);
|
||||
const hydroLow = h.resolveModelInfo('MODEL_PLACEHOLDER_M481', dynHydrogenMap);
|
||||
assert.equal(hydroLow.shortName, 'hydrogen-4-low');
|
||||
assert.deepEqual(
|
||||
{ i: hydroLow.pricing?.input, c: hydroLow.pricing?.cache, o: hydroLow.pricing?.output },
|
||||
{ i: 0.3, c: 0.03, o: 2.5 }
|
||||
{ i: 1.5, c: 0.15, o: 7.5 }
|
||||
);
|
||||
const hydroCodename = h.resolveModelInfo('gemini-hydrogen');
|
||||
assert.equal(hydroCodename.family, 'Gemini');
|
||||
assert.equal(hydroCodename.label, 'Gemini Hydrogen');
|
||||
assert.equal(hydroCodename.pricing?.input, 0.75);
|
||||
assert.equal(hydroCodename.pricing?.input, 1.5);
|
||||
assert.equal(hydroCodename.pricing?.output, 7.5);
|
||||
|
||||
const helixInfo = h.resolveModelInfo('MODEL_PLACEHOLDER_M482', dynHydrogenMap);
|
||||
assert.equal(helixInfo.family, 'Gemini');
|
||||
|
||||
@@ -15,6 +15,7 @@ const DEFAULT_BUNDLED_CATALOG = {
|
||||
|
||||
const BACKEND_MODULE_FILES = [
|
||||
'../backend/config.mjs',
|
||||
'../backend/ls-discovery.mjs',
|
||||
'../backend/pricing-catalog.mjs',
|
||||
'../backend/plugin-updater.mjs',
|
||||
'../backend/ls-rpc.mjs',
|
||||
@@ -24,6 +25,7 @@ const BACKEND_MODULE_FILES = [
|
||||
'../backend/usage-aggregator.mjs',
|
||||
'../backend/telemetry-builder.mjs',
|
||||
'../backend/window-bridge.mjs',
|
||||
'../backend/api-actions.mjs',
|
||||
'../main.mjs',
|
||||
];
|
||||
|
||||
@@ -144,6 +146,6 @@ export function backendHarness({
|
||||
return {ok:true,json:async()=>data};
|
||||
},
|
||||
};
|
||||
vm.runInNewContext(source+'\n globalThis.api={buildTelemetryPayloadInternal,computeStepCost,resolveModelInfo,inferFamilyFromProviderOrKey,isCarbonModelIdentifier,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};',ctx);
|
||||
return {...ctx.api,state};
|
||||
}
|
||||
|
||||
@@ -542,3 +542,229 @@ test('supports Gemini 4 Carbon pricing/pool and resolves all newly added languag
|
||||
assert.equal(p.quotas.activePool.poolKey, 'Carbon');
|
||||
assert.equal(p.quotas.activePool.weeklyRemainingIntPct, 65);
|
||||
});
|
||||
|
||||
test('trendSeries preserves 1-day-per-slot granularity for >90 day spans and recentSteps separates thinking vs response tokens', async () => {
|
||||
const nowMs = Date.now();
|
||||
const oldStartMs = nowMs - 120 * 24 * 3600 * 1000;
|
||||
const oldStartIso = new Date(oldStartMs).toISOString();
|
||||
const oldEndIso = new Date(oldStartMs + 6000).toISOString();
|
||||
const recentStartIso = new Date(nowMs - 8000).toISOString();
|
||||
const recentEndIso = new Date(nowMs - 1000).toISOString();
|
||||
|
||||
const h = backendHarness({
|
||||
trajectories: {
|
||||
cLong: {
|
||||
trajectory: {
|
||||
steps: [
|
||||
{
|
||||
status: 'CORTEX_STEP_STATUS_DONE',
|
||||
metadata: {
|
||||
sourceTrajectoryStepInfo: { stepIndex: 1 },
|
||||
createdAt: oldStartIso,
|
||||
finishedGeneratingAt: oldEndIso,
|
||||
modelUsage: {
|
||||
model: 'MODEL_PLACEHOLDER_M429',
|
||||
inputTokens: '10000',
|
||||
cacheReadTokens: '20000',
|
||||
outputTokens: '700',
|
||||
thinkingOutputTokens: '420',
|
||||
},
|
||||
},
|
||||
plannerResponse: { response: 'early step' },
|
||||
},
|
||||
{
|
||||
status: 'CORTEX_STEP_STATUS_DONE',
|
||||
metadata: {
|
||||
sourceTrajectoryStepInfo: { stepIndex: 2 },
|
||||
createdAt: recentStartIso,
|
||||
finishedGeneratingAt: recentEndIso,
|
||||
modelUsage: {
|
||||
model: 'MODEL_PLACEHOLDER_M429',
|
||||
inputTokens: '5000',
|
||||
cacheReadTokens: '32115',
|
||||
outputTokens: '685',
|
||||
thinkingOutputTokens: '420',
|
||||
responseOutputTokens: '265',
|
||||
},
|
||||
},
|
||||
plannerResponse: { response: 'recent step' },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
summaries: {
|
||||
cLong: { stepCount: 2, lastModifiedTime: recentEndIso, status: 'IDLE' },
|
||||
},
|
||||
});
|
||||
|
||||
const pAll = await h.buildTelemetryPayloadInternal('cLong', false, { range: 'all' });
|
||||
const trendAll = pAll.consumption.trendSeries;
|
||||
assert.ok(trendAll.length >= 120 && trendAll.length <= 122, `Expected ~121 daily slots, got ${trendAll.length}`);
|
||||
assert.equal(trendAll[0].granularity, 'day');
|
||||
assert.match(trendAll[0].fullLabel, /^\d{4}年\d+月\d+日 \(周[日一二三四五六]\)$/);
|
||||
assert.equal(trendAll.reduce((sum, b) => sum + b.tokens, 0), 30700 + 37800);
|
||||
assert.equal(trendAll.reduce((sum, b) => sum + b.calls, 0), 2);
|
||||
|
||||
const steps = pAll.activeConversation.recentSteps;
|
||||
assert.equal(steps.length, 2);
|
||||
// recentSteps is reversed (newest first)
|
||||
assert.equal(steps[0].contextTokens, 37800);
|
||||
assert.equal(steps[0].thinkingTokens, 420);
|
||||
assert.equal(steps[0].responseTokens, 265);
|
||||
assert.equal(steps[1].thinkingTokens, 420);
|
||||
assert.equal(steps[1].responseTokens, 280);
|
||||
});
|
||||
|
||||
test('modelBreakdown exposes avgTtftSec, cacheHitPct, and subagent scoped breakdowns + fit math helpers', async () => {
|
||||
const {
|
||||
computeLinearFit,
|
||||
computeLoessFit,
|
||||
computePublicationFit,
|
||||
getStepModelGroupKey,
|
||||
toChronologicalSteps,
|
||||
} = await import('../src/components/charts/SessionStepCharts.js');
|
||||
|
||||
// 1. Verify OLS + publication LOESS + 95% CI confidence band & [0, 100] cache bounds
|
||||
const olsExact = computeLinearFit([10, 20, 30, 40]);
|
||||
assert.ok(Math.abs(olsExact.slope - 10) < 1e-9);
|
||||
assert.ok(Math.abs(olsExact.r - 1) < 1e-9);
|
||||
assert.ok(Math.abs(olsExact.r2 - 1) < 1e-9);
|
||||
assert.deepEqual(
|
||||
olsExact.values.map((v) => +v.toFixed(4)),
|
||||
[10, 20, 30, 40]
|
||||
);
|
||||
|
||||
// Verify bimodal / high-peak TPS series is NOT crushed flat by Bisquare and builds valid 95% CI band
|
||||
const waveXs = Array.from({ length: 20 }, (_, idx) => idx * 5 + 1);
|
||||
const waveYs = [
|
||||
22, 26, 48, 78, 92, 85, 64, 34, 24, 28,
|
||||
55, 84, 76, 42, 25, 22, 26, 32, 38, 44,
|
||||
];
|
||||
const pubWave = computePublicationFit(waveXs, waveYs, { minVal: 0 });
|
||||
assert.equal(pubWave.method, 'LOESS');
|
||||
assert.equal(pubWave.grid.length, 64);
|
||||
assert.ok(
|
||||
pubWave.grid.every((g) => g.ciLow <= g.fit + 1e-9 && g.fit <= g.ciHigh + 1e-9),
|
||||
'Every grid point satisfies ciLow <= fit <= ciHigh'
|
||||
);
|
||||
// Around peak x ~ 21 (index 4), fitted conditional expectation must rise well above overall mean (~47)
|
||||
assert.ok(pubWave.sampleFits[4] > 55, `Expected peak conditional mean > 55, got ${pubWave.sampleFits[4]}`);
|
||||
|
||||
// Warmup cache curve stays clamped within [0, 100]
|
||||
const cacheSeries = [0, 90, 92, 93, 94, 95, 95];
|
||||
const loessCache = computeLoessFit(cacheSeries, { minVal: 0, maxVal: 100 });
|
||||
assert.equal(loessCache.length, cacheSeries.length);
|
||||
assert.ok(
|
||||
loessCache.every((v) => v >= 0 && v <= 100),
|
||||
'Fitted cache values must stay clamped within [0, 100]'
|
||||
);
|
||||
assert.ok(loessCache[6] > 90, 'Tail fit tracks steady warm cache region');
|
||||
|
||||
// Group key strips [自动压缩] and thinking tier suffixes
|
||||
assert.equal(getStepModelGroupKey({ modelLabel: 'Gemini 3.1 Pro (High) [自动压缩]' }), 'Gemini 3.1 Pro');
|
||||
assert.equal(getStepModelGroupKey({ modelLabel: 'Orchestrator (Carbon)' }), 'Orchestrator (Carbon)');
|
||||
|
||||
const chrono = toChronologicalSteps(
|
||||
[
|
||||
{ stepIndex: 3, createdAtMs: 3000 },
|
||||
{ stepIndex: 1, createdAtMs: 1000 },
|
||||
{ stepIndex: 2, createdAtMs: 2000 },
|
||||
],
|
||||
true
|
||||
);
|
||||
assert.deepEqual(
|
||||
chrono.map((s) => s.stepIndex),
|
||||
[1, 2, 3]
|
||||
);
|
||||
|
||||
// 2. Verify backend modelBreakdown enriches avgTtftSec and cacheHitPct for main & subagents
|
||||
const h = backendHarness({
|
||||
trajectories: {
|
||||
'root-fit': {
|
||||
trajectory: {
|
||||
steps: [
|
||||
{
|
||||
status: 'CORTEX_STEP_STATUS_DONE',
|
||||
metadata: {
|
||||
createdAt: '2026-06-01T00:00:00Z',
|
||||
finishedGeneratingAt: '2026-06-01T00:00:10Z',
|
||||
modelUsage: {
|
||||
model: 'MODEL_PLACEHOLDER_M37',
|
||||
inputTokens: '1000',
|
||||
cacheReadTokens: '9000',
|
||||
outputTokens: '500',
|
||||
thinkingOutputTokens: '100',
|
||||
responseOutputTokens: '400',
|
||||
},
|
||||
},
|
||||
plannerResponse: { response: 'main step 1' },
|
||||
},
|
||||
{
|
||||
type: 'CORTEX_STEP_TYPE_INVOKE_SUBAGENT',
|
||||
status: 'CORTEX_STEP_STATUS_DONE',
|
||||
metadata: { createdAt: '2026-06-01T00:00:12Z' },
|
||||
invokeSubagent: {
|
||||
subagents: [{ typeName: 'research', role: 'Fast Researcher' }],
|
||||
results: [{ conversationId: 'sub-fit' }],
|
||||
},
|
||||
},
|
||||
],
|
||||
generatorMetadata: [
|
||||
{ stepIndices: [0], chatModel: { timeToFirstToken: '2.4s', streamingDuration: '7.6s' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
'sub-fit': {
|
||||
trajectory: {
|
||||
metadata: { parentConversationId: 'root-fit', subagentSpec: { typeName: 'research' } },
|
||||
steps: [
|
||||
{
|
||||
status: 'CORTEX_STEP_STATUS_DONE',
|
||||
metadata: {
|
||||
createdAt: '2026-06-01T00:00:15Z',
|
||||
finishedGeneratingAt: '2026-06-01T00:00:20Z',
|
||||
modelUsage: {
|
||||
model: 'MODEL_PLACEHOLDER_M18',
|
||||
inputTokens: '2000',
|
||||
cacheReadTokens: '6000',
|
||||
outputTokens: '400',
|
||||
thinkingOutputTokens: '50',
|
||||
responseOutputTokens: '350',
|
||||
},
|
||||
},
|
||||
plannerResponse: { response: 'sub step 1' },
|
||||
},
|
||||
],
|
||||
generatorMetadata: [
|
||||
{ stepIndices: [0], chatModel: { timeToFirstToken: '0.8s', streamingDuration: '4.2s' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
summaries: {
|
||||
'root-fit': { stepCount: 2, lastModifiedTime: '2026-06-01T00:00:12Z', status: 'IDLE' },
|
||||
'sub-fit': {
|
||||
stepCount: 1,
|
||||
lastModifiedTime: '2026-06-01T00:00:20Z',
|
||||
status: 'IDLE',
|
||||
trajectoryMetadata: { parentConversationId: 'root-fit' },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const payload = await h.buildTelemetryPayloadInternal('root-fit');
|
||||
const mainMb = payload.activeConversation.modelBreakdown;
|
||||
assert.equal(mainMb.length, 1);
|
||||
assert.equal(mainMb[0].avgTtftSec, 2.4);
|
||||
assert.equal(mainMb[0].ttftSampleCount, 1);
|
||||
assert.equal(mainMb[0].cacheHitPct, 90);
|
||||
|
||||
const subMb = payload.activeConversation.agents[1].modelBreakdown;
|
||||
assert.equal(subMb.length, 1);
|
||||
assert.equal(subMb[0].avgTtftSec, 0.8);
|
||||
assert.equal(subMb[0].cacheHitPct, 75);
|
||||
|
||||
const aggMb = payload.activeConversation.aggregated.modelBreakdown;
|
||||
assert.equal(aggMb.length, 2);
|
||||
});
|
||||
|
||||
@@ -3,7 +3,11 @@ import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
import { extractModelSteps, normalizeCachedStep, MODEL_IDENTITY_VERSION } from '../speed-metrics.mjs';
|
||||
import { formatUsd } from '../src/core/formatters.js';
|
||||
import {
|
||||
formatUsd,
|
||||
mergeModelsByDisplayName,
|
||||
resolveModelDisplayInfo,
|
||||
} from '../src/core/formatters.js';
|
||||
import { backendHarness } from './backend-harness.mjs';
|
||||
|
||||
const FLASH = 'MODEL_PLACEHOLDER_M318', ARGON = 'MODEL_PLACEHOLDER_M418';
|
||||
@@ -195,3 +199,500 @@ test('frontend considers a model-only correction a real telemetry update', () =>
|
||||
const b=structuredClone(a); b.activeConversation.recentSteps[0].modelShort='new-model';
|
||||
assert.equal(ctx.compare(a,b),false); assert.equal(ctx.compare(a,structuredClone(a)),true);
|
||||
});
|
||||
|
||||
const ORCH_CARBON = 'MODEL_PLACEHOLDER_M667';
|
||||
const ORCH_ARGON = 'MODEL_PLACEHOLDER_M681';
|
||||
const ORCH_EXEC_HYDROGEN = 'MODEL_PLACEHOLDER_M669';
|
||||
|
||||
test('Orchestrator (Carbon) direct/planning and inferred compaction steps resolve to orch-carbon and annotate upstream ID', async () => {
|
||||
const rows = [step(1, ORCH_CARBON), step(2, undefined, true), step(3, ORCH_CARBON)];
|
||||
const raw = {
|
||||
trajectory: {
|
||||
steps: rows,
|
||||
generatorMetadata: [
|
||||
{
|
||||
stepIndices: [1],
|
||||
chatModel: {
|
||||
model: ORCH_CARBON,
|
||||
responseModel: 'gemini-pro-orchestrator',
|
||||
modelDisplayName: 'Orchestrator (Carbon)',
|
||||
},
|
||||
plannerConfig: {
|
||||
planModel: ORCH_CARBON,
|
||||
modelName: 'gemini-pro-orchestrator',
|
||||
planExecuteConfig: { executionModel: ORCH_EXEC_HYDROGEN },
|
||||
},
|
||||
},
|
||||
{
|
||||
stepIndices: [3],
|
||||
chatModel: {
|
||||
model: ORCH_CARBON,
|
||||
responseModel: 'gemini-pro-orchestrator',
|
||||
modelDisplayName: 'Orchestrator (Carbon)',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const p = await payload(rows, { trajectories: { test: raw } });
|
||||
const s1 = p.activeConversation.recentSteps.find((s) => s.stepIndex === 1);
|
||||
const cp = p.activeConversation.recentSteps.find((s) => s.stepIndex === 2);
|
||||
|
||||
assert.equal(s1.modelShort, 'orch-carbon');
|
||||
assert.equal(s1.modelUpstream, 'gemini-pro-orchestrator (carbon-4)');
|
||||
assert.equal(s1.costUsd, 0.0129);
|
||||
assert.equal(cp.modelKey, ORCH_CARBON);
|
||||
assert.equal(cp.modelSource, 'inferred_compaction');
|
||||
assert.equal(cp.modelShort, 'orch-carbon·压缩');
|
||||
assert.equal(cp.modelUpstream, 'gemini-pro-orchestrator (carbon-4)·压缩');
|
||||
assert.equal(p.activeConversation.activeModelShort, 'orch-carbon');
|
||||
assert.equal(p.activeConversation.activeModelUpstream, 'gemini-pro-orchestrator (carbon-4)');
|
||||
assert.equal(p.consumption.account.unpricedCalls, 0);
|
||||
assert.equal(p.modelBreakdown.length, 1);
|
||||
assert.equal(p.modelBreakdown[0].label, 'Orchestrator (Carbon)');
|
||||
assert.equal(p.modelBreakdown[0].upstreamName, 'gemini-pro-orchestrator (carbon-4)');
|
||||
assert.equal(p.modelBreakdown[0].calls, 3);
|
||||
});
|
||||
|
||||
test('Orchestrator (Argon) resolves to orch-argon, annotates upstream ID, and is not misclassified as Carbon', async () => {
|
||||
const h = backendHarness({
|
||||
summaries: { test: { stepCount: 1 } },
|
||||
trajectories: {
|
||||
test: {
|
||||
trajectory: {
|
||||
steps: [step(1, ORCH_ARGON)],
|
||||
generatorMetadata: [
|
||||
{
|
||||
stepIndices: [1],
|
||||
chatModel: {
|
||||
model: ORCH_ARGON,
|
||||
responseModel: 'gemini-pro-orchestrator-argon',
|
||||
modelDisplayName: 'Orchestrator (Argon)',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const p = await h.buildTelemetryPayloadInternal('test');
|
||||
const s1 = p.activeConversation.recentSteps[0];
|
||||
assert.equal(s1.modelShort, 'orch-argon');
|
||||
assert.equal(s1.modelUpstream, 'gemini-pro-orchestrator-argon (argon-4)');
|
||||
assert.equal(s1.costUsd, 0.0129);
|
||||
assert.equal(p.modelBreakdown[0].label, 'Orchestrator (Argon)');
|
||||
assert.equal(p.modelBreakdown[0].upstreamName, 'gemini-pro-orchestrator-argon (argon-4)');
|
||||
assert.equal(h.isArgonModelIdentifier(ORCH_ARGON, 'gemini-pro-orchestrator-argon', 'Orchestrator (Argon)'), true);
|
||||
assert.equal(h.isCarbonModelIdentifier(ORCH_ARGON, 'gemini-pro-orchestrator-argon', 'Orchestrator (Argon)'), false);
|
||||
});
|
||||
|
||||
test('real-world M669 worker steps (responseModel gemini-flash-worker-agy, displayName Gemini Flash) and uncatalogued executionModel resolve to Hydrogen', async () => {
|
||||
const FUTURE_EXEC_PH = 'MODEL_PLACEHOLDER_M799';
|
||||
const rows = [step(1, ORCH_CARBON), step(2, ORCH_EXEC_HYDROGEN), step(3, FUTURE_EXEC_PH)];
|
||||
const raw = {
|
||||
trajectory: {
|
||||
steps: rows,
|
||||
generatorMetadata: [
|
||||
{
|
||||
stepIndices: [1],
|
||||
chatModel: {
|
||||
model: ORCH_CARBON,
|
||||
responseModel: 'gemini-pro-orchestrator',
|
||||
modelDisplayName: 'Orchestrator (Carbon)',
|
||||
},
|
||||
plannerConfig: {
|
||||
planModel: ORCH_CARBON,
|
||||
modelName: 'gemini-pro-orchestrator',
|
||||
planExecuteConfig: { executionModel: FUTURE_EXEC_PH },
|
||||
},
|
||||
},
|
||||
{
|
||||
stepIndices: [2],
|
||||
chatModel: {
|
||||
model: ORCH_EXEC_HYDROGEN,
|
||||
responseModel: 'gemini-flash-worker-agy',
|
||||
modelDisplayName: 'Gemini Flash',
|
||||
},
|
||||
},
|
||||
{
|
||||
stepIndices: [3],
|
||||
chatModel: {
|
||||
model: FUTURE_EXEC_PH,
|
||||
responseModel: 'gemini-flash-worker-agy',
|
||||
modelDisplayName: 'Gemini Flash',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const p = await payload(rows, { trajectories: { test: raw } });
|
||||
const s1 = p.activeConversation.recentSteps.find((s) => s.stepIndex === 1);
|
||||
const s2 = p.activeConversation.recentSteps.find((s) => s.stepIndex === 2);
|
||||
const s3 = p.activeConversation.recentSteps.find((s) => s.stepIndex === 3);
|
||||
|
||||
assert.equal(s1.modelShort, 'orch-carbon');
|
||||
assert.equal(s1.modelUpstream, 'gemini-pro-orchestrator (carbon-4)');
|
||||
assert.equal(s1.costUsd, 0.0129);
|
||||
|
||||
assert.equal(s2.modelShort, 'hydrogen-4');
|
||||
assert.equal(s2.modelLabel, 'Orchestrator Worker (Hydrogen)');
|
||||
assert.equal(s2.modelUpstream, 'gemini-flash-worker-agy (hydrogen-4)');
|
||||
assert.equal(s2.costUsd, 0.0103);
|
||||
|
||||
assert.equal(s3.modelShort, 'hydrogen-4');
|
||||
assert.equal(s3.modelLabel, 'Orchestrator Worker (Hydrogen)');
|
||||
assert.equal(s3.modelUpstream, 'gemini-flash-worker-agy (hydrogen-4)');
|
||||
assert.equal(s3.costUsd, 0.0103);
|
||||
|
||||
assert.equal(p.consumption.account.unpricedCalls, 0);
|
||||
const orchRow = p.modelBreakdown.find((m) => m.label === 'Orchestrator (Carbon)');
|
||||
const hydroRow = p.modelBreakdown.find((m) => m.label === 'Orchestrator Worker (Hydrogen)');
|
||||
assert.ok(orchRow && hydroRow, 'modelBreakdown keeps orchestrator planning separate from Hydrogen worker');
|
||||
assert.equal(p.modelBreakdown.some((m) => m.label === 'Gemini Flash'), false);
|
||||
assert.equal(orchRow.calls, 1);
|
||||
assert.equal(hydroRow.calls, 2);
|
||||
assert.equal(hydroRow.upstreamName, 'gemini-flash-worker-agy (hydrogen-4)');
|
||||
|
||||
// Also verify already-cached M669 worker steps carrying vague "Gemini Flash" or transitional "Gemini 4 Hydrogen" resolve cleanly
|
||||
const cachedStep = {
|
||||
...extractModelSteps([step(10, ORCH_EXEC_HYDROGEN)])[0],
|
||||
responseModel: 'gemini-flash-worker-agy',
|
||||
modelDisplayName: 'Gemini Flash',
|
||||
};
|
||||
const cachedTransitionalDirect = {
|
||||
...extractModelSteps([step(11, 'MODEL_PLACEHOLDER_M528')])[0],
|
||||
modelDisplayName: 'Gemini 4 Hydrogen (XHigh)',
|
||||
};
|
||||
const hCached = backendHarness({
|
||||
cache: { test: { signature: 'v13-clean:2:', steps: [cachedStep, cachedTransitionalDirect] } },
|
||||
trajectories: { test: new Error('offline') },
|
||||
});
|
||||
const pCached = await hCached.buildTelemetryPayloadInternal('test');
|
||||
assert.equal(pCached.activeConversation.activeModelShort, 'hydrogen-4-xhigh');
|
||||
assert.equal(
|
||||
pCached.modelBreakdown.find((m) => m.label === 'Orchestrator Worker (Hydrogen)')?.upstreamName,
|
||||
'gemini-flash-worker-agy (hydrogen-4)'
|
||||
);
|
||||
assert.ok(
|
||||
pCached.modelBreakdown.find((m) => m.label === 'Gemini 4 Hydrogen'),
|
||||
'direct Gemini 4 Hydrogen remains in its own breakdown bucket separate from worker-agy'
|
||||
);
|
||||
});
|
||||
|
||||
test('new Carbon (M427/M437/M438) and Hydrogen XHigh/High/Medium/Low (M525-M528) placeholders resolve and group cleanly', () => {
|
||||
const { resolveModelInfo, getBaseModelLabel } = backendHarness();
|
||||
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M427').shortName, 'carbon-4-high');
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M437').shortName, 'carbon-4');
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M438').shortName, 'carbon-4-low');
|
||||
|
||||
const xhigh = resolveModelInfo('MODEL_PLACEHOLDER_M528');
|
||||
assert.equal(xhigh.shortName, 'hydrogen-4-xhigh');
|
||||
assert.equal(xhigh.baseLabel, 'Gemini 4 Hydrogen');
|
||||
assert.equal(xhigh.pricing.input, 1.5);
|
||||
assert.equal(xhigh.pricing.cache, 0.15);
|
||||
assert.equal(xhigh.pricing.output, 7.5);
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M525').shortName, 'hydrogen-4-high');
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M526').shortName, 'hydrogen-4');
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M527').shortName, 'hydrogen-4-low');
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M527').pricing.input, 1.5);
|
||||
assert.equal(resolveModelInfo('MODEL_PLACEHOLDER_M527').pricing.output, 7.5);
|
||||
|
||||
assert.equal(getBaseModelLabel('Orchestrator (Carbon)'), 'Orchestrator (Carbon)');
|
||||
assert.equal(getBaseModelLabel('Orchestrator (Argon)'), 'Orchestrator (Argon)');
|
||||
assert.equal(getBaseModelLabel('Orchestrator Worker (Hydrogen)'), 'Orchestrator Worker (Hydrogen)');
|
||||
});
|
||||
|
||||
test('orchestratorIdMode defaults to compact, persists via settings action, and controls Orchestrator series independently of showUpstreamModel', () => {
|
||||
const h = backendHarness();
|
||||
assert.equal(h.loadSettings().orchestratorIdMode, 'compact');
|
||||
|
||||
const resFull = h.executeSettingsAction({ orchestratorIdMode: 'full' });
|
||||
assert.equal(resFull.ok, true);
|
||||
assert.equal(resFull.updated.orchestratorIdMode, 'full');
|
||||
|
||||
const resInvalid = h.executeSettingsAction({ orchestratorIdMode: 'unexpected' });
|
||||
assert.equal(resInvalid.updated.orchestratorIdMode, 'compact');
|
||||
|
||||
const orchCarbon = {
|
||||
modelKey: ORCH_CARBON,
|
||||
modelShort: 'orch-carbon',
|
||||
modelLabel: 'Orchestrator (Carbon)',
|
||||
modelUpstream: 'gemini-pro-orchestrator (carbon-4)',
|
||||
responseModel: 'gemini-pro-orchestrator',
|
||||
};
|
||||
const orchArgon = {
|
||||
modelKey: ORCH_ARGON,
|
||||
modelShort: 'orch-argon',
|
||||
modelLabel: 'Orchestrator (Argon)',
|
||||
modelUpstream: 'gemini-pro-orchestrator-argon (argon-4)',
|
||||
responseModel: 'gemini-pro-orchestrator-argon',
|
||||
};
|
||||
const orchWorkerCompaction = {
|
||||
modelKey: ORCH_EXEC_HYDROGEN,
|
||||
modelShort: 'hydrogen-4·压缩',
|
||||
modelLabel: 'Orchestrator Worker (Hydrogen) [自动压缩]',
|
||||
modelUpstream: 'gemini-flash-worker-agy (hydrogen-4)·压缩',
|
||||
responseModel: 'gemini-flash-worker-agy',
|
||||
isCompactionStep: true,
|
||||
};
|
||||
const directHydrogen = {
|
||||
modelKey: 'MODEL_PLACEHOLDER_M528',
|
||||
modelShort: 'hydrogen-4-xhigh',
|
||||
modelLabel: 'Gemini 4 Hydrogen (XHigh)',
|
||||
modelUpstream: 'gemini-4-hydrogen-xhigh',
|
||||
};
|
||||
|
||||
for (const showUpstreamModel of [false, true]) {
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(orchCarbon, { showUpstreamModel, orchestratorIdMode: 'compact' }).text,
|
||||
'orchestrator-carbon'
|
||||
);
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(orchArgon, { showUpstreamModel, orchestratorIdMode: 'compact' }).text,
|
||||
'orchestrator-argon'
|
||||
);
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(orchWorkerCompaction, { showUpstreamModel, orchestratorIdMode: 'compact' }).text,
|
||||
'worker-agy-hydrogen·压缩'
|
||||
);
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(orchCarbon, { showUpstreamModel, orchestratorIdMode: 'full' }).text,
|
||||
'gemini-pro-orchestrator (carbon-4)'
|
||||
);
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(orchArgon, { showUpstreamModel, orchestratorIdMode: 'full' }).text,
|
||||
'gemini-pro-orchestrator-argon (argon-4)'
|
||||
);
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(orchWorkerCompaction, { showUpstreamModel, orchestratorIdMode: 'full' }).text,
|
||||
'gemini-flash-worker-agy (hydrogen-4)·压缩'
|
||||
);
|
||||
}
|
||||
|
||||
// Non-Orchestrator direct Hydrogen still follows showUpstreamModel regardless of orchestratorIdMode
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(directHydrogen, { showUpstreamModel: false, orchestratorIdMode: 'compact' }).text,
|
||||
'hydrogen-4-xhigh'
|
||||
);
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(directHydrogen, { showUpstreamModel: true, orchestratorIdMode: 'compact' }).text,
|
||||
'gemini-4-hydrogen-xhigh'
|
||||
);
|
||||
assert.equal(
|
||||
resolveModelDisplayInfo(directHydrogen, { showUpstreamModel: false, orchestratorIdMode: 'full' }, { preferLabelInShort: true }).text,
|
||||
'Gemini 4 Hydrogen (XHigh)'
|
||||
);
|
||||
});
|
||||
|
||||
test('historical placeholders (M15/M16/M47/M84/M132/M133/M264/M330) and verified internal routing slugs resolve and price accurately without wildcarding unknown slugs', () => {
|
||||
const { resolveModelInfo } = backendHarness();
|
||||
|
||||
const expectedPlaceholders = [
|
||||
['MODEL_PLACEHOLDER_M84', 'flash-3.5-high', 1.5, 9.0],
|
||||
['MODEL_PLACEHOLDER_M15', 'flash-3.5-high', 1.5, 9.0],
|
||||
['MODEL_PLACEHOLDER_M132', 'flash-3.5-high', 1.5, 9.0],
|
||||
['MODEL_PLACEHOLDER_M133', 'flash-3.5', 1.5, 9.0],
|
||||
['MODEL_PLACEHOLDER_M47', 'flash-3', 0.5, 3.0],
|
||||
['MODEL_PLACEHOLDER_M16', 'pro-3.1-high', 2.0, 12.0],
|
||||
['MODEL_PLACEHOLDER_M264', 'flash-3.6-high', 0.75, 3.75],
|
||||
['MODEL_PLACEHOLDER_M330', 'flash-2.5-lite', 0.1, 0.4],
|
||||
];
|
||||
for (const [ph, shortName, inputPrice, outputPrice] of expectedPlaceholders) {
|
||||
const info = resolveModelInfo(ph);
|
||||
assert.equal(info.shortName, shortName, `${ph} shortName`);
|
||||
assert.ok(info.pricing, `${ph} should have pricing`);
|
||||
assert.equal(info.pricing.input, inputPrice, `${ph} input price`);
|
||||
assert.equal(info.pricing.output, outputPrice, `${ph} output price`);
|
||||
}
|
||||
|
||||
const expectedSlugs = [
|
||||
['gemini-3-flash-a', 'flash-3.5', 1.5, 9.0],
|
||||
['gemini-3-flash-b', 'flash-3.5', 1.5, 9.0],
|
||||
['gemini-3-flash-c', 'flash-3', 0.5, 3.0],
|
||||
['gemini-3-flash-d', 'flash-3.5', 1.5, 9.0],
|
||||
['gemini-3-flash-agent', 'flash-3.5', 1.5, 9.0],
|
||||
['gemini-pro-default', 'pro-3.1', 2.0, 12.0],
|
||||
['gemini-pro-agent', 'pro-3.1', 2.0, 12.0],
|
||||
['gemini-pro-b', 'pro-3.1', 2.0, 12.0],
|
||||
['gemini-3.7-flash-safety-le', 'flash-3.7', 0.75, 3.75],
|
||||
['gemini-3.8-flash-n', 'flash-3.8', 0.75, 3.75],
|
||||
['gemini-4-argon-f', 'argon-4', 2.0, 10.0],
|
||||
['gemini-4-argon-disabled', 'argon-4', 2.0, 10.0],
|
||||
];
|
||||
for (const [slug, shortName, inputPrice, outputPrice] of expectedSlugs) {
|
||||
const info = resolveModelInfo(slug);
|
||||
assert.equal(info.shortName, shortName, `${slug} shortName`);
|
||||
assert.ok(info.pricing, `${slug} should have pricing`);
|
||||
assert.equal(info.pricing.input, inputPrice, `${slug} input price`);
|
||||
assert.equal(info.pricing.output, outputPrice, `${slug} output price`);
|
||||
}
|
||||
|
||||
// Unverified future variant must still remain unpriced (no reckless prefix fallback)
|
||||
const unknownVariant = resolveModelInfo('gemini-3.1-pro-ultra-v2');
|
||||
assert.equal(unknownVariant.pricing, null);
|
||||
});
|
||||
|
||||
test('deep_stats session-display mislabeling is ignored when step-intrinsic model differs, and micro-costs preserve 6-decimal precision', async () => {
|
||||
const nowIso = new Date(Date.now() - 5_000).toISOString();
|
||||
const h = backendHarness({
|
||||
summaries: {
|
||||
ide_convo: { stepCount: 1 },
|
||||
},
|
||||
trajectories: {
|
||||
ide_convo: {
|
||||
trajectory: {
|
||||
steps: [
|
||||
{
|
||||
type: 'CORTEX_STEP_TYPE_PLANNER_RESPONSE',
|
||||
status: 'CORTEX_STEP_STATUS_DONE',
|
||||
metadata: {
|
||||
sourceTrajectoryStepInfo: { stepIndex: 1 },
|
||||
createdAt: nowIso,
|
||||
completedAt: new Date(Date.now() - 4_000).toISOString(),
|
||||
modelUsage: {
|
||||
model: 'MODEL_GOOGLE_GEMINI_2_5_FLASH_LITE',
|
||||
apiProvider: 'API_PROVIDER_GOOGLE_GEMINI',
|
||||
inputTokens: '1900',
|
||||
cacheReadTokens: '0',
|
||||
outputTokens: '107',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
deepStats: {
|
||||
perConvo: {
|
||||
'standalone:11111111-2222-3333-4444-555555555555': {
|
||||
appSource: 'standalone',
|
||||
entries: [
|
||||
{
|
||||
ts: nowIso,
|
||||
model: 'gemini-2.5-flash-lite',
|
||||
modelCanonicalId: 'gemini-2.5-flash-lite',
|
||||
modelAggregationId: 'session-display:gemini-3-5-flash-lite',
|
||||
modelDisplayName: 'Gemini 3.5 Flash Lite',
|
||||
provider: 'API_PROVIDER_GOOGLE_GEMINI',
|
||||
inp: 12300,
|
||||
cache: 0,
|
||||
out: 154,
|
||||
reasoning: 0,
|
||||
},
|
||||
{
|
||||
ts: nowIso,
|
||||
model: 'gemini-3-flash-a',
|
||||
modelCanonicalId: 'gemini-3-flash-a',
|
||||
modelAggregationId: 'session:gemini-3-flash-a',
|
||||
provider: 'API_PROVIDER_GOOGLE_GEMINI',
|
||||
inp: 3320000,
|
||||
cache: 32730000,
|
||||
out: 120000,
|
||||
reasoning: 195500,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const p = await h.buildTelemetryPayloadInternal('ide_convo');
|
||||
const consumptionModels = p.modelBreakdown;
|
||||
|
||||
// Both gemini-2.5-flash-lite calls (IDE + standalone with session-display:gemini-3-5-flash-lite) merge into one Gemini 2.5 Flash Lite bucket!
|
||||
const flash25Rows = consumptionModels.filter((m) => /2\.5 Flash Lite/i.test(m.label));
|
||||
assert.equal(flash25Rows.length, 1);
|
||||
assert.equal(
|
||||
consumptionModels.some((m) => /3\.5 Flash Lite/i.test(m.label)),
|
||||
false,
|
||||
'mismatched session-display:gemini-3-5-flash-lite should not create a bogus Gemini 3.5 Flash Lite bucket'
|
||||
);
|
||||
assert.equal(flash25Rows[0].calls, 2);
|
||||
assert.equal(flash25Rows[0].unpricedCalls, 0);
|
||||
// 14,200 input * $0.10/M + 261 output * $0.40/M = $0.0015244 -> 0.001524 (> 0, not truncated to 0!)
|
||||
assert.equal(flash25Rows[0].costUsd, 0.001524);
|
||||
|
||||
// Also check single-step micro-cost (< $0.001) on activeConversation.modelBreakdown
|
||||
const sessionFlash25 = p.activeConversation.modelBreakdown.find((m) => /2\.5 Flash Lite/i.test(m.label));
|
||||
assert.ok(sessionFlash25);
|
||||
// 1,900 * $0.10/M + 107 * $0.40/M = $0.0002328 -> 0.000233
|
||||
assert.equal(sessionFlash25.costUsd, 0.000233);
|
||||
assert.equal(formatUsd(sessionFlash25.costUsd, { precise: true }), '<$0.001');
|
||||
assert.equal(formatUsd(flash25Rows[0].costUsd, { precise: true }), '$0.002');
|
||||
|
||||
// Standalone session:gemini-3-flash-a entry preserves responseModel & prices cleanly
|
||||
const flash35Row = consumptionModels.find((m) => m.label === 'Gemini 3.5 Flash');
|
||||
assert.ok(flash35Row);
|
||||
assert.equal(flash35Row.upstreamName, 'gemini-3-flash-a');
|
||||
assert.equal(flash35Row.unpricedCalls, 0);
|
||||
assert.ok(flash35Row.costUsd > 12);
|
||||
});
|
||||
|
||||
test('mergeModelsByDisplayName collapses distinct backend buckets that share the same rendered display text', () => {
|
||||
const rawModels = [
|
||||
{
|
||||
label: 'Gemini 3.8 Flash',
|
||||
shortName: 'flash-3.8',
|
||||
upstreamName: 'gemini-3-flash-a',
|
||||
upstreamModels: ['gemini-3-flash-a', 'gemini-3.8-flash'],
|
||||
calls: 7063,
|
||||
inputTokens: 91_800_000,
|
||||
cacheReadTokens: 674_810_000,
|
||||
outputTokens: 5_510_000,
|
||||
thinkingTokens: 3_130_000,
|
||||
responseTokens: 2_380_000,
|
||||
totalTokens: 772_120_000,
|
||||
costUsd: 286.2,
|
||||
unpricedCalls: 0,
|
||||
avgTokPerSec: 120,
|
||||
speedSummary: { sampleCount: 100, excludedCount: 5, avgTokPerSec: 120 },
|
||||
avgTtftSec: 2.0,
|
||||
ttftSampleCount: 100,
|
||||
},
|
||||
{
|
||||
label: 'Gemini 3.5 Flash',
|
||||
shortName: 'flash-3.5',
|
||||
upstreamName: 'gemini-3-flash-a',
|
||||
upstreamModels: ['gemini-3-flash-a'],
|
||||
calls: 449,
|
||||
inputTokens: 3_320_000,
|
||||
cacheReadTokens: 32_730_000,
|
||||
outputTokens: 315_500,
|
||||
thinkingTokens: 195_500,
|
||||
responseTokens: 120_000,
|
||||
totalTokens: 36_365_500,
|
||||
costUsd: 12.73,
|
||||
unpricedCalls: 0,
|
||||
avgTokPerSec: 80,
|
||||
speedSummary: { sampleCount: 100, excludedCount: 2, avgTokPerSec: 80 },
|
||||
avgTtftSec: 4.0,
|
||||
ttftSampleCount: 100,
|
||||
},
|
||||
];
|
||||
|
||||
// In upstream mode, both resolve to 'gemini-3-flash-a' -> merged into 1 row!
|
||||
const mergedUpstream = mergeModelsByDisplayName(
|
||||
rawModels,
|
||||
{ showUpstreamModel: true },
|
||||
{ preferLabelInShort: true }
|
||||
);
|
||||
assert.equal(mergedUpstream.length, 1);
|
||||
assert.equal(mergedUpstream[0].displayText, 'gemini-3-flash-a');
|
||||
assert.equal(mergedUpstream[0].calls, 7512);
|
||||
assert.equal(mergedUpstream[0].totalTokens, 808_485_500);
|
||||
assert.equal(mergedUpstream[0].costUsd, 298.93);
|
||||
assert.equal(mergedUpstream[0].avgTokPerSec, 100);
|
||||
assert.equal(mergedUpstream[0].avgTtftSec, 3);
|
||||
assert.deepEqual(mergedUpstream[0].sourceLabels, ['Gemini 3.8 Flash', 'Gemini 3.5 Flash']);
|
||||
|
||||
// In friendly label mode, 'Gemini 3.8 Flash' and 'Gemini 3.5 Flash' stay distinct!
|
||||
const mergedShort = mergeModelsByDisplayName(
|
||||
rawModels,
|
||||
{ showUpstreamModel: false },
|
||||
{ preferLabelInShort: true }
|
||||
);
|
||||
assert.equal(mergedShort.length, 2);
|
||||
});
|
||||
|
||||
@@ -308,6 +308,12 @@ test('telemetryStore isEquivalentTelemetry detects quota changes in non-active p
|
||||
b.quotas.pools[1].weeklyUsedPct = 55;
|
||||
b.quotas.pools[1].weeklyRemainingPct = 45;
|
||||
assert.equal(ctx.compare(a, b), false);
|
||||
const c = structuredClone(a);
|
||||
c.quotas.pools[0].cycleWeekly = { tokens: 120_000, costUsd: 0.35, calls: 4 };
|
||||
assert.equal(ctx.compare(a, c), false, 'Pool cycleWeekly change must trigger store update');
|
||||
const d = structuredClone(a);
|
||||
d.quotas.pools[0].cycle5h = { tokens: 50_000, costUsd: 0.15, calls: 2 };
|
||||
assert.equal(ctx.compare(a, d), false, 'Pool cycle5h change must trigger store update');
|
||||
assert.equal(ctx.compare(a, structuredClone(a)), true);
|
||||
});
|
||||
|
||||
@@ -395,3 +401,228 @@ test('switching accounts within 10s immediately invalidates quotaSummaryCache',
|
||||
);
|
||||
assert.equal(second.quotas.pools[0].weeklyRemainingPct, 8.7);
|
||||
});
|
||||
|
||||
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';
|
||||
const ORCH_EXEC_HYDROGEN = 'MODEL_PLACEHOLDER_M669';
|
||||
const geminiReset = new Date(Date.now() + 24 * 3600_000).toISOString();
|
||||
const argonReset = new Date(Date.now() + 48 * 3600_000).toISOString();
|
||||
const carbonReset = new Date(Date.now() + 72 * 3600_000).toISOString();
|
||||
const fiveHourReset = new Date(Date.now() + 2 * 3600_000).toISOString();
|
||||
|
||||
const h = backendHarness({
|
||||
summaries: {
|
||||
orchCarbonPlan: { stepCount: 1 },
|
||||
orchArgonPlan: { stepCount: 1 },
|
||||
orchHydrogenExec: { stepCount: 2 },
|
||||
},
|
||||
trajectories: {
|
||||
orchCarbonPlan: { trajectory: { steps: [makeStep(1, ORCH_CARBON)] } },
|
||||
orchArgonPlan: { trajectory: { steps: [makeStep(1, ORCH_ARGON)] } },
|
||||
orchHydrogenExec: {
|
||||
trajectory: { steps: [makeStep(1, ORCH_CARBON), makeStep(2, ORCH_EXEC_HYDROGEN)] },
|
||||
},
|
||||
},
|
||||
userStatus: {
|
||||
userTier: { id: 'g1-pro-tier', name: 'Google AI Pro' },
|
||||
cascadeModelConfigData: {
|
||||
clientModelConfigs: [
|
||||
{
|
||||
label: 'Orchestrator (Carbon)',
|
||||
modelId: 'gemini-pro-orchestrator',
|
||||
modelOrAlias: { model: ORCH_CARBON },
|
||||
quotaInfo: { remainingFraction: 0.4, resetTime: carbonReset },
|
||||
},
|
||||
{
|
||||
label: 'Orchestrator (Argon)',
|
||||
modelId: 'gemini-pro-orchestrator-argon',
|
||||
modelOrAlias: { model: ORCH_ARGON },
|
||||
quotaInfo: { remainingFraction: 0.6, resetTime: argonReset },
|
||||
},
|
||||
{
|
||||
label: 'Gemini 3.8 Flash (High)',
|
||||
modelId: 'gemini-3.8-flash-high',
|
||||
modelOrAlias: { model: FLASH },
|
||||
quotaInfo: { remainingFraction: 0.9, resetTime: geminiReset },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
quotaSummary: {
|
||||
groups: [
|
||||
{
|
||||
displayName: 'Gemini Models',
|
||||
buckets: [
|
||||
{ bucketId: 'gemini-5h', window: '5h', remainingFraction: 0.95, resetTime: fiveHourReset },
|
||||
{ bucketId: 'gemini-weekly', window: 'weekly', remainingFraction: 0.9, resetTime: geminiReset },
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Gemini 4 Argon',
|
||||
buckets: [
|
||||
{ bucketId: 'argon-weekly', window: 'weekly', remainingFraction: 0.6, resetTime: argonReset },
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Gemini 4 Carbon',
|
||||
buckets: [
|
||||
{ bucketId: 'carbon-weekly', window: 'weekly', remainingFraction: 0.4, resetTime: carbonReset },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const pCarbon = await h.buildTelemetryPayloadInternal('orchCarbonPlan');
|
||||
assert.equal(pCarbon.quotas.activePool.family, 'Carbon');
|
||||
assert.equal(pCarbon.quotas.weekly.poolFamily, 'Carbon');
|
||||
assert.equal(pCarbon.quotas.weekly.remainingPct, 40);
|
||||
|
||||
const pArgon = await h.buildTelemetryPayloadInternal('orchArgonPlan');
|
||||
assert.equal(pArgon.quotas.activePool.family, 'Argon');
|
||||
assert.equal(pArgon.quotas.weekly.poolFamily, 'Argon');
|
||||
assert.equal(pArgon.quotas.weekly.remainingPct, 60);
|
||||
|
||||
const pExec = await h.buildTelemetryPayloadInternal('orchHydrogenExec');
|
||||
assert.equal(pExec.quotas.activePool.family, 'Gemini');
|
||||
assert.equal(pExec.quotas.weekly.poolFamily, 'Gemini');
|
||||
assert.equal(pExec.quotas.weekly.remainingPct, 90);
|
||||
});
|
||||
|
||||
test('per-pool cycle5h and cycleWeekly isolate each pool by its own reset window and sum into quotas.weekly', async () => {
|
||||
const now = Date.now();
|
||||
const CLAUDE_SONNET = 'MODEL_CLAUDE_4_5_SONNET';
|
||||
// Gemini weekly cycle started 1d ago (resets in +6d); 5h cycle started 1h ago (resets in +4h)
|
||||
const geminiWkReset = new Date(now + 6 * 24 * 3600_000).toISOString();
|
||||
const gemini5hReset = new Date(now + 4 * 3600_000).toISOString();
|
||||
// Argon weekly cycle started 5d ago (resets in +2d)
|
||||
const argonWkReset = new Date(now + 2 * 24 * 3600_000).toISOString();
|
||||
// Claude & GPT weekly cycle started 6d ago (resets in +1d); 5h cycle started 4h ago (resets in +1h)
|
||||
const claudeWkReset = new Date(now + 1 * 24 * 3600_000).toISOString();
|
||||
const claude5hReset = new Date(now + 1 * 3600_000).toISOString();
|
||||
|
||||
const makeTimedStep = (idx, model, ageMs, provider = 'API_PROVIDER_GOOGLE_GEMINI', tok = 10_000) => {
|
||||
const t = now - ageMs;
|
||||
return {
|
||||
type: 'CORTEX_STEP_TYPE_PLANNER_RESPONSE',
|
||||
status: 'CORTEX_STEP_STATUS_DONE',
|
||||
metadata: {
|
||||
sourceTrajectoryStepInfo: { stepIndex: idx },
|
||||
createdAt: new Date(t).toISOString(),
|
||||
completedAt: new Date(t + 2_000).toISOString(),
|
||||
modelUsage: {
|
||||
model,
|
||||
apiProvider: provider,
|
||||
inputTokens: String(tok),
|
||||
cacheReadTokens: '0',
|
||||
outputTokens: '1000',
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const h = backendHarness({
|
||||
summaries: { multiCycleConv: { stepCount: 6 } },
|
||||
trajectories: {
|
||||
multiCycleConv: {
|
||||
trajectory: {
|
||||
steps: [
|
||||
// 1. Gemini Flash 30m ago -> inside Gemini 5h (1h ago) & Gemini weekly (1d ago)
|
||||
makeTimedStep(1, FLASH, 30 * 60_000, 'API_PROVIDER_GOOGLE_GEMINI', 10_000),
|
||||
// 2. Gemini Flash 3h ago -> OUTSIDE Gemini 5h (started 1h ago), INSIDE Gemini weekly (1d ago)
|
||||
makeTimedStep(2, FLASH, 3 * 3600_000, 'API_PROVIDER_GOOGLE_GEMINI', 20_000),
|
||||
// 3. Gemini Flash 3d ago -> OUTSIDE Gemini weekly (started 1d ago)!
|
||||
makeTimedStep(3, FLASH, 3 * 24 * 3600_000, 'API_PROVIDER_GOOGLE_GEMINI', 99_000),
|
||||
// 4. Argon 3d ago -> INSIDE Argon weekly (started 5d ago)!
|
||||
makeTimedStep(4, ARGON, 3 * 24 * 3600_000, 'API_PROVIDER_GOOGLE_GEMINI', 40_000),
|
||||
// 5. Claude 3h ago -> INSIDE Claude 5h (started 4h ago) & Claude weekly (started 6d ago)
|
||||
makeTimedStep(5, CLAUDE_SONNET, 3 * 3600_000, 'API_PROVIDER_ANTHROPIC', 30_000),
|
||||
// 6. Claude 4d ago -> OUTSIDE Claude 5h, INSIDE Claude weekly (started 6d ago)
|
||||
makeTimedStep(6, CLAUDE_SONNET, 4 * 24 * 3600_000, 'API_PROVIDER_ANTHROPIC', 50_000),
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
userStatus: {
|
||||
userTier: { id: 'g1-pro-tier', name: 'Google AI Pro' },
|
||||
cascadeModelConfigData: {
|
||||
clientModelConfigs: [
|
||||
{
|
||||
label: 'Gemini 3.8 Flash (High)',
|
||||
modelId: 'gemini-3.8-flash-high',
|
||||
modelOrAlias: { model: FLASH },
|
||||
quotaInfo: { remainingFraction: 0.85, resetTime: gemini5hReset },
|
||||
},
|
||||
{
|
||||
label: 'Gemini 4 Argon (High)',
|
||||
modelId: 'gemini-4-argon-high',
|
||||
modelOrAlias: { model: ARGON },
|
||||
quotaInfo: { remainingFraction: 0.6, resetTime: argonWkReset },
|
||||
},
|
||||
{
|
||||
label: 'Claude 4.5 Sonnet',
|
||||
modelId: 'claude-sonnet-4-5',
|
||||
modelOrAlias: { model: CLAUDE_SONNET },
|
||||
quotaInfo: { remainingFraction: 0.7, resetTime: claude5hReset },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
quotaSummary: {
|
||||
groups: [
|
||||
{
|
||||
displayName: 'Gemini Models',
|
||||
buckets: [
|
||||
{ bucketId: 'gemini-5h', window: '5h', remainingFraction: 0.85, resetTime: gemini5hReset },
|
||||
{ bucketId: 'gemini-weekly', window: 'weekly', remainingFraction: 0.8, resetTime: geminiWkReset },
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Gemini 4 Argon',
|
||||
buckets: [
|
||||
{ bucketId: 'argon-weekly', window: 'weekly', remainingFraction: 0.6, resetTime: argonWkReset },
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Claude and GPT models',
|
||||
buckets: [
|
||||
{ bucketId: '3p-5h', window: '5h', remainingFraction: 0.7, resetTime: claude5hReset },
|
||||
{ bucketId: '3p-weekly', window: 'weekly', remainingFraction: 0.5, resetTime: claudeWkReset },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const p = await h.buildTelemetryPayloadInternal('multiCycleConv');
|
||||
const byKey = new Map(p.quotas.pools.map((pool) => [pool.poolKey, pool]));
|
||||
|
||||
const geminiPool = byKey.get('Gemini');
|
||||
const argonPool = byKey.get('Argon');
|
||||
const claudePool = byKey.get('Claude & GPT');
|
||||
|
||||
// Gemini: step 1 (11,000) in 5h; steps 1+2 (32,000) in weekly; step 3 (3d ago) excluded!
|
||||
assert.equal(geminiPool.cycle5h.calls, 1);
|
||||
assert.equal(geminiPool.cycle5h.tokens, 11_000);
|
||||
assert.equal(geminiPool.cycleWeekly.calls, 2);
|
||||
assert.equal(geminiPool.cycleWeekly.tokens, 32_000);
|
||||
|
||||
// Argon: step 4 (41,000) in weekly (3d ago < 5d window)
|
||||
assert.equal(argonPool.cycleWeekly.calls, 1);
|
||||
assert.equal(argonPool.cycleWeekly.tokens, 41_000);
|
||||
|
||||
// Claude & GPT: step 5 (31,000) in 5h; steps 5+6 (82,000) in weekly (4d ago < 6d window, not clipped by Gemini's 1d window!)
|
||||
assert.equal(claudePool.cycle5h.calls, 1);
|
||||
assert.equal(claudePool.cycle5h.tokens, 31_000);
|
||||
assert.equal(claudePool.cycleWeekly.calls, 2);
|
||||
assert.equal(claudePool.cycleWeekly.tokens, 82_000);
|
||||
|
||||
// Global quotas.weekly equals the exact sum across all pools' weekly cycles (2 + 1 + 2 = 5 calls; 32k + 41k + 82k = 155k tokens)
|
||||
assert.equal(p.quotas.weekly.calls, 5);
|
||||
assert.equal(p.quotas.weekly.tokens, 155_000);
|
||||
assert.equal(
|
||||
p.quotas.weekly.costUsd,
|
||||
+(geminiPool.cycleWeekly.costUsd + argonPool.cycleWeekly.costUsd + claudePool.cycleWeekly.costUsd).toFixed(2)
|
||||
);
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user