fix: address Codex PR review findings

This commit is contained in:
gitea committed 2026-10-25 22:32:45 +08:00
1 parent 0f164b6de5
commit a7974abb08
44 files changed
+3317 -667

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
import { expect, test } from "bun:test";
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
test("source and committed plugin preserve offline review execution contracts", () => {
const root = resolve(import.meta.dir, "..");
const temp = mkdtempSync(join(tmpdir(), "hose-review-plugin-"));
try {
const enterprises = join(temp, "enterprises");
mkdirSync(enterprises);
writeFileSync(join(enterprises, "smoke.json"), JSON.stringify({
id: "smoke", name: "离线测试企业", env: "test",
credentials: { accessToken: "synthetic-offline-token", corpId: "smoke", staffId: "staff" },
}));
const env = {
...process.env,
HOSE_ENTERPRISES_DIR: enterprises,
HOSE_CONFIG_FILE: join(temp, "config.json"),
HOSE_ACCOUNTS_FILE: join(temp, "accounts.json"),
HOSE_APPROVAL_DB: ":memory:",
};
const fixtures = [
{ name: "collections", type: "code", code: 'Map m = new java.util.HashMap(); m.put("x", 7); m.size();', value: 1 },
{ name: "final-expression", type: "code", code: 'Map m = new HashMap(); m.put("x", 7); m;', value: { x: 7 } },
{ name: "javascript", type: "code-js2", code: "return 7;", value: 7 },
{ name: "unsupported", type: "code", code: "new java.util.Date();", error: "UnsupportedMvelSyntax" },
];
for (const fixture of fixtures) {
const file = join(temp, `${fixture.name}.script`);
writeFileSync(file, fixture.code);
for (const entry of [["src/cli.ts"], ["dist/mcp/server.js", "--hose-use-cli"]]) {
const result = Bun.spawnSync([
process.execPath, ...entry, "workflow", "eval-script", "--file", file,
"--type", fixture.type, "--corp", "smoke", "--stateless", "--json",
], { cwd: root, env, timeout: 10000 });
expect(result.exitCode).toBe(fixture.error ? 1 : 0);
const report = JSON.parse(result.stdout.toString());
expect(report.success).toBe(!fixture.error);
if (fixture.error) expect(report.error.name).toBe(fixture.error);
else expect(report.returnValue).toEqual(fixture.value);
}
}
} finally {
rmSync(temp, { recursive: true, force: true });
}
});