From 10852eb198b6729118256b2490f3b38c3d0cb6c5 Mon Sep 17 00:00:00 2001 From: yunyingk Date: Tue, 20 Oct 2026 10:23:36 +0800 Subject: [PATCH] Fix platform-dependent config selection test --- src/core/config/loader.test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/config/loader.test.ts b/src/core/config/loader.test.ts index 08813ce..3ac74c8 100644 --- a/src/core/config/loader.test.ts +++ b/src/core/config/loader.test.ts @@ -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", () => {