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
21 changes: 11 additions & 10 deletions .github/workflows/_e2e-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ jobs:
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Build AFT binary (Windows x64)
run: cargo build --profile $env:CARGO_PROFILE --bin aft --target x86_64-pc-windows-msvc -p agent-file-tools --timings --features wasm-grammars
run: python scripts/ci-stage-aft.py --legacy-msvc-profile-dir "x86_64-pc-windows-msvc/$env:CARGO_PROFILE" cargo rustc --profile $env:CARGO_PROFILE --bin aft --target x86_64-pc-windows-msvc -p agent-file-tools --timings --features wasm-grammars
shell: pwsh
env:
CARGO_TARGET_DIR: ${{ env.AFT_CI_TARGET_DIR }}
CARGO_TARGET_DIR: ${{ env.AFT_CI_JOB_DIR }}/cargo-target
CARGO_BUILD_BUILD_DIR: ${{ env.AFT_CI_TARGET_DIR || format('{0}/target', github.workspace) }}

- name: Install workspace deps + build aft-bridge
run: |
Expand All @@ -548,7 +549,7 @@ jobs:
pwsh -NoProfile -ExecutionPolicy Bypass -File tests/windows-e2e/run.ps1
shell: pwsh
env:
AFT_BINARY_PATH: ${{ env.AFT_CI_TARGET_DIR }}\x86_64-pc-windows-msvc\${{ inputs.cargo_profile == 'stage' && 'stage' || 'release' }}\aft.exe
AFT_BINARY_PATH: ${{ env.AFT_CI_JOB_DIR }}/aft.exe
AFT_PLUGIN_DIST: ${{ github.workspace }}\packages\opencode-plugin\dist

- name: Collect Windows plugin log on failure
Expand Down Expand Up @@ -598,7 +599,6 @@ jobs:
env:
CARGO_INCREMENTAL: "0"
CARGO_PROFILE: ${{ inputs.cargo_profile == 'stage' && 'dev' || 'release' }}
CARGO_PROFILE_DIR: ${{ inputs.cargo_profile == 'stage' && 'debug' || 'release' }}
CARGO_PROFILE_DEV_DEBUG: line-tables-only
steps:
- uses: actions/checkout@v5
Expand Down Expand Up @@ -656,9 +656,10 @@ jobs:
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Build AFT binary (macOS native)
run: cargo build --profile "$CARGO_PROFILE" --bin aft -p agent-file-tools --timings --features wasm-grammars
run: python3 scripts/ci-stage-aft.py cargo rustc --profile "$CARGO_PROFILE" --bin aft -p agent-file-tools --timings --features wasm-grammars
env:
CARGO_TARGET_DIR: ${{ env.AFT_CI_TARGET_DIR }}
CARGO_TARGET_DIR: ${{ env.AFT_CI_JOB_DIR }}/cargo-target
CARGO_BUILD_BUILD_DIR: ${{ env.AFT_CI_TARGET_DIR || format('{0}/target', github.workspace) }}

# Ad-hoc sign + verify + exec once: an unsigned fresh binary gets
# SIGKILLed on newer macOS, and the first exec pays a syspolicyd
Expand All @@ -667,9 +668,9 @@ jobs:
# corrupt-signature shape #238 shipped, with no exec needed.
- name: Sign, verify, and warm the binary
run: |
codesign -f -s - "$AFT_CI_TARGET_DIR/$CARGO_PROFILE_DIR/aft"
codesign --verify --strict "$AFT_CI_TARGET_DIR/$CARGO_PROFILE_DIR/aft"
"$AFT_CI_TARGET_DIR/$CARGO_PROFILE_DIR/aft" --version
codesign -f -s - "$AFT_CI_JOB_DIR/aft"
codesign --verify --strict "$AFT_CI_JOB_DIR/aft"
"$AFT_CI_JOB_DIR/aft" --version

- name: Install workspace deps + build aft-bridge
run: |
Expand All @@ -684,7 +685,7 @@ jobs:
unset CARGO_TARGET_DIR CARGO_BUILD_TARGET_DIR
bash tests/macos-e2e/run.sh
env:
AFT_BINARY_PATH: ${{ env.AFT_CI_TARGET_DIR }}/${{ env.CARGO_PROFILE_DIR }}/aft
AFT_BINARY_PATH: ${{ env.AFT_CI_JOB_DIR }}/aft
AFT_PLUGIN_DIST: ${{ github.workspace }}/packages/opencode-plugin/dist

