Skip to content

Commit 8a93557

Browse files
committed
Remove reusable workflow self-ref check
1 parent 4d55442 commit 8a93557

4 files changed

Lines changed: 34 additions & 19 deletions

File tree

.github/workflows/run-agent-task.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,12 @@ jobs:
163163
credential_mode: ${{ steps.execute.outputs.credential_mode }}
164164
declared_artifacts_json: ${{ steps.execute.outputs.declared_artifacts_json }}
165165
steps:
166-
- name: Validate coherent WP Codebox release tag
167-
env:
168-
WORKFLOW_REF: ${{ github.workflow_ref }}
166+
- name: Validate WP Codebox release tag
169167
run: |
170168
if ! [[ "${WP_CODEBOX_RELEASE_REF}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
171169
echo "wp_codebox_release_ref must be an immutable vX.Y.Z release tag" >&2
172170
exit 1
173171
fi
174-
expected_workflow_ref="Automattic/wp-codebox/.github/workflows/run-agent-task.yml@${WP_CODEBOX_RELEASE_REF}"
175-
if [[ "${WORKFLOW_REF}" != "${expected_workflow_ref}" ]]; then
176-
echo "The reusable workflow tag and wp_codebox_release_ref must match exactly" >&2
177-
exit 1
178-
fi
179172
180173
- name: Checkout WP Codebox workflow helpers
181174
uses: actions/checkout@v4

docs/agent-task-reusable-workflow.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,20 @@ with `wp_codebox_release_ref: v0.12.3`. The accepted format is exactly
3939
`vX.Y.Z`; branches, commit SHAs, moving major tags, prereleases, and arbitrary
4040
refs are rejected.
4141

42-
The workflow validates that its own `uses:` reference and
43-
`wp_codebox_release_ref` match exactly before checkout. It always checks helpers
44-
out from `Automattic/wp-codebox`, verifies the checked-out commit equals the
45-
remote release tag commit, and verifies the checked-out `package.json` version
46-
equals the requested tag without its `v` prefix. The caller cannot select a
47-
different helper repository.
42+
The workflow requires `wp_codebox_release_ref` to be an exact release tag. It
43+
always checks helpers out from `Automattic/wp-codebox`, verifies the checked-out
44+
commit equals the remote release tag commit, and verifies the checked-out
45+
`package.json` version equals the requested tag without its `v` prefix. The
46+
caller cannot select a different helper repository. GitHub nested workflows
47+
expose the caller's `github.workflow_ref`, and the running workflow cannot
48+
introspect its own `uses:` ref, so helper selection relies on the required input
49+
and verified checkout rather than that caller context.
4850

4951
This release-coherence contract fixes [#1759](https://github.com/Automattic/wp-codebox/issues/1759).
5052

5153
## Inputs
5254

53-
- `wp_codebox_release_ref`: required exact immutable WP Codebox release tag. It must match the `@vX.Y.Z` tag in the caller's `uses:` declaration exactly.
55+
- `wp_codebox_release_ref`: required exact immutable WP Codebox release tag in `vX.Y.Z` form.
5456
- `external_package_source`: immutable descriptor with `repository`, full commit `revision`, one package-relative `.agent.json` `path`, and `digest`. Packages are supported only from publicly accessible GitHub repositories, fetched from canonical `https://github.com/OWNER/REPOSITORY.git` without credentials. `digest` is exactly `sha256-bytes-v1:<lowercase-sha256>` over the raw file bytes; filenames and JSON content are UTF-8-safe and are not normalized before hashing.
5557
- `EXTERNAL_PACKAGE_SOURCE_POLICY`: required reusable-workflow secret, supplied by the caller's operator-controlled secret configuration. Its strict version 1 JSON shape is `{"version":1,"repositories":{"owner/repository":["agents/example.agent.json"]}}`. Every entry is an exact standalone `.agent.json` path. The policy is validated in runner memory, is never part of task input, and is not uploaded.
5658
- `target_repo`: `OWNER/REPO` target repository.
@@ -173,7 +175,9 @@ remain caller-workflow responsibilities. This is an intentional exposed-workflow
173175

174176
`wp_codebox_release_ref` is a required v1 input. Existing callers must switch
175177
their `uses:` reference from a branch or other ref to an exact release tag and
176-
pass that identical tag through this input.
178+
pass that exact release tag through this input. Consumer contract tests can
179+
compare both values where the caller workflow is available; the reusable
180+
workflow itself cannot inspect the caller's `uses:` declaration at runtime.
177181

178182
## Upload safety limits
179183

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Regression fixture from Build run 29295530010. In a nested workflow GitHub
2+
# exposed this caller context, not the reusable workflow's own uses ref.
3+
# github.workflow_ref: Automattic/wp-build/.github/workflows/build.yml@trunk
4+
name: Build consumer with foreign caller workflow ref
5+
6+
on: workflow_dispatch
7+
8+
jobs:
9+
run-agent-task:
10+
uses: Automattic/wp-codebox/.github/workflows/run-agent-task.yml@v0.12.4
11+
with:
12+
wp_codebox_release_ref: v0.12.4
13+
external_package_source: '{"repository":"Automattic/example-agent-packages","revision":"0123456789abcdef0123456789abcdef01234567","path":"agents/example.agent.json","digest":"sha256-bytes-v1:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}'
14+
target_repo: Automattic/example-target
15+
prompt: Refresh the configured surface.

tests/agent-task-reusable-workflow.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ assert.match(workflow, /agent-task-upload/)
4242
assert.match(workflow, /if: always\(\)/)
4343
assert.match(workflow, /WP_CODEBOX_RELEASE_REF: \$\{\{ inputs\.wp_codebox_release_ref \}\}/)
4444
assert.match(workflow, /\^v\[0-9\]\+\\\.\[0-9\]\+\\\.\[0-9\]\+\$/)
45-
assert.match(workflow, /WORKFLOW_REF: \$\{\{ github\.workflow_ref \}\}/)
46-
assert.match(workflow, /The reusable workflow tag and wp_codebox_release_ref must match exactly/)
45+
assert.doesNotMatch(workflow, /github\.workflow_ref|WORKFLOW_REF|expected_workflow_ref/)
4746
assert.match(workflow, /repository: Automattic\/wp-codebox/)
4847
assert.match(workflow, /ref: \$\{\{ inputs\.wp_codebox_release_ref \}\}/)
4948
assert.match(workflow, /Verify WP Codebox workflow helper release/)
5049
assert.match(workflow, /git ls-remote --exit-code --refs origin "refs\/tags\/\$\{WP_CODEBOX_RELEASE_REF\}"/)
5150
assert.match(workflow, /checked_out_commit.*remote_tag_commit/)
5251
assert.match(workflow, /JSON\.parse\(readFileSync\("package\.json", "utf8"\)\)\.version/)
5352
assert.doesNotMatch(workflow, /steps\.[^.]+\.outputs\.ref/)
54-
assert.match(workflow, /Validate coherent WP Codebox release tag/)
53+
assert.match(workflow, /Validate WP Codebox release tag/)
5554

5655
const parseConsumerReleaseTags = (consumer: string) => ({
5756
workflow: consumer.match(/uses: Automattic\/wp-codebox\/\.github\/workflows\/run-agent-task\.yml@([^\s]+)/)?.[1],
@@ -64,8 +63,11 @@ const isCoherentConsumer = (consumer: string) => {
6463
}
6564
const coherentConsumer = await readFile(new URL("../fixtures/agent-task-reusable-workflow-consumer.yml", import.meta.url), "utf8")
6665
const mismatchedConsumer = await readFile(new URL("../fixtures/agent-task-reusable-workflow-consumer-mismatched.yml", import.meta.url), "utf8")
66+
const buildRunConsumer = await readFile(new URL("../fixtures/agent-task-reusable-workflow-build-run-29295530010.yml", import.meta.url), "utf8")
6767
assert.equal(isCoherentConsumer(coherentConsumer), true, "An exact matching workflow and helper release tag must succeed")
6868
assert.equal(isCoherentConsumer(mismatchedConsumer), false, "Mismatched workflow and helper release tags must fail")
69+
assert.match(buildRunConsumer, /github\.workflow_ref: Automattic\/wp-build\/\.github\/workflows\/build\.yml@trunk/)
70+
assert.equal(isCoherentConsumer(buildRunConsumer), true, "A foreign caller workflow_ref must not affect the paired release tags")
6971
for (const invalidRef of ["main", "v0", "v0.12", "v0.12.3-rc.1", "0123456789abcdef0123456789abcdef01234567"]) {
7072
assert.equal(isExactReleaseTag(invalidRef), false, `Non-release ref must fail: ${invalidRef}`)
7173
}
@@ -79,6 +81,7 @@ assert.match(docs, /^# Agent Task Reusable Workflow/m)
7981
assert.match(docs, /Automattic\/wp-codebox\/.github\/workflows\/run-agent-task.yml@v0\.12\.3/)
8082
assert.match(docs, /wp_codebox_release_ref: v0\.12\.3/)
8183
assert.match(docs, /branches, commit SHAs, moving major tags, prereleases, and arbitrary\nrefs are rejected/)
84+
assert.match(docs, /GitHub nested workflows\s+expose the caller's `github\.workflow_ref`, and the running workflow cannot\s+introspect its own `uses:` ref/)
8285
assert.match(docs, /external_package_source/)
8386
assert.match(docs, /runner_workspace/)
8487
assert.match(docs, /access_token_repos/)

0 commit comments

Comments
 (0)