From 7971d132d406b1504128e0c9bc32dc92d2b25bf4 Mon Sep 17 00:00:00 2001 From: fullsend-code <278716306+fullsend-ai-coder[bot]@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:06:20 +0000 Subject: [PATCH 1/2] test(#9720): name file and line in workflow_sha trust failures TestWorkflowSHAUsesAreTrusted reported only the offending line's text, so a failure did not say which workflow or line to fix. The scan now lives in workflowSHAViolations, which returns "file:line: text" with a 1-based line number for each job.workflow_sha read that bypasses trustedWorkflowSHA. The test reports one error per violation. The rule itself is unchanged. TestWorkflowSHAViolationsNamesFileAndLine covers the message format with a synthetic workflow: a trusted read on line 6 and a bare read on line 7. TestWorkflowSHAUsesAreTrusted still fails until the nine bare reads in reusable-dispatch.yml and reusable-prioritize.yml use the trusted expression. Those edits are under .github/workflows/ and out of scope for this commit. With them applied in a scratch worktree, go test ./internal/scaffold/ passed. Note: pre-commit could not fetch hook repositories (TLS failure). The applicable hooks ran directly instead and passed: pre-commit-hooks v6.0.0 file checks, gofmt, go vet ./..., lint-broken-symlinks. scan-secrets covered gitleaks. Related to #9720 Co-Authored-By: Claude Opus 5.5 --- internal/scaffold/pr_trigger_test.go | 44 +++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/internal/scaffold/pr_trigger_test.go b/internal/scaffold/pr_trigger_test.go index 3ce1edc169..3cd4b46c2e 100644 --- a/internal/scaffold/pr_trigger_test.go +++ b/internal/scaffold/pr_trigger_test.go @@ -1,6 +1,7 @@ package scaffold import ( + "fmt" "regexp" "strings" "testing" @@ -135,26 +136,53 @@ func TestEveryCheckoutHasTrustedRef(t *testing.T) { } } +// workflowSHAViolations counts the lines in a workflow whose expressions read +// job.workflow_sha. For each line that reads it outside trustedWorkflowSHA it +// returns "file:line: text", with a 1-based line number. +func workflowSHAViolations(file string, content []byte) (uses int, violations []string) { + for i, line := range strings.Split(string(content), "\n") { + if !strings.Contains(line, "${{") || !strings.Contains(line, "job.workflow_sha") { + continue + } + uses++ + if strings.Contains(strings.ReplaceAll(line, trustedWorkflowSHA, ""), "job.workflow_sha") { + violations = append(violations, fmt.Sprintf("%s:%d: %s", file, i+1, strings.TrimSpace(line))) + } + } + return uses, violations +} + // TestWorkflowSHAUsesAreTrusted checks that every expression that reads // job.workflow_sha (checkout refs, CLI install and version inputs, cache // keys) goes through trustedWorkflowSHA. func TestWorkflowSHAUsesAreTrusted(t *testing.T) { for _, file := range []string{".github/workflows/reusable-dispatch.yml", ".github/workflows/reusable-prioritize.yml"} { t.Run(file, func(t *testing.T) { - var uses int - for _, line := range strings.Split(string(loadRepoFile(file)(t)), "\n") { - if !strings.Contains(line, "${{") || !strings.Contains(line, "job.workflow_sha") { - continue - } - uses++ - assert.NotContains(t, strings.ReplaceAll(line, trustedWorkflowSHA, ""), "job.workflow_sha", - "job.workflow_sha must be read through the trusted expression: %s", strings.TrimSpace(line)) + uses, violations := workflowSHAViolations(file, loadRepoFile(file)(t)) + for _, v := range violations { + t.Errorf("job.workflow_sha must be read through the trusted expression: %s", v) } assert.NotZero(t, uses) }) } } +// TestWorkflowSHAViolationsNamesFileAndLine checks that a bare +// job.workflow_sha read is reported with the workflow file and its 1-based +// line number, and that a read through trustedWorkflowSHA is not. +func TestWorkflowSHAViolationsNamesFileAndLine(t *testing.T) { + content := []byte("jobs:\n" + + " a:\n" + + " steps:\n" + + " - uses: actions/checkout@v4\n" + + " with:\n" + + " ref: ${{ " + trustedWorkflowSHA + " }}\n" + + " - run: gh api \"x?ref=${{ job.workflow_sha }}\"\n") + uses, violations := workflowSHAViolations("wf.yml", content) + assert.Equal(t, 2, uses) + assert.Equal(t, []string{`wf.yml:7: - run: gh api "x?ref=${{ job.workflow_sha }}"`}, violations) +} + // prDispatchGuard skips fork and Dependabot PRs on pull_request. const prDispatchGuard = "(github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name ==" + " github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]'))" From 141c9a30257108e42486155e9168b455788ad98c Mon Sep 17 00:00:00 2001 From: Wayne Sun Date: Thu, 19 Nov 2026 17:11:05 -0500 Subject: [PATCH 2/2] fix(workflows): read job.workflow_sha through the trusted expression in the startup-failure fallback #9206 fetches report-agent-startup-failure.sh with a bare ?ref=${{ job.workflow_sha }} in eight reusable-dispatch.yml jobs and in reusable-prioritize.yml. On a same-repo pull_request run of fullsend's own workflows that is the PR merge commit, so the reporter came from PR code, and TestWorkflowSHAUsesAreTrusted (#9230) fails on main. Use the same expression as the checkout refs, which resolves to the base sha there. Fixes #9720 Assisted-by: Claude Signed-off-by: Wayne Sun --- .github/workflows/reusable-dispatch.yml | 16 ++++++++-------- .github/workflows/reusable-prioritize.yml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index f52e60c1fd..84a985b42a 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -1650,7 +1650,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else @@ -1825,7 +1825,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else @@ -2041,7 +2041,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else @@ -2349,7 +2349,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else @@ -2502,7 +2502,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else @@ -2633,7 +2633,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else @@ -2832,7 +2832,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else @@ -3103,7 +3103,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else diff --git a/.github/workflows/reusable-prioritize.yml b/.github/workflows/reusable-prioritize.yml index 0b3ad0b5e6..d4ad1cf1e3 100644 --- a/.github/workflows/reusable-prioritize.yml +++ b/.github/workflows/reusable-prioritize.yml @@ -240,7 +240,7 @@ jobs: [[ -f "${script}" ]] || script=".fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh" if [[ ! -f "${script}" ]]; then script="${RUNNER_TEMP}/fullsend-agent-startup-failure.sh" - if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ job.workflow_sha }}" --jq .content)"; then + if encoded="$(gh api "repos/${{ job.workflow_repository }}/contents/.github/scripts/report-agent-startup-failure.sh?ref=${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }}" --jq .content)"; then printf '%s' "${encoded}" | base64 --decode > "${script}" chmod +x "${script}" else