@@ -90,8 +90,10 @@ def _requirement_disagrees(actual: str, expected: str, version: str) -> str:
9090# Minimum live pin sites, independent of the writer: a removed version no longer matches
9191# discovery. Additional documentation matches cannot replace these required sites.
9292_EXPECTED_REQUIREMENT_SITES = {
93- ".github/workflows/build_linux.yml" : 1 ,
94- ".github/workflows/executorch-test-linux.yml" : 2 ,
93+ # The workflows read the version from these files rather than naming it: the exact pin, and
94+ # the user-facing range whose lower bound is the pin.
95+ "packaging/executorch_pin.txt" : 1 ,
96+ "packaging/executorch_range.txt" : 1 ,
9597 "MODULE.bazel" : 1 ,
9698 "docker/MODULE.bazel.docker" : 1 ,
9799 "docker/MODULE.bazel.ngc" : 1 ,
@@ -277,6 +279,22 @@ def _without_trailing_comment(path: str, text: str) -> str:
277279 return text
278280
279281
282+ def _pip_command_around (path : str , number : int ) -> str :
283+ """The whole pip invocation containing line ``number``, following backslash continuations.
284+
285+ A pip command in a workflow is wrapped across lines, so the index flag and the ``-r`` flag
286+ usually sit on different ones. Reading a single line would miss the index.
287+ """
288+ lines = (REPO_ROOT / path ).read_text ().splitlines ()
289+ start = number - 1
290+ while start > 0 and lines [start - 1 ].rstrip ().endswith ("\\ " ):
291+ start -= 1
292+ end = number - 1
293+ while end + 1 < len (lines ) and lines [end ].rstrip ().endswith ("\\ " ):
294+ end += 1
295+ return "\n " .join (lines [start : end + 1 ])
296+
297+
280298def _counts_toward_minimum (path : str , number : int ) -> bool :
281299 """Whether a requirement at this line counts toward the per-file minimum.
282300
@@ -382,7 +400,9 @@ def test_runtime_callers_use_the_shared_pinned_build(caller, job):
382400 if s .get ("name" ) == "Build the ExecuTorch runtime wheel"
383401 )
384402 assert step ["if" ].startswith ("${{ inputs.build-executorch-runtime" )
385- assert f'executorch=={ _versions ()["__executorch_version__" ]} ' in step ["run" ]
403+ # The version arrives through the requirement file, so the pin moves without touching this
404+ # workflow. Everything else about the install is still asserted here.
405+ assert "-r packaging/executorch_pin.txt" in step ["run" ]
386406 assert "${CONDA_RUN} python -m pip install pyyaml" in step ["run" ]
387407 assert "nightly/${CU_VERSION}" in step ["run" ]
388408 assert "release-executorch-runtime-wheel-artifacts" not in workflow ["jobs" ]
@@ -1820,6 +1840,7 @@ def test_the_range_install_runs_in_a_fresh_venv():
18201840 install = next (line for line in after .splitlines () if line .strip ())
18211841 argv = shlex .split (install , comments = True )
18221842 assert argv [:5 ] == [venv + "/bin/python" , "-m" , "pip" , "install" , "--no-deps" ], argv
1843+ assert "-r" in argv and "packaging/executorch_range.txt" in argv , argv
18231844
18241845
18251846@pytest .mark .unit
@@ -1963,12 +1984,13 @@ def test_review_cuda_export_is_required(monkeypatch, workflow_name):
19631984
19641985
19651986@pytest .mark .unit
1966- def test_review_venv_name_in_comment_does_not_count (monkeypatch ):
1987+ def test_the_range_install_must_name_the_fresh_venv (monkeypatch ):
19671988 path = REPO_ROOT / ".github/workflows/executorch-test-linux.yml"
19681989 text = path .read_text ().replace (
1969- '"${RUNNER_TEMP}/range-check-venv/bin/python" -m pip install --no-deps ' ,
1970- "python -m pip install --no-deps # range-check-venv " ,
1990+ '"${RUNNER_TEMP}/range-check-venv/bin/python" -m pip install' ,
1991+ "python -m pip install" ,
19711992 )
1993+ assert text != path .read_text (), "the decoy changed nothing, so this proves nothing"
19721994 original = Path .read_text
19731995 monkeypatch .setattr (
19741996 Path ,
@@ -2716,3 +2738,31 @@ def test_the_install_script_leaves_the_companion_out(tmp_path, branch):
27162738 assert not any ("executorch_runtime" in name for name in selected ), selected
27172739 # Both of the others, including the variant a prefix match would have missed.
27182740 assert len (selected ) == 2 , selected
2741+
2742+
2743+ @pytest .mark .unit
2744+ def test_every_requirement_file_install_names_the_nightly_channel ():
2745+ """A ``-r`` install carries no requirement literal, so the channel scan cannot see it.
2746+
2747+ That scan walks requirement literals inside pip commands, which is how it checks the index.
2748+ Passing the pin through a file removes the literal from the command, so without this the
2749+ nightly channel could be dropped or pointed at another index and every other guard here
2750+ would still pass. ExecuTorch's CUDA wheels exist only on the nightly index, so an install
2751+ that names another one resolves to a processor-only build.
2752+ """
2753+ wrong = []
2754+ for line in _git ("grep" , "-nI" , "-e" , "-r packaging/executorch_" ).splitlines ():
2755+ path , number , text = line .split (":" , 2 )
2756+ if _is_source_test (path ):
2757+ continue
2758+ command = _pip_command_around (path , int (number ))
2759+ if not re .search (
2760+ r"download\.pytorch\.org/whl/nightly/\$\{CU_VERSION\}" , command
2761+ ):
2762+ wrong .append (
2763+ f"{ path } :{ number } installs a pinned requirement file without the nightly channel"
2764+ )
2765+ assert not wrong , wrong
2766+ assert _git (
2767+ "grep" , "-lI" , "-e" , "-r packaging/executorch_"
2768+ ).strip (), "no requirement-file install found, so this test is not looking"
0 commit comments