harness-everything 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.github/workflows/release.yml +16 -5
  4. package/CHANGELOG.md +25 -0
  5. package/ci/fixtures/system-one-colab-fit-layer-sitecustomize.py +72 -0
  6. package/ci/mechanism-2x-release-automation.test.js +17 -0
  7. package/ci/mechanism-system-one-colab.test.js +83 -5
  8. package/ci/mechanism-system-one-contract.test.js +30 -0
  9. package/ci/mechanism-system-one-curves.test.js +85 -0
  10. package/ci/mechanism-system-one-cycle.test.js +344 -34
  11. package/ci/mechanism-system-one-install.test.js +47 -0
  12. package/ci/mechanism-system-one-provider.test.js +2 -0
  13. package/ci/mechanism-system-one-resident.test.js +69 -0
  14. package/ci/system-one-adapter-test.py +86 -0
  15. package/ci/system-one-fit-layer-test.py +371 -0
  16. package/ci/system-one-layer-test.py +122 -0
  17. package/harness-everything/SKILL.md +1 -1
  18. package/harness-everything/scripts/system-one/cua_adapter.py +36 -1
  19. package/harness-everything/scripts/system-one/install.js +10 -0
  20. package/harness-everything/scripts/system-one/layer.py +178 -0
  21. package/harness-everything/scripts/system-one/manifest.js +8 -1
  22. package/harness-everything/scripts/system-one/provider.js +12 -2
  23. package/opencode-plugin/plugin.json +1 -1
  24. package/package.json +1 -1
  25. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  26. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  27. package/plugins/harness-everything/plugin.json +1 -1
  28. package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
  29. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +36 -1
  30. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +10 -0
  31. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/layer.py +178 -0
  32. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +8 -1
  33. package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +12 -2
  34. package/sbom.cdx.json +7 -7
  35. package/scripts/system-one-colab.js +6 -4
  36. package/scripts/system-one-curves.js +52 -8
  37. package/scripts/system-one-cycle/evaluate.js +56 -5
  38. package/scripts/system-one-cycle/package.js +61 -3
  39. package/scripts/system-one-cycle/score.py +23 -2
  40. package/scripts/system-one-cycle/train.js +212 -20
  41. package/scripts/system-one-fit-layer.py +369 -0
@@ -9,8 +9,10 @@ const { test } = require('node:test');
9
9
  const { buildDataset } = require('../scripts/system-one-cycle/build');
10
10
  const { collect } = require('../scripts/system-one-cycle/collect');
11
11
  const { judgeRows } = require('../scripts/system-one-cycle/judge');
12
- const { runGuarded, processTreeRssMb } = require('../scripts/system-one-cycle/train');
13
- const { buildVersion, trainerCatalogs } = require('../scripts/system-one-cycle/package');
12
+ const { runGuarded, processTreeRssMb, trainCycle, fitLayerStage, validateFitStage, TASKS } = require('../scripts/system-one-cycle/train');
13
+ const { buildVersion, trainerCatalogs, digest } = require('../scripts/system-one-cycle/package');
14
+ const { evaluateCycle, verifyLayerPair } = require('../scripts/system-one-cycle/evaluate');
15
+ const { calibrate } = require('../scripts/system-one-calibrate');
14
16
  const install = require('../harness-everything/scripts/system-one/install');
15
17
  const provider = require('../harness-everything/scripts/system-one/provider');
16
18
  const router = require('../harness-everything/scripts/system-one/router');
@@ -93,22 +95,41 @@ function seed446Candidate(dataDir, version, quality) {
93
95
  for (const task of ['validity', 'intent', 'tier']) {
94
96
  const stageDir = path.join(runDir, task);
95
97
  fs.mkdirSync(stageDir, { recursive: true, mode: 0o700 });
96
- fs.writeFileSync(path.join(stageDir, 'harness-routing-v1.safetensors'), `synthetic-${version}-${task}`);
98
+ const checkpoint = path.join(stageDir, 'harness-routing-v1.safetensors');
99
+ fs.writeFileSync(checkpoint, `synthetic-${version}-${task}`);
97
100
  fs.writeFileSync(path.join(stageDir, 'harness-routing-v1.json'), '{}\n');
98
- fs.writeFileSync(path.join(stageDir, 'train-report.json'), '{}\n');
99
- fs.writeFileSync(path.join(stageDir, 'resource-guard.json'), JSON.stringify({ exitCode: 0, killedForLimit: false, monitorFailed: false }));
100
- fs.writeFileSync(path.join(stageDir, 'calibration.json'), JSON.stringify({
101
- thresholds: Object.fromEntries(cycleTrainerCatalogs[task].map(id => [id, 0.5])),
102
- }));
101
+ const bundleDir = path.join(dataDir, 'training', task === 'validity' ? 'v1-validity' : 'v1');
102
+ const labelFile = task === 'intent' ? 'labels-intent.jsonl' : 'labels.jsonl';
103
+ const dataHash = file => require('node:crypto').createHash('sha256').update(fs.readFileSync(file)).digest('hex');
104
+ const report = { schemaVersion: 1, config: {}, counts: { train: 1, validation: 1, test: 0 }, bestEpoch: 1,
105
+ history: [], datasets: { 'prompts.jsonl': dataHash(path.join(bundleDir, 'prompts.jsonl')),
106
+ [labelFile]: dataHash(path.join(bundleDir, labelFile)) }, seed: 1, task, target: 'label',
107
+ catalog: cycleTrainerCatalogs[task], device: 'cpu', torch: 'fixture' };
108
+ fs.writeFileSync(path.join(stageDir, 'train-report.json'), JSON.stringify(report));
109
+ fs.writeFileSync(path.join(stageDir, 'resource-guard.json'), JSON.stringify({ schemaVersion: 1, exitCode: 0,
110
+ killedForLimit: false, monitorFailed: false, peakRssMb: 1, maxRssMb: 64, threads: 1 }));
111
+ const calibration = { thresholds: Object.fromEntries(cycleTrainerCatalogs[task].map(id => [id, 0.5])) };
112
+ fs.writeFileSync(path.join(stageDir, 'calibration.json'), JSON.stringify(calibration));
103
113
  const gold = task === 'validity' ? 'actionable' : task === 'intent' ? 'fix' : 'tier2';
104
114
  const scores = Object.fromEntries(cycleTrainerCatalogs[task].map(id => [id,
105
115
  task === 'validity' ? (id === 'invalid' ? 1 - quality : quality) : (id === gold ? quality : 0.01)]));
106
116
  writeJsonl(path.join(stageDir, 'val-scores.jsonl'), [{ id: `validation-${task}`, gold, scores }]);
117
+ const holdout = path.join(root, 'benchmarks', 'fixtures', task === 'intent'
118
+ ? 'system-one-intent-holdout.json' : 'system-one-holdout.json');
119
+ const outcome = { schemaVersion: 1, task, outcome: 'keep-base', oofScoreSpace: null,
120
+ datasetSha256: report.datasets, trainerReportSha256: dataHash(path.join(stageDir, 'train-report.json')),
121
+ holdoutSha256: dataHash(holdout), checkpointSha256: dataHash(checkpoint),
122
+ checkpointConfigSha256: dataHash(path.join(stageDir, 'harness-routing-v1.json')),
123
+ validationIds: [`validation-${task}`], calibrationInput: 'val-scores.jsonl',
124
+ calibrationInputSha256: dataHash(path.join(stageDir, 'val-scores.jsonl')),
125
+ calibrationSha256: dataHash(path.join(stageDir, 'calibration.json')) };
126
+ fs.writeFileSync(path.join(stageDir, 'layer-outcome.json'), JSON.stringify(outcome));
107
127
  }
108
128
  }
