merge: integrate review-08-update-dry-run

This commit is contained in:
gitea committed 2026-10-20 23:02:23 +08:00
commit d1a75c011a
4 files changed
+182 -147

No files matched your search

+2
View File
@@ -32,3 +32,5 @@
优先用 `--corp` 明确指定企业。短参数 `-c` 在命令之前表示全局企业选择;在声明了同名参数的命令之后,遵循该命令的含义(例如 `bill list -c` 为单号)。布尔值可写 `--active=false` 或 `--active false`;数字形式使用 `=0` / `=1`,空格后的数字保留为可能的位置 ID。`--` 之后的内容全部作为位置参数。
`hose-use mcp [serve]` 在当前进程启动服务,不派生 Bun 或访问源码脚本;MCP 调用继续只通过 `hose_cli` 分发,流式终端回调不会被注入协议通道。
`update --dry-run` 返回源码或二进制更新计划,不请求发布源、不执行 git/依赖安装、不替换二进制或同步技能;`update check` 和发布历史查询保留只读查询行为。
+25
View File
@@ -0,0 +1,25 @@
import { expect, spyOn, test } from "bun:test";
import * as cp from "node:child_process";
import * as packaging from "../../../packaging/runtime.js";
import * as skill from "../../../packaging/embedded-skill.js";
import { parseArgs } from "../../parser.js";
import { handleUpdateCommand } from "./index.js";
test("source and binary update previews do not fetch, spawn or install skills", async () => {
const spawn = spyOn(cp, "spawnSync").mockImplementation(() => { throw new Error("unexpected spawn"); });
const sync = spyOn(skill, "syncGlobalSkillIfPresent").mockImplementation(() => { throw new Error("unexpected install"); });
const compiled = spyOn(packaging, "isCompiledBinary");
const oldFetch = globalThis.fetch; let requests = 0;
globalThis.fetch = (async () => { requests++; throw new Error("unexpected fetch"); }) as any;
try {
for (const binary of [false, true]) {
compiled.mockReturnValue(binary);
const result = await handleUpdateCommand(parseArgs(["update", "--dry-run"]), { jsonMode: true } as any, { appRoot: "/tmp/update-preview" });
const preview = JSON.parse(result.stdout);
expect(preview.dryRun).toBe(true);
expect(preview.changes.mode).toBe(binary ? "binary" : "source");
expect(result.exitCode).toBe(0);
}
expect(requests).toBe(0); expect(spawn).not.toHaveBeenCalled(); expect(sync).not.toHaveBeenCalled();
} finally { globalThis.fetch = oldFetch; spawn.mockRestore(); sync.mockRestore(); compiled.mockRestore(); }
});
+8
View File
@@ -1,3 +1,4 @@
import { isDryRun, mutationPreview } from "../../mutation.js";
import { chmodSync, existsSync, mkdirSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { spawnSync } from "node:child_process";
@@ -180,6 +181,13 @@ export async function handleUpdateCommand(
}
}
if (!options.checkOnly && !options.changelogOnly && isDryRun(parsed, runtime)) {
return mutationPreview(parsed, runtime, "更新 hose-use", appRoot, {
mode: isCompiledBinary() ? "binary" : "source",
version: targetVersion || "latest", repo, sourcePreference, force: options.force,
});
}
// 1. Changelog / Release History query
if (options.changelogOnly) {
const releases = await fetchGitHubReleases(repo, options.limit ?? 10, options.sourcePreference);