Keybase e2e tests

From keybase/client · View interactive version

Keybase e2e tests is an AI agent skill from the GitHub repository keybase/client. Use when writing, fixing, or adding e2e flow tests for the Keybase app — desktop (Playwright) or iOS (Appium + WebdriverIO). Covers testID conventions, navigation patterns, common pitfalls, and the two-harness structure.

How to use this skill

Skill file

Keybase E2E Flow Tests

Overview

Two harnesses, one shared testID registry. Implement each flow on Electron and iOS together.

Shared testID Registry

shared/tests/e2e/shared/test-ids.ts — single source of truth for all testID values.

Adding a testID to a component:

import * as TestIDs from '@/tests/e2e/shared/test-ids'
// ...
<Kb.ScrollView testID={TestIDs.SETTINGS_ADVANCED}>

Rule: Add testID prop to an already-existing element (input, scroll view, pre-existing wrapper). Never add a new container just to attach a testID.

Desktop — Playwright

| What | Where |

|------|-------|

| Test files | shared/tests/e2e/electron/flows/*.test.ts |

| Nav helpers | shared/tests/e2e/electron/helpers/navigate.ts |

| Run all | yarn test:e2e:desktop |

| Run branch | yarn test:e2e:desktop:branch |

Navigation helpers: navigateToChat, navigateToFiles, navigateToTeams, navigateToGit, navigateToSettings, navigateToPeople, navigateToCrypto, navigateToDevices

Common pitfall — hidden nav stack elements: React Navigation keeps prior screens mounted but hidden. getByTestId(X) may match 2+ elements (one hidden, one visible), causing Playwright strict-mode failures. Fix: use a selector unique to the destination screen rather than one shared with the source screen. Example: after navigating into a Files subfolder, the root screen's files-browser is still in the DOM but hidden — check for the Filter textbox instead, which only exists in subfolder views.

Desktop release gate

The gate's code lives in tests/e2e/shared/gate/ (shared with the iOS gate); its lists stay in tests/e2e/electron/.

yarn test:e2e:desktop:release (from shared/, about 45 min) runs everything and exits 1 on any failure, a flaky or skipped flow test included (retries stay at 1, so a flake shows as flaky: <test>).

Desktop flow rules

Running while you change things: run one test at a time with yarn test:e2e:desktop:flows <file> --grep '<title>', once. Use --repeat-each=N --retries=0 only on the ONE test whose flake fix you are proving. The full release runs at the end of a change, never between edits. A test stuck for more than about 5 minutes without clear progress gets reported with evidence, not dug into.

Accounts and names: every flow runs on the test accounts from ~/.config/keybase-e2e/env (loadE2EEnv() / loadE2EAccounts()). Never put an account, team, password or paper key in the repo, a step name, an error or a log line. Team writes go only in KB_E2E_TEAM or a stamped subteam. Rows are found by exact name (inboxRow(page, title), openE2ETeam, openE2EChannel), never "first row".

Stamped names: everything a flow creates carries the run id (e2eRunId(), accounts/run-id.ts), so the sweeper can find what a run left behind:

Helpers (tests/e2e/electron/helpers/, tests/e2e/shared/):

Coverage counts only from the app's UI. Setup and read-back through the CLI, the peers or mainRpc are fine, but a census item is closed only when the app sends it. Every new write RPC in protocol/bin/enabled-calls.json, route or window needs a flow (or a tour entry, for routes and windows) or an entry in census-exclusions.ts with a real reason (manual-only: <id> names a MANUAL_ONLY entry). The census fails on an exclusion that is no longer needed, so remove it once a flow covers the item.

Assertions: check the outcome (the row, the setting after a reload, a CLI or peer read-back), never only "the modal opened". A flow that changes a setting reads it first and restores it in finally; a failed restore fails the test. No silent skips (test.skip, conditional early returns): missing setup fails and names what is missing. No blind retries, longer sleeps or soft-passes: retries stay at 1 and a flaky test counts as a failure, so find the cause.

Known failures: a deterministic app or service bug on master gets a strict test of the default user path that fails, plus an entry in known-failures.ts keyed <file> › <describe…> › <title> with its cause. The run still fails, and the report labels it "known" (check that it does: a key that does not match shows as a new failure). When the bug is fixed the report says "known now passes" and the entry is removed. A route-around for the rest of the coverage is a separate test, never a replacement. A strict failing test never goes in a serial describe: its failure and retry would rerun or taint the rest of the group.

Secrets: a password, paper key or provisioning phrase is typed only through submitSecret / secret-input.ts, which type through the main process and read back lengths only, so no Playwright action, assertion, trace or failure snapshot ever holds the value. A file that types a secret sets test.describe.configure({retries: 0}) and test.use({trace: 'off'}). The secret-scan reporter (secret-scan-reporter.ts, and the release's secrets phase) scans every artifact for the env file's secrets, every second-account password the env file held during the run included (the start value, a KB_SECOND_PASSWORD_NEXT, the promoted one; kept in memory only), deletes any file that holds one and fails the run. insertSecret types only into a focused element matching its selector.

The second account's password is the harness's own: KB_SECOND_PASSWORD in the env file, a random value set by yarn test:e2e:accounts:second-password. Read it only with requireSecondPassword. A change goes through rotateSecondPassword: the new value is written as KB_SECOND_PASSWORD_NEXT first, then set, then checkSecondSecretSurvives (repaired once with repairSecondSecret on failure) and only then promoted. A leftover KB_SECOND_PASSWORD_NEXT stops every password flow until the owner checks which value the server holds; never edit the env file by hand. After a file signs second in through the app, or does anything as second that can drop its stored secret, its afterAll runs checkOrRepairSecondSecret(env, requireSecondPassword(env), appRepairDeps(_electronPage)) and its afterEach runs restoreToSmoke. Such a file holds only those tests, so the rest of its area keeps traces and retries. The smoke account's password is never touched.

Paper keys and devices: a paper key a flow makes is recorded in the paper-key ledger (accounts/paper-key-ledger.ts: run id, device id and name, never the words) with recordPaperKey, and removed with forgetPaperKey once revoked; the sweeper revokes only ledger entries. A provisioned device is a new peer home homes/prov-<runid> with the file secret store, stopped with ctl stop --shutdown before it is revoked. Nothing provisions the main service.

iOS gate harness

The iOS release gate's flows run through shared/tests/e2e/ios-appium/gate.test.ts (specs wired in wdio.gate.conf.ts); its helpers are in tests/e2e/ios-appium/gate/, and the gate core it shares with desktop in tests/e2e/shared/gate/.

iOS differs from desktop:

iOS release gate

Same core as the desktop gate (tests/e2e/shared/gate/); the iOS code is tests/e2e/ios-appium/release.mts (with release-lib.ts, release-secrets.mts, launch.mts, census.mts / census-platform.mts, report.mts / report-platform.mts).

yarn test:e2e:ios:release (from shared/) runs everything and exits 1 on any failure, a flaky or skipped flow test included.

iOS chat flows

The chat flows (flows/chat-*.test.ts) run in the gate like every other flow. Seeding is each file's describe-level before(ensureChatData) (20-minute bound on a first run).

A control with no label (the profile's avatar, merged into its avatar-and-name element PROFILE_AVATAR_NAME) is named as {handlerOf: 'onEditIcon'}: the one component whose onClick is the scope's own prop of that name.

Either way, read back the effect, not the call alone.

iOS files, teams and git flows

flows/files-*.test.ts, flows/teams-*.test.ts and flows/git.test.ts run in the gate after the chat flows; teams-second registers last, after the other second-account files.

iOS people, profile, crypto and settings flows

flows/people-*.test.ts, flows/profile-*.test.ts, flows/crypto*.test.ts and flows/settings-*.test.ts run after the files, teams and git flows. settings-persisted runs after the chat unfurl flow; profile-proofs and settings-remember-password run after teams-second; settings-password runs last.

iOS native surfaces

The app-level and native flows (app-deep-links, app-push, app-lifecycle, chat-location, chat-attachments-picker, files-upload, files-save-photos, profile-avatar, teams-avatar-emoji, share-extension) reach outside the app through gate/device.ts (simctl, attempt-checked, udid from preflight) and gate/system-ui.ts (springboard, Notification Center, the photo and document pickers, system alerts). Neither credits anything: a flow calls creditSurface(...) once it has asserted the app used the surface.

iOS — Appium + WebdriverIO (TypeScript)

| Command (from shared/) | What it runs |

|------|-------|

| yarn test:e2e:ios:release | the whole iOS release gate (preflight, launch, sweep, flows, render, census, report, secrets) |

| yarn test:e2e:ios:flows | the gate flows alone (wdio.gate.conf.ts, spec gate.test.ts, one session) |

| yarn test:e2e:ios:census | the census again over the last run's results |

| yarn test:e2e:ios:gate-report | the report again over the last run's results |

| yarn test:e2e:accounts:second-password --check | after a release: the host's stored secret for the second account |

Flow files are shared/tests/e2e/ios-appium/flows/*.test.ts, the gate's helpers ios-appium/gate/, the element and navigation helpers ios-appium/helpers/.

Drives the already-installed app black-box (no rebuild). Selectors: ~<testID> (testID → iOS accessibilityIdentifier). Helpers: el/els/waitForTestID/byText/tab (elements), escapeToTabs/goBack/navigateTo*/scrollDownToText (navigate). escapeToTabs runs before every test (resets to the tab root).

Gotchas (hard-won — read before adding flows):

iOS tab structure: People & Teams are direct tabs; Chat & Files have their own nav helpers; Crypto/Devices/Git/Settings live under the More tab (navigateToMore).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.