refactor(subprocess): use mode as fallback warning latch

This commit is contained in:
pku-xht committed 2026-08-20 20:58:33 +08:00
1 parent a160bd55fc
commit 8b81d77d54
2 files changed
-8

No files matched your search

@@ -45,7 +45,6 @@ export class LocalSubprocessRuntime extends SubprocessRuntime {
internals: SpawnInternals = {}
/** Ordinary native containment mode, selected once before its first user command. */
private ordinaryMode: 'linux-scope' | 'windows-job' | 'fallback' | undefined
private fallbackWarned = false
/** Test hook for platform process inspection; production resolves lazily on terminal spawn. */
terminalInspector: ProcessInspector | undefined
@@ -178,8 +177,6 @@ export class LocalSubprocessRuntime extends SubprocessRuntime {
}
private warnFallback(platform: NodeJS.Platform): void {
if (this.fallbackWarned) return
this.fallbackWarned = true
const reason = platform === 'darwin'
? 'macOS has no supported persistent process-range owner'
: platform === 'linux'
@@ -425,7 +425,6 @@ describe('LocalSubprocessRuntime', () => {
const warning = vi.spyOn(ctx.logger, 'warn').mockImplementation(() => {})
const fiber = await ctx.plugin(LocalSubprocessRuntime)
const runtime = ctx.subprocess as unknown as {
fallbackWarned: boolean
warnFallback(platform: NodeJS.Platform): void
}
try {
@@ -435,15 +434,11 @@ describe('LocalSubprocessRuntime', () => {
['win32', 'the Win32 Job runner is unavailable'],
['freebsd', 'platform freebsd has no native managed range'],
] as const) {
runtime.fallbackWarned = false
runtime.warnFallback(platform)
expect(warning).toHaveBeenLastCalledWith(
expect.stringContaining(reason),
)
}
const calls = warning.mock.calls.length
runtime.warnFallback('linux')
expect(warning).toHaveBeenCalledTimes(calls)
} finally {
warning.mockRestore()
await fiber.dispose()