109
129
 
110
130
  function setup446Cycle(t, dataDir, versions, { all = false } = {}) {
111
131
  const fixture = syntheticCycle(dataDir);
132
+ buildDataset({ dataDir, holdoutFiles: [fixture.holdout] });
112
133
  if (all) {
113
134
  const steps = {
114
135
  collect: ['training/observed/prompts-observed.jsonl', 'training/observed/labels-observed.jsonl'],
@@ -544,7 +565,31 @@ test('resource guard kills an over-limit child and records peak RSS', async () =
544
565
  assert.equal(result.monitorFailed, false);
545
566
  });
546
567
 
547
- test('package writes the contract B manifest and carries evaluation into the private version directory', t => {
568
+ test('trainCycle retries an artifact set missing its guard and fails on a malformed trainer report', async t => {
569
+ const dir = private446Root(t);
570
+ const stage = path.join(dir, 'training', 'runs', 'missing-guard', 'validity');
571
+ fs.mkdirSync(stage, { recursive: true });
572
+ for (const file of ['harness-routing-v1.safetensors', 'harness-routing-v1.json', 'val-scores.jsonl'])
573
+ fs.writeFileSync(path.join(stage, file), 'stale artifact\n');
574
+ fs.writeFileSync(path.join(stage, 'train-report.json'), '{"task":"validity"}\n');
575
+ const tasks = [];
576
+ await assert.rejects(trainCycle({ dataDir: dir, version: 'missing-guard', run: async (_bin, args) => {
577
+ tasks.push(args[args.indexOf('--task') + 1]);
578
+ return { exitCode: 0, peakRssMb: 1, maxRssMb: 64, threads: 1, killedForLimit: false, monitorFailed: false };
579
+ } }), /missing or invalid trainer report/);
580
+ assert.deepEqual(tasks, ['validity']);
581
+ const guard = JSON.parse(fs.readFileSync(path.join(stage, 'resource-guard.json'), 'utf8'));
582
+ assert.equal(guard.exitCode, 0);
583
+ assert.equal(fs.existsSync(path.join(dir, 'cycle-state.json')), false);
584
+
585
+ const failedDir = private446Root(t);
586
+ await assert.rejects(trainCycle({ dataDir: failedDir, version: 'failed-guard', run: async () => ({
587
+ exitCode: 0, peakRssMb: 1, maxRssMb: 64, threads: 1, killedForLimit: false, monitorFailed: true,
588
+ }) }), /RSS monitoring failed/);
589
+ assert.equal(fs.existsSync(path.join(failedDir, 'cycle-state.json')), false);
590
+ });
591
+
592
+ test('package rejects new-cycle inputs without a validated fit outcome', t => {
548
593
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-package-'));
549
594
  try {
550
595
  const version = 'synthetic-v1';
@@ -552,38 +597,41 @@ test('package writes the contract B manifest and carries evaluation into the pri
552
597
  const catalogs = trainerCatalogs();
553
598
  const thresholds = Object.fromEntries(Object.entries(catalogs).map(([task, options]) => [task,
554
599
  Object.fromEntries(options.map(id => [id, id === 'unclassified' ? null : 0.5]))]));
555
- for (const [task, values] of Object.entries(thresholds)) {
556
- const stage = path.join(runs, task);
557
- fs.mkdirSync(stage, { recursive: true });
558
- fs.writeFileSync(path.join(stage, 'harness-routing-v1.safetensors'), `${task}-weights`);
559
- fs.writeFileSync(path.join(stage, 'harness-routing-v1.json'), JSON.stringify({ context_tokens: 1024 }));
560
- fs.writeFileSync(path.join(stage, 'calibration.json'), JSON.stringify({ thresholds: values }));
561
- }
600
+ writePackageRuns(dir, version, thresholds);
601
+ fs.rmSync(path.join(runs, 'validity', 'layer-outcome.json'));
562
602
  const candidate = path.join(dir, 'training', 'candidates', version);
563
- buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir: candidate });
564
- fs.mkdirSync(path.join(candidate, 'evaluation'), { recursive: true });
565
- fs.writeFileSync(path.join(candidate, 'evaluation', 'curves.json'), '{}\n');
566
- fs.writeFileSync(path.join(candidate, 'evaluation', 'trend.json'), '{}\n');
567
-
603
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir: candidate }), /fit|report|guard|outcome/i);
604
+ fs.mkdirSync(candidate, { recursive: true });
605
+ fs.writeFileSync(path.join(candidate, 'manifest.json'), JSON.stringify({
606
+ schemaVersion: 1, version, createdAt: '2026-11-17T00:00:00.000Z', evaluation: null,
607
+ stages: Object.fromEntries(Object.entries(catalogs).map(([task, options]) => [task, {
608
+ weights: `${task}.safetensors`, config: `${task}.json`, sha256: digest(path.join(runs, task, 'harness-routing-v1.safetensors')),
609
+ options, thresholds: Object.fromEntries(options.map(id => [id, 0.5])),
610
+ }])),
611
+ }));
612
+ for (const [task, options] of Object.entries(catalogs)) {
613
+ fs.copyFileSync(path.join(runs, task, 'harness-routing-v1.safetensors'), path.join(candidate, `${task}.safetensors`));
614
+ fs.copyFileSync(path.join(runs, task, 'harness-routing-v1.json'), path.join(candidate, `${task}.json`));
615
+ }
568
616
  const output = path.join(dir, 'training', 'versions', version);
569
- buildVersion({ dataDir: dir, version, sourceDir: candidate, versionDir: output });
570
- const manifest = JSON.parse(fs.readFileSync(path.join(output, 'manifest.json'), 'utf8'));
571
-
572
- assert.deepEqual(Object.keys(manifest).sort(), ['createdAt', 'evaluation', 'schemaVersion', 'stages', 'version']);
573
- assert.equal(manifest.schemaVersion, 1);
574
- assert.equal(manifest.version, version);
617
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: candidate, versionDir: output }), /fit|report|outcome|evidence/i);
618
+
619
+ const validCandidate = path.join(dir, 'training', 'candidates', `${version}-valid`);
620
+ const validRuns = writePackageRuns(dir, `${version}-valid`, thresholds);
621
+ buildVersion({ dataDir: dir, version: `${version}-valid`, sourceDir: validRuns, versionDir: validCandidate });
622
+ assert.throws(() => verifyLayerPair(validCandidate, validRuns, { validity: null, intent: null, tier: null }), /fit outcome is missing/);
623
+ fs.mkdirSync(path.join(validCandidate, 'evaluation'), { recursive: true });
624
+ fs.writeFileSync(path.join(validCandidate, 'evaluation', 'curves.json'), '{}\n');
625
+ fs.writeFileSync(path.join(validCandidate, 'evaluation', 'trend.json'), '{}\n');
626
+ const validOutput = path.join(dir, 'training', 'versions', `${version}-valid`);
627
+ buildVersion({ dataDir: dir, version: `${version}-valid`, sourceDir: validCandidate, versionDir: validOutput });
628
+ const manifest = JSON.parse(fs.readFileSync(path.join(validOutput, 'manifest.json'), 'utf8'));
575
629
  assert.equal(manifest.evaluation, 'evaluation/curves.json');
