rewrite phase 1

This commit is contained in:
2026-07-22 23:10:23 +02:00
parent 7527831af6
commit 98ac4abca1
89 changed files with 9179 additions and 2795 deletions
+72 -2
View File
@@ -3,7 +3,7 @@ from pathlib import Path
import pytest
from agentci.adapters.development import (
from agentci.development import (
DevelopmentEnvironment,
DevelopmentEnvironmentError,
)
@@ -37,7 +37,7 @@ async def test_runs_custom_scripts_in_order_with_sanitized_environment(
development = environment(tmp_path, ["first", "second"])
script(
development.scripts_dir / "first",
"printf 'first:%s:%s\\n' \"$DEV_TOOLS_DIR\" \"${AGENTCI_SECRET-unset}\" >> order",
'printf \'first:%s:%s\\n\' "$DEV_TOOLS_DIR" "${AGENTCI_SECRET-unset}" >> order',
)
script(development.scripts_dir / "second", "printf 'second\\n' >> order")
monkeypatch.setenv("AGENTCI_SECRET", "must-not-leak")
@@ -112,6 +112,76 @@ async def test_reports_script_failure_output(tmp_path) -> None:
await development.prepare(workspace)
async def test_reports_missing_install_script(tmp_path: Path) -> None:
workspace = tmp_path / "workspace"
workspace.mkdir()
development = environment(tmp_path, ["missing"])
with pytest.raises(
DevelopmentEnvironmentError,
match=r"Install script 'missing' was not found",
):
await development.prepare(workspace)
async def test_stops_before_second_script_after_failure(tmp_path: Path) -> None:
workspace = tmp_path / "workspace"
workspace.mkdir()
development = environment(tmp_path, ["first", "second"])
script(development.scripts_dir / "first", "printf 'first\n' > first-ran; exit 3")
script(development.scripts_dir / "second", "printf 'second\n' > second-ran")
with pytest.raises(DevelopmentEnvironmentError, match="exited with 3"):
await development.prepare(workspace)
assert (workspace / "first-ran").read_text() == "first\n"
assert not (workspace / "second-ran").exists()
async def test_failure_output_keeps_only_bounded_tail(tmp_path: Path) -> None:
workspace = tmp_path / "workspace"
workspace.mkdir()
development = environment(tmp_path, ["verbose"])
script(
development.scripts_dir / "verbose",
"printf 'discarded-prefix' >&2; "
'i=0; while [ "$i" -lt 2100 ]; do printf x >&2; i=$((i + 1)); done; '
"printf 'useful-tail' >&2; exit 9",
)
with pytest.raises(DevelopmentEnvironmentError) as raised:
await development.prepare(workspace)
message = str(raised.value)
assert "discarded-prefix" not in message
assert message.endswith("useful-tail")
async def test_wraps_subprocess_start_error(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
workspace = tmp_path / "workspace"
workspace.mkdir()
development = environment(tmp_path, ["broken"])
script(development.scripts_dir / "broken", "true")
async def create_subprocess_exec(*_args, **_kwargs):
raise OSError("exec unavailable")
monkeypatch.setattr(
"agentci.development.asyncio.create_subprocess_exec",
create_subprocess_exec,
)
with pytest.raises(
DevelopmentEnvironmentError,
match="Could not run install script 'broken': exec unavailable",
) as raised:
await development.prepare(workspace)
assert isinstance(raised.value.__cause__, OSError)
async def test_times_out_install_script(tmp_path) -> None:
workspace = tmp_path / "workspace"
workspace.mkdir()