Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions tests/web/supervisorActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// The Supervisor page runs one classic script (web/static/js/supervisor.js),
// The Supervisor page runs classic scripts (web/static/js/supervisor.js and
// supervisorPanels.js),
// so a source-shape assertion cannot tell whether a failed Stop still reads as
// sent. Run the real page and script in jsdom with a scripted fetch and a
// hand-driven clock.
Expand All @@ -9,13 +10,19 @@ import { join } from 'node:path';
import { JSDOM } from 'jsdom';

const STATIC = join(__dirname, '..', '..', 'web', 'static');
const SCRIPT_TAG = '<script src="/static/js/supervisor.js"></script>';
/** The page with its script inlined: jsdom does not fetch /static/ assets. */
// Both classic scripts, in load order: the panels declare what supervisor.js's
// init code calls (AGT-4868).
const SCRIPTS = ['supervisorPanels.js', 'supervisor.js'];
/** The page with its scripts inlined: jsdom does not fetch /static/ assets. */
function pageSource(): string {
const html = readFileSync(join(STATIC, 'supervisor.html'), 'utf8');
if (!html.includes(SCRIPT_TAG)) throw new Error('supervisor.html no longer loads supervisor.js');
const script = readFileSync(join(STATIC, 'js', 'supervisor.js'), 'utf8');
return html.replace(SCRIPT_TAG, () => `<script>${script}</script>`);
let html = readFileSync(join(STATIC, 'supervisor.html'), 'utf8');
for (const name of SCRIPTS) {
const tag = `<script src="/static/js/${name}"></script>`;
if (!html.includes(tag)) throw new Error(`supervisor.html no longer loads ${name}`);
const script = readFileSync(join(STATIC, 'js', name), 'utf8');
html = html.replace(tag, () => `<script>${script}</script>`);
}
return html;
}
const PROVIDERS = ['codex', 'openrouter'];

Expand Down
43 changes: 43 additions & 0 deletions tests/web/supervisorSize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// The Supervisor's classic scripts stay under book.md Art. III's 1500 code LOC
// cap per file (AGT-4868). Code LOC = lines that are neither blank nor comment.

import { describe, expect, it } from 'vitest';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

const JS = join(__dirname, '..', '..', 'web', 'static', 'js');
const CAP = 1500;

function codeLoc(source: string): number {
let inBlock = false;
let count = 0;
for (const raw of source.split('\n')) {
const line = raw.trim();
if (inBlock) {
if (line.includes('*/')) inBlock = false;
continue;
}
if (line === '' || line.startsWith('//')) continue;
if (line.startsWith('/*')) {
if (!line.includes('*/')) inBlock = true;
continue;
}
count++;
}
return count;
}

describe('Supervisor script size', () => {
it.each(['supervisor.js', 'supervisorPanels.js'])('%s is under the code LOC cap', (name) => {
expect(codeLoc(readFileSync(join(JS, name), 'utf8'))).toBeLessThan(CAP);
});

it('supervisorPanels.js only declares, so loading it before supervisor.js is safe', () => {
const topLevel = readFileSync(join(JS, 'supervisorPanels.js'), 'utf8')
.split('\n')
.filter((l) => /^[^\s}/)]/.test(l));
for (const line of topLevel) {
expect(line, line).toMatch(/^(?:async function|function|let|var|const) /);
}
});
});
2 changes: 1 addition & 1 deletion tests/web/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('server-rendered legacy pages (AGT-4201)', () => {
const pages = [
join(__dirname, '..', '..', 'src', 'issues', 'issueBoardHtml.ts'),
];
const markupSources = [...pages, join(ROOT, 'js', 'supervisor.js')];
const markupSources = [...pages, join(ROOT, 'js', 'supervisor.js'), join(ROOT, 'js', 'supervisorPanels.js')];

it('link tokens.css, boot the theme first, and offer a toggle', () => {
for (const file of pages) {
Expand Down
Loading
Loading