harness-everything 1.3.2 → 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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/release.yml +23 -6
- package/CHANGELOG.md +42 -0
- package/RELEASING.md +2 -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-system-one-colab.test.js +528 -0
- package/ci/mechanism-system-one-contract.test.js +30 -0
- package/ci/mechanism-system-one-curves.test.js +85 -0
- package/ci/mechanism-system-one-cycle.test.js +344 -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/ci/system-one-train-test.py +26 -0
- package/docs/system-one-cycle.md +10 -0
- package/docs/system-one-training.md +3 -1
- 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 +178 -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 +178 -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 +240 -0
- package/scripts/system-one-curves.js +52 -8
- package/scripts/system-one-cycle/evaluate.js +56 -5
- 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 +212 -20
- package/scripts/system-one-fit-layer.py +369 -0
- package/scripts/system-one-train.py +36 -9
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const crypto = require('node:crypto');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { spawnSync } = require('node:child_process');
|
|
9
|
+
const { test } = require('node:test');
|
|
10
|
+
const { REPO } = require('../scripts/system-one-cycle/common');
|
|
11
|
+
const { TASKS, trainCycle } = require('../scripts/system-one-cycle/train');
|
|
12
|
+
const { remoteRunner } = require('../scripts/system-one-colab');
|
|
13
|
+
|
|
14
|
+
const skipNoColabCli = process.platform === 'win32' && 'google-colab-cli supports Linux and macOS only';
|
|
15
|
+
const launcher = path.join(REPO, 'scripts', 'system-one-colab.js');
|
|
16
|
+
const cycleCli = path.join(REPO, 'scripts', 'system-one-cycle.js');
|
|
17
|
+
const fitter = path.join(REPO, 'scripts', 'system-one-fit-layer.py');
|
|
18
|
+
const fitterFixture = path.join(__dirname, 'fixtures', 'system-one-colab-fit-layer-sitecustomize.py');
|
|
19
|
+
const allowed = [
|
|
20
|
+
'training/v1/prompts.jsonl', 'training/v1/labels.jsonl', 'training/v1/labels-intent.jsonl',
|
|
21
|
+
'training/v1-validity/prompts.jsonl', 'training/v1-validity/labels.jsonl',
|
|
22
|
+
'scripts/system-one-train.py',
|
|
23
|
+
'benchmarks/fixtures/system-one-holdout.json',
|
|
24
|
+
'benchmarks/fixtures/system-one-intent-holdout.json',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
function fixture(t) {
|
|
28
|
+
const root = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-colab-')));
|
|
29
|
+
const dataDir = path.join(root, 'private-cycle');
|
|
30
|
+
fs.mkdirSync(dataDir, { recursive: true, mode: 0o700 });
|
|
31
|
+
for (const relative of allowed.slice(0, 5)) {
|
|
32
|
+
const file = path.join(dataDir, relative);
|
|
33
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
34
|
+
const row = relative.endsWith('prompts.jsonl')
|
|
35
|
+
? { id: 'synthetic-row', family: 'synthetic-family', source: 'observation', split: 'train', text: 'synthetic prompt' }
|
|
36
|
+
: relative.endsWith('labels-intent.jsonl')
|
|
37
|
+
? { id: 'synthetic-row', gold: 'feature', secondary: [] }
|
|
38
|
+
: { id: 'synthetic-row', gold: 'tier2' };
|
|
39
|
+
fs.writeFileSync(file, `${JSON.stringify(row)}\n`, { mode: 0o600 });
|
|
40
|
+
}
|
|
41
|
+
for (const relative of ['training/observed/prompts-observed.jsonl', 'training/relabel-luna/labels.jsonl',
|
|
42
|
+
'training/adjudication/consensus.jsonl', 'training/history.jsonl']) {
|
|
43
|
+
const file = path.join(dataDir, relative);
|
|
44
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
45
|
+
fs.writeFileSync(file, 'PRIVATE-SENTINEL\n', { mode: 0o600 });
|
|
46
|
+
}
|
|
47
|
+
const fakeRoot = path.join(root, 'fake-colab');
|
|
48
|
+
const log = path.join(root, 'colab.jsonl');
|
|
49
|
+
const fitterDir = path.join(root, 'python-fixture');
|
|
50
|
+
const fitterLog = path.join(root, 'fit-layer.jsonl');
|
|
51
|
+
fs.mkdirSync(fitterDir, { recursive: true, mode: 0o700 });
|
|
52
|
+
const fitterSource = fs.readFileSync(fitterFixture, 'utf8').replace(
|
|
53
|
+
"'schemaVersion': 1, 'task': task, 'outcome': 'layer', 'datasetSha256': datasets,",
|
|
54
|
+
"'schemaVersion': 1, 'task': task, 'outcome': 'layer', 'oofScoreSpace': 'h-transform-v2', 'datasetSha256': datasets,");
|
|
55
|
+
fs.writeFileSync(path.join(fitterDir, 'sitecustomize.py'), fitterSource, { mode: 0o600 });
|
|
56
|
+
const bin = path.join(root, 'colab');
|
|
57
|
+
fs.writeFileSync(bin, `#!/usr/bin/env node
|
|
58
|
+
'use strict';
|
|
59
|
+
const fs = require('node:fs');
|
|
60
|
+
const path = require('node:path');
|
|
61
|
+
const crypto = require('node:crypto');
|
|
62
|
+
const a = process.argv.slice(2);
|
|
63
|
+
const root = process.env.FAKE_COLAB_ROOT;
|
|
64
|
+
const log = process.env.FAKE_COLAB_LOG;
|
|
65
|
+
fs.mkdirSync(root, { recursive: true });
|
|
66
|
+
function record(extra = {}) { fs.appendFileSync(log, JSON.stringify({ argv: a, ...extra }) + '\\n'); }
|
|
67
|
+
function remotePath(value) { return path.join(root, value.replace(/^\\/content\\//, '')); }
|
|
68
|
+
if (a[0] === 'upload') {
|
|
69
|
+
record();
|
|
70
|
+
const source = a[3]; const target = remotePath(a[4]);
|
|
71
|
+
if (!fs.existsSync(path.dirname(target))) { console.error('[colab] Upload failed: 500 Server Error'); process.exit(1); }
|
|
72
|
+
fs.copyFileSync(source, target);
|
|
73
|
+
if (a[4] === '/content/bundle-manifest.json') record({ uploadedManifestSha256: crypto.createHash('sha256').update(fs.readFileSync(source)).digest('hex') });
|
|
74
|
+
if (process.env.FAKE_COLAB_CORRUPT_UPLOAD === '1' && a[4].endsWith('training/v1/prompts.jsonl')) fs.appendFileSync(target, 'tampered\\n');
|
|
75
|
+
} else if (a[0] === 'download') {
|
|
76
|
+
record(); if (process.env.FAKE_COLAB_FAIL_DOWNLOAD === a[3] || !fs.existsSync(remotePath(a[3]))) { console.error('[colab] Download failed: File or directory not found'); process.exit(1); } fs.mkdirSync(path.dirname(a[4]), { recursive: true }); fs.copyFileSync(remotePath(a[3]), a[4]);
|
|
77
|
+
} else if (a[0] === 'exec') {
|
|
78
|
+
const script = fs.readFileSync(a[4], 'utf8');
|
|
79
|
+
if (script.includes('os.makedirs')) {
|
|
80
|
+
const remotePaths = JSON.parse(script.match(/PATHS = (\\[[^\\n]+\\])/)[1]);
|
|
81
|
+
record({ task: 'prepare' });
|
|
82
|
+
for (const item of remotePaths) fs.mkdirSync(remotePath(item), { recursive: true });
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
if (!script.includes('hashlib.sha256')) { record(); process.exit(0); }
|
|
86
|
+
// Real colab exec gives up after 30 s without kernel output; the trainer subprocess emits none (s1-2026-11-29 run).
|
|
87
|
+
const timeoutAt = a.indexOf('--timeout');
|
|
88
|
+
if (timeoutAt < 0 || Number(a[timeoutAt + 1]) < 600) { record({ task: 'silence-timeout' }); console.error('TimeoutError: no message from the kernel for 30s'); process.exit(1); }
|
|
89
|
+
const manifestBytes = fs.readFileSync(path.join(root, 'bundle-manifest.json'));
|
|
90
|
+
const manifestSha256 = crypto.createHash('sha256').update(manifestBytes).digest('hex');
|
|
91
|
+
const expectedManifestSha256 = script.match(/EXPECTED_MANIFEST_SHA256 = ["']([^"']+)/)?.[1] || manifestSha256;
|
|
92
|
+
const invocationId = script.match(/INVOCATION_ID = ["']([^"']+)/)?.[1] || null;
|
|
93
|
+
if (manifestSha256 !== expectedManifestSha256) { record({ task: script.match(/TASK = ["']([^"']+)/)?.[1] }); console.error('bundle-manifest-mismatch'); process.exit(0); }
|
|
94
|
+
const manifest = JSON.parse(manifestBytes);
|
|
95
|
+
for (const entry of manifest.files) {
|
|
96
|
+
const actual = crypto.createHash('sha256').update(fs.readFileSync(remotePath('/content/' + entry.path))).digest('hex');
|
|
97
|
+
if (actual !== entry.sha256) { record({ task: script.match(/TASK = [\"']([^\"']+)/)?.[1] }); console.error('manifest-mismatch'); process.exit(0); }
|
|
98
|
+
}
|
|
99
|
+
const task = script.match(/TASK = [\"']([^\"']+)/)?.[1];
|
|
100
|
+
record({ task });
|
|
101
|
+
if (process.env.FAKE_COLAB_FAIL_TASK === task) { console.error('trainer-failed'); process.exit(0); }
|
|
102
|
+
const version = script.match(/VERSION = [\"']([^\"']+)/)?.[1];
|
|
103
|
+
const holdout = task === 'intent' ? 'benchmarks/fixtures/system-one-intent-holdout.json' : 'benchmarks/fixtures/system-one-holdout.json';
|
|
104
|
+
const catalog = task === 'validity' ? ['invalid'] : JSON.parse(fs.readFileSync(remotePath('/content/' + holdout), 'utf8')).cases[0].request.options.map(x => x.id).filter(id => task !== 'tier' || ['tier1','tier2','tier3'].includes(id));
|
|
105
|
+
const out = path.join(root, 'runs', version, task); fs.mkdirSync(out, { recursive: true });
|
|
106
|
+
const header = Buffer.from(JSON.stringify({ weight: { dtype: 'F32', shape: [1], data_offsets: [0, 4] } }));
|
|
107
|
+
const paddedHeader = Buffer.concat([header, Buffer.alloc((8 - header.length % 8) % 8, 0x20)]);
|
|
108
|
+
const headerLength = Buffer.alloc(8);
|
|
109
|
+
headerLength.writeBigUInt64LE(BigInt(paddedHeader.length));
|
|
110
|
+
fs.writeFileSync(path.join(out, 'harness-routing-v1.safetensors'), Buffer.concat([headerLength, paddedHeader, Buffer.alloc(4)]));
|
|
111
|
+
fs.writeFileSync(path.join(out, 'harness-routing-v1.json'), JSON.stringify({ metadata: { domain: 'harness-routing-v1', task, loss: 'binary_cross_entropy', catalog } }));
|
|
112
|
+
const validationGold = catalog[0];
|
|
113
|
+
fs.writeFileSync(path.join(out, 'val-scores.jsonl'), JSON.stringify({ id: 'synthetic-validation', gold: validationGold,
|
|
114
|
+
scores: Object.fromEntries(catalog.map(id => [id, id === validationGold ? 0.99 : 0.01])) }) + '\\n');
|
|
115
|
+
const labelFile = task === 'intent' ? 'labels-intent.jsonl' : 'labels.jsonl';
|
|
116
|
+
const sha256 = file => crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
|
117
|
+
const trainReport = { schemaVersion: 1, task, target: 'label', catalog, config: {},
|
|
118
|
+
counts: { train: 1, validation: 1, test: 0 }, bestEpoch: 1, history: [], device: 'cpu', torch: 'fixture', datasets: {
|
|
119
|
+
'prompts.jsonl': sha256(remotePath('training/' + (task === 'validity' ? 'v1-validity' : 'v1') + '/prompts.jsonl')),
|
|
120
|
+
[labelFile]: sha256(remotePath('training/' + (task === 'validity' ? 'v1-validity' : 'v1') + '/' + labelFile)),
|
|
121
|
+
} };
|
|
122
|
+
fs.writeFileSync(path.join(out, 'train-report.json'), process.env.FAKE_COLAB_BAD_CATALOG === task ? '{' : JSON.stringify(trainReport));
|
|
123
|
+
const files = ['harness-routing-v1.safetensors','harness-routing-v1.json','val-scores.jsonl','train-report.json'];
|
|
124
|
+
const status = { schemaVersion: 1, ok: true, task, version, invocationId,
|
|
125
|
+
manifestSha256: process.env.FAKE_COLAB_STATUS_MANIFEST_SHA256 || expectedManifestSha256,
|
|
126
|
+
files: Object.fromEntries(files.map(file => [file, crypto.createHash('sha256').update(fs.readFileSync(path.join(out, file))).digest('hex')])) };
|
|
127
|
+
fs.writeFileSync(path.join(root, 'runs', version, task, 'remote-status.json'), JSON.stringify(status));
|
|
128
|
+
if (process.env.FAKE_COLAB_TAMPER_STAGE === task + '/harness-routing-v1.json') fs.appendFileSync(path.join(out, 'harness-routing-v1.json'), 'tampered');
|
|
129
|
+
} else if (a[0] === 'stop') {
|
|
130
|
+
record();
|
|
131
|
+
if (process.env.FAKE_COLAB_FAIL_STOP === '1') { console.error('injected-stop-failure'); process.exit(1); }
|
|
132
|
+
} else { record(); }
|
|
133
|
+
`, { mode: 0o700 });
|
|
134
|
+
const env = { ...process.env, FAKE_COLAB_ROOT: fakeRoot, FAKE_COLAB_LOG: log };
|
|
135
|
+
env.PYTHON = process.platform === 'win32' ? 'python' : 'python3';
|
|
136
|
+
env.PYTHONPATH = fitterDir;
|
|
137
|
+
env.PYTHONNOUSERSITE = '1';
|
|
138
|
+
env.PYTHONDONTWRITEBYTECODE = '1';
|
|
139
|
+
env.S1_COLAB_FIT_LAYER_FIXTURE = '1';
|
|
140
|
+
env.S1_COLAB_FIT_LAYER_SCRIPT = fitter;
|
|
141
|
+
env.S1_COLAB_FIT_LAYER_LOG = fitterLog;
|
|
142
|
+
delete env.PYTHONHOME;
|
|
143
|
+
delete env.HARNESS_SYSTEM_ONE_MODE;
|
|
144
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
145
|
+
return { dataDir, fakeRoot, log, fitterLog, bin, env };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function run(f, extra = []) {
|
|
149
|
+
return spawnSync(process.execPath, [launcher, '--data-dir', f.dataDir, '--version', 'synthetic-v1',
|
|
150
|
+
'--colab', f.bin, ...extra], { cwd: REPO, encoding: 'utf8', env: f.env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function logRows(f) {
|
|
154
|
+
return fs.readFileSync(f.log, 'utf8').trim().split(/\r?\n/).filter(Boolean).map(JSON.parse);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function stageDir(f, task) {
|
|
158
|
+
return path.join(f.dataDir, 'training', 'runs', 'synthetic-v1', task);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function assertLayerOutcome(f, task) {
|
|
162
|
+
const stage = stageDir(f, task);
|
|
163
|
+
const outcome = JSON.parse(fs.readFileSync(path.join(stage, 'layer-outcome.json'), 'utf8'));
|
|
164
|
+
assert.equal(outcome.task, task);
|
|
165
|
+
assert.equal(outcome.outcome, 'layer');
|
|
166
|
+
assert.equal(outcome.oofScoreSpace, 'h-transform-v2');
|
|
167
|
+
assert.equal(outcome.checkpointConfigSha256,
|
|
168
|
+
crypto.createHash('sha256').update(fs.readFileSync(path.join(stage, 'harness-routing-v1.json'))).digest('hex'));
|
|
169
|
+
assert.equal(outcome.calibrationInput, 'val-scores-layered.jsonl');
|
|
170
|
+
assert.equal(outcome.calibrationInputSha256,
|
|
171
|
+
crypto.createHash('sha256').update(fs.readFileSync(path.join(stage, 'val-scores-layered.jsonl'))).digest('hex'));
|
|
172
|
+
assert.equal(outcome.calibrationSha256,
|
|
173
|
+
crypto.createHash('sha256').update(fs.readFileSync(path.join(stage, 'calibration.json'))).digest('hex'));
|
|
174
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(stage, 'layer.json'), 'utf8')).stage, task);
|
|
175
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(stage, 'calibration.json'), 'utf8')).task, task);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function fitLayerCalls(f) {
|
|
179
|
+
return fs.readFileSync(f.fitterLog, 'utf8').trim().split(/\r?\n/).filter(Boolean).map(JSON.parse);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function assertIntentRetryReachesTrainCycle(f) {
|
|
183
|
+
const calls = [];
|
|
184
|
+
await assert.rejects(trainCycle({ dataDir: f.dataDir, version: 'synthetic-v1', run: async (_bin, args) => {
|
|
185
|
+
calls.push(args[args.indexOf('--task') + 1]);
|
|
186
|
+
throw new Error('stopped-before-training');
|
|
187
|
+
} }), /stopped-before-training/);
|
|
188
|
+
assert.deepEqual(calls, ['intent']);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function makePublicationFailure(f) {
|
|
192
|
+
const preload = path.join(path.dirname(f.bin), 'fail-publication.js');
|
|
193
|
+
fs.writeFileSync(preload, `const fs = require('node:fs');
|
|
194
|
+
const path = require('node:path');
|
|
195
|
+
const rename = fs.renameSync;
|
|
196
|
+
fs.renameSync = function (source, target, ...args) {
|
|
197
|
+
const name = path.basename(target);
|
|
198
|
+
if (process.env.FAKE_COLAB_FAIL_PUBLISH === '1' && target.includes('/training/runs/synthetic-v1/intent/') &&
|
|
199
|
+
['harness-routing-v1.safetensors', 'harness-routing-v1.json'].includes(name)) {
|
|
200
|
+
fs.appendFileSync(process.env.FAKE_COLAB_PUBLISH_LOG, name + '\\n');
|
|
201
|
+
if (name === 'harness-routing-v1.json') throw new Error('injected-final-publication-failure');
|
|
202
|
+
}
|
|
203
|
+
return rename.call(this, source, target, ...args);
|
|
204
|
+
};
|
|
205
|
+
`);
|
|
206
|
+
f.env.FAKE_COLAB_FAIL_PUBLISH = '1';
|
|
207
|
+
f.env.FAKE_COLAB_PUBLISH_LOG = path.join(path.dirname(f.bin), 'publication.log');
|
|
208
|
+
f.env.NODE_OPTIONS = `${f.env.NODE_OPTIONS || ''} --require=${preload.replace(/\\/g, '/')}`.trim();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function evaluatePackageAndVerifyArtifacts(f) {
|
|
212
|
+
const scorerDir = path.join(path.dirname(f.bin), 'synthetic-scorer');
|
|
213
|
+
const scoreScript = path.join(REPO, 'scripts', 'system-one-cycle', 'score.py');
|
|
214
|
+
fs.mkdirSync(scorerDir, { recursive: true, mode: 0o700 });
|
|
215
|
+
fs.writeFileSync(path.join(scorerDir, 'sitecustomize.py'), `import json, os, sys
|
|
216
|
+
_SCORE_SCRIPT = ${JSON.stringify(scoreScript)}
|
|
217
|
+
if sys.argv and os.path.realpath(sys.argv[0]) == os.path.realpath(_SCORE_SCRIPT):
|
|
218
|
+
args = dict(zip(sys.argv[1::2], sys.argv[2::2]))
|
|
219
|
+
task = args['--task']
|
|
220
|
+
config = json.load(open(os.path.splitext(args['--weights'])[0] + '.json', encoding='utf-8'))
|
|
221
|
+
ids = config['metadata']['catalog']
|
|
222
|
+
holdout = json.load(open(args['--holdout'], encoding='utf-8'))
|
|
223
|
+
rows = []
|
|
224
|
+
for case in holdout['cases']:
|
|
225
|
+
gold = 'actionable' if task == 'validity' else case.get('gold')
|
|
226
|
+
if task == 'intent':
|
|
227
|
+
gold = gold if isinstance(gold, list) else [gold]
|
|
228
|
+
gold = [option for option in gold if option in ids]
|
|
229
|
+
if not gold:
|
|
230
|
+
continue
|
|
231
|
+
elif task == 'tier' and gold not in ids:
|
|
232
|
+
continue
|
|
233
|
+
positives = set(gold if isinstance(gold, list) else [gold])
|
|
234
|
+
scores = {option: (0.01 if option == 'invalid' else 0.99) if task == 'validity'
|
|
235
|
+
else (0.99 if option in positives else 0.01) for option in ids}
|
|
236
|
+
rows.append({'id': case['id'], 'gold': gold, 'scores': scores})
|
|
237
|
+
with open(args['--out'], 'w', encoding='utf-8') as output:
|
|
238
|
+
output.writelines(json.dumps(row, separators=(',', ':')) + '\\n' for row in rows)
|
|
239
|
+
sys.stdout.flush()
|
|
240
|
+
sys.stderr.flush()
|
|
241
|
+
os._exit(0)
|
|
242
|
+
`);
|
|
243
|
+
fs.appendFileSync(path.join(scorerDir, 'sitecustomize.py'), `\n${fs.readFileSync(fitterFixture, 'utf8')}`);
|
|
244
|
+
const env = { ...f.env, PYTHON: f.env.PYTHON, PYTHONPATH: scorerDir,
|
|
245
|
+
PYTHONNOUSERSITE: '1', PYTHONDONTWRITEBYTECODE: '1' };
|
|
246
|
+
const history = path.join(path.dirname(f.bin), 'synthetic-history.jsonl');
|
|
247
|
+
for (const step of ['evaluate', 'package']) {
|
|
248
|
+
const args = [cycleCli, step, '--data-dir', f.dataDir, '--version', 'synthetic-v1'];
|
|
249
|
+
if (step === 'evaluate') args.push('--history', history);
|
|
250
|
+
const result = spawnSync(process.execPath, args,
|
|
251
|
+
{ cwd: REPO, encoding: 'utf8', env });
|
|
252
|
+
assert.equal(result.status, 0, `${step}: ${result.stderr || result.stdout}`);
|
|
253
|
+
}
|
|
254
|
+
const versionDir = path.join(f.dataDir, 'training', 'versions', 'synthetic-v1');
|
|
255
|
+
const manifestFile = path.join(versionDir, 'manifest.json');
|
|
256
|
+
const verify = `import hashlib,json,sys\nsys.path.insert(0, ${JSON.stringify(path.join(REPO, 'harness-everything', 'scripts', 'system-one'))})\nfrom cua_adapter import verify_artifacts\nroot=${JSON.stringify(versionDir)}\nmanifest=json.load(open(sys.argv[1], encoding='utf-8'))\nfor stage in manifest['stages'].values():\n weights=__import__('pathlib').Path(root, stage['weights']).resolve()\n config=__import__('pathlib').Path(root, stage['config']).resolve()\n verify_artifacts({'checkpoint':str(weights),'config':str(config),'weightsSha256':stage['sha256'],'configSha256':hashlib.sha256(config.read_bytes()).hexdigest()})\nprint('verified three packaged stages')\n`;
|
|
257
|
+
const result = spawnSync(env.PYTHON, ['-c', verify, manifestFile], { cwd: REPO, encoding: 'utf8', env });
|
|
258
|
+
assert.equal(result.status, 0, result.stderr);
|
|
259
|
+
assert.match(result.stdout, /verified three packaged stages/);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
test('Colab launcher uploads only allow-listed data and produces stages trainCycle reuses', { skip: skipNoColabCli }, async t => {
|
|
263
|
+
const f = fixture(t);
|
|
264
|
+
const result = run(f, ['--gpu', 'T4', '--session', 'fake-session']);
|
|
265
|
+
assert.equal(result.status, 0, result.stderr);
|
|
266
|
+
const rows = logRows(f);
|
|
267
|
+
const uploads = rows.filter(row => row.argv[0] === 'upload');
|
|
268
|
+
assert.deepEqual(uploads.map(row => row.argv[4].replace(/^\/content\//, '')).filter(remote => remote !== 'bundle-manifest.json').sort(), [...allowed].sort());
|
|
269
|
+
assert.ok(uploads.every(row => !/observed|relabel-luna|adjudication|history/.test(row.argv[4])));
|
|
270
|
+
assert.equal(rows.filter(row => row.argv[0] === 'exec').length, 4);
|
|
271
|
+
const manifestUpload = rows.find(row => row.uploadedManifestSha256);
|
|
272
|
+
assert.equal(JSON.parse(result.stdout).manifestSha256, manifestUpload.uploadedManifestSha256);
|
|
273
|
+
const execIndices = rows.map((row, index) => row.argv[0] === 'exec' && row.task !== 'prepare' ? index : -1).filter(index => index >= 0);
|
|
274
|
+
assert.ok(rows.findIndex(row => row.argv[0] === 'exec' && row.task === 'prepare') < rows.findIndex(row => row.argv[0] === 'upload'));
|
|
275
|
+
for (let i = 0; i < execIndices.length - 1; i++) {
|
|
276
|
+
const downloads = rows.slice(execIndices[i] + 1, execIndices[i + 1]).filter(row => row.argv[0] === 'download');
|
|
277
|
+
assert.equal(downloads.length, 5);
|
|
278
|
+
assert.match(downloads[0].argv[3], /remote-status\.json$/);
|
|
279
|
+
}
|
|
280
|
+
assert.equal(rows.at(-1).argv[0], 'stop');
|
|
281
|
+
for (const task of TASKS) {
|
|
282
|
+
const status = JSON.parse(fs.readFileSync(path.join(f.fakeRoot, 'runs', 'synthetic-v1', task, 'remote-status.json'), 'utf8'));
|
|
283
|
+
assert.match(status.invocationId, /^[0-9a-f-]{36}$/);
|
|
284
|
+
assert.equal(status.manifestSha256, manifestUpload.uploadedManifestSha256);
|
|
285
|
+
assertLayerOutcome(f, task);
|
|
286
|
+
}
|
|
287
|
+
assert.deepEqual(fitLayerCalls(f).map(row => row.task), TASKS);
|
|
288
|
+
const skipped = await trainCycle({ dataDir: f.dataDir, version: 'synthetic-v1', run: () => { throw new Error('unexpected local training'); } });
|
|
289
|
+
assert.equal(skipped.skipped, 3);
|
|
290
|
+
for (const task of TASKS) {
|
|
291
|
+
const stage = path.join(f.dataDir, 'training', 'runs', 'synthetic-v1', task);
|
|
292
|
+
const remote = JSON.parse(fs.readFileSync(path.join(stage, 'resource-guard.json'), 'utf8')).remote;
|
|
293
|
+
assert.equal(remote.provider, 'colab');
|
|
294
|
+
assert.equal(remote.gpu, 'T4');
|
|
295
|
+
assert.equal(remote.session, 'fake-session');
|
|
296
|
+
assert.match(remote.invocationId, /^[a-f0-9-]{36}$/);
|
|
297
|
+
assert.match(remote.manifestSha256, /^[a-f0-9]{64}$/);
|
|
298
|
+
assert.deepEqual(Object.keys(remote.files).sort(), ['harness-routing-v1.json', 'harness-routing-v1.safetensors', 'train-report.json', 'val-scores.jsonl']);
|
|
299
|
+
}
|
|
300
|
+
const priorColabCalls = logRows(f).length;
|
|
301
|
+
for (const task of TASKS) {
|
|
302
|
+
const outcomeFile = path.join(stageDir(f, task), 'layer-outcome.json');
|
|
303
|
+
const stale = JSON.parse(fs.readFileSync(outcomeFile, 'utf8'));
|
|
304
|
+
delete stale.oofScoreSpace;
|
|
305
|
+
fs.writeFileSync(outcomeFile, JSON.stringify(stale));
|
|
306
|
+
}
|
|
307
|
+
fs.writeFileSync(f.fitterLog, '');
|
|
308
|
+
const reused = run(f, ['--session', 'fake-session']);
|
|
309
|
+
assert.equal(reused.status, 0, reused.stderr);
|
|
310
|
+
assert.match(reused.stdout, /"trained":0,"skipped":3/);
|
|
311
|
+
assert.equal(logRows(f).length, priorColabCalls, 'complete stages should reuse without contacting Colab');
|
|
312
|
+
assert.deepEqual(fitLayerCalls(f).map(row => row.task), TASKS);
|
|
313
|
+
for (const task of TASKS) assertLayerOutcome(f, task);
|
|
314
|
+
const intentOutcomeFile = path.join(stageDir(f, 'intent'), 'layer-outcome.json');
|
|
315
|
+
const intentOutcome = JSON.parse(fs.readFileSync(intentOutcomeFile, 'utf8'));
|
|
316
|
+
intentOutcome.checkpointConfigSha256 = '0'.repeat(64);
|
|
317
|
+
fs.writeFileSync(intentOutcomeFile, JSON.stringify(intentOutcome));
|
|
318
|
+
fs.writeFileSync(f.fitterLog, '');
|
|
319
|
+
const refitted = run(f, ['--session', 'fake-session']);
|
|
320
|
+
assert.equal(refitted.status, 0, refitted.stderr);
|
|
321
|
+
assert.match(refitted.stdout, /"trained":0,"skipped":3/);
|
|
322
|
+
assert.equal(logRows(f).length, priorColabCalls, 'a stale local fit digest must not contact Colab again');
|
|
323
|
+
assert.deepEqual(fitLayerCalls(f).map(row => row.task), ['intent'], 'a digest mismatch refits through the shared local fitter');
|
|
324
|
+
assertLayerOutcome(f, 'intent');
|
|
325
|
+
assert.doesNotMatch(result.stdout, /synthetic"|PRIVATE-SENTINEL/);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('manifest mismatch fails before training and still stops the session', { skip: skipNoColabCli }, t => {
|
|
329
|
+
const f = fixture(t);
|
|
330
|
+
f.env.FAKE_COLAB_CORRUPT_UPLOAD = '1';
|
|
331
|
+
const result = run(f);
|
|
332
|
+
assert.notEqual(result.status, 0);
|
|
333
|
+
const rows = logRows(f);
|
|
334
|
+
assert.equal(rows.filter(row => row.argv[0] === 'exec').length, 2);
|
|
335
|
+
assert.equal(rows.at(-1).argv[0], 'stop');
|
|
336
|
+
assert.equal(fs.existsSync(path.join(f.dataDir, 'training', 'runs', 'synthetic-v1', 'validity', 'train-report.json')), false);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test('failed intent stage has no status, keeps validity and writes no intent guard', { skip: skipNoColabCli }, t => {
|
|
340
|
+
const f = fixture(t);
|
|
341
|
+
f.env.FAKE_COLAB_FAIL_TASK = 'intent';
|
|
342
|
+
const failed = run(f);
|
|
343
|
+
assert.notEqual(failed.status, 0);
|
|
344
|
+
assert.match(failed.stderr, /remote-status-missing|remote-training-failed/);
|
|
345
|
+
assert.match(failed.stderr, /trainer-failed/);
|
|
346
|
+
const rows = logRows(f);
|
|
347
|
+
assert.equal(rows.at(-1).argv[0], 'stop');
|
|
348
|
+
assert.equal(fs.existsSync(path.join(f.dataDir, 'training', 'runs', 'synthetic-v1', 'validity', 'train-report.json')), true);
|
|
349
|
+
assert.equal(fs.existsSync(path.join(f.dataDir, 'training', 'runs', 'synthetic-v1', 'intent', 'train-report.json')), false);
|
|
350
|
+
assert.equal(fs.existsSync(path.join(f.dataDir, 'training', 'runs', 'synthetic-v1', 'intent', 'resource-guard.json')), false);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test('tampered downloaded stage file fails its remote hash check and stops the session', { skip: skipNoColabCli }, t => {
|
|
354
|
+
const f = fixture(t);
|
|
355
|
+
f.env.FAKE_COLAB_TAMPER_STAGE = 'validity/harness-routing-v1.json';
|
|
356
|
+
const result = run(f);
|
|
357
|
+
assert.notEqual(result.status, 0);
|
|
358
|
+
assert.match(result.stderr, /stage-hash-mismatch/);
|
|
359
|
+
assert.equal(fs.existsSync(path.join(f.dataDir, 'training', 'runs', 'synthetic-v1', 'validity', 'resource-guard.json')), false);
|
|
360
|
+
assert.equal(logRows(f).at(-1).argv[0], 'stop');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('tampered repair stays incomplete, retries intent, and reuses prior stages', { skip: skipNoColabCli }, async t => {
|
|
364
|
+
const f = fixture(t);
|
|
365
|
+
assert.equal(run(f, ['--session', 'fake-session']).status, 0);
|
|
366
|
+
const intent = stageDir(f, 'intent');
|
|
367
|
+
fs.rmSync(path.join(intent, 'harness-routing-v1.json'));
|
|
368
|
+
f.env.FAKE_COLAB_TAMPER_STAGE = 'intent/harness-routing-v1.json';
|
|
369
|
+
|
|
370
|
+
const failed = run(f, ['--session', 'fake-session']);
|
|
371
|
+
assert.notEqual(failed.status, 0);
|
|
372
|
+
assert.match(failed.stderr, /stage-hash-mismatch: intent\/harness-routing-v1\.json/);
|
|
373
|
+
assert.equal(fs.existsSync(path.join(intent, 'harness-routing-v1.json')), false);
|
|
374
|
+
assert.equal(fs.existsSync(path.join(intent, 'resource-guard.json')), true);
|
|
375
|
+
assert.equal(fs.existsSync(path.join(stageDir(f, 'validity'), 'resource-guard.json')), true);
|
|
376
|
+
await assertIntentRetryReachesTrainCycle(f);
|
|
377
|
+
|
|
378
|
+
delete f.env.FAKE_COLAB_TAMPER_STAGE;
|
|
379
|
+
const repaired = run(f, ['--session', 'fake-session']);
|
|
380
|
+
assert.equal(repaired.status, 0, repaired.stderr);
|
|
381
|
+
assert.match(repaired.stdout, /"trained":1,"skipped":2/);
|
|
382
|
+
assert.equal((await trainCycle({ dataDir: f.dataDir, version: 'synthetic-v1' })).skipped, 3);
|
|
383
|
+
evaluatePackageAndVerifyArtifacts(f);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test('calibration failure with stale calibration does not complete a damaged stage', { skip: skipNoColabCli }, async t => {
|
|
387
|
+
const f = fixture(t);
|
|
388
|
+
assert.equal(run(f, ['--session', 'fake-session']).status, 0);
|
|
389
|
+
const intent = stageDir(f, 'intent');
|
|
390
|
+
fs.rmSync(path.join(intent, 'harness-routing-v1.json'));
|
|
391
|
+
f.env.FAKE_COLAB_BAD_CATALOG = 'intent';
|
|
392
|
+
|
|
393
|
+
const failed = run(f, ['--session', 'fake-session']);
|
|
394
|
+
assert.notEqual(failed.status, 0);
|
|
395
|
+
assert.ok(failed.stderr.length);
|
|
396
|
+
assert.equal(fs.existsSync(path.join(intent, 'calibration.json')), true);
|
|
397
|
+
assert.equal(fs.existsSync(path.join(intent, 'harness-routing-v1.json')), false);
|
|
398
|
+
await assertIntentRetryReachesTrainCycle(f);
|
|
399
|
+
|
|
400
|
+
delete f.env.FAKE_COLAB_BAD_CATALOG;
|
|
401
|
+
const repaired = run(f, ['--session', 'fake-session']);
|
|
402
|
+
assert.equal(repaired.status, 0, repaired.stderr);
|
|
403
|
+
assert.match(repaired.stdout, /"trained":1,"skipped":2/);
|
|
404
|
+
assert.equal((await trainCycle({ dataDir: f.dataDir, version: 'synthetic-v1' })).skipped, 3);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test('stale remote status from a failed invocation is rejected despite matching old artifacts', { skip: skipNoColabCli }, t => {
|
|
408
|
+
const f = fixture(t);
|
|
409
|
+
const first = run(f, ['--session', 'fake-session']);
|
|
410
|
+
assert.equal(first.status, 0, first.stderr);
|
|
411
|
+
const statusFile = path.join(f.fakeRoot, 'runs', 'synthetic-v1', 'intent', 'remote-status.json');
|
|
412
|
+
const prior = JSON.parse(fs.readFileSync(statusFile, 'utf8'));
|
|
413
|
+
fs.rmSync(path.join(stageDir(f, 'intent'), 'harness-routing-v1.json'));
|
|
414
|
+
f.env.FAKE_COLAB_FAIL_TASK = 'intent';
|
|
415
|
+
|
|
416
|
+
const failed = run(f, ['--session', 'fake-session']);
|
|
417
|
+
assert.notEqual(failed.status, 0);
|
|
418
|
+
assert.match(failed.stderr, /status identity mismatch/);
|
|
419
|
+
assert.equal(JSON.parse(fs.readFileSync(statusFile, 'utf8')).invocationId, prior.invocationId);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
test('current invocation with a mismatched status manifest digest is rejected', { skip: skipNoColabCli }, t => {
|
|
423
|
+
const f = fixture(t);
|
|
424
|
+
f.env.FAKE_COLAB_STATUS_MANIFEST_SHA256 = '0'.repeat(64);
|
|
425
|
+
const failed = run(f, ['--session', 'fake-session']);
|
|
426
|
+
|
|
427
|
+
assert.notEqual(failed.status, 0);
|
|
428
|
+
assert.match(failed.stderr, /status identity mismatch/);
|
|
429
|
+
const status = JSON.parse(fs.readFileSync(path.join(f.fakeRoot, 'runs', 'synthetic-v1', 'validity', 'remote-status.json'), 'utf8'));
|
|
430
|
+
const uploadedManifestSha256 = logRows(f).find(row => row.uploadedManifestSha256).uploadedManifestSha256;
|
|
431
|
+
assert.match(status.invocationId, /^[0-9a-f-]{36}$/);
|
|
432
|
+
assert.notEqual(status.manifestSha256, uploadedManifestSha256);
|
|
433
|
+
assert.equal(fs.existsSync(path.join(stageDir(f, 'validity'), 'resource-guard.json')), false);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
test('remote runner rejects a self-consistent substituted manifest before starting training', { skip: skipNoColabCli }, t => {
|
|
437
|
+
const root = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-colab-runner-')));
|
|
438
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
439
|
+
const inputs = path.join(root, 'training', 'v1', 'prompts.jsonl');
|
|
440
|
+
fs.mkdirSync(path.dirname(inputs), { recursive: true });
|
|
441
|
+
fs.writeFileSync(inputs, 'substituted input\n');
|
|
442
|
+
const digest = body => crypto.createHash('sha256').update(body).digest('hex');
|
|
443
|
+
const original = { schemaVersion: 1, files: [{ path: 'training/v1/prompts.jsonl', sha256: digest('original input\n') }] };
|
|
444
|
+
const substituted = { schemaVersion: 1, files: [{ path: 'training/v1/prompts.jsonl', sha256: digest('substituted input\n') }] };
|
|
445
|
+
const expectedManifestSha256 = digest(`${JSON.stringify(original, null, 2)}\n`);
|
|
446
|
+
fs.writeFileSync(path.join(root, 'bundle-manifest.json'), `${JSON.stringify(substituted, null, 2)}\n`);
|
|
447
|
+
const trainer = path.join(root, 'trainer.py');
|
|
448
|
+
const marker = path.join(root, 'training-started');
|
|
449
|
+
fs.writeFileSync(trainer, `from pathlib import Path\nPath(${JSON.stringify(marker)}).write_text('started')\n`);
|
|
450
|
+
const script = remoteRunner({ version: 'synthetic-v1', task: 'intent', device: 'cpu', invocationId: 'new-call', expectedManifestSha256 })
|
|
451
|
+
.replace("pathlib.Path('/content')", `pathlib.Path(${JSON.stringify(root)})`)
|
|
452
|
+
.replace(JSON.stringify('/content/scripts/system-one-train.py'), JSON.stringify(trainer));
|
|
453
|
+
const runner = path.join(root, 'runner.py');
|
|
454
|
+
fs.writeFileSync(runner, script);
|
|
455
|
+
|
|
456
|
+
const result = spawnSync('python3', [runner], { encoding: 'utf8' });
|
|
457
|
+
assert.ifError(result.error);
|
|
458
|
+
assert.notEqual(result.status, 0);
|
|
459
|
+
assert.match(result.stderr, /bundle-manifest-mismatch/);
|
|
460
|
+
assert.equal(fs.existsSync(marker), false);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
test('publication failure after replacement removes the stale success guard and permits retry', { skip: skipNoColabCli }, async t => {
|
|
464
|
+
const f = fixture(t);
|
|
465
|
+
assert.equal(run(f, ['--session', 'fake-session']).status, 0);
|
|
466
|
+
const intent = stageDir(f, 'intent');
|
|
467
|
+
fs.rmSync(path.join(intent, 'harness-routing-v1.json'));
|
|
468
|
+
makePublicationFailure(f);
|
|
469
|
+
|
|
470
|
+
const failed = run(f, ['--session', 'fake-session']);
|
|
471
|
+
assert.notEqual(failed.status, 0);
|
|
472
|
+
assert.match(failed.stderr, /injected-final-publication-failure/);
|
|
473
|
+
assert.deepEqual(fs.readFileSync(f.env.FAKE_COLAB_PUBLISH_LOG, 'utf8').trim().split(/\r?\n/),
|
|
474
|
+
['harness-routing-v1.safetensors', 'harness-routing-v1.json']);
|
|
475
|
+
assert.equal(fs.existsSync(path.join(intent, 'resource-guard.json')), false);
|
|
476
|
+
assert.equal(fs.existsSync(path.join(stageDir(f, 'validity'), 'resource-guard.json')), true);
|
|
477
|
+
await assertIntentRetryReachesTrainCycle(f);
|
|
478
|
+
|
|
479
|
+
delete f.env.FAKE_COLAB_FAIL_PUBLISH;
|
|
480
|
+
const repaired = run(f, ['--session', 'fake-session']);
|
|
481
|
+
assert.equal(repaired.status, 0, repaired.stderr);
|
|
482
|
+
assert.match(repaired.stdout, /"trained":1,"skipped":2/);
|
|
483
|
+
assert.equal((await trainCycle({ dataDir: f.dataDir, version: 'synthetic-v1' })).skipped, 3);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test('download failure still stops the Colab session', { skip: skipNoColabCli }, t => {
|
|
487
|
+
const f = fixture(t);
|
|
488
|
+
f.env.FAKE_COLAB_FAIL_DOWNLOAD = '/content/runs/synthetic-v1/validity/harness-routing-v1.safetensors';
|
|
489
|
+
const result = run(f);
|
|
490
|
+
assert.notEqual(result.status, 0);
|
|
491
|
+
const rows = logRows(f);
|
|
492
|
+
assert.equal(rows.at(-1).argv[0], 'stop');
|
|
493
|
+
assert.equal(rows.filter(row => row.argv[0] === 'exec').length, 2);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
test('trainer and stop failures both reach the CLI with an actionable manual stop command', { skip: skipNoColabCli }, t => {
|
|
497
|
+
const f = fixture(t);
|
|
498
|
+
f.env.FAKE_COLAB_FAIL_TASK = 'validity';
|
|
499
|
+
f.env.FAKE_COLAB_FAIL_STOP = '1';
|
|
500
|
+
const result = run(f, ['--session', 'session-563']);
|
|
501
|
+
|
|
502
|
+
assert.notEqual(result.status, 0);
|
|
503
|
+
assert.match(result.stderr, /trainer-failed/);
|
|
504
|
+
assert.match(result.stderr, /injected-stop-failure/);
|
|
505
|
+
assert.match(result.stderr, /session id: session-563/i);
|
|
506
|
+
assert.match(result.stderr, /colab stop -s session-563/);
|
|
507
|
+
assert.equal(logRows(f).at(-1).argv.join(' '), 'stop -s session-563');
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
test('allow-listed input symlinks cannot redirect private raw data to the Colab bundle', t => {
|
|
511
|
+
if (process.platform === 'win32') { t.skip('Windows symlink creation depends on host privileges'); return; }
|
|
512
|
+
const f = fixture(t);
|
|
513
|
+
const allowedPrompt = path.join(f.dataDir, 'training/v1/prompts.jsonl');
|
|
514
|
+
fs.rmSync(allowedPrompt);
|
|
515
|
+
fs.symlinkSync(path.join(f.dataDir, 'training/observed/prompts-observed.jsonl'), allowedPrompt);
|
|
516
|
+
const result = run(f);
|
|
517
|
+
assert.notEqual(result.status, 0);
|
|
518
|
+
assert.match(result.stderr, /invalid allow-listed file training\/v1\/prompts.jsonl/);
|
|
519
|
+
assert.equal(fs.existsSync(f.log), false);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
test('invalid GPU input is rejected before contacting Colab', t => {
|
|
523
|
+
const f = fixture(t);
|
|
524
|
+
const result = run(f, ['--gpu', 'H100']);
|
|
525
|
+
assert.notEqual(result.status, 0);
|
|
526
|
+
assert.match(result.stderr, /--gpu must be T4, L4, or A100/);
|
|
527
|
+
assert.equal(fs.existsSync(f.log), false);
|
|
528
|
+
});
|
|
@@ -2,13 +2,43 @@
|
|
|
2
2
|
const { test } = require('node:test');
|
|
3
3
|
const assert = require('node:assert/strict');
|
|
4
4
|
const { createRequest, validateRequest, validateResponse, decide } = require('../harness-everything/scripts/system-one/contract');
|
|
5
|
+
const { validateVersionManifest } = require('../harness-everything/scripts/system-one/manifest');
|
|
5
6
|
const options = [{ id: 'tier1', text: 'Bounded edit' }, { id: 'tier3', text: 'Architecture' }];
|
|
7
|
+
const hash = 'a'.repeat(64);
|
|
8
|
+
function versionManifest() {
|
|
9
|
+
const stages = {};
|
|
10
|
+
for (const stage of ['validity', 'intent', 'tier']) stages[stage] = {
|
|
11
|
+
weights: stage + '.safetensors', config: stage + '.json', sha256: hash,
|
|
12
|
+
options: ['a', 'b'], thresholds: { a: 0.5, b: 0.6 },
|
|
13
|
+
};
|
|
14
|
+
return { schemaVersion: 1, version: 'v1', createdAt: '2026-11-14T00:00:00Z', stages, evaluation: null };
|
|
15
|
+
}
|
|
6
16
|
const request = () => createRequest('tier', '修正 typo', options);
|
|
7
17
|
function response(req, p = [0.95, 0.05]) {
|
|
8
18
|
return { schemaVersion: 1, requestHash: req.requestHash, catalogHash: req.catalogHash,
|
|
9
19
|
model: { id: 'test', revision: 'test-v1', domain: 'harness-routing-v1' },
|
|
10
20
|
scores: req.options.map((o, i) => ({ id: o.id, probability: p[i] })) };
|
|
11
21
|
}
|
|
22
|
+
test('version manifest permits paired layer metadata and rejects incomplete or malformed layers', () => {
|
|
23
|
+
const legacy = versionManifest();
|
|
24
|
+
assert.equal(validateVersionManifest(legacy), legacy);
|
|
25
|
+
const layered = versionManifest();
|
|
26
|
+
layered.stages.tier.layer = 'tier.layer.json';
|
|
27
|
+
layered.stages.tier.layerSha256 = hash;
|
|
28
|
+
assert.equal(validateVersionManifest(layered), layered);
|
|
29
|
+
for (const mutate of [
|
|
30
|
+
manifest => { delete manifest.stages.tier.layerSha256; },
|
|
31
|
+
manifest => { manifest.stages.tier.layer = '../tier.layer.json'; },
|
|
32
|
+
manifest => { manifest.stages.tier.layer = 'tier.json'; },
|
|
33
|
+
manifest => { manifest.stages.tier.layerSha256 = 'bad'; },
|
|
34
|
+
]) {
|
|
35
|
+
const malformed = versionManifest();
|
|
36
|
+
malformed.stages.tier.layer = 'tier.layer.json';
|
|
37
|
+
malformed.stages.tier.layerSha256 = hash;
|
|
38
|
+
mutate(malformed);
|
|
39
|
+
assert.throws(() => validateVersionManifest(malformed));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
12
42
|
test('S1-C01 complete response, no mutation and repeatability', () => {
|
|
13
43
|
const req = request(); const res = response(req); const before = JSON.stringify({ req, res });
|
|
14
44
|
assert.deepEqual(decide(req, res), { status: 'accepted', reason: 'scored', selectedId: 'tier1', confidence: 0.95, margin: 0.8999999999999999, model: res.model });
|