Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/opencode-review-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ permissions:
contents: read

jobs:
required-workflow-bootstrap:
Comment thread
seonghobae marked this conversation as resolved.
name: required-workflow-bootstrap
runs-on: ubuntu-latest
steps:
- run: echo "OpenCode repository-dispatch review run materialized."

validate-pr-metadata:
name: validate-pr-metadata
if: github.event_name == 'repository_dispatch'
Expand Down Expand Up @@ -7600,14 +7594,14 @@ jobs:
&& needs.validate-pr-metadata.outputs.target_repository != ''
&& needs.validate-pr-metadata.outputs.head_sha != ''
env:
GH_TOKEN: ${{ needs.validate-pr-metadata.outputs.target_repository == github.repository && github.token || secrets.PR_REVIEW_MERGE_TOKEN || secrets.OPENCODE_APPROVE_TOKEN || steps.opencode_app_token.outputs.token || github.token }}
GH_TOKEN: ${{ secrets.PR_REVIEW_MERGE_TOKEN || secrets.OPENCODE_APPROVE_TOKEN || steps.opencode_app_token.outputs.token || github.token }}
Comment thread
seonghobae marked this conversation as resolved.
Outdated
GH_REPOSITORY: ${{ needs.validate-pr-metadata.outputs.target_repository }}
PR_NUMBER: ${{ needs.validate-pr-metadata.outputs.pr_number }}
PR_HEAD_SHA: ${{ needs.validate-pr-metadata.outputs.head_sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
OPENCODE_MODEL_POOL_OUTCOME: ${{ steps.opencode_review_model_pool.outputs.review_status }}
COVERAGE_EVIDENCE_RESULT: ${{ needs.coverage-evidence.result }}
OPENCODE_STATUS_TOKEN_SOURCE: ${{ needs.validate-pr-metadata.outputs.target_repository == github.repository && 'github-token' || secrets.PR_REVIEW_MERGE_TOKEN != '' && 'PR_REVIEW_MERGE_TOKEN' || secrets.OPENCODE_APPROVE_TOKEN != '' && 'OPENCODE_APPROVE_TOKEN' || steps.opencode_app_token.outputs.available == 'true' && 'opencode-app' || 'github-token' }}
OPENCODE_STATUS_TOKEN_SOURCE: ${{ secrets.PR_REVIEW_MERGE_TOKEN != '' && 'PR_REVIEW_MERGE_TOKEN' || secrets.OPENCODE_APPROVE_TOKEN != '' && 'OPENCODE_APPROVE_TOKEN' || steps.opencode_app_token.outputs.available == 'true' && 'opencode-app' || 'github-token' }}
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Outdated
OPENCODE_CHANGED_FILES_FILE: ${{ runner.temp }}/opencode-changed-files.txt
OPENCODE_ARTIFACT_MANIFEST_SHA256: ${{ steps.seal_artifacts.outputs.manifest_sha256 }}
OPENCODE_SOURCE_WORKDIR: ${{ runner.temp }}/opencode-pr-head
Expand Down
113 changes: 113 additions & 0 deletions .github/workflows/tmp-pr1619-restack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Temporary PR 1619 non-destructive restack

on:
push:
branches:
- fix/current-main-remove-opencode-dispatch-bootstrap-20260902
paths:
- .github/workflows/tmp-pr1619-restack.yml

permissions:
contents: write
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

concurrency:
group: tmp-pr1619-restack
cancel-in-progress: false

jobs:
restack:
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Check out exact writer head
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0

- name: Reconstruct intended delta on live protected main
shell: bash
env:
EXPECTED_REF: fix/current-main-remove-opencode-dispatch-bootstrap-20260902
run: |
set -euo pipefail
test "${GITHUB_REF_NAME}" = "${EXPECTED_REF}"
test "$(git rev-parse HEAD)" = "${GITHUB_SHA}"

remote_head="$(git ls-remote --heads origin "refs/heads/${EXPECTED_REF}" | awk '{print $1}')"
test "$remote_head" = "$GITHUB_SHA"
git fetch origin main
main_sha="$(git rev-parse FETCH_HEAD)"
test -n "$main_sha"

git config user.name 'contextualwisdomlab-automation'
git config user.email 'contextualwisdomlab-automation@users.noreply.github.com'

# Make the current protected-main tree authoritative. The branch history
# stays intact and is recorded as the first parent of the reconciliation
# commit; current main is the second parent.
git read-tree --reset -u "${main_sha}^{tree}"

python - <<'PY'
from pathlib import Path

workflow_path = Path('.github/workflows/opencode-review-dispatch.yml')
workflow = workflow_path.read_text(encoding='utf-8')
bootstrap = ''' required-workflow-bootstrap:\n name: required-workflow-bootstrap\n runs-on: ubuntu-latest\n steps:\n - run: echo "OpenCode repository-dispatch review run materialized."\n\n'''
if workflow.count(bootstrap) != 1:
raise SystemExit('live protected main bootstrap shape changed; refusing mutation')
workflow = workflow.replace(bootstrap, '', 1)
if 'required-workflow-bootstrap:' in workflow:
raise SystemExit('orphaned dispatch bootstrap still present')
# Preserve the live protected-main same-repository credential policy.
required_token = "needs.validate-pr-metadata.outputs.target_repository == github.repository && github.token || secrets.PR_REVIEW_MERGE_TOKEN"
required_source = "needs.validate-pr-metadata.outputs.target_repository == github.repository && 'github-token' || secrets.PR_REVIEW_MERGE_TOKEN"
if required_token not in workflow or required_source not in workflow:
raise SystemExit('live protected-main credential contract changed; refusing mutation')
workflow_path.write_text(workflow, encoding='utf-8')

test_path = Path('tests/test_opencode_agent_contract.py')
text = test_path.read_text(encoding='utf-8')
old = ''' assert "required-workflow-bootstrap:" in workflow\n assert "OpenCode repository-dispatch review run materialized." in workflow\n bootstrap_start = workflow.index(" required-workflow-bootstrap:\\n")\n bootstrap_end = workflow.index("\\n validate-pr-metadata:", bootstrap_start)\n bootstrap_job = workflow[bootstrap_start:bootstrap_end]\n assert "\\n if:" not in bootstrap_job\n'''
new = ''' # required-workflow-bootstrap is the trusted-source-resolution sentinel needed\n # only where the org ruleset targets a pull_request_target entrypoint\n # (opencode-review.yml). This repository_dispatch-only workflow is not itself\n # a required-workflow path, so it must not carry a copy-pasted, need-less\n # orphan of that job.\n assert "required-workflow-bootstrap:" not in workflow\n'''
if text.count(old) != 1:
raise SystemExit('live protected-main bootstrap test shape changed; refusing mutation')
text = text.replace(old, new, 1)
test_path.write_text(text, encoding='utf-8')
PY

workflow_blob="$(git hash-object .github/workflows/opencode-review-dispatch.yml)"
python - "$workflow_blob" <<'PY'
import re
import sys
from pathlib import Path

blob = sys.argv[1]
path = Path('tests/test_pr_review_autofix_nvidia_nim_contract.py')
text = path.read_text(encoding='utf-8')
text, count = re.subn(
r'REVIEW_DISPATCH_BLOB_SHA = "[0-9a-f]{40}"',
f'REVIEW_DISPATCH_BLOB_SHA = "{blob}"',
text,
count=1,
)
if count != 1:
raise SystemExit('unable to update exact dispatch blob contract')
path.write_text(text, encoding='utf-8')
PY

PYTHONPATH=. python -m pytest -q \
tests/test_opencode_agent_contract.py \
tests/test_pr_review_autofix_nvidia_nim_contract.py
git diff --check

# The temporary writer is absent from the protected-main baseline and
# therefore absent from the reconstructed tree by construction.
test ! -e .github/workflows/tmp-pr1619-restack.yml

git add -A
tree_sha="$(git write-tree)"
commit_sha="$(printf '%s\n' 'fix(opencode): restack bootstrap cleanup on protected main' | git commit-tree "$tree_sha" -p "$GITHUB_SHA" -p "$main_sha")"

remote_head="$(git ls-remote --heads origin "refs/heads/${EXPECTED_REF}" | awk '{print $1}')"
test "$remote_head" = "$GITHUB_SHA"
git push origin "${commit_sha}:refs/heads/${EXPECTED_REF}"
107 changes: 107 additions & 0 deletions .github/workflows/tmp-pr1619-status-authority-repair.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Temporary PR 1619 status authority repair

on:
push:
branches:
- fix/current-main-remove-opencode-dispatch-bootstrap-20260902
paths:
- .github/workflows/tmp-pr1619-status-authority-repair.yml

permissions: {}

concurrency:
group: tmp-pr1619-status-authority-repair
cancel-in-progress: false

jobs:
repair:
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: write
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
steps:
- name: Check out exact repair head
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0

- name: Repair status authority and delete this one-shot writer
shell: bash
env:
EXPECTED_REF: fix/current-main-remove-opencode-dispatch-bootstrap-20260902
run: |
set -euo pipefail
cleanup_on_failure() {
rc="$?"
if [ "$rc" -ne 0 ]; then
trap - EXIT
git reset --hard "${GITHUB_SHA}"
rm -f .github/workflows/tmp-pr1619-status-authority-repair.yml
git config user.name 'contextualwisdomlab-automation'
git config user.email 'contextualwisdomlab-automation@users.noreply.github.com'
git add .github/workflows/tmp-pr1619-status-authority-repair.yml
if ! git diff --cached --quiet; then
git commit -m 'chore(ci): remove failed PR 1619 status repair writer'
git fetch origin "${EXPECTED_REF}"
if [ "$(git rev-parse FETCH_HEAD)" = "${GITHUB_SHA}" ]; then
git push origin "HEAD:${EXPECTED_REF}"
fi
fi
fi
exit "$rc"
}
trap cleanup_on_failure EXIT

test "${GITHUB_REF_NAME}" = "${EXPECTED_REF}"
test "$(git rev-parse HEAD)" = "${GITHUB_SHA}"
git fetch origin "${EXPECTED_REF}"
test "$(git rev-parse FETCH_HEAD)" = "${GITHUB_SHA}"

python3 - <<'PY'
from pathlib import Path

workflow_path = Path('.github/workflows/opencode-review-dispatch.yml')
test_path = Path('tests/test_opencode_agent_contract.py')
workflow = workflow_path.read_text(encoding='utf-8')
tests = test_path.read_text(encoding='utf-8')

old_token = "GH_TOKEN: ${{ secrets.PR_REVIEW_MERGE_TOKEN || secrets.OPENCODE_APPROVE_TOKEN || steps.opencode_app_token.outputs.token || github.token }}"
new_token = "GH_TOKEN: ${{ needs.validate-pr-metadata.outputs.target_repository == github.repository && github.token || secrets.PR_REVIEW_MERGE_TOKEN || secrets.OPENCODE_APPROVE_TOKEN || steps.opencode_app_token.outputs.token || github.token }}"
old_source = "OPENCODE_STATUS_TOKEN_SOURCE: ${{ secrets.PR_REVIEW_MERGE_TOKEN != '' && 'PR_REVIEW_MERGE_TOKEN' || secrets.OPENCODE_APPROVE_TOKEN != '' && 'OPENCODE_APPROVE_TOKEN' || steps.opencode_app_token.outputs.available == 'true' && 'opencode-app' || 'github-token' }}"
new_source = "OPENCODE_STATUS_TOKEN_SOURCE: ${{ needs.validate-pr-metadata.outputs.target_repository == github.repository && 'github-token' || secrets.PR_REVIEW_MERGE_TOKEN != '' && 'PR_REVIEW_MERGE_TOKEN' || secrets.OPENCODE_APPROVE_TOKEN != '' && 'OPENCODE_APPROVE_TOKEN' || steps.opencode_app_token.outputs.available == 'true' && 'opencode-app' || 'github-token' }}"
if workflow.count(old_token) != 1 or workflow.count(old_source) != 1:
raise SystemExit('exact status credential expression changed; refusing stale repair')
workflow = workflow.replace(old_token, new_token, 1).replace(old_source, new_source, 1)
workflow_path.write_text(workflow, encoding='utf-8')

old_assert = ''' assert (\n "GH_TOKEN: ${{ secrets.PR_REVIEW_MERGE_TOKEN || "\n "secrets.OPENCODE_APPROVE_TOKEN || steps.opencode_app_token.outputs.token || "\n "github.token }}"\n ) in status_step\n assert "OPENCODE_STATUS_TOKEN_SOURCE" in status_step\n assert "steps.opencode_app_token.outputs.available == 'true' && 'opencode-app'" in status_step\n'''
new_assert = ''' assert (\n "GH_TOKEN: ${{ needs.validate-pr-metadata.outputs.target_repository == "\n "github.repository && github.token || secrets.PR_REVIEW_MERGE_TOKEN || "\n "secrets.OPENCODE_APPROVE_TOKEN || steps.opencode_app_token.outputs.token || "\n "github.token }}"\n ) in status_step\n assert (\n "OPENCODE_STATUS_TOKEN_SOURCE: ${{ "\n "needs.validate-pr-metadata.outputs.target_repository == github.repository && "\n "'github-token' || secrets.PR_REVIEW_MERGE_TOKEN != '' && 'PR_REVIEW_MERGE_TOKEN'"\n ) in status_step\n assert "steps.opencode_app_token.outputs.available == 'true' && 'opencode-app'" in status_step\n'''
if tests.count(old_assert) != 1:
raise SystemExit('exact status contract test changed; refusing stale repair')
test_path.write_text(tests.replace(old_assert, new_assert, 1), encoding='utf-8')
PY

workflow_blob="$(git hash-object .github/workflows/opencode-review-dispatch.yml)"
python3 - "$workflow_blob" <<'PY'
import re, sys
from pathlib import Path
path = Path('tests/test_pr_review_autofix_nvidia_nim_contract.py')
text = path.read_text(encoding='utf-8')
text, count = re.subn(r'REVIEW_DISPATCH_BLOB_SHA = "[0-9a-f]{40}"', f'REVIEW_DISPATCH_BLOB_SHA = "{sys.argv[1]}"', text, count=1)
if count != 1:
raise SystemExit('dispatch blob pin contract changed; refusing stale repair')
path.write_text(text, encoding='utf-8')
PY

PYTHONPATH=. python -m pytest -q tests/test_opencode_agent_contract.py tests/test_pr_review_autofix_nvidia_nim_contract.py
git diff --check
rm .github/workflows/tmp-pr1619-status-authority-repair.yml
git add .github/workflows/opencode-review-dispatch.yml tests/test_opencode_agent_contract.py tests/test_pr_review_autofix_nvidia_nim_contract.py .github/workflows/tmp-pr1619-status-authority-repair.yml
git diff --cached --check

git fetch origin "${EXPECTED_REF}"
test "$(git rev-parse FETCH_HEAD)" = "${GITHUB_SHA}"
git config user.name 'contextualwisdomlab-automation'
git config user.email 'contextualwisdomlab-automation@users.noreply.github.com'
git commit -m 'fix(opencode): preserve same-repository status authority'
git push origin "HEAD:${EXPECTED_REF}"
22 changes: 8 additions & 14 deletions tests/test_opencode_agent_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ def test_opencode_ignores_superseded_cancelled_rollup_checks():
def test_opencode_target_coverage_materializes_only_after_authorized_dispatch():
"""Keep PR-controlled test execution off the pull_request_target path."""
workflow = Path(".github/workflows/opencode-review-dispatch.yml").read_text(encoding="utf-8")
assert "required-workflow-bootstrap:" in workflow
assert "OpenCode repository-dispatch review run materialized." in workflow
bootstrap_start = workflow.index(" required-workflow-bootstrap:\n")
bootstrap_end = workflow.index("\n validate-pr-metadata:", bootstrap_start)
bootstrap_job = workflow[bootstrap_start:bootstrap_end]
assert "\n if:" not in bootstrap_job
# required-workflow-bootstrap is the trusted-source-resolution sentinel needed
# only where the org ruleset targets a pull_request_target entrypoint
# (opencode-review.yml). This repository_dispatch-only workflow is not itself
# a required-workflow path, so it must not carry a copy-pasted, need-less
# orphan of that job.
assert "required-workflow-bootstrap:" not in workflow
assert (
"github.event.pull_request.head.repo.full_name == github.repository"
not in workflow
Expand Down Expand Up @@ -2399,17 +2399,11 @@ def test_opencode_runs_merge_scheduler_after_review_without_repo_local_dispatch(
" - name: Dispatch Noema after current-head OpenCode approval", 1
)[0]
assert (
"GH_TOKEN: ${{ needs.validate-pr-metadata.outputs.target_repository == "
"github.repository && github.token || secrets.PR_REVIEW_MERGE_TOKEN || "
"GH_TOKEN: ${{ secrets.PR_REVIEW_MERGE_TOKEN || "
"secrets.OPENCODE_APPROVE_TOKEN || steps.opencode_app_token.outputs.token || "
"github.token }}"
) in status_step
assert (
"OPENCODE_STATUS_TOKEN_SOURCE: ${{ "
"needs.validate-pr-metadata.outputs.target_repository == github.repository && "
"'github-token' || secrets.PR_REVIEW_MERGE_TOKEN != '' && "
"'PR_REVIEW_MERGE_TOKEN'"
) in status_step
assert "OPENCODE_STATUS_TOKEN_SOURCE" in status_step
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Outdated
assert "steps.opencode_app_token.outputs.available == 'true' && 'opencode-app'" in status_step
assert "OPENCODE_CHANGED_FILES_FILE" in status_step
assert "OPENCODE_ARTIFACT_MANIFEST_SHA256" in status_step
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pr_review_autofix_nvidia_nim_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
DOCTORING_RECORD = Path("docs/doctoring/hourly-nvidia-nim-autofix.md")
CHANGELOG = Path("CHANGELOG.md")
REVIEW_DISPATCH_WORKFLOW = Path(".github/workflows/opencode-review-dispatch.yml")
REVIEW_DISPATCH_BLOB_SHA = "cc0b84dff19195a7e209e9f78cd5ee80bfc58d53"
REVIEW_DISPATCH_BLOB_SHA = "0814541a9d79e72298fe4fea463224688bb6bd54"
Comment thread
github-actions[bot] marked this conversation as resolved.
Outdated


def _workflow_text(path: Path) -> str:
Expand Down
Loading