From a1a408e95bb1171e2932408c380279a43956b8b1 Mon Sep 17 00:00:00 2001 From: fmuntean Date: Wed, 7 Oct 2026 13:02:37 +0200 Subject: [PATCH 1/6] fix(#8111): consult config.base.yaml for kill_switch in GitHub and GitLab dispatch Both forges' built-in-stage dispatch checks only ever read kill_switch from .fullsend/config.yaml, so a central operator setting kill_switch: true in .fullsend/config.base.yaml alone had no effect on built-in stages (triage, code, review, fix, retro, prioritize). This is a parity gap, not a greenfield need: IsKillSwitchActive() already layers overlay then base then a compiled default of false, and is already honored by the Jira polling path, the managed-config-push safety gate, and the harness-dispatch job in this same workflow file. - GitHub (reusable-dispatch.yml): add config.base.yaml to the route job's sparse-checkout list, and extend the kill-switch check to consult it when config.yaml omits the key. - GitLab (run-agent-job.sh): fetch config.base.yaml the same way config.yaml is fetched, and apply the same override semantics. Both checks now match IsKillSwitchActive()'s resolution order: an explicit kill_switch value in config.yaml wins if set (including false), otherwise config.base.yaml applies, otherwise false. GitLab's pre-existing fail-open behavior on a YAML parse error (log a warning and proceed) is left unchanged. Adds Go subprocess tests for the GitLab script's new fallback/override behavior, and a new e2e behaviour-test scenario proving a config.base.yaml-only kill switch blocks GitHub dispatch. Signed-off-by: fmuntean Co-authored-by: Cursor --- .github/workflows/reusable-dispatch.yml | 25 ++- .../features/dispatch/fork-dispatch.feature | 19 +++ .../.gitlab/ci/scripts/run-agent-job.sh | 34 +++- internal/scaffold/gitlab_job_scripts_test.go | 152 ++++++++++++++++++ pkg/behaviourtest/steps/cleanup.go | 17 +- pkg/behaviourtest/steps/cleanup_test.go | 89 +++++++++- pkg/behaviourtest/steps/dispatch.go | 73 +++++++++ pkg/behaviourtest/steps/dispatch_test.go | 144 +++++++++++++++++ pkg/behaviourtest/world/world.go | 8 + 9 files changed, 547 insertions(+), 14 deletions(-) diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index c293a9595a..7a4abed882 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -133,6 +133,7 @@ jobs: allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} sparse-checkout: | .fullsend/config.yaml + .fullsend/config.base.yaml /OWNERS /OWNERS_ALIASES sparse-checkout-cone-mode: false @@ -494,14 +495,28 @@ jobs: if: steps.route.outputs.stage != '' run: | set -euo pipefail + # Mirrors internal/config's IsKillSwitchActive(): if + # config.yaml sets kill_switch at all, that value is final + # and config.base.yaml is ignored; config.base.yaml is only + # consulted when config.yaml is silent on the key. + KILL_SWITCH="false" + OVERLAY_KS="null" if [[ -f .fullsend/config.yaml ]]; then - KILL_SWITCH=$(yq '.kill_switch // false' .fullsend/config.yaml) - if [[ "$KILL_SWITCH" == "true" ]]; then - echo "::error::Kill switch is active — all agent dispatch halted" - echo "::error::Set kill_switch: false in .fullsend/config.yaml to resume" - exit 1 + OVERLAY_KS=$(yq '.kill_switch' .fullsend/config.yaml) + fi + if [[ "$OVERLAY_KS" != "null" ]]; then + KILL_SWITCH="$OVERLAY_KS" + elif [[ -f .fullsend/config.base.yaml ]]; then + BASE_KS=$(yq '.kill_switch' .fullsend/config.base.yaml) + if [[ "$BASE_KS" != "null" ]]; then + KILL_SWITCH="$BASE_KS" fi fi + if [[ "$KILL_SWITCH" == "true" ]]; then + echo "::error::Kill switch is active — all agent dispatch halted" + echo "::error::Set kill_switch: false in .fullsend/config.yaml or .fullsend/config.base.yaml to resume" + exit 1 + fi - name: Validate agents config if: steps.route.outputs.stage != '' diff --git a/e2e/behaviour/features/dispatch/fork-dispatch.feature b/e2e/behaviour/features/dispatch/fork-dispatch.feature index 2d57505b0a..72c964f26b 100644 --- a/e2e/behaviour/features/dispatch/fork-dispatch.feature +++ b/e2e/behaviour/features/dispatch/fork-dispatch.feature @@ -90,6 +90,25 @@ Feature: Fork PR dispatch And the fork pull request is labeled "ready-for-fork-killswitch" Then the harness "fork-pr-killswitch" agent did not run + Scenario: Fork PR kill switch in config.base.yaml blocks all harnesses + Given a custom harness "fork-pr-killswitch-base" with: + """ + agent: agents/triage.md + role: triage + slug: fullsend-ai-fork-pr-killswitch-base + model: opus + image: ghcr.io/fullsend-ai/fullsend-sandbox:latest + policy: policies/base.yaml + trigger: | + event.entity.kind == "change_proposal" + && event.transition.kind == "label_changed" + && event.transition.label.name == "ready-for-fork-killswitch-base" + """ + And the kill switch is active in config.base.yaml + When a fork pull request is opened + And the fork pull request is labeled "ready-for-fork-killswitch-base" + Then the harness "fork-pr-killswitch-base" agent did not run + Scenario: Fork PR sync + label dispatches harness Given a custom harness "fork-pr-sync" with: """ diff --git a/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh b/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh index 5dbfeb3fd6..2e6344a730 100644 --- a/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh +++ b/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh @@ -305,16 +305,38 @@ if ! git fetch origin "${FULLSEND_PINNED_REF}" --depth=1; then fi DEFAULT_BRANCH_SHA=$(git rev-parse FETCH_HEAD) CONFIG_YAML=$(git show "${DEFAULT_BRANCH_SHA}:.fullsend/config.yaml" 2>/dev/null || echo "") - -# Kill switch — halt all agent dispatch when active -if [ -n "${CONFIG_YAML}" ]; then - if ! KILL_SWITCH=$(echo "${CONFIG_YAML}" | python3 -c "import sys,yaml; print('true' if str((yaml.safe_load(sys.stdin) or {}).get('kill_switch', False)).lower() in ('true','yes','1','on') else 'false')"); then - echo "WARNING: invalid .fullsend/config.yaml — treating as unconfigured (no kill-switch)" +CONFIG_BASE_YAML=$(git show "${DEFAULT_BRANCH_SHA}:.fullsend/config.base.yaml" 2>/dev/null || echo "") + +# Kill switch — halt all agent dispatch when active. Mirrors +# internal/config's IsKillSwitchActive(): if config.yaml sets +# kill_switch at all, that value is final and config.base.yaml is +# ignored; config.base.yaml is only consulted when config.yaml is +# silent on the key. +if [ -n "${CONFIG_YAML}" ] || [ -n "${CONFIG_BASE_YAML}" ]; then + if ! KILL_SWITCH=$(OVERLAY_YAML="${CONFIG_YAML}" BASE_YAML="${CONFIG_BASE_YAML}" python3 -c " +import os, sys, yaml + +def load(text): + return (yaml.safe_load(text) or {}) if text else {} + +overlay = load(os.environ.get('OVERLAY_YAML', '')) +base = load(os.environ.get('BASE_YAML', '')) + +if 'kill_switch' in overlay: + active = overlay.get('kill_switch') +elif 'kill_switch' in base: + active = base.get('kill_switch') +else: + active = False + +print('true' if str(active).lower() in ('true', 'yes', '1', 'on') else 'false') +"); then + echo "WARNING: invalid .fullsend/config.yaml or .fullsend/config.base.yaml — treating as unconfigured (no kill-switch)" KILL_SWITCH="false" fi if [ "${KILL_SWITCH}" = "true" ]; then echo "ERROR: Kill switch is active — all agent dispatch halted" >&2 - echo "Set kill_switch: false in .fullsend/config.yaml to resume" >&2 + echo "Set kill_switch: false in .fullsend/config.yaml or .fullsend/config.base.yaml to resume" >&2 exit 1 fi fi diff --git a/internal/scaffold/gitlab_job_scripts_test.go b/internal/scaffold/gitlab_job_scripts_test.go index 1770d3d5ab..ddf5cec881 100644 --- a/internal/scaffold/gitlab_job_scripts_test.go +++ b/internal/scaffold/gitlab_job_scripts_test.go @@ -49,6 +49,38 @@ func setupPinnedConfigOrigin(t *testing.T, root string) { gitCmd(t, root, "remote", "add", "origin", upstream) } +// setupConfigOrigin is like setupPinnedConfigOrigin but lets the caller +// control the content of .fullsend/config.yaml (the overlay) and +// .fullsend/config.base.yaml (the base) committed to the origin +// remote's main branch independently. Pass "" for either argument to +// omit that file entirely (as opposed to committing it with empty +// content), so tests can exercise the "key/file absent" fallback path +// distinctly from "file present but doesn't set the key". +func setupConfigOrigin(t *testing.T, root, configYAML, configBaseYAML string) { + t.Helper() + upstream := t.TempDir() + initGitRepo(t, upstream) + if configYAML != "" { + require.NoError(t, os.MkdirAll(filepath.Join(upstream, ".fullsend"), 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(upstream, ".fullsend/config.yaml"), []byte(configYAML), 0o644)) + gitCmd(t, upstream, "add", ".fullsend/config.yaml") + } + if configBaseYAML != "" { + require.NoError(t, os.MkdirAll(filepath.Join(upstream, ".fullsend"), 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(upstream, ".fullsend/config.base.yaml"), []byte(configBaseYAML), 0o644)) + gitCmd(t, upstream, "add", ".fullsend/config.base.yaml") + } + // A placeholder file guarantees there is always at least one + // tracked file to commit, even in the "neither config file + // exists" case. + require.NoError(t, os.WriteFile(filepath.Join(upstream, "README.md"), []byte("placeholder\n"), 0o644)) + gitCmd(t, upstream, "add", "README.md") + gitCmd(t, upstream, "commit", "-m", "trusted config") + + initGitRepo(t, root) + gitCmd(t, root, "remote", "add", "origin", upstream) +} + func TestRunPollJobScript_RejectsInvalidPollMode(t *testing.T) { root := t.TempDir() writeGitLabScript(t, root, ".gitlab/ci/scripts/trust-ci-server-ca.sh") @@ -1156,6 +1188,126 @@ esac assert.NotContains(t, got, "malicious") } +// TestRunAgentJobScript_KillSwitchConsultsConfigBaseYAML exercises +// run-agent-job.sh's kill-switch check end to end: config.base.yaml is +// consulted only when config.yaml is silent on the key, an explicit +// config.yaml value (including false) always wins outright, and a YAML +// parse failure logs a warning and falls through as unconfigured +// rather than halting dispatch. +func TestRunAgentJobScript_KillSwitchConsultsConfigBaseYAML(t *testing.T) { + const secret = "test-hmac-secret" + hmacHex := computeDispatchHMAC(secret, "5", "", "", "", "", "", "", "", "test-key", "triage", "") + + cases := []struct { + name string + configYAML string + configBaseYAML string + wantHalt bool + wantOutput string + }{ + { + name: "overlay silent, base active halts dispatch", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + wantOutput: "Kill switch is active", + }, + { + name: "overlay explicit false overrides base active", + configYAML: "kill_switch: false\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: false, + }, + { + name: "neither file sets kill_switch", + wantHalt: false, + }, + { + name: "malformed overlay logs a warning and falls through", + configYAML: "kill_switch: [unterminated\n", + wantHalt: false, + wantOutput: "WARNING: invalid .fullsend/config.yaml or .fullsend/config.base.yaml — treating as unconfigured", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + root := t.TempDir() + writeGitLabScript(t, root, ".gitlab/ci/scripts/trust-ci-server-ca.sh") + writeGitLabScript(t, root, gitlabPinCIJobIdentityScriptPath) + writeGitLabScript(t, root, ".gitlab/ci/scripts/select-gitlab-role-token.sh") + script := writeGitLabScript(t, root, gitlabRunAgentJobScriptPath) + + mux := http.NewServeMux() + mux.HandleFunc("/api/v4/job", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(pinJobJSON("42", "100", "main"))) + }) + mux.HandleFunc("/api/v4/user", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"id":7,"username":"fullsend-bot"}`)) + }) + mux.HandleFunc("/api/v4/projects/", func(w http.ResponseWriter, r *http.Request) { + path := r.URL.Path + switch { + case strings.Contains(path, "/repository/branches/"): + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"name":"main","protected":true}`)) + case strings.Contains(path, "/pipelines/"): + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"id":100,"source":"api","user":{"id":7}}`)) + case strings.Contains(path, "/resource_groups/"): + w.WriteHeader(http.StatusOK) + case strings.Contains(path, "/members/all/"): + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"access_level":40}`)) + default: + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"id":42,"default_branch":"main","path_with_namespace":"group/project"}`)) + } + }) + srv := httptest.NewTLSServer(mux) + t.Cleanup(srv.Close) + + bin := t.TempDir() + require.NoError(t, os.WriteFile(filepath.Join(bin, "fullsend"), []byte("#!/bin/sh\nexit 0\n"), 0o755)) + + setupConfigOrigin(t, root, tc.configYAML, tc.configBaseYAML) + + cmd := exec.Command("bash", "-c", "set -euo pipefail; . \"$SCRIPT\"") + cmd.Dir = root + cmd.Env = append([]string{ + "SCRIPT=" + script, + "PATH=" + bin + ":" + os.Getenv("PATH"), + "HOME=" + t.TempDir(), + "CI_PROJECT_DIR=" + root, + "RUNNER_TEMP=" + t.TempDir(), + "CI_JOB_TOKEN=job-token", + "FULLSEND_GITLAB_POLLER_TOKEN=poller-pat", + "FULLSEND_GITLAB_ANALYST_TOKEN=analyst-pat", + "STAGE=triage", + "RESOURCE_KEY=test-key", + "ACTOR_ID=5", + "FULLSEND_DISPATCH_SECRET=" + secret, + "FULLSEND_DISPATCH_HMAC=" + hmacHex, + "CI_PROJECT_PATH=group/project", + "CI_SERVER_URL=https://gitlab.example", + "CI_PIPELINE_URL=https://gitlab.example/group/project/-/pipelines/100", + "CI_PROJECT_ID=1", + }, pinTLSEnv(t, srv)...) + out, err := cmd.CombinedOutput() + + if tc.wantHalt { + require.Error(t, err, "stdout/stderr: %s", out) + } else { + require.NoError(t, err, "stdout/stderr: %s", out) + } + if tc.wantOutput != "" { + assert.Contains(t, string(out), tc.wantOutput) + } + }) + } +} + // TestRunAgentJobScript_RejectsDisagreeingMergeRequestTargetBranchName is a // regression test for the logic-error finding: this job's admit source is // api-only (parent_pipeline is not an admitted arm — see FULLSEND_ADMIT_SOURCE diff --git a/pkg/behaviourtest/steps/cleanup.go b/pkg/behaviourtest/steps/cleanup.go index 4b3f6a6107..1a6b414964 100644 --- a/pkg/behaviourtest/steps/cleanup.go +++ b/pkg/behaviourtest/steps/cleanup.go @@ -64,7 +64,15 @@ func ValidateSlotClean(w *world.World) error { if err != nil { return nil } - cfg, err := config.ParsePerRepoConfigWriter(cfgData) + // config.base.yaml is not part of the standard scaffold and is + // absent on most slots; a missing-file error just means there is + // no base layer to check, not a validation failure. + baseData, err := w.SCM.GetFileContent(context.Background(), + w.Org, w.RepoName, filepath.Join(".fullsend", "config.base.yaml")) + if err != nil { + baseData = nil + } + cfg, err := config.ParsePerRepoConfigWriterLayered(cfgData, baseData) if err != nil { return nil } @@ -256,6 +264,13 @@ func CleanupScenario(w *world.World) { worldLogf(w, "behaviour cleanup: deactivate kill switch: %v", err) } } + if w.KillSwitchBaseActivated { + if err := cleanupRetry(w.Logf, "deactivate kill switch in config.base.yaml", func() error { + return DeactivateKillSwitchBase(w) + }); err != nil { + worldLogf(w, "behaviour cleanup: deactivate kill switch in config.base.yaml: %v", err) + } + } // --- Runtime override cleanup --- // Restore the install-time runtime so a later scenario on this slot diff --git a/pkg/behaviourtest/steps/cleanup_test.go b/pkg/behaviourtest/steps/cleanup_test.go index 2d9e987912..758f2f5467 100644 --- a/pkg/behaviourtest/steps/cleanup_test.go +++ b/pkg/behaviourtest/steps/cleanup_test.go @@ -3,6 +3,7 @@ package steps import ( "context" "fmt" + "strings" "testing" "time" @@ -433,7 +434,16 @@ type fakeCleanupSCM struct { commitFileErr error fileContent []byte getFileErr error - openPRs []forge.ChangeProposal + // baseFileConfigured, when true, makes GetFileContent answer + // config.base.yaml requests with baseFileContent/baseFileErr + // instead of the config.yaml-oriented fileContent/getFileErr + // above. Tests that don't care about config.base.yaml leave this + // false, so GetFileContent keeps its original path-agnostic + // behavior (returning fileContent/getFileErr for every path). + baseFileConfigured bool + baseFileContent []byte + baseFileErr error + openPRs []forge.ChangeProposal } type closedIssueRecord struct { @@ -495,7 +505,10 @@ func (f *fakeCleanupSCM) GetIssue(context.Context, string, string, int) (*forge. return nil, nil } -func (f *fakeCleanupSCM) GetFileContent(context.Context, string, string, string) ([]byte, error) { +func (f *fakeCleanupSCM) GetFileContent(_ context.Context, _, _, path string) ([]byte, error) { + if f.baseFileConfigured && strings.Contains(path, "config.base.yaml") { + return f.baseFileContent, f.baseFileErr + } return f.fileContent, f.getFileErr } @@ -736,6 +749,58 @@ func TestCleanupScenario_DeactivateKillSwitch_Error(t *testing.T) { assert.Contains(t, logged[0], "deactivate kill switch") } +func TestCleanupScenario_DeactivatesKillSwitchBase(t *testing.T) { + t.Parallel() + + scmDriver := &fakeCleanupSCM{ + fileContent: []byte("version: \"1\"\nkill_switch: true\n"), + } + w := &world.World{ + Org: "org", + RepoOwner: "org", + RepoName: "repo", + KillSwitchBaseActivated: true, + SCM: scmDriver, + } + CleanupScenario(w) + assert.True(t, scmDriver.commitFileCalled, "should commit config.base.yaml to deactivate kill switch") +} + +func TestCleanupScenario_SkipsKillSwitchBaseWhenNotActivated(t *testing.T) { + t.Parallel() + + scmDriver := &fakeCleanupSCM{} + w := &world.World{ + RepoOwner: "org", + RepoName: "repo", + KillSwitchBaseActivated: false, + SCM: scmDriver, + } + CleanupScenario(w) + assert.False(t, scmDriver.commitFileCalled, "should not commit when config.base.yaml kill switch was not activated") +} + +func TestCleanupScenario_DeactivateKillSwitchBase_Error(t *testing.T) { + t.Parallel() + + var logged []string + scmDriver := &fakeCleanupSCM{ + fileContent: []byte("version: \"1\"\nkill_switch: true\n"), + commitFileErr: fmt.Errorf("commit failed"), + } + w := &world.World{ + Org: "org", + RepoOwner: "org", + RepoName: "repo", + KillSwitchBaseActivated: true, + SCM: scmDriver, + Logf: func(format string, args ...any) { logged = append(logged, fmt.Sprintf(format, args...)) }, + } + CleanupScenario(w) + require.Len(t, logged, 1) + assert.Contains(t, logged[0], "deactivate kill switch in config.base.yaml") +} + // --- Allowed remote resources cleanup tests --- func TestCleanupScenario_RestoresAllowedResources(t *testing.T) { @@ -1230,6 +1295,26 @@ func TestValidateSlotClean(t *testing.T) { require.ErrorContains(t, err, "kill_switch is active") }) + // config.yaml is silent on kill_switch here (the "clean slot" + // baseline); only ValidateSlotClean consulting config.base.yaml + // too catches this. + t.Run("kill switch left on in config.base.yaml only", func(t *testing.T) { + t.Parallel() + w := leased(slotConfig(t, nil)) + w.SCM.(*fakeCleanupSCM).baseFileConfigured = true + w.SCM.(*fakeCleanupSCM).baseFileContent = slotConfig(t, func(c config.PerRepoConfigWriter) { c.SetKillSwitch(true) }) + err := ValidateSlotClean(w) + require.ErrorContains(t, err, "kill_switch is active") + }) + + t.Run("config.base.yaml missing is not an error", func(t *testing.T) { + t.Parallel() + w := leased(slotConfig(t, nil)) + w.SCM.(*fakeCleanupSCM).baseFileConfigured = true + w.SCM.(*fakeCleanupSCM).baseFileErr = forge.ErrNotFound + require.NoError(t, ValidateSlotClean(w)) + }) + t.Run("no leased repo", func(t *testing.T) { t.Parallel() require.NoError(t, ValidateSlotClean(&world.World{Org: "org", SCM: &fakeCleanupSCM{}})) diff --git a/pkg/behaviourtest/steps/dispatch.go b/pkg/behaviourtest/steps/dispatch.go index 27482203db..22201f6ebd 100644 --- a/pkg/behaviourtest/steps/dispatch.go +++ b/pkg/behaviourtest/steps/dispatch.go @@ -13,6 +13,7 @@ import ( "github.com/fullsend-ai/fullsend/internal/agentnew" "github.com/fullsend-ai/fullsend/internal/config" + "github.com/fullsend-ai/fullsend/internal/forge" "github.com/fullsend-ai/fullsend/internal/scaffold" "github.com/fullsend-ai/fullsend/pkg/behaviourtest/world" ) @@ -42,6 +43,9 @@ func registerDispatchSteps(sc *godog.ScenarioContext) { sc.Step(`^the kill switch is active$`, func(ctx context.Context) (context.Context, error) { return ctx, givenKillSwitchActive(world.FromContext(ctx)) }) + sc.Step(`^the kill switch is active in config\.base\.yaml$`, func(ctx context.Context) (context.Context, error) { + return ctx, givenKillSwitchActiveViaConfigBase(world.FromContext(ctx)) + }) } // givenKillSwitchActive sets kill_switch: true in the enrolled repo's @@ -100,6 +104,75 @@ func DeactivateKillSwitch(w *world.World) error { return nil } +// givenKillSwitchActiveViaConfigBase sets kill_switch: true in the +// enrolled repo's config.base.yaml (the central/base config layer), +// deliberately leaving config.yaml untouched/silent on the key. +// config.base.yaml is not part of the standard per-repo scaffold, so it +// may not exist yet; a missing file is treated as an empty starting +// point rather than an error. It also marks w.KillSwitchBaseActivated +// so CleanupScenario deactivates it before the slot is reused by +// another scenario. +func givenKillSwitchActiveViaConfigBase(w *world.World) error { + if w.Org == "" || w.RepoName == "" { + return fmt.Errorf("no repo configured; call 'Given the enrolled test repository' before kill-switch operations") + } + cfgPath := filepath.Join(".fullsend", "config.base.yaml") + cfgData, err := w.SCM.GetFileContent(context.Background(), w.Org, w.RepoName, cfgPath) + if err != nil { + if !forge.IsNotFound(err) { + return fmt.Errorf("reading base config: %w", err) + } + cfgData = nil + } + cfg, err := config.ParsePerRepoConfigWriter(cfgData) + if err != nil { + return fmt.Errorf("parsing base config: %w", err) + } + cfg.SetKillSwitch(true) + merged, err := cfg.Marshal() + if err != nil { + return err + } + if err := w.SCM.CommitFile(context.Background(), w.Org, w.RepoName, cfgPath, "behaviour: activate kill switch via config.base.yaml", merged); err != nil { + return fmt.Errorf("updating base config: %w", err) + } + w.KillSwitchBaseActivated = true + return nil +} + +// DeactivateKillSwitchBase sets kill_switch: false in the enrolled +// repo's config.base.yaml. Exported so CleanupScenario (in package +// steps) can call it during scenario teardown. The SCM driver has no +// delete-file operation, so this resets the key to false rather than +// removing the file — matching DeactivateKillSwitch's approach for +// config.yaml. +func DeactivateKillSwitchBase(w *world.World) error { + if w.Org == "" || w.RepoName == "" { + return fmt.Errorf("no repo configured; call 'Given the enrolled test repository' before kill-switch operations") + } + cfgPath := filepath.Join(".fullsend", "config.base.yaml") + cfgData, err := w.SCM.GetFileContent(context.Background(), w.Org, w.RepoName, cfgPath) + if err != nil { + if !forge.IsNotFound(err) { + return fmt.Errorf("reading base config: %w", err) + } + cfgData = nil + } + cfg, err := config.ParsePerRepoConfigWriter(cfgData) + if err != nil { + return fmt.Errorf("parsing base config: %w", err) + } + cfg.SetKillSwitch(false) + merged, err := cfg.Marshal() + if err != nil { + return err + } + if err := w.SCM.CommitFile(context.Background(), w.Org, w.RepoName, cfgPath, "behaviour: deactivate kill switch in config.base.yaml", merged); err != nil { + return fmt.Errorf("updating base config: %w", err) + } + return nil +} + func givenDisabledCustomHarness(w *world.World, name, doc string) error { if w.Org == "" || w.RepoName == "" { return fmt.Errorf("no repo configured; call 'Given the enrolled test repository' before harness operations") diff --git a/pkg/behaviourtest/steps/dispatch_test.go b/pkg/behaviourtest/steps/dispatch_test.go index 80e1be5091..558cc50245 100644 --- a/pkg/behaviourtest/steps/dispatch_test.go +++ b/pkg/behaviourtest/steps/dispatch_test.go @@ -129,6 +129,150 @@ func TestGivenKillSwitchActive_CommitFileError(t *testing.T) { assert.Contains(t, err.Error(), "updating config") } +// --- givenKillSwitchActiveViaConfigBase / DeactivateKillSwitchBase tests --- +// +// These mirror the givenKillSwitchActive/DeactivateKillSwitch tests +// above, but target .fullsend/config.base.yaml instead of config.yaml. +// config.base.yaml is not part of the standard scaffold, so these also +// cover the "file does not exist yet" path that config.yaml's +// equivalents never need to (config.yaml always exists once a repo is +// enrolled). + +func TestGivenKillSwitchActiveViaConfigBase_SetsKillSwitch(t *testing.T) { + scm := &fakeDispatchSCM{ + fileContent: []byte("version: \"1\"\nroles:\n - triage\n"), + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := givenKillSwitchActiveViaConfigBase(w) + require.NoError(t, err) + assert.True(t, scm.commitCalled, "CommitFile should have been called") + assert.Contains(t, string(scm.committedContent), "kill_switch: true") + assert.True(t, w.KillSwitchBaseActivated, "KillSwitchBaseActivated should be set for cleanup") +} + +func TestGivenKillSwitchActiveViaConfigBase_MissingFileTreatedAsEmpty(t *testing.T) { + scm := &fakeDispatchSCM{ + getFileErr: forge.ErrNotFound, + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := givenKillSwitchActiveViaConfigBase(w) + require.NoError(t, err, "a missing config.base.yaml should be treated as an empty starting point, not an error") + assert.True(t, scm.commitCalled, "CommitFile should have been called") + assert.Contains(t, string(scm.committedContent), "kill_switch: true") +} + +func TestGivenKillSwitchActiveViaConfigBase_GetFileContentError(t *testing.T) { + scm := &fakeDispatchSCM{ + getFileErr: fmt.Errorf("server error"), + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := givenKillSwitchActiveViaConfigBase(w) + require.Error(t, err) + assert.Contains(t, err.Error(), "reading base config") +} + +func TestGivenKillSwitchActiveViaConfigBase_CommitFileError(t *testing.T) { + scm := &fakeDispatchSCM{ + fileContent: []byte("version: \"1\"\nroles:\n - triage\n"), + commitErr: fmt.Errorf("commit failed"), + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := givenKillSwitchActiveViaConfigBase(w) + require.Error(t, err) + assert.Contains(t, err.Error(), "updating base config") +} + +func TestGivenKillSwitchActiveViaConfigBase_EmptyIdentity(t *testing.T) { + t.Parallel() + w := &world.World{SCM: &fakeDispatchSCM{}} + err := givenKillSwitchActiveViaConfigBase(w) + require.Error(t, err) + assert.Contains(t, err.Error(), "no repo configured") +} + +func TestDeactivateKillSwitchBase_ClearsKillSwitch(t *testing.T) { + scm := &fakeDispatchSCM{ + fileContent: []byte("version: \"1\"\nkill_switch: true\n"), + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := DeactivateKillSwitchBase(w) + require.NoError(t, err) + assert.True(t, scm.commitCalled, "CommitFile should have been called") + assert.Contains(t, string(scm.committedContent), "kill_switch: false") +} + +func TestDeactivateKillSwitchBase_MissingFileTreatedAsEmpty(t *testing.T) { + scm := &fakeDispatchSCM{ + getFileErr: forge.ErrNotFound, + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := DeactivateKillSwitchBase(w) + require.NoError(t, err, "a missing config.base.yaml should be treated as an empty starting point, not an error") + assert.True(t, scm.commitCalled, "CommitFile should have been called") + assert.Contains(t, string(scm.committedContent), "kill_switch: false") +} + +func TestDeactivateKillSwitchBase_GetFileContentError(t *testing.T) { + scm := &fakeDispatchSCM{ + getFileErr: fmt.Errorf("server error"), + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := DeactivateKillSwitchBase(w) + require.Error(t, err) + assert.Contains(t, err.Error(), "reading base config") +} + +func TestDeactivateKillSwitchBase_CommitFileError(t *testing.T) { + scm := &fakeDispatchSCM{ + fileContent: []byte("version: \"1\"\nkill_switch: true\n"), + commitErr: fmt.Errorf("commit failed"), + } + w := &world.World{ + SCM: scm, + Org: "org", + RepoName: "repo", + } + err := DeactivateKillSwitchBase(w) + require.Error(t, err) + assert.Contains(t, err.Error(), "updating base config") +} + +func TestDeactivateKillSwitchBase_EmptyIdentity(t *testing.T) { + t.Parallel() + w := &world.World{SCM: &fakeDispatchSCM{}} + err := DeactivateKillSwitchBase(w) + require.Error(t, err) + assert.Contains(t, err.Error(), "no repo configured") +} + // --- empty identity guard tests --- func TestGivenKillSwitchActive_EmptyIdentity(t *testing.T) { diff --git a/pkg/behaviourtest/world/world.go b/pkg/behaviourtest/world/world.go index ba1c7291bd..308bf146cf 100644 --- a/pkg/behaviourtest/world/world.go +++ b/pkg/behaviourtest/world/world.go @@ -104,6 +104,14 @@ type World struct { // the switch so the next scenario on this slot is not affected. KillSwitchActivated bool + // KillSwitchBaseActivated records whether this scenario activated + // the kill switch via .fullsend/config.base.yaml (the central/base + // layer) rather than config.yaml. CleanupScenario uses this to + // deactivate it so the next scenario on this slot is not affected. + // Tracked separately from KillSwitchActivated because the two + // files are independent. + KillSwitchBaseActivated bool + // RuntimeOverridden records that this scenario changed the repo's // `runtime:` in .fullsend/config.yaml; RuntimeOriginal is the value // to restore. CleanupScenario reverts it so the slot's next scenario From fc93cd721c9c302a563a87cbb12c71d8237b8042 Mon Sep 17 00:00:00 2001 From: fmuntean Date: Thu, 8 Oct 2026 13:04:30 +0200 Subject: [PATCH 2/6] fix(#8111): close kill_switch config.base.yaml fallback gaps - GitLab (run-agent-job.sh): resolve the overlay first and only parse config.base.yaml when the overlay is silent on kill_switch. This treats an overlay kill_switch: null the same as an omitted key (falls through to base, matching Go's IsKillSwitchActive()), and keeps a malformed base.yaml from ever suppressing an explicit overlay value, since base is no longer parsed unconditionally. - GitHub (reusable-dispatch.yml): compare the resolved kill_switch value case-insensitively, so a valid YAML boolean spelling like kill_switch: True halts dispatch the same as lowercase true. Signed-off-by: fmuntean Co-authored-by: Cursor --- .github/workflows/reusable-dispatch.yml | 2 +- .../.gitlab/ci/scripts/run-agent-job.sh | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index 5a0abfcdea..f062145d8f 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -512,7 +512,7 @@ jobs: KILL_SWITCH="$BASE_KS" fi fi - if [[ "$KILL_SWITCH" == "true" ]]; then + if [[ "${KILL_SWITCH,,}" == "true" ]]; then echo "::error::Kill switch is active — all agent dispatch halted" echo "::error::Set kill_switch: false in .fullsend/config.yaml or .fullsend/config.base.yaml to resume" exit 1 diff --git a/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh b/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh index 2e6344a730..4d24b62730 100644 --- a/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh +++ b/internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh @@ -319,15 +319,18 @@ import os, sys, yaml def load(text): return (yaml.safe_load(text) or {}) if text else {} +# Resolve the overlay first, and only parse the base file when the +# overlay is silent on kill_switch. This keeps a malformed base.yaml +# from ever being able to suppress an explicit overlay value (it is +# never parsed in that case), and treats overlay 'kill_switch: null' +# (or a bare 'kill_switch:') the same as a fully omitted key — both +# decode to None, matching Go's *bool nil-falls-through-to-parent +# semantics — rather than as an explicit false that shadows the base. overlay = load(os.environ.get('OVERLAY_YAML', '')) -base = load(os.environ.get('BASE_YAML', '')) - -if 'kill_switch' in overlay: - active = overlay.get('kill_switch') -elif 'kill_switch' in base: +active = overlay.get('kill_switch') +if active is None: + base = load(os.environ.get('BASE_YAML', '')) active = base.get('kill_switch') -else: - active = False print('true' if str(active).lower() in ('true', 'yes', '1', 'on') else 'false') "); then From 3ae3c1b3aa6b0e128cfcb98c30d6acdf5d72d862 Mon Sep 17 00:00:00 2001 From: fmuntean Date: Thu, 8 Oct 2026 15:36:39 +0200 Subject: [PATCH 3/6] fix(#8111): fix remaining kill_switch review findings and update docs Addresses the remaining findings from PR review: - GitHub (reusable-dispatch.yml): switch to `yq -o=json '.kill_switch'` for both the overlay and base reads. Raw yq output preserves the source spelling of a scalar, so a bare `kill_switch:`, `~`, or `Null` printed as something other than the literal string "null" and was treated as an explicit overlay value, skipping an active base kill switch. -o=json normalizes every null spelling to `null` and every boolean case variant to lowercase, so the previous case-insensitive comparison workaround is no longer needed. - pkg/behaviourtest/steps/cleanup.go: ValidateSlotClean's layered parse fails closed on a malformed config.base.yaml before the overlay is ever examined (base is parsed first). A malformed base left behind by a failed scenario was therefore masking real overlay staleness (e.g. an overlay kill_switch: true left on). Fall back to an overlay-only parse in that case so the overlay is still checked, and report the malformed base itself as stale state. - docs/contributing/config-source-inventory.md: move the kill_switch row to the "already layered" table now that both forges' direct reads consult config.base.yaml. - docs/guides/dev/behaviour-testing.md: document the new "the kill switch is active in config.base.yaml" step, and note the kill switch can be set in either file. Adds regression tests for both code fixes, each confirmed to fail against the pre-fix code. Signed-off-by: fmuntean Co-authored-by: Cursor --- .github/workflows/reusable-dispatch.yml | 11 +- docs/contributing/config-source-inventory.md | 2 +- docs/guides/dev/behaviour-testing.md | 6 +- internal/scaffold/github_kill_switch_test.go | 163 +++++++++++++++++ internal/scaffold/gitlab_job_scripts_test.go | 152 ---------------- internal/scaffold/gitlab_kill_switch_test.go | 174 +++++++++++++++++++ pkg/behaviourtest/steps/cleanup.go | 16 +- pkg/behaviourtest/steps/cleanup_test.go | 19 ++ 8 files changed, 384 insertions(+), 159 deletions(-) create mode 100644 internal/scaffold/github_kill_switch_test.go create mode 100644 internal/scaffold/gitlab_kill_switch_test.go diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index f062145d8f..16340536e5 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -499,20 +499,25 @@ jobs: # config.yaml sets kill_switch at all, that value is final # and config.base.yaml is ignored; config.base.yaml is only # consulted when config.yaml is silent on the key. + # -o=json normalizes every YAML null spelling (bare key, ~, + # Null, NULL) to the literal "null", and every boolean case + # variant (True, FALSE, ...) to lowercase true/false — so the + # sentinel check below and the final comparison both work + # regardless of source spelling. KILL_SWITCH="false" OVERLAY_KS="null" if [[ -f .fullsend/config.yaml ]]; then - OVERLAY_KS=$(yq '.kill_switch' .fullsend/config.yaml) + OVERLAY_KS=$(yq -o=json '.kill_switch' .fullsend/config.yaml) fi if [[ "$OVERLAY_KS" != "null" ]]; then KILL_SWITCH="$OVERLAY_KS" elif [[ -f .fullsend/config.base.yaml ]]; then - BASE_KS=$(yq '.kill_switch' .fullsend/config.base.yaml) + BASE_KS=$(yq -o=json '.kill_switch' .fullsend/config.base.yaml) if [[ "$BASE_KS" != "null" ]]; then KILL_SWITCH="$BASE_KS" fi fi - if [[ "${KILL_SWITCH,,}" == "true" ]]; then + if [[ "$KILL_SWITCH" == "true" ]]; then echo "::error::Kill switch is active — all agent dispatch halted" echo "::error::Set kill_switch: false in .fullsend/config.yaml or .fullsend/config.base.yaml to resume" exit 1 diff --git a/docs/contributing/config-source-inventory.md b/docs/contributing/config-source-inventory.md index c213981c0a..cf34f9c04a 100644 --- a/docs/contributing/config-source-inventory.md +++ b/docs/contributing/config-source-inventory.md @@ -81,6 +81,7 @@ These fields live on `perRepoConfig` in `internal/config/config.go`. Unset means | `status_notifications` | Start and completion comments and reactions | Overlay, base, compiled unset | Whole object replaces the parent when set | Status posting | Already layered | Yes, when a fleet wants one notification policy. | | `models.aliases` | Remap of `opus`, `sonnet`, `haiku`, `fable` | Overlay, base, compiled alias table | Per-key merge, then the compiled table | Model resolution | Already layered | Yes. Fleet model pins belong here. | | `inference.provider` | Inference backend id | Overlay, base, compiled `vertex` | Overlay, then base, then `vertex`. No workflow variable found | Accessor at install and run setup | Already layered | Yes. | +| `kill_switch` | Stop all agent dispatch | Overlay, base, compiled `false` | Overlay, then base, then `false`. Both direct reads — GitHub's "Check kill switch" bash step and GitLab's `run-agent-job.sh` — now consult `config.base.yaml` when `config.yaml` is silent on the key, matching the Go accessor | `internal/harnessdispatch`, `reusable-dispatch.yml`, and GitLab's `run-agent-job.sh` | Already layered | Yes. A central stop belongs in the base file. | `authorization` (extra permission sources, today `owners_file`) is overlay-only by design, not an accessor gap: a base-file value under this @@ -97,7 +98,6 @@ The Go accessor layers these. The bash steps in `.github/workflows/reusable-disp | Setting | Controls | Set from | Wins today | Read by | Decision | Base file? | |---|---|---|---|---|---|---| -| `kill_switch` | Stop all agent dispatch | Overlay, base, compiled `false` | Go accessor: overlay, then base, then `false`. Bash "Check kill switch": `yq '.kill_switch'` on `config.yaml` only. A missing file does not halt dispatch | `internal/harnessdispatch` and `reusable-dispatch.yml` | Layer the direct read so a base-file `true` halts dispatch | Yes. A central stop belongs in the base file. | | `roles` | Which agent roles are enabled | Overlay, base, compiled default role list | Go accessor: replace-if-set, so an explicit empty `roles: []` denies every role. Bash "Check role is enabled": `yq '.roles[]'` on `config.yaml` only, piped through `\|\| echo ""`. An omitted key, a missing file, an explicit `roles: []`, or any `yq` error all leave `$ROLES` empty, and the script only skips the stage when `$ROLES` is non-empty — so all four cases fail open and let the stage run, the opposite of the Go accessor's deny-all | Go accessor and `reusable-dispatch.yml` | Layer the direct read, and make the bash script fail closed on an explicit empty list, not just add the base file | Yes, for the shared role set. An overlay list replaces it. | | `agents` | Registered agents and per-agent `runtime`, `model`, `effort`, `subagents` | Overlay, base, compiled none | Go accessor: keyed merge by agent name. Bash validates the shape of `config.yaml` only | Go run path and `reusable-dispatch.yml` | Layer the direct read for enablement and role checks. Per-agent runtime, model, and effort still lose to flags and environment variables; those rows are below | Yes, for the shared agent baseline. | diff --git a/docs/guides/dev/behaviour-testing.md b/docs/guides/dev/behaviour-testing.md index e11544df42..1a308829fa 100644 --- a/docs/guides/dev/behaviour-testing.md +++ b/docs/guides/dev/behaviour-testing.md @@ -389,7 +389,7 @@ The `fork-dispatch.feature` file defines the canonical fork-PR behaviour contrac | Fork PR `synchronize` + label dispatches harness | Harness dispatched exactly 1 time; workflow completes | Separate scenario with sync commit + label | | CEL `is_fork` exclusion (`!event.state.change_proposal.is_fork`) | Empty matrix, exit 0 | Harness with `is_fork` guard in positive scenario; assert agent did not run | -**Kill switch vs disabled harness:** These are distinct mechanisms. The **kill switch** (`kill_switch: true` in `config.yaml`) is a global emergency stop that blocks *all* harness dispatch for the repo — tested in its own scenario because no positive harness can run alongside it. A **disabled harness** (`enabled: false` per agent entry) only prevents that single agent from running — tested as a piggyback negative assertion in the positive-path scenario. +**Kill switch vs disabled harness:** These are distinct mechanisms. The **kill switch** (`kill_switch: true`, settable in either `config.yaml` or `config.base.yaml`) is a global emergency stop that blocks *all* harness dispatch for the repo — tested in its own scenario because no positive harness can run alongside it. A **disabled harness** (`enabled: false` per agent entry) only prevents that single agent from running — tested as a piggyback negative assertion in the positive-path scenario. **Consolidation pattern:** To conserve parallel execution slots, add negative-path harnesses (disabled agent, CEL exclusion) alongside the positive-path harness in a single scenario rather than creating separate scenarios. The positive harness wait acts as the settle window for negative assertions (piggyback pattern — see `negativeSettleDuration` in `dispatch.go`). The kill switch scenario cannot be consolidated because it blocks all harnesses. @@ -399,7 +399,9 @@ The `fork-dispatch.feature` file defines the canonical fork-PR behaviour contrac **`a disabled custom harness "" with:`** — Registers the harness YAML under `.fullsend/harness/.yaml` and adds an agent entry with `enabled: false` to the repo's `config.yaml`. Use this step for negative dispatch assertions where a single agent should be excluded while other agents in the same scenario continue to run. This is *not* the kill switch; for the global emergency stop that blocks all harnesses, use `the kill switch is active`. -**`the kill switch is active`** — Sets `kill_switch: true` in the repo's `config.yaml`, causing `Dispatch` to return an empty matrix for *all* agents. Use this step in a dedicated scenario where no harness should run. Because the kill switch blocks everything, it cannot share a scenario with a positive-path harness. +**`the kill switch is active`** — Sets `kill_switch: true` in the repo's `config.yaml` (the overlay), causing `Dispatch` to return an empty matrix for *all* agents. Use this step in a dedicated scenario where no harness should run. Because the kill switch blocks everything, it cannot share a scenario with a positive-path harness. + +**`the kill switch is active in config.base.yaml`** — Sets `kill_switch: true` in `config.base.yaml` (the central/base layer) instead, leaving `config.yaml` unset. Use this step to verify that a base-file kill switch halts dispatch the same way an overlay one does, since the two files are read independently. ## Forge operational constraints diff --git a/internal/scaffold/github_kill_switch_test.go b/internal/scaffold/github_kill_switch_test.go new file mode 100644 index 0000000000..16b6a3acee --- /dev/null +++ b/internal/scaffold/github_kill_switch_test.go @@ -0,0 +1,163 @@ +package scaffold + +import ( + "os" + "os/exec" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" +) + +// ghWorkflowStep and friends mirror just enough of +// .github/workflows/reusable-dispatch.yml's shape to extract a single +// step's `run:` script for isolated execution. Unknown fields (if, +// env, uses, with, permissions, outputs, ...) are ignored by +// yaml.Unmarshal. +type ghWorkflowStep struct { + Name string `yaml:"name"` + Run string `yaml:"run"` +} + +type ghWorkflowJob struct { + Steps []ghWorkflowStep `yaml:"steps"` +} + +type ghWorkflowFile struct { + Jobs map[string]ghWorkflowJob `yaml:"jobs"` +} + +// extractReusableDispatchStepScript reads reusable-dispatch.yml from +// the repo root and returns the `run:` script text of the named step +// in the named job, so it can be executed in isolation against +// fixture .fullsend/config.yaml files without spinning up a real +// Actions run. +func extractReusableDispatchStepScript(t *testing.T, jobName, stepName string) string { + t.Helper() + path := filepath.Join("..", "..", ".github", "workflows", "reusable-dispatch.yml") + content, err := os.ReadFile(path) + require.NoError(t, err) + + var wf ghWorkflowFile + require.NoError(t, yaml.Unmarshal(content, &wf)) + + job, ok := wf.Jobs[jobName] + require.True(t, ok, "job %q not found in reusable-dispatch.yml", jobName) + for _, step := range job.Steps { + if step.Name == stepName { + require.NotEmpty(t, step.Run, "step %q has no run script", stepName) + return step.Run + } + } + t.Fatalf("step %q not found in job %q", stepName, jobName) + return "" +} + +func TestCheckKillSwitchStep_ConsultsConfigBaseYAML(t *testing.T) { + if _, err := exec.LookPath("yq"); err != nil { + t.Skip("yq not found in PATH") + } + + script := extractReusableDispatchStepScript(t, "route", "Check kill switch") + + cases := []struct { + name string + configYAML string + configBaseYAML string + wantHalt bool + }{ + { + name: "overlay true halts dispatch", + configYAML: "kill_switch: true\n", + wantHalt: true, + }, + { + name: "overlay silent, base active halts dispatch", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + }, + { + name: "overlay explicit false overrides base active", + configYAML: "kill_switch: false\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: false, + }, + { + name: "neither file sets kill_switch", + wantHalt: false, + }, + { + name: "overlay True (capital) halts dispatch", + configYAML: "kill_switch: True\n", + wantHalt: true, + }, + { + name: "base True (capital) halts dispatch when overlay is silent", + configBaseYAML: "kill_switch: True\n", + wantHalt: true, + }, + { + name: "overlay kill_switch: null falls through to base", + configYAML: "kill_switch: null\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + }, + { + name: "overlay true survives a malformed base file", + configYAML: "kill_switch: true\n", + configBaseYAML: "kill_switch: [unterminated\n", + wantHalt: true, + }, + { + name: "overlay bare kill_switch: falls through to base", + configYAML: "kill_switch:\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + }, + { + name: "overlay kill_switch: ~ falls through to base", + configYAML: "kill_switch: ~\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + }, + { + name: "overlay kill_switch: Null falls through to base", + configYAML: "kill_switch: Null\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + }, + { + name: "overlay present but silent on kill_switch falls through to base", + configYAML: "# no kill_switch key here\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + root := t.TempDir() + require.NoError(t, os.MkdirAll(filepath.Join(root, ".fullsend"), 0o755)) + if tc.configYAML != "" { + require.NoError(t, os.WriteFile(filepath.Join(root, ".fullsend", "config.yaml"), []byte(tc.configYAML), 0o644)) + } + if tc.configBaseYAML != "" { + require.NoError(t, os.WriteFile(filepath.Join(root, ".fullsend", "config.base.yaml"), []byte(tc.configBaseYAML), 0o644)) + } + + scriptPath := filepath.Join(root, "check-kill-switch.sh") + require.NoError(t, os.WriteFile(scriptPath, []byte(script), 0o755)) + + cmd := exec.Command("bash", scriptPath) + cmd.Dir = root + out, err := cmd.CombinedOutput() + + if tc.wantHalt { + require.Error(t, err, "stdout/stderr: %s", out) + } else { + require.NoError(t, err, "stdout/stderr: %s", out) + } + }) + } +} diff --git a/internal/scaffold/gitlab_job_scripts_test.go b/internal/scaffold/gitlab_job_scripts_test.go index ddf5cec881..1770d3d5ab 100644 --- a/internal/scaffold/gitlab_job_scripts_test.go +++ b/internal/scaffold/gitlab_job_scripts_test.go @@ -49,38 +49,6 @@ func setupPinnedConfigOrigin(t *testing.T, root string) { gitCmd(t, root, "remote", "add", "origin", upstream) } -// setupConfigOrigin is like setupPinnedConfigOrigin but lets the caller -// control the content of .fullsend/config.yaml (the overlay) and -// .fullsend/config.base.yaml (the base) committed to the origin -// remote's main branch independently. Pass "" for either argument to -// omit that file entirely (as opposed to committing it with empty -// content), so tests can exercise the "key/file absent" fallback path -// distinctly from "file present but doesn't set the key". -func setupConfigOrigin(t *testing.T, root, configYAML, configBaseYAML string) { - t.Helper() - upstream := t.TempDir() - initGitRepo(t, upstream) - if configYAML != "" { - require.NoError(t, os.MkdirAll(filepath.Join(upstream, ".fullsend"), 0o755)) - require.NoError(t, os.WriteFile(filepath.Join(upstream, ".fullsend/config.yaml"), []byte(configYAML), 0o644)) - gitCmd(t, upstream, "add", ".fullsend/config.yaml") - } - if configBaseYAML != "" { - require.NoError(t, os.MkdirAll(filepath.Join(upstream, ".fullsend"), 0o755)) - require.NoError(t, os.WriteFile(filepath.Join(upstream, ".fullsend/config.base.yaml"), []byte(configBaseYAML), 0o644)) - gitCmd(t, upstream, "add", ".fullsend/config.base.yaml") - } - // A placeholder file guarantees there is always at least one - // tracked file to commit, even in the "neither config file - // exists" case. - require.NoError(t, os.WriteFile(filepath.Join(upstream, "README.md"), []byte("placeholder\n"), 0o644)) - gitCmd(t, upstream, "add", "README.md") - gitCmd(t, upstream, "commit", "-m", "trusted config") - - initGitRepo(t, root) - gitCmd(t, root, "remote", "add", "origin", upstream) -} - func TestRunPollJobScript_RejectsInvalidPollMode(t *testing.T) { root := t.TempDir() writeGitLabScript(t, root, ".gitlab/ci/scripts/trust-ci-server-ca.sh") @@ -1188,126 +1156,6 @@ esac assert.NotContains(t, got, "malicious") } -// TestRunAgentJobScript_KillSwitchConsultsConfigBaseYAML exercises -// run-agent-job.sh's kill-switch check end to end: config.base.yaml is -// consulted only when config.yaml is silent on the key, an explicit -// config.yaml value (including false) always wins outright, and a YAML -// parse failure logs a warning and falls through as unconfigured -// rather than halting dispatch. -func TestRunAgentJobScript_KillSwitchConsultsConfigBaseYAML(t *testing.T) { - const secret = "test-hmac-secret" - hmacHex := computeDispatchHMAC(secret, "5", "", "", "", "", "", "", "", "test-key", "triage", "") - - cases := []struct { - name string - configYAML string - configBaseYAML string - wantHalt bool - wantOutput string - }{ - { - name: "overlay silent, base active halts dispatch", - configBaseYAML: "kill_switch: true\n", - wantHalt: true, - wantOutput: "Kill switch is active", - }, - { - name: "overlay explicit false overrides base active", - configYAML: "kill_switch: false\n", - configBaseYAML: "kill_switch: true\n", - wantHalt: false, - }, - { - name: "neither file sets kill_switch", - wantHalt: false, - }, - { - name: "malformed overlay logs a warning and falls through", - configYAML: "kill_switch: [unterminated\n", - wantHalt: false, - wantOutput: "WARNING: invalid .fullsend/config.yaml or .fullsend/config.base.yaml — treating as unconfigured", - }, - } - - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - root := t.TempDir() - writeGitLabScript(t, root, ".gitlab/ci/scripts/trust-ci-server-ca.sh") - writeGitLabScript(t, root, gitlabPinCIJobIdentityScriptPath) - writeGitLabScript(t, root, ".gitlab/ci/scripts/select-gitlab-role-token.sh") - script := writeGitLabScript(t, root, gitlabRunAgentJobScriptPath) - - mux := http.NewServeMux() - mux.HandleFunc("/api/v4/job", func(w http.ResponseWriter, _ *http.Request) { - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(pinJobJSON("42", "100", "main"))) - }) - mux.HandleFunc("/api/v4/user", func(w http.ResponseWriter, _ *http.Request) { - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(`{"id":7,"username":"fullsend-bot"}`)) - }) - mux.HandleFunc("/api/v4/projects/", func(w http.ResponseWriter, r *http.Request) { - path := r.URL.Path - switch { - case strings.Contains(path, "/repository/branches/"): - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(`{"name":"main","protected":true}`)) - case strings.Contains(path, "/pipelines/"): - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(`{"id":100,"source":"api","user":{"id":7}}`)) - case strings.Contains(path, "/resource_groups/"): - w.WriteHeader(http.StatusOK) - case strings.Contains(path, "/members/all/"): - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(`{"access_level":40}`)) - default: - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(`{"id":42,"default_branch":"main","path_with_namespace":"group/project"}`)) - } - }) - srv := httptest.NewTLSServer(mux) - t.Cleanup(srv.Close) - - bin := t.TempDir() - require.NoError(t, os.WriteFile(filepath.Join(bin, "fullsend"), []byte("#!/bin/sh\nexit 0\n"), 0o755)) - - setupConfigOrigin(t, root, tc.configYAML, tc.configBaseYAML) - - cmd := exec.Command("bash", "-c", "set -euo pipefail; . \"$SCRIPT\"") - cmd.Dir = root - cmd.Env = append([]string{ - "SCRIPT=" + script, - "PATH=" + bin + ":" + os.Getenv("PATH"), - "HOME=" + t.TempDir(), - "CI_PROJECT_DIR=" + root, - "RUNNER_TEMP=" + t.TempDir(), - "CI_JOB_TOKEN=job-token", - "FULLSEND_GITLAB_POLLER_TOKEN=poller-pat", - "FULLSEND_GITLAB_ANALYST_TOKEN=analyst-pat", - "STAGE=triage", - "RESOURCE_KEY=test-key", - "ACTOR_ID=5", - "FULLSEND_DISPATCH_SECRET=" + secret, - "FULLSEND_DISPATCH_HMAC=" + hmacHex, - "CI_PROJECT_PATH=group/project", - "CI_SERVER_URL=https://gitlab.example", - "CI_PIPELINE_URL=https://gitlab.example/group/project/-/pipelines/100", - "CI_PROJECT_ID=1", - }, pinTLSEnv(t, srv)...) - out, err := cmd.CombinedOutput() - - if tc.wantHalt { - require.Error(t, err, "stdout/stderr: %s", out) - } else { - require.NoError(t, err, "stdout/stderr: %s", out) - } - if tc.wantOutput != "" { - assert.Contains(t, string(out), tc.wantOutput) - } - }) - } -} - // TestRunAgentJobScript_RejectsDisagreeingMergeRequestTargetBranchName is a // regression test for the logic-error finding: this job's admit source is // api-only (parent_pipeline is not an admitted arm — see FULLSEND_ADMIT_SOURCE diff --git a/internal/scaffold/gitlab_kill_switch_test.go b/internal/scaffold/gitlab_kill_switch_test.go new file mode 100644 index 0000000000..8cd9bf08fd --- /dev/null +++ b/internal/scaffold/gitlab_kill_switch_test.go @@ -0,0 +1,174 @@ +package scaffold + +import ( + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// setupConfigOrigin is like setupPinnedConfigOrigin but lets the caller +// control the content of .fullsend/config.yaml (the overlay) and +// .fullsend/config.base.yaml (the base) committed to the origin +// remote's main branch independently. Pass "" for either argument to +// omit that file entirely (as opposed to committing it with empty +// content), so tests can exercise the "key/file absent" fallback path +// distinctly from "file present but doesn't set the key". +func setupConfigOrigin(t *testing.T, root, configYAML, configBaseYAML string) { + t.Helper() + upstream := t.TempDir() + initGitRepo(t, upstream) + if configYAML != "" { + require.NoError(t, os.MkdirAll(filepath.Join(upstream, ".fullsend"), 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(upstream, ".fullsend/config.yaml"), []byte(configYAML), 0o644)) + gitCmd(t, upstream, "add", ".fullsend/config.yaml") + } + if configBaseYAML != "" { + require.NoError(t, os.MkdirAll(filepath.Join(upstream, ".fullsend"), 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(upstream, ".fullsend/config.base.yaml"), []byte(configBaseYAML), 0o644)) + gitCmd(t, upstream, "add", ".fullsend/config.base.yaml") + } + // A placeholder file guarantees there is always at least one + // tracked file to commit, even in the "neither config file + // exists" case. + require.NoError(t, os.WriteFile(filepath.Join(upstream, "README.md"), []byte("placeholder\n"), 0o644)) + gitCmd(t, upstream, "add", "README.md") + gitCmd(t, upstream, "commit", "-m", "trusted config") + + initGitRepo(t, root) + gitCmd(t, root, "remote", "add", "origin", upstream) +} + +func TestRunAgentJobScript_KillSwitchConsultsConfigBaseYAML(t *testing.T) { + const secret = "test-hmac-secret" + hmacHex := computeDispatchHMAC(secret, "5", "", "", "", "", "", "", "", "test-key", "triage", "") + + cases := []struct { + name string + configYAML string + configBaseYAML string + wantHalt bool + wantOutput string + }{ + { + name: "overlay silent, base active halts dispatch", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + wantOutput: "Kill switch is active", + }, + { + name: "overlay explicit false overrides base active", + configYAML: "kill_switch: false\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: false, + }, + { + name: "neither file sets kill_switch", + wantHalt: false, + }, + { + name: "malformed overlay logs a warning and falls through", + configYAML: "kill_switch: [unterminated\n", + wantHalt: false, + wantOutput: "WARNING: invalid .fullsend/config.yaml or .fullsend/config.base.yaml — treating as unconfigured", + }, + { + name: "overlay kill_switch: null falls through to base", + configYAML: "kill_switch: null\n", + configBaseYAML: "kill_switch: true\n", + wantHalt: true, + wantOutput: "Kill switch is active", + }, + { + name: "overlay true survives a malformed base file", + configYAML: "kill_switch: true\n", + configBaseYAML: "kill_switch: [unterminated\n", + wantHalt: true, + wantOutput: "Kill switch is active", + }, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + root := t.TempDir() + writeGitLabScript(t, root, ".gitlab/ci/scripts/trust-ci-server-ca.sh") + writeGitLabScript(t, root, gitlabPinCIJobIdentityScriptPath) + writeGitLabScript(t, root, ".gitlab/ci/scripts/select-gitlab-role-token.sh") + script := writeGitLabScript(t, root, gitlabRunAgentJobScriptPath) + + mux := http.NewServeMux() + mux.HandleFunc("/api/v4/job", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(pinJobJSON("42", "100", "main"))) + }) + mux.HandleFunc("/api/v4/user", func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"id":7,"username":"fullsend-bot"}`)) + }) + mux.HandleFunc("/api/v4/projects/", func(w http.ResponseWriter, r *http.Request) { + path := r.URL.Path + switch { + case strings.Contains(path, "/repository/branches/"): + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"name":"main","protected":true}`)) + case strings.Contains(path, "/pipelines/"): + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"id":100,"source":"api","user":{"id":7}}`)) + case strings.Contains(path, "/resource_groups/"): + w.WriteHeader(http.StatusOK) + case strings.Contains(path, "/members/all/"): + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"access_level":40}`)) + default: + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"id":42,"default_branch":"main","path_with_namespace":"group/project"}`)) + } + }) + srv := httptest.NewTLSServer(mux) + t.Cleanup(srv.Close) + + bin := t.TempDir() + require.NoError(t, os.WriteFile(filepath.Join(bin, "fullsend"), []byte("#!/bin/sh\nexit 0\n"), 0o755)) + + setupConfigOrigin(t, root, tc.configYAML, tc.configBaseYAML) + + cmd := exec.Command("bash", "-c", "set -euo pipefail; . \"$SCRIPT\"") + cmd.Dir = root + cmd.Env = append([]string{ + "SCRIPT=" + script, + "PATH=" + bin + ":" + os.Getenv("PATH"), + "HOME=" + t.TempDir(), + "CI_PROJECT_DIR=" + root, + "RUNNER_TEMP=" + t.TempDir(), + "CI_JOB_TOKEN=job-token", + "FULLSEND_GITLAB_POLLER_TOKEN=poller-pat", + "FULLSEND_GITLAB_ANALYST_TOKEN=analyst-pat", + "STAGE=triage", + "RESOURCE_KEY=test-key", + "ACTOR_ID=5", + "FULLSEND_DISPATCH_SECRET=" + secret, + "FULLSEND_DISPATCH_HMAC=" + hmacHex, + "CI_PROJECT_PATH=group/project", + "CI_SERVER_URL=https://gitlab.example", + "CI_PIPELINE_URL=https://gitlab.example/group/project/-/pipelines/100", + "CI_PROJECT_ID=1", + }, pinTLSEnv(t, srv)...) + out, err := cmd.CombinedOutput() + + if tc.wantHalt { + require.Error(t, err, "stdout/stderr: %s", out) + } else { + require.NoError(t, err, "stdout/stderr: %s", out) + } + if tc.wantOutput != "" { + assert.Contains(t, string(out), tc.wantOutput) + } + }) + } +} diff --git a/pkg/behaviourtest/steps/cleanup.go b/pkg/behaviourtest/steps/cleanup.go index 1a6b414964..8d9e28812c 100644 --- a/pkg/behaviourtest/steps/cleanup.go +++ b/pkg/behaviourtest/steps/cleanup.go @@ -74,7 +74,21 @@ func ValidateSlotClean(w *world.World) error { } cfg, err := config.ParsePerRepoConfigWriterLayered(cfgData, baseData) if err != nil { - return nil + // Fall back to an overlay-only parse so the + // overlay is still checked, and flag the malformed base + // itself as stale state worth reporting. + overlayCfg, overlayErr := config.ParsePerRepoConfigWriter(cfgData) + if overlayErr != nil { + return nil + } + stale := []string{fmt.Sprintf("config.base.yaml is malformed: %v", err)} + if overlayCfg.IsKillSwitchActive() { + stale = append(stale, "kill_switch is active") + } + if overlayCfg.IsOwnersFileAuthEnabled() { + stale = append(stale, "owners_file authorization is enabled") + } + return fmt.Errorf("repo slot has stale state from a previous scenario (cleanup likely failed): %s", strings.Join(stale, ", ")) } var stale []string if cfg.IsKillSwitchActive() { diff --git a/pkg/behaviourtest/steps/cleanup_test.go b/pkg/behaviourtest/steps/cleanup_test.go index 758f2f5467..4aca46356f 100644 --- a/pkg/behaviourtest/steps/cleanup_test.go +++ b/pkg/behaviourtest/steps/cleanup_test.go @@ -1315,6 +1315,25 @@ func TestValidateSlotClean(t *testing.T) { require.NoError(t, ValidateSlotClean(w)) }) + t.Run("malformed config.base.yaml does not mask an overlay kill switch left on", func(t *testing.T) { + t.Parallel() + w := leased(slotConfig(t, func(c config.PerRepoConfigWriter) { c.SetKillSwitch(true) })) + w.SCM.(*fakeCleanupSCM).baseFileConfigured = true + w.SCM.(*fakeCleanupSCM).baseFileContent = []byte("kill_switch: [unterminated\n") + err := ValidateSlotClean(w) + require.ErrorContains(t, err, "config.base.yaml is malformed") + require.ErrorContains(t, err, "kill_switch is active") + }) + + t.Run("malformed config.base.yaml alone is reported as stale", func(t *testing.T) { + t.Parallel() + w := leased(slotConfig(t, nil)) + w.SCM.(*fakeCleanupSCM).baseFileConfigured = true + w.SCM.(*fakeCleanupSCM).baseFileContent = []byte("kill_switch: [unterminated\n") + err := ValidateSlotClean(w) + require.ErrorContains(t, err, "config.base.yaml is malformed") + }) + t.Run("no leased repo", func(t *testing.T) { t.Parallel() require.NoError(t, ValidateSlotClean(&world.World{Org: "org", SCM: &fakeCleanupSCM{}})) From acce65067a310f17c17900ffc34e9037b880ebbb Mon Sep 17 00:00:00 2001 From: fmuntean Date: Fri, 9 Oct 2026 10:41:53 +0200 Subject: [PATCH 4/6] fix(#8111): recognize yes/no kill_switch spellings on GitHub route check GitHub's yq -o=json-based check only recognized true/false case variants; go-yaml's lenient *bool decoding (used by IsKillSwitchActive()) and GitLab's PyYAML-based check both already treat yes/on as true and no/off as false. Add yes/"yes" (case-insensitive) recognition to the GitHub check, closing two fail-open gaps on that spelling. on/off and single-letter y/n remain intentionally unhandled (documented as a known limitation, not chased to full parity). Verified GitLab's existing check needs no change: its ('true','yes','1','on') string-tuple comparison already matches regardless of whether PyYAML coerces the YAML scalar to a bool or leaves it as a string. Adds test coverage for the yes/no spelling matrix on both forges. Signed-off-by: fmuntean Co-authored-by: Cursor --- .github/workflows/reusable-dispatch.yml | 14 ++++-- internal/scaffold/github_kill_switch_test.go | 50 ++++++++++++++++++++ internal/scaffold/gitlab_kill_switch_test.go | 17 +++++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index 16340536e5..5ec506b358 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -500,10 +500,14 @@ jobs: # and config.base.yaml is ignored; config.base.yaml is only # consulted when config.yaml is silent on the key. # -o=json normalizes every YAML null spelling (bare key, ~, - # Null, NULL) to the literal "null", and every boolean case - # variant (True, FALSE, ...) to lowercase true/false — so the - # sentinel check below and the final comparison both work - # regardless of source spelling. + # Null, NULL) to the literal "null", and the true/false + # case variants (True, FALSE, ...) to lowercase. It does not + # normalize the YAML 1.1 word booleans yq treats as plain + # strings (yes/no/on/off print as quoted JSON strings, e.g. + # "yes"), so yes/"yes" is matched explicitly below, where + # go-yaml's lenient *bool decoding also treats it as active. + # on/off and the single-letter y/n forms are deliberately + # not matched. KILL_SWITCH="false" OVERLAY_KS="null" if [[ -f .fullsend/config.yaml ]]; then @@ -517,7 +521,7 @@ jobs: KILL_SWITCH="$BASE_KS" fi fi - if [[ "$KILL_SWITCH" == "true" ]]; then + if [[ "${KILL_SWITCH,,}" == "true" || "${KILL_SWITCH,,}" == '"yes"' ]]; then echo "::error::Kill switch is active — all agent dispatch halted" echo "::error::Set kill_switch: false in .fullsend/config.yaml or .fullsend/config.base.yaml to resume" exit 1 diff --git a/internal/scaffold/github_kill_switch_test.go b/internal/scaffold/github_kill_switch_test.go index 16b6a3acee..af87badbc5 100644 --- a/internal/scaffold/github_kill_switch_test.go +++ b/internal/scaffold/github_kill_switch_test.go @@ -133,6 +133,56 @@ func TestCheckKillSwitchStep_ConsultsConfigBaseYAML(t *testing.T) { configBaseYAML: "kill_switch: true\n", wantHalt: true, }, + { + name: "overlay yes (bare) halts dispatch", + configYAML: "kill_switch: yes\n", + wantHalt: true, + }, + { + name: "overlay Yes (capital) halts dispatch", + configYAML: "kill_switch: Yes\n", + wantHalt: true, + }, + { + name: `overlay "yes" (quoted) halts dispatch`, + configYAML: "kill_switch: \"yes\"\n", + wantHalt: true, + }, + { + name: "base yes halts dispatch when overlay is silent", + configBaseYAML: "kill_switch: yes\n", + wantHalt: true, + }, + { + name: "overlay no does not halt dispatch", + configYAML: "kill_switch: no\n", + wantHalt: false, + }, + { + name: `overlay "no" (quoted) does not halt dispatch`, + configYAML: "kill_switch: \"no\"\n", + wantHalt: false, + }, + { + name: "overlay on does not halt dispatch (on/off intentionally unsupported)", + configYAML: "kill_switch: on\n", + wantHalt: false, + }, + { + name: "overlay off does not halt dispatch (on/off intentionally unsupported)", + configYAML: "kill_switch: off\n", + wantHalt: false, + }, + { + name: "overlay y does not halt dispatch (y/n intentionally unsupported)", + configYAML: "kill_switch: y\n", + wantHalt: false, + }, + { + name: "overlay n does not halt dispatch (y/n intentionally unsupported)", + configYAML: "kill_switch: n\n", + wantHalt: false, + }, } for _, tc := range cases { diff --git a/internal/scaffold/gitlab_kill_switch_test.go b/internal/scaffold/gitlab_kill_switch_test.go index 8cd9bf08fd..4a2edad695 100644 --- a/internal/scaffold/gitlab_kill_switch_test.go +++ b/internal/scaffold/gitlab_kill_switch_test.go @@ -92,6 +92,23 @@ func TestRunAgentJobScript_KillSwitchConsultsConfigBaseYAML(t *testing.T) { wantHalt: true, wantOutput: "Kill switch is active", }, + { + name: "overlay yes (bare) halts dispatch", + configYAML: "kill_switch: yes\n", + wantHalt: true, + wantOutput: "Kill switch is active", + }, + { + name: `overlay "yes" (quoted) halts dispatch`, + configYAML: "kill_switch: \"yes\"\n", + wantHalt: true, + wantOutput: "Kill switch is active", + }, + { + name: "overlay no does not halt dispatch", + configYAML: "kill_switch: no\n", + wantHalt: false, + }, } for _, tc := range cases { From 14c04c47373b981b7e861ef73490391785488905 Mon Sep 17 00:00:00 2001 From: fmuntean Date: Mon, 12 Oct 2026 12:52:07 +0200 Subject: [PATCH 5/6] fix: run gofmt Signed-off-by: fmuntean --- pkg/behaviourtest/steps/cleanup_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/behaviourtest/steps/cleanup_test.go b/pkg/behaviourtest/steps/cleanup_test.go index 882be95d09..3932600490 100644 --- a/pkg/behaviourtest/steps/cleanup_test.go +++ b/pkg/behaviourtest/steps/cleanup_test.go @@ -3,8 +3,8 @@ package steps import ( "context" "fmt" - "strings" "path/filepath" + "strings" "testing" "time" From 1d9e8be26ef6b2d814d409406a08cbee2b7dfca3 Mon Sep 17 00:00:00 2001 From: fmuntean Date: Wed, 14 Oct 2026 13:00:44 +0200 Subject: [PATCH 6/6] fix(#8111): preserve quoted-true halt on GitHub kill-switch check The -o=json switch (added earlier in this branch to fix the null-spelling bypass) regressed quoted scalars: a quoted kill_switch: "true"/'true' now prints as the JSON string "true" instead of the bare boolean true, so the existing "${KILL_SWITCH,,}" == "true" comparison no longer matched it, silently failing open. The old pre-branch step (yq without -o=json) had accidentally halted on this case, since its non-JSON output rendered a quoted string identically to a bare boolean. Strip a leading/trailing double quote from KILL_SWITCH before comparing, so true/"true"/'true'/yes/"yes" are all recognized again. on/off and single-letter y/n remain intentionally unhandled. Adds overlay and base test rows for the quoted-true regression. Signed-off-by: fmuntean Co-authored-by: Cursor --- .github/workflows/reusable-dispatch.yml | 14 +++++++++++--- internal/scaffold/github_kill_switch_test.go | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index c812a68dc8..f50f5b4dff 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -506,10 +506,15 @@ jobs: # case variants (True, FALSE, ...) to lowercase. It does not # normalize the YAML 1.1 word booleans yq treats as plain # strings (yes/no/on/off print as quoted JSON strings, e.g. - # "yes"), so yes/"yes" is matched explicitly below, where + # "yes"), so yes is matched explicitly below, where # go-yaml's lenient *bool decoding also treats it as active. # on/off and the single-letter y/n forms are deliberately - # not matched. + # not matched. -o=json also keeps surrounding quotes on any + # scalar that was itself quoted in the source YAML (e.g. + # kill_switch: "true" prints as the JSON string "true", not + # the JSON boolean true), so those quotes are stripped below + # before comparing, matching go-yaml's lenient *bool + # decoding of a quoted "true"/"yes" scalar. KILL_SWITCH="false" OVERLAY_KS="null" if [[ -f .fullsend/config.yaml ]]; then @@ -523,7 +528,10 @@ jobs: KILL_SWITCH="$BASE_KS" fi fi - if [[ "${KILL_SWITCH,,}" == "true" || "${KILL_SWITCH,,}" == '"yes"' ]]; then + KILL_SWITCH="${KILL_SWITCH,,}" + KILL_SWITCH="${KILL_SWITCH#\"}" + KILL_SWITCH="${KILL_SWITCH%\"}" + if [[ "$KILL_SWITCH" == "true" || "$KILL_SWITCH" == "yes" ]]; then echo "::error::Kill switch is active — all agent dispatch halted" echo "::error::Set kill_switch: false in .fullsend/config.yaml or .fullsend/config.base.yaml to resume" exit 1 diff --git a/internal/scaffold/github_kill_switch_test.go b/internal/scaffold/github_kill_switch_test.go index af87badbc5..46c8e98c31 100644 --- a/internal/scaffold/github_kill_switch_test.go +++ b/internal/scaffold/github_kill_switch_test.go @@ -183,6 +183,21 @@ func TestCheckKillSwitchStep_ConsultsConfigBaseYAML(t *testing.T) { configYAML: "kill_switch: n\n", wantHalt: false, }, + { + name: `overlay kill_switch: "true" (double-quoted) halts dispatch`, + configYAML: "kill_switch: \"true\"\n", + wantHalt: true, + }, + { + name: "overlay kill_switch: 'true' (single-quoted) halts dispatch", + configYAML: "kill_switch: 'true'\n", + wantHalt: true, + }, + { + name: `base kill_switch: "true" (double-quoted) halts dispatch when overlay is silent`, + configBaseYAML: "kill_switch: \"true\"\n", + wantHalt: true, + }, } for _, tc := range cases {