seriesoftubes/tests/act-args-builtins.test.js
jvanvik 08eb349d87
Some checks are pending
CI / plan (push) Waiting to run
CI / part (push) Blocked by required conditions
CI / build (push) Waiting to run
CI / translations (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / timings (push) Blocked by required conditions
Container image / gate (push) Waiting to run
Container image / test (push) Blocked by required conditions
Container image / publish (push) Blocked by required conditions
Merge upstream: POP standards, latency contracts, device transfer, typed links and NOC downgrades (3.4.0, 3.5.0)
Conflicts, file by file:
- CHANGELOG.md: the fork's Unreleased bullets on top; 3.5.0 and 3.4.0 exactly as upstream has them.
- src/i18n/en.js, site/i18n/{de,es,fr,it,pt}.js: merged label by label, sorted; the labels each side dropped stay dropped.
- src/agent/10-domains.js, 30-docs.js, 40-read.js: both sides' enums, state docs and tables (popStd as the build standard, popTiers, ip4, mp).
- src/agent/20-commands.js: the fork's wording on accept and upRouter, upstream's acceptFix, utilityKitAll/New and pt*; theme, session and transfer acts in the local table.
- src/game/60-features/80-new-game.js: ip4, rgen and mp next to popTiers.
- src/game/80-simulation/29-route-core.js, 30-compute.js: the route core takes both SATN and the spill tiers (TT).
- src/game/80-simulation/40-billing.js: upstream's gulfPair and borderShut; linkCut() is built on borderShut, linkDown() keeps express and satellite.
- src/game/80-simulation/50-sanitize.js: PNI bundles up to PNI_LAG_MAX next to the fork's link kinds; popStdSanitize then ptSanitize; mpSanitize then lcSanitize.
- src/game/80-simulation/75-customer-lifecycle.js: clGrow() stops at a type's most (#137) and at an IPv4 block that is not free (#150).
- src/game/90-actions/60-links.js: rmLink keeps the express guard and moves on to the next parallel link (#119).
- src/game/90-actions/85-routing-and-routers.js: rmRouter checks the PNIs on its routers (#323), upRouter keeps own().
- src/game/90-actions/89-game-and-settings.js: the menu keeps the build standard and session tiles and gains Send to another device.
- src/game/93-ui/40-hud-and-panels.js, 70-link-panels.js: offers show both the IPv4 note and Buy and sign; link headers name their cities, the closed-border section reads in dark mode; the express count stays.
- src/game/93-ui/50-city-panel.js: the teleport section and Link to a city.
- src/game/94-dashboard/40-connections.js: upstream's per-table next port size replaces the fork's own 400G guard.
- src/game/94-dashboard/90-noc-window.js, 96-map/95-clicks.js, 99-loop.js: both sides' acts and boot steps.
- src/styles/40-modal.css: the dark-mode tag tokens and the transfer textarea.
- tests/mcp-commands.test.js: both sides' sample args.

Interaction fixes:
- POP standards and the build standard: a POP marked as a kind keeps its kind's routers (ptKind). The build
  standard's router jobs and the intern's model swaps leave it alone; every other target still applies. Both sheets say so.
- Spill tiers: pathMs() fills a path's ground latency and satellite edges too, so a tier's detour costs users its
  latency (it went uncharged before).
- Send to another device: a session network goes by the session's own #mp= link; its save file is called a copy.
- Buy and sign (#241) does not buy for an offer whose IPv4 block does not fit.
- Dark mode: the closed-border title and the renewal ticks use the dark-aware red (upstream's #292 test follows).
- Server-run tables: the new acts classified (pt*, acceptFix and utilityKitAll quote their cost); mp-sim fixtures
  written again with tests/lib/mp-sim-fixtures.js.

Review fixes:
- POP standards: ptSave, ptApply, ptPlan, ptAll and popStdSet find a POP with own(), so 'toString' is no POP (also
  decomToggle, decomGo, dkStay).
- Server-run envelope: an arg value that names anything on Object.prototype is refused, in args, drafts and
  ctx.win.ui.
- Decommissioning a POP drops its POP-standard mark, so live state stays what a reload makes of it (the T2 gate
  refused later pt* acts).
- acceptFix, ptApply, ptAll and utilityKitAll take a quote within 1% (quoteNear), like utilityKit and bstdApply:
  router prices drift daily.
- The transfer paste box reads in dark mode (--text, as input.t).
- A session's #mp= link pasted under From another device opens it (saved, then loaded again with it), in MP builds.
- The express and satellite circuit panels name their cities as links (#196); a circuit shows the closed-border
  section (#329).
- CHANGELOG: the fork's 400G connections bullet goes (3.5.0 ships it); bullets for POP kinds, the session link and Buy
  and sign's IPv4 check.
2026-11-12 00:52:42 +01:00

44 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// A click's args name things the game looks up by key: S.pops[city], S.myIx[city]. A city that is '__proto__' or
// 'constructor', or any other name Object.prototype has ('toString': S.pops.toString is a function, so it reads as a
// POP), from an MCP agent or a request to a server-run network, must find nothing there, never a prototype or a
// built-in's statics: every action that takes one, with each such name in each usual arg, alone and next to the args
// that get an action that far (a kind, a quoted price), leaves the page's built-ins as they were, spends nothing on
// them, and writes no entry under that name anywhere in the game (S.popTiers.at.toString).
const test = require('node:test');
const assert = require('node:assert/strict');
const { load } = require('./harness');
const BAD = ['__proto__', 'constructor', 'prototype', 'toString', 'hasOwnProperty', 'valueOf'];
// The other args an action may need before it looks the name up: ptSave a kind, ptApply a kind and a price.
const WITH = { k: 'micro', cost: 0 };
const ARGS = ['city', 'id', 'net', 'k', 'c', 'v', 'a', 'b', 'to', 'from', 'link', 's'];
test('no action reaches a built-in through an arg that names one', (t) => {
// The development page: API_CMD is every action an agent may send (the MCP facade), the sent ones of a server's page.
const { ev, errors, dom } = load({ agent: true });
t.after(() => dom.window.close());
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e12;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;");
for (const c of ['fra', 'ams', 'lon', 'par']) ev(`ACT.buildPop({city:'${c}'})`);
ev("ACT.launchBB({city:'fra'});closeModal();UI.confirm=null;compute();");
// What the built-ins hold now: anything an action adds to them is found by name.
ev(`window.__fp=()=>{const o={};for(const [n,x] of [['Object',Object],['Object.prototype',Object.prototype],['Array',Array],['Array.prototype',Array.prototype],['Function.prototype',Function.prototype],['String.prototype',String.prototype]])o[n]=Object.getOwnPropertyNames(x).sort().join(',');
const e=[];for(const k in {})e.push(k);for(const k in [])e.push('[]'+k);o.enum=e.join(',');return o;};window.__fp0=__fp();
window.__clean=()=>{for(const [n,x] of [['Object',Object],['Object.prototype',Object.prototype],['Array',Array],['Array.prototype',Array.prototype],['Function.prototype',Function.prototype],['String.prototype',String.prototype]]){const had=new Set(__fp0[n].split(','));for(const k of Object.getOwnPropertyNames(x))if(!had.has(k))delete x[k];}};
window.__junk=(v)=>{const out=[],walk=(o,p,d)=>{if(!o||typeof o!=='object'||d>4)return;if(Object.prototype.hasOwnProperty.call(o,v)){out.push(p+'.'+v);delete o[v];}for(const k of Object.keys(o))walk(o[k],p+'.'+k,d+1);};walk(S,'S',0);return out;};`);
const acts = JSON.parse(ev('JSON.stringify(Object.keys(API_CMD).filter(k=>typeof ACT[k]==="function"&&!/^pz[A-Z]/.test(k)))'));
const hits = [];
for (const act of acts) {
for (const name of ARGS) {
for (const v of BAD) for (const extra of [{}, WITH]) {
const args = { ...extra, [name]: v };
const r = JSON.parse(ev(`(()=>{const c0=S.cash;let err=null;try{ACT[${JSON.stringify(act)}](${JSON.stringify(args)});}catch(e){err=String(e&&e.message||e);}
try{closeModal();}catch(e){}UI.confirm=null;const f=__fp(),d=Object.keys(f).filter(k=>f[k]!==__fp0[k]);if(d.length)__clean();return JSON.stringify({d,spent:c0-S.cash,err,junk:__junk(${JSON.stringify(v)})});})()`));
if (r.d.length) hits.push(`${act}(${JSON.stringify(args)}) changed ${r.d.join(', ')}${r.spent > 0 ? ` and spent ${r.spent}` : ''}`);
if (r.junk.length) hits.push(`${act}(${JSON.stringify(args)}) wrote ${r.junk.join(', ')}`);
}
}
}
t.diagnostic(`${acts.length} actions × ${ARGS.length} args × ${BAD.length} names × 2`);
assert.deepEqual(hits, []);
assert.deepEqual(errors, []);
});