Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions .github/agents/build-failure-analyst.agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ You do not write to the repository directly. Every change you make is staged as

## Inputs the Calling Workflow Provides

The caller (typically `build-failure-analysis.md` or `build-failure-analysis-command.md`) locates the failed **Azure DevOps** `microsoft.testfx` build, downloads the `.binlog` each build leg produced (it does **not** rebuild), uploads them as an artifact, and the gh-aw MCP gateway mounts them read-only into the `binlog-mcp` container under the directory `/data/binlogs` (one `*.binlog` per leg, enumerated in `GH_AW_BINLOG_LIST`). The caller also sets the environment variables below. You must read all of them before doing anything else.
The caller (typically `build-failure-analysis.md` or `build-failure-analysis-command.md`) locates the failed **Azure DevOps** `microsoft.testfx` build, downloads the `.binlog` each build leg produced (it does **not** rebuild), uploads them as an artifact, and the gh-aw MCP gateway mounts them read-only into the `binlog-mcp` container under the directory `/data/binlogs` (one `*.binlog` per leg, enumerated in `GH_AW_BINLOG_LIST`). These workflows supply the inputs below in `/tmp/gh-aw/build-failure-analysis/analysis-inputs.json`; read it with a standalone `cat` command before doing anything else. Use its values rather than probing the process environment. Other callers may supply equivalent environment values.

The `/data/binlogs` mount is not a local agent directory. Query its paths only
through `binlog-mcp`; failed local directory probes do not establish missing logs.

| Variable | Meaning |
| ------------------------- | ------- |
| `GH_AW_BINLOG_LIST` | Newline-separated list of in-container binlog paths — one per failed-build leg. The fetch step stages them under `/data/binlogs` with a unique numeric prefix per artifact/file (e.g. `/data/binlogs/1_0_Logs_Build_Linux_Release.binlog`), so match on the `.binlog` suffix rather than an exact leg name. Pass each as `binlog_file` on the `binlog_*` MCP tools. |
| `GH_AW_BINLOG_DIR` | Directory the binlogs are mounted under (`/data/binlogs`); enumerate `*.binlog` here if `GH_AW_BINLOG_LIST` is unavailable. |
| `GH_AW_BINLOG_LIST` | Array of in-container binlog paths in the workflow manifest (newline-separated for environment-only callers) — one per failed-build leg. The fetch step stages them under `/data/binlogs` with a unique numeric prefix per artifact/file (e.g. `/data/binlogs/1_0_Logs_Build_Linux_Release.binlog`). Pass every path verbatim as `binlog_file` on the `binlog_*` MCP tools. |
| `GH_AW_BINLOG_DIR` | Directory the binlogs are mounted under inside `binlog-mcp` (`/data/binlogs`), not inside the agent sandbox. A missing required inventory is incomplete analysis, not a reason to probe this directory locally. |
| `GH_AW_BINLOG_PATH` | The first entry of `GH_AW_BINLOG_LIST` — a single-path convenience for prompts/tools that expect one. Empty when no binlog was retrieved. |
| `GH_AW_BINLOG_HOST_PATH` | URL of the originating Azure DevOps build (`https://dev.azure.com/dnceng-public/public/_build/results?buildId=…`). Use only for permalinks / human-facing references — read the binlog data via MCP. |
| `GH_AW_BUILD_OUTCOME` | Always `failure` when this agent runs — the workflow only activates after the Azure DevOps `microsoft.testfx` build failed. |
Expand Down
15 changes: 12 additions & 3 deletions .github/agents/pipeline-test-triage-analyst.agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,18 @@ Every pull-request comment must:

Every created issue must:

- provide a unique `temporary_id` and
`fields: [{"name": "Type", "value": "Bug"}]` in the `create_issue` call so
the native GitHub issue type is assigned atomically with issue creation;
- provide a unique `temporary_id` in the `create_issue` call, then queue
`set_issue_type` with `issue_type: "Bug"` and `issue_number` set to that
same temporary ID, including its `#aw_` prefix. For example, creation with
`temporary_id: "aw_triage123"` is followed by
`set_issue_type({"issue_number": "#aw_triage123", "issue_type": "Bug"})`;
- do not send `fields: [{"name": "Type", "value": "Bug"}]`: `fields` sets
custom issue fields, not the native GitHub Issue Type. Creation and type
assignment are separate queued operations; the publisher resolves the
temporary ID only after successful creation. Do not guess or poll for a
newly created issue number during this agent run. If the creation tool
reports a duplicate, do not queue type assignment for it. Queue at most one
type request; the publisher owns any deferred retry;
- add exactly one relevant allowed label when applicable:
`type/regression`, `type/flaky-test`, `area/dump`, or `area/performance`;
- explain category and confidence, why the signal is actionable, first/last
Expand Down
134 changes: 134 additions & 0 deletions .github/scripts/test_agentic_workflow_warning_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,140 @@ def commit(self, message: str) -> str:
return self.git("rev-parse", "HEAD")


