vibecode-anything 0.3.0 → 0.4.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 +239 -67
- package/dist/cli.js +2140 -73
- package/dist/core/adapters.d.ts +26 -3
- package/dist/core/adapters.js +411 -25
- package/dist/core/agent-adapter.d.ts +67 -0
- package/dist/core/agent-adapter.js +312 -0
- package/dist/core/anti-cheat.d.ts +6 -0
- package/dist/core/anti-cheat.js +372 -0
- package/dist/core/badge.d.ts +18 -0
- package/dist/core/badge.js +360 -0
- package/dist/core/cache.d.ts +47 -0
- package/dist/core/cache.js +403 -0
- package/dist/core/ci-export.d.ts +35 -0
- package/dist/core/ci-export.js +796 -0
- package/dist/core/ci-formats.d.ts +21 -0
- package/dist/core/ci-formats.js +388 -0
- package/dist/core/client-codegen.d.ts +36 -0
- package/dist/core/client-codegen.js +2538 -0
- package/dist/core/compose.d.ts +71 -0
- package/dist/core/compose.js +1088 -0
- package/dist/core/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +21 -1
- package/dist/core/doctor.js +234 -21
- package/dist/core/exec.d.ts +26 -2
- package/dist/core/exec.js +235 -8
- package/dist/core/fixtures.d.ts +153 -0
- package/dist/core/fixtures.js +2245 -0
- package/dist/core/format.d.ts +77 -0
- package/dist/core/format.js +632 -0
- package/dist/core/fs-snapshot.d.ts +37 -0
- package/dist/core/fs-snapshot.js +216 -0
- package/dist/core/graphql-export.d.ts +34 -0
- package/dist/core/graphql-export.js +2482 -0
- package/dist/core/har-export.d.ts +29 -0
- package/dist/core/har-export.js +988 -0
- package/dist/core/html-report.d.ts +27 -0
- package/dist/core/html-report.js +1535 -0
- package/dist/core/http-export.d.ts +31 -0
- package/dist/core/http-export.js +726 -0
- package/dist/core/impact.d.ts +80 -0
- package/dist/core/impact.js +1412 -0
- package/dist/core/lint.d.ts +38 -0
- package/dist/core/lint.js +1111 -0
- package/dist/core/load-export.d.ts +37 -0
- package/dist/core/load-export.js +1813 -0
- package/dist/core/mcp-export.d.ts +35 -0
- package/dist/core/mcp-export.js +1736 -0
- package/dist/core/mock-server.d.ts +47 -0
- package/dist/core/mock-server.js +1722 -0
- package/dist/core/openapi-export.d.ts +44 -0
- package/dist/core/openapi-export.js +1074 -0
- package/dist/core/parity.d.ts +6 -1
- package/dist/core/parity.js +36 -1
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.js +45 -9
- package/dist/core/regression.d.ts +54 -0
- package/dist/core/regression.js +529 -0
- package/dist/core/responsive.d.ts +86 -0
- package/dist/core/responsive.js +606 -0
- package/dist/core/run.d.ts +74 -0
- package/dist/core/run.js +696 -0
- package/dist/core/scheduler.d.ts +24 -0
- package/dist/core/scheduler.js +162 -0
- package/dist/core/schema-export.d.ts +29 -0
- package/dist/core/schema-export.js +2215 -0
- package/dist/core/schema.d.ts +3 -2
- package/dist/core/schema.js +460 -17
- package/dist/core/security.d.ts +233 -0
- package/dist/core/security.js +1839 -0
- package/dist/core/server-export.d.ts +38 -0
- package/dist/core/server-export.js +3198 -0
- package/dist/core/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +11 -2
- package/dist/core/store.js +128 -8
- package/dist/core/target-map.d.ts +34 -0
- package/dist/core/target-map.js +262 -0
- package/dist/core/test-exporter.d.ts +25 -0
- package/dist/core/test-exporter.js +1918 -0
- package/dist/core/types.d.ts +182 -14
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.js +65 -16
- package/dist/core/watch.d.ts +28 -3
- package/dist/core/watch.js +222 -12
- package/dist/core/yaml.d.ts +5 -0
- package/dist/core/yaml.js +1009 -0
- package/dist/diagnostics/diagnose.d.ts +53 -0
- package/dist/diagnostics/diagnose.js +1083 -0
- package/dist/diagnostics/flake.d.ts +71 -0
- package/dist/diagnostics/flake.js +608 -0
- package/dist/diagnostics/mutation-audit.d.ts +69 -0
- package/dist/diagnostics/mutation-audit.js +769 -0
- package/dist/diagnostics/spatial.d.ts +42 -0
- package/dist/diagnostics/spatial.js +346 -0
- package/dist/diagnostics/trends.d.ts +122 -0
- package/dist/diagnostics/trends.js +1190 -0
- package/dist/discovery/discover.d.ts +111 -0
- package/dist/discovery/discover.js +2017 -0
- package/dist/discovery/lock.d.ts +116 -0
- package/dist/discovery/lock.js +1505 -0
- package/dist/discovery/routes.d.ts +36 -0
- package/dist/discovery/routes.js +1494 -0
- package/dist/discovery/test-importer.d.ts +92 -0
- package/dist/discovery/test-importer.js +4952 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +99 -0
- package/dist/ingestors/api-collections.d.ts +28 -0
- package/dist/ingestors/api-collections.js +2335 -0
- package/dist/ingestors/api-repo.d.ts +2 -1
- package/dist/ingestors/api-repo.js +483 -85
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +2 -0
- package/dist/ingestors/bridges.js +702 -0
- package/dist/ingestors/cli.d.ts +2 -1
- package/dist/ingestors/cli.js +234 -46
- package/dist/ingestors/curl.d.ts +14 -0
- package/dist/ingestors/curl.js +1024 -0
- package/dist/ingestors/graphql.d.ts +56 -0
- package/dist/ingestors/graphql.js +1852 -0
- package/dist/ingestors/http-file.d.ts +20 -0
- package/dist/ingestors/http-file.js +923 -0
- package/dist/ingestors/index.js +486 -6
- package/dist/ingestors/openrpc.d.ts +29 -0
- package/dist/ingestors/openrpc.js +1807 -0
- package/dist/ingestors/proto.d.ts +47 -0
- package/dist/ingestors/proto.js +2690 -0
- package/dist/ingestors/trace.d.ts +10 -0
- package/dist/ingestors/trace.js +599 -0
- package/dist/ingestors/video.d.ts +4 -1
- package/dist/ingestors/video.js +86 -36
- package/dist/ingestors/web.d.ts +16 -1
- package/dist/ingestors/web.js +474 -32
- package/dist/mcp/server.js +3532 -67
- package/dist/oracles/api-repo.js +102 -30
- package/dist/oracles/cli.js +65 -17
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.js +178 -28
- package/dist/oracles/index.d.ts +3 -1
- package/dist/oracles/index.js +243 -14
- package/dist/oracles/perf-budget.d.ts +90 -0
- package/dist/oracles/perf-budget.js +1329 -0
- package/dist/oracles/stream.d.ts +94 -0
- package/dist/oracles/stream.js +1268 -0
- package/dist/oracles/ui-states.d.ts +49 -0
- package/dist/oracles/ui-states.js +894 -0
- package/dist/oracles/video.d.ts +1 -1
- package/dist/oracles/video.js +232 -16
- package/dist/oracles/web.js +464 -73
- package/dist/plugins/builtins.d.ts +12 -0
- package/dist/plugins/builtins.js +1052 -0
- package/dist/plugins/registry.d.ts +86 -0
- package/dist/plugins/registry.js +554 -0
- package/dist/setup/index.js +145 -33
- package/package.json +56 -47
- package/skills/vibecode-anything/SKILL.md +75 -52
|
@@ -0,0 +1,1052 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in zero-dependency reference plugins for vibecode-anything:
|
|
3
|
+
* - svgA11yOraclePlugin ("plugin_svg_a11y"): O(N) pure-Node SVG security & a11y audit
|
|
4
|
+
* - stateFileDiffOraclePlugin ("plugin_state_file"): workspace-confined JSON state diff oracle
|
|
5
|
+
* - ndjsonSummaryReporterPlugin ("ndjson-summary"): deterministic holdout-safe NDJSON reporter
|
|
6
|
+
*/
|
|
7
|
+
import crypto from "node:crypto";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { diffJsonSubset } from "../core/diff.js";
|
|
11
|
+
import { errorMessage } from "../core/errors.js";
|
|
12
|
+
import { queryJsonPath, validateJsonSchema } from "../core/schema.js";
|
|
13
|
+
import { STRICT_CONTROL_CHARS_RE, asciiLower, hasCrossPlatformPathEscape, hasUnsafeRelativeSegment, hasVaultOrHoldoutSegment, isForbiddenObjectKey, isInsideVaultDirectory, isPathWithinDir, isRecordSafe, isSecretRelativePath, isSensitiveHeaderName, isSensitiveKeyName, redactDeepValue, redactSensitiveText, safeString } from "../core/security.js";
|
|
14
|
+
import { PluginRegistry } from "./registry.js";
|
|
15
|
+
const MAX_SVG_BYTES = 2 * 1024 * 1024;
|
|
16
|
+
const MAX_STATE_FILE_BYTES = 4 * 1024 * 1024;
|
|
17
|
+
const MAX_DEPTH = 64;
|
|
18
|
+
const MAX_JSON_NODES = 100_000;
|
|
19
|
+
const MAX_REDACT_NODES = 4096;
|
|
20
|
+
const GRAPHICAL_SVG_TAGS = new Set(["path", "rect", "circle", "ellipse", "line", "polyline", "polygon", "text", "g"]);
|
|
21
|
+
const FORBIDDEN_SVG_ELEMENTS = new Set([
|
|
22
|
+
"foreignobject",
|
|
23
|
+
"iframe",
|
|
24
|
+
"object",
|
|
25
|
+
"embed",
|
|
26
|
+
"applet",
|
|
27
|
+
"handler",
|
|
28
|
+
"listener"
|
|
29
|
+
]);
|
|
30
|
+
const URL_BEARING_ATTRS = new Set([
|
|
31
|
+
"href",
|
|
32
|
+
"xlink:href",
|
|
33
|
+
"src",
|
|
34
|
+
"action",
|
|
35
|
+
"formaction",
|
|
36
|
+
"data",
|
|
37
|
+
"poster"
|
|
38
|
+
]);
|
|
39
|
+
const ANIM_VALUE_ATTRS = new Set(["from", "to", "by", "values"]);
|
|
40
|
+
const NAMED_ENTITIES = {
|
|
41
|
+
colon: ":", tab: "\t", newline: "\n", amp: "&", lt: "<", gt: ">", quot: '"', apos: "'"
|
|
42
|
+
};
|
|
43
|
+
const EVENT_HANDLER_RE = /^on[a-z]+$/;
|
|
44
|
+
const VIEWBOX_RE = /^\s*-?(?:\d+\.?\d*|\.\d+)(?:[\s,]+-?(?:\d+\.?\d*|\.\d+)){3}\s*$/;
|
|
45
|
+
const DANGEROUS_URL_RE = /^(?:javascript:|vbscript:|data:(?:text\/html|application\/xhtml|image\/svg|text\/javascript|application\/javascript|text\/ecmascript|application\/ecmascript|text\/xml|application\/xml))/;
|
|
46
|
+
const STYLE_DANGEROUS_COMPACT_RE = /url\(['"]?(?:javascript:|vbscript:|data:(?:text\/html|application\/xhtml|image\/svg|text\/javascript|application\/javascript|text\/ecmascript|application\/ecmascript|text\/xml|application\/xml))|@import['"(]?(?:url\()?['"]?(?:javascript:|vbscript:|data:)|expression\(|-moz-binding:|behavior:/;
|
|
47
|
+
const CSS_HEX_ESCAPE_RE = /\\([0-9a-fA-F]{1,6})[\t\r\n\f ]?/g;
|
|
48
|
+
const JSON_PATH_TOKEN_RE = /\.([A-Za-z_$][A-Za-z0-9_$-]*)|\[(\*|\d+)\]|\[(?:"([^"]*)"|'([^']*)')\]/g;
|
|
49
|
+
const VAULT_MARKER_RE = /\.vibecode-vault\b|holdouts?(?:-[a-f0-9._-]+)?\.json/i;
|
|
50
|
+
const DEFAULT_HOLDOUT_FAIL_MSG = "Holdout invariant failed (expected details redacted)";
|
|
51
|
+
const DEFAULT_HOLDOUT_SKIP_MSG = "Holdout invariant skipped (details redacted)";
|
|
52
|
+
const isPlainObject = isRecordSafe;
|
|
53
|
+
function localTagName(rawName) {
|
|
54
|
+
const lower = asciiLower(rawName);
|
|
55
|
+
const colon = lower.lastIndexOf(":");
|
|
56
|
+
return colon >= 0 ? lower.slice(colon + 1) : lower;
|
|
57
|
+
}
|
|
58
|
+
function checkConfinedPath(candidate, baseDir, label, display) {
|
|
59
|
+
if (!isPathWithinDir(candidate, baseDir, { allowEqual: false }))
|
|
60
|
+
return { ok: false, failure: `Path escapes workspace directory: ${display}` };
|
|
61
|
+
if (hasVaultOrHoldoutSegment(candidate) || isInsideVaultDirectory(candidate))
|
|
62
|
+
return { ok: false, failure: `Vault path rejected for ${label}: ${display}` };
|
|
63
|
+
const rel = path.relative(baseDir, candidate);
|
|
64
|
+
if (hasUnsafeRelativeSegment(rel))
|
|
65
|
+
return { ok: false, failure: `Unsafe path segment rejected for ${label}: ${display}` };
|
|
66
|
+
if (isSecretRelativePath(rel))
|
|
67
|
+
return { ok: false, failure: `Secret file path rejected for ${label}: ${display}` };
|
|
68
|
+
return { ok: true, rel };
|
|
69
|
+
}
|
|
70
|
+
function readWorkspaceTextFile(rawTarget, cwdInput, maxBytes, label) {
|
|
71
|
+
if (typeof rawTarget !== "string" || !rawTarget.trim())
|
|
72
|
+
return { ok: false, failure: `Missing ${label} path in input.path or target` };
|
|
73
|
+
if (cwdInput !== undefined && (typeof cwdInput !== "string" || !cwdInput.trim() || STRICT_CONTROL_CHARS_RE.test(cwdInput))) {
|
|
74
|
+
return { ok: false, failure: `Invalid workspace directory for ${label}` };
|
|
75
|
+
}
|
|
76
|
+
const display = redactSensitiveText(rawTarget.trim());
|
|
77
|
+
if (hasCrossPlatformPathEscape(rawTarget))
|
|
78
|
+
return { ok: false, failure: `Path escape rejected for ${label}: ${display}` };
|
|
79
|
+
const raw = rawTarget.trim();
|
|
80
|
+
if (hasVaultOrHoldoutSegment(raw))
|
|
81
|
+
return { ok: false, failure: `Vault or holdout path rejected for ${label}: ${display}` };
|
|
82
|
+
const baseDir = path.resolve(cwdInput || process.cwd());
|
|
83
|
+
if (!fs.existsSync(baseDir) || !fs.statSync(baseDir).isDirectory())
|
|
84
|
+
return { ok: false, failure: `Workspace directory does not exist for ${label}` };
|
|
85
|
+
const realBaseDir = fs.realpathSync(baseDir);
|
|
86
|
+
const resolved = path.resolve(baseDir, raw);
|
|
87
|
+
const pre = checkConfinedPath(resolved, baseDir, label, display);
|
|
88
|
+
if (!pre.ok)
|
|
89
|
+
return pre;
|
|
90
|
+
// Reject dangling symlinks escaping workspace or targeting vault/secret files before existsSync.
|
|
91
|
+
try {
|
|
92
|
+
const lstat = fs.lstatSync(resolved);
|
|
93
|
+
if (lstat.isSymbolicLink()) {
|
|
94
|
+
const linkTarget = path.resolve(path.dirname(resolved), fs.readlinkSync(resolved));
|
|
95
|
+
const linkCheck = checkConfinedPath(linkTarget, baseDir, label, display);
|
|
96
|
+
if (!linkCheck.ok)
|
|
97
|
+
return linkCheck;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// Missing path handled below
|
|
102
|
+
}
|
|
103
|
+
if (!fs.existsSync(resolved))
|
|
104
|
+
return { ok: false, failure: `${label} file not found: ${redactSensitiveText(pre.rel)}` };
|
|
105
|
+
let realPath;
|
|
106
|
+
try {
|
|
107
|
+
realPath = fs.realpathSync(resolved);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return { ok: false, failure: `Failed to resolve ${label} file: ${redactSensitiveText(errorMessage(err))}` };
|
|
111
|
+
}
|
|
112
|
+
const post = checkConfinedPath(realPath, realBaseDir, label, display);
|
|
113
|
+
if (!post.ok)
|
|
114
|
+
return post;
|
|
115
|
+
try {
|
|
116
|
+
if (!fs.statSync(realPath).isFile())
|
|
117
|
+
return { ok: false, failure: `Target ${label} path is not a regular file` };
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
return { ok: false, failure: `Failed to stat ${label} file: ${redactSensitiveText(errorMessage(err))}` };
|
|
121
|
+
}
|
|
122
|
+
let fd;
|
|
123
|
+
try {
|
|
124
|
+
fd = fs.openSync(realPath, "r");
|
|
125
|
+
const st = fs.fstatSync(fd);
|
|
126
|
+
if (!st.isFile())
|
|
127
|
+
return { ok: false, failure: `Target ${label} path is not a regular file` };
|
|
128
|
+
if (st.size > maxBytes)
|
|
129
|
+
return { ok: false, failure: `${label} file exceeds size cap (${st.size} > ${maxBytes} bytes)` };
|
|
130
|
+
const buf = Buffer.allocUnsafe(Math.min(st.size + 1, maxBytes + 1));
|
|
131
|
+
let totalRead = 0;
|
|
132
|
+
while (totalRead < buf.length) {
|
|
133
|
+
const n = fs.readSync(fd, buf, totalRead, buf.length - totalRead, totalRead);
|
|
134
|
+
if (n <= 0)
|
|
135
|
+
break;
|
|
136
|
+
totalRead += n;
|
|
137
|
+
}
|
|
138
|
+
if (totalRead > maxBytes)
|
|
139
|
+
return { ok: false, failure: `${label} file exceeds size cap (${totalRead} > ${maxBytes} bytes)` };
|
|
140
|
+
let content = buf.subarray(0, totalRead).toString("utf8");
|
|
141
|
+
if (content.startsWith("\uFEFF"))
|
|
142
|
+
content = content.slice(1);
|
|
143
|
+
return { ok: true, content, relPath: post.rel.replace(/\\/g, "/"), bytes: totalRead };
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
return { ok: false, failure: `Failed to read ${label} file: ${redactSensitiveText(errorMessage(err))}` };
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
if (fd !== undefined)
|
|
150
|
+
fs.closeSync(fd);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function decodeXmlEntities(raw) {
|
|
154
|
+
const firstAmp = raw.indexOf("&");
|
|
155
|
+
if (firstAmp === -1)
|
|
156
|
+
return raw;
|
|
157
|
+
const len = raw.length;
|
|
158
|
+
const parts = [];
|
|
159
|
+
let cursor = 0;
|
|
160
|
+
let amp = firstAmp;
|
|
161
|
+
while (amp !== -1) {
|
|
162
|
+
let end = -1;
|
|
163
|
+
let decoded = null;
|
|
164
|
+
const c1 = raw.charCodeAt(amp + 1);
|
|
165
|
+
if (c1 === 35) {
|
|
166
|
+
// Numeric character reference: &#xHEX;? or &#DEC;? (supports arbitrary zero-padding and optional ;)
|
|
167
|
+
const c2 = raw.charCodeAt(amp + 2);
|
|
168
|
+
const isHex = c2 === 120 || c2 === 88;
|
|
169
|
+
let p = isHex ? amp + 3 : amp + 2;
|
|
170
|
+
const digitsStart = p;
|
|
171
|
+
let code = 0;
|
|
172
|
+
let overflow = false;
|
|
173
|
+
while (p < len) {
|
|
174
|
+
const ch = raw.charCodeAt(p);
|
|
175
|
+
let digit = -1;
|
|
176
|
+
if (ch >= 48 && ch <= 57)
|
|
177
|
+
digit = ch - 48;
|
|
178
|
+
else if (isHex && ch >= 65 && ch <= 70)
|
|
179
|
+
digit = ch - 55;
|
|
180
|
+
else if (isHex && ch >= 97 && ch <= 102)
|
|
181
|
+
digit = ch - 87;
|
|
182
|
+
else
|
|
183
|
+
break;
|
|
184
|
+
if (!overflow) {
|
|
185
|
+
code = code * (isHex ? 16 : 10) + digit;
|
|
186
|
+
if (code > 0x10ffff)
|
|
187
|
+
overflow = true;
|
|
188
|
+
}
|
|
189
|
+
p++;
|
|
190
|
+
}
|
|
191
|
+
if (p > digitsStart) {
|
|
192
|
+
end = p < len && raw.charCodeAt(p) === 59 ? p + 1 : p;
|
|
193
|
+
decoded = !overflow && code >= 0 && code <= 0x10ffff ? String.fromCodePoint(code) : "";
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else if ((c1 >= 65 && c1 <= 90) || (c1 >= 97 && c1 <= 122)) {
|
|
197
|
+
// Named entity (max supported name length is 7: "newline")
|
|
198
|
+
const maxEnd = Math.min(len, amp + 9);
|
|
199
|
+
let p = amp + 1;
|
|
200
|
+
while (p < maxEnd) {
|
|
201
|
+
const ch = raw.charCodeAt(p);
|
|
202
|
+
if (ch === 59) {
|
|
203
|
+
const named = NAMED_ENTITIES[raw.slice(amp + 1, p).toLowerCase()];
|
|
204
|
+
if (named !== undefined) {
|
|
205
|
+
decoded = named;
|
|
206
|
+
end = p + 1;
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
if (!((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122)))
|
|
211
|
+
break;
|
|
212
|
+
p++;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (decoded !== null && end !== -1) {
|
|
216
|
+
if (amp > cursor)
|
|
217
|
+
parts.push(raw.slice(cursor, amp));
|
|
218
|
+
if (decoded.length > 0)
|
|
219
|
+
parts.push(decoded);
|
|
220
|
+
cursor = end;
|
|
221
|
+
amp = raw.indexOf("&", cursor);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
amp = raw.indexOf("&", amp + 1);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (cursor === 0)
|
|
228
|
+
return raw;
|
|
229
|
+
if (cursor < len)
|
|
230
|
+
parts.push(raw.slice(cursor));
|
|
231
|
+
return parts.join("");
|
|
232
|
+
}
|
|
233
|
+
function stripCssComments(css) {
|
|
234
|
+
if (!css.includes("/*"))
|
|
235
|
+
return css;
|
|
236
|
+
let out = "";
|
|
237
|
+
let cursor = 0;
|
|
238
|
+
while (cursor < css.length) {
|
|
239
|
+
const start = css.indexOf("/*", cursor);
|
|
240
|
+
if (start === -1) {
|
|
241
|
+
out += css.slice(cursor);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
out += css.slice(cursor, start);
|
|
245
|
+
const end = css.indexOf("*/", start + 2);
|
|
246
|
+
if (end === -1)
|
|
247
|
+
break;
|
|
248
|
+
cursor = end + 2;
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
function hasDangerousCss(rawCss) {
|
|
253
|
+
if (!rawCss)
|
|
254
|
+
return false;
|
|
255
|
+
let css = decodeXmlEntities(rawCss);
|
|
256
|
+
css = stripCssComments(css);
|
|
257
|
+
if (css.includes("\\")) {
|
|
258
|
+
css = css.replace(CSS_HEX_ESCAPE_RE, (_m, hex) => {
|
|
259
|
+
const code = Number.parseInt(hex, 16);
|
|
260
|
+
return Number.isFinite(code) && code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : "";
|
|
261
|
+
});
|
|
262
|
+
css = css.replace(/\\/g, "");
|
|
263
|
+
}
|
|
264
|
+
// eslint-disable-next-line no-control-regex
|
|
265
|
+
const compact = css.replace(/[\s\x00-\x1f\x7f]+/g, "").toLowerCase();
|
|
266
|
+
return STYLE_DANGEROUS_COMPACT_RE.test(compact);
|
|
267
|
+
}
|
|
268
|
+
function isDangerousUrl(rawValue) {
|
|
269
|
+
// eslint-disable-next-line no-control-regex
|
|
270
|
+
const compact = decodeXmlEntities(rawValue).replace(/[\s\x00-\x1f\x7f]+/g, "").toLowerCase();
|
|
271
|
+
return DANGEROUS_URL_RE.test(compact);
|
|
272
|
+
}
|
|
273
|
+
function isValidViewBox(value) {
|
|
274
|
+
if (value.length > 256 || !VIEWBOX_RE.test(value))
|
|
275
|
+
return false;
|
|
276
|
+
const parts = value.trim().split(/[\s,]+/).map(Number);
|
|
277
|
+
return parts.length === 4 && parts.every(Number.isFinite) && parts[2] > 0 && parts[3] > 0;
|
|
278
|
+
}
|
|
279
|
+
function isAsciiWs(c) {
|
|
280
|
+
return c === 32 || c === 9 || c === 10 || c === 13 || c === 12;
|
|
281
|
+
}
|
|
282
|
+
function isNameChar(c) {
|
|
283
|
+
return (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 45 || c === 95 || c === 58 || c === 46;
|
|
284
|
+
}
|
|
285
|
+
function auditSvgDocument(source, expected) {
|
|
286
|
+
const failures = new Set();
|
|
287
|
+
const foundIds = new Set();
|
|
288
|
+
const len = source.length;
|
|
289
|
+
let firstTag = null;
|
|
290
|
+
let foundSvgRoot = false;
|
|
291
|
+
let hasViewBox = false;
|
|
292
|
+
let rootAriaLabel = "";
|
|
293
|
+
let rootAriaLabelledBy = "";
|
|
294
|
+
let rootAriaHidden = false;
|
|
295
|
+
let hasNonEmptyTitle = false;
|
|
296
|
+
let graphicalElements = 0;
|
|
297
|
+
let svgDepth = 0;
|
|
298
|
+
let inRootTitle = false;
|
|
299
|
+
let titleBuf = "";
|
|
300
|
+
let i = 0;
|
|
301
|
+
while (i < len) {
|
|
302
|
+
const lt = source.indexOf("<", i);
|
|
303
|
+
if (lt === -1) {
|
|
304
|
+
if (inRootTitle)
|
|
305
|
+
titleBuf += source.slice(i);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
if (inRootTitle && lt > i)
|
|
309
|
+
titleBuf += source.slice(i, lt);
|
|
310
|
+
if (source.startsWith("<!--", lt)) {
|
|
311
|
+
const end = source.indexOf("-->", lt + 4);
|
|
312
|
+
if (end === -1) {
|
|
313
|
+
failures.add("SVG contains unclosed XML comment");
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
i = end + 3;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (source.startsWith("<![CDATA[", lt)) {
|
|
320
|
+
const end = source.indexOf("]]>", lt + 9);
|
|
321
|
+
if (end === -1) {
|
|
322
|
+
failures.add("SVG contains unclosed CDATA section");
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
if (inRootTitle)
|
|
326
|
+
titleBuf += source.slice(lt + 9, end);
|
|
327
|
+
i = end + 3;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (source.startsWith("<?", lt)) {
|
|
331
|
+
const end = source.indexOf("?>", lt + 2);
|
|
332
|
+
const piHead = source.slice(lt + 2, end === -1 ? Math.min(len, lt + 32) : Math.min(end, lt + 32)).trimStart().toLowerCase();
|
|
333
|
+
if (/^xml-stylesheet(?=[\s]|$)/.test(piHead)) {
|
|
334
|
+
failures.add("SVG contains forbidden <?xml-stylesheet?> processing instruction");
|
|
335
|
+
}
|
|
336
|
+
if (end === -1)
|
|
337
|
+
break;
|
|
338
|
+
i = end + 2;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (source.startsWith("<!", lt)) {
|
|
342
|
+
const declHead = source.slice(lt + 2, Math.min(len, lt + 24)).trimStart().toLowerCase();
|
|
343
|
+
if (/^(?:doctype|entity)(?=[\s\[>]|$)/.test(declHead)) {
|
|
344
|
+
failures.add("SVG contains forbidden <!DOCTYPE>/<!ENTITY> declaration (XXE guard)");
|
|
345
|
+
}
|
|
346
|
+
const end = source.indexOf(">", lt + 2);
|
|
347
|
+
i = end === -1 ? len : end + 1;
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (source.charCodeAt(lt + 1) === 47) {
|
|
351
|
+
let p = lt + 2;
|
|
352
|
+
while (p < len && isAsciiWs(source.charCodeAt(p)))
|
|
353
|
+
p++;
|
|
354
|
+
const s = p;
|
|
355
|
+
while (p < len && isNameChar(source.charCodeAt(p)))
|
|
356
|
+
p++;
|
|
357
|
+
const closeLocal = localTagName(source.slice(s, p));
|
|
358
|
+
const gt = source.indexOf(">", p);
|
|
359
|
+
i = gt === -1 ? len : gt + 1;
|
|
360
|
+
if (inRootTitle && closeLocal === "title") {
|
|
361
|
+
if (decodeXmlEntities(titleBuf).trim().length > 0)
|
|
362
|
+
hasNonEmptyTitle = true;
|
|
363
|
+
inRootTitle = false;
|
|
364
|
+
titleBuf = "";
|
|
365
|
+
}
|
|
366
|
+
if (svgDepth > 0)
|
|
367
|
+
svgDepth--;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
let p = lt + 1;
|
|
371
|
+
const nameStart = p;
|
|
372
|
+
while (p < len && isNameChar(source.charCodeAt(p)))
|
|
373
|
+
p++;
|
|
374
|
+
if (p === nameStart) {
|
|
375
|
+
i = lt + 1;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
const local = localTagName(source.slice(nameStart, p));
|
|
379
|
+
if (firstTag === null)
|
|
380
|
+
firstTag = local;
|
|
381
|
+
const isRootSvg = !foundSvgRoot && local === "svg";
|
|
382
|
+
if (isRootSvg)
|
|
383
|
+
foundSvgRoot = true;
|
|
384
|
+
let selfClosing = false;
|
|
385
|
+
while (p < len) {
|
|
386
|
+
while (p < len && isAsciiWs(source.charCodeAt(p)))
|
|
387
|
+
p++;
|
|
388
|
+
if (p >= len)
|
|
389
|
+
break;
|
|
390
|
+
const ch = source.charCodeAt(p);
|
|
391
|
+
if (ch === 62) {
|
|
392
|
+
p++;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
if (ch === 47 && source.charCodeAt(p + 1) === 62) {
|
|
396
|
+
selfClosing = true;
|
|
397
|
+
p += 2;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
const attrStart = p;
|
|
401
|
+
while (p < len && isNameChar(source.charCodeAt(p)))
|
|
402
|
+
p++;
|
|
403
|
+
if (p === attrStart) {
|
|
404
|
+
p++;
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
const attrEnd = p;
|
|
408
|
+
const attrLen = attrEnd - attrStart;
|
|
409
|
+
while (p < len && isAsciiWs(source.charCodeAt(p)))
|
|
410
|
+
p++;
|
|
411
|
+
let hasValue = false;
|
|
412
|
+
let valStart = p;
|
|
413
|
+
let valEnd = p;
|
|
414
|
+
if (p < len && source.charCodeAt(p) === 61) {
|
|
415
|
+
hasValue = true;
|
|
416
|
+
p++;
|
|
417
|
+
while (p < len && isAsciiWs(source.charCodeAt(p)))
|
|
418
|
+
p++;
|
|
419
|
+
if (p < len && (source.charCodeAt(p) === 34 || source.charCodeAt(p) === 39)) {
|
|
420
|
+
const quoteChar = source.charCodeAt(p++) === 34 ? '"' : "'";
|
|
421
|
+
const endQ = source.indexOf(quoteChar, p);
|
|
422
|
+
valStart = p;
|
|
423
|
+
valEnd = endQ === -1 ? len : endQ;
|
|
424
|
+
p = endQ === -1 ? len : endQ + 1;
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
valStart = p;
|
|
428
|
+
while (p < len && !isAsciiWs(source.charCodeAt(p)) && source.charCodeAt(p) !== 62) {
|
|
429
|
+
if (source.charCodeAt(p) === 47 && source.charCodeAt(p + 1) === 62)
|
|
430
|
+
break;
|
|
431
|
+
p++;
|
|
432
|
+
}
|
|
433
|
+
valEnd = p;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
// Fast path: 1-char attributes (e.g. d, x, y, r) cannot be id/on*/href/src/style/viewBox/aria-*,
|
|
437
|
+
// and valueless attributes can only matter if they look like on*, srcdoc, or namespaced.
|
|
438
|
+
if (attrLen < 2)
|
|
439
|
+
continue;
|
|
440
|
+
if (!hasValue) {
|
|
441
|
+
if (attrLen < 3)
|
|
442
|
+
continue;
|
|
443
|
+
const c0 = source.charCodeAt(attrStart) | 32;
|
|
444
|
+
const c1 = source.charCodeAt(attrStart + 1) | 32;
|
|
445
|
+
const maybeEvent = c0 === 111 && c1 === 110;
|
|
446
|
+
const maybeSrcdoc = attrLen === 6 && c0 === 115 && c1 === 114;
|
|
447
|
+
if (!maybeEvent && !maybeSrcdoc) {
|
|
448
|
+
let hasColon = false;
|
|
449
|
+
for (let k = attrStart; k < attrEnd; k++) {
|
|
450
|
+
if (source.charCodeAt(k) === 58) {
|
|
451
|
+
hasColon = true;
|
|
452
|
+
break;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (!hasColon)
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const attrLower = asciiLower(source.slice(attrStart, attrEnd));
|
|
460
|
+
const attrValue = hasValue ? source.slice(valStart, valEnd) : "";
|
|
461
|
+
const hasColon = attrLower.includes(":");
|
|
462
|
+
const attrLocal = hasColon ? attrLower.slice(attrLower.lastIndexOf(":") + 1) : attrLower;
|
|
463
|
+
if ((attrLocal.charCodeAt(0) === 111 && attrLocal.charCodeAt(1) === 110 && EVENT_HANDLER_RE.test(attrLocal)) ||
|
|
464
|
+
(hasColon && attrLower.charCodeAt(0) === 111 && attrLower.charCodeAt(1) === 110 && EVENT_HANDLER_RE.test(attrLower))) {
|
|
465
|
+
failures.add(`SVG contains forbidden inline event handler "${attrLower}"`);
|
|
466
|
+
}
|
|
467
|
+
if (attrLocal === "srcdoc") {
|
|
468
|
+
failures.add('SVG contains forbidden "srcdoc" attribute');
|
|
469
|
+
}
|
|
470
|
+
else if (URL_BEARING_ATTRS.has(attrLocal)) {
|
|
471
|
+
if (isDangerousUrl(attrValue)) {
|
|
472
|
+
failures.add(`SVG contains forbidden URL scheme in "${attrLower}"`);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
else if (ANIM_VALUE_ATTRS.has(attrLower)) {
|
|
476
|
+
const decodedVal = decodeXmlEntities(attrValue);
|
|
477
|
+
const candidates = attrLower === "values" ? decodedVal.split(";") : [decodedVal];
|
|
478
|
+
if (attrLower === "values" && attrValue.includes(";")) {
|
|
479
|
+
for (const rawPart of attrValue.split(";"))
|
|
480
|
+
candidates.push(decodeXmlEntities(rawPart));
|
|
481
|
+
}
|
|
482
|
+
for (const part of candidates) {
|
|
483
|
+
// eslint-disable-next-line no-control-regex
|
|
484
|
+
if (DANGEROUS_URL_RE.test(part.replace(/[\s\x00-\x1f\x7f]+/g, "").toLowerCase())) {
|
|
485
|
+
failures.add(`SVG contains forbidden URL scheme in "${attrLower}"`);
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
else if (attrLower === "attributename") {
|
|
491
|
+
// eslint-disable-next-line no-control-regex
|
|
492
|
+
const decodedAnimAttr = decodeXmlEntities(attrValue).replace(/[\s\x00-\x1f\x7f]+/g, "").toLowerCase();
|
|
493
|
+
if (EVENT_HANDLER_RE.test(decodedAnimAttr) || EVENT_HANDLER_RE.test(localTagName(decodedAnimAttr))) {
|
|
494
|
+
failures.add(`SVG contains forbidden animated event handler "${decodedAnimAttr}"`);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
else if (attrLower === "style" && hasDangerousCss(attrValue)) {
|
|
498
|
+
failures.add('SVG contains forbidden URL scheme in "style"');
|
|
499
|
+
}
|
|
500
|
+
if ((attrLower === "id" || attrLower === "xml:id") && attrValue.trim())
|
|
501
|
+
foundIds.add(attrValue.trim());
|
|
502
|
+
if (isRootSvg) {
|
|
503
|
+
if (attrLower === "viewbox")
|
|
504
|
+
hasViewBox = isValidViewBox(attrValue);
|
|
505
|
+
else if (attrLower === "aria-label")
|
|
506
|
+
rootAriaLabel = decodeXmlEntities(attrValue).trim();
|
|
507
|
+
else if (attrLower === "aria-labelledby")
|
|
508
|
+
rootAriaLabelledBy = attrValue.trim();
|
|
509
|
+
else if (attrLower === "aria-hidden")
|
|
510
|
+
rootAriaHidden = asciiLower(attrValue.trim()) === "true";
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
i = p;
|
|
514
|
+
if (local === "script") {
|
|
515
|
+
failures.add("SVG contains forbidden <script> element");
|
|
516
|
+
if (!selfClosing) {
|
|
517
|
+
let scan = i;
|
|
518
|
+
let closed = false;
|
|
519
|
+
while (scan < len) {
|
|
520
|
+
const nc = source.indexOf("</", scan);
|
|
521
|
+
if (nc === -1)
|
|
522
|
+
break;
|
|
523
|
+
let cp = nc + 2;
|
|
524
|
+
while (cp < len && isAsciiWs(source.charCodeAt(cp)))
|
|
525
|
+
cp++;
|
|
526
|
+
const cs = cp;
|
|
527
|
+
while (cp < len && isNameChar(source.charCodeAt(cp)))
|
|
528
|
+
cp++;
|
|
529
|
+
if (localTagName(source.slice(cs, cp)) === "script") {
|
|
530
|
+
const gt = source.indexOf(">", cp);
|
|
531
|
+
i = gt === -1 ? len : gt + 1;
|
|
532
|
+
closed = true;
|
|
533
|
+
break;
|
|
534
|
+
}
|
|
535
|
+
scan = nc + 2;
|
|
536
|
+
}
|
|
537
|
+
if (!closed)
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
if (local === "style" && !selfClosing) {
|
|
543
|
+
const styleStart = i;
|
|
544
|
+
let scan = i;
|
|
545
|
+
let closed = false;
|
|
546
|
+
let styleEnd = len;
|
|
547
|
+
while (scan < len) {
|
|
548
|
+
const nc = source.indexOf("</", scan);
|
|
549
|
+
if (nc === -1)
|
|
550
|
+
break;
|
|
551
|
+
let cp = nc + 2;
|
|
552
|
+
while (cp < len && isAsciiWs(source.charCodeAt(cp)))
|
|
553
|
+
cp++;
|
|
554
|
+
const cs = cp;
|
|
555
|
+
while (cp < len && isNameChar(source.charCodeAt(cp)))
|
|
556
|
+
cp++;
|
|
557
|
+
if (localTagName(source.slice(cs, cp)) === "style") {
|
|
558
|
+
styleEnd = nc;
|
|
559
|
+
const gt = source.indexOf(">", cp);
|
|
560
|
+
i = gt === -1 ? len : gt + 1;
|
|
561
|
+
closed = true;
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
scan = nc + 2;
|
|
565
|
+
}
|
|
566
|
+
if (hasDangerousCss(source.slice(styleStart, styleEnd))) {
|
|
567
|
+
failures.add("SVG contains forbidden URL scheme in <style>");
|
|
568
|
+
}
|
|
569
|
+
if (!closed)
|
|
570
|
+
break;
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
if (FORBIDDEN_SVG_ELEMENTS.has(local)) {
|
|
574
|
+
failures.add(`SVG contains forbidden <${local === "foreignobject" ? "foreignObject" : local}> element`);
|
|
575
|
+
}
|
|
576
|
+
if (isRootSvg && !selfClosing)
|
|
577
|
+
svgDepth = 1;
|
|
578
|
+
else if (svgDepth > 0) {
|
|
579
|
+
if (GRAPHICAL_SVG_TAGS.has(local))
|
|
580
|
+
graphicalElements++;
|
|
581
|
+
if (svgDepth === 1 && local === "title" && !selfClosing) {
|
|
582
|
+
inRootTitle = true;
|
|
583
|
+
titleBuf = "";
|
|
584
|
+
}
|
|
585
|
+
if (!selfClosing)
|
|
586
|
+
svgDepth++;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (!foundSvgRoot || firstTag !== "svg")
|
|
590
|
+
failures.add("Document does not have a valid <svg> root element");
|
|
591
|
+
if (expected.requireViewBox !== false && !hasViewBox)
|
|
592
|
+
failures.add("SVG root element is missing a valid viewBox attribute");
|
|
593
|
+
const hasAccessibleName = hasNonEmptyTitle || rootAriaLabel.length > 0 || rootAriaLabelledBy.length > 0;
|
|
594
|
+
if (!rootAriaHidden && expected.requireAccessibleName !== false && !hasAccessibleName) {
|
|
595
|
+
failures.add("SVG is missing an accessible name (<title>, aria-label, or aria-labelledby)");
|
|
596
|
+
}
|
|
597
|
+
if (typeof expected.minElements === "number" && Number.isFinite(expected.minElements) && graphicalElements < expected.minElements) {
|
|
598
|
+
failures.add(`SVG has ${graphicalElements} graphical element(s), expected at least ${expected.minElements}`);
|
|
599
|
+
}
|
|
600
|
+
if (Array.isArray(expected.requiredIds)) {
|
|
601
|
+
for (const rawId of expected.requiredIds) {
|
|
602
|
+
if (typeof rawId === "string" && rawId.length > 0 && !foundIds.has(rawId)) {
|
|
603
|
+
failures.add(`SVG missing required id "${redactSensitiveText(rawId)}"`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return { failures: [...failures], hasViewBox, hasAccessibleName, ariaHidden: rootAriaHidden, graphicalElements, foundIds };
|
|
608
|
+
}
|
|
609
|
+
export const svgA11yOraclePlugin = {
|
|
610
|
+
kind: "oracle",
|
|
611
|
+
name: "builtin-svg-a11y",
|
|
612
|
+
version: "1.0.0",
|
|
613
|
+
invariantTypes: ["plugin_svg_a11y"],
|
|
614
|
+
verify(invariant, ctx) {
|
|
615
|
+
const rawTarget = typeof invariant.input?.path === "string" && invariant.input.path.trim() ? invariant.input.path : ctx.target;
|
|
616
|
+
const file = readWorkspaceTextFile(rawTarget, ctx.cwd, MAX_SVG_BYTES, "SVG");
|
|
617
|
+
if (!file.ok)
|
|
618
|
+
return { status: "fail", score: 0, failures: [file.failure] };
|
|
619
|
+
const audit = auditSvgDocument(file.content, isPlainObject(invariant.expected) ? invariant.expected : {});
|
|
620
|
+
const candidateOutputHash = crypto.createHash("sha256").update(file.content, "utf8").digest("hex");
|
|
621
|
+
return {
|
|
622
|
+
status: audit.failures.length === 0 ? "pass" : "fail",
|
|
623
|
+
score: audit.failures.length === 0 ? 1 : 0,
|
|
624
|
+
failures: audit.failures,
|
|
625
|
+
metrics: {
|
|
626
|
+
path: file.relPath,
|
|
627
|
+
bytes: file.bytes,
|
|
628
|
+
hasViewBox: audit.hasViewBox,
|
|
629
|
+
hasAccessibleName: audit.hasAccessibleName,
|
|
630
|
+
ariaHidden: audit.ariaHidden,
|
|
631
|
+
graphicalElements: audit.graphicalElements,
|
|
632
|
+
idCount: audit.foundIds.size,
|
|
633
|
+
candidateOutputHash
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
function safeJsonStringify(value) {
|
|
639
|
+
try {
|
|
640
|
+
const s = JSON.stringify(value);
|
|
641
|
+
return s !== undefined ? s : "undefined";
|
|
642
|
+
}
|
|
643
|
+
catch {
|
|
644
|
+
return safeString(value);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function safeCloneJson(value, depth = 0, seen = new WeakSet(), budget = { remaining: MAX_JSON_NODES }) {
|
|
648
|
+
if (value === null || typeof value !== "object")
|
|
649
|
+
return value;
|
|
650
|
+
if (depth >= MAX_DEPTH || budget.remaining <= 0)
|
|
651
|
+
return null;
|
|
652
|
+
if (seen.has(value))
|
|
653
|
+
return null;
|
|
654
|
+
budget.remaining--;
|
|
655
|
+
seen.add(value);
|
|
656
|
+
try {
|
|
657
|
+
if (Array.isArray(value)) {
|
|
658
|
+
const outArr = [];
|
|
659
|
+
for (let i = 0; i < value.length; i++) {
|
|
660
|
+
if (budget.remaining <= 0)
|
|
661
|
+
break;
|
|
662
|
+
outArr.push(safeCloneJson(value[i], depth + 1, seen, budget));
|
|
663
|
+
}
|
|
664
|
+
return outArr;
|
|
665
|
+
}
|
|
666
|
+
const out = {};
|
|
667
|
+
for (const key of Object.keys(value)) {
|
|
668
|
+
if (budget.remaining <= 0)
|
|
669
|
+
break;
|
|
670
|
+
if (!isForbiddenObjectKey(key)) {
|
|
671
|
+
Object.defineProperty(out, key, {
|
|
672
|
+
value: safeCloneJson(value[key], depth + 1, seen, budget),
|
|
673
|
+
enumerable: true,
|
|
674
|
+
writable: true,
|
|
675
|
+
configurable: true
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return out;
|
|
680
|
+
}
|
|
681
|
+
finally {
|
|
682
|
+
seen.delete(value);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
function redactJsonValue(value, _depth = 0, forceRedactString = false) {
|
|
686
|
+
if (forceRedactString && typeof value === "string") {
|
|
687
|
+
return value.length > 0 ? "[REDACTED]" : "";
|
|
688
|
+
}
|
|
689
|
+
return redactDeepValue(value, {
|
|
690
|
+
maxDepth: MAX_DEPTH,
|
|
691
|
+
maxNodes: MAX_REDACT_NODES,
|
|
692
|
+
sensitiveKeyMode: "strings",
|
|
693
|
+
redactText: forceRedactString ? (s) => (s.length > 0 ? "[REDACTED]" : "") : redactSensitiveText,
|
|
694
|
+
unwrapError: false,
|
|
695
|
+
stringifyNonJsonPrimitives: false
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
function canonicalJson(value, depth = 0, seen = new WeakSet(), budget = { remaining: MAX_JSON_NODES }) {
|
|
699
|
+
if (value === null)
|
|
700
|
+
return "null";
|
|
701
|
+
if (typeof value === "boolean" || typeof value === "string")
|
|
702
|
+
return JSON.stringify(value);
|
|
703
|
+
if (typeof value === "number")
|
|
704
|
+
return Number.isFinite(value) ? JSON.stringify(value) : "null";
|
|
705
|
+
if (depth >= MAX_DEPTH || budget.remaining <= 0)
|
|
706
|
+
return "null";
|
|
707
|
+
if (typeof value === "object") {
|
|
708
|
+
if (seen.has(value))
|
|
709
|
+
return '"[Circular]"';
|
|
710
|
+
budget.remaining--;
|
|
711
|
+
seen.add(value);
|
|
712
|
+
try {
|
|
713
|
+
if (Array.isArray(value))
|
|
714
|
+
return `[${value.map((item) => canonicalJson(item, depth + 1, seen, budget)).join(",")}]`;
|
|
715
|
+
const obj = value;
|
|
716
|
+
const keys = Object.keys(obj).filter((k) => !isForbiddenObjectKey(k) && obj[k] !== undefined).sort();
|
|
717
|
+
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k], depth + 1, seen, budget)}`).join(",")}}`;
|
|
718
|
+
}
|
|
719
|
+
finally {
|
|
720
|
+
seen.delete(value);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return "null";
|
|
724
|
+
}
|
|
725
|
+
function hasForbiddenJsonPathSegment(expr) {
|
|
726
|
+
if (typeof expr !== "string" || !expr.startsWith("$"))
|
|
727
|
+
return false;
|
|
728
|
+
let idx = 1;
|
|
729
|
+
while (idx < expr.length) {
|
|
730
|
+
JSON_PATH_TOKEN_RE.lastIndex = idx;
|
|
731
|
+
const m = JSON_PATH_TOKEN_RE.exec(expr);
|
|
732
|
+
if (!m || m.index !== idx) {
|
|
733
|
+
// Check raw substring fallback for prototype keys in non-standard path syntax
|
|
734
|
+
return /\b(?:__proto__|constructor|prototype)\b/.test(expr);
|
|
735
|
+
}
|
|
736
|
+
const key = m[1] ?? m[3] ?? m[4];
|
|
737
|
+
if (key !== undefined && isForbiddenObjectKey(key))
|
|
738
|
+
return true;
|
|
739
|
+
idx = JSON_PATH_TOKEN_RE.lastIndex;
|
|
740
|
+
}
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
function isSensitiveJsonPath(expr) {
|
|
744
|
+
if (typeof expr !== "string" || !expr.startsWith("$"))
|
|
745
|
+
return false;
|
|
746
|
+
let lastKey;
|
|
747
|
+
let idx = 1;
|
|
748
|
+
while (idx < expr.length) {
|
|
749
|
+
JSON_PATH_TOKEN_RE.lastIndex = idx;
|
|
750
|
+
const m = JSON_PATH_TOKEN_RE.exec(expr);
|
|
751
|
+
if (!m || m.index !== idx)
|
|
752
|
+
break;
|
|
753
|
+
const key = m[1] ?? m[3] ?? m[4];
|
|
754
|
+
if (key !== undefined)
|
|
755
|
+
lastKey = key;
|
|
756
|
+
idx = JSON_PATH_TOKEN_RE.lastIndex;
|
|
757
|
+
}
|
|
758
|
+
return lastKey !== undefined && (isSensitiveKeyName(lastKey) || isSensitiveHeaderName(lastKey));
|
|
759
|
+
}
|
|
760
|
+
function tokenizeIgnorePath(expr) {
|
|
761
|
+
if (typeof expr !== "string" || !expr.startsWith("$") || expr.length < 2)
|
|
762
|
+
return null;
|
|
763
|
+
const tokens = [];
|
|
764
|
+
let idx = 1;
|
|
765
|
+
while (idx < expr.length) {
|
|
766
|
+
JSON_PATH_TOKEN_RE.lastIndex = idx;
|
|
767
|
+
const m = JSON_PATH_TOKEN_RE.exec(expr);
|
|
768
|
+
if (!m || m.index !== idx)
|
|
769
|
+
return null;
|
|
770
|
+
const key = m[1] ?? m[3] ?? m[4];
|
|
771
|
+
if (key !== undefined) {
|
|
772
|
+
if (isForbiddenObjectKey(key))
|
|
773
|
+
return null;
|
|
774
|
+
tokens.push(key);
|
|
775
|
+
}
|
|
776
|
+
else if (m[2] !== undefined) {
|
|
777
|
+
tokens.push(m[2] === "*" ? "*" : Number(m[2]));
|
|
778
|
+
}
|
|
779
|
+
idx = JSON_PATH_TOKEN_RE.lastIndex;
|
|
780
|
+
}
|
|
781
|
+
return tokens.length > 0 ? tokens : null;
|
|
782
|
+
}
|
|
783
|
+
function deleteAtTokens(node, tokens, pos) {
|
|
784
|
+
if (node === null || typeof node !== "object" || pos >= tokens.length)
|
|
785
|
+
return;
|
|
786
|
+
const tok = tokens[pos];
|
|
787
|
+
const isLeaf = pos === tokens.length - 1;
|
|
788
|
+
if (tok === "*") {
|
|
789
|
+
if (Array.isArray(node)) {
|
|
790
|
+
if (isLeaf)
|
|
791
|
+
node.length = 0;
|
|
792
|
+
else
|
|
793
|
+
node.forEach((item) => deleteAtTokens(item, tokens, pos + 1));
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
const rec = node;
|
|
797
|
+
for (const k of Object.keys(rec)) {
|
|
798
|
+
if (isForbiddenObjectKey(k))
|
|
799
|
+
continue;
|
|
800
|
+
if (isLeaf)
|
|
801
|
+
delete rec[k];
|
|
802
|
+
else
|
|
803
|
+
deleteAtTokens(rec[k], tokens, pos + 1);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
if (typeof tok === "number") {
|
|
809
|
+
if (!Array.isArray(node) || tok < 0 || tok >= node.length)
|
|
810
|
+
return;
|
|
811
|
+
if (isLeaf)
|
|
812
|
+
node.splice(tok, 1);
|
|
813
|
+
else
|
|
814
|
+
deleteAtTokens(node[tok], tokens, pos + 1);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (Array.isArray(node) || isForbiddenObjectKey(tok))
|
|
818
|
+
return;
|
|
819
|
+
const rec = node;
|
|
820
|
+
if (!Object.prototype.hasOwnProperty.call(rec, tok))
|
|
821
|
+
return;
|
|
822
|
+
if (isLeaf)
|
|
823
|
+
delete rec[tok];
|
|
824
|
+
else
|
|
825
|
+
deleteAtTokens(rec[tok], tokens, pos + 1);
|
|
826
|
+
}
|
|
827
|
+
function stripIgnoredPaths(value, ignorePaths) {
|
|
828
|
+
const cloned = safeCloneJson(value);
|
|
829
|
+
for (const expr of ignorePaths) {
|
|
830
|
+
const tokens = tokenizeIgnorePath(expr);
|
|
831
|
+
if (tokens)
|
|
832
|
+
deleteAtTokens(cloned, tokens, 0);
|
|
833
|
+
}
|
|
834
|
+
return cloned;
|
|
835
|
+
}
|
|
836
|
+
export const stateFileDiffOraclePlugin = {
|
|
837
|
+
kind: "oracle",
|
|
838
|
+
name: "builtin-state-file",
|
|
839
|
+
version: "1.0.0",
|
|
840
|
+
invariantTypes: ["plugin_state_file"],
|
|
841
|
+
verify(invariant, ctx) {
|
|
842
|
+
const rawTarget = typeof invariant.input?.path === "string" && invariant.input.path.trim() ? invariant.input.path : ctx.target;
|
|
843
|
+
const file = readWorkspaceTextFile(rawTarget, ctx.cwd, MAX_STATE_FILE_BYTES, "state JSON");
|
|
844
|
+
if (!file.ok)
|
|
845
|
+
return { status: "fail", score: 0, failures: [file.failure] };
|
|
846
|
+
let parsed;
|
|
847
|
+
try {
|
|
848
|
+
parsed = JSON.parse(file.content);
|
|
849
|
+
}
|
|
850
|
+
catch (err) {
|
|
851
|
+
return {
|
|
852
|
+
status: "fail",
|
|
853
|
+
score: 0,
|
|
854
|
+
failures: [`State file is not valid JSON: ${redactSensitiveText(errorMessage(err))}`],
|
|
855
|
+
metrics: { path: file.relPath, bytes: file.bytes }
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
const rawIgnore = invariant.input?.ignorePaths;
|
|
859
|
+
const ignorePaths = Array.isArray(rawIgnore) ? rawIgnore.filter((p) => typeof p === "string" && p.startsWith("$")) : [];
|
|
860
|
+
const normalized = stripIgnoredPaths(parsed, ignorePaths);
|
|
861
|
+
const expected = isPlainObject(invariant.expected) ? invariant.expected : {};
|
|
862
|
+
const failures = [];
|
|
863
|
+
const diff = {};
|
|
864
|
+
if (expected.jsonSchema) {
|
|
865
|
+
const errs = validateJsonSchema(normalized, expected.jsonSchema, "$");
|
|
866
|
+
if (errs.length > 0) {
|
|
867
|
+
errs.slice(0, 10).forEach((e) => failures.push(redactSensitiveText(`jsonSchema ${e.path}: ${e.message}`)));
|
|
868
|
+
diff.jsonSchema = errs.map((e) => ({ path: redactSensitiveText(e.path), message: redactSensitiveText(e.message) }));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (expected.jsonSubset !== undefined) {
|
|
872
|
+
const subsetDiff = diffJsonSubset(stripIgnoredPaths(expected.jsonSubset, ignorePaths), normalized, "$");
|
|
873
|
+
if (subsetDiff.length > 0) {
|
|
874
|
+
const redactedDiffs = subsetDiff.map((e) => {
|
|
875
|
+
const sensitive = isSensitiveJsonPath(e.path);
|
|
876
|
+
return {
|
|
877
|
+
path: redactSensitiveText(e.path),
|
|
878
|
+
expected: redactJsonValue(e.expected, 0, sensitive),
|
|
879
|
+
actual: redactJsonValue(e.actual, 0, sensitive)
|
|
880
|
+
};
|
|
881
|
+
});
|
|
882
|
+
redactedDiffs.slice(0, 10).forEach((e) => failures.push(redactSensitiveText(`jsonSubset ${e.path}: expected ${safeJsonStringify(e.expected)}, got ${safeJsonStringify(e.actual)}`)));
|
|
883
|
+
diff.jsonSubset = redactedDiffs;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (Array.isArray(expected.jsonPaths)) {
|
|
887
|
+
const pathDiffs = [];
|
|
888
|
+
for (const a of expected.jsonPaths) {
|
|
889
|
+
if (!a || typeof a.path !== "string")
|
|
890
|
+
continue;
|
|
891
|
+
const safePath = redactSensitiveText(a.path);
|
|
892
|
+
const sensitive = isSensitiveJsonPath(a.path);
|
|
893
|
+
const hasEq = Object.prototype.hasOwnProperty.call(a, "equals");
|
|
894
|
+
const expVal = hasEq ? a.equals : a.matches;
|
|
895
|
+
if (hasForbiddenJsonPathSegment(a.path)) {
|
|
896
|
+
failures.push(`jsonPath ${safePath}: forbidden prototype segment`);
|
|
897
|
+
pathDiffs.push({ path: safePath, expected: redactJsonValue(expVal, 0, sensitive), actual: undefined });
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
const q = queryJsonPath(normalized, a.path);
|
|
901
|
+
if (!q.found) {
|
|
902
|
+
failures.push(`jsonPath ${safePath}: not found`);
|
|
903
|
+
pathDiffs.push({ path: safePath, expected: redactJsonValue(expVal, 0, sensitive), actual: undefined });
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
const safeExpected = redactJsonValue(expVal, 0, sensitive);
|
|
907
|
+
const safeActual = redactJsonValue(q.value, 0, sensitive);
|
|
908
|
+
let ok = true;
|
|
909
|
+
if (hasEq)
|
|
910
|
+
ok = canonicalJson(q.value) === canonicalJson(a.equals);
|
|
911
|
+
else if (Object.prototype.hasOwnProperty.call(a, "matches")) {
|
|
912
|
+
if (typeof a.matches !== "string") {
|
|
913
|
+
const msg = "matches must be a regex string";
|
|
914
|
+
failures.push(`jsonPath ${safePath}: ${msg}`);
|
|
915
|
+
pathDiffs.push({ path: safePath, expected: safeExpected, actual: safeActual, error: msg });
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
try {
|
|
919
|
+
ok = new RegExp(a.matches).test(safeString(q.value));
|
|
920
|
+
}
|
|
921
|
+
catch (err) {
|
|
922
|
+
const msg = redactSensitiveText(errorMessage(err));
|
|
923
|
+
failures.push(redactSensitiveText(`jsonPath ${safePath}: invalid regex ${safeString(safeExpected)}: ${msg}`));
|
|
924
|
+
pathDiffs.push({ path: safePath, expected: safeExpected, actual: safeActual, error: msg });
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
if (!ok) {
|
|
929
|
+
failures.push(redactSensitiveText(`jsonPath ${safePath}: expected ${safeJsonStringify(safeExpected)}, got ${safeJsonStringify(safeActual)}`));
|
|
930
|
+
pathDiffs.push({ path: safePath, expected: safeExpected, actual: safeActual });
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (pathDiffs.length > 0)
|
|
934
|
+
diff.jsonPaths = pathDiffs;
|
|
935
|
+
}
|
|
936
|
+
const candidateOutputHash = crypto.createHash("sha256").update(canonicalJson(normalized), "utf8").digest("hex");
|
|
937
|
+
return {
|
|
938
|
+
status: failures.length === 0 ? "pass" : "fail",
|
|
939
|
+
score: failures.length === 0 ? 1 : 0,
|
|
940
|
+
failures,
|
|
941
|
+
...(Object.keys(diff).length > 0 ? { diff } : {}),
|
|
942
|
+
metrics: { path: redactSensitiveText(file.relPath), bytes: file.bytes, ignoredPaths: ignorePaths.length, candidateOutputHash }
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
function finiteNum(value, fallback = 0) {
|
|
947
|
+
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
948
|
+
}
|
|
949
|
+
function isHoldoutResult(item) {
|
|
950
|
+
const raw = item;
|
|
951
|
+
return item.metrics?.redacted === true || item.metrics?.holdout === true || raw.holdout === true;
|
|
952
|
+
}
|
|
953
|
+
function safeHoldoutFailureMessage(item) {
|
|
954
|
+
const raw = item;
|
|
955
|
+
const candidates = [];
|
|
956
|
+
if (typeof raw.holdoutHint === "string" && raw.holdoutHint.trim())
|
|
957
|
+
candidates.push(raw.holdoutHint);
|
|
958
|
+
if (item.metrics?.redacted === true && Array.isArray(item.failures) && typeof item.failures[0] === "string" && item.failures[0].trim()) {
|
|
959
|
+
candidates.push(item.failures[0]);
|
|
960
|
+
}
|
|
961
|
+
for (const rawCandidate of candidates) {
|
|
962
|
+
if (VAULT_MARKER_RE.test(rawCandidate))
|
|
963
|
+
continue;
|
|
964
|
+
const clean = redactSensitiveText(rawCandidate).replace(/\s+/g, " ").trim();
|
|
965
|
+
if (clean && !clean.includes("[REDACTED_VAULT]"))
|
|
966
|
+
return clean;
|
|
967
|
+
}
|
|
968
|
+
return DEFAULT_HOLDOUT_FAIL_MSG;
|
|
969
|
+
}
|
|
970
|
+
export const ndjsonSummaryReporterPlugin = {
|
|
971
|
+
kind: "reporter",
|
|
972
|
+
name: "builtin-ndjson-summary",
|
|
973
|
+
version: "1.0.0",
|
|
974
|
+
format: "ndjson-summary",
|
|
975
|
+
render(report) {
|
|
976
|
+
const safeReport = isPlainObject(report) ? report : {};
|
|
977
|
+
const header = {
|
|
978
|
+
kind: "summary",
|
|
979
|
+
schemaVersion: redactSensitiveText(safeString(safeReport.schemaVersion ?? "0.2.0")),
|
|
980
|
+
timestamp: redactSensitiveText(safeString(safeReport.timestamp)),
|
|
981
|
+
gate: {
|
|
982
|
+
passed: Boolean(safeReport.gate?.passed),
|
|
983
|
+
status: redactSensitiveText(safeString(safeReport.gate?.status ?? "incomplete")),
|
|
984
|
+
exitCode: finiteNum(safeReport.gate?.exitCode, 0),
|
|
985
|
+
reasons: Array.isArray(safeReport.gate?.reasons) ? safeReport.gate.reasons.map((r) => redactSensitiveText(safeString(r))) : []
|
|
986
|
+
},
|
|
987
|
+
passed: finiteNum(safeReport.passed, 0),
|
|
988
|
+
total: finiteNum(safeReport.total, 0),
|
|
989
|
+
parity: finiteNum(safeReport.parity, 0),
|
|
990
|
+
compositeScore: finiteNum(safeReport.compositeScore, 0),
|
|
991
|
+
hard: {
|
|
992
|
+
passed: finiteNum(safeReport.hard?.passed, 0), failed: finiteNum(safeReport.hard?.failed, 0),
|
|
993
|
+
skipped: finiteNum(safeReport.hard?.skipped, 0), evaluated: finiteNum(safeReport.hard?.evaluated, 0),
|
|
994
|
+
total: finiteNum(safeReport.hard?.total, 0), parity: finiteNum(safeReport.hard?.parity, 0)
|
|
995
|
+
},
|
|
996
|
+
soft: {
|
|
997
|
+
passed: finiteNum(safeReport.soft?.passed, 0), warned: finiteNum(safeReport.soft?.warned, 0),
|
|
998
|
+
failed: finiteNum(safeReport.soft?.failed, 0), skipped: finiteNum(safeReport.soft?.skipped, 0),
|
|
999
|
+
evaluated: finiteNum(safeReport.soft?.evaluated, 0), total: finiteNum(safeReport.soft?.total, 0),
|
|
1000
|
+
meanScore: finiteNum(safeReport.soft?.meanScore, 0), parity: finiteNum(safeReport.soft?.parity, 0)
|
|
1001
|
+
},
|
|
1002
|
+
nextAction: redactSensitiveText(safeString(safeReport.nextAction ?? "none")),
|
|
1003
|
+
...(safeReport.antiCheat
|
|
1004
|
+
? {
|
|
1005
|
+
antiCheat: {
|
|
1006
|
+
status: redactSensitiveText(safeString(safeReport.antiCheat.status)),
|
|
1007
|
+
reasons: Array.isArray(safeReport.antiCheat.reasons) ? safeReport.antiCheat.reasons.map((r) => redactSensitiveText(safeString(r))) : []
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
: {})
|
|
1011
|
+
};
|
|
1012
|
+
const lines = [JSON.stringify(header)];
|
|
1013
|
+
for (const item of Array.isArray(safeReport.results) ? safeReport.results : []) {
|
|
1014
|
+
if (!isPlainObject(item))
|
|
1015
|
+
continue;
|
|
1016
|
+
const holdout = isHoldoutResult(item);
|
|
1017
|
+
const record = {
|
|
1018
|
+
kind: "invariant",
|
|
1019
|
+
id: redactSensitiveText(safeString(item.id)),
|
|
1020
|
+
type: redactSensitiveText(safeString(item.type)),
|
|
1021
|
+
severity: redactSensitiveText(safeString(item.severity)),
|
|
1022
|
+
status: redactSensitiveText(safeString(item.status)),
|
|
1023
|
+
score: finiteNum(item.score, 0),
|
|
1024
|
+
...(typeof item.durationMs === "number" && Number.isFinite(item.durationMs) ? { durationMs: item.durationMs } : {}),
|
|
1025
|
+
redacted: holdout,
|
|
1026
|
+
failures: holdout
|
|
1027
|
+
? (item.status === "fail" || item.status === "error" ? [safeHoldoutFailureMessage(item)] : [])
|
|
1028
|
+
: (Array.isArray(item.failures) ? item.failures.map((f) => redactSensitiveText(safeString(f))) : [])
|
|
1029
|
+
};
|
|
1030
|
+
if (holdout) {
|
|
1031
|
+
if (item.status === "skipped")
|
|
1032
|
+
record.reason = DEFAULT_HOLDOUT_SKIP_MSG;
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
if (typeof item.reason === "string" && item.reason.trim())
|
|
1036
|
+
record.reason = redactSensitiveText(item.reason);
|
|
1037
|
+
if (typeof item.diagnostic?.code === "string" && item.diagnostic.code)
|
|
1038
|
+
record.diagnosticCode = redactSensitiveText(item.diagnostic.code);
|
|
1039
|
+
}
|
|
1040
|
+
lines.push(JSON.stringify(record));
|
|
1041
|
+
}
|
|
1042
|
+
return lines.join("\n");
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
/** Returns a fresh PluginRegistry pre-loaded with all 3 built-in reference plugins. */
|
|
1046
|
+
export function createDefaultPluginRegistry() {
|
|
1047
|
+
const registry = new PluginRegistry();
|
|
1048
|
+
registry.register(svgA11yOraclePlugin);
|
|
1049
|
+
registry.register(stateFileDiffOraclePlugin);
|
|
1050
|
+
registry.register(ndjsonSummaryReporterPlugin);
|
|
1051
|
+
return registry;
|
|
1052
|
+
}
|