576
630
  assert.deepEqual(manifest.stages.validity.options, catalogs.validity);
577
631
  assert.deepEqual(manifest.stages.intent.options, catalogs.intent);
578
- assert.ok(manifest.stages.intent.options.includes('unclassified'));
579
- assert.deepEqual(Object.keys(manifest.stages.intent.thresholds), catalogs.intent);
580
632
  assert.equal(manifest.stages.intent.thresholds.unclassified, 1);
581
- assert.ok(manifest.stages.intent.referenceOnly.includes('unclassified'));
582
633
  assert.deepEqual(manifest.stages.tier.thresholds, thresholds.tier);
583
- assert.deepEqual(Object.keys(manifest.stages.tier.thresholds), catalogs.tier);
584
- assert.match(manifest.stages.intent.sha256, /^[0-9a-f]{64}$/);
585
- assert.equal(fs.existsSync(path.join(output, 'evaluation', 'trend.json')), true);
586
- assert.equal('referenceOnly' in manifest.stages.validity, false);
634
+ assert.equal(fs.existsSync(path.join(validOutput, 'evaluation', 'trend.json')), true);
587
635
  } finally {
588
636
  fs.rmSync(dir, { recursive: true, force: true });
589
637
  }
@@ -591,21 +639,279 @@ test('package writes the contract B manifest and carries evaluation into the pri
591
639
 
592
640
  function writePackageRuns(dir, version, calibrationByTask) {
593
641
  const runs = path.join(dir, 'training', 'runs', version);
642
+ const bundleDir = path.join(dir, 'training', 'v1');
643
+ const validityBundle = path.join(dir, 'training', 'v1-validity');
644
+ fs.mkdirSync(bundleDir, { recursive: true });
645
+ fs.mkdirSync(validityBundle, { recursive: true });
646
+ for (const [bundle, file] of [[bundleDir, 'prompts.jsonl'], [bundleDir, 'labels.jsonl'],
647
+ [bundleDir, 'labels-intent.jsonl'], [validityBundle, 'prompts.jsonl'], [validityBundle, 'labels.jsonl']]) {
648
+ if (!fs.existsSync(path.join(bundle, file))) fs.writeFileSync(path.join(bundle, file), `${file}\n`);
649
+ }
594
650
  for (const [task, values] of Object.entries(calibrationByTask)) {
595
651
  const stage = path.join(runs, task);
596
652
  fs.mkdirSync(stage, { recursive: true });
597
653
  fs.writeFileSync(path.join(stage, 'harness-routing-v1.safetensors'), `${task}-weights`);
598
654
  fs.writeFileSync(path.join(stage, 'harness-routing-v1.json'), JSON.stringify({ context_tokens: 1024 }));
599
655
  fs.writeFileSync(path.join(stage, 'calibration.json'), JSON.stringify({ thresholds: values }));
656
+ const sourceDir = task === 'validity' ? validityBundle : bundleDir;
657
+ const report = { schemaVersion: 1, task, target: 'label', catalog: trainerCatalogs()[task],
658
+ counts: { train: 1, validation: 1, test: 0 }, datasets: { 'prompts.jsonl': 'a'.repeat(64),
659
+ [task === 'intent' ? 'labels-intent.jsonl' : 'labels.jsonl']: 'b'.repeat(64) },
660
+ config: { context_tokens: 1024 }, bestEpoch: 1, history: [], device: 'cpu', torch: 'synthetic' };
661
+ report.datasets['prompts.jsonl'] = digest(path.join(sourceDir, 'prompts.jsonl'));
662
+ report.datasets[task === 'intent' ? 'labels-intent.jsonl' : 'labels.jsonl'] =
663
+ digest(path.join(sourceDir, task === 'intent' ? 'labels-intent.jsonl' : 'labels.jsonl'));
664
+ fs.writeFileSync(path.join(stage, 'train-report.json'), JSON.stringify(report));
665
+ fs.writeFileSync(path.join(stage, 'resource-guard.json'), JSON.stringify({ schemaVersion: 1, exitCode: 0,
666
+ killedForLimit: false, monitorFailed: false, peakRssMb: 1, maxRssMb: 64, threads: 1 }));
667
+ fs.writeFileSync(path.join(stage, 'val-scores.jsonl'), JSON.stringify({ id: `validation-${task}`, gold: task === 'validity' ? 'actionable' : task === 'intent' ? 'fix' : 'tier2',
668
+ scores: Object.fromEntries(trainerCatalogs()[task].map(id => [id, 0.5])) }) + '\n');
669
+ const outcome = { schemaVersion: 1, task, outcome: 'keep-base', oofScoreSpace: null, datasetSha256: report.datasets,
670
+ trainerReportSha256: digest(path.join(stage, 'train-report.json')),
671
+ holdoutSha256: digest(path.join(root, 'benchmarks', 'fixtures', task === 'intent' ? 'system-one-intent-holdout.json' : 'system-one-holdout.json')),
672
+ checkpointSha256: digest(path.join(stage, 'harness-routing-v1.safetensors')),
673
+ checkpointConfigSha256: digest(path.join(stage, 'harness-routing-v1.json')),
674
+ validationIds: [`validation-${task}`], calibrationInput: 'val-scores.jsonl',
675
+ calibrationInputSha256: digest(path.join(stage, 'val-scores.jsonl')),
676
+ calibrationSha256: digest(path.join(stage, 'calibration.json')) };
677
+ fs.writeFileSync(path.join(stage, 'layer-outcome.json'), JSON.stringify(outcome));
600
678
  }
601
679
  return runs;
602
680
  }
603
681
 
682
+ test('fit evidence rejects a changed or unbound original checkpoint config', t => {
683
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-config-fit-'));
684
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
685
+ const version = 'config-fit-v1';
686
+ const runs = writePackageRuns(dir, version, trainerThresholds());
687
+ const runDir = path.join(runs, 'tier');
688
+ assert.doesNotThrow(() => validateFitStage({ runDir, task: 'tier', dataDir: dir }));
689
+
690
+ const config = path.join(runDir, 'harness-routing-v1.json');
691
+ fs.appendFileSync(config, ' ');
692
+ const priorPythonForLegacy = process.env.PYTHON;
693
+ process.env.PYTHON = process.execPath;
694
+ try {
695
+ assert.throws(() => fitLayerStage({ runDir, task: 'tier', dataDir: dir }), /system-one-fit-layer\.py failed/,
696
+ 'a stale config must leave the reuse path and attempt a refit');
697
+ } finally {
698
+ if (priorPythonForLegacy === undefined) delete process.env.PYTHON;
699
+ else process.env.PYTHON = priorPythonForLegacy;
700
+ }
701
+ assert.throws(() => validateFitStage({ runDir, task: 'tier', dataDir: dir }), /fit outcome.*stale/i);
702
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: runs,
703
+ versionDir: path.join(dir, 'training', 'versions', `${version}-stale`) }), /checkpoint config|fit outcome/i);
704
+
705
+ const outcomeFile = path.join(runDir, 'layer-outcome.json');
706
+ const outcome = JSON.parse(fs.readFileSync(outcomeFile, 'utf8'));
707
+ delete outcome.checkpointConfigSha256;
708
+ fs.writeFileSync(outcomeFile, JSON.stringify(outcome));
709
+ const priorPython = process.env.PYTHON;
710
+ process.env.PYTHON = process.execPath;
711
+ try {
712
+ assert.throws(() => fitLayerStage({ runDir, task: 'tier', dataDir: dir }), /system-one-fit-layer\.py failed/,
713
+ 'an old outcome without a config binding must leave the reuse path');
714
+ } finally {
715
+ if (priorPython === undefined) delete process.env.PYTHON;
716
+ else process.env.PYTHON = priorPython;
717
+ }
718
+ assert.throws(() => validateFitStage({ runDir, task: 'tier', dataDir: dir }), /fit outcome.*stale/i);
719
+ });
720
+
721
+ test('all-keep-base candidates bind the scorer sidecar and repack the manifest-selected config bytes', t => {
722
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-config-candidate-'));
723
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
724
+ const version = 'config-candidate-v1';
725
+ const runs = writePackageRuns(dir, version, trainerThresholds());
726
+ const candidate = path.join(dir, 'training', 'candidates', version);
727
+ buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir: candidate });
728
+ const outcomes = Object.fromEntries(TASKS.map(task => [task,
729
+ JSON.parse(fs.readFileSync(path.join(runs, task, 'layer-outcome.json'), 'utf8'))]));
730
+ const manifestFile = path.join(candidate, 'manifest.json');
731
+ const manifest = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
732
+ const tierConfig = path.join(candidate, 'tier.json');
733
+ const originalConfig = fs.readFileSync(tierConfig);
734
+ const alternateConfig = path.join(candidate, 'tier-alternate.json');
735
+ fs.writeFileSync(alternateConfig, originalConfig);
736
+ manifest.stages.tier.config = 'tier-alternate.json';
737
+ fs.writeFileSync(manifestFile, JSON.stringify(manifest));
738
+
739
+ fs.appendFileSync(tierConfig, ' changed');
740
+ const evaluationDir = path.join(candidate, 'evaluation');
741
+ fs.mkdirSync(evaluationDir, { recursive: true });
742
+ fs.writeFileSync(path.join(evaluationDir, 'curves.json'), '{}\n');
743
+ fs.writeFileSync(path.join(evaluationDir, 'trend.json'), '{}\n');
744
+ const history = path.join(dir, 'history.jsonl');
745
+ fs.writeFileSync(history, '');
746
+ assert.throws(() => evaluateCycle({ dataDir: dir, version, history }), /manifest paths|checkpoint config/i,
747
+ 'the resume flow validates the scorer paths before resuming curves');
748
+ assert.throws(() => verifyLayerPair(candidate, runs, outcomes), /config|scorer|manifest/i,
749
+ 'resume must reject when the scorer sidecar changes even if stage.config points to an intact alternate');
750
+ fs.appendFileSync(alternateConfig, ' changed');
751
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: candidate,
752
+ versionDir: path.join(dir, 'training', 'versions', `${version}-selected-mismatch`) }), /checkpoint config|fit outcome/i,
753
+ 'packaging validates the exact config selected by the candidate manifest');
754
+ fs.writeFileSync(alternateConfig, originalConfig);
755
+ const repack = path.join(dir, 'training', 'versions', `${version}-repack`);
756
+ buildVersion({ dataDir: dir, version, sourceDir: candidate, versionDir: repack });
757
+ assert.deepEqual(fs.readFileSync(path.join(repack, 'tier.json')), originalConfig,
758
+ 'repackaging preserves the exact bytes selected by stage.config');
759
+
760
+ fs.writeFileSync(tierConfig, originalConfig);
761
+ manifest.stages.tier.config = 'tier.json';
762
+ fs.writeFileSync(manifestFile, JSON.stringify(manifest));
763
+ fs.appendFileSync(tierConfig, ' changed');
764
+ assert.throws(() => verifyLayerPair(candidate, runs, outcomes), /config|scorer|manifest/i);
765
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: candidate,
766
+ versionDir: path.join(dir, 'training', 'versions', `${version}-canonical-mismatch`) }), /checkpoint config|fit outcome/i);
767
+ });
768
+
604
769
  function trainerThresholds(value = 0.5) {
605
770
  return Object.fromEntries(Object.entries(trainerCatalogs()).map(([task, options]) => [task,
606
771
  Object.fromEntries(options.map(id => [id, id === 'unclassified' ? null : value]))]));
607
772
  }
