Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: align cli failure coverage and screenshot docs

Luigi Agosti7b3ca671d219
diff --git a/cmd/pinchtab/cmd_cli_browser_nav_test.go b/cmd/pinchtab/cmd_cli_browser_nav_test.go
index bf9ce1a4..16b80db6 100644
--- a/cmd/pinchtab/cmd_cli_browser_nav_test.go
+++ b/cmd/pinchtab/cmd_cli_browser_nav_test.go
@@ -4,12 +4,57 @@ import (
"errors"
"net/http"
"net/http/httptest"
+ "os"
+ "os/exec"
"strings"
"testing"
"github.com/spf13/cobra"
)
+func TestNavPolicyDenialExitsOne(t *testing.T) {
+ if os.Getenv("PINCHTAB_NAV_POLICY_HELPER") == "1" {
+ rootCmd.SetArgs([]string{"--server", os.Getenv("PINCHTAB_NAV_POLICY_SERVER"), "nav", "https://example.com"})
+ if err := rootCmd.Execute(); err != nil {
+ os.Exit(commandExitCode(err))
+ }
+ return
+ }
+
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ if r.URL.Path == "/health" {
+ _, _ = w.Write([]byte(`{"status":"ok"}`))
+ return
+ }
+ if r.URL.Path != "/navigate" {
+ t.Errorf("path = %q, want /navigate", r.URL.Path)
+ }
+ w.WriteHeader(http.StatusForbidden)
+ _, _ = w.Write([]byte(`{"error":"navigation blocked by IDPI","code":"idpi_domain_blocked"}`))
+ }))
+ t.Cleanup(srv.Close)
+
+ child := exec.Command(os.Args[0], "-test.run=^TestNavPolicyDenialExitsOne$", "-test.timeout=30s") // #nosec G204 -- re-executes this test binary with fixed arguments.
+ child.Env = append(os.Environ(),
+ "PINCHTAB_NAV_POLICY_HELPER=1",
+ "PINCHTAB_NAV_POLICY_SERVER="+srv.URL,
+ "HOME="+t.TempDir(),
+ "XDG_STATE_HOME="+t.TempDir(),
+ )
+ out, err := child.CombinedOutput()
+ var exitErr *exec.ExitError
+ if !errors.As(err, &exitErr) {
+ t.Fatalf("nav policy denial exited with %v, want exit 1; output:\n%s", err, out)
+ }
+ if exitErr.ExitCode() != 1 {
+ t.Fatalf("exit code = %d, want 1; output:\n%s", exitErr.ExitCode(), out)
+ }
+ if !strings.Contains(string(out), "Error 403: navigation blocked by IDPI") {
+ t.Fatalf("output did not report the policy 403:\n%s", out)
+ }
+}
+
func TestTabHandoffFamilyRefusesLocallyOnAnEmptyTabID(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Errorf("a request was issued for an empty tab id: %s %s — the refusal must happen before the wire, or the mux 404s /tabs//<verb> and the CLI misdiagnoses the server as outdated", r.Method, r.URL.Path)
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index b87fd8fa..f0cddb09 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -119,7 +119,7 @@ func configureBrowserFlags() {
screenshotCmd.Flags().StringP("selector", "s", "", "Element selector to capture (ref/CSS/XPath/text)")
screenshotCmd.Flags().String("scale", "", "Rescale the output image (e.g. 0.5 = half size, 0.25 = quarter). Default 1.")
screenshotCmd.Flags().Bool("annotate", false, "Overlay numbered ref boxes on interactive elements (or on --selector matches). Prints a [n] ref legend to stdout.")
- screenshotCmd.Flags().String("format", "", "Image format: 'jpeg' (default) or 'png'")
+ screenshotCmd.Flags().String("format", "", "Image format: 'jpeg' or 'png' (default: inferred from -o .png, otherwise jpeg)")
screenshotCmd.Flags().Bool("beyond-viewport", false, "Capture the entire scrollable document, not just the visible viewport. Ignored when --selector is set.")
// Back-compat: --css-1x was removed (replaced by --scale). Keep it as a
// deprecated no-op so old scripts get a notice instead of a hard error.
diff --git a/docs/commands.md b/docs/commands.md
index 43fb9596..e2978ddd 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -279,7 +279,8 @@ curl -X POST "$PINCHTAB_SERVER/tabs/<tabId>/resume"
```bash
pinchtab screenshot # Save a screenshot to a generated .jpg path
-pinchtab screenshot -o <path> # Save screenshot to a chosen path
+pinchtab screenshot -o <path> # Save to a chosen path (.png infers PNG; otherwise JPEG)
+pinchtab screenshot --format <jpeg|png> # Override the inferred output format
pinchtab screenshot -q <0-100> # JPEG quality
pinchtab screenshot -s <selector> # Capture a specific element by selector
pinchtab screenshot --scale 0.5 # Half-size output (quarter the pixels)
diff --git a/docs/reference/screenshot.md b/docs/reference/screenshot.md
index 69a16f24..5a9f0b8d 100644
--- a/docs/reference/screenshot.md
+++ b/docs/reference/screenshot.md
@@ -1,6 +1,8 @@
# Screenshot
-Capture the current page as an image. Defaults to **JPEG** format.
+Capture the current page as an image. The API defaults to **JPEG**. The CLI
+uses PNG when `-o` ends in `.png` and JPEG otherwise; an explicit `--format`
+always takes precedence.
```bash
# Get raw PNG bytes
@@ -48,7 +50,8 @@ curl "http://localhost:9867/screenshot?output=file"
### CLI
-- `-o <path>`: Save to specific path.
+- `-o <path>`: Save to a specific path. A `.png` extension selects PNG when `--format` is omitted; other extensions use JPEG.
+- `--format <jpeg|png>`: Explicitly select the image format, overriding extension inference.
- `-q <0-100>`: Set JPEG quality.
- `-s <selector>`: Capture a specific element.
- `--scale <f>`: Bitmap rescale (e.g. `0.5`).
diff --git a/tests/e2e/scenarios/cli/system-extended.sh b/tests/e2e/scenarios/cli/system-extended.sh
index ae013a9d..d7d80410 100644
--- a/tests/e2e/scenarios/cli/system-extended.sh
+++ b/tests/e2e/scenarios/cli/system-extended.sh
@@ -15,6 +15,19 @@ assert_exit_code 1 "connection failure is reported to automation"
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "pinchtab 403 policy denial exits non-zero"
+
+pt network route "*.png" --abort
+assert_exit_code 1 "403 policy denial is reported to automation"
+if echo "$PT_ERR" | grep -q "Error 403"; then
+ pass_assert "policy denial reports HTTP 403"
+else
+ fail_assert "policy denial reports HTTP 403"
+fi
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "pinchtab daemon (non-interactive shows status)"