Skip to content

Commit 37f2e27

Browse files
EvangelinkCopilot
andauthored
Fix Linux build-analysis workflow contract tests (#12431)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 62b9187 commit 37f2e27

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎.github/scripts/test_agentic_workflow_warning_contracts.py‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ class BuildAnalysisInputTests(unittest.TestCase):
262262

263263
def export(self, workflow: str, *, files: tuple[str, ...] = ("1_Linux.binlog",),
264264
shadow_source: str | None = None,
265+
fixture_parent: pathlib.Path | None = None,
265266
**overrides: str) -> tuple[subprocess.CompletedProcess, pathlib.Path, dict]:
266267
temporary = tempfile.TemporaryDirectory(
267-
prefix="gh-aw-build-inputs-", dir=os.environ.get("WORKFLOW_WARNING_TMP")
268+
prefix="gh-aw-build-inputs-", dir=fixture_parent or os.environ.get("WORKFLOW_WARNING_TMP")
268269
)
269270
self.addCleanup(temporary.cleanup)
270271
root = pathlib.Path(temporary.name)
@@ -306,14 +307,34 @@ def export(self, workflow: str, *, files: tuple[str, ...] = ("1_Linux.binlog",),
306307
source, _ = authored(workflow + ".md")
307308
script = next(step["run"] for step in source["steps"]
308309
if step.get("name") == "Export agent context")
309-
script = script.replace("/tmp/binlogs", binlogs.as_posix()).replace("/tmp/gh-aw", shared.as_posix())
310+
script = re.sub(
311+
r"/tmp/(binlogs|gh-aw)",
312+
lambda match: (binlogs if match[1] == "binlogs" else shared).as_posix(),
313+
script,
314+
)
310315
prelude = 'export PATH="$(cd "$FIXTURE_BIN" && pwd):$PATH"\n'
311316
result = subprocess.run(
312317
[str(BASH), "--noprofile", "--norc", "-s"], input=prelude + script,
313318
cwd=root, env=env, text=True, capture_output=True, timeout=TIMEOUT,
314319
)
315320
return result, shared / "build-failure-analysis/analysis-inputs.json", values
316321

322+
def test_build_context_preserves_fixture_paths_containing_workflow_paths(self) -> None:
323+
temporary = tempfile.TemporaryDirectory(
324+
prefix="gh-aw-build-paths-", dir=os.environ.get("WORKFLOW_WARNING_TMP")
325+
)
326+
self.addCleanup(temporary.cleanup)
327+
root = pathlib.Path(temporary.name)
328+
for parent in ("gh-aw", "binlogs"):
329+
directory = root / "tmp" / parent
330+
directory.mkdir(parents=True)
331+
for workflow in self.workflows:
332+
with self.subTest(workflow=workflow, parent=parent):
333+
result, path, _ = self.export(workflow, fixture_parent=directory)
334+
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
335+
inputs = json.loads(path.read_text(encoding="utf-8"))
336+
self.assertEqual(["/data/binlogs/1_Linux.binlog"], inputs["GH_AW_BINLOG_LIST"])
337+
317338
def test_build_context_is_readable_without_environment_probes(self) -> None:
318339
for workflow in self.workflows:
319340
with self.subTest(workflow=workflow):
@@ -334,7 +355,7 @@ def test_build_context_is_readable_without_environment_probes(self) -> None:
334355
"GH_AW_MISSING_LEGS": values["GH_AW_MISSING_LEGS_VALUE"],
335356
}, inputs)
336357
prompt = authored("shared/build-failure-analysis-shared.md")[1]
337-
command = re.search(r"```bash\n(cat [^\n]+)\n", prompt)
358+
command = re.search(r"```bash\n[ \t]*(cat [^\n]+)\n", prompt)
338359
self.assertIsNotNone(command, "Give the analyst a standalone allowed manifest read")
339360
args = shlex.split(command[1])
340361
self.assertIn(args[0], authored(workflow + ".md")[0]["tools"]["bash"])

‎.github/workflows/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ python .github/scripts/test_build_failure_analysis_checkout.py
5858
python .github/scripts/check_action_pins.py
5959
```
6060

61+
Build-context fixtures substitute authored paths in one pass so temporary
62+
directories containing `/tmp/gh-aw` or `/tmp/binlogs` remain intact. Their
63+
prompt-command extraction also accepts Markdown list indentation.
64+
6165
These are local contract checks, not evidence of live GitHub alert access,
6266
model analysis, or review/PR publication. Live runs require separate authorization.
6367

0 commit comments

Comments
 (0)