608
773
 
774
+ test('calibrator consumes secondary labels from layered OOF rows', () => {
775
+ const result = calibrate([{ id: 'intent-oof', gold: 'primary', secondary: ['secondary'],
776
+ scores: { primary: 0.1, secondary: 0.9 } }], {
777
+ task: 'intent', catalogIds: ['primary', 'secondary'], minPrecision: 1,
778
+ });
779
+ assert.equal(result.options.secondary.feasible, true);
780
+ assert.equal(result.options.secondary.threshold, 0.9);
781
+ });
782
+
783
+ test('package preserves a verified layer and its thresholds through both buildVersion branches', t => {
784
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-package-layer-'));
785
+ try {
786
+ const version = 'synthetic-layer-v1';
787
+ const thresholds = trainerThresholds();
788
+ const runs = writePackageRuns(dir, version, thresholds);
789
+ const task = 'tier';
790
+ const stage = path.join(runs, task);
791
+ const layer = { schemaVersion: 1, kind: 'echl-h', stage: task, options: trainerCatalogs()[task],
792
+ temperature: 1, bias: null, alpha: 0, k: 15, ngrams: [3, 4, 5], maxChars: 2000, index: [],
793
+ fit: { candidate: 'H-temp', heldOutRows: 2, nll: 0.2, baseNll: 0.3, oof: true } };
794
+ const layerFile = path.join(stage, 'layer.json');
795
+ fs.writeFileSync(layerFile, `${JSON.stringify(layer)}\n`);
796
+ writeJsonl(path.join(stage, 'val-scores-layered.jsonl'), [
797
+ { id: 'validation-tier', gold: 'tier1', scores: { tier1: 0.8, tier2: 0.1, tier3: 0.1 } },
798
+ ]);
799
+ fs.writeFileSync(path.join(stage, 'calibration.json'), JSON.stringify({ task, thresholds: thresholds.tier }));
800
+ const outcome = { schemaVersion: 1, task, outcome: 'layer',
801
+ oofScoreSpace: 'h-transform-v2',
802
+ datasetSha256: JSON.parse(fs.readFileSync(path.join(stage, 'train-report.json'), 'utf8')).datasets,
803
+ trainerReportSha256: digest(path.join(stage, 'train-report.json')),
804
+ holdoutSha256: digest(path.join(root, 'benchmarks', 'fixtures', 'system-one-holdout.json')),
805
+ validationIds: ['validation-tier'],
806
+ checkpointSha256: digest(path.join(stage, 'harness-routing-v1.safetensors')),
807
+ checkpointConfigSha256: digest(path.join(stage, 'harness-routing-v1.json')),
808
+ layerSha256: digest(layerFile), calibrationInput: 'val-scores-layered.jsonl',
809
+ calibrationInputSha256: digest(path.join(stage, 'val-scores-layered.jsonl')),
810
+ calibrationSha256: digest(path.join(stage, 'calibration.json')) };
811
+ fs.writeFileSync(path.join(stage, 'layer-outcome.json'), JSON.stringify(outcome));
812
+
813
+ const candidate = path.join(dir, 'training', 'candidates', version);
814
+ buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir: candidate });
815
+ const firstManifest = JSON.parse(fs.readFileSync(path.join(candidate, 'manifest.json'), 'utf8'));
816
+ const firstLayer = path.join(candidate, firstManifest.stages.tier.layer);
817
+ assert.equal(firstManifest.stages.tier.layer, 'tier.layer.json');
818
+ assert.equal(firstManifest.stages.tier.layerSha256, digest(layerFile));
819
+ assert.deepEqual(fs.readFileSync(firstLayer), fs.readFileSync(layerFile));
820
+ assert.deepEqual(firstManifest.stages.tier.thresholds, thresholds.tier);
821
+ const outcomes = Object.fromEntries(['validity', 'intent', 'tier'].map(name => [name,
822
+ JSON.parse(fs.readFileSync(path.join(runs, name, 'layer-outcome.json'), 'utf8'))]));
823
+ verifyLayerPair(candidate, runs, outcomes);
824
+ firstManifest.stages.tier.thresholds.tier1 += 0.01;
825
+ fs.writeFileSync(path.join(candidate, 'manifest.json'), JSON.stringify(firstManifest));
826
+ assert.throws(() => verifyLayerPair(candidate, runs, outcomes), /thresholds do not match/);
827
+ firstManifest.stages.tier.thresholds = { ...thresholds.tier };
828
+ fs.writeFileSync(path.join(candidate, 'manifest.json'), JSON.stringify(firstManifest));
829
+
830
+ const repack = path.join(dir, 'training', 'versions', version);
831
+ buildVersion({ dataDir: dir, version, sourceDir: candidate, versionDir: repack });
832
+ const secondManifest = JSON.parse(fs.readFileSync(path.join(repack, 'manifest.json'), 'utf8'));
833
+ assert.equal(secondManifest.stages.tier.layerSha256, firstManifest.stages.tier.layerSha256);
834
+ assert.equal(secondManifest.stages.tier.layer, 'tier.layer.json');
835
+ assert.deepEqual(fs.readFileSync(path.join(repack, secondManifest.stages.tier.layer)), fs.readFileSync(firstLayer));
836
+ assert.deepEqual(secondManifest.stages.tier.thresholds, firstManifest.stages.tier.thresholds);
837
+
838
+ const savedThresholds = { ...secondManifest.stages.tier.thresholds };
839
+ secondManifest.stages.tier.thresholds.tier1 += 0.01;
840
+ fs.writeFileSync(path.join(repack, 'manifest.json'), JSON.stringify(secondManifest));
841
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: repack,
842
+ versionDir: path.join(dir, 'training', 'versions', `${version}-changed-threshold`) }), /thresholds do not match/);
843
+ secondManifest.stages.tier.thresholds = savedThresholds;
844
+ fs.writeFileSync(path.join(repack, 'manifest.json'), JSON.stringify(secondManifest));
845
+
846
+ const curvesScript = path.join(root, 'scripts/system-one-curves.js');
847
+ const history = path.join(dir, 'history.jsonl');
848
+ const evaluation = path.join(repack, 'evaluation');
849
+ const validationFiles = {};
850
+ const holdoutFiles = {};
851
+ for (const [task, ids] of Object.entries(trainerCatalogs())) {
852
+ const scores = Object.fromEntries(ids.map((id, index) => [id, index === 0 ? 0.8 : 0.1 / Math.max(1, ids.length - 1)]));
853
+ const gold = task === 'validity' ? 'actionable' : ids[0];
854
+ validationFiles[task] = path.join(dir, `${task}-oof.jsonl`);
855
+ holdoutFiles[task] = path.join(dir, `${task}-holdout.jsonl`);
856
+ writeJsonl(validationFiles[task], [{ id: `${task}-val`, gold, scores }]);
857
+ writeJsonl(holdoutFiles[task], [{ id: `${task}-held-out`, gold, scores }]);
858
+ }
859
+ const curveArgs = ['--version', version, '--version-dir', repack];
860
+ for (const task of Object.keys(validationFiles)) {
861
+ curveArgs.push('--val-scores', `${task}=${validationFiles[task]}`,
862
+ '--holdout-scores', `${task}=${holdoutFiles[task]}`);
863
+ }
864
+ curveArgs.push('--history', history, '--out', evaluation);
865
+ const curvesRun = spawnSync(process.execPath, [curvesScript, ...curveArgs], { cwd: root, encoding: 'utf8' });
866
+ assert.equal(curvesRun.status, 0, curvesRun.stderr);
867
+ const curvesFile = path.join(evaluation, 'curves.json');
868
+ const curves = JSON.parse(fs.readFileSync(curvesFile, 'utf8'));
869
+ assert.match(curves.candidateDigest, /^[a-f0-9]{64}$/);
870
+ assert.equal(curves.scoreDigests.validation.tier, digest(validationFiles.tier));
871
+ assert.equal(curves.scoreDigests.holdout.tier, digest(holdoutFiles.tier));
872
+
873
+ const resumeArgs = [curvesScript, '--version', version, '--version-dir', repack,
874
+ '--history', history, '--out', evaluation, '--resume-curves', curvesFile];
875
+ for (const task of Object.keys(validationFiles)) resumeArgs.push('--val-scores', `${task}=${validationFiles[task]}`,
876
+ '--holdout-scores', `${task}=${holdoutFiles[task]}`);
877
+ const beforeHistory = fs.readFileSync(history, 'utf8');
878
+ const stableResume = spawnSync(process.execPath, resumeArgs, { cwd: root, encoding: 'utf8' });
879
+ assert.equal(stableResume.status, 0, stableResume.stderr);
880
+ assert.equal(fs.readFileSync(history, 'utf8'), beforeHistory, 'matching resume must preserve immutable history');
881
+ const originalTierScores = fs.readFileSync(validationFiles.tier);
882
+ writeJsonl(validationFiles.tier, [{ id: 'tier-val', gold: 'tier1', scores: { tier1: 0.7, tier2: 0.2, tier3: 0.1 } }]);
883
+ const changedScoresResume = spawnSync(process.execPath, resumeArgs, { cwd: root, encoding: 'utf8' });
884
+ assert.notEqual(changedScoresResume.status, 0, 'resumed evidence must be bound to its OOF score file');
885
+ assert.equal(fs.readFileSync(history, 'utf8'), beforeHistory, 'rejected score resume must leave history unchanged');
886
+ fs.writeFileSync(validationFiles.tier, originalTierScores);
887
+
888
+ const repackLayer = path.join(repack, secondManifest.stages.tier.layer);
889
+ const changedLayer = JSON.parse(fs.readFileSync(repackLayer, 'utf8'));
890
+ changedLayer.fit.nll += 0.01;
891
+ fs.writeFileSync(repackLayer, `${JSON.stringify(changedLayer)}\n`);
892
+ secondManifest.stages.tier.layerSha256 = digest(repackLayer);
893
+ fs.writeFileSync(path.join(repack, 'manifest.json'), JSON.stringify(secondManifest));
894
+ const resume = spawnSync(process.execPath, resumeArgs, { cwd: root, encoding: 'utf8' });
895
+ assert.notEqual(resume.status, 0, 'resumed evidence must not be reused after the candidate layer changes');
896
+ assert.equal(fs.readFileSync(history, 'utf8'), beforeHistory, 'rejected resume must not mutate immutable history');
897
+
898
+ const outcomeFile = path.join(stage, 'layer-outcome.json');
899
+ const validOutcome = fs.readFileSync(outcomeFile);
900
+ const staleOutcome = JSON.parse(validOutcome.toString('utf8'));
901
+ staleOutcome.calibrationSha256 = '0'.repeat(64);
902
+ fs.writeFileSync(outcomeFile, JSON.stringify(staleOutcome));
903
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: runs,
904
+ versionDir: path.join(dir, 'training', 'versions', 'stale-calibration') }), /fit outcome|calibration|score file is stale/);
905
+ fs.writeFileSync(outcomeFile, validOutcome);
906
+
907
+ fs.writeFileSync(firstLayer, '{"partial":true}\n');
908
+ assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: candidate,
909
+ versionDir: path.join(dir, 'training', 'versions', 'stale-repack') }), /layer hash/);
910
+ } finally {
911
+ fs.rmSync(dir, { recursive: true, force: true });
912
+ }
913
+ });
914
+
609
915
  test('package turns a null calibration threshold into 1 and carries referenceOnly through repackaging', t => {
610
916
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-package-null-'));
611
917
  try {
@@ -670,6 +976,10 @@ test('package still rejects a non-null non-finite threshold', t => {
670
976
  const serialized = JSON.stringify({ thresholds: thresholds.tier });
671
977
  const keyValue = `${JSON.stringify('tier2')}:${thresholds.tier.tier2}`;
672
978
  fs.writeFileSync(calibration, serialized.replace(keyValue, `${JSON.stringify('tier2')}:1e999`));
979
+ const outcomeFile = path.join(runs, 'tier', 'layer-outcome.json');
980
+ const outcome = JSON.parse(fs.readFileSync(outcomeFile, 'utf8'));
981
+ outcome.calibrationSha256 = digest(calibration);
982
+ fs.writeFileSync(outcomeFile, JSON.stringify(outcome));
673
983
  assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: runs,
674
984
  versionDir: path.join(dir, 'training', 'versions', version) }), /finite per-option thresholds/);
675
985
  } finally {
@@ -78,6 +78,53 @@ test('S1-I02 install rejects a tampered stage hash before copying any version',
78
78
  } finally { remove(root, home); }
79
79
  });
