test: 为全局技能版本检查增加测试环境隔离与环境变量覆盖
在 `src/core/skill-version.ts` 中引入 `SEAL_USE_GLOBAL_SKILL_DIR` 环境变量,支持自定义覆盖全局 Skill 路径。 在 `src/cli/runner.test.ts` 中通过隔离的临时目录运行 CLI runner 测试,避免开发者本地环境或发版预检期间 `~/.agents/skills/seal-use` 版本漂移导致 `runner.test.ts` 误报。 同时增加专门的单测验证 Skill 新于 CLI 时 stderr 告警与引导输出。
This commit is contained in:
1 parent
a40bcd1967
commit
3540c634a0
3 files changed
+48
-2
No files matched your search
+32
-1
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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]
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user