High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: config get prints an empty line for a derived key, so nobody can ask where their profiles are kept (PIN-165)
Luigi Agosti1119894041f4
diff --git a/docs/reference/config.md b/docs/reference/config.mdindex e7fc7241..0fbf94ff 100644--- a/docs/reference/config.md+++ b/docs/reference/config.md@@ -99,12 +99,18 @@ pinchtab config validate### `pinchtab config get`-Reads a single dotted-path value from the file config.+Reads a single dotted-path value and reports the **value in effect**: what the file+sets, and otherwise the value the runtime resolves — a shipped default, or a value+derived from another key. `profiles.baseDir` is the clearest case: leave it out of the+file and `config get` reports `<server.stateDir>/profiles`, the directory profiles are+actually kept in, rather than nothing. A key that is genuinely unset — a secret nobody+configured, an optional override such as `browser.binary` — still answers blank.```bashpinchtab config get server.portpinchtab config get instanceDefaults.modepinchtab config get security.attach.allowHosts+pinchtab config get profiles.baseDir # derived from server.stateDir when unset```### `pinchtab config set`@@ -715,5 +721,5 @@ Valid enum values:## Notes- `config show` reports effective runtime values, not just raw file contents.-- `config get`, `set`, and `patch` operate on the file config model, not transient runtime overrides.+- `config get` reports the value in effect, including shipped defaults and values derived from another key. `config set` and `patch` write the file config model and do not carry transient runtime overrides.- the dashboard config API treats `server.token` as write-only; use the CLI or file editing to manage it.diff --git a/internal/config/editor_get.go b/internal/config/editor_get.goindex dffdb317..0d4e6ed5 100644--- a/internal/config/editor_get.go+++ b/internal/config/editor_get.go@@ -4,6 +4,8 @@ import ("fmt""strconv""strings"++ "github.com/pinchtab/pinchtab/internal/safelog")// GetConfigValue reads a dotted-path field from FileConfig and returns its string representation.@@ -553,3 +555,34 @@ func getAutoSolverCredentialsField(c *AutoSolverCredentialsConf, field string) (}return "", fmt.Errorf("unknown field autoSolver.credentials.%s", field)}++// EffectiveConfigValue answers with the value in effect for a dotted path: the file+// value when the file sets one, otherwise the value the runtime resolves. Keys whose+// effective value is derived from another key, or whose default is applied by a+// consumer rather than stored in the config struct, are only visible this way.+func EffectiveConfigValue(path string) (string, error) {+ fc, _, err := LoadFileConfig()+ if err != nil {+ return "", fmt.Errorf("load config: %w", err)+ }+ value, err := GetConfigValue(fc, path)+ if err != nil {+ return "", err+ }+ if strings.TrimSpace(value) != "" {+ return value, nil+ }+ return resolvedConfigValue(path)+}++func resolvedConfigValue(path string) (string, error) {+ cfg, _, err := LoadConfig()+ if err != nil {+ return "", fmt.Errorf("load config: %w", err)+ }+ resolved := FileConfigFromRuntime(cfg)+ if strings.TrimSpace(resolved.Server.LogLevel) == "" {+ resolved.Server.LogLevel = safelog.LevelName(safelog.DefaultLevel)+ }+ return GetConfigValue(&resolved, path)+}diff --git a/internal/config/editor_get_effective_test.go b/internal/config/editor_get_effective_test.gonew file mode 100644index 00000000..7be7366f--- /dev/null+++ b/internal/config/editor_get_effective_test.go@@ -0,0 +1,278 @@+package config++import (+ "os"+ "path/filepath"+ "reflect"+ "strings"+ "testing"++ "github.com/pinchtab/pinchtab/internal/safelog"+)++func writeConfigForGet(t *testing.T, body string) string {+ t.Helper()++ path := filepath.Join(t.TempDir(), "config.json")+ if err := os.WriteFile(path, []byte(body), 0o600); err != nil {+ t.Fatalf("WriteFile() error = %v", err)+ }+ t.Setenv("PINCHTAB_CONFIG", path)+ t.Setenv("PINCHTAB_TOKEN", "")+ return path+}++func effectiveValue(t *testing.T, path string) string {+ t.Helper()++ value, err := EffectiveConfigValue(path)+ if err != nil {+ t.Fatalf("EffectiveConfigValue(%q) error = %v", path, err)+ }+ return value+}++func TestEffectiveConfigValueDerivesProfilesBaseDirFromTheConfiguredStateDir(t *testing.T) {+ stateDir := filepath.Join(t.TempDir(), "mystate")+ writeConfigForGet(t, `{"server":{"stateDir":`+quoteJSON(stateDir)+`}}`)++ want := filepath.Join(stateDir, "profiles")+ if got := effectiveValue(t, "profiles.baseDir"); got != want {+ t.Errorf("profiles.baseDir = %q, want %q derived from the configured stateDir", got, want)+ }+ if got := effectiveValue(t, "profiles.baseDir"); strings.HasPrefix(got, userConfigDir()) {+ t.Errorf("profiles.baseDir = %q, which sits under the default state dir rather than the configured one", got)+ }+}++func TestEffectiveConfigValueReportsTheDocumentedLogLevelDefault(t *testing.T) {+ writeConfigForGet(t, `{}`)++ want := safelog.LevelName(safelog.DefaultLevel)+ if got := effectiveValue(t, "server.logLevel"); got != want {+ t.Errorf("server.logLevel = %q, want the default the runtime records at, %q", got, want)+ }+}++func TestEffectiveConfigValueKeepsWhatTheFileSets(t *testing.T) {+ stateDir := filepath.Join(t.TempDir(), "mystate")+ writeConfigForGet(t, `{+ "server": {"stateDir": `+quoteJSON(stateDir)+`, "logLevel": "warn", "trustProxyHeaders": true},+ "profiles": {"baseDir": "/tmp/explicit-profiles"}+ }`)++ for _, tc := range []struct{ path, want string }{+ {"server.logLevel", "warn"},+ {"server.trustProxyHeaders", "true"},+ {"profiles.baseDir", "/tmp/explicit-profiles"},+ {"server.stateDir", stateDir},+ } {+ if got := effectiveValue(t, tc.path); got != tc.want {+ t.Errorf("%s = %q, want the file value %q", tc.path, got, tc.want)+ }+ }+}++// blankIsTheAnswer holds the keys whose blank answer is correct: an unset optional,+// an override with no default, or a secret nobody configured.+var blankIsTheAnswer = map[string]string{+ "server.token": "no token configured and none in PINCHTAB_TOKEN",+ "browser.binary": "unset means discover the browser instead of using a fixed path",+ "browser.extraFlags": "no extra flags",+ "browser.defaultTarget": "unset means the default provider, not a named target",+ "browser.cloak.fingerprintSeed": "cloak override, unset",+ "browser.cloak.platform": "cloak override, unset",+ "browser.cloak.locale": "cloak override, unset",+ "browser.cloak.timezone": "cloak override, unset",+ "browser.cloak.webrtcIP": "cloak override, unset",+ "browser.cloak.fontsDir": "cloak override, unset",+ "browser.cloak.storageQuotaMB": "cloak override, unset",+ "browser.cloak.disableDefaultStealthArgs": "cloak override, unset",+ "browser.proxy.server": "no proxy configured",+ "browser.proxy.bypassList": "no proxy configured",+ "browser.proxy.username": "no proxy configured",+ "browser.proxy.password": "no proxy configured",+ "browser.proxy.geo.timezone": "no proxy geo override",+ "browser.proxy.geo.locale": "no proxy geo override",+ "browser.proxy.geo.webrtcIP": "no proxy geo override",+ "browser.proxy.geo.countryISO": "no proxy geo override",+ "instanceDefaults.timezone": "unset means the host timezone",+ "instanceDefaults.userAgent": "unset means the browser's own user agent",+ "security.downloadAllowedDomains": "empty list, downloads follow the main allowlist",+ "security.trustedProxyCIDRs": "empty list",+ "security.trustedResolveCIDRs": "empty list",+ "security.idpi.customPatterns": "empty list",+ "autoSolver.llmProvider": "no LLM provider configured",+ "autoSolver.external.capsolverKey": "no external solver key configured",+ "autoSolver.external.twoCaptchaKey": "no external solver key configured",+ "autoSolver.credentials.login.user": "no stored credential",+ "autoSolver.credentials.login.password": "no stored credential",+ "autoSolver.credentials.signup.name": "no stored credential",+ "autoSolver.credentials.signup.email": "no stored credential",+ "autoSolver.credentials.signup.password": "no stored credential",+ "autoSolver.credentials.form.field1": "no stored credential",+ "autoSolver.credentials.form.field2": "no stored credential",+ "autoSolver.credentials.form.email": "no stored credential",+}++// defaultLivesAtItsConsumer holds the keys that still answer blank although a real+// default applies. Each names where that default is written; reporting them needs+// that owner to expose it, which is why they are recorded here rather than spelled+// out a second time in this package. A key must move out of this table, not gain a+// hardcoded value in the print path.+var defaultLivesAtItsConsumer = map[string]string{+ "server.cookieSecure": "the cookie layer decides from the request scheme",+ "browser.fallbackOrder": "the browser registry orders fallbacks",+ "instanceDefaults.tabPolicy.eviction": "the tab policy layer",+ "instanceDefaults.tabPolicy.lifecycle": "the tab policy layer",+ "instanceDefaults.tabPolicy.closeDelaySec": "the tab policy layer",+ "observability.activity.stateDir": "the activity recorder derives it when unset",+ "scheduler.enabled": "scheduler.New applies its own defaults",+ "scheduler.strategy": "scheduler.New applies its own defaults",+ "scheduler.maxQueueSize": "scheduler.New applies its own defaults",+ "scheduler.maxPerAgent": "scheduler.New applies its own defaults",+ "scheduler.maxInflight": "scheduler.New applies its own defaults",+ "scheduler.maxPerAgentInflight": "scheduler.New applies its own defaults",+ "scheduler.resultTTLSec": "scheduler.New applies its own defaults",+ "scheduler.workerCount": "scheduler.New applies its own defaults",+}++// TestEveryAddressableConfigKeyAnswersOrIsAccountedFor is the standing census behind+// this behaviour: a key whose effective value is derived, or defaulted somewhere other+// than the config struct, answers blank and nobody notices. Adding such a key now+// fails here until it either answers or is recorded with a reason.+func TestEveryAddressableConfigKeyAnswersOrIsAccountedFor(t *testing.T) {+ writeConfigForGet(t, `{}`)++ paths := addressableConfigPaths(t)+ if len(paths) < 100 {+ t.Fatalf("found only %d addressable config paths, so this census is not walking FileConfig", len(paths))+ }++ blank := make(map[string]bool, len(paths))+ for _, path := range paths {+ value, err := EffectiveConfigValue(path)+ if err != nil {+ t.Fatalf("EffectiveConfigValue(%q) error = %v", path, err)+ }+ if strings.TrimSpace(value) != "" {+ continue+ }+ blank[path] = true+ if _, ok := blankIsTheAnswer[path]; ok {+ continue+ }+ if reason, ok := defaultLivesAtItsConsumer[path]; ok {+ t.Logf("known hole: %s answers blank because %s", path, reason)+ continue+ }+ t.Errorf("config get %s answers with a blank line; either report the value in effect or record why blank is the answer", path)+ }++ for _, table := range []map[string]string{blankIsTheAnswer, defaultLivesAtItsConsumer} {+ for path := range table {+ if !slicesContains(paths, path) {+ t.Errorf("%s is recorded as blank-answering but is no longer an addressable key; drop the entry", path)+ continue+ }+ if !blank[path] {+ t.Errorf("%s now answers with a value; drop its entry so the census keeps meaning what it says", path)+ }+ }+ }+}++func addressableConfigPaths(t *testing.T) []string {+ t.Helper()++ fc := DefaultFileConfig()+ var out []string+ for _, path := range configLeafPaths(reflect.TypeOf(FileConfig{}), "") {+ if _, err := GetConfigValue(&fc, path); err != nil {+ continue+ }+ out = append(out, path)+ }+ return out+}++func configLeafPaths(typ reflect.Type, prefix string) []string {+ var out []string+ for i := 0; i < typ.NumField(); i++ {+ field := typ.Field(i)+ if !field.IsExported() {+ continue+ }+ tag := strings.Split(field.Tag.Get("json"), ",")[0]+ if tag == "" || tag == "-" {+ continue+ }+ path := tag+ if prefix != "" {+ path = prefix + "." + tag+ }+ fieldType := field.Type+ if fieldType.Kind() == reflect.Ptr {+ fieldType = fieldType.Elem()+ }+ if fieldType.Kind() == reflect.Struct {+ out = append(out, configLeafPaths(fieldType, path)...)+ continue+ }+ out = append(out, path)+ }+ return out+}++func slicesContains(haystack []string, needle string) bool {+ for _, item := range haystack {+ if item == needle {+ return true+ }+ }+ return false+}++func quoteJSON(value string) string {+ return `"` + strings.ReplaceAll(value, `\`, `\\`) + `"`+}++// TestTheProfilesPathRuleHasOneOwner keeps the effective-value reader honest about+// where it gets its answer: joining the state dir with "profiles" a second time would+// make config get agree with the runtime today and drift from it silently later.+func TestTheProfilesPathRuleHasOneOwner(t *testing.T) {+ owners := 0+ for _, dir := range []string{".", "workflow", filepath.Join("..", "..", "cmd", "pinchtab")} {+ entries, err := os.ReadDir(dir)+ if err != nil {+ t.Fatalf("ReadDir(%s): %v", dir, err)+ }+ files := 0+ for _, entry := range entries {+ name := entry.Name()+ if entry.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {+ continue+ }+ files+++ src, err := os.ReadFile(filepath.Join(dir, name))+ if err != nil {+ t.Fatalf("ReadFile(%s): %v", name, err)+ }+ for _, line := range strings.Split(string(src), "\n") {+ if strings.Contains(line, "//") {+ continue+ }+ if strings.Contains(line, `filepath.Join(`) && strings.Contains(line, `"profiles"`) {+ owners+++ t.Logf("profiles path rule in %s/%s: %s", dir, name, strings.TrimSpace(line))+ }+ }+ }+ if files == 0 {+ t.Fatalf("no non-test Go files found in %s, so this census read nothing", dir)+ }+ }+ if owners != 1 {+ t.Errorf("found %d places joining the state dir with \"profiles\", want exactly 1 (finalizeProfileConfig)", owners)+ }+}diff --git a/internal/config/workflow/mutate.go b/internal/config/workflow/mutate.goindex 724ac2f8..e312b94c 100644--- a/internal/config/workflow/mutate.go+++ b/internal/config/workflow/mutate.go@@ -24,15 +24,7 @@ func CurrentConfigPath() string {}func GetValue(path string) (string, error) {- fc, _, err := config.LoadFileConfig()- if err != nil {- return "", fmt.Errorf("load config: %w", err)- }- value, err := config.GetConfigValue(fc, path)- if err != nil {- return "", err- }- return value, nil+ return config.EffectiveConfigValue(path)}func PrepareSetValue(path, value string) (*PreparedChange, error) {diff --git a/internal/safelog/handler.go b/internal/safelog/handler.goindex 2f2856b8..0e8403a1 100644--- a/internal/safelog/handler.go+++ b/internal/safelog/handler.go@@ -16,6 +16,12 @@ import (// DefaultLevel is what a run records with no level set.const DefaultLevel = slog.LevelInfo+// LevelName renders a level the way the config file and --log-level spell it, so a+// surface reporting the level in effect does not spell the default itself.+func LevelName(level slog.Level) string {+ return strings.ToLower(level.String())+}+const (MaxStringValueBytes = 2 * 1024MaxRecordTextBytes = 8 * 1024