vibecode-anything 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +407 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2519 -0
- package/dist/core/adapters.d.ts +31 -0
- package/dist/core/adapters.js +478 -0
- 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/diff.d.ts +10 -0
- package/dist/core/diff.js +207 -0
- package/dist/core/docs-export.d.ts +37 -0
- package/dist/core/docs-export.js +2706 -0
- package/dist/core/doctor.d.ts +70 -0
- package/dist/core/doctor.js +525 -0
- package/dist/core/errors.d.ts +32 -0
- package/dist/core/errors.js +81 -0
- package/dist/core/exec.d.ts +38 -0
- package/dist/core/exec.js +336 -0
- 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 +14 -0
- package/dist/core/parity.js +173 -0
- package/dist/core/playwright-exporter.d.ts +23 -0
- package/dist/core/playwright-exporter.js +1343 -0
- package/dist/core/png.d.ts +7 -0
- package/dist/core/png.js +339 -0
- 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 +18 -0
- package/dist/core/schema.js +1057 -0
- 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/slices.d.ts +24 -0
- package/dist/core/slices.js +294 -0
- package/dist/core/spec-writer.d.ts +9 -0
- package/dist/core/spec-writer.js +1202 -0
- package/dist/core/store.d.ts +26 -0
- package/dist/core/store.js +217 -0
- 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 +919 -0
- package/dist/core/types.js +4 -0
- package/dist/core/visual-semantic.d.ts +67 -0
- package/dist/core/visual-semantic.js +673 -0
- package/dist/core/visual.d.ts +34 -0
- package/dist/core/visual.js +508 -0
- package/dist/core/watch.d.ts +78 -0
- package/dist/core/watch.js +495 -0
- 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 +6 -0
- package/dist/ingestors/api-repo.js +1120 -0
- package/dist/ingestors/asyncapi.d.ts +26 -0
- package/dist/ingestors/asyncapi.js +2105 -0
- package/dist/ingestors/bridges.d.ts +5 -0
- package/dist/ingestors/bridges.js +1264 -0
- package/dist/ingestors/cli.d.ts +10 -0
- package/dist/ingestors/cli.js +454 -0
- 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/image.d.ts +2 -0
- package/dist/ingestors/image.js +147 -0
- package/dist/ingestors/index.d.ts +5 -0
- package/dist/ingestors/index.js +577 -0
- 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 +50 -0
- package/dist/ingestors/video.js +655 -0
- package/dist/ingestors/web.d.ts +40 -0
- package/dist/ingestors/web.js +839 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +3969 -0
- package/dist/oracles/api-repo.d.ts +2 -0
- package/dist/oracles/api-repo.js +286 -0
- package/dist/oracles/cli.d.ts +2 -0
- package/dist/oracles/cli.js +205 -0
- package/dist/oracles/http-workflow.d.ts +68 -0
- package/dist/oracles/http-workflow.js +828 -0
- package/dist/oracles/image.d.ts +2 -0
- package/dist/oracles/image.js +429 -0
- package/dist/oracles/index.d.ts +6 -0
- package/dist/oracles/index.js +320 -0
- 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 +21 -0
- package/dist/oracles/video.js +627 -0
- package/dist/oracles/web.d.ts +2 -0
- package/dist/oracles/web.js +871 -0
- 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.d.ts +7 -0
- package/dist/setup/index.js +298 -0
- package/package.json +54 -4
- package/skills/vibecode-anything/SKILL.md +75 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { VibecodeError, errorMessage } from "../core/errors.js";
|
|
5
|
+
import { validateJsonSchema, queryJsonPath } from "../core/schema.js";
|
|
6
|
+
import { diffJsonSubset } from "../core/diff.js";
|
|
7
|
+
import { collectHeaderSecrets, collectJsonSecrets, collectSecretValue, collectUrlSecrets, hasCrossPlatformPathEscape, isInsideVaultDirectory, isPathWithinDir, isRecordSafe, isSensitiveKeyName, isSensitiveQueryParamName, redactDeepValue, redactSecretSpans, redactSensitiveText, resolveSafeTargetUrl } from "../core/security.js";
|
|
8
|
+
import { scanExportsFromFile } from "../ingestors/api-repo.js";
|
|
9
|
+
import { mergeHeaders } from "../ingestors/trace.js";
|
|
10
|
+
const isObject = isRecordSafe;
|
|
11
|
+
function redactApiText(text, secrets) {
|
|
12
|
+
const raw = String(text ?? "");
|
|
13
|
+
if (!raw)
|
|
14
|
+
return "";
|
|
15
|
+
return redactSensitiveText(secrets.size > 0 ? redactSecretSpans(raw, secrets) : raw);
|
|
16
|
+
}
|
|
17
|
+
async function fetchWithTimeout(url, { method = "GET", headers = {}, body, timeoutMs = 10000 } = {}) {
|
|
18
|
+
const ctrl = new AbortController();
|
|
19
|
+
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
20
|
+
try {
|
|
21
|
+
const res = await fetch(url, {
|
|
22
|
+
method,
|
|
23
|
+
headers,
|
|
24
|
+
body: body === undefined || body === null ? undefined : (typeof body === "string" ? body : JSON.stringify(body)),
|
|
25
|
+
signal: ctrl.signal
|
|
26
|
+
});
|
|
27
|
+
const text = await res.text();
|
|
28
|
+
let json = null;
|
|
29
|
+
try {
|
|
30
|
+
json = text ? JSON.parse(text) : null;
|
|
31
|
+
}
|
|
32
|
+
catch { /* ignore */ }
|
|
33
|
+
const headersObj = {};
|
|
34
|
+
for (const [k, v] of res.headers.entries())
|
|
35
|
+
headersObj[k.toLowerCase()] = v;
|
|
36
|
+
return { status: res.status, headers: headersObj, text, json };
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
clearTimeout(t);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function verifyHttp(invariant, ctx, deps) {
|
|
43
|
+
if (!ctx.target)
|
|
44
|
+
throw new VibecodeError("TARGET_MISSING", "Missing --target <base-url> for HTTP verification.");
|
|
45
|
+
const input = invariant.input || {};
|
|
46
|
+
const expected = invariant.expected || {};
|
|
47
|
+
const method = String(input.method || "GET").toUpperCase();
|
|
48
|
+
const secrets = new Set();
|
|
49
|
+
collectUrlSecrets(secrets, ctx.target);
|
|
50
|
+
if (typeof input.path === "string")
|
|
51
|
+
collectUrlSecrets(secrets, input.path);
|
|
52
|
+
if (isObject(input.query)) {
|
|
53
|
+
for (const [qk, qv] of Object.entries(input.query)) {
|
|
54
|
+
if (qv !== undefined && qv !== null && (isSensitiveQueryParamName(qk) || isSensitiveKeyName(qk))) {
|
|
55
|
+
collectSecretValue(secrets, String(qv));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
collectHeaderSecrets(secrets, isObject(input.headers) ? input.headers : undefined);
|
|
60
|
+
collectHeaderSecrets(secrets, ctx.headers);
|
|
61
|
+
let url;
|
|
62
|
+
try {
|
|
63
|
+
url = resolveSafeTargetUrl(input.path || "/", ctx.target, { query: input.query }).toString();
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
const rawDisplay = typeof input.path === "string" && input.path.trim() ? input.path : ctx.target;
|
|
67
|
+
return {
|
|
68
|
+
status: "fail",
|
|
69
|
+
score: 0,
|
|
70
|
+
failures: [redactApiText(`invalid HTTP URL: ${errorMessage(err)}`, secrets)],
|
|
71
|
+
metrics: { url: redactApiText(rawDisplay, secrets), method: redactApiText(method, secrets) }
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
collectUrlSecrets(secrets, url);
|
|
75
|
+
const safeUrl = redactApiText(url, secrets);
|
|
76
|
+
const headers = mergeHeaders(isObject(input.headers) ? input.headers : undefined, ctx.headers);
|
|
77
|
+
const timeoutMs = input.timeoutMs || 10000;
|
|
78
|
+
const body = input.body ?? null;
|
|
79
|
+
collectJsonSecrets(secrets, body, { maxDepth: 24 });
|
|
80
|
+
let obs;
|
|
81
|
+
const started = Date.now();
|
|
82
|
+
try {
|
|
83
|
+
obs = await (deps.fetchWithTimeout || fetchWithTimeout)(url, { method, headers, body, timeoutMs });
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return {
|
|
87
|
+
status: "fail",
|
|
88
|
+
score: 0,
|
|
89
|
+
failures: [redactApiText(`request failed: ${errorMessage(err)}`, secrets)],
|
|
90
|
+
metrics: { url: safeUrl, method: redactApiText(method, secrets) }
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const durationMs = Date.now() - started;
|
|
94
|
+
collectJsonSecrets(secrets, obs.json, { maxDepth: 24 });
|
|
95
|
+
const failures = [];
|
|
96
|
+
const diff = {};
|
|
97
|
+
if (expected.status !== undefined) {
|
|
98
|
+
const accepted = Array.isArray(expected.status) ? expected.status : [expected.status];
|
|
99
|
+
if (!accepted.includes(obs.status)) {
|
|
100
|
+
failures.push(`status expected ${JSON.stringify(accepted)}, got ${obs.status}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (typeof expected.maxLatencyMs === "number" && durationMs > expected.maxLatencyMs) {
|
|
104
|
+
failures.push(`latency ${durationMs}ms > maxLatencyMs ${expected.maxLatencyMs}ms`);
|
|
105
|
+
}
|
|
106
|
+
if (expected.bodyExact !== undefined && obs.text !== String(expected.bodyExact)) {
|
|
107
|
+
failures.push("bodyExact mismatch");
|
|
108
|
+
}
|
|
109
|
+
if (expected.bodyContains !== undefined) {
|
|
110
|
+
const needles = Array.isArray(expected.bodyContains) ? expected.bodyContains : [expected.bodyContains];
|
|
111
|
+
for (const n of needles) {
|
|
112
|
+
if (!obs.text.includes(String(n)))
|
|
113
|
+
failures.push(`body missing ${JSON.stringify(n)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (isObject(expected.headers)) {
|
|
117
|
+
for (const [k, v] of Object.entries(expected.headers)) {
|
|
118
|
+
const actual = obs.headers[String(k).toLowerCase()];
|
|
119
|
+
if (actual === undefined)
|
|
120
|
+
failures.push(`missing header ${k}`);
|
|
121
|
+
else if (String(actual).toLowerCase() !== String(v).toLowerCase() && !String(actual).toLowerCase().includes(String(v).toLowerCase())) {
|
|
122
|
+
failures.push(`header ${k} expected ${JSON.stringify(v)}, got ${JSON.stringify(actual)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (expected.jsonSchema) {
|
|
127
|
+
if (obs.json === null) {
|
|
128
|
+
failures.push("response is not valid JSON (required by jsonSchema assertion)");
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const schemaErrors = validateJsonSchema(obs.json, expected.jsonSchema, "$");
|
|
132
|
+
if (schemaErrors.length) {
|
|
133
|
+
for (const e of schemaErrors.slice(0, 10))
|
|
134
|
+
failures.push(`jsonSchema ${e.path}: ${e.message}`);
|
|
135
|
+
diff.jsonSchema = schemaErrors;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (expected.jsonSubset !== undefined) {
|
|
140
|
+
const subsetDiff = diffJsonSubset(expected.jsonSubset, obs.json, "$");
|
|
141
|
+
if (subsetDiff.length) {
|
|
142
|
+
for (const e of subsetDiff.slice(0, 10))
|
|
143
|
+
failures.push(`jsonSubset ${e.path}: expected ${JSON.stringify(e.expected)}, got ${JSON.stringify(e.actual)}`);
|
|
144
|
+
diff.jsonSubset = subsetDiff;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const jsonPathDiffs = [];
|
|
148
|
+
for (const assertion of expected.jsonPaths || []) {
|
|
149
|
+
if (obs.json === null) {
|
|
150
|
+
failures.push(`jsonPath ${assertion.path}: response is not valid JSON`);
|
|
151
|
+
jsonPathDiffs.push({ path: assertion.path, expected: assertion.equals, actual: undefined });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const q = queryJsonPath(obs.json, assertion.path);
|
|
155
|
+
if (!q.found) {
|
|
156
|
+
failures.push(`jsonPath ${assertion.path}: not found`);
|
|
157
|
+
jsonPathDiffs.push({ path: assertion.path, expected: assertion.equals, actual: undefined });
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
let ok = true;
|
|
161
|
+
if (Object.prototype.hasOwnProperty.call(assertion, "equals")) {
|
|
162
|
+
ok = JSON.stringify(q.value) === JSON.stringify(assertion.equals);
|
|
163
|
+
}
|
|
164
|
+
else if (Object.prototype.hasOwnProperty.call(assertion, "matches")) {
|
|
165
|
+
try {
|
|
166
|
+
ok = new RegExp(assertion.matches ?? "").test(String(q.value));
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
const msg = errorMessage(err);
|
|
170
|
+
failures.push(`jsonPath ${assertion.path}: invalid regex ${assertion.matches}: ${msg}`);
|
|
171
|
+
jsonPathDiffs.push({ path: assertion.path, expected: assertion.matches, actual: q.value, error: msg });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!ok) {
|
|
176
|
+
const expectedVal = Object.prototype.hasOwnProperty.call(assertion, "equals") ? assertion.equals : assertion.matches;
|
|
177
|
+
failures.push(`jsonPath ${assertion.path}: expected ${JSON.stringify(expectedVal)}, got ${JSON.stringify(q.value)}`);
|
|
178
|
+
jsonPathDiffs.push({ path: assertion.path, expected: expectedVal, actual: q.value });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (jsonPathDiffs.length > 0)
|
|
182
|
+
diff.jsonPaths = jsonPathDiffs;
|
|
183
|
+
const trimmedText = obs.text.trim();
|
|
184
|
+
const candidateOutputHash = trimmedText.length > 0
|
|
185
|
+
? crypto.createHash("sha256").update(trimmedText, "utf8").digest("hex")
|
|
186
|
+
: undefined;
|
|
187
|
+
const scrubbedDiff = Object.keys(diff).length > 0
|
|
188
|
+
? redactDeepValue(diff, {
|
|
189
|
+
maxDepth: 24,
|
|
190
|
+
redactText: (s) => redactApiText(s, secrets),
|
|
191
|
+
sensitiveKeyMode: "value",
|
|
192
|
+
sensitivePathAware: true
|
|
193
|
+
})
|
|
194
|
+
: undefined;
|
|
195
|
+
return {
|
|
196
|
+
status: failures.length ? "fail" : "pass",
|
|
197
|
+
score: failures.length ? 0 : 1,
|
|
198
|
+
failures: failures.map((f) => redactApiText(f, secrets)),
|
|
199
|
+
...(scrubbedDiff ? { diff: scrubbedDiff } : {}),
|
|
200
|
+
metrics: {
|
|
201
|
+
url: safeUrl,
|
|
202
|
+
method: redactApiText(method, secrets),
|
|
203
|
+
status: obs.status,
|
|
204
|
+
bytes: obs.text.length,
|
|
205
|
+
durationMs,
|
|
206
|
+
...(candidateOutputHash ? { candidateOutputHash } : {})
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function resolveRepoSubpath(repoDir, rawRel) {
|
|
211
|
+
if (!rawRel || hasCrossPlatformPathEscape(rawRel) || path.isAbsolute(rawRel))
|
|
212
|
+
return null;
|
|
213
|
+
const resolved = path.resolve(repoDir, rawRel);
|
|
214
|
+
if (!isPathWithinDir(resolved, repoDir, { allowEqual: false }))
|
|
215
|
+
return null;
|
|
216
|
+
if (isInsideVaultDirectory(resolved))
|
|
217
|
+
return null;
|
|
218
|
+
try {
|
|
219
|
+
if (fs.existsSync(resolved)) {
|
|
220
|
+
const realRepo = fs.realpathSync(repoDir);
|
|
221
|
+
const realTarget = fs.realpathSync(resolved);
|
|
222
|
+
if (!isPathWithinDir(realTarget, realRepo, { allowEqual: false }) || isInsideVaultDirectory(realTarget))
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return resolved;
|
|
230
|
+
}
|
|
231
|
+
async function verifyRepoExports(invariant, ctx, _deps) {
|
|
232
|
+
if (!ctx.target)
|
|
233
|
+
throw new VibecodeError("TARGET_MISSING", "Missing --target <repo-dir> for repo verification.");
|
|
234
|
+
const repoDir = path.resolve(ctx.cwd || process.cwd(), ctx.target);
|
|
235
|
+
if (isInsideVaultDirectory(repoDir)) {
|
|
236
|
+
throw new VibecodeError("CONFIG_INVALID", "Repo target must not reside inside a holdout vault directory.");
|
|
237
|
+
}
|
|
238
|
+
if (!fs.existsSync(repoDir) || !fs.statSync(repoDir).isDirectory()) {
|
|
239
|
+
throw new VibecodeError("TARGET_MISSING", `Repo target not found: ${redactSensitiveText(ctx.target)}`);
|
|
240
|
+
}
|
|
241
|
+
const expected = invariant.expected || {};
|
|
242
|
+
const failures = [];
|
|
243
|
+
for (const rel of expected.filesPresent || []) {
|
|
244
|
+
const abs = resolveRepoSubpath(repoDir, rel);
|
|
245
|
+
if (!abs || !fs.existsSync(abs))
|
|
246
|
+
failures.push(`missing file ${redactSensitiveText(rel)}`);
|
|
247
|
+
}
|
|
248
|
+
const modulePath = invariant.input?.modulePath || (expected.filesPresent || [])[0];
|
|
249
|
+
if (Array.isArray(expected.exports) && expected.exports.length) {
|
|
250
|
+
if (!modulePath) {
|
|
251
|
+
failures.push("no modulePath provided for export verification");
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
const abs = resolveRepoSubpath(repoDir, modulePath);
|
|
255
|
+
if (!abs || !fs.existsSync(abs) || !fs.statSync(abs).isFile()) {
|
|
256
|
+
failures.push(`module not found: ${redactSensitiveText(modulePath)}`);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const actual = scanExportsFromFile(abs);
|
|
260
|
+
const actualNames = new Set(actual.map((e) => e.name));
|
|
261
|
+
for (const exp of expected.exports) {
|
|
262
|
+
if (!actualNames.has(exp.name))
|
|
263
|
+
failures.push(`missing export ${exp.name}`);
|
|
264
|
+
else if (exp.kind && exp.kind !== "unknown") {
|
|
265
|
+
const found = actual.find((e) => e.name === exp.name);
|
|
266
|
+
if (found && found.kind !== "unknown" && found.kind !== exp.kind)
|
|
267
|
+
failures.push(`export ${exp.name} kind expected ${exp.kind}, got ${found.kind}`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
status: failures.length ? "fail" : "pass",
|
|
275
|
+
score: failures.length ? 0 : 1,
|
|
276
|
+
failures,
|
|
277
|
+
metrics: { repoDir: redactSensitiveText(repoDir) }
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
export async function verifyInvariant(invariant, ctx, deps = {}) {
|
|
281
|
+
if (invariant.type === "http")
|
|
282
|
+
return verifyHttp(invariant, ctx, deps);
|
|
283
|
+
if (invariant.type === "repo_exports")
|
|
284
|
+
return verifyRepoExports(invariant, ctx, deps);
|
|
285
|
+
throw new VibecodeError("UNSUPPORTED_FORMAT", `Unsupported api-repo invariant type: ${invariant.type}`);
|
|
286
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { splitCommand } from "../core/exec.js";
|
|
5
|
+
import { DETERMINISTIC_CLI_ENV, diffFsSnapshots, resolveCommandForSandbox, runSandboxedCommand, sha256Text, takeFsSnapshot, verifyFsEffects } from "../core/fs-snapshot.js";
|
|
6
|
+
import { normalizeText, diffLines } from "../core/diff.js";
|
|
7
|
+
import { validateJsonSchema, queryJsonPath } from "../core/schema.js";
|
|
8
|
+
import { VibecodeError, errorMessage } from "../core/errors.js";
|
|
9
|
+
import { isInsideVaultDirectory, redactDeepValue, redactSensitiveText } from "../core/security.js";
|
|
10
|
+
export async function verifyInvariant(invariant, ctx, _deps = {}) {
|
|
11
|
+
if (!ctx.target)
|
|
12
|
+
throw new VibecodeError("TARGET_MISSING", "Missing --target \"<command>\" for CLI verification.");
|
|
13
|
+
const tokens = splitCommand(ctx.target);
|
|
14
|
+
if (tokens.length === 0)
|
|
15
|
+
throw new VibecodeError("TARGET_MISSING", "Invalid --target command");
|
|
16
|
+
const resolvedTokens = resolveCommandForSandbox(tokens, ctx.cwd);
|
|
17
|
+
const [target, ...baseArgs] = resolvedTokens;
|
|
18
|
+
const input = invariant.input || {};
|
|
19
|
+
const expected = invariant.expected || {};
|
|
20
|
+
const modes = Array.isArray(expected.normalize) ? expected.normalize : [];
|
|
21
|
+
const args = [...baseArgs, ...(Array.isArray(input.args) ? input.args : [])];
|
|
22
|
+
const env = {
|
|
23
|
+
...DETERMINISTIC_CLI_ENV,
|
|
24
|
+
...(input.env || {})
|
|
25
|
+
};
|
|
26
|
+
const useFsDiff = input.fsDiff === true || Array.isArray(expected.fsEffects);
|
|
27
|
+
const rawCwdInput = typeof input.cwd === "string" ? input.cwd.trim() : "";
|
|
28
|
+
const cwd = rawCwdInput && rawCwdInput !== "." ? path.resolve(ctx.cwd || process.cwd(), rawCwdInput) : ctx.cwd;
|
|
29
|
+
if ((rawCwdInput && isInsideVaultDirectory(rawCwdInput)) || (cwd && isInsideVaultDirectory(cwd))) {
|
|
30
|
+
throw new VibecodeError("CONFIG_INVALID", "CLI invariant input.cwd must not point inside a holdout vault directory.");
|
|
31
|
+
}
|
|
32
|
+
let run;
|
|
33
|
+
let actualEffects = null;
|
|
34
|
+
if (useFsDiff) {
|
|
35
|
+
const fsSandbox = fs.mkdtempSync(path.join(os.tmpdir(), "vibecode-verify-fs-"));
|
|
36
|
+
try {
|
|
37
|
+
const before = takeFsSnapshot(fsSandbox);
|
|
38
|
+
run = await runSandboxedCommand(target, args, {
|
|
39
|
+
stdin: input.stdin,
|
|
40
|
+
env,
|
|
41
|
+
cwd: fsSandbox,
|
|
42
|
+
timeoutMs: input.timeoutMs || 10000,
|
|
43
|
+
shell: input.shell === true
|
|
44
|
+
});
|
|
45
|
+
const after = takeFsSnapshot(fsSandbox);
|
|
46
|
+
actualEffects = diffFsSnapshots(before, after);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
fs.rmSync(fsSandbox, { recursive: true, force: true, maxRetries: 3, retryDelay: 50 });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
run = await runSandboxedCommand(target, args, {
|
|
54
|
+
stdin: input.stdin,
|
|
55
|
+
env,
|
|
56
|
+
cwd,
|
|
57
|
+
timeoutMs: input.timeoutMs || 10000,
|
|
58
|
+
shell: input.shell === true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const failures = [];
|
|
62
|
+
const diff = {};
|
|
63
|
+
const stdout = normalizeText(run.stdout, modes);
|
|
64
|
+
const stderr = normalizeText(run.stderr, modes);
|
|
65
|
+
if (run.timedOut) {
|
|
66
|
+
failures.push(`TIMEOUT: command exceeded ${input.timeoutMs || 10000}ms`);
|
|
67
|
+
}
|
|
68
|
+
if (run.error && run.exitCode === null) {
|
|
69
|
+
failures.push(`EXEC_ERROR: ${run.error.message}`);
|
|
70
|
+
}
|
|
71
|
+
// exitCode
|
|
72
|
+
if (expected.exitCode !== undefined) {
|
|
73
|
+
const accepted = Array.isArray(expected.exitCode) ? expected.exitCode : [expected.exitCode];
|
|
74
|
+
if (!accepted.includes(run.exitCode))
|
|
75
|
+
failures.push(`exitCode expected ${JSON.stringify(accepted)}, got ${run.exitCode}`);
|
|
76
|
+
}
|
|
77
|
+
// stdout assertions
|
|
78
|
+
if (expected.stdoutExact !== undefined && expected.stdoutExact !== null) {
|
|
79
|
+
const want = normalizeText(expected.stdoutExact, modes);
|
|
80
|
+
if (want !== stdout)
|
|
81
|
+
failures.push("stdoutExact mismatch");
|
|
82
|
+
}
|
|
83
|
+
for (const needle of expected.stdoutContains || []) {
|
|
84
|
+
if (!stdout.includes(needle))
|
|
85
|
+
failures.push(`stdout missing ${JSON.stringify(needle)}`);
|
|
86
|
+
}
|
|
87
|
+
for (const needle of expected.stdoutNotContains || []) {
|
|
88
|
+
if (stdout.includes(needle))
|
|
89
|
+
failures.push(`stdout unexpectedly contains ${JSON.stringify(needle)}`);
|
|
90
|
+
}
|
|
91
|
+
for (const pattern of expected.stdoutRegex || []) {
|
|
92
|
+
try {
|
|
93
|
+
if (!new RegExp(pattern).test(stdout))
|
|
94
|
+
failures.push(`stdout did not match /${pattern}/`);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
failures.push(`invalid stdoutRegex: ${errorMessage(err)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// stderr assertions
|
|
101
|
+
if (expected.stderrExact !== undefined && expected.stderrExact !== null) {
|
|
102
|
+
const want = normalizeText(expected.stderrExact, modes);
|
|
103
|
+
if (want !== stderr)
|
|
104
|
+
failures.push("stderrExact mismatch");
|
|
105
|
+
}
|
|
106
|
+
for (const needle of expected.stderrContains || []) {
|
|
107
|
+
if (!stderr.includes(needle))
|
|
108
|
+
failures.push(`stderr missing ${JSON.stringify(needle)}`);
|
|
109
|
+
}
|
|
110
|
+
// golden stdout diff
|
|
111
|
+
if (expected.goldenStdout != null) {
|
|
112
|
+
const golden = normalizeText(expected.goldenStdout, modes);
|
|
113
|
+
const d = diffLines(golden, stdout, { context: 2, maxLines: 60 });
|
|
114
|
+
if (!d.identical) {
|
|
115
|
+
diff.goldenStdout = {
|
|
116
|
+
...d,
|
|
117
|
+
unified: redactSensitiveText(d.unified)
|
|
118
|
+
};
|
|
119
|
+
failures.push(`stdout differs from golden (${d.added} added, ${d.removed} removed)`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// JSON Schema
|
|
123
|
+
let parsed = null;
|
|
124
|
+
let parseOk = false;
|
|
125
|
+
const parseText = normalizeText(run.stdout, [...new Set([...modes, "ansi"])]);
|
|
126
|
+
const trimmed = parseText.trim();
|
|
127
|
+
if (trimmed) {
|
|
128
|
+
try {
|
|
129
|
+
parsed = JSON.parse(trimmed);
|
|
130
|
+
parseOk = true;
|
|
131
|
+
}
|
|
132
|
+
catch { /* ignore */ }
|
|
133
|
+
}
|
|
134
|
+
if (expected.jsonSchema) {
|
|
135
|
+
if (!parseOk) {
|
|
136
|
+
failures.push("stdout is not valid JSON (required by jsonSchema assertion)");
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const schemaErrors = validateJsonSchema(parsed, expected.jsonSchema, "$");
|
|
140
|
+
if (schemaErrors.length) {
|
|
141
|
+
for (const e of schemaErrors.slice(0, 10))
|
|
142
|
+
failures.push(`jsonSchema ${e.path}: ${e.message}`);
|
|
143
|
+
diff.jsonSchema = redactDeepValue(schemaErrors);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const jsonPathDiffs = [];
|
|
148
|
+
for (const assertion of expected.jsonPaths || []) {
|
|
149
|
+
if (!parseOk) {
|
|
150
|
+
failures.push(`jsonPath ${assertion.path}: stdout not JSON`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const q = queryJsonPath(parsed, assertion.path);
|
|
154
|
+
if (!q.found) {
|
|
155
|
+
failures.push(`jsonPath ${assertion.path}: not found`);
|
|
156
|
+
jsonPathDiffs.push({ path: assertion.path, expected: assertion.equals, actual: undefined });
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (Object.prototype.hasOwnProperty.call(assertion, "equals")) {
|
|
160
|
+
const ok = JSON.stringify(q.value) === JSON.stringify(assertion.equals);
|
|
161
|
+
if (!ok) {
|
|
162
|
+
failures.push(`jsonPath ${assertion.path}: expected ${JSON.stringify(assertion.equals)}, got ${JSON.stringify(q.value)}`);
|
|
163
|
+
jsonPathDiffs.push({ path: assertion.path, expected: assertion.equals, actual: q.value });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (Object.prototype.hasOwnProperty.call(assertion, "matches")) {
|
|
167
|
+
let re;
|
|
168
|
+
try {
|
|
169
|
+
re = new RegExp(assertion.matches ?? "");
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
failures.push(`jsonPath ${assertion.path}: invalid matches regex: ${errorMessage(err)}`);
|
|
173
|
+
jsonPathDiffs.push({ path: assertion.path, matches: assertion.matches, actual: q.value });
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (!re.test(String(q.value))) {
|
|
177
|
+
failures.push(`jsonPath ${assertion.path}: value ${JSON.stringify(q.value)} did not match /${assertion.matches}/`);
|
|
178
|
+
jsonPathDiffs.push({ path: assertion.path, matches: assertion.matches, actual: q.value });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (jsonPathDiffs.length > 0)
|
|
183
|
+
diff.jsonPaths = redactDeepValue(jsonPathDiffs);
|
|
184
|
+
if (useFsDiff && actualEffects !== null) {
|
|
185
|
+
const fsResult = verifyFsEffects(expected.fsEffects || [], actualEffects);
|
|
186
|
+
failures.push(...fsResult.failures);
|
|
187
|
+
if (fsResult.diffs.length > 0) {
|
|
188
|
+
diff.fsEffects = redactDeepValue(fsResult.diffs);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const safeFailures = failures.map((f) => redactSensitiveText(f));
|
|
192
|
+
return {
|
|
193
|
+
status: safeFailures.length === 0 ? "pass" : "fail",
|
|
194
|
+
score: safeFailures.length === 0 ? 1 : 0,
|
|
195
|
+
failures: safeFailures,
|
|
196
|
+
...(Object.keys(diff).length ? { diff } : {}),
|
|
197
|
+
metrics: {
|
|
198
|
+
exitCode: run.exitCode,
|
|
199
|
+
durationMs: run.durationMs,
|
|
200
|
+
stdoutBytes: (run.stdout || "").length,
|
|
201
|
+
stderrBytes: (run.stderr || "").length,
|
|
202
|
+
...(stdout.length > 0 ? { candidateOutputHash: sha256Text(stdout) } : {})
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Invariant, JsonPathAssertion, JsonSchema, OracleContext, OracleInvariantOutcome, VerifyDeps } from "../core/types.js";
|
|
2
|
+
export interface HttpWorkflowStepExpected {
|
|
3
|
+
status?: number | number[];
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
bodyExact?: string;
|
|
6
|
+
bodyContains?: string | string[];
|
|
7
|
+
jsonSchema?: JsonSchema;
|
|
8
|
+
jsonSubset?: unknown;
|
|
9
|
+
jsonPaths?: JsonPathAssertion[];
|
|
10
|
+
maxLatencyMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface HttpWorkflowStep {
|
|
13
|
+
id: string;
|
|
14
|
+
method?: string;
|
|
15
|
+
path: string;
|
|
16
|
+
query?: Record<string, string | number | boolean>;
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
body?: unknown;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
extract?: Record<string, string>;
|
|
21
|
+
expected?: HttpWorkflowStepExpected;
|
|
22
|
+
}
|
|
23
|
+
export interface HttpWorkflowInput {
|
|
24
|
+
steps: HttpWorkflowStep[];
|
|
25
|
+
finallySteps?: HttpWorkflowStep[];
|
|
26
|
+
vars?: Record<string, string>;
|
|
27
|
+
cookieJar?: boolean;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface WorkflowStepSummary {
|
|
31
|
+
id: string;
|
|
32
|
+
method: string;
|
|
33
|
+
url: string;
|
|
34
|
+
status?: number;
|
|
35
|
+
durationMs: number;
|
|
36
|
+
passed: boolean;
|
|
37
|
+
phase: "main" | "finally";
|
|
38
|
+
failures: string[];
|
|
39
|
+
}
|
|
40
|
+
export interface WorkflowStepRecord {
|
|
41
|
+
status: number;
|
|
42
|
+
headers: Record<string, string>;
|
|
43
|
+
body: unknown;
|
|
44
|
+
text: string;
|
|
45
|
+
extracted: Record<string, unknown>;
|
|
46
|
+
}
|
|
47
|
+
export interface WorkflowScope {
|
|
48
|
+
steps?: Map<string, WorkflowStepRecord> | Record<string, WorkflowStepRecord>;
|
|
49
|
+
vars?: Map<string, unknown> | Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/** Zero-dependency RFC 6265 cookie jar. */
|
|
52
|
+
export declare class CookieJar {
|
|
53
|
+
private readonly cookies;
|
|
54
|
+
private readonly maxCookies;
|
|
55
|
+
private seq;
|
|
56
|
+
constructor(maxCookies?: number);
|
|
57
|
+
storeFromHeaders(url: string, setCookieHeaders: readonly string[], nowMs?: number): void;
|
|
58
|
+
getCookieHeader(url: string, nowMs?: number): string | undefined;
|
|
59
|
+
clear(): void;
|
|
60
|
+
}
|
|
61
|
+
/** Recursively interpolates `{{...}}` templates safely with prototype-pollution, cycle, and depth guards. */
|
|
62
|
+
export declare function interpolateWorkflowValue(value: unknown, scope: WorkflowScope): {
|
|
63
|
+
value: unknown;
|
|
64
|
+
unresolved: string[];
|
|
65
|
+
};
|
|
66
|
+
/** Verifies a stateful multi-step HTTP workflow with RFC 6265 cookies, extraction, and guaranteed finally cleanup. */
|
|
67
|
+
export declare function verifyHttpWorkflow(invariant: Invariant, ctx: OracleContext, deps?: VerifyDeps): Promise<OracleInvariantOutcome>;
|
|
68
|
+
export declare const verifyInvariant: typeof verifyHttpWorkflow;
|