GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — t3code/scripts/mobile-behavior/scenarios.ts at main · VitaCodez/t3code Expand file tree/ Copy pathscenarios.tsMore file actions 599 lines (556 loc) · 24.7 KB / Copy pathscenarios.tsFile metadata and controls599 lines (556 loc) · 24.7 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 // @effect-diagnostics globalDate:off - scenario windows are wall-clock by nature. /** * Scenarios drive one flow on the device and return metrics. Cases in `cases.ts` name a * scenario and check its metrics, so one flow can serve several issues. */ import type { ThreadId } from "@t3tools/contracts"; import type * as SecureRandom from "effect/crypto/SecureRandom"; import * as Effect from "effect/Effect"; import * as Schema from "effect/Schema"; import { APP_ID, SCHEME, type AxNode, type Device, type FeedSample, type ProbeState, } from "./device.ts"; import { uuid, type EvalEnvironment } from "./environment.ts"; import { feedMotion, frameStats, type Metrics } from "./grade.ts"; export type Pose = "phone" | "duo-closed" | "duo-open" | "ipad"; export interface ScenarioContext { readonly env: EvalEnvironment; readonly device: Device; readonly pose: Pose; readonly fixtures: { readonly longThread: ThreadId }; } // Child thread ids carry `:`, so each segment is encoded. const threadPath = (ctx: ScenarioContext, threadId: string) => `threads/${encodeURIComponent(ctx.env.environmentId)}/${encodeURIComponent(threadId)}`; const isThread = (state: ProbeState, threadId: string) => state.route?.name === "Thread" && state.route.params.threadId === threadId; const openThread = Effect.fn("scenario.openThread")(function* ( ctx: ScenarioContext, threadId: string, ) { yield* ctx.device.open(threadPath(ctx, threadId)); return yield* ctx.device.waitFor( `thread ${threadId} with a ready feed`, (state) => isThread(state, threadId) && state.feed?.threadId === threadId && state.feed.ready, 20_000, ); }); /** Screen size in points, and the x of the thread column (the right column in split view). */ const geometry = Effect.fn("scenario.geometry")(function* (ctx: ScenarioContext) { const nodes = yield* ctx.device.nodes; const rect = nodes[0]?.rect ?? { x: 0, y: 0, width: 400, height: 870 }; const state = yield* ctx.device.state; return { width: rect.width, height: rect.height, threadX: Math.round(rect.width * (state.route?.columns ? 0.72 : 0.5)), }; }); const findNode = Effect.fn("scenario.findNode")(function* ( ctx: ScenarioContext, description: string, match: (node: { label?: string; value?: string; kind?: string; editable?: boolean }) => boolean, ) { const node = (yield* ctx.device.nodes).find(match); if (!node?.rect) return yield* new ScenarioFailure({ message: `No ${description} on screen.` }); return node; }); const composerNode = (ctx: ScenarioContext) => findNode( ctx, "composer text view", (node) => node.kind === "text-view" && node.editable === true, ); /** The text the native editor shows, read from the accessibility tree rather than React props. */ const composerText = Effect.fn("scenario.composerText")(function* (ctx: ScenarioContext) { const node = yield* composerNode(ctx); return node.value ?? node.label ?? ""; }); /** A fresh settled thread, so drafts left by earlier samples never mix in. */ const freshThread = Effect.fn("scenario.freshThread")(function* ( ctx: ScenarioContext, prompt = "Hi. [[eval:reply]]", ) { const threadId = yield* ctx.env.launch(`Fresh ${(yield* uuid).slice(0, 6)}`, prompt); if (!prompt.includes("[[eval:stream")) yield* ctx.env.settled(threadId); return threadId; }); /** Replaces the composer's text, the way a person would after clearing it. */ const typeInComposer = Effect.fn("scenario.typeInComposer")(function* ( ctx: ScenarioContext, text: string, ) { const { x, y } = ctx.device.center(yield* composerNode(ctx)); yield* ctx.device.run(["fill", String(x), String(y), text]); // The composer slides up with the keyboard; a tap before it settles lands on the keyboard. yield* ctx.device.waitFor("the keyboard", (state) => state.composer.keyboard, 10_000); yield* Effect.sleep("1 second"); }); const countUserText = ( projection: { readonly messages: ReadonlyArray<{ readonly text?: string }> }, text: string, ) => projection.messages.filter((message) => message.text === text).length; /** Starts a scripted reply in `threadId` and waits until the app shows it streaming. */ const startStream = Effect.fn("scenario.startStream")(function* ( ctx: ScenarioContext, threadId: ThreadId, script: string, ) { const before = (yield* ctx.device.state).feed?.content ?? 0; yield* ctx.env.send(threadId, `Write the long report. ${script}`); yield* ctx.device.waitFor( "the reply to start streaming in the feed", (state) => (state.feed?.content ?? 0) > before + 200, 20_000, ); }); /** Records frames (and the visible feed) while `action` runs; the action's failure is not the metric. */ /** Records frames (and the visible feed) while `action` runs; stops recording even if it fails. */ const recordFor = <E, R>( ctx: ScenarioContext, withFeed: boolean, action: Effect.Effect<unknown, E, R>, ) => ctx.device.recordStart(withFeed).pipe( Effect.andThen(Effect.exit(action)), Effect.flatMap((exit) => ctx.device.recordStop.pipe(Effect.flatMap((recording) => Effect.as(exit, recording))), ), ); /** JS frame times jitter, so the display's refresh rate comes from the UI thread's vsync times. */ const frameMetrics = (recording: { js: ReadonlyArray<number>; ui: ReadonlyArray<number> }) => { const ui = frameStats(recording.ui, "ui"); const refreshMs = typeof ui.uiRefreshHz === "number" ? 1000 / ui.uiRefreshHz : undefined; return { ...frameStats(recording.js, "js", refreshMs), ...ui }; }; /** Every scenario fails with this one error, so the table has a single function type. */ export class ScenarioFailure extends Schema.TaggedError<ScenarioFailure>()("ScenarioFailure", { message: Schema.String, }) {} const failure = <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.mapError( effect, (error) => new ScenarioFailure({ message: error instanceof Error ? error.message : String(error) }), ); type Scenario = ( ctx: ScenarioContext, ) => Effect.Effect<Metrics, ScenarioFailure, SecureRandom.SecureRandom>; export const SCENARIOS = { /** Six upward flings in the long settled thread. */ scrollUpLongThread: Effect.fn("scenario.scrollUpLongThread")(function* (ctx: ScenarioContext) { yield* openThread(ctx, ctx.fixtures.longThread); const { height, threadX } = yield* geometry(ctx); const recording = yield* recordFor( ctx, true, Effect.gen(function* () { for (let fling = 0; fling < 6; fling++) yield* ctx.device.swipe(threadX, Math.round(height * 0.35), Math.round(height * 0.8)); yield* Effect.sleep("1 second"); }), ); return { ...feedMotion(recording.feed, 1), ...frameMetrics(recording) } satisfies Metrics; }, failure), /** A long reply streams into the open thread for eight seconds. */ streamInView: Effect.fn("scenario.streamInView")(function* (ctx: ScenarioContext) { yield* openThread(ctx, ctx.fixtures.longThread); yield* startStream(ctx, ctx.fixtures.longThread, "[[eval:stream:4000:25]]"); const recording = yield* recordFor(ctx, true, Effect.sleep("8 seconds")); const after = yield* ctx.device.state; yield* ctx.env.interruptAll(); const motion = feedMotion(recording.feed, 0); return { ...motion, ...frameMetrics(recording), settledFromEndPx: settledFromEnd(recording.feed), contentGrewPx: (recording.feed.at(-1)?.content ?? 0) - (recording.feed[0]?.content ?? 0), followingAtEnd: after.feed?.following === true, } satisfies Metrics; }, failure), /** Types and sends a message from the composer at the end of the long thread. */ sendInLongThread: Effect.fn("scenario.sendInLongThread")(function* (ctx: ScenarioContext) { yield* openThread(ctx, ctx.fixtures.longThread); const text = `Follow-up ${(yield* uuid).slice(0, 8)} [[eval:reply]]`; yield* typeInComposer(ctx, text); const recording = yield* recordFor( ctx, true, Effect.gen(function* () { yield* ctx.device.press('label="Send"'); yield* Effect.sleep("4 seconds"); }), ); const after = yield* ctx.device.state; const nativeText = yield* composerText(ctx); const projection = yield* ctx.env.settled(ctx.fixtures.longThread); const motion = feedMotion(recording.feed, 0); return { maxFromEndPx: motion.maxFromEndPx ?? null, finalFromEndPx: motion.finalFromEndPx ?? null, serverMessages: countUserText(projection, text), draftCleared: after.composer.draft === "", editorCleared: nativeText === "", } satisfies Metrics; }, failure), /** A thread in the background finishes while the long thread sits mid-scroll. */ backgroundFinish: Effect.fn("scenario.backgroundFinish")(function* (ctx: ScenarioContext) { const key = `bg-${(yield* uuid).slice(0, 8)}`; const other = yield* ctx.env.launch("Background work", `Run the job. [[eval:hold:${key}]]`); yield* openThread(ctx, ctx.fixtures.longThread); const { height, threadX } = yield* geometry(ctx); for (let fling = 0; fling < 2; fling++) yield* ctx.device.swipe(threadX, Math.round(height * 0.4), Math.round(height * 0.7)); yield* waitForStill(ctx); const recording = yield* recordFor( ctx, true, Effect.gen(function* () { yield* ctx.env.release(key); yield* ctx.env.settled(other); yield* Effect.sleep("2 seconds"); }), ); return { ...feedMotion(recording.feed, 0) } satisfies Metrics; }, failure), /** Types in a streaming thread, switches to another thread, and comes back. */ draftThreadSwitch: Effect.fn("scenario.draftThreadSwitch")(function* (ctx: ScenarioContext) { const text = `Draft ${(yield* uuid).slice(0, 8)}`; const other = yield* freshThread(ctx); const streaming = yield* freshThread(ctx, "Write the long report. [[eval:stream:4000:25]]"); yield* openThread(ctx, streaming); yield* typeInComposer(ctx, text); yield* openThread(ctx, other); yield* Effect.sleep("1 second"); const onOther = yield* ctx.device.state; const otherText = yield* composerText(ctx); yield* openThread(ctx, streaming); yield* Effect.sleep("1 second"); const back = yield* ctx.device.state; const backText = yield* composerText(ctx); yield* ctx.env.interruptAll(); const otherKey = `${ctx.env.environmentId}:${other}`; return { draftKept: back.composer.draft === text, editorShowsDraft: backText === text, leakedIntoOtherDraft: (onOther.composer.drafts[otherKey] ?? "") !== "", leakedIntoOtherEditor: otherText.includes(text), } satisfies Metrics; }, failure), /** Types a draft, sends the app to the background, and brings it back. */ draftBackground: Effect.fn("scenario.draftBackground")(function* (ctx: ScenarioContext) { const text = `Draft ${(yield* uuid).slice(0, 8)}`; const threadId = yield* freshThread(ctx); yield* openThread(ctx, threadId); yield* typeInComposer(ctx, text); yield* ctx.device.home; yield* Effect.sleep("3 seconds"); // A link back to the thread foregrounds the running app; a plain open would reload its JS. yield* ctx.device.run([ "open", APP_ID, "--launch-url", `${SCHEME}://${threadPath(ctx, threadId)}`, ]); const back = yield* ctx.device.waitFor("the thread after foreground", (state) => isThread(state, threadId), ); return { draftKept: back.composer.draft === text, editorShowsDraft: (yield* composerText(ctx)) === text, } satisfies Metrics; }, failure), /** Taps the middle of the composer's text area. */ tapComposer: Effect.fn("scenario.tapComposer")(function* (ctx: ScenarioContext) { const threadId = yield* freshThread(ctx); yield* openThread(ctx, threadId); const node = yield* composerNode(ctx); const { x, y } = ctx.device.center(node); yield* ctx.device.pressAt(x, y); yield* Effect.sleep("1500 millis"); const after = yield* ctx.device.state; return { stayedOnThread: isThread(after, threadId), editorFocused: after.composer.editors.some((editor) => editor.expanded) && after.composer.keyboard, } satisfies Metrics; }, failure), /** Types `/eval`, picks the workspace's `eval-notes` skill, and checks the editor keeps focus. */ skillPick: Effect.fn("scenario.skillPick")(function* (ctx: ScenarioContext) { yield* openThread(ctx, yield* freshThread(ctx)); // Short screens fit one menu row above the keyboard, so filter the menu to one row. yield* typeInComposer(ctx, "/eval"); const composer = yield* composerNode(ctx); // Menu rows read "<icon>, skill:<name>, <description>". Skills arrive with a workspace // snapshot the draft change requests. let item: AxNode | undefined; for (let attempt = 0; attempt < 10 && !item?.rect; attempt++) { yield* Effect.sleep("1 second"); item = (yield* ctx.device.nodes).find( (node) => node.rect !== undefined && node.rect.y + node.rect.height <= composer.rect!.y && node.label?.includes(", skill:eval-notes") === true, ); } if (!item?.rect) return yield* new ScenarioFailure({ message: "The / menu did not list skill:eval-notes." }); const { x, y } = ctx.device.center(item); yield* ctx.device.pressAt(x, y); yield* Effect.sleep("1500 millis"); const after = yield* ctx.device.state; return { editorFocused: after.composer.editors.some((editor) => editor.expanded) && after.composer.keyboard, } satisfies Metrics; }, failure), /** Sends from a thread whose provider instance the server no longer has. */ failedSend: Effect.fn("scenario.failedSend")(function* (ctx: ScenarioContext) { const { threadId, lock } = yield* ctx.env.launchLockable("Locked thread"); yield* openThread(ctx, threadId); const text = `Will fail ${(yield* uuid).slice(0, 8)}`; yield* typeInComposer(ctx, text); yield* lock; // The app learns of the setting a moment after the server commits it. yield* Effect.sleep("2 seconds"); // Either outcome is honest: Send turns off, or the rejected send shows an error. const sendBlocked = (yield* ctx.device.nodes).find((node) => node.label === "Send")?.enabled === false; if (!sendBlocked) yield* ctx.device.press('label="Send"'); const shown = sendBlocked ? false : (yield* ctx.device .waitFor("a composer error", (state) => state.composer.error !== null, 8_000) .pipe(Effect.option))._tag === "Some"; return { sendBlocked, errorShown: shown, silentFailure: !sendBlocked && !shown, } satisfies Metrics; }, failure), /** A working thread finishes while Home is open. */ workingShelfFinish: Effect.fn("scenario.workingShelfFinish")(function* (ctx: ScenarioContext) { const key = `shelf-${(yield* uuid).slice(0, 8)}`; const threadId = yield* ctx.env.launch("Shelf work", `Run the job. [[eval:hold:${key}]]`); const working = yield* ctx.device.waitFor( "the thread to show as working", (state) => state.threads[threadId] === "working", ); yield* ctx.env.release(key); yield* ctx.env.settled(threadId); // The shelf keeps a finished row for WORKING_EXIT_GRACE_MS (2 s) on purpose. yield* Effect.sleep("5 seconds"); const after = yield* ctx.device.state; return { shelfShownWhileWorking: shelfCount(working) > 0, shelfCountAfter: shelfCount(after), // For diagnosis: threads the app itself calls working, beside the shelf's count. appWorkingThreads: Object.values(after.threads).filter((status) => status === "working") .length, statusAfter: after.threads[threadId] ?? "missing", } satisfies Metrics; }, failure), /** A thread asks a question while Home is open. */ pendingQuestion: Effect.fn("scenario.pendingQuestion")(function* (ctx: ScenarioContext) { const threadId = yield* ctx.env.launch("Question", `Ask me first. [[eval:question]]`); yield* ctx.env.waitForPendingInput(threadId); yield* Effect.sleep("2 seconds"); const after = yield* ctx.device.state; yield* ctx.env.interruptAll(); return { status: after.threads[threadId] ?? "missing", shelfCount: shelfCount(after), } satisfies Metrics; }, failure), /** A thread runs two subagents; Home and the thread must not look idle. */ subagentsRunning: Effect.fn("scenario.subagentsRunning")(function* (ctx: ScenarioContext) { const key = `sub-${(yield* uuid).slice(0, 8)}`; const threadId = yield* ctx.env.launch("Subagents", `Fan out. [[eval:subagents:${key}]]`); yield* ctx.env.waitForSubagents(threadId); yield* Effect.sleep("2 seconds"); const home = yield* ctx.device.state; yield* openThread(ctx, threadId); yield* Effect.sleep("1500 millis"); const thread = yield* ctx.device.state; yield* ctx.env.release(key); yield* ctx.env.settled(threadId); return { status: home.threads[threadId] ?? "missing", threadShowsStatus: thread.floatingStatus !== null, } satisfies Metrics; }, failure), /** Scrolls a finished subagent's child thread. */ openSubagentThread: Effect.fn("scenario.openSubagentThread")(function* (ctx: ScenarioContext) { const key = `child-${(yield* uuid).slice(0, 8)}`; const threadId = yield* ctx.env.launch("Parent", `Fan out. [[eval:subagents:${key}]]`); yield* ctx.env.waitForSubagents(threadId); yield* ctx.env.release(key); const projection = yield* ctx.env.settled(threadId); const child = projection.subagents.find( (subagent) => subagent.childThreadId !== null, )?.childThreadId; if (!child) return yield* new ScenarioFailure({ message: "The subagent made no child thread." }); yield* openThread(ctx, child); const { height, threadX } = yield* geometry(ctx); const recording = yield* recordFor( ctx, true, Effect.gen(function* () { yield* ctx.device.swipe(threadX, Math.round(height * 0.7), Math.round(height * 0.3)); yield* ctx.device.swipe(threadX, Math.round(height * 0.3), Math.round(height * 0.7)); }), ); return { movedPx: feedMotion(recording.feed, 0).movedPx ?? 0, ...frameMetrics(recording), } satisfies Metrics; }, failure), /** Long-presses a row on Home and picks Pin. */ pinFromLongPress: Effect.fn("scenario.pinFromLongPress")(function* (ctx: ScenarioContext) { const title = `Pin target ${(yield* uuid).slice(0, 6)}`; const target = yield* ctx.env.launch(title, "Hi. [[eval:reply]]"); yield* ctx.env.settled(target); yield* waitForRow(ctx, title); // A just-inserted row can swallow the first long-press while it animates in. for (let attempt = 0; attempt < 2; attempt++) { yield* ctx.device.longPress(rowSelector(title)); yield* Effect.sleep("1 second"); if ((yield* ctx.device.nodes).some((node) => node.label === "Pin")) break; } yield* ctx.device.press('label="Pin"'); yield* Effect.sleep("2 seconds"); const shell = yield* ctx.env.shell(); const pinned = shell.threads .filter((thread) => thread.pinnedAt != null) .map((thread) => thread.id); for (const id of pinned) yield* ctx.env.unpin(id); return { targetPinned: pinned.includes(target), otherPinned: pinned.filter((id) => id !== target).length, } satisfies Metrics; }, failure), /** Opens a link to a thread created after the app loaded its list. */ linkToNewThread: Effect.fn("scenario.linkToNewThread")(function* (ctx: ScenarioContext) { const threadId = yield* ctx.env.launch("Linked thread", "Hi. [[eval:reply]]"); yield* ctx.device.open(threadPath(ctx, threadId)); yield* Effect.sleep("4 seconds"); const after = yield* ctx.device.state; return { opensTarget: isThread(after, threadId) } satisfies Metrics; }, failure), /** Opens a link to an archived thread. */ linkToArchivedThread: Effect.fn("scenario.linkToArchivedThread")(function* ( ctx: ScenarioContext, ) { const threadId = yield* ctx.env.launch("Archived thread", "Hi. [[eval:reply]]"); yield* ctx.env.settled(threadId); yield* ctx.env.archive(threadId); yield* Effect.sleep("1 second"); yield* ctx.device.open(threadPath(ctx, threadId)); yield* Effect.sleep("4 seconds"); const after = yield* ctx.device.state; return { opensTarget: isThread(after, threadId) } satisfies Metrics; }, failure), /** Taps a row on Home. */ openFromList: Effect.fn("scenario.openFromList")(function* (ctx: ScenarioContext) { const title = `Open me ${(yield* uuid).slice(0, 6)}`; const target = yield* ctx.env.launch(title, "Hi. [[eval:reply]]"); yield* ctx.env.settled(target); yield* waitForRow(ctx, title); // A just-inserted row animates in, and a tap during that misses it. yield* Effect.sleep("1 second"); yield* ctx.device.press(rowSelector(title)); const after = yield* ctx.device .waitFor("the tapped thread", (state) => isThread(state, target)) .pipe(Effect.option); return { opensTarget: after._tag === "Some" } satisfies Metrics; }, failure), /** On a folded Duo: open a thread from the list, go back, and open another. */ duoBackThenOpen: Effect.fn("scenario.duoBackThenOpen")(function* (ctx: ScenarioContext) { const tag = (yield* uuid).slice(0, 6); const first = yield* ctx.env.launch(`Duo first ${tag}`, "Hi. [[eval:reply]]"); const next = yield* ctx.env.launch(`Duo next ${tag}`, "Hi. [[eval:reply]]"); yield* ctx.env.settled(first); yield* ctx.env.settled(next); yield* waitForRow(ctx, `Duo first ${tag}`); yield* ctx.device.press(rowSelector(`Duo first ${tag}`)); yield* ctx.device.waitFor("the first thread", (state) => isThread(state, first)); yield* ctx.device.back; yield* ctx.device.waitFor("Home", (state) => state.route?.name === "Home"); yield* ctx.device.press(rowSelector(`Duo next ${tag}`)); yield* Effect.sleep("2 seconds"); const after = yield* ctx.device.state; // A thread can mount in a hidden column, so its title must sit inside the visible screen. const nodes = yield* ctx.device.nodes; const screen = nodes[0]?.rect; // The header title is a text node inside a navigation bar; a Home row with the title is not. const bars = nodes.flatMap((node) => node.kind === "navigation-bar" && node.rect ? [node.rect] : [], ); const title = nodes.find( (node) => node.label === `Duo next ${tag}` && bars.some((bar) => node.rect && node.rect.y >= bar.y && node.rect.y < bar.y + bar.height), )?.rect; return { opensTarget: isThread(after, next), titleOnScreen: screen !== undefined && title !== undefined && title.x >= screen.x && title.x + title.width <= screen.x + screen.width, } satisfies Metrics; }, failure), } satisfies Record<string, Scenario>; export type ScenarioName = keyof typeof SCENARIOS; /** Row rects are relative to their list, so rows are tapped by label, not by point. */ function rowSelector(title: string) { return `label="${title}"`; } /** Waits until fling momentum ends: the feed's offset holds still across half a second. */ const waitForStill = Effect.fn("scenario.waitForStill")(function* (ctx: ScenarioContext) { let previous = -1; for (let attempt = 0; attempt < 20; attempt++) { const scroll = (yield* ctx.device.state).feed?.scroll ?? -1; if (scroll === previous) return; previous = scroll; yield* Effect.sleep("500 millis"); } }); /** Largest distance from the end on frames where the content did not just grow. */ function settledFromEnd(samples: ReadonlyArray<FeedSample>) { let worst = 0; for (let index = 1; index < samples.length; index++) if (samples[index]!.content === samples[index - 1]!.content) worst = Math.max(worst, samples[index]!.fromEnd ?? 0); return worst; } /** Waits until a row with this title is on screen. */ const waitForRow = Effect.fn("scenario.waitForRow")(function* ( ctx: ScenarioContext, title: string, ) { for (let attempt = 0; attempt < 20; attempt++) { const nodes = yield* ctx.device.nodes; if (nodes.some((node) => node.label?.includes(title))) return; // A crowded list can hold the new row below the fold; scroll to the top once. if (attempt === 4) yield* ctx.device.run(["scroll", "top"]).pipe(Effect.ignore); // A finished row can stay folded in the Working shelf; open it once if it is collapsed. const shelf = nodes.find((node) => /^\d+ working threads?$/.test(node.label ?? "")); const collapsed = (yield* ctx.device.state).homeList?.some( (entry) => entry.type === "v2-working-shelf" && entry.expanded === false, ); if (attempt === 10 && collapsed && shelf?.label) yield* ctx.device.press(`label="${shelf.label}"`); yield* Effect.sleep("500 millis"); } return yield* new ScenarioFailure({ message: `Row "${title}" never appeared on Home.` }); }); function shelfCount(state: ProbeState) { return state.homeList?.find((entry) => entry.type === "v2-working-shelf")?.count ?? 0; } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |