@plune-ai/cli 0.39.16 → 0.40.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/README.md +47 -5
- package/dist/cli.cjs +3754 -1252
- package/dist/{execute-DLNnhkEM.d.cts → execute-CD55D0di.d.cts} +6 -0
- package/dist/{execute-DLNnhkEM.d.ts → execute-CD55D0di.d.ts} +6 -0
- package/dist/index.cjs +1737 -269
- package/dist/index.d.cts +168 -6
- package/dist/index.d.ts +168 -6
- package/dist/index.js +1736 -268
- package/dist/mcp-http.cjs +4 -4
- package/dist/mcp-http.d.cts +1 -1
- package/dist/mcp-http.d.ts +1 -1
- package/dist/mcp-http.js +4 -4
- package/dist/mcp-tools.cjs +4 -4
- package/dist/mcp-tools.d.cts +1 -1
- package/dist/mcp-tools.d.ts +1 -1
- package/dist/mcp-tools.js +4 -4
- package/dist/reporter-core.cjs +28 -5
- package/dist/reporter-core.d.cts +1 -1
- package/dist/reporter-core.d.ts +1 -1
- package/dist/reporter-core.js +28 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,8 +45,8 @@ function machineless(raw, repoRoot, home) {
|
|
|
45
45
|
let text = (0, import_node_util.stripVTControlCharacters)(raw).replaceAll("\x1B", "");
|
|
46
46
|
const root = repoRoot === void 0 ? void 0 : pathIn(repoRoot);
|
|
47
47
|
if (root !== void 0) text = text.replace(new RegExp(`${PATH_START}${root.source}[\\\\/]+`, root.flags), "");
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
48
|
+
const own3 = pathIn(home);
|
|
49
|
+
if (own3 !== void 0) text = text.replace(new RegExp(`${PATH_START}${own3.source}(?![\\w.-])`, own3.flags), "~");
|
|
50
50
|
if (repoRoot === void 0) text = text.replace(ANY_HOME, "~");
|
|
51
51
|
return text;
|
|
52
52
|
}
|
|
@@ -92,12 +92,12 @@ function openJournal(path11, redact) {
|
|
|
92
92
|
if (path11 === void 0) return NONE;
|
|
93
93
|
const fd = (0, import_node_fs2.openSync)(path11, "w", 384);
|
|
94
94
|
if (process.platform !== "win32") (0, import_node_fs2.fchmodSync)(fd, 384);
|
|
95
|
-
const
|
|
95
|
+
const start2 = import_node_perf_hooks.performance.now();
|
|
96
96
|
let closed = false;
|
|
97
97
|
return {
|
|
98
98
|
write(dir, fields) {
|
|
99
99
|
if (closed) return;
|
|
100
|
-
const dtMs = Math.round((import_node_perf_hooks.performance.now() -
|
|
100
|
+
const dtMs = Math.round((import_node_perf_hooks.performance.now() - start2) * 1e3) / 1e3;
|
|
101
101
|
const line = {
|
|
102
102
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
103
103
|
dtMs,
|
|
@@ -254,11 +254,11 @@ function maskUrl(raw) {
|
|
|
254
254
|
} catch {
|
|
255
255
|
return raw;
|
|
256
256
|
}
|
|
257
|
-
if (url.username !== "") url.username =
|
|
258
|
-
if (url.password !== "") url.password =
|
|
257
|
+
if (url.username !== "") url.username = MASK2;
|
|
258
|
+
if (url.password !== "") url.password = MASK2;
|
|
259
259
|
for (const name of [...url.searchParams.keys()])
|
|
260
|
-
if (SECRET_QUERY.has(name.toLowerCase())) url.searchParams.set(name,
|
|
261
|
-
return url.href.replaceAll("%2A%2A%2A",
|
|
260
|
+
if (SECRET_QUERY.has(name.toLowerCase())) url.searchParams.set(name, MASK2);
|
|
261
|
+
return url.href.replaceAll("%2A%2A%2A", MASK2);
|
|
262
262
|
}
|
|
263
263
|
function secretsOf(target) {
|
|
264
264
|
const secrets = { values: [], named: [], urls: [] };
|
|
@@ -309,7 +309,7 @@ function createRedactor(secrets, opts = {}) {
|
|
|
309
309
|
const ordered = longestFirst(forms);
|
|
310
310
|
const urls = longestFirst(opts.url?.raw ?? []).filter((raw) => raw !== "");
|
|
311
311
|
const text = (input) => ordered.reduce(
|
|
312
|
-
(out, secret) => out.replaceAll(secret,
|
|
312
|
+
(out, secret) => out.replaceAll(secret, MASK2),
|
|
313
313
|
urls.reduce((out, raw) => out.replaceAll(raw, opts.url.masked), input)
|
|
314
314
|
);
|
|
315
315
|
const value = (input, depth = 0) => {
|
|
@@ -334,7 +334,7 @@ function describeTarget(target, redact) {
|
|
|
334
334
|
const masked = (entries, secret) => Object.fromEntries(
|
|
335
335
|
Object.entries(entries).map(([name, value]) => [
|
|
336
336
|
name,
|
|
337
|
-
secret(name) ?
|
|
337
|
+
secret(name) ? MASK2 : redact.text(value)
|
|
338
338
|
])
|
|
339
339
|
);
|
|
340
340
|
if (target.kind === "stdio") {
|
|
@@ -352,12 +352,12 @@ function describeTarget(target, redact) {
|
|
|
352
352
|
headers: masked(target.headers, isSecretHeader)
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
|
-
var
|
|
355
|
+
var MASK2, MIN_SECRET_LENGTH, MAX_DEPTH, SECRET_HEADERS, SECRET_HEADER_PART, SECRET_ENV_PART, SECRET_QUERY, isSecretHeader, isSecretEnv, decoded, rawQuery;
|
|
356
356
|
var init_redact = __esm({
|
|
357
357
|
"src/mcp-testing/connect/redact.ts"() {
|
|
358
358
|
"use strict";
|
|
359
359
|
init_cjs_shims();
|
|
360
|
-
|
|
360
|
+
MASK2 = "***";
|
|
361
361
|
MIN_SECRET_LENGTH = 8;
|
|
362
362
|
MAX_DEPTH = 64;
|
|
363
363
|
SECRET_HEADERS = /* @__PURE__ */ new Set(["authorization", "proxy-authorization", "cookie", "set-cookie"]);
|
|
@@ -443,10 +443,10 @@ function readLines(stream, onLine, stats) {
|
|
|
443
443
|
partial = rest.slice(0, STDERR_LINE_LIMIT);
|
|
444
444
|
};
|
|
445
445
|
return new Promise((resolve9) => {
|
|
446
|
-
let
|
|
446
|
+
let done2 = false;
|
|
447
447
|
const finish = () => {
|
|
448
|
-
if (
|
|
449
|
-
|
|
448
|
+
if (done2) return;
|
|
449
|
+
done2 = true;
|
|
450
450
|
feed(decoder.end());
|
|
451
451
|
if (partial !== "") onLine(partial.endsWith("\r") ? partial.slice(0, -1) : partial);
|
|
452
452
|
resolve9();
|
|
@@ -508,9 +508,9 @@ function intercept(transport, name, before) {
|
|
|
508
508
|
});
|
|
509
509
|
}
|
|
510
510
|
function watchStdout(transport, journal, seen) {
|
|
511
|
-
const
|
|
511
|
+
const start2 = transport.start.bind(transport);
|
|
512
512
|
transport.start = async () => {
|
|
513
|
-
await
|
|
513
|
+
await start2();
|
|
514
514
|
const stdout = transport._process?.stdout;
|
|
515
515
|
if (stdout === null || stdout === void 0) return;
|
|
516
516
|
(0, import_node_readline.createInterface)({ input: stdout, crlfDelay: Infinity }).on("line", (line) => {
|
|
@@ -720,7 +720,7 @@ async function openSession(config, options = {}) {
|
|
|
720
720
|
},
|
|
721
721
|
fetchForOrigin(origin) {
|
|
722
722
|
const allowed = new URL(origin).origin;
|
|
723
|
-
const
|
|
723
|
+
const own3 = target.kind !== "stdio" && new URL(target.url).origin === allowed;
|
|
724
724
|
return async (input, init) => {
|
|
725
725
|
const url = new URL(input);
|
|
726
726
|
if (url.origin !== allowed)
|
|
@@ -728,7 +728,7 @@ async function openSession(config, options = {}) {
|
|
|
728
728
|
`fetchForOrigin(${allowed}) refuses a request to another origin, ${url.origin}.`
|
|
729
729
|
);
|
|
730
730
|
const headers = new Headers(init?.headers);
|
|
731
|
-
if (
|
|
731
|
+
if (own3) {
|
|
732
732
|
for (const [name, value] of Object.entries(target.headers))
|
|
733
733
|
if (!headers.has(name)) headers.set(name, value);
|
|
734
734
|
}
|
|
@@ -748,23 +748,23 @@ async function openSession(config, options = {}) {
|
|
|
748
748
|
if (stdin === null || stdin === void 0 || stdin.writableEnded)
|
|
749
749
|
throw spawnError !== void 0 ? await toConnectError(spawnError) : new ConnectError("exited-early", `${LEAD["exited-early"][0]}.`, [...tail]);
|
|
750
750
|
return new Promise((resolve9, reject) => {
|
|
751
|
-
const
|
|
751
|
+
const done2 = () => {
|
|
752
752
|
clearTimeout(timer2);
|
|
753
753
|
listeners.delete(listener);
|
|
754
754
|
stopped.delete(stop);
|
|
755
755
|
};
|
|
756
756
|
const timer2 = setTimeout(() => {
|
|
757
|
-
|
|
757
|
+
done2();
|
|
758
758
|
reject(noAnswer());
|
|
759
759
|
}, ms);
|
|
760
760
|
const listener = (line) => {
|
|
761
761
|
const frame2 = parsed(line);
|
|
762
762
|
if (!answers(frame2, id)) return;
|
|
763
|
-
|
|
763
|
+
done2();
|
|
764
764
|
resolve9({ frame: frame2, text: clean(line).slice(0, RAW_TEXT) });
|
|
765
765
|
};
|
|
766
766
|
const stop = () => {
|
|
767
|
-
|
|
767
|
+
done2();
|
|
768
768
|
void toConnectError(spawnError ?? new Error("closed")).then(reject);
|
|
769
769
|
};
|
|
770
770
|
listeners.add(listener);
|
|
@@ -802,8 +802,8 @@ async function openSession(config, options = {}) {
|
|
|
802
802
|
const reader = res.body.getReader();
|
|
803
803
|
const decoder = new TextDecoder();
|
|
804
804
|
for (; ; ) {
|
|
805
|
-
const { done, value } = await reader.read();
|
|
806
|
-
if (
|
|
805
|
+
const { done: done2, value } = await reader.read();
|
|
806
|
+
if (done2) break;
|
|
807
807
|
text += decoder.decode(value, { stream: true });
|
|
808
808
|
if (sse && (frame = fromEventStream(text, id)) !== void 0) break;
|
|
809
809
|
if (text.length > STDIO_MESSAGE_LIMIT) break;
|
|
@@ -1065,7 +1065,7 @@ init_cjs_shims();
|
|
|
1065
1065
|
|
|
1066
1066
|
// src/cli/commands/run.ts
|
|
1067
1067
|
init_cjs_shims();
|
|
1068
|
-
var
|
|
1068
|
+
var fs6 = __toESM(require("fs"), 1);
|
|
1069
1069
|
var path5 = __toESM(require("path"), 1);
|
|
1070
1070
|
|
|
1071
1071
|
// src/config/loader.ts
|
|
@@ -1106,6 +1106,628 @@ var ConfigValidationError = class extends Error {
|
|
|
1106
1106
|
init_cjs_shims();
|
|
1107
1107
|
var import_zod = require("zod");
|
|
1108
1108
|
|
|
1109
|
+
// src/json-verify/compare.ts
|
|
1110
|
+
init_cjs_shims();
|
|
1111
|
+
|
|
1112
|
+
// src/json-verify/functions.ts
|
|
1113
|
+
init_cjs_shims();
|
|
1114
|
+
|
|
1115
|
+
// src/json-verify/regex.ts
|
|
1116
|
+
init_cjs_shims();
|
|
1117
|
+
var MAX_REGEX_NODES = 2e3;
|
|
1118
|
+
var SHORTHAND = { d: /\d/, w: /\w/, s: /\s/ };
|
|
1119
|
+
var CONTROL = { n: 10, r: 13, t: 9, f: 12, v: 11, "0": 0 };
|
|
1120
|
+
var SIMPLE_REPEAT = { "*": [0, Infinity], "+": [1, Infinity], "?": [0, 1] };
|
|
1121
|
+
var LINE_ENDS = /* @__PURE__ */ new Set([10, 13, 8232, 8233]);
|
|
1122
|
+
var QUANTIFIER = /[*+?]|\{(\d+)(?:(,)(\d*))?\}/y;
|
|
1123
|
+
function caseClass(code) {
|
|
1124
|
+
const upper = String.fromCharCode(code).toUpperCase();
|
|
1125
|
+
if (upper.length !== 1) return code;
|
|
1126
|
+
const folded = upper.charCodeAt(0);
|
|
1127
|
+
return code >= 128 && folded < 128 ? code : folded;
|
|
1128
|
+
}
|
|
1129
|
+
var caseClasses;
|
|
1130
|
+
function sameCase(code) {
|
|
1131
|
+
if (caseClasses === void 0) {
|
|
1132
|
+
const all = /* @__PURE__ */ new Map();
|
|
1133
|
+
for (let c = 0; c < 65536; c++) {
|
|
1134
|
+
const key = caseClass(c);
|
|
1135
|
+
const members = all.get(key);
|
|
1136
|
+
if (members === void 0) all.set(key, [c]);
|
|
1137
|
+
else members.push(c);
|
|
1138
|
+
}
|
|
1139
|
+
caseClasses = new Map([...all].filter(([, members]) => members.length > 1));
|
|
1140
|
+
}
|
|
1141
|
+
return caseClasses.get(caseClass(code)) ?? [code];
|
|
1142
|
+
}
|
|
1143
|
+
function parse(pattern, flags) {
|
|
1144
|
+
let i = 0;
|
|
1145
|
+
const fail2 = (what) => new Error(`${what} (character ${i} of the pattern)`);
|
|
1146
|
+
const ignoreCase = flags.includes("i");
|
|
1147
|
+
const fold = (test) => ignoreCase ? (code) => sameCase(code).some(test) : test;
|
|
1148
|
+
const literal = (code) => fold((c) => c === code);
|
|
1149
|
+
const shorthand = (e) => {
|
|
1150
|
+
const re = SHORTHAND[e.toLowerCase()];
|
|
1151
|
+
if (re === void 0) return void 0;
|
|
1152
|
+
const negated = e !== e.toLowerCase();
|
|
1153
|
+
return (code) => re.test(String.fromCharCode(code)) !== negated;
|
|
1154
|
+
};
|
|
1155
|
+
const escaped = (e) => {
|
|
1156
|
+
if (e === void 0) throw fail2("a backslash ends the pattern");
|
|
1157
|
+
if (e === "0" && /\d/.test(pattern[i] ?? "")) throw fail2("\\0 before a digit is not supported");
|
|
1158
|
+
const control = CONTROL[e];
|
|
1159
|
+
if (control !== void 0) return control;
|
|
1160
|
+
if (/[A-Za-z0-9]/.test(e)) throw fail2(`\\${e} is not supported`);
|
|
1161
|
+
return e.charCodeAt(0);
|
|
1162
|
+
};
|
|
1163
|
+
const classAtom = () => {
|
|
1164
|
+
const ch = pattern[i++];
|
|
1165
|
+
if (ch === void 0) throw fail2("a character class is not closed");
|
|
1166
|
+
if (ch !== "\\") return ch.charCodeAt(0);
|
|
1167
|
+
const e = pattern[i++];
|
|
1168
|
+
if (e === "b") return 8;
|
|
1169
|
+
return (e === void 0 ? void 0 : shorthand(e)) ?? escaped(e);
|
|
1170
|
+
};
|
|
1171
|
+
const parseClass = () => {
|
|
1172
|
+
const negated = pattern[i] === "^";
|
|
1173
|
+
if (negated) i++;
|
|
1174
|
+
const tests = [];
|
|
1175
|
+
while (pattern[i] !== "]") {
|
|
1176
|
+
const low = classAtom();
|
|
1177
|
+
if (typeof low !== "number") tests.push(low);
|
|
1178
|
+
else if (pattern[i] === "-" && pattern[i + 1] !== "]") {
|
|
1179
|
+
i++;
|
|
1180
|
+
const high = classAtom();
|
|
1181
|
+
if (typeof high !== "number" || high < low) throw fail2("a range in a character class is out of order");
|
|
1182
|
+
tests.push(fold((c) => c >= low && c <= high));
|
|
1183
|
+
} else tests.push(literal(low));
|
|
1184
|
+
}
|
|
1185
|
+
i++;
|
|
1186
|
+
return (code) => tests.some((test) => test(code)) !== negated;
|
|
1187
|
+
};
|
|
1188
|
+
const parseAtom = () => {
|
|
1189
|
+
const ch = pattern[i++];
|
|
1190
|
+
if (ch === "(") {
|
|
1191
|
+
if (pattern[i] === "?") {
|
|
1192
|
+
if (pattern[i + 1] !== ":") throw fail2("lookahead, lookbehind and named groups are not supported");
|
|
1193
|
+
i += 2;
|
|
1194
|
+
}
|
|
1195
|
+
const options2 = parseOptions();
|
|
1196
|
+
if (pattern[i] !== ")") throw fail2("a group is not closed");
|
|
1197
|
+
i++;
|
|
1198
|
+
return { t: "group", options: options2 };
|
|
1199
|
+
}
|
|
1200
|
+
if (ch === "[") return { t: "char", test: parseClass() };
|
|
1201
|
+
if (ch === ".") return { t: "char", test: flags.includes("s") ? () => true : (c) => !LINE_ENDS.has(c) };
|
|
1202
|
+
if (ch === "^" || ch === "$") return { t: "anchor", kind: ch };
|
|
1203
|
+
QUANTIFIER.lastIndex = i - 1;
|
|
1204
|
+
if (QUANTIFIER.test(pattern)) throw fail2("nothing to repeat");
|
|
1205
|
+
if (ch !== "\\") return { t: "char", test: literal(ch.charCodeAt(0)) };
|
|
1206
|
+
const e = pattern[i++];
|
|
1207
|
+
if (e === "b" || e === "B") return { t: "anchor", kind: e };
|
|
1208
|
+
const set = e === void 0 ? void 0 : shorthand(e);
|
|
1209
|
+
return { t: "char", test: set ?? literal(escaped(e)) };
|
|
1210
|
+
};
|
|
1211
|
+
const parseRepeat = (atom) => {
|
|
1212
|
+
QUANTIFIER.lastIndex = i;
|
|
1213
|
+
const m = QUANTIFIER.exec(pattern);
|
|
1214
|
+
if (m === null) return atom;
|
|
1215
|
+
i += m[0].length;
|
|
1216
|
+
if (atom.t === "anchor") throw fail2("an anchor cannot be repeated");
|
|
1217
|
+
const least = Number(m[1]);
|
|
1218
|
+
const counted = [least, m[2] === void 0 ? least : m[3] === "" ? Infinity : Number(m[3])];
|
|
1219
|
+
const [min, max] = SIMPLE_REPEAT[m[0]] ?? counted;
|
|
1220
|
+
if (max < min) throw fail2("a repeat has its numbers out of order");
|
|
1221
|
+
if (pattern[i] === "?") i++;
|
|
1222
|
+
return { t: "repeat", node: atom, min, max };
|
|
1223
|
+
};
|
|
1224
|
+
function parseOptions() {
|
|
1225
|
+
const options2 = [[]];
|
|
1226
|
+
while (i < pattern.length && pattern[i] !== ")") {
|
|
1227
|
+
if (pattern[i] === "|") {
|
|
1228
|
+
i++;
|
|
1229
|
+
options2.push([]);
|
|
1230
|
+
} else options2[options2.length - 1].push(parseRepeat(parseAtom()));
|
|
1231
|
+
}
|
|
1232
|
+
return options2;
|
|
1233
|
+
}
|
|
1234
|
+
const options = parseOptions();
|
|
1235
|
+
if (i < pattern.length) throw fail2('a ")" has no group to close');
|
|
1236
|
+
return options;
|
|
1237
|
+
}
|
|
1238
|
+
var CHAR = 0;
|
|
1239
|
+
var SPLIT = 1;
|
|
1240
|
+
var ANCHOR = 2;
|
|
1241
|
+
var MATCH = 3;
|
|
1242
|
+
var isWord = (text, at) => at >= 0 && at < text.length && /\w/.test(text[at]);
|
|
1243
|
+
function compileRegex(pattern, flags = "") {
|
|
1244
|
+
const options = parse(pattern, flags);
|
|
1245
|
+
const multiline = flags.includes("m");
|
|
1246
|
+
const states = [{ kind: MATCH, next: 0, other: 0 }];
|
|
1247
|
+
const tooLarge = () => new Error(`the pattern is too large once its repeats are written out (over ${MAX_REGEX_NODES} parts)`);
|
|
1248
|
+
const add = (state) => {
|
|
1249
|
+
if (states.length > MAX_REGEX_NODES) throw tooLarge();
|
|
1250
|
+
return states.push(state) - 1;
|
|
1251
|
+
};
|
|
1252
|
+
let built = 0;
|
|
1253
|
+
const build = (node, next) => {
|
|
1254
|
+
if (++built > MAX_REGEX_NODES) throw tooLarge();
|
|
1255
|
+
if (node.t === "char") return add({ kind: CHAR, next, other: 0, test: node.test });
|
|
1256
|
+
if (node.t === "anchor") return add({ kind: ANCHOR, next, other: 0, anchor: node.kind });
|
|
1257
|
+
if (node.t === "group") return buildOptions(node.options, next);
|
|
1258
|
+
let enter = next;
|
|
1259
|
+
if (node.max === Infinity) {
|
|
1260
|
+
enter = add({ kind: SPLIT, next: 0, other: next });
|
|
1261
|
+
states[enter].next = build(node.node, enter);
|
|
1262
|
+
} else
|
|
1263
|
+
for (let k = node.min; k < node.max; k++)
|
|
1264
|
+
enter = add({ kind: SPLIT, next: build(node.node, enter), other: enter });
|
|
1265
|
+
for (let k = 0; k < node.min; k++) enter = build(node.node, enter);
|
|
1266
|
+
return enter;
|
|
1267
|
+
};
|
|
1268
|
+
const buildOptions = (list2, next) => list2.map((sequence) => sequence.reduceRight((after, node) => build(node, after), next)).reduceRight((rest, entry) => add({ kind: SPLIT, next: entry, other: rest }));
|
|
1269
|
+
const start2 = buildOptions(options, 0);
|
|
1270
|
+
const holds = (anchor, text, at) => {
|
|
1271
|
+
if (anchor === "b" || anchor === "B") return isWord(text, at - 1) !== isWord(text, at) === (anchor === "b");
|
|
1272
|
+
const edge = anchor === "^" ? at === 0 : at === text.length;
|
|
1273
|
+
return edge || multiline && LINE_ENDS.has(text.charCodeAt(anchor === "^" ? at - 1 : at));
|
|
1274
|
+
};
|
|
1275
|
+
return (text) => {
|
|
1276
|
+
const seen = new Int32Array(states.length).fill(-1);
|
|
1277
|
+
let matched = false;
|
|
1278
|
+
const enter = (list2, from, at2) => {
|
|
1279
|
+
const stack = [from];
|
|
1280
|
+
while (stack.length > 0) {
|
|
1281
|
+
const s = stack.pop();
|
|
1282
|
+
if (seen[s] === at2) continue;
|
|
1283
|
+
seen[s] = at2;
|
|
1284
|
+
const state = states[s];
|
|
1285
|
+
if (state.kind === SPLIT) stack.push(state.next, state.other);
|
|
1286
|
+
else if (state.kind === ANCHOR) {
|
|
1287
|
+
if (holds(state.anchor, text, at2)) stack.push(state.next);
|
|
1288
|
+
} else if (state.kind === MATCH) matched = true;
|
|
1289
|
+
else list2.push(s);
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
let current = [];
|
|
1293
|
+
let at = 0;
|
|
1294
|
+
enter(current, start2, 0);
|
|
1295
|
+
while (!matched && at < text.length) {
|
|
1296
|
+
const code = text.charCodeAt(at++);
|
|
1297
|
+
const following = [];
|
|
1298
|
+
for (const s of current) if (states[s].test(code)) enter(following, states[s].next, at);
|
|
1299
|
+
enter(following, start2, at);
|
|
1300
|
+
current = following;
|
|
1301
|
+
}
|
|
1302
|
+
return matched;
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
// src/json-verify/functions.ts
|
|
1307
|
+
var MAX_REGEX_INPUT = 1e4;
|
|
1308
|
+
var MAX_REGEX_PATTERN = 500;
|
|
1309
|
+
var none = (args) => args.length === 0 ? void 0 : "takes no arguments";
|
|
1310
|
+
var oneNumber = (args) => args.length === 1 && typeof args[0] === "number" ? void 0 : "takes one number";
|
|
1311
|
+
var oneLength = (args) => args.length === 1 && Number.isInteger(args[0]) && args[0] >= 0 ? void 0 : "takes one whole number, 0 or more";
|
|
1312
|
+
var lengthOf = (v) => typeof v === "string" || Array.isArray(v) ? v.length : void 0;
|
|
1313
|
+
var is = (test) => ({ args: none, test });
|
|
1314
|
+
var matchers = /* @__PURE__ */ new Map();
|
|
1315
|
+
function matcher(pattern, flags) {
|
|
1316
|
+
const key = `${flags}/${pattern}`;
|
|
1317
|
+
let compiled = matchers.get(key);
|
|
1318
|
+
if (compiled === void 0) {
|
|
1319
|
+
compiled = compileRegex(pattern, flags);
|
|
1320
|
+
if (matchers.size >= 100) matchers.clear();
|
|
1321
|
+
matchers.set(key, compiled);
|
|
1322
|
+
}
|
|
1323
|
+
return compiled;
|
|
1324
|
+
}
|
|
1325
|
+
function regexArgs(args) {
|
|
1326
|
+
const [pattern, flags = ""] = args;
|
|
1327
|
+
if (args.length < 1 || args.length > 2 || typeof pattern !== "string" || typeof flags !== "string")
|
|
1328
|
+
return "takes a pattern in quotes and, optionally, flags in quotes";
|
|
1329
|
+
if (!/^(?!.*(.).*\1)[ims]*$/.test(flags)) return `takes the flags i, m and s, each at most once; got "${flags}"`;
|
|
1330
|
+
if (pattern.length > MAX_REGEX_PATTERN)
|
|
1331
|
+
return `takes a pattern of at most ${MAX_REGEX_PATTERN} characters; got ${pattern.length}`;
|
|
1332
|
+
try {
|
|
1333
|
+
matcher(pattern, flags);
|
|
1334
|
+
} catch (err) {
|
|
1335
|
+
return `has a pattern it cannot run: ${err.message}`;
|
|
1336
|
+
}
|
|
1337
|
+
return void 0;
|
|
1338
|
+
}
|
|
1339
|
+
var CHECK_FUNCTIONS = {
|
|
1340
|
+
isNotNull: is((v) => v !== null),
|
|
1341
|
+
isString: is((v) => typeof v === "string"),
|
|
1342
|
+
isNumber: is((v) => typeof v === "number"),
|
|
1343
|
+
isBoolean: is((v) => typeof v === "boolean"),
|
|
1344
|
+
isArray: is((v) => Array.isArray(v)),
|
|
1345
|
+
isObject: is((v) => typeof v === "object" && v !== null && !Array.isArray(v)),
|
|
1346
|
+
matchesRegex: {
|
|
1347
|
+
args: regexArgs,
|
|
1348
|
+
test(v, [pattern, flags]) {
|
|
1349
|
+
if (typeof v !== "string") return false;
|
|
1350
|
+
if (v.length > MAX_REGEX_INPUT)
|
|
1351
|
+
return `the value is ${v.length} characters long and a pattern is not run on more than ${MAX_REGEX_INPUT}`;
|
|
1352
|
+
return matcher(pattern, flags ?? "")(v);
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
minLength: { args: oneLength, test: (v, [n]) => (lengthOf(v) ?? -1) >= n },
|
|
1356
|
+
maxLength: { args: oneLength, test: (v, [n]) => (lengthOf(v) ?? Infinity) <= n },
|
|
1357
|
+
gt: { args: oneNumber, test: (v, [n]) => typeof v === "number" && v > n },
|
|
1358
|
+
lt: { args: oneNumber, test: (v, [n]) => typeof v === "number" && v < n },
|
|
1359
|
+
oneOf: {
|
|
1360
|
+
args: (args) => args.length > 0 ? void 0 : "takes at least one value",
|
|
1361
|
+
test: (v, args) => args.includes(v)
|
|
1362
|
+
}
|
|
1363
|
+
};
|
|
1364
|
+
var known = (name) => Object.prototype.hasOwnProperty.call(CHECK_FUNCTIONS, name);
|
|
1365
|
+
var CheckSyntaxError = class extends Error {
|
|
1366
|
+
constructor(message) {
|
|
1367
|
+
super(message);
|
|
1368
|
+
this.name = "CheckSyntaxError";
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
var CALL_START = /^@([A-Za-z_]\w*)(\()?/;
|
|
1372
|
+
var BARE_ARG = /^(?:-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)$/;
|
|
1373
|
+
function parseArgs(s, from, name) {
|
|
1374
|
+
const args = [];
|
|
1375
|
+
const bad = (what, at) => new CheckSyntaxError(`@${name}: ${what} at character ${at + 1} of ${JSON.stringify(s)}`);
|
|
1376
|
+
let i = from;
|
|
1377
|
+
const skipSpaces = () => {
|
|
1378
|
+
while (s[i] === " ") i++;
|
|
1379
|
+
};
|
|
1380
|
+
skipSpaces();
|
|
1381
|
+
if (s[i] === ")") return [args, i + 1];
|
|
1382
|
+
for (; ; ) {
|
|
1383
|
+
const quote = s[i];
|
|
1384
|
+
if (quote === '"' || quote === "'") {
|
|
1385
|
+
let text = "";
|
|
1386
|
+
for (i++; s[i] !== quote; i++) {
|
|
1387
|
+
if (i >= s.length) throw bad("a string is not closed", from);
|
|
1388
|
+
if (s[i] === "\\" && s[i + 1] === quote) i++;
|
|
1389
|
+
text += s[i];
|
|
1390
|
+
}
|
|
1391
|
+
i++;
|
|
1392
|
+
args.push(text);
|
|
1393
|
+
} else {
|
|
1394
|
+
const start2 = i;
|
|
1395
|
+
while (i < s.length && !" ,)".includes(s[i])) i++;
|
|
1396
|
+
const token = s.slice(start2, i);
|
|
1397
|
+
if (!BARE_ARG.test(token))
|
|
1398
|
+
throw bad(
|
|
1399
|
+
`argument ${args.length + 1} must be a number, true, false, null or a string in quotes, got ${JSON.stringify(token)}`,
|
|
1400
|
+
start2
|
|
1401
|
+
);
|
|
1402
|
+
const value = JSON.parse(token);
|
|
1403
|
+
if (typeof value === "number" && !Number.isFinite(value))
|
|
1404
|
+
throw bad(`argument ${args.length + 1} is not a finite number, got ${JSON.stringify(token)}`, start2);
|
|
1405
|
+
args.push(value);
|
|
1406
|
+
}
|
|
1407
|
+
skipSpaces();
|
|
1408
|
+
if (s[i] === ")") return [args, i + 1];
|
|
1409
|
+
if (s[i] !== ",") throw bad('expected "," or ")"', i);
|
|
1410
|
+
i++;
|
|
1411
|
+
skipSpaces();
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
function parseExpectedString(s) {
|
|
1415
|
+
if (s.startsWith("@@")) return { literal: s.slice(1) };
|
|
1416
|
+
const first2 = CALL_START.exec(s);
|
|
1417
|
+
if (first2 === null) return { literal: s };
|
|
1418
|
+
if (first2[2] === void 0) {
|
|
1419
|
+
const after = s[first2[0].length];
|
|
1420
|
+
if (known(first2[1]) && (after === void 0 || after === " "))
|
|
1421
|
+
throw new CheckSyntaxError(
|
|
1422
|
+
`@${first2[1]} needs parentheses to be a check: @${first2[1]}(); for the text itself write @${s}`
|
|
1423
|
+
);
|
|
1424
|
+
return { literal: s };
|
|
1425
|
+
}
|
|
1426
|
+
const checks = [];
|
|
1427
|
+
let i = 0;
|
|
1428
|
+
while (i < s.length) {
|
|
1429
|
+
const call = CALL_START.exec(s.slice(i));
|
|
1430
|
+
if (call === null || call[2] === void 0)
|
|
1431
|
+
throw new CheckSyntaxError(
|
|
1432
|
+
`expected a check such as @isString() at character ${i + 1} of ${JSON.stringify(s)}; for the text itself write @${s}`
|
|
1433
|
+
);
|
|
1434
|
+
const name = call[1];
|
|
1435
|
+
if (!known(name))
|
|
1436
|
+
throw new CheckSyntaxError(
|
|
1437
|
+
`@${name} is not a check function (known: ${Object.keys(CHECK_FUNCTIONS).join(", ")}); for the text itself write @${s}`
|
|
1438
|
+
);
|
|
1439
|
+
const [args, end] = parseArgs(s, i + call[0].length, name);
|
|
1440
|
+
const text = s.slice(i, end);
|
|
1441
|
+
const wrong = CHECK_FUNCTIONS[name].args(args);
|
|
1442
|
+
if (wrong !== void 0) throw new CheckSyntaxError(`@${name} ${wrong}; got ${text}`);
|
|
1443
|
+
checks.push({ name, args, text });
|
|
1444
|
+
i = end;
|
|
1445
|
+
if (i < s.length && s[i] !== " ")
|
|
1446
|
+
throw new CheckSyntaxError(`checks are separated by a space: character ${i + 1} of ${JSON.stringify(s)}`);
|
|
1447
|
+
while (s[i] === " ") i++;
|
|
1448
|
+
}
|
|
1449
|
+
return { checks };
|
|
1450
|
+
}
|
|
1451
|
+
function firstFailedCheck(checks, actual) {
|
|
1452
|
+
for (const check3 of checks) {
|
|
1453
|
+
const result = CHECK_FUNCTIONS[check3.name].test(actual, check3.args);
|
|
1454
|
+
if (result === true) continue;
|
|
1455
|
+
return typeof result === "string" ? { check: check3, note: result } : { check: check3 };
|
|
1456
|
+
}
|
|
1457
|
+
return void 0;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
// src/json-verify/compare.ts
|
|
1461
|
+
var COMPARE_MODES = ["exact", "unordered", "contains"];
|
|
1462
|
+
var ExpectedJsonError = class extends Error {
|
|
1463
|
+
constructor(path11, message) {
|
|
1464
|
+
super(`${path11}: ${message}`);
|
|
1465
|
+
this.path = path11;
|
|
1466
|
+
this.name = "ExpectedJsonError";
|
|
1467
|
+
}
|
|
1468
|
+
path;
|
|
1469
|
+
};
|
|
1470
|
+
var MAX_MATCH_STEPS = 2e6;
|
|
1471
|
+
var MAX_INDEXED_KEYS = 50;
|
|
1472
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1473
|
+
var own = (o, key) => Object.prototype.hasOwnProperty.call(o, key);
|
|
1474
|
+
var typeOf = (v) => v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
|
|
1475
|
+
var PLAIN_KEY = /^[A-Za-z_$][\w$]*$/;
|
|
1476
|
+
var keyPath = (path11, key) => PLAIN_KEY.test(key) ? `${path11}.${key}` : `${path11}[${JSON.stringify(key)}]`;
|
|
1477
|
+
function readMarker(exp) {
|
|
1478
|
+
const keys = Object.keys(exp);
|
|
1479
|
+
if (own(exp, "$literal")) {
|
|
1480
|
+
if (keys.length !== 1)
|
|
1481
|
+
return 'an object with $literal must have no other key; data with a key $literal goes inside {"$literal": ...}';
|
|
1482
|
+
return { value: exp.$literal, literal: true };
|
|
1483
|
+
}
|
|
1484
|
+
if (!own(exp, "$mode")) return void 0;
|
|
1485
|
+
if (keys.length !== 2 || !own(exp, "$value"))
|
|
1486
|
+
return 'an object with $mode must have exactly the keys $mode and $value; data with a key $mode goes inside {"$literal": ...}';
|
|
1487
|
+
const mode = exp.$mode;
|
|
1488
|
+
if (!COMPARE_MODES.includes(mode))
|
|
1489
|
+
return `$mode must be one of ${COMPARE_MODES.join(", ")}; got ${JSON.stringify(exp.$mode)}`;
|
|
1490
|
+
return { value: exp.$value, mode, literal: false };
|
|
1491
|
+
}
|
|
1492
|
+
var MAX_EXPECTED_DEPTH = 100;
|
|
1493
|
+
var JSON_LEAF = /* @__PURE__ */ new Set(["string", "number", "boolean", "object"]);
|
|
1494
|
+
function validateExpected(expected) {
|
|
1495
|
+
const issues = [];
|
|
1496
|
+
const visit = (exp, path11, depth, literal) => {
|
|
1497
|
+
if (depth > MAX_EXPECTED_DEPTH) {
|
|
1498
|
+
issues.push({ path: path11, message: `expected is nested deeper than ${MAX_EXPECTED_DEPTH} levels` });
|
|
1499
|
+
} else if (Array.isArray(exp)) {
|
|
1500
|
+
exp.forEach((item, i) => visit(item, `${path11}[${i}]`, depth + 1, literal));
|
|
1501
|
+
} else if (isObject(exp)) {
|
|
1502
|
+
const proto = Object.getPrototypeOf(exp);
|
|
1503
|
+
const marker = literal ? void 0 : readMarker(exp);
|
|
1504
|
+
if (proto !== Object.prototype && proto !== null)
|
|
1505
|
+
issues.push({ path: path11, message: "an object that is not plain JSON data" });
|
|
1506
|
+
else if (own(exp, "__proto__"))
|
|
1507
|
+
issues.push({ path: keyPath(path11, "__proto__"), message: "the key __proto__ is not supported in expected" });
|
|
1508
|
+
else if (typeof marker === "string") issues.push({ path: path11, message: marker });
|
|
1509
|
+
else if (marker === void 0)
|
|
1510
|
+
for (const key of Object.keys(exp)) visit(exp[key], keyPath(path11, key), depth + 1, literal);
|
|
1511
|
+
else visit(marker.value, path11, depth + 1, marker.literal);
|
|
1512
|
+
} else if (!literal && typeof exp === "string") {
|
|
1513
|
+
try {
|
|
1514
|
+
parseExpectedString(exp);
|
|
1515
|
+
} catch (err) {
|
|
1516
|
+
issues.push({ path: path11, message: err.message });
|
|
1517
|
+
}
|
|
1518
|
+
} else if (!JSON_LEAF.has(typeof exp) || typeof exp === "number" && !Number.isFinite(exp)) {
|
|
1519
|
+
const what = typeof exp === "number" || exp === void 0 ? String(exp) : `a ${typeof exp}`;
|
|
1520
|
+
issues.push({ path: path11, message: `${what} is not a JSON value` });
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
visit(expected, "$", 0, false);
|
|
1524
|
+
return issues;
|
|
1525
|
+
}
|
|
1526
|
+
var done = (sink) => sink.list.length >= sink.limit || sink.budget.spent !== void 0;
|
|
1527
|
+
function walk(exp, act, mode, path11, sink, literal) {
|
|
1528
|
+
if (!literal && isObject(exp)) {
|
|
1529
|
+
const marker = readMarker(exp);
|
|
1530
|
+
if (marker !== void 0) {
|
|
1531
|
+
walk(marker.value, act, marker.mode ?? mode, path11, sink, marker.literal);
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
if (!literal && typeof exp === "string") {
|
|
1536
|
+
const parsed2 = parseExpectedString(exp);
|
|
1537
|
+
if ("checks" in parsed2) {
|
|
1538
|
+
const failed = firstFailedCheck(parsed2.checks, act);
|
|
1539
|
+
if (failed !== void 0)
|
|
1540
|
+
sink.list.push({
|
|
1541
|
+
path: path11,
|
|
1542
|
+
reason: "function",
|
|
1543
|
+
expected: exp,
|
|
1544
|
+
actual: act,
|
|
1545
|
+
detail: failed.note === void 0 ? failed.check.text : `${failed.check.text}: ${failed.note}`
|
|
1546
|
+
});
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
exp = parsed2.literal;
|
|
1550
|
+
}
|
|
1551
|
+
if (typeOf(exp) !== typeOf(act)) {
|
|
1552
|
+
sink.list.push({ path: path11, reason: "type", expected: exp, actual: act });
|
|
1553
|
+
} else if (Array.isArray(exp)) {
|
|
1554
|
+
(mode === "exact" ? walkInOrder : walkAnyOrder)(exp, act, mode, path11, sink, literal);
|
|
1555
|
+
} else if (isObject(exp)) {
|
|
1556
|
+
walkObject(exp, act, mode, path11, sink, literal);
|
|
1557
|
+
} else if (exp !== act) {
|
|
1558
|
+
sink.list.push({ path: path11, reason: "value", expected: exp, actual: act });
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
function walkObject(exp, act, mode, path11, sink, literal) {
|
|
1562
|
+
const keys = Object.keys(exp);
|
|
1563
|
+
if (sink.limit === 1) keys.sort((a, b) => Number(!isScalar(exp[a])) - Number(!isScalar(exp[b])));
|
|
1564
|
+
for (const key of keys) {
|
|
1565
|
+
if (done(sink)) return;
|
|
1566
|
+
const at = keyPath(path11, key);
|
|
1567
|
+
if (own(act, key)) walk(exp[key], act[key], mode, at, sink, literal);
|
|
1568
|
+
else sink.list.push({ path: at, reason: "missing-key", expected: exp[key] });
|
|
1569
|
+
}
|
|
1570
|
+
if (mode === "contains") return;
|
|
1571
|
+
for (const key of Object.keys(act))
|
|
1572
|
+
if (!own(exp, key)) sink.list.push({ path: keyPath(path11, key), reason: "extra-key", actual: act[key] });
|
|
1573
|
+
}
|
|
1574
|
+
function walkInOrder(exp, act, mode, path11, sink, literal) {
|
|
1575
|
+
const shared = Math.min(exp.length, act.length);
|
|
1576
|
+
for (let i = 0; i < shared && !done(sink); i++) walk(exp[i], act[i], mode, `${path11}[${i}]`, sink, literal);
|
|
1577
|
+
for (let i = shared; i < exp.length; i++)
|
|
1578
|
+
sink.list.push({ path: `${path11}[${i}]`, reason: "missing-element", expected: exp[i] });
|
|
1579
|
+
for (let i = shared; i < act.length; i++)
|
|
1580
|
+
sink.list.push({ path: `${path11}[${i}]`, reason: "extra-element", actual: act[i] });
|
|
1581
|
+
}
|
|
1582
|
+
var isScalar = (v) => typeof v !== "object" || v === null;
|
|
1583
|
+
function plainScalar(e, literal) {
|
|
1584
|
+
if (!isScalar(e)) return void 0;
|
|
1585
|
+
if (literal || typeof e !== "string") return { value: e };
|
|
1586
|
+
const parsed2 = parseExpectedString(e);
|
|
1587
|
+
return "literal" in parsed2 ? { value: parsed2.literal } : void 0;
|
|
1588
|
+
}
|
|
1589
|
+
var scalarKey = (v) => `${typeOf(v)}:${String(v)}`;
|
|
1590
|
+
function walkAnyOrder(exp, act, mode, path11, sink, literal) {
|
|
1591
|
+
const probing = sink.limit === 1;
|
|
1592
|
+
if (probing && (mode === "unordered" ? exp.length !== act.length : exp.length > act.length)) {
|
|
1593
|
+
sink.list.push({ path: path11, reason: "no-match" });
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
const { budget } = sink;
|
|
1597
|
+
const taken = new Uint8Array(act.length);
|
|
1598
|
+
const unmatched = [];
|
|
1599
|
+
const rest = [];
|
|
1600
|
+
const scalars = /* @__PURE__ */ new Map();
|
|
1601
|
+
for (let j = act.length - 1; j >= 0; j--) {
|
|
1602
|
+
if (!isScalar(act[j])) continue;
|
|
1603
|
+
const key = scalarKey(act[j]);
|
|
1604
|
+
const at = scalars.get(key);
|
|
1605
|
+
if (at === void 0) scalars.set(key, [j]);
|
|
1606
|
+
else at.push(j);
|
|
1607
|
+
}
|
|
1608
|
+
exp.forEach((e, i) => {
|
|
1609
|
+
const plain = plainScalar(e, literal);
|
|
1610
|
+
if (plain === void 0) return rest.push(i);
|
|
1611
|
+
const j = scalars.get(scalarKey(plain.value))?.pop();
|
|
1612
|
+
if (j === void 0) return unmatched.push(i);
|
|
1613
|
+
taken[j] = 1;
|
|
1614
|
+
});
|
|
1615
|
+
if (rest.length > 0 && !(probing && unmatched.length > 0)) {
|
|
1616
|
+
const open2 = [];
|
|
1617
|
+
for (let j = 0; j < act.length; j++) if (taken[j] === 0) open2.push(j);
|
|
1618
|
+
const fits = /* @__PURE__ */ new Map();
|
|
1619
|
+
const fit = (e, c) => {
|
|
1620
|
+
const at = e * open2.length + c;
|
|
1621
|
+
let known2 = fits.get(at);
|
|
1622
|
+
if (known2 === void 0) {
|
|
1623
|
+
if (--budget.steps < 0) {
|
|
1624
|
+
budget.spent = {
|
|
1625
|
+
path: path11,
|
|
1626
|
+
reason: "too-large",
|
|
1627
|
+
detail: `matching arrays in any order took more than ${MAX_MATCH_STEPS} comparisons of elements`
|
|
1628
|
+
};
|
|
1629
|
+
return false;
|
|
1630
|
+
}
|
|
1631
|
+
const probe = { list: [], limit: 1, budget };
|
|
1632
|
+
walk(exp[rest[e]], act[open2[c]], mode, path11, probe, literal);
|
|
1633
|
+
known2 = probe.list.length === 0;
|
|
1634
|
+
fits.set(at, known2);
|
|
1635
|
+
}
|
|
1636
|
+
return known2;
|
|
1637
|
+
};
|
|
1638
|
+
const all = open2.map((_, c) => c);
|
|
1639
|
+
const index = /* @__PURE__ */ new Map();
|
|
1640
|
+
const withValue = (key, value) => {
|
|
1641
|
+
let byValue = index.get(key);
|
|
1642
|
+
if (byValue === void 0) {
|
|
1643
|
+
if (index.size === MAX_INDEXED_KEYS) return void 0;
|
|
1644
|
+
byValue = /* @__PURE__ */ new Map();
|
|
1645
|
+
for (let c = 0; c < open2.length; c++) {
|
|
1646
|
+
const a = act[open2[c]];
|
|
1647
|
+
if (!isObject(a) || !own(a, key) || !isScalar(a[key])) continue;
|
|
1648
|
+
const list2 = byValue.get(scalarKey(a[key]));
|
|
1649
|
+
if (list2 === void 0) byValue.set(scalarKey(a[key]), [c]);
|
|
1650
|
+
else list2.push(c);
|
|
1651
|
+
}
|
|
1652
|
+
index.set(key, byValue);
|
|
1653
|
+
}
|
|
1654
|
+
return byValue.get(value) ?? [];
|
|
1655
|
+
};
|
|
1656
|
+
const lists = /* @__PURE__ */ new Map();
|
|
1657
|
+
const candidates = (e) => {
|
|
1658
|
+
let best = lists.get(e);
|
|
1659
|
+
if (best !== void 0) return best;
|
|
1660
|
+
best = all;
|
|
1661
|
+
const x = exp[rest[e]];
|
|
1662
|
+
if (isObject(x) && (literal || readMarker(x) === void 0))
|
|
1663
|
+
for (const key of Object.keys(x)) {
|
|
1664
|
+
const plain = plainScalar(x[key], literal);
|
|
1665
|
+
const list2 = plain === void 0 ? void 0 : withValue(key, scalarKey(plain.value));
|
|
1666
|
+
if (list2 !== void 0 && list2.length < best.length) best = list2;
|
|
1667
|
+
}
|
|
1668
|
+
lists.set(e, best);
|
|
1669
|
+
return best;
|
|
1670
|
+
};
|
|
1671
|
+
const holder = new Int32Array(open2.length).fill(-1);
|
|
1672
|
+
const seen = new Int32Array(open2.length).fill(-1);
|
|
1673
|
+
const place = (root) => {
|
|
1674
|
+
const elements = [root];
|
|
1675
|
+
const tried = [0];
|
|
1676
|
+
const reached = [];
|
|
1677
|
+
while (elements.length > 0) {
|
|
1678
|
+
const top = elements.length - 1;
|
|
1679
|
+
const e = elements[top];
|
|
1680
|
+
const list2 = candidates(e);
|
|
1681
|
+
let deeper = false;
|
|
1682
|
+
while (!deeper && tried[top] < list2.length) {
|
|
1683
|
+
const c = list2[(e + tried[top]++) % list2.length];
|
|
1684
|
+
if (seen[c] === root) continue;
|
|
1685
|
+
if (!fit(e, c)) {
|
|
1686
|
+
if (budget.spent !== void 0) return false;
|
|
1687
|
+
continue;
|
|
1688
|
+
}
|
|
1689
|
+
seen[c] = root;
|
|
1690
|
+
reached[top] = c;
|
|
1691
|
+
if (holder[c] === -1) {
|
|
1692
|
+
for (let k = top; k >= 0; k--) holder[reached[k]] = elements[k];
|
|
1693
|
+
return true;
|
|
1694
|
+
}
|
|
1695
|
+
elements.push(holder[c]);
|
|
1696
|
+
tried.push(0);
|
|
1697
|
+
deeper = true;
|
|
1698
|
+
}
|
|
1699
|
+
if (!deeper) {
|
|
1700
|
+
elements.pop();
|
|
1701
|
+
tried.pop();
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return false;
|
|
1705
|
+
};
|
|
1706
|
+
for (let e = 0; e < rest.length; e++) {
|
|
1707
|
+
const placed = place(e);
|
|
1708
|
+
if (budget.spent !== void 0) return;
|
|
1709
|
+
if (placed) continue;
|
|
1710
|
+
unmatched.push(rest[e]);
|
|
1711
|
+
if (probing) break;
|
|
1712
|
+
}
|
|
1713
|
+
holder.forEach((e, c) => {
|
|
1714
|
+
if (e !== -1) taken[open2[c]] = 1;
|
|
1715
|
+
});
|
|
1716
|
+
}
|
|
1717
|
+
for (const i of unmatched.sort((a, b) => a - b))
|
|
1718
|
+
sink.list.push({ path: `${path11}[${i}]`, reason: "no-match", expected: exp[i] });
|
|
1719
|
+
if (mode === "contains") return;
|
|
1720
|
+
for (let j = 0; j < act.length; j++)
|
|
1721
|
+
if (taken[j] === 0) sink.list.push({ path: `${path11}[${j}]`, reason: "extra-element", actual: act[j] });
|
|
1722
|
+
}
|
|
1723
|
+
function compareJson(expected, actual, options = {}) {
|
|
1724
|
+
const issue = validateExpected(expected)[0];
|
|
1725
|
+
if (issue !== void 0) throw new ExpectedJsonError(issue.path, issue.message);
|
|
1726
|
+
const sink = { list: [], limit: Infinity, budget: { steps: MAX_MATCH_STEPS } };
|
|
1727
|
+
walk(expected, actual, options.mode ?? "exact", "$", sink, false);
|
|
1728
|
+
return sink.budget.spent === void 0 ? sink.list : [sink.budget.spent];
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1109
1731
|
// src/util/duration.ts
|
|
1110
1732
|
init_cjs_shims();
|
|
1111
1733
|
var MAX_TIMER_MS = 2147483647;
|
|
@@ -1172,6 +1794,19 @@ var jsonSchemaAssertionSchema = import_zod.z.object({
|
|
|
1172
1794
|
schema: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()),
|
|
1173
1795
|
extract: import_zod.z.enum(["auto", "strict"]).optional()
|
|
1174
1796
|
});
|
|
1797
|
+
var jsonVerifyAssertionSchema = import_zod.z.strictObject({
|
|
1798
|
+
type: import_zod.z.literal("json-verify"),
|
|
1799
|
+
// Optional to the parser so that a missing one gets the message below, not "Invalid input".
|
|
1800
|
+
expected: import_zod.z.any().optional(),
|
|
1801
|
+
mode: import_zod.z.enum(COMPARE_MODES).optional(),
|
|
1802
|
+
extract: import_zod.z.enum(["auto", "strict"]).optional()
|
|
1803
|
+
}).superRefine((a, ctx) => {
|
|
1804
|
+
if (a.expected === void 0)
|
|
1805
|
+
ctx.addIssue({ code: "custom", path: ["expected"], message: "expected is required (null is written as null)" });
|
|
1806
|
+
else
|
|
1807
|
+
for (const issue of validateExpected(a.expected))
|
|
1808
|
+
ctx.addIssue({ code: "custom", path: ["expected"], message: `${issue.path}: ${issue.message}` });
|
|
1809
|
+
});
|
|
1175
1810
|
var jevJudgeSchema = import_zod.z.strictObject({
|
|
1176
1811
|
type: import_zod.z.literal("jev"),
|
|
1177
1812
|
// A full version, never an alias: `jev-latest` would change the judge under a run without a word.
|
|
@@ -1270,6 +1905,7 @@ var assertionConfigSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
1270
1905
|
containsAnyAssertionSchema,
|
|
1271
1906
|
containsAllAssertionSchema,
|
|
1272
1907
|
jsonSchemaAssertionSchema,
|
|
1908
|
+
jsonVerifyAssertionSchema,
|
|
1273
1909
|
llmJudgeAssertionSchema,
|
|
1274
1910
|
semanticSimilarityAssertionSchema,
|
|
1275
1911
|
faithfulnessAssertionSchema,
|
|
@@ -1303,14 +1939,14 @@ var mcpServersSchema = import_zod.z.record(import_zod.z.string().min(1), mcpServ
|
|
|
1303
1939
|
for (const [name, server] of Object.entries(servers)) {
|
|
1304
1940
|
const issue = (message) => ctx.addIssue({ code: "custom", path: [name], message });
|
|
1305
1941
|
const stdio = server.command !== void 0;
|
|
1306
|
-
const
|
|
1307
|
-
if (stdio &&
|
|
1942
|
+
const http2 = server.url !== void 0;
|
|
1943
|
+
if (stdio && http2)
|
|
1308
1944
|
issue(`server "${name}" has both command and url; give command (stdio) or url (HTTP), not both`);
|
|
1309
|
-
else if (!stdio && !
|
|
1945
|
+
else if (!stdio && !http2)
|
|
1310
1946
|
issue(`server "${name}" needs command (a stdio server) or url (an HTTP server)`);
|
|
1311
1947
|
else if (stdio && server.headers !== void 0)
|
|
1312
1948
|
issue(`server "${name}": headers are for a server at url, not one started with command`);
|
|
1313
|
-
else if (
|
|
1949
|
+
else if (http2 && (server.args ?? server.env ?? server.cwd) !== void 0)
|
|
1314
1950
|
issue(`server "${name}": args, env and cwd are for a server started with command, not one at url`);
|
|
1315
1951
|
}
|
|
1316
1952
|
});
|
|
@@ -1330,7 +1966,9 @@ var evalConfigSchema = import_zod.z.object({
|
|
|
1330
1966
|
dataset: datasetRefSchema,
|
|
1331
1967
|
assertions: import_zod.z.array(assertionConfigSchema),
|
|
1332
1968
|
...evalRepeatsShape,
|
|
1333
|
-
mcp: evalMcpSchema.optional()
|
|
1969
|
+
mcp: evalMcpSchema.optional(),
|
|
1970
|
+
// The path of a stub file; the file itself is read and checked when the run starts.
|
|
1971
|
+
stubs: import_zod.z.string().min(1).optional()
|
|
1334
1972
|
}).refine(
|
|
1335
1973
|
(data) => !(data.prompt !== void 0 && data.prompt_file !== void 0),
|
|
1336
1974
|
{ message: "prompt and prompt_file are mutually exclusive" }
|
|
@@ -1375,6 +2013,12 @@ var pluneConfigSchema = import_zod.z.object({
|
|
|
1375
2013
|
});
|
|
1376
2014
|
}
|
|
1377
2015
|
config.evals.forEach((evalConfig, i) => {
|
|
2016
|
+
if (evalConfig.stubs !== void 0 && evalConfig.mcp !== void 0)
|
|
2017
|
+
ctx.addIssue({
|
|
2018
|
+
code: "custom",
|
|
2019
|
+
path: ["evals", i, "stubs"],
|
|
2020
|
+
message: `eval "${evalConfig.id}" has both stubs and mcp: stubs answer the model call of an eval without mcp`
|
|
2021
|
+
});
|
|
1378
2022
|
const server = evalConfig.mcp?.server;
|
|
1379
2023
|
if (server === void 0) {
|
|
1380
2024
|
const misplaced = (assertions, path11) => assertions.forEach((a, j) => {
|
|
@@ -1398,8 +2042,8 @@ var pluneConfigSchema = import_zod.z.object({
|
|
|
1398
2042
|
});
|
|
1399
2043
|
}).transform(({ provider, ...rest }) => {
|
|
1400
2044
|
if (!Array.isArray(provider)) return { provider, ...rest };
|
|
1401
|
-
const [
|
|
1402
|
-
return others.length === 0 ? { provider:
|
|
2045
|
+
const [first2, ...others] = provider;
|
|
2046
|
+
return others.length === 0 ? { provider: first2, ...rest } : { provider: first2, providers: provider, ...rest };
|
|
1403
2047
|
});
|
|
1404
2048
|
|
|
1405
2049
|
// src/config/env-overrides.ts
|
|
@@ -1894,7 +2538,7 @@ function warnReasoningEffortNotSent(model, effort) {
|
|
|
1894
2538
|
`
|
|
1895
2539
|
);
|
|
1896
2540
|
}
|
|
1897
|
-
var
|
|
2541
|
+
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1898
2542
|
function toAnthropicMessages(messages) {
|
|
1899
2543
|
return messages.map((m) => {
|
|
1900
2544
|
if (m.role === "user") return { role: "user", content: m.content };
|
|
@@ -1916,13 +2560,13 @@ function toAnthropicMessages(messages) {
|
|
|
1916
2560
|
type: "tool_use",
|
|
1917
2561
|
id: c.id,
|
|
1918
2562
|
name: c.name,
|
|
1919
|
-
input:
|
|
2563
|
+
input: isObject2(c.args) ? c.args : {}
|
|
1920
2564
|
}))
|
|
1921
2565
|
]
|
|
1922
2566
|
};
|
|
1923
2567
|
});
|
|
1924
2568
|
}
|
|
1925
|
-
function makeAnthropicProvider(config, env, pricing) {
|
|
2569
|
+
function makeAnthropicProvider(config, env, pricing, stubOrigin) {
|
|
1926
2570
|
const apiKey = env[ENV_VAR];
|
|
1927
2571
|
if (apiKey === void 0 || apiKey.trim() === "") {
|
|
1928
2572
|
throw new AuthError(
|
|
@@ -1933,6 +2577,8 @@ function makeAnthropicProvider(config, env, pricing) {
|
|
|
1933
2577
|
const client = new import_sdk.default({
|
|
1934
2578
|
apiKey,
|
|
1935
2579
|
maxRetries: 0,
|
|
2580
|
+
// The client adds `/v1/messages` itself.
|
|
2581
|
+
...stubOrigin !== void 0 ? { baseURL: stubOrigin } : {},
|
|
1936
2582
|
...config.timeout !== void 0 ? { timeout: config.timeout } : {}
|
|
1937
2583
|
});
|
|
1938
2584
|
const maxRetries = config.max_retries ?? DEFAULT_MAX_RETRIES;
|
|
@@ -2126,12 +2772,13 @@ function makeOpenAiCompatibleProvider(opts) {
|
|
|
2126
2772
|
}
|
|
2127
2773
|
};
|
|
2128
2774
|
}
|
|
2129
|
-
function makeOpenAiProvider(config, env, pricing) {
|
|
2775
|
+
function makeOpenAiProvider(config, env, pricing, stubOrigin) {
|
|
2130
2776
|
return makeOpenAiCompatibleProvider({
|
|
2131
2777
|
config,
|
|
2132
2778
|
env,
|
|
2133
2779
|
pricing,
|
|
2134
2780
|
apiKeyEnv: "OPENAI_API_KEY",
|
|
2781
|
+
...stubOrigin !== void 0 ? { baseURL: `${stubOrigin}/v1` } : {},
|
|
2135
2782
|
maxCompletionTokens: true,
|
|
2136
2783
|
sendsReasoningEffort: true
|
|
2137
2784
|
});
|
|
@@ -2140,13 +2787,13 @@ function makeOpenAiProvider(config, env, pricing) {
|
|
|
2140
2787
|
// src/providers/openrouter.ts
|
|
2141
2788
|
init_cjs_shims();
|
|
2142
2789
|
var OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
|
2143
|
-
function makeOpenRouterProvider(config, env, pricing) {
|
|
2790
|
+
function makeOpenRouterProvider(config, env, pricing, stubOrigin) {
|
|
2144
2791
|
return makeOpenAiCompatibleProvider({
|
|
2145
2792
|
config,
|
|
2146
2793
|
env,
|
|
2147
2794
|
pricing,
|
|
2148
2795
|
apiKeyEnv: "OPENROUTER_API_KEY",
|
|
2149
|
-
baseURL: OPENROUTER_BASE_URL,
|
|
2796
|
+
baseURL: stubOrigin !== void 0 ? `${stubOrigin}/api/v1` : OPENROUTER_BASE_URL,
|
|
2150
2797
|
reportsCost: true
|
|
2151
2798
|
// OpenRouter reports the call's actual cost via usage.cost (ADR-PRC02)
|
|
2152
2799
|
});
|
|
@@ -2162,13 +2809,13 @@ function createProviderRegistry() {
|
|
|
2162
2809
|
}
|
|
2163
2810
|
factories.set(name, factory);
|
|
2164
2811
|
},
|
|
2165
|
-
resolve(name, config, env, pricing) {
|
|
2812
|
+
resolve(name, config, env, pricing, stubOrigin) {
|
|
2166
2813
|
const factory = factories.get(name);
|
|
2167
2814
|
if (factory === void 0) {
|
|
2168
|
-
const
|
|
2169
|
-
throw new Error(`Unknown provider type "${name}". Registered providers: ${
|
|
2815
|
+
const known2 = [...factories.keys()].join(", ") || "(none)";
|
|
2816
|
+
throw new Error(`Unknown provider type "${name}". Registered providers: ${known2}.`);
|
|
2170
2817
|
}
|
|
2171
|
-
return factory(config, env, pricing);
|
|
2818
|
+
return factory(config, env, pricing, stubOrigin);
|
|
2172
2819
|
},
|
|
2173
2820
|
has(name) {
|
|
2174
2821
|
return factories.has(name);
|
|
@@ -2182,8 +2829,8 @@ function createDefaultRegistry() {
|
|
|
2182
2829
|
registry.register("openrouter", makeOpenRouterProvider);
|
|
2183
2830
|
return registry;
|
|
2184
2831
|
}
|
|
2185
|
-
function getProvider(config, env, pricing) {
|
|
2186
|
-
return createDefaultRegistry().resolve(config.type, config, env, pricing);
|
|
2832
|
+
function getProvider(config, env, pricing, stubOrigin) {
|
|
2833
|
+
return createDefaultRegistry().resolve(config.type, config, env, pricing, stubOrigin);
|
|
2187
2834
|
}
|
|
2188
2835
|
|
|
2189
2836
|
// src/providers/estimate.ts
|
|
@@ -2523,7 +3170,7 @@ init_cjs_shims();
|
|
|
2523
3170
|
|
|
2524
3171
|
// src/orchestrator/run.ts
|
|
2525
3172
|
init_cjs_shims();
|
|
2526
|
-
var
|
|
3173
|
+
var fs4 = __toESM(require("fs"), 1);
|
|
2527
3174
|
var path3 = __toESM(require("path"), 1);
|
|
2528
3175
|
|
|
2529
3176
|
// src/assertions/json-extract.ts
|
|
@@ -2559,23 +3206,23 @@ function* balancedRuns(s) {
|
|
|
2559
3206
|
while (i < s.length) {
|
|
2560
3207
|
const rel = s.slice(i).search(/[{[]/);
|
|
2561
3208
|
if (rel === -1) return;
|
|
2562
|
-
const
|
|
2563
|
-
const run = balancedFrom(s,
|
|
3209
|
+
const start2 = i + rel;
|
|
3210
|
+
const run = balancedFrom(s, start2);
|
|
2564
3211
|
if (run === null) {
|
|
2565
|
-
i =
|
|
3212
|
+
i = start2 + 1;
|
|
2566
3213
|
} else {
|
|
2567
3214
|
yield run;
|
|
2568
|
-
i =
|
|
3215
|
+
i = start2 + run.length;
|
|
2569
3216
|
}
|
|
2570
3217
|
}
|
|
2571
3218
|
}
|
|
2572
|
-
function balancedFrom(s,
|
|
2573
|
-
const open2 = s[
|
|
3219
|
+
function balancedFrom(s, start2) {
|
|
3220
|
+
const open2 = s[start2];
|
|
2574
3221
|
const close = open2 === "{" ? "}" : "]";
|
|
2575
3222
|
let depth = 0;
|
|
2576
3223
|
let inString = false;
|
|
2577
3224
|
let escaped = false;
|
|
2578
|
-
for (let i =
|
|
3225
|
+
for (let i = start2; i < s.length; i++) {
|
|
2579
3226
|
const ch = s[i];
|
|
2580
3227
|
if (inString) {
|
|
2581
3228
|
if (escaped) escaped = false;
|
|
@@ -2589,7 +3236,7 @@ function balancedFrom(s, start) {
|
|
|
2589
3236
|
depth++;
|
|
2590
3237
|
} else if (ch === close) {
|
|
2591
3238
|
depth--;
|
|
2592
|
-
if (depth === 0) return s.slice(
|
|
3239
|
+
if (depth === 0) return s.slice(start2, i + 1);
|
|
2593
3240
|
}
|
|
2594
3241
|
}
|
|
2595
3242
|
return null;
|
|
@@ -2718,6 +3365,93 @@ var jsonSchema = {
|
|
|
2718
3365
|
}
|
|
2719
3366
|
};
|
|
2720
3367
|
|
|
3368
|
+
// src/assertions/json-verify.ts
|
|
3369
|
+
init_cjs_shims();
|
|
3370
|
+
|
|
3371
|
+
// src/json-verify/format.ts
|
|
3372
|
+
init_cjs_shims();
|
|
3373
|
+
var MAX_FRAGMENT = 120;
|
|
3374
|
+
var MAX_FRAGMENT_DEPTH = 6;
|
|
3375
|
+
var MAX_LISTED = 10;
|
|
3376
|
+
var typeOf2 = (v) => v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
|
|
3377
|
+
function fragment(value) {
|
|
3378
|
+
let out = "";
|
|
3379
|
+
const write = (v, depth) => {
|
|
3380
|
+
if (typeof v !== "object" || v === null) {
|
|
3381
|
+
out += JSON.stringify(typeof v === "string" ? v.slice(0, MAX_FRAGMENT) : v);
|
|
3382
|
+
} else if (depth === MAX_FRAGMENT_DEPTH) {
|
|
3383
|
+
out += "...";
|
|
3384
|
+
} else {
|
|
3385
|
+
const list2 = Array.isArray(v);
|
|
3386
|
+
out += list2 ? "[" : "{";
|
|
3387
|
+
let n = 0;
|
|
3388
|
+
for (const [key, item] of list2 ? v.entries() : Object.entries(v)) {
|
|
3389
|
+
if (out.length > MAX_FRAGMENT) return;
|
|
3390
|
+
if (n++ > 0) out += ",";
|
|
3391
|
+
if (!list2) out += `${JSON.stringify(key)}:`;
|
|
3392
|
+
write(item, depth + 1);
|
|
3393
|
+
}
|
|
3394
|
+
out += list2 ? "]" : "}";
|
|
3395
|
+
}
|
|
3396
|
+
};
|
|
3397
|
+
write(value, 0);
|
|
3398
|
+
if (out.length <= MAX_FRAGMENT) return out;
|
|
3399
|
+
const last = out.charCodeAt(MAX_FRAGMENT - 1);
|
|
3400
|
+
const end = last >= 55296 && last <= 56319 ? MAX_FRAGMENT - 1 : MAX_FRAGMENT;
|
|
3401
|
+
return `${out.slice(0, end)}...`;
|
|
3402
|
+
}
|
|
3403
|
+
function reasonText(m) {
|
|
3404
|
+
switch (m.reason) {
|
|
3405
|
+
case "missing-key":
|
|
3406
|
+
return "missing key";
|
|
3407
|
+
case "extra-key":
|
|
3408
|
+
return "extra key";
|
|
3409
|
+
case "type":
|
|
3410
|
+
return `type differs: expected ${typeOf2(m.expected)}, got ${typeOf2(m.actual)}`;
|
|
3411
|
+
case "value":
|
|
3412
|
+
return "value differs";
|
|
3413
|
+
case "function":
|
|
3414
|
+
return `function not satisfied: ${m.detail}`;
|
|
3415
|
+
case "missing-element":
|
|
3416
|
+
return "missing element";
|
|
3417
|
+
case "extra-element":
|
|
3418
|
+
return "extra element";
|
|
3419
|
+
case "no-match":
|
|
3420
|
+
return "no match for an array element";
|
|
3421
|
+
case "too-large":
|
|
3422
|
+
return `too large: ${m.detail}`;
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
function formatMismatches(list2) {
|
|
3426
|
+
if (list2.length === 0) return "";
|
|
3427
|
+
const lines = [`${list2.length} ${list2.length === 1 ? "mismatch" : "mismatches"}`];
|
|
3428
|
+
for (const m of list2.slice(0, MAX_LISTED)) {
|
|
3429
|
+
lines.push(` ${m.path}: ${reasonText(m)}`);
|
|
3430
|
+
if (m.expected !== void 0) lines.push(` expected: ${fragment(m.expected)}`);
|
|
3431
|
+
if (m.actual !== void 0) lines.push(` actual: ${fragment(m.actual)}`);
|
|
3432
|
+
}
|
|
3433
|
+
if (list2.length > MAX_LISTED) lines.push(` and ${list2.length - MAX_LISTED} more`);
|
|
3434
|
+
return lines.join("\n");
|
|
3435
|
+
}
|
|
3436
|
+
|
|
3437
|
+
// src/assertions/json-verify.ts
|
|
3438
|
+
var jsonVerify = {
|
|
3439
|
+
run(ctx) {
|
|
3440
|
+
const extract = ctx.params.extract ?? "auto";
|
|
3441
|
+
const extracted = extractJson(ctx.output, extract);
|
|
3442
|
+
if (!extracted.ok) {
|
|
3443
|
+
return Promise.resolve({
|
|
3444
|
+
passed: false,
|
|
3445
|
+
reason: `output is not valid JSON (extract mode: ${extract})`
|
|
3446
|
+
});
|
|
3447
|
+
}
|
|
3448
|
+
const mismatches = compareJson(ctx.params.expected, extracted.value, { mode: ctx.params.mode ?? "exact" });
|
|
3449
|
+
return Promise.resolve(
|
|
3450
|
+
mismatches.length === 0 ? { passed: true } : { passed: false, reason: formatMismatches(mismatches) }
|
|
3451
|
+
);
|
|
3452
|
+
}
|
|
3453
|
+
};
|
|
3454
|
+
|
|
2721
3455
|
// src/assertions/semantic-similarity.ts
|
|
2722
3456
|
init_cjs_shims();
|
|
2723
3457
|
var DEFAULT_THRESHOLD = 0.8;
|
|
@@ -3128,9 +3862,9 @@ var firstTool = check((ctx) => {
|
|
|
3128
3862
|
const { tool } = ctx.params;
|
|
3129
3863
|
const t = transcriptOf("first-tool", ctx);
|
|
3130
3864
|
checkNames("first-tool", t, [tool]);
|
|
3131
|
-
const
|
|
3132
|
-
if (
|
|
3133
|
-
const got =
|
|
3865
|
+
const first2 = callsOf(t)[0];
|
|
3866
|
+
if (first2?.call.name === tool) return pass;
|
|
3867
|
+
const got = first2 === void 0 ? "no tool call at all: the model answered without one" : describeCall(first2);
|
|
3134
3868
|
return fail(
|
|
3135
3869
|
`expected the first call to be "${tool}"; got ${got}; check that the prompt and the tool's description point the model to it first`
|
|
3136
3870
|
);
|
|
@@ -3321,8 +4055,8 @@ function createAssertionRegistry() {
|
|
|
3321
4055
|
resolve(type) {
|
|
3322
4056
|
const impl = impls.get(type);
|
|
3323
4057
|
if (impl === void 0) {
|
|
3324
|
-
const
|
|
3325
|
-
throw new Error(`Unknown assertion type "${type}". Registered: ${
|
|
4058
|
+
const known2 = [...impls.keys()].join(", ") || "(none)";
|
|
4059
|
+
throw new Error(`Unknown assertion type "${type}". Registered: ${known2}.`);
|
|
3326
4060
|
}
|
|
3327
4061
|
return impl;
|
|
3328
4062
|
},
|
|
@@ -3341,6 +4075,7 @@ function createDefaultRegistry2() {
|
|
|
3341
4075
|
registry.register("contains-any", containsAny);
|
|
3342
4076
|
registry.register("contains-all", containsAll);
|
|
3343
4077
|
registry.register("json-schema", jsonSchema);
|
|
4078
|
+
registry.register("json-verify", jsonVerify);
|
|
3344
4079
|
registry.register("semantic-similarity", semanticSimilarity);
|
|
3345
4080
|
registry.register("llm-judge", llmJudge);
|
|
3346
4081
|
registry.register("faithfulness", faithfulness);
|
|
@@ -3376,6 +4111,7 @@ var ASSERTION_CLASSES = {
|
|
|
3376
4111
|
"contains-any": "deterministic",
|
|
3377
4112
|
"contains-all": "deterministic",
|
|
3378
4113
|
"json-schema": "deterministic",
|
|
4114
|
+
"json-verify": "deterministic",
|
|
3379
4115
|
// A score against the author's threshold. They decide the row as they always have.
|
|
3380
4116
|
"semantic-similarity": "measure",
|
|
3381
4117
|
"llm-judge": "measure",
|
|
@@ -3499,6 +4235,13 @@ function rowStatus(row) {
|
|
|
3499
4235
|
if (row.error !== void 0) return "errored";
|
|
3500
4236
|
return row.assertions.every((a) => a.passed) ? "passed" : "failed";
|
|
3501
4237
|
}
|
|
4238
|
+
function stubbedEvals(run) {
|
|
4239
|
+
return run.evals.filter((ev) => ev.stubs !== void 0 || ev.rows.some((row) => row.stubbed === true)).map((ev) => ev.id);
|
|
4240
|
+
}
|
|
4241
|
+
function baseEvalId(ev) {
|
|
4242
|
+
const suffix = ev.provider === void 0 ? "" : `@${ev.provider.model}`;
|
|
4243
|
+
return suffix !== "" && ev.id.endsWith(suffix) ? ev.id.slice(0, -suffix.length) : ev.id;
|
|
4244
|
+
}
|
|
3502
4245
|
|
|
3503
4246
|
// src/orchestrator/agent.ts
|
|
3504
4247
|
init_cjs_shims();
|
|
@@ -3540,7 +4283,7 @@ var CAMEL = /[a-z0-9](?:Id|Ids|Uuid|Key|Slug|Number|Ref|Identifier)$/;
|
|
|
3540
4283
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3541
4284
|
var isIdKey = (key) => WHOLE.test(key) || SNAKE.test(key) || CAMEL.test(key);
|
|
3542
4285
|
var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3543
|
-
var
|
|
4286
|
+
var isScalar2 = (v) => typeof v === "string" && v !== "" || typeof v === "number" && Number.isFinite(v);
|
|
3544
4287
|
var EMAIL = /@/;
|
|
3545
4288
|
function segment(key) {
|
|
3546
4289
|
const plain = /^[A-Za-z_][\w-]*$/.test(key) && key.length <= 40 && !UUID.test(key) && !EMAIL.test(key);
|
|
@@ -3555,7 +4298,7 @@ function noteValue(out, v, at) {
|
|
|
3555
4298
|
where.add(at);
|
|
3556
4299
|
out.values.set(h, where);
|
|
3557
4300
|
}
|
|
3558
|
-
function
|
|
4301
|
+
function walk2(value, path11, depth, out) {
|
|
3559
4302
|
if (depth > SCAN_DEPTH) return;
|
|
3560
4303
|
if (typeof value === "string" && UUID.test(value)) {
|
|
3561
4304
|
const at = cap(path11 === "" ? "(root)" : path11);
|
|
@@ -3563,17 +4306,17 @@ function walk(value, path11, depth, out) {
|
|
|
3563
4306
|
noteValue(out, value, at);
|
|
3564
4307
|
}
|
|
3565
4308
|
if (Array.isArray(value)) {
|
|
3566
|
-
for (const item of value.slice(0, SCAN_ITEMS))
|
|
4309
|
+
for (const item of value.slice(0, SCAN_ITEMS)) walk2(item, `${path11}[]`, depth + 1, out);
|
|
3567
4310
|
return;
|
|
3568
4311
|
}
|
|
3569
4312
|
if (!isRecord3(value)) return;
|
|
3570
4313
|
for (const [key, v] of Object.entries(value)) {
|
|
3571
4314
|
const at = cap(path11 === "" ? segment(key) : `${path11}.${segment(key)}`);
|
|
3572
|
-
if (isIdKey(key) && (
|
|
4315
|
+
if (isIdKey(key) && (isScalar2(v) || Array.isArray(v) && v.length > 0 && v.every(isScalar2))) {
|
|
3573
4316
|
out.paths.add(at);
|
|
3574
4317
|
for (const x of Array.isArray(v) ? v : [v]) noteValue(out, x, at);
|
|
3575
4318
|
}
|
|
3576
|
-
|
|
4319
|
+
walk2(v, at, depth + 1, out);
|
|
3577
4320
|
}
|
|
3578
4321
|
}
|
|
3579
4322
|
function scanIds(result) {
|
|
@@ -3582,13 +4325,13 @@ function scanIds(result) {
|
|
|
3582
4325
|
if (isRecord3(result)) {
|
|
3583
4326
|
if (result.structuredContent !== void 0) {
|
|
3584
4327
|
readable = true;
|
|
3585
|
-
|
|
4328
|
+
walk2(result.structuredContent, "", 0, found);
|
|
3586
4329
|
}
|
|
3587
4330
|
if (Array.isArray(result.content))
|
|
3588
4331
|
for (const block of result.content) {
|
|
3589
4332
|
if (!isRecord3(block) || block.type !== "text" || typeof block.text !== "string") continue;
|
|
3590
4333
|
try {
|
|
3591
|
-
|
|
4334
|
+
walk2(JSON.parse(block.text), "", 0, found);
|
|
3592
4335
|
readable = true;
|
|
3593
4336
|
} catch {
|
|
3594
4337
|
}
|
|
@@ -3631,7 +4374,7 @@ function strip(value, depth, st) {
|
|
|
3631
4374
|
for (const [key, v] of Object.entries(value)) {
|
|
3632
4375
|
let name = redactUuids(key);
|
|
3633
4376
|
for (let n = 2; name !== key && Object.hasOwn(out, name); n++) name = `${ID_MARK}#${n}`;
|
|
3634
|
-
out[name] = isIdKey(key) && (
|
|
4377
|
+
out[name] = isIdKey(key) && (isScalar2(v) || Array.isArray(v) && v.length > 0 && v.every(isScalar2)) ? Array.isArray(v) ? v.map(() => ID_MARK) : ID_MARK : strip(v, depth + 1, st);
|
|
3635
4378
|
}
|
|
3636
4379
|
return out;
|
|
3637
4380
|
}
|
|
@@ -3869,8 +4612,8 @@ async function runAgentRow(p) {
|
|
|
3869
4612
|
);
|
|
3870
4613
|
for (const t of listed) {
|
|
3871
4614
|
const isOffered = offered.includes(t);
|
|
3872
|
-
const
|
|
3873
|
-
if (
|
|
4615
|
+
const known2 = transcript.tools.find((k) => k.name === t.name);
|
|
4616
|
+
if (known2 !== void 0) known2.offered ||= isOffered;
|
|
3874
4617
|
else
|
|
3875
4618
|
transcript.tools.push({
|
|
3876
4619
|
name: t.name,
|
|
@@ -4115,6 +4858,200 @@ async function runAgentRow(p) {
|
|
|
4115
4858
|
};
|
|
4116
4859
|
}
|
|
4117
4860
|
|
|
4861
|
+
// src/mock/schema.ts
|
|
4862
|
+
init_cjs_shims();
|
|
4863
|
+
var fs3 = __toESM(require("fs/promises"), 1);
|
|
4864
|
+
var import_node_http = require("http");
|
|
4865
|
+
var import_yaml2 = require("yaml");
|
|
4866
|
+
var import_zod3 = require("zod");
|
|
4867
|
+
var STUB_FILE_VERSION = 1;
|
|
4868
|
+
var sseChunkSchema = import_zod3.z.union([
|
|
4869
|
+
import_zod3.z.string(),
|
|
4870
|
+
import_zod3.z.strictObject({ event: import_zod3.z.string().min(1).optional(), data: import_zod3.z.unknown() })
|
|
4871
|
+
]);
|
|
4872
|
+
var responseSchema = import_zod3.z.strictObject({
|
|
4873
|
+
status: import_zod3.z.number().int().min(200).max(599).default(200),
|
|
4874
|
+
// Checked with the checks Node runs when it sends them, so a bad one fails here and not at a request.
|
|
4875
|
+
headers: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.string()).superRefine((headers, ctx) => {
|
|
4876
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
4877
|
+
const check3 = (what, validate) => {
|
|
4878
|
+
try {
|
|
4879
|
+
validate();
|
|
4880
|
+
} catch {
|
|
4881
|
+
ctx.addIssue({ code: "custom", message: `not a valid header ${what}`, path: [name] });
|
|
4882
|
+
}
|
|
4883
|
+
};
|
|
4884
|
+
check3("name", () => (0, import_node_http.validateHeaderName)(name));
|
|
4885
|
+
check3("value", () => (0, import_node_http.validateHeaderValue)(name, value));
|
|
4886
|
+
}
|
|
4887
|
+
}).default({}),
|
|
4888
|
+
json: import_zod3.z.unknown().optional(),
|
|
4889
|
+
text: import_zod3.z.string().optional(),
|
|
4890
|
+
sse: import_zod3.z.array(sseChunkSchema).optional()
|
|
4891
|
+
}).superRefine((r, ctx) => {
|
|
4892
|
+
const bodies = ["json", "text", "sse"].filter((k) => r[k] !== void 0);
|
|
4893
|
+
if (bodies.length > 1)
|
|
4894
|
+
ctx.addIssue({
|
|
4895
|
+
code: "custom",
|
|
4896
|
+
message: `give one body, not ${bodies.join(" and ")}`,
|
|
4897
|
+
path: [bodies[1]]
|
|
4898
|
+
});
|
|
4899
|
+
});
|
|
4900
|
+
var first = import_zod3.z.number().int().positive().optional();
|
|
4901
|
+
var failureSchema = import_zod3.z.discriminatedUnion("type", [
|
|
4902
|
+
// The request is read and never answered, until the client gives up or the scope closes.
|
|
4903
|
+
import_zod3.z.strictObject({ type: import_zod3.z.literal("timeout"), first }),
|
|
4904
|
+
// The connection is reset once the request is read; no response at all.
|
|
4905
|
+
import_zod3.z.strictObject({ type: import_zod3.z.literal("reset"), first }),
|
|
4906
|
+
import_zod3.z.strictObject({
|
|
4907
|
+
type: import_zod3.z.literal("http_429"),
|
|
4908
|
+
first,
|
|
4909
|
+
retry_after_seconds: import_zod3.z.number().int().min(0).default(1)
|
|
4910
|
+
}),
|
|
4911
|
+
import_zod3.z.strictObject({ type: import_zod3.z.literal("http_500"), first }),
|
|
4912
|
+
// The stub's `response`, complete and correct, at this many bytes per second: a whole number, 1 or more.
|
|
4913
|
+
import_zod3.z.strictObject({ type: import_zod3.z.literal("slow_stream"), first, bytes_per_sec: import_zod3.z.number().int().min(1) }),
|
|
4914
|
+
// The first half of the bytes of `response.json`. `full` declares the length of the whole body and closes
|
|
4915
|
+
// the connection after the half, as when a provider's connection drops: the client's read of the body
|
|
4916
|
+
// fails. `cut` declares the length of the half, as when something in between cut the body and re-framed
|
|
4917
|
+
// it: the response arrives whole and only parsing it fails.
|
|
4918
|
+
import_zod3.z.strictObject({
|
|
4919
|
+
type: import_zod3.z.literal("truncated_json"),
|
|
4920
|
+
first,
|
|
4921
|
+
content_length: import_zod3.z.enum(["full", "cut"]).default("full")
|
|
4922
|
+
})
|
|
4923
|
+
]);
|
|
4924
|
+
var stubSchema = import_zod3.z.strictObject({
|
|
4925
|
+
method: import_zod3.z.string().min(1).default("POST").transform((m) => m.toUpperCase()),
|
|
4926
|
+
// Exact, or with wildcards: `*` stands for any characters inside one path segment, `**` for anything,
|
|
4927
|
+
// slashes included. The query string takes no part in the match, so a path holds none.
|
|
4928
|
+
path: import_zod3.z.string().regex(/^\/[^?#\s]*$/, 'must start with "/" and hold no "?", "#" or whitespace'),
|
|
4929
|
+
// A JSON subset of the request body: every key given here must be in the request with a matching value,
|
|
4930
|
+
// other keys of the request are ignored. Arrays match whole: same length, each item by the same rule.
|
|
4931
|
+
body: import_zod3.z.unknown().optional(),
|
|
4932
|
+
// How `path` and `body` are compared. Left out, or `subset`: as said above. `exact`: the path is compared
|
|
4933
|
+
// as written, so `*` is a character, and `body` is the whole JSON body of the request, with the same
|
|
4934
|
+
// keys and values and nothing more; a stub without `body` then matches a request with no JSON body.
|
|
4935
|
+
// In an exact stub `[masked]` inside the path or a string of the body stands for any text, and a value
|
|
4936
|
+
// that is `[masked]` and nothing else for any value that is there. A recording is written this way.
|
|
4937
|
+
match: import_zod3.z.enum(["subset", "exact"]).optional(),
|
|
4938
|
+
// How many requests the stub answers, failures included; a used-up stub lets the next matching one
|
|
4939
|
+
// answer.
|
|
4940
|
+
times: import_zod3.z.union([import_zod3.z.literal("always"), import_zod3.z.literal("once"), import_zod3.z.number().int().positive()]).default("always"),
|
|
4941
|
+
response: responseSchema.optional(),
|
|
4942
|
+
failure: failureSchema.optional()
|
|
4943
|
+
}).superRefine((stub, ctx) => {
|
|
4944
|
+
const { response, failure } = stub;
|
|
4945
|
+
const need = (message, ...path11) => ctx.addIssue({ code: "custom", message, path: ["response", ...path11] });
|
|
4946
|
+
if (failure === void 0) {
|
|
4947
|
+
if (response === void 0) need("give a response or a failure");
|
|
4948
|
+
} else if (failure.type === "truncated_json") {
|
|
4949
|
+
if (response?.json === void 0) need("truncated_json cuts this body: give it", "json");
|
|
4950
|
+
} else if (response === void 0) {
|
|
4951
|
+
if (failure.type === "slow_stream") need("slow_stream sends this response slowly: give it");
|
|
4952
|
+
else if (failure.first !== void 0)
|
|
4953
|
+
need(`after the first ${failure.first} failed calls this response answers: give it`);
|
|
4954
|
+
} else if (failure.type !== "slow_stream" && failure.first === void 0) {
|
|
4955
|
+
need(
|
|
4956
|
+
`${failure.type} happens on every call, so this response is never sent: remove it or give failure.first`
|
|
4957
|
+
);
|
|
4958
|
+
}
|
|
4959
|
+
if (failure?.first !== void 0 && stub.times !== "always") {
|
|
4960
|
+
if ((stub.times === "once" ? 1 : stub.times) <= failure.first)
|
|
4961
|
+
ctx.addIssue({
|
|
4962
|
+
code: "custom",
|
|
4963
|
+
message: `the first ${failure.first} calls fail and count, so the response is never sent: give more than ${failure.first}, or leave it out`,
|
|
4964
|
+
path: ["times"]
|
|
4965
|
+
});
|
|
4966
|
+
}
|
|
4967
|
+
});
|
|
4968
|
+
var stubFileSchema = import_zod3.z.strictObject({
|
|
4969
|
+
version: import_zod3.z.literal(STUB_FILE_VERSION),
|
|
4970
|
+
stubs: import_zod3.z.array(stubSchema)
|
|
4971
|
+
});
|
|
4972
|
+
var StubFileError = class extends Error {
|
|
4973
|
+
code = "STUB_FILE_ERROR";
|
|
4974
|
+
/** One line per bad field, `path.to.field: what is wrong`. */
|
|
4975
|
+
issues;
|
|
4976
|
+
constructor(message, issues = []) {
|
|
4977
|
+
super(issues.length > 0 ? `${message}
|
|
4978
|
+
${issues.map((i) => ` ${i}`).join("\n")}` : message);
|
|
4979
|
+
this.name = "StubFileError";
|
|
4980
|
+
this.issues = issues;
|
|
4981
|
+
}
|
|
4982
|
+
};
|
|
4983
|
+
function formatIssues(error) {
|
|
4984
|
+
return error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`);
|
|
4985
|
+
}
|
|
4986
|
+
function parseStubFile(text, file = "stub file") {
|
|
4987
|
+
const doc = (0, import_yaml2.parseDocument)(text, { schema: "core", resolveKnownTags: false });
|
|
4988
|
+
const problem = doc.errors[0] ?? doc.warnings[0];
|
|
4989
|
+
if (problem !== void 0) {
|
|
4990
|
+
const at = problem.linePos?.[0];
|
|
4991
|
+
throw new StubFileError(
|
|
4992
|
+
`Cannot parse ${file}: ${problem.code}${at === void 0 ? "" : ` at line ${at.line}, column ${at.col}`}`
|
|
4993
|
+
);
|
|
4994
|
+
}
|
|
4995
|
+
let raw;
|
|
4996
|
+
try {
|
|
4997
|
+
raw = doc.toJS();
|
|
4998
|
+
JSON.stringify(raw, (_key, value) => {
|
|
4999
|
+
if (typeof value === "number" && !Number.isFinite(value)) throw new Error("not finite");
|
|
5000
|
+
return value;
|
|
5001
|
+
});
|
|
5002
|
+
} catch {
|
|
5003
|
+
throw new StubFileError(
|
|
5004
|
+
`Cannot parse ${file}: it holds a value JSON cannot (an alias that holds itself, or a number that is not finite)`
|
|
5005
|
+
);
|
|
5006
|
+
}
|
|
5007
|
+
const result = stubFileSchema.safeParse(raw);
|
|
5008
|
+
if (!result.success) throw new StubFileError(`Invalid ${file}`, formatIssues(result.error));
|
|
5009
|
+
return result.data;
|
|
5010
|
+
}
|
|
5011
|
+
|
|
5012
|
+
// src/orchestrator/stubs.ts
|
|
5013
|
+
init_cjs_shims();
|
|
5014
|
+
var STUB_NOT_CALLED = "STUB_NOT_CALLED";
|
|
5015
|
+
function viaStubs(inner, scope) {
|
|
5016
|
+
return {
|
|
5017
|
+
async complete(req) {
|
|
5018
|
+
const res = await inner.complete(req);
|
|
5019
|
+
if (scope.journal.length + scope.dropped === 0)
|
|
5020
|
+
throw new ProviderError(
|
|
5021
|
+
STUB_NOT_CALLED,
|
|
5022
|
+
"the answer did not come from the stub server: the provider of this run was not pointed at it, so the answer is dropped"
|
|
5023
|
+
);
|
|
5024
|
+
return res;
|
|
5025
|
+
},
|
|
5026
|
+
estimateCost: () => ({ cost_usd: 0, priced: true })
|
|
5027
|
+
};
|
|
5028
|
+
}
|
|
5029
|
+
var nothingSeen = (stubs) => ({
|
|
5030
|
+
never_called: stubs.map((_, i) => i),
|
|
5031
|
+
unmatched: []
|
|
5032
|
+
});
|
|
5033
|
+
function unusedPlaces(stubs, unused) {
|
|
5034
|
+
const places = /* @__PURE__ */ new Set();
|
|
5035
|
+
let u = unused.length - 1;
|
|
5036
|
+
for (let i = stubs.length - 1; i >= 0 && u >= 0; i -= 1) {
|
|
5037
|
+
if (JSON.stringify(stubs[i]) !== JSON.stringify(unused[u])) continue;
|
|
5038
|
+
places.add(i);
|
|
5039
|
+
u -= 1;
|
|
5040
|
+
}
|
|
5041
|
+
return places;
|
|
5042
|
+
}
|
|
5043
|
+
async function inStubScope(server, name, stubs, seen, fn) {
|
|
5044
|
+
const scope = server.scope(name, stubs);
|
|
5045
|
+
try {
|
|
5046
|
+
return await fn(scope);
|
|
5047
|
+
} finally {
|
|
5048
|
+
const unused = unusedPlaces(stubs, scope.close());
|
|
5049
|
+
seen.never_called = seen.never_called.filter((i) => unused.has(i));
|
|
5050
|
+
for (const entry of scope.journal)
|
|
5051
|
+
if (!entry.matched) seen.unmatched.push({ scope: name, method: entry.method });
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
5054
|
+
|
|
4118
5055
|
// src/orchestrator/run.ts
|
|
4119
5056
|
var DEFAULT_MAX_TOKENS3 = 1024;
|
|
4120
5057
|
var PLUNE_VERSION = "0.1.0";
|
|
@@ -4128,7 +5065,7 @@ var RunConfigError = class extends Error {
|
|
|
4128
5065
|
var CACHE_MISS_CODE = "CACHE_MISS";
|
|
4129
5066
|
function answerParses(output, assertions) {
|
|
4130
5067
|
return assertions.every(
|
|
4131
|
-
(a) => a.type !== "json-schema" || extractJson(output, a.extract ?? "auto").ok
|
|
5068
|
+
(a) => a.type !== "json-schema" && a.type !== "json-verify" || extractJson(output, a.extract ?? "auto").ok
|
|
4132
5069
|
);
|
|
4133
5070
|
}
|
|
4134
5071
|
function resolvePrompt(template, vars) {
|
|
@@ -4164,9 +5101,9 @@ async function assess(p, output, input, transcript) {
|
|
|
4164
5101
|
const advice = [];
|
|
4165
5102
|
let assertionError;
|
|
4166
5103
|
for (const assertion of p.assertions) {
|
|
4167
|
-
const
|
|
4168
|
-
const jev =
|
|
4169
|
-
const judgeCfg =
|
|
5104
|
+
const own3 = assertion.type === "llm-judge" ? assertion.provider : void 0;
|
|
5105
|
+
const jev = own3?.type === "jev" ? own3 : void 0;
|
|
5106
|
+
const judgeCfg = own3 === void 0 || own3.type === "jev" ? p.providerConfig : { ...p.providerConfig, ...own3 };
|
|
4170
5107
|
let judgedBy;
|
|
4171
5108
|
const judge = () => {
|
|
4172
5109
|
if (jev !== void 0) {
|
|
@@ -4184,8 +5121,8 @@ async function assess(p, output, input, transcript) {
|
|
|
4184
5121
|
}
|
|
4185
5122
|
};
|
|
4186
5123
|
}
|
|
4187
|
-
let provider = p.provider;
|
|
4188
|
-
if (
|
|
5124
|
+
let provider = p.judgeProvider ?? p.provider;
|
|
5125
|
+
if (own3 !== void 0) {
|
|
4189
5126
|
if (p.resolveJudge === void 0)
|
|
4190
5127
|
throw new Error("this run cannot build the judge named by the provider of an llm-judge check");
|
|
4191
5128
|
provider = p.resolveJudge(judgeCfg);
|
|
@@ -4437,13 +5374,53 @@ function resolveTemplate(ev, baseDir) {
|
|
|
4437
5374
|
if (ev.prompt !== void 0) return ev.prompt;
|
|
4438
5375
|
if (ev.prompt_file !== void 0) {
|
|
4439
5376
|
try {
|
|
4440
|
-
return
|
|
5377
|
+
return fs4.readFileSync(path3.resolve(baseDir, ev.prompt_file), "utf8");
|
|
4441
5378
|
} catch {
|
|
4442
5379
|
throw new RunConfigError(`Eval "${ev.id}": prompt_file not found: ${ev.prompt_file}`);
|
|
4443
5380
|
}
|
|
4444
5381
|
}
|
|
4445
5382
|
throw new RunConfigError(`Eval "${ev.id}" has neither prompt nor prompt_file`);
|
|
4446
5383
|
}
|
|
5384
|
+
var MAX_STUB_FILE_BYTES = 1024 * 1024;
|
|
5385
|
+
function resolveStubs(ev, deps, cacheStrict) {
|
|
5386
|
+
const file = ev.stubs;
|
|
5387
|
+
if (file === void 0) return void 0;
|
|
5388
|
+
const dir = path3.resolve(deps.baseDir);
|
|
5389
|
+
const full = path3.resolve(dir, file);
|
|
5390
|
+
const inside = path3.relative(dir, full);
|
|
5391
|
+
if (inside === "" || inside === ".." || inside.startsWith(`..${path3.sep}`) || path3.isAbsolute(inside))
|
|
5392
|
+
throw new RunConfigError(`Eval "${ev.id}": stubs must name a file inside the folder of the config: ${file}`);
|
|
5393
|
+
let text;
|
|
5394
|
+
try {
|
|
5395
|
+
const stat2 = fs4.statSync(full);
|
|
5396
|
+
if (stat2.isDirectory()) throw new RunConfigError(`Eval "${ev.id}": stubs is a folder, not a file: ${file}`);
|
|
5397
|
+
if (stat2.size > MAX_STUB_FILE_BYTES)
|
|
5398
|
+
throw new RunConfigError(`Eval "${ev.id}": stubs file is over 1 MiB: ${file}`);
|
|
5399
|
+
text = fs4.readFileSync(full, "utf8");
|
|
5400
|
+
} catch (err) {
|
|
5401
|
+
if (err instanceof RunConfigError) throw err;
|
|
5402
|
+
throw new RunConfigError(`Eval "${ev.id}": stubs file not found: ${file}`);
|
|
5403
|
+
}
|
|
5404
|
+
let stubs;
|
|
5405
|
+
try {
|
|
5406
|
+
({ stubs } = parseStubFile(text, file));
|
|
5407
|
+
} catch (err) {
|
|
5408
|
+
if (err instanceof StubFileError && err.issues.some((issue) => issue.startsWith("version:")))
|
|
5409
|
+
throw new RunConfigError(
|
|
5410
|
+
`Eval "${ev.id}": ${file} is not a stub file: a stub file has version: 1 at its top`
|
|
5411
|
+
);
|
|
5412
|
+
throw new RunConfigError(`Eval "${ev.id}": ${err.message}`);
|
|
5413
|
+
}
|
|
5414
|
+
if (cacheStrict)
|
|
5415
|
+
throw new RunConfigError(
|
|
5416
|
+
`Eval "${ev.id}" has stubs: a stubbed answer is never cached, so --cache-strict cannot answer it`
|
|
5417
|
+
);
|
|
5418
|
+
if (deps.stubServer === void 0)
|
|
5419
|
+
throw new RunConfigError(
|
|
5420
|
+
`Eval "${ev.id}" has stubs, and this run cannot start a stub server (PLUNE_MOCK_PROVIDER=1 answers every call itself and takes no stubs)`
|
|
5421
|
+
);
|
|
5422
|
+
return stubs;
|
|
5423
|
+
}
|
|
4447
5424
|
function summarize(evals, durationMs) {
|
|
4448
5425
|
const summary = {
|
|
4449
5426
|
total: 0,
|
|
@@ -4462,6 +5439,7 @@ function summarize(evals, durationMs) {
|
|
|
4462
5439
|
errored: 0,
|
|
4463
5440
|
saved: { input_tokens: 0, output_tokens: 0, cost_usd: 0 }
|
|
4464
5441
|
};
|
|
5442
|
+
let stubbed = 0;
|
|
4465
5443
|
for (const ev of evals) {
|
|
4466
5444
|
for (const row of ev.rows) {
|
|
4467
5445
|
summary.total += 1;
|
|
@@ -4470,13 +5448,14 @@ function summarize(evals, durationMs) {
|
|
|
4470
5448
|
cache.saved.input_tokens += row.cache_saved?.input_tokens ?? 0;
|
|
4471
5449
|
cache.saved.output_tokens += row.cache_saved?.output_tokens ?? 0;
|
|
4472
5450
|
cache.saved.cost_usd += row.cache_saved?.cost_usd ?? 0;
|
|
4473
|
-
if (row.
|
|
5451
|
+
if (row.stubbed === true) stubbed += 1;
|
|
5452
|
+
else if (row.cached) cache.from_cache += 1;
|
|
4474
5453
|
else if (row.error?.code === CACHE_MISS_CODE) cache.missed += 1;
|
|
4475
5454
|
else if (row.output !== null) cache.from_model += 1;
|
|
4476
5455
|
else if (row.error !== void 0) cache.errored += 1;
|
|
4477
5456
|
}
|
|
4478
5457
|
}
|
|
4479
|
-
return { ...summary, cache };
|
|
5458
|
+
return { ...summary, cache: stubbed > 0 ? { ...cache, stubbed } : cache };
|
|
4480
5459
|
}
|
|
4481
5460
|
function agenticProvider(ev, providerConfig, deps, cacheStrict) {
|
|
4482
5461
|
if (cacheStrict)
|
|
@@ -4512,22 +5491,28 @@ async function runOrchestration(config, options, deps) {
|
|
|
4512
5491
|
const models = config.providers ?? [config.provider];
|
|
4513
5492
|
const prepared = selectEvals(config.evals, options.only).map((ev) => {
|
|
4514
5493
|
const template = resolveTemplate(ev, deps.baseDir);
|
|
5494
|
+
const stubs = resolveStubs(ev, deps, cacheStrict);
|
|
4515
5495
|
const rows = deps.loadDataset(ev.dataset, deps.baseDir);
|
|
4516
5496
|
for (const row of rows) {
|
|
4517
5497
|
resolvePrompt(template, row.vars);
|
|
4518
5498
|
}
|
|
4519
5499
|
const cells = models.map((model) => {
|
|
4520
5500
|
const providerConfig = { ...model, ...ev.provider };
|
|
5501
|
+
const hangs = stubs?.findIndex((stub) => stub.failure?.type === "timeout") ?? -1;
|
|
5502
|
+
if (hangs !== -1 && providerConfig.timeout === void 0)
|
|
5503
|
+
throw new RunConfigError(
|
|
5504
|
+
`Eval "${ev.id}": stubs.${hangs} of ${ev.stubs} is a timeout failure and the provider of the eval sets no timeout, so each attempt would wait as long as the provider SDK does by default (minutes): set provider.timeout, in milliseconds, at the root or on the eval`
|
|
5505
|
+
);
|
|
4521
5506
|
const agentic = ev.mcp === void 0 || dryRun ? void 0 : agenticProvider(ev, providerConfig, deps, cacheStrict);
|
|
4522
5507
|
return { providerConfig, agentic };
|
|
4523
5508
|
});
|
|
4524
|
-
return { ev, template, rows, cells };
|
|
5509
|
+
return { ev, template, rows, cells, stubs };
|
|
4525
5510
|
});
|
|
4526
5511
|
const judges = /* @__PURE__ */ new Map();
|
|
4527
5512
|
const resolveJudge = (cfg) => {
|
|
4528
5513
|
const key = canonicalJson(cfg);
|
|
4529
|
-
const
|
|
4530
|
-
if (
|
|
5514
|
+
const known2 = judges.get(key);
|
|
5515
|
+
if (known2 !== void 0) return known2;
|
|
4531
5516
|
const made = deps.resolveProvider(cfg);
|
|
4532
5517
|
judges.set(key, made);
|
|
4533
5518
|
return made;
|
|
@@ -4537,14 +5522,15 @@ async function runOrchestration(config, options, deps) {
|
|
|
4537
5522
|
throw new RunConfigError(
|
|
4538
5523
|
"--tool-description needs an eval with mcp in this run: no tool is offered otherwise"
|
|
4539
5524
|
);
|
|
4540
|
-
cellLoop: for (const { ev, template, rows, cells } of prepared) {
|
|
5525
|
+
cellLoop: for (const { ev, template, rows, cells, stubs } of prepared) {
|
|
4541
5526
|
for (const { providerConfig, agentic } of cells) {
|
|
4542
5527
|
const provider = agentic ?? deps.resolveProvider(providerConfig);
|
|
5528
|
+
const seen = stubs === void 0 || dryRun ? void 0 : nothingSeen(stubs);
|
|
4543
5529
|
const limit2 = options.concurrency ?? providerConfig.concurrency ?? (ev.mcp !== void 0 ? 1 : 4);
|
|
4544
5530
|
const runs = options.runs ?? ev.runs ?? config.runs ?? 1;
|
|
4545
5531
|
const passThreshold = ev.pass_threshold ?? config.pass_threshold ?? 1;
|
|
4546
5532
|
const assertions = [...config.defaults?.assertions ?? [], ...ev.assertions];
|
|
4547
|
-
const rowResults = await mapLimit(rows, limit2, (row) => {
|
|
5533
|
+
const rowResults = await mapLimit(rows, limit2, (row, rowIndex) => {
|
|
4548
5534
|
const params = {
|
|
4549
5535
|
template,
|
|
4550
5536
|
assertions,
|
|
@@ -4562,6 +5548,25 @@ async function runOrchestration(config, options, deps) {
|
|
|
4562
5548
|
cacheStrict,
|
|
4563
5549
|
...options.cacheMaxAgeMs !== void 0 ? { cacheMaxAgeMs: options.cacheMaxAgeMs } : {}
|
|
4564
5550
|
};
|
|
5551
|
+
if (stubs !== void 0 && seen !== void 0) {
|
|
5552
|
+
return runRepeats(
|
|
5553
|
+
params,
|
|
5554
|
+
runs,
|
|
5555
|
+
passThreshold,
|
|
5556
|
+
async (p) => inStubScope(
|
|
5557
|
+
await deps.stubServer(),
|
|
5558
|
+
`${ev.id}.row${rowIndex + 1}${p.attempt === void 0 ? "" : `.run${p.attempt + 1}`}`,
|
|
5559
|
+
stubs,
|
|
5560
|
+
seen,
|
|
5561
|
+
(scope) => runRow({
|
|
5562
|
+
...p,
|
|
5563
|
+
provider: viaStubs(deps.resolveProvider(providerConfig, scope.url), scope),
|
|
5564
|
+
judgeProvider: p.provider,
|
|
5565
|
+
noCache: true
|
|
5566
|
+
})
|
|
5567
|
+
)
|
|
5568
|
+
).then((result) => ({ ...result, stubbed: true }));
|
|
5569
|
+
}
|
|
4565
5570
|
if (ev.mcp === void 0) return runRepeats(params, runs, passThreshold);
|
|
4566
5571
|
const agentParams = {
|
|
4567
5572
|
...params,
|
|
@@ -4588,7 +5593,8 @@ async function runOrchestration(config, options, deps) {
|
|
|
4588
5593
|
rows: rowResults,
|
|
4589
5594
|
passed,
|
|
4590
5595
|
measured,
|
|
4591
|
-
...models.length > 1 ? { provider: { type: providerConfig.type, model: providerConfig.model } } : {}
|
|
5596
|
+
...models.length > 1 ? { provider: { type: providerConfig.type, model: providerConfig.model } } : {},
|
|
5597
|
+
...seen !== void 0 ? { stubs: seen } : {}
|
|
4592
5598
|
});
|
|
4593
5599
|
if (options.bail === true && !dryRun && !passed) break cellLoop;
|
|
4594
5600
|
}
|
|
@@ -4613,7 +5619,7 @@ init_cjs_shims();
|
|
|
4613
5619
|
|
|
4614
5620
|
// src/orchestrator/dataset.ts
|
|
4615
5621
|
init_cjs_shims();
|
|
4616
|
-
var
|
|
5622
|
+
var fs5 = __toESM(require("fs"), 1);
|
|
4617
5623
|
var path4 = __toESM(require("path"), 1);
|
|
4618
5624
|
function loadDataset(ref5, baseDir) {
|
|
4619
5625
|
if (typeof ref5 !== "string") {
|
|
@@ -4622,7 +5628,7 @@ function loadDataset(ref5, baseDir) {
|
|
|
4622
5628
|
const file = path4.resolve(baseDir, ref5);
|
|
4623
5629
|
let content;
|
|
4624
5630
|
try {
|
|
4625
|
-
content =
|
|
5631
|
+
content = fs5.readFileSync(file, "utf8");
|
|
4626
5632
|
} catch (err) {
|
|
4627
5633
|
throw new RunConfigError(
|
|
4628
5634
|
err.code === "ENOENT" ? `${ref5}: dataset file not found (looked for ${file})` : `${ref5}: cannot read the dataset file (${err.message})`
|
|
@@ -4637,9 +5643,9 @@ function loadDataset(ref5, baseDir) {
|
|
|
4637
5643
|
} catch (err) {
|
|
4638
5644
|
throw new RunConfigError(`${ref5}:${i + 1}: not valid JSON (${err.message})`);
|
|
4639
5645
|
}
|
|
4640
|
-
const vars =
|
|
4641
|
-
if (!
|
|
4642
|
-
const why =
|
|
5646
|
+
const vars = isObject3(row) ? row["vars"] : void 0;
|
|
5647
|
+
if (!isObject3(vars)) {
|
|
5648
|
+
const why = isObject3(row) && "vars" in row ? `vars: Invalid input: expected record, received ${typeName(vars)}` : 'this row has no "vars"';
|
|
4643
5649
|
throw new RunConfigError(
|
|
4644
5650
|
`${ref5}:${i + 1}: a dataset row must be { "vars": { ... } }; ${why}`
|
|
4645
5651
|
);
|
|
@@ -4648,7 +5654,7 @@ function loadDataset(ref5, baseDir) {
|
|
|
4648
5654
|
});
|
|
4649
5655
|
return rows;
|
|
4650
5656
|
}
|
|
4651
|
-
function
|
|
5657
|
+
function isObject3(value) {
|
|
4652
5658
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4653
5659
|
}
|
|
4654
5660
|
function typeName(value) {
|
|
@@ -4677,8 +5683,8 @@ Criterion:
|
|
|
4677
5683
|
${q.criteria}`;
|
|
4678
5684
|
}
|
|
4679
5685
|
function jevBaseUrl(env) {
|
|
4680
|
-
const
|
|
4681
|
-
const [name, value] =
|
|
5686
|
+
const own3 = env[JEV_BASE_URL_ENV];
|
|
5687
|
+
const [name, value] = own3 !== void 0 && own3 !== "" ? [JEV_BASE_URL_ENV, own3] : ["TYPESAFE_BASE_URL", env["TYPESAFE_BASE_URL"]];
|
|
4682
5688
|
if (value === void 0 || value === "") return JEV_BASE_URL;
|
|
4683
5689
|
let url;
|
|
4684
5690
|
try {
|
|
@@ -4762,6 +5768,416 @@ function warnJevExperimental(write = (l) => process.stderr.write(l)) {
|
|
|
4762
5768
|
);
|
|
4763
5769
|
}
|
|
4764
5770
|
|
|
5771
|
+
// src/mock/server.ts
|
|
5772
|
+
init_cjs_shims();
|
|
5773
|
+
var http = __toESM(require("http"), 1);
|
|
5774
|
+
var JOURNAL_MAX_ENTRIES = 1e3;
|
|
5775
|
+
var MAX_CONNECTIONS = 256;
|
|
5776
|
+
var REAL_TIMERS = {
|
|
5777
|
+
now: () => performance.now(),
|
|
5778
|
+
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
|
5779
|
+
clearTimeout: (handle) => clearTimeout(handle)
|
|
5780
|
+
};
|
|
5781
|
+
var SLOW_STREAM_STEP_MS = 50;
|
|
5782
|
+
var MASK = "[masked]";
|
|
5783
|
+
var SECRET_NAME = /auth|key|token|secret|cookie|password|passwd|pwd|credential|sig|jwt|session|csrf|otp|code|assertion/i;
|
|
5784
|
+
var SCOPE_NAME = /^(?!\.{1,2}$)[A-Za-z0-9._-]+$/;
|
|
5785
|
+
var DOT_SEGMENT = /^(\.|%2e){1,2}$/i;
|
|
5786
|
+
var MAX_BODY_BYTES = 16 * 1024 * 1024;
|
|
5787
|
+
function pathMatcher(pattern) {
|
|
5788
|
+
const tokens = pattern.match(/\*\*|[^]/g) ?? [];
|
|
5789
|
+
const n = tokens.length;
|
|
5790
|
+
const skipWildcards = (at) => {
|
|
5791
|
+
for (let i = 0; i < n; i += 1)
|
|
5792
|
+
if (at[i] && (tokens[i] === "*" || tokens[i] === "**")) at[i + 1] = 1;
|
|
5793
|
+
};
|
|
5794
|
+
return (path11) => {
|
|
5795
|
+
let at = new Uint8Array(n + 1);
|
|
5796
|
+
at[0] = 1;
|
|
5797
|
+
skipWildcards(at);
|
|
5798
|
+
for (let c = 0; c < path11.length; c += 1) {
|
|
5799
|
+
const ch = path11[c];
|
|
5800
|
+
const next = new Uint8Array(n + 1);
|
|
5801
|
+
for (let i = 0; i < n; i += 1) {
|
|
5802
|
+
if (!at[i]) continue;
|
|
5803
|
+
const token = tokens[i];
|
|
5804
|
+
if (token === "**" || token === "*" && ch !== "/") next[i] = 1;
|
|
5805
|
+
else if (token !== "*" && token === ch) next[i + 1] = 1;
|
|
5806
|
+
}
|
|
5807
|
+
skipWildcards(next);
|
|
5808
|
+
at = next;
|
|
5809
|
+
}
|
|
5810
|
+
return at[n] === 1;
|
|
5811
|
+
};
|
|
5812
|
+
}
|
|
5813
|
+
function matchesSubset(expected, actual) {
|
|
5814
|
+
if (Array.isArray(expected))
|
|
5815
|
+
return Array.isArray(actual) && actual.length === expected.length && expected.every((item, i) => matchesSubset(item, actual[i]));
|
|
5816
|
+
if (expected !== null && typeof expected === "object")
|
|
5817
|
+
return actual !== null && typeof actual === "object" && !Array.isArray(actual) && Object.entries(expected).every(
|
|
5818
|
+
([k, v]) => Object.hasOwn(actual, k) && matchesSubset(v, actual[k])
|
|
5819
|
+
);
|
|
5820
|
+
return expected === actual;
|
|
5821
|
+
}
|
|
5822
|
+
function maskedTextMatches(expected, actual) {
|
|
5823
|
+
const parts = expected.split(MASK);
|
|
5824
|
+
const first2 = parts[0];
|
|
5825
|
+
const last = parts[parts.length - 1];
|
|
5826
|
+
if (parts.length === 1) return expected === actual;
|
|
5827
|
+
if (actual.length < first2.length + last.length) return false;
|
|
5828
|
+
if (!actual.startsWith(first2) || !actual.endsWith(last)) return false;
|
|
5829
|
+
const end = actual.length - last.length;
|
|
5830
|
+
let at = first2.length;
|
|
5831
|
+
for (const part of parts.slice(1, -1)) {
|
|
5832
|
+
const found = actual.indexOf(part, at);
|
|
5833
|
+
if (found === -1 || found + part.length > end) return false;
|
|
5834
|
+
at = found + part.length;
|
|
5835
|
+
}
|
|
5836
|
+
return true;
|
|
5837
|
+
}
|
|
5838
|
+
function matchesExact(expected, actual) {
|
|
5839
|
+
if (expected === MASK) return actual !== void 0;
|
|
5840
|
+
if (typeof expected === "string")
|
|
5841
|
+
return typeof actual === "string" && maskedTextMatches(expected, actual);
|
|
5842
|
+
if (Array.isArray(expected))
|
|
5843
|
+
return Array.isArray(actual) && actual.length === expected.length && expected.every((item, i) => matchesExact(item, actual[i]));
|
|
5844
|
+
if (expected !== null && typeof expected === "object")
|
|
5845
|
+
return actual !== null && typeof actual === "object" && !Array.isArray(actual) && Object.keys(actual).length === Object.keys(expected).length && Object.entries(expected).every(
|
|
5846
|
+
([k, v]) => Object.hasOwn(actual, k) && matchesExact(v, actual[k])
|
|
5847
|
+
);
|
|
5848
|
+
return expected === actual;
|
|
5849
|
+
}
|
|
5850
|
+
function notLocal(req, port, bound = "127.0.0.1") {
|
|
5851
|
+
const names = ["127.0.0.1", "localhost", "[::1]", bound.includes(":") ? `[${bound}]` : bound];
|
|
5852
|
+
const hosts = names.flatMap((name) => port === 80 ? [name, `${name}:80`] : [`${name}:${port}`]);
|
|
5853
|
+
const host = (req.headers.host ?? "").toLowerCase();
|
|
5854
|
+
const { origin } = req.headers;
|
|
5855
|
+
return !hosts.includes(host) || origin !== void 0 && !hosts.some((h) => origin.toLowerCase() === `http://${h}`);
|
|
5856
|
+
}
|
|
5857
|
+
var NOT_LOCAL_MESSAGE = "This server answers only a request addressed to 127.0.0.1, localhost or [::1] with its own port, and none a web page of another origin sent";
|
|
5858
|
+
function maskedHeaders(headers) {
|
|
5859
|
+
const out = {};
|
|
5860
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
5861
|
+
if (value === void 0) continue;
|
|
5862
|
+
out[name] = SECRET_NAME.test(name) ? MASK : Array.isArray(value) ? value.join(", ") : value;
|
|
5863
|
+
}
|
|
5864
|
+
return out;
|
|
5865
|
+
}
|
|
5866
|
+
function maskedQuery(params) {
|
|
5867
|
+
return [...params].map(
|
|
5868
|
+
([k, v]) => `${encodeURIComponent(k)}=${SECRET_NAME.test(k) ? MASK : encodeURIComponent(v)}`
|
|
5869
|
+
).join("&");
|
|
5870
|
+
}
|
|
5871
|
+
function renderBody(response) {
|
|
5872
|
+
if (response.sse !== void 0) {
|
|
5873
|
+
const events = response.sse.map((chunk2) => {
|
|
5874
|
+
const { event, data } = typeof chunk2 === "string" ? { event: void 0, data: chunk2 } : chunk2;
|
|
5875
|
+
const line = typeof data === "string" ? data : JSON.stringify(data);
|
|
5876
|
+
return `${event === void 0 ? "" : `event: ${event}
|
|
5877
|
+
`}data: ${line}
|
|
5878
|
+
|
|
5879
|
+
`;
|
|
5880
|
+
});
|
|
5881
|
+
return { type: "text/event-stream", body: Buffer.from(events.join("")) };
|
|
5882
|
+
}
|
|
5883
|
+
if (response.text !== void 0)
|
|
5884
|
+
return { type: "text/plain; charset=utf-8", body: Buffer.from(response.text) };
|
|
5885
|
+
if (response.json !== void 0)
|
|
5886
|
+
return { type: "application/json", body: Buffer.from(JSON.stringify(response.json)) };
|
|
5887
|
+
return { body: Buffer.alloc(0) };
|
|
5888
|
+
}
|
|
5889
|
+
function responseHeaders(response, type, length) {
|
|
5890
|
+
const headers = {};
|
|
5891
|
+
if (type !== void 0) headers["content-type"] = type;
|
|
5892
|
+
if (response.sse === void 0) headers["content-length"] = length;
|
|
5893
|
+
else headers["cache-control"] = "no-cache";
|
|
5894
|
+
for (const [name, value] of Object.entries(response.headers)) headers[name.toLowerCase()] = value;
|
|
5895
|
+
return headers;
|
|
5896
|
+
}
|
|
5897
|
+
function sendJson(res, status, body, headers = {}) {
|
|
5898
|
+
const text = JSON.stringify(body);
|
|
5899
|
+
res.writeHead(status, {
|
|
5900
|
+
"content-type": "application/json",
|
|
5901
|
+
"content-length": Buffer.byteLength(text),
|
|
5902
|
+
...headers
|
|
5903
|
+
});
|
|
5904
|
+
res.end(text);
|
|
5905
|
+
}
|
|
5906
|
+
var providerError = (type, code, message) => ({
|
|
5907
|
+
type: "error",
|
|
5908
|
+
error: { type, code, message }
|
|
5909
|
+
});
|
|
5910
|
+
function writeSlowly(res, body, bytesPerSec, timers) {
|
|
5911
|
+
const startedAt = timers.now();
|
|
5912
|
+
const step = Math.max(1, Math.round(bytesPerSec * SLOW_STREAM_STEP_MS / 1e3));
|
|
5913
|
+
let sent = 0;
|
|
5914
|
+
let handle;
|
|
5915
|
+
const tick = () => {
|
|
5916
|
+
const due = Math.min(
|
|
5917
|
+
body.length,
|
|
5918
|
+
Math.floor((timers.now() - startedAt) * bytesPerSec / 1e3)
|
|
5919
|
+
);
|
|
5920
|
+
if (due > sent) {
|
|
5921
|
+
res.write(body.subarray(sent, due));
|
|
5922
|
+
sent = due;
|
|
5923
|
+
}
|
|
5924
|
+
if (sent >= body.length) {
|
|
5925
|
+
res.end();
|
|
5926
|
+
return;
|
|
5927
|
+
}
|
|
5928
|
+
const nextAt = startedAt + Math.min(body.length, sent + step) * 1e3 / bytesPerSec;
|
|
5929
|
+
handle = timers.setTimeout(tick, Math.max(1, Math.ceil(nextAt - timers.now())));
|
|
5930
|
+
};
|
|
5931
|
+
tick();
|
|
5932
|
+
return () => timers.clearTimeout(handle);
|
|
5933
|
+
}
|
|
5934
|
+
async function start(options = {}) {
|
|
5935
|
+
const host = options.host ?? "127.0.0.1";
|
|
5936
|
+
const journalBodyCap = options.journalBodyCap ?? 64 * 1024;
|
|
5937
|
+
const timers = options.timers ?? REAL_TIMERS;
|
|
5938
|
+
const scopes = /* @__PURE__ */ new Map();
|
|
5939
|
+
const unrouted = [];
|
|
5940
|
+
let unroutedDropped = 0;
|
|
5941
|
+
let closing;
|
|
5942
|
+
const record = (journal, entry) => {
|
|
5943
|
+
journal.push(entry);
|
|
5944
|
+
if (journal.length <= JOURNAL_MAX_ENTRIES) return 0;
|
|
5945
|
+
journal.shift();
|
|
5946
|
+
return 1;
|
|
5947
|
+
};
|
|
5948
|
+
function answer(req, res, body) {
|
|
5949
|
+
const target = req.url ?? "";
|
|
5950
|
+
const queryAt = target.indexOf("?");
|
|
5951
|
+
const rawPath = queryAt === -1 ? target : target.slice(0, queryAt);
|
|
5952
|
+
const segments = rawPath.split("/");
|
|
5953
|
+
const badTarget = segments[0] !== "" || segments.length < 2 || segments[1] === "" && segments.length > 2 || segments.some((segment2) => DOT_SEGMENT.test(segment2));
|
|
5954
|
+
const name = badTarget ? "" : segments[1];
|
|
5955
|
+
const method = req.method ?? "GET";
|
|
5956
|
+
const path11 = badTarget ? rawPath : rawPath.slice(name.length + 1) || "/";
|
|
5957
|
+
const entry = {
|
|
5958
|
+
scope: name,
|
|
5959
|
+
method,
|
|
5960
|
+
path: path11,
|
|
5961
|
+
query: maskedQuery(new URLSearchParams(queryAt === -1 ? "" : target.slice(queryAt + 1))),
|
|
5962
|
+
headers: maskedHeaders(req.headers),
|
|
5963
|
+
body: body.subarray(0, journalBodyCap).toString("utf8"),
|
|
5964
|
+
bodyTruncated: body.length > journalBodyCap,
|
|
5965
|
+
matched: false
|
|
5966
|
+
};
|
|
5967
|
+
const refuse = (status, type, message, open2) => sendJson(res, status, {
|
|
5968
|
+
error: { type, message, method, ...open2 === void 0 ? {} : { scope: open2 } }
|
|
5969
|
+
});
|
|
5970
|
+
const scope = badTarget ? void 0 : scopes.get(name);
|
|
5971
|
+
if (scope === void 0) {
|
|
5972
|
+
unroutedDropped += record(unrouted, entry);
|
|
5973
|
+
if (badTarget)
|
|
5974
|
+
refuse(
|
|
5975
|
+
400,
|
|
5976
|
+
"mock_bad_target",
|
|
5977
|
+
'Bad request target: it starts with "/<scope>" and holds no "." or ".." segment'
|
|
5978
|
+
);
|
|
5979
|
+
else
|
|
5980
|
+
refuse(
|
|
5981
|
+
404,
|
|
5982
|
+
"mock_no_stub",
|
|
5983
|
+
`No open scope for this ${method} request: the first path segment names the scope`
|
|
5984
|
+
);
|
|
5985
|
+
return;
|
|
5986
|
+
}
|
|
5987
|
+
scope.dropped += record(scope.journal, entry);
|
|
5988
|
+
let json;
|
|
5989
|
+
let parsed2 = false;
|
|
5990
|
+
const live = scope.stubs.find(({ stub, matches, calls }) => {
|
|
5991
|
+
if (stub.times !== "always" && calls >= (stub.times === "once" ? 1 : stub.times))
|
|
5992
|
+
return false;
|
|
5993
|
+
if (stub.method !== method || !matches(path11)) return false;
|
|
5994
|
+
const exact = stub.match === "exact";
|
|
5995
|
+
if (stub.body === void 0 && !exact) return true;
|
|
5996
|
+
if (!parsed2) {
|
|
5997
|
+
parsed2 = true;
|
|
5998
|
+
try {
|
|
5999
|
+
json = JSON.parse(body.toString("utf8"));
|
|
6000
|
+
} catch {
|
|
6001
|
+
json = void 0;
|
|
6002
|
+
}
|
|
6003
|
+
}
|
|
6004
|
+
if (!exact) return matchesSubset(stub.body, json);
|
|
6005
|
+
return stub.body === void 0 ? json === void 0 : matchesExact(stub.body, json);
|
|
6006
|
+
});
|
|
6007
|
+
if (live === void 0) {
|
|
6008
|
+
refuse(
|
|
6009
|
+
404,
|
|
6010
|
+
"mock_no_stub",
|
|
6011
|
+
`No stub matches this ${method} request in scope "${name}": compare its path and body in the journal of the scope with the stubs`,
|
|
6012
|
+
name
|
|
6013
|
+
);
|
|
6014
|
+
return;
|
|
6015
|
+
}
|
|
6016
|
+
entry.matched = true;
|
|
6017
|
+
live.calls += 1;
|
|
6018
|
+
const response = live.stub.response ?? { status: 200, headers: {} };
|
|
6019
|
+
const rendered = renderBody(response);
|
|
6020
|
+
const head = (length) => {
|
|
6021
|
+
res.writeHead(response.status, responseHeaders(response, rendered.type, length));
|
|
6022
|
+
};
|
|
6023
|
+
const { failure } = live.stub;
|
|
6024
|
+
if (failure === void 0 || failure.first !== void 0 && live.calls > failure.first) {
|
|
6025
|
+
head(rendered.body.length);
|
|
6026
|
+
res.end(rendered.body);
|
|
6027
|
+
return;
|
|
6028
|
+
}
|
|
6029
|
+
const hold = (stop = () => void 0) => {
|
|
6030
|
+
const abort = () => {
|
|
6031
|
+
stop();
|
|
6032
|
+
res.destroy();
|
|
6033
|
+
};
|
|
6034
|
+
scope.held.add(abort);
|
|
6035
|
+
res.on("close", () => {
|
|
6036
|
+
stop();
|
|
6037
|
+
scope.held.delete(abort);
|
|
6038
|
+
});
|
|
6039
|
+
};
|
|
6040
|
+
switch (failure.type) {
|
|
6041
|
+
case "timeout":
|
|
6042
|
+
hold();
|
|
6043
|
+
return;
|
|
6044
|
+
case "reset":
|
|
6045
|
+
req.socket.resetAndDestroy();
|
|
6046
|
+
return;
|
|
6047
|
+
case "http_429":
|
|
6048
|
+
sendJson(
|
|
6049
|
+
res,
|
|
6050
|
+
429,
|
|
6051
|
+
providerError("rate_limit_error", "rate_limit_exceeded", "Rate limit exceeded (stub)"),
|
|
6052
|
+
{ "retry-after": String(failure.retry_after_seconds) }
|
|
6053
|
+
);
|
|
6054
|
+
return;
|
|
6055
|
+
case "http_500":
|
|
6056
|
+
sendJson(
|
|
6057
|
+
res,
|
|
6058
|
+
500,
|
|
6059
|
+
providerError("api_error", "internal_error", "Internal server error (stub)")
|
|
6060
|
+
);
|
|
6061
|
+
return;
|
|
6062
|
+
case "slow_stream":
|
|
6063
|
+
head(rendered.body.length);
|
|
6064
|
+
res.flushHeaders();
|
|
6065
|
+
hold(writeSlowly(res, rendered.body, failure.bytes_per_sec, timers));
|
|
6066
|
+
return;
|
|
6067
|
+
case "truncated_json": {
|
|
6068
|
+
const cut = rendered.body.subarray(0, Math.floor(rendered.body.length / 2));
|
|
6069
|
+
if (failure.content_length === "cut") {
|
|
6070
|
+
head(cut.length);
|
|
6071
|
+
res.end(cut);
|
|
6072
|
+
} else {
|
|
6073
|
+
head(rendered.body.length);
|
|
6074
|
+
res.write(cut, () => res.destroy());
|
|
6075
|
+
}
|
|
6076
|
+
return;
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
}
|
|
6080
|
+
let port = 0;
|
|
6081
|
+
const server = http.createServer((req, res) => {
|
|
6082
|
+
if (notLocal(req, port, host)) {
|
|
6083
|
+
req.resume();
|
|
6084
|
+
sendJson(res, 403, { error: { type: "mock_not_local", message: NOT_LOCAL_MESSAGE } });
|
|
6085
|
+
return;
|
|
6086
|
+
}
|
|
6087
|
+
const chunks = [];
|
|
6088
|
+
let size = 0;
|
|
6089
|
+
req.on("error", () => void 0);
|
|
6090
|
+
req.on("data", (chunk2) => {
|
|
6091
|
+
size += chunk2.length;
|
|
6092
|
+
if (size <= MAX_BODY_BYTES) chunks.push(chunk2);
|
|
6093
|
+
else chunks.length = 0;
|
|
6094
|
+
});
|
|
6095
|
+
req.on("end", () => {
|
|
6096
|
+
if (size > MAX_BODY_BYTES) {
|
|
6097
|
+
sendJson(res, 413, {
|
|
6098
|
+
error: { type: "mock_body_too_large", message: "Request body over 16 MiB" }
|
|
6099
|
+
});
|
|
6100
|
+
return;
|
|
6101
|
+
}
|
|
6102
|
+
try {
|
|
6103
|
+
answer(req, res, Buffer.concat(chunks));
|
|
6104
|
+
} catch {
|
|
6105
|
+
if (res.headersSent) res.destroy();
|
|
6106
|
+
else
|
|
6107
|
+
sendJson(res, 500, {
|
|
6108
|
+
error: { type: "mock_internal", message: "The stub server failed on this request" }
|
|
6109
|
+
});
|
|
6110
|
+
}
|
|
6111
|
+
});
|
|
6112
|
+
});
|
|
6113
|
+
server.maxConnections = MAX_CONNECTIONS;
|
|
6114
|
+
await new Promise((resolve9, reject) => {
|
|
6115
|
+
server.once("error", reject);
|
|
6116
|
+
server.listen(options.port ?? 0, host, () => {
|
|
6117
|
+
server.off("error", reject);
|
|
6118
|
+
resolve9();
|
|
6119
|
+
});
|
|
6120
|
+
});
|
|
6121
|
+
({ port } = server.address());
|
|
6122
|
+
const url = `http://${host.includes(":") ? `[${host}]` : host}:${port}`;
|
|
6123
|
+
return {
|
|
6124
|
+
url,
|
|
6125
|
+
port,
|
|
6126
|
+
unrouted,
|
|
6127
|
+
get unroutedDropped() {
|
|
6128
|
+
return unroutedDropped;
|
|
6129
|
+
},
|
|
6130
|
+
scope(name, stubs = []) {
|
|
6131
|
+
if (closing !== void 0) throw new Error("The server is closed: it takes no new scope");
|
|
6132
|
+
if (!SCOPE_NAME.test(name))
|
|
6133
|
+
throw new Error(
|
|
6134
|
+
`Bad scope name "${name}": letters, digits, ".", "_" and "-" only, and not "." or ".."`
|
|
6135
|
+
);
|
|
6136
|
+
if (scopes.has(name)) throw new Error(`Scope "${name}" is already open`);
|
|
6137
|
+
const state = { stubs: [], journal: [], dropped: 0, held: /* @__PURE__ */ new Set() };
|
|
6138
|
+
scopes.set(name, state);
|
|
6139
|
+
const scope = {
|
|
6140
|
+
name,
|
|
6141
|
+
url: `${url}/${name}`,
|
|
6142
|
+
journal: state.journal,
|
|
6143
|
+
get dropped() {
|
|
6144
|
+
return state.dropped;
|
|
6145
|
+
},
|
|
6146
|
+
add(...inputs) {
|
|
6147
|
+
for (const input of inputs) {
|
|
6148
|
+
const result = stubSchema.safeParse(input);
|
|
6149
|
+
if (!result.success)
|
|
6150
|
+
throw new Error(`Invalid stub: ${formatIssues(result.error).join("; ")}`);
|
|
6151
|
+
state.stubs.push({
|
|
6152
|
+
stub: result.data,
|
|
6153
|
+
matches: result.data.match === "exact" ? (path11) => maskedTextMatches(result.data.path, path11) : pathMatcher(result.data.path),
|
|
6154
|
+
calls: 0
|
|
6155
|
+
});
|
|
6156
|
+
}
|
|
6157
|
+
},
|
|
6158
|
+
close() {
|
|
6159
|
+
if (scopes.get(name) === state) scopes.delete(name);
|
|
6160
|
+
const unused = state.stubs.filter((s) => s.calls === 0).map((s) => s.stub);
|
|
6161
|
+
state.stubs = [];
|
|
6162
|
+
for (const abort of [...state.held]) abort();
|
|
6163
|
+
return unused;
|
|
6164
|
+
}
|
|
6165
|
+
};
|
|
6166
|
+
scope.add(...stubs);
|
|
6167
|
+
return scope;
|
|
6168
|
+
},
|
|
6169
|
+
close() {
|
|
6170
|
+
closing ??= new Promise((resolve9) => {
|
|
6171
|
+
for (const state of scopes.values()) for (const abort of [...state.held]) abort();
|
|
6172
|
+
scopes.clear();
|
|
6173
|
+
server.close(() => resolve9());
|
|
6174
|
+
server.closeAllConnections();
|
|
6175
|
+
});
|
|
6176
|
+
return closing;
|
|
6177
|
+
}
|
|
6178
|
+
};
|
|
6179
|
+
}
|
|
6180
|
+
|
|
4765
6181
|
// src/cli/commands/run.ts
|
|
4766
6182
|
var NOOP_CACHE = { get: () => void 0, set: () => {
|
|
4767
6183
|
}, delete: () => {
|
|
@@ -4788,12 +6204,12 @@ function parseToolDescriptions(values) {
|
|
|
4788
6204
|
const file = text.slice(1);
|
|
4789
6205
|
try {
|
|
4790
6206
|
const full = path5.resolve(file);
|
|
4791
|
-
const stat2 =
|
|
6207
|
+
const stat2 = fs6.statSync(full);
|
|
4792
6208
|
if (!stat2.isFile())
|
|
4793
6209
|
throw new RunConfigError(`--tool-description ${tool}: ${file} is not a file`);
|
|
4794
6210
|
if (stat2.size > MAX_DESCRIPTION_BYTES)
|
|
4795
6211
|
throw new RunConfigError(`--tool-description ${tool}: ${file} is over 64 KB`);
|
|
4796
|
-
text =
|
|
6212
|
+
text = fs6.readFileSync(full, "utf8").replace(/\r?\n$/, "");
|
|
4797
6213
|
} catch (err) {
|
|
4798
6214
|
if (err instanceof RunConfigError) throw err;
|
|
4799
6215
|
throw new RunConfigError(`--tool-description ${tool}: cannot read ${file}`);
|
|
@@ -4811,7 +6227,7 @@ function mockScript(env) {
|
|
|
4811
6227
|
if (file === void 0 || file === "") return void 0;
|
|
4812
6228
|
let text;
|
|
4813
6229
|
try {
|
|
4814
|
-
text =
|
|
6230
|
+
text = fs6.readFileSync(path5.resolve(file), "utf8");
|
|
4815
6231
|
} catch {
|
|
4816
6232
|
throw new RunConfigError(`PLUNE_MOCK_SCRIPT: cannot read ${file}`);
|
|
4817
6233
|
}
|
|
@@ -4845,11 +6261,11 @@ function resolveProviderFor(config, dryRun) {
|
|
|
4845
6261
|
return () => makeMockProvider(script);
|
|
4846
6262
|
}
|
|
4847
6263
|
if (dryRun) return (cfg) => makeEstimateProvider(cfg, config.pricing);
|
|
4848
|
-
return (cfg) => getProvider(cfg, process.env, config.pricing);
|
|
6264
|
+
return (cfg, stubOrigin) => getProvider(cfg, process.env, config.pricing, stubOrigin);
|
|
4849
6265
|
}
|
|
4850
6266
|
function buildRealDeps(config, baseDir, dryRun) {
|
|
4851
6267
|
const dir = path5.join(baseDir, ".plune");
|
|
4852
|
-
|
|
6268
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
4853
6269
|
return {
|
|
4854
6270
|
resolveProvider: resolveProviderFor(config, dryRun),
|
|
4855
6271
|
embedder: getDefaultEmbedder(),
|
|
@@ -4875,8 +6291,21 @@ function buildRealDeps(config, baseDir, dryRun) {
|
|
|
4875
6291
|
}
|
|
4876
6292
|
function persist(result, baseDir) {
|
|
4877
6293
|
const dir = path5.join(baseDir, ".plune");
|
|
4878
|
-
|
|
4879
|
-
|
|
6294
|
+
fs6.mkdirSync(dir, { recursive: true });
|
|
6295
|
+
fs6.writeFileSync(path5.join(dir, "last-run.json"), JSON.stringify(result, null, 2));
|
|
6296
|
+
}
|
|
6297
|
+
function stubWarnings(config, result) {
|
|
6298
|
+
return result.evals.flatMap((ev) => {
|
|
6299
|
+
if (ev.stubs === void 0) return [];
|
|
6300
|
+
const { never_called: never, unmatched } = ev.stubs;
|
|
6301
|
+
const file = config.evals.find((e) => e.id === baseEvalId(ev))?.stubs ?? "its stub file";
|
|
6302
|
+
return [
|
|
6303
|
+
...never.length > 0 ? [`${never.map((i) => `stubs.${i}`).join(", ")} of ${file} ${never.length === 1 ? "was" : "were"} never called`] : [],
|
|
6304
|
+
...unmatched.length > 0 ? [
|
|
6305
|
+
`${unmatched.length} request${unmatched.length === 1 ? "" : "s"} matched no stub: ` + unmatched.map((u) => `${u.method} in ${u.scope}`).join(", ")
|
|
6306
|
+
] : []
|
|
6307
|
+
].map((line) => `eval "${ev.id}": ${line}`);
|
|
6308
|
+
});
|
|
4880
6309
|
}
|
|
4881
6310
|
function jevAddressCheck(config, env) {
|
|
4882
6311
|
const checks = [...config.defaults?.assertions ?? [], ...config.evals.flatMap((ev) => ev.assertions)];
|
|
@@ -4898,7 +6327,9 @@ async function handleRun(options, depsFactory) {
|
|
|
4898
6327
|
`);
|
|
4899
6328
|
const toolDescriptions = options.toolDescription !== void 0 && options.toolDescription.length > 0 ? parseToolDescriptions(options.toolDescription) : void 0;
|
|
4900
6329
|
const factory = depsFactory ?? ((c, d) => buildRealDeps(c, d, options.dryRun));
|
|
4901
|
-
const
|
|
6330
|
+
const given = factory(config, baseDir);
|
|
6331
|
+
let stubServer;
|
|
6332
|
+
const deps = depsFactory === void 0 && isMockMode(process.env) ? given : { ...given, stubServer: () => stubServer ??= (given.stubServer ?? start)() };
|
|
4902
6333
|
try {
|
|
4903
6334
|
const stale = deps.cache.staleEntries ?? 0;
|
|
4904
6335
|
if (stale > 0) {
|
|
@@ -4934,6 +6365,8 @@ async function handleRun(options, depsFactory) {
|
|
|
4934
6365
|
`
|
|
4935
6366
|
);
|
|
4936
6367
|
}
|
|
6368
|
+
for (const warning of stubWarnings(config, result)) process.stderr.write(`warning: ${warning}
|
|
6369
|
+
`);
|
|
4937
6370
|
if (options.dryRun) {
|
|
4938
6371
|
const agentic = new Set(config.evals.filter((ev) => ev.mcp !== void 0).map((ev) => ev.id));
|
|
4939
6372
|
if (result.evals.some((ev) => agentic.has(ev.id)))
|
|
@@ -4945,164 +6378,173 @@ async function handleRun(options, depsFactory) {
|
|
|
4945
6378
|
return result;
|
|
4946
6379
|
} finally {
|
|
4947
6380
|
deps.cache.close();
|
|
6381
|
+
if (stubServer !== void 0) await stubServer.then((server) => server.close(), () => void 0);
|
|
4948
6382
|
}
|
|
4949
6383
|
}
|
|
4950
6384
|
|
|
4951
6385
|
// src/cli/commands/sync.ts
|
|
4952
6386
|
init_cjs_shims();
|
|
4953
6387
|
var import_node_crypto2 = require("crypto");
|
|
4954
|
-
var
|
|
6388
|
+
var fs7 = __toESM(require("fs"), 1);
|
|
4955
6389
|
var path6 = __toESM(require("path"), 1);
|
|
4956
6390
|
|
|
4957
6391
|
// src/types/run-result-schema.ts
|
|
4958
6392
|
init_cjs_shims();
|
|
4959
|
-
var
|
|
6393
|
+
var import_zod4 = require("zod");
|
|
4960
6394
|
var RUN_RESULT_SCHEMA_VERSION = 1;
|
|
4961
|
-
var binaryVerdictSchema =
|
|
4962
|
-
question:
|
|
4963
|
-
passed:
|
|
6395
|
+
var binaryVerdictSchema = import_zod4.z.object({
|
|
6396
|
+
question: import_zod4.z.string().min(1),
|
|
6397
|
+
passed: import_zod4.z.boolean()
|
|
4964
6398
|
});
|
|
4965
|
-
var assertionResultRecordSchema2 =
|
|
4966
|
-
type:
|
|
4967
|
-
passed:
|
|
4968
|
-
score:
|
|
4969
|
-
reason:
|
|
4970
|
-
binaryVerdicts:
|
|
6399
|
+
var assertionResultRecordSchema2 = import_zod4.z.object({
|
|
6400
|
+
type: import_zod4.z.string(),
|
|
6401
|
+
passed: import_zod4.z.boolean(),
|
|
6402
|
+
score: import_zod4.z.number().optional(),
|
|
6403
|
+
reason: import_zod4.z.string().optional(),
|
|
6404
|
+
binaryVerdicts: import_zod4.z.array(binaryVerdictSchema).optional(),
|
|
4971
6405
|
/** plune-ai/cli#373. Optional and additive — a RunResult written before it validates unchanged. */
|
|
4972
|
-
judge_model:
|
|
6406
|
+
judge_model: import_zod4.z.string().optional()
|
|
4973
6407
|
});
|
|
4974
|
-
var usageSchema =
|
|
4975
|
-
input_tokens:
|
|
4976
|
-
output_tokens:
|
|
4977
|
-
cost_usd:
|
|
6408
|
+
var usageSchema = import_zod4.z.object({
|
|
6409
|
+
input_tokens: import_zod4.z.number(),
|
|
6410
|
+
output_tokens: import_zod4.z.number(),
|
|
6411
|
+
cost_usd: import_zod4.z.number(),
|
|
4978
6412
|
/** cli#151. Optional and additive — a RunResult written before it validates unchanged. */
|
|
4979
|
-
priced:
|
|
6413
|
+
priced: import_zod4.z.boolean().optional()
|
|
4980
6414
|
});
|
|
4981
|
-
var runErrorSchema =
|
|
4982
|
-
code:
|
|
4983
|
-
message:
|
|
6415
|
+
var runErrorSchema = import_zod4.z.object({
|
|
6416
|
+
code: import_zod4.z.string(),
|
|
6417
|
+
message: import_zod4.z.string()
|
|
4984
6418
|
});
|
|
4985
|
-
var savedSchema =
|
|
4986
|
-
input_tokens:
|
|
4987
|
-
output_tokens:
|
|
4988
|
-
cost_usd:
|
|
6419
|
+
var savedSchema = import_zod4.z.object({
|
|
6420
|
+
input_tokens: import_zod4.z.number(),
|
|
6421
|
+
output_tokens: import_zod4.z.number(),
|
|
6422
|
+
cost_usd: import_zod4.z.number()
|
|
4989
6423
|
});
|
|
4990
|
-
var rowResultSchema =
|
|
4991
|
-
vars:
|
|
4992
|
-
output:
|
|
4993
|
-
cached:
|
|
6424
|
+
var rowResultSchema = import_zod4.z.object({
|
|
6425
|
+
vars: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()),
|
|
6426
|
+
output: import_zod4.z.string().nullable(),
|
|
6427
|
+
cached: import_zod4.z.boolean(),
|
|
6428
|
+
/** A row of an eval with `stubs`. Kept by the parser so that `plune sync` can see it and refuse the upload. */
|
|
6429
|
+
stubbed: import_zod4.z.boolean().optional(),
|
|
4994
6430
|
usage: usageSchema.optional(),
|
|
4995
|
-
latency_ms:
|
|
6431
|
+
latency_ms: import_zod4.z.number().optional(),
|
|
4996
6432
|
error: runErrorSchema.optional(),
|
|
4997
|
-
assertions:
|
|
6433
|
+
assertions: import_zod4.z.array(assertionResultRecordSchema2),
|
|
4998
6434
|
cache_saved: savedSchema.optional(),
|
|
4999
6435
|
/** Optional and additive — the same enum the platform validates on `POST /v1/runs`. */
|
|
5000
|
-
inconclusive:
|
|
6436
|
+
inconclusive: import_zod4.z.enum(ROW_INCONCLUSIVE).optional(),
|
|
5001
6437
|
/** Repeats (`runs` above 1). Optional and additive — a RunResult without it validates unchanged. */
|
|
5002
|
-
attempts:
|
|
5003
|
-
runs:
|
|
5004
|
-
pass_threshold:
|
|
5005
|
-
passed:
|
|
5006
|
-
failed:
|
|
5007
|
-
errored:
|
|
5008
|
-
results:
|
|
5009
|
-
|
|
5010
|
-
output:
|
|
5011
|
-
cached:
|
|
6438
|
+
attempts: import_zod4.z.object({
|
|
6439
|
+
runs: import_zod4.z.number(),
|
|
6440
|
+
pass_threshold: import_zod4.z.number(),
|
|
6441
|
+
passed: import_zod4.z.number(),
|
|
6442
|
+
failed: import_zod4.z.number(),
|
|
6443
|
+
errored: import_zod4.z.number(),
|
|
6444
|
+
results: import_zod4.z.array(
|
|
6445
|
+
import_zod4.z.object({
|
|
6446
|
+
output: import_zod4.z.string().nullable(),
|
|
6447
|
+
cached: import_zod4.z.boolean(),
|
|
5012
6448
|
usage: usageSchema.optional(),
|
|
5013
|
-
latency_ms:
|
|
6449
|
+
latency_ms: import_zod4.z.number().optional(),
|
|
5014
6450
|
error: runErrorSchema.optional(),
|
|
5015
|
-
assertions:
|
|
6451
|
+
assertions: import_zod4.z.array(assertionResultRecordSchema2),
|
|
5016
6452
|
cache_saved: savedSchema.optional()
|
|
5017
6453
|
})
|
|
5018
6454
|
)
|
|
5019
6455
|
}).optional(),
|
|
5020
6456
|
/** The tool loop of an eval with an `mcp` server. Optional and additive — a RunResult without it validates unchanged. */
|
|
5021
|
-
agent:
|
|
5022
|
-
server:
|
|
5023
|
-
tools:
|
|
5024
|
-
|
|
5025
|
-
name:
|
|
5026
|
-
offered:
|
|
5027
|
-
annotations:
|
|
6457
|
+
agent: import_zod4.z.object({
|
|
6458
|
+
server: import_zod4.z.string(),
|
|
6459
|
+
tools: import_zod4.z.array(
|
|
6460
|
+
import_zod4.z.object({
|
|
6461
|
+
name: import_zod4.z.string(),
|
|
6462
|
+
offered: import_zod4.z.boolean(),
|
|
6463
|
+
annotations: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional()
|
|
5028
6464
|
})
|
|
5029
6465
|
),
|
|
5030
|
-
steps:
|
|
5031
|
-
|
|
5032
|
-
index:
|
|
5033
|
-
text:
|
|
5034
|
-
finish_reason:
|
|
6466
|
+
steps: import_zod4.z.array(
|
|
6467
|
+
import_zod4.z.object({
|
|
6468
|
+
index: import_zod4.z.number(),
|
|
6469
|
+
text: import_zod4.z.string(),
|
|
6470
|
+
finish_reason: import_zod4.z.string().optional(),
|
|
5035
6471
|
usage: usageSchema,
|
|
5036
|
-
calls:
|
|
5037
|
-
|
|
5038
|
-
id:
|
|
5039
|
-
name:
|
|
5040
|
-
args:
|
|
5041
|
-
executed:
|
|
5042
|
-
is_error:
|
|
5043
|
-
error_kind:
|
|
5044
|
-
duration_ms:
|
|
5045
|
-
result:
|
|
6472
|
+
calls: import_zod4.z.array(
|
|
6473
|
+
import_zod4.z.object({
|
|
6474
|
+
id: import_zod4.z.string(),
|
|
6475
|
+
name: import_zod4.z.string(),
|
|
6476
|
+
args: import_zod4.z.unknown(),
|
|
6477
|
+
executed: import_zod4.z.boolean(),
|
|
6478
|
+
is_error: import_zod4.z.boolean(),
|
|
6479
|
+
error_kind: import_zod4.z.enum(["content", "protocol", "timeout", "not-offered", "bad-arguments"]).optional(),
|
|
6480
|
+
duration_ms: import_zod4.z.number().optional(),
|
|
6481
|
+
result: import_zod4.z.object({ text: import_zod4.z.string(), bytes: import_zod4.z.number(), truncated: import_zod4.z.boolean() }).optional()
|
|
5046
6482
|
})
|
|
5047
6483
|
),
|
|
5048
6484
|
/** Optional and additive: the step whose request first offered a changed list. */
|
|
5049
|
-
offered_changed:
|
|
6485
|
+
offered_changed: import_zod4.z.object({ added: import_zod4.z.array(import_zod4.z.string()), removed: import_zod4.z.array(import_zod4.z.string()) }).optional()
|
|
5050
6486
|
})
|
|
5051
6487
|
),
|
|
5052
|
-
stop:
|
|
5053
|
-
reason:
|
|
5054
|
-
limit:
|
|
6488
|
+
stop: import_zod4.z.object({
|
|
6489
|
+
reason: import_zod4.z.enum(["complete", "limit", "error"]),
|
|
6490
|
+
limit: import_zod4.z.enum(["max_steps", "max_tool_calls", "max_total_tokens", "timeout_ms", "tool_timeout_ms"]).optional()
|
|
5055
6491
|
}),
|
|
5056
|
-
collection:
|
|
6492
|
+
collection: import_zod4.z.enum(["complete", "partial"]),
|
|
5057
6493
|
/** Heuristic findings, never a verdict. Optional and additive. */
|
|
5058
|
-
advice:
|
|
5059
|
-
|
|
5060
|
-
type:
|
|
5061
|
-
reason:
|
|
5062
|
-
tool:
|
|
5063
|
-
steps:
|
|
5064
|
-
count:
|
|
5065
|
-
paths:
|
|
6494
|
+
advice: import_zod4.z.array(
|
|
6495
|
+
import_zod4.z.object({
|
|
6496
|
+
type: import_zod4.z.string(),
|
|
6497
|
+
reason: import_zod4.z.string(),
|
|
6498
|
+
tool: import_zod4.z.string().optional(),
|
|
6499
|
+
steps: import_zod4.z.array(import_zod4.z.number()).optional(),
|
|
6500
|
+
count: import_zod4.z.number().optional(),
|
|
6501
|
+
paths: import_zod4.z.array(import_zod4.z.string()).optional()
|
|
5066
6502
|
})
|
|
5067
6503
|
).optional(),
|
|
5068
|
-
description_overrides:
|
|
6504
|
+
description_overrides: import_zod4.z.array(import_zod4.z.object({ tool: import_zod4.z.string(), sha256: import_zod4.z.string() })).optional()
|
|
5069
6505
|
}).optional()
|
|
5070
6506
|
});
|
|
5071
|
-
var summarySchema =
|
|
5072
|
-
total:
|
|
5073
|
-
passed:
|
|
5074
|
-
failed:
|
|
5075
|
-
errored:
|
|
6507
|
+
var summarySchema = import_zod4.z.object({
|
|
6508
|
+
total: import_zod4.z.number(),
|
|
6509
|
+
passed: import_zod4.z.number(),
|
|
6510
|
+
failed: import_zod4.z.number(),
|
|
6511
|
+
errored: import_zod4.z.number(),
|
|
5076
6512
|
/** Optional and additive — a RunResult written before them validates unchanged. */
|
|
5077
|
-
blocked:
|
|
5078
|
-
skipped:
|
|
5079
|
-
cost_usd:
|
|
5080
|
-
duration_ms:
|
|
5081
|
-
cache:
|
|
5082
|
-
from_cache:
|
|
5083
|
-
from_model:
|
|
5084
|
-
missed:
|
|
5085
|
-
errored:
|
|
5086
|
-
|
|
6513
|
+
blocked: import_zod4.z.number().optional(),
|
|
6514
|
+
skipped: import_zod4.z.number().optional(),
|
|
6515
|
+
cost_usd: import_zod4.z.number(),
|
|
6516
|
+
duration_ms: import_zod4.z.number(),
|
|
6517
|
+
cache: import_zod4.z.object({
|
|
6518
|
+
from_cache: import_zod4.z.number(),
|
|
6519
|
+
from_model: import_zod4.z.number(),
|
|
6520
|
+
missed: import_zod4.z.number(),
|
|
6521
|
+
errored: import_zod4.z.number(),
|
|
6522
|
+
stubbed: import_zod4.z.number().optional(),
|
|
6523
|
+
saved: import_zod4.z.object({ input_tokens: import_zod4.z.number(), output_tokens: import_zod4.z.number(), cost_usd: import_zod4.z.number() })
|
|
5087
6524
|
}).optional()
|
|
5088
6525
|
});
|
|
5089
|
-
var evalResultSchema =
|
|
5090
|
-
id:
|
|
5091
|
-
tags:
|
|
5092
|
-
rows:
|
|
5093
|
-
passed:
|
|
6526
|
+
var evalResultSchema = import_zod4.z.object({
|
|
6527
|
+
id: import_zod4.z.string(),
|
|
6528
|
+
tags: import_zod4.z.array(import_zod4.z.string()),
|
|
6529
|
+
rows: import_zod4.z.array(rowResultSchema),
|
|
6530
|
+
passed: import_zod4.z.boolean(),
|
|
5094
6531
|
/** What the eval measured, for the pass-rate gate of `plune diff`. Optional and additive. */
|
|
5095
|
-
measured:
|
|
5096
|
-
runs:
|
|
5097
|
-
rows:
|
|
5098
|
-
rows_hash:
|
|
5099
|
-
assertions_hash:
|
|
5100
|
-
model:
|
|
6532
|
+
measured: import_zod4.z.object({
|
|
6533
|
+
runs: import_zod4.z.number(),
|
|
6534
|
+
rows: import_zod4.z.number(),
|
|
6535
|
+
rows_hash: import_zod4.z.string(),
|
|
6536
|
+
assertions_hash: import_zod4.z.string(),
|
|
6537
|
+
model: import_zod4.z.string().optional()
|
|
5101
6538
|
}).optional(),
|
|
5102
6539
|
/** The type and model of a cell of a multi-model run. Optional and additive. */
|
|
5103
|
-
provider:
|
|
6540
|
+
provider: import_zod4.z.object({ type: import_zod4.z.string(), model: import_zod4.z.string() }).optional(),
|
|
6541
|
+
/** The mark of an eval answered from stubs, kept for the same reason as a row's `stubbed`. */
|
|
6542
|
+
stubs: import_zod4.z.object({
|
|
6543
|
+
never_called: import_zod4.z.array(import_zod4.z.number()),
|
|
6544
|
+
unmatched: import_zod4.z.array(import_zod4.z.object({ scope: import_zod4.z.string(), method: import_zod4.z.string() }))
|
|
6545
|
+
}).optional(),
|
|
5104
6546
|
/** The link to the eval's trace in your own observability (Langfuse, OTel). Optional and additive; `plune sync` drops one `traceUrlProblem` refuses. */
|
|
5105
|
-
traceUrl:
|
|
6547
|
+
traceUrl: import_zod4.z.string().optional()
|
|
5106
6548
|
});
|
|
5107
6549
|
var TRACE_URL_MAX = 2048;
|
|
5108
6550
|
function traceUrlProblem(value) {
|
|
@@ -5120,16 +6562,16 @@ function traceUrlProblem(value) {
|
|
|
5120
6562
|
if (parsed2.username !== "" || parsed2.password !== "") return "must carry no user name or password";
|
|
5121
6563
|
return void 0;
|
|
5122
6564
|
}
|
|
5123
|
-
var runResultSchema =
|
|
5124
|
-
schemaVersion:
|
|
5125
|
-
plune_version:
|
|
5126
|
-
started_at:
|
|
5127
|
-
finished_at:
|
|
5128
|
-
config_hash:
|
|
6565
|
+
var runResultSchema = import_zod4.z.object({
|
|
6566
|
+
schemaVersion: import_zod4.z.literal(RUN_RESULT_SCHEMA_VERSION),
|
|
6567
|
+
plune_version: import_zod4.z.string(),
|
|
6568
|
+
started_at: import_zod4.z.string(),
|
|
6569
|
+
finished_at: import_zod4.z.string(),
|
|
6570
|
+
config_hash: import_zod4.z.string(),
|
|
5129
6571
|
/** cli#244. The result of `--dry-run`. Optional and additive — a RunResult without it validates unchanged. */
|
|
5130
|
-
dry_run:
|
|
6572
|
+
dry_run: import_zod4.z.boolean().optional(),
|
|
5131
6573
|
summary: summarySchema,
|
|
5132
|
-
evals:
|
|
6574
|
+
evals: import_zod4.z.array(evalResultSchema)
|
|
5133
6575
|
});
|
|
5134
6576
|
function parseRunResult(value) {
|
|
5135
6577
|
return runResultSchema.parse(value);
|
|
@@ -5137,11 +6579,30 @@ function parseRunResult(value) {
|
|
|
5137
6579
|
|
|
5138
6580
|
// src/cli/api-url.ts
|
|
5139
6581
|
init_cjs_shims();
|
|
5140
|
-
var
|
|
6582
|
+
var PRODUCTION_API_URL = "https://api.plune.ai";
|
|
6583
|
+
var BETA_API_URL = "https://beta-api.plune.ai";
|
|
6584
|
+
var DEFAULT_API_URL = PRODUCTION_API_URL;
|
|
6585
|
+
var DASHBOARDS = /* @__PURE__ */ new Map([
|
|
6586
|
+
[PRODUCTION_API_URL, "https://app.plune.ai"],
|
|
6587
|
+
[BETA_API_URL, "https://beta.plune.ai"]
|
|
6588
|
+
]);
|
|
5141
6589
|
function resolveApiUrl(explicit) {
|
|
5142
|
-
const raw = explicit
|
|
6590
|
+
const raw = explicit?.trim() || process.env["PLUNE_API_URL"]?.trim() || DEFAULT_API_URL;
|
|
5143
6591
|
return raw.replace(/\/+$/, "");
|
|
5144
6592
|
}
|
|
6593
|
+
function knownApi(apiUrl) {
|
|
6594
|
+
try {
|
|
6595
|
+
const origin = new URL(apiUrl.trim()).origin;
|
|
6596
|
+
return DASHBOARDS.has(origin) ? origin : void 0;
|
|
6597
|
+
} catch {
|
|
6598
|
+
return void 0;
|
|
6599
|
+
}
|
|
6600
|
+
}
|
|
6601
|
+
function tokenRefusedBy(apiUrl = resolveApiUrl()) {
|
|
6602
|
+
const named = `The address that refused it is ${apiUrl}.`;
|
|
6603
|
+
if (knownApi(apiUrl) !== PRODUCTION_API_URL) return named;
|
|
6604
|
+
return `${named} A token from a beta account works only on the beta: run "plune login" with a token from ${DASHBOARDS.get(PRODUCTION_API_URL)}, or set PLUNE_API_URL=${BETA_API_URL} to keep using the beta account.`;
|
|
6605
|
+
}
|
|
5145
6606
|
|
|
5146
6607
|
// src/cli/credentials.ts
|
|
5147
6608
|
init_cjs_shims();
|
|
@@ -5261,9 +6722,9 @@ var NotLoggedInError = class extends Error {
|
|
|
5261
6722
|
}
|
|
5262
6723
|
};
|
|
5263
6724
|
var TokenRejectedError = class extends Error {
|
|
5264
|
-
constructor() {
|
|
6725
|
+
constructor(apiUrl = resolveApiUrl()) {
|
|
5265
6726
|
super(
|
|
5266
|
-
|
|
6727
|
+
`Your API token was rejected (revoked or invalid). Run "plune login" with a fresh token. ${tokenRefusedBy(apiUrl)}`
|
|
5267
6728
|
);
|
|
5268
6729
|
this.name = "TokenRejectedError";
|
|
5269
6730
|
}
|
|
@@ -5294,7 +6755,7 @@ function readRun(cwd, file, warn) {
|
|
|
5294
6755
|
const target = file !== void 0 ? path6.resolve(cwd, file) : path6.join(cwd, ".plune", "last-run.json");
|
|
5295
6756
|
let raw;
|
|
5296
6757
|
try {
|
|
5297
|
-
raw =
|
|
6758
|
+
raw = fs7.readFileSync(target, "utf8");
|
|
5298
6759
|
} catch {
|
|
5299
6760
|
throw new SyncFileError(
|
|
5300
6761
|
file !== void 0 ? `Run file not found: ${target}` : 'No run to sync. Run "plune run" first (or pass --file <path>).'
|
|
@@ -5307,11 +6768,18 @@ function readRun(cwd, file, warn) {
|
|
|
5307
6768
|
throw new SyncFileError(`Run file is not valid JSON: ${target}`);
|
|
5308
6769
|
}
|
|
5309
6770
|
dropBadTraceLinks(json, warn);
|
|
6771
|
+
let run;
|
|
5310
6772
|
try {
|
|
5311
|
-
|
|
6773
|
+
run = parseRunResult(json);
|
|
5312
6774
|
} catch {
|
|
5313
6775
|
throw new SyncFileError(`Run file does not match the RunResult schema: ${target}`);
|
|
5314
6776
|
}
|
|
6777
|
+
const stubbed = stubbedEvals(run);
|
|
6778
|
+
if (stubbed.length > 0)
|
|
6779
|
+
throw new SyncFileError(
|
|
6780
|
+
`This run is not uploaded: its evals ${stubbed.join(", ")} were answered from stubs, not by a model. Run them without stubs, or sync a run of the other evals (plune run --only).`
|
|
6781
|
+
);
|
|
6782
|
+
return run;
|
|
5315
6783
|
}
|
|
5316
6784
|
function dropBadTraceLinks(json, warn) {
|
|
5317
6785
|
const evals = json?.evals;
|
|
@@ -5376,7 +6844,7 @@ async function handleSync(deps = {}) {
|
|
|
5376
6844
|
}
|
|
5377
6845
|
if (!res.ok) {
|
|
5378
6846
|
const detail = await safeErrorDetail(res);
|
|
5379
|
-
if (res.status === 401) throw new TokenRejectedError();
|
|
6847
|
+
if (res.status === 401) throw new TokenRejectedError(apiUrl);
|
|
5380
6848
|
throw new SyncHttpError(res.status, detail);
|
|
5381
6849
|
}
|
|
5382
6850
|
const body = await res.json().catch(() => ({}));
|
|
@@ -5418,7 +6886,7 @@ var path10 = __toESM(require("path"), 1);
|
|
|
5418
6886
|
init_cjs_shims();
|
|
5419
6887
|
var import_node_fs5 = require("fs");
|
|
5420
6888
|
var import_node_stream = require("stream");
|
|
5421
|
-
var
|
|
6889
|
+
var import_node_http2 = require("http");
|
|
5422
6890
|
var import_node_https = require("https");
|
|
5423
6891
|
var BACKOFF_BASE_MS = 300;
|
|
5424
6892
|
var BACKOFF_CAP_MS = 1e4;
|
|
@@ -5431,12 +6899,12 @@ function parseRetryAfter(raw, now = Date.now()) {
|
|
|
5431
6899
|
if (!Number.isFinite(seconds)) return null;
|
|
5432
6900
|
return Math.min(Math.max(seconds, 0) * 1e3, RETRY_AFTER_CAP_MS);
|
|
5433
6901
|
}
|
|
5434
|
-
var POOLS = { "http:": new
|
|
6902
|
+
var POOLS = { "http:": new import_node_http2.Agent({ keepAlive: true }), "https:": new import_node_https.Agent({ keepAlive: true }) };
|
|
5435
6903
|
var IDLE_MS = 3e5;
|
|
5436
6904
|
function nodeTransport(url, init, idleMs = IDLE_MS) {
|
|
5437
6905
|
return new Promise((resolve9, reject) => {
|
|
5438
6906
|
const target = new URL(url);
|
|
5439
|
-
const send = target.protocol === "https:" ? import_node_https.request :
|
|
6907
|
+
const send = target.protocol === "https:" ? import_node_https.request : import_node_http2.request;
|
|
5440
6908
|
const agent = POOLS[target.protocol === "https:" ? "https:" : "http:"];
|
|
5441
6909
|
const req = send(target, { method: init.method, headers: init.headers, agent }, (res) => {
|
|
5442
6910
|
const chunks = [];
|
|
@@ -5467,7 +6935,7 @@ var withoutLength = (headers) => Object.fromEntries(Object.entries(headers).filt
|
|
|
5467
6935
|
function nodePut(url, headers, source, idleMs) {
|
|
5468
6936
|
return new Promise((resolve9, reject) => {
|
|
5469
6937
|
const target = new URL(url);
|
|
5470
|
-
const send = target.protocol === "https:" ? import_node_https.request :
|
|
6938
|
+
const send = target.protocol === "https:" ? import_node_https.request : import_node_http2.request;
|
|
5471
6939
|
const length = "body" in source ? source.body.length : source.size;
|
|
5472
6940
|
let answered;
|
|
5473
6941
|
const settle = (err) => answered !== void 0 ? resolve9(answered) : reject(err);
|
|
@@ -5674,7 +7142,7 @@ var BUCKET_CODES = /* @__PURE__ */ new Set([
|
|
|
5674
7142
|
|
|
5675
7143
|
// src/reporter-core/fallback.ts
|
|
5676
7144
|
init_cjs_shims();
|
|
5677
|
-
var
|
|
7145
|
+
var fs8 = __toESM(require("fs"), 1);
|
|
5678
7146
|
var path8 = __toESM(require("path"), 1);
|
|
5679
7147
|
var DEFAULT_FALLBACK_PATH = path8.join(".plune", "pending-results.jsonl");
|
|
5680
7148
|
|
|
@@ -5727,12 +7195,12 @@ var TYPE_BY_EXTENSION = {
|
|
|
5727
7195
|
var READ_NOT_KEPT = /* @__PURE__ */ new Set(["application/plune.metadata+json", "application/plune.findings+json"]);
|
|
5728
7196
|
var NAME_MAX = 200;
|
|
5729
7197
|
function nameOf(file) {
|
|
5730
|
-
const
|
|
7198
|
+
const own3 = file.name.split(/[\\/]/).pop()?.trim() || (file.path === void 0 ? "" : (0, import_node_path3.basename)(file.path));
|
|
5731
7199
|
const fileExt = file.path === void 0 ? "" : (0, import_node_path3.extname)(file.path);
|
|
5732
|
-
const ownExt = (0, import_node_path3.extname)(
|
|
7200
|
+
const ownExt = (0, import_node_path3.extname)(own3);
|
|
5733
7201
|
const typed = ownExt !== "" && (ownExt.toLowerCase() === fileExt.toLowerCase() || TYPE_BY_EXTENSION[ownExt.toLowerCase()] !== void 0);
|
|
5734
7202
|
const ext = typed ? ownExt : fileExt;
|
|
5735
|
-
let stem = typed ?
|
|
7203
|
+
let stem = typed ? own3.slice(0, -ownExt.length) : own3;
|
|
5736
7204
|
if (stem.length + ext.length > NAME_MAX) {
|
|
5737
7205
|
stem = stem.slice(0, Math.max(0, NAME_MAX - ext.length));
|
|
5738
7206
|
if (/[\uD800-\uDBFF]$/.test(stem)) stem = stem.slice(0, -1);
|
|
@@ -5870,9 +7338,9 @@ function fileSender(options) {
|
|
|
5870
7338
|
if (out.ok) countsOf(kind).uploaded += 1;
|
|
5871
7339
|
else failed(job, out.detail || out.kind);
|
|
5872
7340
|
}
|
|
5873
|
-
async function uploadToBucket(job, size,
|
|
7341
|
+
async function uploadToBucket(job, size, first2) {
|
|
5874
7342
|
const source = job.body !== void 0 ? { body: job.body } : { path: job.path, size };
|
|
5875
|
-
let link =
|
|
7343
|
+
let link = first2;
|
|
5876
7344
|
for (let renewed = false; ; ) {
|
|
5877
7345
|
const put = await client.put(link.url, link.headers, source);
|
|
5878
7346
|
if (put.ok) break;
|
|
@@ -5885,8 +7353,8 @@ function fileSender(options) {
|
|
|
5885
7353
|
link = fresh;
|
|
5886
7354
|
}
|
|
5887
7355
|
requests += 1;
|
|
5888
|
-
const
|
|
5889
|
-
if (!
|
|
7356
|
+
const done2 = await client.post(`/v1/files/${encodeURIComponent(link.id)}/complete`, {}, uploadRetries);
|
|
7357
|
+
if (!done2.ok) return failedToBucket(job, codeOf2(done2));
|
|
5890
7358
|
countsOf(job.kind).uploaded += 1;
|
|
5891
7359
|
}
|
|
5892
7360
|
let free = uploadsAtOnce;
|
|
@@ -6052,9 +7520,9 @@ function fileSender(options) {
|
|
|
6052
7520
|
const toComplete = [];
|
|
6053
7521
|
await Promise.all(
|
|
6054
7522
|
puts.map(
|
|
6055
|
-
({ s, link:
|
|
7523
|
+
({ s, link: first2 }) => gated(async () => {
|
|
6056
7524
|
const source = s.job.body !== void 0 ? { body: s.job.body } : { path: s.job.path, size: s.size };
|
|
6057
|
-
let link =
|
|
7525
|
+
let link = first2;
|
|
6058
7526
|
for (let renewed = false; ; ) {
|
|
6059
7527
|
const put = await client.put(link.url, link.headers, source);
|
|
6060
7528
|
if (put.ok) break;
|
|
@@ -6240,7 +7708,7 @@ function fileSender(options) {
|
|
|
6240
7708
|
|
|
6241
7709
|
// src/cli/commands/cairn-artifact.ts
|
|
6242
7710
|
init_cjs_shims();
|
|
6243
|
-
var
|
|
7711
|
+
var fs9 = __toESM(require("fs/promises"), 1);
|
|
6244
7712
|
var path9 = __toESM(require("path"), 1);
|
|
6245
7713
|
|
|
6246
7714
|
// src/importers/trace-url.ts
|
|
@@ -7803,14 +9271,14 @@ var NoCairnRunsError = class extends Error {
|
|
|
7803
9271
|
}
|
|
7804
9272
|
};
|
|
7805
9273
|
async function findLatestCairnRun(runsDir = "runs") {
|
|
7806
|
-
const entries = await
|
|
9274
|
+
const entries = await fs9.readdir(runsDir, { withFileTypes: true }).catch(() => null);
|
|
7807
9275
|
if (entries === null) throw new NoCairnRunsError(runsDir);
|
|
7808
9276
|
let newest;
|
|
7809
9277
|
for (const entry of entries) {
|
|
7810
9278
|
if (!entry.isDirectory()) continue;
|
|
7811
9279
|
const dir = path9.join(runsDir, entry.name);
|
|
7812
9280
|
try {
|
|
7813
|
-
const report = await
|
|
9281
|
+
const report = await fs9.lstat(path9.join(dir, "report.json"));
|
|
7814
9282
|
if (!report.isFile()) continue;
|
|
7815
9283
|
if (newest === void 0 || report.mtimeMs > newest.at) {
|
|
7816
9284
|
newest = { dir, at: report.mtimeMs };
|
|
@@ -7861,13 +9329,13 @@ var CairnEvidenceAmbiguousError = class extends Error {
|
|
|
7861
9329
|
};
|
|
7862
9330
|
var asRecord = (v) => typeof v === "object" && v !== null ? v : {};
|
|
7863
9331
|
var str = (v, fallback = "") => typeof v === "string" && v !== "" ? v : fallback;
|
|
7864
|
-
var
|
|
9332
|
+
var own2 = (rec, key) => Object.hasOwn(rec, key) ? rec[key] : void 0;
|
|
7865
9333
|
var MAX_ARTIFACT_BYTES = 32 * 1024 * 1024;
|
|
7866
9334
|
var MAX_MCP_CASES = 5e3;
|
|
7867
9335
|
async function checkSize(dir, file) {
|
|
7868
9336
|
let size;
|
|
7869
9337
|
try {
|
|
7870
|
-
const st = await
|
|
9338
|
+
const st = await fs9.stat(path9.join(dir, file));
|
|
7871
9339
|
if (!st.isFile()) throw new CairnArtifactShapeError(file, "", "is not a regular file");
|
|
7872
9340
|
size = st.size;
|
|
7873
9341
|
} catch (e) {
|
|
@@ -7885,20 +9353,20 @@ async function checkSize(dir, file) {
|
|
|
7885
9353
|
}
|
|
7886
9354
|
async function readJson(file) {
|
|
7887
9355
|
try {
|
|
7888
|
-
return JSON.parse(await
|
|
9356
|
+
return JSON.parse(await fs9.readFile(file, "utf8"));
|
|
7889
9357
|
} catch {
|
|
7890
9358
|
return void 0;
|
|
7891
9359
|
}
|
|
7892
9360
|
}
|
|
7893
9361
|
var ARGS_CHARS2 = 200;
|
|
7894
|
-
var
|
|
9362
|
+
var SECRET_NAME2 = /key|token|secret|password|passwd|auth|cookie|credential/i;
|
|
7895
9363
|
var maskNamed = (v, depth = 0) => {
|
|
7896
9364
|
if (depth > 16) return "[deep]";
|
|
7897
9365
|
if (Array.isArray(v)) return v.slice(0, 50).map((x) => maskNamed(x, depth + 1));
|
|
7898
9366
|
if (typeof v === "object" && v !== null) {
|
|
7899
9367
|
const out = {};
|
|
7900
9368
|
for (const [k, x] of Object.entries(v).slice(0, 50)) {
|
|
7901
|
-
out[k] =
|
|
9369
|
+
out[k] = SECRET_NAME2.test(k) ? "***" : maskNamed(x, depth + 1);
|
|
7902
9370
|
}
|
|
7903
9371
|
return out;
|
|
7904
9372
|
}
|
|
@@ -7925,7 +9393,7 @@ async function readMcpEvidence(dir, states) {
|
|
|
7925
9393
|
if (!await checkSize(dir, file)) return void 0;
|
|
7926
9394
|
let raw;
|
|
7927
9395
|
try {
|
|
7928
|
-
raw = JSON.parse(await
|
|
9396
|
+
raw = JSON.parse(await fs9.readFile(path9.join(dir, file), "utf8"));
|
|
7929
9397
|
} catch {
|
|
7930
9398
|
throw new CairnArtifactShapeError(file, "", "is not valid JSON");
|
|
7931
9399
|
}
|
|
@@ -7939,7 +9407,7 @@ async function readMcpEvidence(dir, states) {
|
|
|
7939
9407
|
throw new CairnArtifactShapeError(file, `[${i}]`, "must be an object");
|
|
7940
9408
|
}
|
|
7941
9409
|
const rec = item;
|
|
7942
|
-
const id =
|
|
9410
|
+
const id = own2(rec, "stableId");
|
|
7943
9411
|
if (typeof id !== "string" || !states.has(id)) {
|
|
7944
9412
|
throw new CairnArtifactShapeError(
|
|
7945
9413
|
file,
|
|
@@ -7950,18 +9418,18 @@ async function readMcpEvidence(dir, states) {
|
|
|
7950
9418
|
if (byId.has(id)) {
|
|
7951
9419
|
throw new CairnArtifactShapeError(file, `[${i}].stableId`, "appears more than once");
|
|
7952
9420
|
}
|
|
7953
|
-
if (
|
|
9421
|
+
if (own2(rec, "state") !== states.get(id)) {
|
|
7954
9422
|
throw new CairnArtifactShapeError(
|
|
7955
9423
|
file,
|
|
7956
9424
|
`[${i}].state`,
|
|
7957
9425
|
"does not agree with the state in report.json"
|
|
7958
9426
|
);
|
|
7959
9427
|
}
|
|
7960
|
-
const request =
|
|
9428
|
+
const request = own2(rec, "request");
|
|
7961
9429
|
if (request !== void 0 && typeof request !== "string") {
|
|
7962
9430
|
throw new CairnArtifactShapeError(file, `[${i}].request`, "must be text");
|
|
7963
9431
|
}
|
|
7964
|
-
const durationMs =
|
|
9432
|
+
const durationMs = own2(rec, "durationMs");
|
|
7965
9433
|
if (durationMs !== void 0 && typeof durationMs !== "number") {
|
|
7966
9434
|
throw new CairnArtifactShapeError(file, `[${i}].durationMs`, "must be a number");
|
|
7967
9435
|
}
|
|
@@ -7979,7 +9447,7 @@ function expectedOfMcp(type, adversarial) {
|
|
|
7979
9447
|
return adversarial ? "The server rejects the call, or handles the value without harm." : "The server rejects the call: it does not act on a value the tool's inputSchema forbids.";
|
|
7980
9448
|
}
|
|
7981
9449
|
async function casesFromMcp(dir, report) {
|
|
7982
|
-
const list2 =
|
|
9450
|
+
const list2 = own2(report, "cases");
|
|
7983
9451
|
if (!Array.isArray(list2))
|
|
7984
9452
|
throw new CairnArtifactShapeError("report.json", "cases", "must be a list");
|
|
7985
9453
|
if (list2.length > MAX_MCP_CASES) {
|
|
@@ -7997,7 +9465,7 @@ async function casesFromMcp(dir, report) {
|
|
|
7997
9465
|
}
|
|
7998
9466
|
const c = raw;
|
|
7999
9467
|
const text = (key) => {
|
|
8000
|
-
const v =
|
|
9468
|
+
const v = own2(c, key);
|
|
8001
9469
|
if (typeof v !== "string" || v === "") {
|
|
8002
9470
|
throw new CairnArtifactShapeError("report.json", `${at}.${key}`, "must be text");
|
|
8003
9471
|
}
|
|
@@ -8027,14 +9495,14 @@ async function casesFromMcp(dir, report) {
|
|
|
8027
9495
|
}
|
|
8028
9496
|
states.set(stableId, state);
|
|
8029
9497
|
const kind = type;
|
|
8030
|
-
const technique =
|
|
9498
|
+
const technique = own2(c, "technique");
|
|
8031
9499
|
return {
|
|
8032
9500
|
stableId,
|
|
8033
9501
|
name,
|
|
8034
9502
|
tool,
|
|
8035
9503
|
type: kind,
|
|
8036
9504
|
state,
|
|
8037
|
-
adversarial:
|
|
9505
|
+
adversarial: own2(c, "adversarialStyle") !== void 0,
|
|
8038
9506
|
...typeof technique === "string" ? { technique } : {}
|
|
8039
9507
|
};
|
|
8040
9508
|
});
|
|
@@ -8070,7 +9538,7 @@ function casesFromDesign(report, notes) {
|
|
|
8070
9538
|
const c = asRecord(raw);
|
|
8071
9539
|
const steps = (Array.isArray(c["steps"]) ? c["steps"] : []).map((s) => str(s)).filter((s) => s !== "");
|
|
8072
9540
|
const title = str(c["title"], "untitled case");
|
|
8073
|
-
const link =
|
|
9541
|
+
const link = own2(c, "traceUrl") ?? void 0;
|
|
8074
9542
|
const said = [];
|
|
8075
9543
|
const traceUrl = traceUrlOf(link, title, said);
|
|
8076
9544
|
if (said.length > 0) {
|
|
@@ -8140,11 +9608,11 @@ async function readCairnRun(dir, deps = {}) {
|
|
|
8140
9608
|
}
|
|
8141
9609
|
cases = casesFromApi(report, verdicts);
|
|
8142
9610
|
} else if (mode === "mcp") {
|
|
8143
|
-
cases =
|
|
9611
|
+
cases = own2(report, "cases") === void 0 && Array.isArray(own2(report, "testCases")) ? casesFromDesign(report, deps.notes ?? []) : await casesFromMcp(dir, report);
|
|
8144
9612
|
} else {
|
|
8145
9613
|
cases = casesFromDesign(report, deps.notes ?? []);
|
|
8146
9614
|
}
|
|
8147
|
-
const tokens =
|
|
9615
|
+
const tokens = own2(asRecord(own2(report, "cost")), "totalTokens");
|
|
8148
9616
|
return {
|
|
8149
9617
|
schemaVersion: INGEST_SCHEMA_VERSION,
|
|
8150
9618
|
run: {
|
|
@@ -8162,7 +9630,7 @@ var clip = (s) => s.slice(0, DECLARED.text).replace(/[\uD800-\uDBFF]$/, "");
|
|
|
8162
9630
|
async function readCairnSessionFiles(dir) {
|
|
8163
9631
|
const raw = await readJson(path9.join(dir, "screencasts", "screencasts.json"));
|
|
8164
9632
|
if (!Array.isArray(raw)) return void 0;
|
|
8165
|
-
const root = await
|
|
9633
|
+
const root = await fs9.realpath(dir).catch(() => path9.resolve(dir));
|
|
8166
9634
|
const within = (p) => {
|
|
8167
9635
|
const rel = path9.relative(root, p);
|
|
8168
9636
|
return rel !== "" && !rel.startsWith("..") && !path9.isAbsolute(rel);
|
|
@@ -8171,10 +9639,10 @@ async function readCairnSessionFiles(dir) {
|
|
|
8171
9639
|
const inside = async (p) => {
|
|
8172
9640
|
if (typeof p !== "string" || p === "") return void 0;
|
|
8173
9641
|
const abs = path9.resolve(root, p);
|
|
8174
|
-
const real = await
|
|
9642
|
+
const real = await fs9.realpath(abs).catch(() => void 0);
|
|
8175
9643
|
if (within(abs) && (real === void 0 || within(real))) {
|
|
8176
9644
|
const file = real ?? abs;
|
|
8177
|
-
const size = await
|
|
9645
|
+
const size = await fs9.stat(file).then((s) => s.size, () => void 0);
|
|
8178
9646
|
return { path: file, rel: path9.relative(root, abs).split(path9.sep).join("/"), ...size !== void 0 ? { size } : {} };
|
|
8179
9647
|
}
|
|
8180
9648
|
outside += 1;
|
|
@@ -8187,11 +9655,11 @@ async function readCairnSessionFiles(dir) {
|
|
|
8187
9655
|
const rec = asRecord(entry);
|
|
8188
9656
|
const found = [];
|
|
8189
9657
|
for (const kind of ["video", "trace"]) {
|
|
8190
|
-
const at = await inside(
|
|
9658
|
+
const at = await inside(own2(rec, kind));
|
|
8191
9659
|
if (at !== void 0) found.push({ file: { path: at.path, ...at.size !== void 0 ? { size: at.size } : {} }, rel: at.rel, kind });
|
|
8192
9660
|
}
|
|
8193
9661
|
if (found.length === 0) continue;
|
|
8194
|
-
const stableId =
|
|
9662
|
+
const stableId = own2(rec, "stableId");
|
|
8195
9663
|
if (typeof stableId !== "string" || stableId === "") {
|
|
8196
9664
|
unmapped += 1;
|
|
8197
9665
|
continue;
|
|
@@ -8199,7 +9667,7 @@ async function readCairnSessionFiles(dir) {
|
|
|
8199
9667
|
byCase.set(stableId, [...byCase.get(stableId) ?? [], ...found.map((f) => f.file)]);
|
|
8200
9668
|
const declared = screencasts.get(stableId) ?? [];
|
|
8201
9669
|
const keys = new Set(declared.flatMap((s) => s.files.map((f) => f.key)));
|
|
8202
|
-
const title = clip(str(
|
|
9670
|
+
const title = clip(str(own2(rec, "test")));
|
|
8203
9671
|
const files = found.filter((f) => {
|
|
8204
9672
|
if ((f.file.size ?? 0) < 1 || f.rel.length > DECLARED.text || path9.basename(f.file.path).length > DECLARED.name || keys.has(f.rel)) return false;
|
|
8205
9673
|
keys.add(f.rel);
|
|
@@ -8207,14 +9675,14 @@ async function readCairnSessionFiles(dir) {
|
|
|
8207
9675
|
});
|
|
8208
9676
|
if (title === "" || files.length === 0 || declared.length >= DECLARED.perCase) continue;
|
|
8209
9677
|
for (const f of files) f.file.key = f.rel;
|
|
8210
|
-
const timing =
|
|
9678
|
+
const timing = own2(rec, "timing");
|
|
8211
9679
|
declared.push({
|
|
8212
9680
|
title,
|
|
8213
9681
|
...timing === "trace" || timing === "estimated" ? { timing } : {},
|
|
8214
|
-
chapters: (Array.isArray(
|
|
9682
|
+
chapters: (Array.isArray(own2(rec, "chapters")) ? own2(rec, "chapters") : []).flatMap((c) => {
|
|
8215
9683
|
const chapter = asRecord(c);
|
|
8216
|
-
const t = clip(str(
|
|
8217
|
-
const atMs =
|
|
9684
|
+
const t = clip(str(own2(chapter, "title")));
|
|
9685
|
+
const atMs = own2(chapter, "atMs");
|
|
8218
9686
|
return t !== "" && Number.isInteger(atMs) && atMs >= 0 ? [{ title: t, atMs }] : [];
|
|
8219
9687
|
}).slice(0, DECLARED.chapters),
|
|
8220
9688
|
files: files.map((f) => ({ key: f.rel, name: path9.basename(f.file.path), kind: f.kind, size: f.file.size }))
|
|
@@ -8232,8 +9700,8 @@ var IngestNotLoggedInError = class extends Error {
|
|
|
8232
9700
|
}
|
|
8233
9701
|
};
|
|
8234
9702
|
var IngestTokenRejectedError = class extends Error {
|
|
8235
|
-
constructor() {
|
|
8236
|
-
super(
|
|
9703
|
+
constructor(apiUrl = resolveApiUrl()) {
|
|
9704
|
+
super(`Your API token was rejected (401). Run "plune login" again with a fresh token. ${tokenRefusedBy(apiUrl)}`);
|
|
8237
9705
|
this.name = "IngestTokenRejectedError";
|
|
8238
9706
|
}
|
|
8239
9707
|
};
|
|
@@ -8429,7 +9897,7 @@ async function handleIngest(deps) {
|
|
|
8429
9897
|
}
|
|
8430
9898
|
if (!res.ok) {
|
|
8431
9899
|
const detail = await safeErrorDetail2(res);
|
|
8432
|
-
if (res.status === 401) throw new IngestTokenRejectedError();
|
|
9900
|
+
if (res.status === 401) throw new IngestTokenRejectedError(apiUrl);
|
|
8433
9901
|
throw new IngestHttpError(res.status, detail);
|
|
8434
9902
|
}
|
|
8435
9903
|
const body = await res.json().catch(() => ({}));
|