harness-everything 0.51.0 → 0.52.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 +34 -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/ci/mechanism-2am-observations-session-import.test.js +4 -1
- package/ci/mechanism-34-observations.test.js +127 -23
- package/ci/mechanism-349-ci-change-scope.test.js +260 -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 +206 -0
- package/ci/mechanism-system-one-cycle.test.js +585 -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/routing.md +2 -2
- package/docs/system-one-cycle.md +68 -0
- package/docs/system-one-observations.md +9 -8
- 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 +43 -4
- 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 +43 -4
- 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 +332 -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 +50 -0
- package/scripts/system-one-cycle/common.js +137 -0
- package/scripts/system-one-cycle/engines.js +62 -0
- package/scripts/system-one-cycle/evaluate.js +70 -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 +131 -0
- package/scripts/system-one-observations-export.js +29 -6
- package/scripts/system-one-observations-review.js +4 -5
- package/scripts/system-one-train.py +117 -61
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Component tests for the script-generated hand-off file (#233 / #409 L0).
|
|
4
|
+
// The generator writes a Markdown work order whose first bytes are a short YAML
|
|
5
|
+
// header; these tests pin the round-trip and the three rejection paths.
|
|
6
|
+
|
|
7
|
+
const assert = require('node:assert');
|
|
8
|
+
const { test } = require('node:test');
|
|
9
|
+
const { execFileSync } = require('node:child_process');
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const os = require('node:os');
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
|
|
14
|
+
const SCRIPT = path.join(__dirname, '..', 'scripts', 'handoff-file.js');
|
|
15
|
+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-handoff-'));
|
|
16
|
+
|
|
17
|
+
function run(args) {
|
|
18
|
+
return execFileSync(process.execPath, [SCRIPT, ...args], { encoding: 'utf8' });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function expectFailure(args) {
|
|
22
|
+
try {
|
|
23
|
+
run(args);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
return String(err.stderr || err.message);
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`expected failure for: ${args.join(' ')}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
test('new writes a header that header round-trips back', () => {
|
|
31
|
+
const out = path.join(tempRoot, 'roundtrip.md');
|
|
32
|
+
run([
|
|
33
|
+
'new',
|
|
34
|
+
'--kind', 'implement',
|
|
35
|
+
'--title', 'Cache fix',
|
|
36
|
+
'--summary', 'Keep the read cache warm across restarts',
|
|
37
|
+
'--out', out,
|
|
38
|
+
'--writes', 'a.js,b.js',
|
|
39
|
+
'--gate', 'node --test passes',
|
|
40
|
+
'--report', 'reports/R.md',
|
|
41
|
+
]);
|
|
42
|
+
assert.deepStrictEqual(JSON.parse(run(['header', out])), {
|
|
43
|
+
'harness-handoff': 1,
|
|
44
|
+
kind: 'implement',
|
|
45
|
+
title: 'Cache fix',
|
|
46
|
+
summary: 'Keep the read cache warm across restarts',
|
|
47
|
+
writes: ['a.js', 'b.js'],
|
|
48
|
+
gate: 'node --test passes',
|
|
49
|
+
report: 'reports/R.md',
|
|
50
|
+
});
|
|
51
|
+
const body = fs.readFileSync(out, 'utf8');
|
|
52
|
+
for (const section of ['## Scope anchor', '## Task', '## Write-set', '## Verification', '## Report']) {
|
|
53
|
+
assert.ok(body.includes(section), `body is missing ${section}`);
|
|
54
|
+
}
|
|
55
|
+
assert.ok(body.trimEnd().endsWith('-->'), 'body should end with the pending status comment');
|
|
56
|
+
assert.strictEqual(run(['check', out]).trim().endsWith('ok (kind=implement)'), true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('a summary longer than 200 characters is rejected', () => {
|
|
60
|
+
const out = path.join(tempRoot, 'long-summary.md');
|
|
61
|
+
const stderr = expectFailure([
|
|
62
|
+
'new',
|
|
63
|
+
'--kind', 'test',
|
|
64
|
+
'--title', 'Too long',
|
|
65
|
+
'--summary', 'a'.repeat(201),
|
|
66
|
+
'--out', out,
|
|
67
|
+
]);
|
|
68
|
+
assert.match(stderr, /200 characters/);
|
|
69
|
+
assert.strictEqual(fs.existsSync(out), false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a file without a header is rejected', () => {
|
|
73
|
+
const out = path.join(tempRoot, 'no-header.md');
|
|
74
|
+
fs.writeFileSync(out, '# Just prose\n', 'utf8');
|
|
75
|
+
assert.match(expectFailure(['header', out]), /no handoff header/);
|
|
76
|
+
assert.match(expectFailure(['check', out]), /no handoff header/);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('a header larger than 2 KB is rejected', () => {
|
|
80
|
+
const out = path.join(tempRoot, 'too-large.md');
|
|
81
|
+
fs.writeFileSync(out, `---\nharness-handoff: 1\nkind: implement\ntitle: "${'a'.repeat(3000)}"\n---\n`, 'utf8');
|
|
82
|
+
assert.match(expectFailure(['header', out]), /exceeds 2048 bytes/);
|
|
83
|
+
assert.match(expectFailure(['check', out]), /exceeds 2048 bytes/);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('values containing ":" and "#" survive the round-trip', () => {
|
|
87
|
+
const out = path.join(tempRoot, 'punct.md');
|
|
88
|
+
run([
|
|
89
|
+
'new',
|
|
90
|
+
'--kind', 'question',
|
|
91
|
+
'--title', 'Fix: cache #1',
|
|
92
|
+
'--summary', 'Why: it drops keys #2',
|
|
93
|
+
'--out', out,
|
|
94
|
+
'--gate', 'reviewer #A signs off: yes',
|
|
95
|
+
]);
|
|
96
|
+
const header = JSON.parse(run(['header', out]));
|
|
97
|
+
assert.strictEqual(header.title, 'Fix: cache #1');
|
|
98
|
+
assert.strictEqual(header.summary, 'Why: it drops keys #2');
|
|
99
|
+
assert.strictEqual(header.gate, 'reviewer #A signs off: yes');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('new refuses a header it would write larger than 2 KB', () => {
|
|
103
|
+
const out = path.join(tempRoot, 'new-too-large.md');
|
|
104
|
+
const stderr = expectFailure([
|
|
105
|
+
'new',
|
|
106
|
+
'--kind', 'implement',
|
|
107
|
+
'--title', 'a'.repeat(3000),
|
|
108
|
+
'--summary', 'S',
|
|
109
|
+
'--out', out,
|
|
110
|
+
]);
|
|
111
|
+
assert.match(stderr, /exceeds 2048 bytes/);
|
|
112
|
+
assert.strictEqual(fs.existsSync(out), false);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('an unknown key is rejected', () => {
|
|
116
|
+
const out = path.join(tempRoot, 'unknown-key.md');
|
|
117
|
+
run(['new', '--kind', 'design', '--title', 'T', '--summary', 'S', '--out', out]);
|
|
118
|
+
const body = fs.readFileSync(out, 'utf8').replace('summary: S', 'summary: S\nmystery: 7');
|
|
119
|
+
fs.writeFileSync(out, body, 'utf8');
|
|
120
|
+
assert.match(expectFailure(['check', out]), /unknown header key/);
|
|
121
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const { test } = require('node:test');
|
|
3
3
|
const assert = require('node:assert/strict');
|
|
4
|
-
const { createRequest, validateRequest, decide } = require('../harness-everything/scripts/system-one/contract');
|
|
4
|
+
const { createRequest, validateRequest, validateResponse, decide } = require('../harness-everything/scripts/system-one/contract');
|
|
5
5
|
const options = [{ id: 'tier1', text: 'Bounded edit' }, { id: 'tier3', text: 'Architecture' }];
|
|
6
6
|
const request = () => createRequest('tier', '修正 typo', options);
|
|
7
7
|
function response(req, p = [0.95, 0.05]) {
|
|
@@ -29,12 +29,19 @@ test('S1-C02 rejected input partitions and byte boundaries', () => {
|
|
|
29
29
|
const r = request(); mutate(r); assert.throws(() => validateRequest(r));
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
+
test('legacy requests reject one option while live validity can opt in', () => {
|
|
33
|
+
const single = [{ id: 'invalid', text: 'Needs context' }];
|
|
34
|
+
assert.throws(() => createRequest('validity', 'current text', single), { code: 'invalid-request' });
|
|
35
|
+
const live = createRequest('validity', 'current text', single, { minOptions: 1 });
|
|
36
|
+
assert.equal(validateRequest(live), true);
|
|
37
|
+
});
|
|
32
38
|
test('S1-C03 complete output validation and no raw-data leakage', () => {
|
|
33
39
|
const req = request();
|
|
34
|
-
for (const mutate of [r => { r.schemaVersion = 2; }, r => { r.requestHash = 'stale'; }, r => { r.catalogHash = 'stale'; }, r => { r.scores.pop(); }, r => { r.scores.push(r.scores[0]); }, r => { r.scores.reverse(); }, r => { r.scores[1].id = r.scores[0].id; }, r => { r.scores[0].probability = NaN; }, r => { r.scores[0].probability = Infinity; }, r => { r.scores[0].probability = -1; }, r => { r.scores[0].probability = 1.1; }, r => { r.scores[0].probability = '0.95'; }, r => { r.scores[0].
|
|
40
|
+
for (const mutate of [r => { r.schemaVersion = 2; }, r => { r.requestHash = 'stale'; }, r => { r.catalogHash = 'stale'; }, r => { r.scores.pop(); }, r => { r.scores.push(r.scores[0]); }, r => { r.scores.reverse(); }, r => { r.scores[1].id = r.scores[0].id; }, r => { r.scores[0].probability = NaN; }, r => { r.scores[0].probability = Infinity; }, r => { r.scores[0].probability = -1; }, r => { r.scores[0].probability = 1.1; }, r => { r.scores[0].probability = '0.95'; }, r => { r.scores[0].extra = 'secret'; }, r => { r.model.extra = 'secret'; }, r => { r.model.revision = ''; }, r => { delete r.model; }, r => { r.extra = 'secret'; }]) {
|
|
35
41
|
const res = response(req); mutate(res);
|
|
36
42
|
assert.deepEqual(decide(req, res), { status: 'invalid-output', reason: 'invalid-response', selectedId: null, confidence: null, margin: null, model: null });
|
|
37
43
|
}
|
|
44
|
+
assert.equal(validateResponse(req, response(req, [0.8, 0.75])), true);
|
|
38
45
|
for (const value of [null, [], 'invalid']) assert.equal(decide(req, value).status, 'invalid-output');
|
|
39
46
|
});
|
|
40
47
|
test('S1-C04 abstention and policy boundaries', () => {
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { test } = require('node:test');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { spawnSync } = require('node:child_process');
|
|
7
|
+
const assert = require('node:assert/strict');
|
|
8
|
+
|
|
9
|
+
const root = path.resolve(__dirname, '..');
|
|
10
|
+
const cli = path.join(root, 'scripts/system-one-curves.js');
|
|
11
|
+
function fixture(t, { stage = 'validity', options = ['invalid'], referenceOnly = [] } = {}) {
|
|
12
|
+
const dir = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), 'harness-s1-curves-')));
|
|
13
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
14
|
+
const versionDir = path.join(dir, 'version');
|
|
15
|
+
fs.mkdirSync(versionDir);
|
|
16
|
+
const history = path.join(dir, 'history.jsonl');
|
|
17
|
+
const out = path.join(dir, 'out');
|
|
18
|
+
const writeVersion = version => {
|
|
19
|
+
const catalogs = { validity: ['invalid'], intent: ['fix'], tier: ['tier1'] };
|
|
20
|
+
catalogs[stage] = options;
|
|
21
|
+
const stages = Object.fromEntries(Object.entries(catalogs).map(([name, ids]) => {
|
|
22
|
+
const weights = `${name}.bin`; const config = `${name}.json`;
|
|
23
|
+
fs.writeFileSync(path.join(versionDir, weights), 'fixture');
|
|
24
|
+
fs.writeFileSync(path.join(versionDir, config), '{}\n');
|
|
25
|
+
const thresholds = Object.fromEntries(ids.map(id => [id, name === stage && referenceOnly.includes(id) ? 1 : 0.5]));
|
|
26
|
+
return [name, { weights, config, sha256: '0'.repeat(64), options: ids, thresholds,
|
|
27
|
+
...(name === stage && referenceOnly.length ? { referenceOnly } : {}) }];
|
|
28
|
+
}));
|
|
29
|
+
const manifest = {
|
|
30
|
+
schemaVersion: 1,
|
|
31
|
+
version,
|
|
32
|
+
createdAt: '2026-11-14T00:00:00.000Z',
|
|
33
|
+
stages,
|
|
34
|
+
evaluation: null,
|
|
35
|
+
};
|
|
36
|
+
fs.writeFileSync(path.join(versionDir, 'manifest.json'), JSON.stringify(manifest));
|
|
37
|
+
return manifest;
|
|
38
|
+
};
|
|
39
|
+
function run({ version = 'v1', val, holdout, mutateManifest, expectFailure = false } = {}) {
|
|
40
|
+
const manifest = writeVersion(version);
|
|
41
|
+
if (mutateManifest) {
|
|
42
|
+
mutateManifest(manifest);
|
|
43
|
+
fs.writeFileSync(path.join(versionDir, 'manifest.json'), JSON.stringify(manifest));
|
|
44
|
+
}
|
|
45
|
+
const valFile = path.join(dir, `${version}-val.jsonl`);
|
|
46
|
+
fs.writeFileSync(valFile, val.map(row => JSON.stringify(row)).join('\n') + '\n');
|
|
47
|
+
const args = [cli, '--version', version, '--version-dir', versionDir, '--val-scores', `${stage}=${valFile}`, '--history', history, '--out', out];
|
|
48
|
+
if (holdout) {
|
|
49
|
+
const holdoutFile = path.join(dir, `${version}-holdout.jsonl`);
|
|
50
|
+
fs.writeFileSync(holdoutFile, holdout.map(row => JSON.stringify(row)).join('\n') + '\n');
|
|
51
|
+
args.splice(args.indexOf('--history'), 0, '--holdout-scores', `${stage}=${holdoutFile}`);
|
|
52
|
+
}
|
|
53
|
+
const child = spawnSync(process.execPath, args, { cwd: root, encoding: 'utf8', env: { ...process.env, HARNESS_SYSTEM_ONE_HOME: dir } });
|
|
54
|
+
if (expectFailure) {
|
|
55
|
+
assert.notEqual(child.status, 0, child.stdout);
|
|
56
|
+
return child;
|
|
57
|
+
}
|
|
58
|
+
assert.equal(child.status, 0, child.stderr || child.stdout);
|
|
59
|
+
return {
|
|
60
|
+
stdout: child.stdout.trim(),
|
|
61
|
+
curves: JSON.parse(fs.readFileSync(path.join(out, 'curves.json'), 'utf8')),
|
|
62
|
+
trend: JSON.parse(fs.readFileSync(path.join(out, 'trend.json'), 'utf8')),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return { dir, history, run };
|
|
66
|
+
}
|
|
67
|
+
const validityRows = probabilities => probabilities.map(([gold, p], i) => ({ id: `v${i}`, gold, scores: { invalid: p } }));
|
|
68
|
+
const tierRows = (scores, prefix = 't') => scores.map(([gold, a, b], i) => ({ id: `${prefix}${i}`, gold, scores: { a, b } }));
|
|
69
|
+
|
|
70
|
+
test('hand-computed proper scores average independent options without a sum-to-one rule', t => {
|
|
71
|
+
const f = fixture(t, { stage: 'tier', options: ['a', 'b'] });
|
|
72
|
+
const { curves } = f.run({ val: tierRows([['a', 0.8, 0.3], ['b', 0.2, 0.7]]) });
|
|
73
|
+
assert.ok(Math.abs(curves.stages.tier.logLoss - (-Math.log(0.8) - Math.log(0.7)) / 2) < 1e-12);
|
|
74
|
+
assert.ok(Math.abs(curves.stages.tier.brier - 0.065) < 1e-12);
|
|
75
|
+
assert.equal(curves.stages.tier.coverageCurve.length, 101);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('perfectly calibrated synthetic probabilities have zero ECE', t => {
|
|
79
|
+
const f = fixture(t);
|
|
80
|
+
const rows = [
|
|
81
|
+
...Array.from({ length: 10 }, (_, i) => [i < 2 ? 'invalid' : 'actionable', 0.2]),
|
|
82
|
+
...Array.from({ length: 10 }, (_, i) => [i < 8 ? 'invalid' : 'actionable', 0.8]),
|
|
83
|
+
];
|
|
84
|
+
const { curves } = f.run({ val: validityRows(rows) });
|
|
85
|
+
assert.ok(curves.stages.validity.ece < 1e-12);
|
|
86
|
+
assert.equal(curves.stages.validity.reliability.length, 10);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('better ranking with worse calibration does not auto-promote', t => {
|
|
90
|
+
const f = fixture(t, { stage: 'tier', options: ['a', 'b'] });
|
|
91
|
+
f.run({ version: 'v0', val: tierRows([['a', 0.5, 0.5], ['b', 0.5, 0.5], ['a', 0.5, 0.5], ['b', 0.5, 0.5]]) });
|
|
92
|
+
const { curves, trend } = f.run({ version: 'v1', val: tierRows([
|
|
93
|
+
['a', 0.95, 0.1], ['b', 0.1, 0.95], ['a', 0.95, 0.1], ['b', 0.95, 0.9],
|
|
94
|
+
]) });
|
|
95
|
+
assert.equal(trend.verdict, 'hold');
|
|
96
|
+
assert.ok(curves.stages.tier.ece > 0);
|
|
97
|
+
assert.ok(trend.reasons.some(reason => reason.includes('coverage-accuracy AUC delta +')));
|
|
98
|
+
assert.ok(trend.reasons.some(reason => reason.includes('ECE delta +')));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('an old-holdout regression blocks promotion', t => {
|
|
102
|
+
const f = fixture(t, { stage: 'tier', options: ['a', 'b'] });
|
|
103
|
+
const goldRows = [['a', 0.8, 0.2], ['b', 0.2, 0.8], ['a', 0.8, 0.2], ['b', 0.2, 0.8]];
|
|
104
|
+
f.run({ version: 'v0', val: tierRows([['a', 0.5, 0.5], ['b', 0.5, 0.5], ['a', 0.5, 0.5], ['b', 0.5, 0.5]], 'v'), holdout: tierRows(goldRows, 'h') });
|
|
105
|
+
const { curves, trend } = f.run({ version: 'v1', val: tierRows(goldRows, 'v'), holdout: tierRows([
|
|
106
|
+
['a', 0.1, 0.9], ['b', 0.9, 0.1], ['a', 0.1, 0.9], ['b', 0.9, 0.1],
|
|
107
|
+
], 'h') });
|
|
108
|
+
assert.equal(curves.floor.oldHoldoutRegression, true);
|
|
109
|
+
assert.equal(trend.verdict, 'hold');
|
|
110
|
+
assert.ok(trend.reasons.some(reason => reason.includes('old-holdout') && reason.includes('regression')));
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('one successful run appends exactly one history line', t => {
|
|
114
|
+
const f = fixture(t);
|
|
115
|
+
const first = f.run({ val: validityRows([['invalid', 0.8], ['actionable', 0.2]]) });
|
|
116
|
+
let lines = fs.readFileSync(f.history, 'utf8').trim().split('\n');
|
|
117
|
+
assert.equal(lines.length, 1);
|
|
118
|
+
assert.deepEqual(JSON.parse(lines[0]), first.curves);
|
|
119
|
+
const second = f.run({ version: 'v2', val: validityRows([['invalid', 0.7], ['actionable', 0.3]]) });
|
|
120
|
+
lines = fs.readFileSync(f.history, 'utf8').trim().split('\n');
|
|
121
|
+
assert.equal(lines.length, 2);
|
|
122
|
+
assert.deepEqual(JSON.parse(lines[1]), second.curves);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('intent curves keep reference-only unclassified scores but never use them as the selected option', t => {
|
|
126
|
+
const f = fixture(t, { stage: 'intent', options: ['fix', 'unclassified'], referenceOnly: ['unclassified'] });
|
|
127
|
+
const { curves, trend } = f.run({ val: [
|
|
128
|
+
{ id: 'i1', gold: ['fix'], scores: { fix: 0.7, unclassified: 0.99 } },
|
|
129
|
+
] });
|
|
130
|
+
const metrics = curves.stages.intent;
|
|
131
|
+
assert.deepEqual(metrics.optionDistributions.unclassified, [0.99, 0.99, 0.99, 0.99, 0.99]);
|
|
132
|
+
assert.equal(metrics.coverageCurve[80][1], 0);
|
|
133
|
+
assert.equal(metrics.coverageCurve[70][1], 1);
|
|
134
|
+
assert.equal(trend.verdict, 'hold');
|
|
135
|
+
assert.equal(fs.existsSync(path.join(f.dir, 'out', 'curves.json')), true);
|
|
136
|
+
assert.equal(fs.existsSync(path.join(f.dir, 'out', 'trend.json')), true);
|
|
137
|
+
assert.equal(fs.readFileSync(f.history, 'utf8').trim().split('\n').length, 1);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('curves rejects malformed reference-only metadata and score rows that omit catalog ids', t => {
|
|
141
|
+
const f = fixture(t, { stage: 'intent', options: ['fix', 'unclassified'], referenceOnly: ['unclassified'] });
|
|
142
|
+
const row = { id: 'i1', gold: ['fix'], scores: { fix: 0.7, unclassified: 0.8 } };
|
|
143
|
+
f.run({ val: [row], mutateManifest: manifest => { manifest.stages.intent.referenceOnly = ['missing']; }, expectFailure: true });
|
|
144
|
+
f.run({ val: [row], mutateManifest: manifest => { manifest.stages.intent.thresholds.unclassified = 0.9; }, expectFailure: true });
|
|
145
|
+
f.run({ val: [{ id: 'i2', gold: ['fix'], scores: { fix: 0.7 } }], expectFailure: true });
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('curves reports zero coverage when every intent option is reference-only', t => {
|
|
149
|
+
const f = fixture(t, { stage: 'intent', options: ['unclassified'], referenceOnly: ['unclassified'] });
|
|
150
|
+
const { curves } = f.run({ val: [{ id: 'i1', gold: ['unclassified'], scores: { unclassified: 0.99 } }] });
|
|
151
|
+
assert.deepEqual(curves.stages.intent.optionDistributions.unclassified, [0.99, 0.99, 0.99, 0.99, 0.99]);
|
|
152
|
+
assert.ok(curves.stages.intent.coverageCurve.every(([, coverage]) => coverage === 0));
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// F11 (#442 P1-1): validity correctness is predicted-vs-gold validity equivalence,
|
|
156
|
+
// not membership in the one-option catalog's positive set (Set([]) for gold actionable).
|
|
157
|
+
const validityCell = (t, rows, options) => {
|
|
158
|
+
const f = fixture(t, options);
|
|
159
|
+
const { stdout, curves } = f.run({ val: validityRows(rows) });
|
|
160
|
+
return { point: curves.stages.validity.coverageCurve[80], auc: JSON.parse(stdout).stages.validity.coverageAccuracyAuc };
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
test('validity cell 1: gold invalid, high p(invalid) predicts invalid and is correct', t => {
|
|
164
|
+
const cell = validityCell(t, [['invalid', 0.8]]);
|
|
165
|
+
assert.deepEqual(cell.point, [0.8, 1, 1]);
|
|
166
|
+
assert.equal(cell.auc, 1);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('validity cell 2: gold invalid, low p(invalid) predicts actionable and is wrong', t => {
|
|
170
|
+
const cell = validityCell(t, [['invalid', 0.2]]);
|
|
171
|
+
assert.deepEqual(cell.point, [0.8, 1, 0]);
|
|
172
|
+
assert.equal(cell.auc, 0);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('validity cell 3: gold actionable, low p(invalid) predicts actionable and is correct', t => {
|
|
176
|
+
const cell = validityCell(t, [['actionable', 0.2]]);
|
|
177
|
+
assert.deepEqual(cell.point, [0.8, 1, 1]);
|
|
178
|
+
assert.equal(cell.auc, 1);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('validity cell 4: gold actionable, high p(invalid) predicts invalid and is wrong', t => {
|
|
182
|
+
const cell = validityCell(t, [['actionable', 0.8]]);
|
|
183
|
+
assert.deepEqual(cell.point, [0.8, 1, 0]);
|
|
184
|
+
assert.equal(cell.auc, 0);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('validity reference-only invalid keeps its established semantics (unchanged control)', t => {
|
|
188
|
+
const f = fixture(t, { referenceOnly: ['invalid'] });
|
|
189
|
+
const { curves } = f.run({ val: validityRows([['invalid', 0.75], ['actionable', 0.25]]) });
|
|
190
|
+
const curve = curves.stages.validity.coverageCurve;
|
|
191
|
+
assert.deepEqual(curve[75], [0.75, 0.5, 1]);
|
|
192
|
+
assert.deepEqual(curve[25], [0.25, 1, 0.5]);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('active trend rolls back after two consecutive worsening cycles', t => {
|
|
196
|
+
const f = fixture(t);
|
|
197
|
+
const cycles = [
|
|
198
|
+
validityRows([['invalid', 0.8], ['invalid', 0.8], ['actionable', 0.2], ['actionable', 0.2]]),
|
|
199
|
+
validityRows([['invalid', 0.9], ['invalid', 0.9], ['actionable', 0.9], ['actionable', 0.9]]),
|
|
200
|
+
validityRows([['invalid', 0.6], ['invalid', 0.6], ['actionable', 0.9], ['actionable', 0.9]]),
|
|
201
|
+
];
|
|
202
|
+
cycles.forEach((val, i) => f.run({ version: `v${i}`, val }));
|
|
203
|
+
const { trend } = f.run({ version: 'v3', val: cycles[2] });
|
|
204
|
+
assert.equal(trend.verdict, 'rollback');
|
|
205
|
+
assert.ok(trend.reasons.some(reason => reason.includes('two consecutive')));
|
|
206
|
+
});
|