@plune-ai/cairn 0.9.0 → 0.11.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 +84 -8
- package/dist/agent/check-docs.d.ts +25 -0
- package/dist/agent/check-docs.d.ts.map +1 -0
- package/dist/agent/check-docs.js +57 -0
- package/dist/agent/check-docs.js.map +1 -0
- package/dist/agent/collect-docs.d.ts +94 -0
- package/dist/agent/collect-docs.d.ts.map +1 -0
- package/dist/agent/collect-docs.js +326 -0
- package/dist/agent/collect-docs.js.map +1 -0
- package/dist/agent/graph.d.ts +39 -2
- package/dist/agent/graph.d.ts.map +1 -1
- package/dist/agent/graph.js +113 -4
- package/dist/agent/graph.js.map +1 -1
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +114 -10
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/overlays.d.ts +88 -0
- package/dist/agent/overlays.d.ts.map +1 -0
- package/dist/agent/overlays.js +447 -0
- package/dist/agent/overlays.js.map +1 -0
- package/dist/agent/repair-loop.d.ts +8 -1
- package/dist/agent/repair-loop.d.ts.map +1 -1
- package/dist/agent/repair-loop.js +18 -3
- package/dist/agent/repair-loop.js.map +1 -1
- package/dist/analyze/index.d.ts +1 -1
- package/dist/analyze/index.d.ts.map +1 -1
- package/dist/analyze/index.js +3 -2
- package/dist/analyze/index.js.map +1 -1
- package/dist/api/adversarial.d.ts +1 -1
- package/dist/api/adversarial.js +1 -1
- package/dist/api/collection.d.ts +20 -0
- package/dist/api/collection.d.ts.map +1 -0
- package/dist/api/collection.js +357 -0
- package/dist/api/collection.js.map +1 -0
- package/dist/api/derived.d.ts +179 -0
- package/dist/api/derived.d.ts.map +1 -0
- package/dist/api/derived.js +852 -0
- package/dist/api/derived.js.map +1 -0
- package/dist/api/discover.d.ts +66 -0
- package/dist/api/discover.d.ts.map +1 -0
- package/dist/api/discover.js +125 -0
- package/dist/api/discover.js.map +1 -0
- package/dist/api/flows.d.ts +194 -0
- package/dist/api/flows.d.ts.map +1 -0
- package/dist/api/flows.js +663 -0
- package/dist/api/flows.js.map +1 -0
- package/dist/api/guard.d.ts +19 -0
- package/dist/api/guard.d.ts.map +1 -1
- package/dist/api/guard.js +18 -4
- package/dist/api/guard.js.map +1 -1
- package/dist/api/openapi.d.ts +17 -1
- package/dist/api/openapi.d.ts.map +1 -1
- package/dist/api/openapi.js +64 -3
- package/dist/api/openapi.js.map +1 -1
- package/dist/api/runner.d.ts.map +1 -1
- package/dist/api/runner.js +18 -14
- package/dist/api/runner.js.map +1 -1
- package/dist/api/two-actor.d.ts +165 -0
- package/dist/api/two-actor.d.ts.map +1 -0
- package/dist/api/two-actor.js +627 -0
- package/dist/api/two-actor.js.map +1 -0
- package/dist/artifacts/contract.d.ts +1 -1
- package/dist/artifacts/contract.d.ts.map +1 -1
- package/dist/artifacts/index.d.ts +5 -0
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +14 -10
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/report.d.ts +29 -2
- package/dist/artifacts/report.d.ts.map +1 -1
- package/dist/artifacts/report.js +65 -1
- package/dist/artifacts/report.js.map +1 -1
- package/dist/artifacts/testcase-md.d.ts +18 -0
- package/dist/artifacts/testcase-md.d.ts.map +1 -1
- package/dist/artifacts/testcase-md.js +15 -1
- package/dist/artifacts/testcase-md.js.map +1 -1
- package/dist/browser/api-traffic.d.ts +85 -0
- package/dist/browser/api-traffic.d.ts.map +1 -0
- package/dist/browser/api-traffic.js +283 -0
- package/dist/browser/api-traffic.js.map +1 -0
- package/dist/browser/backends/playwright-cli.d.ts.map +1 -1
- package/dist/browser/backends/playwright-cli.js +3 -0
- package/dist/browser/backends/playwright-cli.js.map +1 -1
- package/dist/browser/backends/playwright-lib.d.ts +84 -1
- package/dist/browser/backends/playwright-lib.d.ts.map +1 -1
- package/dist/browser/backends/playwright-lib.js +677 -32
- package/dist/browser/backends/playwright-lib.js.map +1 -1
- package/dist/browser/click-effect.d.ts +84 -0
- package/dist/browser/click-effect.d.ts.map +1 -0
- package/dist/browser/click-effect.js +235 -0
- package/dist/browser/click-effect.js.map +1 -0
- package/dist/browser/gateway.d.ts +9 -1
- package/dist/browser/gateway.d.ts.map +1 -1
- package/dist/browser/index.d.ts +3 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +5 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/types.d.ts +196 -1
- package/dist/browser/types.d.ts.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +123 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/codegen/index.d.ts +10 -1
- package/dist/codegen/index.d.ts.map +1 -1
- package/dist/codegen/index.js +28 -7
- package/dist/codegen/index.js.map +1 -1
- package/dist/codegen/lint.d.ts +32 -1
- package/dist/codegen/lint.d.ts.map +1 -1
- package/dist/codegen/lint.js +286 -1
- package/dist/codegen/lint.js.map +1 -1
- package/dist/codegen/mailbox.d.ts +19 -0
- package/dist/codegen/mailbox.d.ts.map +1 -0
- package/dist/codegen/mailbox.js +78 -0
- package/dist/codegen/mailbox.js.map +1 -0
- package/dist/codegen/schema.d.ts.map +1 -1
- package/dist/codegen/schema.js +3 -2
- package/dist/codegen/schema.js.map +1 -1
- package/dist/config/profiles.d.ts +2 -0
- package/dist/config/profiles.d.ts.map +1 -1
- package/dist/config/profiles.js +2 -0
- package/dist/config/profiles.js.map +1 -1
- package/dist/core/modalities/api.d.ts.map +1 -1
- package/dist/core/modalities/api.js +265 -29
- package/dist/core/modalities/api.js.map +1 -1
- package/dist/core/modalities/check-docs.d.ts +3 -0
- package/dist/core/modalities/check-docs.d.ts.map +1 -0
- package/dist/core/modalities/check-docs.js +64 -0
- package/dist/core/modalities/check-docs.js.map +1 -0
- package/dist/core/modalities/collect-docs.d.ts +3 -0
- package/dist/core/modalities/collect-docs.d.ts.map +1 -0
- package/dist/core/modalities/collect-docs.js +48 -0
- package/dist/core/modalities/collect-docs.js.map +1 -0
- package/dist/core/modalities/explore.d.ts.map +1 -1
- package/dist/core/modalities/explore.js +2 -0
- package/dist/core/modalities/explore.js.map +1 -1
- package/dist/core/modalities/mcp-test.d.ts +3 -0
- package/dist/core/modalities/mcp-test.d.ts.map +1 -0
- package/dist/core/modalities/mcp-test.js +26 -0
- package/dist/core/modalities/mcp-test.js.map +1 -0
- package/dist/core/registry.d.ts.map +1 -1
- package/dist/core/registry.js +11 -3
- package/dist/core/registry.js.map +1 -1
- package/dist/decider/uses/repair-triage.d.ts +9 -0
- package/dist/decider/uses/repair-triage.d.ts.map +1 -1
- package/dist/decider/uses/repair-triage.js +20 -3
- package/dist/decider/uses/repair-triage.js.map +1 -1
- package/dist/design/critique.d.ts +1 -1
- package/dist/design/index.d.ts +7 -1
- package/dist/design/index.d.ts.map +1 -1
- package/dist/design/index.js +20 -2
- package/dist/design/index.js.map +1 -1
- package/dist/design/schema.d.ts +9 -3
- package/dist/design/schema.d.ts.map +1 -1
- package/dist/design/schema.js +4 -1
- package/dist/design/schema.js.map +1 -1
- package/dist/documentarian/check.d.ts +91 -0
- package/dist/documentarian/check.d.ts.map +1 -0
- package/dist/documentarian/check.js +230 -0
- package/dist/documentarian/check.js.map +1 -0
- package/dist/documentarian/docs.d.ts +103 -0
- package/dist/documentarian/docs.d.ts.map +1 -0
- package/dist/documentarian/docs.js +243 -0
- package/dist/documentarian/docs.js.map +1 -0
- package/dist/documentarian/index.d.ts +2 -0
- package/dist/documentarian/index.d.ts.map +1 -1
- package/dist/documentarian/index.js +5 -4
- package/dist/documentarian/index.js.map +1 -1
- package/dist/environment/apply.js +1 -1
- package/dist/environment/apply.js.map +1 -1
- package/dist/flow/crawl.d.ts +4 -0
- package/dist/flow/crawl.d.ts.map +1 -1
- package/dist/flow/crawl.js +9 -2
- package/dist/flow/crawl.js.map +1 -1
- package/dist/fs/inside-dir.d.ts +8 -0
- package/dist/fs/inside-dir.d.ts.map +1 -0
- package/dist/fs/inside-dir.js +15 -0
- package/dist/fs/inside-dir.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +1 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/structured.d.ts +19 -0
- package/dist/llm/structured.d.ts.map +1 -1
- package/dist/llm/structured.js +61 -0
- package/dist/llm/structured.js.map +1 -1
- package/dist/mailbox/doctor.d.ts +10 -0
- package/dist/mailbox/doctor.d.ts.map +1 -0
- package/dist/mailbox/doctor.js +33 -0
- package/dist/mailbox/doctor.js.map +1 -0
- package/dist/mailbox/rule.d.ts +34 -0
- package/dist/mailbox/rule.d.ts.map +1 -0
- package/dist/mailbox/rule.js +47 -0
- package/dist/mailbox/rule.js.map +1 -0
- package/dist/mailbox/session.d.ts +5 -0
- package/dist/mailbox/session.d.ts.map +1 -1
- package/dist/mailbox/session.js +8 -0
- package/dist/mailbox/session.js.map +1 -1
- package/dist/mcp/server.d.ts +15 -5
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +75 -27
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +194 -82
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +82 -8
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp-test/adversarial.d.ts +80 -0
- package/dist/mcp-test/adversarial.d.ts.map +1 -0
- package/dist/mcp-test/adversarial.js +99 -0
- package/dist/mcp-test/adversarial.js.map +1 -0
- package/dist/mcp-test/advice.d.ts +20 -0
- package/dist/mcp-test/advice.d.ts.map +1 -0
- package/dist/mcp-test/advice.js +22 -0
- package/dist/mcp-test/advice.js.map +1 -0
- package/dist/mcp-test/call.d.ts +76 -0
- package/dist/mcp-test/call.d.ts.map +1 -0
- package/dist/mcp-test/call.js +105 -0
- package/dist/mcp-test/call.js.map +1 -0
- package/dist/mcp-test/cases.d.ts +154 -0
- package/dist/mcp-test/cases.d.ts.map +1 -0
- package/dist/mcp-test/cases.js +643 -0
- package/dist/mcp-test/cases.js.map +1 -0
- package/dist/mcp-test/connect.d.ts +70 -0
- package/dist/mcp-test/connect.d.ts.map +1 -0
- package/dist/mcp-test/connect.js +426 -0
- package/dist/mcp-test/connect.js.map +1 -0
- package/dist/mcp-test/coverage.d.ts +61 -0
- package/dist/mcp-test/coverage.d.ts.map +1 -0
- package/dist/mcp-test/coverage.js +76 -0
- package/dist/mcp-test/coverage.js.map +1 -0
- package/dist/mcp-test/discover.d.ts +40 -0
- package/dist/mcp-test/discover.d.ts.map +1 -0
- package/dist/mcp-test/discover.js +149 -0
- package/dist/mcp-test/discover.js.map +1 -0
- package/dist/mcp-test/guard.d.ts +161 -0
- package/dist/mcp-test/guard.d.ts.map +1 -0
- package/dist/mcp-test/guard.js +363 -0
- package/dist/mcp-test/guard.js.map +1 -0
- package/dist/mcp-test/model.d.ts +89 -0
- package/dist/mcp-test/model.d.ts.map +1 -0
- package/dist/mcp-test/model.js +88 -0
- package/dist/mcp-test/model.js.map +1 -0
- package/dist/mcp-test/payloads.d.ts +20 -0
- package/dist/mcp-test/payloads.d.ts.map +1 -0
- package/dist/mcp-test/payloads.js +20 -0
- package/dist/mcp-test/payloads.js.map +1 -0
- package/dist/mcp-test/report.d.ts +55 -0
- package/dist/mcp-test/report.d.ts.map +1 -0
- package/dist/mcp-test/report.js +157 -0
- package/dist/mcp-test/report.js.map +1 -0
- package/dist/mcp-test/run.d.ts +68 -0
- package/dist/mcp-test/run.d.ts.map +1 -0
- package/dist/mcp-test/run.js +467 -0
- package/dist/mcp-test/run.js.map +1 -0
- package/dist/mcp-test/runner.d.ts +133 -0
- package/dist/mcp-test/runner.d.ts.map +1 -0
- package/dist/mcp-test/runner.js +412 -0
- package/dist/mcp-test/runner.js.map +1 -0
- package/dist/mcp-test/schema.d.ts +103 -0
- package/dist/mcp-test/schema.d.ts.map +1 -0
- package/dist/mcp-test/schema.js +513 -0
- package/dist/mcp-test/schema.js.map +1 -0
- package/dist/mcp-test/secrets.d.ts +25 -0
- package/dist/mcp-test/secrets.d.ts.map +1 -0
- package/dist/mcp-test/secrets.js +67 -0
- package/dist/mcp-test/secrets.js.map +1 -0
- package/dist/observe/index.d.ts +3 -1
- package/dist/observe/index.d.ts.map +1 -1
- package/dist/observe/index.js +1 -0
- package/dist/observe/index.js.map +1 -1
- package/dist/observe/locator-hints.d.ts +18 -0
- package/dist/observe/locator-hints.d.ts.map +1 -0
- package/dist/observe/locator-hints.js +36 -0
- package/dist/observe/locator-hints.js.map +1 -0
- package/dist/observe/overlays.d.ts +135 -0
- package/dist/observe/overlays.d.ts.map +1 -0
- package/dist/observe/overlays.js +242 -0
- package/dist/observe/overlays.js.map +1 -0
- package/dist/observe/parse-aria.d.ts +7 -1
- package/dist/observe/parse-aria.d.ts.map +1 -1
- package/dist/observe/parse-aria.js +79 -4
- package/dist/observe/parse-aria.js.map +1 -1
- package/dist/probe/index.d.ts +3 -1
- package/dist/probe/index.d.ts.map +1 -1
- package/dist/probe/index.js +3 -2
- package/dist/probe/index.js.map +1 -1
- package/dist/project/index.d.ts +2 -0
- package/dist/project/index.d.ts.map +1 -1
- package/dist/project/index.js +10 -2
- package/dist/project/index.js.map +1 -1
- package/dist/prompts/local/describe-screen.d.ts +7 -0
- package/dist/prompts/local/describe-screen.d.ts.map +1 -0
- package/dist/prompts/local/describe-screen.js +29 -0
- package/dist/prompts/local/describe-screen.js.map +1 -0
- package/dist/prompts/local/index.d.ts.map +1 -1
- package/dist/prompts/local/index.js +7 -0
- package/dist/prompts/local/index.js.map +1 -1
- package/dist/prompts/local/name-overlays.d.ts +6 -0
- package/dist/prompts/local/name-overlays.d.ts.map +1 -0
- package/dist/prompts/local/name-overlays.js +16 -0
- package/dist/prompts/local/name-overlays.js.map +1 -0
- package/dist/prompts/local/qa-api-flows.d.ts +8 -0
- package/dist/prompts/local/qa-api-flows.d.ts.map +1 -0
- package/dist/prompts/local/qa-api-flows.js +19 -0
- package/dist/prompts/local/qa-api-flows.js.map +1 -0
- package/dist/prompts/local/qa-playwright-ts-writer.d.ts +1 -1
- package/dist/prompts/local/qa-playwright-ts-writer.d.ts.map +1 -1
- package/dist/prompts/local/qa-playwright-ts-writer.js +5 -1
- package/dist/prompts/local/qa-playwright-ts-writer.js.map +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.d.ts +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.d.ts.map +1 -1
- package/dist/prompts/local/qa-testcase-from-ui.js +2 -0
- package/dist/prompts/local/qa-testcase-from-ui.js.map +1 -1
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +24 -2
- package/dist/session/index.js.map +1 -1
- package/dist/validate/index.d.ts +11 -0
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +21 -0
- package/dist/validate/index.js.map +1 -1
- package/dist/validate/runner.d.ts +15 -1
- package/dist/validate/runner.d.ts.map +1 -1
- package/dist/validate/runner.js +158 -25
- package/dist/validate/runner.js.map +1 -1
- package/dist/validate/write-guard.d.ts +24 -0
- package/dist/validate/write-guard.d.ts.map +1 -0
- package/dist/validate/write-guard.js +210 -0
- package/dist/validate/write-guard.js.map +1 -0
- package/dist/view/index.d.ts +9 -0
- package/dist/view/index.d.ts.map +1 -0
- package/dist/view/index.js +126 -0
- package/dist/view/index.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
import { stableCaseId } from "../artifacts/contract.js";
|
|
2
|
+
import { safeText } from "./model.js";
|
|
3
|
+
import { maskSecrets } from "./secrets.js";
|
|
4
|
+
import { ROBUST_EXPECTATION, buildCandidates, resolveLimits, } from "./adversarial.js";
|
|
5
|
+
import { CannotBuild, MAX_ARRAY_ITEMS, ORACLE_TIME_LIMIT_MS, OracleTimeout, MAX_STRING_LENGTH, SchemaBuilder, OracleHost, has, isIntegerType, put, scanSchema, } from "./schema.js";
|
|
6
|
+
export const MCP_CASES_VERSION = 1;
|
|
7
|
+
export const DEFAULT_MAX_CASES_PER_TOOL = 12;
|
|
8
|
+
export const CASES_FILE = "mcp-cases.json";
|
|
9
|
+
/** Kinds in the order they are kept when a tool has more cases than the limit allows. */
|
|
10
|
+
export const CASE_KIND_PRIORITY = ["valid", "missing-required", "wrong-type", "boundary", "branch", "enum", "all-params"];
|
|
11
|
+
/** The time all schema checks of one run may take together; tools after that are skipped by name. */
|
|
12
|
+
export const TOTAL_TIME_BUDGET_MS = 15000;
|
|
13
|
+
export const BUDGET_SPENT_REASON = "time budget for checking schemas was spent";
|
|
14
|
+
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
15
|
+
const clone = (v) => JSON.parse(JSON.stringify(v));
|
|
16
|
+
/** A JSON pointer to a top-level property. */
|
|
17
|
+
const pointerTo = (k) => `/${k.replace(/~/g, "~0").replace(/\//g, "~1")}`;
|
|
18
|
+
const failsFor = (errors, r) => errors.some((e) => e.keyword === r.keyword && e.path === r.path && (r.missing === undefined || e.missing === r.missing));
|
|
19
|
+
/** Every part of an id keeps case and spaces: stableCaseId folds them, the code points do not fold. */
|
|
20
|
+
const exact = (text) => Array.from(text, (c) => c.codePointAt(0).toString(16)).join(".");
|
|
21
|
+
const TECHNIQUE = {
|
|
22
|
+
valid: "equivalence-partitioning",
|
|
23
|
+
"all-params": "equivalence-partitioning",
|
|
24
|
+
enum: "equivalence-partitioning",
|
|
25
|
+
branch: "equivalence-partitioning",
|
|
26
|
+
"missing-required": "error-guessing",
|
|
27
|
+
"wrong-type": "error-guessing",
|
|
28
|
+
boundary: "boundary-value",
|
|
29
|
+
};
|
|
30
|
+
const RATIONALE = {
|
|
31
|
+
valid: "Only the required arguments, with the simplest values the schema allows.",
|
|
32
|
+
"all-params": "Every declared argument at once.",
|
|
33
|
+
enum: "One of the values the schema lists for this argument.",
|
|
34
|
+
branch: "One branch of the schema's oneOf/anyOf.",
|
|
35
|
+
"missing-required": "A required argument is left out; the schema forbids it.",
|
|
36
|
+
"wrong-type": "An argument has a value of a type the schema does not allow.",
|
|
37
|
+
boundary: "A value on or just beyond a limit the schema sets.",
|
|
38
|
+
};
|
|
39
|
+
/** Values of other JSON types to try, in this order, when a wrong type is needed. */
|
|
40
|
+
const WRONG_TYPE_CANDIDATES = [12345, "text", true, null, [], {}];
|
|
41
|
+
function expectFor(type, tool) {
|
|
42
|
+
return type === "Positive"
|
|
43
|
+
? { outcome: "success", outputSchema: tool.outputSchema !== undefined }
|
|
44
|
+
: { outcome: "rejected", forms: [{ jsonRpcErrorCode: -32602 }, { resultIsError: true }] };
|
|
45
|
+
}
|
|
46
|
+
function why(e) {
|
|
47
|
+
if (e instanceof CannotBuild)
|
|
48
|
+
return { keyword: e.keyword, reason: safeText(e.message, 200) };
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
function boundaryCandidates(prop, schema, builder, base) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const num = (k) => (typeof schema[k] === "number" ? schema[k] : undefined);
|
|
54
|
+
const integer = isIntegerType(schema);
|
|
55
|
+
const step = integer ? 1 : 0.5;
|
|
56
|
+
const withValue = (v) => ({ ...base(), [prop]: v });
|
|
57
|
+
const add = (keyword, side, type, v) => {
|
|
58
|
+
out.push({
|
|
59
|
+
kind: "boundary",
|
|
60
|
+
detail: `${prop}.${keyword}.${side}`,
|
|
61
|
+
type,
|
|
62
|
+
make: () => withValue(v()),
|
|
63
|
+
...(type === "Negative" ? { reason: { keyword, path: pointerTo(prop) } } : {}),
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const min = num("minimum");
|
|
67
|
+
const max = num("maximum");
|
|
68
|
+
const exMin = num("exclusiveMinimum");
|
|
69
|
+
const exMax = num("exclusiveMaximum");
|
|
70
|
+
if (min !== undefined) {
|
|
71
|
+
add("minimum", "on", "Positive", () => min);
|
|
72
|
+
add("minimum", "beyond", "Negative", () => min - step);
|
|
73
|
+
}
|
|
74
|
+
if (max !== undefined) {
|
|
75
|
+
add("maximum", "on", "Positive", () => max);
|
|
76
|
+
add("maximum", "beyond", "Negative", () => max + step);
|
|
77
|
+
}
|
|
78
|
+
if (exMin !== undefined) {
|
|
79
|
+
add("exclusiveMinimum", "on", "Negative", () => exMin);
|
|
80
|
+
add("exclusiveMinimum", "beyond", "Positive", () => exMin + step);
|
|
81
|
+
}
|
|
82
|
+
if (exMax !== undefined) {
|
|
83
|
+
add("exclusiveMaximum", "on", "Negative", () => exMax);
|
|
84
|
+
add("exclusiveMaximum", "beyond", "Positive", () => exMax - step);
|
|
85
|
+
}
|
|
86
|
+
const minLength = num("minLength");
|
|
87
|
+
const maxLength = num("maxLength");
|
|
88
|
+
const text = (n) => {
|
|
89
|
+
if (n > MAX_STRING_LENGTH)
|
|
90
|
+
throw new CannotBuild("maxLength", `the string needs ${n} characters; the limit is ${MAX_STRING_LENGTH}`);
|
|
91
|
+
return "a".repeat(Math.max(0, n));
|
|
92
|
+
};
|
|
93
|
+
if (minLength !== undefined) {
|
|
94
|
+
add("minLength", "on", "Positive", () => text(minLength));
|
|
95
|
+
if (minLength > 0)
|
|
96
|
+
add("minLength", "beyond", "Negative", () => text(minLength - 1));
|
|
97
|
+
}
|
|
98
|
+
if (maxLength !== undefined) {
|
|
99
|
+
add("maxLength", "on", "Positive", () => text(maxLength));
|
|
100
|
+
add("maxLength", "beyond", "Negative", () => text(maxLength + 1));
|
|
101
|
+
}
|
|
102
|
+
const minItems = num("minItems");
|
|
103
|
+
const maxItems = num("maxItems");
|
|
104
|
+
const items = (n) => {
|
|
105
|
+
if (n > MAX_ARRAY_ITEMS)
|
|
106
|
+
throw new CannotBuild("maxItems", `the array needs ${n} items; the limit is ${MAX_ARRAY_ITEMS}`);
|
|
107
|
+
const one = schema["items"] === undefined ? "value" : builder.value(schema["items"], 1);
|
|
108
|
+
return Array.from({ length: Math.max(0, n) }, () => clone(one));
|
|
109
|
+
};
|
|
110
|
+
if (minItems !== undefined) {
|
|
111
|
+
add("minItems", "on", "Positive", () => items(minItems));
|
|
112
|
+
if (minItems > 0)
|
|
113
|
+
add("minItems", "beyond", "Negative", () => items(minItems - 1));
|
|
114
|
+
}
|
|
115
|
+
if (maxItems !== undefined) {
|
|
116
|
+
add("maxItems", "on", "Positive", () => items(maxItems));
|
|
117
|
+
add("maxItems", "beyond", "Negative", () => items(maxItems + 1));
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
function casesForTool(tool, opts, host) {
|
|
122
|
+
const skipped = [];
|
|
123
|
+
const errors = [];
|
|
124
|
+
const skipTool = (e) => {
|
|
125
|
+
const w = why(e);
|
|
126
|
+
skipped.push({ tool: tool.name, kind: "tool", detail: "", ...w });
|
|
127
|
+
return { cases: [], skipped, errors };
|
|
128
|
+
};
|
|
129
|
+
const problem = scanSchema(tool.inputSchema);
|
|
130
|
+
if (problem)
|
|
131
|
+
return skipTool(problem);
|
|
132
|
+
let oracle;
|
|
133
|
+
let builder;
|
|
134
|
+
let rootView;
|
|
135
|
+
try {
|
|
136
|
+
oracle = host.oracle(tool.inputSchema);
|
|
137
|
+
builder = new SchemaBuilder(tool.inputSchema);
|
|
138
|
+
rootView = builder.view(tool.inputSchema);
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
return skipTool(e);
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
return buildCases(tool, opts, oracle, builder, rootView);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
// The schema check ran out of time or could not run: the tool gives no cases, only this entry.
|
|
148
|
+
if (e instanceof CannotBuild)
|
|
149
|
+
return skipTool(e);
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function buildCases(tool, opts, oracle, builder, rootView) {
|
|
154
|
+
const skipped = [];
|
|
155
|
+
const errors = [];
|
|
156
|
+
const props = isObj(rootView["properties"]) ? rootView["properties"] : {};
|
|
157
|
+
const propNames = Object.keys(props).sort();
|
|
158
|
+
if (propNames.length === 0)
|
|
159
|
+
return { cases: [], skipped, noCases: true, errors };
|
|
160
|
+
const required = [...new Set((Array.isArray(rootView["required"]) ? rootView["required"] : []).filter((r) => typeof r === "string"))].sort();
|
|
161
|
+
// The arguments of the `valid` case: the file's, or built from the schema.
|
|
162
|
+
let source = "schema";
|
|
163
|
+
let baseArgs;
|
|
164
|
+
const fromFile = opts.examples.get(tool.name);
|
|
165
|
+
if (fromFile !== undefined) {
|
|
166
|
+
source = "examples-file";
|
|
167
|
+
baseArgs = clone(fromFile);
|
|
168
|
+
const r = oracle.check(baseArgs);
|
|
169
|
+
if (!r.valid) {
|
|
170
|
+
errors.push({
|
|
171
|
+
tool: tool.name,
|
|
172
|
+
message: `the value given in --examples for "${safeText(tool.name, 60)}" does not pass the tool's inputSchema (${r.keyword ?? "unknown keyword"}${r.path ? ` at ${safeText(r.path, 60)}` : ""})`,
|
|
173
|
+
});
|
|
174
|
+
return { cases: [], skipped, errors };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
try {
|
|
179
|
+
const built = builder.value(tool.inputSchema);
|
|
180
|
+
baseArgs = isObj(built) ? built : undefined;
|
|
181
|
+
if (!baseArgs)
|
|
182
|
+
throw new CannotBuild("type", "the input schema does not describe an object");
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
const w = why(e);
|
|
186
|
+
skipped.push({ tool: tool.name, kind: "valid", detail: "", ...w });
|
|
187
|
+
return { cases: [], skipped, errors };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const base = () => clone(baseArgs);
|
|
191
|
+
const cands = [{ kind: "valid", detail: "required", type: "Positive", make: base }];
|
|
192
|
+
for (const k of required) {
|
|
193
|
+
if (has(baseArgs, k)) {
|
|
194
|
+
cands.push({
|
|
195
|
+
kind: "missing-required",
|
|
196
|
+
detail: k,
|
|
197
|
+
type: "Negative",
|
|
198
|
+
make: () => {
|
|
199
|
+
const a = base();
|
|
200
|
+
delete a[k];
|
|
201
|
+
return a;
|
|
202
|
+
},
|
|
203
|
+
reason: { keyword: "required", path: "", missing: k },
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
for (const k of propNames) {
|
|
208
|
+
cands.push({
|
|
209
|
+
kind: "wrong-type",
|
|
210
|
+
detail: k,
|
|
211
|
+
type: "Negative",
|
|
212
|
+
reason: { keyword: "type", path: pointerTo(k) },
|
|
213
|
+
make: () => {
|
|
214
|
+
for (const w of WRONG_TYPE_CANDIDATES) {
|
|
215
|
+
const a = { ...base(), [k]: clone(w) };
|
|
216
|
+
const r = oracle.check(a);
|
|
217
|
+
if (!r.valid && failsFor(r.errors, { keyword: "type", path: pointerTo(k) }))
|
|
218
|
+
return a;
|
|
219
|
+
}
|
|
220
|
+
throw new CannotBuild("type", `no value of another JSON type is refused by a type check for "${safeText(k, 60)}"`);
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
for (const k of propNames) {
|
|
225
|
+
try {
|
|
226
|
+
cands.push(...boundaryCandidates(k, builder.view(props[k]), builder, base));
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
skipped.push({ tool: tool.name, kind: "boundary", detail: k, ...why(e) });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const addBranches = (detailPrefix, owner, place) => {
|
|
233
|
+
let list;
|
|
234
|
+
try {
|
|
235
|
+
list = builder.branches(owner);
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
skipped.push({ tool: tool.name, kind: "branch", detail: detailPrefix || "root", ...why(e) });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
for (const b of list) {
|
|
242
|
+
const detail = `${detailPrefix}${b.keyword}[${b.index}]`;
|
|
243
|
+
cands.push({ kind: "branch", detail, type: "Positive", make: () => place(builder.value(b.schema, 1)), covers: { branch: detail } });
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
addBranches("", tool.inputSchema, (v) => {
|
|
247
|
+
if (!isObj(v))
|
|
248
|
+
throw new CannotBuild("type", "the branch does not describe an object");
|
|
249
|
+
return v;
|
|
250
|
+
});
|
|
251
|
+
for (const k of propNames)
|
|
252
|
+
addBranches(`${k}.`, props[k], (v) => ({ ...base(), [k]: v }));
|
|
253
|
+
for (const k of propNames) {
|
|
254
|
+
let view;
|
|
255
|
+
try {
|
|
256
|
+
view = builder.view(props[k]);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (!Array.isArray(view["enum"]))
|
|
262
|
+
continue;
|
|
263
|
+
const seenValues = new Set();
|
|
264
|
+
for (const v of view["enum"].slice(0, 32)) {
|
|
265
|
+
if (seenValues.has(JSON.stringify(v)))
|
|
266
|
+
continue;
|
|
267
|
+
seenValues.add(JSON.stringify(v));
|
|
268
|
+
cands.push({ kind: "enum", detail: `${k}=${JSON.stringify(v)}`, type: "Positive", make: () => ({ ...base(), [k]: clone(v) }), covers: { param: k, enumValue: JSON.stringify(v) } });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
cands.push({
|
|
272
|
+
kind: "all-params",
|
|
273
|
+
detail: "all",
|
|
274
|
+
type: "Positive",
|
|
275
|
+
make: () => {
|
|
276
|
+
const a = base();
|
|
277
|
+
for (const k of propNames)
|
|
278
|
+
if (!has(a, k))
|
|
279
|
+
put(a, k, builder.value(props[k], 1));
|
|
280
|
+
return a;
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
// The oracle decides. Order by kind priority first (stable inside a kind), so the cut keeps the most useful ones.
|
|
284
|
+
const kept = [];
|
|
285
|
+
const seenArgs = new Set();
|
|
286
|
+
for (const kind of CASE_KIND_PRIORITY) {
|
|
287
|
+
for (const cand of cands.filter((c) => c.kind === kind)) {
|
|
288
|
+
let args;
|
|
289
|
+
try {
|
|
290
|
+
args = cand.make();
|
|
291
|
+
}
|
|
292
|
+
catch (e) {
|
|
293
|
+
skipped.push({ tool: tool.name, kind: cand.kind, detail: cand.detail, ...why(e) });
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const r = oracle.check(args);
|
|
297
|
+
if (cand.type === "Negative" && !r.valid && cand.reason && !failsFor(r.errors, cand.reason)) {
|
|
298
|
+
skipped.push({
|
|
299
|
+
tool: tool.name,
|
|
300
|
+
kind: cand.kind,
|
|
301
|
+
detail: cand.detail,
|
|
302
|
+
keyword: cand.reason.keyword,
|
|
303
|
+
reason: `the schema refuses it, but not for the reason of its kind (no ${cand.reason.keyword} error${cand.reason.path ? ` at ${safeText(cand.reason.path, 60)}` : ""}; first error: ${r.keyword ?? "unknown"})`,
|
|
304
|
+
});
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if ((cand.type === "Positive") !== r.valid) {
|
|
308
|
+
skipped.push({
|
|
309
|
+
tool: tool.name,
|
|
310
|
+
kind: cand.kind,
|
|
311
|
+
detail: cand.detail,
|
|
312
|
+
keyword: r.keyword ?? "schema",
|
|
313
|
+
reason: cand.type === "Positive" ? `the schema refuses it (${r.keyword ?? "unknown keyword"})` : "the schema accepts it, so it cannot be a negative case",
|
|
314
|
+
});
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const key = `${cand.type}:${JSON.stringify(args)}`;
|
|
318
|
+
// Every-argument-at-once adds nothing when it equals the valid case. Other kinds are kept even when their arguments
|
|
319
|
+
// match another case: which of two equal cases survives must not depend on the order of the schema's lists.
|
|
320
|
+
if (cand.kind === "all-params" && seenArgs.has(key))
|
|
321
|
+
continue;
|
|
322
|
+
seenArgs.add(key);
|
|
323
|
+
kept.push({ cand, args });
|
|
324
|
+
}
|
|
325
|
+
if (kind === "valid" && kept.length === 0) {
|
|
326
|
+
// Every other case is the valid one with one change; without a valid base none of them proves what it claims.
|
|
327
|
+
const first = skipped.find((x) => x.tool === tool.name && x.kind === "valid");
|
|
328
|
+
skipped.push({
|
|
329
|
+
tool: tool.name,
|
|
330
|
+
kind: "tool",
|
|
331
|
+
detail: "derived cases",
|
|
332
|
+
keyword: first?.keyword ?? "schema",
|
|
333
|
+
reason: "there is no valid case to start from, so no case was made for this tool",
|
|
334
|
+
});
|
|
335
|
+
return { cases: [], skipped, errors };
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// An id is a function of the exact tool name, kind and detail alone: not of the order, the limit or the values.
|
|
339
|
+
const cases = kept.map(({ cand, args }) => {
|
|
340
|
+
return {
|
|
341
|
+
name: `${tool.name} · ${cand.kind} · ${cand.detail}`,
|
|
342
|
+
stableId: stableCaseId(["mcp", exact(tool.name), exact(cand.kind), exact(cand.detail)]),
|
|
343
|
+
tool: tool.name,
|
|
344
|
+
kind: cand.kind,
|
|
345
|
+
detail: cand.detail,
|
|
346
|
+
type: cand.type,
|
|
347
|
+
technique: TECHNIQUE[cand.kind],
|
|
348
|
+
rationale: RATIONALE[cand.kind],
|
|
349
|
+
args,
|
|
350
|
+
expect: expectFor(cand.type, tool),
|
|
351
|
+
source: cand.kind === "valid" ? source : "schema",
|
|
352
|
+
...(cand.covers ? { covers: cand.covers } : {}),
|
|
353
|
+
...styleTag(cand.kind, opts),
|
|
354
|
+
};
|
|
355
|
+
});
|
|
356
|
+
const adversarialOut = opts.adversarial ? adversarialFor(tool, opts.adversarial, oracle, builder, rootView, props, propNames, baseArgs, skipped) : undefined;
|
|
357
|
+
const advPart = adversarialOut ? { adversarial: adversarialOut.cases, adversarialCut: adversarialOut.cut } : {};
|
|
358
|
+
if (cases.length <= opts.maxCasesPerTool)
|
|
359
|
+
return { cases, skipped, errors, ...advPart };
|
|
360
|
+
const left = cases.slice(opts.maxCasesPerTool);
|
|
361
|
+
const kinds = {};
|
|
362
|
+
for (const c of left)
|
|
363
|
+
kinds[c.kind] = (kinds[c.kind] ?? 0) + 1;
|
|
364
|
+
return { cases: cases.slice(0, opts.maxCasesPerTool), skipped, cut: { tool: tool.name, count: left.length, kinds }, errors, ...advPart };
|
|
365
|
+
}
|
|
366
|
+
function styleTag(kind, opts) {
|
|
367
|
+
const styles = opts.adversarial?.styles ?? [];
|
|
368
|
+
if (kind === "valid" && styles.includes("normal"))
|
|
369
|
+
return { adversarialStyle: "normal" };
|
|
370
|
+
if ((kind === "all-params" || kind === "enum" || kind === "branch") && styles.includes("curious"))
|
|
371
|
+
return { adversarialStyle: "curious" };
|
|
372
|
+
return {};
|
|
373
|
+
}
|
|
374
|
+
/** The type of a parameter as its schema says it (first non-null type; for a oneOf/anyOf, that of the first branch). */
|
|
375
|
+
function paramType(builder, raw) {
|
|
376
|
+
const typeOf = (v) => {
|
|
377
|
+
const t = v["type"];
|
|
378
|
+
if (typeof t === "string")
|
|
379
|
+
return t;
|
|
380
|
+
return Array.isArray(t) ? t.find((x) => typeof x === "string" && x !== "null") : undefined;
|
|
381
|
+
};
|
|
382
|
+
try {
|
|
383
|
+
const own = typeOf(builder.view(raw));
|
|
384
|
+
if (own)
|
|
385
|
+
return own;
|
|
386
|
+
const first = builder.branches(raw)[0];
|
|
387
|
+
return first ? typeOf(first.schema) : undefined;
|
|
388
|
+
}
|
|
389
|
+
catch {
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
export function adversarialFor(tool, adv, oracle, builder, rootView, props, propNames, base, skipped) {
|
|
394
|
+
const targets = {};
|
|
395
|
+
for (const k of propNames) {
|
|
396
|
+
const t = paramType(builder, props[k]);
|
|
397
|
+
if ((t === "integer" || t === "number") && targets.number === undefined)
|
|
398
|
+
targets.number = k;
|
|
399
|
+
else if (t === "string" && targets.string === undefined)
|
|
400
|
+
targets.string = k;
|
|
401
|
+
else if (t === "array" && targets.array === undefined)
|
|
402
|
+
targets.array = k;
|
|
403
|
+
else if (t === "object" && targets.object === undefined)
|
|
404
|
+
targets.object = k;
|
|
405
|
+
}
|
|
406
|
+
const baseText = JSON.stringify(base);
|
|
407
|
+
const out = [];
|
|
408
|
+
// After the first schema check that fails (it ran out of time, say) the rest are not tried one by one against it.
|
|
409
|
+
let broken;
|
|
410
|
+
let notChecked = 0;
|
|
411
|
+
for (const c of buildCandidates(base, targets, rootView["additionalProperties"] === false, adv.styles, adv.limits)) {
|
|
412
|
+
if (JSON.stringify(c.args) === baseText)
|
|
413
|
+
continue;
|
|
414
|
+
if (broken) {
|
|
415
|
+
notChecked += 1;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
let passes;
|
|
419
|
+
try {
|
|
420
|
+
passes = oracle.check(c.args).valid;
|
|
421
|
+
}
|
|
422
|
+
catch (e) {
|
|
423
|
+
if (!(e instanceof CannotBuild))
|
|
424
|
+
throw e;
|
|
425
|
+
const detail = `${c.style} · ${c.kind}`;
|
|
426
|
+
if (e instanceof OracleTimeout) {
|
|
427
|
+
// The time of this tool's schema check is spent: the rest are not tried against it one by one.
|
|
428
|
+
broken = { keyword: e.keyword, reason: `the schema check of this tool took too long (more than ${ORACLE_TIME_LIMIT_MS} ms; a pattern may backtrack badly), so its adversarial cases were skipped` };
|
|
429
|
+
skipped.push({ tool: tool.name, kind: "adversarial", detail, ...broken });
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
// This one candidate cannot be checked; the next may be.
|
|
433
|
+
skipped.push({ tool: tool.name, kind: "adversarial", detail, keyword: e.keyword, reason: safeText(e.message, 200) });
|
|
434
|
+
}
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
out.push({
|
|
438
|
+
name: `${tool.name} · ${c.style} · ${c.kind} · ${c.target}`,
|
|
439
|
+
stableId: stableCaseId(["mcp-adv", exact(tool.name), exact(c.style), exact(c.kind), exact(c.target)]),
|
|
440
|
+
tool: tool.name,
|
|
441
|
+
kind: c.kind,
|
|
442
|
+
style: c.style,
|
|
443
|
+
target: c.target,
|
|
444
|
+
schemaVerdict: passes ? "passes" : "fails",
|
|
445
|
+
type: passes ? "Positive" : "Negative",
|
|
446
|
+
technique: c.technique,
|
|
447
|
+
...(c.wstgId ? { wstgId: c.wstgId } : {}),
|
|
448
|
+
rationale: c.rationale,
|
|
449
|
+
args: c.args,
|
|
450
|
+
expect: ROBUST_EXPECTATION,
|
|
451
|
+
humanOracle: c.humanOracle,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
if (broken && notChecked) {
|
|
455
|
+
skipped.push({
|
|
456
|
+
tool: tool.name,
|
|
457
|
+
kind: "adversarial",
|
|
458
|
+
detail: "the rest",
|
|
459
|
+
keyword: broken.keyword,
|
|
460
|
+
reason: `${notChecked} more adversarial cases were not checked, because the check of this tool's schema failed first`,
|
|
461
|
+
count: notChecked,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const kept = out.slice(0, adv.limits.maxPerTool);
|
|
465
|
+
return { cases: kept, cut: out.length - kept.length };
|
|
466
|
+
}
|
|
467
|
+
/** Test cases for every tool, in the order of the tools' names. */
|
|
468
|
+
export function generateMcpCases(tools, options = {}) {
|
|
469
|
+
const maxCasesPerTool = options.maxCasesPerTool ?? DEFAULT_MAX_CASES_PER_TOOL;
|
|
470
|
+
const report = { version: MCP_CASES_VERSION, maxCasesPerTool, cases: [], skipped: [], cut: [], noCases: [], errors: [] };
|
|
471
|
+
const examples = new Map(Object.entries(options.examples ?? {}));
|
|
472
|
+
const advLimits = options.adversarial ? resolveLimits(options.adversarial) : undefined;
|
|
473
|
+
const advStyles = options.adversarial?.styles ?? [];
|
|
474
|
+
const adversarial = options.adversarial && advLimits && advStyles.length ? { styles: advStyles, limits: advLimits } : undefined;
|
|
475
|
+
if (adversarial) {
|
|
476
|
+
report.adversarial = [];
|
|
477
|
+
report.adversarialLimits = { ...adversarial.limits, styles: [...adversarial.styles] };
|
|
478
|
+
report.adversarialCut = [];
|
|
479
|
+
}
|
|
480
|
+
// Two tools with one exact name: neither is trusted, so the result does not depend on the order the server sent them.
|
|
481
|
+
const copies = new Map();
|
|
482
|
+
for (const tool of tools)
|
|
483
|
+
copies.set(tool.name, (copies.get(tool.name) ?? 0) + 1);
|
|
484
|
+
const budgetEnd = Date.now() + (options.timeBudgetMs ?? TOTAL_TIME_BUDGET_MS);
|
|
485
|
+
const host = new OracleHost();
|
|
486
|
+
try {
|
|
487
|
+
runTools(tools, copies, examples, maxCasesPerTool, budgetEnd, host, report, adversarial);
|
|
488
|
+
}
|
|
489
|
+
finally {
|
|
490
|
+
host.close();
|
|
491
|
+
}
|
|
492
|
+
return finish(report, options);
|
|
493
|
+
}
|
|
494
|
+
function runTools(tools, copies, examples, maxCasesPerTool, budgetEnd, host, report, adversarial) {
|
|
495
|
+
const reported = new Set();
|
|
496
|
+
for (const tool of [...tools].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
|
|
497
|
+
const n = copies.get(tool.name) ?? 1;
|
|
498
|
+
if (n > 1) {
|
|
499
|
+
if (!reported.has(tool.name)) {
|
|
500
|
+
reported.add(tool.name);
|
|
501
|
+
report.skipped.push({ tool: tool.name, kind: "tool", detail: "", keyword: "name", reason: `${n} tools have this exact name; none of them is used` });
|
|
502
|
+
}
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
if (Date.now() >= budgetEnd) {
|
|
506
|
+
report.skipped.push({ tool: tool.name, kind: "tool", detail: "", keyword: "budget", reason: BUDGET_SPENT_REASON });
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const r = casesForTool(tool, { maxCasesPerTool, examples, ...(adversarial ? { adversarial } : {}) }, host);
|
|
510
|
+
if (r.adversarial && report.adversarial) {
|
|
511
|
+
report.adversarial.push(...r.adversarial);
|
|
512
|
+
if (r.adversarialCut)
|
|
513
|
+
report.adversarialCut?.push({ tool: tool.name, count: r.adversarialCut, scope: "per-tool" });
|
|
514
|
+
}
|
|
515
|
+
report.cases.push(...r.cases);
|
|
516
|
+
report.skipped.push(...r.skipped);
|
|
517
|
+
report.errors.push(...r.errors);
|
|
518
|
+
if (examples.has(tool.name) && r.cases.length === 0 && r.errors.length === 0) {
|
|
519
|
+
report.errors.push({ tool: tool.name, message: `--examples gives a value for "${safeText(tool.name, 60)}", but no cases could be made for that tool (${r.noCases ? "its input schema declares no properties" : "see skipped"})` });
|
|
520
|
+
}
|
|
521
|
+
if (r.cut)
|
|
522
|
+
report.cut.push(r.cut);
|
|
523
|
+
if (r.noCases)
|
|
524
|
+
report.noCases.push(tool.name);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
function finish(report, options) {
|
|
528
|
+
const adv = report.adversarial;
|
|
529
|
+
if (adv && report.adversarialLimits) {
|
|
530
|
+
// The cap for the whole run: the first cases in the order of tool names stay.
|
|
531
|
+
const room = report.adversarialLimits.maxPerRun;
|
|
532
|
+
if (adv.length > room) {
|
|
533
|
+
const lost = new Map();
|
|
534
|
+
for (const c of adv.slice(room))
|
|
535
|
+
lost.set(c.tool, (lost.get(c.tool) ?? 0) + 1);
|
|
536
|
+
adv.length = room;
|
|
537
|
+
for (const [tool, count] of lost)
|
|
538
|
+
report.adversarialCut?.push({ tool, count, scope: "per-run" });
|
|
539
|
+
}
|
|
540
|
+
const o = options.adversarial;
|
|
541
|
+
if (o?.styles.includes("hacker") && o.http?.authenticated) {
|
|
542
|
+
const name = (o.allowTools ?? []).find((n) => report.cases.some((c) => c.tool === n && c.kind === "valid"));
|
|
543
|
+
const valid = name === undefined ? undefined : report.cases.find((c) => c.tool === name && c.kind === "valid");
|
|
544
|
+
if (valid)
|
|
545
|
+
report.noCredentials = { tool: valid.tool, args: valid.args, expectAuth: o.expectAuth === true, sent: false };
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
// One id per case, one name per case, in the whole run. Names that read the same (a tool name can hold " · ") also carry the id.
|
|
549
|
+
const ids = new Set();
|
|
550
|
+
for (const c of [...report.cases, ...(report.adversarial ?? [])]) {
|
|
551
|
+
if (ids.has(c.stableId))
|
|
552
|
+
throw new Error(`internal error: two cases share the id ${c.stableId} (${c.name})`);
|
|
553
|
+
ids.add(c.stableId);
|
|
554
|
+
}
|
|
555
|
+
const labelCount = new Map();
|
|
556
|
+
for (const c of [...report.cases, ...(report.adversarial ?? [])])
|
|
557
|
+
labelCount.set(c.name, (labelCount.get(c.name) ?? 0) + 1);
|
|
558
|
+
for (const c of [...report.cases, ...(report.adversarial ?? [])])
|
|
559
|
+
if ((labelCount.get(c.name) ?? 0) > 1)
|
|
560
|
+
c.name = `${c.name} [${c.stableId}]`;
|
|
561
|
+
return report;
|
|
562
|
+
}
|
|
563
|
+
/** Console lines. Everything that comes from the server goes through safeText. */
|
|
564
|
+
export function renderCasesSummary(report) {
|
|
565
|
+
const lines = [];
|
|
566
|
+
const byTool = new Map();
|
|
567
|
+
for (const c of report.cases)
|
|
568
|
+
byTool.set(c.tool, [...(byTool.get(c.tool) ?? []), c]);
|
|
569
|
+
const pos = report.cases.filter((c) => c.type === "Positive").length;
|
|
570
|
+
const spent = report.skipped.filter((x) => x.keyword === "budget").length;
|
|
571
|
+
lines.push(`Cases from inputSchema: ${report.cases.length} (${pos} positive, ${report.cases.length - pos} negative); nothing was sent.`);
|
|
572
|
+
for (const [tool, list] of byTool) {
|
|
573
|
+
const kinds = {};
|
|
574
|
+
for (const c of list)
|
|
575
|
+
kinds[c.kind] = (kinds[c.kind] ?? 0) + 1;
|
|
576
|
+
lines.push(` ${safeText(tool, 60)}: ${list.length} (${Object.entries(kinds).map(([k, n]) => `${k} ${n}`).join(", ")})`);
|
|
577
|
+
}
|
|
578
|
+
if (spent)
|
|
579
|
+
lines.push(` ${spent} tools skipped: ${BUDGET_SPENT_REASON}.`);
|
|
580
|
+
for (const t of report.noCases)
|
|
581
|
+
lines.push(` ${safeText(t, 60)}: no cases (the input schema declares no properties).`);
|
|
582
|
+
for (const c of report.cut) {
|
|
583
|
+
lines.push(` ${safeText(c.tool, 60)}: ${c.count} more cut at --max-cases-per-tool ${report.maxCasesPerTool} (${Object.entries(c.kinds).map(([k, n]) => `${k} ${n}`).join(", ")}).`);
|
|
584
|
+
}
|
|
585
|
+
if (report.adversarial && report.adversarialLimits) {
|
|
586
|
+
const adv = report.adversarial;
|
|
587
|
+
const by = {};
|
|
588
|
+
for (const c of adv)
|
|
589
|
+
by[c.style] = (by[c.style] ?? 0) + 1;
|
|
590
|
+
lines.push(`Adversarial cases: ${adv.length} (${Object.entries(by).map(([k, n]) => `${k} ${n}`).join(", ") || "none"}); string length ${report.adversarialLimits.maxStringLength}, depth ${report.adversarialLimits.maxDepth}.`);
|
|
591
|
+
const human = adv.filter((c) => c.humanOracle).length;
|
|
592
|
+
if (human)
|
|
593
|
+
lines.push(` ${human} of them need a human-defined oracle: whether the payload was handled safely is not decided by a rule.`);
|
|
594
|
+
for (const c of report.adversarialCut ?? []) {
|
|
595
|
+
lines.push(` ${safeText(c.tool, 60)}: ${c.count} adversarial cases cut at the cap (${c.scope === "per-tool" ? `${report.adversarialLimits.maxPerTool} per tool` : `${report.adversarialLimits.maxPerRun} per run`}).`);
|
|
596
|
+
}
|
|
597
|
+
const advSkipped = report.skipped.filter((x) => x.kind === "adversarial").reduce((n, x) => n + (x.count ?? 1), 0);
|
|
598
|
+
if (advSkipped)
|
|
599
|
+
lines.push(` ${advSkipped} adversarial cases skipped (see skipped).`);
|
|
600
|
+
if (report.noCredentials) {
|
|
601
|
+
lines.push(` A call without credentials is described for ${safeText(report.noCredentials.tool, 60)} (once per server, not sent${report.noCredentials.expectAuth ? "; a pass would be a failure" : "; a pass would be a finding"}).`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
if (report.skipped.length) {
|
|
605
|
+
lines.push(` Skipped (${report.skipped.length}):`);
|
|
606
|
+
for (const s of report.skipped.slice(0, 20)) {
|
|
607
|
+
lines.push(` ${safeText(s.tool, 60)} · ${s.kind}${s.detail ? ` · ${safeText(s.detail, 60)}` : ""}: ${safeText(s.keyword, 40)} — ${safeText(s.reason, 160)}`);
|
|
608
|
+
}
|
|
609
|
+
if (report.skipped.length > 20)
|
|
610
|
+
lines.push(` … and ${report.skipped.length - 20} more (see ${CASES_FILE}).`);
|
|
611
|
+
}
|
|
612
|
+
return lines;
|
|
613
|
+
}
|
|
614
|
+
/** Cases whose arguments hold something the secret list masks are moved to `skipped`: a masked value would no longer match the schema. */
|
|
615
|
+
export function dropMaskedCases(report, secrets) {
|
|
616
|
+
const keep = [];
|
|
617
|
+
const skipped = [...report.skipped];
|
|
618
|
+
for (const c of report.cases) {
|
|
619
|
+
const text = JSON.stringify(c.args);
|
|
620
|
+
if (maskSecrets(text, secrets) === text)
|
|
621
|
+
keep.push(c);
|
|
622
|
+
else
|
|
623
|
+
skipped.push({ tool: c.tool, kind: c.kind, detail: c.detail, keyword: "masked", reason: "value masked" });
|
|
624
|
+
}
|
|
625
|
+
const advKeep = [];
|
|
626
|
+
for (const c of report.adversarial ?? []) {
|
|
627
|
+
const text = JSON.stringify(c.args);
|
|
628
|
+
if (maskSecrets(text, secrets) === text)
|
|
629
|
+
advKeep.push(c);
|
|
630
|
+
else
|
|
631
|
+
skipped.push({ tool: c.tool, kind: "adversarial", detail: `${c.style} · ${c.kind}`, keyword: "masked", reason: "value masked" });
|
|
632
|
+
}
|
|
633
|
+
const out = { ...report, cases: keep, skipped, ...(report.adversarial ? { adversarial: advKeep } : {}) };
|
|
634
|
+
if (report.noCredentials) {
|
|
635
|
+
const text = JSON.stringify(report.noCredentials.args);
|
|
636
|
+
if (maskSecrets(text, secrets) !== text) {
|
|
637
|
+
delete out.noCredentials;
|
|
638
|
+
skipped.push({ tool: report.noCredentials.tool, kind: "adversarial", detail: "no-credentials", keyword: "masked", reason: "value masked" });
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return out;
|
|
642
|
+
}
|
|
643
|
+
//# sourceMappingURL=cases.js.map
|