High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat(a11y): add 'pinchtab a11y audit' CLI command with --axe/--tags/--rules/--json (PIN-397)
Luigi Agosti132852582974
diff --git a/cmd/pinchtab/cmd_cli_a11y.go b/cmd/pinchtab/cmd_cli_a11y.gonew file mode 100644index 00000000..077d8a2c--- /dev/null+++ b/cmd/pinchtab/cmd_cli_a11y.go@@ -0,0 +1,45 @@+package main++import (+ browseractions "github.com/pinchtab/pinchtab/internal/cli/actions"+ "github.com/spf13/cobra"+)++// a11yCmd is a bare group: the shared unknown-subcommand guard installs its+// argument validator and help action, so setting Args or RunE here would opt it+// out of the refusal that names its subcommands.+var a11yCmd = &cobra.Command{+ Use: "a11y",+ Short: "Accessibility auditing",+ Long: "Accessibility auditing. Subcommand: audit — score the page and list violations (native engine, or axe-core with --axe).",+}++var a11yAuditCmd = &cobra.Command{+ Use: "audit",+ Short: "Audit the current page for accessibility issues",+ Long: `Audit the current page for accessibility issues.++The default native engine scores the page over the accessibility snapshot. Pass+--axe to run vendored axe-core in the page instead: it returns industry rule ids+(image-alt, label, color-contrast, …) with WCAG tags, help URLs and, where a+failing element maps to a snapshot ref, that ref — so you can act on it with+'pinchtab action'. Filter an axe run with --tags (WCAG tag list) or --rules (a+rule-id allowlist).`,+ Args: cobra.NoArgs,+ Run: func(cmd *cobra.Command, args []string) {+ runCLI(func(rt cliRuntime) {+ browseractions.A11yAudit(rt.client, rt.base, rt.token, cmd)+ })+ },+}++func configureA11yFlags() {+ a11yAuditCmd.Flags().Bool("axe", false, "Run the axe-core engine instead of the native scan (engine=axe)")+ a11yAuditCmd.Flags().String("engine", "", "Audit engine: native (default) or axe")+ a11yAuditCmd.Flags().String("tags", "", "axe: comma list of WCAG tags to run, e.g. wcag2a,wcag2aa,best-practice")+ a11yAuditCmd.Flags().String("rules", "", "axe: comma list of rule ids to run (allowlist)")+ a11yAuditCmd.Flags().Bool("include-incomplete", false, "axe: include rules axe could not decide (incomplete)")+ a11yAuditCmd.Flags().String("selector", "", "Scope the audit to a CSS selector")+ a11yAuditCmd.Flags().String("tab", "", "Target tab ID")+ a11yAuditCmd.Flags().Bool("json", false, "Output raw JSON")+}diff --git a/cmd/pinchtab/cmd_cli_a11y_test.go b/cmd/pinchtab/cmd_cli_a11y_test.gonew file mode 100644index 00000000..47bb2889--- /dev/null+++ b/cmd/pinchtab/cmd_cli_a11y_test.go@@ -0,0 +1,29 @@+package main++import "testing"++// The axe engine and its filters must be reachable from the CLI: 'a11y audit'+// wires the flags the endpoint reads, and the subcommand hangs off the a11y+// group so 'pinchtab a11y audit' resolves.+func TestA11yAuditCommandRegistersEngineFlags(t *testing.T) {+ for _, name := range []string{"axe", "engine", "tags", "rules", "include-incomplete", "selector", "tab", "json"} {+ if a11yAuditCmd.Flags().Lookup(name) == nil {+ t.Errorf("a11y audit missing --%s flag", name)+ }+ }+}++func TestA11yAuditIsRegisteredUnderA11y(t *testing.T) {+ var found bool+ for _, c := range a11yCmd.Commands() {+ if c.Name() == "audit" {+ found = true+ }+ }+ if !found {+ t.Fatal("a11y audit subcommand is not registered under a11yCmd")+ }+ if a11yAuditCmd.Flags().Lookup("axe").DefValue != "false" {+ t.Errorf("--axe default = %q, want false (native is the default engine)", a11yAuditCmd.Flags().Lookup("axe").DefValue)+ }+}diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.goindex e7e92400..ce3d25d4 100644--- a/cmd/pinchtab/cmd_cli_register.go+++ b/cmd/pinchtab/cmd_cli_register.go@@ -27,7 +27,7 @@ func browserRootCommands() []*cobra.Command {downloadCmd, uploadCmd, findCmd, selectCmd, checkCmd, uncheckCmd, networkCmd, waitCmd,keyboardCmd, keydownCmd, keyupCmd, scrollintoviewCmd, dialogCmd, consoleCmd, errorsCmd,clipboardCmd, cacheCmd, cookiesCmd, setCmd, storageCmd, stateCmd, closeCmd, handoffCmd,- resumeCmd, handoffStatusCmd, recordCmd, auditCmd, compareCmd, scrapeCmd,+ resumeCmd, handoffStatusCmd, recordCmd, auditCmd, compareCmd, scrapeCmd, a11yCmd,}}@@ -46,8 +46,10 @@ func registerBrowserCommands() {mouseCmd.AddCommand(mouseMoveCmd, mouseDownCmd, mouseUpCmd, mouseWheelCmd)networkCmd.AddCommand(networkRouteCmd, networkUnrouteCmd, networkRulesCmd)recordCmd.AddCommand(recordStartCmd, recordStopCmd, recordStatusCmd)+ a11yCmd.AddCommand(a11yAuditCmd)configureBrowserFlags()+ configureA11yFlags()addRootCommands(rootCmds...)}diff --git a/internal/cli/actions/actions_a11y.go b/internal/cli/actions/actions_a11y.gonew file mode 100644index 00000000..4011d59b--- /dev/null+++ b/internal/cli/actions/actions_a11y.go@@ -0,0 +1,92 @@+package actions++import (+ "encoding/json"+ "fmt"+ "net/http"+ "net/url"++ "github.com/pinchtab/pinchtab/internal/cli/apiclient"+ "github.com/spf13/cobra"+)++// A11yAudit runs GET /a11y/audit with the engine and filters its flags select,+// printing the full JSON envelope with --json or a short summary otherwise. The+// summary shape follows the engine: axe reports rule ids with impact and refs,+// native reports its scored findings.+func A11yAudit(client *http.Client, base, token string, cmd *cobra.Command) {+ params := url.Values{}+ if v, _ := cmd.Flags().GetString("tab"); v != "" {+ params.Set("tabId", v)+ }+ engine, _ := cmd.Flags().GetString("engine")+ if axe, _ := cmd.Flags().GetBool("axe"); axe {+ engine = "axe"+ }+ if engine != "" {+ params.Set("engine", engine)+ }+ if v, _ := cmd.Flags().GetString("tags"); v != "" {+ params.Set("tags", v)+ }+ if v, _ := cmd.Flags().GetString("rules"); v != "" {+ params.Set("rules", v)+ }+ if inc, _ := cmd.Flags().GetBool("include-incomplete"); inc {+ params.Set("includeIncomplete", "true")+ }+ if v, _ := cmd.Flags().GetString("selector"); v != "" {+ params.Set("selector", v)+ }++ if jsonOutput, _ := cmd.Flags().GetBool("json"); jsonOutput {+ apiclient.DoGet(client, base, token, "/a11y/audit", params)+ return+ }+ printA11ySummary(apiclient.DoGetRaw(client, base, token, "/a11y/audit", params))+}++// printA11ySummary renders a compact human summary for either engine, falling+// back to the raw body when it does not decode.+func printA11ySummary(body []byte) {+ var report struct {+ Engine string `json:"engine"`+ Version string `json:"version"`+ Score int `json:"score"`+ Violations []struct {+ ID string `json:"id"`+ Impact string `json:"impact"`+ Nodes []struct {+ Ref string `json:"ref"`+ } `json:"nodes"`+ } `json:"violations"`+ Findings []struct {+ Rule string `json:"rule"`+ Severity string `json:"severity"`+ Count int `json:"count"`+ } `json:"findings"`+ }+ if err := json.Unmarshal(body, &report); err != nil {+ fmt.Println(string(body))+ return+ }++ if report.Engine == "axe" {+ fmt.Printf("engine=axe version=%s score=%d\n", report.Version, report.Score)+ for _, v := range report.Violations {+ refs := 0+ for _, n := range v.Nodes {+ if n.Ref != "" {+ refs+++ }+ }+ fmt.Printf(" %-24s %-8s nodes=%d refs=%d\n", v.ID, v.Impact, len(v.Nodes), refs)+ }+ return+ }++ fmt.Printf("engine=native score=%d\n", report.Score)+ for _, f := range report.Findings {+ fmt.Printf(" %-24s %-8s count=%d\n", f.Rule, f.Severity, f.Count)+ }+}