Refine version command with async update cache and background check
This commit is contained in:
1 parent
68a858b4b9
commit
6ad01893b3
6 files changed
+410
-5
No files matched your search
@@ -118,3 +118,71 @@ describe("getMirrorMode routing", () => {
|
||||
// Restore env
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
describe("update command bgSave and cache integration", () => {
|
||||
test("bgSave option saves cache silently without stdout output", async () => {
|
||||
const { mkdtempSync, rmSync } = await import("node:fs");
|
||||
const { tmpdir } = await import("node:os");
|
||||
const { handleUpdateCommand } = await import("./update.js");
|
||||
const { loadUpdateCache, UPDATE_CACHE_FILE_ENV } = await import("../../core/update-cache.js");
|
||||
|
||||
const tempDir = mkdtempSync(join(tmpdir(), "seal-use-bg-save-test-"));
|
||||
const tempCacheFile = join(tempDir, "update-cache.json");
|
||||
const prevEnv = process.env[UPDATE_CACHE_FILE_ENV];
|
||||
process.env[UPDATE_CACHE_FILE_ENV] = tempCacheFile;
|
||||
|
||||
try {
|
||||
const mockRuntime = {
|
||||
appRoot: process.cwd(),
|
||||
entryFile: join(process.cwd(), "src/cli.ts")
|
||||
};
|
||||
|
||||
// Mock fetch to avoid real network calls during test
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = (async () =>
|
||||
new Response(
|
||||
JSON.stringify([
|
||||
{
|
||||
tag_name: "v0.10.99",
|
||||
published_at: "2026-09-20T12:00:00Z",
|
||||
html_url: "https://github.com/yunyingk/seal-use/releases/tag/v0.10.99",
|
||||
assets: []
|
||||
}
|
||||
]),
|
||||
{ status: 200, headers: { "Content-Type": "application/json" } }
|
||||
)) as any;
|
||||
|
||||
let stdoutCaptured = "";
|
||||
const originalLog = console.log;
|
||||
console.log = (msg: string) => {
|
||||
stdoutCaptured += msg;
|
||||
};
|
||||
|
||||
try {
|
||||
await handleUpdateCommand(mockRuntime, {
|
||||
checkOnly: true,
|
||||
bgSave: true
|
||||
});
|
||||
|
||||
// bgSave should NOT print to stdout
|
||||
expect(stdoutCaptured).toBe("");
|
||||
|
||||
// Cache should be saved with latestVersion
|
||||
const cache = loadUpdateCache(tempCacheFile);
|
||||
expect(cache).not.toBeNull();
|
||||
expect(cache?.latestVersion).toBe("0.10.99");
|
||||
expect(cache?.publishedAt).toBe("2026-09-20T12:00:00Z");
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
console.log = originalLog;
|
||||
}
|
||||
} finally {
|
||||
if (prevEnv !== undefined) {
|
||||
process.env[UPDATE_CACHE_FILE_ENV] = prevEnv;
|
||||
} else {
|
||||
delete process.env[UPDATE_CACHE_FILE_ENV];
|
||||
}
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user