High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: add --tab support to upload and download commands
Luigi Agostidf0e4642f828
diff --git a/cmd/pinchtab/cmd_cli_browser_inspect.go b/cmd/pinchtab/cmd_cli_browser_inspect.goindex a307c2e3..14b978d0 100644--- a/cmd/pinchtab/cmd_cli_browser_inspect.go+++ b/cmd/pinchtab/cmd_cli_browser_inspect.go@@ -221,7 +221,7 @@ var downloadCmd = &cobra.Command{Run: func(cmd *cobra.Command, args []string) {args[0] = urls.Normalize(args[0])runCLI(func(rt cliRuntime) {- browseractions.Download(rt.client, rt.base, rt.token, args, stringFlag(cmd, "output"))+ browseractions.Download(rt.client, rt.base, rt.token, args, stringFlag(cmd, "output"), stringFlag(cmd, "tab"))})},}@@ -232,7 +232,7 @@ var uploadCmd = &cobra.Command{Args: cobra.MinimumNArgs(1),Run: func(cmd *cobra.Command, args []string) {runCLI(func(rt cliRuntime) {- browseractions.Upload(rt.client, rt.base, rt.token, args, stringFlag(cmd, "selector"))+ browseractions.Upload(rt.client, rt.base, rt.token, args, stringFlag(cmd, "selector"), stringFlag(cmd, "tab"))})},}diff --git a/cmd/pinchtab/cmd_cli_register.go b/cmd/pinchtab/cmd_cli_register.goindex 1f8eee02..ecb1ffbf 100644--- a/cmd/pinchtab/cmd_cli_register.go+++ b/cmd/pinchtab/cmd_cli_register.go@@ -242,6 +242,8 @@ func configureBrowserFlags() {scrollCmd,selectCmd,evalCmd,+ uploadCmd,+ downloadCmd,checkCmd,uncheckCmd,keyboardTypeCmd,diff --git a/internal/cli/actions/actions_download.go b/internal/cli/actions/actions_download.goindex 5530254b..5f78c91f 100644--- a/internal/cli/actions/actions_download.go+++ b/internal/cli/actions/actions_download.go@@ -15,9 +15,9 @@ import (const downloadDataPreviewLimit = 256-func Download(client *http.Client, base, token string, args []string, output string) {+func Download(client *http.Client, base, token string, args []string, output, tabID string) {if len(args) < 1 {- cli.Fatal("Usage: pinchtab download <url> [-o <file>]")+ cli.Fatal("Usage: pinchtab download <url> [-o <file>] [--tab <id>]")}targetURL := args[0]@@ -25,7 +25,12 @@ func Download(client *http.Client, base, token string, args []string, output strparams := url.Values{}params.Set("url", targetURL)- body := apiclient.DoGetRaw(client, base, token, "/download", params)+ path := "/download"+ if tabID != "" {+ path = "/tabs/" + url.PathEscape(tabID) + "/download"+ }++ body := apiclient.DoGetRaw(client, base, token, path, params)if body == nil {return}diff --git a/internal/cli/actions/actions_download_test.go b/internal/cli/actions/actions_download_test.goindex 90d67a43..3fd06192 100644--- a/internal/cli/actions/actions_download_test.go+++ b/internal/cli/actions/actions_download_test.go@@ -15,7 +15,7 @@ func TestDownloadTruncatesPrintedBase64(t *testing.T) {defer m.close()output := captureStdout(t, func() {- Download(m.server.Client(), m.base(), "", []string{"https://example.com/image.png"}, "")+ Download(m.server.Client(), m.base(), "", []string{"https://example.com/image.png"}, "", "")})if !strings.Contains(output, `"dataTruncated": true`) {@@ -42,7 +42,7 @@ func TestDownloadWithOutputSavesDecodedFileAndTruncatesPrintedBase64(t *testing.outFile := filepath.Join(t.TempDir(), "image.bin")output := captureStdout(t, func() {- Download(m.server.Client(), m.base(), "", []string{"https://example.com/image.png"}, outFile)+ Download(m.server.Client(), m.base(), "", []string{"https://example.com/image.png"}, outFile, "")})written, err := os.ReadFile(outFile)@@ -62,3 +62,17 @@ func TestDownloadWithOutputSavesDecodedFileAndTruncatesPrintedBase64(t *testing.t.Fatalf("expected output to avoid printing the full base64 payload")}}++func TestDownloadTabScopedPath(t *testing.T) {+ m := newMockServer()+ m.response = `{"data":"","contentType":"text/plain","size":0}`+ defer m.close()++ captureStdout(t, func() {+ Download(m.server.Client(), m.base(), "", []string{"https://example.com/f.txt"}, "", "tab1")+ })++ if m.lastPath != "/tabs/tab1/download" {+ t.Fatalf("expected /tabs/tab1/download, got %s", m.lastPath)+ }+}diff --git a/internal/cli/actions/actions_upload.go b/internal/cli/actions/actions_upload.goindex 2c11fac0..19c6627a 100644--- a/internal/cli/actions/actions_upload.go+++ b/internal/cli/actions/actions_upload.go@@ -3,15 +3,16 @@ package actionsimport ("encoding/base64""net/http"+ "net/url""os""github.com/pinchtab/pinchtab/internal/cli""github.com/pinchtab/pinchtab/internal/cli/apiclient")-func Upload(client *http.Client, base, token string, args []string, selector string) {+func Upload(client *http.Client, base, token string, args []string, selector, tabID string) {if len(args) < 1 {- cli.Fatal("Usage: pinchtab upload <file-path> [--selector <css>]")+ cli.Fatal("Usage: pinchtab upload <file-path> [--selector <css>] [--tab <id>]")}var files []string@@ -30,5 +31,10 @@ func Upload(client *http.Client, base, token string, args []string, selector strbody["selector"] = selector}- apiclient.DoPost(client, base, token, "/upload", body)+ path := "/upload"+ if tabID != "" {+ path = "/tabs/" + url.PathEscape(tabID) + "/upload"+ }++ apiclient.DoPost(client, base, token, path, body)}diff --git a/internal/cli/actions/actions_upload_test.go b/internal/cli/actions/actions_upload_test.gonew file mode 100644index 00000000..b02e0fa5--- /dev/null+++ b/internal/cli/actions/actions_upload_test.go@@ -0,0 +1,43 @@+package actions++import (+ "os"+ "path/filepath"+ "testing"+)++func TestUploadDefaultPath(t *testing.T) {+ m := newMockServer()+ defer m.close()++ f := filepath.Join(t.TempDir(), "doc.txt")+ if err := os.WriteFile(f, []byte("hello"), 0600); err != nil {+ t.Fatalf("write fixture: %v", err)+ }++ captureStdout(t, func() {+ Upload(m.server.Client(), m.base(), "", []string{f}, "#file", "")+ })++ if m.lastPath != "/upload" {+ t.Fatalf("expected /upload, got %s", m.lastPath)+ }+}++func TestUploadTabScopedPath(t *testing.T) {+ m := newMockServer()+ defer m.close()++ f := filepath.Join(t.TempDir(), "doc.txt")+ if err := os.WriteFile(f, []byte("hello"), 0600); err != nil {+ t.Fatalf("write fixture: %v", err)+ }++ captureStdout(t, func() {+ Upload(m.server.Client(), m.base(), "", []string{f}, "#file", "tab1")+ })++ if m.lastPath != "/tabs/tab1/upload" {+ t.Fatalf("expected /tabs/tab1/upload, got %s", m.lastPath)+ }+}