Skip to content

feat(snapshot): honor --depth=N with landmark nesting#2

Merged
drakulavich merged 1 commit into
mainfrom
feat/snapshot-depth-nesting
May 14, 2026
Merged

feat(snapshot): honor --depth=N with landmark nesting#2
drakulavich merged 1 commit into
mainfrom
feat/snapshot-depth-nesting

Conversation

@drakulavich
Copy link
Copy Markdown
Owner

Summary

  • The snapshot script now emits a path of landmark ancestors (main, navigation, header, footer, section, article, aside, form, dialog, list, region, …) per ref. toYaml renders landmarks as parent nodes and reuses shared prefixes between sibling refs, producing real aria-tree nesting that matches playwright-cli output.
  • --depth=N is honored: --depth=1 reproduces the flat v0.2 output, --depth=2 keeps only the outermost landmark, default (omitted) is unbounded. --depth=0 is rejected with a usage error.
  • Crosses off the next open roadmap item ("Snapshot nesting honoring `--depth=N`") and unblocks the AGENTS.md gotcha that said "flat in v0.2 — fix the parser, not callers, when implementing nesting."
  • Ref.path is optional, so older state.json files from v0.2 keep working and render flat.

Example

A page with a primary nav, a signup form inside <main>, and a footer now renders:

- generic:
  - navigation \"Primary\":
    - link \"Home\": [ref=e1] /
    - link \"About\": [ref=e2] /about
  - main \"\":
    - form \"Sign up\":
      - textbox \"Email\": [ref=e3]
      - button \"Submit\": [ref=e4]
  - contentinfo \"\":
    - link \"Contact\": [ref=e5] /c

bowser snapshot --depth=2 clips that to:

- generic:
  - navigation \"Primary\":
    - link \"Home\": [ref=e1] /
    - link \"About\": [ref=e2] /about
  - main \"\":
    - textbox \"Email\": [ref=e3]
    - button \"Submit\": [ref=e4]
  - contentinfo \"\":
    - link \"Contact\": [ref=e5] /c

Test plan

  • `bun test` — 77 pass / 0 fail / 10 skip
  • Unit golden tests for nested rendering and depth clipping (`tests/snapshot.test.ts`).
  • Command-layer test that `cmdSnapshot` honors `--depth` and rejects `--depth=0` (`tests/commands.test.ts`).
  • `BOWSER_E2E=1 bun test tests/e2e.test.ts tests/e2e-todo.test.ts` against a real headless Chromium — both pass; the existing substring assertions (`'"Add": [ref='`, etc.) still match because leaf lines still end with the same `role "name": [ref=eN]` pattern, just under deeper indentation when relevant.
  • `bun build src/cli.ts --compile` produces a working binary; `--help` still lists `snapshot [--filename=f] [--depth=N]`.
  • (Not run here) live-internet `BOWSER_E2E_NET=1` against github.com.

🤖 Generated with Claude Code

The snapshot script now attaches a `path` of landmark ancestors
(`main`, `navigation`, `header`, `footer`, `section`, `article`,
`aside`, `form`, `dialog`, `list`, `region`, …) to every ref.
`toYaml` renders those landmarks as parent nodes and reuses shared
prefixes between siblings, producing real aria-tree nesting that
matches playwright-cli output.

`--depth=N` clips the path: `--depth=1` reproduces the flat v0.2
output, `--depth=2` keeps only the outermost landmark, default is
unbounded. `--depth=0` is rejected with a usage error.

`Ref.path` is optional in state.json, so older state files without
it continue to render flat.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@drakulavich drakulavich merged commit a475e84 into main May 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants