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).
This commit is contained in:
Glary-Bot
2026-05-14 20:32:40 +00:00
parent 1c5a0079f0
commit c753f30a5f

View File

@@ -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 () => {