The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {blank, measured, revised, syntheticCSV, kinds} from './fixtures.mjs';
import {clone, validateProject, validateTransition, canonical, digest, event} from '../template/studio/project.mjs';
import {generatePlan, approveProtocol, appendPhase} from '../template/studio/design.mjs';
import {parseCSV, prepareImport, commitImport, recordMeasurement, verifySources, csv, numeric} from '../template/studio/measurements.mjs';
import {fitProject, plannedAnalysis, predict, compare, predictionSnapshot, confirmationResults} from '../template/studio/analysis.mjs';
import {kitFiles, chartSVG, reportHTML} from '../template/studio/formats.mjs';
test('complete factorial repetitions and blocks are balanced and independently randomized', async () => {
const p = await blank('canopy'); assert.equal(p.runs.length, 24);
for (const block of p.design.blocks) {const counts = new Map(); for (const r of p.runs.filter(r => r.block === block)) counts.set(canonical(r.settings), (counts.get(canonical(r.settings)) ?? 0) + 1); assert.equal(counts.size, 6); assert.ok([...counts.values()].every(x => x === 2));}
assert.deepEqual(generatePlan(p).runs, p.runs); const q = clone(p); q.design.seed = 'another'; assert.notDeepEqual(generatePlan(q).runs, p.runs);
});
test('midpoint controls bracket and span the randomized treatments', async () => {const p = await blank(); const controls = p.runs.filter(r => r.kind === 'control'); assert.deepEqual(controls.map(r => r.order), [1, 8, 15]); assert.ok(controls.every(r => r.settings.steep === 12 && r.settings.dose === 75));});
test('oversized factorials and malformed protocols fail before generating a run sheet', async () => {const p = await blank(); p.design.replicates = 20; p.design.blocks = Array.from({length: 8}, (_, i) => 'b' + i); p.runs = []; p.phases = []; assert.throws(() => generatePlan(p), /512/); p.design.controls = 1; assert.throws(() => validateProject(p), /control/);});
test('CSV reader preserves quoted commas, newlines, BOM and exact original line references', () => {const data = parseCSV('\uFEFFid,value,note\r\na,2,"a comma, then\na line"\r\nb,3,"a ""quote"""\r\n'); assert.equal(data.rows[0].values.note, 'a comma, then\na line'); assert.equal(data.rows[1].row, 4); assert.equal(data.rows[1].values.note, 'a "quote"'); assert.throws(() => parseCSV('a,b\n1,"bad'), /quoted/);});
test('measurement numbers do not silently coerce blanks, Infinity, thousands separators or units', () => {for (const x of ['', 'NaN', 'Infinity', '1,000', '12 mm', '0x10']) assert.throws(() => numeric(x)); assert.equal(numeric('-2.5e2'), -250);});
test('imports retain raw bytes and hashes, and validate all rows before applying anything', async () => {
const p = await blank(), bytes = syntheticCSV(p), prepared = await prepareImport(p, bytes, {name: 'synthetic.csv', mapping: {runId: 'run_id', response: 'response'}, unit: '%'}); const q = commitImport(p, prepared);
assert.equal(q.measurements.length, 15); assert.equal(q.sources[0].sha256, await digest(bytes)); assert.deepEqual(await verifySources(q), q); validateTransition(p, q);
for (const text of ['run_id,response\nr0001,1\nr0001,2\n', 'run_id,response\nunknown,1\n', 'run_id,response,steep\nr0001,1,99\n']) await assert.rejects(() => prepareImport(p, new TextEncoder().encode(text), {name: 'invalid.csv', mapping: {runId: 'run_id', response: 'response'}, unit: '%'}));
await assert.rejects(() => prepareImport(p, bytes, {name: 'bad-unit.csv', mapping: {runId: 'run_id', response: 'response'}, unit: 'g/L'}), /unit|Confirm/);
const tampered = clone(q); tampered.sources[0].sha256 = '0'.repeat(64); await assert.rejects(() => verifySources(tampered), /hash mismatch/); assert.equal(p.measurements.length, 0);
});
test('blank responses stay pending and a stale import cannot overwrite a direct entry', async () => {const p = await blank(), bytes = new TextEncoder().encode('run_id,response\nr0001,12\nr0002,\n'); const prepared = await prepareImport(p, bytes, {name: 'partial.csv', mapping: {runId: 'run_id', response: 'response'}, unit: '%'}); assert.equal(prepared.pending, 1); const q = recordMeasurement(p, 'r0001', {value: 10, reason: 'Direct observation'}); assert.throws(() => commitImport(q, prepared), /already measured/);});
test('collected and approved protocols cannot be reshuffled or changed by a source save', async () => {const p = await measured(); assert.throws(() => generatePlan(p), /reshuffled/); const q = clone(p); q.runs[0].settings.steep = 8; assert.throws(() => validateTransition(p, q), /existing run/); q.runs = clone(p.runs); q.protocol.unit = 'different'; assert.throws(() => validateTransition(p, q), /locked/);});
test('corrections and exclusions preserve origin and require the actual before/after log', async () => {const p = await measured(), m = p.measurements[0]; const q = recordMeasurement(p, m.runId, {value: m.value + .1, note: 'corrected transcription', reason: 'Checked the original notebook'}); validateTransition(p, q); assert.equal(q.measurements[0].origin.value, m.value); const bad = clone(q); bad.audit.pop(); assert.throws(() => validateProject(bad), /logged/); assert.throws(() => validateTransition(p, bad), /logged/); await verifySources(q);});
test('two-level corners and common centers cannot identify separate squared effects', async () => {const p = await measured(); p.model.terms.push('steep^2', 'dose^2'); assert.equal(plannedAnalysis(p).rank, 5); const fit = fitProject(p); assert.equal(fit.ok, false); assert.match(fit.issue, /identify 5 of 6/);});
test('too few repetitions withhold residual uncertainty rather than returning an exact-looking fit', async () => {let p = await blank(); p.design.controls = 0; p.design.replicates = 1; p = generatePlan(p); p = commitImport(p, await prepareImport(p, syntheticCSV(p), {name: 'saturated.csv', mapping: {runId: 'run_id', response: 'response'}, unit: '%'})); assert.equal(fitProject(p).ok, false); assert.match(fitProject(p).issue, /repetitions/);});
test('zero residual variation withholds intervals and confirmation planning', async () => {let p = await blank(); const bytes = new TextEncoder().encode(csv([['id','value'], ...p.runs.map(r => [r.id, 10+r.settings.steep])])); p = commitImport(p, await prepareImport(p, bytes, {name:'exact.csv',mapping:{runId:'id',response:'value'},unit:'%'})); const fit = fitProject(p); assert.equal(fit.inferential,false); assert.equal(predict(p,fit,{steep:12,dose:75},p.design.blocks[0]).meanCI,null); await assert.rejects(()=>predictionSnapshot(p,fit,[{settings:{steep:12,dose:75},block:p.design.blocks[0]}]),/uncertainty/);});
test('predictions respect declared bounds, and shared-fit differences include covariance', async () => {const p=await measured(),f=fitProject(p),point={settings:{steep:12,dose:75},block:p.design.blocks[0]},c=compare(p,f,point,point); assert.equal(c.difference,0);assert.equal(c.se,0);assert.deepEqual(c.ci,[0,0]);const pred=predict(p,f,point.settings,point.block);assert.ok(pred.predictionCI[1]-pred.predictionCI[0]>pred.meanCI[1]-pred.meanCI[0]);assert.throws(()=>predict(p,f,{steep:20,dose:75},point.block),/range/);});
test('fresh confirmation observations cannot improve the fit they are evaluating', async () => {const before=await measured(),after=await revised(before,'coffee'); validateTransition(before,after); const a=fitProject(before),b=fitProject(after); assert.deepEqual(a.beta,b.beta);assert.equal(a.n,b.n);assert.equal(b.confirmation,6);assert.deepEqual(after.runs.slice(0,before.runs.length),before.runs);assert.deepEqual(after.sources[0],before.sources[0]);const results=confirmationResults(after);assert.equal(results.length,2);assert.ok(results.every(x=>x.n===3&&x.ci));assert.equal(after.phases[1].snapshot.matrix.y.length,a.n);});
test('an extension can identify missing curvature without changing previously collected runs', async () => {let p=await measured();p.model.terms.push('steep^2','dose^2');const before=clone(p);p=appendPhase(p,{points:[{settings:{steep:12,dose:60},block:p.design.blocks[0]},{settings:{steep:8,dose:75},block:p.design.blocks[0]}],repeats:2,label:'Resolve curvature',reason:'Add separate axial settings',seed:'axes',kind:'extension'});const runs=p.runs.filter(r=>r.phase!=='initial');p=commitImport(p,await prepareImport(p,syntheticCSV(p,'coffee',runs),{name:'axes.csv',mapping:{runId:'run_id',response:'response'},unit:'%'}));validateTransition(before,p);assert.equal(fitProject(p).ok,true);assert.equal(fitProject(p).rank,6);});
test('all three authored experiments fit reproducibly and keep their approved source through revision', async () => {for(const kind of kinds){const p=await measured(kind),q=await revised(p,kind);validateTransition(p,q);await verifySources(q);const fit=fitProject(q);assert.equal(fit.ok,true,kind);assert.equal(canonical(fit),canonical(fitProject(q)));assert.ok(fit.coefficients.every(c=>Number.isFinite(c.value)));assert.deepEqual(q.factors,p.factors);assert.deepEqual(q.protocol,p.protocol);assert.deepEqual(q.runs.slice(0,p.runs.length),p.runs);assert.deepEqual(q.sources[0],p.sources[0]);}});
test('excluded evidence remains exportable beside the all-recorded sensitivity fit', async () => {const before=await measured('canopy'),p=await revised(before,'canopy');assert.equal(fitProject(p).n,23);assert.equal(fitProject(p,{includeExcluded:true}).n,24);const files=kitFiles(p,'<html/>',{reproduce:'',requirements:'',licenses:'',license:''});assert.ok(files['sensitivity-all-recorded.json']);assert.ok(files['sources/'+p.sources[0].id+'.csv'] instanceof Uint8Array);assert.match(files['audit.json'],/failed instrument/);assert.match(files['report.html'],/synthetic/i);});
test('authored text is escaped in reports and chart labels', async () => {const p=await measured();p.title='<script>alert(1)</script>';p.question='<img src=x onerror=alert(1)>';const html=reportHTML(p);assert.ok(!html.includes(p.title));assert.match(html,/<script>/);p.response.name='<bad>';assert.ok(!chartSVG(p,fitProject(p)).includes('<bad>'));});