test(claude): harden withPlatform mock against cross-file leak

The process.platform mock omitted configurable:true and never restored
the value when the property had no own descriptor, leaving win32 mocked
for later tests on the same Vitest worker. Add configurable + an else
branch that deletes the override to expose the real inherited value.
This commit is contained in:
ozymandiashh 2026-07-06 03:48:46 +03:00
parent 89c94164d7
commit 9ca89523a1

View file

@ -18,11 +18,12 @@ const savedEnv = {
function withPlatform<T>(platform: typeof process.platform, run: () => T): T {
const descriptor = Object.getOwnPropertyDescriptor(process, 'platform')
Object.defineProperty(process, 'platform', { value: platform })
Object.defineProperty(process, 'platform', { value: platform, enumerable: true, configurable: true })
try {
return run()
} finally {
if (descriptor) Object.defineProperty(process, 'platform', descriptor)
else delete (process as { platform?: NodeJS.Platform }).platform
}
}