loadam 0.2.2 → 0.2.3
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 +48 -20
- package/dist/bin.js +135 -86
- package/dist/bin.js.map +1 -1
- package/dist/index.js +135 -86
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm i -g loadam # or: npx loadam ...
|
|
11
|
-
loadam
|
|
12
|
-
#
|
|
11
|
+
loadam test ./openapi.yaml --target https://api.example.com
|
|
12
|
+
# Interactive: prompts for missing creds, runs k6 smoke, archives the session.
|
|
13
|
+
loadam report --open # Single-file HTML report with charts.
|
|
13
14
|
```
|
|
14
15
|
|
|
15
|
-
That's it. One spec → three production-grade rigs. **One engine, two surfaces:**
|
|
16
|
+
That's it. One spec → three production-grade rigs **plus** a session archive and an HTML report. **One engine, two surfaces:**
|
|
16
17
|
|
|
17
18
|
- **Test surface** — adversarial. Break the API: load, perf, contract drift.
|
|
18
19
|
- **Agent surface** — cooperative. Let LLM agents use the API safely via MCP (stdio + HTTP).
|
|
@@ -43,41 +44,53 @@ Requires Node.js 20+. The generated rigs have their own runtime requirements: **
|
|
|
43
44
|
# 1. Inspect what loadam sees in your spec.
|
|
44
45
|
loadam init ./openapi.yaml
|
|
45
46
|
|
|
46
|
-
# 2. Generate a
|
|
47
|
+
# 2. Generate + run a k6 smoke test in one shot (interactive: prompts for creds).
|
|
47
48
|
loadam test ./openapi.yaml --target https://api.example.com
|
|
48
|
-
cd loadam-out/k6 && cp .env.example .env && k6 run smoke.js
|
|
49
49
|
|
|
50
|
-
# 3.
|
|
50
|
+
# 3. Browse archived runs and open the HTML report.
|
|
51
|
+
loadam history
|
|
52
|
+
loadam show latest
|
|
53
|
+
loadam report latest --open
|
|
54
|
+
|
|
55
|
+
# 4. Generate a property-based Schemathesis contract suite.
|
|
51
56
|
loadam contract ./openapi.yaml --target https://api.example.com
|
|
52
57
|
cd loadam-out/contract && pip install -e . && pytest
|
|
53
58
|
|
|
54
|
-
#
|
|
59
|
+
# 5. Generate an MCP server. Read-only by default.
|
|
55
60
|
loadam mcp ./openapi.yaml
|
|
56
61
|
cd loadam-out/mcp && npm install && node bin.js # stdio (Claude Desktop)
|
|
57
62
|
node bin.js --http # streamable HTTP
|
|
58
63
|
|
|
59
|
-
#
|
|
64
|
+
# 6. Detect drift between spec and live API.
|
|
60
65
|
loadam diff ./openapi.yaml --target https://api.example.com -o drift.md
|
|
61
66
|
```
|
|
62
67
|
|
|
63
|
-
Every command supports `--json` for CI:
|
|
68
|
+
Every command supports `--json` for CI, and `--no-interactive` to skip prompts:
|
|
64
69
|
|
|
65
70
|
```bash
|
|
66
|
-
loadam
|
|
71
|
+
loadam test ./openapi.yaml --target $LOADAM_TARGET --no-interactive --json | jq .sessionId
|
|
67
72
|
```
|
|
68
73
|
|
|
74
|
+
Set `LOADAM_TARGET` once per shell to drop the `--target` flag from every invocation.
|
|
75
|
+
|
|
69
76
|
## Commands
|
|
70
77
|
|
|
71
|
-
| Command
|
|
72
|
-
|
|
|
73
|
-
| `loadam init <spec>`
|
|
74
|
-
| `loadam test <spec>`
|
|
75
|
-
| `loadam contract <spec>`
|
|
76
|
-
| `loadam mcp <spec>`
|
|
77
|
-
| `loadam diff <spec>`
|
|
78
|
-
| `loadam
|
|
79
|
-
| `loadam
|
|
80
|
-
| `loadam
|
|
78
|
+
| Command | What it does | Output |
|
|
79
|
+
| ----------------------------- | --------------------------------------------------------------------- | --------------------------------- |
|
|
80
|
+
| `loadam init <spec>` | Parse spec → IR with inferred resource graph | `loadam.ir.json` |
|
|
81
|
+
| `loadam test <spec>` | Compile + (optionally) run k6 smoke / load; archives the session | `loadam-out/k6/` + session |
|
|
82
|
+
| `loadam contract <spec>` | Compile to a Schemathesis pytest project | `loadam-out/contract/` + session |
|
|
83
|
+
| `loadam mcp <spec>` | Compile to a runnable MCP server (stdio + HTTP) | `loadam-out/mcp/` |
|
|
84
|
+
| `loadam diff <spec>` | Probe a live API and report spec-vs-reality drift | Markdown + session |
|
|
85
|
+
| `loadam history` | List archived sessions (newest first) | table or `--json` |
|
|
86
|
+
| `loadam show <id\|latest>` | Show a session's metadata + inline k6/drift summary | text or `--json` |
|
|
87
|
+
| `loadam report <id\|latest>` | Render a single-file HTML report (charts, threshold table) | `report.html` (`--open` to view) |
|
|
88
|
+
| `loadam clean` | Prune session archive (`--older-than 7d`, `--dry-run` by default) | text or `--json` |
|
|
89
|
+
| `loadam auth import` | Infer an auth profile from a `curl` command | JSON / pretty |
|
|
90
|
+
| `loadam update` | Check npm for a newer version of `loadam` | text or `--json` |
|
|
91
|
+
| `loadam completion` | Print bash/zsh/fish completion script | stdout |
|
|
92
|
+
|
|
93
|
+
Use `--no-interactive` on `test` to skip prompts (CI-safe), and set `LOADAM_TARGET` to avoid repeating `--target`.
|
|
81
94
|
|
|
82
95
|
## What you get from `loadam mcp`
|
|
83
96
|
|
|
@@ -100,6 +113,19 @@ loadam mcp ./openapi.yaml --json | jq .toolNames
|
|
|
100
113
|
}
|
|
101
114
|
```
|
|
102
115
|
|
|
116
|
+
## Session archive & HTML reports
|
|
117
|
+
|
|
118
|
+
Every `loadam test`, `loadam contract`, and `loadam diff` invocation is archived to `./loadam-out/sessions/<id>/` with the parsed IR, the exact spec source, command flags, exit code, and any artefacts the run produced (k6 summary JSON, drift markdown, contract findings). The archive is local-only — it never leaves disk.
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
loadam history # newest 20 sessions
|
|
122
|
+
loadam show latest # inline k6 p95 / threshold pass-fail
|
|
123
|
+
loadam report latest --open # one-file HTML report (charts, dark mode)
|
|
124
|
+
loadam clean --older-than 7d --apply # prune old runs
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The HTML report is a single self-contained file (no external CDNs, no JS dependencies) and is safe to drop into a CI artefact store, gh-pages, or Slack.
|
|
128
|
+
|
|
103
129
|
## Why loadam
|
|
104
130
|
|
|
105
131
|
Most teams have an OpenAPI spec sitting in a repo and **none** of the rigs that should fall out of it. They wire each one by hand, badly, and then drift. Loadam treats the spec as the source of truth and emits everything once: load, contract, drift, agent. One shape of input, four shapes of output, zero hand-rolled boilerplate.
|
|
@@ -128,6 +154,7 @@ packages/
|
|
|
128
154
|
test-contract/ Schemathesis compiler — emits pytest project
|
|
129
155
|
test-drift/ Live probe + Markdown diff report
|
|
130
156
|
mcp/ MCP compiler — emits stdio + HTTP server
|
|
157
|
+
report/ Pure-function HTML report renderer (no DOM dependency)
|
|
131
158
|
cli/ commander-based CLI tying it all together
|
|
132
159
|
```
|
|
133
160
|
|
|
@@ -150,6 +177,7 @@ V1 (this) targets **petstore-class specs** end-to-end. Stripe-class specs (polym
|
|
|
150
177
|
|
|
151
178
|
- [examples/basic-openapi](examples/basic-openapi/) — petstore, no auth required to generate
|
|
152
179
|
- [examples/with-auth](examples/with-auth/) — bookstore with bearer auth + multi-server
|
|
180
|
+
- [examples/demo](examples/demo/) — a real `report.html` generated against live petstore
|
|
153
181
|
|
|
154
182
|
## Development
|
|
155
183
|
|
package/dist/bin.js
CHANGED
|
@@ -1606,6 +1606,14 @@ function slugify(s) {
|
|
|
1606
1606
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
1607
1607
|
}
|
|
1608
1608
|
|
|
1609
|
+
// src/util/target.ts
|
|
1610
|
+
function resolveTarget(flag) {
|
|
1611
|
+
if (typeof flag === "string" && flag.length > 0) return flag;
|
|
1612
|
+
const env = process.env.LOADAM_TARGET;
|
|
1613
|
+
if (typeof env === "string" && env.length > 0) return env;
|
|
1614
|
+
return void 0;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1609
1617
|
// src/commands/contract.ts
|
|
1610
1618
|
function registerContractCommand(program) {
|
|
1611
1619
|
program.command("contract").description("Compile an OpenAPI spec into a Schemathesis property-based contract suite.").argument("<spec>", "path to OpenAPI 3.x spec (YAML or JSON)").option(
|
|
@@ -1623,8 +1631,9 @@ async function runContract(spec, opts) {
|
|
|
1623
1631
|
parseIR(ir);
|
|
1624
1632
|
const specSource = await readFile4(specPath, "utf8");
|
|
1625
1633
|
const examples = Number.parseInt(opts.examples ?? "25", 10);
|
|
1634
|
+
const target = resolveTarget(opts.target);
|
|
1626
1635
|
const result = compileContract(ir, specSource, {
|
|
1627
|
-
baseUrl:
|
|
1636
|
+
baseUrl: target,
|
|
1628
1637
|
examples: Number.isFinite(examples) ? examples : 25
|
|
1629
1638
|
});
|
|
1630
1639
|
const outDir = resolve4(opts.output);
|
|
@@ -1644,10 +1653,10 @@ async function runContract(spec, opts) {
|
|
|
1644
1653
|
specSource,
|
|
1645
1654
|
ir,
|
|
1646
1655
|
irJson: JSON.stringify(ir, null, 2),
|
|
1647
|
-
target:
|
|
1656
|
+
target: target ?? null,
|
|
1648
1657
|
envVars: result.envVars ?? [],
|
|
1649
1658
|
flags: {
|
|
1650
|
-
target:
|
|
1659
|
+
target: target ?? null,
|
|
1651
1660
|
examples
|
|
1652
1661
|
},
|
|
1653
1662
|
slug: `contract-${ir.meta.title ?? "run"}`
|
|
@@ -1932,10 +1941,14 @@ function severityBadge(s) {
|
|
|
1932
1941
|
|
|
1933
1942
|
// src/commands/diff.ts
|
|
1934
1943
|
function registerDiffCommand(program) {
|
|
1935
|
-
program.command("diff").description("Probe a live API and report drift against the spec (Markdown).").argument("<spec>", "path to OpenAPI 3.x spec (YAML or JSON)").
|
|
1944
|
+
program.command("diff").description("Probe a live API and report drift against the spec (Markdown).").argument("<spec>", "path to OpenAPI 3.x spec (YAML or JSON)").option("--target <url>", "base URL of the live API (or set LOADAM_TARGET)").option("-o, --output <path>", "write report to this file (otherwise stdout)").option("--timeout-ms <n>", "per-request timeout", "5000").option("--mutating", "also probe mutating ops (DANGEROUS \u2014 not for prod)", false).option("-H, --header <kv...>", 'additional headers, repeatable, "Name: value" form').option("--path-param <kv...>", 'fallback path-param values, repeatable, "name=value" form').option("--fail-on <severity>", "exit non-zero when findings of this severity exist", "error").option("--json", "emit a single JSON summary on stdout (CI mode)", false).action(withFriendlyErrors(runDiff));
|
|
1936
1945
|
}
|
|
1937
1946
|
async function runDiff(spec, opts) {
|
|
1938
1947
|
const out = makeOutput(!!opts.json);
|
|
1948
|
+
const target = resolveTarget(opts.target);
|
|
1949
|
+
if (!target) {
|
|
1950
|
+
throw new Error("--target is required (or set LOADAM_TARGET env var)");
|
|
1951
|
+
}
|
|
1939
1952
|
const specPath = resolve5(spec);
|
|
1940
1953
|
out.start(`Parsing OpenAPI spec: ${specPath}`);
|
|
1941
1954
|
const specSource = await readFile5(specPath, "utf8");
|
|
@@ -1945,9 +1958,9 @@ async function runDiff(spec, opts) {
|
|
|
1945
1958
|
const headers = parseKvPairs(opts.header ?? [], ":");
|
|
1946
1959
|
const pathParams = parseKvPairs(opts.pathParam ?? [], "=");
|
|
1947
1960
|
const timeoutMs = Number.parseInt(opts.timeoutMs ?? "5000", 10);
|
|
1948
|
-
out.start(`Probing ${ir.operations.length} operations on ${
|
|
1961
|
+
out.start(`Probing ${ir.operations.length} operations on ${target}\u2026`);
|
|
1949
1962
|
const { probes, skipped } = await probeOperations(ir, {
|
|
1950
|
-
baseUrl:
|
|
1963
|
+
baseUrl: target,
|
|
1951
1964
|
headers,
|
|
1952
1965
|
pathParams,
|
|
1953
1966
|
timeoutMs: Number.isFinite(timeoutMs) ? timeoutMs : 5e3,
|
|
@@ -1962,10 +1975,10 @@ async function runDiff(spec, opts) {
|
|
|
1962
1975
|
specSource,
|
|
1963
1976
|
ir,
|
|
1964
1977
|
irJson: JSON.stringify(ir, null, 2),
|
|
1965
|
-
target
|
|
1978
|
+
target,
|
|
1966
1979
|
envVars: [],
|
|
1967
1980
|
flags: {
|
|
1968
|
-
target
|
|
1981
|
+
target,
|
|
1969
1982
|
timeoutMs,
|
|
1970
1983
|
mutating: !!opts.mutating,
|
|
1971
1984
|
failOn: opts.failOn ?? "error",
|
|
@@ -1976,7 +1989,7 @@ async function runDiff(spec, opts) {
|
|
|
1976
1989
|
});
|
|
1977
1990
|
const report = renderMarkdownReport({
|
|
1978
1991
|
ir,
|
|
1979
|
-
baseUrl:
|
|
1992
|
+
baseUrl: target,
|
|
1980
1993
|
findings,
|
|
1981
1994
|
skipped
|
|
1982
1995
|
});
|
|
@@ -2016,7 +2029,7 @@ async function runDiff(spec, opts) {
|
|
|
2016
2029
|
});
|
|
2017
2030
|
out.result({
|
|
2018
2031
|
command: "diff",
|
|
2019
|
-
target
|
|
2032
|
+
target,
|
|
2020
2033
|
probed: probes.length,
|
|
2021
2034
|
skipped: skipped.length,
|
|
2022
2035
|
findings: findings.length,
|
|
@@ -2625,8 +2638,9 @@ async function runMcp(spec, opts) {
|
|
|
2625
2638
|
const ir = await fromOpenApiFile(specPath);
|
|
2626
2639
|
inferResourceGraph(ir);
|
|
2627
2640
|
parseIR(ir);
|
|
2641
|
+
const target = resolveTarget(opts.target);
|
|
2628
2642
|
const result = compileMcp(ir, {
|
|
2629
|
-
baseUrl:
|
|
2643
|
+
baseUrl: target,
|
|
2630
2644
|
includeWrites: !!opts.writes,
|
|
2631
2645
|
exclude: opts.exclude
|
|
2632
2646
|
});
|
|
@@ -2937,7 +2951,7 @@ footer{margin-top:40px;padding-top:16px;border-top:1px solid var(--brd);color:va
|
|
|
2937
2951
|
`;
|
|
2938
2952
|
|
|
2939
2953
|
// src/commands/report.ts
|
|
2940
|
-
var VERSION = true ? "0.2.
|
|
2954
|
+
var VERSION = true ? "0.2.3" : "0.0.0";
|
|
2941
2955
|
function registerReportCommand(program) {
|
|
2942
2956
|
program.command("report").description("Render a self-contained HTML report for an archived session.").argument("[id]", 'session ID, prefix, or "latest" (default: latest)', "latest").option("--root <dir>", "session archive root", "./loadam-out").option("-o, --output <path>", "write to this path instead of <session>/report.html").option("--open", "open the report in your default browser after writing", false).option("--json", "emit a JSON summary on stdout (CI mode)", false).action(withFriendlyErrors(runReport));
|
|
2943
2957
|
}
|
|
@@ -3004,7 +3018,76 @@ async function openInBrowser(path) {
|
|
|
3004
3018
|
|
|
3005
3019
|
// src/commands/show.ts
|
|
3006
3020
|
import { readFile as readFile7, readdir as readdir2 } from "fs/promises";
|
|
3007
|
-
import { join as
|
|
3021
|
+
import { join as join4, resolve as resolve10 } from "path";
|
|
3022
|
+
|
|
3023
|
+
// src/util/k6.ts
|
|
3024
|
+
import { spawn as spawn2 } from "child_process";
|
|
3025
|
+
import { constants, access } from "fs/promises";
|
|
3026
|
+
import { delimiter, join as join3 } from "path";
|
|
3027
|
+
async function findK6Binary() {
|
|
3028
|
+
const path = process.env.PATH ?? "";
|
|
3029
|
+
const exts = process.platform === "win32" ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
3030
|
+
for (const dir of path.split(delimiter)) {
|
|
3031
|
+
if (!dir) continue;
|
|
3032
|
+
for (const ext of exts) {
|
|
3033
|
+
const candidate = join3(dir, `k6${ext}`);
|
|
3034
|
+
try {
|
|
3035
|
+
await access(candidate, constants.X_OK);
|
|
3036
|
+
return candidate;
|
|
3037
|
+
} catch {
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
return null;
|
|
3042
|
+
}
|
|
3043
|
+
async function runK6(opts) {
|
|
3044
|
+
const bin = await findK6Binary();
|
|
3045
|
+
if (!bin) {
|
|
3046
|
+
throw new Error(
|
|
3047
|
+
"k6 not found on PATH. Install it from https://grafana.com/docs/k6/latest/set-up/install-k6/ and try again."
|
|
3048
|
+
);
|
|
3049
|
+
}
|
|
3050
|
+
const args = ["run"];
|
|
3051
|
+
if (opts.summaryPath) args.push(`--summary-export=${opts.summaryPath}`);
|
|
3052
|
+
args.push(...opts.args ?? [], opts.script);
|
|
3053
|
+
return await new Promise((resolveExit, reject) => {
|
|
3054
|
+
const child = spawn2(bin, args, {
|
|
3055
|
+
cwd: opts.cwd,
|
|
3056
|
+
env: { ...process.env, ...opts.env },
|
|
3057
|
+
stdio: "inherit"
|
|
3058
|
+
});
|
|
3059
|
+
child.on("error", reject);
|
|
3060
|
+
child.on("close", (code) => resolveExit(code ?? 0));
|
|
3061
|
+
});
|
|
3062
|
+
}
|
|
3063
|
+
async function digestK6Summary(path) {
|
|
3064
|
+
try {
|
|
3065
|
+
const { readFile: readFile10 } = await import("fs/promises");
|
|
3066
|
+
const text = await readFile10(path, "utf8");
|
|
3067
|
+
const data = JSON.parse(text);
|
|
3068
|
+
const passed = [];
|
|
3069
|
+
const failed = [];
|
|
3070
|
+
const metrics = {};
|
|
3071
|
+
for (const [name, m] of Object.entries(data.metrics ?? {})) {
|
|
3072
|
+
if (m.thresholds) {
|
|
3073
|
+
for (const [expr, info] of Object.entries(m.thresholds)) {
|
|
3074
|
+
(info.ok ? passed : failed).push(`${name}: ${expr}`);
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
if (m.values) {
|
|
3078
|
+
if (typeof m.values["p(95)"] === "number") metrics[`${name}.p95`] = m.values["p(95)"];
|
|
3079
|
+
if (typeof m.values.rate === "number") metrics[`${name}.rate`] = m.values.rate;
|
|
3080
|
+
if (typeof m.values.count === "number") metrics[`${name}.count`] = m.values.count;
|
|
3081
|
+
if (typeof m.values.avg === "number") metrics[`${name}.avg`] = m.values.avg;
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
return { passed, failed, metrics };
|
|
3085
|
+
} catch {
|
|
3086
|
+
return null;
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
// src/commands/show.ts
|
|
3008
3091
|
function registerShowCommand(program) {
|
|
3009
3092
|
program.command("show").description("Show details of an archived session.").argument("<id>", 'session ID, prefix, or "latest"').option("--root <dir>", "session archive root", "./loadam-out").option("--json", "emit the meta.json payload on stdout", false).action(withFriendlyErrors(runShow));
|
|
3010
3093
|
}
|
|
@@ -3012,7 +3095,7 @@ async function runShow(id, opts) {
|
|
|
3012
3095
|
const out = makeOutput(!!opts.json);
|
|
3013
3096
|
const root = resolve10(opts.root);
|
|
3014
3097
|
const meta = await resolveSessionId(root, id);
|
|
3015
|
-
const dir =
|
|
3098
|
+
const dir = join4(root, "sessions", meta.id);
|
|
3016
3099
|
if (out.json) {
|
|
3017
3100
|
out.result({ ...meta });
|
|
3018
3101
|
return;
|
|
@@ -3050,13 +3133,45 @@ async function runShow(id, opts) {
|
|
|
3050
3133
|
}
|
|
3051
3134
|
if (meta.command === "diff") {
|
|
3052
3135
|
try {
|
|
3053
|
-
const drift = await readFile7(
|
|
3136
|
+
const drift = await readFile7(join4(dir, "drift.md"), "utf8");
|
|
3054
3137
|
out.info("");
|
|
3055
3138
|
out.info("\u2500\u2500\u2500\u2500 drift.md \u2500\u2500\u2500\u2500");
|
|
3056
3139
|
process.stdout.write(drift);
|
|
3057
3140
|
} catch {
|
|
3058
3141
|
}
|
|
3059
3142
|
}
|
|
3143
|
+
if (meta.command === "test") {
|
|
3144
|
+
try {
|
|
3145
|
+
const entries = await readdir2(dir);
|
|
3146
|
+
const summaryFile = entries.find((e) => /^k6-.*-summary\.json$/.test(e));
|
|
3147
|
+
if (summaryFile) {
|
|
3148
|
+
const digest = await digestK6Summary(join4(dir, summaryFile));
|
|
3149
|
+
if (digest) {
|
|
3150
|
+
out.info("");
|
|
3151
|
+
out.info(`\u2500\u2500\u2500\u2500 ${summaryFile} \u2500\u2500\u2500\u2500`);
|
|
3152
|
+
const headline = [];
|
|
3153
|
+
const dur = digest.metrics["http_req_duration.p95"];
|
|
3154
|
+
const cnt = digest.metrics["http_reqs.count"];
|
|
3155
|
+
const rate = digest.metrics["http_reqs.rate"];
|
|
3156
|
+
const failRate = digest.metrics["http_req_failed.rate"];
|
|
3157
|
+
if (typeof dur === "number")
|
|
3158
|
+
headline.push(["http_req_duration p95", `${dur.toFixed(1)}ms`]);
|
|
3159
|
+
if (typeof cnt === "number") headline.push(["http_reqs count", `${cnt}`]);
|
|
3160
|
+
if (typeof rate === "number") headline.push(["http_reqs rate", `${rate.toFixed(2)}/s`]);
|
|
3161
|
+
if (typeof failRate === "number")
|
|
3162
|
+
headline.push(["http_req_failed rate", `${(failRate * 100).toFixed(2)}%`]);
|
|
3163
|
+
for (const [k, v] of headline) out.info(` ${k}: ${v}`);
|
|
3164
|
+
if (digest.passed.length || digest.failed.length) {
|
|
3165
|
+
out.info(
|
|
3166
|
+
` Thresholds: ${digest.passed.length} passed \xB7 ${digest.failed.length} failed`
|
|
3167
|
+
);
|
|
3168
|
+
for (const t of digest.failed) out.info(` \u2717 ${t}`);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
} catch {
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3060
3175
|
}
|
|
3061
3176
|
|
|
3062
3177
|
// src/commands/test.ts
|
|
@@ -3705,73 +3820,6 @@ async function readEnvFile(path) {
|
|
|
3705
3820
|
}
|
|
3706
3821
|
}
|
|
3707
3822
|
|
|
3708
|
-
// src/util/k6.ts
|
|
3709
|
-
import { spawn as spawn2 } from "child_process";
|
|
3710
|
-
import { constants, access } from "fs/promises";
|
|
3711
|
-
import { delimiter, join as join4 } from "path";
|
|
3712
|
-
async function findK6Binary() {
|
|
3713
|
-
const path = process.env.PATH ?? "";
|
|
3714
|
-
const exts = process.platform === "win32" ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
3715
|
-
for (const dir of path.split(delimiter)) {
|
|
3716
|
-
if (!dir) continue;
|
|
3717
|
-
for (const ext of exts) {
|
|
3718
|
-
const candidate = join4(dir, `k6${ext}`);
|
|
3719
|
-
try {
|
|
3720
|
-
await access(candidate, constants.X_OK);
|
|
3721
|
-
return candidate;
|
|
3722
|
-
} catch {
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
}
|
|
3726
|
-
return null;
|
|
3727
|
-
}
|
|
3728
|
-
async function runK6(opts) {
|
|
3729
|
-
const bin = await findK6Binary();
|
|
3730
|
-
if (!bin) {
|
|
3731
|
-
throw new Error(
|
|
3732
|
-
"k6 not found on PATH. Install it from https://grafana.com/docs/k6/latest/set-up/install-k6/ and try again."
|
|
3733
|
-
);
|
|
3734
|
-
}
|
|
3735
|
-
const args = ["run"];
|
|
3736
|
-
if (opts.summaryPath) args.push(`--summary-export=${opts.summaryPath}`);
|
|
3737
|
-
args.push(...opts.args ?? [], opts.script);
|
|
3738
|
-
return await new Promise((resolveExit, reject) => {
|
|
3739
|
-
const child = spawn2(bin, args, {
|
|
3740
|
-
cwd: opts.cwd,
|
|
3741
|
-
env: { ...process.env, ...opts.env },
|
|
3742
|
-
stdio: "inherit"
|
|
3743
|
-
});
|
|
3744
|
-
child.on("error", reject);
|
|
3745
|
-
child.on("close", (code) => resolveExit(code ?? 0));
|
|
3746
|
-
});
|
|
3747
|
-
}
|
|
3748
|
-
async function digestK6Summary(path) {
|
|
3749
|
-
try {
|
|
3750
|
-
const { readFile: readFile10 } = await import("fs/promises");
|
|
3751
|
-
const text = await readFile10(path, "utf8");
|
|
3752
|
-
const data = JSON.parse(text);
|
|
3753
|
-
const passed = [];
|
|
3754
|
-
const failed = [];
|
|
3755
|
-
const metrics = {};
|
|
3756
|
-
for (const [name, m] of Object.entries(data.metrics ?? {})) {
|
|
3757
|
-
if (m.thresholds) {
|
|
3758
|
-
for (const [expr, info] of Object.entries(m.thresholds)) {
|
|
3759
|
-
(info.ok ? passed : failed).push(`${name}: ${expr}`);
|
|
3760
|
-
}
|
|
3761
|
-
}
|
|
3762
|
-
if (m.values) {
|
|
3763
|
-
if (typeof m.values["p(95)"] === "number") metrics[`${name}.p95`] = m.values["p(95)"];
|
|
3764
|
-
if (typeof m.values.rate === "number") metrics[`${name}.rate`] = m.values.rate;
|
|
3765
|
-
if (typeof m.values.count === "number") metrics[`${name}.count`] = m.values.count;
|
|
3766
|
-
if (typeof m.values.avg === "number") metrics[`${name}.avg`] = m.values.avg;
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
return { passed, failed, metrics };
|
|
3770
|
-
} catch {
|
|
3771
|
-
return null;
|
|
3772
|
-
}
|
|
3773
|
-
}
|
|
3774
|
-
|
|
3775
3823
|
// src/commands/test.ts
|
|
3776
3824
|
var VALID_MODES = ["smoke", "load", "both", "skip"];
|
|
3777
3825
|
function registerTestCommand(program) {
|
|
@@ -3793,8 +3841,9 @@ async function runTest(spec, opts) {
|
|
|
3793
3841
|
parseIR(ir);
|
|
3794
3842
|
const fixtureSize = Number.parseInt(opts.fixtureSize ?? "10", 10);
|
|
3795
3843
|
const seed = Number.parseInt(opts.seed ?? "1", 10);
|
|
3844
|
+
const target = resolveTarget(opts.target);
|
|
3796
3845
|
const result = compileK6(ir, {
|
|
3797
|
-
baseUrl:
|
|
3846
|
+
baseUrl: target,
|
|
3798
3847
|
fixtureSize: Number.isFinite(fixtureSize) ? fixtureSize : 10,
|
|
3799
3848
|
seed: Number.isFinite(seed) ? seed : 1
|
|
3800
3849
|
});
|
|
@@ -3850,11 +3899,11 @@ async function runTest(spec, opts) {
|
|
|
3850
3899
|
specSource,
|
|
3851
3900
|
ir,
|
|
3852
3901
|
irJson: JSON.stringify(ir, null, 2),
|
|
3853
|
-
target:
|
|
3902
|
+
target: target ?? result.baseUrl,
|
|
3854
3903
|
envVars: result.auth.envVars,
|
|
3855
3904
|
flags: {
|
|
3856
3905
|
mode,
|
|
3857
|
-
target:
|
|
3906
|
+
target: target ?? null,
|
|
3858
3907
|
fixtureSize,
|
|
3859
3908
|
seed,
|
|
3860
3909
|
noInteractive: !!opts.noInteractive,
|
|
@@ -4080,7 +4129,7 @@ ${dim}${TAGLINE}${reset}
|
|
|
4080
4129
|
}
|
|
4081
4130
|
|
|
4082
4131
|
// src/program.ts
|
|
4083
|
-
var VERSION2 = true ? "0.2.
|
|
4132
|
+
var VERSION2 = true ? "0.2.3" : "0.0.0";
|
|
4084
4133
|
function buildProgram() {
|
|
4085
4134
|
const program = new Command();
|
|
4086
4135
|
program.name("loadam").description(
|