mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-27 01:19:25 +08:00
refactor(panel): extract overlay anchors and consumption row builders
- Extract host anchor discovery, 4-stage capsule layout hysteresis, and ShadowRoot stylesheet mounting from WindowOverlayShell into overlayHostAnchors - Extract reusable model, client-source, workspace, and top-conversation breakdown row builders from ConsumptionView into ConsumptionBreakdownRows - Add root CHANGELOG.md and regression coverage for extracted P3 modules and export header documentation
This commit is contained in:
@@ -430,6 +430,9 @@ test('Feature 5: TrendAreaChart drill-down click and unified Models/Sessions seg
|
||||
const { document } = createMockDom();
|
||||
globalThis.document = document;
|
||||
globalThis.window = {
|
||||
sidecar: {
|
||||
fetch: (url, init) => globalThis.fetch(url, init),
|
||||
},
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
requestAnimationFrame: (cb) => {
|
||||
@@ -621,6 +624,9 @@ test('Feature 6: model ranking multi-metric sort with efficiency footer & valida
|
||||
const { document } = createMockDom();
|
||||
globalThis.document = document;
|
||||
globalThis.window = {
|
||||
sidecar: {
|
||||
fetch: (url, init) => globalThis.fetch(url, init),
|
||||
},
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
requestAnimationFrame: (cb) => {
|
||||
@@ -1099,6 +1105,9 @@ test('Feature 9: workspace/project cost aggregation (full + fast paths) and Proj
|
||||
const { document } = createMockDom();
|
||||
globalThis.document = document;
|
||||
globalThis.window = {
|
||||
sidecar: {
|
||||
fetch: (url, init) => globalThis.fetch(url, init),
|
||||
},
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
requestAnimationFrame: (cb) => {
|
||||
@@ -2886,3 +2895,106 @@ test('P2 regressions: bundler regex-after-paren lexer, shared URI/prompt/atomic
|
||||
assert.equal(reimported.patch.experimentalQuotaReservation, true);
|
||||
assert.equal(reimported.patch.accountQuotaRefreshMinutes, 180);
|
||||
});
|
||||
|
||||
test('Feature 16: P3 extracted sub-modules (stepChartMath, overlayHostAnchors, ConsumptionBreakdownRows) and doc-to-code parity guard', async (t) => {
|
||||
const prevDoc = globalThis.document;
|
||||
const prevWin = globalThis.window;
|
||||
const { document } = createMockDom();
|
||||
globalThis.document = document;
|
||||
globalThis.window = {
|
||||
location: { pathname: '/' },
|
||||
addEventListener() {},
|
||||
removeEventListener() {},
|
||||
requestAnimationFrame: (cb) => setTimeout(cb, 0),
|
||||
cancelAnimationFrame: (id) => clearTimeout(id),
|
||||
};
|
||||
t.after(() => {
|
||||
globalThis.document = prevDoc;
|
||||
globalThis.window = prevWin;
|
||||
});
|
||||
|
||||
const [
|
||||
{ computeLinearFit, computeNiceYScale, buildSplinePath },
|
||||
{ computeCapsuleLayoutMode },
|
||||
{ partitionModelSegments },
|
||||
{ DEFAULT_SETTINGS_SCHEMA },
|
||||
{ BRIDGE_API_ROUTE_DEFS },
|
||||
fsMod,
|
||||
pathMod,
|
||||
urlMod,
|
||||
] = await Promise.all([
|
||||
import('../src/components/charts/stepChartMath.js'),
|
||||
import('../src/components/layout/overlayHostAnchors.js'),
|
||||
import('../src/components/widgets/ConsumptionBreakdownRows.js'),
|
||||
import('../backend/settings-schema.mjs'),
|
||||
import('../shared/window-bridge-protocol.mjs'),
|
||||
import('node:fs'),
|
||||
import('node:path'),
|
||||
import('node:url'),
|
||||
]);
|
||||
|
||||
// 1. Extracted chart math + layout hysteresis + model segment partition
|
||||
const fit = computeLinearFit([20, 30, 40], { xs: [1000, 2000, 3000] });
|
||||
assert.ok(fit && Math.abs(fit.slope - 0.01) < 1e-6);
|
||||
const scale = computeNiceYScale(0, 93, 4);
|
||||
assert.ok(scale.max >= 93 && scale.ticks.length >= 2);
|
||||
assert.match(buildSplinePath([{ x: 0, y: 10 }, { x: 20, y: 30 }, { x: 40, y: 15 }]), /^M/);
|
||||
|
||||
assert.equal(computeCapsuleLayoutMode(380, 'wide', { slotCount: 3 }), 'wide');
|
||||
assert.equal(computeCapsuleLayoutMode(260, 'wide', { slotCount: 3 }), 'wide');
|
||||
assert.equal(computeCapsuleLayoutMode(260, 'compact', { slotCount: 3 }), 'compact');
|
||||
assert.equal(computeCapsuleLayoutMode(70, 'minimal', { slotCount: 3 }), 'ring-only');
|
||||
|
||||
const segs = partitionModelSegments(
|
||||
[
|
||||
{ label: '4-neon', totalTokens: 700 },
|
||||
{ label: '4-argon', totalTokens: 300 },
|
||||
],
|
||||
new Map()
|
||||
);
|
||||
assert.equal(segs.length, 2);
|
||||
assert.equal(Math.round(segs[0].pct + segs[1].pct), 100);
|
||||
|
||||
// 2. Repo documentation parity against live schema & route definitions
|
||||
// Note: `docs/` and `plan/` are local engineering directories (.gitignore); guard with existsSync so fresh CI clones pass cleanly while local dev enforces 100% parity.
|
||||
const repoRoot = pathMod.resolve(pathMod.dirname(urlMod.fileURLToPath(import.meta.url)), '..', '..', '..');
|
||||
assert.ok(fsMod.existsSync(pathMod.join(repoRoot, 'CHANGELOG.md')), 'Root CHANGELOG.md must exist');
|
||||
const readmeEn = fsMod.readFileSync(pathMod.join(repoRoot, 'README.md'), 'utf8');
|
||||
const readmeZh = fsMod.readFileSync(pathMod.join(repoRoot, 'README.zh-CN.md'), 'utf8');
|
||||
assert.ok(readmeEn.includes('defineComponent') && !readmeEn.includes('native Web Components'));
|
||||
assert.ok(readmeZh.includes('defineComponent') && !readmeZh.includes('原生 Web Components'));
|
||||
|
||||
const docsDir = pathMod.join(repoRoot, 'docs');
|
||||
if (fsMod.existsSync(docsDir)) {
|
||||
const settingsDoc = fsMod.readFileSync(pathMod.join(docsDir, 'settings-and-cli.md'), 'utf8');
|
||||
for (const key of Object.keys(DEFAULT_SETTINGS_SCHEMA)) {
|
||||
assert.ok(settingsDoc.includes(`\`${key}\``), `docs/settings-and-cli.md must document setting key: ${key}`);
|
||||
}
|
||||
|
||||
const apiDoc = fsMod.readFileSync(pathMod.join(docsDir, 'backend-and-api.md'), 'utf8');
|
||||
for (const route of BRIDGE_API_ROUTE_DEFS) {
|
||||
assert.ok(
|
||||
apiDoc.includes(`${route.method} ${route.path}`),
|
||||
`docs/backend-and-api.md must document route: ${route.method} ${route.path}`
|
||||
);
|
||||
}
|
||||
for (const requiredModule of [
|
||||
'cloudcode-proxy.mjs',
|
||||
'quota-reservation.mjs',
|
||||
'fs-atomic.mjs',
|
||||
'trajectory-cache-store.mjs',
|
||||
'.xlsx',
|
||||
]) {
|
||||
assert.ok(apiDoc.includes(requiredModule), `docs/backend-and-api.md must cover ${requiredModule}`);
|
||||
}
|
||||
|
||||
const feDoc = fsMod.readFileSync(pathMod.join(docsDir, 'frontend-core-and-store.md'), 'utf8');
|
||||
assert.ok(feDoc.includes('xlsxBuilder.js') && feDoc.includes('exportBinaryFileWithFeedback'));
|
||||
}
|
||||
|
||||
const legacyPlanPath = pathMod.join(repoRoot, 'plan', 'code-audit-and-cleanup-plan.md');
|
||||
if (fsMod.existsSync(legacyPlanPath)) {
|
||||
const legacyPlan = fsMod.readFileSync(legacyPlanPath, 'utf8');
|
||||
assert.match(legacyPlan, /ARCHIVED/);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user