From c753f30a5ff441ff2bba1f0fa12a5c05bb643920 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 14 May 2026 20:32:40 +0000 Subject: [PATCH] test(website): isolate cloudNodes suite from WEBSITE_CLOUD_NODES_FIXTURE Defensive hardening per CodeRabbit feedback. WEBSITE_CLOUD_NODES_FIXTURE is currently read only by loadPacksForBuild (cloudNodes.build.ts), not by fetchCloudNodesForBuild, so the tests in cloudNodes.test.ts are not affected today. But clearing the env var in beforeEach and restoring it in afterEach guards against future refactors that might let the override bleed into the fetcher, and matches the pattern already used in cloudNodes.build.test.ts. Also fixes a latent bug in the existing afterEach: previously, process.env.WEBSITE_CLOUD_API_KEY = savedCloudApiKey would set the env var to the literal string 'undefined' when savedCloudApiKey was unset. Now both env vars are conditionally restored (matching the cloudNodes.build test convention). --- apps/website/src/utils/cloudNodes.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/website/src/utils/cloudNodes.test.ts b/apps/website/src/utils/cloudNodes.test.ts index 27edebea49..90a9a949fd 100644 --- a/apps/website/src/utils/cloudNodes.test.ts +++ b/apps/website/src/utils/cloudNodes.test.ts @@ -87,6 +87,7 @@ function withSnapshotDir(snapshot: NodesSnapshot | null): URL { describe('fetchCloudNodesForBuild', () => { const savedCloudApiKey = process.env.WEBSITE_CLOUD_API_KEY + const savedCloudNodesFixture = process.env.WEBSITE_CLOUD_NODES_FIXTURE beforeEach(() => { resetCloudNodesFetcherForTests() @@ -94,11 +95,21 @@ describe('fetchCloudNodesForBuild', () => { fetchRegistryPacksMock.mockResolvedValue(new Map()) sanitizeCallSpy.mockReset() delete process.env.WEBSITE_CLOUD_API_KEY + delete process.env.WEBSITE_CLOUD_NODES_FIXTURE }) afterEach(() => { vi.restoreAllMocks() - process.env.WEBSITE_CLOUD_API_KEY = savedCloudApiKey + if (savedCloudApiKey === undefined) { + delete process.env.WEBSITE_CLOUD_API_KEY + } else { + process.env.WEBSITE_CLOUD_API_KEY = savedCloudApiKey + } + if (savedCloudNodesFixture === undefined) { + delete process.env.WEBSITE_CLOUD_NODES_FIXTURE + } else { + process.env.WEBSITE_CLOUD_NODES_FIXTURE = savedCloudNodesFixture + } }) it('returns fresh when API succeeds', async () => {