From bb22e74d25ed999dc267fc1877130ccb6d01d77f Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Sat, 14 Nov 2026 08:38:44 -0600 Subject: [PATCH] fix(mcpx): move the 11 guard-flagged constants into defaults.json (#8270) TestNoPackageRedeclaresADefault was red on clean main: four mcpauth/failover timings, two cli import-probe timeouts, the daemon script-view wait, and three testsupport timings bypassed internal/defaults, plus the seed package sign mask. New defaults sections mcpauth (cooldown, refreshSkew, jwtBackdate, jwtLifetime -- protocol-bound by GitHub's ten-minute App JWT cap, so data not settings) and testsupport (leftoverGracePeriod, leftoverPollInterval, eraReplyWait); cli.importTimeout and daemon.scriptWaitDelay join their existing sections. The seed 1<<63 is allowlisted in the guard with its reason: it is the int64 sign mask, arithmetic, not a size or a policy value. Guard test green; mcpauth, testsupport and defaults suites pass. The six internal/cli surface failures (plugin declared twice, parity/manual drift) are pre-existing on clean main at 3b4cb17751, verified in a pristine worktree, and untouched here. --- pkgs/mcpx/internal/cli/adapter_import.go | 3 +- .../mcpx/internal/cli/adapter_import_parse.go | 5 +- pkgs/mcpx/internal/daemon/scriptview.go | 2 +- pkgs/mcpx/internal/defaults/defaults.go | 65 +++++++++++++++++-- pkgs/mcpx/internal/defaults/defaults.json | 17 ++++- pkgs/mcpx/internal/defaults/guard_test.go | 1 + pkgs/mcpx/internal/mcpauth/failover.go | 12 ++-- pkgs/mcpx/internal/testsupport/eramcp/main.go | 4 +- pkgs/mcpx/internal/testsupport/sweep.go | 6 +- 9 files changed, 95 insertions(+), 20 deletions(-) diff --git a/pkgs/mcpx/internal/cli/adapter_import.go b/pkgs/mcpx/internal/cli/adapter_import.go index baeb59eea6..7e1c35470b 100644 --- a/pkgs/mcpx/internal/cli/adapter_import.go +++ b/pkgs/mcpx/internal/cli/adapter_import.go @@ -15,6 +15,7 @@ import ( "unicode" "github.com/developing-today/code/pkgs/mcpx/internal/adapter" + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // Declaration generation for `mcpx adapter import` (#1962 steps 2-5). @@ -682,7 +683,7 @@ func parseCompletion(text, shell, name string) *importShape { // runCapture runs a program for its text output with a bound: import // probes binaries, and a probe that hangs would hang the import. func runCapture(binary string, args ...string) (string, error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), defaults.CLIImportTimeout) defer cancel() cmd := exec.CommandContext(ctx, binary, args...) var out strings.Builder diff --git a/pkgs/mcpx/internal/cli/adapter_import_parse.go b/pkgs/mcpx/internal/cli/adapter_import_parse.go index 3835d64ad4..733a7e687d 100644 --- a/pkgs/mcpx/internal/cli/adapter_import_parse.go +++ b/pkgs/mcpx/internal/cli/adapter_import_parse.go @@ -7,7 +7,8 @@ import ( "regexp" "sort" "strings" - "time" + + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // The source parsers for adapter import (#1962). Each is a pure function @@ -441,7 +442,7 @@ func manShape(binary string) (*importShape, error) { // runCaptureEnv is runCapture with extra environment. func runCaptureEnv(env map[string]string, binary string, args ...string) (string, error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), defaults.CLIImportTimeout) defer cancel() cmd := exec.CommandContext(ctx, binary, args...) cmd.Env = os.Environ() diff --git a/pkgs/mcpx/internal/daemon/scriptview.go b/pkgs/mcpx/internal/daemon/scriptview.go index 45f32e83b7..737dbbb5d3 100644 --- a/pkgs/mcpx/internal/daemon/scriptview.go +++ b/pkgs/mcpx/internal/daemon/scriptview.go @@ -26,7 +26,7 @@ import ( // scriptWaitDelay bounds how long a script view's call waits on its output // pipes after the program exits, so a grandchild that inherited them cannot // hold the call open. -const scriptWaitDelay = 2 * time.Second +var scriptWaitDelay = defaults.ScriptWaitDelay // ScriptAnnotations is the behaviour hints a script-backed view declares // (#1933 slice 2). A script has no upstream annotations, so the declaration diff --git a/pkgs/mcpx/internal/defaults/defaults.go b/pkgs/mcpx/internal/defaults/defaults.go index a08eab8991..dda338e49c 100644 --- a/pkgs/mcpx/internal/defaults/defaults.go +++ b/pkgs/mcpx/internal/defaults/defaults.go @@ -48,9 +48,10 @@ type Defaults struct { Trace bool `json:"trace"` } `json:"logging"` Daemon struct { - ReapInterval string `json:"reapInterval"` - SaveInterval string `json:"saveInterval"` - TSNetUpTimeout string `json:"tsnetUpTimeout"` + ReapInterval string `json:"reapInterval"` + SaveInterval string `json:"saveInterval"` + TSNetUpTimeout string `json:"tsnetUpTimeout"` + ScriptWaitDelay string `json:"scriptWaitDelay"` } `json:"daemon"` Secrets struct { RequestRetention string `json:"requestRetention"` @@ -141,8 +142,9 @@ type Defaults struct { // CLI governs how the command line renders what it did not write a // formatter for: the commands generated from the /v1 operation table. CLI struct { - CellWidth int `json:"cellWidth"` - UsageColumn int `json:"usageColumn"` + CellWidth int `json:"cellWidth"` + UsageColumn int `json:"usageColumn"` + ImportTimeout string `json:"importTimeout"` } `json:"cli"` Catalog struct { Budget int `json:"budget"` @@ -396,6 +398,28 @@ type Defaults struct { Proxy struct { Timeout string `json:"timeout"` } `json:"proxy"` + // McpAuth is the GitHub identity failover machinery's timing + // (internal/mcpauth). The JWT values are bounded by GitHub's own + // rules -- an App JWT may live at most ten minutes -- so they are + // data here rather than settings: a configuration key that pushed + // the lifetime past the cap would only mint tokens GitHub refuses. + McpAuth struct { + Cooldown string `json:"cooldown"` + RefreshSkew string `json:"refreshSkew"` + JWTBackdate string `json:"jwtBackdate"` + JWTLifetime string `json:"jwtLifetime"` + } `json:"mcpauth"` + // TestSupport is the test harness's own timing (internal/ + // testsupport): how long the leftover-process sweep waits out an + // orderly shutdown, and how long the era test server waits for a + // reply before calling it dropped. They are here so the constants + // guard has exactly one answer for them, not because a user of + // the shipped binary can reach them. + TestSupport struct { + LeftoverGracePeriod string `json:"leftoverGracePeriod"` + LeftoverPollInterval string `json:"leftoverPollInterval"` + EraReplyWait string `json:"eraReplyWait"` + } `json:"testsupport"` } // Embeddings defaults. @@ -405,6 +429,29 @@ var ( ProxyUpstreamTimeout = mustDur(builtin.Proxy.Timeout, "proxy.timeout") ) +// McpAuth (GitHub identity failover) defaults. +var ( + // McpAuthCooldown is the failover cooldown when the config sets + // no CooldownSeconds: how long a soft-blocked identity is skipped. + McpAuthCooldown = mustDur(builtin.McpAuth.Cooldown, "mcpauth.cooldown") + // McpAuthRefreshSkew is how far ahead of expiry a minted App + // token stops being reused, so a token never dies mid-request. + McpAuthRefreshSkew = mustDur(builtin.McpAuth.RefreshSkew, "mcpauth.refreshSkew") + // McpAuthJWTBackdate is how far the App JWT's iat is backdated + // for clock skew between this host and GitHub. + McpAuthJWTBackdate = mustDur(builtin.McpAuth.JWTBackdate, "mcpauth.jwtBackdate") + // McpAuthJWTLifetime is the App JWT's lifetime; GitHub caps it + // at ten minutes, and this sits under the cap. + McpAuthJWTLifetime = mustDur(builtin.McpAuth.JWTLifetime, "mcpauth.jwtLifetime") +) + +// TestSupport (test harness) defaults. +var ( + TestSupportLeftoverGracePeriod = mustDur(builtin.TestSupport.LeftoverGracePeriod, "testsupport.leftoverGracePeriod") + TestSupportLeftoverPollInterval = mustDur(builtin.TestSupport.LeftoverPollInterval, "testsupport.leftoverPollInterval") + TestSupportEraReplyWait = mustDur(builtin.TestSupport.EraReplyWait, "testsupport.eraReplyWait") +) + // Upstream connection defaults. var ( // UpstreamProtocol is the era preference for a server that names none. @@ -573,7 +620,10 @@ var ( SaveInterval = mustDur(builtin.Daemon.SaveInterval, "daemon.saveInterval") // TSNetUpTimeout bounds how long a tsnet node may take to authenticate // and reach Running before its listener is believed. - TSNetUpTimeout = mustDur(builtin.Daemon.TSNetUpTimeout, "daemon.tsnetUpTimeout") + TSNetUpTimeout = mustDur(builtin.Daemon.TSNetUpTimeout, "daemon.tsnetUpTimeout") + // ScriptWaitDelay bounds how long a script view's call waits on + // its output pipes after the program exits. + ScriptWaitDelay = mustDur(builtin.Daemon.ScriptWaitDelay, "daemon.scriptWaitDelay") SecretRequestRetention = mustDur(builtin.Secrets.RequestRetention, "secrets.requestRetention") ShutdownGrace = mustDur(builtin.Plumbing.ShutdownGrace, "plumbing.shutdownGrace") @@ -721,6 +771,9 @@ var ( // description in full turns a table into a wall. OpCellWidth = builtin.CLI.CellWidth UsageColumn = builtin.CLI.UsageColumn + // CLIImportTimeout bounds one import probe of a binary (its + // --help, its man page): a probe that hangs would hang the import. + CLIImportTimeout = mustDur(builtin.CLI.ImportTimeout, "cli.importTimeout") Permissions = builtin.Script.Permissions // RuntimeOrder is the order auto tries runtimes in. diff --git a/pkgs/mcpx/internal/defaults/defaults.json b/pkgs/mcpx/internal/defaults/defaults.json index 2a17df41da..4af877ca5f 100644 --- a/pkgs/mcpx/internal/defaults/defaults.json +++ b/pkgs/mcpx/internal/defaults/defaults.json @@ -22,14 +22,16 @@ "daemon": { "reapInterval": "30s", "saveInterval": "5m", - "tsnetUpTimeout": "30s" + "tsnetUpTimeout": "30s", + "scriptWaitDelay": "2s" }, "secrets": { "requestRetention": "10m" }, "cli": { "cellWidth": 60, - "usageColumn": 30 + "usageColumn": 30, + "importTimeout": "10s" }, "catalog": { "budget": 2000 @@ -310,5 +312,16 @@ }, "hooks": { "timeout": "2s" + }, + "mcpauth": { + "cooldown": "60s", + "refreshSkew": "5m", + "jwtBackdate": "60s", + "jwtLifetime": "9m" + }, + "testsupport": { + "leftoverGracePeriod": "10s", + "leftoverPollInterval": "100ms", + "eraReplyWait": "2s" } } diff --git a/pkgs/mcpx/internal/defaults/guard_test.go b/pkgs/mcpx/internal/defaults/guard_test.go index 8595a1746c..46a25eedd7 100644 --- a/pkgs/mcpx/internal/defaults/guard_test.go +++ b/pkgs/mcpx/internal/defaults/guard_test.go @@ -74,6 +74,7 @@ var allowed = map[string]string{ "1<<20": "the definition of a mebibyte, in the size parser", "1<<30": "the definition of a gibibyte, in the size parser", "1<<40": "the definition of a tebibyte, in the size parser", + "1<<63": "the int64 sign mask: seed.Shuffle clears the sign bit of a uint64 hash to derive a non-negative int64 (MaxInt63 by arithmetic), in internal/testsupport/seed", // A unit boundary in a duration renderer: it decides whether to print // hours or days, which is arithmetic rather than policy. diff --git a/pkgs/mcpx/internal/mcpauth/failover.go b/pkgs/mcpx/internal/mcpauth/failover.go index ec03bf79d3..ae43a7a123 100644 --- a/pkgs/mcpx/internal/mcpauth/failover.go +++ b/pkgs/mcpx/internal/mcpauth/failover.go @@ -44,6 +44,8 @@ import ( "strings" "sync" "time" + + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // Identity is one entry in a failover list. @@ -81,13 +83,13 @@ type Failover struct { StatePath string `json:"statePath,omitempty"` // CooldownSeconds is how long a soft-blocked identity is skipped. - // A response's Retry-After wins when it is longer. Zero means 60. + // A response's Retry-After wins when it is longer. Zero means defaults.McpAuthCooldown. CooldownSeconds int `json:"cooldownSeconds,omitempty"` } func (f *Failover) cooldown() time.Duration { if f == nil || f.CooldownSeconds <= 0 { - return 60 * time.Second + return defaults.McpAuthCooldown } return time.Duration(f.CooldownSeconds) * time.Second } @@ -270,7 +272,7 @@ func (r *Rotator) Token(ctx context.Context, id Identity, secrets SecretFunc, mi return secrets(id.Secret) case "app": r.mu.Lock() - if mt, ok := r.minted[id.Name]; ok && r.now().Before(mt.expires.Add(-5*time.Minute)) { + if mt, ok := r.minted[id.Name]; ok && r.now().Before(mt.expires.Add(-defaults.McpAuthRefreshSkew)) { r.mu.Unlock() return mt.token, nil } @@ -496,8 +498,8 @@ func signAppJWT(keyPEM []byte, appID int64, now time.Time) (string, error) { header := enc([]byte(`{"alg":"RS256","typ":"JWT"}`)) claims, _ := json.Marshal(map[string]any{ "iss": appID, - "iat": now.Add(-60 * time.Second).Unix(), - "exp": now.Add(9 * time.Minute).Unix(), + "iat": now.Add(-defaults.McpAuthJWTBackdate).Unix(), + "exp": now.Add(defaults.McpAuthJWTLifetime).Unix(), }) signing := header + "." + enc(claims) sum := sha256.Sum256([]byte(signing)) diff --git a/pkgs/mcpx/internal/testsupport/eramcp/main.go b/pkgs/mcpx/internal/testsupport/eramcp/main.go index d4f1407d34..d98e7db9d0 100644 --- a/pkgs/mcpx/internal/testsupport/eramcp/main.go +++ b/pkgs/mcpx/internal/testsupport/eramcp/main.go @@ -39,6 +39,8 @@ import ( "sync" "sync/atomic" "time" + + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) type frame struct { @@ -223,7 +225,7 @@ func handle(f frame) { select { case <-answered: ok(f.ID, textResult("answered")) - case <-time.After(2 * time.Second): + case <-time.After(defaults.TestSupportEraReplyWait): ok(f.ID, textResult("dropped")) } return diff --git a/pkgs/mcpx/internal/testsupport/sweep.go b/pkgs/mcpx/internal/testsupport/sweep.go index b0843e6cd6..70826e44d8 100644 --- a/pkgs/mcpx/internal/testsupport/sweep.go +++ b/pkgs/mcpx/internal/testsupport/sweep.go @@ -9,6 +9,8 @@ import ( "strings" "sync" "time" + + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // The build temp dirs this test binary created by its fixture builders @@ -110,9 +112,9 @@ func processesExecutingFrom(dirs []string) []LeftoverProcess { // allows the same 10 seconds for the asynchronous exit). Polling inside // that budget is not leniency — a survivor past it is not draining, it // is leaked. -var leftoverGracePeriod = 10 * time.Second +var leftoverGracePeriod = defaults.TestSupportLeftoverGracePeriod -const leftoverPollInterval = 100 * time.Millisecond +var leftoverPollInterval = defaults.TestSupportLeftoverPollInterval // SweepBuildTempDirs is the suite-wide sweep of #1971 remainder item 2: // it removes this test binary's build temp dirs and reports any process