{"data":{"slug":"github-microsoft-playwright-claude-skills-playwright-test-results-b18fb8b7c8a8","title":"Query Playwright Test Results with SQL","summary":"Use SQL to analyze Playwright CI test results stored in a DuckDB database. Identify flaky tests, failure rates, and performance issues. The database is refreshed every few hours and contains one row per test result, including metadata like run details, test status, and duration.","url":"https:\/\/skillshunter.net\/skills\/github-microsoft-playwright-claude-skills-playwright-test-results-b18fb8b7c8a8","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-microsoft-playwright-claude-skills-playwright-test-results-b18fb8b7c8a8","markdown_url":"https:\/\/skillshunter.net\/skills\/github-microsoft-playwright-claude-skills-playwright-test-results-b18fb8b7c8a8.md","download_url":"https:\/\/skillshunter.net\/skills\/github-microsoft-playwright-claude-skills-playwright-test-results-b18fb8b7c8a8\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before querying, ensure you have installed dependencies by running `npm ci` from the repo root. Use the `update` command to download the latest snapshot and ingest new test results, or `download` to refresh the snapshot without ingesting. The database must not be deleted to avoid exhausting the GitHub API request budget.","instructions":"---\nname: playwright-test-results\ndescription: Query Playwright CI test results from the aggregated DuckDB database. Answers questions about flaky tests, failure rates, slow tests, and per-run\/SHA\/PR results without hunting through GitHub artifacts.\nuser_invocable: true\n---\n\n# Playwright Test Results (DuckDB)\n\nA single DuckDB file holds recent Playwright CI test results, so you can answer\nquestions about failures, flakiness, and slow tests with plain SQL. It is\nrefreshed every few hours.\n\n## Get the database\n\nDownload the latest snapshot and top it up with the newest runs:\n\n```bash\nnpm ci                       # first time only, from the repo root\nGITHUB_TOKEN=$(gh auth token) node utils\/test-results-db\/cli.ts update --lookback-days 3\n```\n\n`update` downloads the snapshot first when there is no local database, then\ningests only the artifacts the snapshot lacks. Never delete the database to\nrebuild it: every artifact costs one GitHub API request, the budget is shared\nby every workflow in the repository, and a rebuild of a few days exhausts it.\nTo only refresh the snapshot without ingesting, run `download`.\n\nQuery it through the bundled `@duckdb\/node-api` binding \u2014 no separate DuckDB\ninstall needed, it ships in `node_modules` after `npm ci`:\n\n```bash\nnode --input-type=module -e '\nimport { DuckDBInstance } from \"@duckdb\/node-api\";\nconst conn = await (await DuckDBInstance.create(\"utils\/test-results-db\/test-results.duckdb\")).connect();\nconsole.table((await conn.runAndReadAll(process.argv[1])).getRowObjectsJson());\n' \"SELECT count(*) FROM test_results\"\n```\n\nInteger columns come back as strings (JSON-safe), so do ranking and filtering\nin SQL, not in JS.\n\n## Schema\n\nSingle table `test_results`, one row per test result (**one row per retry**).\nThe columns are inferred from the parquet the reporter emits\n(`tests\/config\/parquetReporter.ts`), plus two trailing columns this CLI adds:\n\n| Column | Meaning |\n| --- | --- |\n| `run_id`, `run_attempt` | GitHub Actions run identity |\n| `run_started_at` | when the run started |\n| `workflow_name` | e.g. `tests 1` \/ `tests 2` \/ `tests others` \/ `MCP` |\n| `event` | `push` \/ `pull_request` |\n| `head_sha`, `head_branch`, `pr_number` | what was tested |\n| `bot_name` | e.g. `chromium-ubuntu-22.04-node20`, `webkit-macos-15-large` \u2014 the CI bot. **OS and arch are encoded here**; there is no separate os column. |\n| `project_name` | CI project = browser + suite, e.g. `chromium-page`, `webkit-library`, `playwright-test` |\n| `test_title` | title path within the file, joined by ` \u203a ` (`describe \u203a test`) |\n| `file`, `line`, `column_number` | source location (file is relative to repo root) |\n| `expected_status` | `passed` \/ `skipped` \/ ... |\n| `status` | actual result: `passed` \/ `failed` \/ `timedOut` \/ `skipped` \/ `interrupted` |\n| `retry` | 0 = first attempt |\n| `result_started_at` | when this attempt started |\n| `duration_ms` | result duration |\n| `error_message` | all errors joined, ANSI-stripped (NULL when none) |\n| `tags` | **list** of strings, e.g. `['@slow', '@flaky']` (use list functions \/ `list_contains`) |\n| `annotations` | list of `{type, description}` structs, e.g. `[{'type': 'skip', 'description': 'flaky on CI'}]` (empty list when none) |\n| `artifact_id` | the GitHub artifact this row came from (dedupe key) |\n| `ingested_at` | debug only \u2014 when this row was imported |\n\nNotes:\n- **A test is identified by `(project_name, file, test_title)`** \u2014 group on that\n  tuple. (Playwright's `test_id` hash is deliberately not stored; those three\n  columns are its pre-image.)\n- **Flakiness is derived**, not stored. The signal that matters most is\n  **cross-run**: a test whose *final* verdict (after retries) flips between\n  runs \u2014 green in some, red in others. A separate **within-run** flake is a\n  test a retry rescued inside a single run (`failed`\u2192`passed`).\n- **Real failures vs intentional ones:** filter `expected_status = 'passed'`.\n  Tests marked `test.fail()` record `status='failed'` *with*\n  `expected_status='failed'` and would otherwise dominate any \"most failing\" list.\n- The db is size-capped by **run count**: the oldest whole runs are evicted over\n  time, so it holds a recent window, not full history.\n\n## Example queries\n\nGroup tests by `(project_name, file, test_title)` and (for failure\/flakiness)\nscope to `expected_status = 'passed'` so intentional `test.fail()` tests don't\nskew the results.\n\n**Flaky across runs** \u2014 the test's final verdict flips between runs (this is\nwhat makes a red CI run ambiguous). `least(failed_runs, passed_runs)` ranks\ngenuinely bimodal tests above both always-broken and one-off failures:\n\n```sql\nWITH per_run AS (\n  SELECT project_name, file, test_title, run_id, run_attempt,\n         arg_max(status, retry) AS final_status,\n         any_value(expected_status) AS expected\n  FROM test_results\n  GROUP BY project_name, file, test_title, run_id, run_attempt)\nSELECT project_name, test_title,\n       count(*) AS runs,\n       count(*) FILTER (WHERE final_status IN ('failed','timedOut')) AS failed_runs,\n       count(*) FILTER (WHERE final_status = 'passed') AS passed_runs,\n       round(100.0 * count(*) FILTER (WHERE final_status IN ('failed','timedOut'))\n             \/ count(*), 1) AS fail_pct\nFROM per_run\nWHERE expected = 'passed'\nGROUP BY project_name, test_title\nHAVING failed_runs > 0 AND passed_runs > 0 AND runs >= 10\nORDER BY least(failed_runs, passed_runs) DESC, failed_runs DESC\nLIMIT 20;\n```\n\n**Filter by tag** (`tags` is a list, not a string):\n\n```sql\nSELECT project_name, test_title, count(*) AS runs\nFROM test_results\nWHERE list_contains(tags, '@slow')\nGROUP BY project_name, test_title\nORDER BY runs DESC\nLIMIT 20;\n```\n\n## Generate a linked emoji run history\n\nFor a compact result that drops straight into a GitHub comment, render each\nfinal run verdict as a linked square. Edit the four test identity fields, then\nrun:\n\n```bash\nnode --input-type=module <<'EOF'\nimport { DuckDBInstance } from \"@duckdb\/node-api\";\n\nconst repository = \"microsoft\/playwright\";\nconst test = {\n  projectName: \"firefox-library\",\n  file: \"library\/proxy.spec.ts\",\n  testTitle: \"should exclude patterns\",\n  botName: \"firefox-macos-15-large\",\n};\n\nconst conn = await (await DuckDBInstance.create(\n  \"utils\/test-results-db\/test-results.duckdb\"\n)).connect();\nconst result = await conn.runAndReadAll(`\n  WITH per_run AS (\n    SELECT run_id, run_attempt,\n           any_value(run_started_at) AS run_started_at,\n           arg_max(status, retry) AS final_status,\n           arg_max(expected_status, retry) AS expected_status,\n           list(status ORDER BY retry) AS attempt_statuses\n    FROM test_results\n    WHERE project_name = $projectName\n      AND file = $file\n      AND test_title = $testTitle\n      AND bot_name = $botName\n    GROUP BY run_id, run_attempt\n  )\n  SELECT run_id, run_attempt, final_status, attempt_statuses\n  FROM per_run\n  WHERE expected_status = 'passed'\n    AND final_status IN ('passed', 'failed', 'timedOut')\n  ORDER BY run_started_at, run_id, run_attempt\n`, test);\n\nconst markdown = result.getRowObjectsJson().map(row => {\n  const rescued = row.final_status === \"passed\" &&\n    row.attempt_statuses.some(status => status === \"failed\" || status === \"timedOut\");\n  const emoji = rescued ? \"\ud83d\udfe7\" : row.final_status === \"passed\" ? \"\ud83d\udfe9\" : \"\ud83d\udfe5\";\n  const url = `https:\/\/github.com\/${repository}\/actions\/runs\/${row.run_id}\/attempts\/${row.run_attempt}`;\n  return `[${emoji}](${url})`;\n}).join(\"\");\n\nconsole.log(markdown);\nEOF\n```\n\nThe output is Markdown:\n\n```markdown\n[\ud83d\udfe9](https:\/\/github.com\/microsoft\/playwright\/actions\/runs\/123\/attempts\/1)[\ud83d\udfe7](https:\/\/github.com\/microsoft\/playwright\/actions\/runs\/456\/attempts\/1)[\ud83d\udfe5](https:\/\/github.com\/microsoft\/playwright\/actions\/runs\/789\/attempts\/1)\n```\n\nEach square is one workflow run attempt, oldest first. Green means passed,\norange means a retry rescued an earlier failure, and red means failed or timed\nout. `arg_max(status, retry)` picks the final verdict after retries, while\ngrouping by `(run_id, run_attempt)` keeps retries from turning into extra\nsquares. The `\/attempts\/<n>` URL links to the exact rerun that produced the\nresult.\n\n## Fetching the full detail\n\nThe db stores per-result summaries. For the full step tree \/ attachments \/ stdio,\nfetch the original blob report for that run, if the run uploaded one. A row\nidentifies it by `run_id` + `bot_name`: the run's blob artifact is named\n`blob-report-<bot_name>`.\n\n```bash\n# List the run's blob artifacts and find the one for this bot_name:\ngh api \/repos\/microsoft\/playwright\/actions\/runs\/<run_id>\/artifacts \\\n  --jq '.artifacts[] | select(.name | startswith(\"blob-report\")) | {id, name}'\n\n# Download it (name == \"blob-report-<bot_name>\"):\ngh api \/repos\/microsoft\/playwright\/actions\/artifacts\/<artifact_id>\/zip > blob.zip\n```\n\nBlob and parquet artifacts have a 7-day retention, so this works only for recent\nruns; the db itself retains summaries longer (until run-count eviction).\n","use_cases":["Identify flaky tests that fail intermittently across runs","Analyze failure rates for specific test files or projects","Detect slow tests based on duration metrics","Generate a linked emoji run history for a test in a GitHub comment"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/microsoft\/playwright\/blob\/b4d016aadc5cbd2b898a284307975fe73e05483d\/.claude\/skills\/playwright-test-results\/SKILL.md","source_commit":"b4d016aadc5cbd2b898a284307975fe73e05483d","license":null,"version":null,"listing_approved_at":"2026-11-21","created_at":"2026-11-20T13:33:57.000000Z","updated_at":"2026-11-21T09:43:53.000000Z","seo_title":"Query Playwright Test Results with SQL","seo_description":"Analyze Playwright CI test results using SQL queries on a DuckDB database. Identify flaky tests, failure rates, and performance issues. The database is refreshed everyfew","seo_keywords":["Playwright test results","CI test analysis","SQL test query","Flaky test detection","Test failure analysis","DuckDB test database","GitHub Actions test results"]}}