This repository has been archived on 2026-11-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
platform-ci/tests/test_expanded_runtimes.py
forge-recoveryandClaude Sonnet 5.5 fd4689fd19
KofTwentyTwo/ci-policy: ci / fork-guard (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / go-0 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / go-nix-1 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / gradle-2 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / gradle-3 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / java-docker-4 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / java-maven-5 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / manifests-6 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / nix-7 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / node-8 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / python-9 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / rust-10 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / rust-11 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / rust-12 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / source-config-13 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / source-config-14 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-0 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-1 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-2 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-3 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-4 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-5 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-6 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / image-build-7 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / not-enrolled (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / content-validate-0 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / standards-0 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / node-matrix-0 (pull_request) Skipped
KofTwentyTwo/ci-policy: ci / source-config-15 (pull_request) Blocked by required conditions
KofTwentyTwo/ci-policy: Shared source and config CI / verify (pull_request) Blocked by required conditions
KofTwentyTwo/ci-policy: Shared source and config CI / secrets (pull_request) Blocked by required conditions
KofTwentyTwo/ci-policy: Shared source and config CI / gate (pull_request) Waiting for needed jobs
KofTwentyTwo/ci-policy: ci / ci-result (pull_request) Waiting for needed jobs
KofTwentyTwo/ci-policy: native / fork-deny (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-macos-0 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-macos-1 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-macos-2 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-macos-3 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-windows-4 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-windows-5 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-windows-6 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / build-windows-7 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / dotnet-8 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / dotnet-9 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / dotnet-10 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / dotnet-11 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-12 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-13 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-14 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-15 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-16 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-17 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-18 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / swift-19 (pull_request) Skipped
KofTwentyTwo/ci-policy: native / native-result (pull_request) Canceled after 3s
feat(ci): reuse verified builds before merge verification
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 03:54:30 +00:00

114 lines
5.9 KiB
Python

"""Expanded runtimes: the container and script tools, the make tool, and the interpreter naming that protects the pipeline's own Python."""
import tempfile
import unittest
from collections.abc import Mapping, Sequence
from pathlib import Path
from typing import override
from platform_ci.build_tools import BUILD_TOOLS
from platform_ci.configuration import ConfigurationError, parse_project_configuration
from platform_ci.execution import ExecutionError, run_target_commands
from platform_ci.plan import Target
from platform_ci.runtimes import parse_runtime_catalog
from tests.support import event, plan_for
CONTROL_IMAGE = f"registry.example/control@sha256:{'5' * 64}"
BUILDKIT_IMAGE = f"registry.example/container@sha256:{'6' * 64}"
CATALOG = parse_runtime_catalog(
{
"schema": 1,
"runners": {"macos-arm64": {"standard": "test-macos-pool"}},
"toolchains": {
"control": {"1": {"image": CONTROL_IMAGE}},
"container": {"0.34.0": {"image": BUILDKIT_IMAGE}},
"xcode": {"27": {"image": None, "hosts": ["macos-arm64"]}},
},
}
)
def _configuration(tool: str, toolchain: str, version: str, commands: object, **component: object) -> dict[str, object]:
"""Return a one-component configuration for a tool."""
return {"schema": 1, "components": {"unit": {"toolchains": {toolchain: version}, "build": {"tool": tool, "commands": commands}, **component}}}
class Recorder:
"""A command stub that records invocations."""
def __init__(self) -> None:
"""Start empty."""
self.commands: list[list[str]] = []
def __call__(self, command: Sequence[str], working_directory: Path, environment: Mapping[str, str]) -> int:
"""Record and succeed."""
del working_directory, environment
self.commands.append(list(command))
return 0
class ExpandedToolTest(unittest.TestCase):
"""The new rows behave like the rest of the registry."""
def test_python_never_shadows_the_pipelines_own_interpreter(self) -> None:
"""The project's interpreter is `python`; `python3` stays the control image's, which the pipeline runs on."""
self.assertEqual(BUILD_TOOLS["python"].executable, "python")
def test_cargo_keeps_the_images_toolchain_home(self) -> None:
"""Only the download cache moves to scratch; the installed toolchain directory is not overridden."""
self.assertEqual({name for name, _value in BUILD_TOOLS["cargo"].container_environment}, {"CARGO_HOME"})
def test_container_and_make_plan_with_their_own_executables(self) -> None:
"""`buildctl` runs in a catalog image; `make` runs on a macOS host."""
container = plan_for(parse_project_configuration(_configuration("container", "container", "0.34.0", [["build", "--frontend", "dockerfile.v0"]])), event(), CATALOG)["targets"][0]
self.assertEqual((container["commands"], container["image"], container["display"]), ([["buildctl", "build", "--frontend", "dockerfile.v0"]], BUILDKIT_IMAGE, "unit / Linux / BuildKit 0.34.0"))
mac = plan_for(parse_project_configuration(_configuration("make", "xcode", "27", [["test"]])), event(), CATALOG)["targets"][0]
self.assertEqual((mac["commands"], mac["execution"], mac["runner"]), ([["make", "test"]], "host", "test-macos-pool"))
class ScriptToolTest(unittest.TestCase):
"""A script command names a checked-in program inside the component directory; nothing else can run."""
@override
def setUp(self) -> None:
"""Create a checkout with one script."""
directory = tempfile.TemporaryDirectory()
self.addCleanup(directory.cleanup)
self.root = Path(directory.name)
self.source = self.root / "source"
(self.source / "scripts").mkdir(parents=True)
(self.source / "scripts" / "check.sh").write_text("#!/bin/sh\n", encoding="utf-8")
(self.root / "outside.sh").write_text("#!/bin/sh\n", encoding="utf-8")
def _plan_target(self, command: list[str]) -> Target:
"""Plan one script command against the control image."""
return plan_for(parse_project_configuration(_configuration("script", "control", "1", [command])), event(), CATALOG)["targets"][0]
def test_a_checked_in_program_plans_as_its_own_command(self) -> None:
"""The command is the program and its arguments, with no interpreter or shell added."""
target = self._plan_target(["./scripts/check.sh", "--strict"])
self.assertEqual((target["commands"], target["image"], target["display"]), ([["./scripts/check.sh", "--strict"]], CONTROL_IMAGE, "unit / Linux / Control 1"))
recorder = Recorder()
self.assertTrue(run_target_commands(target, self.source, recorder, {"PATH": "/usr/bin"}))
self.assertEqual(recorder.commands, [["./scripts/check.sh", "--strict"]])
def test_anything_but_a_relative_program_is_rejected(self) -> None:
"""Bare commands, absolute paths, parent segments and shell text fail validation naming the field."""
for command in (["sh", "-c", "id"], ["/bin/sh"], ["./../outside.sh"], ["./a/../../outside.sh"], ["./x; id"], ["scripts/check.sh"]):
with self.subTest(command), self.assertRaisesRegex(ConfigurationError, r"build\.commands\[0\]\[0\]: expected a checked-in program"):
parse_project_configuration(_configuration("script", "control", "1", [command]))
def test_a_program_that_resolves_outside_the_component_or_is_missing_is_refused_at_run_time(self) -> None:
"""A link in the checkout cannot point the script outside it; a missing file is an error, not a pass."""
try:
(self.source / "scripts" / "escape.sh").symlink_to(self.root / "outside.sh")
except OSError:
self.skipTest("this platform does not allow creating symbolic links")
for program in ("./scripts/escape.sh", "./scripts/missing.sh"):
with self.subTest(program), self.assertRaisesRegex(ExecutionError, "is not a file inside the component directory"):
run_target_commands(self._plan_target([program]), self.source, Recorder(), {"PATH": "/usr/bin"})
if __name__ == "__main__":
unittest.main()