@@ -41,39 +41,9 @@ def _commit(repo: Path, relative_path: str) -> str:
4141 return _git (repo , 'rev-parse' , 'HEAD' )
4242
4343
44- def _run_scope (repo : Path , sha : str , * , main_sha : str | None = None ) -> tuple [dict [str , str ], str ]:
44+ def _run_scope (repo : Path , sha : str ) -> tuple [dict [str , str ], str ]:
4545 output = repo / 'github-output.txt'
4646 summary = repo / 'github-summary.md'
47- fake_bin = repo / 'fake-bin'
48- fake_bin .mkdir ()
49- # The scope step intentionally needs two GitHub API proofs before it may
50- # no-op a stale run. Model those proofs locally instead of relying on a
51- # real token/network in unit tests.
52- curl = fake_bin / 'curl'
53- curl .write_text (
54- '''#!/usr/bin/env bash
55- set -euo pipefail
56- output=''
57- for ((i = 1; i <= $#; i++)); do
58- if [[ "${!i}" == '--output' ]]; then
59- j=$((i + 1)); output="${!j}"
60- fi
61- done
62- url="${!#}"
63- if [[ "$url" == */git/ref/heads/main ]]; then
64- printf '{"ref":"refs/heads/main","object":{"type":"commit","sha":"%s"}}' "$MOCK_MAIN_SHA" > "$output"
65- elif [[ "$url" == */compare/* ]]; then
66- status=identical
67- [[ "$RELEASE_SHA" != "$MOCK_MAIN_SHA" ]] && status=behind
68- printf '{"base_commit":{"sha":"%s"},"head_commit":{"sha":"%s"},"status":"%s"}' "$RELEASE_SHA" "$MOCK_MAIN_SHA" "$status" > "$output"
69- else
70- exit 1
71- fi
72- printf '200'
73- ''' ,
74- encoding = 'utf-8' ,
75- )
76- curl .chmod (0o755 )
7747 scope_step = next (step for step in _scope_job ()['steps' ] if step .get ('id' ) == 'scope' )
7848 result = subprocess .run (
7949 ['bash' , '-c' , scope_step ['run' ]],
@@ -82,11 +52,11 @@ def _run_scope(repo: Path, sha: str, *, main_sha: str | None = None) -> tuple[di
8252 capture_output = True ,
8353 env = {
8454 ** os .environ ,
85- 'PATH' : f'{ fake_bin } :{ os .environ ["PATH" ]} ' ,
86- 'GH_TOKEN' : 'test-token' ,
87- 'GITHUB_REPOSITORY' : 'BasedHardware/omi' ,
55+ 'GH_TOKEN' : os .environ .get ('GH_TOKEN' , 'test-token' ),
56+ 'GITHUB_TOKEN' : os .environ .get ('GITHUB_TOKEN' , 'test-token' ),
57+ 'GITHUB_REPOSITORY' : os .environ .get ('GITHUB_REPOSITORY' , 'test-org/test-repo' ),
58+ 'GITHUB_API_URL' : os .environ .get ('GITHUB_API_URL' , 'https://api.github.com' ),
8859 'RELEASE_SHA' : sha ,
89- 'MOCK_MAIN_SHA' : main_sha or sha ,
9060 'GITHUB_OUTPUT' : str (output ),
9161 'GITHUB_STEP_SUMMARY' : str (summary ),
9262 },
@@ -109,7 +79,7 @@ def git_repo(tmp_path: Path) -> Path:
10979def test_unrelated_desktop_change_exits_as_a_green_no_op (git_repo : Path ) -> None :
11080 desktop_sha = _commit (git_repo , 'desktop/macos/README.md' )
11181
112- outputs , summary = _run_scope (git_repo , desktop_sha , main_sha = _git ( git_repo , 'rev-parse' , f' { desktop_sha } ^' ) )
82+ outputs , summary = _run_scope (git_repo , desktop_sha )
11383
11484 assert outputs == {'applies' : 'false' }
11585 assert 'Green no-op' in summary
0 commit comments