1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
|
#!/usr/bin/env node
'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const test = require('node:test');
const { materializeWorkspace, parseGrading, clearGradingSlot, persistGradingOutcome, extractExecutorModel } = require('./run-evals');
const { stageSkillResources } = require('./lib/skill-resources');
const RUNNER = path.join(__dirname, 'run-evals.js');
function writeJson(file, value) {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
}
function writeSkill(root, name, description) {
const dir = path.join(root, 'skills', name);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(
path.join(dir, 'SKILL.md'),
`---\nname: ${name}\ndescription: ${description}\n---\n\n# ${name}\n`,
);
}
function behavioralEval(files = ['project/context.txt']) {
return {
id: 1,
prompt: 'Inspect the attached project and complete the requested work.',
expected_output: 'A verified result grounded in the attached project',
files,
expectations: ['The attached project is inspected before reporting a result'],
};
}
function completeCase(skillName, positivePrompt, topK = 1, files) {
return {
skill_name: skillName,
trigger: {
positive: [1, 2, 3].map(() => ({ prompt: positivePrompt, top_k: topK })),
negative: [
{ prompt: 'unrelated banana request' },
{ prompt: 'unrelated orange request' },
],
},
evals: [behavioralEval(files)],
};
}
function makeSandbox() {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-skills-run-evals-test-'));
fs.mkdirSync(path.join(root, 'scripts'), { recursive: true });
fs.mkdirSync(path.join(root, 'evals', 'cases'), { recursive: true });
fs.mkdirSync(path.join(root, 'evals', 'fixtures', 'project'), { recursive: true });
fs.copyFileSync(RUNNER, path.join(root, 'scripts', 'run-evals.js'));
fs.cpSync(path.join(__dirname, 'lib'), path.join(root, 'scripts', 'lib'), { recursive: true });
fs.writeFileSync(path.join(root, 'evals', 'fixtures', 'project', 'context.txt'), 'fixture\n');
return root;
}
function run(root, args = []) {
return spawnSync(process.execPath, [path.join(root, 'scripts', 'run-evals.js'), ...args], {
cwd: root,
encoding: 'utf8',
});
}
function runBehavioralWithGrading(root, raw, options = {}) {
const { args = [] } = options;
writeSkill(root, 'alpha-skill', 'Handles alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals = (options.ids || [1]).map((id) => (options.execution
? { ...behavioralEval(), id }
: { ...behavioralEval([]), id, kind: 'dialogue' }));
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
for (const [rel, content] of Object.entries(options.resources || {})) {
fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true });
fs.writeFileSync(path.join(root, rel), content);
}
const stub = path.join(root, 'stub-claude.cjs');
fs.writeFileSync(stub, `
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const execute = require('child_process').execFileSync;
const temporary = fs.mkdtempSync;
fs.mkdtempSync = (prefix, ...args) => {
const dir = temporary(prefix, ...args);
if (prefix.includes('skill-resources-')) fs.writeFileSync(${JSON.stringify(path.join(root, 'staged-path.txt'))}, dir);
return dir;
};
require('child_process').execFileSync = (command, args, settings) => {
if (command !== 'claude') return execute(command, args, settings);
const executor = args.includes('--output-format');
fs.appendFileSync(${JSON.stringify(path.join(root, 'claude-calls.txt'))}, executor ? 'executor\\n' : 'grader\\n');
if (executor) { ${options.onExecute || ''} }
if (executor && ${JSON.stringify(Boolean(options.error))}) throw Object.assign(new Error('executor failed'), ${JSON.stringify(options.error || {})});
return executor ? ${JSON.stringify(options.trace ?? '{"type":"result","subtype":"success","is_error":false,"result":"done"}\n')} : ${JSON.stringify(raw)};
};
`);
return spawnSync(process.execPath, [
'--require', stub, path.join(root, 'scripts', 'run-evals.js'),
'--behavioral', 'alpha-skill', ...args,
], { cwd: root, encoding: 'utf8' });
}
const passingGrading = JSON.stringify({
expectations: [{ id: 1, text: 'check', passed: true, evidence: 'observed' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
});
const terminal = { type: 'result', subtype: 'success', is_error: false };
const call = { type: 'assistant', message: { content: [{ type: 'tool_use', name: 'Bash', id: 'test', input: {} }] } };
const returned = (id, is_error = false) => ({ type: 'user', message: { content: [{ type: 'tool_result', tool_use_id: id, is_error }] } });
const traceOf = (...events) => events.map((event) => JSON.stringify(event)).join('\n') + '\n';
for (const [name, trace] of Object.entries({
'terminal error': traceOf({ type: 'result', subtype: 'error_max_turns', is_error: true }),
'missing terminal': traceOf(call),
'implicit success': traceOf({ type: 'result', subtype: 'success' }),
'stale terminal': traceOf(terminal, call),
'permission denial': traceOf({ ...terminal, permission_denials: [{ tool_name: 'Read' }] }),
'pending tool': traceOf(call, terminal),
'unmatched return': traceOf(returned('unknown'), terminal),
'malformed event': 'null\n',
'invalid JSON': 'not JSON\n',
'null assistant message': traceOf({ type: 'assistant', message: null }, terminal),
'array assistant message': traceOf({ type: 'assistant', message: [] }, terminal),
'null assistant content': traceOf({ type: 'assistant', message: { content: null } }, terminal),
'object assistant content': traceOf({ type: 'assistant', message: { content: { type: 'tool_use', id: 'hidden' } } }, terminal),
'null user message': traceOf({ type: 'user', message: null }, terminal),
'null content block': traceOf({ type: 'assistant', message: { content: [null] } }, terminal),
})) {
test(`does not grade an incomplete execution: ${name}`, () => {
const root = makeSandbox();
try {
const result = runBehavioralWithGrading(root, passingGrading, { trace });
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /execution incomplete/);
const base = path.join(root, 'evals/results/alpha-skill.eval-1');
assert.equal(fs.existsSync(`${base}.grading.json`), false);
assert.equal(fs.readFileSync(`${base}.execution.raw.txt`, 'utf8'), trace);
assert.equal(fs.readFileSync(path.join(root, 'claude-calls.txt'), 'utf8'), 'executor\n');
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
}
for (const id of [null, 0, 2]) {
test(id === null ? 'behavioral default grades every case' : `behavioral --eval ${id} grades only the selected case`, () => {
const root = makeSandbox();
try {
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check', passed: true, evidence: 'observed' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
});
const args = id === null ? [] : ['--eval', String(id)];
const result = runBehavioralWithGrading(root, raw, { args, ids: [0, 2] });
assert.equal(result.status, 0, result.stdout + result.stderr);
for (const candidate of [0, 2]) {
assert.equal(fs.existsSync(path.join(root, 'evals/results', `alpha-skill.eval-${candidate}.grading.json`)), id === null || id === candidate);
}
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
}
for (const fail of [false, true]) {
test(`stages local and shared resources outside the fixture tree and cleans up on ${fail ? 'failure' : 'success'}`, () => {
const root = makeSandbox();
try {
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check', passed: true, evidence: 'observed' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
});
const result = runBehavioralWithGrading(root, raw, {
execution: true,
resources: {
'skills/alpha-skill/SKILL.md': '---\nname: alpha-skill\ndescription: Handles alpha widgets.\n---\n\n# Alpha\nRead references/shared.md and the local references/local.md.',
'skills/alpha-skill/references/local.md': 'See ../../../references/shared.md',
'skills/alpha-skill/scripts/helper.js': 'local helper',
'references/shared.md': 'See nested/next.md',
'references/nested/next.md': 'transitive shared material',
},
onExecute: `
const index = args.indexOf('--add-dir');
assert.notEqual(index, -1, 'resource access must be granted');
const staged = args[index + 1];
const skill = path.join(staged, 'skills', 'alpha-skill');
const prompt = args[args.indexOf('--append-system-prompt') + 1];
assert.ok(prompt.includes('Base directory for this skill: ' + skill));
assert.ok(prompt.includes('Shared references directory: ' + path.join(staged, 'references')));
assert.ok(prompt.includes('Read references/shared.md'));
assert.equal(fs.readFileSync(path.join(staged, 'references/shared.md'), 'utf8'), 'See nested/next.md');
assert.equal(fs.readFileSync(path.join(skill, 'references/local.md'), 'utf8'), 'See ../../../references/shared.md');
assert.equal(fs.readFileSync(path.resolve(skill, '../../references/nested/next.md'), 'utf8'), 'transitive shared material');
assert.equal(fs.readFileSync(path.join(skill, 'scripts/helper.js'), 'utf8'), 'local helper');
assert.ok(path.relative(settings.cwd, staged).startsWith('..'), 'resources must stay outside the fixture tree');
assert.equal(execute('git', ['status', '--porcelain'], {cwd: settings.cwd, encoding: 'utf8'}), '');
assert.equal(execute('git', ['ls-files'], {cwd: settings.cwd, encoding: 'utf8'}).trim(), 'project/context.txt');
fs.writeFileSync(${JSON.stringify(path.join(root, 'workspace-path.txt'))}, settings.cwd);
if (${fail}) throw new Error('synthetic executor failure');
`,
});
assert.equal(result.status, fail ? 1 : 0, result.stdout + result.stderr);
const staged = fs.readFileSync(path.join(root, 'staged-path.txt'), 'utf8');
const workspace = fs.readFileSync(path.join(root, 'workspace-path.txt'), 'utf8');
assert.equal(fs.existsSync(staged), false, 'resource directory must be removed');
assert.equal(fs.existsSync(workspace), false, 'fixture workspace must be removed');
assert.equal(fs.readFileSync(path.join(root, 'references/nested/next.md'), 'utf8'), 'transitive shared material');
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
}
test('an incomplete execution saves no record and is not graded', () => {
const root = makeSandbox();
try {
const result = runBehavioralWithGrading(root, passingGrading, { trace: traceOf(call), args: ['--record'] });
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /execution incomplete/);
const results = path.join(root, 'evals/results');
assert.deepEqual(fs.readdirSync(results).filter((f) => f.endsWith('.record.json')), []);
assert.equal(fs.existsSync(path.join(results, 'alpha-skill.eval-1.grading.json')), false);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
test('a returned failed probe can recover before successful completion', () => {
const root = makeSandbox();
try {
const next = { ...call, message: { content: [{ ...call.message.content[0], id: 'green' }] } };
const trace = traceOf(call, returned('test', true),
{ type: 'user', message: { content: 'Continue the repair.' } }, next, returned('green'), terminal,
{ type: 'system', subtype: 'status', status: 'idle' });
const result = runBehavioralWithGrading(root, passingGrading, { trace });
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.equal(fs.existsSync(path.join(root, 'evals/results/alpha-skill.eval-1.grading.json')), true);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
for (const code of ['ETIMEDOUT', 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER']) {
test(`retains partial execution evidence and continues after ${code}`, () => {
const root = makeSandbox();
try {
const trace = traceOf(call);
const result = runBehavioralWithGrading(root, passingGrading,
{ error: { code, stdout: trace, stderr: 'captured diagnostic' }, ids: [1, 2] });
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /eval 2: executing/);
for (const id of [1, 2]) {
const base = path.join(root, `evals/results/alpha-skill.eval-${id}`);
assert.equal(fs.existsSync(`${base}.grading.json`), false);
assert.equal(fs.readFileSync(`${base}.execution.raw.txt`, 'utf8'), trace);
assert.match(fs.readFileSync(`${base}.execution.error.txt`, 'utf8'), new RegExp(code));
assert.match(fs.readFileSync(`${base}.execution.error.txt`, 'utf8'), /captured diagnostic/);
}
assert.equal(fs.readFileSync(path.join(root, 'claude-calls.txt'), 'utf8'), 'executor\nexecutor\n');
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
}
for (const args of [['--eval'], ['--eval', 'not-a-number'], ['--eval', '1.5'], ['--eval', '9007199254740993']]) {
test(`rejects an invalid behavioral selector ${JSON.stringify(args)}`, () => {
const root = makeSandbox();
try {
const result = run(root, ['--behavioral', 'alpha-skill', ...args]);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stderr, /--eval must be an integer case id/);
assert.equal(fs.existsSync(path.join(root, 'evals/results')), false);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
}
test('rejects an unknown behavioral case before creating results', () => {
const root = makeSandbox();
try {
const result = runBehavioralWithGrading(root, '{}', { args: ['--eval', '99'] });
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stderr, /has no behavioral eval id=99/);
assert.equal(fs.existsSync(path.join(root, 'evals/results')), false);
assert.equal(fs.existsSync(path.join(root, 'claude-calls.txt')), false);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
test('a selector does not hide duplicate IDs among unselected cases', () => {
const root = makeSandbox();
try {
const result = runBehavioralWithGrading(root, '{}', { args: ['--eval', '0'], ids: [0, 2, 2] });
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stderr, /duplicate behavioral eval id=2/);
assert.equal(fs.existsSync(path.join(root, 'evals/results')), false);
assert.equal(fs.existsSync(path.join(root, 'claude-calls.txt')), false);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
test('--eval is available only for behavioral runs', () => {
const root = makeSandbox();
try {
const result = run(root, ['--eval', '1']);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stderr, /--eval applies only to behavioral evals/);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
test('rejects symlinked resources before execution and removes partial staging', () => {
const root = makeSandbox();
try {
fs.mkdirSync(path.join(root, 'skills/alpha-skill'), { recursive: true });
fs.mkdirSync(path.join(root, 'private'));
fs.symlinkSync(path.join(root, 'private'), path.join(root, 'skills/alpha-skill/escape'), 'junction');
const result = runBehavioralWithGrading(root, '{}');
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stderr, /symbolic link in skill resources/);
assert.equal(fs.existsSync(path.join(root, 'claude-calls.txt')), false);
assert.equal(fs.existsSync(fs.readFileSync(path.join(root, 'staged-path.txt'), 'utf8')), false);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
for (const entry of ['skills', 'references']) {
test(`rejects a ${entry === 'skills' ? 'linked skill ancestor' : 'dangling shared-reference link'}`, () => {
const root = makeSandbox();
const outside = fs.mkdtempSync(path.join(os.tmpdir(), 'outside-skill-resources-'));
let staged;
try {
writeSkill(entry === 'skills' ? outside : root, 'alpha-skill', 'Handles alpha.');
const target = entry === 'skills' ? path.join(outside, 'skills') : path.join(outside, 'missing');
fs.symlinkSync(target, path.join(root, entry), 'junction');
assert.throws(() => { staged = stageSkillResources(root, 'alpha-skill'); }, /symbolic link in skill resources/);
} finally {
if (staged) fs.rmSync(staged.root, { recursive: true, force: true });
fs.rmSync(root, { recursive: true, force: true });
fs.rmSync(outside, { recursive: true, force: true });
}
});
}
test('a whole-checkout alias can stage ordinary skill resources', () => {
const root = makeSandbox();
let staged;
try {
writeSkill(root, 'alpha-skill', 'Handles alpha.');
const alias = path.join(root, 'checkout-alias');
fs.symlinkSync(root, alias, 'junction');
staged = stageSkillResources(alias, 'alpha-skill');
assert.equal(fs.readFileSync(path.join(staged.skillDir, 'SKILL.md'), 'utf8'),
fs.readFileSync(path.join(root, 'skills/alpha-skill/SKILL.md'), 'utf8'));
} finally {
if (staged) fs.rmSync(staged.root, { recursive: true, force: true });
fs.rmSync(root, { recursive: true, force: true });
}
});
for (const passed of [true, false]) {
for (const evidence of ['', ' \t\r\n', '\u00a0\u2003']) {
test(`behavioral CLI diagnoses blank evidence for ${passed ? 'passing' : 'failing'} verdict ${JSON.stringify(evidence)}`, () => {
const root = makeSandbox();
try {
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check the result', passed, evidence }],
summary: { passed: Number(passed), failed: Number(!passed), total: 1, pass_rate: Number(passed) },
});
const base = path.join(root, 'evals', 'results', 'alpha-skill.eval-1');
writeJson(`${base}.grading.json`, { stale: true });
const result = runBehavioralWithGrading(root, raw);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /grader returned blank evidence/);
assert.doesNotMatch(result.stdout, /invalid JSON/);
assert.match(result.stdout, /raw saved to .*alpha-skill\.eval-1\.grading\.raw\.txt/);
assert.equal(fs.readFileSync(`${base}.grading.raw.txt`, 'utf8'), raw);
assert.equal(fs.existsSync(`${base}.grading.json`), false);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});
}
}
for (const raw of ['not JSON', '{"expectations":', '{"expectations":[]}']) {
test(`behavioral CLI retains the generic diagnostic for invalid grading ${raw}`, () => {
const root = makeSandbox();
try {
const result = runBehavioralWithGrading(root, raw);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /grader returned invalid JSON/);
assert.doesNotMatch(result.stdout, /blank evidence/);
const base = path.join(root, 'evals', 'results', 'alpha-skill.eval-1');
assert.equal(fs.readFileSync(`${base}.grading.raw.txt`, 'utf8'), raw);
assert.equal(fs.existsSync(`${base}.grading.json`), false);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});
}
test('behavioral CLI still publishes valid grading without a rejection diagnostic', () => {
const root = makeSandbox();
try {
const evidence = ' observed in the trace ';
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check the result', passed: true, evidence }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
});
const result = runBehavioralWithGrading(root, raw);
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.doesNotMatch(result.stdout, /grader returned/);
const base = path.join(root, 'evals', 'results', 'alpha-skill.eval-1');
const grading = JSON.parse(fs.readFileSync(`${base}.grading.json`, 'utf8'));
assert.equal(grading.expectations[0].evidence, evidence);
assert.equal(fs.existsSync(`${base}.grading.raw.txt`), false);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});
test('accepts a complete and consistent grader result', () => {
const raw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed in the trace' },
{ id: 2, text: 'second expectation', passed: false, evidence: 'not observed in the trace' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.5 },
});
assert.deepEqual(parseGrading(raw, ['first expectation', 'second expectation']), JSON.parse(raw));
});
for (const passed of [true, false]) {
for (const evidence of ['', ' \t\r\n', '\u00a0\u2003']) {
test(`rejects ${passed ? 'passing' : 'failing'} grading with blank evidence ${JSON.stringify(evidence)}`, () => {
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check the result', passed, evidence }],
summary: { passed: Number(passed), failed: Number(!passed), total: 1, pass_rate: Number(passed) },
});
assert.equal(parseGrading(raw, ['check the result']), null);
});
}
}
test('preserves nonblank evidence including surrounding whitespace', () => {
const evidence = ' No matching tool call was found.\n';
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check the result', passed: false, evidence }],
summary: { passed: 0, failed: 1, total: 1, pass_rate: 0 },
});
assert.equal(parseGrading(raw, ['check the result']).expectations[0].evidence, evidence);
});
test('blank evidence retains raw grading without publishing a scored artifact', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-blank-evidence-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check the result', passed: true, evidence: '' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
});
clearGradingSlot(base);
assert.equal(persistGradingOutcome(base, parseGrading(raw, ['check the result']), raw), false);
assert.equal(fs.existsSync(`${base}.grading.json`), false);
assert.equal(fs.readFileSync(`${base}.grading.raw.txt`, 'utf8'), raw);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test('rejects grader results that omit expectations', () => {
const raw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed in the trace' },
],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
});
assert.equal(parseGrading(raw, ['first expectation', 'second expectation']), null);
});
test('rejects null expectation entries without throwing', () => {
const cases = [
{ results: [null], declared: ['first expectation'] },
{ results: [{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' }, null], declared: ['first expectation', 'second expectation'] },
];
for (const { results, declared } of cases) {
const raw = JSON.stringify({
expectations: results,
summary: {
passed: results.length - 1,
failed: 1,
total: results.length,
pass_rate: (results.length - 1) / results.length,
},
});
assert.equal(parseGrading(raw, declared), null);
}
});
test('rejects incomplete or inconsistent grader summaries', () => {
const declared = ['expected behavior'];
const expectation = { id: 1, text: 'expected behavior', passed: false, evidence: 'not observed' };
const cases = [
{
expectations: [],
summary: { passed: 0, failed: 0, total: 0, pass_rate: 0 },
declared: [],
},
{
expectations: [{ id: 1, text: 'expected behavior', passed: false }],
summary: { passed: 0, failed: 1, total: 1, pass_rate: 0 },
declared,
},
{
expectations: [expectation],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
declared,
},
{
expectations: [expectation],
summary: { passed: 0, total: 1, pass_rate: 0 },
declared,
},
{
expectations: [expectation],
summary: { passed: 0, failed: 1, total: 1 },
declared,
},
];
for (const { declared: d, ...grading } of cases) {
assert.equal(parseGrading(JSON.stringify(grading), d), null);
}
});
test('names a positive prompt that passes top_k but does not rank first', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
writeSkill(root, 'beta-skill', 'Tunes widget caches. Use when tuning the widget cache for alpha.');
writeJson(
path.join(root, 'evals', 'cases', 'alpha-skill.json'),
completeCase('alpha-skill', 'tune the alpha widget cache', 3),
);
writeJson(
path.join(root, 'evals', 'cases', 'beta-skill.json'),
completeCase('beta-skill', 'tune the widget cache', 1),
);
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.match(result.stdout, /alpha-skill: positive prompt ranked #2, inside top 3 but not first/);
assert.match(result.stdout, /#1: beta-skill \(\d\.\d{3}\) vs \d\.\d{3}/);
assert.match(result.stdout, /rank-1 rate: 50% \(3\/6/);
});
test('fails when a skill has no eval case file', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const result = run(root);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /no eval case file/);
});
test('fails when an eval case is below the required minimums', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), {
skill_name: 'alpha-skill',
trigger: {
positive: [{ prompt: 'change alpha widget', top_k: 1 }],
negative: [],
},
evals: [behavioralEval()],
});
const result = run(root);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /below required minimums/);
});
test('fails when a behavioral eval references a missing fixture', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
writeJson(
path.join(root, 'evals', 'cases', 'alpha-skill.json'),
completeCase('alpha-skill', 'change alpha widget', 1, ['missing/project.txt']),
);
const result = run(root);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /fixture not found/);
});
test('requires fixtures for execution evals', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
writeJson(
path.join(root, 'evals', 'cases', 'alpha-skill.json'),
completeCase('alpha-skill', 'change alpha widget', 1, []),
);
const result = run(root);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /needs a non-empty files\[\] fixture list/);
});
test('allows dialogue evals without fixtures', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals = [{ ...behavioralEval([]), kind: 'dialogue' }];
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
});
test('rejects provisional execution evals', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals[0].trust_level = 'provisional';
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
const result = run(root);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /is still provisional/);
});
test('allows dialogue evals with a legacy provisional marker', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals = [{ ...behavioralEval([]), kind: 'dialogue', trust_level: 'provisional' }];
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
});
test('rejects unknown behavioral eval kinds', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals[0].kind = 'conversation';
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
const result = run(root);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /unknown kind "conversation"/);
});
test('dry-runs a fixtureless dialogue eval', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals = [{ ...behavioralEval([]), kind: 'dialogue' }];
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
const result = run(root, ['--behavioral', 'alpha-skill', '--dry-run']);
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.match(result.stdout, /dialogue transcript/);
assert.match(result.stdout, /--add-dir <staged skill resources>/);
});
test('enforces the configured rank-1 floor', () => {
const root = makeSandbox();
writeSkill(root, 'alpha-skill', 'Handles widget work. Use when implementing widget changes.');
writeSkill(
root,
'beta-skill',
'Diagnoses urgent widget failures in production. Use when repairing urgent widget failures.',
);
writeJson(
path.join(root, 'evals', 'cases', 'alpha-skill.json'),
completeCase('alpha-skill', 'urgent widget failure production', 2),
);
writeJson(
path.join(root, 'evals', 'cases', 'beta-skill.json'),
completeCase('beta-skill', 'repair urgent widget failure', 1),
);
const passing = run(root, ['--min-rank1', '50']);
const failing = run(root, ['--min-rank1', '60']);
assert.equal(passing.status, 0, passing.stdout + passing.stderr);
assert.equal(failing.status, 1, failing.stdout + failing.stderr);
assert.match(failing.stdout, /below required 60%/);
});
test('rejects an invalid rank-1 floor', () => {
const root = makeSandbox();
const result = run(root, ['--min-rank1', '101']);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stderr, /--min-rank1 must be a number from 0 to 100/);
});
test('routes clipped prompt forms to their long-form skill (see #660)', () => {
const root = makeSandbox();
// Note: the skill name must not contain the clipped form itself — name
// tokens are weighted 2x, which would route the prompt even without the
// alias map. The prompt shares no vocabulary with the description except
// the clipped/long pair (auth/authentication): without the alias map the
// skill scores zero and the positive prompt fails.
writeSkill(
root,
'credential-skill',
'Protects credential verification. Use when configuring authentication ceremonies.',
);
writeSkill(root, 'paint-skill', 'Paints sheds. Use when choosing exterior paint colors.');
writeJson(
path.join(root, 'evals', 'cases', 'credential-skill.json'),
completeCase('credential-skill', 'fix broken auth checks', 1),
);
writeJson(
path.join(root, 'evals', 'cases', 'paint-skill.json'),
completeCase('paint-skill', 'choose exterior paint colors', 1),
);
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
});
test('folds -ifications to their -ify verb, not to the unrelated "specific" (see #660)', () => {
const root = makeSandbox();
// "specification" is a nominalization of "specify", so it must reach the
// spec skill. Stripping a bare "-ation" instead yields "specific", which
// silently cross-merges the two words and starves the spec skill. Each
// prompt shares vocabulary with its own skill only.
writeSkill(root, 'spec-skill', 'Agree on requirements up front. Use when you specify behaviour.');
writeSkill(root, 'specific-skill', 'Narrow a choice down. Use when one target matters.');
writeJson(
path.join(root, 'evals', 'cases', 'spec-skill.json'),
completeCase('spec-skill', 'document a specification for the billing rollout', 1),
);
writeJson(
path.join(root, 'evals', 'cases', 'specific-skill.json'),
completeCase('specific-skill', 'narrow the choice down to one target', 1),
);
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
});
test('strips -ations as well as -ation so plurals do not out-stem singulars (see #660)', () => {
const root = makeSandbox();
// "migration" and "migrations" are the same word, so both forms have to
// reach the migration skill. With only "-ation" in the suffix list the
// plural keeps its "-s" ("migration" -> "migr" vs "migrations" ->
// "migration"), which splits the pair and halves the score. Neither
// prompt shares vocabulary with the other skill.
writeSkill(root, 'migration-skill', 'Move old data stores off production without downtime.');
writeSkill(root, 'recipe-skill', 'Plan tonight dinner from what is already in the cupboard.');
writeJson(
path.join(root, 'evals', 'cases', 'migration-skill.json'),
completeCase('migration-skill', 'plan the database migrations', 1),
);
writeJson(
path.join(root, 'evals', 'cases', 'recipe-skill.json'),
completeCase('recipe-skill', 'plan tonight dinner from the cupboard', 1),
);
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
});
// ---------- parseGrading expectation-binding tests ----------
test('accepts reordered-but-complete grader results', () => {
const expectations = ['first expectation', 'second expectation'];
const raw = JSON.stringify({
expectations: [
{ id: 2, text: 'second expectation', passed: false, evidence: 'not observed' },
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed in the trace' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.5 },
});
const result = parseGrading(raw, expectations);
assert.notEqual(result, null);
assert.equal(result.summary.passed, 1);
assert.equal(result.summary.failed, 1);
});
test('rejects duplicate grader results for the same expectation', () => {
const expectations = ['first expectation', 'second expectation'];
// Valid baseline: each id appears exactly once
const validRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 2, text: 'second expectation', passed: false, evidence: 'not observed' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.5 },
});
assert.notEqual(parseGrading(validRaw, expectations), null);
// Duplicate: id 1 appears twice, id 2 is missing
const dupRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed again' },
],
summary: { passed: 2, failed: 0, total: 2, pass_rate: 1 },
});
assert.equal(parseGrading(dupRaw, expectations), null);
});
test('rejects grader results whose ids are not in the declared set', () => {
const expectations = ['first expectation', 'second expectation'];
// Valid baseline
const validRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 2, text: 'second expectation', passed: false, evidence: 'not observed' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.5 },
});
assert.notEqual(parseGrading(validRaw, expectations), null);
// id 3 is out of range 1..2
const badIdRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 3, text: 'unknown expectation', passed: false, evidence: 'not found' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.5 },
});
assert.equal(parseGrading(badIdRaw, expectations), null);
});
test('rejects a result set that omits a declared expectation', () => {
const expectations = ['first expectation', 'second expectation', 'third expectation'];
// Valid baseline
const validRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 2, text: 'second expectation', passed: true, evidence: 'observed' },
{ id: 3, text: 'third expectation', passed: false, evidence: 'not observed' },
],
summary: { passed: 2, failed: 1, total: 3, pass_rate: 2 / 3 },
});
assert.notEqual(parseGrading(validRaw, expectations), null);
// Only 2 results for 3 expectations (id 3 omitted)
const partialRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 2, text: 'second expectation', passed: true, evidence: 'observed' },
],
summary: { passed: 2, failed: 0, total: 2, pass_rate: 1 },
});
assert.equal(parseGrading(partialRaw, expectations), null);
});
test('derives pass_rate from counters rather than trusting the grader value', () => {
const expectations = ['first expectation', 'second expectation'];
// Correct pass_rate should be accepted
const validRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 2, text: 'second expectation', passed: false, evidence: 'not observed' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.5 },
});
const valid = parseGrading(validRaw, expectations);
assert.notEqual(valid, null);
assert.equal(valid.summary.pass_rate, 0.5);
// Wrong pass_rate with correct counters: accepted, but recomputed
const wrongRaw = JSON.stringify({
expectations: [
{ id: 1, text: 'first expectation', passed: true, evidence: 'observed' },
{ id: 2, text: 'second expectation', passed: false, evidence: 'not observed' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.999 },
});
const corrected = parseGrading(wrongRaw, expectations);
assert.notEqual(corrected, null);
assert.equal(corrected.summary.pass_rate, 0.5);
// The integer counters stay exact checks
assert.equal(corrected.summary.passed, 1);
assert.equal(corrected.summary.failed, 1);
});
test('replaces paraphrased grader text with the declared expectation', () => {
const expectations = ['first expectation', 'second expectation'];
const raw = JSON.stringify({
expectations: [
{ id: 2, text: 'the agent did the second thing', passed: false, evidence: 'not observed' },
{ id: 1, text: 'roughly the first one', passed: true, evidence: 'observed' },
],
summary: { passed: 1, failed: 1, total: 2, pass_rate: 0.5 },
});
const result = parseGrading(raw, expectations);
assert.notEqual(result, null);
assert.equal(result.expectations.find((r) => r.id === 1).text, 'first expectation');
assert.equal(result.expectations.find((r) => r.id === 2).text, 'second expectation');
});
// ---------- persistGradingOutcome stale-cleanup tests ----------
test('rejected grading writes raw output', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-cleanup-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
const result = persistGradingOutcome(base, null, 'unparseable grader output');
assert.equal(result, false);
assert.equal(fs.existsSync(`${base}.grading.raw.txt`), true, 'raw output must be written');
assert.equal(fs.readFileSync(`${base}.grading.raw.txt`, 'utf8'), 'unparseable grader output');
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test('rejected grading succeeds even when no prior grading.json exists', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-cleanup-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
const result = persistGradingOutcome(base, null, 'bad output');
assert.equal(result, false);
assert.equal(fs.existsSync(`${base}.grading.raw.txt`), true);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test('accepted grading writes grading.json', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-cleanup-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
const grading = {
expectations: [{ id: 1, text: 'x', passed: true, evidence: 'y' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
};
const result = persistGradingOutcome(base, grading, 'unused');
assert.equal(result, true);
const written = JSON.parse(fs.readFileSync(`${base}.grading.json`, 'utf8'));
assert.deepEqual(written, grading);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
// ---------- upfront slot-clearing tests ----------
test('a grader that throws leaves no result file behind', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-crash-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
// Stale files from a prior run
fs.writeFileSync(`${base}.grading.json`, '{"previous":"run"}\n');
fs.writeFileSync(`${base}.grading.raw.txt`, 'previous raw output');
fs.writeFileSync(`${base}.execution.raw.txt`, 'previous partial trace');
fs.writeFileSync(`${base}.execution.error.txt`, 'previous execution failure');
clearGradingSlot(base);
// Executor or grader crashes — persistGradingOutcome is never called
assert.equal(fs.existsSync(`${base}.grading.json`), false, 'stale grading.json must not survive a crash');
assert.equal(fs.existsSync(`${base}.grading.raw.txt`), false, 'stale grading.raw.txt must not survive a crash');
assert.equal(fs.existsSync(`${base}.execution.raw.txt`), false, 'old partial trace must not survive a new attempt');
assert.equal(fs.existsSync(`${base}.execution.error.txt`), false, 'old execution failure must not survive a new attempt');
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test('successful grading leaves no stale raw file behind', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-success-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
// Stale raw from a prior rejected run
fs.writeFileSync(`${base}.grading.raw.txt`, 'previous raw output');
clearGradingSlot(base);
// Successful grading
const grading = {
expectations: [{ id: 1, text: 'x', passed: true, evidence: 'y' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
};
persistGradingOutcome(base, grading, 'unused');
assert.equal(fs.existsSync(`${base}.grading.json`), true, 'grading.json must be written');
assert.equal(fs.existsSync(`${base}.grading.raw.txt`), false, 'stale grading.raw.txt must not survive');
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
// ---------- extractExecutorModel tests ----------
test('extracts model from the stream-json init event', () => {
const trace = [
'{"type":"system","subtype":"init","model":"claude-sonnet-4-6-20250514","session_id":"abc"}',
'{"type":"assistant","message":{"id":"msg_1","content":[{"type":"text","text":"Hi"}]}}',
'{"type":"result","subtype":"success","result":"Hi"}',
].join('\n');
assert.equal(extractExecutorModel(trace), 'claude-sonnet-4-6-20250514');
});
test('returns null when the trace has no init event', () => {
const trace = [
'{"type":"assistant","message":{"id":"msg_1","content":[]}}',
'{"type":"result","subtype":"success","result":"done"}',
].join('\n');
assert.equal(extractExecutorModel(trace), null);
});
test('returns null when the init event has no model field', () => {
const trace = '{"type":"system","subtype":"init","session_id":"abc"}\n';
assert.equal(extractExecutorModel(trace), null);
});
test('tolerates non-JSON lines in the trace', () => {
const trace = [
'not json',
'{"type":"system","subtype":"init","model":"claude-opus-4-6","session_id":"abc"}',
].join('\n');
assert.equal(extractExecutorModel(trace), 'claude-opus-4-6');
});
// ---------- persistGradingOutcome run identity tests ----------
test('accepted grading includes run metadata when provided', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-run-meta-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
const grading = {
expectations: [{ id: 1, text: 'x', passed: true, evidence: 'y' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
};
const runMeta = {
executor_model: 'claude-sonnet-4-6-20250514',
grader_model: 'unknown',
timestamp: '2026-09-21T00:00:00.000Z',
};
persistGradingOutcome(base, grading, 'unused', runMeta);
const written = JSON.parse(fs.readFileSync(`${base}.grading.json`, 'utf8'));
assert.deepEqual(written.run, runMeta);
assert.deepEqual(written.expectations, grading.expectations);
assert.deepEqual(written.summary, grading.summary);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test('accepted grading omits run key when no metadata is provided', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'grading-no-meta-'));
try {
const base = path.join(dir, 'my-skill.eval-1');
const grading = {
expectations: [{ id: 1, text: 'x', passed: true, evidence: 'y' }],
summary: { passed: 1, failed: 0, total: 1, pass_rate: 1 },
};
persistGradingOutcome(base, grading, 'unused');
const written = JSON.parse(fs.readFileSync(`${base}.grading.json`, 'utf8'));
assert.equal('run' in written, false);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test('materializes a git baseline and applies a working-tree patch', () => {
const workspace = materializeWorkspace({ files: ['git-workflow-and-versioning'] });
try {
const status = spawnSync('git', ['status', '--short'], { cwd: workspace, encoding: 'utf8' });
const commits = spawnSync('git', ['rev-list', '--count', 'HEAD'], { cwd: workspace, encoding: 'utf8' });
assert.equal(status.status, 0, status.stdout + status.stderr);
assert.match(status.stdout, / M git-workflow-and-versioning\/app\.js/);
assert.equal(commits.stdout.trim(), '1');
assert.equal(fs.existsSync(path.join(workspace, '.eval')), false);
} finally {
fs.rmSync(workspace, { recursive: true, force: true });
}
});
// The real CLI, with only the paid Claude subprocess replaced. Works without
// a shell shim on Windows as well as Unix; git and filesystem operations stay real.
function recordedSandbox(t, kind = 'dialogue') {
const root = makeSandbox();
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
writeSkill(root, 'alpha-skill', 'Handles alpha widgets.');
fs.mkdirSync(path.join(root, 'skills/alpha-skill/references'));
fs.writeFileSync(path.join(root, 'skills/alpha-skill/references/guide.md'), 'local reference');
fs.mkdirSync(path.join(root, 'references'));
fs.writeFileSync(path.join(root, 'references/shared.md'), 'shared reference');
const rubric = completeCase('alpha-skill', 'change alpha widget');
rubric.evals = [{ ...behavioralEval(kind === 'dialogue' ? [] : ['project/context.txt']), kind }];
const caseFile = path.join(root, 'evals', 'cases', 'alpha-skill.json');
writeJson(caseFile, rubric);
const stub = path.join(root, 'claude-stub.cjs');
fs.writeFileSync(stub, `
const fs = require('node:fs');
const cp = require('node:child_process');
const original = cp.execFileSync;
cp.execFileSync = (command, args, options) => {
if (command !== 'claude') return original(command, args, options);
fs.appendFileSync(process.env.CALL_LOG, JSON.stringify({args, input: options?.input}) + '\\n');
if (args.includes('--version')) return '2.1.test\\n';
if (args.includes('stream-json')) return '{"type":"system","subtype":"init","model":"observed-model"}\\n{"type":"result","subtype":"success","is_error":false,"result":"original evidence"}\\n';
if (process.env.GRADER_THROWS) throw new Error('grader unavailable');
return process.env.GRADER_RAW || '{"expectations":[{"id":1,"text":"paraphrase","passed":true,"evidence":"original evidence"}],"summary":{"passed":1,"failed":0,"total":1,"pass_rate":1}}';
};
`);
const log = path.join(root, 'calls.jsonl');
return {
root, rubric, caseFile,
run: (args, env = {}) => spawnSync(process.execPath, ['--require', stub, path.join(root, 'scripts/run-evals.js'), ...args], {
cwd: root, encoding: 'utf8', env: { ...process.env, CALL_LOG: log, ...env },
}),
calls: () => fs.existsSync(log) ? fs.readFileSync(log, 'utf8').trim().split('\n').map(JSON.parse) : [],
records: () => fs.readdirSync(path.join(root, 'evals/results')).filter(n => n.endsWith('.record.json')).map(n => path.join(root, 'evals/results', n)),
};
}
for (const kind of ['dialogue', 'execution']) {
test(`records and regrades the same ${kind} evidence without another executor`, t => {
const s = recordedSandbox(t, kind);
const first = s.run(['--behavioral', 'alpha-skill', '--record', '--model', 'requested-model']);
assert.equal(first.status, 0, first.stdout + first.stderr);
assert.equal(s.records().length, 1);
const file = s.records()[0];
const original = fs.readFileSync(file, 'utf8');
const record = JSON.parse(original);
assert.equal(record.evidence.run.executor_model, 'observed-model');
assert.equal(record.evidence.run.requested_model, 'requested-model');
assert.equal(record.evidence.run.claude_version, '2.1.test');
const digest = (text) => require('node:crypto').createHash('sha256').update(text).digest('hex');
assert.equal(record.evidence.references, undefined);
assert.deepEqual(record.evidence.staged, [
{ path: 'references/shared.md', sha256: digest('shared reference') },
{ path: 'skills/alpha-skill/SKILL.md', sha256: digest(record.evidence.skill_text) },
{ path: 'skills/alpha-skill/references/guide.md', sha256: digest('local reference') },
]);
const latest = fs.readFileSync(path.join(s.root, 'evals/results/alpha-skill.eval-1.grading.json'), 'utf8');
s.rubric.evals[0].expectations = ['Revised expectation'];
writeJson(s.caseFile, s.rubric);
// Replay must not read today's skill or fixture tree.
fs.rmSync(path.join(s.root, 'skills'), { recursive: true });
fs.rmSync(path.join(s.root, 'evals/fixtures'), { recursive: true });
const replay = s.run(['--regrade', file, '--rubric', s.caseFile, '--model', 'new-grader']);
assert.equal(replay.status, 0, replay.stdout + replay.stderr);
assert.match(replay.stdout, /historical/i);
assert.match(replay.stdout, /staged 3 file\(s\), listed in the record/);
assert.equal(fs.readFileSync(file, 'utf8'), original);
assert.equal(fs.readFileSync(path.join(s.root, 'evals/results/alpha-skill.eval-1.grading.json'), 'utf8'), latest);
const calls = s.calls().filter(c => !c.args.includes('--version'));
assert.equal(calls.length, 3);
assert.equal(calls.filter(c => c.args.includes('stream-json')).length, 1);
assert.match(calls[2].input, /Revised expectation/);
assert.match(calls[2].input, /original evidence/);
assert.equal(calls[2].args.at(-1), 'new-grader');
const attempts = fs.readdirSync(path.dirname(file)).filter(n => n.includes('.attempt-'));
assert.equal(attempts.length, 2);
const grades = attempts.map(n => JSON.parse(fs.readFileSync(path.join(path.dirname(file), n), 'utf8')));
assert.ok(grades.some(g => g.historical === true && g.grading.expectations[0].text === 'Revised expectation'));
});
}
function recordOnce(s, env) {
const result = s.run(['--behavioral', 'alpha-skill', '--record'], env);
return { result, file: s.records()[0] };
}
for (const passed of [true, false]) {
for (const evidence of ['', ' \t\r\n', '\u00a0\u2003']) {
test(`record and regrade retain blank evidence diagnostics for ${passed ? 'passing' : 'failing'} verdict ${JSON.stringify(evidence)}`, t => {
const s = recordedSandbox(t);
const raw = JSON.stringify({
expectations: [{ id: 1, text: 'check the result', passed, evidence }],
summary: { passed: Number(passed), failed: Number(!passed), total: 1, pass_rate: Number(passed) },
});
const { result, file } = recordOnce(s, { GRADER_RAW: raw });
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /grader returned blank evidence/);
assert.doesNotMatch(result.stdout + result.stderr, /invalid JSON/);
const original = fs.readFileSync(file, 'utf8');
const base = path.join(s.root, 'evals/results/alpha-skill.eval-1');
assert.equal(fs.existsSync(`${base}.grading.json`), false);
assert.equal(fs.readFileSync(`${base}.grading.raw.txt`, 'utf8'), raw);
const replay = s.run(['--regrade', file, '--rubric', s.caseFile], { GRADER_RAW: raw });
assert.equal(replay.status, 1, replay.stdout + replay.stderr);
assert.match(replay.stderr, /grader returned blank evidence/);
assert.doesNotMatch(replay.stderr, /invalid JSON/);
const attempts = fs.readdirSync(path.dirname(file)).filter(n => n.includes('.attempt-'));
assert.equal(attempts.length, 2);
for (const name of attempts) {
const attempt = JSON.parse(fs.readFileSync(path.join(path.dirname(file), name), 'utf8'));
assert.equal(attempt.status, 'invalid');
assert.equal(attempt.gradingError, 'grader returned blank evidence');
assert.equal(attempt.raw, raw);
assert.equal(attempt.grading, null);
}
const retry = s.run(['--regrade', file, '--rubric', s.caseFile]);
assert.equal(retry.status, 0, retry.stdout + retry.stderr);
assert.equal(fs.readFileSync(file, 'utf8'), original);
assert.equal(fs.existsSync(`${base}.grading.json`), false);
assert.equal(fs.readFileSync(`${base}.grading.raw.txt`, 'utf8'), raw);
const calls = s.calls().filter(c => !c.args.includes('--version'));
assert.equal(calls.filter(c => c.args.includes('stream-json')).length, 1);
for (const call of calls.filter(c => !c.args.includes('stream-json'))) {
assert.match(call.input, /provide non-blank evidence/);
}
});
}
}
test('rejects altered evidence before any Claude invocation', t => {
const s = recordedSandbox(t);
const { file } = recordOnce(s);
const original = JSON.parse(fs.readFileSync(file, 'utf8'));
const calls = s.calls().length;
for (const field of ['trace', 'skill_text', 'eval', 'staged', 'run']) {
const changed = structuredClone(original);
changed.evidence[field] = 'altered';
writeJson(file, changed);
const result = s.run(['--regrade', file, '--rubric', s.caseFile]);
assert.equal(result.status, 1);
assert.match(result.stderr, /integrity/);
assert.equal(s.calls().length, calls);
}
});
test('rejects a staged list that does not match the record, even with a valid digest', t => {
const s = recordedSandbox(t);
const { file } = recordOnce(s);
const original = JSON.parse(fs.readFileSync(file, 'utf8'));
const calls = s.calls().length;
const digest = (value) => require('node:crypto').createHash('sha256').update(JSON.stringify(value)).digest('hex');
const changes = [
e => { e.staged = e.staged.filter(f => !f.path.endsWith('/SKILL.md')); },
e => { e.staged[0].path = 'evals/fixtures/project/context.txt'; },
e => { e.staged[0].path = 'references/../secret.txt'; },
e => { e.staged.push({ ...e.staged[0] }); },
e => { e.skill_text += 'changed'; },
e => { delete e.staged; e.references = { status: 'not-staged', files: [] }; },
];
for (const change of changes) {
const changed = structuredClone(original);
change(changed.evidence);
changed.sha256 = digest(changed.evidence);
writeJson(file, changed);
const result = s.run(['--regrade', file, '--rubric', s.caseFile]);
assert.equal(result.status, 1);
assert.match(result.stderr, /Invalid behavioral record evidence/);
assert.equal(s.calls().length, calls);
}
});
test('rejects a changed task, mismatched rubric, or invalid expectations before model calls', t => {
const s = recordedSandbox(t);
const { file } = recordOnce(s);
const calls = s.calls().length;
const changes = [
r => { r.evals[0].prompt = 'different task'; },
r => { r.evals[0].kind = 'execution'; },
r => { r.evals[0].files = ['different/input']; },
r => { r.skill_name = 'another-skill'; },
r => { r.evals[0].id = 9; },
r => { r.evals.push(structuredClone(r.evals[0])); },
r => { r.evals[0].expectations = []; },
r => { r.evals[0].expectations = [null]; },
];
for (const change of changes) {
const rubric = structuredClone(s.rubric);
change(rubric);
writeJson(s.caseFile, rubric);
const result = s.run(['--regrade', file, '--rubric', s.caseFile]);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.equal(s.calls().length, calls);
}
});
for (const [env, status] of [[{ GRADER_RAW: 'invalid response' }, 'invalid'], [{ GRADER_THROWS: '1' }, 'error']]) {
test(`keeps the generation and ${status} attempt when the grader fails`, t => {
const s = recordedSandbox(t);
const { result, file } = recordOnce(s, env);
assert.equal(result.status, 1);
assert.ok(file);
const original = fs.readFileSync(file, 'utf8');
const attemptFile = fs.readdirSync(path.dirname(file)).find(n => n.includes('.attempt-'));
const attempt = JSON.parse(fs.readFileSync(path.join(path.dirname(file), attemptFile), 'utf8'));
assert.equal(attempt.status, status);
if (status === 'invalid') assert.equal(attempt.raw, 'invalid response');
else assert.match(attempt.error, /grader unavailable/);
const replay = s.run(['--regrade', file, '--rubric', s.caseFile]);
assert.equal(replay.status, 0, replay.stdout + replay.stderr);
assert.equal(fs.readFileSync(file, 'utf8'), original);
assert.equal(s.calls().filter(c => c.args.includes('stream-json')).length, 1);
});
}
test('record dry-run and replay dry-run make no Claude calls or output changes', t => {
const s = recordedSandbox(t);
assert.equal(s.run(['--behavioral', 'alpha-skill', '--record', '--dry-run']).status, 0);
assert.equal(s.calls().length, 0);
assert.equal(fs.existsSync(path.join(s.root, 'evals/results')), false);
const { file } = recordOnce(s);
const calls = s.calls().length;
const files = fs.readdirSync(path.dirname(file));
assert.equal(s.run(['--regrade', file, '--rubric', s.caseFile, '--dry-run']).status, 0);
assert.equal(s.calls().length, calls);
assert.deepEqual(fs.readdirSync(path.dirname(file)), files);
});
test('ordinary runs retain their output shape and do not record or query CLI version', t => {
const s = recordedSandbox(t);
assert.equal(s.run(['--behavioral', 'alpha-skill']).status, 0);
const files = fs.readdirSync(path.join(s.root, 'evals/results'));
assert.deepEqual(files, ['alpha-skill.eval-1.grading.json']);
assert.equal(s.calls().length, 2);
});
test('separate generations and repeated regrades preserve every record and attempt', t => {
const s = recordedSandbox(t);
const first = recordOnce(s).file;
const original = fs.readFileSync(first, 'utf8');
recordOnce(s);
assert.equal(s.records().length, 2);
for (let i = 0; i < 2; i++) assert.equal(s.run(['--regrade', first, '--rubric', s.caseFile]).status, 0);
assert.equal(fs.readFileSync(first, 'utf8'), original);
assert.equal(fs.readdirSync(path.dirname(first)).filter(n => n.includes('.attempt-')).length, 4);
});
test('rejects incomplete and incompatible record/replay CLI options', t => {
const s = recordedSandbox(t);
for (const args of [
['--record'], ['--model'], ['--model', '--record'], ['--regrade'],
['--regrade', 'missing'], ['--rubric', 'missing'],
['--regrade', 'missing', '--rubric', 'missing', '--behavioral', 'alpha-skill'],
['--regrade', 'missing', '--rubric', 'missing', '--record'],
['--regrade', 'missing', '--rubric', 'missing', '--min-rank1', '95'],
]) {
assert.equal(s.run(args).status, 1, args.join(' '));
assert.equal(s.calls().length, 0);
}
});
test('a failing historical grade stays a failure and retains its attempt', t => {
const s = recordedSandbox(t);
const { file } = recordOnce(s);
const raw = JSON.stringify({ expectations: [{ id: 1, text: 'x', passed: false, evidence: 'not observed' }],
summary: { passed: 0, failed: 1, total: 1, pass_rate: 0 } });
const result = s.run(['--regrade', file, '--rubric', s.caseFile], { GRADER_RAW: raw });
assert.equal(result.status, 1);
assert.match(result.stdout, /0\/1 expectations passed/);
const attempts = fs.readdirSync(path.dirname(file)).filter(n => n.includes('.attempt-'));
assert.equal(attempts.length, 2);
});
test('rejects unknown record versions and malformed JSON without calling Claude', t => {
const s = recordedSandbox(t);
const { file } = recordOnce(s);
const calls = s.calls().length;
const record = JSON.parse(fs.readFileSync(file, 'utf8'));
record.version = 99;
writeJson(file, record);
assert.equal(s.run(['--regrade', file, '--rubric', s.caseFile]).status, 1);
fs.writeFileSync(file, '{broken json');
assert.equal(s.run(['--regrade', file, '--rubric', s.caseFile]).status, 1);
assert.equal(s.calls().length, calls);
});
test('record mode rejects duplicate behavioral IDs before any Claude invocation or output changes', t => {
const s = recordedSandbox(t);
s.rubric.evals.push({ ...s.rubric.evals[0], prompt: 'A different evaluation' });
writeJson(s.caseFile, s.rubric);
for (const flags of [[], ['--dry-run']]) {
const result = s.run(['--behavioral', 'alpha-skill', '--record', ...flags]);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stderr, /duplicate behavioral eval id=1/);
assert.equal(s.calls().length, 0);
assert.equal(fs.existsSync(path.join(s.root, 'evals/results')), false);
}
});
test('fixture baseline commits ignore inherited user signing requirements', () => {
const root = makeSandbox();
const config = path.join(root, 'global.gitconfig');
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'fixture-signing-test-'));
try {
fs.writeFileSync(config, '[commit]\n\tgpgsign = true\n[gpg]\n\tprogram = definitely-missing-eval-signer\n');
const result = spawnSync(process.execPath, ['-e', `
const fs = require('node:fs');
const { materializeWorkspace } = require(${JSON.stringify(path.join(root, 'scripts', 'run-evals.js'))});
let workspace;
try { workspace = materializeWorkspace({ files: ['project/context.txt'] }); }
finally { if (workspace) fs.rmSync(workspace, { recursive: true, force: true }); }
`], { cwd: root, encoding: 'utf8', env: { ...process.env, GIT_CONFIG_GLOBAL: config, TMPDIR: temp, TMP: temp, TEMP: temp } });
assert.equal(result.status, 0, result.stdout + result.stderr);
} finally {
fs.rmSync(root, { recursive: true, force: true });
fs.rmSync(temp, { recursive: true, force: true });
}
});
test('rejects duplicate behavioral IDs before they can overwrite a grading slot', () => {
const root = makeSandbox();
try {
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals.push({ ...behavioralEval(), prompt: 'A different evaluation' });
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
const result = run(root);
assert.equal(result.status, 1, result.stdout + result.stderr);
assert.match(result.stdout, /duplicate behavioral eval id=1/);
const dryRun = run(root, ['--behavioral', 'alpha-skill', '--dry-run']);
assert.equal(dryRun.status, 1, dryRun.stdout + dryRun.stderr);
assert.match(dryRun.stderr, /duplicate behavioral eval id=1/);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
test('accepts distinct behavioral IDs including zero', () => {
const root = makeSandbox();
try {
writeSkill(root, 'alpha-skill', 'Handles alpha widgets. Use when changing alpha widgets.');
const evalCase = completeCase('alpha-skill', 'change alpha widget');
evalCase.evals.push({ ...behavioralEval(), id: 0 });
writeJson(path.join(root, 'evals', 'cases', 'alpha-skill.json'), evalCase);
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
test('removes the throwaway workspace when fixture setup fails', () => {
const root = makeSandbox();
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'workspace-cleanup-test-'));
try {
const result = spawnSync(process.execPath, ['-e', `
const { materializeWorkspace } = require(${JSON.stringify(path.join(root, 'scripts', 'run-evals.js'))});
try { materializeWorkspace({ files: ['project/context.txt', 'missing.txt'] }); }
catch (error) { console.error(error.message); }
`], { cwd: root, encoding: 'utf8', env: { ...process.env, TMPDIR: temp, TMP: temp, TEMP: temp } });
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.match(result.stderr, /fixture listed in files\[\] not found/);
assert.deepEqual(fs.readdirSync(temp), [], 'partially copied fixture data must be removed');
} finally {
fs.rmSync(root, { recursive: true, force: true });
fs.rmSync(temp, { recursive: true, force: true });
}
});
test('loads quoted YAML skill identities using their decoded values', () => {
const root = makeSandbox();
try {
writeSkill(root, 'alpha', 'code unit tests');
const skill = path.join(root, 'skills', 'alpha', 'SKILL.md');
fs.writeFileSync(skill, fs.readFileSync(skill, 'utf8').replace('name: alpha', "name: 'alpha'")
.replace('description: code unit tests', 'description: "code unit tests"'));
writeJson(path.join(root, 'evals', 'cases', 'alpha.json'), completeCase('alpha', 'code unit tests'));
const result = run(root);
assert.equal(result.status, 0, result.stdout + result.stderr);
assert.match(result.stdout, /PASSED/);
} finally { fs.rmSync(root, { recursive: true, force: true }); }
});
|