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,828 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { VibecodeError, errorMessage } from "../core/errors.js";
|
|
3
|
+
import { queryJsonPath, validateJsonSchema } from "../core/schema.js";
|
|
4
|
+
import { diffJsonSubset } from "../core/diff.js";
|
|
5
|
+
import { HTTP_HEADER_NAME_RE, STRICT_CONTROL_CHARS_RE, collectJsonSecrets, collectSecretValue, collectUrlSecrets, isForbiddenObjectKey, isRecordSafe, isSensitiveHeaderName, isSensitiveKeyName, isSensitiveQueryParamName, redactDeepValue, redactSecretSpans, redactSensitiveText, resolveSafeTargetUrl, safeOwnProp, stripTerminalEscapes } from "../core/security.js";
|
|
6
|
+
import { collectRuntimeSecretValues, mergeRuntimeVars } from "../core/target-map.js";
|
|
7
|
+
import { mergeHeaders } from "../ingestors/trace.js";
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = 10000;
|
|
9
|
+
const MAX_DEPTH = 32;
|
|
10
|
+
const MAX_PATH_LENGTH = 2048;
|
|
11
|
+
const MAX_PATH_TOKENS = 64;
|
|
12
|
+
const MAX_COOKIE_BYTES = 4096;
|
|
13
|
+
const MAX_COOKIE_NAME_BYTES = 256;
|
|
14
|
+
const MAX_COOKIE_PATH_BYTES = 1024;
|
|
15
|
+
const MAX_COOKIE_DOMAIN_BYTES = 255;
|
|
16
|
+
const MAX_SET_COOKIE_HEADER_BYTES = 64 * 1024;
|
|
17
|
+
const MAX_SINGLE_COOKIE_RAW_BYTES = 8192;
|
|
18
|
+
const HTTP_METHOD_RE = /^[A-Z!#$%&'*+\-.^_`|~0-9]+$/;
|
|
19
|
+
const COOKIE_DOMAIN_RE = /^[a-z0-9.-]+$/;
|
|
20
|
+
// eslint-disable-next-line no-control-regex
|
|
21
|
+
const CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/;
|
|
22
|
+
const TEMPLATE_SINGLE_RE = /^\{\{([^{}]+)\}\}$/;
|
|
23
|
+
const TEMPLATE_GLOBAL_RE = /\{\{([^{}]+)\}\}/g;
|
|
24
|
+
const FORBIDDEN_PATH_RE = /(?:^|[.[\]"'\s])(?:__proto__|constructor|prototype)(?:$|[.[\]"'\s])/;
|
|
25
|
+
const WORKFLOW_SECRET_OPTS = {};
|
|
26
|
+
const isObject = isRecordSafe;
|
|
27
|
+
const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
28
|
+
const posInt = (v, fb) => typeof v === "number" && Number.isFinite(v) && v > 0 ? Math.floor(v) : fb;
|
|
29
|
+
const isIp = (host) => /^\d{1,3}(?:\.\d{1,3}){3}$/.test(host) || host.includes(":");
|
|
30
|
+
const domainMatches = (host, dom) => host === dom || (!isIp(host) && !isIp(dom) && host.endsWith(`.${dom}`));
|
|
31
|
+
const pathMatches = (p, cp) => p === cp || (p.startsWith(cp) && (cp.endsWith("/") || p[cp.length] === "/"));
|
|
32
|
+
const defaultCookiePath = (p) => (!p || !p.startsWith("/") ? "/" : p.lastIndexOf("/") <= 0 ? "/" : p.slice(0, p.lastIndexOf("/")));
|
|
33
|
+
const isSensitiveKey = (name) => isSensitiveHeaderName(name) || isSensitiveKeyName(name);
|
|
34
|
+
const toStr = (v) => {
|
|
35
|
+
if (typeof v === "string")
|
|
36
|
+
return v;
|
|
37
|
+
if (v === null || v === undefined)
|
|
38
|
+
return "";
|
|
39
|
+
if (typeof v === "number" || typeof v === "boolean")
|
|
40
|
+
return String(v);
|
|
41
|
+
try {
|
|
42
|
+
return JSON.stringify(v);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return "[UNSERIALIZABLE]";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
function isCookieTokenChar(code) {
|
|
49
|
+
return ((code >= 48 && code <= 57) || // 0-9
|
|
50
|
+
(code >= 65 && code <= 90) || // A-Z
|
|
51
|
+
(code >= 97 && code <= 122) || // a-z
|
|
52
|
+
code === 33 || code === 35 || code === 36 || code === 37 || code === 38 ||
|
|
53
|
+
code === 39 || code === 42 || code === 43 || code === 45 || code === 46 ||
|
|
54
|
+
code === 94 || code === 95 || code === 96 || code === 124 || code === 126);
|
|
55
|
+
}
|
|
56
|
+
/** Strictly O(N) RFC 6265 Set-Cookie splitter that preserves commas inside Expires dates. */
|
|
57
|
+
function splitSetCookieHeader(combined) {
|
|
58
|
+
const out = [];
|
|
59
|
+
const len = combined.length;
|
|
60
|
+
let start = 0;
|
|
61
|
+
for (let i = 0; i < len; i++) {
|
|
62
|
+
if (combined.charCodeAt(i) !== 44)
|
|
63
|
+
continue; // ','
|
|
64
|
+
let j = i + 1;
|
|
65
|
+
while (j < len && (combined.charCodeAt(j) === 32 || combined.charCodeAt(j) === 9))
|
|
66
|
+
j++;
|
|
67
|
+
let k = j;
|
|
68
|
+
while (k < len && isCookieTokenChar(combined.charCodeAt(k)))
|
|
69
|
+
k++;
|
|
70
|
+
if (k > j && k < len && combined.charCodeAt(k) === 61) { // '='
|
|
71
|
+
const part = combined.slice(start, i).trim();
|
|
72
|
+
if (part)
|
|
73
|
+
out.push(part);
|
|
74
|
+
start = i + 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const tail = combined.slice(start).trim();
|
|
78
|
+
if (tail)
|
|
79
|
+
out.push(tail);
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/** Zero-dependency RFC 6265 cookie jar. */
|
|
83
|
+
export class CookieJar {
|
|
84
|
+
cookies;
|
|
85
|
+
maxCookies;
|
|
86
|
+
seq;
|
|
87
|
+
constructor(maxCookies = 128) {
|
|
88
|
+
this.cookies = new Map();
|
|
89
|
+
this.maxCookies = Math.max(1, Math.floor(maxCookies));
|
|
90
|
+
this.seq = 0;
|
|
91
|
+
}
|
|
92
|
+
storeFromHeaders(url, setCookieHeaders, nowMs = Date.now()) {
|
|
93
|
+
let parsed;
|
|
94
|
+
try {
|
|
95
|
+
parsed = new URL(url);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const reqHost = parsed.hostname.toLowerCase();
|
|
101
|
+
const defPath = defaultCookiePath(parsed.pathname);
|
|
102
|
+
for (const rawHeader of setCookieHeaders) {
|
|
103
|
+
if (typeof rawHeader !== "string" || !rawHeader.trim())
|
|
104
|
+
continue;
|
|
105
|
+
if (CONTROL_CHAR_RE.test(rawHeader) || Buffer.byteLength(rawHeader, "utf8") > MAX_SET_COOKIE_HEADER_BYTES)
|
|
106
|
+
continue;
|
|
107
|
+
for (const raw of splitSetCookieHeader(rawHeader)) {
|
|
108
|
+
if (!raw || CONTROL_CHAR_RE.test(raw) || Buffer.byteLength(raw, "utf8") > MAX_SINGLE_COOKIE_RAW_BYTES)
|
|
109
|
+
continue;
|
|
110
|
+
const parts = raw.split(";");
|
|
111
|
+
const first = parts[0] ?? "";
|
|
112
|
+
const eq = first.indexOf("=");
|
|
113
|
+
if (eq <= 0)
|
|
114
|
+
continue;
|
|
115
|
+
const name = first.slice(0, eq).trim();
|
|
116
|
+
const value = first.slice(eq + 1).trim();
|
|
117
|
+
if (!HTTP_HEADER_NAME_RE.test(name) || CONTROL_CHAR_RE.test(value) || value.includes(";"))
|
|
118
|
+
continue;
|
|
119
|
+
const nameBytes = Buffer.byteLength(name, "utf8");
|
|
120
|
+
const valBytes = Buffer.byteLength(value, "utf8");
|
|
121
|
+
if (nameBytes > MAX_COOKIE_NAME_BYTES || valBytes > MAX_COOKIE_BYTES)
|
|
122
|
+
continue;
|
|
123
|
+
let domain = reqHost, hostOnly = true, cookiePath = defPath, secure = false, httpOnly = false, hasMaxAge = false, rejected = false;
|
|
124
|
+
let expiresAt = null;
|
|
125
|
+
for (let i = 1; i < parts.length; i++) {
|
|
126
|
+
const attr = parts[i].trim();
|
|
127
|
+
if (!attr)
|
|
128
|
+
continue;
|
|
129
|
+
const aEq = attr.indexOf("=");
|
|
130
|
+
const aName = (aEq === -1 ? attr : attr.slice(0, aEq)).trim().toLowerCase();
|
|
131
|
+
const aVal = aEq === -1 ? "" : attr.slice(aEq + 1).trim();
|
|
132
|
+
if (aName === "domain") {
|
|
133
|
+
const stripped = aVal.startsWith(".") ? aVal.slice(1) : aVal;
|
|
134
|
+
const norm = stripped.toLowerCase();
|
|
135
|
+
if (!norm ||
|
|
136
|
+
norm.length > MAX_COOKIE_DOMAIN_BYTES ||
|
|
137
|
+
norm.startsWith(".") ||
|
|
138
|
+
norm.endsWith(".") ||
|
|
139
|
+
norm.includes("..") ||
|
|
140
|
+
!COOKIE_DOMAIN_RE.test(norm) ||
|
|
141
|
+
(norm !== reqHost && !norm.includes(".")) ||
|
|
142
|
+
!domainMatches(reqHost, norm)) {
|
|
143
|
+
rejected = true;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
domain = norm;
|
|
147
|
+
hostOnly = isIp(reqHost);
|
|
148
|
+
}
|
|
149
|
+
else if (aName === "path" && aVal.startsWith("/")) {
|
|
150
|
+
if (Buffer.byteLength(aVal, "utf8") > MAX_COOKIE_PATH_BYTES) {
|
|
151
|
+
rejected = true;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
cookiePath = aVal;
|
|
155
|
+
}
|
|
156
|
+
else if (aName === "max-age" && /^-?\d+$/.test(aVal)) {
|
|
157
|
+
hasMaxAge = true;
|
|
158
|
+
const secs = Number(aVal);
|
|
159
|
+
expiresAt = secs <= 0 ? 0 : Number.isFinite(secs) ? nowMs + secs * 1000 : Number.MAX_SAFE_INTEGER;
|
|
160
|
+
}
|
|
161
|
+
else if (aName === "expires" && !hasMaxAge) {
|
|
162
|
+
const ts = Date.parse(aVal);
|
|
163
|
+
if (Number.isFinite(ts))
|
|
164
|
+
expiresAt = ts;
|
|
165
|
+
}
|
|
166
|
+
else if (aName === "secure")
|
|
167
|
+
secure = true;
|
|
168
|
+
else if (aName === "httponly")
|
|
169
|
+
httpOnly = true;
|
|
170
|
+
}
|
|
171
|
+
if (rejected)
|
|
172
|
+
continue;
|
|
173
|
+
const key = `${domain}\0${cookiePath}\0${name}`;
|
|
174
|
+
if (expiresAt !== null && expiresAt <= nowMs) {
|
|
175
|
+
this.cookies.delete(key);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (!this.cookies.has(key) && this.cookies.size >= this.maxCookies) {
|
|
179
|
+
for (const [k, c] of this.cookies.entries())
|
|
180
|
+
if (c.expiresAt !== null && c.expiresAt <= nowMs)
|
|
181
|
+
this.cookies.delete(k);
|
|
182
|
+
if (this.cookies.size >= this.maxCookies) {
|
|
183
|
+
const oldest = this.cookies.keys().next().value;
|
|
184
|
+
if (oldest !== undefined)
|
|
185
|
+
this.cookies.delete(oldest);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
this.cookies.delete(key);
|
|
189
|
+
this.cookies.set(key, { name, value, domain, hostOnly, path: cookiePath, secure, httpOnly, expiresAt, createdAt: ++this.seq });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
getCookieHeader(url, nowMs = Date.now()) {
|
|
194
|
+
let parsed;
|
|
195
|
+
try {
|
|
196
|
+
parsed = new URL(url);
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const reqHost = parsed.hostname.toLowerCase();
|
|
202
|
+
const reqPath = parsed.pathname || "/";
|
|
203
|
+
const isHttps = parsed.protocol === "https:";
|
|
204
|
+
const matched = [];
|
|
205
|
+
for (const [key, c] of this.cookies.entries()) {
|
|
206
|
+
if (c.expiresAt !== null && c.expiresAt <= nowMs) {
|
|
207
|
+
this.cookies.delete(key);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (c.secure && !isHttps)
|
|
211
|
+
continue;
|
|
212
|
+
if ((c.hostOnly ? reqHost === c.domain : domainMatches(reqHost, c.domain)) && pathMatches(reqPath, c.path))
|
|
213
|
+
matched.push(c);
|
|
214
|
+
}
|
|
215
|
+
if (matched.length === 0)
|
|
216
|
+
return undefined;
|
|
217
|
+
matched.sort((a, b) => b.path.length - a.path.length || a.createdAt - b.createdAt);
|
|
218
|
+
return matched.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
219
|
+
}
|
|
220
|
+
clear() { this.cookies.clear(); }
|
|
221
|
+
}
|
|
222
|
+
function readScope(src, key) {
|
|
223
|
+
if (!src || !key || isForbiddenObjectKey(key))
|
|
224
|
+
return { found: false, value: undefined };
|
|
225
|
+
if (src instanceof Map)
|
|
226
|
+
return src.has(key) ? { found: true, value: src.get(key) } : { found: false, value: undefined };
|
|
227
|
+
return hasOwn(src, key) ? { found: true, value: safeOwnProp(src, key) } : { found: false, value: undefined };
|
|
228
|
+
}
|
|
229
|
+
function parseTokens(expr) {
|
|
230
|
+
if (!expr || expr.length > MAX_PATH_LENGTH)
|
|
231
|
+
return null;
|
|
232
|
+
const src = expr.startsWith("[") || expr.startsWith(".") ? expr : `.${expr}`;
|
|
233
|
+
const tokens = [];
|
|
234
|
+
const re = /\.([^.[\]]+)|\.?\[(\d+)\]|\.?\[(?:"([^"]*)"|'([^']*)')\]/g;
|
|
235
|
+
for (let i = 0; i < src.length;) {
|
|
236
|
+
if (tokens.length >= MAX_PATH_TOKENS)
|
|
237
|
+
return null;
|
|
238
|
+
re.lastIndex = i;
|
|
239
|
+
const m = re.exec(src);
|
|
240
|
+
if (!m || m.index !== i)
|
|
241
|
+
return null;
|
|
242
|
+
tokens.push(m[1] !== undefined ? m[1] : m[2] !== undefined ? Number(m[2]) : (m[3] ?? m[4] ?? ""));
|
|
243
|
+
i = re.lastIndex;
|
|
244
|
+
}
|
|
245
|
+
return tokens;
|
|
246
|
+
}
|
|
247
|
+
function safeQueryJsonPath(obj, expr) {
|
|
248
|
+
if (FORBIDDEN_PATH_RE.test(expr))
|
|
249
|
+
return { found: false, value: undefined, blocked: true };
|
|
250
|
+
return queryJsonPath(obj, expr);
|
|
251
|
+
}
|
|
252
|
+
function walkPath(root, tokens) {
|
|
253
|
+
let cur = root;
|
|
254
|
+
for (const tok of tokens) {
|
|
255
|
+
if ((typeof tok === "string" && isForbiddenObjectKey(tok)) || cur === null || cur === undefined)
|
|
256
|
+
return { found: false, value: undefined };
|
|
257
|
+
if (Array.isArray(cur)) {
|
|
258
|
+
const idx = typeof tok === "number" ? tok : /^\d+$/.test(tok) ? Number(tok) : -1;
|
|
259
|
+
if (idx < 0 || idx >= cur.length)
|
|
260
|
+
return { found: false, value: undefined };
|
|
261
|
+
cur = cur[idx];
|
|
262
|
+
}
|
|
263
|
+
else if (typeof cur === "object" && typeof tok === "string" && hasOwn(cur, tok)) {
|
|
264
|
+
cur = safeOwnProp(cur, tok);
|
|
265
|
+
}
|
|
266
|
+
else
|
|
267
|
+
return { found: false, value: undefined };
|
|
268
|
+
}
|
|
269
|
+
return { found: true, value: cur };
|
|
270
|
+
}
|
|
271
|
+
function resolveExpression(rawExpr, scope) {
|
|
272
|
+
const expr = rawExpr.trim();
|
|
273
|
+
if (!expr || FORBIDDEN_PATH_RE.test(expr))
|
|
274
|
+
return { found: false, value: undefined };
|
|
275
|
+
if (expr.startsWith("vars.")) {
|
|
276
|
+
const vp = expr.slice(5);
|
|
277
|
+
const direct = readScope(scope.vars, vp);
|
|
278
|
+
if (direct.found)
|
|
279
|
+
return direct;
|
|
280
|
+
const tokens = parseTokens(vp);
|
|
281
|
+
if (!tokens || tokens.length < 2 || typeof tokens[0] !== "string")
|
|
282
|
+
return { found: false, value: undefined };
|
|
283
|
+
const base = readScope(scope.vars, tokens[0]);
|
|
284
|
+
return base.found ? walkPath(base.value, tokens.slice(1)) : { found: false, value: undefined };
|
|
285
|
+
}
|
|
286
|
+
if (expr.startsWith("steps.")) {
|
|
287
|
+
const after = expr.slice(6);
|
|
288
|
+
const dot = after.indexOf(".");
|
|
289
|
+
if (dot <= 0)
|
|
290
|
+
return { found: false, value: undefined };
|
|
291
|
+
const entry = readScope(scope.steps, after.slice(0, dot));
|
|
292
|
+
if (!entry.found || !entry.value)
|
|
293
|
+
return { found: false, value: undefined };
|
|
294
|
+
const rec = entry.value;
|
|
295
|
+
const rest = after.slice(dot + 1);
|
|
296
|
+
if (rest === "status")
|
|
297
|
+
return { found: true, value: rec.status };
|
|
298
|
+
if (rest === "body")
|
|
299
|
+
return { found: true, value: rec.body };
|
|
300
|
+
if (rest.startsWith("headers.")) {
|
|
301
|
+
const target = rest.slice(8).trim().toLowerCase();
|
|
302
|
+
if (!target || isForbiddenObjectKey(target))
|
|
303
|
+
return { found: false, value: undefined };
|
|
304
|
+
for (const [k, v] of Object.entries(rec.headers || {}))
|
|
305
|
+
if (k.toLowerCase() === target)
|
|
306
|
+
return { found: true, value: v };
|
|
307
|
+
return { found: false, value: undefined };
|
|
308
|
+
}
|
|
309
|
+
if (rest.startsWith("extracted.")) {
|
|
310
|
+
const ep = rest.slice(10);
|
|
311
|
+
if (!isForbiddenObjectKey(ep) && hasOwn(rec.extracted, ep))
|
|
312
|
+
return { found: true, value: rec.extracted[ep] };
|
|
313
|
+
const tokens = parseTokens(ep);
|
|
314
|
+
return tokens ? walkPath(rec.extracted, tokens) : { found: false, value: undefined };
|
|
315
|
+
}
|
|
316
|
+
if (rest.startsWith("body.") || rest.startsWith("body[")) {
|
|
317
|
+
const tokens = parseTokens(rest.startsWith("body.") ? rest.slice(5) : rest.slice(4));
|
|
318
|
+
return tokens && tokens.length > 0 ? walkPath(rec.body, tokens) : { found: false, value: undefined };
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return { found: false, value: undefined };
|
|
322
|
+
}
|
|
323
|
+
/** Recursively interpolates `{{...}}` templates safely with prototype-pollution, cycle, and depth guards. */
|
|
324
|
+
export function interpolateWorkflowValue(value, scope) {
|
|
325
|
+
const unresolved = [];
|
|
326
|
+
const seen = new Set();
|
|
327
|
+
const ancestors = new WeakSet();
|
|
328
|
+
const mark = (k) => { if (!seen.has(k)) {
|
|
329
|
+
seen.add(k);
|
|
330
|
+
unresolved.push(k);
|
|
331
|
+
} };
|
|
332
|
+
const visit = (node, depth) => {
|
|
333
|
+
if (depth > MAX_DEPTH) {
|
|
334
|
+
mark("<max-depth-exceeded>");
|
|
335
|
+
return "[TRUNCATED]";
|
|
336
|
+
}
|
|
337
|
+
if (typeof node === "string") {
|
|
338
|
+
if (!node.includes("{{"))
|
|
339
|
+
return node;
|
|
340
|
+
const single = TEMPLATE_SINGLE_RE.exec(node);
|
|
341
|
+
if (single) {
|
|
342
|
+
const expr = single[1].trim();
|
|
343
|
+
const res = resolveExpression(expr, scope);
|
|
344
|
+
if (!res.found) {
|
|
345
|
+
mark(expr);
|
|
346
|
+
return node;
|
|
347
|
+
}
|
|
348
|
+
return res.value;
|
|
349
|
+
}
|
|
350
|
+
return node.replace(TEMPLATE_GLOBAL_RE, (full, rawExpr) => {
|
|
351
|
+
const expr = rawExpr.trim();
|
|
352
|
+
const res = resolveExpression(expr, scope);
|
|
353
|
+
if (!res.found) {
|
|
354
|
+
mark(expr);
|
|
355
|
+
return full;
|
|
356
|
+
}
|
|
357
|
+
return toStr(res.value);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (node !== null && typeof node === "object") {
|
|
361
|
+
if (ancestors.has(node)) {
|
|
362
|
+
mark("<circular-reference>");
|
|
363
|
+
return "[CIRCULAR]";
|
|
364
|
+
}
|
|
365
|
+
ancestors.add(node);
|
|
366
|
+
try {
|
|
367
|
+
if (Array.isArray(node))
|
|
368
|
+
return node.map((item) => visit(item, depth + 1));
|
|
369
|
+
if (isObject(node)) {
|
|
370
|
+
const out = {};
|
|
371
|
+
for (const [k, v] of Object.entries(node)) {
|
|
372
|
+
if (isForbiddenObjectKey(k))
|
|
373
|
+
continue;
|
|
374
|
+
Object.defineProperty(out, k, { value: visit(v, depth + 1), enumerable: true, writable: true, configurable: true });
|
|
375
|
+
}
|
|
376
|
+
return out;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
finally {
|
|
380
|
+
ancestors.delete(node);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return node;
|
|
384
|
+
};
|
|
385
|
+
return { value: visit(value, 0), unresolved };
|
|
386
|
+
}
|
|
387
|
+
function redactText(text, secrets) {
|
|
388
|
+
const raw = String(text ?? "");
|
|
389
|
+
if (!raw)
|
|
390
|
+
return "";
|
|
391
|
+
const preScrub = redactSecretSpans(raw, secrets);
|
|
392
|
+
const stripped = stripTerminalEscapes(preScrub);
|
|
393
|
+
return redactSensitiveText(redactSecretSpans(stripped, secrets));
|
|
394
|
+
}
|
|
395
|
+
function redactData(value, secrets) {
|
|
396
|
+
return redactDeepValue(value, {
|
|
397
|
+
maxDepth: MAX_DEPTH,
|
|
398
|
+
redactText: (s) => redactText(s, secrets),
|
|
399
|
+
sensitiveKeyMode: "value",
|
|
400
|
+
sensitivePathAware: true
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
function validateHeaders(raw, secrets) {
|
|
404
|
+
if (!isObject(raw))
|
|
405
|
+
return null;
|
|
406
|
+
for (const [rawKey, rawVal] of Object.entries(raw)) {
|
|
407
|
+
if (rawVal === undefined || rawVal === null)
|
|
408
|
+
continue;
|
|
409
|
+
const trimmed = rawKey.trim();
|
|
410
|
+
if (STRICT_CONTROL_CHARS_RE.test(rawKey) || !trimmed || !HTTP_HEADER_NAME_RE.test(trimmed)) {
|
|
411
|
+
return `invalid HTTP header name ${JSON.stringify(redactText(rawKey, secrets))}`;
|
|
412
|
+
}
|
|
413
|
+
const strVal = String(rawVal);
|
|
414
|
+
if (STRICT_CONTROL_CHARS_RE.test(strVal)) {
|
|
415
|
+
return `invalid HTTP header value for ${JSON.stringify(redactText(trimmed, secrets))}: contains control characters`;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
async function nativeFetchWithCookies(url, { method = "GET", headers = {}, body, timeoutMs = DEFAULT_TIMEOUT_MS } = {}) {
|
|
421
|
+
const ctrl = new AbortController();
|
|
422
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
423
|
+
try {
|
|
424
|
+
const payload = body === undefined || body === null ? undefined : typeof body === "string" ? body : JSON.stringify(body);
|
|
425
|
+
const res = await fetch(url, { method, headers, body: payload, signal: ctrl.signal });
|
|
426
|
+
const text = await res.text();
|
|
427
|
+
let json = null;
|
|
428
|
+
try {
|
|
429
|
+
json = text ? JSON.parse(text) : null;
|
|
430
|
+
}
|
|
431
|
+
catch { /* non-JSON */ }
|
|
432
|
+
const headersObj = {};
|
|
433
|
+
for (const [k, v] of res.headers.entries())
|
|
434
|
+
headersObj[k.toLowerCase()] = v;
|
|
435
|
+
const getSetCookie = res.headers.getSetCookie;
|
|
436
|
+
const rawSetCookies = typeof getSetCookie === "function"
|
|
437
|
+
? getSetCookie.call(res.headers)
|
|
438
|
+
: headersObj["set-cookie"] ? [headersObj["set-cookie"]] : [];
|
|
439
|
+
const setCookies = rawSetCookies.flatMap((h) => splitSetCookieHeader(h));
|
|
440
|
+
return { status: res.status, headers: headersObj, text, json, setCookies };
|
|
441
|
+
}
|
|
442
|
+
finally {
|
|
443
|
+
clearTimeout(timer);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function parseSteps(raw) {
|
|
447
|
+
if (!Array.isArray(raw))
|
|
448
|
+
return null;
|
|
449
|
+
for (const item of raw) {
|
|
450
|
+
if (!isObject(item) || typeof item.id !== "string" || !item.id.trim() || isForbiddenObjectKey(item.id.trim()) || typeof item.path !== "string") {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return raw;
|
|
455
|
+
}
|
|
456
|
+
function applyExtractions(step, obs, scope, secrets, failures) {
|
|
457
|
+
const extracted = Object.create(null);
|
|
458
|
+
if (!isObject(step.extract))
|
|
459
|
+
return extracted;
|
|
460
|
+
for (const [rawVarName, rawExpr] of Object.entries(step.extract)) {
|
|
461
|
+
const varName = rawVarName.trim();
|
|
462
|
+
if (!varName || isForbiddenObjectKey(varName) || FORBIDDEN_PATH_RE.test(rawVarName)) {
|
|
463
|
+
failures.push(`extract "${rawVarName}": forbidden variable name`);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (typeof rawExpr !== "string" || !rawExpr.trim()) {
|
|
467
|
+
failures.push(`extract "${varName}": invalid expression`);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const expr = rawExpr.trim();
|
|
471
|
+
let found = false, val;
|
|
472
|
+
if (expr.toLowerCase() === "status") {
|
|
473
|
+
found = true;
|
|
474
|
+
val = obs.status;
|
|
475
|
+
}
|
|
476
|
+
else if (/^header:/i.test(expr)) {
|
|
477
|
+
const hKey = expr.slice(7).trim().toLowerCase();
|
|
478
|
+
if (hKey && !isForbiddenObjectKey(hKey) && hasOwn(obs.headers, hKey)) {
|
|
479
|
+
found = true;
|
|
480
|
+
val = obs.headers[hKey];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else if (expr.startsWith("$")) {
|
|
484
|
+
if (FORBIDDEN_PATH_RE.test(expr)) {
|
|
485
|
+
failures.push(`extract "${varName}": blocked prototype key in "${expr}"`);
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (obs.json !== null && obs.json !== undefined) {
|
|
489
|
+
const q = safeQueryJsonPath(obs.json, expr);
|
|
490
|
+
if (q.blocked) {
|
|
491
|
+
failures.push(`extract "${varName}": blocked prototype key in "${expr}"`);
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
found = q.found;
|
|
495
|
+
val = q.value;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
failures.push(`extract "${varName}": unsupported extractor "${expr}"`);
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
if (!found) {
|
|
503
|
+
failures.push(`extract "${varName}" (${expr}): not found`);
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
extracted[varName] = val;
|
|
507
|
+
scope.vars.set(varName, val);
|
|
508
|
+
const valStr = toStr(val);
|
|
509
|
+
if (isSensitiveKeyName(varName) || isSensitiveKeyName(expr) || redactSensitiveText(valStr) !== valStr) {
|
|
510
|
+
collectSecretValue(secrets, valStr, WORKFLOW_SECRET_OPTS);
|
|
511
|
+
}
|
|
512
|
+
if (val !== null && typeof val === "object")
|
|
513
|
+
collectJsonSecrets(secrets, val, { maxDepth: MAX_DEPTH, ...WORKFLOW_SECRET_OPTS });
|
|
514
|
+
}
|
|
515
|
+
return extracted;
|
|
516
|
+
}
|
|
517
|
+
function evaluateExpectations(expected, obs, durationMs, failures, secrets) {
|
|
518
|
+
const diff = {};
|
|
519
|
+
if (!expected)
|
|
520
|
+
return diff;
|
|
521
|
+
const safeJson = (val) => JSON.stringify(redactData(val, secrets));
|
|
522
|
+
if (expected.status !== undefined) {
|
|
523
|
+
const accepted = Array.isArray(expected.status) ? expected.status : [expected.status];
|
|
524
|
+
if (!accepted.includes(obs.status))
|
|
525
|
+
failures.push(`status expected ${JSON.stringify(accepted)}, got ${obs.status}`);
|
|
526
|
+
}
|
|
527
|
+
if (typeof expected.maxLatencyMs === "number" && durationMs > expected.maxLatencyMs)
|
|
528
|
+
failures.push(`latency ${durationMs}ms > maxLatencyMs ${expected.maxLatencyMs}ms`);
|
|
529
|
+
if (expected.bodyExact !== undefined && obs.text !== String(expected.bodyExact))
|
|
530
|
+
failures.push("bodyExact mismatch");
|
|
531
|
+
if (expected.bodyContains !== undefined) {
|
|
532
|
+
for (const n of Array.isArray(expected.bodyContains) ? expected.bodyContains : [expected.bodyContains]) {
|
|
533
|
+
if (!obs.text.includes(String(n)))
|
|
534
|
+
failures.push(`body missing ${safeJson(String(n))}`);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
if (isObject(expected.headers)) {
|
|
538
|
+
for (const [k, v] of Object.entries(expected.headers)) {
|
|
539
|
+
const actual = obs.headers[k.toLowerCase()], expStr = String(v);
|
|
540
|
+
if (actual === undefined)
|
|
541
|
+
failures.push(`missing header ${k}`);
|
|
542
|
+
else if (actual.toLowerCase() !== expStr.toLowerCase() && !actual.toLowerCase().includes(expStr.toLowerCase())) {
|
|
543
|
+
const mask = isSensitiveKey(k);
|
|
544
|
+
failures.push(`header ${k} expected ${mask ? "[REDACTED]" : safeJson(expStr)}, got ${mask ? "[REDACTED]" : safeJson(actual)}`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (expected.jsonSchema) {
|
|
549
|
+
if (obs.json === null)
|
|
550
|
+
failures.push("response is not valid JSON (required by jsonSchema assertion)");
|
|
551
|
+
else {
|
|
552
|
+
const errs = validateJsonSchema(obs.json, expected.jsonSchema, "$");
|
|
553
|
+
if (errs.length > 0) {
|
|
554
|
+
for (const e of errs.slice(0, 10))
|
|
555
|
+
failures.push(`jsonSchema ${e.path}: ${e.message}`);
|
|
556
|
+
diff.jsonSchema = errs;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (expected.jsonSubset !== undefined) {
|
|
561
|
+
const sub = diffJsonSubset(expected.jsonSubset, obs.json, "$");
|
|
562
|
+
if (sub.length > 0) {
|
|
563
|
+
for (const e of sub.slice(0, 10)) {
|
|
564
|
+
const mask = isSensitiveKeyName(e.path);
|
|
565
|
+
failures.push(`jsonSubset ${e.path}: expected ${mask ? '"[REDACTED]"' : safeJson(e.expected)}, got ${mask ? '"[REDACTED]"' : safeJson(e.actual)}`);
|
|
566
|
+
}
|
|
567
|
+
diff.jsonSubset = sub;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const jpDiffs = [];
|
|
571
|
+
for (const a of expected.jsonPaths || []) {
|
|
572
|
+
if (FORBIDDEN_PATH_RE.test(a.path)) {
|
|
573
|
+
failures.push(`jsonPath ${a.path}: blocked prototype key`);
|
|
574
|
+
jpDiffs.push({ path: a.path, error: "blocked prototype key" });
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (obs.json === null) {
|
|
578
|
+
failures.push(`jsonPath ${a.path}: response is not valid JSON`);
|
|
579
|
+
jpDiffs.push({ path: a.path, expected: a.equals, actual: undefined });
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
const q = safeQueryJsonPath(obs.json, a.path);
|
|
583
|
+
if (q.blocked) {
|
|
584
|
+
failures.push(`jsonPath ${a.path}: blocked prototype key`);
|
|
585
|
+
jpDiffs.push({ path: a.path, error: "blocked prototype key" });
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
if (!q.found) {
|
|
589
|
+
failures.push(`jsonPath ${a.path}: not found`);
|
|
590
|
+
jpDiffs.push({ path: a.path, expected: a.equals, actual: undefined });
|
|
591
|
+
continue;
|
|
592
|
+
}
|
|
593
|
+
let ok = true;
|
|
594
|
+
if (hasOwn(a, "equals"))
|
|
595
|
+
ok = JSON.stringify(q.value) === JSON.stringify(a.equals);
|
|
596
|
+
else if (hasOwn(a, "matches")) {
|
|
597
|
+
if (typeof a.matches !== "string") {
|
|
598
|
+
failures.push(`jsonPath ${a.path}: invalid regex pattern`);
|
|
599
|
+
jpDiffs.push({ path: a.path, expected: a.matches, actual: q.value, error: "invalid regex pattern" });
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
try {
|
|
603
|
+
ok = new RegExp(a.matches).test(String(q.value));
|
|
604
|
+
}
|
|
605
|
+
catch (err) {
|
|
606
|
+
const msg = errorMessage(err);
|
|
607
|
+
failures.push(`jsonPath ${a.path}: invalid regex ${a.matches}: ${msg}`);
|
|
608
|
+
jpDiffs.push({ path: a.path, expected: a.matches, actual: q.value, error: msg });
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
if (!ok) {
|
|
613
|
+
const expVal = hasOwn(a, "equals") ? a.equals : a.matches;
|
|
614
|
+
const mask = isSensitiveKeyName(a.path);
|
|
615
|
+
failures.push(`jsonPath ${a.path}: expected ${mask ? '"[REDACTED]"' : safeJson(expVal)}, got ${mask ? '"[REDACTED]"' : safeJson(q.value)}`);
|
|
616
|
+
jpDiffs.push({ path: a.path, expected: expVal, actual: q.value });
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (jpDiffs.length > 0)
|
|
620
|
+
diff.jsonPaths = jpDiffs;
|
|
621
|
+
return diff;
|
|
622
|
+
}
|
|
623
|
+
/** Verifies a stateful multi-step HTTP workflow with RFC 6265 cookies, extraction, and guaranteed finally cleanup. */
|
|
624
|
+
export async function verifyHttpWorkflow(invariant, ctx, deps = {}) {
|
|
625
|
+
if (!ctx.target)
|
|
626
|
+
throw new VibecodeError("TARGET_MISSING", "Missing --target <base-url> for HTTP workflow verification.");
|
|
627
|
+
const rawInput = (invariant.input || {});
|
|
628
|
+
const steps = parseSteps(rawInput.steps);
|
|
629
|
+
if (!steps || steps.length === 0) {
|
|
630
|
+
return { status: "fail", score: 0, failures: ["http_workflow requires a non-empty input.steps array of { id, path } steps"], metrics: { totalSteps: 0, passedMainSteps: 0, finallyStepsExecuted: 0, stepSummaries: [] } };
|
|
631
|
+
}
|
|
632
|
+
const finallySteps = rawInput.finallySteps !== undefined ? parseSteps(rawInput.finallySteps) : [];
|
|
633
|
+
if (finallySteps === null) {
|
|
634
|
+
return { status: "fail", score: 0, failures: ["http_workflow input.finallySteps must be an array of { id, path } steps"], metrics: { totalSteps: steps.length, passedMainSteps: 0, finallyStepsExecuted: 0, stepSummaries: [] } };
|
|
635
|
+
}
|
|
636
|
+
const workflowTimeoutMs = posInt(rawInput.timeoutMs, DEFAULT_TIMEOUT_MS);
|
|
637
|
+
const useJar = rawInput.cookieJar !== false;
|
|
638
|
+
const cookieJar = new CookieJar();
|
|
639
|
+
const secrets = new Set();
|
|
640
|
+
const scope = { steps: new Map(), vars: new Map() };
|
|
641
|
+
collectUrlSecrets(secrets, ctx.target, WORKFLOW_SECRET_OPTS);
|
|
642
|
+
// Runtime vars (--var / VIBECODE_VAR_* / SDK ctx.vars) override contract input.vars in-memory only.
|
|
643
|
+
const contractVars = isObject(rawInput.vars) ? rawInput.vars : {};
|
|
644
|
+
const contractStringVars = {};
|
|
645
|
+
for (const [k, v] of Object.entries(contractVars))
|
|
646
|
+
if (typeof v === "string" && !isForbiddenObjectKey(k))
|
|
647
|
+
contractStringVars[k] = v;
|
|
648
|
+
const effectiveVars = { ...contractVars, ...mergeRuntimeVars(contractStringVars, ctx.vars) };
|
|
649
|
+
for (const [k, v] of Object.entries(effectiveVars)) {
|
|
650
|
+
if (isForbiddenObjectKey(k))
|
|
651
|
+
continue;
|
|
652
|
+
scope.vars.set(k, v);
|
|
653
|
+
if (typeof v === "string" && (isSensitiveKeyName(k) || redactSensitiveText(v) !== v))
|
|
654
|
+
collectSecretValue(secrets, v, WORKFLOW_SECRET_OPTS);
|
|
655
|
+
else if (v !== null && typeof v === "object")
|
|
656
|
+
collectJsonSecrets(secrets, v, { maxDepth: MAX_DEPTH, ...WORKFLOW_SECRET_OPTS });
|
|
657
|
+
}
|
|
658
|
+
for (const runtimeSecret of collectRuntimeSecretValues(ctx.vars))
|
|
659
|
+
collectSecretValue(secrets, runtimeSecret, WORKFLOW_SECRET_OPTS);
|
|
660
|
+
if (isObject(ctx.headers))
|
|
661
|
+
for (const [k, v] of Object.entries(ctx.headers))
|
|
662
|
+
if (isSensitiveKey(k))
|
|
663
|
+
collectSecretValue(secrets, v, WORKFLOW_SECRET_OPTS);
|
|
664
|
+
const startedAt = Date.now();
|
|
665
|
+
const stepSummaries = [];
|
|
666
|
+
const topFailures = [];
|
|
667
|
+
const stepDiffs = {};
|
|
668
|
+
const digestEntries = [];
|
|
669
|
+
let failedStepId;
|
|
670
|
+
async function runStep(step, phase) {
|
|
671
|
+
const t0 = Date.now(), method = String(step.method || "GET").trim().toUpperCase();
|
|
672
|
+
const unresolved = [];
|
|
673
|
+
const interp = (val) => { const r = interpolateWorkflowValue(val, scope); for (const u of r.unresolved)
|
|
674
|
+
if (!unresolved.includes(u))
|
|
675
|
+
unresolved.push(u); return r.value; };
|
|
676
|
+
const resolvedPath = toStr(interp(step.path));
|
|
677
|
+
collectUrlSecrets(secrets, resolvedPath, WORKFLOW_SECRET_OPTS);
|
|
678
|
+
const rawQuery = isObject(step.query) ? interp(step.query) : undefined;
|
|
679
|
+
const resolvedQuery = rawQuery ? Object.fromEntries(Object.entries(rawQuery).filter(([, v]) => v !== undefined && v !== null).map(([k, v]) => {
|
|
680
|
+
const c = typeof v === "number" || typeof v === "boolean" ? v : String(v);
|
|
681
|
+
if (isSensitiveQueryParamName(k) || isSensitiveKeyName(k))
|
|
682
|
+
collectSecretValue(secrets, String(c), WORKFLOW_SECRET_OPTS);
|
|
683
|
+
return [k, c];
|
|
684
|
+
})) : undefined;
|
|
685
|
+
const rawHeaders = isObject(step.headers) ? interp(step.headers) : undefined;
|
|
686
|
+
if (isObject(rawHeaders)) {
|
|
687
|
+
for (const [k, v] of Object.entries(rawHeaders)) {
|
|
688
|
+
if (v !== undefined && v !== null && isSensitiveKey(k))
|
|
689
|
+
collectSecretValue(secrets, String(v), WORKFLOW_SECRET_OPTS);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
const resolvedBody = step.body !== undefined ? interp(step.body) : undefined;
|
|
693
|
+
collectJsonSecrets(secrets, resolvedBody, { maxDepth: MAX_DEPTH, ...WORKFLOW_SECRET_OPTS });
|
|
694
|
+
const resolvedExpected = step.expected ? interp(step.expected) : undefined;
|
|
695
|
+
let url;
|
|
696
|
+
try {
|
|
697
|
+
url = resolveSafeTargetUrl(resolvedPath, ctx.target, { query: resolvedQuery }).toString();
|
|
698
|
+
}
|
|
699
|
+
catch (err) {
|
|
700
|
+
return { id: redactText(step.id, secrets), method, url: redactText(String(step.path), secrets), durationMs: Date.now() - t0, passed: false, phase, failures: [redactText(`invalid URL: ${errorMessage(err)}`, secrets)] };
|
|
701
|
+
}
|
|
702
|
+
collectUrlSecrets(secrets, url, WORKFLOW_SECRET_OPTS);
|
|
703
|
+
const safeUrl = redactText(url, secrets);
|
|
704
|
+
if (!HTTP_METHOD_RE.test(method)) {
|
|
705
|
+
return { id: redactText(step.id, secrets), method: redactText(method, secrets), url: safeUrl, durationMs: Date.now() - t0, passed: false, phase, failures: [redactText(`invalid HTTP method: ${JSON.stringify(method)}`, secrets)] };
|
|
706
|
+
}
|
|
707
|
+
if (unresolved.length > 0) {
|
|
708
|
+
const msgs = unresolved.map((u) => redactText(FORBIDDEN_PATH_RE.test(u) ? `blocked prototype key in template expression "${u}"` : `unresolved template expression "${u}"`, secrets));
|
|
709
|
+
return { id: redactText(step.id, secrets), method, url: safeUrl, durationMs: Date.now() - t0, passed: false, phase, failures: msgs };
|
|
710
|
+
}
|
|
711
|
+
const headerErr = validateHeaders(ctx.headers, secrets) ?? validateHeaders(rawHeaders, secrets);
|
|
712
|
+
if (headerErr) {
|
|
713
|
+
return { id: redactText(step.id, secrets), method, url: safeUrl, durationMs: Date.now() - t0, passed: false, phase, failures: [redactText(headerErr, secrets)] };
|
|
714
|
+
}
|
|
715
|
+
const resolvedHeaders = rawHeaders ? Object.fromEntries(Object.entries(rawHeaders).filter(([, v]) => v !== undefined && v !== null).map(([k, v]) => [k, String(v)])) : undefined;
|
|
716
|
+
const headers = mergeHeaders(ctx.headers, resolvedHeaders);
|
|
717
|
+
if (useJar) {
|
|
718
|
+
const jarCookie = cookieJar.getCookieHeader(url);
|
|
719
|
+
if (jarCookie) {
|
|
720
|
+
const key = Object.keys(headers).find((k) => k.toLowerCase() === "cookie");
|
|
721
|
+
headers[key || "Cookie"] = key ? `${headers[key]}; ${jarCookie}` : jarCookie;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (resolvedBody !== undefined && resolvedBody !== null && typeof resolvedBody !== "string" && !Object.keys(headers).some((k) => k.toLowerCase() === "content-type")) {
|
|
725
|
+
headers["Content-Type"] = "application/json";
|
|
726
|
+
}
|
|
727
|
+
const mergedHeaderErr = validateHeaders(headers, secrets);
|
|
728
|
+
if (mergedHeaderErr) {
|
|
729
|
+
return { id: redactText(step.id, secrets), method, url: safeUrl, durationMs: Date.now() - t0, passed: false, phase, failures: [redactText(mergedHeaderErr, secrets)] };
|
|
730
|
+
}
|
|
731
|
+
const stepTimeoutMs = posInt(step.timeoutMs, workflowTimeoutMs);
|
|
732
|
+
let obs;
|
|
733
|
+
try {
|
|
734
|
+
if (deps.fetchWithTimeout) {
|
|
735
|
+
const raw = await deps.fetchWithTimeout(url, { method, headers, body: resolvedBody, timeoutMs: stepTimeoutMs });
|
|
736
|
+
const normHeaders = {};
|
|
737
|
+
for (const [hk, hv] of Object.entries(raw.headers || {}))
|
|
738
|
+
normHeaders[hk.toLowerCase()] = hv;
|
|
739
|
+
obs = { ...raw, headers: normHeaders, setCookies: normHeaders["set-cookie"] ? splitSetCookieHeader(normHeaders["set-cookie"]) : [] };
|
|
740
|
+
}
|
|
741
|
+
else {
|
|
742
|
+
obs = await nativeFetchWithCookies(url, { method, headers, body: resolvedBody, timeoutMs: stepTimeoutMs });
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
catch (err) {
|
|
746
|
+
return { id: redactText(step.id, secrets), method, url: safeUrl, durationMs: Date.now() - t0, passed: false, phase, failures: [redactText(`request failed: ${errorMessage(err)}`, secrets)] };
|
|
747
|
+
}
|
|
748
|
+
const durationMs = Date.now() - t0;
|
|
749
|
+
for (const sc of obs.setCookies) {
|
|
750
|
+
const first = sc.split(";")[0] ?? "";
|
|
751
|
+
const eq = first.indexOf("=");
|
|
752
|
+
if (eq > 0)
|
|
753
|
+
collectSecretValue(secrets, first.slice(eq + 1), WORKFLOW_SECRET_OPTS);
|
|
754
|
+
}
|
|
755
|
+
collectJsonSecrets(secrets, obs.json, { maxDepth: MAX_DEPTH, ...WORKFLOW_SECRET_OPTS });
|
|
756
|
+
for (const [hk, hv] of Object.entries(obs.headers))
|
|
757
|
+
if (isSensitiveKey(hk))
|
|
758
|
+
collectSecretValue(secrets, hv, WORKFLOW_SECRET_OPTS);
|
|
759
|
+
if (useJar && obs.setCookies.length > 0)
|
|
760
|
+
cookieJar.storeFromHeaders(url, obs.setCookies);
|
|
761
|
+
const stepFailures = [];
|
|
762
|
+
const extracted = applyExtractions(step, obs, scope, secrets, stepFailures);
|
|
763
|
+
scope.steps.set(step.id, { status: obs.status, headers: obs.headers, body: obs.json, text: obs.text, extracted });
|
|
764
|
+
const rawDiff = evaluateExpectations(resolvedExpected, obs, durationMs, stepFailures, secrets);
|
|
765
|
+
if (Object.keys(rawDiff).length > 0) {
|
|
766
|
+
const diffKey = redactText(phase === "finally" ? `finally:${step.id}` : step.id, secrets);
|
|
767
|
+
if (!isForbiddenObjectKey(diffKey)) {
|
|
768
|
+
Object.defineProperty(stepDiffs, diffKey, { value: redactData(rawDiff, secrets), enumerable: true, writable: true, configurable: true });
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
const redactedFailures = stepFailures.map((f) => redactText(f, secrets));
|
|
772
|
+
digestEntries.push(`${phase}:${step.id}:${obs.status}:${redactText(obs.text.trim(), secrets)}`);
|
|
773
|
+
return { id: redactText(step.id, secrets), method, url: redactText(url, secrets), status: obs.status, durationMs, passed: redactedFailures.length === 0, phase, failures: redactedFailures };
|
|
774
|
+
}
|
|
775
|
+
try {
|
|
776
|
+
for (const step of steps) {
|
|
777
|
+
const summary = await runStep(step, "main");
|
|
778
|
+
stepSummaries.push(summary);
|
|
779
|
+
if (!summary.passed) {
|
|
780
|
+
failedStepId = step.id;
|
|
781
|
+
for (const f of summary.failures)
|
|
782
|
+
topFailures.push(redactText(`step ${step.id} failed: ${f}`, secrets));
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
finally {
|
|
788
|
+
for (const step of finallySteps) {
|
|
789
|
+
const summary = await runStep(step, "finally");
|
|
790
|
+
stepSummaries.push(summary);
|
|
791
|
+
if (!summary.passed)
|
|
792
|
+
for (const f of summary.failures)
|
|
793
|
+
topFailures.push(redactText(`finally step ${step.id} failed: ${f}`, secrets));
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
const finalFailures = topFailures.map((f) => redactText(f, secrets));
|
|
797
|
+
const finalSummaries = stepSummaries.map((s) => ({
|
|
798
|
+
...s,
|
|
799
|
+
id: redactText(s.id, secrets),
|
|
800
|
+
url: redactText(s.url, secrets),
|
|
801
|
+
failures: s.failures.map((f) => redactText(f, secrets))
|
|
802
|
+
}));
|
|
803
|
+
const candidateOutputHash = digestEntries.length > 0 ? crypto.createHash("sha256").update(digestEntries.map((d) => redactText(d, secrets)).join("\n"), "utf8").digest("hex") : undefined;
|
|
804
|
+
const diff = {};
|
|
805
|
+
if (failedStepId) {
|
|
806
|
+
diff.code = "STATE_ORDER_BROKEN";
|
|
807
|
+
diff.failedStepId = redactText(failedStepId, secrets);
|
|
808
|
+
}
|
|
809
|
+
if (Object.keys(stepDiffs).length > 0)
|
|
810
|
+
diff.steps = redactData(stepDiffs, secrets);
|
|
811
|
+
return {
|
|
812
|
+
status: finalFailures.length === 0 ? "pass" : "fail",
|
|
813
|
+
score: finalFailures.length === 0 ? 1 : 0,
|
|
814
|
+
failures: finalFailures,
|
|
815
|
+
...(Object.keys(diff).length > 0 ? { diff } : {}),
|
|
816
|
+
metrics: {
|
|
817
|
+
totalSteps: steps.length,
|
|
818
|
+
executedMainSteps: finalSummaries.filter((s) => s.phase === "main").length,
|
|
819
|
+
passedMainSteps: finalSummaries.filter((s) => s.phase === "main" && s.passed).length,
|
|
820
|
+
finallyStepsExecuted: finalSummaries.filter((s) => s.phase === "finally").length,
|
|
821
|
+
finallyStepsPassed: finalSummaries.filter((s) => s.phase === "finally" && s.passed).length,
|
|
822
|
+
durationMs: Date.now() - startedAt,
|
|
823
|
+
stepSummaries: finalSummaries,
|
|
824
|
+
...(candidateOutputHash ? { candidateOutputHash } : {})
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
export const verifyInvariant = verifyHttpWorkflow;
|