Files
NODEDC_MISSION_CORE/apps/control-station/test/simulationRunConfiguration.test.mjs
T
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

44 lines
2.8 KiB
JavaScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { test } from 'node:test';
import ts from 'typescript';
const source=ts.transpileModule(readFileSync(new URL('../src/core/simulation/runConfiguration.ts',import.meta.url),'utf8'),
{compilerOptions:{module:ts.ModuleKind.ESNext}}).outputText;
const {parseSavedSelection,currentSelection,runDurationSeconds,selectionStorageKey}=
await import(`data:text/javascript;base64,${Buffer.from(source).toString('base64')}`);
const selection={schema_version:'missioncore.observatory-ai-composition/v1',selections:[
{group:'segmentation',module_id:'outdoor-provider',module_sha256:'a'.repeat(64),parameters:{}},
{group:'policy',module_id:'mission',module_sha256:'b'.repeat(64),parameters:{environment:'park'}},
]};
const installed={selection:{...selection,selections:[]},catalog:{groups:[
{group:'segmentation',modules:[{moduleId:'outdoor-provider',moduleSha256:'c'.repeat(64),defaults:{}}]},
{group:'policy',modules:[{moduleId:'mission',moduleSha256:'d'.repeat(64),defaults:{environment:'natural'}}]},
]}};
test('stored per-location intent survives JSON; malformed, duplicate or foreign groups are rejected',()=>{
assert.deepEqual(parseSavedSelection(JSON.stringify(selection)),selection);
for(const value of [null,'broken',JSON.stringify({...selection,selections:[...selection.selections,selection.selections[0]]}),
JSON.stringify({...selection,selections:[{...selection.selections[0],group:'source'}]}),
JSON.stringify({...selection,selections:[{...selection.selections[0],parameters:[]} ]})]) {
assert.equal(parseSavedSelection(value),undefined);
}
assert.notEqual(selectionStorageKey('riverside','tracked'),selectionStorageKey('forest','tracked'));
assert.notEqual(selectionStorageKey('riverside','tracked'),selectionStorageKey('riverside','wheeled'));
});
test('alternative provider is rebound from full registry and park permissions survive an update',()=>{
const fresh=currentSelection(selection,installed);
assert.equal(fresh.selections[0].module_sha256,'c'.repeat(64));
assert.equal(fresh.selections[1].parameters.environment,'park');
assert.equal(selection.selections[0].module_sha256,'a'.repeat(64));
assert.throws(()=>currentSelection(selection,{...installed,catalog:{groups:[]}}),/недоступен/);
});
test('310 m at 0.15 m/s is not cut off by the old 30-minute ceiling; budgets stay bounded',()=>{
assert.ok(runDurationSeconds(310.34,.15)>310.34/.15+120);
assert.ok(runDurationSeconds(310.34,.15)>1800);
assert.equal(runDurationSeconds(3.4,.15),1800);
assert.equal(runDurationSeconds(100000,.01),7200);
for(const speed of [0,-1,NaN,Infinity])assert.equal(runDurationSeconds(310,speed),1800);
for(const length of [undefined,NaN,-1,Infinity])assert.equal(runDurationSeconds(length,.15),1800);
});