class BuildAnalysisInputTests(unittest.TestCase):
workflows = ("build-failure-analysis", "build-failure-analysis-command")

def export(self, workflow: str, *, files: tuple[str, ...] = ("1_Linux.binlog",),
shadow_source: str | None = None,
**overrides: str) -> tuple[subprocess.CompletedProcess, pathlib.Path, dict]:
temporary = tempfile.TemporaryDirectory(
prefix="gh-aw-build-inputs-", dir=os.environ.get("WORKFLOW_WARNING_TMP")
)
self.addCleanup(temporary.cleanup)
root = pathlib.Path(temporary.name)
binlogs, shared, tools = root / "binlogs", root / "shared", root / "tools"
for directory in (binlogs, shared, tools, root / "home"):
directory.mkdir()
for name in files:
(binlogs / name).write_bytes(b"fixture inventory; not parsed as a binary log")
wrapper = tools / "python3"
wrapper.write_text('#!/bin/bash\nexec "$FIXTURE_PYTHON" "$@"\n', encoding="utf-8")
wrapper.chmod(0o755)
env = {key: value for key, value in os.environ.items()
if key.upper() in ("PATH", "SYSTEMROOT", "WINDIR", "TEMP", "TMP")}
values = {
"GH_AW_BINLOG_FOUND_VALUE": "true", "GH_AW_PR_NUMBER_VALUE": "73",
"GH_AW_PR_HEAD_SHA_VALUE": "a" * 40, "GH_AW_PR_MERGE_SHA_VALUE": "b" * 40,
"GH_AW_ADO_BUILD_URL_VALUE": "https://dev.azure.com/fixture/public/_build/results?buildId=420",
"GH_AW_MISSING_LEGS_VALUE": 'Windows "Release"\n(unknown timeline)',
"GH_AW_GITHUB_WORKSPACE": str(root / "workspace"),
}
values.update(overrides)
env.update(values)
if shadow_source is not None:
location = root if shadow_source == "checkout" else root / "pythonpath"
location.mkdir(exist_ok=True)
(location / "json.py").write_text(
'open("shadow-imported", "w").write("untrusted module executed")\n'
'raise RuntimeError("PR-controlled json module imported")\n',
encoding="utf-8",
)
if shadow_source == "pythonpath":
env["PYTHONPATH"] = str(location)
env.update({
"HOME": str(root / "home"), "USERPROFILE": str(root / "home"),
"GITHUB_REPOSITORY": REPOSITORY, "GITHUB_ENV": str(root / "context.env"),
"FIXTURE_PYTHON": str(sys.executable), "FIXTURE_BIN": tools.as_posix(),
"PYTHONDONTWRITEBYTECODE": "1",
})
source, _ = authored(workflow + ".md")
script = next(step["run"] for step in source["steps"]
if step.get("name") == "Export agent context")
script = script.replace("/tmp/binlogs", binlogs.as_posix()).replace("/tmp/gh-aw", shared.as_posix())
prelude = 'export PATH="$(cd "$FIXTURE_BIN" && pwd):$PATH"\n'
result = subprocess.run(
[str(BASH), "--noprofile", "--norc", "-s"], input=prelude + script,
cwd=root, env=env, text=True, capture_output=True, timeout=TIMEOUT,
)
return result, shared / "build-failure-analysis/analysis-inputs.json", values

