Files
hose-use/scripts/build/plugin-review-smoke.test.ts
T
gitea 362acfba58 feat(cli): 分离 hose-aipro 独立命令体系并升级至 v0.9.0
1. 架构对称性与声明式注册表抽取:
   - 新增 src/cli/aipro-registry.ts,声明式定义 AIPRO_COMMAND_REGISTRY 及其别名映射与 mutating 突变检查
   - 重构 src/aipro-cli.ts,移除过程式 switch-case 分发,改为查表式声明分发,与 hose-use 的 CLI_COMMAND_REGISTRY 保持 100% 对称
   - 在 src/cli/registry.ts 统一重导出 aipro-registry,巩固其作为顶层声明注册表的单一事实源地位
   - 增加 aipro-cli 测试用例,强制校验 COMMAND_METADATA["hose-aipro"] 与声明式注册表双向一致性

2. 双 Skill 独立打包与内嵌部署:
   - 注册两个独立技能:skills/hose-use 与 skills/hose-aipro,互相关联引用
   - src/packaging/embedded-skill.ts 增加双 Skill 编译期嵌入与 installSkillFiles 全量同步
   - hose-use / hose-aipro 下的 skill status/dump/install 完全对齐

3. 守护服务交叉治理:
   - src/cli/service.ts 支持 ServiceTargetName ("hose-use" | "hose-aipro"),默认端口 8888 与 8889
   - 支持 hose-use aipro <start|stop|...> 与 hose-aipro hose-use <start|stop|...> 双向服务纳管
   - 误触非本领域业务命令时提供友好互导拦截

4. 审批领域数据层防御加固:
   - 迁移 004:approval_runs 增加 short_id 唯一约束
   - 增加 allocateUniqueShortId 冲突重试,多步写操作纳入事务

5. 版本升级至 v0.9.0:
   - package.json、README.md、specs、.zcode-plugin 及两套 Skill 同步更新至 0.9.0
   - bump-version 脚本适配多 Skill 自动递增
2026-11-03 19:16:12 +08:00

73 lines
3.9 KiB
TypeScript

import { expect, test } from "bun:test";
import { existsSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
test("source and freshly packaged plugin preserve offline review and MCP contracts without a prebuilt dist", () => {
const root = resolve(import.meta.dir, "../..");
const temp = mkdtempSync(join(tmpdir(), "hose review plugin "));
try {
const packaged = Bun.spawnSync([
process.execPath, join(root, "scripts/build/package-plugin.mjs"), `--out-dir=${join(temp, "artifacts")}`,
], { cwd: temp, env: { ...process.env, BUN_BIN: process.execPath }, timeout: 30_000 });
expect(packaged.exitCode, packaged.stderr.toString()).toBe(0);
const version = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).version;
const archive = join(temp, "artifacts", `hose-use-plugin-v${version}.tar.gz`);
const pluginRoot = join(temp, "unpacked");
mkdirSync(pluginRoot);
const extracted = Bun.spawnSync(["tar", "-xzf", archive, "-C", pluginRoot]);
expect(extracted.exitCode, extracted.stderr.toString()).toBe(0);
expect(readdirSync(pluginRoot).sort()).toEqual([".mcp.json", ".zcode-plugin", "dist", "skills"]);
const manifest = JSON.parse(readFileSync(join(pluginRoot, ".zcode-plugin/plugin.json"), "utf8"));
expect(manifest.version).toBe(version);
expect(manifest.skills).toBe("skills");
const mcp = JSON.parse(readFileSync(join(pluginRoot, manifest.mcpServers), "utf8")).mcpServers["hose-use"];
expect(mcp.command).toBe("bun");
const bundle = mcp.args[0].replace("${CLAUDE_PLUGIN_ROOT}", pluginRoot);
expect(existsSync(bundle)).toBe(true);
for (const file of readdirSync(join(root, "skills"), { recursive: true })) {
expect(existsSync(join(pluginRoot, "skills", file))).toBe(true);
}
const protocol = Bun.spawnSync([
process.execPath, join(root, "scripts/build/verify-binary.ts"), bundle, "--plugin",
], { cwd: temp, timeout: 30_000 });
expect(protocol.exitCode, protocol.stderr.toString()).toBe(0);
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 [[join(root, "src/cli.ts")], [bundle, "--hose-use-cli"]]) {
const result = Bun.spawnSync([
process.execPath, ...entry, "workflow", "eval-script", "--file", file,
"--type", fixture.type, "--corp", "smoke", "--stateless", "--json",
], { cwd: pluginRoot, env, timeout: 30000 });
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 });
}
}, 60_000);