- name: Upload macOS plugin log on failure
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/_unit-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1698,9 +1698,10 @@ jobs:
run: bun run typecheck

- name: Cargo build (debug — needed by plugin tests)
run: cargo build --features wasm-grammars -p agent-file-tools
run: python3 scripts/ci-stage-aft.py cargo rustc --features wasm-grammars -p agent-file-tools --bin aft
env:
CARGO_TARGET_DIR: ${{ env.AFT_CI_TARGET_DIR }}
CARGO_TARGET_DIR: ${{ env.AFT_CI_JOB_DIR }}/cargo-target
CARGO_BUILD_BUILD_DIR: ${{ env.AFT_CI_TARGET_DIR || format('{0}/target', github.workspace) }}

- name: Rust conformance gate (macOS)
run: |
Expand Down Expand Up @@ -1778,7 +1779,7 @@ jobs:
env:
AFT_TEST_NATIVE_FIXTURE_TIMING: "1"
AFT_CACHE_DIR: ${{ runner.temp }}/aft-cache
AFT_BINARY_PATH: ${{ env.AFT_CI_TARGET_DIR }}/debug/aft
AFT_BINARY_PATH: ${{ env.AFT_CI_JOB_DIR }}/aft
SUBC_CORE_BIN: ${{ steps.subc_core.outputs.path }}
SUBC_CORE_WIRE_VERSION: ${{ steps.subc_core.outputs.wire_version }}

Expand Down Expand Up @@ -2370,10 +2371,11 @@ jobs:
shell: pwsh

- name: Cargo build (debug — bash.test.ts spawns the real aft binary)
run: cargo build --features wasm-grammars -p agent-file-tools
run: python scripts/ci-stage-aft.py --legacy-msvc-profile-dir debug cargo rustc --features wasm-grammars -p agent-file-tools --bin aft
shell: pwsh
env:
CARGO_TARGET_DIR: ${{ env.AFT_CI_TARGET_DIR }}
CARGO_TARGET_DIR: ${{ env.AFT_CI_JOB_DIR }}/cargo-target
CARGO_BUILD_BUILD_DIR: ${{ env.AFT_CI_TARGET_DIR || format('{0}/target', github.workspace) }}

- name: Bun test (bash permission flow — full bridge + plugin + Rust)
run: |
Expand All @@ -2383,7 +2385,7 @@ jobs:
shell: pwsh
env:
AFT_CACHE_DIR: ${{ runner.temp }}/aft-cache
AFT_BINARY_PATH: ${{ env.AFT_CI_TARGET_DIR }}/debug/aft.exe
AFT_BINARY_PATH: ${{ env.AFT_CI_JOB_DIR }}/aft.exe

- name: Clean native test processes
if: always()
Expand Down
19 changes: 11 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,16 @@ jobs:

- name: Build
# MSVC keeps debug info in a PDB, not in the shipped executable.
run: cargo build --release --target aarch64-pc-windows-msvc --config 'profile.release.strip=false' --features wasm-grammars
run: python scripts/ci-stage-aft.py --pdb --legacy-msvc-profile-dir aarch64-pc-windows-msvc/release cargo rustc --release --bin aft --target aarch64-pc-windows-msvc -p agent-file-tools --config 'profile.release.strip=false' --features wasm-grammars
shell: pwsh
env:
CARGO_TARGET_DIR: ${{ env.AFT_CI_TARGET_DIR }}
CARGO_TARGET_DIR: ${{ env.AFT_CI_JOB_DIR }}/cargo-target
CARGO_BUILD_BUILD_DIR: ${{ env.AFT_CI_TARGET_DIR || format('{0}/target', github.workspace) }}

- name: Stage the built binary for the existing artifact contract
shell: pwsh
run: |
$source = "$env:AFT_CI_TARGET_DIR/aarch64-pc-windows-msvc/release/aft.exe"
$source = "$env:AFT_CI_JOB_DIR/aft.exe"
$destination = Join-Path $env:GITHUB_WORKSPACE "target/aarch64-pc-windows-msvc/release/aft.exe"
$null = New-Item -ItemType Directory -Force -Path (Split-Path $destination)
Copy-Item -LiteralPath $source -Destination $destination -Force
Expand All @@ -523,7 +525,7 @@ jobs:

