fix(web-runtime): enforce pressKey allowlist in factory

The factory accepted any string while randomPressKey only emitted
enter/tab/escape/arrows. A spec emitting pressKey({key:"home"}) would
flow through to the chrome driver, which rejects unsupported keys with
a runtime error mid-step. Reject at the factory so the spec author
sees the failure where it originates.
This commit is contained in:
pj committed 2026-05-03 11:07:27 +07:00
1 parent 9722839339
commit ba9a456659
1 file changed
+5
+5
View File
@@ -336,6 +336,11 @@ const runtime = {
return null; return null;
}, },
pressKey(p: { key: string }): unknown { pressKey(p: { key: string }): unknown {
if (!WEB_PRESS_KEYS.includes(p.key)) {
throw new Error(
`pressKey: unsupported key ${JSON.stringify(p.key)} (allowed: ${WEB_PRESS_KEYS.join(", ")})`,
);
}
return { kind: "PressKey", key: p.key }; return { kind: "PressKey", key: p.key };
}, },
wait(p: { durationMillis: number }): unknown { wait(p: { durationMillis: number }): unknown {