fix(simulation): validate semantic click identity (#37808)
This commit is contained in:
parent
edc93ceff1
commit
71cb419570
6 changed files with 118 additions and 3 deletions
|
|
@ -208,6 +208,15 @@ export const execute = Effect.fn("SimulationActions.execute")(function* (harness
|
|||
const target = all(harness.renderer.root).find((item) => item.num === action.target)
|
||||
if (!target || !target.visible || target.isDestroyed)
|
||||
return yield* Effect.fail(new Error(`click target is stale or unavailable: ${action.target}`))
|
||||
if (action.semantic) {
|
||||
const current = snapshot(harness).nodes.find((node) => node.element === action.target)
|
||||
if (
|
||||
current?.id !== action.semantic.id ||
|
||||
current.instance !== action.semantic.instance ||
|
||||
current.element !== action.semantic.element
|
||||
)
|
||||
return yield* Effect.fail(new Error(`semantic click target is stale or unavailable: ${action.semantic.id}`))
|
||||
}
|
||||
if (
|
||||
!Number.isFinite(action.x) ||
|
||||
action.x < 0 ||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ function handle(harness: Harness, request: SimulationProtocol.Frontend.Request)
|
|||
target: request.params.target,
|
||||
x: request.params.x,
|
||||
y: request.params.y,
|
||||
semantic: request.params.semantic,
|
||||
})
|
||||
case "ui.resize":
|
||||
return SimulationActions.execute(harness, {
|
||||
|
|
|
|||
|
|
@ -171,6 +171,7 @@ export namespace Frontend {
|
|||
"ui.arrow",
|
||||
"ui.focus",
|
||||
"ui.click",
|
||||
"ui.click.semantic",
|
||||
"ui.resize",
|
||||
"ui.matches",
|
||||
"ui.screenshot",
|
||||
|
|
@ -189,13 +190,26 @@ export namespace Frontend {
|
|||
})
|
||||
export interface KeyModifiers extends Schema.Schema.Type<typeof KeyModifiers> {}
|
||||
|
||||
export const SemanticClickTarget = Schema.Struct({
|
||||
id: Schema.NonEmptyString,
|
||||
instance: Schema.optionalKey(Schema.NonEmptyString),
|
||||
element: Schema.Number.check(Schema.isInt(), Schema.isGreaterThan(0)),
|
||||
})
|
||||
export interface SemanticClickTarget extends Schema.Schema.Type<typeof SemanticClickTarget> {}
|
||||
|
||||
export const Action = Schema.Union([
|
||||
Schema.Struct({ type: Schema.Literal("ui.type"), text: Schema.String }),
|
||||
Schema.Struct({ type: Schema.Literal("ui.press"), key: Schema.String, modifiers: Schema.optional(KeyModifiers) }),
|
||||
Schema.Struct({ type: Schema.Literal("ui.enter") }),
|
||||
Schema.Struct({ type: Schema.Literal("ui.arrow"), direction: Schema.Literals(["up", "down", "left", "right"]) }),
|
||||
Schema.Struct({ type: Schema.Literal("ui.focus"), target: Schema.Number }),
|
||||
Schema.Struct({ type: Schema.Literal("ui.click"), target: Schema.Number, x: Schema.Number, y: Schema.Number }),
|
||||
Schema.Struct({
|
||||
type: Schema.Literal("ui.click"),
|
||||
target: Schema.Number,
|
||||
x: Schema.Number,
|
||||
y: Schema.Number,
|
||||
semantic: Schema.optionalKey(SemanticClickTarget),
|
||||
}),
|
||||
Schema.Struct({ type: Schema.Literal("ui.resize"), cols: Schema.Number, rows: Schema.Number }),
|
||||
])
|
||||
export type Action = Schema.Schema.Type<typeof Action>
|
||||
|
|
@ -313,7 +327,12 @@ export namespace Frontend {
|
|||
export const FocusParams = Schema.Struct({ target: Schema.Number })
|
||||
export interface FocusParams extends Schema.Schema.Type<typeof FocusParams> {}
|
||||
|
||||
export const ClickParams = Schema.Struct({ target: Schema.Number, x: Schema.Number, y: Schema.Number })
|
||||
export const ClickParams = Schema.Struct({
|
||||
target: Schema.Number,
|
||||
x: Schema.Number,
|
||||
y: Schema.Number,
|
||||
semantic: Schema.optionalKey(SemanticClickTarget),
|
||||
})
|
||||
export interface ClickParams extends Schema.Schema.Type<typeof ClickParams> {}
|
||||
|
||||
export const ResizeParams = Schema.Struct({ cols: Schema.Number, rows: Schema.Number })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue