fix(windows): drain native coverage lifecycles

This commit is contained in:
Tianyi Cui
2026-08-08 23:56:00 +08:00
parent 0aefa18636
commit 3a518021f6
7 changed files with 72 additions and 8 deletions

View File

@@ -22,6 +22,23 @@ import BrowseDirectoryPicker from '@deepseek-ai/dsh-host-directory-picker-browse
import NativeDirectoryPicker from '@deepseek-ai/dsh-host-directory-picker-native'
import * as DirectoryPickerAuto from '../src/index.ts'
const renameControl = vi.hoisted(() => ({ attempts: 0, remainingFailures: 0 }))
vi.mock('node:fs/promises', async (importOriginal) => {
const actual = await importOriginal<typeof import('node:fs/promises')>()
return {
...actual,
async rename(oldPath: string, newPath: string): Promise<void> {
renameControl.attempts++
if (renameControl.remainingFailures > 0) {
renameControl.remainingFailures--
throw Object.assign(new Error(`transient rename failure for ${newPath}`), { code: 'EPERM' })
}
await actual.rename(oldPath, newPath)
},
}
})
const AUTO = '@deepseek-ai/dsh-host-directory-picker-auto'
const NATIVE = '@deepseek-ai/dsh-host-directory-picker-native'
const BROWSE = '@deepseek-ai/dsh-host-directory-picker-browse'
@@ -41,6 +58,8 @@ afterEach(async () => {
}
root = undefined
fakeBin = undefined
renameControl.attempts = 0
renameControl.remainingFailures = 0
})
/** Write a two-row cordis.yml (webserver + chooser), then boot it through the real Loader. */
@@ -163,9 +182,11 @@ describe('real Loader composition', () => {
const backendEntry = [...ctx.loader.entries()].find(entry => entry.options.name === NATIVE)!
await ctx.loader.remove(backendEntry.id)
const autoEntry = [...ctx.loader.entries()].find(entry => entry.options.name === AUTO)!
renameControl.remainingFailures = 1
await expect(autoEntry.fiber!.dispose()).resolves.not.toThrow()
expect(entryNames(ctx)).not.toContain(NATIVE)
// Same self-dispose persistence as above: let the write land before teardown.
await expect.poll(async () => await readFile(configPath, 'utf8')).toContain('disabled: true')
expect(renameControl.attempts).toBe(2)
})
})