diff --git a/.github/scripts/resolve-effective-mint-url-test.sh b/.github/scripts/resolve-effective-mint-url-test.sh new file mode 100755 index 0000000000..f695d62e08 --- /dev/null +++ b/.github/scripts/resolve-effective-mint-url-test.sh @@ -0,0 +1,295 @@ +#!/usr/bin/env bash +# resolve-effective-mint-url-test.sh — Tests for resolve-effective-mint-url.sh +# +# Run from the repo root: +# bash .github/scripts/resolve-effective-mint-url-test.sh + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPT="${SCRIPT_DIR}/resolve-effective-mint-url.sh" +BASH_ABS="$(command -v bash)" +FAILURES=0 + +if ! command -v yq >/dev/null 2>&1; then + echo "FAIL: yq is required to run resolve-effective-mint-url-test.sh" >&2 + exit 1 +fi + +TMPDIR="$(mktemp -d)" +trap 'rm -rf "${TMPDIR}"' EXIT + +run_resolve() { + local fallback="${1:-}" + local output_file="${TMPDIR}/github-output.txt" + local stderr_file="${TMPDIR}/resolve-stderr.txt" + local oldpwd="${PWD}" + : >"${output_file}" + : >"${stderr_file}" + cd "${TMPDIR}/repo" + GITHUB_OUTPUT="${output_file}" FALLBACK_MINT_URL="${fallback}" "${BASH_ABS}" "${SCRIPT}" 2>"${stderr_file}" + cd "${oldpwd}" + grep '^mint_url=' "${output_file}" | cut -d= -f2- +} + +run_resolve_stderr() { + local fallback="${1:-}" + local output_file="${TMPDIR}/github-output.txt" + local stderr_file="${TMPDIR}/resolve-stderr.txt" + local oldpwd="${PWD}" + : >"${output_file}" + : >"${stderr_file}" + cd "${TMPDIR}/repo" + GITHUB_OUTPUT="${output_file}" FALLBACK_MINT_URL="${fallback}" "${BASH_ABS}" "${SCRIPT}" 2>"${stderr_file}" + cd "${oldpwd}" + cat "${stderr_file}" +} + +assert_notice_contains() { + local name="$1" want="$2" stderr="$3" + if ! grep -F -- "${want}" <<<"${stderr}" >/dev/null; then + echo "FAIL: ${name}: expected notice containing ${want@Q}, stderr=${stderr@Q}" + FAILURES=$((FAILURES + 1)) + fi +} + +assert_no_notice_override() { + local name="$1" stderr="$2" + if grep -F -- "overrides FULLSEND_MINT_URL" <<<"${stderr}" >/dev/null; then + echo "FAIL: ${name}: unexpected override notice in stderr=${stderr@Q}" + FAILURES=$((FAILURES + 1)) + fi +} + +run_resolve_expect_fail() { + local fallback="${1:-}" + local name="${2}" + local expected="${3}" + local leak="${4:-}" + local output_file="${TMPDIR}/github-output.txt" + local stderr_file="${TMPDIR}/stderr.txt" + local oldpwd="${PWD}" + local got + local script_path="${RESOLVE_PATH:-${PATH}}" + : >"${output_file}" + : >"${stderr_file}" + cd "${TMPDIR}/repo" + if PATH="${script_path}" GITHUB_OUTPUT="${output_file}" FALLBACK_MINT_URL="${fallback}" "${BASH_ABS}" "${SCRIPT}" 2>"${stderr_file}"; then + cd "${oldpwd}" + echo "FAIL: ${name}: expected non-zero exit" + FAILURES=$((FAILURES + 1)) + return 0 + fi + cd "${oldpwd}" + got="$(cat "${stderr_file}")" + if ! grep -F -- "${expected}" "${stderr_file}" >/dev/null; then + echo "FAIL: ${name}: expected ${expected@Q} in stderr, got ${got@Q}" + FAILURES=$((FAILURES + 1)) + fi + if [[ -n "${leak}" ]] && grep -F -- "${leak}" "${stderr_file}" >/dev/null; then + echo "FAIL: ${name}: stderr leaked ${leak@Q}" + FAILURES=$((FAILURES + 1)) + fi +} + +setup_repo() { + rm -rf "${TMPDIR}/repo" + mkdir -p "${TMPDIR}/repo/.fullsend" + cd "${TMPDIR}/repo" +} + +assert_eq() { + local name="$1" want="$2" got="$3" + if [[ "${want}" != "${got}" ]]; then + echo "FAIL: ${name}: want ${want@Q}, got ${got@Q}" + if [[ -s "${TMPDIR}/resolve-stderr.txt" ]]; then + echo "Resolver stderr:" + cat "${TMPDIR}/resolve-stderr.txt" + fi + FAILURES=$((FAILURES + 1)) + fi +} + +setup_repo +if (unset GITHUB_OUTPUT; FALLBACK_MINT_URL="https://fallback.example" "${BASH_ABS}" "${SCRIPT}" 2>"${TMPDIR}/resolve-stderr.txt"); then + echo "FAIL: missing GITHUB_OUTPUT: expected non-zero exit" + FAILURES=$((FAILURES + 1)) +else + assert_notice_contains "missing GITHUB_OUTPUT" "GITHUB_OUTPUT is required" "$(cat "${TMPDIR}/resolve-stderr.txt")" +fi + +setup_repo +assert_eq "fallback only" "https://fallback.example" "$(run_resolve "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: https://overlay.example\n' >.fullsend/config.yaml +assert_eq "overlay wins" "https://overlay.example" "$(run_resolve "https://fallback.example")" +assert_notice_contains "overlay override notice" "mint_url from .fullsend config overrides FULLSEND_MINT_URL" "$(run_resolve_stderr "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: https://same.example\n' >.fullsend/config.yaml +assert_eq "file matches fallback" "https://same.example" "$(run_resolve "https://same.example")" +assert_no_notice_override "no notice when values match" "$(run_resolve_stderr "https://same.example")" + +setup_repo +assert_no_notice_override "no notice for fallback only" "$(run_resolve_stderr "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: https://base.example\n' >.fullsend/config.base.yaml +assert_eq "base only" "https://base.example" "$(run_resolve "https://fallback.example")" +assert_notice_contains "base override notice" "mint_url from .fullsend config overrides FULLSEND_MINT_URL" "$(run_resolve_stderr "https://fallback.example")" + +setup_repo +printf 'version: "1"\n' >.fullsend/config.yaml +printf 'version: "1"\nmint_url: https://base.example\n' >.fullsend/config.base.yaml +assert_eq "silent overlay uses base" "https://base.example" "$(run_resolve "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: https://overlay.example\n' >.fullsend/config.yaml +printf 'version: "1"\nmint_url: https://base.example\n' >.fullsend/config.base.yaml +assert_eq "overlay beats base" "https://overlay.example" "$(run_resolve "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: null\n' >.fullsend/config.yaml +printf 'version: "1"\nmint_url: https://base.example\n' >.fullsend/config.base.yaml +assert_eq "null overlay uses base" "https://base.example" "$(run_resolve "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: ""\n' >.fullsend/config.yaml +printf 'version: "1"\nmint_url: https://base.example\n' >.fullsend/config.base.yaml +assert_eq "empty overlay uses base" "https://base.example" "$(run_resolve "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: ""\n' >.fullsend/config.base.yaml +assert_eq "empty base uses fallback" "https://fallback.example" "$(run_resolve "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: null\n' >.fullsend/config.yaml +assert_eq "null overlay uses fallback" "https://fallback.example" "$(run_resolve "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: "null"\n' >.fullsend/config.yaml +assert_eq "literal null overlay uses fallback" "https://fallback.example" "$(run_resolve "https://fallback.example")" + +setup_repo +assert_eq "empty fallback" "" "$(run_resolve "")" + +setup_repo +printf 'version: "1"\nmint_url: http://evil.example\n' >.fullsend/config.yaml +run_resolve_expect_fail "https://fallback.example" "reject non-loopback http from config" "::error::mint_url must be a valid HTTPS URL, or HTTP on localhost/127.0.0.1" + +setup_repo +printf 'version: "1"\nmint_url: https://user:pass@mint.example\n' >.fullsend/config.yaml +run_resolve_expect_fail "https://fallback.example" "reject userinfo mint_url" "::error::mint_url must not contain userinfo" "user:pass" + +setup_repo +printf 'version: "1"\nmint_url: https://mint.example/a@b\n' >.fullsend/config.yaml +assert_eq "at-sign in path is not userinfo" "https://mint.example/a@b" "$(run_resolve "")" + +setup_repo +printf 'version: "1"\nmint_url: HTTPS://mint.example\n' >.fullsend/config.yaml +run_resolve_expect_fail "" "reject uppercase scheme (Go parity)" "::error::mint_url must be a valid HTTPS URL" + +setup_repo +assert_eq "localhost http fallback" "http://localhost:8080" "$(run_resolve "http://localhost:8080")" + +setup_repo +assert_eq "loopback http fallback" "http://127.0.0.1:8080" "$(run_resolve "http://127.0.0.1:8080")" + +setup_repo +printf 'version: "1"\nmint_url: http://127.0.0.1:18502\n' >.fullsend/config.yaml +assert_eq "emulator loopback http in overlay and fallback" "http://127.0.0.1:18502" "$(run_resolve "http://127.0.0.1:18502")" + +setup_repo +printf 'version: "1"\nmint_url: http://localhost:8080\n' >.fullsend/config.base.yaml +assert_eq "localhost http from base config" "http://localhost:8080" "$(run_resolve "https://fallback.example")" + +setup_repo +run_resolve_expect_fail "http://evil.example" "reject non-loopback http fallback" "::error::mint_url must be a valid HTTPS URL, or HTTP on localhost/127.0.0.1" + +setup_repo +run_resolve_expect_fail "https://u:p@host" "reject userinfo fallback" "::error::mint_url must not contain userinfo" "u:p" + +setup_repo +run_resolve_expect_fail "http://user@127.0.0.1" "Go rejects loopback userinfo" "::error::mint_url must not contain userinfo" "user@" + +# Mirror the URL cases in internal/urlutil.TestIsMintURL. The resolver +# deliberately permits an empty value: mint-token reports that separately. +for valid_url in \ + "https://mint.example.com" \ + "https://mint.example.com/v1/token" \ + "http://127.0.0.1:18502" \ + "http://localhost"; do + setup_repo + assert_eq "Go accepts ${valid_url}" "${valid_url}" "$(run_resolve "${valid_url}")" +done + +for invalid_url in \ + "http://10.0.0.1" \ + "http://example.com" \ + "https://" \ + "http:///path" \ + "ftp://127.0.0.1" \ + "https://mint.example " \ + "https://host:abc" \ + $'https://mint.example\t/path'; do + setup_repo + run_resolve_expect_fail "${invalid_url}" "Go rejects ${invalid_url}" "::error::mint_url must be a valid HTTPS URL" +done + +setup_repo +run_resolve_expect_fail $'https://mint.example\nsmuggled' "reject LF in fallback" "::error::mint_url must not contain CR or LF" + +setup_repo +run_resolve_expect_fail $'https://mint.example\rsmuggled' "reject CR in fallback" "::error::mint_url must not contain CR or LF" + +setup_repo +printf 'mint_url: [unclosed\n' >.fullsend/config.yaml +run_resolve_expect_fail "https://fallback.example" "reject unparsable overlay" "::error::failed to read mint_url from .fullsend/config.yaml" + +setup_repo +printf 'version: "1"\n' >.fullsend/config.yaml +printf 'mint_url: [unclosed\n' >.fullsend/config.base.yaml +run_resolve_expect_fail "https://fallback.example" "reject unparsable base under silent overlay" "::error::failed to read mint_url from .fullsend/config.base.yaml" + +# Isolate PATH so yq is missing without dropping bash/tr from system +# directories that also contain yq (for example /usr/bin on merged-/usr). +noyq_bin="${TMPDIR}/noyq-bin" +mkdir -p "${noyq_bin}" +for _cmd in bash tr grep cut cat; do + _src="$(command -v "${_cmd}")" + if [[ -z "${_src}" || ! -x "${_src}" ]]; then + echo "FAIL: required tool ${_cmd} not found on PATH" + exit 1 + fi + ln -s "${_src}" "${noyq_bin}/${_cmd}" +done +if PATH="${noyq_bin}" command -v yq >/dev/null 2>&1; then + echo "FAIL: isolated PATH still finds yq" + exit 1 +fi + +run_resolve_without_yq() { + local fallback="${1:-}" + local output_file="${TMPDIR}/github-output.txt" + local oldpwd="${PWD}" + : >"${output_file}" + cd "${TMPDIR}/repo" + PATH="${noyq_bin}" GITHUB_OUTPUT="${output_file}" FALLBACK_MINT_URL="${fallback}" "${BASH_ABS}" "${SCRIPT}" + cd "${oldpwd}" + grep '^mint_url=' "${output_file}" | cut -d= -f2- +} + +setup_repo +assert_eq "no yq without config files" "https://fallback.example" "$(run_resolve_without_yq "https://fallback.example")" + +setup_repo +printf 'version: "1"\nmint_url: https://overlay.example\n' >.fullsend/config.yaml +RESOLVE_PATH="${noyq_bin}" run_resolve_expect_fail "https://fallback.example" "yq required when config files exist" "::error::yq is required to resolve mint_url from config" + +if [[ "${FAILURES}" -eq 0 ]]; then + echo "All tests passed." +else + echo "${FAILURES} test(s) failed." + exit 1 +fi diff --git a/.github/scripts/resolve-effective-mint-url.sh b/.github/scripts/resolve-effective-mint-url.sh new file mode 100755 index 0000000000..68088cd9f0 --- /dev/null +++ b/.github/scripts/resolve-effective-mint-url.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash +# resolve-effective-mint-url.sh — Layered mint_url for GitHub dispatch workflows. +# +# Mirrors ConfigMintURLFromFile (overlay, then base) with FALLBACK_MINT_URL as +# the FULLSEND_MINT_URL snapshot when both files are silent. Stops short of the +# compiled default (https://mint.fullsend.sh), matching resolveMintURL in the CLI. +# +# Both config and fallback values allow HTTPS or loopback HTTP (localhost / +# 127.0.0.1), without userinfo, matching validateDeclaredMintURL. +# +# Requires: GITHUB_OUTPUT, FALLBACK_MINT_URL (may be empty). yq is required +# only when .fullsend/config.yaml or config.base.yaml is present. + +set -euo pipefail + +if [[ -z "${GITHUB_OUTPUT:-}" ]]; then + echo "GITHUB_OUTPUT is required" >&2 + exit 1 +fi + +_effective="${FALLBACK_MINT_URL:-}" +_from_file=false +_overlay=".fullsend/config.yaml" +_base=".fullsend/config.base.yaml" + +if [[ -f "${_overlay}" || -f "${_base}" ]]; then + if ! command -v yq >/dev/null 2>&1; then + echo "::error::yq is required to resolve mint_url from config" >&2 + exit 1 + fi +fi + +# Never echoes the URL: rejected values may contain userinfo. +_validate_resolved_mint_url() { + local url="$1" + if [[ -z "${url}" ]]; then + return 0 + fi + if [[ "${url}" == *$'\n'* || "${url}" == *$'\r'* ]]; then + echo "::error::mint_url must not contain CR or LF" >&2 + return 1 + fi + + local scheme rest authority host + local invalid_url="::error::mint_url must be a valid HTTPS URL, or HTTP on localhost/127.0.0.1" + # Reject characters and ports that net/url.Parse rejects before checking + # the scheme. Keep this gate aligned with internal/urlutil.TestIsMintURL. + if [[ "${url}" == *[[:cntrl:]]* ]]; then + echo "${invalid_url}" >&2 + return 1 + fi + if [[ "${url}" =~ ^([A-Za-z][A-Za-z0-9+.-]*)://(.*)$ ]]; then + scheme="${BASH_REMATCH[1]}" + rest="${BASH_REMATCH[2]}" + else + echo "${invalid_url}" >&2 + return 1 + fi + authority="${rest%%[/?#]*}" + if [[ -z "${authority}" ]]; then + echo "${invalid_url}" >&2 + return 1 + fi + if [[ "${authority}" == *@* ]]; then + echo "::error::mint_url must not contain userinfo" >&2 + return 1 + fi + if [[ "${authority}" == *[[:space:]]* || + ( "${authority}" != \[* && ! "${authority}" =~ ^[^:]+(:[0-9]*)?$ ) || + ( "${authority}" == \[* && ! "${authority}" =~ ^\[[^][]+\](:[0-9]*)?$ ) ]]; then + echo "${invalid_url}" >&2 + return 1 + fi + if [[ "${scheme}" == "https" ]]; then + return 0 + fi + if [[ "${scheme}" == "http" ]]; then + host="${authority%%:*}" + if [[ "${host}" == "localhost" || "${host}" == "127.0.0.1" ]]; then + return 0 + fi + fi + echo "${invalid_url}" >&2 + return 1 +} + +_read_mint_url() { + local file="$1" + local value + if ! value=$(yq -r '.mint_url // ""' "${file}"); then + echo "::error::failed to read mint_url from ${file}" >&2 + exit 1 + fi + if [[ -n "${value}" && "${value}" != "null" ]]; then + printf '%s' "${value}" + fi +} + +if [[ -f "${_overlay}" ]]; then + overlay=$(_read_mint_url "${_overlay}") + if [[ -n "${overlay}" ]]; then + _effective="${overlay}" + _from_file=true + elif [[ -f "${_base}" ]]; then + base=$(_read_mint_url "${_base}") + if [[ -n "${base}" ]]; then + _effective="${base}" + _from_file=true + fi + fi +elif [[ -f "${_base}" ]]; then + base=$(_read_mint_url "${_base}") + if [[ -n "${base}" ]]; then + _effective="${base}" + _from_file=true + fi +fi + +if ! _validate_resolved_mint_url "${_effective}"; then + exit 1 +fi + +# File-sourced mint_url overrides the FULLSEND_MINT_URL snapshot; say so without +# echoing the URL or host (mint-token masks the endpoint in later steps). +if [[ "${_from_file}" == "true" && "${_effective}" != "${FALLBACK_MINT_URL:-}" ]]; then + echo "::notice::mint_url from .fullsend config overrides FULLSEND_MINT_URL" >&2 +fi + +{ + printf 'mint_url=%s\n' "${_effective}" +} >>"${GITHUB_OUTPUT}" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4b27354387..8fde4892a6 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -42,6 +42,15 @@ jobs: echo "8fcbf1b3e95551c82fd995535e3c1defa70e23299ce36eb3afd6c98778de6ca0 /tmp/pinact.tar.gz" | sha256sum -c tar xzf /tmp/pinact.tar.gz -C /usr/local/bin pinact + - name: Install yq + run: | + curl -sSfL "https://github.com/mikefarah/yq/releases/download/v4.54.1/yq_linux_amd64.tar.gz" -o /tmp/yq.tar.gz + echo "e68a456f90c577af3fe4960184b3a3cf5c461e0348407c10f107da3a5fec8972 /tmp/yq.tar.gz" | sha256sum -c + tar xzf /tmp/yq.tar.gz -C /tmp + mv /tmp/yq_linux_amd64 /usr/local/bin/yq + chmod 0755 /usr/local/bin/yq + # yq_linux_arm64.tar.gz sha256sum 8c27f6e7476fb5acefb9352e3d30f6bc2dc93f1956eb92e8da727173fb7ec6d3 + # The gateway doc config check pulls an agentgateway image, so it runs # in its own job, only when its files change. - run: make lint-all diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index 0cec1eea30..7d3caa490d 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -146,6 +146,9 @@ jobs: stage: ${{ steps.review-skip-publish.outputs.skipped != 'true' && steps.agent-check.outputs.skipped != 'true' && steps.route.outputs.stage || '' }} trigger_source: ${{ steps.route.outputs.trigger_source }} event_payload: ${{ steps.payload.outputs.event_payload }} + # Only jobs that never mint in route may consume this output. The + # skip-note mint masks the URL, so review resolves it in its own job. + mint_url: ${{ steps.resolve-mint.outputs.mint_url }} # The fork PR number for workflow_run events, whose payload has none; # the stage concurrency groups fall back to it. pr_number: ${{ steps.fork-pr.outputs.number }} @@ -160,8 +163,9 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # checkout@v7 blocks fork PR checkouts on pull_request_target by - # default. Safe here: only .fullsend/ config is read, no fork code - # is executed, and credentials are not persisted. Pin to base branch + # default. Safe here: trusted config under .fullsend/ is read; the + # vendored or workflow-pinned mint URL resolver may run later with + # id-token scope. Credentials are not persisted. Pin to base branch # SHA for PR-scoped events so kill-switch / role gating always reads # trusted config — PR authors cannot self-authorize. ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} @@ -170,6 +174,7 @@ jobs: sparse-checkout: | .fullsend/config.yaml .fullsend/config.base.yaml + .defaults/.github/scripts/resolve-effective-mint-url.sh .defaults/action.yml .defaults/.github/actions/mint-token/ .defaults/.github/actions/prepare-workspace/ @@ -1357,6 +1362,118 @@ jobs: echo "stage=${STAGE}" >> "${GITHUB_OUTPUT}" echo "trigger_source=${TRIGGER_SOURCE}" >> "${GITHUB_OUTPUT}" + # Validate the final route and resolve the mint URL before any + # write-capable review skip-note token is minted. + - name: Validate routed stage + if: steps.route.outputs.stage != '' + env: + STAGE: ${{ steps.route.outputs.stage }} + TRIGGER_SOURCE: ${{ steps.route.outputs.trigger_source }} + run: | + set -euo pipefail + + if [[ ! "$STAGE" =~ ^[a-z][a-z0-9_-]*$ ]]; then + echo "::error::Invalid stage name: must start with lowercase letter and contain only [a-z0-9_-]" + exit 1 + fi + + if [[ -n "${TRIGGER_SOURCE:-}" ]]; then + if [[ ! "$TRIGGER_SOURCE" =~ ^[a-zA-Z0-9_-]+(\[bot\])?$ ]]; then + echo "::error::Invalid trigger_source format: must be alphanumeric with optional [bot] suffix" + exit 1 + fi + fi + + - name: Check kill switch + if: steps.route.outputs.stage != '' && (steps.review-dedup-guard.outputs.prevalidated != 'true' || steps.route.outputs.stage != 'review') + 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. + # -o=json normalizes every YAML null spelling (bare key, ~, + # 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 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. -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 + 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 -o=json '.kill_switch' .fullsend/config.base.yaml) + if [[ "$BASE_KS" != "null" ]]; then + KILL_SWITCH="$BASE_KS" + fi + fi + 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 + fi + + - name: Prepare mint URL resolver script + if: steps.route.outputs.stage != '' + id: mint-resolver-script + run: | + set -euo pipefail + RESOLVER="" + if [[ -f .defaults/.github/scripts/resolve-effective-mint-url.sh ]]; then + RESOLVER=".defaults/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ -n "${RESOLVER}" ]]; then + echo "path=${RESOLVER}" >> "${GITHUB_OUTPUT}" + echo "fetched=false" >> "${GITHUB_OUTPUT}" + else + echo "fetched=true" >> "${GITHUB_OUTPUT}" + fi + + - name: Checkout workflow mint URL resolver + if: steps.route.outputs.stage != '' && steps.mint-resolver-script.outputs.fetched == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ job.workflow_repository }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + path: .workflow-mint-resolver + fetch-depth: 1 + persist-credentials: false + sparse-checkout: | + .github/scripts/resolve-effective-mint-url.sh + sparse-checkout-cone-mode: false + + - name: Resolve effective mint URL + if: steps.route.outputs.stage != '' + id: resolve-mint + env: + FALLBACK_MINT_URL: ${{ inputs.mint_url }} + run: | + set -euo pipefail + RESOLVER="${{ steps.mint-resolver-script.outputs.path }}" + if [[ -z "${RESOLVER}" ]]; then + RESOLVER=".workflow-mint-resolver/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ ! -f "${RESOLVER}" ]]; then + echo "::error::resolve-effective-mint-url.sh is missing from vendored defaults and workflow repository" + exit 1 + fi + bash "${RESOLVER}" + # Only obtain a write-capable review token after final routing has # authorized the review stage. The diff check above remains read-only. - name: Checkout upstream defaults for review skip note @@ -1402,7 +1519,7 @@ jobs: source_repo: ${{ github.repository }} - name: Mint review token for review skip note - if: ((github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' || (github.event_name == 'workflow_run' && steps.bash-route.outputs.event_action == 'synchronize')) && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') == '' && steps.review-token-workspace.outcome == 'success' + if: ((github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' || (github.event_name == 'workflow_run' && steps.bash-route.outputs.event_action == 'synchronize')) && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && steps.resolve-mint.outcome == 'success' && hashFiles('.fullsend/.defaults/action.yml') == '' && steps.review-token-workspace.outcome == 'success' id: review-token continue-on-error: true timeout-minutes: 2 @@ -1411,10 +1528,10 @@ jobs: role: review repos: ${{ steps.review-token-workspace.outputs.repo_name }} level: write - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ steps.resolve-mint.outputs.mint_url }} - name: Mint review token for review skip note (nested vendor) - if: ((github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' || (github.event_name == 'workflow_run' && steps.bash-route.outputs.event_action == 'synchronize')) && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') != '' && steps.review-token-workspace-nested.outcome == 'success' + if: ((github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' || (github.event_name == 'workflow_run' && steps.bash-route.outputs.event_action == 'synchronize')) && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && steps.resolve-mint.outcome == 'success' && hashFiles('.fullsend/.defaults/action.yml') != '' && steps.review-token-workspace-nested.outcome == 'success' id: review-token-nested continue-on-error: true timeout-minutes: 2 @@ -1423,7 +1540,7 @@ jobs: role: review repos: ${{ steps.review-token-workspace-nested.outputs.repo_name }} level: write - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ steps.resolve-mint.outputs.mint_url }} - name: Publish review skip note id: review-skip-publish @@ -1464,70 +1581,6 @@ jobs: echo "skipped=true" >> "${GITHUB_OUTPUT}" fi - - name: Validate routed stage - if: steps.route.outputs.stage != '' - env: - STAGE: ${{ steps.route.outputs.stage }} - TRIGGER_SOURCE: ${{ steps.route.outputs.trigger_source }} - run: | - set -euo pipefail - - if [[ ! "$STAGE" =~ ^[a-z][a-z0-9_-]*$ ]]; then - echo "::error::Invalid stage name: must start with lowercase letter and contain only [a-z0-9_-]" - exit 1 - fi - - if [[ -n "${TRIGGER_SOURCE:-}" ]]; then - if [[ ! "$TRIGGER_SOURCE" =~ ^[a-zA-Z0-9_-]+(\[bot\])?$ ]]; then - echo "::error::Invalid trigger_source format: must be alphanumeric with optional [bot] suffix" - exit 1 - fi - fi - - - name: Check kill switch - if: steps.route.outputs.stage != '' && (steps.review-dedup-guard.outputs.prevalidated != 'true' || steps.route.outputs.stage != 'review') - 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. - # -o=json normalizes every YAML null spelling (bare key, ~, - # 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 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. -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 - 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 -o=json '.kill_switch' .fullsend/config.base.yaml) - if [[ "$BASE_KS" != "null" ]]; then - KILL_SWITCH="$BASE_KS" - fi - fi - 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 - fi - - name: Validate agents config if: steps.route.outputs.stage != '' run: | @@ -1756,7 +1809,7 @@ jobs: with: role: triage repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ needs.route.outputs.mint_url }} - name: Checkout target repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -1826,7 +1879,7 @@ jobs: source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ needs.route.outputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} - name: Report triage launch failure @@ -1910,7 +1963,7 @@ jobs: with: role: coder repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ needs.route.outputs.mint_url }} - name: Checkout target repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -2001,7 +2054,7 @@ jobs: source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ needs.route.outputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} - name: Report code launch failure @@ -2073,6 +2126,52 @@ jobs: internal/scaffold/fullsend-repo/ action.yml + # The route skip-note token masks its URL; GitHub omits masked job + # outputs. Resolve locally so a failed skip note can still run review. + - name: Prepare mint URL resolver script + id: mint-resolver-script + run: | + set -euo pipefail + RESOLVER="" + if [[ -f .defaults/.github/scripts/resolve-effective-mint-url.sh ]]; then + RESOLVER=".defaults/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ -n "${RESOLVER}" ]]; then + echo "path=${RESOLVER}" >> "${GITHUB_OUTPUT}" + echo "fetched=false" >> "${GITHUB_OUTPUT}" + else + echo "fetched=true" >> "${GITHUB_OUTPUT}" + fi + + - name: Checkout workflow mint URL resolver + if: steps.mint-resolver-script.outputs.fetched == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ job.workflow_repository }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + path: .workflow-mint-resolver + fetch-depth: 1 + persist-credentials: false + sparse-checkout: | + .github/scripts/resolve-effective-mint-url.sh + sparse-checkout-cone-mode: false + + - name: Resolve effective mint URL + id: resolve-mint + env: + FALLBACK_MINT_URL: ${{ inputs.mint_url }} + run: | + set -euo pipefail + RESOLVER="${{ steps.mint-resolver-script.outputs.path }}" + if [[ -z "${RESOLVER}" ]]; then + RESOLVER=".workflow-mint-resolver/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ ! -f "${RESOLVER}" ]]; then + echo "::error::resolve-effective-mint-url.sh is missing from vendored defaults and workflow repository" + exit 1 + fi + bash "${RESOLVER}" + # The review job is separate from route, so it must install its own # copy before using the CLI to supersede an earlier skip note. - name: Detect review dedup CLI @@ -2194,7 +2293,7 @@ jobs: with: role: review repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ steps.resolve-mint.outputs.mint_url }} - name: Checkout target repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -2312,7 +2411,7 @@ jobs: source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ steps.resolve-mint.outputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} - name: Report review launch failure @@ -2396,7 +2495,7 @@ jobs: with: role: coder repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ needs.route.outputs.mint_url }} - name: Resolve bot identity env: @@ -2620,7 +2719,7 @@ jobs: source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ needs.route.outputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} - name: Report fix launch failure @@ -2703,7 +2802,7 @@ jobs: with: role: retro repos: ${{ steps.workspace.outputs.repo_name }} - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ needs.route.outputs.mint_url }} - name: Checkout target repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -2773,7 +2872,7 @@ jobs: source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} status-comment-id: ${{ fromJSON(needs.route.outputs.event_payload).comment.id }} failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ needs.route.outputs.mint_url }} pr-head-sha: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.head.sha || '' }} - name: Report retro launch failure @@ -2906,7 +3005,7 @@ jobs: status-number: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} source-system: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github' }} failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ needs.route.outputs.mint_url }} - name: Report prioritize launch failure if: ${{ failure() && !cancelled() && steps.run-agent.outcome == 'skipped' && (fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system || 'github') == 'github' }} @@ -2977,6 +3076,7 @@ jobs: .defaults/.github/actions/install-fullsend-cli/ .defaults/.github/scripts/report-agent-startup-failure.sh .fullsend/.defaults/action.yml + .defaults/.github/scripts/resolve-effective-mint-url.sh .fullsend/.defaults/.github/scripts/report-agent-startup-failure.sh sparse-checkout-cone-mode: false @@ -2999,6 +3099,52 @@ jobs: fi echo "has_triggers=${has_triggers}" >> "${GITHUB_OUTPUT}" + - name: Prepare mint URL resolver script + if: steps.triggers.outputs.has_triggers == 'true' + id: mint-resolver-script + run: | + set -euo pipefail + RESOLVER="" + if [[ -f .defaults/.github/scripts/resolve-effective-mint-url.sh ]]; then + RESOLVER=".defaults/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ -n "${RESOLVER}" ]]; then + echo "path=${RESOLVER}" >> "${GITHUB_OUTPUT}" + echo "fetched=false" >> "${GITHUB_OUTPUT}" + else + echo "fetched=true" >> "${GITHUB_OUTPUT}" + fi + + - name: Checkout workflow mint URL resolver + if: steps.triggers.outputs.has_triggers == 'true' && steps.mint-resolver-script.outputs.fetched == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ job.workflow_repository }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + path: .workflow-mint-resolver + fetch-depth: 1 + persist-credentials: false + sparse-checkout: | + .github/scripts/resolve-effective-mint-url.sh + sparse-checkout-cone-mode: false + + - name: Resolve effective mint URL + if: steps.triggers.outputs.has_triggers == 'true' + id: resolve-mint + env: + FALLBACK_MINT_URL: ${{ inputs.mint_url }} + run: | + set -euo pipefail + RESOLVER="${{ steps.mint-resolver-script.outputs.path }}" + if [[ -z "${RESOLVER}" ]]; then + RESOLVER=".workflow-mint-resolver/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ ! -f "${RESOLVER}" ]]; then + echo "::error::resolve-effective-mint-url.sh is missing from vendored defaults and workflow repository" + exit 1 + fi + bash "${RESOLVER}" + - name: Detect dispatch CLI install mode id: mode if: steps.triggers.outputs.has_triggers == 'true' @@ -3105,7 +3251,7 @@ jobs: GH_TOKEN: ${{ github.token }} GITHUB_EVENT_NAME: ${{ github.event_name }} EVENT_ACTION: ${{ inputs.event_action }} - FULLSEND_MINT_URL: ${{ inputs.mint_url }} + FULLSEND_MINT_URL: ${{ steps.resolve-mint.outputs.mint_url }} run: | set -euo pipefail if [[ "${{ steps.triggers.outputs.has_triggers }}" != "true" ]]; then @@ -3213,6 +3359,50 @@ jobs: mkdir -p .github/scripts cp "${SRC}/.github/scripts/setup-agent-env.sh" .github/scripts/setup-agent-env.sh + - name: Prepare mint URL resolver script + id: mint-resolver-script + run: | + set -euo pipefail + RESOLVER="" + if [[ -f .defaults/.github/scripts/resolve-effective-mint-url.sh ]]; then + RESOLVER=".defaults/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ -n "${RESOLVER}" ]]; then + echo "path=${RESOLVER}" >> "${GITHUB_OUTPUT}" + echo "fetched=false" >> "${GITHUB_OUTPUT}" + else + echo "fetched=true" >> "${GITHUB_OUTPUT}" + fi + + - name: Checkout workflow mint URL resolver + if: steps.mint-resolver-script.outputs.fetched == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ job.workflow_repository }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + path: .workflow-mint-resolver + fetch-depth: 1 + persist-credentials: false + sparse-checkout: | + .github/scripts/resolve-effective-mint-url.sh + sparse-checkout-cone-mode: false + + - name: Resolve effective mint URL + id: resolve-mint + env: + FALLBACK_MINT_URL: ${{ inputs.mint_url }} + run: | + set -euo pipefail + RESOLVER="${{ steps.mint-resolver-script.outputs.path }}" + if [[ -z "${RESOLVER}" ]]; then + RESOLVER=".workflow-mint-resolver/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ ! -f "${RESOLVER}" ]]; then + echo "::error::resolve-effective-mint-url.sh is missing from vendored defaults and workflow repository" + exit 1 + fi + bash "${RESOLVER}" + - name: Extract repo metadata id: repo-parts shell: bash @@ -3238,7 +3428,7 @@ jobs: with: role: ${{ matrix.role }} repos: ${{ steps.repo-parts.outputs.name }} - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ steps.resolve-mint.outputs.mint_url }} - name: Checkout target repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -3390,7 +3580,7 @@ jobs: source-system: ${{ matrix.event_payload._normalized_event.source.system || 'github' }} status-comment-id: ${{ matrix.event_payload.comment.id }} failure-trusted-bots: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ steps.resolve-mint.outputs.mint_url }} pr-head-sha: ${{ matrix.event_payload.pull_request.head.sha || '' }} artifact-name: ${{ steps.dispatch-env.outputs.artifact_name }} - name: Report harness launch failure diff --git a/.github/workflows/reusable-prioritize.yml b/.github/workflows/reusable-prioritize.yml index d4ad1cf1e3..504c6f0a37 100644 --- a/.github/workflows/reusable-prioritize.yml +++ b/.github/workflows/reusable-prioritize.yml @@ -105,8 +105,9 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # checkout@v7 blocks fork PR checkouts on pull_request_target by default. - # Safe here: only .fullsend/ config is read, no fork code is executed, - # and credentials are not persisted. + # Safe here: trusted config under .fullsend/ is read; the vendored or + # workflow-pinned mint URL resolver may run later with id-token scope. + # Credentials are not persisted. ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -140,6 +141,49 @@ jobs: mkdir -p .github/scripts cp "${SRC}/.github/scripts/setup-agent-env.sh" .github/scripts/setup-agent-env.sh + - name: Prepare mint URL resolver script + id: mint-resolver-script + run: | + set -euo pipefail + RESOLVER="" + if [[ -f .defaults/.github/scripts/resolve-effective-mint-url.sh ]]; then + RESOLVER=".defaults/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ -n "${RESOLVER}" ]]; then + echo "path=${RESOLVER}" >> "${GITHUB_OUTPUT}" + echo "fetched=false" >> "${GITHUB_OUTPUT}" + else + echo "fetched=true" >> "${GITHUB_OUTPUT}" + fi + + - name: Checkout workflow mint URL resolver + if: steps.mint-resolver-script.outputs.fetched == 'true' + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ${{ job.workflow_repository }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} + path: .workflow-mint-resolver + fetch-depth: 1 + persist-credentials: false + sparse-checkout: | + .github/scripts/resolve-effective-mint-url.sh + sparse-checkout-cone-mode: false + + - name: Resolve effective mint URL + id: resolve-mint + env: + FALLBACK_MINT_URL: ${{ inputs.mint_url }} + run: | + set -euo pipefail + RESOLVER="${{ steps.mint-resolver-script.outputs.path }}" + if [[ -z "${RESOLVER}" ]]; then + RESOLVER=".workflow-mint-resolver/.github/scripts/resolve-effective-mint-url.sh" + fi + if [[ ! -f "${RESOLVER}" ]]; then + echo "::error::resolve-effective-mint-url.sh is missing from vendored defaults and workflow repository" + exit 1 + fi + bash "${RESOLVER}" - name: Validate enrollment and extract repository metadata id: repo-parts @@ -155,7 +199,7 @@ jobs: with: role: prioritize repos: ${{ steps.repo-parts.outputs.name }} - mint_url: ${{ inputs.mint_url }} + mint_url: ${{ steps.resolve-mint.outputs.mint_url }} - name: Prepare GCP credentials for an explicit CLI override if: env.FULLSEND_LEGACY_GCP_SETUP == 'true' @@ -216,7 +260,7 @@ jobs: fullsend-dir: .fullsend github_token: ${{ github.token }} failure-token: ${{ steps.app-token.outputs.token || github.token }} - mint-url: ${{ inputs.mint_url }} + mint-url: ${{ steps.resolve-mint.outputs.mint_url }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} failure-repo: ${{ inputs.source_repo }} failure-number: ${{ fromJSON(inputs.event_payload).issue.number || fromJSON(inputs.event_payload).pull_request.number }} diff --git a/Makefile b/Makefile index 6e8d860500..9eb1abc590 100644 --- a/Makefile +++ b/Makefile @@ -196,6 +196,7 @@ script-test: $(call run-timed,bash .github/scripts/check-fix-eligibility-test.sh) $(call run-timed,bash .github/scripts/count-fix-commits-test.sh) $(call run-timed,bash .github/scripts/pre-fetch-review-body-test.sh) + $(call run-timed,bash .github/scripts/resolve-effective-mint-url-test.sh) $(call run-timed,bash .github/scripts/report-agent-startup-failure-test.sh) $(call run-timed,bash .github/scripts/retry-with-backoff-test.sh) $(call run-timed,bash scripts/check-agents-gate-pin-test.sh) diff --git a/docs/contributing/config-source-inventory.md b/docs/contributing/config-source-inventory.md index 9e46c4fb8c..732e9fd2f8 100644 --- a/docs/contributing/config-source-inventory.md +++ b/docs/contributing/config-source-inventory.md @@ -49,7 +49,9 @@ its own separate allowlist of `FULLSEND_*` repository variables into the job environment. The OpenAI Workload Identity variables come from a separate opt-in step, `fullsend inference openai import --variables`. Dispatch steps in `reusable-dispatch.yml` also `yq` `.fullsend/config.yaml` -directly and do not read `config.base.yaml`. +directly for some checks and do not read `config.base.yaml`, except +`mint_url` and `kill_switch`, which use the layered files (see their rows +below). A value set only in the base file is invisible to a reader that looks at the repository variable or at `config.yaml` alone. @@ -83,6 +85,7 @@ These fields live on `perRepoConfig` in `internal/config/config.go`. Unset means | `progress` | What the live job log prints while an agent runs (`verbosity`, `by_source`; ADR 0163) | Overlay, base, compiled `full` | `verbosity` overrides, then base, then `full`; `by_source` merges per key; an unresolvable level is `quiet` | `fullsend run` (event renderer, agent CLI stderr, transcript-error annotations, output-file and transcript extraction lines, failed-step error text, validation lines, the audit log line, and the final run error) | Already layered | Yes. A fleet that takes work from private trackers can set it in the base file. | | `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. | +| `mint_url` | Token mint address | `--mint-url`, overlay, base, `FULLSEND_MINT_URL`, compiled `https://mint.fullsend.sh` | `--mint-url` when explicitly passed, then overlay, then base, then `FULLSEND_MINT_URL` / the workflow `mint_url` input snapshot (`resolveMintURL` and `resolve-effective-mint-url.sh`, #8400, #8672). Workflows resolve overlay → base → `inputs.mint_url` before `mint-token` and before passing `mint-url` to `fullsend run`. Stops short of the compiled default when every layer is silent (same as the CLI file layer). `mint token` has no `--fullsend-dir`, so it stays flag then env | `fullsend run`, `reconcile-status`, `mint token`, `fullsend dispatch`, `reusable-dispatch.yml`, `reusable-prioritize.yml`. GitLab never mints | Already layered. `FULLSEND_MINT_URL` stays the fallback when both YAML layers are silent. OIDC downgrade for `reconcile-status` and status comments, and mint-endpoint checks for file-only prioritize, remain tracked separately | Yes. | `authorization` (extra permission sources, today `owners_file` and `jira`) is overlay-only by design, not an accessor gap: a base-file value under this @@ -110,7 +113,6 @@ The Go accessor layers these. The bash steps in `.github/workflows/reusable-disp | `runtime`, and per-agent `agents[].runtime` | Which runtime runs (`claude`, `pi`, `codex`, `dummy`) | `--runtime`, `FULLSEND_RUNTIME` (repository variable copied by `setup-agent-env.sh`), agent entry, repo `runtime:`, compiled `claude` | Flag, then `FULLSEND_RUNTIME`, then the agent entry, then repo `runtime:`, then `claude` (`docs/cli/run.md`) | `fullsend run` | File should win. Flag stays first. `FULLSEND_RUNTIME` stays as the fallback | Yes, for the fleet default. | | `agents[].model` | Model for one agent | `--model`, `FULLSEND_MODEL`, then `FULLSEND_PI_MODEL` or `FULLSEND_CODEX_MODEL` when that runtime is selected, agent entry, harness, frontmatter | Flag, then `FULLSEND_MODEL`, then the runtime-scoped alias, then the agent entry | `fullsend run` | File should win. Same fallback rule | The shared default can live on the base-file agent entry. | | `agents[].effort` | Effort for one agent | `--effort`, `FULLSEND_EFFORT`, agent entry, harness | Flag, then `FULLSEND_EFFORT`, then the agent entry | `fullsend run` | File should win. Same fallback rule | Same as model. | -| `mint_url` | Token mint address | `--mint-url`, `FULLSEND_MINT_URL`, layered `mint_url`, compiled `https://mint.fullsend.sh` | `fullsend run` and `reconcile-status --fullsend-dir`: flag, then layered `mint_url`, then `FULLSEND_MINT_URL` (`resolveMintURL`, #8400). Only `runAgent`'s agent-token mint downgrades a file-sourced value to warn-and-skip (ambient `GH_TOKEN`) when GitHub Actions OIDC is unavailable; `reconcile-status` and the status-comment mint still attempt it and fail — fail-closed for `reconcile-status`, a per-call warning for status comments. `mint token` has no `--fullsend-dir`, so it stays flag then env | `fullsend run`, `reconcile-status`, `mint token`, `fullsend dispatch` (GitHub bot-role lookup, flag-less: layered `mint_url`, then `FULLSEND_MINT_URL`). GitLab never mints | File should win: done for `run` and `reconcile-status`. This has a live effect today, not only a future one: `action.yml` (`MINT_FLAGS`) omits `--mint-url` entirely when the composite action's `mint_url` input is empty, rather than passing an empty value, and the `prioritize` paths (`reusable-prioritize.yml` and the inlined `prioritize` job in `reusable-dispatch.yml`) have no upfront mint-token step gating on `FULLSEND_MINT_URL` the way triage/code/review/fix/retro/harness-run do. So when that repository variable is unset, those two paths (and any other composite-action caller that leaves `mint-url` empty) already mint — and notify — from a file-only `mint_url` inside real GitHub Actions runs with working OIDC. Every other dispatched stage still passes `mint-url` built from the possibly-stale variable, so the flag wins there until the `route` job computes the value from the file itself. `mint token` stays flag-then-env; it has no directory to layer from. The OIDC downgrade should extend to `reconcile-status` and status comments for consistency — tracked, not yet done. Confirming the mint endpoint serves the `prioritize` role wherever `mint_url` is file-only is tracked, not yet done (#8400 review) | Yes. | | `inference.region` | GCP region for inference | Layered `inference.region`, compiled `global`. Workflows pass `vars.FULLSEND_GCP_REGION` as `gcp_region`, which becomes `CLOUD_ML_REGION`. GitLab `run-agent-job.sh` exports `CLOUD_ML_REGION` from `FULLSEND_GCP_REGION` | The job environment, not the file. Setup writes the file's effective region into `FULLSEND_GCP_REGION` at install time. A later edit to the file does not change the variable | Vertex client via `CLOUD_ML_REGION`. The accessor is used at install and converge | File should win for the binary. Keep `FULLSEND_GCP_REGION` as the fallback and as the value old workflows still pass | Yes. | | `inference.project` | GCP project for inference | Layered `inference.project` (no compiled default), secret `FULLSEND_GCP_PROJECT_ID` | The secret. Workflows export it as `ANTHROPIC_VERTEX_PROJECT_ID`. `setup-gcp` uses the same secret to authenticate before the binary runs | Google auth action and the Vertex client | Leave the secret for the auth action. The file should be what the binary reads, with the secret as fallback. Do not put the secret value only in git if the auth action still needs it | Yes for the project id the binary uses. The secret remains for the auth action. | | `inference.wif_provider` | Workload Identity provider resource name | Layered `inference.wif_provider` (no compiled default), secret `FULLSEND_GCP_WIF_PROVIDER` | The secret. `setup-gcp` reads it | Google auth action | Leave the secret for the auth action. The file should describe the provider the binary needs. Same split as the project id | Yes for the non-secret resource name. The credential material stays a secret. | diff --git a/docs/guides/infrastructure/layered-config-reference.md b/docs/guides/infrastructure/layered-config-reference.md index 9545f20eab..c204280c6b 100644 --- a/docs/guides/infrastructure/layered-config-reference.md +++ b/docs/guides/infrastructure/layered-config-reference.md @@ -262,6 +262,13 @@ unset, the accessor falls through to the base layer, then to code defaults. unset (`""`) falls through to parent, then to code default `DefaultPerRepoMintURL` (the hosted public mint). +**GitHub agent dispatch** uses the same overlay-then-base order, then the +`FULLSEND_MINT_URL` snapshot from the caller (`inputs.mint_url` on the +reusable workflow), not `DefaultPerRepoMintURL`. A declared config value +overrides the variable; the resolver stops there when both files are silent +on `mint_url`. Validation and failure modes for dispatch runs are listed in +[Config reference — `mint_url`](../../reference/config-reference.md#mint_url). + **`inference`** groups inference backend settings under a single YAML key (`inference:`) using the `PerRepoInferenceConfig` struct. Each subfield (`provider`, `project`, `region`, `wif_provider`, `wif_audience`, diff --git a/docs/guides/infrastructure/mint-administration.md b/docs/guides/infrastructure/mint-administration.md index b08f5c2b5f..4545c2d46e 100644 --- a/docs/guides/infrastructure/mint-administration.md +++ b/docs/guides/infrastructure/mint-administration.md @@ -32,7 +32,31 @@ The fullsend team operates a public hosted community mint service. Install the s https://mint.fullsend.sh ``` -The CLI defaults to this URL. You can also set the `FULLSEND_MINT_URL` repository/org variable in GitHub explicitly. If you are using the hosted community mint, the rest of this guide (deploying, enrolling, troubleshooting) is for platform operators managing self-hosted mints — you do not need to manage mint infrastructure yourself. +The CLI defaults to this URL. You can also set the `FULLSEND_MINT_URL` +repository/org variable in GitHub explicitly. When `mint_url` is declared +in `.fullsend/config.yaml` or `config.base.yaml`, dispatch resolves that +layered value before the variable (see +[Layered configuration reference](layered-config-reference.md)); the +variable remains the fallback when both files are silent on `mint_url`. +If you are using the hosted community mint, the rest of this guide +(deploying, enrolling, troubleshooting) is for platform operators +managing self-hosted mints — you do not need to manage mint +infrastructure yourself. + +### Dispatch mint URL migration + +If `.fullsend/config.yaml` or `config.base.yaml` declares `mint_url`, +dispatch uses that endpoint instead of `FULLSEND_MINT_URL`. To retarget a +repo, change or remove the config field (removing it restores the variable +fallback). When config declares a value that differs from the workflow +`FULLSEND_MINT_URL` snapshot, dispatch follows config. The same applies +when the variable is unset. Dispatch emits a workflow notice that config +overrides the variable. The notice omits the URL and host. + +Dispatch validates the resolved URL on every run. Both config and the +variable fallback accept HTTPS or HTTP on `localhost` or `127.0.0.1`, +without userinfo. Dispatch fails when config is present but `yq` is missing, +YAML does not parse, or the resolved URL fails validation. ## Prerequisites @@ -173,7 +197,13 @@ fullsend mint deploy --project="$GCP_PROJECT" --pem-dir=/path/to/pems \ The mint URL is stable across redeploys within the same project and region — updating the Cloud Function does not change its URL. Enrolling a new repository in an existing mint only updates `PER_REPO_WIF_REPOS` (and WIF configuration) without redeploying the function. Shared `ROLE_APP_IDS` are managed at deploy/bootstrap time (`mint deploy --pem-dir`) or per-role via `mint add-role` / `remove-role` — not during enrollment. Existing enrolled repos continue working with no changes when new repos are enrolled. -Deploying to a **different region** (e.g., changing `--region` from `us-central1` to `us-east5`) creates a new Cloud Run service with a different URL. All enrolled repos store the mint URL in a repo or org variable (`FULLSEND_MINT_URL`), so changing the region requires updating every enrolled repo's variable. Avoid changing `--region` after initial deployment unless you plan to update all consumers. +Deploying to a **different region** (e.g., changing `--region` from +`us-central1` to `us-east5`) creates a new Cloud Run service with a +different URL. Update every consumer: set `mint_url` in +`.fullsend/config.yaml` or `config.base.yaml` when dispatch reads config, +and update `FULLSEND_MINT_URL` when config is silent on `mint_url` (see +[dispatch mint URL migration](#dispatch-mint-url-migration)). Avoid changing +`--region` after initial deployment unless you plan to update all consumers. ### HTTP Strict Transport Security diff --git a/docs/guides/infrastructure/standalone-mint.md b/docs/guides/infrastructure/standalone-mint.md index ae4382ae82..fa8d5cad0c 100644 --- a/docs/guides/infrastructure/standalone-mint.md +++ b/docs/guides/infrastructure/standalone-mint.md @@ -201,6 +201,12 @@ gh api -X POST /repos/myorg/my-repo/actions/variables \ > **Note:** Repository-level variables override organization-level variables in GitHub Actions. If a repo already has `FULLSEND_MINT_URL` set at the repo level, update it there — the org-level variable will be ignored for that repo. +> **Dispatch precedence:** When `.fullsend/config.yaml` or +> `config.base.yaml` declares `mint_url`, agent dispatch uses that value +> instead of `FULLSEND_MINT_URL`. Retarget by updating the config field; +> changing only the variable is not enough when config sets a URL. See +> [Mint administration — dispatch mint URL migration](mint-administration.md#dispatch-mint-url-migration). + ## Privilege levels Levels are keys on each role. The mint looks up the requested level and returns the stored permission map — or returns an error if the level is not defined. Every role must define at least `read` and `write`; custom roles may define additional named levels. diff --git a/docs/guides/user/custom-agent-identity.md b/docs/guides/user/custom-agent-identity.md index 9cfe2a1d62..3075abf4c8 100644 --- a/docs/guides/user/custom-agent-identity.md +++ b/docs/guides/user/custom-agent-identity.md @@ -117,9 +117,10 @@ Set it up, then point your repo at it: slug: my-org-my-role # install-time App discovery; still not read by the mint ``` -3. **Point your repo at your mint** — set `FULLSEND_MINT_URL` to your mint's - URL. Without this, tokens are requested from the hosted mint, which does not - serve `my-role`. +3. **Point your repo at your mint** — set `FULLSEND_MINT_URL` and/or declare + `mint_url` in `.fullsend/config.yaml` or `config.base.yaml`. Dispatch + prefers the config value when both are set. Without either, tokens are + requested from the hosted mint, which does not serve `my-role`. > **Tip: adopt gradually.** With `FALLBACK_MINT_URL`, your standalone mint > serves your custom roles locally and proxies the built-in ones to the hosted diff --git a/docs/reference/config-reference.md b/docs/reference/config-reference.md index dc474e5b60..2e5102228b 100644 --- a/docs/reference/config-reference.md +++ b/docs/reference/config-reference.md @@ -981,6 +981,24 @@ variable. Install, dry run and `repos status` report a conflict when it differs from the manifest's own `mint_url`. See [Effective infrastructure values](../cli/repos.md#effective-infrastructure-values). +**GitHub agent dispatch** (`reusable-dispatch.yml`, `reusable-prioritize.yml`) +resolves the mint endpoint before minting credentials: this field in +`config.yaml`, then `config.base.yaml`, then the `FULLSEND_MINT_URL` +repository/org variable snapshot passed into the reusable workflow. A +declared config value overrides the variable; changing only the variable has +no effect while config sets `mint_url`. When every layer is silent, dispatch +uses the variable and does not apply the compiled CLI default +(`https://mint.fullsend.sh`). Dispatch fails when a config file exists but +`yq` is missing, a config file does not parse, or the resolved URL fails +validation. Both config and the variable fallback accept HTTPS or HTTP on +`localhost` or `127.0.0.1`, without userinfo. +When a declared config value differs from the workflow variable snapshot +(including an unset variable), dispatch follows config and the route job +may emit a workflow notice that config overrides the variable (no URL or +host in the notice). See +[Layered configuration reference](../guides/infrastructure/layered-config-reference.md) +and [Mint administration — dispatch mint URL migration](../guides/infrastructure/mint-administration.md#dispatch-mint-url-migration). + ### `inference` Groups inference backend settings under a single key. Each subfield resolves diff --git a/hack/ci-local/Containerfile b/hack/ci-local/Containerfile index b2d84bfd23..905ac6051b 100644 --- a/hack/ci-local/Containerfile +++ b/hack/ci-local/Containerfile @@ -1,6 +1,6 @@ # Local replica of the fullsend CI toolchain (.github/workflows/lint.yml, # mint-cf-worker-test.yml, site-build.yml): ubuntu-24.04 runner, Go, Python + -# the pre-commit stack, Node, lychee, pinact. Build it with +# the pre-commit stack, Node, lychee, pinact, yq. Build it with # `hack/ci-local/ci-local build-image`: the versions are read from go.mod and # lint.yml and passed in as build args, so this file pins none of them. # Digest-pinned like images/*; Renovate keeps the digest current. @@ -31,8 +31,12 @@ ARG LYCHEE_VERSION ARG LYCHEE_SHA256_AMD64 ARG PINACT_VERSION ARG PINACT_SHA256_AMD64 +ARG YQ_VERSION +ARG YQ_SHA256_AMD64 +ARG YQ_SHA256_ARM64 RUN for v in GO_VERSION PYTHON_VERSION NODE_VERSION PIP_PACKAGES LYCHEE_VERSION \ - LYCHEE_SHA256_AMD64 PINACT_VERSION PINACT_SHA256_AMD64; do \ + LYCHEE_SHA256_AMD64 PINACT_VERSION PINACT_SHA256_AMD64 \ + YQ_VERSION YQ_SHA256_AMD64 YQ_SHA256_ARM64; do \ eval "x=\${$v}"; [ -n "$x" ] || { echo "build arg $v is not set; build with hack/ci-local/ci-local build-image" >&2; exit 1; }; \ done @@ -84,9 +88,10 @@ RUN uv venv --python "${PYTHON_VERSION}" /opt/venv \ && VIRTUAL_ENV=/opt/venv uv pip install ${PIP_PACKAGES} \ && chmod -R a+rX /opt/uv-python /opt/venv -# lychee + pinact (lint.yml "Install lychee" / "Install pinact"). On amd64 the -# checksum is the one lint.yml pins; lint.yml pins no arm64 checksum, so other -# architectures use the release's own checksum file. +# lychee + pinact + yq (lint.yml "Install lychee" / "Install pinact" / +# "Install yq"). On amd64 the checksum is the one lint.yml pins. lychee and +# pinact have no arm64 pin in lint.yml, so other architectures use the +# release's own checksum file; yq pins both architectures in lint.yml. RUN set -e; \ case "$TARGETARCH" in amd64) a=x86_64 ;; arm64) a=aarch64 ;; *) a=$TARGETARCH ;; esac; \ name="lychee-${a}-unknown-linux-gnu.tar.gz"; \ @@ -100,6 +105,15 @@ RUN set -e; \ if [ "$TARGETARCH" = amd64 ]; then s=$PINACT_SHA256_AMD64; else s=$(sumof "$rel/pinact_${PINACT_VERSION}_checksums.txt" "$name"); fi; \ fetch "$rel/$name" "$s"; \ tar -xzf /tmp/dl -C /usr/local/bin pinact; rm /tmp/dl +RUN set -e; \ + name="yq_linux_${TARGETARCH}.tar.gz"; \ + url="https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/$name"; \ + if [ "$TARGETARCH" = amd64 ]; then s=$YQ_SHA256_AMD64; else s=$YQ_SHA256_ARM64; fi; \ + fetch "$url" "$s"; \ + tar -xzf /tmp/dl -C /tmp; rm /tmp/dl; \ + mv /tmp/yq_linux_${TARGETARCH} /usr/local/bin/yq; \ + chmod 0755 /usr/local/bin/yq; \ + rm -f /tmp/yq.1 /tmp/install-man-page.sh # CI=true: matches Actions and makes `make ensure-hooks` a no-op, so running # lint never installs git hooks into the host checkout. diff --git a/hack/ci-local/README.md b/hack/ci-local/README.md index 8ad729f647..0d3aff2bd0 100644 --- a/hack/ci-local/README.md +++ b/hack/ci-local/README.md @@ -163,7 +163,7 @@ checkout and passes them in as build args: | Go | `go.mod` (`go` line), as `actions/setup-go` does | | Python, Node | `python-version` / `node-version` in `.github/workflows/lint.yml` | | pip packages | the `uv pip install --system` step in `lint.yml` | -| lychee, pinact | the download URLs and SHA256s in `lint.yml` | +| lychee, pinact, yq | the download URLs and SHA256s in `lint.yml` | | uv | latest release (`lint.yml` doesn't pin it) | The image is tagged with a hash of those versions and the `Containerfile`, so @@ -188,10 +188,12 @@ Python also comes from a different build: uv's python-build-standalone here, actions/python-versions in CI. `hack/ci-local/ci-local build-image` rebuilds without cache to pick up new patch releases. -On amd64, lychee and pinact are verified against the SHA256s that `lint.yml` -pins. `lint.yml` pins no arm64 checksums, so on arm64 (Apple silicon) they, -like Node and uv everywhere, are verified against the publisher's checksum -file from the same release. +On amd64, lychee, pinact, and yq are verified against the SHA256s that +`lint.yml` pins. `lint.yml` pins no arm64 checksums for lychee and pinact, so +on arm64 (Apple silicon) those two, like Node and uv everywhere, are verified +against the publisher's checksum file from the same release. yq pins both +architectures in `lint.yml` because its GitHub checksums file is not a +standard SHA256 list. Each version set leaves its own image behind. `hack/ci-local/ci-local clean` removes every `ci-local` image except the current one for this checkout (add diff --git a/hack/ci-local/ci-local b/hack/ci-local/ci-local index d5aeec82d0..2efc7213c4 100755 --- a/hack/ci-local/ci-local +++ b/hack/ci-local/ci-local @@ -157,6 +157,9 @@ resolve_versions() { add LYCHEE_SHA256_AMD64 "$(grep -m1 -E 'lychee\.tar\.gz.*sha256sum' "$wf" | grep -oE '[0-9a-f]{64}')" lint.yml add PINACT_VERSION "$(grep -m1 -oE 'pinact/releases/download/v[0-9.]+/' "$wf" | sed -E 's#.*/v##; s#/$##')" lint.yml add PINACT_SHA256_AMD64 "$(grep -m1 -E 'pinact\.tar\.gz.*sha256sum' "$wf" | grep -oE '[0-9a-f]{64}')" lint.yml + add YQ_VERSION "$(grep -m1 -oE 'mikefarah/yq/releases/download/v[0-9.]+/' "$wf" | sed -E 's#.*/v##; s#/$##')" lint.yml + add YQ_SHA256_AMD64 "$(grep -m1 -E 'yq\.tar\.gz.*sha256sum' "$wf" | grep -oE '[0-9a-f]{64}')" lint.yml + add YQ_SHA256_ARM64 "$(grep -m1 -E 'yq_linux_arm64\.tar\.gz.*sha256sum' "$wf" | grep -oE '[0-9a-f]{64}')" lint.yml # Docker and rootful Podman run as the host uid:gid (user_args); build # runner with those ids so whoami/id -un resolve. keep-id adds its own # passwd entry. diff --git a/hack/ci-local/ci-local_test.sh b/hack/ci-local/ci-local_test.sh index f6ba251cca..ce546cac6e 100755 --- a/hack/ci-local/ci-local_test.sh +++ b/hack/ci-local/ci-local_test.sh @@ -207,13 +207,15 @@ BUILD=$(last_build_args) arg() { grep -A1 -x -- '--build-arg' <<< "${BUILD}" | sed -n "s/^$1=//p"; } want_go=$(awk '$1 == "go" {print $2; exit}' "${REPO}/go.mod") missing="" -for v in GO_VERSION PYTHON_VERSION NODE_VERSION PIP_PACKAGES LYCHEE_VERSION LYCHEE_SHA256_AMD64 PINACT_VERSION PINACT_SHA256_AMD64; do +for v in GO_VERSION PYTHON_VERSION NODE_VERSION PIP_PACKAGES LYCHEE_VERSION LYCHEE_SHA256_AMD64 PINACT_VERSION PINACT_SHA256_AMD64 YQ_VERSION YQ_SHA256_AMD64 YQ_SHA256_ARM64; do [ -n "$(arg "$v")" ] || missing="${missing} $v" done if [ -z "${missing}" ] && [ "$(arg GO_VERSION)" = "${want_go}" ] && grep -q "python-version: \"$(arg PYTHON_VERSION)\"" "${REPO}/.github/workflows/lint.yml" && grep -q "$(arg LYCHEE_SHA256_AMD64) /tmp/lychee.tar.gz" "${REPO}/.github/workflows/lint.yml" && - [[ "$(arg PINACT_SHA256_AMD64)" =~ ^[0-9a-f]{64}$ ]]; then + [[ "$(arg PINACT_SHA256_AMD64)" =~ ^[0-9a-f]{64}$ ]] && + grep -q "$(arg YQ_SHA256_AMD64) /tmp/yq.tar.gz" "${REPO}/.github/workflows/lint.yml" && + grep -q "yq_linux_arm64.tar.gz sha256sum $(arg YQ_SHA256_ARM64)" "${REPO}/.github/workflows/lint.yml"; then pass "all build args are read from the real go.mod and lint.yml" else fail "build args from CI config: missing=[${missing}] args=$(tr '\n' ' ' <<< "${BUILD}")" diff --git a/internal/scaffold/vendorcontent.go b/internal/scaffold/vendorcontent.go index 573a31c2f2..790cf138a2 100644 --- a/internal/scaffold/vendorcontent.go +++ b/internal/scaffold/vendorcontent.go @@ -157,13 +157,15 @@ func isVendoredReusableWorkflow(path string) bool { // vendoredDefaultsScripts is the explicit allowlist of .github/scripts/ // files that ship to consumer repos. Everything here is executed in user -// repos: check-fix-eligibility.sh directly by the vendored reusable -// workflows, pre-fetch-review-body.sh and count-fix-commits.jq by the fix -// job's "Pre-fetch review body" (#8353) and "Extract PR number and -// context" (#8425) steps, the other four by the root composite action -// (action.yml, invoked as ./.defaults/ with GITHUB_ACTION_PATH resolving -// into the vendored tree). retry-with-backoff.sh is sourced by -// install-podman.sh and install-openshell.sh, so it must ship with them. +// repos: check-fix-eligibility.sh and resolve-effective-mint-url.sh +// directly by the vendored reusable workflows (dispatch route/harness jobs +// and reusable-prioritize); pre-fetch-review-body.sh and count-fix-commits.jq +// by the fix job's "Pre-fetch review body" (#8353) and "Extract PR number and +// context" (#8425) steps; install-openshell.sh, install-podman.sh, and +// openshell-version.sh by the root composite action (action.yml, invoked as +// ./.defaults/ with GITHUB_ACTION_PATH resolving into the vendored tree). +// retry-with-backoff.sh is sourced by install-podman.sh and +// install-openshell.sh, so it must ship with them. // // .github/scripts/ also hosts repo-local CI tooling and *-test.sh files // that must NOT ship to consumers. The directory prefix alone is @@ -180,6 +182,7 @@ var vendoredDefaultsScripts = map[string]bool{ ".github/scripts/install-podman.sh": true, ".github/scripts/openshell-version.sh": true, ".github/scripts/pre-fetch-review-body.sh": true, + ".github/scripts/resolve-effective-mint-url.sh": true, ".github/scripts/retry-with-backoff.sh": true, ".github/scripts/report-agent-startup-failure.sh": true, } diff --git a/internal/scaffold/vendorcontent_test.go b/internal/scaffold/vendorcontent_test.go index 9b3a9d24bc..4d8804bc3c 100644 --- a/internal/scaffold/vendorcontent_test.go +++ b/internal/scaffold/vendorcontent_test.go @@ -114,6 +114,8 @@ func TestIsVendoredDefaultsInfra(t *testing.T) { assert.True(t, isVendoredDefaultsInfra(".github/scripts/count-fix-commits.jq")) assert.True(t, isVendoredDefaultsInfra(".github/scripts/install-podman.sh")) assert.True(t, isVendoredDefaultsInfra(".github/scripts/pre-fetch-review-body.sh")) + assert.True(t, isVendoredDefaultsInfra(".github/scripts/resolve-effective-mint-url.sh")) + assert.False(t, isVendoredDefaultsInfra(".github/scripts/resolve-effective-mint-url-test.sh")) // The installers source retry-with-backoff.sh, so it must ship with them. assert.True(t, isVendoredDefaultsInfra(".github/scripts/install-openshell.sh")) assert.True(t, isVendoredDefaultsInfra(".github/scripts/retry-with-backoff.sh")) diff --git a/internal/scaffold/vendormanifest.go b/internal/scaffold/vendormanifest.go index 44d73f3dc2..17c5685c6a 100644 --- a/internal/scaffold/vendormanifest.go +++ b/internal/scaffold/vendormanifest.go @@ -163,6 +163,7 @@ var vendoredDefaultsInfraPaths = []string{ ".github/scripts/install-podman.sh", ".github/scripts/openshell-version.sh", ".github/scripts/pre-fetch-review-body.sh", + ".github/scripts/resolve-effective-mint-url.sh", ".github/scripts/retry-with-backoff.sh", ".github/scripts/report-agent-startup-failure.sh", } diff --git a/internal/scaffold/workflow_call_alignment_test.go b/internal/scaffold/workflow_call_alignment_test.go index a3582ac62a..e3cf3e812a 100644 --- a/internal/scaffold/workflow_call_alignment_test.go +++ b/internal/scaffold/workflow_call_alignment_test.go @@ -96,6 +96,8 @@ func TestStartupFailureReportingGuards(t *testing.T) { require.NoError(t, err) prioritizeText := string(prioritize) assert.Contains(t, prioritizeText, "failure-repo: ${{ inputs.source_repo }}") + assert.Contains(t, prioritizeText, "mint_url: ${{ steps.resolve-mint.outputs.mint_url }}", + "prioritize status token must use the config-derived mint URL") assert.NotContains(t, prioritizeText, "status-repo: ${{ inputs.source_repo }}") section := extractStepSection(t, prioritizeText, "Run prioritize agent") assert.Contains(t, section, "failure-repo:") @@ -1213,12 +1215,27 @@ func TestReusableDispatchJobsReceiveMintOIDC(t *testing.T) { require.NoError(t, err) require.NoError(t, yaml.Unmarshal(content, &workflow)) + routeJob, ok := workflow.Jobs["route"] + require.True(t, ok, "route job must exist") + assert.Equal(t, "${{ steps.resolve-mint.outputs.mint_url }}", routeJob.Outputs["mint_url"], + "route job must export the resolved mint URL for stage jobs") + for _, tc := range []struct { jobName string stepName string + mintURL string }{ - {jobName: "route", stepName: "Evaluate CEL route"}, - {jobName: "harness-dispatch", stepName: "Run fullsend dispatch"}, + { + jobName: "route", + stepName: "Evaluate CEL route", + // CLI resolveMintURL layers config files over FULLSEND_MINT_URL. + mintURL: "${{ inputs.mint_url }}", + }, + { + jobName: "harness-dispatch", + stepName: "Run fullsend dispatch", + mintURL: "${{ steps.resolve-mint.outputs.mint_url }}", + }, } { t.Run(tc.jobName, func(t *testing.T) { job, ok := workflow.Jobs[tc.jobName] @@ -1236,8 +1253,8 @@ func TestReusableDispatchJobsReceiveMintOIDC(t *testing.T) { require.NotEmpty(t, dispatch.Name, "job %q must include step %q", tc.jobName, tc.stepName) assert.Contains(t, dispatch.Run, "--input-driver gha-event", "step %q must use the GitHub event driver", tc.stepName) - assert.Equal(t, "${{ inputs.mint_url }}", dispatch.Env["FULLSEND_MINT_URL"], - "step %q must receive the configured mint URL", tc.stepName) + assert.Equal(t, tc.mintURL, dispatch.Env["FULLSEND_MINT_URL"], + "step %q must receive the expected mint URL", tc.stepName) for name, value := range job.Outputs { assert.NotContains(t, name, "ACTIONS_ID_TOKEN_REQUEST_TOKEN", "job %q output names must not expose the OIDC request token", tc.jobName) @@ -1250,6 +1267,315 @@ func TestReusableDispatchJobsReceiveMintOIDC(t *testing.T) { "the workflow must not copy the OIDC request token into logs or matrix data") } +// TestReusableDispatchStageJobsResolvedMintURL ensures inline stage jobs use +// resolved mint URLs. Review must resolve locally: its route skip-note token +// masks the URL, which GitHub then omits from route's job outputs (#8672). +func TestReusableDispatchStageJobsResolvedMintURL(t *testing.T) { + type workflowStep struct { + Name string `yaml:"name"` + ID string `yaml:"id"` + If string `yaml:"if"` + Uses string `yaml:"uses"` + With map[string]string `yaml:"with"` + Env map[string]string `yaml:"env"` + ContinueOnError bool `yaml:"continue-on-error"` + } + type workflowJob struct { + Outputs map[string]string `yaml:"outputs"` + Steps []workflowStep `yaml:"steps"` + } + var workflow struct { + Jobs map[string]workflowJob `yaml:"jobs"` + } + + content, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-dispatch.yml")) + require.NoError(t, err) + require.NoError(t, yaml.Unmarshal(content, &workflow)) + + wantLocal := "${{ steps.resolve-mint.outputs.mint_url }}" + route, ok := workflow.Jobs["route"] + require.True(t, ok, "route job must exist") + resolverIndex := -1 + var routeMintTokens int + var sawSkipPublish bool + for i, step := range route.Steps { + if step.Name == "Resolve effective mint URL" { + resolverIndex = i + } + if step.Uses == "./.defaults/.github/actions/mint-token" || + step.Uses == "./.fullsend/.defaults/.github/actions/mint-token" { + routeMintTokens++ + assert.True(t, step.ContinueOnError, "skip-note token failure must fall back to review") + require.GreaterOrEqual(t, resolverIndex, 0, "route must resolve before minting %q", step.Name) + assert.Less(t, resolverIndex, i, "route must resolve before minting %q", step.Name) + assert.Equal(t, wantLocal, step.With["mint_url"], "route mint-token %q must use resolved URL", step.Name) + assert.Contains(t, step.If, "steps.resolve-mint.outcome == 'success'", + "route mint-token %q must not run when resolution fails", step.Name) + } + if step.ID == "review-skip-publish" { + sawSkipPublish = true + assert.True(t, step.ContinueOnError, "skip-note publication failure must fall back to review") + } + } + assert.Equal(t, 2, routeMintTokens, "route must check both review skip-note mint paths") + assert.True(t, sawSkipPublish, "route must attempt skip-note publication") + assert.Contains(t, route.Outputs["stage"], "steps.review-skip-publish.outputs.skipped != 'true'", + "review must run when skip-note minting or publication fails") + + wantRoute := "${{ needs.route.outputs.mint_url }}" + for _, jobName := range []string{"triage", "code", "fix", "retro", "prioritize"} { + t.Run(jobName, func(t *testing.T) { + job, ok := workflow.Jobs[jobName] + require.True(t, ok, "job %q must exist", jobName) + var sawMintToken, sawAgent, sawFailureReporter bool + for _, step := range job.Steps { + if step.Uses == "./.defaults/.github/actions/mint-token" { + sawMintToken = true + assert.Equal(t, wantRoute, step.With["mint_url"], + "job %q mint-token must use route output", jobName) + assert.NotEqual(t, "${{ inputs.mint_url }}", step.With["mint_url"], + "job %q mint-token must not use workflow input", jobName) + } + if step.Uses == "./.defaults/" { + sawAgent = true + assert.Equal(t, wantRoute, step.With["mint-url"], + "job %q agent action must use route output", jobName) + } + if step.Name == "Report "+jobName+" launch failure" { + sawFailureReporter = true + assert.True(t, sawAgent, "job %q must report failures after its resolved-URL agent consumer", jobName) + if jobName != "prioritize" { + assert.True(t, sawMintToken, "job %q must report failures after its resolved-URL token consumer", jobName) + } + } + } + if jobName != "prioritize" { + assert.True(t, sawMintToken, "job %q must mint an app token", jobName) + } + assert.True(t, sawAgent, "job %q must run the agent composite", jobName) + assert.True(t, sawFailureReporter, "job %q must include its launch-failure reporter", jobName) + }) + } + + review, ok := workflow.Jobs["review"] + require.True(t, ok, "review job must exist") + resolvedAt := -1 + var reviewMint, reviewAgent bool + for i, step := range review.Steps { + if step.ID == "resolve-mint" { + resolvedAt = i + assert.Equal(t, "${{ inputs.mint_url }}", step.Env["FALLBACK_MINT_URL"]) + } + if step.Uses == "./.defaults/.github/actions/mint-token" { + reviewMint = true + assert.GreaterOrEqual(t, resolvedAt, 0, "review must resolve before mint-token") + assert.Less(t, resolvedAt, i) + assert.Equal(t, wantLocal, step.With["mint_url"], + "review must not use a route output masked by skip-note minting") + } + if step.Uses == "./.defaults/" { + reviewAgent = true + assert.GreaterOrEqual(t, resolvedAt, 0, "review must resolve before agent") + assert.Less(t, resolvedAt, i) + assert.Equal(t, wantLocal, step.With["mint-url"]) + } + } + assert.True(t, reviewMint, "review must mint an app token") + assert.True(t, reviewAgent, "review must run the agent composite") + + harnessRun, ok := workflow.Jobs["harness-run"] + require.True(t, ok, "harness-run job must exist") + var harnessMintToken, harnessAgent bool + for _, step := range harnessRun.Steps { + if step.Uses == "./.defaults/.github/actions/mint-token" { + harnessMintToken = true + assert.Equal(t, wantLocal, step.With["mint_url"], + "harness-run mint-token must use job-local resolve output") + } + if step.Uses == "./.defaults/" { + harnessAgent = true + assert.Equal(t, wantLocal, step.With["mint-url"], + "harness-run agent action must use job-local resolve output") + } + } + assert.True(t, harnessMintToken, "harness-run must mint an app token") + assert.True(t, harnessAgent, "harness-run must run the agent composite") + + harnessDispatch, ok := workflow.Jobs["harness-dispatch"] + require.True(t, ok, "harness-dispatch job must exist") + var sawDispatch bool + for _, step := range harnessDispatch.Steps { + if step.Name == "Run fullsend dispatch" { + sawDispatch = true + assert.Equal(t, wantLocal, step.Env["FULLSEND_MINT_URL"], + "harness-dispatch CLI must receive job-local resolve output") + } + } + assert.True(t, sawDispatch, "harness-dispatch must run the CLI") + + prioritizePath := filepath.Join("..", "..", ".github", "workflows", "reusable-prioritize.yml") + prioritizeContent, err := os.ReadFile(prioritizePath) + require.NoError(t, err) + var prioritizeWF struct { + Jobs map[string]struct { + Steps []workflowStep `yaml:"steps"` + } `yaml:"jobs"` + } + require.NoError(t, yaml.Unmarshal(prioritizeContent, &prioritizeWF)) + var prioritizeAgents, prioritizeMintTokens int + for jobName, job := range prioritizeWF.Jobs { + for _, step := range job.Steps { + if step.Uses == "./.defaults/" { + prioritizeAgents++ + assert.Equal(t, wantLocal, step.With["mint-url"], + "reusable-prioritize job %q must use resolve-mint output", jobName) + } + if step.Uses == "./.defaults/.github/actions/mint-token" { + prioritizeMintTokens++ + assert.Equal(t, wantLocal, step.With["mint_url"], + "reusable-prioritize job %q mint-token must use resolve-mint output", jobName) + } + } + } + assert.Positive(t, prioritizeAgents, "reusable-prioritize must run at least one agent composite") + assert.Positive(t, prioritizeMintTokens, "reusable-prioritize must mint at least one app token") +} + +// TestReusableDispatchMintResolverFetchesFromWorkflow ensures upstream-mode +// callers without a vendored resolver can sparse-checkout the script from +// job.workflow_repository (#9104). +func TestReusableDispatchMintResolverFetchesFromWorkflow(t *testing.T) { + type workflowStep struct { + Name string `yaml:"name"` + If string `yaml:"if"` + Env map[string]string `yaml:"env"` + Uses string `yaml:"uses"` + } + type workflowJob struct { + Steps []workflowStep `yaml:"steps"` + } + var workflow struct { + Jobs map[string]workflowJob `yaml:"jobs"` + } + + content, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-dispatch.yml")) + require.NoError(t, err) + require.NoError(t, yaml.Unmarshal(content, &workflow)) + + stepIndex := func(names []string, name string) int { + t.Helper() + for i, n := range names { + if n == name { + return i + } + } + t.Fatalf("missing step %q", name) + return -1 + } + + for _, jobName := range []string{"route", "review", "harness-dispatch", "harness-run"} { + t.Run(jobName, func(t *testing.T) { + job, ok := workflow.Jobs[jobName] + require.True(t, ok, "job %q must exist", jobName) + names := make([]string, 0, len(job.Steps)) + var checkoutStep, resolveStep workflowStep + for _, step := range job.Steps { + names = append(names, step.Name) + if step.Name == "Checkout workflow mint URL resolver" { + checkoutStep = step + } + if step.Name == "Resolve effective mint URL" { + resolveStep = step + } + } + assert.Contains(t, names, "Prepare mint URL resolver script") + assert.Contains(t, names, "Checkout workflow mint URL resolver") + assert.Contains(t, names, "Resolve effective mint URL") + assert.Contains(t, checkoutStep.If, "mint-resolver-script.outputs.fetched") + assert.Equal(t, "${{ inputs.mint_url }}", resolveStep.Env["FALLBACK_MINT_URL"], + "job %q must pass the variable snapshot to the resolver", jobName) + switch jobName { + case "route": + assert.Less(t, stepIndex(names, "Check kill switch"), + stepIndex(names, "Prepare mint URL resolver script"), + "route must resolve mint URL after the kill switch") + assert.Contains(t, checkoutStep.If, "steps.route.outputs.stage") + assert.Contains(t, resolveStep.If, "steps.route.outputs.stage", + "route must not resolve mint URL when no stage is selected") + case "harness-dispatch": + assert.Less(t, stepIndex(names, "Detect registered harness triggers"), + stepIndex(names, "Prepare mint URL resolver script"), + "harness-dispatch must resolve mint URL after trigger detection") + assert.Contains(t, checkoutStep.If, "has_triggers") + assert.Contains(t, resolveStep.If, "has_triggers", + "harness-dispatch must not resolve mint URL without registered triggers") + case "harness-run": + assert.Less(t, stepIndex(names, "Checkout upstream defaults"), + stepIndex(names, "Resolve effective mint URL"), + "harness-run must resolve mint URL only after upstream defaults are available") + } + if jobName == "review" || jobName == "harness-run" || jobName == "harness-dispatch" { + resolveIndex := stepIndex(names, "Resolve effective mint URL") + for i, step := range job.Steps { + if step.Uses == "./.defaults/.github/actions/mint-token" || + step.Uses == "./.defaults/" || + step.Name == "Run fullsend dispatch" { + assert.Less(t, resolveIndex, i, "job %q must resolve before %q", jobName, step.Name) + } + } + } + }) + } + assert.Contains(t, string(content), "path: .workflow-mint-resolver", + "upstream resolver checkout must use a workspace-relative path") + assert.NotContains(t, string(content), "runner.temp }}/workflow-mint-resolver", + "actions/checkout path must stay under GITHUB_WORKSPACE") + assert.NotContains(t, string(content), "RUNNER_TEMP}/workflow-mint-resolver", + "resolver script path must stay under GITHUB_WORKSPACE") + + prioritizeContent, err := os.ReadFile(filepath.Join("..", "..", ".github", "workflows", "reusable-prioritize.yml")) + require.NoError(t, err) + prioritize := string(prioritizeContent) + assert.Contains(t, prioritize, "Checkout workflow mint URL resolver") + assert.Contains(t, prioritize, "Prepare mint URL resolver script") + assert.Contains(t, prioritize, "path: .workflow-mint-resolver") + assert.NotContains(t, prioritize, "runner.temp }}/workflow-mint-resolver") + var prioritizeWF struct { + Jobs map[string]workflowJob `yaml:"jobs"` + } + require.NoError(t, yaml.Unmarshal(prioritizeContent, &prioritizeWF)) + for jobName, job := range prioritizeWF.Jobs { + names := make([]string, 0, len(job.Steps)) + for _, step := range job.Steps { + names = append(names, step.Name) + if step.Name == "Resolve effective mint URL" { + assert.Equal(t, "${{ inputs.mint_url }}", step.Env["FALLBACK_MINT_URL"], + "reusable-prioritize job %q must pass the variable snapshot", jobName) + } + } + assert.Less(t, stepIndex(names, "Checkout upstream defaults"), + stepIndex(names, "Resolve effective mint URL"), + "reusable-prioritize job %q must resolve mint URL after upstream defaults", jobName) + assert.Less(t, stepIndex(names, "Resolve effective mint URL"), + stepIndex(names, "Validate enrollment and extract repository metadata"), + "reusable-prioritize job %q must resolve mint URL before composite actions", jobName) + resolveIndex := stepIndex(names, "Resolve effective mint URL") + for i, step := range job.Steps { + if step.Uses == "./.defaults/.github/actions/mint-token" || step.Uses == "./.defaults/" { + assert.Less(t, resolveIndex, i, "reusable-prioritize job %q must resolve before %q", jobName, step.Name) + } + } + } + + w := string(content) + assert.NotContains(t, w, "for candidate in .github/scripts/resolve-effective-mint-url.sh", + "resolver must not prefer a caller-root script copy") + assert.Contains(t, w, "if [[ -f .defaults/.github/scripts/resolve-effective-mint-url.sh ]]", + "resolver must read vendored defaults before workflow fetch") + assert.NotContains(t, w, ".fullsend/config.base.yaml\n .github/scripts/resolve-effective-mint-url.sh\n", + "route sparse checkout must not pull caller-root resolver") +} + // TestCustomAppSetReviewBotWiring ensures every GitHub review/fix dispatch // path receives the configured app-set prefix and recognizes its exact review // bot identity.