def test_build_context_is_readable_without_environment_probes(self) -> None:
for workflow in self.workflows:
with self.subTest(workflow=workflow):
result, path, values = self.export(
workflow, files=("2_Windows Release.binlog", "1_Linux.binlog"))
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
self.assertTrue(path.is_file(), "The analyst needs a sandbox-visible input manifest")
inputs = json.loads(path.read_text(encoding="utf-8"))
self.assertEqual({
"schema_version": 1, "repository": REPOSITORY,
"GH_AW_BUILD_OUTCOME": "failure", "GH_AW_BINLOG_DIR": "/data/binlogs",
"GH_AW_BINLOG_LIST": ["/data/binlogs/1_Linux.binlog", "/data/binlogs/2_Windows Release.binlog"],
"GH_AW_BINLOG_PATH": "/data/binlogs/1_Linux.binlog",
"GH_AW_PR_NUMBER": 73, "GH_AW_PR_HEAD_SHA": "a" * 40,
"GH_AW_PR_MERGE_SHA": "b" * 40,
"GH_AW_BINLOG_HOST_PATH": values["GH_AW_ADO_BUILD_URL_VALUE"],
"GH_AW_WORKSPACE": values["GH_AW_GITHUB_WORKSPACE"],
"GH_AW_MISSING_LEGS": values["GH_AW_MISSING_LEGS_VALUE"],
}, inputs)
prompt = authored("shared/build-failure-analysis-shared.md")[1]
command = re.search(r"```bash\n(cat [^\n]+)\n", prompt)
self.assertIsNotNone(command, "Give the analyst a standalone allowed manifest read")
args = shlex.split(command[1])
self.assertIn(args[0], authored(workflow + ".md")[0]["tools"]["bash"])
self.assertEqual("/tmp/gh-aw/build-failure-analysis/analysis-inputs.json", args[1])
read = subprocess.run(
[str(BASH), "--noprofile", "--norc", "-c", 'cat "$1"', "fixture", path.as_posix()],
env={"PATH": os.environ["PATH"], "SYSTEMROOT": os.environ.get("SYSTEMROOT", "")},
text=True, capture_output=True, timeout=TIMEOUT,
)
self.assertEqual(0, read.returncode, read.stderr)
self.assertEqual(inputs, json.loads(read.stdout))

def test_build_context_rejects_missing_inventory_or_invalid_identity(self) -> None:
cases = (
((), {}),
(("1_Linux.binlog",), {"GH_AW_BINLOG_FOUND_VALUE": "false"}),
(("1_Linux.binlog",), {"GH_AW_PR_NUMBER_VALUE": "false"}),
(("1_Linux.binlog",), {"GH_AW_PR_NUMBER_VALUE": "0"}),
(("1_Linux.binlog",), {"GH_AW_PR_HEAD_SHA_VALUE": "abc"}),
(("1_Linux.binlog",), {"GH_AW_PR_MERGE_SHA_VALUE": "invalid"}),
)
for workflow in self.workflows:
for files, values in cases:
with self.subTest(workflow=workflow, files=files, values=values):
result, path, _ = self.export(workflow, files=files, **values)
self.assertNotEqual(0, result.returncode, "Invalid inputs must stop the agent")
self.assertIn("Missing or invalid required build-analysis inputs.", result.stderr)
self.assertFalse(path.exists())

def test_build_context_ignores_checkout_and_python_path_modules(self) -> None:
for workflow in self.workflows:
for source in ("checkout", "pythonpath"):
with self.subTest(workflow=workflow, source=source):
result, path, _ = self.export(workflow, shadow_source=source)
self.assertFalse((path.parents[2] / "shadow-imported").exists(),
"PR-controlled or PYTHONPATH modules must not execute on the host")
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
self.assertTrue(path.is_file())
self.assertEqual(73, json.loads(path.read_text(encoding="utf-8"))["GH_AW_PR_NUMBER"])

def test_build_context_preserves_optional_merge_and_compiled_delivery(self) -> None:
for workflow in self.workflows:
with self.subTest(workflow=workflow):
result, path, _ = self.export(workflow, GH_AW_PR_MERGE_SHA_VALUE="")
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
self.assertTrue(path.is_file())
self.assertEqual("", json.loads(path.read_text(encoding="utf-8"))["GH_AW_PR_MERGE_SHA"])
source, _ = authored(workflow + ".md")
script = next(step["run"] for step in source["steps"]
if step.get("name") == "Export agent context")
delivered = next(step["run"] for step in compiled(workflow + ".lock.yml")["jobs"]["agent"]["steps"]
if step.get("name") == "Export agent context")
self.assertEqual(script, delivered)
self.assertEqual(["/tmp/binlogs:/data/binlogs:ro"], source["mcp-servers"]["binlog-mcp"]["mounts"])


@unittest.skipUnless(sys.platform.startswith("linux"), "Ubuntu runner setup uses /etc/os-release")
class MarkdownLinterSetupTests(unittest.TestCase):
def scripts(self) -> list[tuple[str, str]]:
Expand Down
Loading
Loading