fix: harden CLI parsing, MCP startup and release integrity
This commit is contained in:
1 parent
f0902f5f20
commit
103ead0fe5
53 files changed
+3713
-1945
No files matched your search
@@ -19,6 +19,7 @@ function run(args) {
|
||||
|
||||
const mcpOutput = resolve(root, "dist/mcp/server.js");
|
||||
mkdirSync(dirname(mcpOutput), { recursive: true });
|
||||
run(["build", "src/server.ts", "--minify", "--target=node", "--outfile", mcpOutput]);
|
||||
// The shared CLI uses bun:sqlite; the plugin manifest must use this runtime too.
|
||||
run(["build", "src/server.ts", "--minify", "--target=bun", "--outfile", mcpOutput]);
|
||||
writeFileSync(mcpOutput, readFileSync(mcpOutput, "utf8").replace(/[ \t]+$/gm, ""));
|
||||
console.log(`✓ Successfully bundled MCP server: ${mcpOutput}`);
|
||||
+113
-85
@@ -1,93 +1,121 @@
|
||||
#!/usr/bin/env bun
|
||||
import { readFileSync, writeFileSync, existsSync, cpSync, readdirSync } from "node:fs";
|
||||
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { execSync } from "node:child_process";
|
||||
import { execFileSync } from "node:child_process";
|
||||
|
||||
const ROOT = join(import.meta.dirname, "..");
|
||||
const pkgPath = join(ROOT, "package.json");
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
||||
const currentVersion: string = pkg.version;
|
||||
export function bumpVersion(ROOT: string, input: string, rebuild = () => {
|
||||
execFileSync(process.execPath, ["run", "openapi:all"], { cwd: ROOT, stdio: "inherit" });
|
||||
execFileSync(process.execPath, ["run", "build:plugin"], { cwd: ROOT, stdio: "inherit" });
|
||||
execFileSync(process.execPath, ["run", "check:version"], { cwd: ROOT, stdio: "inherit" });
|
||||
}): string {
|
||||
const pkgPath = join(ROOT, "package.json");
|
||||
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
||||
const currentVersion: string = pkg.version;
|
||||
|
||||
const input = process.argv[2]?.trim();
|
||||
if (!input) {
|
||||
console.error("Usage: bun run bump <version | patch | minor | major>");
|
||||
console.error(`Current version: ${currentVersion}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let nextVersion = input.replace(/^v/, "");
|
||||
if (input === "patch" || input === "minor" || input === "major") {
|
||||
const [major, minor, patch] = currentVersion.split(".").map(Number);
|
||||
if (input === "patch") nextVersion = `${major}.${minor}.${patch + 1}`;
|
||||
if (input === "minor") nextVersion = `${major}.${minor + 1}.0`;
|
||||
if (input === "major") nextVersion = `${major + 1}.0.0`;
|
||||
}
|
||||
|
||||
if (!/^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$/.test(nextVersion)) {
|
||||
console.error(`Invalid SemVer format: '${nextVersion}'`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`==> Bumping version: ${currentVersion} -> ${nextVersion}`);
|
||||
|
||||
// 1. package.json
|
||||
pkg.version = nextVersion;
|
||||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
||||
console.log("✓ Updated package.json");
|
||||
|
||||
// 2. README.md
|
||||
const readmePath = join(ROOT, "README.md");
|
||||
let readmeContent = readFileSync(readmePath, "utf-8");
|
||||
readmeContent = readmeContent.replace(/# hose-use \(v[\d.]+\)/g, `# hose-use (v${nextVersion})`);
|
||||
writeFileSync(readmePath, readmeContent);
|
||||
console.log("✓ Updated README.md");
|
||||
|
||||
// 3. skills/hose-use/SKILL.md
|
||||
const skillPath = join(ROOT, "skills", "hose-use", "SKILL.md");
|
||||
let skillContent = readFileSync(skillPath, "utf-8");
|
||||
skillContent = skillContent.replace(/# hose-use \(v[\d.]+\)/g, `# hose-use (v${nextVersion})`);
|
||||
skillContent = skillContent.replace(/v[\d.]+: 合思/g, `v${nextVersion}: 合思`);
|
||||
skillContent = skillContent.replace(/version: [\d.]+/g, `version: ${nextVersion}`);
|
||||
skillContent = skillContent.replace(/\(v[\d.]+\)/g, `(v${nextVersion})`);
|
||||
writeFileSync(skillPath, skillContent);
|
||||
console.log("✓ Updated skills/hose-use/SKILL.md");
|
||||
|
||||
// 4. specs/openapi/openapi.yaml
|
||||
const openapiPath = join(ROOT, "specs", "openapi", "openapi.yaml");
|
||||
if (existsSync(openapiPath)) {
|
||||
let openapiContent = readFileSync(openapiPath, "utf-8");
|
||||
openapiContent = openapiContent.replace(/version: [\d.]+/g, `version: ${nextVersion}`);
|
||||
writeFileSync(openapiPath, openapiContent);
|
||||
console.log("✓ Updated specs/openapi/openapi.yaml");
|
||||
}
|
||||
|
||||
// 4.5 .zcode-plugin/plugin.json
|
||||
const pluginJsonPath = join(ROOT, ".zcode-plugin", "plugin.json");
|
||||
if (existsSync(pluginJsonPath)) {
|
||||
const pluginJson = JSON.parse(readFileSync(pluginJsonPath, "utf-8"));
|
||||
pluginJson.version = nextVersion;
|
||||
writeFileSync(pluginJsonPath, JSON.stringify(pluginJson, null, 2) + "\n");
|
||||
console.log("✓ Updated .zcode-plugin/plugin.json");
|
||||
}
|
||||
|
||||
// 5. Sync to global ~/.agents/skills/hose-use/ if present
|
||||
const globalSkillDir = join(process.env.HOME || "", ".agents", "skills", "hose-use");
|
||||
if (existsSync(globalSkillDir)) {
|
||||
const srcDir = join(ROOT, "skills", "hose-use");
|
||||
for (const item of readdirSync(srcDir)) {
|
||||
cpSync(join(srcDir, item), join(globalSkillDir, item), { recursive: true, force: true });
|
||||
if (!input) {
|
||||
console.error("Usage: bun run bump <version | patch | minor | major>");
|
||||
console.error(`Current version: ${currentVersion}`);
|
||||
throw new Error("A release version is required");
|
||||
}
|
||||
console.log("✓ Synchronized ~/.agents/skills/hose-use/");
|
||||
|
||||
let nextVersion = input.replace(/^v/, "");
|
||||
if (input === "patch" || input === "minor" || input === "major") {
|
||||
const [major, minor, patch] = currentVersion.split("-")[0].split(".").map(Number);
|
||||
if (input === "patch") nextVersion = `${major}.${minor}.${patch + 1}`;
|
||||
if (input === "minor") nextVersion = `${major}.${minor + 1}.0`;
|
||||
if (input === "major") nextVersion = `${major + 1}.0.0`;
|
||||
}
|
||||
|
||||
if (!isReleaseVersion(nextVersion)) throw new Error(`Invalid SemVer format: '${nextVersion}'`);
|
||||
if (Bun.semver.order(nextVersion, currentVersion) <= 0) throw new Error(`Version must increase: ${currentVersion} -> ${nextVersion}`);
|
||||
const git = (args: string[]) => execFileSync("git", args, { cwd: ROOT, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
||||
if (git(["status", "--porcelain"])) throw new Error("Release preparation requires a clean working tree");
|
||||
const branch = git(["branch", "--show-current"]);
|
||||
if (!["codex/release-v", "release/v"].some(prefix => branch === `${prefix}${nextVersion}`)) {
|
||||
throw new Error(`Prepare the release on codex/release-v${nextVersion} or release/v${nextVersion}; current branch: ${branch || "detached HEAD"}`);
|
||||
}
|
||||
if (git(["tag", "--list", `v${nextVersion}`])) throw new Error(`Tag v${nextVersion} already exists`);
|
||||
// Read all versioned sources before writing any of them.
|
||||
for (const file of ["README.md", "skills/hose-use/SKILL.md"]) readFileSync(join(ROOT, file), "utf8");
|
||||
for (const file of ["specs/openapi/openapi.yaml", ".zcode-plugin/plugin.json"]) {
|
||||
if (existsSync(join(ROOT, file))) {
|
||||
const content = readFileSync(join(ROOT, file), "utf8");
|
||||
if (file.endsWith(".json")) JSON.parse(content);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`==> Bumping version: ${currentVersion} -> ${nextVersion}`);
|
||||
|
||||
// 1. package.json
|
||||
pkg.version = nextVersion;
|
||||
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
||||
console.log("✓ Updated package.json");
|
||||
|
||||
// 2. README.md
|
||||
const readmePath = join(ROOT, "README.md");
|
||||
let readmeContent = readFileSync(readmePath, "utf-8");
|
||||
readmeContent = readmeContent.replace(/# hose-use \(v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?\)/g, `# hose-use (v${nextVersion})`);
|
||||
writeFileSync(readmePath, readmeContent);
|
||||
console.log("✓ Updated README.md");
|
||||
|
||||
// 3. skills/hose-use/SKILL.md
|
||||
const skillPath = join(ROOT, "skills", "hose-use", "SKILL.md");
|
||||
let skillContent = readFileSync(skillPath, "utf-8");
|
||||
skillContent = skillContent.replace(/# hose-use \(v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?\)/g, `# hose-use (v${nextVersion})`);
|
||||
skillContent = skillContent.replace(/v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?: 合思/g, `v${nextVersion}: 合思`);
|
||||
skillContent = skillContent.replace(/version: \d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?/g, `version: ${nextVersion}`);
|
||||
skillContent = skillContent.replace(/\(v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?\)/g, `(v${nextVersion})`);
|
||||
writeFileSync(skillPath, skillContent);
|
||||
console.log("✓ Updated skills/hose-use/SKILL.md");
|
||||
|
||||
// 4. specs/openapi/openapi.yaml
|
||||
const openapiPath = join(ROOT, "specs", "openapi", "openapi.yaml");
|
||||
if (existsSync(openapiPath)) {
|
||||
let openapiContent = readFileSync(openapiPath, "utf-8");
|
||||
openapiContent = openapiContent.replace(/version: \d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?/g, `version: ${nextVersion}`);
|
||||
writeFileSync(openapiPath, openapiContent);
|
||||
console.log("✓ Updated specs/openapi/openapi.yaml");
|
||||
}
|
||||
|
||||
// 4.5 .zcode-plugin/plugin.json
|
||||
const pluginJsonPath = join(ROOT, ".zcode-plugin", "plugin.json");
|
||||
if (existsSync(pluginJsonPath)) {
|
||||
const pluginJson = JSON.parse(readFileSync(pluginJsonPath, "utf-8"));
|
||||
pluginJson.version = nextVersion;
|
||||
writeFileSync(pluginJsonPath, JSON.stringify(pluginJson, null, 2) + "\n");
|
||||
console.log("✓ Updated .zcode-plugin/plugin.json");
|
||||
}
|
||||
|
||||
// 5. Sync to global ~/.agents/skills/hose-use/ is now an explicit dev:override step.
|
||||
// A version bump must not overwrite personal Skill files in the user's environment.
|
||||
|
||||
// 7. Rebuild OpenAPI and plugin bundles so generated artifacts stay in lockstep.
|
||||
console.log("==> Rebuilding OpenAPI and plugin bundles...");
|
||||
rebuild();
|
||||
|
||||
console.log("\n🎉 Successfully bumped version to " + nextVersion + "!");
|
||||
console.log("\nNext steps to publish:");
|
||||
console.log(` 1. Review the diff, then run bun test && bun run check && bun run check:version`);
|
||||
console.log(` 2. Commit on ${branch}, push that branch and open a PR to main`);
|
||||
console.log(` 3. Wait for CI and review, then merge the PR`);
|
||||
console.log(` 4. Switch to main; git pull --ff-only origin main; git push home main`);
|
||||
console.log(` 5. Create annotated tag v${nextVersion} on the merged release commit`);
|
||||
console.log(` 6. git push home refs/tags/v${nextVersion} (first), then git push origin refs/tags/v${nextVersion}`);
|
||||
console.log(` 7. Verify the Release build, binary archives and checksums on both sources`);
|
||||
console.log(` Optional: bun run dev:override to explicitly sync your global development binary and Skill`);
|
||||
return nextVersion;
|
||||
}
|
||||
|
||||
// 7. Rebuild OpenAPI and plugin bundles so generated artifacts stay in lockstep.
|
||||
console.log("==> Rebuilding OpenAPI and plugin bundles...");
|
||||
execSync("bun run openapi:all", { cwd: ROOT, stdio: "inherit" });
|
||||
execSync("bun run build:plugin", { cwd: ROOT, stdio: "inherit" });
|
||||
export function isReleaseVersion(value: string): boolean {
|
||||
const match = value.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*))?$/);
|
||||
return !!match && (!match[4] || match[4].split(".").every(part => !/^0\d+$/.test(part)));
|
||||
}
|
||||
|
||||
console.log("\n🎉 Successfully bumped version to " + nextVersion + "!");
|
||||
console.log("\nNext steps to publish:");
|
||||
console.log(` 1. Update CHANGELOG.md (if exists)`);
|
||||
console.log(` 2. git commit -am "chore(release): bump version to v${nextVersion}"`);
|
||||
console.log(` 3. git tag -a v${nextVersion} -m "🚀 Release v${nextVersion}"`);
|
||||
console.log(` 4. git push origin <feature-branch>\n`);
|
||||
if (import.meta.main) {
|
||||
try {
|
||||
bumpVersion(join(import.meta.dirname, ".."), process.argv[2]?.trim() || "");
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
+119
-78
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -euo pipefail
|
||||
|
||||
REPO="yunyingk/hose-use"
|
||||
|
||||
@@ -34,9 +34,10 @@ case "$ARCH" in
|
||||
esac
|
||||
|
||||
# Resolve best writable bin directory without requiring sudo
|
||||
TARGET_DIR=""
|
||||
TARGET_DIR="${HOSE_USE_INSTALL_DIR:-}"
|
||||
if [ -n "$TARGET_DIR" ]; then mkdir -p "$TARGET_DIR"; fi
|
||||
for candidate in "/opt/homebrew/bin" "/usr/local/bin" "$HOME/.local/bin" "$HOME/bin"; do
|
||||
if [ -d "$candidate" ] && [ -w "$candidate" ]; then
|
||||
if [ -z "$TARGET_DIR" ] && [ -d "$candidate" ] && [ -w "$candidate" ]; then
|
||||
TARGET_DIR="$candidate"
|
||||
break
|
||||
fi
|
||||
@@ -49,6 +50,10 @@ fi
|
||||
|
||||
ASSET_NAME="hose-use-${PLATFORM}-${ARCH_NAME}"
|
||||
TARGET_PATH="${TARGET_DIR}/hose-use"
|
||||
if [ -d "$TARGET_PATH" ] || { [ -d "${TARGET_DIR}/hose-aipro" ] && [ ! -L "${TARGET_DIR}/hose-aipro" ]; }; then
|
||||
echo "Error: an install target is a directory; refusing to replace it." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
get_file_size() {
|
||||
local file="$1"
|
||||
@@ -102,7 +107,7 @@ download_candidate() {
|
||||
if curl -fL --progress-bar "$url" -o "$dest"; then
|
||||
local size_bytes
|
||||
size_bytes="$(get_file_size "$dest")"
|
||||
if [ "$size_bytes" -gt 1000000 ]; then
|
||||
if [ "$size_bytes" -gt 0 ]; then
|
||||
echo "✓ Download complete! Total size: $(format_bytes "$size_bytes")"
|
||||
echo "✓ Successfully fetched from host: ${host}"
|
||||
return 0
|
||||
@@ -114,103 +119,139 @@ download_candidate() {
|
||||
}
|
||||
|
||||
echo "==> Target install location: ${TARGET_PATH}"
|
||||
TMP_FILE="$(mktemp)"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
TMP_FILE="${TMP_DIR}/download"
|
||||
CHECKSUM_FILE="${TMP_DIR}/checksums.txt"
|
||||
INSTALL_STAGE=""
|
||||
trap 'rm -rf "$TMP_DIR"; if [ -n "$INSTALL_STAGE" ]; then rm -f "$INSTALL_STAGE"; fi' EXIT
|
||||
DOWNLOAD_SUCCESS=false
|
||||
DOWNLOADED_FORMAT="archive"
|
||||
|
||||
# Resolve latest Gitea tag if available
|
||||
GITEA_API_URL="https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/latest"
|
||||
LATEST_TAG=""
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
LATEST_TAG="$(curl -sL --connect-timeout 3 "$GITEA_API_URL" | sed -n 's/.*"tag_name":"\([^"]*\)".*/\1/p' || true)"
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
echo "Error: curl is required." >&2
|
||||
exit 1
|
||||
fi
|
||||
[ -z "$LATEST_TAG" ] && LATEST_TAG="v0.8.9"
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
hash_file() { sha256sum "$1" | awk '{ print tolower($1) }'; }
|
||||
elif command -v shasum >/dev/null 2>&1; then
|
||||
hash_file() { shasum -a 256 "$1" | awk '{ print tolower($1) }'; }
|
||||
else
|
||||
echo "Error: SHA-256 verification requires sha256sum or shasum." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MIRROR="${HOSE_USE_MIRROR:-auto}"
|
||||
case "$MIRROR" in auto|github|gitea) ;; *) echo "Invalid HOSE_USE_MIRROR: $MIRROR" >&2; exit 1 ;; esac
|
||||
|
||||
# Resolve latest Gitea tag if available. Resolve once, then pin every mirror and
|
||||
# checksum request to that exact version instead of guessing an old release.
|
||||
GITEA_API_URL="https://git.ying-qing.cn/api/v1/repos/gitea/hose-use/releases/latest"
|
||||
GITHUB_API_URL="https://api.github.com/repos/${REPO}/releases/latest"
|
||||
LATEST_TAG="${HOSE_USE_VERSION:-}"
|
||||
if [ -n "$LATEST_TAG" ]; then
|
||||
LATEST_TAG="v${LATEST_TAG#v}"
|
||||
else
|
||||
api_urls=()
|
||||
if [ "$MIRROR" != "github" ]; then api_urls+=("$GITEA_API_URL"); fi
|
||||
if [ "$MIRROR" != "gitea" ]; then api_urls+=("$GITHUB_API_URL"); fi
|
||||
for api_url in "${api_urls[@]}"; do
|
||||
if release_json=$(curl -fsSL --connect-timeout 4 --max-time 15 "$api_url"); then
|
||||
LATEST_TAG=$(printf '%s' "$release_json" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^" ]*\)".*/\1/p' | head -n 1)
|
||||
if [ -n "$LATEST_TAG" ]; then break; fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if ! [[ "$LATEST_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then
|
||||
echo "Error: could not resolve a release version; set HOSE_USE_VERSION explicitly." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
release_bases=()
|
||||
if [ "$MIRROR" != "github" ]; then release_bases+=("https://git.ying-qing.cn/gitea/hose-use/releases/download/${LATEST_TAG}"); fi
|
||||
if [ "$MIRROR" != "gitea" ]; then
|
||||
release_bases+=("https://github.com/${REPO}/releases/download/${LATEST_TAG}")
|
||||
release_bases+=("https://ghfast.top/https://github.com/${REPO}/releases/download/${LATEST_TAG}")
|
||||
fi
|
||||
|
||||
verified_download() {
|
||||
local base="$1" asset="$2" expected actual
|
||||
if ! download_candidate "${base}/checksums.txt" "$CHECKSUM_FILE" "Release checksums"; then
|
||||
echo " ↳ Missing checksums.txt for ${LATEST_TAG}; refusing an unverified install." >&2
|
||||
return 1
|
||||
fi
|
||||
expected=$(awk -v name="$asset" '{ sub(/\r$/, "") } $2 == name || $2 == "*" name { count++; if (length($1) == 64 && $1 ~ /^[0-9a-fA-F]+$/) value=tolower($1); else invalid=1 } END { if (count == 1 && !invalid) print value; else exit 1 }' "$CHECKSUM_FILE") || {
|
||||
echo " ↳ Missing or ambiguous checksum for ${asset}." >&2
|
||||
return 1
|
||||
}
|
||||
if ! download_candidate "${base}/${asset}" "$TMP_FILE" "Release ${LATEST_TAG}"; then return 1; fi
|
||||
actual=$(hash_file "$TMP_FILE")
|
||||
if [ "$actual" != "$expected" ]; then
|
||||
echo " ↳ SHA-256 mismatch for ${asset}; refusing this download." >&2
|
||||
return 1
|
||||
fi
|
||||
echo "✓ SHA-256 verified: ${asset}"
|
||||
}
|
||||
|
||||
# 1. First priority: Compressed Archives (.tar.gz) - fast download & includes aliases
|
||||
GITEA_ARCHIVE_URL="https://git.ying-qing.cn/gitea/hose-use/releases/download/${LATEST_TAG}/${ASSET_NAME}.tar.gz"
|
||||
GITHUB_ARCHIVE_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}.tar.gz"
|
||||
GHPROXY_ARCHIVE_URL="https://ghfast.top/https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}.tar.gz"
|
||||
|
||||
if [ "${HOSE_USE_MIRROR:-auto}" = "gitea" ] || [ "${HOSE_USE_MIRROR:-auto}" = "auto" ]; then
|
||||
if download_candidate "$GITEA_ARCHIVE_URL" "$TMP_FILE" "Gitea High-Speed Mirror (Archive)"; then
|
||||
DOWNLOAD_SUCCESS=true
|
||||
DOWNLOADED_FORMAT="archive"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$DOWNLOAD_SUCCESS" = "false" ] && [ "${HOSE_USE_MIRROR:-auto}" != "gitea" ]; then
|
||||
if download_candidate "$GITHUB_ARCHIVE_URL" "$TMP_FILE" "GitHub Releases (Archive Direct)"; then
|
||||
DOWNLOAD_SUCCESS=true
|
||||
DOWNLOADED_FORMAT="archive"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$DOWNLOAD_SUCCESS" = "false" ] && [ "${HOSE_USE_MIRROR:-auto}" != "gitea" ]; then
|
||||
if download_candidate "$GHPROXY_ARCHIVE_URL" "$TMP_FILE" "Fast CDN Mirror (Archive Fallback)"; then
|
||||
DOWNLOAD_SUCCESS=true
|
||||
DOWNLOADED_FORMAT="archive"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2. Second priority: Raw Executable (Fallback)
|
||||
if [ "$DOWNLOAD_SUCCESS" = "false" ]; then
|
||||
GITEA_RAW_URL="https://git.ying-qing.cn/gitea/hose-use/releases/download/${LATEST_TAG}/${ASSET_NAME}"
|
||||
GITHUB_RAW_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
|
||||
GHPROXY_RAW_URL="https://ghfast.top/https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
|
||||
|
||||
if [ "${HOSE_USE_MIRROR:-auto}" = "gitea" ] || [ "${HOSE_USE_MIRROR:-auto}" = "auto" ]; then
|
||||
if download_candidate "$GITEA_RAW_URL" "$TMP_FILE" "Gitea High-Speed Mirror (Raw Binary)"; then
|
||||
# 2. Second priority: Raw Executable (Fallback), with the same checksum requirement.
|
||||
for format in archive raw; do
|
||||
asset="$ASSET_NAME"
|
||||
if [ "$format" = "archive" ]; then asset="${asset}.tar.gz"; fi
|
||||
for base in "${release_bases[@]}"; do
|
||||
if verified_download "$base" "$asset"; then
|
||||
DOWNLOAD_SUCCESS=true
|
||||
DOWNLOADED_FORMAT="raw"
|
||||
DOWNLOADED_FORMAT="$format"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$DOWNLOAD_SUCCESS" = "false" ] && [ "${HOSE_USE_MIRROR:-auto}" != "gitea" ]; then
|
||||
if download_candidate "$GITHUB_RAW_URL" "$TMP_FILE" "GitHub Releases (Raw Direct)"; then
|
||||
DOWNLOAD_SUCCESS=true
|
||||
DOWNLOADED_FORMAT="raw"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$DOWNLOAD_SUCCESS" = "false" ] && [ "${HOSE_USE_MIRROR:-auto}" != "gitea" ]; then
|
||||
if download_candidate "$GHPROXY_RAW_URL" "$TMP_FILE" "Fast CDN Mirror (Raw Fallback)"; then
|
||||
DOWNLOAD_SUCCESS=true
|
||||
DOWNLOADED_FORMAT="raw"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [ "$DOWNLOAD_SUCCESS" = "true" ]; then break; fi
|
||||
done
|
||||
|
||||
if [ "$DOWNLOAD_SUCCESS" = "false" ]; then
|
||||
echo "Error: Failed to download ${ASSET_NAME} from all candidate mirrors." >&2
|
||||
rm -f "$TMP_FILE"
|
||||
echo "Error: Failed to obtain a verified ${ASSET_NAME} for ${LATEST_TAG} from all candidate mirrors." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$DOWNLOADED_FORMAT" = "archive" ]; then
|
||||
echo "==> Extracting archive to ${TARGET_DIR}..."
|
||||
tar -xzf "$TMP_FILE" -C "$TARGET_DIR"
|
||||
rm -f "$TMP_FILE"
|
||||
chmod +x "$TARGET_PATH"
|
||||
[ -f "${TARGET_DIR}/hose-aipro" ] && chmod +x "${TARGET_DIR}/hose-aipro"
|
||||
echo "==> Extracting selected binary in temporary staging..."
|
||||
member=""
|
||||
listing=$(tar -tzf "$TMP_FILE")
|
||||
for candidate in "$ASSET_NAME" "./$ASSET_NAME" hose-use ./hose-use; do
|
||||
if printf '%s\n' "$listing" | awk -v name="$candidate" '$0 == name { count++ } END { exit count != 1 }'; then
|
||||
member="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$member" ]; then echo "Error: release archive has no expected platform binary." >&2; exit 1; fi
|
||||
# Stream only the exact member; archive paths and aliases never get written to bin.
|
||||
tar -xOzf "$TMP_FILE" "$member" > "${TMP_DIR}/hose-use"
|
||||
if [ ! -s "${TMP_DIR}/hose-use" ]; then echo "Error: release binary is empty." >&2; exit 1; fi
|
||||
else
|
||||
chmod +x "$TMP_FILE"
|
||||
mv "$TMP_FILE" "$TARGET_PATH"
|
||||
# Create hose-aipro multicall alias pointing at the single binary.
|
||||
if [ -w "$TARGET_DIR" ]; then
|
||||
ln -sf "$TARGET_PATH" "${TARGET_DIR}/hose-aipro" 2>/dev/null || true
|
||||
fi
|
||||
mv "$TMP_FILE" "${TMP_DIR}/hose-use"
|
||||
fi
|
||||
|
||||
# Stage on the target filesystem so the final rename is atomic.
|
||||
INSTALL_STAGE=$(mktemp "${TARGET_DIR}/.hose-use-install.XXXXXX")
|
||||
cp "${TMP_DIR}/hose-use" "$INSTALL_STAGE"
|
||||
chmod 755 "$INSTALL_STAGE"
|
||||
# Ad-hoc sign on macOS
|
||||
if [ "$PLATFORM" = "darwin" ] && command -v codesign >/dev/null 2>&1; then
|
||||
echo "==> Applying macOS code signature..."
|
||||
codesign --force --sign - "$TARGET_PATH" 2>/dev/null || true
|
||||
[ -f "${TARGET_DIR}/hose-aipro" ] && codesign --force --sign - "${TARGET_DIR}/hose-aipro" 2>/dev/null || true
|
||||
codesign --force --sign - "$INSTALL_STAGE" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
mv -f "$INSTALL_STAGE" "$TARGET_PATH"
|
||||
INSTALL_STAGE=""
|
||||
# Create hose-aipro multicall alias pointing at the single binary.
|
||||
ln -sfn hose-use "${TARGET_DIR}/hose-aipro"
|
||||
|
||||
echo "==> Initializing agent skill to ~/.agents/skills/hose-use..."
|
||||
"$TARGET_PATH" skill install >/dev/null 2>&1 || true
|
||||
echo "✓ Agent skill installed to ~/.agents/skills/hose-use"
|
||||
if "$TARGET_PATH" skill install --yes; then
|
||||
echo "✓ Agent skill installed to ~/.agents/skills/hose-use"
|
||||
else
|
||||
echo "Error: binary installed to ${TARGET_PATH}, but Agent Skill installation failed. Retry: hose-use skill install --yes" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "✨ hose-use successfully installed to ${TARGET_PATH}!"
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
import { createHash } from "node:crypto";
|
||||
import { existsSync, mkdtempSync, mkdirSync, readFileSync, readlinkSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
|
||||
const fixtures: string[] = [];
|
||||
afterEach(() => { for (const root of fixtures.splice(0)) rmSync(root, { recursive: true, force: true }); });
|
||||
const hash = (data: Buffer | string) => createHash("sha256").update(data).digest("hex");
|
||||
|
||||
function fixture(options: { badHash?: boolean; missingEntry?: boolean; duplicate?: boolean; rawOnly?: boolean } = {}) {
|
||||
const root = mkdtempSync(join(tmpdir(), "hose-installer-test-"));
|
||||
fixtures.push(root);
|
||||
const tools = join(root, "tools"), source = join(root, "release"), target = join(root, "bin");
|
||||
for (const dir of [tools, source, target]) mkdirSync(dir);
|
||||
const binary = `#!/bin/sh
|
||||
if [ "$1" = "skill" ]; then
|
||||
printf '%s\\n' "$*" > "$HOSE_FIXTURE_LOG"
|
||||
[ "$2" = "install" ] && [ "$3" = "--yes" ] || exit 10
|
||||
[ "\${HOSE_FIXTURE_SKILL_FAIL:-0}" != "1" ] || exit 3
|
||||
else
|
||||
printf 'hose-use v9.9.9\\n'
|
||||
fi
|
||||
`;
|
||||
const asset = "hose-use-linux-x64";
|
||||
writeFileSync(join(source, asset), binary, { mode: 0o755 });
|
||||
symlinkSync(asset, join(source, "hose-aipro"));
|
||||
writeFileSync(join(source, "unrelated.txt"), "must not reach the install directory");
|
||||
const archive = `${asset}.tar.gz`;
|
||||
expect(spawnSync("tar", ["-czf", join(source, archive), "-C", source, asset, "hose-aipro", "unrelated.txt"]).status).toBe(0);
|
||||
const entry = `${options.badHash ? "0".repeat(64) : hash(readFileSync(join(source, archive)))} ${archive}\n`;
|
||||
writeFileSync(join(source, "checksums.txt"), (options.missingEntry ? "" : entry + (options.duplicate ? entry : "")) + `${options.badHash ? "0".repeat(64) : hash(binary)} ${asset}\n`);
|
||||
if (options.rawOnly) rmSync(join(source, archive));
|
||||
const curl = `#!/bin/bash
|
||||
set -eu
|
||||
url=""; dest=""; head_only=false
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o) dest="$2"; shift 2 ;;
|
||||
--connect-timeout|--max-time) shift 2 ;;
|
||||
-fIs) head_only=true; shift ;;
|
||||
https://*) url="$1"; shift ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\\n' "$url" >> "$HOSE_FIXTURE_REQUESTS"
|
||||
if [ "\${HOSE_FIXTURE_GITEA_FAIL:-0}" = "1" ] && [[ "$url" == *git.ying-qing.cn* ]]; then exit 22; fi
|
||||
if [[ "$url" == */releases/latest ]]; then
|
||||
[ "\${HOSE_FIXTURE_NO_TAG:-0}" != "1" ] || exit 22
|
||||
printf '{"tag_name": "v9.9.9"}'
|
||||
exit 0
|
||||
fi
|
||||
name="\${url##*/}"
|
||||
if [ "$name" = "checksums.txt" ] && [ "\${HOSE_FIXTURE_NO_MANIFEST:-0}" = "1" ]; then exit 22; fi
|
||||
file="$HOSE_FIXTURE_SOURCE/$name"
|
||||
[ -f "$file" ] || exit 22
|
||||
if [ "$head_only" = "true" ]; then exit 0; fi
|
||||
if [ -n "$dest" ]; then cp "$file" "$dest"; else cat "$file"; fi
|
||||
`;
|
||||
writeFileSync(join(tools, "curl"), curl, { mode: 0o755 });
|
||||
writeFileSync(join(tools, "uname"), '#!/bin/sh\nif [ "$1" = "-s" ]; then echo Linux; else echo x86_64; fi\n', { mode: 0o755 });
|
||||
const run = (env: Record<string, string> = {}) => spawnSync("bash", [resolve(import.meta.dir, "install.sh")], {
|
||||
cwd: root,
|
||||
env: { ...process.env, PATH: `${tools}:${process.env.PATH}`, HOSE_USE_INSTALL_DIR: target, HOSE_USE_VERSION: "9.9.9", HOSE_USE_MIRROR: "auto", HOSE_FIXTURE_SOURCE: source, HOSE_FIXTURE_LOG: join(root, "skill.log"), HOSE_FIXTURE_REQUESTS: join(root, "requests.log"), ...env },
|
||||
encoding: "utf8", timeout: 10_000,
|
||||
});
|
||||
return { root, source, target, run, binary };
|
||||
}
|
||||
|
||||
describe("verified standalone installer", () => {
|
||||
test("installs a platform-named archive and alias, then explicitly confirms Skill setup", () => {
|
||||
const f = fixture();
|
||||
const result = f.run();
|
||||
expect(result.status).toBe(0);
|
||||
expect(readFileSync(join(f.target, "hose-use"), "utf8")).toBe(f.binary);
|
||||
expect(readlinkSync(join(f.target, "hose-aipro"))).toBe("hose-use");
|
||||
expect(readFileSync(join(f.root, "skill.log"), "utf8").trim()).toBe("skill install --yes");
|
||||
expect(readdirSync(f.target).sort()).toEqual(["hose-aipro", "hose-use"]);
|
||||
});
|
||||
|
||||
for (const options of [{ badHash: true }, { missingEntry: true }, { duplicate: true }]) {
|
||||
test(`rejects an invalid manifest/archive and preserves the old binary: ${JSON.stringify(options)}`, () => {
|
||||
const f = fixture(options);
|
||||
// Remove raw fallback, so a missing archive entry cannot be hidden by another valid asset.
|
||||
rmSync(join(f.source, "hose-use-linux-x64"));
|
||||
writeFileSync(join(f.target, "hose-use"), "old binary");
|
||||
const result = f.run();
|
||||
expect(result.status).toBe(1);
|
||||
expect(readFileSync(join(f.target, "hose-use"), "utf8")).toBe("old binary");
|
||||
expect(existsSync(join(f.root, "skill.log"))).toBe(false);
|
||||
});
|
||||
}
|
||||
|
||||
test("does not silently bypass missing checksums or guess an old tag", () => {
|
||||
const f = fixture();
|
||||
expect(f.run({ HOSE_FIXTURE_NO_MANIFEST: "1" }).status).toBe(1);
|
||||
const unknown = f.run({ HOSE_USE_VERSION: "", HOSE_FIXTURE_NO_TAG: "1" });
|
||||
expect(unknown.status).toBe(1);
|
||||
expect(unknown.stderr).toContain("could not resolve");
|
||||
expect(existsSync(join(f.target, "hose-use"))).toBe(false);
|
||||
expect(readFileSync(join(f.root, "requests.log"), "utf8")).not.toContain("v0.8.9");
|
||||
});
|
||||
|
||||
test("uses a verified raw fallback and a fixed tag when the first mirror fails", () => {
|
||||
const f = fixture({ rawOnly: true });
|
||||
const result = f.run({ HOSE_FIXTURE_GITEA_FAIL: "1", HOSE_USE_VERSION: "" });
|
||||
expect(result.status).toBe(0);
|
||||
expect(readFileSync(join(f.target, "hose-use"), "utf8")).toBe(f.binary);
|
||||
const requests = readFileSync(join(f.root, "requests.log"), "utf8");
|
||||
expect(requests).toContain("/download/v9.9.9/");
|
||||
expect(requests).not.toContain("/latest/download/");
|
||||
});
|
||||
|
||||
test("reports Skill failure without claiming it was installed", () => {
|
||||
const f = fixture();
|
||||
const result = f.run({ HOSE_FIXTURE_SKILL_FAIL: "1" });
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stderr).toContain("binary installed");
|
||||
expect(result.stdout).not.toContain("Agent skill installed");
|
||||
expect(result.stdout).not.toContain("successfully installed");
|
||||
});
|
||||
|
||||
test("does not replace directories or follow an existing alias into a directory", () => {
|
||||
const f = fixture();
|
||||
mkdirSync(join(f.root, "personal"));
|
||||
symlinkSync(join(f.root, "personal"), join(f.target, "hose-aipro"));
|
||||
expect(f.run().status).toBe(0);
|
||||
expect(readdirSync(join(f.root, "personal"))).toEqual([]);
|
||||
expect(readlinkSync(join(f.target, "hose-aipro"))).toBe("hose-use");
|
||||
rmSync(join(f.target, "hose-aipro"));
|
||||
mkdirSync(join(f.target, "hose-aipro"));
|
||||
writeFileSync(join(f.target, "hose-use"), "old binary");
|
||||
expect(f.run().status).toBe(1);
|
||||
expect(readFileSync(join(f.target, "hose-use"), "utf8")).toBe("old binary");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,120 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { parse } from "yaml";
|
||||
import { bumpVersion } from "./bump-version.js";
|
||||
import { verifyReleaseTag } from "./verify-release.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); });
|
||||
|
||||
function repository() {
|
||||
const root = mkdtempSync(join(tmpdir(), "hose-release-test-"));
|
||||
roots.push(root);
|
||||
const git = (...args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
||||
git("init", "--initial-branch=main");
|
||||
git("config", "user.name", "Release fixture");
|
||||
git("config", "user.email", "fixture@example.test");
|
||||
git("config", "core.hooksPath", "/dev/null");
|
||||
git("config", "commit.gpgsign", "false");
|
||||
git("config", "tag.gpgsign", "false");
|
||||
for (const dir of ["skills/hose-use", "specs/openapi", ".zcode-plugin"]) mkdirSync(join(root, dir), { recursive: true });
|
||||
writeFileSync(join(root, "package.json"), '{"version":"1.0.0"}\n');
|
||||
writeFileSync(join(root, "README.md"), "# hose-use (v1.0.0)\n");
|
||||
writeFileSync(join(root, "skills/hose-use/SKILL.md"), "version: 1.0.0\n# hose-use (v1.0.0)\n");
|
||||
writeFileSync(join(root, "specs/openapi/openapi.yaml"), "info:\n version: 1.0.0\n");
|
||||
writeFileSync(join(root, ".zcode-plugin/plugin.json"), '{"version":"1.0.0"}\n');
|
||||
git("add", ".");
|
||||
git("commit", "-m", "fixture");
|
||||
git("update-ref", "refs/remotes/origin/main", "HEAD");
|
||||
return { root, git, version: () => JSON.parse(readFileSync(join(root, "package.json"), "utf8")).version };
|
||||
}
|
||||
|
||||
describe("release preparation and publication guards", () => {
|
||||
test("bump rejects wrong branches, dirty trees and invalid/non-increasing versions before writes", () => {
|
||||
const f = repository();
|
||||
expect(() => bumpVersion(f.root, "patch", () => {})).toThrow("release-v1.0.1");
|
||||
f.git("switch", "-c", "codex/release-v1.0.1");
|
||||
writeFileSync(join(f.root, "untracked.txt"), "work in progress");
|
||||
expect(() => bumpVersion(f.root, "patch", () => {})).toThrow("clean working tree");
|
||||
rmSync(join(f.root, "untracked.txt"));
|
||||
for (const version of ["1.0.0", "0.9.9", "1.0.01", "1.0.1-rc.01", "invalid"]) expect(() => bumpVersion(f.root, version, () => {})).toThrow();
|
||||
expect(f.version()).toBe("1.0.0");
|
||||
expect(f.git("status", "--porcelain")).toBe("");
|
||||
});
|
||||
|
||||
test("bump updates sources on its release branch and explicitly invokes regeneration", () => {
|
||||
const f = repository();
|
||||
f.git("switch", "-c", "release/v1.0.1");
|
||||
let rebuilt = false;
|
||||
expect(bumpVersion(f.root, "patch", () => { rebuilt = true; })).toBe("1.0.1");
|
||||
expect(rebuilt).toBe(true);
|
||||
expect(f.version()).toBe("1.0.1");
|
||||
expect(readFileSync(join(f.root, "skills/hose-use/SKILL.md"), "utf8")).toContain("version: 1.0.1");
|
||||
expect(parse(readFileSync(join(f.root, "specs/openapi/openapi.yaml"), "utf8")).info.version).toBe("1.0.1");
|
||||
});
|
||||
|
||||
test("an existing release tag cannot be reused during bump", () => {
|
||||
const f = repository();
|
||||
f.git("switch", "-c", "release/v1.0.1");
|
||||
f.git("tag", "v1.0.1");
|
||||
expect(() => bumpVersion(f.root, "patch", () => {})).toThrow("already exists");
|
||||
expect(f.version()).toBe("1.0.0");
|
||||
});
|
||||
|
||||
test("publication validates the actual HEAD, main ancestry and package version", () => {
|
||||
const f = repository();
|
||||
f.git("tag", "v1.0.0");
|
||||
expect(() => verifyReleaseTag(f.root, "v1.0.0")).not.toThrow();
|
||||
expect(() => verifyReleaseTag(f.root, "main")).toThrow("Invalid release tag");
|
||||
f.git("tag", "v9.9.9");
|
||||
expect(() => verifyReleaseTag(f.root, "v9.9.9")).toThrow("does not match");
|
||||
f.git("switch", "-c", "unmerged");
|
||||
writeFileSync(join(f.root, "change"), "unreviewed");
|
||||
f.git("add", "."); f.git("commit", "-m", "unmerged fixture");
|
||||
expect(() => verifyReleaseTag(f.root, "v1.0.0")).toThrow("exact tagged commit");
|
||||
f.git("tag", "v1.0.1");
|
||||
expect(() => verifyReleaseTag(f.root, "v1.0.1")).toThrow("ancestor");
|
||||
});
|
||||
|
||||
test("workflows validate committed versions before generation and ship the checksum manifest", () => {
|
||||
const root = join(import.meta.dir, "..");
|
||||
const ci = parse(readFileSync(join(root, ".github/workflows/ci.yml"), "utf8"));
|
||||
const release = parse(readFileSync(join(root, ".github/workflows/release.yml"), "utf8"));
|
||||
expect(ci.on.pull_request.branches).toContain("main");
|
||||
expect(ci.permissions.contents).toBe("read");
|
||||
const steps = release.jobs["build-and-publish"].steps;
|
||||
const runs = steps.map((s: { run?: string }) => s.run || "");
|
||||
expect(runs.findIndex((s: string) => s.includes("check:version"))).toBeLessThan(runs.findIndex((s: string) => s.includes("openapi:all")));
|
||||
expect(steps[0].with.ref).toContain("inputs.tag");
|
||||
expect(runs.some((s: string) => s.includes("verify-release.ts"))).toBe(true);
|
||||
expect(runs.some((s: string) => s.includes("sha256sum hose-use-* > checksums.txt"))).toBe(true);
|
||||
for (const step of [...ci.jobs.validate.steps, ...steps]) if (step.uses) expect(step.uses).toMatch(/@[a-f0-9]{40}$/);
|
||||
expect(JSON.parse(readFileSync(join(root, ".mcp.json"), "utf8")).mcpServers["hose-use"].command).toBe("bun");
|
||||
});
|
||||
|
||||
test("a failed background Gitea upload makes the Release step fail", () => {
|
||||
const f = repository();
|
||||
const workflow = parse(readFileSync(join(import.meta.dir, "../.github/workflows/release.yml"), "utf8"));
|
||||
const step = workflow.jobs["build-and-publish"].steps.find((s: { name?: string }) => s.name === "Publish Gitea Release");
|
||||
mkdirSync(join(f.root, "tools")); mkdirSync(join(f.root, "dist/bin"), { recursive: true });
|
||||
writeFileSync(join(f.root, "dist/bin/hose-use-linux-x64"), "fixture");
|
||||
writeFileSync(join(f.root, "dist/bin/checksums.txt"), "fixture checksums");
|
||||
writeFileSync(join(f.root, "tools/curl"), `#!/bin/sh
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
*/assets?*) exit 22 ;;
|
||||
*/releases) printf '{"id":42}'; exit 0 ;;
|
||||
*/releases/42) printf '{"assets":[]}'; exit 0 ;;
|
||||
esac
|
||||
done
|
||||
exit 22
|
||||
`, { mode: 0o755 });
|
||||
const result = spawnSync("bash", ["-eo", "pipefail", "-c", step.run], { cwd: f.root, env: { ...process.env, PATH: `${join(f.root, "tools")}:${process.env.PATH}`, GITEA_TOKEN: "fixture", GITEA_HOST: "https://example.test", GITEA_REPO: "test/repo", RELEASE_TAG: "v1.0.0" }, encoding: "utf8", timeout: 5000 });
|
||||
expect(result.status).toBe(1);
|
||||
expect(result.stdout).toContain("assets failed to upload");
|
||||
expect(result.stdout).not.toContain("Successfully published");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bun
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { resolve, join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
|
||||
const binary = resolve(process.argv[2] || "dist/bin/hose-use");
|
||||
const plugin = process.argv.includes("--plugin");
|
||||
const command = plugin ? process.execPath : binary;
|
||||
const prefix = plugin ? [binary] : [];
|
||||
const cwd = mkdtempSync(join(tmpdir(), "hose-binary-smoke-"));
|
||||
// The binary must work without Bun on PATH or a source checkout in cwd.
|
||||
const env = { PATH: process.platform === "win32" ? process.env.SystemRoot || "C:\\Windows" : "/usr/bin:/bin", HOSE_USE_MCP_ENABLED: "true", HOSE_CONFIG_FILE: join(cwd, "config.json"), HOSE_ENTERPRISES_DIR: cwd };
|
||||
const client = new Client({ name: "hose-binary-smoke", version: "1.0.0" });
|
||||
const transport = new StdioClientTransport({ command, args: plugin ? prefix : ["mcp", "serve"], cwd, env, stderr: "pipe" });
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", chunk => { stderr += chunk.toString(); });
|
||||
const deadline = setTimeout(() => { void client.close(); }, 15_000);
|
||||
try {
|
||||
const version = spawnSync(command, [...prefix, ...(plugin ? ["--hose-use-cli"] : []), "version", "--json"], { cwd, env, encoding: "utf8", timeout: 5000 });
|
||||
assert.equal(version.status, 0, version.stderr);
|
||||
assert.ok(JSON.parse(version.stdout).version);
|
||||
await client.connect(transport, { timeout: 5000 });
|
||||
const tools = await client.listTools();
|
||||
assert.deepEqual(tools.tools.map(tool => tool.name), ["hose_cli"]);
|
||||
const result = await client.callTool({ name: "hose_cli", arguments: { command: "version --json" } });
|
||||
assert.ok(!result.isError, JSON.stringify(result));
|
||||
const text = (result.content as Array<{ type: string; text?: string }>).find(c => c.type === "text")?.text;
|
||||
assert.equal(JSON.parse(text || "").version, JSON.parse(version.stdout).version);
|
||||
const invalid = await client.callTool({ name: "hose_cli", arguments: { command: "bill list --limitt 5 --json" } });
|
||||
assert.equal(invalid.isError, true);
|
||||
assert.match(JSON.stringify(invalid.content), /未知选项/);
|
||||
console.log(plugin ? "Plugin bundle version and MCP stdio verified with its Bun runtime." : "Binary version and MCP stdio verified without Bun or source files.");
|
||||
} catch (error) {
|
||||
throw new Error(`Binary smoke failed: ${error instanceof Error ? error.message : error}\n${stderr}`);
|
||||
} finally {
|
||||
clearTimeout(deadline);
|
||||
await client.close();
|
||||
rmSync(cwd, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bun
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { isReleaseVersion } from "./bump-version.js";
|
||||
|
||||
export function verifyReleaseTag(root: string, tag: string): void {
|
||||
if (!tag.startsWith("v") || !isReleaseVersion(tag.slice(1))) throw new Error(`Invalid release tag: ${tag}`);
|
||||
const git = (args: string[]) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
||||
const taggedCommit = git(["rev-parse", "--verify", `refs/tags/${tag}^{commit}`]);
|
||||
if (git(["rev-parse", "HEAD"]) !== taggedCommit) throw new Error("Release HEAD must be the exact tagged commit");
|
||||
try {
|
||||
git(["merge-base", "--is-ancestor", taggedCommit, "refs/remotes/origin/main"]);
|
||||
} catch {
|
||||
throw new Error("Release tag must be an ancestor of origin/main; merge the PR before tagging");
|
||||
}
|
||||
const { version } = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8"));
|
||||
if (tag !== `v${version}`) throw new Error(`Release tag ${tag} does not match package.json v${version}`);
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
verifyReleaseTag(resolve(import.meta.dir, ".."), process.argv[2] || "");
|
||||
console.log("Release tag, HEAD, main ancestry and package version verified.");
|
||||
}
|
||||
Reference in new issue
Block a user