-
Notifications
You must be signed in to change notification settings - Fork 0
8034 lines (7557 loc) · 420 KB
/
Copy pathopencode-review-dispatch.yml
File metadata and controls
8034 lines (7557 loc) · 420 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: OpenCode Review Dispatch
run-name: >-
OpenCode Review Dispatch ${{ github.event.client_payload.target_repository ||
github.repository }}#${{ github.event.client_payload.pr_number || 'event' }}@${{
github.event.client_payload.pr_head_sha || github.sha }}
on:
# This workflow contains the privileged review, PR-head materialization, and
# publication path. Keep it default-branch-only so no pull request event can
# combine untrusted source data with review-write credentials or secrets.
repository_dispatch:
types: [opencode-review]
concurrency:
# PR-number scope keeps stale dispatches replaced for the current head.
group: >-
opencode-review-repository-dispatch-${{
github.event.client_payload.target_repository || github.repository }}-${{
github.event.client_payload.pr_number && format('pr-{0}', github.event.client_payload.pr_number) ||
github.run_id }}
cancel-in-progress: true
permissions:
contents: read
jobs:
required-workflow-bootstrap:
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'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
id-token: write
outputs:
target_repository: ${{ steps.validate.outputs.target_repository }}
pr_number: ${{ steps.validate.outputs.pr_number }}
base_ref: ${{ steps.validate.outputs.base_ref }}
base_sha: ${{ steps.validate.outputs.base_sha }}
head_ref: ${{ steps.validate.outputs.head_ref }}
head_sha: ${{ steps.validate.outputs.head_sha }}
is_private: ${{ steps.validate.outputs.is_private }}
steps:
- name: Exchange OpenCode app token for target repository metadata reads
id: metadata_read_app_token
if: >-
github.event_name == 'repository_dispatch'
&& github.event.client_payload.target_repository != ''
&& github.event.client_payload.target_repository != github.repository
env:
OIDC_AUDIENCE: opencode-github-action
OPENCODE_API_BASE_URL: https://api.opencode.ai
run: |
set -euo pipefail
mark_unavailable() {
echo "available=false" >>"$GITHUB_OUTPUT"
}
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ] ||
[ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ]; then
echo "OpenCode app token exchange unavailable: OIDC request environment is missing."
mark_unavailable
exit 0
fi
request_url="${ACTIONS_ID_TOKEN_REQUEST_URL}"
separator="&"
case "$request_url" in
*\?*) ;;
*) separator="?" ;;
esac
if ! oidc_response="$(
curl -fsS \
-H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
"${request_url}${separator}audience=${OIDC_AUDIENCE}"
)"; then
echo "OpenCode app token exchange unavailable: OIDC token request did not complete."
mark_unavailable
exit 0
fi
oidc_token="$(jq -r '.value // empty' <<<"$oidc_response")"
if [ -z "$oidc_token" ]; then
echo "OpenCode app token exchange unavailable: OIDC token response was empty."
mark_unavailable
exit 0
fi
if ! token_response="$(
curl -fsS \
-X POST \
-H "Authorization: Bearer ${oidc_token}" \
"${OPENCODE_API_BASE_URL}/exchange_github_app_token"
)"; then
echo "OpenCode app token exchange unavailable: app token request did not complete."
mark_unavailable
exit 0
fi
app_token="$(jq -r '.token // empty' <<<"$token_response")"
if [ -z "$app_token" ]; then
echo "OpenCode app token exchange unavailable: app token response was empty."
mark_unavailable
exit 0
fi
echo "::add-mask::$app_token"
{
echo "available=true"
echo "token=$app_token"
} >>"$GITHUB_OUTPUT"
- name: Bind workflow inputs to live organization pull request metadata
id: validate
env:
GH_TOKEN: ${{ steps.metadata_read_app_token.outputs.token || secrets.PR_REVIEW_MERGE_TOKEN || secrets.OPENCODE_APPROVE_TOKEN || github.token }}
EVENT_NAME: ${{ github.event_name }}
# A rerun retains github.actor from the original dispatch; authorize
# the identity that initiated the current run or rerun instead.
DISPATCH_ACTOR: ${{ github.triggering_actor }}
DISPATCH_SENDER: ${{ github.event.sender.login || '' }}
ALLOWED_DISPATCH_ACTOR: ${{ vars.OPENCODE_REPOSITORY_DISPATCH_ACTOR }}
ALLOWED_DISPATCH_TARGETS: ${{ vars.OPENCODE_REPOSITORY_DISPATCH_TARGETS }}
TARGET_REPOSITORY: ${{ github.event.client_payload.target_repository || github.repository }}
PR_NUMBER: ${{ github.event.client_payload.pr_number }}
SUPPLIED_BASE_REF: ${{ github.event.client_payload.pr_base_ref || '' }}
SUPPLIED_BASE_SHA: ${{ github.event.client_payload.pr_base_sha || '' }}
SUPPLIED_HEAD_REF: ${{ github.event.client_payload.pr_head_ref || '' }}
SUPPLIED_HEAD_SHA: ${{ github.event.client_payload.pr_head_sha || '' }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "repository_dispatch" ]; then
if [ -z "$ALLOWED_DISPATCH_ACTOR" ] ||
[ "$DISPATCH_ACTOR" != "$ALLOWED_DISPATCH_ACTOR" ] ||
[ "$DISPATCH_SENDER" != "$ALLOWED_DISPATCH_ACTOR" ]; then
printf '::error::repository_dispatch authorization rejected actor=%s sender=%s because both must match the configured scheduler identity.\n' "${DISPATCH_ACTOR:-<empty>}" "${DISPATCH_SENDER:-<empty>}"
exit 1
fi
target_allowed=0
IFS=',' read -r -a allowed_dispatch_targets <<<"$ALLOWED_DISPATCH_TARGETS"
for allowed_target in "${allowed_dispatch_targets[@]}"; do
allowed_target="${allowed_target//[[:space:]]/}"
if [ -n "$allowed_target" ] && [ "$TARGET_REPOSITORY" = "$allowed_target" ]; then
target_allowed=1
break
fi
done
if [ "$target_allowed" -ne 1 ]; then
printf '::error::repository_dispatch authorization rejected target=%s because it is absent from the configured exact repository allowlist.\n' "${TARGET_REPOSITORY:-<empty>}"
exit 1
fi
printf 'Authorized repository_dispatch actor=%s sender=%s target=%s.\n' "$DISPATCH_ACTOR" "$DISPATCH_SENDER" "$TARGET_REPOSITORY"
fi
if ! [[ "$TARGET_REPOSITORY" =~ ^ContextualWisdomLab/[A-Za-z0-9_.-]+$ ]] ||
! [[ "$PR_NUMBER" =~ ^[1-9][0-9]*$ ]]; then
printf '::error::PR metadata validation rejected a target outside ContextualWisdomLab or an invalid pull request number. target=%s pr=%s\n' "${TARGET_REPOSITORY:-<empty>}" "${PR_NUMBER:-<empty>}"
exit 1
fi
pull_request_json="$(gh api "repos/${TARGET_REPOSITORY}/pulls/${PR_NUMBER}")"
live_base_repository="$(jq -r '.base.repo.full_name // empty' <<<"$pull_request_json")"
live_head_repository="$(jq -r '.head.repo.full_name // empty' <<<"$pull_request_json")"
live_base_ref="$(jq -r '.base.ref // empty' <<<"$pull_request_json")"
live_base_sha="$(jq -r '.base.sha // empty' <<<"$pull_request_json")"
live_head_ref="$(jq -r '.head.ref // empty' <<<"$pull_request_json")"
live_head_sha="$(jq -r '.head.sha // empty' <<<"$pull_request_json")"
live_state="$(jq -r '.state // empty' <<<"$pull_request_json")"
live_is_private="$(jq -r '.base.repo.private | tostring' <<<"$pull_request_json")"
if [ "$live_state" != "open" ] ||
[ "$live_base_repository" != "$TARGET_REPOSITORY" ] ||
[ "$live_head_repository" != "$TARGET_REPOSITORY" ] ||
! [[ "$live_base_sha" =~ ^[0-9a-fA-F]{40}$ ]] ||
! [[ "$live_head_sha" =~ ^[0-9a-fA-F]{40}$ ]] ||
! [[ "$live_is_private" =~ ^(true|false)$ ]] ||
[ -z "$live_base_ref" ] ||
[ -z "$live_head_ref" ]; then
printf '::error::PR metadata validation rejected closed, missing, cross-repository, or malformed live metadata. target=%s#%s state=%s base_repo=%s head_repo=%s base=%s head=%s\n' "$TARGET_REPOSITORY" "$PR_NUMBER" "${live_state:-<missing>}" "${live_base_repository:-<missing>}" "${live_head_repository:-<missing>}" "${live_base_sha:-<missing>}" "${live_head_sha:-<missing>}"
exit 1
fi
if [ "$EVENT_NAME" = "repository_dispatch" ]; then
mismatches=()
[ "$SUPPLIED_BASE_REF" = "$live_base_ref" ] || mismatches+=("base_ref")
[ "$SUPPLIED_BASE_SHA" = "$live_base_sha" ] || mismatches+=("base_sha")
[ "$SUPPLIED_HEAD_REF" = "$live_head_ref" ] || mismatches+=("head_ref")
[ "$SUPPLIED_HEAD_SHA" = "$live_head_sha" ] || mismatches+=("head_sha")
if [ "${#mismatches[@]}" -gt 0 ]; then
printf '::error::repository_dispatch metadata does not match the live pull request: %s. supplied_base=%s/%s live_base=%s/%s supplied_head=%s/%s live_head=%s/%s\n' "$(IFS=,; printf '%s' "${mismatches[*]}")" "${SUPPLIED_BASE_REF:-<empty>}" "${SUPPLIED_BASE_SHA:-<empty>}" "$live_base_ref" "$live_base_sha" "${SUPPLIED_HEAD_REF:-<empty>}" "${SUPPLIED_HEAD_SHA:-<empty>}" "$live_head_ref" "$live_head_sha"
exit 1
fi
fi
{
printf 'target_repository=%s\n' "$TARGET_REPOSITORY"
printf 'pr_number=%s\n' "$PR_NUMBER"
printf 'base_ref=%s\n' "$live_base_ref"
printf 'base_sha=%s\n' "$live_base_sha"
printf 'head_ref=%s\n' "$live_head_ref"
printf 'head_sha=%s\n' "$live_head_sha"
printf 'is_private=%s\n' "$live_is_private"
} >>"$GITHUB_OUTPUT"
printf 'Validated current live metadata for %s#%s: base=%s/%s head=%s/%s.\n' "$TARGET_REPOSITORY" "$PR_NUMBER" "$live_base_ref" "$live_base_sha" "$live_head_ref" "$live_head_sha"
coverage-source-tree:
name: coverage-source-tree
needs: [validate-pr-metadata]
if: >-
needs.validate-pr-metadata.result == 'success'
&& github.event_name == 'repository_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
steps:
- name: Exchange OpenCode app token for target repository coverage reads
id: coverage_read_app_token
if: >-
github.event_name == 'repository_dispatch'
&& needs.validate-pr-metadata.outputs.target_repository != ''
&& needs.validate-pr-metadata.outputs.target_repository != github.repository
env:
OIDC_AUDIENCE: opencode-github-action
OPENCODE_API_BASE_URL: https://api.opencode.ai
run: |
set -euo pipefail
mark_unavailable() {
echo "available=false" >>"$GITHUB_OUTPUT"
}
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ]; then
echo "OpenCode app token exchange unavailable: OIDC request environment is missing."
mark_unavailable
exit 0
fi
request_url="${ACTIONS_ID_TOKEN_REQUEST_URL}"
separator="&"
case "$request_url" in
*\?*) ;;
*) separator="?" ;;
esac
if ! oidc_response="$(
curl -fsS \
-H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
"${request_url}${separator}audience=${OIDC_AUDIENCE}"
)"; then
echo "OpenCode app token exchange unavailable: OIDC token request did not complete."
mark_unavailable
exit 0
fi
oidc_token="$(jq -r '.value // empty' <<<"$oidc_response")"
if [ -z "$oidc_token" ]; then
echo "OpenCode app token exchange unavailable: OIDC token response was empty."
mark_unavailable
exit 0
fi
if ! token_response="$(
curl -fsS \
-X POST \
-H "Authorization: Bearer ${oidc_token}" \
"${OPENCODE_API_BASE_URL}/exchange_github_app_token"
)"; then
echo "OpenCode app token exchange unavailable: app token request did not complete."
mark_unavailable
exit 0
fi
app_token="$(jq -r '.token // empty' <<<"$token_response")"
if [ -z "$app_token" ]; then
echo "OpenCode app token exchange unavailable: app token response was empty."
mark_unavailable
exit 0
fi
echo "::add-mask::$app_token"
{
echo "available=true"
echo "token=$app_token"
} >>"$GITHUB_OUTPUT"
- name: Materialize pull request merge tree for coverage measurement
env:
GH_TOKEN: ${{ steps.coverage_read_app_token.outputs.token || secrets.PR_REVIEW_MERGE_TOKEN || secrets.OPENCODE_APPROVE_TOKEN || github.token }}
TARGET_REPOSITORY: ${{ needs.validate-pr-metadata.outputs.target_repository }}
PR_NUMBER: ${{ needs.validate-pr-metadata.outputs.pr_number }}
PR_BASE_SHA: ${{ needs.validate-pr-metadata.outputs.base_sha }}
PR_HEAD_SHA: ${{ needs.validate-pr-metadata.outputs.head_sha }}
COVERAGE_SOURCE_WORKDIR: ${{ runner.temp }}/opencode-coverage-source
COVERAGE_SOURCE_ARCHIVE: ${{ runner.temp }}/opencode-coverage-source.tar
run: |
set -euo pipefail
fetch_dir="${RUNNER_TEMP}/opencode-coverage-fetch"
rm -rf "$fetch_dir" "$COVERAGE_SOURCE_WORKDIR" "$COVERAGE_SOURCE_ARCHIVE"
if [ -z "${GH_TOKEN:-}" ]; then
echo "::error::Coverage merge tree materialization requires a GitHub token."
exit 1
fi
missing_metadata=()
[ -n "${TARGET_REPOSITORY:-}" ] || missing_metadata+=("target_repository")
[ -n "${PR_NUMBER:-}" ] || missing_metadata+=("pr_number")
[ -n "${PR_BASE_SHA:-}" ] || missing_metadata+=("pr_base_sha")
[ -n "${PR_HEAD_SHA:-}" ] || missing_metadata+=("pr_head_sha")
if [ "${#missing_metadata[@]}" -gt 0 ]; then
printf '::error::Coverage merge tree materialization missing required PR metadata for event %s: %s. target_repository=%s pr_number=%s base=%s head=%s\n' \
"${GITHUB_EVENT_NAME:-unknown}" \
"$(IFS=,; printf '%s' "${missing_metadata[*]}")" \
"${TARGET_REPOSITORY:-<empty>}" \
"${PR_NUMBER:-<empty>}" \
"${PR_BASE_SHA:-<empty>}" \
"${PR_HEAD_SHA:-<empty>}"
exit 1
fi
auth_header="$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 | tr -d '\n')"
echo "::add-mask::$auth_header"
git init "$fetch_dir"
git -C "$fetch_dir" remote add origin "${GITHUB_SERVER_URL}/${TARGET_REPOSITORY}.git"
if ! git -C "$fetch_dir" \
-c http.extraheader="AUTHORIZATION: basic ${auth_header}" \
fetch --no-tags --prune --no-recurse-submodules origin "$PR_BASE_SHA" "$PR_HEAD_SHA"; then
echo "::error::Coverage fetch could not authenticate to ${TARGET_REPOSITORY} or read base/head SHAs ${PR_BASE_SHA}/${PR_HEAD_SHA}; check token permissions, target repository access, and SHA visibility."
exit 1
fi
git -C "$fetch_dir" checkout --detach "$PR_BASE_SHA"
git -C "$fetch_dir" config user.name "github-actions[bot]"
git -C "$fetch_dir" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if ! git -C "$fetch_dir" merge --no-ff --no-edit "$PR_HEAD_SHA"; then
echo "::error::Coverage merge tree could not be materialized for base ${PR_BASE_SHA} and head ${PR_HEAD_SHA}; resolve merge conflicts or rerun after GitHub can synthesize the PR merge commit."
exit 1
fi
mkdir -p "$(dirname "$COVERAGE_SOURCE_WORKDIR")"
mv "$fetch_dir" "$COVERAGE_SOURCE_WORKDIR"
git -C "$COVERAGE_SOURCE_WORKDIR" status --short
tar -cf "$COVERAGE_SOURCE_ARCHIVE" -C "$COVERAGE_SOURCE_WORKDIR" .
- name: Upload materialized pull request merge tree
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: opencode-coverage-source
path: ${{ runner.temp }}/opencode-coverage-source.tar
if-no-files-found: error
retention-days: 1
coverage-evidence:
name: coverage-evidence
needs: [validate-pr-metadata, coverage-source-tree]
if: >-
always()
&& needs.validate-pr-metadata.result == 'success'
&& needs.coverage-source-tree.result != 'cancelled'
&& github.event_name == 'repository_dispatch'
runs-on: ubuntu-latest
permissions:
# The PR tree arrives through a same-run artifact. No repository-content,
# identity, secret, or write token is available to untrusted tests.
actions: read
outputs:
coverage_summary: ${{ steps.measure.outputs.coverage_summary }}
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
steps:
- name: Resolve trusted OpenCode source ref
id: trusted_source
env:
JOB_CONTEXT_JSON: ${{ toJSON(job) }}
GITHUB_CONTEXT_JSON: ${{ toJSON(github) }}
run: |
set -euo pipefail
python3 <<'PY' >>"$GITHUB_OUTPUT"
import json
import os
import re
import sys
try:
job_context = json.loads(os.environ.get("JOB_CONTEXT_JSON") or "{}")
github_context = json.loads(os.environ.get("GITHUB_CONTEXT_JSON") or "{}")
except json.JSONDecodeError as exc:
print(f"::error::Could not parse GitHub workflow context JSON: {exc}", file=sys.stderr)
raise SystemExit(1)
trusted_ref = str(
job_context.get("workflow_sha") or github_context.get("workflow_sha") or ""
).strip()
workflow_ref = str(
job_context.get("workflow_ref") or github_context.get("workflow_ref") or ""
).strip()
if not trusted_ref:
trusted_ref = "main"
prefix = "ContextualWisdomLab/.github/.github/workflows/opencode-review-dispatch.yml@"
if workflow_ref.startswith(prefix):
trusted_ref = workflow_ref.split("@", 1)[1]
if not re.fullmatch(r"[0-9a-fA-F]{40}|refs/[^\s]+|[A-Za-z0-9._/-]+", trusted_ref):
print("::error::Trusted OpenCode workflow ref resolved to an invalid value.", file=sys.stderr)
raise SystemExit(1)
print(f"ref={trusted_ref}")
PY
- name: Materialize trusted OpenCode coverage contract without a repository token
env:
TRUSTED_SOURCE_REF: ${{ steps.trusted_source.outputs.ref }}
run: |
set -euo pipefail
git init "$GITHUB_WORKSPACE"
git -C "$GITHUB_WORKSPACE" remote add trusted-source https://github.com/ContextualWisdomLab/.github.git
git -C "$GITHUB_WORKSPACE" fetch --depth=1 --no-tags trusted-source "$TRUSTED_SOURCE_REF"
git -C "$GITHUB_WORKSPACE" checkout --detach FETCH_HEAD
printf 'Materialized trusted coverage contract at %s from validated ref %s.\n' \
"$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD)" "$TRUSTED_SOURCE_REF"
- name: Report coverage source materialization failure
if: needs.coverage-source-tree.result != 'success'
run: |
echo "::error::Coverage source tree could not be materialized; see the coverage-source-tree job log for the exact target repository, base SHA, head SHA, and fetch or merge failure."
exit 1
- name: Download materialized pull request merge tree
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: opencode-coverage-source
path: ${{ runner.temp }}/opencode-coverage-artifact
- name: Prepare pull request merge tree for coverage measurement
env:
COVERAGE_SOURCE_ARCHIVE: ${{ runner.temp }}/opencode-coverage-artifact/opencode-coverage-source.tar
COVERAGE_SOURCE_WORKDIR: ${{ runner.temp }}/pr-head
run: |
set -euo pipefail
rm -rf "$COVERAGE_SOURCE_WORKDIR"
mkdir -p "$COVERAGE_SOURCE_WORKDIR"
# The archive contains pull-request-controlled paths. Validate every
# member before extraction so a symlink, hardlink, device, FIFO, or
# traversal path cannot redirect a later trusted host-side parser.
python3 -I - "$COVERAGE_SOURCE_ARCHIVE" "$COVERAGE_SOURCE_WORKDIR" <<'PY'
import os
from pathlib import Path, PurePosixPath
import sys
import tarfile
archive = Path(sys.argv[1])
destination = Path(sys.argv[2]).resolve()
if not archive.is_file() or archive.is_symlink():
raise SystemExit(
f"Coverage source archive is not a regular non-symlink file: {archive}"
)
with tarfile.open(archive, mode="r:*") as bundle:
members = bundle.getmembers()
seen: set[str] = set()
for member in members:
path = PurePosixPath(member.name)
normalized = path.as_posix()
if path.is_absolute() or ".." in path.parts:
raise SystemExit(
f"Coverage source archive contains an unsafe path: {member.name!r}"
)
if normalized in seen:
raise SystemExit(
f"Coverage source archive contains a duplicate path: {member.name!r}"
)
seen.add(normalized)
if not (member.isfile() or member.isdir()):
raise SystemExit(
"Coverage source archive contains a forbidden non-regular "
f"member: {member.name!r}"
)
candidate = (destination / Path(*path.parts)).resolve()
if os.path.commonpath((str(destination), str(candidate))) != str(destination):
raise SystemExit(
f"Coverage source archive escapes its destination: {member.name!r}"
)
bundle.extractall(destination, members=members, filter="data")
PY
git -C "$COVERAGE_SOURCE_WORKDIR" status --short
- name: Enforce post-merge stale agent replay guard
env:
PR_BASE_SHA: ${{ needs.validate-pr-metadata.outputs.base_sha }}
PR_HEAD_SHA: ${{ needs.validate-pr-metadata.outputs.head_sha }}
COVERAGE_SOURCE_WORKDIR: ${{ runner.temp }}/pr-head
# Dependency resolution may consume wheels/packages, but PR-defined
# install/build hooks are never executed implicitly.
UV_NO_BUILD: "1"
NPM_CONFIG_IGNORE_SCRIPTS: "true"
PNPM_CONFIG_IGNORE_SCRIPTS: "true"
YARN_ENABLE_SCRIPTS: "false"
GITHUB_TOKEN: ""
run: |
set -euo pipefail
replay_report="${RUNNER_TEMP}/pr-head-replay-guard.txt"
replay_status=0
python3 "$GITHUB_WORKSPACE/scripts/ci/pr_head_replay_guard.py" \
--repo-root "$COVERAGE_SOURCE_WORKDIR" \
--base-sha "$PR_BASE_SHA" \
--head-sha "$PR_HEAD_SHA" >"$replay_report" 2>&1 || replay_status=$?
cat "$replay_report"
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
{
printf '## PR head replay guard\n\n```text\n'
cat "$replay_report"
printf '\n```\n'
} >>"$GITHUB_STEP_SUMMARY"
fi
if [ "$replay_status" -ne 0 ]; then
echo "::error::Current HEAD discarded a prior base merge or replay evidence could not be evaluated; see the exact SHAs and deletion counts above."
exit "$replay_status"
fi
# Run every trusted follow-up before executing pull-request code. Even a
# credential-free test can write runner command files, so no trusted shell
# step may consume state after coverage measurement begins.
- name: Enforce changed-file syntax gate
env:
PR_BASE_SHA: ${{ needs.validate-pr-metadata.outputs.base_sha }}
COVERAGE_SOURCE_WORKDIR: ${{ runner.temp }}/pr-head
run: |
set -euo pipefail
# Deterministic per-file syntax check on the PR's changed files. The
# LLM reviewer reads diffs and the test suite only exercises imported
# files, so a syntax error in a changed file that no test imports (or
# in a language with no wired-in runner) could otherwise be approved.
changed_files_file="${RUNNER_TEMP}/opencode-syntax-changed-files.txt"
if ! git -C "$COVERAGE_SOURCE_WORKDIR" diff --name-only "$PR_BASE_SHA" HEAD >"$changed_files_file" 2>/dev/null; then
: >"$changed_files_file"
fi
syntax_report="${RUNNER_TEMP}/opencode-syntax-report.txt"
syntax_status=0
( cd "$COVERAGE_SOURCE_WORKDIR" && python3 "${GITHUB_WORKSPACE}/scripts/ci/changed_file_syntax_gate.py" --changed-files-file "$changed_files_file" ) >"$syntax_report" 2>&1 || syntax_status=$?
cat "$syntax_report"
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
{
printf '## Changed-file syntax gate\n\n```text\n'
cat "$syntax_report"
printf '\n```\n'
} >>"$GITHUB_STEP_SUMMARY"
fi
if [ "$syntax_status" -ne 0 ]; then
echo "::error::A changed file has a syntax error; OpenCode approval is blocked until it parses on the current head."
exit 1
fi
- name: Measure test and docstring evidence
id: measure
env:
PR_BASE_SHA: ${{ needs.validate-pr-metadata.outputs.base_sha }}
PR_HEAD_SHA: ${{ needs.validate-pr-metadata.outputs.head_sha }}
COVERAGE_SOURCE_WORKDIR: ${{ runner.temp }}/pr-head
# Apply wheel-only resolution in the same step that consumes
# pull-request dependency metadata. A value on an earlier step does
# not cross the GitHub Actions step boundary.
UV_NO_BUILD: "1"
run: |
set -euo pipefail
# The runner worker retains an Actions runtime token in an ancestor
# environment even after shell variables are unset. Execute all
# pull-request-controlled tests in Docker's default private PID namespace with a
# read-only trusted tree and no host Docker socket. The image is
# pinned to the reviewed linux/amd64 manifest digest. JavaScript
# registry access is likewise restricted to exact base package inputs
# or strictly registry/hash-bounded npm inputs from the live-validated
# HEAD; the PR-head sandbox consumes only the resulting offline store.
if [ "${OPENCODE_COVERAGE_SANDBOXED:-0}" != "1" ]; then
host_github_output="$GITHUB_OUTPUT"
sandbox_result_dir="${RUNNER_TEMP}/opencode-coverage-sandbox-result"
measure_step_script="$(realpath "$0")"
case "$measure_step_script" in
"${RUNNER_TEMP}"/*) ;;
*)
echo "::error::Coverage sandbox launcher is outside RUNNER_TEMP: ${measure_step_script}."
exit 1
;;
esac
if [ ! -f "$measure_step_script" ] || [ -L "$0" ] || [ "$(stat -c '%u' "$measure_step_script")" != "$(id -u)" ]; then
echo "::error::Coverage sandbox launcher failed regular-file, symlink, or ownership validation."
exit 1
fi
sudo rm -rf "$sandbox_result_dir"
mkdir -p "$sandbox_result_dir"
chmod 0700 "$sandbox_result_dir"
# Build the coverage tool image before the pull-request tree is
# mounted anywhere. The networked build context contains only this
# trusted Dockerfile, the reviewed CI requirements, exact base
# dependency locks, and strictly registry/hash-bounded npm locks
# read directly from the live-validated HEAD SHA. It never contains
# PR-head source, credentials, lifecycle execution, or runner
# command files.
coverage_tool_image="opencode-coverage-tools:${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
coverage_build_dir="${RUNNER_TEMP}/opencode-coverage-tool-build"
trusted_ci_requirements="${GITHUB_WORKSPACE}/requirements-opencode-review-ci-hashes.txt"
trusted_base_python_installer="${GITHUB_WORKSPACE}/scripts/ci/install_base_python_locks.py"
if [ ! -f "$trusted_ci_requirements" ] || [ -L "$trusted_ci_requirements" ]; then
echo "::error::Trusted coverage requirements must be a regular non-symlink file."
exit 1
fi
if [ ! -f "$trusted_base_python_installer" ] || [ -L "$trusted_base_python_installer" ]; then
echo "::error::Trusted base Python lock installer must be a regular non-symlink file."
exit 1
fi
sudo rm -rf "$coverage_build_dir"
mkdir -p "$coverage_build_dir"
chmod 0700 "$coverage_build_dir"
install -m 0644 "$trusted_ci_requirements" \
"$coverage_build_dir/requirements-opencode-review-ci-hashes.txt"
install -m 0755 "$trusted_base_python_installer" \
"$coverage_build_dir/install-base-python-locks.py"
python3 -I "$GITHUB_WORKSPACE/scripts/ci/materialize_base_python_requirements.py" \
--repo-root "$COVERAGE_SOURCE_WORKDIR" \
--base-sha "$PR_BASE_SHA" \
--output-dir "$coverage_build_dir/base-python-requirements"
python3 -I "$GITHUB_WORKSPACE/scripts/ci/materialize_base_javascript_packages.py" \
--repo-root "$COVERAGE_SOURCE_WORKDIR" \
--base-sha "$PR_BASE_SHA" \
--head-sha "$PR_HEAD_SHA" \
--output-dir "$coverage_build_dir/base-javascript-packages"
cat >"$coverage_build_dir/Dockerfile" <<'DOCKERFILE'
FROM docker.io/library/python:3.14-slim@sha256:b877e50bd90de10af8d82c57a022fc2e0dc731c5320d762a27986facfc3355c1
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
ca-certificates \
cargo \
curl \
git \
jq \
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
mesa-vulkan-drivers \
libvulkan1 \
pkg-config \
r-base \
r-cran-covr \
r-cran-testthat \
llvm-19 \
rustc \
util-linux \
vulkan-tools \
xz-utils \
&& rm -rf /var/lib/apt/lists/*
ENV LLVM_COV=/usr/bin/llvm-cov-19
ENV LLVM_PROFDATA=/usr/bin/llvm-profdata-19
RUN test -x "$LLVM_COV" && test -x "$LLVM_PROFDATA"
RUN curl --proto '=https' --tlsv1.2 -fsSLo /tmp/node-linux-x64.tar.xz \
https://nodejs.org/dist/v24.18.0/node-v24.18.0-linux-x64.tar.xz \
&& echo '55aa7153f9d88f28d765fcdad5ae6945b5c0f98a36881703817e4c450fa76742 /tmp/node-linux-x64.tar.xz' | sha256sum -c - \
&& tar --no-same-owner -xJf /tmp/node-linux-x64.tar.xz -C /usr/local --strip-components=1 \
&& test "$(/usr/local/bin/node --version)" = "v24.18.0" \
&& /usr/local/bin/npm --version >/dev/null \
&& rm -f /tmp/node-linux-x64.tar.xz
RUN curl --proto '=https' --tlsv1.2 -fsSLo /tmp/cargo-llvm-cov.tar.gz \
https://github.com/taiki-e/cargo-llvm-cov/releases/download/v0.8.7/cargo-llvm-cov-x86_64-unknown-linux-musl.tar.gz \
&& echo '967b5cc996c29d8baa52bbb4595ef1f53af35255af8e2036ddbc6468d7b523c7 /tmp/cargo-llvm-cov.tar.gz' | sha256sum -c - \
&& tar -xzf /tmp/cargo-llvm-cov.tar.gz -C /usr/local/bin cargo-llvm-cov \
&& chmod 0755 /usr/local/bin/cargo-llvm-cov \
&& rm -f /tmp/cargo-llvm-cov.tar.gz
RUN curl --proto '=https' --tlsv1.2 -fsSLo /tmp/pnpm.tgz \
https://registry.npmjs.org/pnpm/-/pnpm-11.5.3.tgz \
&& echo '7ac1c919341c213a34dc0d02afb7143c5c26ac26ee8c4782deea821b8ac64d2134a081fd8941dae6e29bbb48f58dfc2b7fbceeccc07cb2f09d219d342a4969ed /tmp/pnpm.tgz' | sha512sum -c - \
&& mkdir -p /opt/pnpm \
&& tar --no-same-owner -xzf /tmp/pnpm.tgz -C /opt/pnpm --strip-components=1 \
&& chmod 0755 /opt/pnpm/bin/pnpm.cjs \
&& ln -s /opt/pnpm/bin/pnpm.cjs /usr/local/bin/pnpm \
&& test "$(/usr/local/bin/pnpm --version)" = "11.5.3" \
&& rm -f /tmp/pnpm.tgz
COPY base-javascript-packages /tmp/base-javascript-packages
RUN set -eu; \
mkdir -p /opt/javascript-package-locks /opt/npm-cache /opt/pnpm-store; \
install -m 0444 /tmp/base-javascript-packages/manifest.json \
/opt/javascript-package-locks/manifest.json; \
jq -r '.[] | [.directory, .package_manager] | @tsv' \
/tmp/base-javascript-packages/manifest.json \
| while IFS="$(printf '\t')" read -r project_dir package_manager; do \
[ -n "$project_dir" ] || continue; \
cd "/tmp/base-javascript-packages/${project_dir}"; \
case "$package_manager" in \
npm) \
npm ci \
--ignore-scripts \
--cache /opt/npm-cache \
--no-audit \
--no-fund; \
rm -rf node_modules; \
;; \
pnpm@11.5.3) \
pnpm fetch \
--frozen-lockfile \
--ignore-scripts \
--store-dir /opt/pnpm-store; \
;; \
*) \
printf 'Unsupported trusted base package manager: %s\n' "$package_manager" >&2; \
exit 1; \
;; \
esac; \
done; \
npm cache verify --cache /opt/npm-cache; \
chmod -R a+rX /opt/npm-cache /opt/pnpm-store; \
rm -rf /tmp/base-javascript-packages
COPY requirements-opencode-review-ci-hashes.txt /tmp/requirements-opencode-review-ci-hashes.txt
RUN python3 -m pip install \
--break-system-packages \
--disable-pip-version-check \
--require-hashes \
--only-binary=:all: \
-r /tmp/requirements-opencode-review-ci-hashes.txt \
&& rm -f /tmp/requirements-opencode-review-ci-hashes.txt
COPY install-base-python-locks.py /usr/local/libexec/install-base-python-locks.py
COPY base-python-requirements /tmp/base-python-requirements
RUN python3 -I /usr/local/libexec/install-base-python-locks.py \
--requirements-root /tmp/base-python-requirements \
&& rm -rf /tmp/base-python-requirements \
&& rm -f /usr/local/libexec/install-base-python-locks.py
DOCKERFILE
if ! docker build --pull --no-cache --network=default \
--tag "$coverage_tool_image" \
--file "$coverage_build_dir/Dockerfile" \
"$coverage_build_dir"; then
echo "::error::Trusted coverage tool image build failed before PR execution."
exit 1
fi
sudo rm -rf "$coverage_build_dir"
sandbox_status=0
docker run --rm --init --network=none \
--name "opencode-coverage-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" \
--pids-limit 2048 \
--memory 14g \
--cpus 4 \
--security-opt no-new-privileges:true \
--cap-drop ALL \
--cap-add CHOWN \
--cap-add DAC_OVERRIDE \
--cap-add DAC_READ_SEARCH \
--cap-add FOWNER \
--cap-add KILL \
--cap-add SETGID \
--cap-add SETUID \
--tmpfs /tmp:rw,exec,nosuid,nodev,mode=1777,size=4g \
--tmpfs /secure-output:rw,noexec,nosuid,nodev,mode=0700,size=64m \
--mount "type=bind,source=${GITHUB_WORKSPACE},target=/trusted,readonly" \
--mount "type=bind,source=${COVERAGE_SOURCE_WORKDIR},target=/work" \
--mount "type=bind,source=${sandbox_result_dir},target=/out" \
--mount "type=bind,source=${measure_step_script},target=/trusted-measure-step.sh,readonly" \
--env OPENCODE_COVERAGE_SANDBOXED=1 \
--env OPENCODE_SANDBOX_RESULT_DIR=/out \
--env GITHUB_ACTIONS=true \
--env CI=true \
--env GITHUB_WORKSPACE=/trusted \
--env COVERAGE_SOURCE_WORKDIR=/work \
--env PR_BASE_SHA="$PR_BASE_SHA" \
--env PR_HEAD_SHA="$PR_HEAD_SHA" \
--env RUNNER_TEMP=/secure-output \
--env GITHUB_OUTPUT=/secure-output/github-output \
--env GITHUB_STEP_SUMMARY=/secure-output/step-summary \
"$coverage_tool_image" \
/bin/bash /trusted-measure-step.sh || sandbox_status=$?
sandbox_output="${sandbox_result_dir}/github-output"
if [ ! -f "$sandbox_output" ] || [ -L "$sandbox_output" ]; then
echo "::error::Coverage sandbox did not publish a regular authenticated output file; sandbox exit=${sandbox_status}."
exit 1
fi
sandbox_output_owner="$(stat -c '%u' "$sandbox_output")"
sandbox_output_size="$(stat -c '%s' "$sandbox_output")"
if [ "$sandbox_output_owner" != "0" ] || [ "$sandbox_output_size" -gt 262144 ]; then
echo "::error::Coverage sandbox output failed ownership/size validation (owner=${sandbox_output_owner}, bytes=${sandbox_output_size})."
exit 1
fi
cat "$sandbox_output" >>"$host_github_output"
if [ "$sandbox_status" -ne 0 ]; then
echo "::error::Coverage sandbox reported failing test, build, or coverage evidence (exit ${sandbox_status}); the complete reason is in the log above."
exit "$sandbox_status"
fi
echo "Coverage measurement completed in the isolated current-head sandbox."
exit 0
fi
# Use a fixed nobody-like identity that cannot traverse the host-owned
# /out bind mount. This prevents even a daemonized test process from
# racing trusted result publication.
export OPENCODE_SANDBOX_UID=65532
export OPENCODE_SANDBOX_GID=65532
# Keep repository-local Git metadata outside the untrusted test
# identity's write boundary. The source tree itself stays writable so
# package managers and tests can create ordinary build artifacts.
chown "$OPENCODE_SANDBOX_UID:$OPENCODE_SANDBOX_GID" /work
find /work -mindepth 1 -maxdepth 1 ! -name .git \
-exec chown -R --no-dereference "$OPENCODE_SANDBOX_UID:$OPENCODE_SANDBOX_GID" {} +
if [ -e /work/.git ] || [ -L /work/.git ]; then
chown -R root:root /work/.git
chmod -R go-w /work/.git
fi
mkdir -p "$RUNNER_TEMP" /work/.opencode-sandbox-home /work/.opencode-sandbox-cache
chown "$OPENCODE_SANDBOX_UID:$OPENCODE_SANDBOX_GID" /work/.opencode-sandbox-home /work/.opencode-sandbox-cache
chmod 0700 "$RUNNER_TEMP"
: >"$GITHUB_OUTPUT"
chmod 0600 "$GITHUB_OUTPUT"
unset ACTIONS_ID_TOKEN_REQUEST_TOKEN ACTIONS_ID_TOKEN_REQUEST_URL ACTIONS_RUNTIME_TOKEN GH_TOKEN GITHUB_TOKEN
umask 077
cd "$COVERAGE_SOURCE_WORKDIR"
summary_file="${RUNNER_TEMP}/coverage-evidence.md"
summary_output_file="${RUNNER_TEMP}/coverage-evidence-output.md"
failures=0
r_peer_check_required=0
append() {
printf '%s\n' "$*" >>"$summary_file"
}
append_command() {
printf '$ ' >>"$summary_file"
printf '%q ' "$@" >>"$summary_file"
printf '\n' >>"$summary_file"
}
emit_captured_log() {
local log_file="$1"
local line_count
line_count="$(wc -l <"$log_file" | tr -d '[:space:]')"
if [ "${line_count:-0}" -le 260 ]; then
cat "$log_file" >>"$summary_file"
return
fi
sed -n '1,140p' "$log_file" >>"$summary_file"
append ""
append "... output truncated: showing first 140 and last 180 of ${line_count} lines ..."
append ""
tail -n 180 "$log_file" >>"$summary_file"
}
run_and_capture() {
local label="$1"
shift
local log_file
log_file="$(mktemp)"
append "### ${label}"
append ""
append '```text'
append_command "$@"
set +e
timeout --kill-after=20 900 setpriv \
--reuid "$OPENCODE_SANDBOX_UID" \
--regid "$OPENCODE_SANDBOX_GID" \
--clear-groups \
env \
-u ACTIONS_ID_TOKEN_REQUEST_TOKEN \
-u ACTIONS_ID_TOKEN_REQUEST_URL \
-u ACTIONS_RUNTIME_TOKEN \
-u GH_TOKEN \
-u GITHUB_TOKEN \
GITHUB_ENV=/dev/null \
GITHUB_PATH=/dev/null \
GITHUB_OUTPUT=/dev/null \
GITHUB_STEP_SUMMARY=/dev/null \
BASH_ENV=/dev/null \
UV_NO_BUILD=1 \
GIT_CONFIG_NOSYSTEM=1 \
GIT_CONFIG_GLOBAL=/dev/null \
GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0=safe.directory \
GIT_CONFIG_VALUE_0=/work \
HOME=/work/.opencode-sandbox-home \
XDG_CACHE_HOME=/work/.opencode-sandbox-cache \
CARGO_HOME=/work/.opencode-sandbox-home/.cargo \
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
"$@" >"$log_file" 2>&1
local rc=$?
set -e
emit_captured_log "$log_file"
append '```'
append ""
if [ "$rc" -ne 0 ]; then
append "- Result: FAIL (exit ${rc})"
failures=$((failures + 1))
else
append "- Result: PASS"
fi
append ""
rm -f "$log_file"
}
run_r_package_testthat() {
local package_name="$1"
local log_file rc classification description_snapshot
log_file="$(mktemp)"
append "### R package testthat suite"
append ""
description_snapshot="$(mktemp "$RUNNER_TEMP/r-description.XXXXXX")"
if [ ! -f DESCRIPTION ] || [ -L DESCRIPTION ] ||
! install -m 0444 -- DESCRIPTION "$description_snapshot"; then
append "- Result: FAIL"
append "- Reason: DESCRIPTION must be a regular non-symlink file that can be snapshotted before untrusted tests run."
append ""
failures=$((failures + 1))
rm -f "$log_file" "$description_snapshot"
return
fi
append '```text'
append_command \
Rscript -e 'lib <- Sys.getenv("R_LIBS_USER"); .libPaths(c(lib, .libPaths())); testthat::test_dir("tests/testthat")'
set +e
timeout --kill-after=20 900 setpriv \
--reuid "$OPENCODE_SANDBOX_UID" \
--regid "$OPENCODE_SANDBOX_GID" \
--clear-groups \
env \
-u ACTIONS_ID_TOKEN_REQUEST_TOKEN \
-u ACTIONS_ID_TOKEN_REQUEST_URL \
-u ACTIONS_RUNTIME_TOKEN \
-u GH_TOKEN \
-u GITHUB_TOKEN \
GITHUB_ENV=/dev/null \
GITHUB_PATH=/dev/null \
GITHUB_OUTPUT=/dev/null \
GITHUB_STEP_SUMMARY=/dev/null \
BASH_ENV=/dev/null \
UV_NO_BUILD=1 \
GIT_CONFIG_NOSYSTEM=1 \
GIT_CONFIG_GLOBAL=/dev/null \
GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0=safe.directory \
GIT_CONFIG_VALUE_0=/work \
HOME=/work/.opencode-sandbox-home \
XDG_CACHE_HOME=/work/.opencode-sandbox-cache \
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
Rscript -e 'lib <- Sys.getenv("R_LIBS_USER"); .libPaths(c(lib, .libPaths())); testthat::test_dir("tests/testthat")' \
>"$log_file" 2>&1
rc=$?
set -e
emit_captured_log "$log_file"
append '```'
append ""
if [ "$rc" -eq 0 ]; then
append "- Result: PASS"
elif classification="$(
python3 -I "$GITHUB_WORKSPACE/scripts/ci/r_coverage_peer_gate.py" \
classify-testthat \
--log "$log_file" \
--package "$package_name" \
--description "$description_snapshot" 2>/dev/null
)"; then
append "- Result: PASS"
append "- Reason: ${classification}; direct sandbox failures are deferred only to a successful current-head peer R CMD check."
r_peer_check_required=1
else
append "- Result: FAIL (exit ${rc})"
failures=$((failures + 1))
fi
append ""
rm -f "$log_file" "$description_snapshot"
}
run_and_capture_advisory() {
local label="$1"
shift
local log_file
log_file="$(mktemp)"
append "### ${label}"
append ""
append '```text'
append_command "$@"
set +e
timeout --kill-after=20 900 setpriv \
--reuid "$OPENCODE_SANDBOX_UID" \
--regid "$OPENCODE_SANDBOX_GID" \
--clear-groups \
env \
-u ACTIONS_ID_TOKEN_REQUEST_TOKEN \
-u ACTIONS_ID_TOKEN_REQUEST_URL \
-u ACTIONS_RUNTIME_TOKEN \
-u GH_TOKEN \
-u GITHUB_TOKEN \
GITHUB_ENV=/dev/null \
GITHUB_PATH=/dev/null \
GITHUB_OUTPUT=/dev/null \
GITHUB_STEP_SUMMARY=/dev/null \
BASH_ENV=/dev/null \