- name: Verify and package Windows PDB
shell: pwsh
run: python scripts/release-debug-symbols.py windows --binary target/aarch64-pc-windows-msvc/release/aft.exe --pdb "$env:AFT_CI_TARGET_DIR/aarch64-pc-windows-msvc/release/aft.pdb" --archive release-debug/aft-windows-arm64-pdb.zip
run: python scripts/release-debug-symbols.py windows --binary target/aarch64-pc-windows-msvc/release/aft.exe --pdb "$env:AFT_CI_JOB_DIR/aft.pdb" --archive release-debug/aft-windows-arm64-pdb.zip
- uses: actions/upload-artifact@v4
with:
name: windows-arm64-pdb
Expand Down Expand Up @@ -611,15 +613,16 @@ jobs:
CARGO_TARGET_DIR: ${{ env.AFT_CI_TARGET_DIR }}

- name: Build
run: cargo build --release --bin aft --target x86_64-pc-windows-msvc -p agent-file-tools --timings --config 'profile.release.strip=false' --features wasm-grammars
run: python scripts/ci-stage-aft.py --pdb --legacy-msvc-profile-dir x86_64-pc-windows-msvc/release cargo rustc --release --bin aft --target x86_64-pc-windows-msvc -p agent-file-tools --timings --config 'profile.release.strip=false' --features wasm-grammars
shell: pwsh
env:
CARGO_TARGET_DIR: ${{ env.AFT_CI_TARGET_DIR }}
CARGO_TARGET_DIR: ${{ env.AFT_CI_JOB_DIR }}/cargo-target
CARGO_BUILD_BUILD_DIR: ${{ env.AFT_CI_TARGET_DIR || format('{0}/target', github.workspace) }}

- name: Stage the built binary for the existing artifact contract
shell: pwsh
run: |
$source = "$env:AFT_CI_TARGET_DIR/x86_64-pc-windows-msvc/release/aft.exe"
$source = "$env:AFT_CI_JOB_DIR/aft.exe"
$destination = Join-Path $env:GITHUB_WORKSPACE "target/x86_64-pc-windows-msvc/release/aft.exe"
$null = New-Item -ItemType Directory -Force -Path (Split-Path $destination)
Copy-Item -LiteralPath $source -Destination $destination -Force
Expand All @@ -629,7 +632,7 @@ jobs:

- name: Verify and package Windows PDB
shell: pwsh
run: python scripts/release-debug-symbols.py windows --binary target/x86_64-pc-windows-msvc/release/aft.exe --pdb "$env:AFT_CI_TARGET_DIR/x86_64-pc-windows-msvc/release/aft.pdb" --archive release-debug/aft-windows-x64-pdb.zip
run: python scripts/release-debug-symbols.py windows --binary target/x86_64-pc-windows-msvc/release/aft.exe --pdb "$env:AFT_CI_JOB_DIR/aft.pdb" --archive release-debug/aft-windows-x64-pdb.zip
- uses: actions/upload-artifact@v4
with:
name: windows-x64-pdb
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"slice_class": "non_ranking",
"targeted_mechanism": "none",
"kind": "harness",
"fixtures": [
".github/workflows/_e2e-suite.yml",
".github/workflows/_unit-suite.yml",
".github/workflows/release.yml",
"scripts/ci-native-state.py",
"scripts/ci-stage-aft.py",
"scripts/lib/test_native_release_workflow.py",
"scripts/lib/test_workflow_gates.py"
],
"slices": [
"fix-ci-native-binary-provenance"
],
"note": "Native CI keeps Cargo intermediates warm but stages each job's reported executable and release PDB from private outputs. No product or ranking code changes."
}
3 changes: 3 additions & 0 deletions scripts/ci-native-state.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ def main() -> None:
phase = sys.argv[1]
if os.environ.get("RUNNER_ENVIRONMENT") != "self-hosted":
if phase == "setup":
runner_temp = Path(os.environ["RUNNER_TEMP"])
job_dir = Path(tempfile.mkdtemp(prefix="aft-ci-job-", dir=runner_temp))
with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as env:
print(f"AFT_CI_ARCHIVE_DIR={os.environ['RUNNER_TEMP']}", file=env)
print(f"AFT_CI_JOB_DIR={job_dir.as_posix()}", file=env)
return
root = Path.home() / "aft-ci"
run_dir = run_directory(root, os.environ["GITHUB_RUN_ID"], os.environ["GITHUB_RUN_ATTEMPT"])
Expand Down
99 changes: 99 additions & 0 deletions scripts/ci-stage-aft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
"""Build aft and stage the executable (and optional MSVC PDB) for this CI job."""

