Skip to content

feat: add assert commands for test assertions with exit codes#944

Open
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:osc/assert-commands
Open

feat: add assert commands for test assertions with exit codes#944
mvanhorn wants to merge 2 commits intovercel-labs:mainfrom
mvanhorn:osc/assert-commands

Conversation

@mvanhorn
Copy link
Contributor

Summary

Adds an assert command family for verifying expected state in automation pipelines. Each command reuses existing daemon actions and exits with code 1 on failure.

Commands

Command Description
assert visible @ref Assert element is visible
assert hidden @ref Assert element is NOT visible
assert text @ref "expected" Assert element contains text
assert url "**/dashboard" Assert URL matches glob pattern
assert title "Page Title" Assert page title matches
assert enabled @ref Assert element is enabled
assert checked @ref Assert element is checked

Why this matters

The batch command (#865) enables multi-step workflows, but there's no way to verify expected state between steps. The is commands (commands.rs:1690) return true/false as JSON but don't fail the process. Assertions with exit codes are the missing piece for CI/CD and agent pipelines.

Every testing framework (Playwright, Cypress, Selenium) has assertion primitives. This brings the same capability to agent-browser's CLI.

Changes

  • cli/src/commands.rs: New parse_assert function (follows parse_is pattern). Sends same daemon actions with assert: true metadata. Unit tests included.
  • cli/src/main.rs: Assert evaluator intercepts responses before normal output. Prints PASS/FAIL. Glob matcher for URL patterns (* = non-slash, ** = any chars). Exits 1 on failure. Works in batch mode with --bail.
  • cli/src/output.rs: Help text for assert commands.

No new daemon code - reuses isvisible, isenabled, ischecked, gettext, url, and title actions.

Usage

agent-browser open https://example.com/login
agent-browser type @username "admin"
agent-browser click @submit
agent-browser assert url "**/dashboard"
agent-browser assert visible @welcome-banner
agent-browser assert text @greeting "Welcome"

Testing

  • cargo check passes
  • Unit tests for all parse_assert subcommands
  • Glob matcher tested for * and ** patterns

This contribution was developed with AI assistance (Claude Code).

Adds assert visible, hidden, text, url, title, enabled, and checked
commands. Each reuses existing daemon actions (isvisible, gettext, etc.)
and exits with code 1 on failure. Supports glob matching for URL
assertions (* and **). Works in batch mode with --bail.
@vercel
Copy link
Contributor

vercel bot commented Mar 20, 2026

@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines +946 to +949
if !flags.json {
println!("{}", msg);
return;
}
Copy link
Contributor

@vercel vercel bot Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In single-command mode with --json, a passing assert falls through without printing structured JSON output, instead printing the raw daemon response.

Fix on Vercel

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.

1 participant