harness-everything 1.4.0 → 1.5.1
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/ci.yml +16 -0
- package/.github/workflows/release.yml +16 -5
- package/CHANGELOG.md +33 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/README.md +57 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/candidates.json +22802 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/labels.json +131 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/oracle.json +362 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/rows.json +648 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/sample.json +215 -0
- package/benchmarks/results/error-ledger-oracle-484-pilot/select.js +127 -0
- package/ci/fixtures/system-one-colab-fit-layer-sitecustomize.py +72 -0
- package/ci/mechanism-2x-release-automation.test.js +17 -0
- package/ci/mechanism-349-ci-change-scope.test.js +69 -1
- package/ci/mechanism-548-bigint-identity.test.js +1 -1
- package/ci/mechanism-571-fit-guard.test.js +165 -0
- package/ci/mechanism-571-nll-labels.test.js +79 -0
- package/ci/mechanism-system-one-colab.test.js +83 -5
- package/ci/mechanism-system-one-contract.test.js +30 -0
- package/ci/mechanism-system-one-curves.test.js +91 -0
- package/ci/mechanism-system-one-cycle.test.js +417 -34
- package/ci/mechanism-system-one-install.test.js +47 -0
- package/ci/mechanism-system-one-provider.test.js +2 -0
- package/ci/mechanism-system-one-resident.test.js +69 -0
- package/ci/system-one-adapter-test.py +86 -0
- package/ci/system-one-fit-layer-test.py +371 -0
- package/ci/system-one-layer-test.py +122 -0
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/system-one/cua_adapter.py +36 -1
- package/harness-everything/scripts/system-one/install.js +10 -0
- package/harness-everything/scripts/system-one/layer.py +188 -0
- package/harness-everything/scripts/system-one/manifest.js +8 -1
- package/harness-everything/scripts/system-one/provider.js +12 -2
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +36 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +10 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/layer.py +188 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +8 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +12 -2
- package/sbom.cdx.json +7 -7
- package/scripts/system-one-colab.js +6 -4
- package/scripts/system-one-curves.js +114 -13
- package/scripts/system-one-cycle/evaluate.js +72 -9
- package/scripts/system-one-cycle/package.js +61 -3
- package/scripts/system-one-cycle/score.py +23 -2
- package/scripts/system-one-cycle/train.js +254 -20
- package/scripts/system-one-fit-layer.py +379 -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
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
fs.
|
|
101
|
-
|
|
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('
|
|
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
|
-
|
|
556
|
-
|
|
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(
|
|
565
|
-
fs.writeFileSync(path.join(candidate, '
|
|
566
|
-
|
|
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
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
assert.
|
|
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.
|
|
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 {
|
|
@@ -972,6 +1282,79 @@ test('446 cross-cycle: resume keeps one immutable row, repairs a missing append,
|
|
|
972
1282
|
assert.doesNotMatch(conflict.stderr, /synthetic-|holdout-|validation-/);
|
|
973
1283
|
});
|
|
974
1284
|
|
|
1285
|
+
test('new-cycle all-keep-base resume rejects candidate weights-only mutation before history changes', t => {
|
|
1286
|
+
const tmp = private446Root(t);
|
|
1287
|
+
const history = path.join(tmp, 'history.jsonl');
|
|
1288
|
+
const fixture = setup446Cycle(t, path.join(tmp, 'cycle'), [{ version: 'v1', quality: 0.9 }]);
|
|
1289
|
+
const initial = run446Cycle(fixture, 'v1', { history });
|
|
1290
|
+
assert.equal(initial.status, 0, initial.stderr || initial.stdout);
|
|
1291
|
+
const historyBefore = fs.readFileSync(history);
|
|
1292
|
+
const candidate = path.join(fixture.dataDir, 'training', 'candidates', 'v1');
|
|
1293
|
+
const manifestBefore = fs.readFileSync(path.join(candidate, 'manifest.json'));
|
|
1294
|
+
const evaluationDir = path.join(candidate, 'evaluation');
|
|
1295
|
+
const curvesFile = path.join(evaluationDir, 'curves.json');
|
|
1296
|
+
const curves = JSON.parse(fs.readFileSync(curvesFile, 'utf8'));
|
|
1297
|
+
assert.equal(curves.cycleEvidenceVersion, 1);
|
|
1298
|
+
assert.match(curves.candidateDigest, /^[a-f0-9]{64}$/);
|
|
1299
|
+
assert.deepEqual(Object.keys(curves.scoreDigests.validation).sort(), ['intent', 'tier', 'validity']);
|
|
1300
|
+
assert.deepEqual(Object.keys(curves.scoreDigests.holdout).sort(), ['intent', 'tier', 'validity']);
|
|
1301
|
+
const resume = run446Cycle(fixture, 'v1', { history });
|
|
1302
|
+
assert.equal(resume.status, 0, resume.stderr || resume.stdout, 'positive control: unmodified candidate resumes');
|
|
1303
|
+
assert.deepEqual(fs.readFileSync(history), historyBefore);
|
|
1304
|
+
|
|
1305
|
+
const source = path.join(fixture.dataDir, 'training', 'runs', 'v1');
|
|
1306
|
+
const validationFile = path.join(source, 'validity', 'val-scores.jsonl');
|
|
1307
|
+
const outcomeFile = path.join(source, 'validity', 'layer-outcome.json');
|
|
1308
|
+
const validationBefore = fs.readFileSync(validationFile);
|
|
1309
|
+
const outcomeBefore = fs.readFileSync(outcomeFile);
|
|
1310
|
+
const changedRows = JSON.parse(validationBefore.toString('utf8'));
|
|
1311
|
+
changedRows.scores.invalid = 0.37;
|
|
1312
|
+
writeJsonl(validationFile, [changedRows]);
|
|
1313
|
+
const outcome = JSON.parse(outcomeBefore.toString('utf8'));
|
|
1314
|
+
outcome.calibrationInputSha256 = digest(validationFile);
|
|
1315
|
+
fs.writeFileSync(outcomeFile, JSON.stringify(outcome));
|
|
1316
|
+
const rejectedScore = run446Cycle(fixture, 'v1', { history });
|
|
1317
|
+
assert.notEqual(rejectedScore.status, 0, 'changed fit-bound validation scores must reject resume');
|
|
1318
|
+
assert.match(rejectedScore.stderr, /saved-score-evaluation-evidence-is-stale/);
|
|
1319
|
+
assert.equal(fs.readFileSync(history).toString(), historyBefore.toString());
|
|
1320
|
+
fs.writeFileSync(validationFile, validationBefore);
|
|
1321
|
+
fs.writeFileSync(outcomeFile, outcomeBefore);
|
|
1322
|
+
|
|
1323
|
+
const holdoutFile = path.join(evaluationDir, 'validity-holdout-scores.jsonl');
|
|
1324
|
+
const holdoutBefore = fs.readFileSync(holdoutFile);
|
|
1325
|
+
const changedHoldout = JSON.parse(holdoutBefore.toString('utf8'));
|
|
1326
|
+
changedHoldout.scores.invalid = 0.31;
|
|
1327
|
+
writeJsonl(holdoutFile, [changedHoldout]);
|
|
1328
|
+
fs.writeFileSync(history, '');
|
|
1329
|
+
const rejectedHoldout = run446Cycle(fixture, 'v1', { history });
|
|
1330
|
+
assert.notEqual(rejectedHoldout.status, 0, 'changed holdout scores must reject resume');
|
|
1331
|
+
assert.match(rejectedHoldout.stderr, /saved-score-evaluation-evidence-is-stale/);
|
|
1332
|
+
assert.equal(fs.readFileSync(history).toString(), '', 'rejected missing-append reconciliation leaves history unchanged');
|
|
1333
|
+
fs.writeFileSync(history, historyBefore);
|
|
1334
|
+
fs.writeFileSync(holdoutFile, holdoutBefore);
|
|
1335
|
+
|
|
1336
|
+
const curvesBefore = fs.readFileSync(curvesFile);
|
|
1337
|
+
delete curves.cycleEvidenceVersion;
|
|
1338
|
+
delete curves.candidateDigest;
|
|
1339
|
+
delete curves.scoreDigests;
|
|
1340
|
+
fs.writeFileSync(curvesFile, JSON.stringify(curves, null, 2) + '\n');
|
|
1341
|
+
const rejectedUnbound = run446Cycle(fixture, 'v1', { history });
|
|
1342
|
+
assert.notEqual(rejectedUnbound.status, 0, 'older unbound cycle evidence must reject resume');
|
|
1343
|
+
assert.match(rejectedUnbound.stderr, /unbound-cycle-evaluation-cannot-resume/);
|
|
1344
|
+
assert.equal(fs.readFileSync(history).toString(), historyBefore.toString());
|
|
1345
|
+
fs.writeFileSync(curvesFile, curvesBefore);
|
|
1346
|
+
|
|
1347
|
+
const manifest = JSON.parse(manifestBefore.toString('utf8'));
|
|
1348
|
+
fs.appendFileSync(path.join(candidate, manifest.stages.validity.weights), 'tampered');
|
|
1349
|
+
assert.deepEqual(fs.readFileSync(path.join(candidate, 'manifest.json')), manifestBefore,
|
|
1350
|
+
'the mutation changes candidate weights only; manifest bytes stay fixed');
|
|
1351
|
+
const rejected = run446Cycle(fixture, 'v1', { history });
|
|
1352
|
+
assert.notEqual(rejected.status, 0, 'weights-only mutation must reject resume');
|
|
1353
|
+
assert.match(rejected.stderr, /candidate weights do not match its fit outcome/);
|
|
1354
|
+
assert.equal(fs.readFileSync(history).toString(), historyBefore.toString(),
|
|
1355
|
+
'rejected resume leaves immutable history byte-identical');
|
|
1356
|
+
});
|
|
1357
|
+
|
|
975
1358
|
test('446 cross-cycle: default history remains local and explicit history validation fails closed', t => {
|
|
976
1359
|
const tmp = private446Root(t);
|
|
977
1360
|
const local = setup446Cycle(t, path.join(tmp, 'default-cycle'), [{ version: 'default-v0', quality: 0.9 }]);
|
|
@@ -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/);
|