from __future__ import annotations

import argparse
from collections.abc import Iterable
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys


def read_aft_artifact(lines: Iterable[str]) -> dict | None:
artifact = None
for line in lines:
# Cargo may relay plain stdout from tools in addition to its JSON records.
if not line.startswith("{"):
print(line, end="", flush=True)
continue
message = json.loads(line)
if message["reason"] == "compiler-message":
print(message["message"]["rendered"] or "", end="", file=sys.stderr, flush=True)
if (message["reason"] == "compiler-artifact" and message["target"]["name"] == "aft"
and "bin" in message["target"]["kind"] and message.get("executable")):
artifact = message
return artifact


def stage_artifact(artifact: dict | None, target_dir: Path, job_dir: Path, with_pdb: bool) -> None:
if artifact is None:
raise ValueError("Cargo did not report an executable for the aft binary")
executable = Path(artifact["executable"]).resolve(strict=True)
if not executable.is_relative_to(target_dir) or executable.name not in ("aft", "aft.exe"):
raise ValueError(f"Cargo reported an unexpected aft executable: {executable}")
outputs = [executable]
if with_pdb:
pdb = executable.with_suffix(".pdb")
if executable.suffix != ".exe" or pdb not in (Path(p).resolve() for p in artifact["filenames"]):
raise ValueError("Cargo did not report the aft.pdb paired with the aft executable")
outputs.append(pdb)
for source in outputs:
# Copy rather than hardlink: ad-hoc signing must not alter Cargo's cache.
destination = job_dir / source.name
shutil.copy2(source, destination)
print(f"Staged {destination} from {source}")


def invalidate_legacy_msvc_binary(build_dir: Path, profile_dir: Path) -> None:
deps = (build_dir / profile_dir / "deps").resolve()
if not deps.is_relative_to(build_dir):
raise ValueError(f"MSVC profile directory is outside the Cargo build directory: {profile_dir}")
# Cargo 1.99 can treat a unit as fresh after another build overwrites the
# unversioned deps/aft.exe. Remove only that link output and its PDB so
# Cargo relinks aft but keeps the dependency cache. Remove this workaround
# when the Windows runner uses Cargo 1.100's per-unit output directories.
(deps / "aft.exe").unlink(missing_ok=True)
(deps / "aft.pdb").unlink(missing_ok=True)


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--pdb", action="store_true", help="also stage the PDB from the same Cargo artifact")
parser.add_argument("--legacy-msvc-profile-dir", type=Path, help="profile path inside a shared legacy build dir")
parser.add_argument("command", nargs=argparse.REMAINDER, help="cargo rustc command and Cargo arguments")
args = parser.parse_args()
if args.command[:2] != ["cargo", "rustc"] or "--" in args.command:
parser.error("expected a cargo rustc command without rustc arguments")
job_dir = Path(os.environ["AFT_CI_JOB_DIR"]).resolve(strict=True)
target_dir = Path(os.environ["CARGO_TARGET_DIR"]).resolve()
# Cargo reports the final target-dir path, even for reused artifacts.
# Two builds can overwrite that path unless each job has its own target dir.
if target_dir == job_dir or not target_dir.is_relative_to(job_dir):
parser.error("CARGO_TARGET_DIR must be inside AFT_CI_JOB_DIR")
if args.legacy_msvc_profile_dir and os.environ.get("RUNNER_ENVIRONMENT") == "self-hosted":
version = subprocess.check_output(["cargo", "--version"], text=True).split()[1]
major, minor, _ = version.split(".", 2)
if (int(major), int(minor)) < (1, 100):
invalidate_legacy_msvc_binary(Path(os.environ["CARGO_BUILD_BUILD_DIR"]).resolve(),
args.legacy_msvc_profile_dir)
# Only the final bin gets the revision key; the library and dependencies
# retain their existing compiler flags and fingerprints.
metadata = f"metadata=aft-{os.environ['GITHUB_SHA']}"
with subprocess.Popen([*args.command, "--message-format=json-render-diagnostics", "--", "-C", metadata],
stdout=subprocess.PIPE, text=True, encoding="utf-8") as cargo:
assert cargo.stdout is not None
artifact = read_aft_artifact(cargo.stdout)
if code := cargo.wait():
raise SystemExit(code)
try:
stage_artifact(artifact, target_dir, job_dir, args.pdb)
except (OSError, ValueError) as error:
parser.exit(1, f"{error}\n")


