Fix platform-dependent config selection test

This commit is contained in:
gitea committed 2026-10-20 10:23:36 +08:00
1 parent b21d92efae
commit 10852eb198
1 file changed
+12 -4
+12 -4
View File
@@ -142,14 +142,22 @@ describe("loadCorpConfigs", () => {
test("same-directory duplicates and invalid shadows use the selected valid file", () => {
const dir = makeTempDir();
process.env.SEAL_USE_ENTERPRISES_DIR = dir;
writeCorpConfig(join(dir, "a.json"), "duplicate", "First");
const selected = join(dir, "b.json");
writeCorpConfig(selected, "duplicate", "Second");
const first = join(dir, "a.json");
const second = join(dir, "b.json");
writeCorpConfig(first, "duplicate", "First");
writeCorpConfig(second, "duplicate", "Second");
writeFileSync(join(dir, "z-invalid.json"), JSON.stringify({ id: "duplicate" }));
// Filesystem enumeration order differs across platforms; writes must follow reads.
const selectedName = loadCorpConfigs()[0]?.name;
expect(["First", "Second"]).toContain(selectedName ?? "");
const selected = selectedName === "First" ? first : second;
const untouched = selectedName === "First" ? second : first;
const untouchedName = JSON.parse(readFileSync(untouched, "utf8")).name;
expect(findCorpConfigFile("duplicate")).toBe(selected);
updateCorpConfig("duplicate", { name: "Updated" });
expect(loadCorpConfigs()[0]?.name).toBe("Updated");
expect(JSON.parse(readFileSync(join(dir, "a.json"), "utf8")).name).toBe("First");
expect(JSON.parse(readFileSync(selected, "utf8")).name).toBe("Updated");
expect(JSON.parse(readFileSync(untouched, "utf8")).name).toBe(untouchedName);
});
test.skipIf(process.platform === "win32")("credential updates and overwrites tighten existing files", () => {