Repository navigation
fix(mobile): validate device.setPermission's name and state before the device call - #1605
Conversation
…e device call
device.setPermission sent any name and state straight to agent-device's
settings.update, so a typo such as 'camra' failed as ENGINE_FAILURE after a
device round trip ("settings permission requires a target: ..."). It now runs
the same check as device.openApp({ permissions }) first and refuses a bad
name (naming the nearest one), a bad state, or a missing state with
INVALID_ARGUMENT.
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
A symbol name was skipped by the map check, and an object whose toString() returned "camera" passed as camera while the object itself reached settings.update. setPermission now refuses any non-string name with INVALID_ARGUMENT. The step label goes through String() so a symbol reaches that check instead of throwing a TypeError while the label is built. The changeset now says which error names the nearest permission (a bad name) and which lists the valid states (a bad or missing state).
okwasniewski
left a comment
There was a problem hiding this comment.
Automated review by Claude Code on behalf of maintainers.
The fix is right: it reuses assertPermissions with the same DEVICE_PERMISSIONS / PERMISSION_STATES as openApp({ permissions }), so the lists can't drift. Tests are real (removing the call, the undefined guard, or the whole block each fails a test). CI green. Two shape asks before it's ready:
Must fix
packages/mobile/src/surface.ts:840-849- wrapping one argument as{ [permission]: state }to reuse the map validator is what forces the extratypeofandundefinedguards, and line 848 hand-copies themust be one of ..., gottemplate from line 359. Add oneassertPermission(label, name, state, code)next toassertPermissions(string inDEVICE_PERMISSIONSwith nearest-name suggestion, state inPERMISSION_STATES,undefinedrefused), have theassertPermissionsloop call it per entry, and makesetPermissiona single call. One function owns the message.- Drop the symbol /
{ toString }hardening (surface.ts:839-845,String(permission)indevice.ts:323, the symbol loop inengine.test.ts). It guards deliberateas nevercallers, not the #1603 typo, and sibling setters (setNetwork,setAppearance) don't do it. Atypeof name === 'string'check inside fix 1 covers it.
Nits
- Message reads
has unknown key "camra"for a positional arg; something likedevice.setPermission permission "camra" is unknown; did you mean "camera"?falls out of fix 1. - Changeset can be one line: "
device.setPermissionrejects an unknown permission name or state withINVALID_ARGUMENT, naming the nearest permission for a typo."
|
Thanks @okwasniewski, done in 191b1ac:
Changeset is the one line you suggested. On the message nit: the typo message still reads
|
Re-review at 68e1541. Both asks from the last round are done, thanks. Asks
Changeset is one line. Docs table matches the other Non-blocking
Checked
LGTM once CI is green. This was an automated review. |
Addressed in 191b1ac, see re-review.
okwasniewski
left a comment
There was a problem hiding this comment.
Automated review: asks done, see comment.
What and why
device.openApp({ permissions })checks permission names and states, butdevice.setPermissionsent them straight to agent-device, so'camra'failed asENGINE_FAILURE("settings permission requires a target: ...").setPermissionnow runs the same check first: a bad name (naming the nearest one), a bad state, or a missing state isINVALID_ARGUMENT, and no device command is sent.setPermission.Issue
Fixes #1603
Verified
Ran it locally: yes - built CLI on an iPhone 16 simulator (iOS 18.5), scratch target on
com.apple.Preferences, pluspnpm --filter @e2e-dev/mobile run testandpnpm check.setPermission('camra', 'grant')ENGINE_FAILURE: permission camra grant failed: settings permission requires a target: all|camera|...INVALID_ARGUMENT: device.setPermission has unknown key "camra"; did you mean "camera"?setPermission('camera', 'allow')ENGINE_FAILURE: ... Invalid permission state: allow. Use <grant|deny|reset> ...INVALID_ARGUMENT: device.setPermission.camera must be one of grant, deny, reset, got "allow"setPermission('camera', 'reset')Checklist
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it..d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures.e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.