80
80
 
81
+ test('install verifies and privately copies a layer while stage hashes keep their legacy meaning', () => {
82
+ const root = tempDir('harness-s1-layer-repo-'); const home = tempDir('harness-s1-layer-home-');
83
+ try {
84
+ const source = makeRepo(root, 'v1', '.safetensors');
85
+ const manifestFile = path.join(source, 'manifest.json');
86
+ const manifest = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
87
+ const bytes = Buffer.from(JSON.stringify({
88
+ schemaVersion: 1, kind: 'echl-h', stage: 'tier', options: ['tier-a', 'tier-b'],
89
+ temperature: 1, bias: null, alpha: 0, k: 1, ngrams: [3], maxChars: 2000, index: [],
90
+ fit: { candidate: 'H-temp', heldOutRows: 1, nll: 0.1, baseNll: 0.2, oof: true },
91
+ }));
92
+ fs.writeFileSync(path.join(source, 'tier.layer.json'), bytes);
93
+ manifest.stages.tier.layer = 'tier.layer.json';
94
+ manifest.stages.tier.layerSha256 = sha(bytes);
95
+ fs.writeFileSync(manifestFile, JSON.stringify(manifest));
96
+ const installed = install.installVersion(root, 'v1', home);
97
+ const copied = path.join(installed.dir, 'tier.layer.json');
98
+ assert.deepEqual(fs.readFileSync(copied), bytes);
99
+ if (process.platform !== 'win32') assert.equal(fs.statSync(copied).mode & 0o777, 0o600);
100
+ install.activate('v1', home);
101
+ const hashes = install.status(home).active;
102
+ assert.deepEqual(Object.keys(hashes.hashes).sort(), [...stages].sort());
103
+ assert.equal(hashes.hashes.tier, manifest.stages.tier.sha256);
104
+ const active = readActive({ HARNESS_SYSTEM_ONE_HOME: home });
105
+ const python = process.env.PYTHON || (process.platform === 'win32' ? 'python' : 'python3');
106
+ const adapterDir = path.join(__dirname, '../harness-everything/scripts/system-one');
107
+ const probe = spawnSync(python, ['-B', '-c',
108
+ "import sys; sys.path.insert(0,sys.argv[2]); import cua_adapter; b=cua_adapter.load_active_bundle(sys.argv[1], scorer_loader=lambda *_: (lambda _r: [], {})); print(b['fingerprint'])",
109
+ path.join(home, 'active.json'), adapterDir], { encoding: 'utf8' });
110
+ assert.equal(probe.status, 0, probe.stderr);
111
+ assert.equal(probe.stdout.trim(), active.fingerprint);
112
+
113
+ fs.writeFileSync(path.join(source, 'tier.layer.json'), 'tampered');
114
+ const invalidHome = tempDir('harness-s1-layer-invalid-');
115
+ try {
116
+ assert.throws(() => install.installVersion(root, 'v1', invalidHome), /artifact-hash/);
117
+ assert.equal(fs.existsSync(path.join(invalidHome, 'versions', 'v1')), false);
118
+ const layerFd = fs.openSync(path.join(source, 'tier.layer.json'), 'w');
119
+ fs.ftruncateSync(layerFd, 32 * 1024 * 1024 + 1);
120
+ fs.closeSync(layerFd);
121
+ manifest.stages.tier.layerSha256 = 'a'.repeat(64);
122
+ fs.writeFileSync(manifestFile, JSON.stringify(manifest));
123
+ assert.throws(() => install.installVersion(root, 'v1', invalidHome), /checkpoint-format/);
124
+ } finally { remove(invalidHome); }
125
+ } finally { remove(root, home); }
126
+ });
127
+
81
128
  test('install accepts referenceOnly only when its option threshold is one', () => {
82
129
  const root = tempDir('harness-s1-reference-only-'); const home = tempDir('harness-s1-reference-home-');
83
130
  try {
@@ -35,6 +35,8 @@ test('S1-P03 trusted manifest validation', () => {
35
35
  });
36
36
  test('S1-P04 Python artifact validation and byte-limit rejection without ML dependency', () => {
37
37
  const python = process.env.PYTHON || (process.platform === 'win32' ? 'python' : 'python3');
38
+ const layer = spawnSync(python, [path.join(__dirname, 'system-one-layer-test.py')], { encoding: 'utf8' });
39
+ assert.equal(layer.status, 0, layer.stderr || String(layer.error));
38
40
  const result = spawnSync(python, [path.join(__dirname, 'system-one-adapter-test.py')], { encoding: 'utf8' });
39
41
  assert.equal(result.status, 0, result.stderr || String(result.error));
40
42
  assert.match(result.stderr, /OK/);
@@ -6,6 +6,7 @@ const os = require('node:os');
6
6
  const path = require('node:path');
7
7
  const { createHash } = require('node:crypto');
8
8
  const { spawnSync } = require('node:child_process');
9
+ const install = require('../harness-everything/scripts/system-one/install');
9
10
  const resident = require('../harness-everything/scripts/system-one/resident');
10
11
  const provider = require('../harness-everything/scripts/system-one/provider');
11
12
  const { createRequest, decide } = require('../harness-everything/scripts/system-one/contract');
@@ -107,6 +108,74 @@ test('S1-RS01 manifest transport fields and digest-bound file names', () => {
107
108
  } finally { cleanup(f); }
108
109
  });
109
110
 
111
+ test('active resident identity includes a verified layer and preserves the legacy identity', async () => {
112
+ function version(home, withLayer) {
113
+ const versionDir = path.join(home, 'versions', 'v1');
114
+ fs.mkdirSync(versionDir, { recursive: true });
115
+ const stages = {};
116
+ for (const stage of ['validity', 'intent', 'tier']) {
117
+ const options = stage === 'validity' ? ['invalid'] : stage === 'tier' ? ['tier1', 'tier2', 'tier3'] : ['fix'];
118
+ const weights = Buffer.from(stage + '-weights');
119
+ const config = Buffer.from(JSON.stringify({ metadata: { domain: 'harness-routing-v1', task: stage, loss: 'binary_cross_entropy' } }));
120
+ fs.writeFileSync(path.join(versionDir, stage + '.safetensors'), weights);
121
+ fs.writeFileSync(path.join(versionDir, stage + '.json'), config);
122
+ stages[stage] = { weights: stage + '.safetensors', config: stage + '.json',
123
+ sha256: createHash('sha256').update(weights).digest('hex'),
124
+ options, thresholds: Object.fromEntries(options.map(id => [id, 0.5])) };
125
+ if (stage === 'tier' && withLayer) {
126
+ const layerBytes = Buffer.from(JSON.stringify({ schemaVersion: 1, kind: 'echl-h', stage, options,
127
+ temperature: 1, bias: null, alpha: 0, k: 1, ngrams: [3], maxChars: 2000, index: [],
128
+ fit: { candidate: 'H-temp', heldOutRows: 1, nll: 0.1, baseNll: 0.2, oof: true } }));
129
+ fs.writeFileSync(path.join(versionDir, 'tier.layer.json'), layerBytes);
130
+ stages[stage].layer = 'tier.layer.json';
131
+ stages[stage].layerSha256 = createHash('sha256').update(layerBytes).digest('hex');
132
+ }
133
+ }
134
+ fs.writeFileSync(path.join(versionDir, 'manifest.json'), JSON.stringify({ schemaVersion: 1, version: 'v1',
135
+ createdAt: '2026-11-14T00:00:00Z', stages, evaluation: null }));
136
+ fs.writeFileSync(path.join(home, 'active.json'), JSON.stringify({ schemaVersion: 1, version: 'v1',
137
+ dir: versionDir, previous: null, activatedAt: '2026-11-14T00:00:00Z' }));
138
+ return versionDir;
139
+ }
140
+
141
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-s1-active-layer-'));
142
+ try {
143
+ const legacyDir = version(home, false);
144
+ const legacy = provider.readActive({ HARNESS_SYSTEM_ONE_HOME: home });
145
+ const legacyInput = ['v1', legacyDir];
146
+ for (const stage of ['validity', 'intent', 'tier']) {
147
+ const entry = legacy.stages[stage];
148
+ legacyInput.push(stage, entry.sha256, entry.configSha256);
149
+ }
150
+ assert.equal(legacy.fingerprint, createHash('sha256').update(legacyInput.join('\0')).digest('hex'));
151
+ const layerDir = version(home, true);
152
+ const layered = provider.readActive({ HARNESS_SYSTEM_ONE_HOME: home });
153
+ assert.ok(layered.stages.tier.layerPath.endsWith('tier.layer.json'));
154
+ assert.notEqual(layered.fingerprint, legacy.fingerprint);
155
+ assert.notEqual(resident.activeStateFiles(layered).state, resident.activeStateFiles(legacy).state);
156
+ const request = createRequest('tier', 'fix a typo in README', TIER_OPTIONS);
157
+ const argsPath = path.join(home, 'active-start-args.json');
158
+ const result = await resident.scoreActiveStage(layered, 'tier', request, {
159
+ command: () => [process.execPath, ['-e', "require('node:fs').writeFileSync(process.argv[1], JSON.stringify(process.argv.slice(2)))", argsPath]],
160
+ });
161
+ assert.equal(result.reason, 'provider-starting');
162
+ const deadline = Date.now() + 2000;
163
+ while (!fs.existsSync(argsPath) && Date.now() < deadline) sleep(10);
164
+ const startupArgs = JSON.parse(fs.readFileSync(argsPath, 'utf8'));
165
+ assert.equal(startupArgs[0], layered.pointerPath);
166
+ assert.equal(startupArgs.at(-1), layered.fingerprint);
167
+ const badPath = path.join(layerDir, 'tier.layer.json');
168
+ const largeFd = fs.openSync(badPath, 'w');
169
+ fs.ftruncateSync(largeFd, 32 * 1024 * 1024 + 1);
170
+ fs.closeSync(largeFd);
171
+ assert.equal(provider.readActive({ HARNESS_SYSTEM_ONE_HOME: home }), null);
172
+ fs.writeFileSync(badPath, 'tampered');
173
+ assert.equal(provider.readActive({ HARNESS_SYSTEM_ONE_HOME: home }), null);
174
+ } finally {
175
+ fs.rmSync(home, { recursive: true, force: true });
176
+ }
177
+ });
178
+
110
179
  test('S1-RS02 cold start never blocks, spawns once, then serves warm repeatable scores', () => {
111
180
  const f = fixture();
112
181
  try {