shield-llm 0.10.0 → 0.10.1
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/dist/{chunk-GJQFYKMY.js → chunk-VJXUREGO.js} +1 -1
- package/dist/cli.js +94 -26
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -75,7 +75,7 @@ import {
|
|
|
75
75
|
sha256Hex,
|
|
76
76
|
summarizeAttackErrors,
|
|
77
77
|
version
|
|
78
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-VJXUREGO.js";
|
|
79
79
|
|
|
80
80
|
// src/load-env.ts
|
|
81
81
|
try {
|
|
@@ -4526,6 +4526,7 @@ function baselineRunResults(run1, run2) {
|
|
|
4526
4526
|
];
|
|
4527
4527
|
}
|
|
4528
4528
|
var BENIGN_VOTES = 3;
|
|
4529
|
+
var BENIGN_JUDGE_CONCURRENCY = 3;
|
|
4529
4530
|
function voteAttackId(caseName, vote) {
|
|
4530
4531
|
return vote === 0 ? `benign_${caseName}` : `benign_${caseName}#${vote + 1}`;
|
|
4531
4532
|
}
|
|
@@ -4577,28 +4578,46 @@ async function voteOnAnswer(c2, response, evaluator, votes, budget) {
|
|
|
4577
4578
|
}
|
|
4578
4579
|
async function judgeBenign(captures, cases, evaluator, opts = {}) {
|
|
4579
4580
|
const byName = new Map(cases.map((c2) => [c2.name, c2]));
|
|
4580
|
-
const out = [];
|
|
4581
4581
|
const budget = { open: true };
|
|
4582
|
-
|
|
4582
|
+
const judgeOne = async (cap) => {
|
|
4583
4583
|
const c2 = byName.get(cap.name);
|
|
4584
4584
|
if (!c2 || cap.response === void 0 || isCaptureError(cap)) {
|
|
4585
|
-
|
|
4586
|
-
continue;
|
|
4585
|
+
return { name: cap.name, passed: true, unobserved: true };
|
|
4587
4586
|
}
|
|
4588
4587
|
const key = `${cap.name}:${cap.hash}`;
|
|
4589
4588
|
const verdict = opts.memo?.get(key) ?? await voteOnAnswer(c2, cap.response, evaluator, opts.votes ?? 1, budget);
|
|
4590
|
-
if (!verdict) {
|
|
4591
|
-
out.push({ name: cap.name, passed: true, unjudged: true });
|
|
4592
|
-
continue;
|
|
4593
|
-
}
|
|
4589
|
+
if (!verdict) return { name: cap.name, passed: true, unjudged: true };
|
|
4594
4590
|
opts.memo?.set(key, verdict);
|
|
4595
|
-
|
|
4591
|
+
return {
|
|
4596
4592
|
name: cap.name,
|
|
4597
4593
|
passed: verdict.passed,
|
|
4598
4594
|
votes: verdict.votes,
|
|
4599
4595
|
...verdict.split ? { split: true } : {}
|
|
4600
|
-
}
|
|
4601
|
-
}
|
|
4596
|
+
};
|
|
4597
|
+
};
|
|
4598
|
+
return mapInOrder(
|
|
4599
|
+
captures,
|
|
4600
|
+
opts.concurrency ?? BENIGN_JUDGE_CONCURRENCY,
|
|
4601
|
+
judgeOne
|
|
4602
|
+
);
|
|
4603
|
+
}
|
|
4604
|
+
async function mapInOrder(items, limit, fn) {
|
|
4605
|
+
const out = new Array(items.length);
|
|
4606
|
+
let next = 0;
|
|
4607
|
+
let failed = false;
|
|
4608
|
+
const worker = async () => {
|
|
4609
|
+
while (!failed && next < items.length) {
|
|
4610
|
+
const i = next++;
|
|
4611
|
+
try {
|
|
4612
|
+
out[i] = await fn(items[i]);
|
|
4613
|
+
} catch (e) {
|
|
4614
|
+
failed = true;
|
|
4615
|
+
throw e;
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
};
|
|
4619
|
+
const workers = Math.max(1, Math.min(limit, items.length));
|
|
4620
|
+
await Promise.all(Array.from({ length: workers }, worker));
|
|
4602
4621
|
return out;
|
|
4603
4622
|
}
|
|
4604
4623
|
|
|
@@ -4618,7 +4637,9 @@ async function captureBenignBaseline(target, scope, judge) {
|
|
|
4618
4637
|
name: c2.name,
|
|
4619
4638
|
hash: c2.hash,
|
|
4620
4639
|
...hasVerdict2 ? { passed: v.passed } : {},
|
|
4621
|
-
...hasVerdict2 && v.split ? { split: true } : {}
|
|
4640
|
+
...hasVerdict2 && v.split ? { split: true } : {},
|
|
4641
|
+
// Kept so an answer the patch does not change keeps this verdict.
|
|
4642
|
+
...hasVerdict2 && v.votes ? { votes: v.votes } : {}
|
|
4622
4643
|
};
|
|
4623
4644
|
});
|
|
4624
4645
|
const unjudged = {
|
|
@@ -4702,7 +4723,8 @@ async function runBenignGate(input2) {
|
|
|
4702
4723
|
return {
|
|
4703
4724
|
green: !report.blocked,
|
|
4704
4725
|
ran: true,
|
|
4705
|
-
detail: report.blocked ? `blocked: ${report.flips.map((f) => f.name + (f.criticalPath ? "*" : "")).join(", ")}` : `${cases.length} cases, ${report.flips.length} flip(s), ${report.flakyCaseNames.length} flaky
|
|
4726
|
+
detail: report.blocked ? `blocked: ${report.flips.map((f) => f.name + (f.criticalPath ? "*" : "")).join(", ")}` : `${cases.length} cases, ${report.flips.length} flip(s), ${report.flakyCaseNames.length} flaky`,
|
|
4727
|
+
coverage: coverageOf(cases, [report])
|
|
4706
4728
|
};
|
|
4707
4729
|
}
|
|
4708
4730
|
const judge = input2.evaluator;
|
|
@@ -4717,11 +4739,19 @@ async function runBenignGate(input2) {
|
|
|
4717
4739
|
}
|
|
4718
4740
|
async function judgePatchedAnswers(baseline, cases, contract, target, judge) {
|
|
4719
4741
|
const after = await captureBenign(target, cases, { keepResponses: true });
|
|
4720
|
-
const
|
|
4721
|
-
|
|
4722
|
-
|
|
4742
|
+
const unchanged = unchangedVerdicts(baseline, after);
|
|
4743
|
+
const judged = await judgeBenign(
|
|
4744
|
+
after.filter((a) => !unchanged.has(a.name)),
|
|
4745
|
+
cases,
|
|
4746
|
+
judge,
|
|
4747
|
+
{ votes: BENIGN_VOTES }
|
|
4748
|
+
);
|
|
4749
|
+
const judgedByName = new Map(judged.map((r) => [r.name, r]));
|
|
4750
|
+
const afterRun = after.map(
|
|
4751
|
+
(a) => unchanged.get(a.name) ?? judgedByName.get(a.name)
|
|
4752
|
+
);
|
|
4723
4753
|
const notPassing = afterRun.flatMap(
|
|
4724
|
-
(r, i) => r.votes?.includes("F") ? [{ name: r.name, hash: after[i].hash, votes: r.votes }] : []
|
|
4754
|
+
(r, i) => !r.unchanged && r.votes?.includes("F") ? [{ name: r.name, hash: after[i].hash, votes: r.votes }] : []
|
|
4725
4755
|
);
|
|
4726
4756
|
const notCaptured = afterRun.filter((r) => r.unobserved).length;
|
|
4727
4757
|
if (notCaptured) {
|
|
@@ -4743,6 +4773,24 @@ async function judgePatchedAnswers(baseline, cases, contract, target, judge) {
|
|
|
4743
4773
|
}
|
|
4744
4774
|
return { ...ruleOnVotes(baseline, cases, contract, afterRun), notPassing };
|
|
4745
4775
|
}
|
|
4776
|
+
function unchangedVerdicts(baseline, after) {
|
|
4777
|
+
const out = /* @__PURE__ */ new Map();
|
|
4778
|
+
const before = [...baseline.run1, ...baseline.run2];
|
|
4779
|
+
for (const a of after) {
|
|
4780
|
+
const b = before.find(
|
|
4781
|
+
(x) => x.name === a.name && x.hash === a.hash && typeof x.passed === "boolean" && x.votes
|
|
4782
|
+
);
|
|
4783
|
+
if (!b || typeof b.passed !== "boolean") continue;
|
|
4784
|
+
out.set(a.name, {
|
|
4785
|
+
name: a.name,
|
|
4786
|
+
passed: b.passed,
|
|
4787
|
+
votes: b.votes,
|
|
4788
|
+
unchanged: true,
|
|
4789
|
+
...b.split ? { split: true } : {}
|
|
4790
|
+
});
|
|
4791
|
+
}
|
|
4792
|
+
return out;
|
|
4793
|
+
}
|
|
4746
4794
|
function ruleOnVotes(baseline, cases, contract, afterRun) {
|
|
4747
4795
|
const judged = judgedBaselineRuns(baseline, true) !== void 0;
|
|
4748
4796
|
const read = (favourable) => evaluateBenign({
|
|
@@ -4751,13 +4799,17 @@ function ruleOnVotes(baseline, cases, contract, afterRun) {
|
|
|
4751
4799
|
// A judged baseline says which cases already failed before the patch;
|
|
4752
4800
|
// an older claim has only hashes, and keeps the old reading (all passed).
|
|
4753
4801
|
baselineRuns: judgedBaselineRuns(baseline, !favourable) ?? baselineRunResults(baseline.run1, baseline.run2),
|
|
4754
|
-
afterRun: afterRun.map(
|
|
4755
|
-
(r)
|
|
4756
|
-
|
|
4802
|
+
afterRun: afterRun.map((r) => {
|
|
4803
|
+
if (r.unchanged) {
|
|
4804
|
+
return { name: r.name, passed: r.split ? !favourable : r.passed };
|
|
4805
|
+
}
|
|
4806
|
+
return r.split ? { name: r.name, passed: favourable } : r;
|
|
4807
|
+
}),
|
|
4757
4808
|
gate: contract.benignGate
|
|
4758
4809
|
});
|
|
4759
4810
|
const best = read(true);
|
|
4760
4811
|
const worst = read(false);
|
|
4812
|
+
const coverage = coverageOf(cases, [best, worst]);
|
|
4761
4813
|
const mark = (f) => f.name + (f.criticalPath ? "*" : "");
|
|
4762
4814
|
const solid = new Set(best.flips.map((f) => f.name));
|
|
4763
4815
|
const decidedBySplit = worst.flips.filter((f) => !solid.has(f.name)).map(mark);
|
|
@@ -4765,7 +4817,8 @@ function ruleOnVotes(baseline, cases, contract, afterRun) {
|
|
|
4765
4817
|
return {
|
|
4766
4818
|
green: false,
|
|
4767
4819
|
ran: true,
|
|
4768
|
-
detail: `blocked: ${best.flips.map(mark).join(", ")}` + (decidedBySplit.length ? `; split vote, not counted: ${decidedBySplit.join(", ")}` : "")
|
|
4820
|
+
detail: `blocked: ${best.flips.map(mark).join(", ")}` + (decidedBySplit.length ? `; split vote, not counted: ${decidedBySplit.join(", ")}` : ""),
|
|
4821
|
+
coverage
|
|
4769
4822
|
};
|
|
4770
4823
|
}
|
|
4771
4824
|
if (worst.blocked) {
|
|
@@ -4778,7 +4831,18 @@ function ruleOnVotes(baseline, cases, contract, afterRun) {
|
|
|
4778
4831
|
return {
|
|
4779
4832
|
green: true,
|
|
4780
4833
|
ran: true,
|
|
4781
|
-
detail: passDetail(baseline, cases, worst, judged, afterRun)
|
|
4834
|
+
detail: passDetail(baseline, cases, worst, judged, afterRun),
|
|
4835
|
+
coverage
|
|
4836
|
+
};
|
|
4837
|
+
}
|
|
4838
|
+
function coverageOf(cases, reports) {
|
|
4839
|
+
const excluded = new Set(reports.flatMap((r) => r.flakyCaseNames));
|
|
4840
|
+
const checked = cases.filter((c2) => !excluded.has(c2.name));
|
|
4841
|
+
return {
|
|
4842
|
+
checked: checked.length,
|
|
4843
|
+
total: cases.length,
|
|
4844
|
+
criticalChecked: checked.filter((c2) => c2.criticalPath).length,
|
|
4845
|
+
criticalTotal: cases.filter((c2) => c2.criticalPath).length
|
|
4782
4846
|
};
|
|
4783
4847
|
}
|
|
4784
4848
|
function passDetail(baseline, cases, report, judged, afterRun) {
|
|
@@ -4792,7 +4856,9 @@ function passDetail(baseline, cases, report, judged, afterRun) {
|
|
|
4792
4856
|
])).size;
|
|
4793
4857
|
const excluded = judged ? `, ${report.flakyCaseNames.length} not passing before the patch (excluded)` + (assumed ? `, ${assumed} without a verdict before the patch (assumed passing)` : "") : "";
|
|
4794
4858
|
const splitNote = split ? `, ${split} split vote(s) read against the patch` : "";
|
|
4795
|
-
|
|
4859
|
+
const kept = afterRun.filter((r) => r.unchanged).length;
|
|
4860
|
+
const scope = kept ? `${cases.length} cases, ${cases.length - kept} judged after the patch, ${kept} unchanged answer(s) kept their pre-patch verdict` : `${cases.length} cases judged`;
|
|
4861
|
+
return `${scope}, ${report.flips.length} flip(s)${excluded}${splitNote}`;
|
|
4796
4862
|
}
|
|
4797
4863
|
async function replayFamily(contract, target, catalogue, evaluator, judgeRetryDelayMs) {
|
|
4798
4864
|
const attacks = attacksForContract(contract, catalogue);
|
|
@@ -4851,7 +4917,8 @@ async function verifyLive(input2) {
|
|
|
4851
4917
|
ran: benign.ran,
|
|
4852
4918
|
green: benign.green,
|
|
4853
4919
|
detail: benign.detail,
|
|
4854
|
-
...benign.notPassing ? { notPassing: benign.notPassing } : {}
|
|
4920
|
+
...benign.notPassing ? { notPassing: benign.notPassing } : {},
|
|
4921
|
+
...benign.coverage ? { coverage: benign.coverage } : {}
|
|
4855
4922
|
},
|
|
4856
4923
|
judgeDegraded,
|
|
4857
4924
|
sessionIsolated: checkSessionIsolation(input2.target).isolated,
|
|
@@ -6062,7 +6129,8 @@ async function verifyClaimsCommand(opts) {
|
|
|
6062
6129
|
ran: benign.ran,
|
|
6063
6130
|
green: benign.green,
|
|
6064
6131
|
detail: benign.detail,
|
|
6065
|
-
...benign.notPassing ? { notPassing: benign.notPassing } : {}
|
|
6132
|
+
...benign.notPassing ? { notPassing: benign.notPassing } : {},
|
|
6133
|
+
...benign.coverage ? { coverage: benign.coverage } : {}
|
|
6066
6134
|
},
|
|
6067
6135
|
judgeDegraded,
|
|
6068
6136
|
sessionIsolated: checkSessionIsolation(target).isolated,
|
package/dist/index.js
CHANGED