( req: DaemonRequest, existingSession?: SessionState, )
| 17 | type NormalizedLockPlatform = NonNullable<PlatformSelector>; |
| 18 | |
| 19 | export function applyRequestLockPolicy( |
| 20 | req: DaemonRequest, |
| 21 | existingSession?: SessionState, |
| 22 | ): DaemonRequest { |
| 23 | const lockPolicy = req.meta?.lockPolicy; |
| 24 | if (!lockPolicy) { |
| 25 | return req; |
| 26 | } |
| 27 | |
| 28 | const nextFlags: CommandFlags = { ...(req.flags ?? {}) }; |
| 29 | const canOverrideSelector = canOverrideLockPolicySelector(req.command); |
| 30 | const conflicts = canOverrideSelector |
| 31 | ? [] |
| 32 | : existingSession |
| 33 | ? listSessionSelectorConflicts(existingSession, nextFlags) |
| 34 | : listFreshSessionConflicts(nextFlags, req.meta?.lockPlatform); |
| 35 | const lockPlatform = req.meta?.lockPlatform; |
| 36 | |
| 37 | if (conflicts.length === 0) { |
| 38 | if ( |
| 39 | shouldApplyLockPlatformDefault(canOverrideSelector, existingSession, nextFlags, lockPlatform) |
| 40 | ) { |
| 41 | nextFlags.platform = lockPlatform; |
| 42 | } |
| 43 | return { |
| 44 | ...req, |
| 45 | flags: nextFlags, |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | if (lockPolicy === 'strip') { |
| 50 | applyStripLockPolicy(nextFlags, conflicts, lockPlatform, existingSession); |
| 51 | return { |
| 52 | ...req, |
| 53 | flags: nextFlags, |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | throw new AppError( |
| 58 | 'INVALID_ARGS', |
| 59 | buildLockPolicyConflictMessage(req, conflicts, existingSession), |
| 60 | { |
| 61 | session: req.session, |
| 62 | conflicts: conflicts.map(formatSessionSelectorConflict), |
| 63 | hint: buildLockPolicyConflictHint(req, existingSession), |
| 64 | }, |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | function buildLockPolicyConflictMessage( |
| 69 | req: DaemonRequest, |
no test coverage detected