diff --git a/src/cli/runner.test.ts b/src/cli/runner.test.ts index ebdee93..aee4b79 100644 --- a/src/cli/runner.test.ts +++ b/src/cli/runner.test.ts @@ -1,11 +1,29 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { describe, expect, test } from "bun:test"; +import { afterEach, beforeEach, describe, expect, test } from "bun:test"; import { runCli } from "./runner.js"; import { saveUpdateCache, UPDATE_CACHE_FILE_ENV } from "../core/update-cache.js"; +import { GLOBAL_SKILL_DIR_ENV } from "../core/skill-version.js"; describe("CLI runner", () => { + let tempSkillDir: string; + let prevSkillEnv: string | undefined; + + beforeEach(() => { + tempSkillDir = mkdtempSync(join(tmpdir(), "seal-use-runner-skill-")); + prevSkillEnv = process.env[GLOBAL_SKILL_DIR_ENV]; + process.env[GLOBAL_SKILL_DIR_ENV] = tempSkillDir; + }); + + afterEach(() => { + if (prevSkillEnv !== undefined) { + process.env[GLOBAL_SKILL_DIR_ENV] = prevSkillEnv; + } else { + delete process.env[GLOBAL_SKILL_DIR_ENV]; + } + rmSync(tempSkillDir, { recursive: true, force: true }); + }); test("returns version output without touching the process lifecycle", async () => { const tempDir = mkdtempSync(join(tmpdir(), "seal-use-runner-version-test-")); const tempCacheFile = join(tempDir, "update-cache.json"); @@ -158,4 +176,17 @@ describe("CLI runner", () => { rmSync(tempDir, { recursive: true, force: true }); } }); + + test("version output alerts on newer installed skill via stderr", async () => { + writeFileSync( + join(tempSkillDir, "SKILL.md"), + "---\nname: seal-use\nmetadata:\n version: \"99.99.99\"\n---\n" + ); + + const result = await runCli(["version"]); + expect(result.exitCode).toBe(0); + expect(result.stderr).toContain("技能版本与 CLI 需要核对: CLI"); + expect(result.stderr).toContain("Skill 99.99.99"); + expect(result.stderr).toContain("👉 Next action: seal-use update"); + }); }); diff --git a/src/core/skill-version.test.ts b/src/core/skill-version.test.ts index 336d34c..4cbce85 100644 --- a/src/core/skill-version.test.ts +++ b/src/core/skill-version.test.ts @@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test" import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" -import { getSkillVersionStatus, parseSkillVersion } from "./skill-version.js" +import { getDefaultGlobalSkillDir, getSkillVersionStatus, GLOBAL_SKILL_DIR_ENV, parseSkillVersion } from "./skill-version.js" describe("lightweight Skill version inspection", () => { test("compares release generations without mistaking a development suffix for drift", () => { @@ -21,4 +21,15 @@ describe("lightweight Skill version inspection", () => { expect(parseSkillVersion("---\r\nmetadata:\r\n version: '2.0.0'\r\n---\r\n")).toBe("2.0.0") } finally { rmSync(dir, { recursive: true, force: true }) } }) + + test("getDefaultGlobalSkillDir respects GLOBAL_SKILL_DIR_ENV override", () => { + const prev = process.env[GLOBAL_SKILL_DIR_ENV] + try { + process.env[GLOBAL_SKILL_DIR_ENV] = "/tmp/custom-agents-skill" + expect(getDefaultGlobalSkillDir()).toBe("/tmp/custom-agents-skill") + } finally { + if (prev !== undefined) process.env[GLOBAL_SKILL_DIR_ENV] = prev + else delete process.env[GLOBAL_SKILL_DIR_ENV] + } + }) }) diff --git a/src/core/skill-version.ts b/src/core/skill-version.ts index 3350c37..1b45670 100644 --- a/src/core/skill-version.ts +++ b/src/core/skill-version.ts @@ -3,8 +3,12 @@ import { homedir } from "node:os" import { join } from "node:path" import { compareSemVer } from "./semver.js" +export const GLOBAL_SKILL_DIR_ENV = "SEAL_USE_GLOBAL_SKILL_DIR" + // Keep local version inspection independent of the embedded Skill asset graph. export function getDefaultGlobalSkillDir(): string { + const custom = process.env[GLOBAL_SKILL_DIR_ENV]?.trim() + if (custom) return custom return join(homedir(), ".agents", "skills", "seal-use") }