Skip to content

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

fix(cli): declare the json flag on instance list, not only on the deprecated alias

Luigi Agosti1f33bad8081a
diff --git a/cmd/pinchtab/cmd_cli_instance_test.go b/cmd/pinchtab/cmd_cli_instance_test.go
index 4abd18c5..ac9f619d 100644
--- a/cmd/pinchtab/cmd_cli_instance_test.go
+++ b/cmd/pinchtab/cmd_cli_instance_test.go
@@ -2,11 +2,13 @@ package main
import (
"bytes"
+ "sort"
"strings"
"testing"
"github.com/pinchtab/pinchtab/internal/cli"
"github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
func instanceSubcommand(t *testing.T, name string) *cobra.Command {
@@ -137,3 +139,30 @@ func TestExecutePrintsAnErrorOnlyWhenCobraDidNot(t *testing.T) {
})
}
}
+
+func flagNames(cmd *cobra.Command) []string {
+ var names []string
+ cmd.Flags().VisitAll(func(f *pflag.Flag) {
+ names = append(names, f.Name)
+ })
+ sort.Strings(names)
+ return names
+}
+
+// listInstances forwards the INVOKED command to the action, so every flag the
+// action reads has to be declared on both spellings — sharing the Run body does
+// not share the flags. The --json flag was declared only on the alias, which
+// left the documented `pinchtab instance list --json` failing with "unknown
+// flag" while the deprecated spelling kept working.
+func TestBothInstanceListSpellingsExposeTheSameFlags(t *testing.T) {
+ canonical := flagNames(instanceSubcommand(t, "list"))
+ alias := flagNames(instancesCmd)
+
+ if len(canonical) == 0 {
+ t.Fatal("pinchtab instance list declares no flags at all; this guard would pass vacuously")
+ }
+ if strings.Join(canonical, ",") != strings.Join(alias, ",") {
+ t.Errorf("the two spellings of the listing accept different flags:\n instance list = %v\n instances = %v\nA flag on only one of them breaks whichever spelling the docs tell people to run.",
+ canonical, alias)
+ }
+}
diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.go
index bb0d43a3..1a4ed0d8 100644
--- a/cmd/pinchtab/cmd_cli_register.go
+++ b/cmd/pinchtab/cmd_cli_register.go
@@ -425,7 +425,9 @@ func configureManagementFlags() {
activityCmd.PersistentFlags().Int("limit", 200, "Maximum number of events to return")
activityCmd.PersistentFlags().Int("age-sec", 0, "Only include events from the last N seconds")
- instancesCmd.Flags().Bool("json", false, "Output full JSON response instead of terse status")
+ // Both spellings share one implementation, and listInstances forwards the
+ // INVOKED command to the action, so the flag has to exist on each of them.
+ addJSONFlag(instancesCmd, instanceListCmd)
profilesCmd.Flags().Bool("json", false, "Output full JSON response instead of terse status")
profilesPruneCmd.Flags().Bool("confirm", false, "Actually remove the quarantined profiles (without it, nothing is deleted)")
diff --git a/tests/e2e/scenarios/cli/browser-basic.sh b/tests/e2e/scenarios/cli/browser-basic.sh
index af1351a7..c6301844 100644
--- a/tests/e2e/scenarios/cli/browser-basic.sh
+++ b/tests/e2e/scenarios/cli/browser-basic.sh
@@ -14,14 +14,20 @@ assert_output_contains "ok" "returns ok status"
end_test
# ─────────────────────────────────────────────────────────────────
-start_test "pinchtab instances"
+start_test "pinchtab instance list"
-pt_ok instances --json
+pt_ok instance list --json
assert_output_json
# Output is an array like [{id:..., status:...}], check for instance properties
assert_output_contains "id" "returns instance id"
assert_output_contains "status" "returns instance status"
+# The pre-rename spelling stays runnable for existing scripts, so it is exercised
+# here rather than only asserted on the command tree.
+pt_ok instances --json
+assert_output_json
+assert_output_contains "id" "deprecated alias still returns instance ids"
+
end_test
# ─────────────────────────────────────────────────────────────────
diff --git a/tests/soak/setup.sh b/tests/soak/setup.sh
index 72bab243..ff336a9e 100755
--- a/tests/soak/setup.sh
+++ b/tests/soak/setup.sh
@@ -70,7 +70,7 @@ sleep 3
docker exec "$CONTAINER" sh -c "
echo '[soak] ready:'
pinchtab nav http://localhost:$FIX_PORT/heavy.html >/dev/null 2>&1 && echo ' heavy nav OK'
- echo \" instance: \$(pinchtab instances 2>&1 | head -1)\"
+ echo \" instance: \$(pinchtab instance list 2>&1 | head -1)\"
echo \" maxTabs=\$(pinchtab config get instanceDefaults.maxTabs) fixtures=http://localhost:$FIX_PORT\"
"
echo "[soak] container '$CONTAINER' ready. Run: CONTAINER=$CONTAINER FIX_PORT=$FIX_PORT tests/soak/soak.sh 3600"