Survivor #3 (bake-off data un-archived): per-run JSON a1..b3.json was never committed (git diff-filter=A empty), so the medians/jaccard ladder cannot be re-derived or audited. Commit-path would require fabricated data (forbidden) → downgraded "POSITIVE" to "opt-in-defensible (single un-archived run)" in docs/T2-bakeoff-results.md (verdict line + §5 header + new §Reproducibility caveat) and the v5.5.0 CHANGELOG entry. New doc-consistency pin fails if the doc re-asserts bare POSITIVE or drops the un-archived disclosure. Survivor #5 (latent dispatch risk): planning/research/review orchestrators are inline reference docs no command invokes, yet shipped tools:["Agent",...]. The harness cannot spawn sub-agents with Agent, so the grant was pure latent risk. Dropped "Agent" from all three frontmatters; flipped the agent-frontmatter invariant (its canonical home) from "must include Agent" to "must NOT include Agent". Removed the duplicate orchestrator pin from doc-consistency to avoid a double guard (S19 anti-bloat). Tests 690 → 691 (689 pass / 2 skip / 0 fail). claude plugin validate passes (1 accepted CLAUDE.md-at-root warning). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LqBYc8Ltrk7LipyJmGxXiB
129 lines
4.7 KiB
JavaScript
129 lines
4.7 KiB
JavaScript
// tests/lib/agent-frontmatter.test.mjs
|
|
// Pin the agent-frontmatter contract from Steps 1-3 of plan-v2:
|
|
// every agents/*.md MUST declare:
|
|
// - model: (one of opus | sonnet | haiku)
|
|
// - tools: (allowlist) OR disallowedTools: (denylist), at least one
|
|
// Orchestrator agents (planning/research/review) MUST be model: opus and
|
|
// MUST include the `Agent` tool in their tools allowlist (they spawn the swarm).
|
|
//
|
|
// When this test fails, fix the agent file — do NOT relax the assertion to
|
|
// hide drift. The contract is what /trek* commands rely on for
|
|
// disciplined model selection + tool scoping.
|
|
|
|
import { test } from 'node:test';
|
|
import { strict as assert } from 'node:assert';
|
|
import { readFileSync, readdirSync } from 'node:fs';
|
|
import { join, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
const ROOT = join(HERE, '..', '..');
|
|
const AGENTS_DIR = join(ROOT, 'agents');
|
|
|
|
const ORCHESTRATORS = new Set([
|
|
'planning-orchestrator.md',
|
|
'research-orchestrator.md',
|
|
'review-orchestrator.md',
|
|
]);
|
|
|
|
const ALLOWED_MODELS = new Set(['opus', 'sonnet', 'haiku']);
|
|
|
|
function read(rel) {
|
|
return readFileSync(join(ROOT, rel), 'utf-8');
|
|
}
|
|
|
|
function extractFrontmatter(text) {
|
|
const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
return m ? m[1] : null;
|
|
}
|
|
|
|
function hasTopLevelKey(fm, key) {
|
|
return new RegExp(`^${key}\\s*:`, 'm').test(fm);
|
|
}
|
|
|
|
function getTopLevelValue(fm, key) {
|
|
const m = fm.match(new RegExp(`^${key}\\s*:\\s*(.+?)\\s*$`, 'm'));
|
|
return m ? m[1] : null;
|
|
}
|
|
|
|
const agentFiles = readdirSync(AGENTS_DIR).filter(f => f.endsWith('.md'));
|
|
|
|
test('every agents/*.md declares a model: field', () => {
|
|
assert.ok(agentFiles.length > 0, 'No agent files found under agents/');
|
|
for (const f of agentFiles) {
|
|
const fm = extractFrontmatter(read(`agents/${f}`));
|
|
assert.ok(fm, `agents/${f}: missing YAML frontmatter block`);
|
|
assert.ok(
|
|
hasTopLevelKey(fm, 'model'),
|
|
`agents/${f}: required \`model:\` field missing from frontmatter`,
|
|
);
|
|
const value = getTopLevelValue(fm, 'model');
|
|
assert.ok(
|
|
value && ALLOWED_MODELS.has(value),
|
|
`agents/${f}: model: "${value}" must be one of ${[...ALLOWED_MODELS].join(' | ')}`,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('every agents/*.md declares tools: or disallowedTools:', () => {
|
|
for (const f of agentFiles) {
|
|
const fm = extractFrontmatter(read(`agents/${f}`));
|
|
assert.ok(fm, `agents/${f}: missing YAML frontmatter block`);
|
|
assert.ok(
|
|
hasTopLevelKey(fm, 'tools') || hasTopLevelKey(fm, 'disallowedTools'),
|
|
`agents/${f}: required \`tools:\` (allowlist) or \`disallowedTools:\` (denylist) field missing`,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('every agents/*.md frontmatter name matches its filename', () => {
|
|
for (const f of agentFiles) {
|
|
const fm = extractFrontmatter(read(`agents/${f}`));
|
|
assert.ok(fm, `agents/${f}: missing frontmatter`);
|
|
const expected = f.replace(/\.md$/, '');
|
|
const value = getTopLevelValue(fm, 'name');
|
|
assert.equal(
|
|
value,
|
|
expected,
|
|
`agents/${f}: frontmatter name="${value}" should match filename "${expected}"`,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('orchestrator agents are model: opus and do NOT include the Agent tool (reference-only, never spawned)', () => {
|
|
// S17 / Survivor #5: these orchestrator .md files are inline reference docs.
|
|
// No command invokes them, and the harness does not expose the Agent tool to
|
|
// sub-agents, so an Agent grant here is purely a latent dispatch risk. They
|
|
// must NOT carry it — the real orchestration runs in the main session.
|
|
for (const f of ORCHESTRATORS) {
|
|
const path = `agents/${f}`;
|
|
const fm = extractFrontmatter(read(path));
|
|
assert.ok(fm, `${path}: missing frontmatter`);
|
|
const model = getTopLevelValue(fm, 'model');
|
|
assert.equal(
|
|
model,
|
|
'opus',
|
|
`${path}: orchestrator must be model: opus (documents multi-agent swarm reasoning) — got "${model}"`,
|
|
);
|
|
const tools = getTopLevelValue(fm, 'tools');
|
|
assert.ok(
|
|
tools && !/\bAgent\b/.test(tools),
|
|
`${path}: orchestrator is reference-only — tools: must NOT include "Agent" (Survivor #5) — got ${tools}`,
|
|
);
|
|
}
|
|
});
|
|
|
|
test('non-orchestrator agents do NOT include the Agent tool (no recursive swarming)', () => {
|
|
for (const f of agentFiles) {
|
|
if (ORCHESTRATORS.has(f)) continue;
|
|
const fm = extractFrontmatter(read(`agents/${f}`));
|
|
assert.ok(fm, `agents/${f}: missing frontmatter`);
|
|
const tools = getTopLevelValue(fm, 'tools');
|
|
if (tools === null) continue; // disallowedTools-only agent — fine
|
|
assert.ok(
|
|
!/\bAgent\b/.test(tools),
|
|
`agents/${f}: non-orchestrator must NOT include the Agent tool ` +
|
|
`(only orchestrators spawn sub-agents) — got tools: ${tools}`,
|
|
);
|
|
}
|
|
});
|