MCP: the agent facade moves into src/agent/, assembled into the development page only
The command tables and the page-side reads, screens and dispatch (scripts/lib/mcp-commands.js and
mcp-page.js) become src/agent/, the facade window.TUBES.call(tool, args) in the page's own scope.
A new <!-- @include-dev agent --> line in src/index.html pastes it in after the game, but only in the
development page (npm run dev, the MCP server, i18n-check, tests that ask with load({agent:true})).
The build drops the line whole: _site/ is byte for byte what main builds.
Tests load the page players get by default, the build test fails if anything outside src/agent/ names
the facade's api/API_ names, and the pages test checks the built page carries none of it and still
plays. ADR 0004 records the rule.
This commit is contained in:
parent
b2366ed260
commit
5b76685e5c
27 changed files with 1052 additions and 869 deletions
|
|
@ -46,10 +46,28 @@ test('src: partials follow the layout rules (docs/adr/0002-one-page-assembled-at
|
|||
const src = path.join(root, 'src');
|
||||
for (const f of listFiles(src)) {
|
||||
if (f === 'index.html' || f === 'i18n/en.js') continue;
|
||||
assert.match(f, /^(styles\/(\d\d-[a-z0-9-]+\/)*\d\d-[a-z0-9-]+\.css|game\/(\d\d-[a-z0-9-]+\/)*\d\d-[a-z0-9-]+\.js)$/, `${f}: name it NN-lower-case under styles/ or game/`);
|
||||
assert.match(f, /^(styles\/(\d\d-[a-z0-9-]+\/)*\d\d-[a-z0-9-]+\.css|(game|agent)\/(\d\d-[a-z0-9-]+\/)*\d\d-[a-z0-9-]+\.js)$/, `${f}: name it NN-lower-case under styles/, game/ or agent/`);
|
||||
}
|
||||
for (const dev of [false, true]) {
|
||||
const { html, map } = assemble({ dev });
|
||||
assert.equal((html.match(/^const ACT=\{$/gm) || []).length, 1, 'ACT is declared once; other action files use Object.assign(ACT,{…})');
|
||||
assert.equal((html.match(/<script>/g) || []).length, 2, 'the language loader and the game: one inline game script');
|
||||
assert.ok(map.length > 50 && map.every((m) => m.to >= m.from), 'the line map covers every partial');
|
||||
}
|
||||
});
|
||||
|
||||
test('src: the game never names the agent code, which only the development page has (docs/adr/0004-dev-only-code.md)', () => {
|
||||
// Everything src/agent/ defines at the top level is named api…, API_… (or is window.TUBES), so one pattern finds any
|
||||
// use of it elsewhere: such code would work in development and break in the page players get.
|
||||
const { listFiles } = require('../scripts/lib/page');
|
||||
const src = path.join(root, 'src'), read = (f) => fs.readFileSync(path.join(src, f), 'utf8'), AGENT = /\b(api[A-Z]\w*|API_[A-Z0-9_]+|TUBES)\b/;
|
||||
let n = 0;
|
||||
for (const f of listFiles(path.join(src, 'agent'))) {
|
||||
for (const m of read('agent/' + f).matchAll(/^(?:const|let|var|function|async function)\s+([A-Za-z_$][\w$]*)/gm)) { n++; assert.match(m[1], AGENT, `src/agent/${f}: top-level ${m[1]} is named api… or API_…`); }
|
||||
}
|
||||
assert.ok(n > 30, `found the agent's top-level names (${n})`);
|
||||
for (const f of listFiles(src).filter((f) => !f.startsWith('agent/'))) {
|
||||
const m = read(f).match(AGENT);
|
||||
assert.equal(m, null, `src/${f} names ${m && m[0]}, which only the development page defines`);
|
||||
}
|
||||
const { html, map } = assemble();
|
||||
assert.equal((html.match(/^const ACT=\{$/gm) || []).length, 1, 'ACT is declared once; other action files use Object.assign(ACT,{…})');
|
||||
assert.equal((html.match(/<script>/g) || []).length, 2, 'the language loader and the game: one inline game script');
|
||||
assert.ok(map.length > 50 && map.every((m) => m.to >= m.from), 'the line map covers every partial');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue