harness-everything 0.51.0 → 0.53.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/ci.yml +23 -0
- package/CHANGELOG.md +54 -0
- package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-a-evid-001.md +123 -0
- package/benchmarks/results/doc-evidence-e1/cycle-2026-11-11-b-route-001.md +130 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/README.md +7 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-probe.js +16 -0
- package/benchmarks/results/live-host/opencode-2026-11-15-workspace/live-workspace-trace-2026-11-15.jsonl +4 -0
- package/ci/mechanism-2am-observations-session-import.test.js +4 -1
- package/ci/mechanism-2n-opencode-plugin.test.js +1 -1
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +18 -3
- package/ci/mechanism-338-opencode-async.test.js +20 -3
- package/ci/mechanism-34-observations.test.js +127 -23
- package/ci/mechanism-341-opencode-lane.test.js +7 -1
- package/ci/mechanism-349-ci-change-scope.test.js +260 -0
- package/ci/mechanism-397-cycle-import.test.js +399 -0
- package/ci/mechanism-397-host-acceptance.test.js +119 -0
- package/ci/mechanism-397-opencode-observations.test.js +1922 -0
- package/ci/mechanism-handoff-file.test.js +121 -0
- package/ci/mechanism-system-one-contract.test.js +9 -2
- package/ci/mechanism-system-one-curves.test.js +223 -0
- package/ci/mechanism-system-one-cycle.test.js +1204 -0
- package/ci/mechanism-system-one-evaluation.test.js +32 -5
- package/ci/mechanism-system-one-handoff-input.test.js +208 -0
- package/ci/mechanism-system-one-install.test.js +202 -77
- package/ci/mechanism-system-one-live.test.js +361 -0
- package/ci/mechanism-system-one-relevance.test.js +11 -1
- package/ci/mechanism-system-one-train.test.js +136 -53
- package/ci/system-one-adapter-test.py +331 -0
- package/ci/system-one-train-test.py +116 -24
- package/docs/adr/EVID-001.md +123 -0
- package/docs/adr/ROUTE-001-error-lesson-delivery.md +305 -0
- package/docs/governed-index.md +2 -0
- package/docs/platform-capabilities.md +13 -6
- package/docs/routing.md +2 -2
- package/docs/system-one-cycle.md +77 -0
- package/docs/system-one-observations.md +43 -11
- package/docs/system-one-routing.md +163 -115
- package/docs/system-one-suggestion-gates.md +6 -8
- package/docs/system-one-training.md +44 -7
- package/docs/workflow-runtime.md +19 -0
- package/harness-everything/SKILL.md +1 -1
- package/harness-everything/scripts/kernel-router.js +2 -1
- package/harness-everything/scripts/system-one/contract.js +19 -15
- package/harness-everything/scripts/system-one/cua_adapter.py +211 -17
- package/harness-everything/scripts/system-one/evaluate.js +4 -9
- package/harness-everything/scripts/system-one/handoff-input.js +76 -0
- package/harness-everything/scripts/system-one/install.js +281 -113
- package/harness-everything/scripts/system-one/manifest.js +58 -0
- package/harness-everything/scripts/system-one/provider.js +96 -2
- package/harness-everything/scripts/system-one/resident.js +47 -1
- package/harness-everything/scripts/system-one/router.js +80 -1
- package/harness-everything/scripts/tier-router.js +21 -6
- package/hooks/scripts/lib/observations.js +48 -7
- package/opencode-plugin/README.md +22 -8
- package/opencode-plugin/index.mjs +424 -44
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/observations.js +48 -7
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/scripts/handoff-file.js +223 -0
- package/plugins/harness-everything/skills/harness-everything/SKILL.md +1 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/kernel-router.js +2 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/contract.js +19 -15
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/cua_adapter.py +211 -17
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/evaluate.js +4 -9
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/handoff-input.js +76 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/install.js +281 -113
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/manifest.js +58 -0
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/provider.js +96 -2
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/resident.js +47 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/system-one/router.js +80 -1
- package/plugins/harness-everything/skills/harness-everything/scripts/tier-router.js +21 -6
- package/sbom.cdx.json +7 -7
- package/scripts/ci-change-scope.js +59 -0
- package/scripts/handoff-file.js +223 -0
- package/scripts/sync-openai-plugin.js +4 -0
- package/scripts/system-one-calibrate.js +108 -41
- package/scripts/system-one-curves.js +472 -0
- package/scripts/system-one-cycle/adjudication-input.js +65 -0
- package/scripts/system-one-cycle/build.js +165 -0
- package/scripts/system-one-cycle/collect.js +67 -0
- package/scripts/system-one-cycle/common.js +175 -0
- package/scripts/system-one-cycle/engines.js +62 -0
- package/scripts/system-one-cycle/evaluate.js +73 -0
- package/scripts/system-one-cycle/judge.js +106 -0
- package/scripts/system-one-cycle/label.js +59 -0
- package/scripts/system-one-cycle/package.js +173 -0
- package/scripts/system-one-cycle/score.py +111 -0
- package/scripts/system-one-cycle/train.js +136 -0
- package/scripts/system-one-cycle.js +136 -0
- package/scripts/system-one-observations-export.js +58 -6
- package/scripts/system-one-observations-import-store.js +128 -0
- package/scripts/system-one-observations-review.js +4 -5
- package/scripts/system-one-train.py +117 -61
|
@@ -0,0 +1,1204 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawnSync } = require('node:child_process');
|
|
8
|
+
const { test } = require('node:test');
|
|
9
|
+
const { buildDataset } = require('../scripts/system-one-cycle/build');
|
|
10
|
+
const { collect } = require('../scripts/system-one-cycle/collect');
|
|
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');
|
|
14
|
+
const install = require('../harness-everything/scripts/system-one/install');
|
|
15
|
+
const provider = require('../harness-everything/scripts/system-one/provider');
|
|
16
|
+
const router = require('../harness-everything/scripts/system-one/router');
|
|
17
|
+
const { CATALOGS } = require('../harness-everything/scripts/system-one/catalogs');
|
|
18
|
+
|
|
19
|
+
const root = fs.realpathSync.native(path.resolve(__dirname, '..'));
|
|
20
|
+
const cycleCli = path.join(root, 'scripts', 'system-one-cycle.js');
|
|
21
|
+
const cycleTrainerCatalogs = {
|
|
22
|
+
validity: ['invalid'],
|
|
23
|
+
intent: CATALOGS.intent.map(option => option.id),
|
|
24
|
+
tier: CATALOGS.tier.map(option => option.id).filter(id => id !== 'unclassified'),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function outside(rootDir, target) {
|
|
28
|
+
const relative = path.relative(rootDir, target);
|
|
29
|
+
return relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function private446Root(t) {
|
|
33
|
+
const dir = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-446-')));
|
|
34
|
+
assert.ok(outside(root, dir), '446 cycle fixtures must live outside the repository');
|
|
35
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
36
|
+
return dir;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function write446Scorer(dir) {
|
|
40
|
+
const file = path.join(dir, 'sitecustomize.py');
|
|
41
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
42
|
+
fs.writeFileSync(file, [
|
|
43
|
+
'# shortcut: replaces model inference, upgrade when H3 needs model-loading or quality evidence.',
|
|
44
|
+
'import json',
|
|
45
|
+
'import math',
|
|
46
|
+
'import os',
|
|
47
|
+
'import sys',
|
|
48
|
+
`_SCORE_SCRIPT = ${JSON.stringify(path.join(root, 'scripts/system-one-cycle/score.py'))}`,
|
|
49
|
+
"if (sys.argv and os.path.normcase(os.path.realpath(sys.argv[0])) == os.path.normcase(os.path.realpath(_SCORE_SCRIPT)) and os.environ.get('S1_446_FIXTURE') == '1'):",
|
|
50
|
+
' try:',
|
|
51
|
+
" required_env = ('S1_446_CATALOGS', 'S1_446_CALL_LOG', 'S1_446_QUALITY')",
|
|
52
|
+
" if any(name not in os.environ for name in required_env): raise ValueError('fixture scorer environment is incomplete')",
|
|
53
|
+
" names = ('--weights', '--holdout', '--task', '--out')",
|
|
54
|
+
' args = sys.argv[1:]',
|
|
55
|
+
" if len(args) != len(names) * 2: raise ValueError('expected --weights, --holdout, --task, --out exactly once')",
|
|
56
|
+
' values = {}',
|
|
57
|
+
' for name, value in zip(args[::2], args[1::2]):',
|
|
58
|
+
" if name not in names or name in values or not value: raise ValueError('expected --weights, --holdout, --task, --out exactly once')",
|
|
59
|
+
' values[name] = value',
|
|
60
|
+
" if set(values) != set(names): raise ValueError('expected --weights, --holdout, --task, --out exactly once')",
|
|
61
|
+
" if not os.path.isfile(values['--weights']): raise ValueError('fixture scorer weights are unavailable')",
|
|
62
|
+
" if not os.path.isfile(values['--holdout']): raise ValueError('fixture scorer holdout is unavailable')",
|
|
63
|
+
" catalogs = json.loads(os.environ['S1_446_CATALOGS'])",
|
|
64
|
+
" task = values['--task']",
|
|
65
|
+
" if not isinstance(catalogs, dict) or task not in ('validity', 'intent', 'tier') or not isinstance(catalogs.get(task), list) or not catalogs[task] or any(not isinstance(option, str) or not option for option in catalogs[task]): raise ValueError('fixture scorer catalog is invalid')",
|
|
66
|
+
" if len(set(catalogs[task])) != len(catalogs[task]): raise ValueError('fixture scorer catalog has duplicate ids')",
|
|
67
|
+
" quality = float(os.environ['S1_446_QUALITY'])",
|
|
68
|
+
" if not math.isfinite(quality) or not 0 <= quality <= 1: raise ValueError('fixture scorer quality is invalid')",
|
|
69
|
+
" gold = 'actionable' if task == 'validity' else ('fix' if task == 'intent' else 'tier2')",
|
|
70
|
+
" scores = {option: (1 - quality if option == 'invalid' else quality) if task == 'validity' else (quality if option == gold else 0.01) for option in catalogs[task]}",
|
|
71
|
+
" output = values['--out']",
|
|
72
|
+
" os.makedirs(os.path.dirname(os.path.abspath(output)), exist_ok=True)",
|
|
73
|
+
" with open(output, 'w', encoding='utf-8', newline='') as stream: stream.write(json.dumps({'id': 'holdout-' + task, 'gold': gold, 'scores': scores}, separators=(',', ':')) + '\\n')",
|
|
74
|
+
" with open(os.environ['S1_446_CALL_LOG'], 'a', encoding='utf-8', newline='') as stream: stream.write(task + ':holdout\\n')",
|
|
75
|
+
' except Exception as error:',
|
|
76
|
+
" sys.stderr.write('S1_446 fixture scorer: ' + str(error) + '\\n')",
|
|
77
|
+
' sys.stderr.flush()',
|
|
78
|
+
' sys.stdout.flush()',
|
|
79
|
+
' os._exit(2)',
|
|
80
|
+
' sys.stdout.flush()',
|
|
81
|
+
' sys.stderr.flush()',
|
|
82
|
+
' os._exit(0)',
|
|
83
|
+
].join('\n') + '\n', { encoding: 'utf8', mode: 0o700 });
|
|
84
|
+
return {
|
|
85
|
+
python: process.env.PYTHON || (process.platform === 'win32' ? 'python' : 'python3'),
|
|
86
|
+
pythonPath: dir,
|
|
87
|
+
hook: file,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function seed446Candidate(dataDir, version, quality) {
|
|
92
|
+
const runDir = path.join(dataDir, 'training', 'runs', version);
|
|
93
|
+
for (const task of ['validity', 'intent', 'tier']) {
|
|
94
|
+
const stageDir = path.join(runDir, task);
|
|
95
|
+
fs.mkdirSync(stageDir, { recursive: true, mode: 0o700 });
|
|
96
|
+
fs.writeFileSync(path.join(stageDir, 'harness-routing-v1.safetensors'), `synthetic-${version}-${task}`);
|
|
97
|
+
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
|
+
}));
|
|
103
|
+
const gold = task === 'validity' ? 'actionable' : task === 'intent' ? 'fix' : 'tier2';
|
|
104
|
+
const scores = Object.fromEntries(cycleTrainerCatalogs[task].map(id => [id,
|
|
105
|
+
task === 'validity' ? (id === 'invalid' ? 1 - quality : quality) : (id === gold ? quality : 0.01)]));
|
|
106
|
+
writeJsonl(path.join(stageDir, 'val-scores.jsonl'), [{ id: `validation-${task}`, gold, scores }]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function setup446Cycle(t, dataDir, versions, { all = false } = {}) {
|
|
111
|
+
const fixture = syntheticCycle(dataDir);
|
|
112
|
+
if (all) {
|
|
113
|
+
const steps = {
|
|
114
|
+
collect: ['training/observed/prompts-observed.jsonl', 'training/observed/labels-observed.jsonl'],
|
|
115
|
+
label: ['training/relabel-luna/labels.jsonl', 'training/relabel-luna/labels-intent.jsonl'],
|
|
116
|
+
judge: ['training/adjudication/input.jsonl', 'training/adjudication/consensus.jsonl'],
|
|
117
|
+
};
|
|
118
|
+
for (const outputs of Object.values(steps)) {
|
|
119
|
+
for (const relative of outputs) {
|
|
120
|
+
const file = path.join(dataDir, relative);
|
|
121
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
122
|
+
if (!fs.existsSync(file)) fs.writeFileSync(file, '');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
fs.writeFileSync(path.join(dataDir, 'cycle-state.json'), JSON.stringify({ schemaVersion: 1,
|
|
126
|
+
steps: Object.fromEntries(Object.entries(steps).map(([step, outputs]) => [step,
|
|
127
|
+
{ completedAt: '2026-11-17T00:00:00.000Z', outputs }])) }));
|
|
128
|
+
}
|
|
129
|
+
for (const { version, quality } of versions) seed446Candidate(dataDir, version, quality);
|
|
130
|
+
const tmp = path.dirname(dataDir);
|
|
131
|
+
const callLog = path.join(tmp, 'scorer-calls.log');
|
|
132
|
+
const scorer = write446Scorer(tmp);
|
|
133
|
+
return { dataDir, holdout: fixture.holdout, ...scorer, callLog, tmp };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function environment446(fixture, quality = 0.9) {
|
|
137
|
+
const env = {
|
|
138
|
+
...process.env,
|
|
139
|
+
HOME: path.join(fixture.tmp, 'home'),
|
|
140
|
+
USERPROFILE: path.join(fixture.tmp, 'user-profile'),
|
|
141
|
+
HARNESS_STATE_HOME: path.join(fixture.tmp, 'state'),
|
|
142
|
+
HARNESS_OBSERVATIONS_DIR: path.join(fixture.tmp, 'observations'),
|
|
143
|
+
TMPDIR: fixture.tmp,
|
|
144
|
+
PYTHON: fixture.python,
|
|
145
|
+
PYTHONPATH: fixture.pythonPath,
|
|
146
|
+
PYTHONNOUSERSITE: '1',
|
|
147
|
+
PYTHONDONTWRITEBYTECODE: '1',
|
|
148
|
+
S1_446_FIXTURE: '1',
|
|
149
|
+
S1_446_CATALOGS: JSON.stringify(cycleTrainerCatalogs),
|
|
150
|
+
S1_446_CALL_LOG: fixture.callLog,
|
|
151
|
+
S1_446_QUALITY: String(quality),
|
|
152
|
+
};
|
|
153
|
+
delete env.HARNESS_SYSTEM_ONE_MODE;
|
|
154
|
+
delete env.PYTHONHOME;
|
|
155
|
+
return env;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function run446Cycle(fixture, version, { history, quality = 0.9, all = false } = {}) {
|
|
159
|
+
const args = [cycleCli, all ? 'all' : 'evaluate'];
|
|
160
|
+
if (all) args.push('--until', 'evaluate');
|
|
161
|
+
args.push('--data-dir', fixture.dataDir, '--holdout', fixture.holdout, '--version', version);
|
|
162
|
+
if (history === true) args.push('--history');
|
|
163
|
+
else if (history !== undefined) args.push('--history', history);
|
|
164
|
+
return spawnSync(process.execPath, args, { cwd: root, encoding: 'utf8', env: environment446(fixture, quality) });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function rows446(history) {
|
|
168
|
+
return fs.readFileSync(history, 'utf8').split(/\r?\n/).filter(Boolean).map(JSON.parse);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function writeRows446(history, rows, ending = '\n') {
|
|
172
|
+
fs.mkdirSync(path.dirname(history), { recursive: true, mode: 0o700 });
|
|
173
|
+
fs.writeFileSync(history, rows.map(row => JSON.stringify(row)).join('\n') + (rows.length ? ending : ''));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function snapshot446(files) {
|
|
177
|
+
return new Map(files.map(file => [file, fs.readFileSync(file)]));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function assertSnapshot446(snapshot) {
|
|
181
|
+
for (const [file, bytes] of snapshot) assert.deepEqual(fs.readFileSync(file), bytes, `${file} changed`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function evaluation446(dataDir, version) {
|
|
185
|
+
const dir = path.join(dataDir, 'training', 'candidates', version, 'evaluation');
|
|
186
|
+
return {
|
|
187
|
+
curves: JSON.parse(fs.readFileSync(path.join(dir, 'curves.json'), 'utf8')),
|
|
188
|
+
trend: JSON.parse(fs.readFileSync(path.join(dir, 'trend.json'), 'utf8')),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function assertEvaluationNotMarked(dataDir) {
|
|
193
|
+
const stateFile = path.join(dataDir, 'cycle-state.json');
|
|
194
|
+
if (fs.existsSync(stateFile)) assert.equal(JSON.parse(fs.readFileSync(stateFile, 'utf8')).steps?.evaluate, undefined);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function writeJsonl(file, rows) {
|
|
198
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
199
|
+
fs.writeFileSync(file, rows.map(row => JSON.stringify(row)).join('\n') + (rows.length ? '\n' : ''));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function syntheticCycle(dir) {
|
|
203
|
+
const training = path.join(dir, 'training');
|
|
204
|
+
const prompts = [
|
|
205
|
+
{ id: 'agent-dispatch', family: 'family-agent', source: 'agent-dispatch', split: 'train', text: 'synthetic-agent-dispatch-case', previous: 'synthetic-previous-field' },
|
|
206
|
+
{ id: 'agrees', family: 'family-agrees', source: 'observation', split: 'train', text: 'synthetic-agreement-case', previous: 'synthetic-previous-field' },
|
|
207
|
+
{ id: 'legacy-intent-shape', family: 'family-legacy-intent', source: 'observation', split: 'train', text: 'synthetic-legacy-intent-case' },
|
|
208
|
+
{ id: 'intent-majority', family: 'family-intent-majority', source: 'observation', split: 'train', text: 'synthetic-intent-majority-case' },
|
|
209
|
+
{ id: 'intent-no-majority', family: 'family-intent-no-majority', source: 'observation', split: 'train', text: 'synthetic-intent-no-majority-case' },
|
|
210
|
+
{ id: 'tier-only', family: 'family-tier-only', source: 'observation', split: 'train', text: 'synthetic-tier-only-case' },
|
|
211
|
+
{ id: 'writes', family: 'family-writes', source: 'observation', split: 'train', text: 'synthetic-write-evidence-case' },
|
|
212
|
+
{ id: 'vote', family: 'family-vote', source: 'observation', split: 'train', text: 'synthetic-majority-vote-case' },
|
|
213
|
+
{ id: 'null-vote', family: 'family-null-vote', source: 'observation', split: 'train', text: 'synthetic-null-consensus-case' },
|
|
214
|
+
{ id: 'validity-conflict', family: 'family-validity-conflict', source: 'observation', split: 'train', text: 'synthetic-validity-conflict-case' },
|
|
215
|
+
{ id: 'split-train', family: 'family-split-train', source: 'observation', split: 'train', text: 'same normalized synthetic phrase' },
|
|
216
|
+
{ id: 'split-validation', family: 'family-split-validation', source: 'observation', split: 'validation', text: 'Same, normalized synthetic phrase!' },
|
|
217
|
+
{ id: 'no-majority', family: 'family-no-majority', source: 'observation', split: 'train', text: 'synthetic-no-majority-case' },
|
|
218
|
+
{ id: 'no-vote', family: 'family-no-vote', source: 'observation', split: 'train', text: 'synthetic-missing-vote-case' },
|
|
219
|
+
{ id: 'holdout-copy', family: 'family-holdout', source: 'observation', split: 'train', text: 'holdout only synthetic sentinel' },
|
|
220
|
+
{ id: 'invalid', family: 'family-invalid', source: 'observation', split: 'train', text: 'synthetic-context-dependent-case' },
|
|
221
|
+
];
|
|
222
|
+
writeJsonl(path.join(training, 'observed/prompts-observed.jsonl'), prompts);
|
|
223
|
+
writeJsonl(path.join(training, 'observed/labels-observed.jsonl'), [
|
|
224
|
+
{ id: 'agrees', tier: 'tier2', intents: ['feature'], contextDependent: true, contradictions: [], behaviorEvidence: 'unobserved' },
|
|
225
|
+
{ id: 'legacy-intent-shape', tier: 'tier2', contradictions: [], behaviorEvidence: 'unobserved' },
|
|
226
|
+
{ id: 'intent-majority', tier: 'tier2', intents: ['fix'], contradictions: [], behaviorEvidence: 'unobserved' },
|
|
227
|
+
{ id: 'intent-no-majority', tier: 'tier2', intents: ['edit'], contradictions: [], behaviorEvidence: 'unobserved' },
|
|
228
|
+
{ id: 'tier-only', tier: 'tier1', intents: ['review'], contradictions: [], behaviorEvidence: 'unobserved' },
|
|
229
|
+
{ id: 'writes', tier: 'tier1', intents: ['feature'], contextDependent: true, contradictions: ['tier1-with-writes'], behaviorEvidence: 'observed' },
|
|
230
|
+
{ id: 'vote', tier: 'tier1', intents: ['feature'], contextDependent: true, contradictions: [], behaviorEvidence: 'unobserved' },
|
|
231
|
+
{ id: 'null-vote', tier: 'tier2', intents: ['feature'], contextDependent: false, contradictions: [], behaviorEvidence: 'unobserved' },
|
|
232
|
+
{ id: 'validity-conflict', tier: 'tier2', intents: [], contextDependent: true, contradictions: [], behaviorEvidence: 'unobserved' },
|
|
233
|
+
{ id: 'split-train', tier: 'tier2', intents: ['feature'], contextDependent: false, contradictions: [], behaviorEvidence: 'observed' },
|
|
234
|
+
{ id: 'split-validation', tier: 'tier2', intents: ['feature'], contextDependent: false, contradictions: [], behaviorEvidence: 'observed' },
|
|
235
|
+
{ id: 'no-majority', tier: 'tier1', intents: ['feature'], contextDependent: false, contradictions: [], behaviorEvidence: 'observed' },
|
|
236
|
+
{ id: 'no-vote', tier: 'tier1', intents: ['feature'], contextDependent: false, contradictions: [], behaviorEvidence: 'observed' },
|
|
237
|
+
{ id: 'invalid', tier: null, intents: [], contextDependent: true, contradictions: [], behaviorEvidence: 'unobserved' },
|
|
238
|
+
]);
|
|
239
|
+
writeJsonl(path.join(training, 'relabel-luna/labels.jsonl'), [
|
|
240
|
+
...['agent-dispatch', 'agrees', 'legacy-intent-shape', 'intent-majority', 'intent-no-majority', 'writes', 'split-train', 'split-validation'].map(id => ({ id, gold: id === 'writes' ? 'tier1' : id === 'agrees' || id === 'legacy-intent-shape' || id.startsWith('intent-') || id.startsWith('split') ? 'tier2' : 'tier3' })),
|
|
241
|
+
{ id: 'tier-only', gold: 'tier2' },
|
|
242
|
+
{ id: 'vote', gold: 'tier2' }, { id: 'null-vote', gold: 'tier1' }, { id: 'validity-conflict', gold: null },
|
|
243
|
+
{ id: 'no-majority', gold: 'tier2' }, { id: 'no-vote', gold: 'tier2' },
|
|
244
|
+
{ id: 'holdout-copy', gold: 'tier2' }, { id: 'invalid', gold: null },
|
|
245
|
+
]);
|
|
246
|
+
writeJsonl(path.join(training, 'relabel-luna/labels-intent.jsonl'), prompts.map(row => ({
|
|
247
|
+
id: row.id,
|
|
248
|
+
gold: row.id === 'invalid' || row.id === 'holdout-copy' || row.id === 'validity-conflict' ? null
|
|
249
|
+
: row.id === 'intent-no-majority' ? 'explain' : row.id === 'tier-only' ? 'review'
|
|
250
|
+
: row.id === 'legacy-intent-shape' ? 'explain' : 'feature',
|
|
251
|
+
secondary: [],
|
|
252
|
+
})));
|
|
253
|
+
writeJsonl(path.join(training, 'adjudication/consensus.jsonl'), [
|
|
254
|
+
{ id: 'vote', status: 'majority', consensus: 'tier3', votes: [{ judge: 'luna', tier: 'tier3' }, { judge: 'opencode', tier: 'tier3' }] },
|
|
255
|
+
{ id: 'intent-majority', status: 'majority', consensus: 'tier2', intentStatus: 'majority', intentConsensus: 'fix',
|
|
256
|
+
votes: [{ judge: 'luna', tier: 'tier2', intent: 'fix' }, { judge: 'opencode', tier: 'tier2', intent: 'fix' }] },
|
|
257
|
+
{ id: 'intent-no-majority', status: 'majority', consensus: 'tier2', intentStatus: 'no-majority', intentConsensus: null,
|
|
258
|
+
votes: [{ judge: 'luna', tier: 'tier2', intent: 'edit' }, { judge: 'opencode', tier: 'tier2', intent: 'feature' }] },
|
|
259
|
+
{ id: 'tier-only', status: 'majority', consensus: 'tier3',
|
|
260
|
+
votes: [{ judge: 'luna', tier: 'tier3' }, { judge: 'opencode', tier: 'tier3' }] },
|
|
261
|
+
{ id: 'null-vote', status: 'unanimous', consensus: null, votes: [{ judge: 'luna', tier: null }, { judge: 'opencode', tier: null }] },
|
|
262
|
+
{ id: 'validity-conflict', status: 'majority', consensus: 'tier2', votes: [{ judge: 'luna', tier: 'tier2' }, { judge: 'opencode', tier: 'tier2' }] },
|
|
263
|
+
{ id: 'no-majority', status: 'no-majority', consensus: null, votes: [{ judge: 'luna', tier: 'tier2' }, { judge: 'opencode', tier: 'tier3' }] },
|
|
264
|
+
]);
|
|
265
|
+
const holdout = path.join(dir, 'holdout.json');
|
|
266
|
+
fs.writeFileSync(holdout, JSON.stringify({ schemaVersion: 1, cases: [{ request: { context: 'holdout-only synthetic sentinel' } }] }));
|
|
267
|
+
return { training, holdout };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function assertNoDatasetOutputs(...dirs) {
|
|
271
|
+
for (const dir of dirs) {
|
|
272
|
+
for (const file of ['prompts.jsonl', 'labels.jsonl', 'labels-intent.jsonl', 'report.json']) {
|
|
273
|
+
assert.equal(fs.existsSync(path.join(dir, file)), false, `unexpected dataset output ${file}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
test('cycle dataset uses text-only labels, consensus, behavior evidence, holdout fields, and private prompt elision', t => {
|
|
279
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-build-'));
|
|
280
|
+
try {
|
|
281
|
+
const fixture = syntheticCycle(dir);
|
|
282
|
+
const report = buildDataset({ dataDir: dir, holdoutFiles: [fixture.holdout] });
|
|
283
|
+
const output = path.join(fixture.training, 'v1');
|
|
284
|
+
const prompts = fs.readFileSync(path.join(output, 'prompts.jsonl'), 'utf8').trim().split('\n').map(JSON.parse);
|
|
285
|
+
const labels = new Map(fs.readFileSync(path.join(output, 'labels.jsonl'), 'utf8').trim().split('\n').map(JSON.parse).map(row => [row.id, row.gold]));
|
|
286
|
+
const validityLabels = new Map(fs.readFileSync(path.join(fixture.training, 'v1-validity/labels.jsonl'), 'utf8').trim().split('\n').map(JSON.parse).map(row => [row.id, row.gold]));
|
|
287
|
+
const intents = new Map(fs.readFileSync(path.join(output, 'labels-intent.jsonl'), 'utf8').trim().split('\n').map(JSON.parse).map(row => [row.id, row]));
|
|
288
|
+
const ids = new Set(prompts.map(row => row.id));
|
|
289
|
+
|
|
290
|
+
assert.equal(ids.has('agent-dispatch'), true);
|
|
291
|
+
assert.equal(labels.get('agrees'), 'tier2');
|
|
292
|
+
assert.equal(intents.get('agrees').gold, 'feature');
|
|
293
|
+
assert.equal(intents.get('legacy-intent-shape').gold, 'explain');
|
|
294
|
+
assert.equal(labels.get('vote'), 'tier3');
|
|
295
|
+
assert.equal(labels.get('null-vote'), null);
|
|
296
|
+
assert.equal(labels.get('validity-conflict'), 'tier2');
|
|
297
|
+
assert.equal(validityLabels.get('validity-conflict'), null);
|
|
298
|
+
assert.equal(labels.has('intent-no-majority'), true);
|
|
299
|
+
assert.equal(validityLabels.get('intent-no-majority'), 'tier2');
|
|
300
|
+
assert.equal(labels.get('tier-only'), 'tier3');
|
|
301
|
+
assert.equal(labels.get('writes'), 'tier2');
|
|
302
|
+
assert.equal(labels.has('no-majority'), false);
|
|
303
|
+
assert.equal(labels.has('no-vote'), false);
|
|
304
|
+
assert.equal(labels.has('holdout-copy'), false);
|
|
305
|
+
assert.equal(labels.has('split-train'), false);
|
|
306
|
+
assert.equal(labels.has('split-validation'), true);
|
|
307
|
+
assert.equal(labels.get('invalid'), null);
|
|
308
|
+
assert.deepEqual(intents.get('invalid'), { id: 'invalid', gold: null, secondary: [] });
|
|
309
|
+
assert.equal(intents.get('intent-majority').gold, 'fix');
|
|
310
|
+
assert.equal(intents.has('intent-no-majority'), false);
|
|
311
|
+
assert.equal(intents.get('tier-only').gold, 'review');
|
|
312
|
+
assert.ok(prompts.every(row => Object.keys(row).sort().join(',') === 'family,id,source,split,text'));
|
|
313
|
+
assert.equal(fs.readFileSync(path.join(output, 'report.json'), 'utf8').includes('synthetic-'), false);
|
|
314
|
+
assert.equal(report.droppedByReason['no-majority'], 1);
|
|
315
|
+
assert.equal(report.droppedByReason['intent-no-majority'], 1);
|
|
316
|
+
assert.equal(report.droppedByReason['no-vote'], 1);
|
|
317
|
+
} finally {
|
|
318
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('collect preserves self-reported intents from the actual session export shape', t => {
|
|
323
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-collect-'));
|
|
324
|
+
const sessions = path.join(dir, 'sessions');
|
|
325
|
+
const home = path.join(dir, 'home');
|
|
326
|
+
const liveStore = path.join(dir, 'live-observations');
|
|
327
|
+
const envKeys = ['HOME', 'USERPROFILE', 'HARNESS_OBSERVATIONS_DIR'];
|
|
328
|
+
const previousEnv = Object.fromEntries(envKeys.map(key => [key, process.env[key]]));
|
|
329
|
+
fs.mkdirSync(home);
|
|
330
|
+
fs.mkdirSync(liveStore);
|
|
331
|
+
Object.assign(process.env, { HOME: home, USERPROFILE: home, HARNESS_OBSERVATIONS_DIR: liveStore });
|
|
332
|
+
try {
|
|
333
|
+
fs.mkdirSync(sessions, { recursive: true });
|
|
334
|
+
const startedAt = new Date(Date.now() - 60_000).toISOString();
|
|
335
|
+
const completedAt = new Date(Date.now() - 30_000).toISOString();
|
|
336
|
+
const label = { v: 1, validity: 'actionable', tier: 'tier2', intents: ['fix', 'explain'], workflow: null, skills: [] };
|
|
337
|
+
const session = [
|
|
338
|
+
{ type: 'session_meta', payload: { session_id: 'synthetic-collect-session' } },
|
|
339
|
+
{ type: 'event_msg', timestamp: startedAt, payload: { type: 'task_started', turn_id: 'synthetic-turn', started_at: startedAt } },
|
|
340
|
+
{ type: 'response_item', timestamp: startedAt, payload: { type: 'message', role: 'user', content: [{ type: 'input_text', text: 'synthetic collect intent case' }] } },
|
|
341
|
+
{ type: 'event_msg', timestamp: completedAt, payload: { type: 'task_complete', turn_id: 'synthetic-turn', completed_at: completedAt,
|
|
342
|
+
last_agent_message: `Synthetic response\n<!-- harness-label ${JSON.stringify(label)} -->` } },
|
|
343
|
+
];
|
|
344
|
+
fs.writeFileSync(path.join(sessions, 'synthetic.jsonl'), session.map(row => JSON.stringify(row)).join('\n') + '\n');
|
|
345
|
+
const since = new Date(Date.now() - 86_400_000).toISOString().slice(0, 10);
|
|
346
|
+
const dataDir = path.join(dir, 'cycle');
|
|
347
|
+
|
|
348
|
+
collect({ dataDir, since, sessionsDir: sessions });
|
|
349
|
+
|
|
350
|
+
const labels = fs.readFileSync(path.join(dataDir, 'training/observed/labels-observed.jsonl'), 'utf8')
|
|
351
|
+
.trim().split('\n').map(JSON.parse);
|
|
352
|
+
assert.equal(labels.length, 1);
|
|
353
|
+
assert.deepEqual(labels[0].intents, ['fix', 'explain']);
|
|
354
|
+
} finally {
|
|
355
|
+
for (const [key, value] of Object.entries(previousEnv)) {
|
|
356
|
+
if (value === undefined) delete process.env[key];
|
|
357
|
+
else process.env[key] = value;
|
|
358
|
+
}
|
|
359
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('cycle dataset rejects direct, aliased, and unresolved checkout destinations before writing either output', t => {
|
|
364
|
+
for (const aliasKind of ['direct', 'ancestor', 'leaf', 'unresolved']) {
|
|
365
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-private-destination-'));
|
|
366
|
+
const forbidden = fs.mkdtempSync(path.join(root, 'ci', '.s1-f9-forbidden-'));
|
|
367
|
+
let alias;
|
|
368
|
+
try {
|
|
369
|
+
const fixture = syntheticCycle(dir);
|
|
370
|
+
let validityOutDir = forbidden;
|
|
371
|
+
if (aliasKind !== 'direct') {
|
|
372
|
+
alias = path.join(dir, `forbidden-${aliasKind}`);
|
|
373
|
+
try { fs.symlinkSync(aliasKind === 'unresolved' ? path.join(forbidden, 'missing-target') : forbidden, alias, 'dir'); }
|
|
374
|
+
catch (error) {
|
|
375
|
+
if (['EACCES', 'EPERM', 'ENOSYS', 'ENOTSUP'].includes(error.code)) {
|
|
376
|
+
t.skip(`directory symlinks unavailable: ${error.code}`);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
throw error;
|
|
380
|
+
}
|
|
381
|
+
validityOutDir = aliasKind === 'leaf' ? alias : path.join(alias, 'missing', 'validity');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const safeOutput = path.join(dir, 'safe-output');
|
|
385
|
+
if (aliasKind === 'unresolved') {
|
|
386
|
+
assert.throws(() => buildDataset({ dataDir: dir, holdoutFiles: [fixture.holdout],
|
|
387
|
+
outDir: safeOutput, validityOutDir }), error => error.code === 'ENOENT');
|
|
388
|
+
} else {
|
|
389
|
+
assert.throws(() => buildDataset({ dataDir: dir, holdoutFiles: [fixture.holdout],
|
|
390
|
+
outDir: safeOutput, validityOutDir }), /outside the repository/);
|
|
391
|
+
}
|
|
392
|
+
assertNoDatasetOutputs(safeOutput, forbidden);
|
|
393
|
+
} finally {
|
|
394
|
+
if (alias) fs.rmSync(alias, { recursive: true, force: true });
|
|
395
|
+
fs.rmSync(forbidden, { recursive: true, force: true });
|
|
396
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
test('cycle dataset accepts an external data directory through an external symlink alias', t => {
|
|
402
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-external-alias-'));
|
|
403
|
+
const dataDir = path.join(dir, 'data');
|
|
404
|
+
const alias = path.join(dir, 'data-alias');
|
|
405
|
+
try {
|
|
406
|
+
const fixture = syntheticCycle(dataDir);
|
|
407
|
+
try { fs.symlinkSync(dataDir, alias, 'dir'); }
|
|
408
|
+
catch (error) {
|
|
409
|
+
if (['EACCES', 'EPERM', 'ENOSYS', 'ENOTSUP'].includes(error.code)) {
|
|
410
|
+
t.skip(`directory symlinks unavailable: ${error.code}`);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
buildDataset({ dataDir: alias, holdoutFiles: [fixture.holdout] });
|
|
417
|
+
assert.equal(fs.existsSync(path.join(dataDir, 'training', 'v1', 'prompts.jsonl')), true);
|
|
418
|
+
} finally {
|
|
419
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test('cycle dataset keeps the .s1-work exception tied to the canonical synthetic destination', t => {
|
|
424
|
+
const base = path.join(root, '.s1-work');
|
|
425
|
+
fs.mkdirSync(base, { recursive: true });
|
|
426
|
+
const dataDir = fs.mkdtempSync(path.join(base, 'f9-canonical-exception-'));
|
|
427
|
+
const alias = path.join(os.tmpdir(), `system-one-cycle-s1-work-alias-${process.pid}`);
|
|
428
|
+
try {
|
|
429
|
+
const fixture = syntheticCycle(dataDir);
|
|
430
|
+
const promptFile = path.join(fixture.training, 'observed', 'prompts-observed.jsonl');
|
|
431
|
+
const prompts = fs.readFileSync(promptFile, 'utf8').trim().split('\n').map(JSON.parse)
|
|
432
|
+
.map(row => ({ ...row, text: 'agent request without the fixture marker' }));
|
|
433
|
+
writeJsonl(promptFile, prompts);
|
|
434
|
+
try { fs.symlinkSync(dataDir, alias, 'dir'); }
|
|
435
|
+
catch (error) {
|
|
436
|
+
if (['EACCES', 'EPERM', 'ENOSYS', 'ENOTSUP'].includes(error.code)) {
|
|
437
|
+
t.skip(`directory symlinks unavailable: ${error.code}`);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
throw error;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
assert.throws(() => buildDataset({ dataDir: alias, holdoutFiles: [fixture.holdout] }), /synthetic fixture rows/);
|
|
444
|
+
assertNoDatasetOutputs(path.join(dataDir, 'training', 'v1'), path.join(dataDir, 'training', 'v1-validity'));
|
|
445
|
+
} finally {
|
|
446
|
+
fs.rmSync(alias, { recursive: true, force: true });
|
|
447
|
+
fs.rmSync(dataDir, { recursive: true, force: true });
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test('cycle dataset requires the real holdout request.context field', t => {
|
|
452
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-holdout-'));
|
|
453
|
+
try {
|
|
454
|
+
const fixture = syntheticCycle(dir);
|
|
455
|
+
fs.writeFileSync(fixture.holdout, JSON.stringify({ schemaVersion: 1, cases: [{ request: { task: 'tier' } }] }));
|
|
456
|
+
assert.throws(() => buildDataset({ dataDir: dir, holdoutFiles: [fixture.holdout] }), /request\.context/);
|
|
457
|
+
} finally {
|
|
458
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test('cycle dataset rejects duplicate observed prompt ids', t => {
|
|
463
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-duplicate-'));
|
|
464
|
+
try {
|
|
465
|
+
const fixture = syntheticCycle(dir);
|
|
466
|
+
const promptsFile = path.join(fixture.training, 'observed/prompts-observed.jsonl');
|
|
467
|
+
const prompts = fs.readFileSync(promptsFile, 'utf8').trim().split('\n').map(JSON.parse);
|
|
468
|
+
writeJsonl(promptsFile, [...prompts, { ...prompts[0], text: 'synthetic-duplicate-id-case' }]);
|
|
469
|
+
assert.throws(() => buildDataset({ dataDir: dir, holdoutFiles: [fixture.holdout] }), /duplicate prompt id/);
|
|
470
|
+
} finally {
|
|
471
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
test('judge resumes completed rows and records no-majority without prompt text', async t => {
|
|
476
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-judge-'));
|
|
477
|
+
try {
|
|
478
|
+
const training = path.join(dir, 'training');
|
|
479
|
+
writeJsonl(path.join(training, 'observed/prompts-observed.jsonl'), [
|
|
480
|
+
{ id: 'done', family: 'f1', source: 'observation', split: 'train', text: 'synthetic-completed-case', previous: 'synthetic-private-context' },
|
|
481
|
+
{ id: 'todo', family: 'f2', source: 'observation', split: 'train', text: 'synthetic-pending-case', previous: 'synthetic-private-context' },
|
|
482
|
+
{ id: 'intent-only', family: 'f3', source: 'observation', split: 'train', text: 'synthetic-intent-disagreement-case' },
|
|
483
|
+
{ id: 'tier-only-no-intent-label', family: 'f4', source: 'observation', split: 'train', text: 'synthetic-tier-disagreement-case' },
|
|
484
|
+
]);
|
|
485
|
+
writeJsonl(path.join(training, 'observed/labels-observed.jsonl'), [
|
|
486
|
+
{ id: 'done', tier: 'tier1', intents: ['feature'] }, { id: 'todo', tier: 'tier1', intents: ['feature'] },
|
|
487
|
+
{ id: 'intent-only', tier: 'tier2', intents: ['fix'] },
|
|
488
|
+
{ id: 'tier-only-no-intent-label', tier: 'tier1', intents: ['feature'] },
|
|
489
|
+
]);
|
|
490
|
+
writeJsonl(path.join(training, 'relabel-luna/labels.jsonl'), [
|
|
491
|
+
{ id: 'done', gold: 'tier2' }, { id: 'todo', gold: 'tier2' }, { id: 'intent-only', gold: 'tier2' },
|
|
492
|
+
{ id: 'tier-only-no-intent-label', gold: 'tier2' },
|
|
493
|
+
]);
|
|
494
|
+
writeJsonl(path.join(training, 'relabel-luna/labels-intent.jsonl'), [
|
|
495
|
+
{ id: 'done', gold: 'feature', secondary: [] }, { id: 'todo', gold: 'feature', secondary: [] },
|
|
496
|
+
{ id: 'intent-only', gold: 'feature', secondary: [] },
|
|
497
|
+
]);
|
|
498
|
+
writeJsonl(path.join(training, 'adjudication/consensus.jsonl'), [
|
|
499
|
+
{ id: 'done', status: 'majority', consensus: 'tier2', votes: [{ judge: 'luna', tier: 'tier2' }, { judge: 'opencode', tier: 'tier2' }] },
|
|
500
|
+
]);
|
|
501
|
+
const calls = [];
|
|
502
|
+
const report = await judgeRows({ dataDir: dir, runJudge: async (engine, batch) => {
|
|
503
|
+
calls.push(engine);
|
|
504
|
+
assert.deepEqual(batch.map(row => row.id), ['todo', 'intent-only', 'tier-only-no-intent-label']);
|
|
505
|
+
return batch.map((row, i) => ({ i,
|
|
506
|
+
tier: row.id === 'intent-only' ? 'tier2' : (engine === 'luna' ? 'tier2' : 'tier3'),
|
|
507
|
+
...(row.selfIntent === undefined ? {} : { intent: 'fix' }),
|
|
508
|
+
}));
|
|
509
|
+
} });
|
|
510
|
+
const saved = fs.readFileSync(path.join(training, 'adjudication/consensus.jsonl'), 'utf8');
|
|
511
|
+
const rows = saved.trim().split('\n').map(JSON.parse);
|
|
512
|
+
const input = fs.readFileSync(path.join(training, 'adjudication/input.jsonl'), 'utf8').trim().split('\n').map(JSON.parse);
|
|
513
|
+
|
|
514
|
+
assert.deepEqual(calls, ['luna', 'opencode']);
|
|
515
|
+
assert.equal(report.voted, 3);
|
|
516
|
+
assert.equal(rows.find(row => row.id === 'todo').status, 'no-majority');
|
|
517
|
+
assert.equal(rows.find(row => row.id === 'intent-only').intentStatus, 'majority');
|
|
518
|
+
assert.equal(rows.find(row => row.id === 'intent-only').intentConsensus, 'fix');
|
|
519
|
+
assert.equal(saved.includes('synthetic-'), false);
|
|
520
|
+
assert.deepEqual(input.map(row => row.id), ['done', 'todo', 'intent-only', 'tier-only-no-intent-label']);
|
|
521
|
+
assert.equal(new Set(input.map(row => row.id)).size, input.length);
|
|
522
|
+
assert.deepEqual(Object.keys(input[0]).sort(), ['id', 'lunaTier', 'selfTier', 'text']);
|
|
523
|
+
assert.deepEqual(Object.keys(input.find(row => row.id === 'intent-only')).sort(),
|
|
524
|
+
['id', 'lunaIntent', 'lunaTier', 'selfIntent', 'selfTier', 'text']);
|
|
525
|
+
assert.deepEqual(Object.keys(input.find(row => row.id === 'tier-only-no-intent-label')).sort(),
|
|
526
|
+
['id', 'lunaTier', 'selfTier', 'text']);
|
|
527
|
+
} finally {
|
|
528
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
test('resource guard kills an over-limit child and records peak RSS', async () => {
|
|
533
|
+
let samples = 0;
|
|
534
|
+
let rssReader;
|
|
535
|
+
try { processTreeRssMb(process.pid); rssReader = processTreeRssMb; }
|
|
536
|
+
catch { rssReader = () => (++samples === 1 ? 48 : 128); }
|
|
537
|
+
const result = await runGuarded(process.execPath, ['-e', 'const b=Buffer.allocUnsafe(160*1024*1024); for(let i=0;i<b.length;i+=4096)b[i]=1; const {spawn}=require("node:child_process"); spawn(process.execPath,["-e","setInterval(()=>{},1000)"],{stdio:"ignore"}); setInterval(()=>{},1000);'], {
|
|
538
|
+
maxRssMb: 96, threads: 4, pollMs: 100, rssReader,
|
|
539
|
+
});
|
|
540
|
+
assert.equal(result.killedForLimit, true);
|
|
541
|
+
assert.ok(result.peakRssMb > 96);
|
|
542
|
+
assert.equal(result.monitorFailed, false);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
test('package writes the contract B manifest and carries evaluation into the private version directory', t => {
|
|
546
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-package-'));
|
|
547
|
+
try {
|
|
548
|
+
const version = 'synthetic-v1';
|
|
549
|
+
const runs = path.join(dir, 'training', 'runs', version);
|
|
550
|
+
const catalogs = trainerCatalogs();
|
|
551
|
+
const thresholds = Object.fromEntries(Object.entries(catalogs).map(([task, options]) => [task,
|
|
552
|
+
Object.fromEntries(options.map(id => [id, id === 'unclassified' ? null : 0.5]))]));
|
|
553
|
+
for (const [task, values] of Object.entries(thresholds)) {
|
|
554
|
+
const stage = path.join(runs, task);
|
|
555
|
+
fs.mkdirSync(stage, { recursive: true });
|
|
556
|
+
fs.writeFileSync(path.join(stage, 'harness-routing-v1.safetensors'), `${task}-weights`);
|
|
557
|
+
fs.writeFileSync(path.join(stage, 'harness-routing-v1.json'), JSON.stringify({ context_tokens: 1024 }));
|
|
558
|
+
fs.writeFileSync(path.join(stage, 'calibration.json'), JSON.stringify({ thresholds: values }));
|
|
559
|
+
}
|
|
560
|
+
const candidate = path.join(dir, 'training', 'candidates', version);
|
|
561
|
+
buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir: candidate });
|
|
562
|
+
fs.mkdirSync(path.join(candidate, 'evaluation'), { recursive: true });
|
|
563
|
+
fs.writeFileSync(path.join(candidate, 'evaluation', 'curves.json'), '{}\n');
|
|
564
|
+
fs.writeFileSync(path.join(candidate, 'evaluation', 'trend.json'), '{}\n');
|
|
565
|
+
|
|
566
|
+
const output = path.join(dir, 'training', 'versions', version);
|
|
567
|
+
buildVersion({ dataDir: dir, version, sourceDir: candidate, versionDir: output });
|
|
568
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(output, 'manifest.json'), 'utf8'));
|
|
569
|
+
|
|
570
|
+
assert.deepEqual(Object.keys(manifest).sort(), ['createdAt', 'evaluation', 'schemaVersion', 'stages', 'version']);
|
|
571
|
+
assert.equal(manifest.schemaVersion, 1);
|
|
572
|
+
assert.equal(manifest.version, version);
|
|
573
|
+
assert.equal(manifest.evaluation, 'evaluation/curves.json');
|
|
574
|
+
assert.deepEqual(manifest.stages.validity.options, catalogs.validity);
|
|
575
|
+
assert.deepEqual(manifest.stages.intent.options, catalogs.intent);
|
|
576
|
+
assert.ok(manifest.stages.intent.options.includes('unclassified'));
|
|
577
|
+
assert.deepEqual(Object.keys(manifest.stages.intent.thresholds), catalogs.intent);
|
|
578
|
+
assert.equal(manifest.stages.intent.thresholds.unclassified, 1);
|
|
579
|
+
assert.ok(manifest.stages.intent.referenceOnly.includes('unclassified'));
|
|
580
|
+
assert.deepEqual(manifest.stages.tier.thresholds, thresholds.tier);
|
|
581
|
+
assert.deepEqual(Object.keys(manifest.stages.tier.thresholds), catalogs.tier);
|
|
582
|
+
assert.match(manifest.stages.intent.sha256, /^[0-9a-f]{64}$/);
|
|
583
|
+
assert.equal(fs.existsSync(path.join(output, 'evaluation', 'trend.json')), true);
|
|
584
|
+
assert.equal('referenceOnly' in manifest.stages.validity, false);
|
|
585
|
+
} finally {
|
|
586
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
function writePackageRuns(dir, version, calibrationByTask) {
|
|
591
|
+
const runs = path.join(dir, 'training', 'runs', version);
|
|
592
|
+
for (const [task, values] of Object.entries(calibrationByTask)) {
|
|
593
|
+
const stage = path.join(runs, task);
|
|
594
|
+
fs.mkdirSync(stage, { recursive: true });
|
|
595
|
+
fs.writeFileSync(path.join(stage, 'harness-routing-v1.safetensors'), `${task}-weights`);
|
|
596
|
+
fs.writeFileSync(path.join(stage, 'harness-routing-v1.json'), JSON.stringify({ context_tokens: 1024 }));
|
|
597
|
+
fs.writeFileSync(path.join(stage, 'calibration.json'), JSON.stringify({ thresholds: values }));
|
|
598
|
+
}
|
|
599
|
+
return runs;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function trainerThresholds(value = 0.5) {
|
|
603
|
+
return Object.fromEntries(Object.entries(trainerCatalogs()).map(([task, options]) => [task,
|
|
604
|
+
Object.fromEntries(options.map(id => [id, id === 'unclassified' ? null : value]))]));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
test('package turns a null calibration threshold into 1 and carries referenceOnly through repackaging', t => {
|
|
608
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-package-null-'));
|
|
609
|
+
try {
|
|
610
|
+
const version = 'synthetic-null-v1';
|
|
611
|
+
const thresholds = trainerThresholds();
|
|
612
|
+
thresholds.tier.tier2 = null;
|
|
613
|
+
const runs = writePackageRuns(dir, version, thresholds);
|
|
614
|
+
const candidate = path.join(dir, 'training', 'candidates', version);
|
|
615
|
+
buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir: candidate });
|
|
616
|
+
const candidateManifest = JSON.parse(fs.readFileSync(path.join(candidate, 'manifest.json'), 'utf8'));
|
|
617
|
+
assert.equal(candidateManifest.stages.tier.thresholds.tier2, 1);
|
|
618
|
+
assert.deepEqual(candidateManifest.stages.tier.referenceOnly, ['tier2']);
|
|
619
|
+
|
|
620
|
+
const output = path.join(dir, 'training', 'versions', version);
|
|
621
|
+
buildVersion({ dataDir: dir, version, sourceDir: candidate, versionDir: output });
|
|
622
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(output, 'manifest.json'), 'utf8'));
|
|
623
|
+
assert.equal(manifest.stages.tier.thresholds.tier2, 1);
|
|
624
|
+
assert.deepEqual(manifest.stages.tier.referenceOnly, ['tier2']);
|
|
625
|
+
assert.equal('referenceOnly' in manifest.stages.validity, false);
|
|
626
|
+
} finally {
|
|
627
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
test('package restores omitted unclassified metadata from a prior candidate without retraining', t => {
|
|
632
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-package-legacy-catalog-'));
|
|
633
|
+
try {
|
|
634
|
+
const version = 'synthetic-legacy-catalog-v1';
|
|
635
|
+
const thresholds = trainerThresholds();
|
|
636
|
+
const runs = writePackageRuns(dir, version, thresholds);
|
|
637
|
+
const candidate = path.join(dir, 'training', 'candidates', version);
|
|
638
|
+
buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir: candidate });
|
|
639
|
+
|
|
640
|
+
const manifestFile = path.join(candidate, 'manifest.json');
|
|
641
|
+
const oldManifest = JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
|
|
642
|
+
oldManifest.stages.intent.options = oldManifest.stages.intent.options.filter(id => id !== 'unclassified');
|
|
643
|
+
delete oldManifest.stages.intent.thresholds.unclassified;
|
|
644
|
+
oldManifest.stages.intent.referenceOnly = oldManifest.stages.intent.referenceOnly.filter(id => id !== 'unclassified');
|
|
645
|
+
if (!oldManifest.stages.intent.referenceOnly.length) delete oldManifest.stages.intent.referenceOnly;
|
|
646
|
+
fs.writeFileSync(manifestFile, JSON.stringify(oldManifest));
|
|
647
|
+
|
|
648
|
+
const output = path.join(dir, 'training', 'versions', version);
|
|
649
|
+
buildVersion({ dataDir: dir, version, sourceDir: candidate, versionDir: output });
|
|
650
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(output, 'manifest.json'), 'utf8'));
|
|
651
|
+
assert.ok(manifest.stages.intent.options.includes('unclassified'));
|
|
652
|
+
assert.equal(manifest.stages.intent.thresholds.unclassified, 1);
|
|
653
|
+
assert.ok(manifest.stages.intent.referenceOnly.includes('unclassified'));
|
|
654
|
+
assert.deepEqual(Object.keys(manifest.stages.intent.thresholds), manifest.stages.intent.options);
|
|
655
|
+
} finally {
|
|
656
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
test('package still rejects a non-null non-finite threshold', t => {
|
|
661
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-package-nan-'));
|
|
662
|
+
try {
|
|
663
|
+
const version = 'synthetic-nan-v1';
|
|
664
|
+
const thresholds = trainerThresholds();
|
|
665
|
+
const runs = writePackageRuns(dir, version, thresholds);
|
|
666
|
+
// 1e999 overflows to Infinity, the non-null non-finite value JSON can carry.
|
|
667
|
+
const calibration = path.join(runs, 'tier', 'calibration.json');
|
|
668
|
+
const serialized = JSON.stringify({ thresholds: thresholds.tier });
|
|
669
|
+
const keyValue = `${JSON.stringify('tier2')}:${thresholds.tier.tier2}`;
|
|
670
|
+
fs.writeFileSync(calibration, serialized.replace(keyValue, `${JSON.stringify('tier2')}:1e999`));
|
|
671
|
+
assert.throws(() => buildVersion({ dataDir: dir, version, sourceDir: runs,
|
|
672
|
+
versionDir: path.join(dir, 'training', 'versions', version) }), /finite per-option thresholds/);
|
|
673
|
+
} finally {
|
|
674
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
test('package publishes a trainer-catalog version that installs, activates, and reports reference-only scores', async t => {
|
|
679
|
+
const dir = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-roundtrip-')));
|
|
680
|
+
const home = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-home-')));
|
|
681
|
+
try {
|
|
682
|
+
const version = 'synthetic-roundtrip-v1';
|
|
683
|
+
const catalogs = trainerCatalogs();
|
|
684
|
+
const thresholds = Object.fromEntries(Object.entries(catalogs).map(([task, options]) => [task,
|
|
685
|
+
Object.fromEntries(options.map(id => [id, id === 'unclassified' ? null : 0.5]))]));
|
|
686
|
+
thresholds.intent.fix = null;
|
|
687
|
+
thresholds.tier.tier3 = null;
|
|
688
|
+
const runs = writePackageRuns(dir, version, thresholds);
|
|
689
|
+
const versionDir = path.join(dir, 'training', 'versions', version);
|
|
690
|
+
buildVersion({ dataDir: dir, version, sourceDir: runs, versionDir });
|
|
691
|
+
const packaged = JSON.parse(fs.readFileSync(path.join(versionDir, 'manifest.json'), 'utf8'));
|
|
692
|
+
for (const [stage, ids] of Object.entries(catalogs)) {
|
|
693
|
+
assert.deepEqual(packaged.stages[stage].options, ids);
|
|
694
|
+
assert.deepEqual(Object.keys(packaged.stages[stage].thresholds), ids);
|
|
695
|
+
}
|
|
696
|
+
assert.deepEqual(packaged.stages.intent.referenceOnly, ['fix', 'unclassified']);
|
|
697
|
+
const scoreScript = path.join(root, 'scripts/system-one-cycle/score.py');
|
|
698
|
+
const pythonCode = "import importlib.util,json,sys; spec=importlib.util.spec_from_file_location('score',sys.argv[1]); module=importlib.util.module_from_spec(spec); spec.loader.exec_module(module); print(json.dumps([o['id'] for o in module.trained_catalog(sys.argv[2],'intent',sys.argv[3])]))";
|
|
699
|
+
const scoredCatalog = spawnSync(process.env.PYTHON || 'python3', ['-c', pythonCode, scoreScript,
|
|
700
|
+
path.join(versionDir, 'intent.safetensors'), path.join(root, 'benchmarks/fixtures/system-one-intent-holdout.json')],
|
|
701
|
+
{ cwd: root, encoding: 'utf8' });
|
|
702
|
+
assert.equal(scoredCatalog.status, 0, scoredCatalog.stderr);
|
|
703
|
+
assert.deepEqual(JSON.parse(scoredCatalog.stdout), catalogs.intent);
|
|
704
|
+
|
|
705
|
+
const publishCommand = spawnSync(process.execPath, [path.join(root, 'scripts/system-one-cycle.js'), 'publish',
|
|
706
|
+
'--data-dir', dir, '--version', version], { cwd: root, encoding: 'utf8' });
|
|
707
|
+
assert.equal(publishCommand.status, 0, publishCommand.stderr);
|
|
708
|
+
const published = JSON.parse(publishCommand.stdout).steps[0];
|
|
709
|
+
assert.equal(published.publishedPath, path.join(dir, 'models', 'cua-s1', version));
|
|
710
|
+
|
|
711
|
+
install.installVersion(dir, version, home);
|
|
712
|
+
install.activate(version, home);
|
|
713
|
+
const env = { HARNESS_SYSTEM_ONE_HOME: home };
|
|
714
|
+
const active = provider.readActive(env);
|
|
715
|
+
assert.equal(active.version, version);
|
|
716
|
+
const liveCatalogs = {
|
|
717
|
+
validity: router.VALIDITY_OPTIONS,
|
|
718
|
+
intent: CATALOGS.intent,
|
|
719
|
+
tier: router.TIER_OPTIONS,
|
|
720
|
+
};
|
|
721
|
+
const result = await provider.scoreLive('synthetic request', env, liveCatalogs, async (_stage, request) => ({
|
|
722
|
+
status: 'scored',
|
|
723
|
+
response: {
|
|
724
|
+
schemaVersion: 1, requestHash: request.requestHash, catalogHash: request.catalogHash,
|
|
725
|
+
model: { id: version, revision: version, domain: 'harness-routing-v1' },
|
|
726
|
+
scores: request.options.map(option => ({ id: option.id,
|
|
727
|
+
probability: option.id === 'fix' || option.id === 'tier3' ? 0.99 : option.id === 'tier2' ? 0.8 : 0.1 })),
|
|
728
|
+
},
|
|
729
|
+
}));
|
|
730
|
+
assert.deepEqual(result.referenceOnly, { validity: [], intent: ['fix', 'unclassified'], tier: ['tier3'] });
|
|
731
|
+
assert.equal(result.stageScores.intent.fix, 0.99);
|
|
732
|
+
assert.equal(result.stageScores.intent.unclassified, 0.1);
|
|
733
|
+
assert.equal(result.stageScores.tier.tier3, 0.99);
|
|
734
|
+
const routed = router.routeLive({ tier: 'Tier 1 (Trivial)', floor: null, explicit: false }, result);
|
|
735
|
+
assert.equal(routed.systemOne.intents.fix, 0.99);
|
|
736
|
+
assert.equal(Object.hasOwn(routed.systemOne.intents, 'unclassified'), false);
|
|
737
|
+
assert.equal(routed.systemOne.decision.intents.includes('fix'), false);
|
|
738
|
+
assert.equal(routed.systemOne.decision.tier, 'tier2');
|
|
739
|
+
assert.deepEqual(routed.reference.referenceOnlyOptions, [
|
|
740
|
+
{ stage: 'intent', id: 'fix', probability: 0.99 }, { stage: 'intent', id: 'unclassified', probability: 0.1 },
|
|
741
|
+
{ stage: 'tier', id: 'tier3', probability: 0.99 },
|
|
742
|
+
]);
|
|
743
|
+
} finally {
|
|
744
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
745
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
test('all --until build uses prepared synthetic stages and stops before training', t => {
|
|
750
|
+
const base = path.join(root, '.s1-work');
|
|
751
|
+
fs.mkdirSync(base, { recursive: true });
|
|
752
|
+
const dir = fs.mkdtempSync(path.join(base, 'cycle-until-build-'));
|
|
753
|
+
const isolation = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-all-isolation-'));
|
|
754
|
+
const home = path.join(isolation, 'home');
|
|
755
|
+
const liveStore = path.join(isolation, 'live-observations');
|
|
756
|
+
const sessions = path.join(isolation, 'codex-sessions');
|
|
757
|
+
fs.mkdirSync(home);
|
|
758
|
+
fs.mkdirSync(liveStore);
|
|
759
|
+
fs.mkdirSync(sessions);
|
|
760
|
+
try {
|
|
761
|
+
const fixture = syntheticCycle(dir);
|
|
762
|
+
fs.writeFileSync(path.join(dir, 'cycle-state.json'), JSON.stringify({ schemaVersion: 1, steps: {
|
|
763
|
+
collect: { completedAt: '2026-11-14T00:00:00.000Z' },
|
|
764
|
+
label: { completedAt: '2026-11-14T00:00:00.000Z' },
|
|
765
|
+
judge: { completedAt: '2026-11-14T00:00:00.000Z' },
|
|
766
|
+
} }));
|
|
767
|
+
const result = spawnSync(process.execPath, [path.join(root, 'scripts/system-one-cycle.js'), 'all', '--until', 'build', '--data-dir', dir,
|
|
768
|
+
'--sessions', sessions, '--holdout', fixture.holdout], {
|
|
769
|
+
cwd: root, encoding: 'utf8', env: { ...process.env, HOME: home, USERPROFILE: home,
|
|
770
|
+
CODEX_HOME: path.join(home, '.codex'), HARNESS_STATE_HOME: path.join(home, '.harness-state'), HARNESS_OBSERVATIONS_DIR: liveStore },
|
|
771
|
+
});
|
|
772
|
+
assert.equal(result.status, 0, result.stderr);
|
|
773
|
+
assert.equal(result.stdout.includes('synthetic-'), false);
|
|
774
|
+
const state = JSON.parse(fs.readFileSync(path.join(dir, 'cycle-state.json'), 'utf8'));
|
|
775
|
+
assert.ok(state.steps.build.completedAt);
|
|
776
|
+
assert.equal(state.steps.train, undefined);
|
|
777
|
+
assert.equal(fs.existsSync(path.join(dir, 'training/runs')), false);
|
|
778
|
+
} finally {
|
|
779
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
780
|
+
fs.rmSync(isolation, { recursive: true, force: true });
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
test('446 cross-cycle: A/v0 and B/v1 share history, compare against the first holdout, and promote unchanged quality', t => {
|
|
785
|
+
const tmp = private446Root(t);
|
|
786
|
+
const sharedParent = path.join(tmp, 'shared');
|
|
787
|
+
fs.mkdirSync(sharedParent, { mode: 0o755 });
|
|
788
|
+
if (process.platform !== 'win32') fs.chmodSync(sharedParent, 0o755);
|
|
789
|
+
const history = path.join(sharedParent, 'history', 'private-history.jsonl');
|
|
790
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
791
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [{ version: 'v1', quality: 0.9 }], { all: true });
|
|
792
|
+
|
|
793
|
+
const a = run446Cycle(monthA, 'v0', { history, quality: 0.9, all: true });
|
|
794
|
+
assert.equal(a.status, 0, a.stderr || a.stdout);
|
|
795
|
+
const b = run446Cycle(monthB, 'v1', { history, quality: 0.9, all: true });
|
|
796
|
+
assert.equal(b.status, 0, b.stderr || b.stdout);
|
|
797
|
+
|
|
798
|
+
const { curves, trend } = evaluation446(monthB.dataDir, 'v1');
|
|
799
|
+
assert.equal(curves.floor.detail.status, 'checked',
|
|
800
|
+
`B must use A's shared holdout baseline; got ${curves.floor.detail.status} with ${trend.verdict}`);
|
|
801
|
+
assert.equal(curves.floor.detail.baselineVersion, 'v0');
|
|
802
|
+
for (const stage of Object.values(curves.floor.detail.stages)) {
|
|
803
|
+
assert.equal(stage.baselineVersion, 'v0');
|
|
804
|
+
assert.equal(stage.baselineAvailable, true);
|
|
805
|
+
assert.deepEqual(stage.deltas, { auc: 0, logLoss: 0, ece: 0 });
|
|
806
|
+
}
|
|
807
|
+
assert.equal(trend.verdict, 'promote');
|
|
808
|
+
assert.deepEqual(rows446(history).map(row => row.version), ['v0', 'v1']);
|
|
809
|
+
assert.ok(outside(monthA.dataDir, history));
|
|
810
|
+
assert.ok(outside(monthB.dataDir, history));
|
|
811
|
+
if (process.platform !== 'win32') {
|
|
812
|
+
assert.equal(fs.statSync(sharedParent).mode & 0o777, 0o755, 'an existing shared parent must not be chmodded');
|
|
813
|
+
assert.equal(fs.statSync(path.dirname(history)).mode & 0o777, 0o700);
|
|
814
|
+
assert.equal(fs.statSync(history).mode & 0o777, 0o600);
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
test('446 H3: fixture-selected Python runs commands and intercepts only the production scorer', t => {
|
|
819
|
+
const rootDir = private446Root(t);
|
|
820
|
+
const fixtureDir = path.join(rootDir, 'fixture path with spaces');
|
|
821
|
+
const fixture = setup446Cycle(t, path.join(fixtureDir, 'data'), [{ version: 'h3-v0', quality: 0.9 }], { all: true });
|
|
822
|
+
const env = environment446(fixture);
|
|
823
|
+
|
|
824
|
+
const probe = spawnSync(fixture.python, ['-c', "import json,sitecustomize,sys; print(json.dumps({'sentinel':'S1_446_PYTHON_SENTINEL','executable':sys.executable,'version':sys.version.split()[0],'hook':sitecustomize.__file__}))"],
|
|
825
|
+
{ cwd: root, encoding: 'utf8', env, windowsHide: true });
|
|
826
|
+
assert.equal(probe.status, 0, probe.stderr);
|
|
827
|
+
const python = JSON.parse(probe.stdout);
|
|
828
|
+
assert.equal(python.sentinel, 'S1_446_PYTHON_SENTINEL', 'fixture-selected executable must execute Python -c');
|
|
829
|
+
assert.ok(path.isAbsolute(python.executable), 'Python must report its actual interpreter path');
|
|
830
|
+
assert.match(python.version, /^\d+\.\d+(?:\.\d+)?$/);
|
|
831
|
+
assert.equal(fs.realpathSync.native(python.hook), path.join(fixture.tmp, 'sitecustomize.py'));
|
|
832
|
+
assert.doesNotMatch(fixture.python, /\.(?:js|cmd)$/i, 'PYTHON must be a real interpreter, not a script wrapper');
|
|
833
|
+
assert.ok(fixture.tmp.includes(' '), 'fixture transport must support paths with spaces');
|
|
834
|
+
|
|
835
|
+
const unrelatedDir = path.join(fixture.tmp, 'unrelated');
|
|
836
|
+
fs.mkdirSync(unrelatedDir, { recursive: true });
|
|
837
|
+
const unrelatedScript = path.join(unrelatedDir, 'score.py');
|
|
838
|
+
fs.writeFileSync(unrelatedScript, "print('S1_446_UNRELATED_SCORE')\n", 'utf8');
|
|
839
|
+
const unrelated = spawnSync(fixture.python, [unrelatedScript], { cwd: root, encoding: 'utf8', env, windowsHide: true });
|
|
840
|
+
assert.equal(unrelated.status, 0, unrelated.stderr);
|
|
841
|
+
assert.equal(unrelated.stdout.trim(), 'S1_446_UNRELATED_SCORE', 'an unrelated score.py must run normally');
|
|
842
|
+
|
|
843
|
+
const failedCommand = spawnSync(fixture.python, ['-c', 'raise SystemExit(37)'],
|
|
844
|
+
{ cwd: root, encoding: 'utf8', env, windowsHide: true });
|
|
845
|
+
assert.equal(failedCommand.status, 37, 'a real failing Python -c command must retain its exit status');
|
|
846
|
+
|
|
847
|
+
const result = run446Cycle(fixture, 'h3-v0', { quality: 0.9, all: true });
|
|
848
|
+
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
849
|
+
const versionDir = path.join(fixture.dataDir, 'training', 'candidates', 'h3-v0');
|
|
850
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(versionDir, 'manifest.json'), 'utf8'));
|
|
851
|
+
const evaluationDir = path.join(versionDir, 'evaluation');
|
|
852
|
+
const goldByTask = { validity: 'actionable', intent: 'fix', tier: 'tier2' };
|
|
853
|
+
for (const [task, ids] of Object.entries(cycleTrainerCatalogs)) {
|
|
854
|
+
assert.deepEqual(manifest.stages[task].options, ids, `real trainer catalog for ${task} must match fixture options`);
|
|
855
|
+
const rows = fs.readFileSync(path.join(evaluationDir, `${task}-holdout-scores.jsonl`), 'utf8').trim().split(/\r?\n/).map(JSON.parse);
|
|
856
|
+
assert.equal(rows.length, 1);
|
|
857
|
+
assert.equal(rows[0].id, `holdout-${task}`);
|
|
858
|
+
assert.equal(rows[0].gold, goldByTask[task]);
|
|
859
|
+
assert.deepEqual(Object.keys(rows[0].scores), ids);
|
|
860
|
+
}
|
|
861
|
+
assert.deepEqual(fs.readFileSync(fixture.callLog, 'utf8').trim().split(/\r?\n/), [
|
|
862
|
+
'validity:holdout', 'intent:holdout', 'tier:holdout',
|
|
863
|
+
]);
|
|
864
|
+
|
|
865
|
+
const malformed = spawnSync(fixture.python, [path.join(root, 'scripts/system-one-cycle/score.py'), '--task', 'validity'],
|
|
866
|
+
{ cwd: root, encoding: 'utf8', env, windowsHide: true });
|
|
867
|
+
assert.notEqual(malformed.status, 0, 'malformed scorer arguments must fail in the fixture hook');
|
|
868
|
+
assert.match(malformed.stderr, /S1_446 fixture scorer: expected --weights, --holdout, --task, --out/);
|
|
869
|
+
|
|
870
|
+
const noHookEnv = { ...env, PYTHONPATH: path.join(fixture.tmp, 'empty-pythonpath') };
|
|
871
|
+
delete noHookEnv.S1_446_CATALOGS;
|
|
872
|
+
delete noHookEnv.S1_446_CALL_LOG;
|
|
873
|
+
delete noHookEnv.S1_446_QUALITY;
|
|
874
|
+
const noHookOutput = path.join(fixture.tmp, 'without-hook.jsonl');
|
|
875
|
+
const noHook = spawnSync(fixture.python, [path.join(root, 'scripts/system-one-cycle/score.py'),
|
|
876
|
+
'--weights', path.join(versionDir, 'validity.safetensors'), '--holdout', path.join(root, 'benchmarks/fixtures/system-one-holdout.json'),
|
|
877
|
+
'--task', 'validity', '--out', noHookOutput], { cwd: root, encoding: 'utf8', env: noHookEnv, windowsHide: true });
|
|
878
|
+
assert.notEqual(noHook.status, 0, 'without scoring interception the fixture scorer smoke path must fail, not skip');
|
|
879
|
+
assert.equal(fs.existsSync(noHookOutput), false);
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
test('446 cross-cycle: cumulative holdout drift stays measured against A/v0 after partial recovery', t => {
|
|
883
|
+
const tmp = private446Root(t);
|
|
884
|
+
const history = path.join(tmp, 'shared', 'private-history.jsonl');
|
|
885
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
886
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [
|
|
887
|
+
{ version: 'v1', quality: 0.7 }, { version: 'v2', quality: 0.8 },
|
|
888
|
+
], { all: true });
|
|
889
|
+
|
|
890
|
+
for (const [fixture, version, quality] of [[monthA, 'v0', 0.9], [monthB, 'v1', 0.7], [monthB, 'v2', 0.8]]) {
|
|
891
|
+
const result = run446Cycle(fixture, version, { history, quality, all: true });
|
|
892
|
+
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
const { curves, trend } = evaluation446(monthB.dataDir, 'v2');
|
|
896
|
+
assert.equal(curves.floor.detail.status, 'regression');
|
|
897
|
+
assert.equal(curves.floor.oldHoldoutRegression, true);
|
|
898
|
+
assert.equal(curves.floor.detail.baselineVersion, 'v0');
|
|
899
|
+
assert.ok(Object.values(curves.floor.detail.stages).every(stage => stage.baselineVersion === 'v0'));
|
|
900
|
+
assert.equal(trend.verdict, 'hold');
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
test('446 cross-cycle: four evaluations detect two worsening transitions across A and B directories', t => {
|
|
904
|
+
const tmp = private446Root(t);
|
|
905
|
+
const history = path.join(tmp, 'shared', 'private-history.jsonl');
|
|
906
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
907
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [
|
|
908
|
+
{ version: 'v1', quality: 0.8 }, { version: 'v2', quality: 0.7 }, { version: 'v3', quality: 0.6 },
|
|
909
|
+
], { all: true });
|
|
910
|
+
|
|
911
|
+
for (const [fixture, version, quality] of [
|
|
912
|
+
[monthA, 'v0', 0.9], [monthB, 'v1', 0.8], [monthB, 'v2', 0.7], [monthB, 'v3', 0.6],
|
|
913
|
+
]) {
|
|
914
|
+
const result = run446Cycle(fixture, version, { history, quality, all: true });
|
|
915
|
+
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const { trend } = evaluation446(monthB.dataDir, 'v3');
|
|
919
|
+
assert.equal(trend.verdict, 'rollback');
|
|
920
|
+
assert.ok(trend.reasons.some(reason => reason.includes('two consecutive cycles (v0 → v1 → v2)')));
|
|
921
|
+
assert.deepEqual(rows446(history).map(row => row.version), ['v0', 'v1', 'v2', 'v3']);
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
test('446 cross-cycle: resume keeps one immutable row, repairs a missing append, and rejects conflicting reuse', t => {
|
|
925
|
+
const tmp = private446Root(t);
|
|
926
|
+
const history = path.join(tmp, 'month-b', 'training', 'history.jsonl');
|
|
927
|
+
const alternateHistory = path.join(tmp, 'alternate', 'private-history.jsonl');
|
|
928
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
929
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [{ version: 'v1', quality: 0.9 }], { all: true });
|
|
930
|
+
const a = run446Cycle(monthA, 'v0', { quality: 0.9, all: true });
|
|
931
|
+
assert.equal(a.status, 0, a.stderr || a.stdout);
|
|
932
|
+
const baseline = rows446(path.join(monthA.dataDir, 'training', 'history.jsonl'))[0];
|
|
933
|
+
fs.mkdirSync(path.dirname(history), { recursive: true, mode: 0o700 });
|
|
934
|
+
fs.writeFileSync(history, `${JSON.stringify(baseline)}\n`);
|
|
935
|
+
const b = run446Cycle(monthB, 'v1', { quality: 0.9, all: true });
|
|
936
|
+
assert.equal(b.status, 0, b.stderr || b.stdout);
|
|
937
|
+
const callsBeforeResume = fs.readFileSync(monthB.callLog, 'utf8').trim().split(/\r?\n/).length;
|
|
938
|
+
const original = fs.readFileSync(history, 'utf8');
|
|
939
|
+
const completeResume = run446Cycle(monthB, 'v1', { history, quality: 0.9 });
|
|
940
|
+
assert.equal(completeResume.status, 0, completeResume.stderr || completeResume.stdout);
|
|
941
|
+
assert.equal(fs.readFileSync(history, 'utf8'), original);
|
|
942
|
+
assert.equal(rows446(history).filter(row => row.version === 'v1').length, 1);
|
|
943
|
+
|
|
944
|
+
const savedBaseline = rows446(history).find(row => row.version === 'v0');
|
|
945
|
+
fs.writeFileSync(history, `${JSON.stringify(savedBaseline)}\n`);
|
|
946
|
+
fs.mkdirSync(path.dirname(alternateHistory), { recursive: true, mode: 0o700 });
|
|
947
|
+
fs.writeFileSync(alternateHistory, `${JSON.stringify(savedBaseline)}\n`);
|
|
948
|
+
const repaired = run446Cycle(monthB, 'v1', { history: alternateHistory, quality: 0.9 });
|
|
949
|
+
assert.equal(repaired.status, 0, repaired.stderr || repaired.stdout);
|
|
950
|
+
assert.deepEqual(rows446(history).map(row => row.version), ['v0']);
|
|
951
|
+
assert.ok(fs.existsSync(alternateHistory), 'resume must reconcile to the selected alternate history file');
|
|
952
|
+
assert.deepEqual(rows446(alternateHistory).map(row => row.version), ['v0', 'v1']);
|
|
953
|
+
assert.equal(fs.readFileSync(monthB.callLog, 'utf8').trim().split(/\r?\n/).length, callsBeforeResume,
|
|
954
|
+
'resume reconciliation must not rescore');
|
|
955
|
+
const restored = rows446(alternateHistory).find(row => row.version === 'v1');
|
|
956
|
+
assert.deepEqual(restored, evaluation446(monthB.dataDir, 'v1').curves);
|
|
957
|
+
const restoredBytes = fs.readFileSync(alternateHistory, 'utf8');
|
|
958
|
+
const secondResume = run446Cycle(monthB, 'v1', { history: alternateHistory, quality: 0.9 });
|
|
959
|
+
assert.equal(secondResume.status, 0, secondResume.stderr || secondResume.stdout);
|
|
960
|
+
assert.equal(fs.readFileSync(alternateHistory, 'utf8'), restoredBytes);
|
|
961
|
+
assert.equal(rows446(alternateHistory).filter(row => row.version === 'v1').length, 1);
|
|
962
|
+
|
|
963
|
+
const conflictingRows = rows446(alternateHistory);
|
|
964
|
+
conflictingRows.find(row => row.version === 'v1').stages.validity.logLoss += 1;
|
|
965
|
+
fs.writeFileSync(alternateHistory, `${conflictingRows.map(row => JSON.stringify(row)).join('\n')}\n`);
|
|
966
|
+
const conflictingBytes = fs.readFileSync(alternateHistory, 'utf8');
|
|
967
|
+
const conflict = run446Cycle(monthB, 'v1', { history: alternateHistory, quality: 0.9 });
|
|
968
|
+
assert.notEqual(conflict.status, 0, 'conflicting reuse of an immutable version must fail');
|
|
969
|
+
assert.equal(fs.readFileSync(alternateHistory, 'utf8'), conflictingBytes, 'conflict must not overwrite history');
|
|
970
|
+
assert.doesNotMatch(conflict.stderr, /synthetic-|holdout-|validation-/);
|
|
971
|
+
});
|
|
972
|
+
|
|
973
|
+
test('446 cross-cycle: default history remains local and explicit history validation fails closed', t => {
|
|
974
|
+
const tmp = private446Root(t);
|
|
975
|
+
const local = setup446Cycle(t, path.join(tmp, 'default-cycle'), [{ version: 'default-v0', quality: 0.9 }]);
|
|
976
|
+
const defaultRun = run446Cycle(local, 'default-v0', { quality: 0.9 });
|
|
977
|
+
assert.equal(defaultRun.status, 0, defaultRun.stderr || defaultRun.stdout);
|
|
978
|
+
const defaultHistory = path.join(local.dataDir, 'training', 'history.jsonl');
|
|
979
|
+
assert.deepEqual(rows446(defaultHistory).map(row => row.version), ['default-v0']);
|
|
980
|
+
|
|
981
|
+
const bare = setup446Cycle(t, path.join(tmp, 'bare-cycle'), [{ version: 'bare-v0', quality: 0.9 }]);
|
|
982
|
+
const bareResult = run446Cycle(bare, 'bare-v0', { history: true, quality: 0.9 });
|
|
983
|
+
assert.notEqual(bareResult.status, 0, 'bare --history must be rejected');
|
|
984
|
+
assertEvaluationNotMarked(bare.dataDir);
|
|
985
|
+
|
|
986
|
+
const repositoryPath = setup446Cycle(t, path.join(tmp, 'repository-cycle'), [{ version: 'repo-v0', quality: 0.9 }]);
|
|
987
|
+
const repoResult = run446Cycle(repositoryPath, 'repo-v0', { history: path.join(root, 'docs/system-one-cycle.md'), quality: 0.9 });
|
|
988
|
+
assert.notEqual(repoResult.status, 0, 'repository-contained history must be rejected');
|
|
989
|
+
assert.equal(fs.existsSync(path.join(repositoryPath.dataDir, 'cycle-state.json')), false);
|
|
990
|
+
|
|
991
|
+
const directory = path.join(tmp, 'history-is-directory');
|
|
992
|
+
fs.mkdirSync(directory);
|
|
993
|
+
const directoryFixture = setup446Cycle(t, path.join(tmp, 'directory-cycle'), [{ version: 'directory-v0', quality: 0.9 }]);
|
|
994
|
+
const directoryResult = run446Cycle(directoryFixture, 'directory-v0', { history: directory, quality: 0.9 });
|
|
995
|
+
assert.notEqual(directoryResult.status, 0, 'history destinations must be files, not directories');
|
|
996
|
+
assert.equal(fs.existsSync(path.join(directoryFixture.dataDir, 'cycle-state.json')), false);
|
|
997
|
+
|
|
998
|
+
const symlink = path.join(tmp, 'history-symlink.jsonl');
|
|
999
|
+
try { fs.symlinkSync(path.join(root, 'docs/system-one-cycle.md'), symlink); }
|
|
1000
|
+
catch (error) {
|
|
1001
|
+
if (!['EACCES', 'EPERM', 'ENOSYS', 'ENOTSUP'].includes(error.code)) throw error;
|
|
1002
|
+
t.diagnostic(`symlink path leg unavailable: ${error.code}; direct repository-path control ran`);
|
|
1003
|
+
}
|
|
1004
|
+
if (fs.existsSync(symlink)) {
|
|
1005
|
+
const symlinkFixture = setup446Cycle(t, path.join(tmp, 'symlink-cycle'), [{ version: 'symlink-v0', quality: 0.9 }]);
|
|
1006
|
+
const symlinkResult = run446Cycle(symlinkFixture, 'symlink-v0', { history: symlink, quality: 0.9 });
|
|
1007
|
+
assert.notEqual(symlinkResult.status, 0, 'symlink resolving into the repository must be rejected');
|
|
1008
|
+
assert.equal(fs.existsSync(path.join(symlinkFixture.dataDir, 'cycle-state.json')), false);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const malformed = setup446Cycle(t, path.join(tmp, 'malformed-cycle'), [{ version: 'malformed-v0', quality: 0.9 }]);
|
|
1012
|
+
const malformedHistory = path.join(tmp, 'malformed-history.jsonl');
|
|
1013
|
+
fs.writeFileSync(malformedHistory, 'PRIVATE_SCORE_SENTINEL {not-json}\n');
|
|
1014
|
+
const malformedResult = run446Cycle(malformed, 'malformed-v0', { history: malformedHistory, quality: 0.9 });
|
|
1015
|
+
assert.notEqual(malformedResult.status, 0, 'malformed history must not bootstrap as empty');
|
|
1016
|
+
assert.doesNotMatch(malformedResult.stderr, /PRIVATE_SCORE_SENTINEL/);
|
|
1017
|
+
assert.equal(fs.existsSync(path.join(malformed.dataDir, 'cycle-state.json')), false);
|
|
1018
|
+
|
|
1019
|
+
const appendFailure = setup446Cycle(t, path.join(tmp, 'append-failure-cycle'), [{ version: 'append-v0', quality: 0.9 }]);
|
|
1020
|
+
const parentFile = path.join(tmp, 'not-a-directory');
|
|
1021
|
+
fs.writeFileSync(parentFile, 'fixture');
|
|
1022
|
+
const failedHistory = run446Cycle(appendFailure, 'append-v0', {
|
|
1023
|
+
history: path.join(parentFile, 'private-history.jsonl'), quality: 0.9,
|
|
1024
|
+
});
|
|
1025
|
+
assert.notEqual(failedHistory.status, 0, 'history append failure must fail evaluation');
|
|
1026
|
+
assert.equal(fs.existsSync(path.join(appendFailure.dataDir, 'cycle-state.json')), false);
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
test('446 H2: rejects changed same-id baseline before append, including an existing identical candidate', t => {
|
|
1030
|
+
const tmp = private446Root(t);
|
|
1031
|
+
const originalHistory = path.join(tmp, 'original-history.jsonl');
|
|
1032
|
+
const absentHistory = path.join(tmp, 'alternate-absent.jsonl');
|
|
1033
|
+
const presentHistory = path.join(tmp, 'alternate-present.jsonl');
|
|
1034
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.8 }], { all: true });
|
|
1035
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [{ version: 'v1', quality: 0.9 }], { all: true });
|
|
1036
|
+
assert.equal(run446Cycle(monthA, 'v0', { history: originalHistory, quality: 0.8, all: true }).status, 0);
|
|
1037
|
+
assert.equal(run446Cycle(monthB, 'v1', { history: originalHistory, quality: 0.9, all: true }).status, 0);
|
|
1038
|
+
const candidate = rows446(originalHistory).find(row => row.version === 'v1');
|
|
1039
|
+
|
|
1040
|
+
const alternateA = setup446Cycle(t, path.join(tmp, 'alternate-a'), [{ version: 'v0', quality: 0.99 }], { all: true });
|
|
1041
|
+
assert.equal(run446Cycle(alternateA, 'v0', { history: absentHistory, quality: 0.99, all: true }).status, 0);
|
|
1042
|
+
const alternateBaseline = rows446(absentHistory)[0];
|
|
1043
|
+
writeRows446(absentHistory, [alternateBaseline]);
|
|
1044
|
+
const stateFile = path.join(monthB.dataDir, 'cycle-state.json');
|
|
1045
|
+
const paths = [absentHistory, ...['curves.json', 'trend.json'].map(file =>
|
|
1046
|
+
path.join(monthB.dataDir, 'training', 'candidates', 'v1', 'evaluation', file)),
|
|
1047
|
+
path.join(monthB.dataDir, 'training', 'candidates', 'v1', 'manifest.json'),
|
|
1048
|
+
stateFile, monthB.callLog];
|
|
1049
|
+
const beforeAbsent = snapshot446(paths);
|
|
1050
|
+
const absent = run446Cycle(monthB, 'v1', { history: absentHistory, quality: 0.9 });
|
|
1051
|
+
assert.notEqual(absent.status, 0, 'a cached promotion must reject a changed same-id baseline');
|
|
1052
|
+
assertSnapshot446(beforeAbsent);
|
|
1053
|
+
assert.doesNotMatch(`${absent.stdout}\n${absent.stderr}`, /0\.99|synthetic-|holdout-|validation-/);
|
|
1054
|
+
|
|
1055
|
+
const freshHistory = path.join(tmp, 'fresh-diagnostic.jsonl');
|
|
1056
|
+
writeRows446(freshHistory, [alternateBaseline]);
|
|
1057
|
+
const freshB = setup446Cycle(t, path.join(tmp, 'fresh-b'), [{ version: 'v1', quality: 0.9 }], { all: true });
|
|
1058
|
+
assert.equal(run446Cycle(freshB, 'v1', { history: freshHistory, quality: 0.9, all: true }).status, 0);
|
|
1059
|
+
assert.equal(evaluation446(freshB.dataDir, 'v1').curves.floor.detail.status, 'regression');
|
|
1060
|
+
assert.equal(evaluation446(freshB.dataDir, 'v1').trend.verdict, 'hold');
|
|
1061
|
+
|
|
1062
|
+
writeRows446(presentHistory, [alternateBaseline, candidate]);
|
|
1063
|
+
const beforePresent = snapshot446([...paths.filter(file => file !== absentHistory), presentHistory]);
|
|
1064
|
+
const present = run446Cycle(monthB, 'v1', { history: presentHistory, quality: 0.9 });
|
|
1065
|
+
assert.notEqual(present.status, 0, 'an identical candidate row must not bypass baseline validation');
|
|
1066
|
+
assertSnapshot446(beforePresent);
|
|
1067
|
+
assert.doesNotMatch(`${present.stdout}\n${present.stderr}`, /0\.99|synthetic-|holdout-|validation-/);
|
|
1068
|
+
|
|
1069
|
+
const matching = fs.readFileSync(originalHistory, 'utf8');
|
|
1070
|
+
const matchingResume = run446Cycle(monthB, 'v1', { history: originalHistory, quality: 0.9 });
|
|
1071
|
+
assert.equal(matchingResume.status, 0, matchingResume.stderr || matchingResume.stdout);
|
|
1072
|
+
assert.equal(fs.readFileSync(originalHistory, 'utf8'), matching, 'matching history resume stays byte-stable');
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
test('446 H2: rejects stale predecessor metrics and reordered trend rows before writes', t => {
|
|
1076
|
+
const tmp = private446Root(t);
|
|
1077
|
+
const originalHistory = path.join(tmp, 'original-history.jsonl');
|
|
1078
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
1079
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [
|
|
1080
|
+
{ version: 'v1', quality: 0.8 }, { version: 'v2', quality: 0.7 }, { version: 'v3', quality: 0.6 },
|
|
1081
|
+
], { all: true });
|
|
1082
|
+
for (const [fixture, version, quality] of [
|
|
1083
|
+
[monthA, 'v0', 0.9], [monthB, 'v1', 0.8], [monthB, 'v2', 0.7], [monthB, 'v3', 0.6],
|
|
1084
|
+
]) assert.equal(run446Cycle(fixture, version, { history: originalHistory, quality, all: true }).status, 0);
|
|
1085
|
+
assert.equal(evaluation446(monthB.dataDir, 'v3').trend.verdict, 'rollback');
|
|
1086
|
+
|
|
1087
|
+
const changedHistory = path.join(tmp, 'changed-prior-history.jsonl');
|
|
1088
|
+
const changedB = setup446Cycle(t, path.join(tmp, 'changed-b'), [
|
|
1089
|
+
{ version: 'v1', quality: 0.8 }, { version: 'v2', quality: 0.9 },
|
|
1090
|
+
], { all: true });
|
|
1091
|
+
const changedA = setup446Cycle(t, path.join(tmp, 'changed-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
1092
|
+
assert.equal(run446Cycle(changedA, 'v0', { history: changedHistory, quality: 0.9, all: true }).status, 0);
|
|
1093
|
+
assert.equal(run446Cycle(changedB, 'v1', { history: changedHistory, quality: 0.8, all: true }).status, 0);
|
|
1094
|
+
assert.equal(run446Cycle(changedB, 'v2', { history: changedHistory, quality: 0.9, all: true }).status, 0);
|
|
1095
|
+
const changedBytes = fs.readFileSync(changedHistory, 'utf8');
|
|
1096
|
+
const changedPaths = [changedHistory,
|
|
1097
|
+
path.join(monthB.dataDir, 'training', 'candidates', 'v3', 'evaluation', 'curves.json'),
|
|
1098
|
+
path.join(monthB.dataDir, 'training', 'candidates', 'v3', 'evaluation', 'trend.json'),
|
|
1099
|
+
path.join(monthB.dataDir, 'training', 'candidates', 'v3', 'manifest.json'),
|
|
1100
|
+
path.join(monthB.dataDir, 'cycle-state.json'), monthB.callLog];
|
|
1101
|
+
const changedBefore = snapshot446(changedPaths);
|
|
1102
|
+
const changed = run446Cycle(monthB, 'v3', { history: changedHistory, quality: 0.6 });
|
|
1103
|
+
assert.notEqual(changed.status, 0, 'same baseline with changed prior comparison rows must reject a stale rollback');
|
|
1104
|
+
assertSnapshot446(changedBefore);
|
|
1105
|
+
assert.equal(fs.readFileSync(changedHistory, 'utf8'), changedBytes);
|
|
1106
|
+
|
|
1107
|
+
const reorderedHistory = path.join(tmp, 'reordered-history.jsonl');
|
|
1108
|
+
writeRows446(reorderedHistory, [rows446(originalHistory)[0], rows446(originalHistory)[2], rows446(originalHistory)[1]]);
|
|
1109
|
+
const reorderedBytes = fs.readFileSync(reorderedHistory, 'utf8');
|
|
1110
|
+
const reordered = run446Cycle(monthB, 'v3', { history: reorderedHistory, quality: 0.6 });
|
|
1111
|
+
assert.notEqual(reordered.status, 0, 'saved predecessor ids must retain their original order');
|
|
1112
|
+
assert.equal(fs.readFileSync(reorderedHistory, 'utf8'), reorderedBytes);
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
test('446 H2: resumes bootstrap and older candidates against their original predecessor prefixes', t => {
|
|
1116
|
+
const tmp = private446Root(t);
|
|
1117
|
+
const history = path.join(tmp, 'shared-history.jsonl');
|
|
1118
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
1119
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [
|
|
1120
|
+
{ version: 'v1', quality: 0.9 }, { version: 'v2', quality: 0.9 },
|
|
1121
|
+
], { all: true });
|
|
1122
|
+
for (const [fixture, version] of [[monthA, 'v0'], [monthB, 'v1'], [monthB, 'v2']]) {
|
|
1123
|
+
const result = run446Cycle(fixture, version, { history, quality: 0.9, all: true });
|
|
1124
|
+
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
1125
|
+
}
|
|
1126
|
+
const original = fs.readFileSync(history, 'utf8');
|
|
1127
|
+
const callsBefore = fs.readFileSync(monthB.callLog, 'utf8');
|
|
1128
|
+
const bootstrap = evaluation446(monthA.dataDir, 'v0');
|
|
1129
|
+
assert.equal(bootstrap.trend.verdict, 'hold');
|
|
1130
|
+
assert.equal(run446Cycle(monthA, 'v0', { history, quality: 0.9 }).status, 0);
|
|
1131
|
+
const older = evaluation446(monthB.dataDir, 'v1');
|
|
1132
|
+
assert.equal(run446Cycle(monthB, 'v1', { history, quality: 0.9 }).status, 0);
|
|
1133
|
+
assert.deepEqual(evaluation446(monthB.dataDir, 'v1').trend, older.trend);
|
|
1134
|
+
assert.equal(fs.readFileSync(history, 'utf8'), original);
|
|
1135
|
+
assert.equal(fs.readFileSync(monthB.callLog, 'utf8'), callsBefore, 'resume must not rescore');
|
|
1136
|
+
});
|
|
1137
|
+
|
|
1138
|
+
test('446 H2: fresh append separates a valid history without LF and the next evaluation reads it', t => {
|
|
1139
|
+
const tmp = private446Root(t);
|
|
1140
|
+
const history = path.join(tmp, 'shared-history.jsonl');
|
|
1141
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
1142
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [
|
|
1143
|
+
{ version: 'v1', quality: 0.9 }, { version: 'v2', quality: 0.9 },
|
|
1144
|
+
], { all: true });
|
|
1145
|
+
assert.equal(run446Cycle(monthA, 'v0', { history, quality: 0.9, all: true }).status, 0);
|
|
1146
|
+
const original = fs.readFileSync(history, 'utf8');
|
|
1147
|
+
assert.ok(original.endsWith('\n'));
|
|
1148
|
+
const prefix = original.slice(0, -1);
|
|
1149
|
+
fs.writeFileSync(history, prefix);
|
|
1150
|
+
|
|
1151
|
+
const firstAppend = run446Cycle(monthB, 'v1', { history, quality: 0.9, all: true });
|
|
1152
|
+
assert.equal(firstAppend.status, 0, firstAppend.stderr || firstAppend.stdout);
|
|
1153
|
+
const afterFirst = fs.readFileSync(history, 'utf8');
|
|
1154
|
+
assert.ok(afterFirst.startsWith(prefix), 'the original history bytes must remain a prefix');
|
|
1155
|
+
assert.ok(afterFirst.slice(prefix.length).startsWith('\n{'), 'append must restore the missing JSONL separator');
|
|
1156
|
+
assert.deepEqual(rows446(history).map(row => row.version), ['v0', 'v1']);
|
|
1157
|
+
|
|
1158
|
+
const secondAppend = run446Cycle(monthB, 'v2', { history, quality: 0.9, all: true });
|
|
1159
|
+
assert.equal(secondAppend.status, 0, secondAppend.stderr || secondAppend.stdout);
|
|
1160
|
+
assert.deepEqual(rows446(history).map(row => row.version), ['v0', 'v1', 'v2']);
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
test('446 H2: missing-append resume repairs no-LF once; duplicate and conflict no-ops preserve bytes', t => {
|
|
1164
|
+
const tmp = private446Root(t);
|
|
1165
|
+
const sourceHistory = path.join(tmp, 'source-history.jsonl');
|
|
1166
|
+
const alternateHistory = path.join(tmp, 'alternate-history.jsonl');
|
|
1167
|
+
const monthA = setup446Cycle(t, path.join(tmp, 'month-a'), [{ version: 'v0', quality: 0.9 }], { all: true });
|
|
1168
|
+
const monthB = setup446Cycle(t, path.join(tmp, 'month-b'), [{ version: 'v1', quality: 0.9 }], { all: true });
|
|
1169
|
+
assert.equal(run446Cycle(monthA, 'v0', { history: sourceHistory, quality: 0.9, all: true }).status, 0);
|
|
1170
|
+
assert.equal(run446Cycle(monthB, 'v1', { history: sourceHistory, quality: 0.9, all: true }).status, 0);
|
|
1171
|
+
const baseline = rows446(sourceHistory)[0];
|
|
1172
|
+
writeRows446(alternateHistory, [baseline], '');
|
|
1173
|
+
const callsBefore = fs.readFileSync(monthB.callLog, 'utf8');
|
|
1174
|
+
|
|
1175
|
+
const resume = run446Cycle(monthB, 'v1', { history: alternateHistory, quality: 0.9 });
|
|
1176
|
+
assert.equal(resume.status, 0, resume.stderr || resume.stdout);
|
|
1177
|
+
let bytes = fs.readFileSync(alternateHistory, 'utf8');
|
|
1178
|
+
assert.ok(bytes.startsWith(JSON.stringify(baseline)));
|
|
1179
|
+
assert.ok(bytes.slice(JSON.stringify(baseline).length).startsWith('\n{'), 'resume append must restore its missing separator');
|
|
1180
|
+
assert.deepEqual(rows446(alternateHistory).map(row => row.version), ['v0', 'v1']);
|
|
1181
|
+
assert.equal(fs.readFileSync(monthB.callLog, 'utf8'), callsBefore, 'cached resume must not rescore');
|
|
1182
|
+
|
|
1183
|
+
fs.writeFileSync(alternateHistory, bytes.slice(0, -1));
|
|
1184
|
+
const noFinalLf = fs.readFileSync(alternateHistory, 'utf8');
|
|
1185
|
+
const duplicate = run446Cycle(monthB, 'v1', { history: alternateHistory, quality: 0.9 });
|
|
1186
|
+
assert.equal(duplicate.status, 0, duplicate.stderr || duplicate.stdout);
|
|
1187
|
+
assert.equal(fs.readFileSync(alternateHistory, 'utf8'), noFinalLf, 'deduplication must not normalize a no-op');
|
|
1188
|
+
|
|
1189
|
+
const timestampRows = rows446(alternateHistory);
|
|
1190
|
+
timestampRows.find(row => row.version === 'v1').createdAt = '2026-11-17T00:00:00.000Z';
|
|
1191
|
+
writeRows446(alternateHistory, timestampRows, '');
|
|
1192
|
+
const timestampBytes = fs.readFileSync(alternateHistory, 'utf8');
|
|
1193
|
+
const timestampResume = run446Cycle(monthB, 'v1', { history: alternateHistory, quality: 0.9 });
|
|
1194
|
+
assert.equal(timestampResume.status, 0, timestampResume.stderr || timestampResume.stdout);
|
|
1195
|
+
assert.equal(fs.readFileSync(alternateHistory, 'utf8'), timestampBytes, 'timestamp-only identity remains a byte-stable no-op');
|
|
1196
|
+
|
|
1197
|
+
const conflictingRows = rows446(alternateHistory);
|
|
1198
|
+
conflictingRows.find(row => row.version === 'v1').stages.validity.logLoss += 1;
|
|
1199
|
+
writeRows446(alternateHistory, conflictingRows, '');
|
|
1200
|
+
const conflictBytes = fs.readFileSync(alternateHistory, 'utf8');
|
|
1201
|
+
const conflict = run446Cycle(monthB, 'v1', { history: alternateHistory, quality: 0.9 });
|
|
1202
|
+
assert.notEqual(conflict.status, 0, 'conflicting duplicate must reject');
|
|
1203
|
+
assert.equal(fs.readFileSync(alternateHistory, 'utf8'), conflictBytes, 'rejection must not normalize history');
|
|
1204
|
+
});
|