harness-everything 0.52.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/CHANGELOG.md +20 -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-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-341-opencode-lane.test.js +7 -1
- 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-system-one-curves.test.js +17 -0
- package/ci/mechanism-system-one-cycle.test.js +621 -2
- package/docs/platform-capabilities.md +13 -6
- package/docs/system-one-cycle.md +12 -3
- package/docs/system-one-observations.md +35 -4
- package/hooks/scripts/lib/observations.js +5 -3
- 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 +5 -3
- package/plugins/harness-everything/plugin.json +1 -1
- package/sbom.cdx.json +7 -7
- package/scripts/system-one-curves.js +154 -14
- package/scripts/system-one-cycle/collect.js +20 -3
- package/scripts/system-one-cycle/common.js +39 -1
- package/scripts/system-one-cycle/evaluate.js +8 -5
- package/scripts/system-one-cycle.js +7 -2
- package/scripts/system-one-observations-export.js +29 -0
- package/scripts/system-one-observations-import-store.js +128 -0
|
@@ -17,6 +17,182 @@ const router = require('../harness-everything/scripts/system-one/router');
|
|
|
17
17
|
const { CATALOGS } = require('../harness-everything/scripts/system-one/catalogs');
|
|
18
18
|
|
|
19
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
|
+
}
|
|
20
196
|
|
|
21
197
|
function writeJsonl(file, rows) {
|
|
22
198
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
@@ -146,6 +322,13 @@ test('cycle dataset uses text-only labels, consensus, behavior evidence, holdout
|
|
|
146
322
|
test('collect preserves self-reported intents from the actual session export shape', t => {
|
|
147
323
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'system-one-cycle-collect-'));
|
|
148
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 });
|
|
149
332
|
try {
|
|
150
333
|
fs.mkdirSync(sessions, { recursive: true });
|
|
151
334
|
const startedAt = new Date(Date.now() - 60_000).toISOString();
|
|
@@ -169,6 +352,10 @@ test('collect preserves self-reported intents from the actual session export sha
|
|
|
169
352
|
assert.equal(labels.length, 1);
|
|
170
353
|
assert.deepEqual(labels[0].intents, ['fix', 'explain']);
|
|
171
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
|
+
}
|
|
172
359
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
173
360
|
}
|
|
174
361
|
});
|
|
@@ -563,6 +750,13 @@ test('all --until build uses prepared synthetic stages and stops before training
|
|
|
563
750
|
const base = path.join(root, '.s1-work');
|
|
564
751
|
fs.mkdirSync(base, { recursive: true });
|
|
565
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);
|
|
566
760
|
try {
|
|
567
761
|
const fixture = syntheticCycle(dir);
|
|
568
762
|
fs.writeFileSync(path.join(dir, 'cycle-state.json'), JSON.stringify({ schemaVersion: 1, steps: {
|
|
@@ -570,8 +764,10 @@ test('all --until build uses prepared synthetic stages and stops before training
|
|
|
570
764
|
label: { completedAt: '2026-11-14T00:00:00.000Z' },
|
|
571
765
|
judge: { completedAt: '2026-11-14T00:00:00.000Z' },
|
|
572
766
|
} }));
|
|
573
|
-
const result = spawnSync(process.execPath, [path.join(root, 'scripts/system-one-cycle.js'), 'all', '--until', 'build', '--data-dir', dir,
|
|
574
|
-
|
|
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 },
|
|
575
771
|
});
|
|
576
772
|
assert.equal(result.status, 0, result.stderr);
|
|
577
773
|
assert.equal(result.stdout.includes('synthetic-'), false);
|
|
@@ -581,5 +777,428 @@ test('all --until build uses prepared synthetic stages and stops before training
|
|
|
581
777
|
assert.equal(fs.existsSync(path.join(dir, 'training/runs')), false);
|
|
582
778
|
} finally {
|
|
583
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);
|
|
584
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');
|
|
585
1204
|
});
|