loadam 0.2.1 → 0.2.2
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/dist/bin.js +376 -34
- package/dist/bin.js.map +1 -1
- package/dist/index.js +376 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -2661,17 +2661,358 @@ async function runMcp(spec, opts) {
|
|
|
2661
2661
|
});
|
|
2662
2662
|
}
|
|
2663
2663
|
|
|
2664
|
-
// src/commands/
|
|
2665
|
-
import {
|
|
2664
|
+
// src/commands/report.ts
|
|
2665
|
+
import { spawn } from "child_process";
|
|
2666
|
+
import { readFile as readFile6, writeFile as writeFile6 } from "fs/promises";
|
|
2666
2667
|
import { join as join2, resolve as resolve9 } from "path";
|
|
2668
|
+
|
|
2669
|
+
// ../report/dist/index.js
|
|
2670
|
+
function renderReport(input) {
|
|
2671
|
+
const { meta, loadamVersion } = input;
|
|
2672
|
+
const passed = meta.exitCode === 0 && (meta.thresholds?.failed.length ?? 0) === 0;
|
|
2673
|
+
const dataPayload = {
|
|
2674
|
+
meta,
|
|
2675
|
+
k6Summaries: input.k6Summaries ?? null,
|
|
2676
|
+
contractFailures: input.contractFailures ?? null,
|
|
2677
|
+
loadamVersion
|
|
2678
|
+
};
|
|
2679
|
+
return [
|
|
2680
|
+
"<!doctype html>",
|
|
2681
|
+
`<html lang="en">`,
|
|
2682
|
+
"<head>",
|
|
2683
|
+
`<meta charset="utf-8" />`,
|
|
2684
|
+
`<meta name="viewport" content="width=device-width,initial-scale=1" />`,
|
|
2685
|
+
`<meta name="generator" content="loadam ${esc(loadamVersion)}" />`,
|
|
2686
|
+
`<title>${esc(reportTitle(meta))}</title>`,
|
|
2687
|
+
`<style>${STYLES}</style>`,
|
|
2688
|
+
"</head>",
|
|
2689
|
+
"<body>",
|
|
2690
|
+
renderHeader(meta, passed),
|
|
2691
|
+
renderSummary(meta, input.k6Summaries),
|
|
2692
|
+
renderThresholds(meta),
|
|
2693
|
+
renderK6Metrics(input.k6Summaries),
|
|
2694
|
+
input.driftMarkdown ? renderDrift(input.driftMarkdown) : "",
|
|
2695
|
+
input.contractFailures && input.contractFailures.length > 0 ? renderContract(input.contractFailures) : "",
|
|
2696
|
+
renderRunDetails(meta),
|
|
2697
|
+
renderFooter(meta, loadamVersion),
|
|
2698
|
+
`<script type="application/json" id="loadam-data">${escScript(JSON.stringify(dataPayload))}</script>`,
|
|
2699
|
+
"</body>",
|
|
2700
|
+
"</html>",
|
|
2701
|
+
""
|
|
2702
|
+
].join("\n");
|
|
2703
|
+
}
|
|
2704
|
+
function renderHeader(meta, passed) {
|
|
2705
|
+
const status = passed ? "PASSED" : "FAILED";
|
|
2706
|
+
const cls = passed ? "ok" : "bad";
|
|
2707
|
+
return `
|
|
2708
|
+
<header class="hdr">
|
|
2709
|
+
<div class="hdr-left">
|
|
2710
|
+
<div class="cmd">${esc(meta.command)}</div>
|
|
2711
|
+
<h1>${esc(meta.spec.title ?? "Untitled API")}</h1>
|
|
2712
|
+
<div class="sub">${esc(meta.spec.version ?? "")} \xB7 target <code>${esc(meta.target ?? "\u2014")}</code></div>
|
|
2713
|
+
</div>
|
|
2714
|
+
<div class="hdr-right">
|
|
2715
|
+
<span class="badge ${cls}">${status}</span>
|
|
2716
|
+
<div class="when">${esc(meta.startedAt)}</div>
|
|
2717
|
+
${typeof meta.durationMs === "number" ? `<div class="dur">${(meta.durationMs / 1e3).toFixed(2)}s</div>` : ""}
|
|
2718
|
+
</div>
|
|
2719
|
+
</header>`;
|
|
2720
|
+
}
|
|
2721
|
+
function renderSummary(meta, k6) {
|
|
2722
|
+
const cells = [];
|
|
2723
|
+
if (meta.summary) {
|
|
2724
|
+
for (const [k, v] of Object.entries(meta.summary)) {
|
|
2725
|
+
cells.push({ label: k, value: String(v) });
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
if (k6) {
|
|
2729
|
+
for (const [name, s] of Object.entries(k6)) {
|
|
2730
|
+
const dur = s.metrics?.http_req_duration?.values;
|
|
2731
|
+
if (dur && typeof dur["p(95)"] === "number") {
|
|
2732
|
+
cells.push({ label: `${name} p95`, value: `${dur["p(95)"].toFixed(0)} ms` });
|
|
2733
|
+
}
|
|
2734
|
+
const reqs = s.metrics?.http_reqs?.values;
|
|
2735
|
+
if (reqs && typeof reqs.count === "number") {
|
|
2736
|
+
cells.push({ label: `${name} reqs`, value: String(reqs.count) });
|
|
2737
|
+
}
|
|
2738
|
+
if (reqs && typeof reqs.rate === "number") {
|
|
2739
|
+
cells.push({ label: `${name} rps`, value: `${reqs.rate.toFixed(1)}/s` });
|
|
2740
|
+
}
|
|
2741
|
+
const failed = s.metrics?.http_req_failed?.values;
|
|
2742
|
+
if (failed && typeof failed.rate === "number") {
|
|
2743
|
+
cells.push({
|
|
2744
|
+
label: `${name} fail`,
|
|
2745
|
+
value: `${(failed.rate * 100).toFixed(2)}%`
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
if (cells.length === 0) return "";
|
|
2751
|
+
return `
|
|
2752
|
+
<section class="cards">
|
|
2753
|
+
${cells.map(
|
|
2754
|
+
(c) => `<div class="card"><div class="card-v">${esc(c.value)}</div><div class="card-l">${esc(c.label)}</div></div>`
|
|
2755
|
+
).join("\n ")}
|
|
2756
|
+
</section>`;
|
|
2757
|
+
}
|
|
2758
|
+
function renderThresholds(meta) {
|
|
2759
|
+
const t = meta.thresholds;
|
|
2760
|
+
if (!t || t.passed.length === 0 && t.failed.length === 0) return "";
|
|
2761
|
+
return `
|
|
2762
|
+
<section>
|
|
2763
|
+
<h2>Thresholds</h2>
|
|
2764
|
+
<ul class="thr">
|
|
2765
|
+
${t.failed.map((x) => `<li class="bad">\u2717 ${esc(x)}</li>`).join("\n ")}
|
|
2766
|
+
${t.passed.map((x) => `<li class="ok">\u2713 ${esc(x)}</li>`).join("\n ")}
|
|
2767
|
+
</ul>
|
|
2768
|
+
</section>`;
|
|
2769
|
+
}
|
|
2770
|
+
function renderK6Metrics(k6) {
|
|
2771
|
+
if (!k6 || Object.keys(k6).length === 0) return "";
|
|
2772
|
+
const blocks = [];
|
|
2773
|
+
for (const [name, s] of Object.entries(k6)) {
|
|
2774
|
+
const metrics = s.metrics ?? {};
|
|
2775
|
+
const dur = metrics.http_req_duration?.values;
|
|
2776
|
+
if (!dur) continue;
|
|
2777
|
+
const rows = [
|
|
2778
|
+
["min", fmtMs(dur.min)],
|
|
2779
|
+
["med", fmtMs(dur.med)],
|
|
2780
|
+
["avg", fmtMs(dur.avg)],
|
|
2781
|
+
["p(90)", fmtMs(dur["p(90)"])],
|
|
2782
|
+
["p(95)", fmtMs(dur["p(95)"])],
|
|
2783
|
+
["p(99)", fmtMs(dur["p(99)"])],
|
|
2784
|
+
["max", fmtMs(dur.max)]
|
|
2785
|
+
];
|
|
2786
|
+
blocks.push(`
|
|
2787
|
+
<div class="metric-block">
|
|
2788
|
+
<h3>${esc(name)} \xB7 http_req_duration</h3>
|
|
2789
|
+
<table class="kv">
|
|
2790
|
+
<tbody>
|
|
2791
|
+
${rows.map(([k, v]) => `<tr><th>${esc(k)}</th><td>${esc(v)}</td></tr>`).join("\n ")}
|
|
2792
|
+
</tbody>
|
|
2793
|
+
</table>
|
|
2794
|
+
${renderPercentileBars(dur)}
|
|
2795
|
+
</div>`);
|
|
2796
|
+
}
|
|
2797
|
+
if (blocks.length === 0) return "";
|
|
2798
|
+
return `<section><h2>Latency</h2>${blocks.join("\n")}</section>`;
|
|
2799
|
+
}
|
|
2800
|
+
function renderPercentileBars(dur) {
|
|
2801
|
+
const max = dur.max ?? Math.max(...Object.values(dur));
|
|
2802
|
+
if (!Number.isFinite(max) || max <= 0) return "";
|
|
2803
|
+
const bars = [
|
|
2804
|
+
["med", dur.med ?? 0],
|
|
2805
|
+
["p(90)", dur["p(90)"] ?? 0],
|
|
2806
|
+
["p(95)", dur["p(95)"] ?? 0],
|
|
2807
|
+
["p(99)", dur["p(99)"] ?? 0],
|
|
2808
|
+
["max", max]
|
|
2809
|
+
];
|
|
2810
|
+
return `
|
|
2811
|
+
<div class="bars">
|
|
2812
|
+
${bars.map(([k, v]) => {
|
|
2813
|
+
const pct = Math.max(2, Math.round(v / max * 100));
|
|
2814
|
+
return `<div class="bar-row"><span class="bar-l">${esc(k)}</span><div class="bar"><div class="bar-fill" style="width:${pct}%"></div></div><span class="bar-v">${esc(fmtMs(v))}</span></div>`;
|
|
2815
|
+
}).join("\n ")}
|
|
2816
|
+
</div>`;
|
|
2817
|
+
}
|
|
2818
|
+
function renderDrift(md) {
|
|
2819
|
+
return `
|
|
2820
|
+
<section>
|
|
2821
|
+
<h2>Drift findings</h2>
|
|
2822
|
+
<pre class="drift">${esc(md)}</pre>
|
|
2823
|
+
</section>`;
|
|
2824
|
+
}
|
|
2825
|
+
function renderContract(failures) {
|
|
2826
|
+
return `
|
|
2827
|
+
<section>
|
|
2828
|
+
<h2>Contract failures (${failures.length})</h2>
|
|
2829
|
+
<ul class="failures">
|
|
2830
|
+
${failures.map(
|
|
2831
|
+
(f) => `<li><div class="ftest">${esc(f.test)}</div>${f.message ? `<pre>${esc(f.message)}</pre>` : ""}</li>`
|
|
2832
|
+
).join("\n ")}
|
|
2833
|
+
</ul>
|
|
2834
|
+
</section>`;
|
|
2835
|
+
}
|
|
2836
|
+
function renderRunDetails(meta) {
|
|
2837
|
+
const flagRows = Object.entries(meta.flags).map(
|
|
2838
|
+
([k, v]) => `<tr><th>${esc(k)}</th><td>${esc(String(v))}</td></tr>`
|
|
2839
|
+
);
|
|
2840
|
+
const envRow = meta.envVars.length > 0 ? `<tr><th>env vars</th><td>${meta.envVars.map((e) => `<code>${esc(e)}</code>`).join(" ")}</td></tr>` : "";
|
|
2841
|
+
return `
|
|
2842
|
+
<section>
|
|
2843
|
+
<h2>Run details</h2>
|
|
2844
|
+
<table class="kv">
|
|
2845
|
+
<tbody>
|
|
2846
|
+
<tr><th>session id</th><td><code>${esc(meta.id)}</code></td></tr>
|
|
2847
|
+
<tr><th>spec</th><td><code>${esc(meta.spec.path)}</code></td></tr>
|
|
2848
|
+
<tr><th>spec sha256</th><td><code>${esc(meta.spec.sha256.slice(0, 16))}\u2026</code></td></tr>
|
|
2849
|
+
<tr><th>IR digest</th><td><code>${esc(meta.irDigest.slice(0, 16))}\u2026</code></td></tr>
|
|
2850
|
+
<tr><th>started</th><td>${esc(meta.startedAt)}</td></tr>
|
|
2851
|
+
${meta.endedAt ? `<tr><th>ended</th><td>${esc(meta.endedAt)}</td></tr>` : ""}
|
|
2852
|
+
${typeof meta.exitCode === "number" ? `<tr><th>exit code</th><td>${meta.exitCode}</td></tr>` : ""}
|
|
2853
|
+
${envRow}
|
|
2854
|
+
${flagRows.join("\n ")}
|
|
2855
|
+
</tbody>
|
|
2856
|
+
</table>
|
|
2857
|
+
</section>`;
|
|
2858
|
+
}
|
|
2859
|
+
function renderFooter(meta, version) {
|
|
2860
|
+
return `
|
|
2861
|
+
<footer>
|
|
2862
|
+
Generated by <a href="https://github.com/anonxhash/loadam">loadam ${esc(version)}</a> \xB7
|
|
2863
|
+
schema v${meta.schemaVersion} \xB7
|
|
2864
|
+
IR <code>${esc(meta.irDigest.slice(0, 12))}</code>
|
|
2865
|
+
</footer>`;
|
|
2866
|
+
}
|
|
2867
|
+
function reportTitle(meta) {
|
|
2868
|
+
const t = meta.spec.title ?? "loadam";
|
|
2869
|
+
return `${t} \xB7 ${meta.command} \xB7 ${meta.id}`;
|
|
2870
|
+
}
|
|
2871
|
+
function fmtMs(n) {
|
|
2872
|
+
if (typeof n !== "number" || !Number.isFinite(n)) return "\u2014";
|
|
2873
|
+
if (n >= 1e3) return `${(n / 1e3).toFixed(2)} s`;
|
|
2874
|
+
return `${n.toFixed(0)} ms`;
|
|
2875
|
+
}
|
|
2876
|
+
function esc(s) {
|
|
2877
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2878
|
+
}
|
|
2879
|
+
function escScript(s) {
|
|
2880
|
+
return s.replace(/<\/script/gi, "<\\/script");
|
|
2881
|
+
}
|
|
2882
|
+
var STYLES = `
|
|
2883
|
+
:root{
|
|
2884
|
+
--bg:#fafafa;--fg:#111;--mut:#666;--brd:#e5e5e5;--card:#fff;
|
|
2885
|
+
--ok:#15803d;--ok-bg:#dcfce7;--bad:#b91c1c;--bad-bg:#fee2e2;
|
|
2886
|
+
--acc:#2563eb;--bar:#3b82f6;--code:#f4f4f5;
|
|
2887
|
+
}
|
|
2888
|
+
@media (prefers-color-scheme:dark){
|
|
2889
|
+
:root{
|
|
2890
|
+
--bg:#0a0a0a;--fg:#f5f5f5;--mut:#a1a1aa;--brd:#27272a;--card:#18181b;
|
|
2891
|
+
--ok:#86efac;--ok-bg:#14532d;--bad:#fca5a5;--bad-bg:#7f1d1d;
|
|
2892
|
+
--acc:#60a5fa;--bar:#3b82f6;--code:#27272a;
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
*{box-sizing:border-box}
|
|
2896
|
+
html,body{margin:0;padding:0;background:var(--bg);color:var(--fg);font:14px/1.5 system-ui,-apple-system,Segoe UI,Roboto,sans-serif}
|
|
2897
|
+
body{max-width:960px;margin:0 auto;padding:24px 20px 60px}
|
|
2898
|
+
h1{font-size:20px;margin:0 0 4px}
|
|
2899
|
+
h2{font-size:15px;margin:24px 0 12px;text-transform:uppercase;letter-spacing:.04em;color:var(--mut)}
|
|
2900
|
+
h3{font-size:14px;margin:16px 0 8px;font-weight:600}
|
|
2901
|
+
code{font:12px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--code);padding:1px 6px;border-radius:3px}
|
|
2902
|
+
a{color:var(--acc);text-decoration:none}
|
|
2903
|
+
a:hover{text-decoration:underline}
|
|
2904
|
+
section{margin-top:8px}
|
|
2905
|
+
.hdr{display:flex;justify-content:space-between;align-items:flex-start;gap:24px;padding-bottom:16px;border-bottom:1px solid var(--brd)}
|
|
2906
|
+
.hdr-left .cmd{font-size:11px;text-transform:uppercase;letter-spacing:.08em;color:var(--mut);font-weight:600}
|
|
2907
|
+
.hdr-left .sub{color:var(--mut);font-size:13px;margin-top:4px}
|
|
2908
|
+
.hdr-right{text-align:right}
|
|
2909
|
+
.hdr-right .when,.hdr-right .dur{font-size:12px;color:var(--mut);margin-top:4px;font-variant-numeric:tabular-nums}
|
|
2910
|
+
.badge{display:inline-block;padding:4px 10px;border-radius:4px;font-size:11px;font-weight:700;letter-spacing:.06em}
|
|
2911
|
+
.badge.ok{background:var(--ok-bg);color:var(--ok)}
|
|
2912
|
+
.badge.bad{background:var(--bad-bg);color:var(--bad)}
|
|
2913
|
+
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px;margin-top:20px}
|
|
2914
|
+
.card{background:var(--card);border:1px solid var(--brd);border-radius:6px;padding:12px 14px}
|
|
2915
|
+
.card-v{font-size:18px;font-weight:600;font-variant-numeric:tabular-nums}
|
|
2916
|
+
.card-l{font-size:11px;color:var(--mut);text-transform:uppercase;letter-spacing:.04em;margin-top:2px}
|
|
2917
|
+
.thr{list-style:none;padding:0;margin:0}
|
|
2918
|
+
.thr li{padding:4px 8px;border-radius:3px;margin:2px 0;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}
|
|
2919
|
+
.thr li.ok{color:var(--ok)}
|
|
2920
|
+
.thr li.bad{background:var(--bad-bg);color:var(--bad);font-weight:600}
|
|
2921
|
+
table.kv{border-collapse:collapse;width:100%;font-size:13px}
|
|
2922
|
+
table.kv th,table.kv td{padding:6px 10px;text-align:left;border-bottom:1px solid var(--brd);vertical-align:top}
|
|
2923
|
+
table.kv th{font-weight:500;color:var(--mut);width:160px;white-space:nowrap}
|
|
2924
|
+
.metric-block{background:var(--card);border:1px solid var(--brd);border-radius:6px;padding:12px 16px;margin-bottom:12px}
|
|
2925
|
+
.bars{margin-top:10px}
|
|
2926
|
+
.bar-row{display:grid;grid-template-columns:60px 1fr 80px;gap:10px;align-items:center;font-size:12px;font-variant-numeric:tabular-nums;margin:3px 0}
|
|
2927
|
+
.bar-l{color:var(--mut)}
|
|
2928
|
+
.bar{background:var(--code);height:8px;border-radius:4px;overflow:hidden}
|
|
2929
|
+
.bar-fill{background:var(--bar);height:100%}
|
|
2930
|
+
.bar-v{text-align:right;color:var(--fg)}
|
|
2931
|
+
.drift{background:var(--card);border:1px solid var(--brd);border-radius:6px;padding:12px 16px;overflow-x:auto;font:12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap}
|
|
2932
|
+
.failures{list-style:none;padding:0;margin:0}
|
|
2933
|
+
.failures li{background:var(--bad-bg);border:1px solid var(--bad);border-radius:4px;padding:8px 12px;margin-bottom:6px}
|
|
2934
|
+
.failures .ftest{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;font-weight:600}
|
|
2935
|
+
.failures pre{margin:6px 0 0;font:11px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;white-space:pre-wrap}
|
|
2936
|
+
footer{margin-top:40px;padding-top:16px;border-top:1px solid var(--brd);color:var(--mut);font-size:12px;text-align:center}
|
|
2937
|
+
`;
|
|
2938
|
+
|
|
2939
|
+
// src/commands/report.ts
|
|
2940
|
+
var VERSION = true ? "0.2.2" : "0.0.0";
|
|
2941
|
+
function registerReportCommand(program) {
|
|
2942
|
+
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
|
+
}
|
|
2944
|
+
async function runReport(id, opts) {
|
|
2945
|
+
const out = makeOutput(!!opts.json);
|
|
2946
|
+
const root = resolve9(opts.root);
|
|
2947
|
+
const meta = await resolveSessionId(root, id);
|
|
2948
|
+
const dir = join2(root, "sessions", meta.id);
|
|
2949
|
+
const k6Summaries = {};
|
|
2950
|
+
for (const a of meta.artefacts) {
|
|
2951
|
+
if (a.startsWith("k6-") && a.endsWith("-summary.json")) {
|
|
2952
|
+
const label = a.replace(/^k6-/, "").replace(/-summary\.json$/, "");
|
|
2953
|
+
try {
|
|
2954
|
+
k6Summaries[label] = JSON.parse(await readFile6(join2(dir, a), "utf8"));
|
|
2955
|
+
} catch {
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
let driftMarkdown;
|
|
2960
|
+
if (meta.command === "diff") {
|
|
2961
|
+
try {
|
|
2962
|
+
driftMarkdown = await readFile6(join2(dir, "drift.md"), "utf8");
|
|
2963
|
+
} catch {
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
const html = renderReport({
|
|
2967
|
+
meta,
|
|
2968
|
+
k6Summaries: Object.keys(k6Summaries).length > 0 ? k6Summaries : void 0,
|
|
2969
|
+
driftMarkdown,
|
|
2970
|
+
loadamVersion: VERSION
|
|
2971
|
+
});
|
|
2972
|
+
const outPath = opts.output ? resolve9(opts.output) : join2(dir, "report.html");
|
|
2973
|
+
await writeFile6(outPath, html, "utf8");
|
|
2974
|
+
const sizeKb = Math.round(Buffer.byteLength(html, "utf8") / 1024);
|
|
2975
|
+
if (!out.json) {
|
|
2976
|
+
out.success(`Wrote ${outPath} (${sizeKb} KB)`);
|
|
2977
|
+
}
|
|
2978
|
+
out.result({
|
|
2979
|
+
command: "report",
|
|
2980
|
+
sessionId: meta.id,
|
|
2981
|
+
path: outPath,
|
|
2982
|
+
sizeBytes: Buffer.byteLength(html, "utf8"),
|
|
2983
|
+
opened: false
|
|
2984
|
+
});
|
|
2985
|
+
if (opts.open) {
|
|
2986
|
+
await openInBrowser(outPath);
|
|
2987
|
+
if (!out.json) out.info("Opened in default browser");
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
async function openInBrowser(path) {
|
|
2991
|
+
const platform = process.platform;
|
|
2992
|
+
const cmd = platform === "darwin" ? "open" : platform === "win32" ? "start" : "xdg-open";
|
|
2993
|
+
const args = platform === "win32" ? ["", path] : [path];
|
|
2994
|
+
try {
|
|
2995
|
+
const child = spawn(cmd, args, {
|
|
2996
|
+
detached: true,
|
|
2997
|
+
stdio: "ignore",
|
|
2998
|
+
shell: platform === "win32"
|
|
2999
|
+
});
|
|
3000
|
+
child.unref();
|
|
3001
|
+
} catch {
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
// src/commands/show.ts
|
|
3006
|
+
import { readFile as readFile7, readdir as readdir2 } from "fs/promises";
|
|
3007
|
+
import { join as join3, resolve as resolve10 } from "path";
|
|
2667
3008
|
function registerShowCommand(program) {
|
|
2668
3009
|
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));
|
|
2669
3010
|
}
|
|
2670
3011
|
async function runShow(id, opts) {
|
|
2671
3012
|
const out = makeOutput(!!opts.json);
|
|
2672
|
-
const root =
|
|
3013
|
+
const root = resolve10(opts.root);
|
|
2673
3014
|
const meta = await resolveSessionId(root, id);
|
|
2674
|
-
const dir =
|
|
3015
|
+
const dir = join3(root, "sessions", meta.id);
|
|
2675
3016
|
if (out.json) {
|
|
2676
3017
|
out.result({ ...meta });
|
|
2677
3018
|
return;
|
|
@@ -2709,7 +3050,7 @@ async function runShow(id, opts) {
|
|
|
2709
3050
|
}
|
|
2710
3051
|
if (meta.command === "diff") {
|
|
2711
3052
|
try {
|
|
2712
|
-
const drift = await
|
|
3053
|
+
const drift = await readFile7(join3(dir, "drift.md"), "utf8");
|
|
2713
3054
|
out.info("");
|
|
2714
3055
|
out.info("\u2500\u2500\u2500\u2500 drift.md \u2500\u2500\u2500\u2500");
|
|
2715
3056
|
process.stdout.write(drift);
|
|
@@ -2719,8 +3060,8 @@ async function runShow(id, opts) {
|
|
|
2719
3060
|
}
|
|
2720
3061
|
|
|
2721
3062
|
// src/commands/test.ts
|
|
2722
|
-
import { mkdir as mkdir4, readFile as
|
|
2723
|
-
import { dirname as dirname3, join as
|
|
3063
|
+
import { mkdir as mkdir4, readFile as readFile9, writeFile as writeFile8 } from "fs/promises";
|
|
3064
|
+
import { dirname as dirname3, join as join5, resolve as resolve12 } from "path";
|
|
2724
3065
|
|
|
2725
3066
|
// ../data/dist/index.js
|
|
2726
3067
|
import { faker } from "@faker-js/faker";
|
|
@@ -2773,20 +3114,20 @@ function inferKindFromFieldName(field) {
|
|
|
2773
3114
|
const root = m[1];
|
|
2774
3115
|
return root.charAt(0).toUpperCase() + root.slice(1);
|
|
2775
3116
|
}
|
|
2776
|
-
function expandRefs(node,
|
|
2777
|
-
if (Array.isArray(node)) return node.map((n) => expandRefs(n,
|
|
3117
|
+
function expandRefs(node, resolve13, seen) {
|
|
3118
|
+
if (Array.isArray(node)) return node.map((n) => expandRefs(n, resolve13, seen));
|
|
2778
3119
|
if (!node || typeof node !== "object") return node;
|
|
2779
3120
|
const obj = node;
|
|
2780
3121
|
if (typeof obj.$ref === "string") {
|
|
2781
3122
|
if (seen.has(obj.$ref)) return {};
|
|
2782
|
-
const target =
|
|
3123
|
+
const target = resolve13(obj.$ref);
|
|
2783
3124
|
if (target === void 0) return obj;
|
|
2784
3125
|
const next = new Set(seen);
|
|
2785
3126
|
next.add(obj.$ref);
|
|
2786
|
-
return expandRefs(target,
|
|
3127
|
+
return expandRefs(target, resolve13, next);
|
|
2787
3128
|
}
|
|
2788
3129
|
const out = {};
|
|
2789
|
-
for (const [k, v] of Object.entries(obj)) out[k] = expandRefs(v,
|
|
3130
|
+
for (const [k, v] of Object.entries(obj)) out[k] = expandRefs(v, resolve13, seen);
|
|
2790
3131
|
return out;
|
|
2791
3132
|
}
|
|
2792
3133
|
|
|
@@ -3282,8 +3623,8 @@ function compileK6(ir, opts = {}) {
|
|
|
3282
3623
|
}
|
|
3283
3624
|
|
|
3284
3625
|
// src/util/interactive.ts
|
|
3285
|
-
import { chmod, readFile as
|
|
3286
|
-
import { resolve as
|
|
3626
|
+
import { chmod, readFile as readFile8, writeFile as writeFile7 } from "fs/promises";
|
|
3627
|
+
import { resolve as resolve11 } from "path";
|
|
3287
3628
|
import { confirm, password, select } from "@inquirer/prompts";
|
|
3288
3629
|
function isInteractive(noInteractiveFlag) {
|
|
3289
3630
|
if (noInteractiveFlag) return false;
|
|
@@ -3320,7 +3661,7 @@ async function confirmContinue(message) {
|
|
|
3320
3661
|
return await confirm({ message, default: true });
|
|
3321
3662
|
}
|
|
3322
3663
|
async function writeEnvFile(dir, baseUrl, vars, opts = {}) {
|
|
3323
|
-
const path =
|
|
3664
|
+
const path = resolve11(dir, ".env");
|
|
3324
3665
|
const existing = await readEnvFile(path);
|
|
3325
3666
|
const written = [];
|
|
3326
3667
|
const preserved = [];
|
|
@@ -3340,14 +3681,14 @@ async function writeEnvFile(dir, baseUrl, vars, opts = {}) {
|
|
|
3340
3681
|
}
|
|
3341
3682
|
const body = `${Object.entries(existing).map(([k, v]) => `${k}=${v}`).join("\n")}
|
|
3342
3683
|
`;
|
|
3343
|
-
await
|
|
3684
|
+
await writeFile7(path, body, "utf8");
|
|
3344
3685
|
await chmod(path, 384).catch(() => {
|
|
3345
3686
|
});
|
|
3346
3687
|
return { path, written, preserved };
|
|
3347
3688
|
}
|
|
3348
3689
|
async function readEnvFile(path) {
|
|
3349
3690
|
try {
|
|
3350
|
-
const text = await
|
|
3691
|
+
const text = await readFile8(path, "utf8");
|
|
3351
3692
|
const out = {};
|
|
3352
3693
|
for (const raw of text.split(/\r?\n/)) {
|
|
3353
3694
|
const line = raw.trim();
|
|
@@ -3365,16 +3706,16 @@ async function readEnvFile(path) {
|
|
|
3365
3706
|
}
|
|
3366
3707
|
|
|
3367
3708
|
// src/util/k6.ts
|
|
3368
|
-
import { spawn } from "child_process";
|
|
3709
|
+
import { spawn as spawn2 } from "child_process";
|
|
3369
3710
|
import { constants, access } from "fs/promises";
|
|
3370
|
-
import { delimiter, join as
|
|
3711
|
+
import { delimiter, join as join4 } from "path";
|
|
3371
3712
|
async function findK6Binary() {
|
|
3372
3713
|
const path = process.env.PATH ?? "";
|
|
3373
3714
|
const exts = process.platform === "win32" ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
3374
3715
|
for (const dir of path.split(delimiter)) {
|
|
3375
3716
|
if (!dir) continue;
|
|
3376
3717
|
for (const ext of exts) {
|
|
3377
|
-
const candidate =
|
|
3718
|
+
const candidate = join4(dir, `k6${ext}`);
|
|
3378
3719
|
try {
|
|
3379
3720
|
await access(candidate, constants.X_OK);
|
|
3380
3721
|
return candidate;
|
|
@@ -3395,7 +3736,7 @@ async function runK6(opts) {
|
|
|
3395
3736
|
if (opts.summaryPath) args.push(`--summary-export=${opts.summaryPath}`);
|
|
3396
3737
|
args.push(...opts.args ?? [], opts.script);
|
|
3397
3738
|
return await new Promise((resolveExit, reject) => {
|
|
3398
|
-
const child =
|
|
3739
|
+
const child = spawn2(bin, args, {
|
|
3399
3740
|
cwd: opts.cwd,
|
|
3400
3741
|
env: { ...process.env, ...opts.env },
|
|
3401
3742
|
stdio: "inherit"
|
|
@@ -3406,8 +3747,8 @@ async function runK6(opts) {
|
|
|
3406
3747
|
}
|
|
3407
3748
|
async function digestK6Summary(path) {
|
|
3408
3749
|
try {
|
|
3409
|
-
const { readFile:
|
|
3410
|
-
const text = await
|
|
3750
|
+
const { readFile: readFile10 } = await import("fs/promises");
|
|
3751
|
+
const text = await readFile10(path, "utf8");
|
|
3411
3752
|
const data = JSON.parse(text);
|
|
3412
3753
|
const passed = [];
|
|
3413
3754
|
const failed = [];
|
|
@@ -3444,9 +3785,9 @@ function registerTestCommand(program) {
|
|
|
3444
3785
|
}
|
|
3445
3786
|
async function runTest(spec, opts) {
|
|
3446
3787
|
const out = makeOutput(!!opts.json);
|
|
3447
|
-
const specPath =
|
|
3788
|
+
const specPath = resolve12(spec);
|
|
3448
3789
|
out.start(`Parsing OpenAPI spec: ${specPath}`);
|
|
3449
|
-
const specSource = await
|
|
3790
|
+
const specSource = await readFile9(specPath, "utf8");
|
|
3450
3791
|
const ir = await fromOpenApiFile(specPath);
|
|
3451
3792
|
inferResourceGraph(ir);
|
|
3452
3793
|
parseIR(ir);
|
|
@@ -3457,12 +3798,12 @@ async function runTest(spec, opts) {
|
|
|
3457
3798
|
fixtureSize: Number.isFinite(fixtureSize) ? fixtureSize : 10,
|
|
3458
3799
|
seed: Number.isFinite(seed) ? seed : 1
|
|
3459
3800
|
});
|
|
3460
|
-
const outDir =
|
|
3801
|
+
const outDir = resolve12(opts.output);
|
|
3461
3802
|
await mkdir4(outDir, { recursive: true });
|
|
3462
3803
|
for (const [rel, contents] of Object.entries(result.files)) {
|
|
3463
|
-
const full =
|
|
3804
|
+
const full = resolve12(outDir, rel);
|
|
3464
3805
|
await mkdir4(dirname3(full), { recursive: true });
|
|
3465
|
-
await
|
|
3806
|
+
await writeFile8(full, contents, "utf8");
|
|
3466
3807
|
}
|
|
3467
3808
|
const fileCount = Object.keys(result.files).length;
|
|
3468
3809
|
const fixtureCount = Object.keys(result.fixtures.byOperationId).length;
|
|
@@ -3569,7 +3910,7 @@ function parseModeFlag(raw) {
|
|
|
3569
3910
|
return raw;
|
|
3570
3911
|
}
|
|
3571
3912
|
function getSessionRoot(outDir) {
|
|
3572
|
-
return
|
|
3913
|
+
return resolve12(outDir, "..");
|
|
3573
3914
|
}
|
|
3574
3915
|
async function maybeRunWithSession(input) {
|
|
3575
3916
|
const { mode, cwd, out, session } = input;
|
|
@@ -3595,7 +3936,7 @@ async function maybeRunWithSession(input) {
|
|
|
3595
3936
|
out.step("");
|
|
3596
3937
|
out.step("Running k6 smoke test...");
|
|
3597
3938
|
}
|
|
3598
|
-
const summaryPath =
|
|
3939
|
+
const summaryPath = join5(session.dir, "k6-smoke-summary.json");
|
|
3599
3940
|
result.smokeExit = await runK6({ cwd, script: "smoke.js", summaryPath });
|
|
3600
3941
|
const digest = await digestK6Summary(summaryPath);
|
|
3601
3942
|
if (digest) {
|
|
@@ -3625,7 +3966,7 @@ async function maybeRunWithSession(input) {
|
|
|
3625
3966
|
out.step("");
|
|
3626
3967
|
out.step("Running k6 load test...");
|
|
3627
3968
|
}
|
|
3628
|
-
const summaryPath =
|
|
3969
|
+
const summaryPath = join5(session.dir, "k6-load-summary.json");
|
|
3629
3970
|
result.loadExit = await runK6({ cwd, script: "load.js", summaryPath });
|
|
3630
3971
|
const digest = await digestK6Summary(summaryPath);
|
|
3631
3972
|
if (digest) {
|
|
@@ -3739,12 +4080,12 @@ ${dim}${TAGLINE}${reset}
|
|
|
3739
4080
|
}
|
|
3740
4081
|
|
|
3741
4082
|
// src/program.ts
|
|
3742
|
-
var
|
|
4083
|
+
var VERSION2 = true ? "0.2.2" : "0.0.0";
|
|
3743
4084
|
function buildProgram() {
|
|
3744
4085
|
const program = new Command();
|
|
3745
4086
|
program.name("loadam").description(
|
|
3746
4087
|
"Generate test rigs and MCP servers from any API spec. From spec to running rig in 60s."
|
|
3747
|
-
).version(
|
|
4088
|
+
).version(VERSION2, "-v, --version", "print version").addHelpText("beforeAll", banner());
|
|
3748
4089
|
registerInitCommand(program);
|
|
3749
4090
|
registerAuthCommands(program);
|
|
3750
4091
|
registerTestCommand(program);
|
|
@@ -3753,9 +4094,10 @@ function buildProgram() {
|
|
|
3753
4094
|
registerMcpCommand(program);
|
|
3754
4095
|
registerHistoryCommand(program);
|
|
3755
4096
|
registerShowCommand(program);
|
|
4097
|
+
registerReportCommand(program);
|
|
3756
4098
|
registerCleanCommand(program);
|
|
3757
4099
|
registerCompletionCommand(program);
|
|
3758
|
-
registerUpdateCommand(program,
|
|
4100
|
+
registerUpdateCommand(program, VERSION2);
|
|
3759
4101
|
return program;
|
|
3760
4102
|
}
|
|
3761
4103
|
export {
|