1
0

refactor: 清理 checker 遗留边界

This commit is contained in:
2026-05-13 12:53:03 +08:00
parent 7b20b59b79
commit aade0bbff7
6 changed files with 85 additions and 196 deletions

View File

@@ -7,6 +7,10 @@ import { CommandChecker } from "../../../../../src/server/checker/runner/command
const checker = new CommandChecker();
const processEnv = Object.fromEntries(
Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] !== undefined),
);
function makeCtx(timeoutMs = 5000): CheckerContext {
const controller = new AbortController();
setTimeout(() => controller.abort(), timeoutMs);
@@ -21,7 +25,7 @@ function makeTarget(
command: {
args: ["hello"],
cwd: "/tmp",
env: {},
env: processEnv,
exec: "echo",
maxOutputBytes: 1024 * 1024,
...command,
@@ -125,6 +129,22 @@ describe("CommandChecker", () => {
expect(result.matched).toBe(true);
});
test("execute 使用 resolved env", async () => {
const result = await checker.execute(
makeTarget(
{
args: ["-e", "console.log(process.env.DIAL_TEST_ENV ?? '')"],
env: { DIAL_TEST_ENV: "resolved-env" },
exec: process.execPath,
},
{ expect: { stdout: [{ contains: "resolved-env" }] } },
),
makeCtx(),
);
expect(result.matched).toBe(true);
});
test("serialize 返回命令摘要和 config JSON", () => {
const target = makeTarget({ args: ["hello"], exec: "echo" });
const s = checker.serialize(target);