@@ -4,7 +4,9 @@ import path from "node:path";
44import { resolveExecApprovalsPath } from "./exec-approvals-config.js" ;
55
66const DOCTOR_CLAIM_SUFFIX = ".doctor-importing" ;
7- const legacyPresenceCache = new Map < string , boolean > ( ) ;
7+ // Doctor usually runs in another process, so cache only the steady-state absence;
8+ // a present verdict must be re-probed on the next attempt after Doctor finishes.
9+ const legacyAbsenceCache = new Set < string > ( ) ;
810
911/**
1012 * Doctor repairs whichever state directory its own environment resolves to, so a bare
@@ -42,26 +44,20 @@ export function assertNoPendingLegacyExecApprovals(
4244 options : { pathMayExist ?: ( filePath : string ) => boolean } = { } ,
4345) : void {
4446 const sourcePath = resolveExecApprovalsPath ( ) ;
45- let hasLegacy = legacyPresenceCache . get ( sourcePath ) ;
46- if ( hasLegacy === undefined ) {
47- const probe = options . pathMayExist ?? pathMayExist ;
48- // Bound both Doctor rename directions: source -> claim and claim -> source.
49- const sourceBefore = probe ( sourcePath ) ;
50- const claim = probe ( `${ sourcePath } ${ DOCTOR_CLAIM_SUFFIX } ` ) ;
51- const sourceAfter = probe ( sourcePath ) ;
52- hasLegacy = sourceBefore || claim || sourceAfter ;
53- legacyPresenceCache . set ( sourcePath , hasLegacy ) ;
47+ if ( legacyAbsenceCache . has ( sourcePath ) ) {
48+ return ;
5449 }
55- if ( hasLegacy ) {
50+ const probe = options . pathMayExist ?? pathMayExist ;
51+ // Bound both Doctor rename directions: source -> claim and claim -> source.
52+ const sourceBefore = probe ( sourcePath ) ;
53+ const claim = probe ( `${ sourcePath } ${ DOCTOR_CLAIM_SUFFIX } ` ) ;
54+ const sourceAfter = probe ( sourcePath ) ;
55+ if ( sourceBefore || claim || sourceAfter ) {
5656 throw new ExecApprovalsMigrationRequiredError ( sourcePath ) ;
5757 }
58- }
59-
60- /** Forget one process-local legacy probe after Doctor resolves the source. */
61- export function resetLegacyExecApprovalsPresenceCache ( env : NodeJS . ProcessEnv = process . env ) : void {
62- legacyPresenceCache . delete ( resolveExecApprovalsPath ( env ) ) ;
58+ legacyAbsenceCache . add ( sourcePath ) ;
6359}
6460
6561export function resetExecApprovalsMigrationGateForTest ( ) : void {
66- legacyPresenceCache . clear ( ) ;
62+ legacyAbsenceCache . clear ( ) ;
6763}
0 commit comments