@hcmai/cli 0.15.4 → 0.15.5
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/index.js +44 -11
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -12100,6 +12100,7 @@ async function chironPageCommand(target, args, deps = defaultChironPageDeps) {
|
|
|
12100
12100
|
// src/commands/chiron-test.ts
|
|
12101
12101
|
init_exit();
|
|
12102
12102
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
12103
|
+
import { randomUUID } from "crypto";
|
|
12103
12104
|
import { promises as fs13 } from "fs";
|
|
12104
12105
|
import path14 from "path";
|
|
12105
12106
|
import yaml2 from "js-yaml";
|
|
@@ -12905,14 +12906,23 @@ function matches(actual, rule) {
|
|
|
12905
12906
|
return String(actual) === want;
|
|
12906
12907
|
}
|
|
12907
12908
|
}
|
|
12909
|
+
function selfCliInvocation(argv, runtime = process) {
|
|
12910
|
+
const entry = runtime.argv[1];
|
|
12911
|
+
if (!entry) throw new Error("\u65E0\u6CD5\u786E\u5B9A\u5F53\u524D hcm CLI \u5165\u53E3\uFF0C\u4E0D\u80FD\u5B89\u5168\u6267\u884C\u56DE\u5F52\u5B50\u6B65\u9AA4");
|
|
12912
|
+
return { command: runtime.execPath, args: [entry, ...argv] };
|
|
12913
|
+
}
|
|
12914
|
+
function runSelf(argv, cwd, maxBuffer, timeout) {
|
|
12915
|
+
const invocation = selfCliInvocation(argv);
|
|
12916
|
+
return spawnSync2(invocation.command, invocation.args, { cwd, encoding: "utf8", maxBuffer, timeout });
|
|
12917
|
+
}
|
|
12908
12918
|
var defaultDeps3 = {
|
|
12909
12919
|
assess: (argv) => assessEffectiveDeliveryCommand(argv),
|
|
12910
12920
|
hcm: (argv, cwd) => {
|
|
12911
|
-
const r =
|
|
12921
|
+
const r = runSelf(argv, cwd, 1 << 26, 6e5);
|
|
12912
12922
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
12913
12923
|
},
|
|
12914
12924
|
page: (root, argv) => {
|
|
12915
|
-
const r =
|
|
12925
|
+
const r = runSelf(["chiron", "page", ...argv], root, 1 << 24, 3e5);
|
|
12916
12926
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
12917
12927
|
},
|
|
12918
12928
|
readXlsx: (file) => xlsxRows(file),
|
|
@@ -12950,13 +12960,20 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
|
|
|
12950
12960
|
const want = c.expect ?? {};
|
|
12951
12961
|
const bad = [];
|
|
12952
12962
|
if (want.exit !== void 0 && r2.status !== want.exit) bad.push(`\u9000\u51FA\u7801 ${r2.status} \u2260 ${want.exit}`);
|
|
12953
|
-
for (const
|
|
12954
|
-
|
|
12963
|
+
for (const raw of want.stdout_contains ?? []) {
|
|
12964
|
+
const t = fill(raw);
|
|
12965
|
+
if (!r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u6CA1\u6709\u300C${t}\u300D`);
|
|
12966
|
+
}
|
|
12967
|
+
for (const raw of want.stdout_not_contains ?? []) {
|
|
12968
|
+
const t = fill(raw);
|
|
12969
|
+
if (r2.stdout.includes(t)) bad.push(`\u8F93\u51FA\u91CC\u51FA\u73B0\u4E86\u4E0D\u8BE5\u6709\u7684\u300C${t}\u300D`);
|
|
12970
|
+
}
|
|
12955
12971
|
if (want.json) {
|
|
12956
12972
|
const parsed = parseJsonLoose(r2.stdout);
|
|
12957
12973
|
if (parsed === void 0) bad.push("\u8F93\u51FA\u4E0D\u662F JSON\uFF0C\u65E0\u6CD5\u6309 json \u5224\u636E\u6BD4\u5BF9");
|
|
12958
12974
|
if (parsed !== void 0) {
|
|
12959
|
-
for (const [expr,
|
|
12975
|
+
for (const [expr, rawRule] of Object.entries(want.json)) {
|
|
12976
|
+
const rule = fill(rawRule);
|
|
12960
12977
|
const actual = pick(parsed, expr);
|
|
12961
12978
|
if (!matches(actual, rule)) bad.push(`${expr} \u5B9E\u9645 ${JSON.stringify(actual)}\uFF0C\u671F\u671B ${rule}`);
|
|
12962
12979
|
}
|
|
@@ -12980,23 +12997,34 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
|
|
|
12980
12997
|
if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
|
|
12981
12998
|
const rows2 = deps.readXlsx(file);
|
|
12982
12999
|
const header = (rows2[0] ?? []).map((x) => String(x).trim());
|
|
12983
|
-
for (const
|
|
13000
|
+
for (const raw of want.xlsx_header ?? []) {
|
|
13001
|
+
const h = fill(raw);
|
|
13002
|
+
if (!header.includes(h)) bad.push(`\u8868\u5934\u91CC\u6CA1\u6709\u300C${h}\u300D\uFF0C\u5B9E\u9645\u662F [${header.slice(0, 8).join(", ")}]`);
|
|
13003
|
+
}
|
|
12984
13004
|
if (want.xlsx_min_rows !== void 0 && rows2.length - 1 < want.xlsx_min_rows) bad.push(`\u6570\u636E\u884C ${Math.max(rows2.length - 1, 0)} \u5C11\u4E8E ${want.xlsx_min_rows}`);
|
|
12985
13005
|
}
|
|
12986
13006
|
if (want.text_contains) {
|
|
12987
13007
|
const text = await deps.readText(file);
|
|
12988
|
-
for (const
|
|
13008
|
+
for (const raw of want.text_contains) {
|
|
13009
|
+
const t = fill(raw);
|
|
13010
|
+
if (!text.includes(t)) bad.push(`\u6587\u4EF6\u91CC\u6CA1\u6709\u300C${t}\u300D`);
|
|
13011
|
+
}
|
|
12989
13012
|
}
|
|
12990
13013
|
results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
|
|
12991
13014
|
continue;
|
|
12992
13015
|
}
|
|
12993
|
-
const out = path14.join(
|
|
13016
|
+
const out = path14.join(
|
|
13017
|
+
"evidence",
|
|
13018
|
+
"test",
|
|
13019
|
+
opts.evidenceRunId ?? "current",
|
|
13020
|
+
`${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png"
|
|
13021
|
+
);
|
|
12994
13022
|
const argv = [fill(c.page), "--out", out, "--project", root];
|
|
12995
13023
|
if (opts.env) argv.push("--env", opts.env);
|
|
12996
13024
|
const as = c.as ?? opts.as;
|
|
12997
13025
|
if (as) argv.push("--as", as);
|
|
12998
|
-
for (const t of c.expect_text ?? []) argv.push("--expect-text", t);
|
|
12999
|
-
for (const t of c.reject_text ?? []) argv.push("--reject-text", t);
|
|
13026
|
+
for (const t of c.expect_text ?? []) argv.push("--expect-text", fill(t));
|
|
13027
|
+
for (const t of c.reject_text ?? []) argv.push("--reject-text", fill(t));
|
|
13000
13028
|
const r = deps.page(root, argv);
|
|
13001
13029
|
results.push(r.status === 0 ? { name: c.name, verdict: "pass", detail: out } : { name: c.name, verdict: "fail", detail: (r.stderr || r.stdout).trim().split("\n").slice(-1)[0] ?? `\u9000\u51FA\u7801 ${r.status}` });
|
|
13002
13030
|
} catch (e) {
|
|
@@ -13025,7 +13053,12 @@ async function chironTestCommand(target, args, deps) {
|
|
|
13025
13053
|
const report = [];
|
|
13026
13054
|
let failed2 = 0;
|
|
13027
13055
|
for (const { file, spec } of cases) {
|
|
13028
|
-
const results = await runCase(
|
|
13056
|
+
const results = await runCase(
|
|
13057
|
+
spec,
|
|
13058
|
+
root,
|
|
13059
|
+
{ env: args.env, as: args.as, evidenceRunId: randomUUID() },
|
|
13060
|
+
deps
|
|
13061
|
+
);
|
|
13029
13062
|
failed2 += results.filter((r) => r.verdict === "fail").length;
|
|
13030
13063
|
report.push({ case: spec.name, file: path14.relative(root, file), results });
|
|
13031
13064
|
}
|