if __name__ == "__main__":
main()
19 changes: 14 additions & 5 deletions scripts/lib/test_native_release_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,19 @@ def test_windows_release_jobs_reuse_narli_without_mutating_rust_or_the_artifact_
self.assertEqual(steps[-1], {"uses": "./.github/actions/native-ci-state", "if": "always()",
"with": {"phase": "cleanup"}})
if job_id.startswith("build-"):
build = next(i for i, step in enumerate(steps) if step.get("name") == "Build")
self.assertIn(f"--legacy-msvc-profile-dir {target}/release", steps[build]["run"])
self.assertIn(f"cargo rustc --release --bin aft --target {target}", steps[build]["run"])
self.assertIn("ci-stage-aft.py --pdb", steps[build]["run"])
self.assertEqual(steps[build]["env"]["CARGO_TARGET_DIR"], "${{ env.AFT_CI_JOB_DIR }}/cargo-target")
self.assertEqual(steps[build]["env"]["CARGO_BUILD_BUILD_DIR"],
"${{ env.AFT_CI_TARGET_DIR || format('{0}/target', github.workspace) }}")
stage = next(i for i, step in enumerate(steps)
if step.get("name") == "Stage the built binary for the existing artifact contract")
self.assertIn(f'$env:AFT_CI_TARGET_DIR/{target}/release/aft.exe', steps[stage]["run"])
self.assertIn('$source = "$env:AFT_CI_JOB_DIR/aft.exe"', steps[stage]["run"])
self.assertIn("Get-FileHash $source", steps[stage]["run"])
upload = next(i for i, step in enumerate(steps) if step.get("uses") == "actions/upload-artifact@v4")
self.assertLess(build, stage)
self.assertLess(stage, upload)
arm = commands(jobs["build-win32-arm64"])
self.assertIn("Hostx64/arm64/cl.exe", arm)
Expand Down Expand Up @@ -211,13 +219,14 @@ def test_main_and_train_native_e2e_use_the_staging_selector(self):
def test_macos_landing_e2e_uses_debug_without_changing_publication(self):
job = self.workflow("_e2e-suite.yml")["jobs"]["e2e-macos"]
self.assertEqual(job["env"]["CARGO_PROFILE"], "${{ inputs.cargo_profile == 'stage' && 'dev' || 'release' }}")
self.assertEqual(job["env"]["CARGO_PROFILE_DIR"], "${{ inputs.cargo_profile == 'stage' && 'debug' || 'release' }}")
self.assertEqual(job["env"]["CARGO_PROFILE_DEV_DEBUG"], "line-tables-only")
self.assertIn('cargo build --profile "$CARGO_PROFILE"', commands(job))
for command in ('codesign -f -s -', 'codesign --verify --strict', '"$AFT_CI_TARGET_DIR/$CARGO_PROFILE_DIR/aft" --version'):
self.assertIn('cargo rustc --profile "$CARGO_PROFILE"', commands(job))
for command in ('codesign -f -s - "$AFT_CI_JOB_DIR/aft"',
'codesign --verify --strict "$AFT_CI_JOB_DIR/aft"',
'"$AFT_CI_JOB_DIR/aft" --version'):
self.assertIn(command, commands(job))
run = next(step for step in job["steps"] if "bash tests/macos-e2e/run.sh" in step.get("run", "").splitlines())
self.assertEqual(run["env"]["AFT_BINARY_PATH"], "${{ env.AFT_CI_TARGET_DIR }}/${{ env.CARGO_PROFILE_DIR }}/aft")
self.assertEqual(run["env"]["AFT_BINARY_PATH"], "${{ env.AFT_CI_JOB_DIR }}/aft")

def test_macos_e2e_reuses_coreutils_without_write_access_to_homebrew(self):
source = (ROOT / "tests/macos-e2e/run.sh").read_text()
Expand Down
Loading
Loading