fix: test

This commit is contained in:
LukeGus committed 2026-11-05 12:52:04 -06:00
1 parent 041e10eb5c
commit c09d09f2ce
2 files changed
+34 -8

No files matched your search

+22 -1
View File
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, it } from "vitest"; import { afterEach, describe, expect, it, vi } from "vitest";
import crypto from "node:crypto"; import crypto from "node:crypto";
import fs from "node:fs"; import fs from "node:fs";
import os from "node:os"; import os from "node:os";
@@ -471,6 +471,27 @@ describe("rebuilding local plugins", () => {
expect(isLocalBuildStale(root)).toBe(false); expect(isLocalBuildStale(root)).toBe(false);
}); });
it("survives a build replacing dist during the scan", () => {
const root = repo(tempDir(), "Plugin-A", "a");
const gone = path.join(root, "dist", "migrations", "postgres");
fs.mkdirSync(gone, { recursive: true });
fs.writeFileSync(path.join(root, "manifest.json"), "{}");
const realStat = fs.statSync;
const spy = vi.spyOn(fs, "statSync").mockImplementation(((
target: string,
) => {
if (target === gone) {
throw Object.assign(new Error("gone"), { code: "ENOENT" });
}
return realStat(target);
}) as typeof fs.statSync);
try {
expect(() => isLocalBuildStale(root)).not.toThrow();
} finally {
spy.mockRestore();
}
});
it("builds with this checkout's SDK CLI, not the plugin's own", () => { it("builds with this checkout's SDK CLI, not the plugin's own", () => {
const [command, args] = localSdkBuildCommand(); const [command, args] = localSdkBuildCommand();
expect(command).toBe(process.execPath); expect(command).toBe(process.execPath);
+12 -7
View File
@@ -370,15 +370,20 @@ const BUILD_INPUTS = [
"package.json", "package.json",
]; ];
// A build can replace dist while this walks it, so a path can vanish mid scan.
function newestMtime(target) { function newestMtime(target) {
if (!fs.existsSync(target)) return 0; try {
const stat = fs.statSync(target); const stat = fs.statSync(target);
if (!stat.isDirectory()) return stat.mtimeMs; if (!stat.isDirectory()) return stat.mtimeMs;
let newest = 0; let newest = 0;
for (const name of fs.readdirSync(target)) { for (const name of fs.readdirSync(target)) {
newest = Math.max(newest, newestMtime(path.join(target, name))); newest = Math.max(newest, newestMtime(path.join(target, name)));
}
return newest;
} catch (error) {
if (error.code === "ENOENT") return 0;
throw error;
} }
return newest;
} }
/** True when a plugin repo has never been built or its sources changed since. */ /** True when a plugin repo has never been built or its sources changed since. */