Skip to content

Commit bc5a4c9

Browse files
committed
fix: preserve explicit inventory selectors
1 parent 203be5b commit bc5a4c9

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/daemon/__tests__/request-lock-policy.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ test.each([
154154
{
155155
command: 'apps',
156156
flags: { device: 'iPhone 17' },
157-
expected: { platform: 'ios', device: 'iPhone 17', serial: undefined },
157+
expected: { platform: undefined, device: 'iPhone 17', serial: undefined },
158158
},
159159
{
160160
command: 'devices',
@@ -180,6 +180,41 @@ test.each([
180180
},
181181
);
182182

183+
test('allows inventory commands to use explicit Apple selectors under another lock platform', () => {
184+
const req = applyRequestLockPolicy({
185+
token: 'token',
186+
session: 'qa-android',
187+
command: 'apps',
188+
positionals: [],
189+
flags: {
190+
udid: 'SIM-001',
191+
},
192+
meta: {
193+
lockPolicy: 'reject',
194+
lockPlatform: 'android',
195+
},
196+
});
197+
198+
assert.equal(req.flags?.platform, undefined);
199+
assert.equal(req.flags?.udid, 'SIM-001');
200+
});
201+
202+
test('defaults inventory commands without explicit selectors to the lock platform', () => {
203+
const req = applyRequestLockPolicy({
204+
token: 'token',
205+
session: 'qa-ios',
206+
command: 'apps',
207+
positionals: [],
208+
flags: {},
209+
meta: {
210+
lockPolicy: 'reject',
211+
lockPlatform: 'ios',
212+
},
213+
});
214+
215+
assert.equal(req.flags?.platform, 'ios');
216+
});
217+
183218
test('allows matching redundant selectors for existing sessions', () => {
184219
const req = applyRequestLockPolicy(
185220
{

src/daemon/request-lock-policy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function shouldApplyLockPlatformDefault(
8383
if (!canOverrideSelector) {
8484
return true;
8585
}
86-
return flags.serial === undefined && flags.androidDeviceAllowlist === undefined;
86+
return !LOCKABLE_SELECTOR_KEYS.some((key) => hasSelectorValue(flags[key]));
8787
}
8888

8989
function applyStripLockPolicy(
@@ -119,13 +119,17 @@ function listFreshSessionConflicts(
119119
}
120120
for (const key of LOCKABLE_SELECTOR_KEYS) {
121121
const value = flags[key];
122-
if (typeof value === 'string' && value.trim().length > 0) {
122+
if (hasSelectorValue(value)) {
123123
conflicts.push({ key: key as SessionSelectorConflictKey, value });
124124
}
125125
}
126126
return conflicts;
127127
}
128128

129+
function hasSelectorValue(value: unknown): value is string {
130+
return typeof value === 'string' && value.trim().length > 0;
131+
}
132+
129133
function platformSelectorsConflict(
130134
requested: ReturnType<typeof normalizePlatformSelector>,
131135
locked: ReturnType<typeof normalizePlatformSelector>,

0 commit comments

Comments
 (0)