From 0c4be22e3d8f1715f4375920c91ca50118ac1a85 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Sat, 31 Oct 2026 08:35:21 -0400 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20feature(integration):=20verify?= =?UTF-8?q?=20genuine=20required=20candidate=20contexts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/integration-candidate.template.yml | 223 ++ .github/scripts/generate-integration-ci.py | 104 +- .github/scripts/integration-governance.cjs | 119 + .../scripts/integration-governance.test.cjs | 66 + .../scripts/test-generate-integration-ci.py | 60 + .github/workflows/integration-candidate.yml | 2313 +++++++++++++++-- .../workflows/integration-technical-v2-ci.yml | 6 +- .github/workflows/v2-ci.yml | 6 +- .../added-integration-candidate-contexts.md | 1 + src/docs/integration-orchestration.md | 55 + .../integration/execution_archive.go | 35 +- .../integration/execution_archive_test.go | 56 + .../integration_execution_promotion.go | 6 + src/pkg/forgestate/integration_contexts.go | 44 + .../forgestate/integration_contexts_test.go | 40 + .../integration_candidate_governance.go | 122 + .../integration_candidate_governance_test.go | 162 ++ .../integration_candidate_observation.go | 52 +- .../integration_candidate_observation_test.go | 60 +- src/scripts/check-changelog-fragment.sh | 5 +- 20 files changed, 3350 insertions(+), 185 deletions(-) create mode 100644 .github/integration-candidate.template.yml create mode 100644 .github/scripts/integration-governance.cjs create mode 100644 .github/scripts/integration-governance.test.cjs create mode 100644 .github/scripts/test-generate-integration-ci.py create mode 100644 changelog.d/added-integration-candidate-contexts.md create mode 100644 src/pkg/forgestate/integration_contexts.go create mode 100644 src/pkg/forgestate/integration_contexts_test.go create mode 100644 src/pkg/github/integration_candidate_governance.go create mode 100644 src/pkg/github/integration_candidate_governance_test.go diff --git a/.github/integration-candidate.template.yml b/.github/integration-candidate.template.yml new file mode 100644 index 0000000000..ffcb146bae --- /dev/null +++ b/.github/integration-candidate.template.yml @@ -0,0 +1,223 @@ +name: Integration candidate +run-name: Integration ${{ fromJSON(inputs.manifest).id }} ${{ fromJSON(inputs.manifest).dispatchClaim.owner.nonce }} + +on: + workflow_dispatch: + inputs: + manifest: + description: Exact versioned subject emitted by an enrolled trusted materializer. + required: true + type: string + +permissions: + contents: read + pull-requests: read + +concurrency: + group: integration-candidate-${{ github.run_id }} + cancel-in-progress: false + +jobs: + subject: + name: gate + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + metadata_digest: ${{ steps.metadata.outputs.metadata_digest }} + steps: + - name: Validate immutable ordered subject before assigning technical jobs + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + with: + script: | + const crypto = require('node:crypto'); + const MAX_MANIFEST_BYTES = 32 * 1024; + const MAX_CANDIDATE_MEMBERS = 8; + const EXPECTED_PARENTS = 2; + const fail = message => { throw new Error(message); }; + const sha = value => typeof value === 'string' && /^[a-f0-9]{40}$/.test(value) && !/^0+$/.test(value); + const digest = value => typeof value === 'string' && /^[a-f0-9]{64}$/.test(value) && !/^0+$/.test(value); + const raw = process.env.SUBJECT_MANIFEST || ''; + if (Buffer.byteLength(raw, 'utf8') > MAX_MANIFEST_BYTES) fail('Candidate manifest exceeds the bounded protocol'); + const subject = JSON.parse(raw); + const canonical = value => { + if (value === null || typeof value !== 'object') return JSON.stringify(value); + if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`; + return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`; + }; + if (subject.schema !== 1 || subject.protocol !== 'integration-prefix-v1' || + subject.engine !== 'hive' || !digest(subject.id) || + subject.repo !== `${context.repo.owner}/${context.repo.repo}` || + !sha(subject.baseSHA) || !digest(subject.policy) || + !sha(subject.workflowTree) || !Number.isSafeInteger(subject.generation) || + subject.generation < 1 || typeof subject.base !== 'string' || !subject.base.length) { + fail('Invalid integration subject identity; no candidate jobs admitted'); + } + const {id, generation, preparedBy, dispatchClaim, ...immutable} = subject; + if (crypto.createHash('sha256').update(canonical(immutable)).digest('hex') !== id) { + fail('Subject ID does not bind its exact immutable membership, commits, trees and policy'); + } + const claimKey = crypto.createHash('sha256').update(`integration-ci-initial-v1/${subject.id}`).digest('hex'); + if (!dispatchClaim || dispatchClaim.state !== 'claimed' || + dispatchClaim.key !== claimKey || dispatchClaim.ref !== `heads/hive-integration-intents/${claimKey}` || + !sha(dispatchClaim.commit) || !dispatchClaim.owner || + typeof dispatchClaim.owner.nonce !== 'string' || !/^[a-f0-9]{32}$/.test(dispatchClaim.owner.nonce) || + !/^[1-9][0-9]*$/.test(dispatchClaim.owner.runID) || !/^[1-9][0-9]*$/.test(dispatchClaim.owner.attempt)) { + fail('Candidate has no exact shared single-attempt dispatch owner'); + } + if (context.eventName !== 'workflow_dispatch' || + context.ref !== `refs/tags/hive-integration/${subject.id}` || + !Array.isArray(subject.members) || !Array.isArray(subject.prefixes) || + subject.members.length < 1 || subject.members.length > MAX_CANDIDATE_MEMBERS || + subject.members.length !== subject.prefixes.length) { + fail('Candidate dispatch/ref or bounded ordered membership mismatch'); + } + const numbers = new Set(); + const heads = new Set(); + const variables = {owner: context.repo.owner, name: context.repo.repo, + claimRef: `refs/${dispatchClaim.ref}`}; + const declarations = ['$owner:String!', '$name:String!', '$policy:String!', '$claimRef:String!']; + const objects = []; + for (let i = 0; i < subject.members.length; i++) { + const member = subject.members[i], prefix = subject.prefixes[i]; + if (!member || !Number.isSafeInteger(member.pr) || member.pr < 1 || + numbers.has(member.pr) || heads.has(member.head) || !sha(member.head) || + !prefix || !sha(prefix.commit) || !sha(prefix.tree)) { + fail('Invalid or duplicate ordered candidate member'); + } + numbers.add(member.pr); + heads.add(member.head); + declarations.push(`$prefix${i}:String!`); + variables[`prefix${i}`] = prefix.commit; + objects.push(`prefix${i}:object(expression:$prefix${i}){... on Commit{oid tree{oid} parents(first:${EXPECTED_PARENTS + 1}){nodes{oid}}}}`); + } + if (subject.prefixes.at(-1).commit !== context.sha) { + fail('Dispatch does not execute the actual tested candidate commit'); + } + variables.policy = `${context.sha}:.github`; + const query = `query(${declarations.join(',')}){repository(owner:$owner,name:$name){nameWithOwner claim:ref(qualifiedName:$claimRef){target{oid ... on Commit{message}}} policy:object(expression:$policy){... on Tree{oid}} ${objects.join(' ')}}}`; + const {repository} = await github.graphql(query, variables); + if (repository?.nameWithOwner !== subject.repo || repository.policy?.oid !== subject.workflowTree) { + fail('Repository or producer workflow closure changed'); + } + if (repository.claim?.target?.oid !== dispatchClaim.commit) { + fail('Shared dispatch authority changed or is unavailable; no TTL takeover'); + } + const records = (repository.claim.target.message || '').split('\n').filter(line => line.startsWith('{')); + if (records.length !== 1) fail('Shared dispatch authority record is malformed'); + const owner = JSON.parse(records[0]); + if (owner.schema !== 1 || owner.kind !== 'integration-ci-single-attempt-v1' || + owner.key !== claimKey || owner.subjectID !== subject.id || + owner.owner?.nonce !== dispatchClaim.owner.nonce || + owner.owner?.runID !== dispatchClaim.owner.runID || + owner.owner?.attempt !== dispatchClaim.owner.attempt) { + fail('Shared dispatch owner does not match the candidate execution'); + } + let parent = subject.baseSHA; + for (let i = 0; i < subject.members.length; i++) { + const actual = repository[`prefix${i}`], expected = subject.prefixes[i]; + const parents = actual?.parents?.nodes; + if (actual?.oid !== expected.commit || actual.tree?.oid !== expected.tree || + !Array.isArray(parents) || parents.length !== EXPECTED_PARENTS || + parents[0].oid !== parent || parents[1].oid !== subject.members[i].head) { + fail(`Candidate prefix ${i + 1} is not its exact ordered two-parent subject`); + } + parent = actual.oid; + } + core.info(`Validated immutable subject ${subject.id}; this is not promotion authorization.`); + core.info(`Manifest SHA256 ${crypto.createHash('sha256').update(raw).digest('hex')}`); + + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Bind exact current member governance metadata + id: metadata + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + with: + script: | + const {snapshot, digest} = require('./.github/scripts/integration-governance.cjs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + core.setOutput('metadata_digest', digest(await snapshot(github, subject))); + + receipt: + name: integration producer receipt + needs: [subject] + if: ${{ always() && needs.subject.result == 'success' }} + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + actions: read + checks: read + id-token: write + steps: + - name: Bind exact receipt bytes to this isolated finalizer job + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + TECHNICAL_OUTCOMES: ${{ toJSON(needs) }} + REQUIRED_CONTEXT_JOBS: '{}' # Filled from the actual generated DAG. + with: + script: | + const crypto = require('node:crypto'); + const fs = require('node:fs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + const needs = JSON.parse(process.env.TECHNICAL_OUTCOMES); + const metadataDigest = needs.subject.outputs.metadata_digest; + if (!/^[a-f0-9]{64}$/.test(metadataDigest || '')) throw new Error('Missing exact member governance binding'); + for (const [id, job] of Object.entries(needs)) { + if (id.startsWith('governance-') && job.outputs.metadata_digest !== metadataDigest) { + throw new Error('Member metadata drifted during governance verification'); + } + } + const runID = Number(process.env.GITHUB_RUN_ID), attempt = Number(process.env.GITHUB_RUN_ATTEMPT); + const args = {...context.repo, run_id: runID}; + const {data: run} = await github.rest.actions.getWorkflowRun(args); + const {data: jobs} = await github.rest.actions.listJobsForWorkflowRunAttempt({...args, attempt_number: attempt, per_page: 100}); + const {data: checks} = await github.rest.checks.listForRef({...context.repo, ref: context.sha, filter: 'all', per_page: 100}); + if (run.run_attempt !== attempt || run.head_sha !== context.sha || + jobs.total_count !== jobs.jobs.length || checks.total_count !== checks.check_runs.length) { + throw new Error('Latest exact-attempt job/check cohort is unknown or truncated'); + } + const contexts = {}; + for (const [name, id] of Object.entries(JSON.parse(process.env.REQUIRED_CONTEXT_JOBS))) { + const matches = jobs.jobs.filter(job => job.name === name); + if (matches.length !== 1) throw new Error(`Missing/ambiguous actual required job ${name}`); + const job = matches[0], checkID = Number(job.check_run_url.split('/').at(-1)); + const check = checks.check_runs.find(item => item.id === checkID); + if (!check || job.run_id !== runID || job.head_sha !== context.sha || + check.name !== name || check.head_sha !== context.sha || check.check_suite.id !== run.check_suite_id || + check.app.id !== 15368 || job.status !== 'completed' || check.status !== 'completed' || + check.conclusion !== job.conclusion || job.conclusion !== needs[id].result) { + throw new Error(`Required context ${name} is not its actual exact-subject Actions producer`); + } + contexts[name] = {jobID: job.id, checkID, appID: check.app.id, suiteID: check.check_suite.id, conclusion: job.conclusion}; + } + const payload = Buffer.from(JSON.stringify({ + schema: 2, + protocol: 'integration-producer-receipt-v2', + subject, + runID: process.env.GITHUB_RUN_ID, + runAttempt: process.env.GITHUB_RUN_ATTEMPT, + metadataDigest, + contexts, + }), 'utf8'); + const digest = crypto.createHash('sha256').update(payload).digest('hex'); + const token = await core.getIDToken(`hive-integration-producer-v1/${digest}`); + core.setSecret(token); + fs.mkdirSync('.integration-producer', {recursive: true}); + fs.writeFileSync('.integration-producer/receipt.json', JSON.stringify({ + schema: 1, payload: payload.toString('base64'), token, + }), {flag: 'wx', mode: 0o600}); + core.info(`Recorded producer identity for ${subject.id}; passing CI and live policy require independent verification.`); + - name: Publish immutable attempt-specific producer receipt + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: integration-producer-receipt-${{ github.run_attempt }} + path: .integration-producer/receipt.json + include-hidden-files: true + if-no-files-found: error + retention-days: 30 diff --git a/.github/scripts/generate-integration-ci.py b/.github/scripts/generate-integration-ci.py index 656546e1b8..003c40acd8 100644 --- a/.github/scripts/generate-integration-ci.py +++ b/.github/scripts/generate-integration-ci.py @@ -34,6 +34,16 @@ "# Generated by .github/scripts/generate-integration-ci.py; do not edit.\n" "# Candidate-only technical CI. Ordinary and native CI remain in the source.\n" ) +CONTEXTS = { + "build-and-test", "test", "coverage", "golangci-lint", + "gosec (insecure patterns)", "govulncheck (known vulnerabilities)", +} +GOVERNANCE = { + "dco": "DCO", + "changelog": "changelog-fragment-guard", + "contents": "verify PR contents", + "attribution": "Sign-off survives the squash", +} class WorkflowLoader(yaml.SafeLoader): @@ -137,16 +147,99 @@ def render(source, document): document, Dumper=WorkflowDumper, sort_keys=False, width=10000 ) +def compose(documents): + template = ROOT / ".github" / "integration-candidate.template.yml" + entry = yaml.load(template.read_text(), Loader=WorkflowLoader) + jobs = entry["jobs"] + receipt = jobs.pop("receipt") + bindings = {"gate": "subject"} + for source, document in documents.items(): + lane = {"v2-ci.yml": "ci", "v2-tests.yml": "tests", + "go-security-analysis.yml": "security"}[source] + generated = yaml.load(render(source, document), Loader=WorkflowLoader) + mapping = {key: f"{lane}-{key}" for key in generated["jobs"]} + + def rewrite(value): + if isinstance(value, str): + return re.sub(r"\bneeds\.([A-Za-z0-9_-]+)", + lambda match: "needs." + mapping.get(match[1], match[1]), value) + if isinstance(value, list): + return [rewrite(item) for item in value] + if isinstance(value, dict): + return {key: rewrite(item) for key, item in value.items()} + return value + + for key, original in generated["jobs"].items(): + job = rewrite(original) + dependencies = original.get("needs", []) + if isinstance(dependencies, str): + dependencies = [dependencies] + job["needs"] = ["subject"] + [mapping[value] for value in dependencies] + condition = str(job.get("if", "${{ success() }}")).strip() + if condition.startswith("${{") and condition.endswith("}}"): + condition = condition[3:-2].strip() + job["if"] = "${{ always() && needs.subject.result == 'success' && (" + condition + ") }}" + job["name"] = original.get("name", key) + job["env"] = {**generated.get("env", {}), **job.get("env", {})} + if job["name"] in CONTEXTS: + if job["name"] in bindings: + raise ValueError(f"duplicate required context {job['name']}") + bindings[job["name"]] = mapping[key] + if source == "v2-tests.yml" and key == "test": + for step in job["steps"]: + if step.get("name") == "Check shard results": + step["run"] = step["run"].replace( + 'if [ "${#cancelled[@]}" -gt 0 ]; then', + 'if [ "${#cancelled[@]}" -gt 0 ]; then\n echo "::error::Candidate shards must all complete"; exit 1') + jobs[mapping[key]] = job + if set(bindings) != CONTEXTS | {"gate"}: + raise ValueError("actual technical producer context coverage changed") + for kind, name in GOVERNANCE.items(): + key = f"governance-{kind}" + bindings[name] = key + jobs[key] = { + "name": name, "needs": ["subject"], "runs-on": "ubuntu-latest", + "timeout-minutes": 15, + "outputs": {"metadata_digest": "${{ steps.verify.outputs.metadata_digest }}"}, + "steps": [ + {"uses": "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1", + "with": {"fetch-depth": 0, "persist-credentials": False}}, + {"name": "Verify exact current members with trusted readonly policy", "id": "verify", + "uses": "actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3", + "env": {"SUBJECT_MANIFEST": "${{ inputs.manifest }}", + "EXPECTED_METADATA_DIGEST": "${{ needs.subject.outputs.metadata_digest }}", + "GITHUB_TOKEN": "${{ github.token }}"}, + "with": {"script": ( + "const policy = require('./.github/scripts/integration-governance.cjs');\n" + "const subject = JSON.parse(process.env.SUBJECT_MANIFEST);\n" + "const members = await policy.snapshot(github, subject);\n" + "const actual = policy.digest(members);\n" + "if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted');\n" + "core.setOutput('metadata_digest', actual);\n" + f"await policy.verify('{kind}', subject, members);\n" + )}}, + ], + } + receipt["needs"] = list(jobs) + for step in receipt["steps"]: + if "REQUIRED_CONTEXT_JOBS" in step.get("env", {}): + import json + step["env"]["REQUIRED_CONTEXT_JOBS"] = json.dumps(bindings, sort_keys=True) + jobs["receipt"] = receipt + return HEADER + yaml.dump(entry, Dumper=WorkflowDumper, sort_keys=False, width=10000) + def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check", action="store_true") args = parser.parse_args() different = False + documents = {} for source in SOURCES: original = ROOT / ".github" / "workflows" / source output = original.with_name(f"integration-technical-{source}") - expected = render(source, yaml.load(original.read_text(), Loader=WorkflowLoader)) + documents[source] = yaml.load(original.read_text(), Loader=WorkflowLoader) + expected = render(source, documents[source]) if args.check: actual = output.read_text() if output.exists() else "" if actual != expected: @@ -158,6 +251,15 @@ def main(): else: output.write_text(expected) print(output.relative_to(ROOT)) + output = ROOT / ".github" / "workflows" / "integration-candidate.yml" + expected = compose(documents) + if args.check: + if not output.exists() or output.read_text() != expected: + different = True + print("integration-candidate.yml differs from its trusted template/composed producers") + else: + output.write_text(expected) + print(output.relative_to(ROOT)) if different: raise SystemExit("Run python3 .github/scripts/generate-integration-ci.py") diff --git a/.github/scripts/integration-governance.cjs b/.github/scripts/integration-governance.cjs new file mode 100644 index 0000000000..636ca31e64 --- /dev/null +++ b/.github/scripts/integration-governance.cjs @@ -0,0 +1,119 @@ +'use strict'; + +const crypto = require('node:crypto'); +const cp = require('node:child_process'); +const fs = require('node:fs'); +const path = require('node:path'); +const MAX_MEMBERS = 8; +const MAX_COMMITS = 1000; +const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4'; +const sha = value => crypto.createHash('sha256').update(value).digest('hex'); +const git = (args, cwd = process.cwd()) => + cp.execFileSync('git', ['-c', 'core.hooksPath=/dev/null', ...args], {cwd, encoding: 'utf8'}).trim(); + +function row(pr) { + return [pr.number, pr.head.sha, pr.base.repo.full_name, sha(pr.base.ref), + pr.user.id, pr.user.login, Boolean(pr.draft), sha(pr.title), sha(pr.body || ''), + pr.labels.map(label => sha(label.name)).sort(), sha(pr.head.ref)]; +} +const digest = members => sha(JSON.stringify(members.map(row))); + +async function snapshot(github, subject) { + if (!Array.isArray(subject.members) || !subject.members.length || subject.members.length > MAX_MEMBERS || + subject.members.length !== subject.prefixes.length || subject.repo.split('/').length !== 2) { + throw new Error('Invalid bounded candidate membership'); + } + const [owner, repo] = subject.repo.split('/'); + const members = [], seen = new Set(); + for (const [index, member] of subject.members.entries()) { + const {data: pr} = await github.rest.pulls.get({owner, repo, pull_number: member.pr}); + if (seen.has(member.pr) || pr.number !== member.pr || pr.head.sha !== member.head || + pr.head.repo?.full_name !== subject.repo || pr.base.repo.full_name !== subject.repo || + pr.base.ref !== subject.base || pr.draft || !pr.user?.id || !pr.user.login || + typeof pr.title !== 'string' || !Array.isArray(pr.labels) || + !(pr.state === 'open' || pr.merged === true && pr.merge_commit_sha === subject.prefixes[index].commit)) { + throw new Error(`Member ${member.pr} does not match exact candidate provenance`); + } + seen.add(member.pr); + members.push(pr); + } + return members; +} + +// Readonly adaptation of verify/type.go, verify/issue.go and notes/common/prefix.go +// at SOURCE (SPDX-License-Identifier: Apache-2.0, Copyright 2020 The Kubernetes Authors). +// https://www.apache.org/licenses/LICENSE-2.0 . Unlike the +// advisory image wrapper, unavailable validation never becomes success. +function verifyContents(title) { + const trimmed = title.replace(/^\W?WIP\W/iu, '').trim().replace(/^\[[\w.-]*\]/, '').trim(); + const prefixes = ['✨', '🐛', '📖', '🌱', '⚠', '🚀', '🏃', + ':sparkles:', ':bug:', ':book:', ':seedling:', ':warning:', ':rocket:', ':running:']; + if (!prefixes.some(prefix => trimmed.startsWith(prefix)) || /#[0-9]+\b/.test(title)) { + throw new Error(`PR content policy rejected title; immutable source ${SOURCE}`); + } +} + +function run(script, args, cwd, extra = {}) { + cp.execFileSync('bash', [path.resolve('src/scripts', script), ...args], { + cwd, stdio: 'inherit', env: {...process.env, ...extra}, + }); +} + +async function verify(kind, subject, members) { + if (!['dco', 'changelog', 'contents', 'attribution'].includes(kind)) throw new Error('Unknown governance policy'); + const root = process.cwd(), source = subject.preparedBy?.sourceSHA; + if (!/^[a-f0-9]{40}$/.test(source || '') || + git(['rev-parse', `${source}:.github`]) !== subject.workflowTree || + git(['rev-parse', `${source}:src/scripts`]) !== git(['rev-parse', 'HEAD:src/scripts'])) { + throw new Error('Trusted control/helper closure unavailable; no candidate script execution'); + } + if (kind === 'contents') { + for (const pr of members) verifyContents(pr.title); + return; + } + if (kind === 'dco') { + const tested = subject.prefixes.at(-1).commit; + const range = `${subject.baseSHA}..${tested}`; + const count = Number(git(['rev-list', '--count', range])); + if (!Number.isSafeInteger(count) || count < 1 || count > MAX_COMMITS) throw new Error('DCO introduced commit cohort unknown/too large'); + run('check-dco-trailers.sh', [String(count), range], root, { + DCO_SKIP_BOT_AUTHORS: 'false', DCO_WAIVED_COMMITS: '', DCO_ALLOWLIST_EMAILS: '', + }); + for (const prefix of subject.prefixes) { + const author = git(['show', '-s', '--format=%an <%ae>', prefix.commit]); + const message = git(['show', '-s', '--format=%B', prefix.commit]); + if (!message.split('\n').some(line => line.toLowerCase() === `Signed-off-by: ${author}`.toLowerCase())) { + throw new Error('Generated merge lacks its own actual author signoff'); + } + } + return; + } + if (kind === 'attribution') { + for (const pr of members) { + run('check-squash-signoff-attribution.sh', [subject.baseSHA, pr.head.sha, pr.user.login], root, { + PR_AUTHOR_LOGIN: pr.user.login, + PR_MERGE_METHOD: pr.labels.some(label => label.name === 'merge-method/merge') ? 'merge' : '', + LANDED_REFS: subject.baseSHA, + }); + } + return; + } + const work = path.resolve('.integration-governance'); + fs.mkdirSync(work, {recursive: true}); + for (const pr of members) { + const target = path.join(work, String(pr.number)); + git(['worktree', 'add', '--detach', target, pr.head.sha]); + try { + run('check-changelog-fragment.sh', [subject.base], target, { + BASE_SHA: subject.baseSHA, HEAD_REF: pr.head.ref, + HAS_NO_CHANGELOG_LABEL: String(pr.labels.some(label => label.name === 'no-changelog')), + }); + } finally { git(['worktree', 'remove', '--force', target]); } + } + if (git(['diff', '--name-only', subject.baseSHA, subject.prefixes.at(-1).commit]) + .split('\n').some(file => /^src\/pkg\/(hub|dashboard)\/server\.go$|^src\/pkg\/(hub|dashboard)\/static\//.test(file))) { + run('check-api-reference-citations.sh', [], root); + } +} + +module.exports = {SOURCE, row, digest, snapshot, verifyContents, verify}; diff --git a/.github/scripts/integration-governance.test.cjs b/.github/scripts/integration-governance.test.cjs new file mode 100644 index 0000000000..5c2f9610c7 --- /dev/null +++ b/.github/scripts/integration-governance.test.cjs @@ -0,0 +1,66 @@ +'use strict'; +const test = require('node:test'); +const assert = require('node:assert/strict'); +const policy = require('./integration-governance.cjs'); + +const head = 'a'.repeat(40), commit = 'b'.repeat(40); +const subject = () => ({repo: 'hivecommons/hive', base: 'v5', + members: [{pr: 7, head}], prefixes: [{commit, tree: 'c'.repeat(40)}]}); +const member = () => ({number: 7, head: {sha: head, ref: 'feature', repo: {full_name: 'hivecommons/hive'}}, + base: {ref: 'v5', sha: 'd'.repeat(40), repo: {full_name: 'hivecommons/hive'}}, + user: {id: 42, login: 'author'}, draft: false, state: 'open', title: '✨ feature: exact subject', + body: 'Fixes #6', labels: [{name: 'approved'}]}); +const client = pr => ({rest: {pulls: {get: async () => ({data: pr})}}}); + +test('pinned pure verifier actually validates the immutable upstream rules', () => { + assert.ok(policy.SOURCE.endsWith('012269a88fa4c034a0acf1ba84c26b195c0dbab4')); + for (const title of ['✨ feature', '🐛 fix', '📖 docs', '🌱 infra', '⚠️ breaking', '🚀 release', + ':bug: fix', ':running: legacy', 'WIP: [scope] ✨ feature', '🐛WIP: 📖 docs']) { + assert.doesNotThrow(() => policy.verifyContents(title), title); + } + for (const title of ['', 'ordinary title', '📝 proposal', '✨ fix #123', ':bug: #12a and #13']) { + assert.throws(() => policy.verifyContents(title), title); + } +}); + +test('member snapshots never accept another head/repo/member or an unrelated merge', async () => { + assert.equal((await policy.snapshot(client(member()), subject())).length, 1); + const mutations = [ + pr => {pr.number++;}, pr => {pr.head.sha = 'e'.repeat(40);}, + pr => {pr.head.repo.full_name = 'other/fork';}, pr => {pr.base.ref = 'other';}, + pr => {pr.base.repo.full_name = 'other/repo';}, pr => {pr.draft = true;}, + pr => {pr.user.id = 0;}, pr => {pr.user.login = '';}, pr => {pr.state = 'closed';}, + pr => {pr.title = null;}, pr => {pr.labels = null;}, + pr => {pr.state = 'closed'; pr.merged = true; pr.merge_commit_sha = 'f'.repeat(40);}, + ]; + for (const mutate of mutations) { + const pr = member(); mutate(pr); + await assert.rejects(policy.snapshot(client(pr), subject())); + } + const duplicate = subject(); + duplicate.members.push({...duplicate.members[0]}); duplicate.prefixes.push({...duplicate.prefixes[0]}); + await assert.rejects(policy.snapshot(client(member()), duplicate)); + await assert.rejects(policy.snapshot(client(member()), {...subject(), members: []})); + await assert.rejects(policy.snapshot(client(member()), {...subject(), prefixes: []})); +}); + +test('mutable governance is bound, but exact documented prefix promotion is not invalidated', async () => { + const pr = member(), before = policy.digest([pr]); + for (const change of [ + value => {value.title += ' changed';}, value => {value.body += ' changed';}, + value => {value.labels.push({name: 'no-changelog'});}, value => {value.head.ref = 'sync/v5';}, + value => {value.user.login = 'someone-else';}, value => {value.user.id++;}, + value => {value.draft = true;}, + ]) { + const value = structuredClone(pr); change(value); + assert.notEqual(policy.digest([value]), before); + } + pr.state = 'closed'; pr.merged = true; pr.merge_commit_sha = commit; + pr.base.sha = 'f'.repeat(40); pr.updated_at = '2026-10-31T12:00:00Z'; + assert.equal(policy.digest(await policy.snapshot(client(pr), subject())), before); +}); + +test('unsupported or untrusted helper scope refuses instead of returning green', async () => { + await assert.rejects(policy.verify('unknown', subject(), [member()])); + await assert.rejects(policy.verify('contents', subject(), [member()]), /closure unavailable/); +}); diff --git a/.github/scripts/test-generate-integration-ci.py b/.github/scripts/test-generate-integration-ci.py new file mode 100644 index 0000000000..ca0e2b05f4 --- /dev/null +++ b/.github/scripts/test-generate-integration-ci.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +import copy +import importlib.util +import json +from pathlib import Path +import unittest + +spec = importlib.util.spec_from_file_location("candidate_generator", Path(__file__).with_name("generate-integration-ci.py")) +generator = importlib.util.module_from_spec(spec) +spec.loader.exec_module(generator) + + +class CompositionTest(unittest.TestCase): + def setUp(self): + self.documents = { + name: generator.yaml.load((generator.ROOT / ".github/workflows" / name).read_text(), + Loader=generator.WorkflowLoader) + for name in generator.SOURCES + } + + def test_real_jobs_are_top_level_with_the_entire_exact_dag(self): + workflow = generator.yaml.load(generator.compose(self.documents), Loader=generator.WorkflowLoader) + jobs = workflow["jobs"] + expected = generator.CONTEXTS | set(generator.GOVERNANCE.values()) | {"gate"} + bindings = json.loads(jobs["receipt"]["steps"][0]["env"]["REQUIRED_CONTEXT_JOBS"]) + self.assertEqual(set(bindings), expected) + for name, key in bindings.items(): + self.assertEqual(jobs[key]["name"], name) + self.assertIn("steps", jobs[key]) + self.assertNotIn("uses", jobs[key]) + self.assertEqual(sum(job.get("name") == name for job in jobs.values()), 1) + self.assertEqual(set(jobs["receipt"]["needs"]), set(jobs) - {"receipt"}) + for key, job in jobs.items(): + for dependency in job.get("needs", []): + self.assertIn(dependency, jobs, key) + if key.startswith(("ci-", "tests-", "security-")): + self.assertIn("needs.subject.result == 'success'", job["if"]) + script = next(step["run"] for step in jobs["tests-test"]["steps"] if step.get("name") == "Check shard results") + self.assertIn('Candidate shards must all complete"; exit 1', script) + self.assertEqual(workflow["permissions"], {"contents": "read", "pull-requests": "read"}) + + def test_unqualified_producer_permissions_or_context_drift_cannot_generate_green_aliases(self): + for mutation in ("permission", "missing", "checkout", "needs"): + documents = copy.deepcopy(self.documents) + job = documents["v2-ci.yml"]["jobs"]["build-and-test"] + if mutation == "permission": + job["permissions"] = {"contents": "write"} + elif mutation == "missing": + job["name"] = "not-the-required-context" + elif mutation == "checkout": + checkout = next(step for step in job["steps"] if str(step.get("uses", "")).startswith("actions/checkout@")) + checkout.setdefault("with", {})["ref"] = "other-head" + else: + job["needs"] = ["does-not-exist"] + with self.assertRaises(ValueError, msg=mutation): + generator.compose(documents) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/integration-candidate.yml b/.github/workflows/integration-candidate.yml index d2e19050e7..e850f55e36 100644 --- a/.github/workflows/integration-candidate.yml +++ b/.github/workflows/integration-candidate.yml @@ -1,190 +1,2181 @@ +# Generated by .github/scripts/generate-integration-ci.py; do not edit. +# Candidate-only technical CI. Ordinary and native CI remain in the source. name: Integration candidate run-name: Integration ${{ fromJSON(inputs.manifest).id }} ${{ fromJSON(inputs.manifest).dispatchClaim.owner.nonce }} - -on: +'on': workflow_dispatch: inputs: manifest: description: Exact versioned subject emitted by an enrolled trusted materializer. required: true type: string - permissions: contents: read - + pull-requests: read concurrency: group: integration-candidate-${{ github.run_id }} cancel-in-progress: false - jobs: subject: - name: integration subject + name: gate runs-on: ubuntu-latest timeout-minutes: 10 + outputs: + metadata_digest: ${{ steps.metadata.outputs.metadata_digest }} steps: - - name: Validate immutable ordered subject before assigning technical jobs - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - env: - SUBJECT_MANIFEST: ${{ inputs.manifest }} - with: - script: | - const crypto = require('node:crypto'); - const MAX_MANIFEST_BYTES = 32 * 1024; - const MAX_CANDIDATE_MEMBERS = 8; - const EXPECTED_PARENTS = 2; - const fail = message => { throw new Error(message); }; - const sha = value => typeof value === 'string' && /^[a-f0-9]{40}$/.test(value) && !/^0+$/.test(value); - const digest = value => typeof value === 'string' && /^[a-f0-9]{64}$/.test(value) && !/^0+$/.test(value); - const raw = process.env.SUBJECT_MANIFEST || ''; - if (Buffer.byteLength(raw, 'utf8') > MAX_MANIFEST_BYTES) fail('Candidate manifest exceeds the bounded protocol'); - const subject = JSON.parse(raw); - const canonical = value => { - if (value === null || typeof value !== 'object') return JSON.stringify(value); - if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`; - return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`; - }; - if (subject.schema !== 1 || subject.protocol !== 'integration-prefix-v1' || - subject.engine !== 'hive' || !digest(subject.id) || - subject.repo !== `${context.repo.owner}/${context.repo.repo}` || - !sha(subject.baseSHA) || !digest(subject.policy) || - !sha(subject.workflowTree) || !Number.isSafeInteger(subject.generation) || - subject.generation < 1 || typeof subject.base !== 'string' || !subject.base.length) { - fail('Invalid integration subject identity; no candidate jobs admitted'); + - name: Validate immutable ordered subject before assigning technical jobs + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + with: + script: | + const crypto = require('node:crypto'); + const MAX_MANIFEST_BYTES = 32 * 1024; + const MAX_CANDIDATE_MEMBERS = 8; + const EXPECTED_PARENTS = 2; + const fail = message => { throw new Error(message); }; + const sha = value => typeof value === 'string' && /^[a-f0-9]{40}$/.test(value) && !/^0+$/.test(value); + const digest = value => typeof value === 'string' && /^[a-f0-9]{64}$/.test(value) && !/^0+$/.test(value); + const raw = process.env.SUBJECT_MANIFEST || ''; + if (Buffer.byteLength(raw, 'utf8') > MAX_MANIFEST_BYTES) fail('Candidate manifest exceeds the bounded protocol'); + const subject = JSON.parse(raw); + const canonical = value => { + if (value === null || typeof value !== 'object') return JSON.stringify(value); + if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`; + return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`; + }; + if (subject.schema !== 1 || subject.protocol !== 'integration-prefix-v1' || + subject.engine !== 'hive' || !digest(subject.id) || + subject.repo !== `${context.repo.owner}/${context.repo.repo}` || + !sha(subject.baseSHA) || !digest(subject.policy) || + !sha(subject.workflowTree) || !Number.isSafeInteger(subject.generation) || + subject.generation < 1 || typeof subject.base !== 'string' || !subject.base.length) { + fail('Invalid integration subject identity; no candidate jobs admitted'); + } + const {id, generation, preparedBy, dispatchClaim, ...immutable} = subject; + if (crypto.createHash('sha256').update(canonical(immutable)).digest('hex') !== id) { + fail('Subject ID does not bind its exact immutable membership, commits, trees and policy'); + } + const claimKey = crypto.createHash('sha256').update(`integration-ci-initial-v1/${subject.id}`).digest('hex'); + if (!dispatchClaim || dispatchClaim.state !== 'claimed' || + dispatchClaim.key !== claimKey || dispatchClaim.ref !== `heads/hive-integration-intents/${claimKey}` || + !sha(dispatchClaim.commit) || !dispatchClaim.owner || + typeof dispatchClaim.owner.nonce !== 'string' || !/^[a-f0-9]{32}$/.test(dispatchClaim.owner.nonce) || + !/^[1-9][0-9]*$/.test(dispatchClaim.owner.runID) || !/^[1-9][0-9]*$/.test(dispatchClaim.owner.attempt)) { + fail('Candidate has no exact shared single-attempt dispatch owner'); + } + if (context.eventName !== 'workflow_dispatch' || + context.ref !== `refs/tags/hive-integration/${subject.id}` || + !Array.isArray(subject.members) || !Array.isArray(subject.prefixes) || + subject.members.length < 1 || subject.members.length > MAX_CANDIDATE_MEMBERS || + subject.members.length !== subject.prefixes.length) { + fail('Candidate dispatch/ref or bounded ordered membership mismatch'); + } + const numbers = new Set(); + const heads = new Set(); + const variables = {owner: context.repo.owner, name: context.repo.repo, + claimRef: `refs/${dispatchClaim.ref}`}; + const declarations = ['$owner:String!', '$name:String!', '$policy:String!', '$claimRef:String!']; + const objects = []; + for (let i = 0; i < subject.members.length; i++) { + const member = subject.members[i], prefix = subject.prefixes[i]; + if (!member || !Number.isSafeInteger(member.pr) || member.pr < 1 || + numbers.has(member.pr) || heads.has(member.head) || !sha(member.head) || + !prefix || !sha(prefix.commit) || !sha(prefix.tree)) { + fail('Invalid or duplicate ordered candidate member'); } - const {id, generation, preparedBy, dispatchClaim, ...immutable} = subject; - if (crypto.createHash('sha256').update(canonical(immutable)).digest('hex') !== id) { - fail('Subject ID does not bind its exact immutable membership, commits, trees and policy'); + numbers.add(member.pr); + heads.add(member.head); + declarations.push(`$prefix${i}:String!`); + variables[`prefix${i}`] = prefix.commit; + objects.push(`prefix${i}:object(expression:$prefix${i}){... on Commit{oid tree{oid} parents(first:${EXPECTED_PARENTS + 1}){nodes{oid}}}}`); + } + if (subject.prefixes.at(-1).commit !== context.sha) { + fail('Dispatch does not execute the actual tested candidate commit'); + } + variables.policy = `${context.sha}:.github`; + const query = `query(${declarations.join(',')}){repository(owner:$owner,name:$name){nameWithOwner claim:ref(qualifiedName:$claimRef){target{oid ... on Commit{message}}} policy:object(expression:$policy){... on Tree{oid}} ${objects.join(' ')}}}`; + const {repository} = await github.graphql(query, variables); + if (repository?.nameWithOwner !== subject.repo || repository.policy?.oid !== subject.workflowTree) { + fail('Repository or producer workflow closure changed'); + } + if (repository.claim?.target?.oid !== dispatchClaim.commit) { + fail('Shared dispatch authority changed or is unavailable; no TTL takeover'); + } + const records = (repository.claim.target.message || '').split('\n').filter(line => line.startsWith('{')); + if (records.length !== 1) fail('Shared dispatch authority record is malformed'); + const owner = JSON.parse(records[0]); + if (owner.schema !== 1 || owner.kind !== 'integration-ci-single-attempt-v1' || + owner.key !== claimKey || owner.subjectID !== subject.id || + owner.owner?.nonce !== dispatchClaim.owner.nonce || + owner.owner?.runID !== dispatchClaim.owner.runID || + owner.owner?.attempt !== dispatchClaim.owner.attempt) { + fail('Shared dispatch owner does not match the candidate execution'); + } + let parent = subject.baseSHA; + for (let i = 0; i < subject.members.length; i++) { + const actual = repository[`prefix${i}`], expected = subject.prefixes[i]; + const parents = actual?.parents?.nodes; + if (actual?.oid !== expected.commit || actual.tree?.oid !== expected.tree || + !Array.isArray(parents) || parents.length !== EXPECTED_PARENTS || + parents[0].oid !== parent || parents[1].oid !== subject.members[i].head) { + fail(`Candidate prefix ${i + 1} is not its exact ordered two-parent subject`); } - const claimKey = crypto.createHash('sha256').update(`integration-ci-initial-v1/${subject.id}`).digest('hex'); - if (!dispatchClaim || dispatchClaim.state !== 'claimed' || - dispatchClaim.key !== claimKey || dispatchClaim.ref !== `heads/hive-integration-intents/${claimKey}` || - !sha(dispatchClaim.commit) || !dispatchClaim.owner || - typeof dispatchClaim.owner.nonce !== 'string' || !/^[a-f0-9]{32}$/.test(dispatchClaim.owner.nonce) || - !/^[1-9][0-9]*$/.test(dispatchClaim.owner.runID) || !/^[1-9][0-9]*$/.test(dispatchClaim.owner.attempt)) { - fail('Candidate has no exact shared single-attempt dispatch owner'); - } - if (context.eventName !== 'workflow_dispatch' || - context.ref !== `refs/tags/hive-integration/${subject.id}` || - !Array.isArray(subject.members) || !Array.isArray(subject.prefixes) || - subject.members.length < 1 || subject.members.length > MAX_CANDIDATE_MEMBERS || - subject.members.length !== subject.prefixes.length) { - fail('Candidate dispatch/ref or bounded ordered membership mismatch'); - } - const numbers = new Set(); - const heads = new Set(); - const variables = {owner: context.repo.owner, name: context.repo.repo, - claimRef: `refs/${dispatchClaim.ref}`}; - const declarations = ['$owner:String!', '$name:String!', '$policy:String!', '$claimRef:String!']; - const objects = []; - for (let i = 0; i < subject.members.length; i++) { - const member = subject.members[i], prefix = subject.prefixes[i]; - if (!member || !Number.isSafeInteger(member.pr) || member.pr < 1 || - numbers.has(member.pr) || heads.has(member.head) || !sha(member.head) || - !prefix || !sha(prefix.commit) || !sha(prefix.tree)) { - fail('Invalid or duplicate ordered candidate member'); - } - numbers.add(member.pr); - heads.add(member.head); - declarations.push(`$prefix${i}:String!`); - variables[`prefix${i}`] = prefix.commit; - objects.push(`prefix${i}:object(expression:$prefix${i}){... on Commit{oid tree{oid} parents(first:${EXPECTED_PARENTS + 1}){nodes{oid}}}}`); - } - if (subject.prefixes.at(-1).commit !== context.sha) { - fail('Dispatch does not execute the actual tested candidate commit'); - } - variables.policy = `${context.sha}:.github`; - const query = `query(${declarations.join(',')}){repository(owner:$owner,name:$name){nameWithOwner claim:ref(qualifiedName:$claimRef){target{oid ... on Commit{message}}} policy:object(expression:$policy){... on Tree{oid}} ${objects.join(' ')}}}`; - const {repository} = await github.graphql(query, variables); - if (repository?.nameWithOwner !== subject.repo || repository.policy?.oid !== subject.workflowTree) { - fail('Repository or producer workflow closure changed'); - } - if (repository.claim?.target?.oid !== dispatchClaim.commit) { - fail('Shared dispatch authority changed or is unavailable; no TTL takeover'); - } - const records = (repository.claim.target.message || '').split('\n').filter(line => line.startsWith('{')); - if (records.length !== 1) fail('Shared dispatch authority record is malformed'); - const owner = JSON.parse(records[0]); - if (owner.schema !== 1 || owner.kind !== 'integration-ci-single-attempt-v1' || - owner.key !== claimKey || owner.subjectID !== subject.id || - owner.owner?.nonce !== dispatchClaim.owner.nonce || - owner.owner?.runID !== dispatchClaim.owner.runID || - owner.owner?.attempt !== dispatchClaim.owner.attempt) { - fail('Shared dispatch owner does not match the candidate execution'); - } - let parent = subject.baseSHA; - for (let i = 0; i < subject.members.length; i++) { - const actual = repository[`prefix${i}`], expected = subject.prefixes[i]; - const parents = actual?.parents?.nodes; - if (actual?.oid !== expected.commit || actual.tree?.oid !== expected.tree || - !Array.isArray(parents) || parents.length !== EXPECTED_PARENTS || - parents[0].oid !== parent || parents[1].oid !== subject.members[i].head) { - fail(`Candidate prefix ${i + 1} is not its exact ordered two-parent subject`); - } - parent = actual.oid; - } - core.info(`Validated immutable subject ${subject.id}; this is not promotion authorization.`); - core.info(`Manifest SHA256 ${crypto.createHash('sha256').update(raw).digest('hex')}`); - - ci: - needs: subject - permissions: - contents: read - uses: ./.github/workflows/integration-technical-v2-ci.yml - - tests: - needs: subject - permissions: - contents: read - uses: ./.github/workflows/integration-technical-v2-tests.yml - - security: - needs: subject - permissions: - contents: read - uses: ./.github/workflows/integration-technical-go-security-analysis.yml - + parent = actual.oid; + } + core.info(`Validated immutable subject ${subject.id}; this is not promotion authorization.`); + core.info(`Manifest SHA256 ${crypto.createHash('sha256').update(raw).digest('hex')}`); + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Bind exact current member governance metadata + id: metadata + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + with: + script: | + const {snapshot, digest} = require('./.github/scripts/integration-governance.cjs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + core.setOutput('metadata_digest', digest(await snapshot(github, subject))); + ci-required-context-scope: + name: required context scope + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + run-ci: ${{ steps.scope.outputs.run-ci }} + steps: + - name: Decide whether build-and-test needs the real CI lane + id: scope + env: + GITHUB_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + set -euo pipefail + if [ "${{ true }}" = true ] && + { [ "$GITHUB_EVENT_NAME" != workflow_dispatch ] || [[ "$GITHUB_REF" != refs/tags/hive-integration/* ]]; }; then + echo "::error::Integration candidates require an explicitly dispatched immutable candidate tag" + exit 1 + fi + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo "run-ci=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + : > changed-files.txt + page=1 + api_root="${GITHUB_API_URL:-https://api.github.com}" + while :; do + curl -fsSL -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" "${api_root}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?per_page=100&page=${page}" -o changed-files-page.json + python3 - <<'PYFILES' >> changed-files.txt + import json + with open('changed-files-page.json', encoding='utf-8') as f: + for item in json.load(f): + print(item['filename']) + PYFILES + count=$(python3 - <<'PYCOUNT' + import json + with open('changed-files-page.json', encoding='utf-8') as f: + print(len(json.load(f))) + PYCOUNT + ) + [ "$count" -lt 100 ] && break + page=$((page + 1)) + done + rm -f changed-files-page.json + run=false + while IFS= read -r path; do + case "$path" in + CHANGELOG.md|changelog.d/*|src/*|bin/*|config/*|README.md|docs/*|.github/scripts/*|.github/workflows/*) + run=true + ;; + esac + done < changed-files.txt + echo "run-ci=${run}" >> "$GITHUB_OUTPUT" + if [ "$run" = true ]; then + echo "v2 build-and-test will run." + else + echo "No v2 CI paths changed; build-and-test will be reported as skipped/success." + fi + needs: + - subject + if: ${{ always() && needs.subject.result == 'success' && (success()) }} + env: + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + ci-build-and-test: + needs: + - subject + - ci-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.ci-required-context-scope.result != 'success' || needs.ci-required-context-scope.outputs.run-ci == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + runs-on: ubuntu-latest + timeout-minutes: 50 + defaults: + run: + working-directory: src + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Ensure PyYAML on self-hosted runners + working-directory: . + run: | + python3 -c "import yaml" 2>/dev/null && exit 0 + # A stale or unreachable third-party apt index (e.g. a PPA 503) must not block the install. + sudo apt-get update -qq || true + sudo apt-get install -y -qq python3-yaml && exit 0 + # Noble (Python 3.12) refuses --user installs under PEP 668 without --break-system-packages. + python3 -m pip install --user -q --break-system-packages pyyaml \ + || { curl -sS https://bootstrap.pypa.io/get-pip.py | python3 - --user -q --break-system-packages && python3 -m pip install --user -q --break-system-packages pyyaml; } + - name: Check readonly candidate CI generation + working-directory: . + run: | + python3 .github/scripts/generate-integration-ci.py --check + python3 .github/scripts/test-generate-integration-ci.py + - name: Warm shared Go tool cache (serialize the cold-cache population) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + uses: ./.github/actions/go-mod-download-retry + - name: Restore warm Go build cache + if: ${{ !contains('["ubuntu-latest"]', 'hive-runners') }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: ~/.cache/go-build + key: hive-go-build-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }} + restore-keys: | + hive-go-build-${{ runner.os }}-${{ runner.arch }}- + - name: Build + run: go build ./cmd/hive/ + - name: Build crux (root host and standalone module) + run: | + go build -o /dev/null ./cmd/crux + (cd crux && GOWORK=off go build -o /dev/null ./cmd/crux) + - name: Crux module smoke (crux serve over a unix socket) + working-directory: src/crux + run: GOWORK=off bash scripts/smoke.sh + - name: CI install tool apt cache tests + working-directory: . + run: bash .github/scripts/test-ci-install-tool-apt-cache.sh + - name: Go cache guard tests + working-directory: . + run: bash .github/scripts/test-go-cache-guard.sh + - name: Go tool cache guard tests + working-directory: . + run: bash .github/scripts/test-go-toolcache-guard.sh + - name: Runner cache prune tests + working-directory: . + run: python3 .github/scripts/test-runner-cache-prune.py + - name: Patch coverage script tests + working-directory: . + run: bash .github/scripts/test-patch-coverage.sh + - name: CI infra classifier tests + working-directory: . + run: python3 .github/scripts/test-ci-infra.py + - name: Vet + run: go vet ./... ./crux/... + - name: Price table staleness guard + run: go run ./internal/tools/pricetable --check-age 60 + - name: Entrypoint runtime-config migration tests + run: bash deploy/test_entrypoint_runtime_config.sh + - name: Entrypoint NET_ADMIN ambient-cap tests (#3760) + run: bash deploy/test_entrypoint_netadmin_ambient.sh + - name: Entrypoint dangling key_file tests (#4368) + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash deploy/test_entrypoint_dangling_keyfile.sh + - name: Entrypoint standalone terminal-key fallback tests (#6489) + run: bash deploy/test_entrypoint_terminal_key_fallback.sh + - name: Entrypoint /data ownership invariant (#5369) + run: bash deploy/test_entrypoint_data_ownership.sh + - name: Entrypoint UID-isolation migration (#5525) + run: bash deploy/test_entrypoint_uid_isolation.sh + - name: Entrypoint stable agent UID allocation (#9592) + run: bash deploy/test_entrypoint_uid_stable.sh + - name: Entrypoint replica agent names (#13166) + run: bash deploy/test_entrypoint_replica_names.sh + - name: Entrypoint token-access audit log not agent-writable (#6287) + run: bash deploy/test_entrypoint_token_access_audit.sh + - name: arm64 lane probes PR code, not the published image (#5370) + run: bash deploy/test_arm64_lane_probes_pr_code.sh + - name: PR Verifier reports on the PR, not on registry reachability (#6085) + run: bash deploy/test_pr_verifier_advisory.sh + - name: Supply-chain pin guard + run: bash deploy/test_supply_chain_pins.sh + - name: Docker release-tag publication policy (#4804) + run: bash scripts/test-publish-image-tags.sh + - name: Stable soak promotion policy (#5974) + run: bash scripts/test-promote-stable.sh + - name: Issue co-author trailer helper (#6588) + run: bash scripts/test-issue-coauthor.sh + - name: Issue confirm-fixed command (#9746) + run: bash scripts/test-issue-confirm-fixed.sh + - name: Release push retry/deferral state machine (#5142) + run: bash scripts/test-release-push-retry.sh + - name: release_sha ancestry guard (#6419) + run: bash scripts/test-check-release-sha-ancestry.sh + - name: Changelog fragment compiler properties (#5675) + run: bash scripts/test-compile-changelog.sh + - name: Release notes extraction fallback (#5934) + run: bash scripts/test-extract-release-notes.sh + - name: Standalone image-reference source of truth (#4206) + run: bash deploy/test_standalone_image_refs.sh + - name: Docker-socket containment guard (#3865) + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash deploy/test_watchtower_socket_contract.sh + - name: Standalone service deployment contract (#4204) + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash deploy/test_standalone_service_contract.sh + - name: Quadlet published-port boundary (#4375) + run: bash deploy/test_quadlet_port_boundary.sh + - name: Quadlet config-coupling contract (#4367) + run: bash deploy/test_quadlet_config_contract.sh + - name: Documented Compose quick start contract (#4477) + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash deploy/test_compose_quickstart_contract.sh + - name: Docker/Podman contract parity (#4404) + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash deploy/test_standalone_runtime_parity.sh + - name: gh-wrapper gate tests + working-directory: . + run: bash bin/test_gh_wrapper_gates.sh + - name: go-wrapper gate tests + working-directory: . + run: bash bin/go-wrapper.test.sh + - name: enumerate-actionable contract tests + working-directory: . + run: bash bin/test_enumerate_actionable.sh + - name: issue-classifier contract tests (tiers, lanes, clustering) + working-directory: . + run: bash bin/test_issue_classifier.sh + - name: hive-gh compact projection contract tests + working-directory: . + run: bash bin/test_hive_gh.sh + - name: kick-governor contract tests + working-directory: . + run: bash bin/test_kick_governor.sh + - name: merge-gate contract tests + working-directory: . + run: bash bin/test_merge_gate.sh + - name: gh-rate-check contract tests + working-directory: . + run: bash bin/test_gh_rate_check.sh + - name: dibs cutover preflight contract (#5925) + working-directory: . + run: bash bin/test_dibs_cutover_preflight.sh + - name: dibs cutover verification contract (#5925) + working-directory: . + run: bash bin/test_dibs_cutover_verify.sh + - name: GA4 anomaly detector drop-arm contract (#6430) + working-directory: . + run: bash bin/test_ga4_anomaly_detector.sh + - name: git-credential-hive helper tests (#4289) + working-directory: . + run: bash bin/test_git_credential_hive.sh + - name: gh-auth native-install guard (#3842) + working-directory: . + run: bash bin/test_gh_auth_native_no_cat.sh + - name: agent shell token scrub (#4045) + working-directory: . + run: bash bin/test_agent_env_scrub.sh + - name: Standalone runtime selection contract (#4205) + working-directory: . + run: bash bin/test_hive_standalone_runtime.sh + - name: Podman preflight contract (#4207) + working-directory: . + run: bash bin/test_hive_podman_preflight.sh + - name: Podman ownership and cleanup contract (#4210) + working-directory: . + run: bash bin/test_hive_podman_cleanup.sh + - name: Podman teardown through the ownership contract (#4326) + working-directory: . + run: bash bin/test_hive_podman_teardown.sh + - name: Podman SELinux, mount, secret, and port preflight (#4209) + working-directory: . + run: bash bin/test_hive_podman_preflight_host.sh + - name: Podman subordinate-ID, graphroot, and network preflight (#4208) + working-directory: . + run: bash bin/test_hive_podman_preflight_ids.sh + - name: Podman Quadlet lifecycle probe (#4377) + working-directory: . + run: bash bin/test_hive_podman_lifecycle_probe.sh + - name: SELinux label reader is resolved, never assumed (#4490) + working-directory: . + run: bash src/deploy/test_selinux_label_reader.sh + - name: Podman one-command installer (#4470) + working-directory: . + run: bash bin/test_hive_podman_setup.sh + - name: hivectl contributor bootstrap (#8200) + working-directory: . + run: bash bin/test_hivectl_bootstrap.sh + - name: Podman Quadlet update and rollback (#4378) + working-directory: . + run: bash bin/test_hive_podman_update.sh + - name: gh-wrapper author-gate tests (#3072, + working-directory: . + run: bash bin/gh-wrapper.test.sh + - name: repo-toolchain manifest tests (#7925) + working-directory: . + run: bash bin/repo-toolchain.test.sh + - name: hive-open-issue helper tests + working-directory: . + run: bash bin/test_hive_open_issue.sh + - name: hive-open-pr helper tests + working-directory: . + run: bash bin/test_hive_open_pr.sh + - name: hive-review helper tests + working-directory: . + run: bash bin/test_hive_review.sh + - name: Shared CI baseline classifier tests + working-directory: . + run: bash bin/test_hive_baseline_check.sh + - name: Every bin/ test suite is wired into something (#4363) + working-directory: . + run: bash bin/test_bin_suites_wired.sh + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + with: + node-version: '22' + - name: Guard shared node tool cache (repair a half-written entry) + if: ${{ always() }} + run: | + set -u + command -v npm >/dev/null 2>&1 && exit 0 + for marker in "${RUNNER_TOOL_CACHE:-/nonexistent}"/node/*/x64.complete; do + [ -e "$marker" ] || continue + dir="${marker%.complete}" + [ -x "$dir/bin/npm" ] && continue + echo "::warning::node tool cache $dir has a .complete marker but no executable bin/npm; removing the marker so the next job on $RUNNER_NAME rebuilds it" + rm -f "$marker" + done + echo "::error::npm is not on PATH after actions/setup-node on $RUNNER_NAME (half-written shared tool cache, see #10518); marker removed, re-run this job" + exit 1 + - name: Proxy Tests + run: cd proxy && npm ci && npm test + - name: Dashboard helper tests + working-directory: . + run: node --test src/pkg/dashboard/*.test.js + - name: Commons web page tests + working-directory: . + run: node --test src/pkg/hivectl/commands/*.test.js + - name: Integration candidate materializer contracts + working-directory: . + run: node --test .github/scripts/integration-*.test.cjs + - name: Contributor Relay Syntax + Tests + working-directory: . + run: | + bash bin/contributor-agent.test.sh + node --check bin/contributor-relay.js + node --check bin/lib/pane-classifier.js + bash -n bin/contributor-relay.sh + node bin/contributor-relay.test.js + node --test bin/mlx-backend.test.js + - name: vibe-kanban mirror tests + working-directory: . + run: | + node --check bin/vibe-kanban-mirror.js + node bin/vibe-kanban-mirror.test.js + - name: Backend smoke failure-issue attribution + working-directory: . + run: bash bin/test_backend_smoke_attribution.sh + - name: Backend smoke pins this repository's contributor image + working-directory: . + run: bash bin/test_backend_smoke_image_owner.sh + - name: Backend smoke (keyless subset) + working-directory: . + run: bash bin/test_backend_smoke.sh + - name: Install just + run: | + set -euo pipefail + JUST_VERSION=1.58.0 + JUST_SHA256=4a5cc2f53e6f0f8c59092a6cc38291eb729d46a7dd95d3ae582008881b84931d + curl -fsSL -o /tmp/just.tgz "https://github.com/casey/just/releases/download/${JUST_VERSION}/just-${JUST_VERSION}-x86_64-unknown-linux-musl.tar.gz" + echo "${JUST_SHA256} /tmp/just.tgz" | sha256sum -c - + tar -xzf /tmp/just.tgz -C /tmp just + sudo install -m 0755 /tmp/just /usr/local/bin/just + just --version + - name: Contributor K8s Workload Generation + working-directory: . + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash src/deploy/test_contribute_k8s_workload.sh + - name: Terminal scrollback legibility (#4399) + working-directory: . + run: bash src/deploy/test_terminal_scrollback_status.sh + - name: ttyd keeps --url-arg when credentialed (#4593) + working-directory: . + run: bash src/deploy/test_ttyd_url_arg.sh + - name: ttyd finds the default tmux socket under an arbitrary container UID + working-directory: . + run: bash src/deploy/test_ttyd_default_socket_uid.sh + - name: hive-discord.service does not execute planted code (#5435) + working-directory: . + run: bash src/deploy/test_hive_discord_unit_contract.sh + - name: hive-snapshot.service does not execute planted code (#5483) + working-directory: . + run: bash src/deploy/test_hive_snapshot_unit_contract.sh + - name: hive-deploy.service does not root-install planted code (#5936) + working-directory: . + run: bash src/deploy/test_hive_deploy_unit_contract.sh + - name: Changelog reminder never blocks a merge (#4440) + working-directory: . + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash src/deploy/test_changelog_reminder.sh + - name: Contributor identity relocation (#4408) + working-directory: . + run: bash src/deploy/test_contribute_move.sh + - name: In-container attach hints name the real runtime (#5145) + working-directory: . + run: bash src/deploy/test_attach_hint_runtime.sh + - name: Isolated contributor Compose contract (#9188) + working-directory: . + run: | + # hive-runners lack python3-venv (ensurepip); the job's first step + # already guarantees PyYAML for the system python3, so fall back to it. + if python3 -m venv "$RUNNER_TEMP/isolated-contributor-tests" 2>/dev/null; then + "$RUNNER_TEMP/isolated-contributor-tests/bin/pip" install PyYAML==6.0.2 + PY="$RUNNER_TEMP/isolated-contributor-tests/bin/python" + else + python3 -c "import yaml" + PY=python3 + fi + "$PY" src/deploy/test_isolated_contributor_compose.py + - name: Contributor containers enforce resource limits (#6485) + working-directory: . + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash src/deploy/test_contributor_container_resources.sh + - name: Contributor containers stage only the Claude credential and settings (#7836) + working-directory: . + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash src/deploy/test_contributor_claude_staging.sh + - name: A skip is fatal where the caller guarantees the precondition (#5388) + working-directory: . + run: bash src/deploy/test_skip_discipline.sh + - name: Entrypoint system gitconfig contract + working-directory: . + env: + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: bash src/deploy/test_entrypoint_system_gitconfig.sh + - name: Entrypoint Copilot token symlink contract (#5529) + working-directory: . + run: bash src/deploy/test_entrypoint_symlinks.sh + - name: Entrypoint permission-guard survivability (#5730) + working-directory: . + run: bash src/deploy/test_entrypoint_perm_guard.sh + - name: hivectl extraction route contract (#5646) + working-directory: . + run: bash src/deploy/test_hivectl_extraction_contract.sh + - name: Entrypoint iptables append failure handling (#6003) + working-directory: . + run: bash src/deploy/test_entrypoint_iptables_gate.sh + - name: Entrypoint egress ruleset result checks (#6003) + working-directory: . + run: bash src/deploy/test_entrypoint_egress_ruleset.sh + - name: Entrypoint netfilter extension preflight (#6003) + working-directory: . + run: bash src/deploy/test_entrypoint_xt_module_preflight.sh + - name: Every src/deploy/ test suite is wired into a workflow (#5529) + working-directory: . + run: bash src/deploy/test_deploy_suites_wired.sh + - name: Runner labels are fork-portable (#6083) + working-directory: . + run: bash src/deploy/test_runner_labels_portable.sh + name: build-and-test + env: + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + ci-docker: + name: docker (${{ matrix.name }}) + needs: + - subject + - ci-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.ci-required-context-scope.result != 'success' || needs.ci-required-context-scope.outputs.run-ci == 'true')) }} + runs-on: ubuntu-latest + timeout-minutes: 45 + strategy: + fail-fast: false + matrix: + include: + - name: hive + file: src/Dockerfile + smoke: 'true' + - name: hub + file: src/Dockerfile.hub + smoke: 'false' + - name: contributor + file: src/Dockerfile.contributor + smoke: 'false' + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + fetch-depth: ${{ matrix.name == 'hub' && 0 || 1 }} + - name: Skip non-hive images on push + if: '!true && github.event_name != ''pull_request'' && matrix.name != ''hive''' + run: echo "skip=true" >> "$GITHUB_ENV" + - name: Set up Docker Buildx + if: env.skip != 'true' + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 + with: + driver-opts: network=host + - name: Resolve base image registry (mirror.gcr.io with docker.io fallback) + if: env.skip != 'true' + uses: ./.github/actions/docker-base-registry + - name: Build Docker image + if: env.skip != 'true' + run: docker buildx build --load --network host --build-arg BASE_REGISTRY="$BASE_REGISTRY" -f "${{ matrix.file }}" -t "hive-ci-${{ matrix.name }}:test" . + - name: Smoke test + if: env.skip != 'true' && matrix.smoke == 'true' + shell: bash + run: "set -euo pipefail\nname=\"hive-v2-ci-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}\"\ncleanup() {\n docker rm -f -v \"$name\" >/dev/null 2>&1 || true\n}\ntrap cleanup EXIT\n# #3760: the binary carries NO file capability anymore, so it must exec\n# under docker's DEFAULT cap set (no --cap-add) \u2014 a self-hosted spoke\n# has exactly that bounding set. NET_ADMIN, when present, is raised by\n# the entrypoint as an ambient cap; the raw `--version` here needs none.\n# The old `--help || true` form could not fail and asserted nothing.\ntimeout --signal=TERM --kill-after=10s 60s \\\n docker run --rm --name \"$name\" --network none hive-ci-hive:test --version\n" + env: + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + ci-overlayfs-exec-guard: + needs: + - subject + - ci-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.ci-required-context-scope.result != 'success' || needs.ci-required-context-scope.outputs.run-ci == 'true')) }} + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 + - name: Resolve runner ref name + id: ref_name + run: | + set -euo pipefail + : "${GITHUB_REF_NAME:?GITHUB_REF_NAME is required}" + echo "value=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT" + - name: Resolve base image registry (mirror.gcr.io with docker.io fallback) + uses: ./.github/actions/docker-base-registry + - name: Build image via buildx (OCI archive, no attestations) + uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc + with: + context: . + file: src/Dockerfile + platforms: linux/amd64 + provenance: false + sbom: false + outputs: type=oci,oci-mediatypes=true,dest=/tmp/hive-oci.tar,tar=true + cache-from: type=gha,scope=tmux-linux-amd64 + build-args: | + BASE_REGISTRY=${{ env.BASE_REGISTRY }} + GIT_HASH=${{ github.sha }} + GIT_BRANCH=${{ steps.ref_name.outputs.value }} + - name: Run under containerd/overlayfs and assert in-place exec + shell: bash + run: "set -euo pipefail\n# containerd ships on GitHub ubuntu runners; ensure it is up and using\n# the overlayfs snapshotter (its default) \u2014 that is what makes the\n# metacopy redirect observable.\nsudo systemctl start containerd 2>/dev/null || sudo containerd >/tmp/containerd.log 2>&1 &\nfor i in $(seq 1 30); do\n if sudo ctr version >/dev/null 2>&1; then break; fi\n sleep 1\ndone\nsudo ctr version\n# Confirm the overlayfs snapshotter is present (the failing runtime).\nsudo ctr plugins ls | grep -i overlayfs || {\n echo \"overlayfs snapshotter not available on this runner\" >&2; exit 1; }\n\nIMG=\"hive-3760-guard:test\"\n# Import the OCI archive BuildKit produced into containerd. Resolve\n# the linux/amd64 platform (the archive is single-arch, but pin it so\n# the run below has a concrete manifest to unpack).\nsudo ctr images import --platform linux/amd64 --index-name \"$IMG\" /tmp/hive-oci.tar \\\n || sudo ctr images import --index-name \"$IMG\" /tmp/hive-oci.tar\nsudo ctr images ls | grep \"$IMG\"\n\n# The assertion: exec /usr/local/bin/hive AT ITS IMAGE PATH, no copy,\n# under containerd's overlayfs snapshotter. --net-host keeps the run\n# simple; we deliberately do NOT add NET_ADMIN \u2014 a self-hosted spoke\n# has the docker/containerd default bounding set. Override the\n# entrypoint so we test the raw binary exec (the #3760 symptom is a\n# bare EPERM at execve of the binary, not an entrypoint failure).\nset +e\nout=$(sudo timeout 90s ctr run --rm --snapshotter overlayfs \\\n --net-host \\\n \"$IMG\" hive-3760-inplace \\\n /usr/local/bin/hive --version 2>&1)\nrc=$?\nset -e\necho \"----- hive --version (in-place, containerd/overlayfs) -----\"\necho \"$out\"\necho \"exit=$rc\"\nif [ $rc -ne 0 ]; then\n echo \"::error::#3760 regression: /usr/local/bin/hive failed to exec IN PLACE under containerd/overlayfs (rc=$rc). This is the BuildKit metacopy-redirect crash-loop \u2014 a plain build-side attestation/OCI-index change or a removed in-stage binary rewrite has reintroduced it.\" >&2\n exit 1\nfi\ncase \"$out\" in\n *\"Operation not permitted\"*|*EPERM*)\n echo \"::error::#3760 regression: hive execve returned Operation not permitted at its image path under containerd/overlayfs.\" >&2\n exit 1 ;;\nesac\n\n# STALE-BINARY GUARD. The exec check above passes even for an OLD hive\n# binary \u2014 a stale binary works fine, it just reports the WRONG commit.\n# A branch-persistent GHA cache once let BuildKit serve a cached\n# final-stage `COPY --from=builder /hive` layer, so the manifest digest\n# advanced but /usr/local/bin/hive was an old build (reported commit\n# 4d9c11c while HEAD had the #3760 fix). Assert the built binary's\n# embedded commit matches THIS build's commit so a stale-layer cache hit\n# is caught directly, not just an exec failure. `hive --version` prints\n# `hive 3.0.0 (commit , branch )`; main.gitShort is the\n# 7-char short SHA stamped from GIT_HASH=${{ github.sha }} at build.\nEXPECTED_SHORT=\"${GITHUB_SHA::7}\"\nREPORTED_COMMIT=$(printf '%s\\n' \"$out\" | sed -n 's/.*commit \\([0-9a-f][0-9a-f]*\\).*/\\1/p' | head -n1)\necho \"expected commit=$EXPECTED_SHORT reported commit=$REPORTED_COMMIT\"\nif [ -z \"$REPORTED_COMMIT\" ]; then\n echo \"::error::stale-binary guard: could not parse commit from 'hive --version' output \u2014 version stamping is broken or the output format changed.\" >&2\n exit 1\nfi\nif [ \"$REPORTED_COMMIT\" != \"$EXPECTED_SHORT\" ]; then\n echo \"::error::stale-binary guard: shipped hive reports commit '$REPORTED_COMMIT' but this build is '$EXPECTED_SHORT'. The binary is STALE \u2014 a cached final-stage COPY --from=builder layer shipped an old /usr/local/bin/hive (the bug that let #3760's fix miss the published image). Check no-cache-filters covers the runtime stage in docker.yml.\" >&2\n exit 1\nfi\necho \"OK: hive execs in-place under containerd/overlayfs (no copy, no NET_ADMIN) AND reports the current commit ($REPORTED_COMMIT).\"\n" + name: overlayfs-exec-guard + env: + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-required-context-scope: + name: required context scope + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + run-tests: ${{ steps.scope.outputs.run-tests }} + steps: + - name: Decide whether the test and coverage gates need the real suite + id: scope + env: + GITHUB_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + set -euo pipefail + if [ "${{ true }}" = true ] && + { [ "$GITHUB_EVENT_NAME" != workflow_dispatch ] || [[ "$GITHUB_REF" != refs/tags/hive-integration/* ]]; }; then + echo "::error::Integration candidates require an explicitly dispatched immutable candidate tag" + exit 1 + fi + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo "run-tests=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + : > changed-files.txt + page=1 + api_root="${GITHUB_API_URL:-https://api.github.com}" + while :; do + curl -fsSL -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" "${api_root}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?per_page=100&page=${page}" -o changed-files-page.json + python3 - <<'PYFILES' >> changed-files.txt + import json + with open('changed-files-page.json', encoding='utf-8') as f: + for item in json.load(f): + print(item['filename']) + PYFILES + count=$(python3 - <<'PYCOUNT' + import json + with open('changed-files-page.json', encoding='utf-8') as f: + print(len(json.load(f))) + PYCOUNT + ) + [ "$count" -lt 100 ] && break + page=$((page + 1)) + done + rm -f changed-files-page.json + run=false + while IFS= read -r path; do + case "$path" in + src/*|bin/*|config/*|Justfile|dashboard/openapi.json|CHANGELOG.md|changelog.d/*|.github/workflows/*|.github/scripts/*) + run=true + ;; + esac + done < changed-files.txt + echo "run-tests=${run}" >> "$GITHUB_OUTPUT" + if [ "$run" = true ]; then + echo "v2 test/coverage gates will run real shards." + else + echo "No v2 test paths changed; required test/coverage contexts will report success without shards." + fi + needs: + - subject + if: ${{ always() && needs.subject.result == 'success' && (success()) }} + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-test-hub: + needs: + - subject + - tests-required-context-scope + - tests-list-packages + if: ${{ always() && needs.subject.result == 'success' && ((needs.tests-required-context-scope.result != 'success' || needs.tests-required-context-scope.outputs.run-tests == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: test (hub ${{ matrix.idx }}/4) + strategy: + fail-fast: false + matrix: + idx: + - 1 + - 2 + - 3 + - 4 + runs-on: ubuntu-latest + timeout-minutes: 20 + defaults: + run: + working-directory: src + steps: + - name: Affected-package selection + id: select + working-directory: . + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + RUN_LANE: ${{ needs.tests-list-packages.outputs.run-hub }} + run: | + if [ "$SELECTION" = partial ] && [ "$RUN_LANE" = false ]; then + echo "Affected-package selection: pkg/hub is not affected by this diff; reporting success without running tests. Push and scheduled runs test it in full." + echo "run=false" >> "$GITHUB_OUTPUT" + else + echo "run=true" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + if: steps.select.outputs.run == 'true' + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + if: steps.select.outputs.run == 'true' + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + if: steps.select.outputs.run == 'true' + uses: ./.github/actions/go-mod-download-retry + - name: Install gotestsum + if: steps.select.outputs.run == 'true' + run: | + echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH" + go install gotest.tools/gotestsum@v1.13.0 + "$(go env GOPATH)/bin/gotestsum" --version + - name: Restore warm Go build cache + if: ${{ steps.select.outputs.run == 'true' && (!contains('["ubuntu-latest"]', 'hive-runners')) }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: ~/.cache/go-build + key: hive-go-build-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }} + restore-keys: | + hive-go-build-${{ runner.os }}-${{ runner.arch }}- + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + if: steps.select.outputs.run == 'true' + with: + node-version: '22' + - name: Guard shared node tool cache (repair a half-written entry) + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: | + set -u + command -v npm >/dev/null 2>&1 && exit 0 + for marker in "${RUNNER_TOOL_CACHE:-/nonexistent}"/node/*/x64.complete; do + [ -e "$marker" ] || continue + dir="${marker%.complete}" + [ -x "$dir/bin/npm" ] && continue + echo "::warning::node tool cache $dir has a .complete marker but no executable bin/npm; removing the marker so the next job on $RUNNER_NAME rebuilds it" + rm -f "$marker" + done + echo "::error::npm is not on PATH after actions/setup-node on $RUNNER_NAME (half-written shared tool cache, see #10518); marker removed, re-run this job" + exit 1 + - name: Restore cgo toolchain package cache + if: steps.select.outputs.run == 'true' + id: restore-cgo-apt-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + restore-keys: | + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev- + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}- + hive-cgo-race-apt- + - name: Prepare cgo toolchain for race tests + if: steps.select.outputs.run == 'true' + id: prepare-cgo-toolchain + env: + HIVE_CI_APT_CACHE_DIR: ${{ github.workspace }}/.ci/apt-cache/cgo-race + HIVE_CI_MISSING_TOOLCHAIN_SOFT_FAIL: ${{ !true && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '1' || '0' }} + run: | + bash "$GITHUB_WORKSPACE/.github/scripts/ci-install-tool.sh" \ + --require gcc --for '-race tests' \ + --apt 'gcc libc6-dev' --apk 'gcc musl-dev' --verify 'gcc --version' + - name: Save cgo toolchain package cache + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.restore-cgo-apt-cache.outputs.cache-hit != 'true' && steps.prepare-cgo-toolchain.outputs.apt-cache-populated == 'true') }} + continue-on-error: true + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + - name: Test slice of pkg/hub + if: ${{ steps.select.outputs.run == 'true' && (steps.prepare-cgo-toolchain.outputs.toolchain-ready == 'true') }} + env: + IDX: ${{ matrix.idx }} + TOTAL: ${{ strategy.job-total }} + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: "set -o pipefail\nROOT=\"$PWD\"\nexport LC_ALL=C # Regex length guards below must count bytes.\nexport TEST_PACKAGE=github.com/hivecommons/hive/pkg/hub\nexport TEST_DIR=\"$ROOT/pkg/hub\"\nexport TEST_BINARY=\"$ROOT/hub.test\"\ngo test -c -race -cover -o \"$TEST_BINARY\" ./pkg/hub\n(cd \"$TEST_DIR\" && \"$TEST_BINARY\" -test.short -test.list '.*') | grep -E '^(Test|Example|Fuzz)' | LC_ALL=C sort > all-tests.txt\nif [ ! -s all-tests.txt ]; then\n echo \"::error::go test -list produced no test functions for pkg/hub \u2014 refusing to run an empty slice (fail closed)\"\n exit 1\nfi\nawk -v n=\"$TOTAL\" -v i=\"$IDX\" 'NR % n == i - 1' all-tests.txt > slice.txt\necho \"slice $IDX/$TOTAL: $(wc -l < slice.txt) of $(wc -l < all-tests.txt) test functions\"\nif [ ! -s slice.txt ]; then\n echo \"::error::empty hub slice \u2014 failing closed\"\n exit 1\nfi\nexport CHUNK_DIR TEST_SHUFFLE=off\nCHUNK_DIR=$(mktemp -d \"$ROOT/test-chunks.XXXXXX\")\nsplit -l 1000 slice.txt \"$CHUNK_DIR/chunk-\"\nif [ \"$GITHUB_EVENT_NAME\" != \"pull_request\" ]; then TEST_SHUFFLE=on; fi\n# raw-command preserves one JUnit/flake report across all chunks.\n# gotestsum appends -test.run and package arguments on reruns.\ncat > \"$CHUNK_DIR/run.sh\" <<'RUNNER'\n#!/usr/bin/env bash\nset -uo pipefail\ncd \"$TEST_DIR\" || exit 1\nrun_chunk() {\n local RUN=\"$1\" PROFILE=\"$2\"\n # MAX_ARG_STRLEN is 131072 bytes; never approach it, even if a\n # future test has an exceptionally long name. Guard before exec.\n if [ \"${#RUN}\" -gt 120000 ]; then\n echo \"::error::chunk regex exceeds 120000 bytes; reduce chunk size\" >&2\n return 1\n fi\n go tool test2json -t -p \"$TEST_PACKAGE\" \"$TEST_BINARY\" \\\n -test.short -test.count=1 -test.v=test2json -test.timeout=10m \\\n -test.shuffle=\"$TEST_SHUFFLE\" \"$RUN\" -test.coverprofile=\"$PROFILE\"\n}\nif [ \"$#\" -gt 0 ]; then\n # Reruns must not overwrite the first-pass coverage.\n run_chunk \"$1\" \"$CHUNK_DIR/rerun.out\"\n exit $?\nfi\nstatus=0\nfor chunk in \"$CHUNK_DIR\"/chunk-*; do\n RUN=\"-test.run=^($(paste -sd'|' \"$chunk\"))$\"\n run_chunk \"$RUN\" \"$chunk.out\" || status=1\ndone\nexit \"$status\"\nRUNNER\nstatus=0\nif gotestsum --format=standard-verbose --rerun-fails=2 --rerun-fails-max-failures=5 \\\n --rerun-fails-report=flaky-tests-hub-\"$IDX\".txt \\\n --junitfile junit-hub-\"$IDX\".xml --raw-command -- bash \"$CHUNK_DIR/run.sh\" \\\n 2>&1 | grep --line-buffered -vE '^=== (RUN|PAUSE|CONT) ' | tee test-hub-\"$IDX\".log; then\n :\nelse\n status=1\nfi\n# The test binary runs under test2json, not the `go test` driver, so\n# nothing prints the `ok ` / `FAIL ` summary line the\n# coverage scorer classifies packages by (#14135). Append it.\nif [ \"$status\" -eq 0 ]; then\n printf 'ok \\t%s\\t(slice %s/%s)\\n' \"$TEST_PACKAGE\" \"$IDX\" \"$TOTAL\" >> test-hub-\"$IDX\".log\nelse\n printf 'FAIL\\t%s\\t(slice %s/%s)\\n' \"$TEST_PACKAGE\" \"$IDX\" \"$TOTAL\" >> test-hub-\"$IDX\".log\nfi\n# Sum first-pass counters for identical blocks; never count reruns.\n# Do this even after test failure so the coverage gate has evidence.\nawk 'FNR == 1 { next } { key=$1 \" \" $2; hits[key]+=$3 }\n END { print \"mode: atomic\"; for (key in hits) print key, hits[key] }' \\\n \"$CHUNK_DIR\"/chunk-*.out > coverage-hub-\"$IDX\".out\nexit \"$status\"\n" + - name: Surface flaky reruns + id: flaky-reruns + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/ci-gotestsum-flake-summary.sh" "flaky-tests-hub-${{ matrix.idx }}.txt" "hub ${{ matrix.idx }}/4" + - name: Upload flaky rerun report + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.flaky-reruns.outputs.has-flakes == 'true') }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: flaky-tests-hub-${{ matrix.idx }} + path: src/flaky-tests-hub-${{ matrix.idx }}.txt + if-no-files-found: error + retention-days: 14 + - name: Slowest tests in this slice + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/slowest-tests.sh" "hub ${{ matrix.idx }}/4" test-hub-${{ matrix.idx }}.log + - name: Upload shard coverage artifacts + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: test-shard-hub-${{ matrix.idx }} + path: | + src/coverage-hub-${{ matrix.idx }}.out + src/test-hub-${{ matrix.idx }}.log + if-no-files-found: warn + retention-days: 1 + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-test-sliced: + needs: + - subject + - tests-required-context-scope + - tests-list-packages + if: ${{ always() && needs.subject.result == 'success' && ((needs.tests-required-context-scope.result != 'success' || needs.tests-required-context-scope.outputs.run-tests == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: test (${{ matrix.lane }} ${{ matrix.idx }}/${{ matrix.total }}) + strategy: + fail-fast: false + matrix: + include: + - lane: dashboard + pkg: pkg/dashboard + idx: 1 + total: 4 + - lane: dashboard + pkg: pkg/dashboard + idx: 2 + total: 4 + - lane: dashboard + pkg: pkg/dashboard + idx: 3 + total: 4 + - lane: dashboard + pkg: pkg/dashboard + idx: 4 + total: 4 + - lane: scheduler + pkg: pkg/scheduler + idx: 1 + total: 3 + - lane: scheduler + pkg: pkg/scheduler + idx: 2 + total: 3 + - lane: scheduler + pkg: pkg/scheduler + idx: 3 + total: 3 + runs-on: ubuntu-latest + timeout-minutes: 20 + defaults: + run: + working-directory: src + steps: + - name: Affected-package selection + id: select + working-directory: . + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + LANE: ${{ matrix.lane }} + PKG: ${{ matrix.pkg }} + RUN_DASHBOARD: ${{ needs.tests-list-packages.outputs.run-dashboard }} + RUN_SCHEDULER: ${{ needs.tests-list-packages.outputs.run-scheduler }} + run: | + case "$LANE" in + dashboard) RUN_LANE=$RUN_DASHBOARD ;; + scheduler) RUN_LANE=$RUN_SCHEDULER ;; + *) RUN_LANE=true ;; + esac + if [ "$SELECTION" = partial ] && [ "$RUN_LANE" = false ]; then + echo "Affected-package selection: $PKG is not affected by this diff; reporting success without running tests. Push and scheduled runs test it in full." + echo "run=false" >> "$GITHUB_OUTPUT" + else + echo "run=true" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + if: steps.select.outputs.run == 'true' + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + if: steps.select.outputs.run == 'true' + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + if: steps.select.outputs.run == 'true' + uses: ./.github/actions/go-mod-download-retry + - name: Install gotestsum + if: steps.select.outputs.run == 'true' + run: | + echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH" + go install gotest.tools/gotestsum@v1.13.0 + "$(go env GOPATH)/bin/gotestsum" --version + - name: Restore warm Go build cache + if: ${{ steps.select.outputs.run == 'true' && (!contains('["ubuntu-latest"]', 'hive-runners')) }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: ~/.cache/go-build + key: hive-go-build-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }} + restore-keys: | + hive-go-build-${{ runner.os }}-${{ runner.arch }}- + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + if: steps.select.outputs.run == 'true' + with: + node-version: '22' + - name: Guard shared node tool cache (repair a half-written entry) + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: | + set -u + command -v npm >/dev/null 2>&1 && exit 0 + for marker in "${RUNNER_TOOL_CACHE:-/nonexistent}"/node/*/x64.complete; do + [ -e "$marker" ] || continue + dir="${marker%.complete}" + [ -x "$dir/bin/npm" ] && continue + echo "::warning::node tool cache $dir has a .complete marker but no executable bin/npm; removing the marker so the next job on $RUNNER_NAME rebuilds it" + rm -f "$marker" + done + echo "::error::npm is not on PATH after actions/setup-node on $RUNNER_NAME (half-written shared tool cache, see #10518); marker removed, re-run this job" + exit 1 + - name: Restore cgo toolchain package cache + if: steps.select.outputs.run == 'true' + id: restore-cgo-apt-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + restore-keys: | + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev- + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}- + hive-cgo-race-apt- + - name: Prepare cgo toolchain for race tests + if: steps.select.outputs.run == 'true' + id: prepare-cgo-toolchain + env: + HIVE_CI_APT_CACHE_DIR: ${{ github.workspace }}/.ci/apt-cache/cgo-race + HIVE_CI_MISSING_TOOLCHAIN_SOFT_FAIL: ${{ !true && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '1' || '0' }} + run: | + bash "$GITHUB_WORKSPACE/.github/scripts/ci-install-tool.sh" \ + --require gcc --for '-race tests' \ + --apt 'gcc libc6-dev' --apk 'gcc musl-dev' --verify 'gcc --version' + - name: Save cgo toolchain package cache + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.restore-cgo-apt-cache.outputs.cache-hit != 'true' && steps.prepare-cgo-toolchain.outputs.apt-cache-populated == 'true') }} + continue-on-error: true + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + - name: Test slice of ${{ matrix.pkg }} + if: ${{ steps.select.outputs.run == 'true' && (steps.prepare-cgo-toolchain.outputs.toolchain-ready == 'true') }} + env: + IDX: ${{ matrix.idx }} + TOTAL: ${{ matrix.total }} + LANE: ${{ matrix.lane }} + PKG: ${{ matrix.pkg }} + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: "set -o pipefail\nROOT=\"$PWD\"\nexport LC_ALL=C # Regex length guards below must count bytes.\nexport TEST_PACKAGE=\"github.com/hivecommons/hive/$PKG\"\nexport TEST_DIR=\"$ROOT/$PKG\"\nexport TEST_BINARY=\"$ROOT/$LANE.test\"\ngo test -c -race -cover -o \"$TEST_BINARY\" \"./$PKG\"\n(cd \"$TEST_DIR\" && \"$TEST_BINARY\" -test.short -test.list '.*') | grep -E '^(Test|Example|Fuzz)' | LC_ALL=C sort > all-tests.txt\nif [ ! -s all-tests.txt ]; then\n echo \"::error::go test -list produced no test functions for $PKG \u2014 refusing to run an empty slice (fail closed)\"\n exit 1\nfi\nawk -v n=\"$TOTAL\" -v i=\"$IDX\" 'NR % n == i - 1' all-tests.txt > slice.txt\necho \"slice $IDX/$TOTAL: $(wc -l < slice.txt) of $(wc -l < all-tests.txt) test functions\"\nif [ ! -s slice.txt ]; then\n echo \"::error::empty $LANE slice \u2014 failing closed\"\n exit 1\nfi\nexport CHUNK_DIR TEST_SHUFFLE=off\nCHUNK_DIR=$(mktemp -d \"$ROOT/test-chunks.XXXXXX\")\nsplit -l 1000 slice.txt \"$CHUNK_DIR/chunk-\"\nif [ \"$GITHUB_EVENT_NAME\" != \"pull_request\" ]; then TEST_SHUFFLE=on; fi\n# raw-command preserves one JUnit/flake report across all chunks.\n# gotestsum appends -test.run and package arguments on reruns.\ncat > \"$CHUNK_DIR/run.sh\" <<'RUNNER'\n#!/usr/bin/env bash\nset -uo pipefail\ncd \"$TEST_DIR\" || exit 1\nrun_chunk() {\n local RUN=\"$1\" PROFILE=\"$2\"\n # MAX_ARG_STRLEN is 131072 bytes; never approach it, even if a\n # future test has an exceptionally long name. Guard before exec.\n if [ \"${#RUN}\" -gt 120000 ]; then\n echo \"::error::chunk regex exceeds 120000 bytes; reduce chunk size\" >&2\n return 1\n fi\n go tool test2json -t -p \"$TEST_PACKAGE\" \"$TEST_BINARY\" \\\n -test.short -test.count=1 -test.v=test2json -test.timeout=10m \\\n -test.shuffle=\"$TEST_SHUFFLE\" \"$RUN\" -test.coverprofile=\"$PROFILE\"\n}\nif [ \"$#\" -gt 0 ]; then\n # Reruns must not overwrite the first-pass coverage.\n run_chunk \"$1\" \"$CHUNK_DIR/rerun.out\"\n exit $?\nfi\nstatus=0\nfor chunk in \"$CHUNK_DIR\"/chunk-*; do\n RUN=\"-test.run=^($(paste -sd'|' \"$chunk\"))$\"\n run_chunk \"$RUN\" \"$chunk.out\" || status=1\ndone\nexit \"$status\"\nRUNNER\nstatus=0\nif gotestsum --format=standard-verbose --rerun-fails=2 --rerun-fails-max-failures=5 \\\n --rerun-fails-report=flaky-tests-\"$LANE\"-\"$IDX\".txt \\\n --junitfile junit-\"$LANE\"-\"$IDX\".xml --raw-command -- bash \"$CHUNK_DIR/run.sh\" \\\n 2>&1 | grep --line-buffered -vE '^=== (RUN|PAUSE|CONT) ' | tee test-\"$LANE\"-\"$IDX\".log; then\n :\nelse\n status=1\nfi\n# The test binary runs under test2json, not the `go test` driver, so\n# nothing prints the `ok ` / `FAIL ` summary line the\n# coverage scorer classifies packages by (#14135). Append it.\nif [ \"$status\" -eq 0 ]; then\n printf 'ok \\t%s\\t(slice %s/%s)\\n' \"$TEST_PACKAGE\" \"$IDX\" \"$TOTAL\" >> test-\"$LANE\"-\"$IDX\".log\nelse\n printf 'FAIL\\t%s\\t(slice %s/%s)\\n' \"$TEST_PACKAGE\" \"$IDX\" \"$TOTAL\" >> test-\"$LANE\"-\"$IDX\".log\nfi\n# Sum first-pass counters for identical blocks; never count reruns.\n# Do this even after test failure so the coverage gate has evidence.\nawk 'FNR == 1 { next } { key=$1 \" \" $2; hits[key]+=$3 }\n END { print \"mode: atomic\"; for (key in hits) print key, hits[key] }' \\\n \"$CHUNK_DIR\"/chunk-*.out > coverage-\"$LANE\"-\"$IDX\".out\nexit \"$status\"\n" + - name: Surface flaky reruns + id: flaky-reruns + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/ci-gotestsum-flake-summary.sh" "flaky-tests-${{ matrix.lane }}-${{ matrix.idx }}.txt" "${{ matrix.lane }} ${{ matrix.idx }}/${{ matrix.total }}" + - name: Upload flaky rerun report + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.flaky-reruns.outputs.has-flakes == 'true') }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: flaky-tests-${{ matrix.lane }}-${{ matrix.idx }} + path: src/flaky-tests-${{ matrix.lane }}-${{ matrix.idx }}.txt + if-no-files-found: error + retention-days: 14 + - name: Slowest tests in this slice + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/slowest-tests.sh" "${{ matrix.lane }} ${{ matrix.idx }}/${{ matrix.total }}" test-${{ matrix.lane }}-${{ matrix.idx }}.log + - name: Upload shard coverage artifacts + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: test-shard-${{ matrix.lane }}-${{ matrix.idx }} + path: | + src/coverage-${{ matrix.lane }}-${{ matrix.idx }}.out + src/test-${{ matrix.lane }}-${{ matrix.idx }}.log + if-no-files-found: warn + retention-days: 1 + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-test-agent: + needs: + - subject + - tests-required-context-scope + - tests-list-packages + if: ${{ always() && needs.subject.result == 'success' && ((needs.tests-required-context-scope.result != 'success' || needs.tests-required-context-scope.outputs.run-tests == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: test (agent ${{ matrix.idx }}/5) + strategy: + fail-fast: false + matrix: + idx: + - 1 + - 2 + - 3 + - 4 + - 5 + runs-on: ubuntu-latest + timeout-minutes: 25 + defaults: + run: + working-directory: src + steps: + - name: Affected-package selection + id: select + working-directory: . + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + RUN_LANE: ${{ needs.tests-list-packages.outputs.run-agent }} + run: | + if [ "$SELECTION" = partial ] && [ "$RUN_LANE" = false ]; then + echo "Affected-package selection: crux/agent is not affected by this diff; reporting success without running tests. Push and scheduled runs test it in full." + echo "run=false" >> "$GITHUB_OUTPUT" + else + echo "run=true" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + if: steps.select.outputs.run == 'true' + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + if: steps.select.outputs.run == 'true' + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + if: steps.select.outputs.run == 'true' + uses: ./.github/actions/go-mod-download-retry + - name: Install gotestsum + if: steps.select.outputs.run == 'true' + run: | + echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH" + go install gotest.tools/gotestsum@v1.13.0 + "$(go env GOPATH)/bin/gotestsum" --version + - name: Restore warm Go build cache + if: ${{ steps.select.outputs.run == 'true' && (!contains('["ubuntu-latest"]', 'hive-runners')) }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: ~/.cache/go-build + key: hive-go-build-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }} + restore-keys: | + hive-go-build-${{ runner.os }}-${{ runner.arch }}- + - name: Restore cgo toolchain package cache + if: steps.select.outputs.run == 'true' + id: restore-cgo-apt-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + restore-keys: | + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev- + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}- + hive-cgo-race-apt- + - name: Prepare cgo toolchain for race tests + if: steps.select.outputs.run == 'true' + id: prepare-cgo-toolchain + env: + HIVE_CI_APT_CACHE_DIR: ${{ github.workspace }}/.ci/apt-cache/cgo-race + HIVE_CI_MISSING_TOOLCHAIN_SOFT_FAIL: ${{ !true && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '1' || '0' }} + run: | + bash "$GITHUB_WORKSPACE/.github/scripts/ci-install-tool.sh" \ + --require gcc --for '-race tests' \ + --apt 'gcc libc6-dev' --apk 'gcc musl-dev' --verify 'gcc --version' + - name: Save cgo toolchain package cache + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.restore-cgo-apt-cache.outputs.cache-hit != 'true' && steps.prepare-cgo-toolchain.outputs.apt-cache-populated == 'true') }} + continue-on-error: true + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + - name: Install tmux (precondition for the behavioural gate) + if: ${{ steps.select.outputs.run == 'true' && (steps.prepare-cgo-toolchain.outputs.toolchain-ready == 'true') }} + run: | + bash "$GITHUB_WORKSPACE/.github/scripts/ci-install-tool.sh" \ + --require tmux --for 'the behavioural gate' \ + --apt tmux --apk tmux --verify 'tmux -V' + - name: Test slice of crux/agent + if: ${{ steps.select.outputs.run == 'true' && (steps.prepare-cgo-toolchain.outputs.toolchain-ready == 'true') }} + env: + IDX: ${{ matrix.idx }} + TOTAL: ${{ strategy.job-total }} + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: "set -o pipefail\nROOT=\"$PWD\"\nexport LC_ALL=C # Regex length guards below must count bytes.\nexport TEST_PACKAGE=github.com/hivecommons/hive/crux/agent\nexport TEST_DIR=\"$ROOT/crux/agent\"\nexport TEST_BINARY=\"$ROOT/agent.test\"\ngo test -c -race -cover -o \"$TEST_BINARY\" ./crux/agent\n# Include Test/Example/Fuzz, but not opt-in benchmarks.\n(cd \"$TEST_DIR\" && \"$TEST_BINARY\" -test.short -test.list '.*') | grep -E '^(Test|Example|Fuzz)' | LC_ALL=C sort > all-tests.txt\nif [ ! -s all-tests.txt ]; then\n echo \"::error::go test -list produced no test functions for crux/agent \u2014 refusing to run an empty slice (fail closed)\"\n exit 1\nfi\nawk -v n=\"$TOTAL\" -v i=\"$IDX\" 'NR % n == i - 1' all-tests.txt > slice.txt\necho \"slice $IDX/$TOTAL: $(wc -l < slice.txt) of $(wc -l < all-tests.txt) test functions\"\nif [ ! -s slice.txt ]; then\n echo \"::error::empty agent slice \u2014 failing closed\"\n exit 1\nfi\nexport CHUNK_DIR TEST_SHUFFLE=off\nCHUNK_DIR=$(mktemp -d \"$ROOT/test-chunks.XXXXXX\")\nsplit -l 1000 slice.txt \"$CHUNK_DIR/chunk-\"\nif [ \"$GITHUB_EVENT_NAME\" != \"pull_request\" ]; then TEST_SHUFFLE=on; fi\n# raw-command preserves one JUnit/flake report across all chunks.\n# gotestsum appends -test.run and package arguments on reruns.\ncat > \"$CHUNK_DIR/run.sh\" <<'RUNNER'\n#!/usr/bin/env bash\nset -uo pipefail\ncd \"$TEST_DIR\" || exit 1\nrun_chunk() {\n local RUN=\"$1\" PROFILE=\"$2\"\n # MAX_ARG_STRLEN is 131072 bytes; never approach it, even if a\n # future test has an exceptionally long name. Guard before exec.\n if [ \"${#RUN}\" -gt 120000 ]; then\n echo \"::error::chunk regex exceeds 120000 bytes; reduce chunk size\" >&2\n return 1\n fi\n go tool test2json -t -p \"$TEST_PACKAGE\" \"$TEST_BINARY\" \\\n -test.short -test.count=1 -test.v=test2json -test.timeout=10m \\\n -test.shuffle=\"$TEST_SHUFFLE\" \"$RUN\" -test.coverprofile=\"$PROFILE\"\n}\nif [ \"$#\" -gt 0 ]; then\n # Reruns must not overwrite the first-pass coverage.\n run_chunk \"$1\" \"$CHUNK_DIR/rerun.out\"\n exit $?\nfi\nstatus=0\nfor chunk in \"$CHUNK_DIR\"/chunk-*; do\n RUN=\"-test.run=^($(paste -sd'|' \"$chunk\"))$\"\n run_chunk \"$RUN\" \"$chunk.out\" || status=1\ndone\nexit \"$status\"\nRUNNER\nstatus=0\nif gotestsum --format=standard-verbose --rerun-fails=2 --rerun-fails-max-failures=5 \\\n --rerun-fails-report=flaky-tests-agent-\"$IDX\".txt \\\n --junitfile junit-agent-\"$IDX\".xml --raw-command -- bash \"$CHUNK_DIR/run.sh\" \\\n 2>&1 | grep --line-buffered -vE '^=== (RUN|PAUSE|CONT) ' | tee test-agent-\"$IDX\".log; then\n :\nelse\n status=1\nfi\n# The test binary runs under test2json, not the `go test` driver, so\n# nothing prints the `ok ` / `FAIL ` summary line the\n# coverage scorer classifies packages by (#14135). Append it.\nif [ \"$status\" -eq 0 ]; then\n printf 'ok \\t%s\\t(slice %s/%s)\\n' \"$TEST_PACKAGE\" \"$IDX\" \"$TOTAL\" >> test-agent-\"$IDX\".log\nelse\n printf 'FAIL\\t%s\\t(slice %s/%s)\\n' \"$TEST_PACKAGE\" \"$IDX\" \"$TOTAL\" >> test-agent-\"$IDX\".log\nfi\n# Sum first-pass counters for identical blocks; never count reruns.\n# Do this even after test failure so the coverage gate has evidence.\nawk 'FNR == 1 { next } { key=$1 \" \" $2; hits[key]+=$3 }\n END { print \"mode: atomic\"; for (key in hits) print key, hits[key] }' \\\n \"$CHUNK_DIR\"/chunk-*.out > coverage-agent-\"$IDX\".out\nexit \"$status\"\n" + - name: Surface flaky reruns + id: flaky-reruns + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/ci-gotestsum-flake-summary.sh" "flaky-tests-agent-${{ matrix.idx }}.txt" "agent ${{ matrix.idx }}/5" + - name: Upload flaky rerun report + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.flaky-reruns.outputs.has-flakes == 'true') }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: flaky-tests-agent-${{ matrix.idx }} + path: src/flaky-tests-agent-${{ matrix.idx }}.txt + if-no-files-found: error + retention-days: 14 + - name: Slowest tests in this slice + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/slowest-tests.sh" "agent ${{ matrix.idx }}/5" test-agent-${{ matrix.idx }}.log + - name: Upload shard coverage artifacts + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: test-shard-agent-${{ matrix.idx }} + path: | + src/coverage-agent-${{ matrix.idx }}.out + src/test-agent-${{ matrix.idx }}.log + if-no-files-found: warn + retention-days: 1 + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-list-packages: + needs: + - subject + - tests-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && ((needs.tests-required-context-scope.result != 'success' || needs.tests-required-context-scope.outputs.run-tests == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + runs-on: ubuntu-latest + timeout-minutes: 15 + outputs: + matrix: ${{ steps.partition.outputs.matrix }} + selection: ${{ steps.select.outputs.selection }} + selected: ${{ steps.select.outputs.selected }} + run-hub: ${{ steps.select.outputs.run-hub }} + run-agent: ${{ steps.select.outputs.run-agent }} + run-dashboard: ${{ steps.select.outputs.run-dashboard }} + run-scheduler: ${{ steps.select.outputs.run-scheduler }} + crux-scope: ${{ steps.select.outputs.crux-scope }} + defaults: + run: + working-directory: src + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + fetch-depth: 2 + - name: Warm shared Go tool cache (serialize the cold-cache population) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + uses: ./.github/actions/go-mod-download-retry + - name: Restore warm Go build cache + if: ${{ !contains('["ubuntu-latest"]', 'hive-runners') }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: ~/.cache/go-build + key: hive-go-build-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }} + restore-keys: | + hive-go-build-${{ runner.os }}-${{ runner.arch }}- + - name: Restore cgo toolchain package cache + id: restore-cgo-apt-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + restore-keys: | + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev- + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}- + hive-cgo-race-apt- + - name: Prepare cgo toolchain for race tests + id: prepare-cgo-toolchain + env: + HIVE_CI_APT_CACHE_DIR: ${{ github.workspace }}/.ci/apt-cache/cgo-race + HIVE_CI_MISSING_TOOLCHAIN_SOFT_FAIL: ${{ !true && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '1' || '0' }} + run: | + bash "$GITHUB_WORKSPACE/.github/scripts/ci-install-tool.sh" \ + --require gcc --for '-race tests' \ + --apt 'gcc libc6-dev' --apk 'gcc musl-dev' --verify 'gcc --version' + - name: Save cgo toolchain package cache + if: always() && steps.restore-cgo-apt-cache.outputs.cache-hit != 'true' && steps.prepare-cgo-toolchain.outputs.apt-cache-populated == 'true' + continue-on-error: true + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + - name: Select affected packages + id: select + env: + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + SELECTION_SWITCH: ${{ 'false' }} + run: "set -uo pipefail\nsel=../affected-pkgs.txt\nif [ \"$GITHUB_EVENT_NAME\" != pull_request ]; then\n echo \"$GITHUB_EVENT_NAME run: full suite (only pull requests use affected-package selection).\"\n echo all > \"$sel\"\nelif [ \"${SELECTION_SWITCH:-}\" = off ]; then\n echo \"HIVE_AFFECTED_TEST_SELECTION=off: full suite.\"\n echo all > \"$sel\"\nelif [ -z \"${PR_HEAD_SHA:-}\" ] || [ \"$(git rev-parse -q --verify 'HEAD^2' || true)\" != \"$PR_HEAD_SHA\" ]; then\n echo \"::notice::checkout is not the PR merge commit of $PR_HEAD_SHA; running the full suite\"\n echo all > \"$sel\"\nelse\n bash \"$GITHUB_WORKSPACE/.github/scripts/affected-go-packages.sh\" 'HEAD^1' HEAD \"$sel\" || echo all > \"$sel\"\nfi\n[ -f \"$sel\" ] || echo all > \"$sel\"\n# src/go.work puts `go list -m` in workspace mode, where it prints\n# every workspace module; the selection file is keyed by the root\n# module's import paths, so ask for that module alone.\nmod=$(GOWORK=off go list -m)\ncrux_scope=full\nif [ \"$(head -n1 \"$sel\")\" = all ]; then\n selection=full\n run_hub=true run_agent=true run_dashboard=true run_scheduler=true\nelse\n selection=partial\n has() { grep -Fxq \"$mod/$1\" \"$sel\" && echo true || echo false; }\n run_hub=$(has pkg/hub) run_agent=$(has crux/agent) run_dashboard=$(has pkg/dashboard) run_scheduler=$(has pkg/scheduler)\n # Crux boundary filter (#13536) \u2014 see the header comment. Only a\n # partial selection is ever narrowed; the script answers `full`\n # for every fail-safe path and for anything it cannot read, and\n # `full` leaves the selection exactly as the dependency analysis\n # computed it.\n crux_scope=$(bash \"$GITHUB_WORKSPACE/.github/scripts/crux-scope.sh\" 'HEAD^1' HEAD) || crux_scope=full\n case \"$crux_scope\" in\n crux-only)\n run_hub=false run_dashboard=false run_scheduler=false run_agent=true\n # Rest buckets: the selected Crux packages plus the always-on\n # tree-scanning packages (mirrors ALWAYS_PATTERNS in\n # affected-go-packages.sh); a failure here falls back to the\n # unnarrowed selection.\n if go list ./crux/... \\\n ./internal/... ./pkg/config ./pkg/rotation > ../crux-pkgs.txt 2>/dev/null \\\n && [ -s ../crux-pkgs.txt ]; then\n grep -Fx -f ../crux-pkgs.txt \"$sel\" > \"$sel.crux\" || true\n echo \"crux-only diff: narrowing $(grep -c . \"$sel\" || true) selected packages to $(grep -c . \"$sel.crux\" || true) Crux/always-on packages; hub, dashboard and scheduler slices and the dashboard shuffle lane will not run\"\n mv \"$sel.crux\" \"$sel\"\n else\n echo \"::warning::crux-only diff but go list of the Crux set failed; keeping the unnarrowed selection\"\n crux_scope=mixed\n fi\n ;;\n none)\n # Drop crux/agent from the selection too: the coverage job\n # requires every selected package to have produced a result,\n # and the agent slices are the only lane that tests it.\n run_agent=false\n grep -Fxv \"$mod/crux/agent\" \"$sel\" > \"$sel.nocrux\" || true\n mv \"$sel.nocrux\" \"$sel\"\n echo \"no Crux package changed: agent slices will not run\"\n ;;\n mixed|full) ;;\n *)\n echo \"::warning::unexpected crux-scope verdict '$crux_scope'; treating as mixed\"\n crux_scope=mixed\n ;;\n esac\nfi\n{\n echo \"selection=$selection\"\n echo \"selected=$(paste -sd' ' \"$sel\")\"\n echo \"run-hub=$run_hub\"\n echo \"run-agent=$run_agent\"\n echo \"run-dashboard=$run_dashboard\"\n echo \"run-scheduler=$run_scheduler\"\n echo \"crux-scope=$crux_scope\"\n} >> \"$GITHUB_OUTPUT\"\n{\n echo \"## Go test selection\"\n echo \"\"\n if [ \"$selection\" = full ]; then\n echo \"Full suite.\"\n else\n echo \"Affected packages only ($(grep -c . \"$sel\" || true)); crux-scope=$crux_scope; hub=$run_hub agent=$run_agent dashboard=$run_dashboard scheduler=$run_scheduler.\"\n echo \"\"\n sed 's/^/- /' \"$sel\"\n fi\n} >> \"$GITHUB_STEP_SUMMARY\"\necho \"selection=$selection crux-scope=$crux_scope hub=$run_hub agent=$run_agent dashboard=$run_dashboard scheduler=$run_scheduler\"\n" + - name: Partition packages into balanced buckets + id: partition + run: "R=4\n# Drop only the monolithic packages that have function-sliced jobs\n# of their own: pkg/hub (test-hub), pkg/dashboard and pkg/scheduler\n# (test-sliced). All their subpackages belong in the rest buckets\n# so coverage floors and the no-test-files gate apply to them too.\n# pkg/hubbackup, pkg/dashboard/webstatic et al. stay here.\n# ./internal/... carries the shared test helpers (internal/testutil)\n# and their contract tests, such as the time.Sleep ratchet in\n# sleep_ratchet_test.go. ./crux/... is the nested Crux module\n# (#13536), reachable from src/ through src/go.work; its manager\n# package crux/agent has the dedicated agent slices.\ngo list ./pkg/... ./cmd/... ./internal/... ./crux/... \\\n | awk '$0 == \"github.com/hivecommons/hive/pkg/hub\" { next }\n $0 == \"github.com/hivecommons/hive/pkg/dashboard\" { next }\n $0 == \"github.com/hivecommons/hive/pkg/scheduler\" { next }\n { print }' \\\n | grep -Ev '^github\\.com/hivecommons/hive/crux/agent$' \\\n | LC_ALL=C sort > rest-pkgs.txt\nif [ ! -s rest-pkgs.txt ]; then\n echo \"::error::go list produced no rest packages \u2014 failing closed\"\n exit 1\nfi\n# Affected-package selection narrows membership only after the\n# fail-closed check above ran on the full list. The bucket count\n# stays R, so every `test (rest i/R)` context still reports; a\n# bucket left empty succeeds without running (see test-rest).\nif [ \"$(head -n1 ../affected-pkgs.txt)\" != all ]; then\n grep -Fx -f ../affected-pkgs.txt rest-pkgs.txt > rest-selected.txt || true\n echo \"affected-package selection: $(wc -l < rest-selected.txt) of $(wc -l < rest-pkgs.txt) rest packages\"\n mv rest-selected.txt rest-pkgs.txt\nfi\n\n# Weights = measured -short -race package wall seconds on the\n# hive-runners fleet, mean of two v5 push runs (40383615331 and\n# 40382244011, 2026-10-26, rounded). Re-measure with: for each\n# `test (rest i/R)` job log, grep the\n# `ok github.com/hivecommons/hive/ s` lines. Anything\n# under ~5s is noise and takes the 1s default. Packages inside a\n# bucket run concurrently under one go test, so a bucket's wall\n# clock is its heaviest package plus compile time \u2014 the table\n# mainly has to keep the big ones apart, and the sum-based greedy\n# below does that while spreading the compile load. pkg/hub/spoke\n# is the floor now that pkg/dashboard and pkg/scheduler are sliced\n# (test-sliced above): the widest bucket can never be faster than\n# it. pkg/dashboard and pkg/scheduler are listed so a stale\n# exclusion above still yields a sane partition. pkg/github is\n# ~1s with ~1% coverage on push runs but 70s on pull requests (PR\n# 14407's run 40387365403), where it is weighed \u2014 measure it from a\n# PR run, not a push run.\nweight() {\n case \"$1\" in\n */pkg/dashboard) echo 219 ;;\n */pkg/scheduler) echo 199 ;;\n */pkg/hub/spoke) echo 85 ;;\n */pkg/config) echo 82 ;;\n */pkg/github) echo 70 ;;\n */cmd/hive) echo 69 ;;\n */crux/proxy) echo 56 ;;\n */pkg/dashboard/webstatic) echo 35 ;;\n */pkg/hubbackup) echo 30 ;;\n */pkg/advisory) echo 29 ;;\n */internal/testutil) echo 22 ;;\n */pkg/ioscan) echo 16 ;;\n */pkg/hivectl) echo 15 ;;\n */pkg/tui) echo 14 ;;\n */pkg/discord) echo 12 ;;\n */pkg/fleetreport) echo 11 ;;\n */pkg/hivectl/commands) echo 10 ;;\n */pkg/stageengine) echo 10 ;;\n */pkg/apphealth) echo 9 ;;\n */pkg/rotation) echo 9 ;;\n */pkg/beads) echo 8 ;;\n */pkg/github/automerge) echo 8 ;;\n */crux/api/callback) echo 6 ;;\n */crux/inference) echo 6 ;;\n */cmd/hive-backup) echo 5 ;;\n */pkg/mint) echo 5 ;;\n */pkg/policies) echo 5 ;;\n *) echo 1 ;;\n esac\n}\n\n# Deterministic greedy LPT: stable-sort by weight desc (name asc on\n# ties), assign each package to the currently lightest bucket\n# (lowest index on ties).\nwhile read -r p; do\n echo \"$(weight \"$p\") $p\"\ndone < rest-pkgs.txt | sort -k1,1nr -k2,2 > weighted.txt\n\ndeclare -a LOAD BUCKET\nfor ((i=0; i> \"$GITHUB_OUTPUT\"\n" + name: list-packages + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-test-rest: + if: ${{ always() && needs.subject.result == 'success' && ((needs.tests-required-context-scope.result != 'success' || needs.tests-required-context-scope.outputs.run-tests == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: test (rest ${{ matrix.idx }}/${{ matrix.total }}) + needs: + - subject + - tests-required-context-scope + - tests-list-packages + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.tests-list-packages.outputs.matrix) }} + runs-on: ubuntu-latest + timeout-minutes: 25 + defaults: + run: + working-directory: src + steps: + - name: Affected-package selection + id: select + working-directory: . + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + PKGS: ${{ matrix.pkgs }} + run: | + if [ "$SELECTION" = partial ] && [ -z "$PKGS" ]; then + echo "Affected-package selection: no affected package landed in this bucket; reporting success without running tests. Push and scheduled runs test it in full." + echo "run=false" >> "$GITHUB_OUTPUT" + else + echo "run=true" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + if: steps.select.outputs.run == 'true' + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + if: steps.select.outputs.run == 'true' + with: + cache: false + go-version-file: src/go.mod + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + if: steps.select.outputs.run == 'true' + with: + node-version: '22' + - name: Guard shared node tool cache (repair a half-written entry) + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: | + set -u + command -v npm >/dev/null 2>&1 && exit 0 + for marker in "${RUNNER_TOOL_CACHE:-/nonexistent}"/node/*/x64.complete; do + [ -e "$marker" ] || continue + dir="${marker%.complete}" + [ -x "$dir/bin/npm" ] && continue + echo "::warning::node tool cache $dir has a .complete marker but no executable bin/npm; removing the marker so the next job on $RUNNER_NAME rebuilds it" + rm -f "$marker" + done + echo "::error::npm is not on PATH after actions/setup-node on $RUNNER_NAME (half-written shared tool cache, see #10518); marker removed, re-run this job" + exit 1 + - name: Guard shared Go cache (fall back when the runner volume is full) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + if: steps.select.outputs.run == 'true' + uses: ./.github/actions/go-mod-download-retry + - name: Install gotestsum + if: steps.select.outputs.run == 'true' + run: | + echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH" + go install gotest.tools/gotestsum@v1.13.0 + "$(go env GOPATH)/bin/gotestsum" --version + - name: Restore warm Go build cache + if: ${{ steps.select.outputs.run == 'true' && (!contains('["ubuntu-latest"]', 'hive-runners')) }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: ~/.cache/go-build + key: hive-go-build-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }} + restore-keys: | + hive-go-build-${{ runner.os }}-${{ runner.arch }}- + - name: Restore cgo toolchain package cache + if: steps.select.outputs.run == 'true' + id: restore-cgo-apt-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + restore-keys: | + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev- + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}- + hive-cgo-race-apt- + - name: Prepare cgo toolchain for race tests + if: steps.select.outputs.run == 'true' + id: prepare-cgo-toolchain + env: + HIVE_CI_APT_CACHE_DIR: ${{ github.workspace }}/.ci/apt-cache/cgo-race + HIVE_CI_MISSING_TOOLCHAIN_SOFT_FAIL: ${{ !true && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '1' || '0' }} + run: | + bash "$GITHUB_WORKSPACE/.github/scripts/ci-install-tool.sh" \ + --require gcc --for '-race tests' \ + --apt 'gcc libc6-dev' --apk 'gcc musl-dev' --verify 'gcc --version' + - name: Save cgo toolchain package cache + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.restore-cgo-apt-cache.outputs.cache-hit != 'true' && steps.prepare-cgo-toolchain.outputs.apt-cache-populated == 'true') }} + continue-on-error: true + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + - name: Test + if: ${{ steps.select.outputs.run == 'true' && (steps.prepare-cgo-toolchain.outputs.toolchain-ready == 'true') }} + env: + PKGS: ${{ matrix.pkgs }} + HIVE_TEST_REQUIRE_BEHAVIOURAL: '1' + run: "set -o pipefail\nif [ -z \"$PKGS\" ]; then\n echo \"::error::empty package bucket \u2014 failing closed\"\n exit 1\nfi\n# -timeout=20m: kept from when pkg/dashboard lived in these buckets\n# and nearly exhausted go test's default 10m on loaded PR runners\n# (#12113); a loaded runner can still stretch pkg/hub/spoke.\nSHUFFLE=\"\"\nif [ \"$GITHUB_EVENT_NAME\" != \"pull_request\" ]; then SHUFFLE=\"-shuffle=on\"; fi\n# shellcheck disable=SC2086 # PKGS and SHUFFLE are deliberate word-split lists\nbash \"$GITHUB_WORKSPACE/.github/scripts/ci-gotestsum-preserve-coverprofile.sh\" \\\n gotestsum --format=standard-verbose --rerun-fails=2 --rerun-fails-max-failures=5 \\\n --rerun-fails-report=flaky-tests-rest-${{ matrix.idx }}.txt \\\n --packages=\"$PKGS\" --junitfile junit-rest-${{ matrix.idx }}.xml \\\n -- -short -race -count=1 -timeout=20m -v $SHUFFLE -coverprofile=coverage-rest-${{ matrix.idx }}.out \\\n 2>&1 | grep --line-buffered -vE '^=== (RUN|PAUSE|CONT) ' | tee test-rest-${{ matrix.idx }}.log\n" + - name: Surface flaky reruns + id: flaky-reruns + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/ci-gotestsum-flake-summary.sh" "flaky-tests-rest-${{ matrix.idx }}.txt" "rest ${{ matrix.idx }}/${{ matrix.total }}" + - name: Upload flaky rerun report + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.flaky-reruns.outputs.has-flakes == 'true') }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: flaky-tests-rest-${{ matrix.idx }} + path: src/flaky-tests-rest-${{ matrix.idx }}.txt + if-no-files-found: error + retention-days: 14 + - name: Slowest tests in this bucket + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/slowest-tests.sh" "rest ${{ matrix.idx }}/${{ matrix.total }}" test-rest-${{ matrix.idx }}.log + - name: Upload shard coverage artifacts + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: test-shard-rest-${{ matrix.idx }} + path: | + src/coverage-rest-${{ matrix.idx }}.out + src/test-rest-${{ matrix.idx }}.log + if-no-files-found: warn + retention-days: 1 + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-test-dashboard-shuffle: + needs: + - subject + - tests-required-context-scope + - tests-list-packages + if: ${{ always() && needs.subject.result == 'success' && ((needs.tests-required-context-scope.result != 'success' || needs.tests-required-context-scope.outputs.run-tests == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: test (dashboard shuffle ${{ matrix.idx }}/3) + strategy: + fail-fast: false + matrix: + idx: + - 1 + - 2 + - 3 + runs-on: ubuntu-latest + timeout-minutes: 20 + defaults: + run: + working-directory: src + steps: + - name: Affected-package selection + id: select + working-directory: . + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + RUN_LANE: ${{ needs.tests-list-packages.outputs.run-dashboard }} + run: | + if [ "$SELECTION" = partial ] && [ "$RUN_LANE" = false ]; then + echo "Affected-package selection: pkg/dashboard is not affected by this diff; reporting success without running tests. Push and scheduled runs test it in full." + echo "run=false" >> "$GITHUB_OUTPUT" + else + echo "run=true" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + if: steps.select.outputs.run == 'true' + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + if: steps.select.outputs.run == 'true' + with: + cache: false + go-version-file: src/go.mod + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 + if: steps.select.outputs.run == 'true' + with: + node-version: '22' + - name: Guard shared node tool cache (repair a half-written entry) + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: | + set -u + command -v npm >/dev/null 2>&1 && exit 0 + for marker in "${RUNNER_TOOL_CACHE:-/nonexistent}"/node/*/x64.complete; do + [ -e "$marker" ] || continue + dir="${marker%.complete}" + [ -x "$dir/bin/npm" ] && continue + echo "::warning::node tool cache $dir has a .complete marker but no executable bin/npm; removing the marker so the next job on $RUNNER_NAME rebuilds it" + rm -f "$marker" + done + echo "::error::npm is not on PATH after actions/setup-node on $RUNNER_NAME (half-written shared tool cache, see #10518); marker removed, re-run this job" + exit 1 + - name: Guard shared Go cache (fall back when the runner volume is full) + if: steps.select.outputs.run == 'true' + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + if: steps.select.outputs.run == 'true' + uses: ./.github/actions/go-mod-download-retry + - name: Install gotestsum + if: steps.select.outputs.run == 'true' + run: | + echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH" + go install gotest.tools/gotestsum@v1.13.0 + "$(go env GOPATH)/bin/gotestsum" --version + - name: Restore warm Go build cache + if: ${{ steps.select.outputs.run == 'true' && (!contains('["ubuntu-latest"]', 'hive-runners')) }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: ~/.cache/go-build + key: hive-go-build-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }} + restore-keys: | + hive-go-build-${{ runner.os }}-${{ runner.arch }}- + - name: Restore cgo toolchain package cache + if: steps.select.outputs.run == 'true' + id: restore-cgo-apt-cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + restore-keys: | + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev- + hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}- + hive-cgo-race-apt- + - name: Prepare cgo toolchain for race tests + if: steps.select.outputs.run == 'true' + id: prepare-cgo-toolchain + env: + HIVE_CI_APT_CACHE_DIR: ${{ github.workspace }}/.ci/apt-cache/cgo-race + HIVE_CI_MISSING_TOOLCHAIN_SOFT_FAIL: ${{ !true && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && '1' || '0' }} + run: | + bash "$GITHUB_WORKSPACE/.github/scripts/ci-install-tool.sh" \ + --require gcc --for '-race tests' \ + --apt 'gcc libc6-dev' --apk 'gcc musl-dev' --verify 'gcc --version' + - name: Save cgo toolchain package cache + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.restore-cgo-apt-cache.outputs.cache-hit != 'true' && steps.prepare-cgo-toolchain.outputs.apt-cache-populated == 'true') }} + continue-on-error: true + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 + with: + path: .ci/apt-cache/cgo-race + key: hive-cgo-race-apt-${{ runner.os }}-${{ runner.arch }}-gcc-libc6-dev-v2 + - name: Test pkg/dashboard in shuffled order + if: ${{ steps.select.outputs.run == 'true' && (steps.prepare-cgo-toolchain.outputs.toolchain-ready == 'true') }} + env: + IDX: ${{ matrix.idx }} + TOTAL: ${{ strategy.job-total }} + run: "set -o pipefail\n# Sliced like test-hub (NR mod N \u2014 pairwise disjoint, jointly\n# exhaustive) so no single job carries the whole ~6-minute lane;\n# -shuffle still varies order within each slice every run.\nROOT=\"$PWD\"\nexport TEST_PACKAGE=github.com/hivecommons/hive/pkg/dashboard\nexport TEST_DIR=\"$ROOT/pkg/dashboard\"\nexport TEST_BINARY=\"$ROOT/dashboard.test\"\ngo test -c -race -o \"$TEST_BINARY\" ./pkg/dashboard\n(cd \"$TEST_DIR\" && \"$TEST_BINARY\" -test.short -test.list '.*') | grep -E '^(Test|Example|Fuzz)' | LC_ALL=C sort > all-tests.txt\nif [ ! -s all-tests.txt ]; then\n echo \"::error::go test -list produced no test functions for pkg/dashboard \u2014 refusing to run an empty slice (fail closed)\"\n exit 1\nfi\nawk -v n=\"$TOTAL\" -v i=\"$IDX\" 'NR % n == i - 1' all-tests.txt > slice.txt\necho \"slice $IDX/$TOTAL: $(wc -l < slice.txt) of $(wc -l < all-tests.txt) test functions\"\nif [ ! -s slice.txt ]; then\n echo \"::error::empty dashboard slice \u2014 failing closed\"\n exit 1\nfi\nexport CHUNK_DIR\nCHUNK_DIR=$(mktemp -d \"$ROOT/test-chunks.XXXXXX\")\nsplit -l 1000 slice.txt \"$CHUNK_DIR/chunk-\"\n# raw-command preserves one JUnit/flake report across all chunks.\n# gotestsum appends -test.run and package arguments on reruns.\ncat > \"$CHUNK_DIR/run.sh\" <<'RUNNER'\n#!/usr/bin/env bash\nset -uo pipefail\nexport LC_ALL=C # ${#RUN} must count bytes, not Unicode characters.\ncd \"$TEST_DIR\" || exit 1\nrun_chunk() {\n local RUN=\"$1\"\n # MAX_ARG_STRLEN is 131072 bytes; fail clearly before execve.\n if [ \"${#RUN}\" -gt 120000 ]; then\n echo \"::error::chunk regex exceeds 120000 bytes; reduce chunk size\" >&2\n return 1\n fi\n # Bound t.Parallel to avoid exhausting httptest ephemeral ports.\n go tool test2json -t -p \"$TEST_PACKAGE\" \"$TEST_BINARY\" \\\n -test.short -test.count=1 -test.v=test2json -test.timeout=10m \\\n -test.shuffle=on -test.parallel=4 \"$RUN\"\n}\nif [ \"$#\" -gt 0 ]; then\n run_chunk \"$1\"\n exit $?\nfi\nstatus=0\nfor chunk in \"$CHUNK_DIR\"/chunk-*; do\n RUN=\"-test.run=^($(paste -sd'|' \"$chunk\"))$\"\n run_chunk \"$RUN\" || status=1\ndone\nexit \"$status\"\nRUNNER\nif gotestsum --format=standard-verbose --rerun-fails=2 --rerun-fails-max-failures=5 \\\n --rerun-fails-report=flaky-tests-dashboard-shuffle-\"$IDX\".txt \\\n --junitfile junit-dashboard-shuffle-\"$IDX\".xml --raw-command -- bash \"$CHUNK_DIR/run.sh\" \\\n 2>&1 | grep --line-buffered -vE '^=== (RUN|PAUSE|CONT) ' | tee test-dashboard-shuffle-\"$IDX\".log; then\n exit 0\nfi\n# Each chunk prints its own -test.shuffle seed immediately before\n# its tests; do not report the first chunk's seed for a later failure.\necho \"::error::pkg/dashboard failed (slice $IDX/$TOTAL); see the failing chunk's -test.shuffle seed in test-dashboard-shuffle-$IDX.log. Reproduce the failing test with: go test ./pkg/dashboard -short -race -count=1 -p 1 -parallel 4 -run '^TestName$' -shuffle=\"\nexit 1\n" + - name: Surface flaky reruns + id: flaky-reruns + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/ci-gotestsum-flake-summary.sh" "flaky-tests-dashboard-shuffle-${{ matrix.idx }}.txt" "dashboard shuffle ${{ matrix.idx }}/3" + - name: Upload flaky rerun report + if: ${{ steps.select.outputs.run == 'true' && (always() && steps.flaky-reruns.outputs.has-flakes == 'true') }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: flaky-tests-dashboard-shuffle-${{ matrix.idx }} + path: src/flaky-tests-dashboard-shuffle-${{ matrix.idx }}.txt + if-no-files-found: error + retention-days: 14 + - name: Slowest tests in this lane + if: ${{ steps.select.outputs.run == 'true' && (always()) }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/slowest-tests.sh" "dashboard shuffle ${{ matrix.idx }}/3" test-dashboard-shuffle-${{ matrix.idx }}.log + - name: Upload shuffle log + if: ${{ steps.select.outputs.run == 'true' && (failure()) }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: test-dashboard-shuffle-log-${{ matrix.idx }} + path: src/test-dashboard-shuffle-${{ matrix.idx }}.log + if-no-files-found: warn + retention-days: 1 + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-test: + if: ${{ always() && needs.subject.result == 'success' && (always() && !cancelled() && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + runs-on: ubuntu-latest + timeout-minutes: 10 + needs: + - subject + - tests-required-context-scope + - tests-list-packages + - tests-test-hub + - tests-test-sliced + - tests-test-agent + - tests-test-rest + - tests-test-dashboard-shuffle + steps: + - name: Check shard results + env: + LIST_PACKAGES_RESULT: ${{ needs.tests-list-packages.result }} + TEST_HUB_RESULT: ${{ needs.tests-test-hub.result }} + TEST_SLICED_RESULT: ${{ needs.tests-test-sliced.result }} + TEST_AGENT_RESULT: ${{ needs.tests-test-agent.result }} + TEST_REST_RESULT: ${{ needs.tests-test-rest.result }} + TEST_DASHBOARD_SHUFFLE_RESULT: ${{ needs.tests-test-dashboard-shuffle.result }} + RUN_TESTS: ${{ needs.tests-required-context-scope.outputs.run-tests }} + SCOPE_RESULT: ${{ needs.tests-required-context-scope.result }} + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + CRUX_SCOPE: ${{ needs.tests-list-packages.outputs.crux-scope }} + RUN_HUB: ${{ needs.tests-list-packages.outputs.run-hub }} + RUN_AGENT: ${{ needs.tests-list-packages.outputs.run-agent }} + RUN_DASHBOARD: ${{ needs.tests-list-packages.outputs.run-dashboard }} + RUN_SCHEDULER: ${{ needs.tests-list-packages.outputs.run-scheduler }} + run: "set -euo pipefail\n\nif [ \"${SCOPE_RESULT:-}\" != success ]; then\n echo \"::error::required-context-scope failed; refusing to report test success without a diff verdict\"\n exit 1\nfi\n\nif [ \"${RUN_TESTS:-}\" != true ]; then\n echo \"No v2 test paths changed; reporting required test context success without running shards.\"\n exit 0\nfi\n\n# Lanes with nothing selected still ran (and succeeded) \u2014 see the\n# Affected-package selection step in each shard \u2014 so the fail-closed\n# result check below is unchanged by selection.\necho \"Go test selection: ${SELECTION:-} (partial = affected packages only on this PR; push and scheduled runs are always full)\"\n# Crux boundary filter (#13536): the lanes allowed to report success\n# without testing are exactly those whose run flag list-packages set\n# to false. Print that allowlist here so the verdict is auditable\n# from the aggregate log; a lane absent from it that did not test\n# would have failed its own selection step logic, and any shard\n# result other than success still fails this job below.\nif [ \"${SELECTION:-}\" = partial ]; then\n allow=()\n [ \"${RUN_HUB:-true}\" = false ] && allow+=(test-hub)\n [ \"${RUN_AGENT:-true}\" = false ] && allow+=(test-agent)\n [ \"${RUN_DASHBOARD:-true}\" = false ] && allow+=(test-dashboard-shuffle \"test-sliced (dashboard)\")\n [ \"${RUN_SCHEDULER:-true}\" = false ] && allow+=(\"test-sliced (scheduler)\")\n echo \"Crux scope: ${CRUX_SCOPE:-}; lanes allowed to succeed without testing: ${allow[*]:-}\"\nfi\n\nshard_names=(\n list-packages\n test-hub\n test-sliced\n test-agent\n test-rest\n test-dashboard-shuffle\n)\nshard_results=(\n \"${LIST_PACKAGES_RESULT:-}\"\n \"${TEST_HUB_RESULT:-}\"\n \"${TEST_SLICED_RESULT:-}\"\n \"${TEST_AGENT_RESULT:-}\"\n \"${TEST_REST_RESULT:-}\"\n \"${TEST_DASHBOARD_SHUFFLE_RESULT:-}\"\n)\n\nfailures=()\nskipped=()\ncancelled=()\nunknown=()\n\nfor i in \"${!shard_names[@]}\"; do\n name=${shard_names[$i]}\n result=${shard_results[$i]}\n printf '%-23s %s\\n' \"${name}:\" \"${result:-}\"\n case \"$result\" in\n success) ;;\n failure) failures+=(\"$name\") ;;\n skipped) skipped+=(\"$name\") ;;\n cancelled) cancelled+=(\"$name\") ;;\n *) unknown+=(\"$name=${result:-}\") ;;\n esac\ndone\n\njoin_by_comma() {\n local IFS=', '\n echo \"$*\"\n}\n\nappend_summary() {\n if [ -n \"${GITHUB_STEP_SUMMARY:-}\" ]; then\n {\n echo \"## v2 shard aggregate\"\n echo \"\"\n echo \"$1\"\n } >> \"$GITHUB_STEP_SUMMARY\"\n fi\n}\n\nif [ \"${#failures[@]}\" -gt 0 ] || [ \"${#skipped[@]}\" -gt 0 ] || [ \"${#unknown[@]}\" -gt 0 ]; then\n if [ \"${#failures[@]}\" -gt 0 ]; then\n echo \"::error::Failing shard(s): $(join_by_comma \"${failures[@]}\")\"\n fi\n if [ \"${#skipped[@]}\" -gt 0 ]; then\n echo \"::error::Skipped shard(s): $(join_by_comma \"${skipped[@]}\"). A skipped shard means tests may not have run.\"\n fi\n if [ \"${#unknown[@]}\" -gt 0 ]; then\n echo \"::error::Unknown shard result(s): $(join_by_comma \"${unknown[@]}\")\"\n fi\n if [ \"${#cancelled[@]}\" -gt 0 ]; then\n echo \"::error::Candidate shards must all complete\"; exit 1\n echo \"Cancelled shard(s) were also present: $(join_by_comma \"${cancelled[@]}\"). They are not treated as infrastructure-only because another shard failed, skipped, or reported an unknown state.\"\n fi\n append_summary \"\u274C At least one shard failed, skipped, or reported an unknown state. Cancelled shards, if any, were not allowed to mask that result.\"\n exit 1\nfi\n\nif [ \"${#cancelled[@]}\" -gt 0 ]; then\n echo \"::error::Candidate shards must all complete\"; exit 1\n message=\"Infrastructure cancellation: shard(s) did not complete: $(join_by_comma \"${cancelled[@]}\"). No test failure was observed, but this run is not complete test evidence for those shard(s).\"\n echo \"::warning title=Infrastructure cancellation::$message\"\n append_summary \"\u26A0\uFE0F $message\"\n exit 0\nfi\n\nappend_summary \"\u2705 All shards succeeded.\"\necho \"All shards succeeded.\"\n" + name: test + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + tests-coverage: + if: ${{ always() && needs.subject.result == 'success' && (always() && (true || github.event_name == 'merge_group' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'release-gate/')))) }} + runs-on: ubuntu-latest + timeout-minutes: 30 + needs: + - subject + - tests-required-context-scope + - tests-list-packages + - tests-test-hub + - tests-test-sliced + - tests-test-agent + - tests-test-rest + steps: + - name: Report coverage not required for this diff + if: ${{ needs.tests-required-context-scope.result == 'success' && needs.tests-required-context-scope.outputs.run-tests != 'true' }} + run: echo "No v2 coverage paths changed; reporting required coverage context success." + - name: Fail if scope failed or a required test shard did not complete + if: ${{ needs.tests-required-context-scope.result != 'success' || (needs.tests-required-context-scope.outputs.run-tests == 'true' && (needs.tests-test-hub.result != 'success' || needs.tests-test-sliced.result != 'success' || needs.tests-test-agent.result != 'success' || needs.tests-test-rest.result != 'success')) }} + run: | + if [ "${{ needs.tests-required-context-scope.result }}" != success ]; then + echo "::error::required-context-scope failed; refusing to report coverage success without a diff verdict" + exit 1 + fi + echo "::error::Coverage requires successful test shards (hub=${{ needs.tests-test-hub.result }}, sliced=${{ needs.tests-test-sliced.result }}, agent=${{ needs.tests-test-agent.result }}, rest=${{ needs.tests-test-rest.result }})" + exit 1 + - name: Decide what coverage to score + id: cov-scope + if: ${{ needs.tests-required-context-scope.outputs.run-tests == 'true' }} + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + SELECTED: ${{ needs.tests-list-packages.outputs.selected }} + run: | + if [ "$SELECTION" = partial ] && [ -z "${SELECTED// /}" ]; then + echo "Affected-package selection chose no Go package; no coverage to score. Push and scheduled runs score the full suite." + echo "score=false" >> "$GITHUB_OUTPUT" + else + echo "Coverage scoring: ${SELECTION:-} selection." + echo "score=true" >> "$GITHUB_OUTPUT" + fi + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + if: ${{ steps.cov-scope.outputs.score == 'true' }} + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + if: ${{ steps.cov-scope.outputs.score == 'true' }} + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + if: ${{ steps.cov-scope.outputs.score == 'true' }} + with: + go-version-file: src/go.mod + cache-dependency-path: | + src/go.sum + src/crux/go.sum + - name: Download Go modules (retry transient proxy resets) + if: ${{ steps.cov-scope.outputs.score == 'true' }} + uses: ./.github/actions/go-mod-download-retry + - name: List packages present in checkout + if: ${{ steps.cov-scope.outputs.score == 'true' }} + working-directory: src + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + run: | + # The coverage scorer consumes shard artifacts, but the package set it + # scores must still be bounded by the checked-out tree for this run. + # This mirrors coverage-hourly.yml, whose `go test` command can only + # emit packages that exist in the checkout. + go list ./pkg/... ./cmd/... ./internal/... ./crux/... | LC_ALL=C sort -u > ../existing-pkgs.txt + if [ ! -s ../existing-pkgs.txt ]; then + echo "::error::go list produced no packages for coverage scoring" + exit 1 + fi + # On a partial selection the shard logs only cover the selected + # packages, so take the no-test-files gate from the whole tree + # instead (cheap: go list only). Same definition as the `?` / + # `coverage: 0.0%` lines a full run classifies below. + : > ../no-test-pkgs.txt + if [ "$SELECTION" = partial ]; then + go list -f '{{if not (or .TestGoFiles .XTestGoFiles)}}{{.ImportPath}}{{end}}' ./pkg/... ./cmd/... ./crux/... \ + | { grep . || true; } | LC_ALL=C sort -u > ../no-test-pkgs.txt + fi + - name: Download shard coverage artifacts + if: ${{ steps.cov-scope.outputs.score == 'true' }} + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 + with: + pattern: test-shard-* + path: shards + merge-multiple: true + - name: Check per-package coverage + if: ${{ steps.cov-scope.outputs.score == 'true' }} + working-directory: shards + env: + SELECTION: ${{ needs.tests-list-packages.outputs.selection }} + SELECTED: ${{ needs.tests-list-packages.outputs.selected }} + run: "THRESHOLD=90\nFAILED=\"\"\nBROKEN=\"\"\nREPORT=\"\"\n\n# Per-package threshold overrides. A handful of packages are heavily\n# coupled to the live runtime (fixed /data,/proc,/var/run paths, real\n# github.com/platform.claude.com device-flow, a live tmux agent buffer,\n# an in-cluster k8s serviceaccount) and cannot be exercised hermetically\n# in CI without invasive production seams. They get a documented lower\n# floor so the gate still catches regressions below their real ceiling,\n# rather than blocking forever on untestable code. Raise these toward 90\n# as seams are added; do not add new entries without justification here.\n#\n# KEEP IN SYNC with coverage-hourly.yml, which applies the same floors\n# on its hourly scheduled run.\ndeclare -A PKG_THRESHOLD=(\n [dashboard]=84 # 86.2% on 2026-09-01; the residue is the inception tmux watcher + copilot/claude device-flow + /data file I/O + k8s\n [hub]=87 # kubectl-shelling + live-GitHub paths; see #2355. Was 89 against v2's 89.9%; v4 measures 87.6%.\n [crux/agent]=89 # pre-existing shortfall inherited from #2350, NOT a new regression. See #2355. Keyed crux/ since the module cut (#13536)\n\n # \u2500\u2500 Floors recorded when the gate moved from v2 to v4 (#3903) \u2500\u2500\u2500\u2500\u2500\n # A RATCHET, NOT A TARGET \u2014 see coverage-hourly.yml for the full\n # rationale. Raise these toward 90 as tests land; never raise one to\n # paper over a drop.\n #\n # \u2500\u2500 Ratchet turned for #4570 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # sandbox/ioscan/pushbroker: tests added in the same PR, so the\n # floors move with the gain (67.6\u219298.5, 71.0\u219297.1, 72.8\u2192100.0).\n # intent/tracing/dashboard: NO code change \u2014 these had drifted far\n # above floors recorded at d89121f5 and were no longer catching\n # anything. Re-measured on v4 at cd8aee5d and moved up to what\n # they actually hold, with ~1 point of headroom.\n # scheduler (90.4) and escalation (93.2) now clear the 90% default\n # and no longer need an entry at all.\n [intent]=87\n [tracing]=85\n [review]=80\n [retro]=82\n [github]=88 # 88.9% on 2026-10-05\n [hivectl]=88\n [knowledge]=89\n [crux/proxy]=89\n [ioscan]=96\n [crux/sandbox]=98\n [crux/pushbroker]=99\n [crux/kubejob]=90 # new in #6311; sandbox.Launcher over the in-cluster API, tested against httptest\n\n # \u2500\u2500 Stale module-path parser repaired on v5 (#6066) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # These packages were pre-existing below-default floors that became\n # visible again when the v2-tests coverage classifier was corrected\n # from the old github.com/kubestellar/hive module path to\n # github.com/hivecommons/hive. Record their current ceilings so the\n # parser fix can gate new packages (pkg/effects, pkg/hub/spoke)\n # without turning unrelated backlog into a blocker.\n [convergence/mutation]=86 # 86.7% on PR #6076\n [convergence/audit]=92 # measured 95.6% on v5 after #9930 (in-package Run/reconcile/publish tests, #9928); was 6 (seed tests only, #9688)\n [dashboard/webstatic]=88 # 88.9% on PR #6076\n [github/automerge]=88 # 88.6% on PR #6076\n [mint]=89 # 89.1% on PR #6076\n [turn]=87 # 87.1% on PR #6076\n\n # \u2500\u2500 Ratchet turned for #7146 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # spoke was unfloored and flapped across the 90 default (run\n # 35026215085 at 89.6%, green runs either side, no spoke change\n # between). #7130 covered the timing-dependent paths rather than\n # lowering the floor; spoke now holds a flat 96.3% with zero variance\n # over five runs. See coverage-hourly.yml for the full rationale.\n [spoke]=95 # 96.3% on 2026-09-16 after #7130; was unfloored/flapping\n\n # \u2500\u2500 ./cmd/... floors (#4701) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # See coverage-hourly.yml for the rationale. cmd keys are prefixed\n # (\"cmd/\") so cmd/hivectl can never collide with\n # pkg/hivectl's floor. Recorded just below what v4 measures after\n # #4700/#4719 so the ratchet can turn as CLI tests land.\n # \u2500\u2500 Ratchet turned 2026-09-01 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # cmd/bd, cmd/hive, cmd/hive-backup, dashboard, github: NO code\n # change \u2014 each had drifted 4\u201320 points above its recorded floor\n # (cmd/hive most of all: 18.8 \u2192 37.5 as eval-cycle helpers grew\n # tests) and the gate was no longer catching a drop. Re-measured\n # on the 2026-09-01 hourly run and moved to ~2\u20134 points under\n # what they hold. cmd/apiproxy is unchanged at 13.9%.\n # \u2500\u2500 Ratchet turned for #7407 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # NO code change \u2014 re-measured on 2026-09-17 with `go test -cover\n # ./cmd/... -short -count=1` (three runs, zero variance) and moved\n # to ~2-3 points under the lower of the linux/darwin measurements.\n # See coverage-hourly.yml for the full rationale and both numbers.\n [cmd/bd]=92 # 95.7% on 2026-09-17; was 75\n [cmd/hive]=42 # 44.8% on 2026-09-17; bulk is main()/run-loop wiring; was 35\n [cmd/apiproxy]=92 # 95.6% on 2026-09-17; was 13\n [cmd/hive-backup]=85 # 90.4% on 2026-09-17; was 78\n [cmd/hivectl]=97 # 100.0% on 2026-09-17; was exempt as an untested main\n [cmd/flue-fixture]=75 # 80.0% on 2026-09-22 (#8361): main() is the single uncovered statement; run() and signalContext() are tested in-process and the binary is smoke-tested as a child process, which yields no profile\n [cmd/crux]=75 # 80.0% on 2026-10-23 (#13536): same shape as flue-fixture; main() is the one uncovered statement, run() is tested in-process. floor_key maps BOTH ./cmd/crux (root host) and ./crux/cmd/crux (the module's own binary, #14138) here; the module one measured 80.0% on 2026-10-25\n [crux/cli]=92 # 97.8% on 2026-10-23 (#13536): the crux CLI against a fake crux.Runtime plus a real unix control socket; the residue is Main() and write-error branches\n\n # \u2500\u2500 Crux module (#13536, Stage 2 step 4) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n # Packages of the nested module at src/crux are keyed \"crux/\"\n # (floor_key below): crux/agent, crux/proxy, crux/sandbox,\n # crux/pushbroker, crux/kubejob and crux/cli above carried their\n # pkg/ floors across the move unchanged. The module root\n # package is keyed \"crux\". Every other crux/ takes the\n # default.\n)\n\n# Thin flag-parsing mains with no test files, wrapping packages the\n# gate already floors. KEEP IN SYNC with coverage-hourly.yml. Any NEW\n# untested cmd package still hard-fails.\n#\n# Empty since #7407: cmd/hivectl, the only entry, gained tests in\n# a3f9842c, so no \"[no test files]\" line is emitted for it and the\n# exemption could never match. The mechanism itself is unchanged.\nUNTESTED_CMD_MAINS=''\n\n# Merge every shard profile: per-block counts are summed, so the N\n# partial crux/agent profiles combine into the package's true\n# coverage. Blocks are keyed by (location, statement count); package\n# = the directory of the block's file. Emits \"pkg pct\" lines plus a\n# TOTAL over ./pkg/... \u2014 the same statements-covered/statements\n# definition `go test -cover` prints, so floors are unchanged.\n#\n# Packages are selected by their \"/pkg/\" path segment rather than by\n# a hard-coded module prefix. The previous version matched the literal\n# module path, so the kubestellar -> hivecommons org rename silently\n# emptied every filter and disabled the whole gate. A segment match\n# survives any future rename, and only this repository's own packages\n# appear in these profiles, so it cannot over-match. The nested Crux\n# module's packages carry a \"/crux\" segment (github.com//hive/crux\n# and .../crux/) and get a second, informational total.\nawk '\n FNR == 1 { next } # skip each file'\\''s \"mode:\" line\n {\n file = $1; sub(/:[^:]*$/, \"\", file)\n pkg = file; sub(/\\/[^\\/]+$/, \"\", pkg)\n key = pkg \"|\" $1 \"|\" $2\n stmts[key] = $2; owner[key] = pkg\n count[key] += $3\n }\n END {\n for (k in count) {\n p = owner[k]\n tot[p] += stmts[k]\n if (count[k] > 0) cov[p] += stmts[k]\n }\n gt = 0; gc = 0; xt = 0; xc = 0\n for (p in tot) {\n printf \"%s %.1f\\n\", p, cov[p] * 100 / tot[p]\n if (p ~ /\\/pkg\\//) {\n gt += tot[p]; gc += cov[p]\n } else if (p ~ /\\/crux(\\/|$)/ && p !~ /\\/cmd\\//) {\n xt += tot[p]; xc += cov[p]\n }\n }\n if (gt > 0) printf \"TOTAL %.1f\\n\", gc * 100 / gt\n if (xt > 0) printf \"CRUX_TOTAL %.1f\\n\", xc * 100 / xt\n }\n' coverage-*.out > pkg-pcts.txt\n\nTOTAL=$(awk '$1 == \"TOTAL\" {print $2 \"%\"}' pkg-pcts.txt)\nCRUX_TOTAL=$(awk '$1 == \"CRUX_TOTAL\" {print $2 \"%\"}' pkg-pcts.txt)\necho \"Total coverage (./pkg/...): ${TOTAL:-unavailable}\"\necho \"Total coverage (./crux/...): ${CRUX_TOTAL:-unavailable}\"\ + \n\n# Partial selection (#12454): every number here covers the selected\n# packages only. Per-package floors still apply unchanged to each of\n# them; the total is informational and not comparable to the\n# repo-wide figure, so it is labelled rather than compared.\nPARTIAL=false\nSELECTED_SCORED=\"\"\nif [ \"$SELECTION\" = partial ]; then\n PARTIAL=true\n for p in $SELECTED; do\n case \"$p\" in */pkg/*|*/cmd/*|*/crux|*/crux/*) ;; *) continue ;; esac\n grep -Fxq \"$p\" ../existing-pkgs.txt && SELECTED_SCORED=\"$SELECTED_SCORED $p\"\n done\n echo \"Partial selection: scoring only the $(wc -w <<<\"$SELECTED_SCORED\") selected ./pkg/..., ./cmd/... and ./crux/... packages; the totals above are over the selected packages and are not comparable to the repo-wide totals.\"\n if [ -z \"$TOTAL\" ] && ! grep -q '/pkg/' <<<\"$SELECTED_SCORED\"; then\n TOTAL=\"n/a (no ./pkg/... package selected)\"\n fi\nfi\n\n# Fail closed. Every step below is a filter, and an empty filter\n# result looks exactly like \"nothing was wrong\". This gate silently\n# scored zero packages for the whole window in which it still matched\n# the pre-rename module path github.com/kubestellar/hive, while the\n# module had become github.com/hivecommons/hive: TOTAL was\n# \"unavailable\", pkg-states.txt was empty, the scoring loop never ran\n# once, and the job reported success on every PR. A gate that cannot\n# see anything must fail, not pass.\nif [ -z \"$TOTAL\" ]; then\n echo \"COVERAGE GATE FAILED: no coverage data parsed from the shard artifacts.\"\n echo \"coverage-*.out was present but produced no ./pkg/... totals.\"\n exit 1\nfi\n# Same guard for the Crux module on a full run: its shards (the\n# agent slices and the rest buckets holding ./crux/...) must have\n# produced profiles, or the module's floors are vacuously met.\nif [ \"$SELECTION\" != partial ] && [ -z \"$CRUX_TOTAL\" ]; then\n echo \"COVERAGE GATE FAILED: no coverage data parsed for the Crux module (./crux/...).\"\n exit 1\nfi\n\n# Classify every package exactly once from the combined logs. With\n# gotestsum reruns, a package can have an initial FAIL line followed\n# by a final ok line in the same successful shard; score the final\n# successful rerun rather than treating the surfaced flake as a\n# coverage-blocking broken package.\n# ./cmd/... is scored too (#4701): the shards have run cmd tests\n# since the partition change, but coverage floors previously applied\n# to ./pkg/... only, so a CLI package could lose all its tests\n# without the gate noticing. The TOTAL line remains ./pkg/...-only\n# for trend continuity.\ncat test-*.log > cover-run.log\nawk '\n NR == FNR {\n exists[$1] = 1\n next\n }\n $1 == \"ok\" || $1 == \"FAIL\" || $1 == \"?\" {\n if (!exists[$2]) next\n if ($2 ~ /\\/(pkg|cmd)\\// || $2 ~ /\\/crux(\\/|$)/) {\n seen[$2] = 1\n if ($1 == \"ok\") ok[$2] = 1\n else if ($1 == \"FAIL\") fail[$2] = 1\n else if ($1 == \"?\") no_tests[$2] = 1\n }\n next\n }\n /^\\t.*\\t\\tcoverage: 0\\.0% of statements$/ {\n if (exists[$1] && ($1 ~ /\\/(pkg|cmd)\\// || $1 ~ /\\/crux(\\/|$)/)) {\n seen[$1] = 1\n no_tests[$1] = 1\n }\n }\n END {\n for (pkg in seen) {\n if (ok[pkg]) print \"ok\", pkg\n else if (fail[pkg]) print \"FAIL\", pkg\n else if (no_tests[pkg]) print \"?\", pkg\n }\n }\n ' ../existing-pkgs.txt cover-run.log \\\n | LC_ALL=C sort -u > pkg-states.txt\n\n# Second fail-closed guard, for the same reason as the TOTAL one:\n# an empty pkg-states.txt means the scoring loop never executes and\n# every floor is vacuously satisfied.\nif [ ! -s pkg-states.txt ] && { [ \"$PARTIAL\" != true ] || [ -n \"$SELECTED_SCORED\" ]; }; then\n echo \"COVERAGE GATE FAILED: no package pass/fail states parsed from test-*.log.\"\n echo \"No package could be scored against its floor.\"\n exit 1\nfi\n\n# Partial selection: every selected package must have been run and\n# classified \u2014 a selected package missing here was never tested.\n# The no-test-files gate is taken from the whole tree (see \"List\n# packages present in checkout\") so an unselected untested package\n# still fails exactly as it would on a full run.\nif [ \"$PARTIAL\" = true ]; then\n MISSING=\"\"\n for p in $SELECTED_SCORED; do\n awk -v p=\"$p\" '$2 == p { f = 1 } END { exit !f }' pkg-states.txt || MISSING=\"$MISSING $p\"\n done\n if [ -n \"$MISSING\" ]; then\n echo \"COVERAGE GATE FAILED: selected package(s) produced no test result:$MISSING\"\n exit 1\n fi\n while read -r p; do\n [ -n \"$p\" ] || continue\n awk -v p=\"$p\" '$2 == p { f = 1 } END { exit !f }' pkg-states.txt || echo \"? $p\" >> pkg-states.txt\n done < ../no-test-pkgs.txt\nfi\n\n# Floor-map key: cmd packages get a \"cmd/\" prefix so cmd/hivectl can\n# never resolve to pkg/hivectl's floor; pkg packages are keyed by\n# their full path below pkg/ so a nested package can never alias the\n# top-level one sharing its name (v5 has both pkg/spoke and\n# pkg/hub/spoke); the nested Crux module's packages are keyed\n# \"crux/\" (the module root package is \"crux\") so crux/config\n# can never alias pkg/config. See coverage-hourly.yml for the full\n# rationale.\nfloor_key() {\n case \"$1\" in\n */cmd/*) echo \"cmd/${1##*/}\" ;;\n */pkg/*) echo \"${1##*/pkg/}\" ;;\n */crux/*) echo \"crux/${1##*/crux/}\" ;;\n */crux) echo \"crux\" ;;\n *) echo \"${1##*/}\" ;;\n esac\n}\n\nwhile read -r state pkgpath; do\n pkg=$(floor_key \"$pkgpath\")\n case \"$state\" in\n ok)\n # Package states are collapsed above, so an ok means either\n # the package passed immediately or gotestsum reran its flakes\n # to a successful final result.\n pct=$(awk -v p=\"$pkgpath\" '$1 == p {print $2}' pkg-pcts.txt)\n if [ -z \"$pct\" ]; then continue; fi\n int_pct=${pct%.*}\n pkg_threshold=${PKG_THRESHOLD[$pkg]:-$THRESHOLD}\n if [ \"$int_pct\" -lt \"$pkg_threshold\" ]; then\n FAILED=\"${FAILED}${pkg}: ${pct}% (floor ${pkg_threshold}%)\\n\"\n fi\n REPORT=\"${REPORT}${pkg}: ${pct}%\\n\"\n ;;\n FAIL)\n BROKEN=\"${BROKEN}${pkg}: TESTS FAILING\\n\"\n REPORT=\"${REPORT}${pkg}: FAIL\\n\"\n ;;\n \\?)\n case \" $UNTESTED_CMD_MAINS \" in\n *\" $pkg \"*)\n REPORT=\"${REPORT}${pkg}: no tests (exempt thin main)\\n\"\n ;;\n *)\n BROKEN=\"${BROKEN}${pkg}: NO TEST FILES\\n\"\n REPORT=\"${REPORT}${pkg}: no tests\\n\"\n ;;\n esac\n ;;\n esac\ndone < pkg-states.txt\n\n{\n echo \"## Per-package coverage\"\n echo \"\"\n echo \"Total (./pkg/...): ${TOTAL:-unavailable}\"\n echo \"Total (./crux/...): ${CRUX_TOTAL:-unavailable}\"\n echo \"\"\n echo -e \"${REPORT}\"\n} >> \"$GITHUB_STEP_SUMMARY\"\n\nif [ -n \"$BROKEN\" ] || [ -n \"$FAILED\" ]; then\n {\n [ -n \"$BROKEN\" ] && echo -e \"### Packages that cannot be scored\\n${BROKEN}\"\n [ -n \"$FAILED\" ] && echo -e \"### Packages below their floor\\n${FAILED}\"\n } >> \"$GITHUB_STEP_SUMMARY\"\n echo \"\"\n echo \"COVERAGE GATE FAILED:\"\n [ -n \"$BROKEN\" ] && echo -e \"${BROKEN}\"\n [ -n \"$FAILED\" ] && echo -e \"${FAILED}\"\n exit 1\nfi\necho \"All packages meet their coverage floor\" >> \"$GITHUB_STEP_SUMMARY\"\n" + name: coverage + env: + CGO_ENABLED: '1' + KUBERNETES_SERVICE_HOST: '' + KUBERNETES_SERVICE_PORT: '' + ACTIONS_CACHE_SEGMENT_DOWNLOAD_TIMEOUT_MINS: '1' + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + security-required-context-scope: + name: required context scope + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + run-go-security: ${{ steps.scope.outputs.run-go-security }} + steps: + - name: Decide whether Go security checks need real scans + id: scope + env: + GITHUB_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + set -euo pipefail + if [ "${{ true }}" = true ] && + { [ "$GITHUB_EVENT_NAME" != workflow_dispatch ] || [[ "$GITHUB_REF" != refs/tags/hive-integration/* ]]; }; then + echo "::error::Integration candidates require an explicitly dispatched immutable candidate tag" + exit 1 + fi + if [ "${{ github.event_name }}" != "pull_request" ]; then + echo "run-go-security=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + : > changed-files.txt + page=1 + api_root="${GITHUB_API_URL:-https://api.github.com}" + while :; do + curl -fsSL -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github+json" "${api_root}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?per_page=100&page=${page}" -o changed-files-page.json + python3 - <<'PYFILES' >> changed-files.txt + import json + with open('changed-files-page.json', encoding='utf-8') as f: + for item in json.load(f): + print(item['filename']) + PYFILES + count=$(python3 - <<'PYCOUNT' + import json + with open('changed-files-page.json', encoding='utf-8') as f: + print(len(json.load(f))) + PYCOUNT + ) + [ "$count" -lt 100 ] && break + page=$((page + 1)) + done + rm -f changed-files-page.json + run=false + while IFS= read -r path; do + case "$path" in + CHANGELOG.md|changelog.d/*|src/*|NOTICE|.github/workflows/*|.github/scripts/*|.github/release-lines.yml) + run=true + ;; + esac + done < changed-files.txt + echo "run-go-security=${run}" >> "$GITHUB_OUTPUT" + if [ "$run" = true ]; then + echo "Go security checks will run real scans." + else + echo "No Go security paths changed; required scan contexts will be skipped/success." + fi + needs: + - subject + if: ${{ always() && needs.subject.result == 'success' && (success()) }} + env: + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + security-govulncheck: + needs: + - subject + - security-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.security-required-context-scope.result != 'success' || needs.security-required-context-scope.outputs.run-go-security == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: govulncheck (known vulnerabilities) + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + uses: ./.github/actions/go-mod-download-retry + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@v1.1.4 + - name: Scan + working-directory: src + run: govulncheck ./... ./crux/... + env: + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + security-gosec: + needs: + - subject + - security-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.security-required-context-scope.result != 'success' || needs.security-required-context-scope.outputs.run-go-security == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: gosec (insecure patterns) + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + uses: ./.github/actions/go-mod-download-retry + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@v2.29.0 + - name: Scan + working-directory: src + continue-on-error: true + run: gosec -exclude-generated ./... ./crux/... + env: + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + security-golangci-lint: + needs: + - subject + - security-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.security-required-context-scope.result != 'success' || needs.security-required-context-scope.outputs.run-go-security == 'true') && !(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release-gate/'))) }} + name: golangci-lint + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Warm shared Go tool cache (serialize the cold-cache population) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + uses: ./.github/actions/go-mod-download-retry + - uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a + with: + version: v2.13.1 + working-directory: src + args: ./... ./crux/... + skip-cache: true + env: + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + security-action-pins: + name: action pins resolve + needs: + - subject + - security-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.security-required-context-scope.result != 'success' || needs.security-required-context-scope.outputs.run-go-security == 'true')) }} + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Action-pins gate self-test + run: bash src/scripts/test-check-action-pins.sh + - name: Check every pinned action SHA exists + env: + GH_TOKEN: ${{ github.token }} + run: src/scripts/check-action-pins.sh .github/workflows + env: + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + security-notice-drift: + name: NOTICE matches the module graph + needs: + - subject + - security-required-context-scope + if: ${{ always() && needs.subject.result == 'success' && (always() && (needs.security-required-context-scope.result != 'success' || needs.security-required-context-scope.outputs.run-go-security == 'true')) }} + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + - name: Exercise NOTICE drift diagnostics + run: src/scripts/test-check-notice-drift.sh + - name: Exercise generated-NOTICE validation + run: src/scripts/test-validate-generated-notice.sh + - name: Warm shared Go tool cache (serialize the cold-cache population) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e + with: + cache: false + go-version-file: src/go.mod + - name: Guard shared Go cache (fall back when the runner volume is full) + run: bash "$GITHUB_WORKSPACE/.github/scripts/go-cache-guard.sh" + - name: Download Go modules (retry transient proxy resets) + uses: ./.github/actions/go-mod-download-retry + - name: Regenerate NOTICE from the current module graph + run: src/scripts/generate-notice.sh /tmp/NOTICE.generated + - name: Publish the regenerated NOTICE for the autofix workflow + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: notice-generated + path: /tmp/NOTICE.generated + retention-days: 1 + if-no-files-found: error + - name: Record the PR number for the autofix workflow + if: github.event_name == 'pull_request' + run: echo "${{ github.event.pull_request.number }}" > /tmp/pr-number.txt + - name: Publish the PR number for the autofix workflow + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: notice-pr-number + path: /tmp/pr-number.txt + retention-days: 1 + if-no-files-found: error + - name: Fail if the committed NOTICE is stale + run: src/scripts/check-notice-drift.sh NOTICE /tmp/NOTICE.generated + env: + GO_CACHE_GUARD_BUILD_CACHE: ${{ 'job' || 'job' }} + governance-dco: + name: DCO + needs: + - subject + runs-on: ubuntu-latest + timeout-minutes: 15 + outputs: + metadata_digest: ${{ steps.verify.outputs.metadata_digest }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + fetch-depth: 0 + persist-credentials: false + - name: Verify exact current members with trusted readonly policy + id: verify + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + EXPECTED_METADATA_DIGEST: ${{ needs.subject.outputs.metadata_digest }} + GITHUB_TOKEN: ${{ github.token }} + with: + script: | + const policy = require('./.github/scripts/integration-governance.cjs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + const members = await policy.snapshot(github, subject); + const actual = policy.digest(members); + if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); + core.setOutput('metadata_digest', actual); + await policy.verify('dco', subject, members); + governance-changelog: + name: changelog-fragment-guard + needs: + - subject + runs-on: ubuntu-latest + timeout-minutes: 15 + outputs: + metadata_digest: ${{ steps.verify.outputs.metadata_digest }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + fetch-depth: 0 + persist-credentials: false + - name: Verify exact current members with trusted readonly policy + id: verify + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + EXPECTED_METADATA_DIGEST: ${{ needs.subject.outputs.metadata_digest }} + GITHUB_TOKEN: ${{ github.token }} + with: + script: | + const policy = require('./.github/scripts/integration-governance.cjs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + const members = await policy.snapshot(github, subject); + const actual = policy.digest(members); + if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); + core.setOutput('metadata_digest', actual); + await policy.verify('changelog', subject, members); + governance-contents: + name: verify PR contents + needs: + - subject + runs-on: ubuntu-latest + timeout-minutes: 15 + outputs: + metadata_digest: ${{ steps.verify.outputs.metadata_digest }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + fetch-depth: 0 + persist-credentials: false + - name: Verify exact current members with trusted readonly policy + id: verify + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + EXPECTED_METADATA_DIGEST: ${{ needs.subject.outputs.metadata_digest }} + GITHUB_TOKEN: ${{ github.token }} + with: + script: | + const policy = require('./.github/scripts/integration-governance.cjs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + const members = await policy.snapshot(github, subject); + const actual = policy.digest(members); + if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); + core.setOutput('metadata_digest', actual); + await policy.verify('contents', subject, members); + governance-attribution: + name: Sign-off survives the squash + needs: + - subject + runs-on: ubuntu-latest + timeout-minutes: 15 + outputs: + metadata_digest: ${{ steps.verify.outputs.metadata_digest }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + fetch-depth: 0 + persist-credentials: false + - name: Verify exact current members with trusted readonly policy + id: verify + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + EXPECTED_METADATA_DIGEST: ${{ needs.subject.outputs.metadata_digest }} + GITHUB_TOKEN: ${{ github.token }} + with: + script: | + const policy = require('./.github/scripts/integration-governance.cjs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + const members = await policy.snapshot(github, subject); + const actual = policy.digest(members); + if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); + core.setOutput('metadata_digest', actual); + await policy.verify('attribution', subject, members); receipt: name: integration producer receipt - needs: [subject, ci, tests, security] + needs: + - subject + - ci-required-context-scope + - ci-build-and-test + - ci-docker + - ci-overlayfs-exec-guard + - tests-required-context-scope + - tests-test-hub + - tests-test-sliced + - tests-test-agent + - tests-list-packages + - tests-test-rest + - tests-test-dashboard-shuffle + - tests-test + - tests-coverage + - security-required-context-scope + - security-govulncheck + - security-gosec + - security-golangci-lint + - security-action-pins + - security-notice-drift + - governance-dco + - governance-changelog + - governance-contents + - governance-attribution if: ${{ always() && needs.subject.result == 'success' }} runs-on: ubuntu-latest timeout-minutes: 10 permissions: contents: read + actions: read + checks: read id-token: write steps: - - name: Bind exact receipt bytes to this isolated finalizer job - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - env: - SUBJECT_MANIFEST: ${{ inputs.manifest }} - TECHNICAL_OUTCOMES: ${{ toJSON(needs) }} - with: - script: | - const crypto = require('node:crypto'); - const fs = require('node:fs'); - const subject = JSON.parse(process.env.SUBJECT_MANIFEST); - const needs = JSON.parse(process.env.TECHNICAL_OUTCOMES); - const payload = Buffer.from(JSON.stringify({ - schema: 1, - protocol: 'integration-producer-receipt-v1', - subject, - runID: process.env.GITHUB_RUN_ID, - runAttempt: process.env.GITHUB_RUN_ATTEMPT, - outcomes: {ci: needs.ci.result, tests: needs.tests.result, security: needs.security.result}, - }), 'utf8'); - const digest = crypto.createHash('sha256').update(payload).digest('hex'); - const token = await core.getIDToken(`hive-integration-producer-v1/${digest}`); - core.setSecret(token); - fs.mkdirSync('.integration-producer', {recursive: true}); - fs.writeFileSync('.integration-producer/receipt.json', JSON.stringify({ - schema: 1, payload: payload.toString('base64'), token, - }), {flag: 'wx', mode: 0o600}); - core.info(`Recorded producer identity for ${subject.id}; passing CI and live policy require independent verification.`); - - name: Publish immutable attempt-specific producer receipt - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: integration-producer-receipt-${{ github.run_attempt }} - path: .integration-producer/receipt.json - include-hidden-files: true - if-no-files-found: error - retention-days: 30 + - name: Bind exact receipt bytes to this isolated finalizer job + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 + env: + SUBJECT_MANIFEST: ${{ inputs.manifest }} + TECHNICAL_OUTCOMES: ${{ toJSON(needs) }} + REQUIRED_CONTEXT_JOBS: '{"DCO": "governance-dco", "Sign-off survives the squash": "governance-attribution", "build-and-test": "ci-build-and-test", "changelog-fragment-guard": "governance-changelog", "coverage": "tests-coverage", "gate": "subject", "golangci-lint": "security-golangci-lint", "gosec (insecure patterns)": "security-gosec", "govulncheck (known vulnerabilities)": "security-govulncheck", "test": "tests-test", "verify PR contents": "governance-contents"}' + with: + script: | + const crypto = require('node:crypto'); + const fs = require('node:fs'); + const subject = JSON.parse(process.env.SUBJECT_MANIFEST); + const needs = JSON.parse(process.env.TECHNICAL_OUTCOMES); + const metadataDigest = needs.subject.outputs.metadata_digest; + if (!/^[a-f0-9]{64}$/.test(metadataDigest || '')) throw new Error('Missing exact member governance binding'); + for (const [id, job] of Object.entries(needs)) { + if (id.startsWith('governance-') && job.outputs.metadata_digest !== metadataDigest) { + throw new Error('Member metadata drifted during governance verification'); + } + } + const runID = Number(process.env.GITHUB_RUN_ID), attempt = Number(process.env.GITHUB_RUN_ATTEMPT); + const args = {...context.repo, run_id: runID}; + const {data: run} = await github.rest.actions.getWorkflowRun(args); + const {data: jobs} = await github.rest.actions.listJobsForWorkflowRunAttempt({...args, attempt_number: attempt, per_page: 100}); + const {data: checks} = await github.rest.checks.listForRef({...context.repo, ref: context.sha, filter: 'all', per_page: 100}); + if (run.run_attempt !== attempt || run.head_sha !== context.sha || + jobs.total_count !== jobs.jobs.length || checks.total_count !== checks.check_runs.length) { + throw new Error('Latest exact-attempt job/check cohort is unknown or truncated'); + } + const contexts = {}; + for (const [name, id] of Object.entries(JSON.parse(process.env.REQUIRED_CONTEXT_JOBS))) { + const matches = jobs.jobs.filter(job => job.name === name); + if (matches.length !== 1) throw new Error(`Missing/ambiguous actual required job ${name}`); + const job = matches[0], checkID = Number(job.check_run_url.split('/').at(-1)); + const check = checks.check_runs.find(item => item.id === checkID); + if (!check || job.run_id !== runID || job.head_sha !== context.sha || + check.name !== name || check.head_sha !== context.sha || check.check_suite.id !== run.check_suite_id || + check.app.id !== 15368 || job.status !== 'completed' || check.status !== 'completed' || + check.conclusion !== job.conclusion || job.conclusion !== needs[id].result) { + throw new Error(`Required context ${name} is not its actual exact-subject Actions producer`); + } + contexts[name] = {jobID: job.id, checkID, appID: check.app.id, suiteID: check.check_suite.id, conclusion: job.conclusion}; + } + const payload = Buffer.from(JSON.stringify({ + schema: 2, + protocol: 'integration-producer-receipt-v2', + subject, + runID: process.env.GITHUB_RUN_ID, + runAttempt: process.env.GITHUB_RUN_ATTEMPT, + metadataDigest, + contexts, + }), 'utf8'); + const digest = crypto.createHash('sha256').update(payload).digest('hex'); + const token = await core.getIDToken(`hive-integration-producer-v1/${digest}`); + core.setSecret(token); + fs.mkdirSync('.integration-producer', {recursive: true}); + fs.writeFileSync('.integration-producer/receipt.json', JSON.stringify({ + schema: 1, payload: payload.toString('base64'), token, + }), {flag: 'wx', mode: 0o600}); + core.info(`Recorded producer identity for ${subject.id}; passing CI and live policy require independent verification.`); + - name: Publish immutable attempt-specific producer receipt + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 + with: + name: integration-producer-receipt-${{ github.run_attempt }} + path: .integration-producer/receipt.json + include-hidden-files: true + if-no-files-found: error + retention-days: 30 diff --git a/.github/workflows/integration-technical-v2-ci.yml b/.github/workflows/integration-technical-v2-ci.yml index c2354fbfe7..601fc8cef0 100644 --- a/.github/workflows/integration-technical-v2-ci.yml +++ b/.github/workflows/integration-technical-v2-ci.yml @@ -94,7 +94,9 @@ jobs: || { curl -sS https://bootstrap.pypa.io/get-pip.py | python3 - --user -q --break-system-packages && python3 -m pip install --user -q --break-system-packages pyyaml; } - name: Check readonly candidate CI generation working-directory: . - run: python3 .github/scripts/generate-integration-ci.py --check + run: | + python3 .github/scripts/generate-integration-ci.py --check + python3 .github/scripts/test-generate-integration-ci.py - name: Warm shared Go tool cache (serialize the cold-cache population) run: bash "$GITHUB_WORKSPACE/.github/scripts/go-toolcache-guard.sh" - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e @@ -331,7 +333,7 @@ jobs: run: node --test src/pkg/hivectl/commands/*.test.js - name: Integration candidate materializer contracts working-directory: . - run: node --test .github/scripts/integration-materialize.test.cjs + run: node --test .github/scripts/integration-*.test.cjs - name: Contributor Relay Syntax + Tests working-directory: . run: | diff --git a/.github/workflows/v2-ci.yml b/.github/workflows/v2-ci.yml index b42d8910bb..e106acf2ac 100644 --- a/.github/workflows/v2-ci.yml +++ b/.github/workflows/v2-ci.yml @@ -148,7 +148,9 @@ jobs: - name: Check readonly candidate CI generation working-directory: . - run: python3 .github/scripts/generate-integration-ci.py --check + run: | + python3 .github/scripts/generate-integration-ci.py --check + python3 .github/scripts/test-generate-integration-ci.py # Populate the shared node-local Go tool cache under the runner pods' # node-wide lock before setup-go, so parallel jobs on a cold cache (a @@ -912,7 +914,7 @@ jobs: - name: Integration candidate materializer contracts working-directory: . - run: node --test .github/scripts/integration-materialize.test.cjs + run: node --test .github/scripts/integration-*.test.cjs # bin/contributor-relay.js used to carry the source under a misleading # .sh name (kubestellar/hive#6429), which needed a copy trick for diff --git a/changelog.d/added-integration-candidate-contexts.md b/changelog.d/added-integration-candidate-contexts.md new file mode 100644 index 0000000000..dfa438b3f3 --- /dev/null +++ b/changelog.d/added-integration-candidate-contexts.md @@ -0,0 +1 @@ +- Trusted integration candidates now compose real required CI jobs and bind read-only member-governance verification to signed exact-job receipts; execution remains opt-in and OFF by default, with protected-promotion qualification still required. diff --git a/src/docs/integration-orchestration.md b/src/docs/integration-orchestration.md index 7642cd3a39..9f617b77d9 100644 --- a/src/docs/integration-orchestration.md +++ b/src/docs/integration-orchestration.md @@ -5,6 +5,61 @@ and GitHub's native queue. It is not a merge engine and does not activate either authority. Every existing CI, review, trust, DCO, coverage, soak, hold and current-base guard remains authoritative. Nothing deploys automatically. +## Trusted candidate required-context profile + +The candidate entry workflow is generated from +`.github/integration-candidate.template.yml` and the existing technical CI +sources by `.github/scripts/generate-integration-ci.py`. Its six technical +required contexts execute the actual top-level build, lint, test, coverage, +gosec and govulncheck jobs, with their full prerequisite DAG. They are not +aliases of reusable-workflow checks or copied author-head statuses. Every +technical job, including jobs using `always()`, requires successful immutable +subject validation before execution. Candidate shard cancellation cannot count +as complete testing. + +The five governance contexts run trusted read-only policy: + +* `gate` validates the immutable tag, repository, ordered parents/trees, + workflow closure and exact shared single-attempt owner. Candidates cannot + publish release images. This gate is **not** an ARM/Docker build receipt. +* `DCO` validates the full introduced commit range, without bot/waiver + shortcuts, and explicitly checks each generated merge's own author signoff. +* `changelog-fragment-guard` validates every member separately against the + immutable base. One member's fragment cannot excuse another member. Combined + citation checks still apply; candidate validation never autofixes, pushes + or comments. +* `verify PR contents` runs a read-only adaptation of the pure title/type and + issue-reference rules in `kubernetes-sigs/kubebuilder-release-tools` commit + `012269a88fa4c034a0acf1ba84c26b195c0dbab4` (v0.4.3, Apache-2.0). It does not + execute the advisory image wrapper, grant its checks-writing permissions, + silently accept an unavailable image, or impersonate the DCO App. Unsupported + titles, including prefixes not accepted by that immutable policy, fail + explicitly rather than nominally succeeding. +* `Sign-off survives the squash` validates the original exact member heads and + authors under their reviewed merge policy. The candidate itself is a tested + merge object, not a fabricated bot-authored squash PR. + +Candidate receipt schema 2 signs the actual job/check/App/suite identities and +conclusions for all eleven contexts, plus the exact subject/run/attempt and a +digest of member author, head/ref, base identity, draft, title, body and labels. +Only the isolated OIDC finalizer has `id-token: write`; technical/control jobs +have no write authority. Missing, duplicate, skipped, foreign-head or +wrong-producer jobs cannot become passing candidate proof. The observer +verifies those physical identities against actual Actions/check observations; +the live promotion guard re-reads current member metadata. State/base/time +changes from a documented exact-prefix merge do not themselves invalidate +otherwise identical metadata. Historical schema 1 remains replayable, but +cannot satisfy the new literal protected-context profile. + +This source profile does **not** enable the producer policy, create authority, +change GitHub protection or App permissions, dispatch candidates, deploy a +runtime, or replace isolated protected-promotion qualification. A bounded +read on 2026-10-31 found no resolved v5 rulesets and all eleven classic required +contexts unbound to a specific App; that user-credential observation is not +proof that the live installation App can promote. Any additional required +image/architecture or producer contract must be genuinely qualified, not +inferred from a check name. Execution remains OFF until separately authorized. + ## Exact protected-promotion protocol The authoring layer remains distinct from separately opted-in Hive-owned diff --git a/src/pkg/convergence/integration/execution_archive.go b/src/pkg/convergence/integration/execution_archive.go index 7440ac4416..36c3e9aa32 100644 --- a/src/pkg/convergence/integration/execution_archive.go +++ b/src/pkg/convergence/integration/execution_archive.go @@ -190,20 +190,39 @@ func validateExecutionArchiveBody(proof ExecutionProof) error { return err } var payload struct { - Schema int `json:"schema"` - Protocol string `json:"protocol"` - Subject forgestate.IntegrationCandidateSubject `json:"subject"` - RunID string `json:"runID"` - Attempt string `json:"runAttempt"` - Outcomes struct{ CI, Tests, Security string } `json:"outcomes"` + Schema int `json:"schema"` + Protocol string `json:"protocol"` + Subject forgestate.IntegrationCandidateSubject `json:"subject"` + RunID string `json:"runID"` + Attempt string `json:"runAttempt"` + Outcomes struct{ CI, Tests, Security string } `json:"outcomes"` + MetadataDigest string `json:"metadataDigest"` + Contexts map[string]forgestate.IntegrationContextReceipt `json:"contexts"` } if err := json.NewDecoder(bytes.NewReader(a.Payload)).Decode(&payload); err != nil { return err } - if payload.Schema != 1 || payload.Protocol != "integration-producer-receipt-v1" || + passed := payload.Schema == 1 && payload.Protocol == "integration-producer-receipt-v1" && + payload.Outcomes.CI == "success" && payload.Outcomes.Tests == "success" && payload.Outcomes.Security == "success" + if payload.Schema == 2 && payload.Protocol == "integration-producer-receipt-v2" { + passed = forgestate.IntegrationContextsPassed(payload.Contexts, payload.MetadataDigest) + for _, record := range payload.Contexts { + found := false + for _, checkID := range a.CheckIDs { + if record.CheckID == checkID { + found = true + } + } + if !found || record.SuiteID != a.SuiteID { + return fmt.Errorf("archived signed governance check differs from retained actual cohort") + } + } + } + if !(payload.Schema == 1 && payload.Protocol == "integration-producer-receipt-v1" || + payload.Schema == 2 && payload.Protocol == "integration-producer-receipt-v2") || !payload.Subject.SameCore(proof.Subject) || payload.RunID != strconv.FormatInt(proof.RunID, 10) || payload.Attempt != strconv.Itoa(proof.Attempt) || - proof.State == Passed && (payload.Outcomes.CI != "success" || payload.Outcomes.Tests != "success" || payload.Outcomes.Security != "success") { + (proof.State == Passed || proof.ObservedState == Passed) && !passed { return fmt.Errorf("archived payload changed exact candidate/outcome binding") } return nil diff --git a/src/pkg/convergence/integration/execution_archive_test.go b/src/pkg/convergence/integration/execution_archive_test.go index 0671ce5899..d3bab36e8e 100644 --- a/src/pkg/convergence/integration/execution_archive_test.go +++ b/src/pkg/convergence/integration/execution_archive_test.go @@ -69,6 +69,62 @@ func executionSignArchive(t *testing.T, archive *ExecutionArchive, key *rsa.Priv archive.Token = signed } +func TestExecutionV2GovernanceArchiveRejectsMissingFalseGreenOrForeignPhysicalChecks(t *testing.T) { + key, err := rsa.GenerateKey(rand.Reader, 2048) + if err != nil { + t.Fatal(err) + } + for _, scenario := range []string{"passed", "missing", "foreign-check", "foreign-suite", "skipped", "metadata", "protocol", "superseded-false-green"} { + t.Run(scenario, func(t *testing.T) { + proof := executionProofFixture() + proof.State, proof.ObservedState = Passed, Passed + proof.Archive = executionSignedArchive(t, proof, key) + contexts := map[string]forgestate.IntegrationContextReceipt{} + for i, name := range forgestate.IntegrationRequiredContexts() { + record := forgestate.IntegrationContextReceipt{JobID: int64(100 + i), CheckID: int64(200 + i), + AppID: 15368, SuiteID: proof.Archive.SuiteID, Conclusion: "success"} + contexts[name] = record + proof.Archive.CheckIDs = append(proof.Archive.CheckIDs, record.CheckID) + } + metadata, protocol := strings.Repeat("a", 64), "integration-producer-receipt-v2" + record := contexts["DCO"] + switch scenario { + case "missing": + delete(contexts, "DCO") + case "foreign-check": + record.CheckID = 9999 + contexts["DCO"] = record + case "foreign-suite": + record.SuiteID++ + contexts["DCO"] = record + case "skipped", "superseded-false-green": + record.Conclusion = "skipped" + contexts["DCO"] = record + if scenario == "superseded-false-green" { + proof.State = Superseded + } + case "metadata": + metadata = "" + case "protocol": + protocol = "unbound" + } + proof.Archive.Payload, err = json.Marshal(map[string]any{ + "schema": 2, "protocol": protocol, "subject": proof.Subject, + "runID": strconv.FormatInt(proof.RunID, 10), "runAttempt": strconv.Itoa(proof.Attempt), + "contexts": contexts, "metadataDigest": metadata, + }) + if err != nil { + t.Fatal(err) + } + executionSignArchive(t, proof.Archive, key, proof.Subject.Repo, proof.RunID, proof.Attempt) + err = validateExecutionArchive(proof) + if (scenario == "passed") != (err == nil) { + t.Fatalf("scenario %s: %v", scenario, err) + } + }) + } +} + func TestExecutionMaterializerPrivateReplayAndPartialPrefix(t *testing.T) { store, cfg, in := executionAdmissionFixture(t) admitted, err := store.PlanExecution(cfg, in) diff --git a/src/pkg/dashboard/integration_execution_promotion.go b/src/pkg/dashboard/integration_execution_promotion.go index 8a8650ac92..c6a5345649 100644 --- a/src/pkg/dashboard/integration_execution_promotion.go +++ b/src/pkg/dashboard/integration_execution_promotion.go @@ -263,6 +263,12 @@ func (s *Server) executionPromotionGuard(ctx context.Context, store *integration if err := s.executionLiveAuthority(ctx, cfg, scope, protection); err != nil { return err } + if refreshed.Archive == nil { + return fmt.Errorf("private signed candidate receipt unavailable") + } + if err := s.deps.GHClient.VerifyIntegrationCandidateGovernance(ctx, proof.Subject, refreshed.Archive.Payload); err != nil { + return err + } // Review/hold/head observations invalidate eligibility, not the immutable // technical payload. Restore only after this complete live evaluation. revision := refreshed.EligibilityRevision diff --git a/src/pkg/forgestate/integration_contexts.go b/src/pkg/forgestate/integration_contexts.go new file mode 100644 index 0000000000..01e6365da6 --- /dev/null +++ b/src/pkg/forgestate/integration_contexts.go @@ -0,0 +1,44 @@ +package forgestate + +import ( + "crypto/sha256" + "encoding/hex" + "strings" +) + +type IntegrationContextReceipt struct { + JobID int64 `json:"jobID"` + CheckID int64 `json:"checkID"` + AppID int64 `json:"appID"` + SuiteID int64 `json:"suiteID"` + Conclusion string `json:"conclusion"` +} + +func IntegrationRequiredContexts() []string { + return []string{"gate", "DCO", "build-and-test", "test", "coverage", "golangci-lint", + "gosec (insecure patterns)", "govulncheck (known vulnerabilities)", "changelog-fragment-guard", + "verify PR contents", "Sign-off survives the squash"} +} + +func IntegrationContextsPassed(contexts map[string]IntegrationContextReceipt, metadata string) bool { + raw, err := hex.DecodeString(metadata) + if err != nil || len(raw) != sha256.Size || metadata != strings.ToLower(metadata) || strings.Trim(metadata, "0") == "" || + len(contexts) != len(IntegrationRequiredContexts()) { + return false + } + jobs, checks := map[int64]bool{}, map[int64]bool{} + var appID, suiteID int64 + for _, name := range IntegrationRequiredContexts() { + record, exists := contexts[name] + if !exists || record.JobID <= 0 || record.CheckID <= 0 || record.AppID <= 0 || record.SuiteID <= 0 || + record.Conclusion != "success" || jobs[record.JobID] || checks[record.CheckID] { + return false + } + if appID != 0 && (record.AppID != appID || record.SuiteID != suiteID) { + return false + } + appID, suiteID = record.AppID, record.SuiteID + jobs[record.JobID], checks[record.CheckID] = true, true + } + return true +} diff --git a/src/pkg/forgestate/integration_contexts_test.go b/src/pkg/forgestate/integration_contexts_test.go new file mode 100644 index 0000000000..416be1a8c2 --- /dev/null +++ b/src/pkg/forgestate/integration_contexts_test.go @@ -0,0 +1,40 @@ +package forgestate + +import ( + "strings" + "testing" +) + +func TestIntegrationContextsRequireEveryPhysicalProducerAndSuccess(t *testing.T) { + makeRecords := func() map[string]IntegrationContextReceipt { + out := map[string]IntegrationContextReceipt{} + for i, name := range IntegrationRequiredContexts() { + out[name] = IntegrationContextReceipt{JobID: int64(i + 1), CheckID: int64(i + 101), AppID: 9, SuiteID: 10, Conclusion: "success"} + } + return out + } + if !IntegrationContextsPassed(makeRecords(), strings.Repeat("a", 64)) { + t.Fatal("complete actual success cohort rejected") + } + for _, invalid := range []string{"", strings.Repeat("0", 64), strings.Repeat("A", 64), strings.Repeat("g", 64)} { + if IntegrationContextsPassed(makeRecords(), invalid) { + t.Fatalf("invalid metadata digest accepted: %s", invalid) + } + } + for _, mutate := range []func(map[string]IntegrationContextReceipt){ + func(r map[string]IntegrationContextReceipt) { delete(r, "DCO") }, + func(r map[string]IntegrationContextReceipt) { r["fake"] = r["DCO"] }, + func(r map[string]IntegrationContextReceipt) { v := r["DCO"]; v.JobID = 0; r["DCO"] = v }, + func(r map[string]IntegrationContextReceipt) { v := r["DCO"]; v.CheckID = 0; r["DCO"] = v }, + func(r map[string]IntegrationContextReceipt) { v := r["DCO"]; v.AppID = 0; r["DCO"] = v }, + func(r map[string]IntegrationContextReceipt) { v := r["DCO"]; v.SuiteID = 0; r["DCO"] = v }, + func(r map[string]IntegrationContextReceipt) { v := r["DCO"]; v.Conclusion = "skipped"; r["DCO"] = v }, + func(r map[string]IntegrationContextReceipt) { r["DCO"] = r["gate"] }, + } { + records := makeRecords() + mutate(records) + if IntegrationContextsPassed(records, strings.Repeat("a", 64)) { + t.Fatal("incomplete/false-green actual context accepted") + } + } +} diff --git a/src/pkg/github/integration_candidate_governance.go b/src/pkg/github/integration_candidate_governance.go new file mode 100644 index 0000000000..f506a78537 --- /dev/null +++ b/src/pkg/github/integration_candidate_governance.go @@ -0,0 +1,122 @@ +package github + +import ( + "context" + "crypto/sha256" + "encoding/hex" + "encoding/json" + "fmt" + "sort" + "strings" + + gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/forgestate" +) + +func integrationGovernanceHash(value string) string { + digest := sha256.Sum256([]byte(value)) + return hex.EncodeToString(digest[:]) +} + +func integrationGovernanceRow(pr *gh.PullRequest) []any { + labels := make([]string, 0, len(pr.Labels)) + for _, label := range pr.Labels { + labels = append(labels, integrationGovernanceHash(label.GetName())) + } + sort.Strings(labels) + return []any{pr.GetNumber(), pr.GetHead().GetSHA(), pr.GetBase().GetRepo().GetFullName(), + integrationGovernanceHash(pr.GetBase().GetRef()), pr.GetUser().GetID(), pr.GetUser().GetLogin(), + pr.GetDraft(), integrationGovernanceHash(pr.GetTitle()), integrationGovernanceHash(pr.GetBody()), labels, + integrationGovernanceHash(pr.GetHead().GetRef())} +} + +// VerifyIntegrationCandidateGovernance revalidates mutable member policy, not +// author-head check results. State/base advancement from an exact documented +// prefix merge deliberately does not change the immutable metadata digest. +func (c *Client) VerifyIntegrationCandidateGovernance(ctx context.Context, subject forgestate.IntegrationCandidateSubject, payload []byte) error { + var receipt integrationCandidateReceipt + if err := json.Unmarshal(payload, &receipt); err != nil { + return err + } + if receipt.Schema == 1 { + return nil // Historical v1 remains readable; new protected names require v2. + } + if receipt.Schema != 2 || receipt.Protocol != "integration-producer-receipt-v2" || + !receipt.Subject.SameCore(subject) || !forgestate.IntegrationContextsPassed(receipt.Contexts, receipt.MetadataDigest) { + return fmt.Errorf("complete signed candidate governance/context binding unavailable") + } + if c == nil || c.client == nil || len(subject.Members) == 0 || len(subject.Members) > integrationCandidateMaxMembers || + len(subject.Members) != len(subject.Prefixes) { + return fmt.Errorf("bounded candidate governance reader unavailable") + } + parts := strings.SplitN(subject.Repo, "/", 2) + if len(parts) != 2 { + return fmt.Errorf("invalid candidate governance repository") + } + rows := make([][]any, 0, len(subject.Members)) + for index, member := range subject.Members { + pr, _, err := c.client.PullRequests.Get(ctx, parts[0], parts[1], member.PR) + if err != nil { + return err + } + if pr == nil || pr.GetNumber() != member.PR || pr.GetHead().GetSHA() != member.Head || + pr.GetHead().GetRepo().GetFullName() != subject.Repo || pr.GetBase().GetRepo().GetFullName() != subject.Repo || + pr.GetBase().GetRef() != subject.Base || pr.GetDraft() || pr.GetUser().GetID() <= 0 || pr.GetUser().GetLogin() == "" || + !(pr.GetState() == "open" || pr.GetMerged() && pr.GetMergeCommitSHA() == subject.Prefixes[index].Commit) { + return fmt.Errorf("candidate governance member %d changed or is not its exact known prefix", member.PR) + } + rows = append(rows, integrationGovernanceRow(pr)) + } + raw, err := json.Marshal(rows) + if err != nil { + return err + } + if integrationGovernanceHash(string(raw)) != receipt.MetadataDigest { + return fmt.Errorf("candidate member title/body/labels/author/head policy changed; old proof cannot authorize promotion") + } + return nil +} + +func bindCandidateContextReceipt(receipt integrationCandidateReceipt, run *gh.WorkflowRun, jobs []*gh.WorkflowJob, checks []*gh.CheckRun, appID int64) error { + if receipt.Schema == 1 { + return nil + } + if len(receipt.Contexts) != len(forgestate.IntegrationRequiredContexts()) { + return fmt.Errorf("signed required context cohort incomplete") + } + seenJobs, seenChecks := map[int64]bool{}, map[int64]bool{} + for _, name := range forgestate.IntegrationRequiredContexts() { + record, exists := receipt.Contexts[name] + if !exists || record.JobID <= 0 || record.CheckID <= 0 || record.AppID != appID || + record.SuiteID != run.GetCheckSuiteID() || seenJobs[record.JobID] || seenChecks[record.CheckID] { + return fmt.Errorf("signed context %q producer or physical identity differs", name) + } + seenJobs[record.JobID], seenChecks[record.CheckID] = true, true + var actual *gh.WorkflowJob + for _, job := range jobs { + if job.GetName() == name { + if actual != nil { + return fmt.Errorf("duplicate actual protected context %q", name) + } + actual = job + } + } + if actual == nil || actual.GetID() != record.JobID || actual.GetRunID() != run.GetID() || + actual.GetHeadSHA() != run.GetHeadSHA() || actual.GetStatus() != "completed" || + actual.GetConclusion() != record.Conclusion || !strings.HasSuffix(actual.GetCheckRunURL(), "/"+fmt.Sprint(record.CheckID)) { + return fmt.Errorf("signed context %q differs from actual exact-run job", name) + } + found := false + for _, check := range checks { + if check.GetID() == record.CheckID && check.GetName() == name && + check.GetHeadSHA() == run.GetHeadSHA() && check.GetCheckSuite().GetID() == record.SuiteID && + check.GetApp().GetID() == appID && check.GetStatus() == "completed" && check.GetConclusion() == record.Conclusion { + found = true + } + } + if !found { + return fmt.Errorf("signed context %q differs from actual check/app/suite", name) + } + } + return nil +} diff --git a/src/pkg/github/integration_candidate_governance_test.go b/src/pkg/github/integration_candidate_governance_test.go new file mode 100644 index 0000000000..a0fdad00da --- /dev/null +++ b/src/pkg/github/integration_candidate_governance_test.go @@ -0,0 +1,162 @@ +package github + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "net/url" + "strings" + "testing" + + gh "github.com/google/go-github/v72/github" + "github.com/hivecommons/hive/pkg/forgestate" +) + +func governanceReceiptFixture() (integrationCandidateReceipt, *gh.WorkflowRun, []*gh.WorkflowJob, []*gh.CheckRun) { + receipt := integrationCandidateReceipt{Schema: 2, Protocol: "integration-producer-receipt-v2", + MetadataDigest: strings.Repeat("a", 64), Contexts: map[string]forgestate.IntegrationContextReceipt{}} + run := &gh.WorkflowRun{ID: gh.Int64(1), HeadSHA: gh.String(strings.Repeat("b", 40)), CheckSuiteID: gh.Int64(2)} + jobs, checks := []*gh.WorkflowJob{}, []*gh.CheckRun{} + for i, name := range forgestate.IntegrationRequiredContexts() { + record := forgestate.IntegrationContextReceipt{JobID: int64(10 + i), CheckID: int64(110 + i), AppID: 3, SuiteID: 2, Conclusion: "success"} + receipt.Contexts[name] = record + jobs = append(jobs, &gh.WorkflowJob{ID: gh.Int64(record.JobID), RunID: run.ID, HeadSHA: run.HeadSHA, Name: gh.String(name), + CheckRunURL: gh.String("https://api.github.com/checks/" + fmtID(record.CheckID)), Status: gh.String("completed"), Conclusion: gh.String("success")}) + checks = append(checks, &gh.CheckRun{ID: gh.Int64(record.CheckID), Name: gh.String(name), HeadSHA: run.HeadSHA, + CheckSuite: &gh.CheckSuite{ID: run.CheckSuiteID}, App: &gh.App{ID: gh.Int64(3)}, Status: gh.String("completed"), Conclusion: gh.String("success")}) + } + return receipt, run, jobs, checks +} + +func fmtID(value int64) string { + raw, _ := json.Marshal(value) + return string(raw) +} + +func TestCandidateSignedContextsCannotCopyAnotherJobHeadSuiteAppOrAttempt(t *testing.T) { + receipt, run, jobs, checks := governanceReceiptFixture() + if err := bindCandidateContextReceipt(receipt, run, jobs, checks, 3); err != nil { + t.Fatal(err) + } + for _, mutate := range []func(*integrationCandidateReceipt, *[]*gh.WorkflowJob, *[]*gh.CheckRun){ + func(r *integrationCandidateReceipt, _ *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + delete(r.Contexts, "DCO") + }, + func(r *integrationCandidateReceipt, _ *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + r.Contexts["DCO"] = r.Contexts["gate"] + }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { *j = (*j)[1:] }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + *j = append(*j, (*j)[0]) + }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + (*j)[0].HeadSHA = gh.String("other") + }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + (*j)[0].RunID = gh.Int64(9) + }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + (*j)[0].ID = gh.Int64(99) + }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + (*j)[0].Status = gh.String("queued") + }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + (*j)[0].Conclusion = gh.String("skipped") + }, + func(_ *integrationCandidateReceipt, j *[]*gh.WorkflowJob, _ *[]*gh.CheckRun) { + (*j)[0].CheckRunURL = gh.String("wrong") + }, + func(_ *integrationCandidateReceipt, _ *[]*gh.WorkflowJob, c *[]*gh.CheckRun) { *c = (*c)[1:] }, + func(_ *integrationCandidateReceipt, _ *[]*gh.WorkflowJob, c *[]*gh.CheckRun) { + (*c)[0].App.ID = gh.Int64(99) + }, + func(_ *integrationCandidateReceipt, _ *[]*gh.WorkflowJob, c *[]*gh.CheckRun) { + (*c)[0].CheckSuite.ID = gh.Int64(99) + }, + func(_ *integrationCandidateReceipt, _ *[]*gh.WorkflowJob, c *[]*gh.CheckRun) { + (*c)[0].Conclusion = gh.String("failure") + }, + } { + r, actual, j, c := governanceReceiptFixture() + mutate(&r, &j, &c) + if err := bindCandidateContextReceipt(r, actual, j, c, 3); err == nil { + t.Fatal("false-green/missing/wrong physical context accepted") + } + } + if err := bindCandidateContextReceipt(integrationCandidateReceipt{Schema: 1}, nil, nil, nil, 0); err != nil { + t.Fatal("historical contract unreadable", err) + } +} + +func TestCandidateGovernanceBindsMutableMetadataButAllowsExactDocumentedPrefix(t *testing.T) { + subject := forgestate.IntegrationCandidateSubject{Schema: 1, Protocol: "integration-prefix-v1", Engine: "hive", Repo: "o/r", Base: "v5", + BaseSHA: strings.Repeat("a", 40), Policy: strings.Repeat("b", 64), WorkflowTree: strings.Repeat("c", 40), ID: strings.Repeat("d", 64), + Members: []forgestate.IntegrationCandidateMember{{PR: 7, Head: strings.Repeat("e", 40)}}, + Prefixes: []forgestate.IntegrationCandidatePrefix{{Commit: strings.Repeat("f", 40), Tree: strings.Repeat("1", 40)}}} + makePR := func() *gh.PullRequest { + repo := &gh.Repository{FullName: gh.String("o/r")} + return &gh.PullRequest{Number: gh.Int(7), State: gh.String("open"), Title: gh.String("✨ title"), Body: gh.String("body <>&\u2028"), + User: &gh.User{ID: gh.Int64(42), Login: gh.String("author")}, + Base: &gh.PullRequestBranch{Ref: gh.String("v5"), Repo: repo}, Head: &gh.PullRequestBranch{SHA: gh.String(subject.Members[0].Head), Ref: gh.String("feature"), Repo: repo}, + Labels: []*gh.Label{{Name: gh.String("approved")}}} + } + current := makePR() + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if current == nil { + w.WriteHeader(http.StatusServiceUnavailable) + return + } + _ = json.NewEncoder(w).Encode(current) + })) + defer server.Close() + api := gh.NewClient(server.Client()) + api.BaseURL, _ = url.Parse(server.URL + "/") + client := &Client{client: api} + receipt, _, _, _ := governanceReceiptFixture() + receipt.Subject = subject + row, _ := json.Marshal([][]any{integrationGovernanceRow(current)}) + receipt.MetadataDigest = integrationGovernanceHash(string(row)) + payload, _ := json.Marshal(receipt) + if err := client.VerifyIntegrationCandidateGovernance(context.Background(), subject, payload); err != nil { + t.Fatal(err) + } + current.State, current.Merged, current.MergeCommitSHA = gh.String("closed"), gh.Bool(true), gh.String(subject.Prefixes[0].Commit) + if err := client.VerifyIntegrationCandidateGovernance(context.Background(), subject, payload); err != nil { + t.Fatal("exact documented prefix spuriously invalidated", err) + } + for _, mutate := range []func(*gh.PullRequest){ + func(pr *gh.PullRequest) { pr.Title = gh.String("changed") }, + func(pr *gh.PullRequest) { pr.Body = gh.String("changed") }, + func(pr *gh.PullRequest) { pr.Labels = nil }, + func(pr *gh.PullRequest) { pr.Head.Ref = gh.String("sync/v5") }, + func(pr *gh.PullRequest) { pr.Head.SHA = gh.String("other") }, + func(pr *gh.PullRequest) { pr.Base.Ref = gh.String("other") }, + func(pr *gh.PullRequest) { pr.Draft = gh.Bool(true) }, + func(pr *gh.PullRequest) { pr.State = gh.String("closed") }, + func(pr *gh.PullRequest) { + pr.State = gh.String("closed") + pr.Merged = gh.Bool(true) + pr.MergeCommitSHA = gh.String("wrong") + }, + } { + current = makePR() + mutate(current) + if err := client.VerifyIntegrationCandidateGovernance(context.Background(), subject, payload); err == nil { + t.Fatal("changed member policy accepted") + } + } + current = nil + if err := client.VerifyIntegrationCandidateGovernance(context.Background(), subject, payload); err == nil { + t.Fatal("missing API proof accepted") + } + for _, invalid := range [][]byte{[]byte("{"), []byte(`{"schema":3}`), []byte(`{"schema":2,"protocol":"wrong"}`)} { + if err := client.VerifyIntegrationCandidateGovernance(context.Background(), subject, invalid); err == nil { + t.Fatal("invalid contract accepted") + } + } + if err := client.VerifyIntegrationCandidateGovernance(context.Background(), subject, []byte(`{"schema":1}`)); err != nil { + t.Fatal(err) + } +} diff --git a/src/pkg/github/integration_candidate_observation.go b/src/pkg/github/integration_candidate_observation.go index 20e1f18229..0857d12a69 100644 --- a/src/pkg/github/integration_candidate_observation.go +++ b/src/pkg/github/integration_candidate_observation.go @@ -52,12 +52,14 @@ type IntegrationCandidateObservation struct { } type integrationCandidateReceipt struct { - Schema int `json:"schema"` - Protocol string `json:"protocol"` - Subject forgestate.IntegrationCandidateSubject `json:"subject"` - RunID string `json:"runID"` - RunAttempt string `json:"runAttempt"` - Outcomes struct { + Schema int `json:"schema"` + Protocol string `json:"protocol"` + Subject forgestate.IntegrationCandidateSubject `json:"subject"` + RunID string `json:"runID"` + RunAttempt string `json:"runAttempt"` + MetadataDigest string `json:"metadataDigest,omitempty"` + Contexts map[string]forgestate.IntegrationContextReceipt `json:"contexts,omitempty"` + Outcomes struct { CI string `json:"ci"` Tests string `json:"tests"` Security string `json:"security"` @@ -240,11 +242,36 @@ func (c *Client) ReadIntegrationCandidateObservation(ctx context.Context, expect if err := decoder.Decode(&trailing); err != io.EOF { return out, fmt.Errorf("candidate receipt has trailing data") } - if receipt.Schema != 1 || receipt.Protocol != "integration-producer-receipt-v1" || + if !(receipt.Schema == 1 && receipt.Protocol == "integration-producer-receipt-v1" || + receipt.Schema == 2 && receipt.Protocol == "integration-producer-receipt-v2") || receipt.RunID != strconv.FormatInt(expected.RunID, 10) || receipt.RunAttempt != strconv.Itoa(expected.Attempt) || !receipt.Subject.SameCore(expected.Subject) { return out, fmt.Errorf("receipt does not bind the enrolled exact immutable subject and attempt") } + for _, name := range expected.RequiredJobs { + for _, required := range forgestate.IntegrationRequiredContexts() { + if name == required && receipt.Schema != 2 { + return out, fmt.Errorf("protected candidate context profile requires v2 signed actual-job governance") + } + } + } + if err := bindCandidateContextReceipt(receipt, &run, jobs.Jobs, checks.CheckRuns, expected.CheckAppID); err != nil { + return out, err + } + if receipt.Schema == 2 { + for _, name := range forgestate.IntegrationRequiredContexts() { + id := receipt.Contexts[name].CheckID + exists := false + for _, retained := range proof.CheckIDs { + if retained == id { + exists = true + } + } + if !exists { + proof.CheckIDs = append(proof.CheckIDs, id) + } + } + } digest := sha256.Sum256(payload) out.Identity, err = verifier.Verify(ctx, token, payload, IntegrationProducerBinding{ Repo: repo, RepositoryID: expected.RepositoryID, ActorID: expected.ActorID, @@ -271,7 +298,16 @@ func (c *Client) ReadIntegrationCandidateObservation(ctx context.Context, expect out.ArtifactID, out.ArtifactDigest, out.Payload, out.Token = artifactID, artifactDigest, payload, token out.CheckIDs = proof.CheckIDs out.State, out.Detail = "rejected", "actual technical workflow/jobs rejected; provenance alone is not green" - if proof.Passed && receipt.Outcomes.CI == "success" && receipt.Outcomes.Tests == "success" && receipt.Outcomes.Security == "success" { + passed := receipt.Schema == 1 && receipt.Outcomes.CI == "success" && receipt.Outcomes.Tests == "success" && receipt.Outcomes.Security == "success" + if receipt.Schema == 2 { + passed = forgestate.IntegrationContextsPassed(receipt.Contexts, receipt.MetadataDigest) + if passed { + if err := c.VerifyIntegrationCandidateGovernance(ctx, expected.Subject, payload); err != nil { + return out, err + } + } + } + if proof.Passed && passed { out.State, out.Detail = "passed", "exact candidate technical proof verified; author review and live promotion gates remain separate" } return out, nil diff --git a/src/pkg/github/integration_candidate_observation_test.go b/src/pkg/github/integration_candidate_observation_test.go index 08802d9c56..5e1431a45c 100644 --- a/src/pkg/github/integration_candidate_observation_test.go +++ b/src/pkg/github/integration_candidate_observation_test.go @@ -21,7 +21,7 @@ import ( ) func TestIntegrationCandidateObserverBindsActualRunJobCheckArtifactAndOrderedSubject(t *testing.T) { - for _, scenario := range []string{"passed", "rejected", "latest_attempt", "changed_during_read", "wrong_app", "wrong_tree", "missing_job", "digest", "unknown_job_cohort", "wrong_receipt_subject", "materialized", "materialized_partial", "materialized_wrong_closure"} { + for _, scenario := range []string{"passed", "rejected", "latest_attempt", "changed_during_read", "wrong_app", "wrong_tree", "missing_job", "digest", "unknown_job_cohort", "wrong_receipt_subject", "materialized", "materialized_partial", "materialized_wrong_closure", "v2_passed", "v2_missing", "v2_context_app", "v2_metadata"} { t.Run(scenario, func(t *testing.T) { key, binding, claims := producerIdentityFixture(t) subject := forgestate.IntegrationCandidateSubject{ @@ -35,6 +35,15 @@ func TestIntegrationCandidateObserverBindsActualRunJobCheckArtifactAndOrderedSub WorkflowID: 7, CheckAppID: 9, RunID: 3, Attempt: 1, RequiredJobs: []string{"ci / build-and-test"}} materializer := strings.HasPrefix(scenario, "materialized") names := []string{"ci / build-and-test", integrationCandidateFinalizer} + v2 := strings.HasPrefix(scenario, "v2_") + memberPR := &gh.PullRequest{Number: gh.Int(10), State: gh.String("open"), Title: gh.String("✨ feature"), + User: &gh.User{ID: gh.Int64(42), Login: gh.String("author")}, + Base: &gh.PullRequestBranch{Ref: gh.String("v5"), Repo: &gh.Repository{FullName: gh.String(subject.Repo)}}, + Head: &gh.PullRequestBranch{SHA: gh.String(subject.Members[0].Head), Ref: gh.String("feature"), Repo: &gh.Repository{FullName: gh.String(subject.Repo)}}} + if v2 { + expected.RequiredJobs = forgestate.IntegrationRequiredContexts() + names = append(forgestate.IntegrationRequiredContexts(), integrationCandidateFinalizer) + } workflowPath, event, artifactPrefix, filename := integrationCandidateWorkflow, "workflow_dispatch", integrationReceiptArtifact, integrationReceiptFile preparation := IntegrationPreparationRequest{ Schema: 1, Protocol: subject.Protocol, Engine: subject.Engine, Repo: subject.Repo, @@ -52,6 +61,32 @@ func TestIntegrationCandidateObserverBindsActualRunJobCheckArtifactAndOrderedSub if err != nil { t.Fatal(err) } + if v2 { + contexts := map[string]forgestate.IntegrationContextReceipt{} + for i, name := range forgestate.IntegrationRequiredContexts() { + contexts[name] = forgestate.IntegrationContextReceipt{JobID: int64(80 + i), CheckID: int64(100 + i), AppID: 9, SuiteID: 8, Conclusion: "success"} + } + if scenario == "v2_missing" { + delete(contexts, "DCO") + } + if scenario == "v2_context_app" { + record := contexts["DCO"] + record.AppID++ + contexts["DCO"] = record + } + row, rowErr := json.Marshal([][]any{integrationGovernanceRow(memberPR)}) + if rowErr != nil { + t.Fatal(rowErr) + } + payload, err = json.Marshal(map[string]any{"schema": 2, "protocol": "integration-producer-receipt-v2", "subject": subject, + "runID": "3", "runAttempt": "1", "metadataDigest": integrationGovernanceHash(string(row)), "contexts": contexts}) + if err != nil { + t.Fatal(err) + } + if scenario == "v2_metadata" { + memberPR.Body = gh.String("changed after signed governance") + } + } if materializer { workflowPath, event = integrationMaterializerWorkflow, "repository_dispatch" artifactPrefix, filename = integrationMaterializerArtifact, "materialization.json" @@ -135,6 +170,12 @@ func TestIntegrationCandidateObserverBindsActualRunJobCheckArtifactAndOrderedSub if i == 1 { checkID = 4 } + if v2 { + checkID = 100 + i + if i == len(names)-1 { + checkID = 4 + } + } result := "success" if scenario == "rejected" && i == 0 { result = "failure" @@ -160,6 +201,12 @@ func TestIntegrationCandidateObserverBindsActualRunJobCheckArtifactAndOrderedSub if i == 1 { id = 4 } + if v2 { + id = 100 + i + if i == len(names)-1 { + id = 4 + } + } if scenario == "rejected" && i == 0 { result = "failure" } @@ -167,6 +214,8 @@ func TestIntegrationCandidateObserverBindsActualRunJobCheckArtifactAndOrderedSub "status": "completed", "conclusion": result, "check_suite": map[string]int{"id": 8}, "app": map[string]int{"id": app}}) } emit(map[string]any{"total_count": len(checks), "check_runs": checks}) + case "/repos/owner/repo/pulls/10": + emit(memberPR) case "/repos/owner/repo/actions/runs/3/artifacts": emit(map[string]any{"total_count": 1, "artifacts": []any{map[string]any{"id": 10, "name": artifactPrefix + "1", "size_in_bytes": buffer.Len(), "digest": digest, @@ -231,6 +280,15 @@ func TestIntegrationCandidateObserverBindsActualRunJobCheckArtifactAndOrderedSub } result, err := observer.ReadIntegrationCandidateObservation(context.Background(), expected, verifier, binding.ObservedAt) switch scenario { + case "v2_passed": + if err != nil || result.State != "passed" || len(result.Jobs) != len(names) || + len(result.CheckIDs) != len(names) || result.Identity.FinalizerCheckRunID != 4 { + t.Fatalf("complete actual v2 subject not verified: %+v %v", result, err) + } + case "v2_metadata": + if err == nil || result.State == "passed" { + t.Fatal("metadata drift accepted as passing exact proof") + } case "passed", "rejected": if err != nil || result.State != scenario || result.ArtifactID != 10 || result.Identity.FinalizerCheckRunID != 4 || len(result.Jobs) != 2 || result.JobCompleteness != "complete" { diff --git a/src/scripts/check-changelog-fragment.sh b/src/scripts/check-changelog-fragment.sh index a270dee7c2..42715385c2 100755 --- a/src/scripts/check-changelog-fragment.sh +++ b/src/scripts/check-changelog-fragment.sh @@ -11,6 +11,7 @@ if [ -z "$base_ref" ]; then exit 2 fi has_no_changelog_label="${HAS_NO_CHANGELOG_LABEL:-false}" +diff_base="${BASE_SHA:-origin/${base_ref}}" # Forward-merge sync PRs (v5-topup.yml / v6-topup.yml and the hand-rolled ones # opened when those conflict) carry the source line's whole history, so the @@ -33,8 +34,8 @@ esac # Two views of the diff: ALL changed paths (deletions included — a PR that only # removes code is still a code change an operator can see), and paths still # present at HEAD (a deleted fragment can be neither validated nor counted). -git diff --name-only "origin/${base_ref}...HEAD" > "$work_dir"/changed-files.txt -git diff --name-only --diff-filter=d "origin/${base_ref}...HEAD" > "$work_dir"/present-files.txt +git diff --name-only "${diff_base}...HEAD" > "$work_dir"/changed-files.txt +git diff --name-only --diff-filter=d "${diff_base}...HEAD" > "$work_dir"/present-files.txt echo "Changed files vs merge base with origin/${base_ref}:" sed 's/^/ /' "$work_dir"/changed-files.txt From 413ddfba4460e560467851ace4c02b62bd3a05c1 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Sat, 31 Oct 2026 08:39:20 -0400 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20fix(integration):=20reject?= =?UTF-8?q?=20degraded=20candidate=20author=20attribution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/scripts/generate-integration-ci.py | 2 +- .github/scripts/integration-governance.cjs | 42 ++++++++++-- .../scripts/integration-governance.test.cjs | 66 +++++++++++++++++++ .github/workflows/integration-candidate.yml | 8 +-- src/docs/integration-orchestration.md | 11 +++- 5 files changed, 117 insertions(+), 12 deletions(-) diff --git a/.github/scripts/generate-integration-ci.py b/.github/scripts/generate-integration-ci.py index 003c40acd8..c5daa5c357 100644 --- a/.github/scripts/generate-integration-ci.py +++ b/.github/scripts/generate-integration-ci.py @@ -216,7 +216,7 @@ def rewrite(value): "const actual = policy.digest(members);\n" "if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted');\n" "core.setOutput('metadata_digest', actual);\n" - f"await policy.verify('{kind}', subject, members);\n" + f"await policy.verify('{kind}', subject, members, github);\n" )}}, ], } diff --git a/.github/scripts/integration-governance.cjs b/.github/scripts/integration-governance.cjs index 636ca31e64..ff8298a944 100644 --- a/.github/scripts/integration-governance.cjs +++ b/.github/scripts/integration-governance.cjs @@ -6,6 +6,7 @@ const fs = require('node:fs'); const path = require('node:path'); const MAX_MEMBERS = 8; const MAX_COMMITS = 1000; +const MAX_AUTHOR_BATCH = 50; const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4'; const sha = value => crypto.createHash('sha256').update(value).digest('hex'); const git = (args, cwd = process.cwd()) => @@ -59,7 +60,34 @@ function run(script, args, cwd, extra = {}) { }); } -async function verify(kind, subject, members) { +async function attributionAuthors(github, subject, members) { + const commits = [...new Set(members.flatMap(pr => + git(['rev-list', '--no-merges', `${subject.baseSHA}..${pr.head.sha}`]).split('\n').filter(Boolean)))]; + if (!github?.graphql || !commits.length || commits.length > MAX_COMMITS) { + throw new Error('Exact bounded commit-author attribution unavailable'); + } + const [owner, name] = subject.repo.split('/'), mapping = []; + for (let start = 0; start < commits.length; start += MAX_AUTHOR_BATCH) { + const batch = commits.slice(start, start + MAX_AUTHOR_BATCH), variables = {owner, name}; + const declarations = ['$owner:String!', '$name:String!'], fields = []; + for (const [index, oid] of batch.entries()) { + declarations.push(`$oid${index}:GitObjectID!`); variables[`oid${index}`] = oid; + fields.push(`c${index}:object(oid:$oid${index}){... on Commit{oid author{user{login}}}}`); + } + const {repository} = await github.graphql(`query(${declarations.join(',')}){repository(owner:$owner,name:$name){nameWithOwner ${fields.join(' ')}}}`, variables); + if (repository?.nameWithOwner !== subject.repo) throw new Error('Commit-author repository differs'); + for (const [index, oid] of batch.entries()) { + const actual = repository[`c${index}`], login = actual?.author?.user?.login; + if (actual?.oid !== oid || !/^[A-Za-z0-9][A-Za-z0-9-]*(?:\[bot\])?$/.test(login || '')) { + throw new Error('Original commit author association unknown; candidate cannot use degraded attribution success'); + } + mapping.push(`${oid}=${login}`); + } + } + return mapping.join(','); +} + +async function verify(kind, subject, members, github) { if (!['dco', 'changelog', 'contents', 'attribution'].includes(kind)) throw new Error('Unknown governance policy'); const root = process.cwd(), source = subject.preparedBy?.sourceSHA; if (!/^[a-f0-9]{40}$/.test(source || '') || @@ -71,13 +99,15 @@ async function verify(kind, subject, members) { for (const pr of members) verifyContents(pr.title); return; } + const tested = subject.prefixes.at(-1).commit; + const range = `${subject.baseSHA}..${tested}`; + const count = Number(git(['rev-list', '--count', range])); + if (!Number.isSafeInteger(count) || count < 1 || count > MAX_COMMITS) throw new Error('Introduced governance commit cohort unknown/too large'); if (kind === 'dco') { - const tested = subject.prefixes.at(-1).commit; - const range = `${subject.baseSHA}..${tested}`; - const count = Number(git(['rev-list', '--count', range])); - if (!Number.isSafeInteger(count) || count < 1 || count > MAX_COMMITS) throw new Error('DCO introduced commit cohort unknown/too large'); run('check-dco-trailers.sh', [String(count), range], root, { DCO_SKIP_BOT_AUTHORS: 'false', DCO_WAIVED_COMMITS: '', DCO_ALLOWLIST_EMAILS: '', + DCO_AUTHOR_LOGIN_MAP: '', DCO_SAME_PERSON_EVIDENCE_REFS: '', + DCO_GITHUB_REPOSITORY: subject.repo, }); for (const prefix of subject.prefixes) { const author = git(['show', '-s', '--format=%an <%ae>', prefix.commit]); @@ -89,11 +119,13 @@ async function verify(kind, subject, members) { return; } if (kind === 'attribution') { + const authors = await attributionAuthors(github, subject, members); for (const pr of members) { run('check-squash-signoff-attribution.sh', [subject.baseSHA, pr.head.sha, pr.user.login], root, { PR_AUTHOR_LOGIN: pr.user.login, PR_MERGE_METHOD: pr.labels.some(label => label.name === 'merge-method/merge') ? 'merge' : '', LANDED_REFS: subject.baseSHA, + DCO_AUTHOR_LOGIN_MAP: authors, }); } return; diff --git a/.github/scripts/integration-governance.test.cjs b/.github/scripts/integration-governance.test.cjs index 5c2f9610c7..35f14881ff 100644 --- a/.github/scripts/integration-governance.test.cjs +++ b/.github/scripts/integration-governance.test.cjs @@ -1,6 +1,9 @@ 'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); +const cp = require('node:child_process'); +const fs = require('node:fs'); +const path = require('node:path'); const policy = require('./integration-governance.cjs'); const head = 'a'.repeat(40), commit = 'b'.repeat(40); @@ -64,3 +67,66 @@ test('unsupported or untrusted helper scope refuses instead of returning green', await assert.rejects(policy.verify('unknown', subject(), [member()])); await assert.rejects(policy.verify('contents', subject(), [member()]), /closure unavailable/); }); + +test('real pinned helpers enforce each original member and reject missing signoff or fragment', () => { + const root = process.cwd(), workspace = path.join(root, '.integration-governance-fixture'); + const helper = path.join(root, '.github/scripts/integration-governance.cjs'); + const env = {...process.env, GITHUB_TOKEN: '', GH_TOKEN: '', GITHUB_REPOSITORY: '', DCO_GITHUB_REPOSITORY: ''}; + const git = (...args) => cp.execFileSync('git', ['-c', 'core.hooksPath=/dev/null', ...args], + {cwd: workspace, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']}).trim(); + const check = (kind, manifest, members, knownAuthor = true) => cp.execFileSync(process.execPath, ['-e', + `const subject = ${JSON.stringify(manifest)}; + const github = {graphql: async (_, variables) => ({repository: {nameWithOwner: subject.repo, + ...Object.fromEntries(Object.entries(variables).filter(([key]) => key.startsWith('oid')).map(([key, oid]) => + [key.replace('oid', 'c'), {oid, author: {user: ${knownAuthor ? "{login:'fixture'}" : "null"}}}]))}})}; + require(${JSON.stringify(helper)}).verify(${JSON.stringify(kind)}, subject, ${JSON.stringify(members)}, github).catch(error => {console.error(error); process.exitCode = 1;})`], + {cwd: workspace, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']}); + assert.equal(fs.existsSync(workspace), false, 'fixture must not overwrite another workspace'); + fs.mkdirSync(workspace); + try { + fs.mkdirSync(path.join(workspace, '.github')); + fs.mkdirSync(path.join(workspace, 'src/scripts'), {recursive: true}); + for (const file of ['check-dco-trailers.sh', 'lib-dco-identity.sh', + 'check-squash-signoff-attribution.sh', 'check-changelog-fragment.sh']) { + fs.copyFileSync(path.join(root, 'src/scripts', file), path.join(workspace, 'src/scripts', file)); + } + fs.writeFileSync(path.join(workspace, '.github/trusted'), 'trusted closure\n'); + git('init', '--initial-branch=base'); + git('config', 'user.name', 'Fixture Author'); + git('config', 'user.email', 'fixture@example.invalid'); + git('config', 'commit.gpgsign', 'false'); + git('add', '.'); git('commit', '-s', '-m', 'Initial trusted helpers'); + const base = git('rev-parse', 'HEAD'), workflowTree = git('rev-parse', 'HEAD:.github'); + git('checkout', '-b', 'feature'); + fs.writeFileSync(path.join(workspace, 'src/code.go'), 'package fixture\n'); + git('add', '.'); git('commit', '-s', '-m', 'Feature initially missing fragment'); + const missingFragment = git('rev-parse', 'HEAD'); + fs.mkdirSync(path.join(workspace, 'changelog.d')); + fs.writeFileSync(path.join(workspace, 'changelog.d/added-fixture.md'), '- Actual fixture feature.\n'); + git('add', '.'); git('commit', '-s', '-m', 'Add own fragment'); + const memberHead = git('rev-parse', 'HEAD'); + git('checkout', 'base'); + git('merge', '--no-ff', 'feature', '-m', 'Candidate\n\nSigned-off-by: Fixture Author '); + const manifest = {repo: 'fixture/repo', base: 'base', baseSHA: base, workflowTree, + preparedBy: {sourceSHA: base}, members: [{pr: 7, head: memberHead}], + prefixes: [{commit: git('rev-parse', 'HEAD')}]}; + const pr = {number: 7, head: {sha: memberHead, ref: 'feature'}, user: {login: 'fixture'}, labels: []}; + for (const kind of ['dco', 'attribution', 'changelog']) assert.doesNotThrow(() => check(kind, manifest, [pr]), kind); + assert.throws(() => check('attribution', manifest, [pr], false), /Command failed/); + const unsignedPrefix = structuredClone(manifest); + unsignedPrefix.prefixes[0].commit = git('commit-tree', 'HEAD^{tree}', '-p', base, '-p', memberHead, '-m', 'Unsigned generated merge'); + assert.throws(() => check('dco', unsignedPrefix, [pr])); + // The combined tree's fragment cannot satisfy another original member. + assert.throws(() => check('changelog', manifest, [{...pr, head: {...pr.head, sha: missingFragment}}])); + git('checkout', '-b', 'unsigned'); + fs.writeFileSync(path.join(workspace, 'src/unsigned.go'), 'package fixture\n'); + git('add', '.'); git('commit', '-m', 'Unsigned introduced commit'); + const bad = structuredClone(manifest); + bad.prefixes[0].commit = git('rev-parse', 'HEAD'); + assert.throws(() => check('dco', bad, [pr])); + // Changing the helper closure is not permission to execute a new checker. + fs.appendFileSync(path.join(workspace, 'src/scripts/check-dco-trailers.sh'), '\n# different helper\n'); + git('add', '.'); git('commit', '-s', '-m', 'Different helper closure'); + assert.throws(() => check('dco', bad, [pr])); + } finally { fs.rmSync(workspace, {recursive: true, force: true}); } +}); diff --git a/.github/workflows/integration-candidate.yml b/.github/workflows/integration-candidate.yml index e850f55e36..23118e4d2f 100644 --- a/.github/workflows/integration-candidate.yml +++ b/.github/workflows/integration-candidate.yml @@ -1988,7 +1988,7 @@ jobs: const actual = policy.digest(members); if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); core.setOutput('metadata_digest', actual); - await policy.verify('dco', subject, members); + await policy.verify('dco', subject, members, github); governance-changelog: name: changelog-fragment-guard needs: @@ -2017,7 +2017,7 @@ jobs: const actual = policy.digest(members); if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); core.setOutput('metadata_digest', actual); - await policy.verify('changelog', subject, members); + await policy.verify('changelog', subject, members, github); governance-contents: name: verify PR contents needs: @@ -2046,7 +2046,7 @@ jobs: const actual = policy.digest(members); if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); core.setOutput('metadata_digest', actual); - await policy.verify('contents', subject, members); + await policy.verify('contents', subject, members, github); governance-attribution: name: Sign-off survives the squash needs: @@ -2075,7 +2075,7 @@ jobs: const actual = policy.digest(members); if (actual !== process.env.EXPECTED_METADATA_DIGEST) throw new Error('Member metadata drifted'); core.setOutput('metadata_digest', actual); - await policy.verify('attribution', subject, members); + await policy.verify('attribution', subject, members, github); receipt: name: integration producer receipt needs: diff --git a/src/docs/integration-orchestration.md b/src/docs/integration-orchestration.md index 9f617b77d9..585f88ca33 100644 --- a/src/docs/integration-orchestration.md +++ b/src/docs/integration-orchestration.md @@ -36,8 +36,12 @@ The five governance contexts run trusted read-only policy: titles, including prefixes not accepted by that immutable policy, fail explicitly rather than nominally succeeding. * `Sign-off survives the squash` validates the original exact member heads and - authors under their reviewed merge policy. The candidate itself is a tested - merge object, not a fabricated bot-authored squash PR. + authors under their reviewed merge policy. Bounded read-only forge GraphQL + batches resolve original commit-author identities before invoking the pinned + checker; an unavailable/unlinked author cannot use its legacy degraded-success + fallback. That context stops explicitly until truthful attribution is + available. The candidate itself is a tested merge object, not a fabricated + bot-authored squash PR. Candidate receipt schema 2 signs the actual job/check/App/suite identities and conclusions for all eleven contexts, plus the exact subject/run/attempt and a @@ -50,6 +54,9 @@ the live promotion guard re-reads current member metadata. State/base/time changes from a documented exact-prefix merge do not themselves invalidate otherwise identical metadata. Historical schema 1 remains replayable, but cannot satisfy the new literal protected-context profile. +Metadata drift invalidates proof; it does not authorize an automatic rerun or +steal an existing dispatch claim. Existing bounded owner-repair/authority rules +still apply. This source profile does **not** enable the producer policy, create authority, change GitHub protection or App permissions, dispatch candidates, deploy a From 4dc7a34e6cc88ac4f294341d8741d9bc8c4c1ef1 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Sat, 31 Oct 2026 08:41:59 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=90=9B=20fix(integration):=20pin=20ex?= =?UTF-8?q?ecutable=20governance=20helper=20closure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/scripts/integration-governance.cjs | 6 +++++- .github/scripts/integration-governance.test.cjs | 9 ++++----- src/docs/integration-orchestration.md | 7 +++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/scripts/integration-governance.cjs b/.github/scripts/integration-governance.cjs index ff8298a944..fcc9b4c0e4 100644 --- a/.github/scripts/integration-governance.cjs +++ b/.github/scripts/integration-governance.cjs @@ -7,6 +7,9 @@ const path = require('node:path'); const MAX_MEMBERS = 8; const MAX_COMMITS = 1000; const MAX_AUTHOR_BATCH = 50; +// This literal is inside the enrolled .github closure. A caller-supplied +// preparedBy.sourceSHA must never choose a new executable verifier tree. +const TRUSTED_SCRIPTS_TREE = 'c1b6e83ee24e5108657ef7f9b15865fd23f4ebce'; const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4'; const sha = value => crypto.createHash('sha256').update(value).digest('hex'); const git = (args, cwd = process.cwd()) => @@ -92,7 +95,8 @@ async function verify(kind, subject, members, github) { const root = process.cwd(), source = subject.preparedBy?.sourceSHA; if (!/^[a-f0-9]{40}$/.test(source || '') || git(['rev-parse', `${source}:.github`]) !== subject.workflowTree || - git(['rev-parse', `${source}:src/scripts`]) !== git(['rev-parse', 'HEAD:src/scripts'])) { + git(['rev-parse', `${source}:src/scripts`]) !== TRUSTED_SCRIPTS_TREE || + git(['rev-parse', 'HEAD:src/scripts']) !== TRUSTED_SCRIPTS_TREE) { throw new Error('Trusted control/helper closure unavailable; no candidate script execution'); } if (kind === 'contents') { diff --git a/.github/scripts/integration-governance.test.cjs b/.github/scripts/integration-governance.test.cjs index 35f14881ff..769a13506d 100644 --- a/.github/scripts/integration-governance.test.cjs +++ b/.github/scripts/integration-governance.test.cjs @@ -85,11 +85,7 @@ test('real pinned helpers enforce each original member and reject missing signof fs.mkdirSync(workspace); try { fs.mkdirSync(path.join(workspace, '.github')); - fs.mkdirSync(path.join(workspace, 'src/scripts'), {recursive: true}); - for (const file of ['check-dco-trailers.sh', 'lib-dco-identity.sh', - 'check-squash-signoff-attribution.sh', 'check-changelog-fragment.sh']) { - fs.copyFileSync(path.join(root, 'src/scripts', file), path.join(workspace, 'src/scripts', file)); - } + fs.cpSync(path.join(root, 'src/scripts'), path.join(workspace, 'src/scripts'), {recursive: true}); fs.writeFileSync(path.join(workspace, '.github/trusted'), 'trusted closure\n'); git('init', '--initial-branch=base'); git('config', 'user.name', 'Fixture Author'); @@ -128,5 +124,8 @@ test('real pinned helpers enforce each original member and reject missing signof fs.appendFileSync(path.join(workspace, 'src/scripts/check-dco-trailers.sh'), '\n# different helper\n'); git('add', '.'); git('commit', '-s', '-m', 'Different helper closure'); assert.throws(() => check('dco', bad, [pr])); + const forgedSource = structuredClone(bad); + forgedSource.preparedBy.sourceSHA = git('rev-parse', 'HEAD'); + assert.throws(() => check('dco', forgedSource, [pr])); } finally { fs.rmSync(workspace, {recursive: true, force: true}); } }); diff --git a/src/docs/integration-orchestration.md b/src/docs/integration-orchestration.md index 585f88ca33..156779faa7 100644 --- a/src/docs/integration-orchestration.md +++ b/src/docs/integration-orchestration.md @@ -43,6 +43,13 @@ The five governance contexts run trusted read-only policy: available. The candidate itself is a tested merge object, not a fabricated bot-authored squash PR. +The verifier's enrolled `.github` closure contains a literal pin to the +`src/scripts` tree, not merely a comparison against caller-supplied +`preparedBy.sourceSHA`. Both the declared source and checkout must match that +pin before any checker executes. Helper changes require a deliberately reviewed +pin/profile update; choosing the candidate itself as a new source cannot +authorize changed verifier code. + Candidate receipt schema 2 signs the actual job/check/App/suite identities and conclusions for all eleven contexts, plus the exact subject/run/attempt and a digest of member author, head/ref, base identity, draft, title, body and labels. From ca204bbf7202e3f910a8b56fde25afc9506dda64 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Sat, 31 Oct 2026 08:43:42 -0400 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20fix(integration):=20cover=20?= =?UTF-8?q?trusted=20template=20changes=20in=20required=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- .github/scripts/integration-governance.test.cjs | 8 +++++++- .github/workflows/integration-candidate.yml | 2 +- .github/workflows/integration-technical-v2-ci.yml | 2 +- .github/workflows/v2-ci.yml | 4 ++-- src/docs/integration-orchestration.md | 4 ++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/scripts/integration-governance.test.cjs b/.github/scripts/integration-governance.test.cjs index 769a13506d..cff97879e8 100644 --- a/.github/scripts/integration-governance.test.cjs +++ b/.github/scripts/integration-governance.test.cjs @@ -85,7 +85,13 @@ test('real pinned helpers enforce each original member and reject missing signof fs.mkdirSync(workspace); try { fs.mkdirSync(path.join(workspace, '.github')); - fs.cpSync(path.join(root, 'src/scripts'), path.join(workspace, 'src/scripts'), {recursive: true}); + const scripts = cp.execFileSync('git', ['ls-files', '-z', 'src/scripts'], {cwd: root, encoding: 'utf8'}); + for (const file of scripts.split('\0').filter(Boolean)) { + const source = path.join(root, file), target = path.join(workspace, file); + fs.mkdirSync(path.dirname(target), {recursive: true}); + fs.copyFileSync(source, target); + fs.chmodSync(target, fs.statSync(source).mode); + } fs.writeFileSync(path.join(workspace, '.github/trusted'), 'trusted closure\n'); git('init', '--initial-branch=base'); git('config', 'user.name', 'Fixture Author'); diff --git a/.github/workflows/integration-candidate.yml b/.github/workflows/integration-candidate.yml index 23118e4d2f..544777afa0 100644 --- a/.github/workflows/integration-candidate.yml +++ b/.github/workflows/integration-candidate.yml @@ -185,7 +185,7 @@ jobs: run=false while IFS= read -r path; do case "$path" in - CHANGELOG.md|changelog.d/*|src/*|bin/*|config/*|README.md|docs/*|.github/scripts/*|.github/workflows/*) + CHANGELOG.md|changelog.d/*|src/*|bin/*|config/*|README.md|docs/*|.github/scripts/*|.github/workflows/*|.github/integration-candidate.template.yml) run=true ;; esac diff --git a/.github/workflows/integration-technical-v2-ci.yml b/.github/workflows/integration-technical-v2-ci.yml index 601fc8cef0..f63aed8f28 100644 --- a/.github/workflows/integration-technical-v2-ci.yml +++ b/.github/workflows/integration-technical-v2-ci.yml @@ -59,7 +59,7 @@ jobs: run=false while IFS= read -r path; do case "$path" in - CHANGELOG.md|changelog.d/*|src/*|bin/*|config/*|README.md|docs/*|.github/scripts/*|.github/workflows/*) + CHANGELOG.md|changelog.d/*|src/*|bin/*|config/*|README.md|docs/*|.github/scripts/*|.github/workflows/*|.github/integration-candidate.template.yml) run=true ;; esac diff --git a/.github/workflows/v2-ci.yml b/.github/workflows/v2-ci.yml index e106acf2ac..ffab7567b9 100644 --- a/.github/workflows/v2-ci.yml +++ b/.github/workflows/v2-ci.yml @@ -23,7 +23,7 @@ on: # src/**, so this is the same rule applied to the docs outside src/. # Protected-branch monitor/gate workflow changes must run required CI so branch protection can merge the PR. # release PRs touch only these; the required contexts must report — #10795 - paths: ['CHANGELOG.md', 'changelog.d/**', 'src/**', 'bin/**', 'config/**', 'README.md', 'docs/**', '.github/scripts/**', '.github/workflows/**'] + paths: ['CHANGELOG.md', 'changelog.d/**', 'src/**', 'bin/**', 'config/**', 'README.md', 'docs/**', '.github/scripts/**', '.github/workflows/**', '.github/integration-candidate.template.yml'] pull_request: branches: [v4, v5, v6] # Required contexts from this workflow must appear on every PR head. Keep @@ -108,7 +108,7 @@ jobs: run=false while IFS= read -r path; do case "$path" in - CHANGELOG.md|changelog.d/*|src/*|bin/*|config/*|README.md|docs/*|.github/scripts/*|.github/workflows/*) + CHANGELOG.md|changelog.d/*|src/*|bin/*|config/*|README.md|docs/*|.github/scripts/*|.github/workflows/*|.github/integration-candidate.template.yml) run=true ;; esac diff --git a/src/docs/integration-orchestration.md b/src/docs/integration-orchestration.md index 156779faa7..c42072965f 100644 --- a/src/docs/integration-orchestration.md +++ b/src/docs/integration-orchestration.md @@ -73,6 +73,10 @@ contexts unbound to a specific App; that user-credential observation is not proof that the live installation App can promote. Any additional required image/architecture or producer contract must be genuinely qualified, not inferred from a check name. Execution remains OFF until separately authorized. +The composed DAG includes prerequisite/matrix jobs beyond the eleven context +names. Qualification must measure that actual fanout and assigned-runner cost +against explicitly configured admission bounds; eleven names are not an +eleven-job capacity or throughput claim. ## Exact protected-promotion protocol