-
Notifications
You must be signed in to change notification settings - Fork 2
Add act/Docker integration tests for subprocess boundary and _extract… #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wpak-ai
merged 6 commits into
cppalliance:develop
from
henry0816191:feature/act-integration-tests
May 29, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8763ff1
Add act/Docker integration tests for subprocess boundary and _extract…
henry0816191 fb6a264
addressed ai reviews
henry0816191 cdbab8e
addressed AI reviews
henry0816191 2e71982
Addressed all of Brad's reviews
henry0816191 d8e4b2a
added _executor_capture_from_log_text to fix integration error
henry0816191 e43d1e2
addressed ai review
henry0816191 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
cli/tests/fixtures/integration/project/.github/workflows/invalid.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| name: Invalid | ||
| on: [push | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest |
15 changes: 15 additions & 0 deletions
15
cli/tests/fixtures/integration/project/.github/workflows/test-fail.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: Integration Failure | ||
| on: [push] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - name: "Hello" | ||
| runs-on: ubuntu-latest | ||
| compiler: gcc | ||
| version: "15" | ||
| steps: | ||
| - run: exit 1 |
15 changes: 15 additions & 0 deletions
15
cli/tests/fixtures/integration/project/.github/workflows/test.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: Integration Success | ||
| on: [push] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - name: "Hello" | ||
| runs-on: ubuntu-latest | ||
| compiler: gcc | ||
| version: "15" | ||
| steps: | ||
| - run: echo "Hello" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| version: 1 | ||
| workflow: .github/workflows/test.yml | ||
| event: push | ||
|
|
||
| parallel: | ||
| max_jobs: 1 | ||
|
|
||
| platforms: | ||
| linux: true | ||
| windows: false | ||
| macos: false | ||
|
|
||
| images: | ||
| auto_build: false | ||
|
|
||
| cache: | ||
| enabled: false | ||
|
|
||
| logging: | ||
| level: warning | ||
| directory: logs | ||
|
|
||
| execution: | ||
| timeout: 120 | ||
| keep_containers: false | ||
| stop_on_first_failure: false |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """Shared fixtures for act/Docker integration tests.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import shutil | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import yaml | ||
|
|
||
| from localci.core.executor import JobExecutor | ||
| from localci.core.image_tag import derive_image_tag | ||
| from localci.errors import DockerNotAvailableError | ||
|
|
||
| FIXTURE_PROJECT = ( | ||
| Path(__file__).resolve().parent.parent / "fixtures" / "integration" / "project" | ||
| ) | ||
| ACT_RUNNER_IMAGE = "catthehacker/ubuntu:act-24.04" | ||
| INTEGRATION_JOB_ID = "test" | ||
| INTEGRATION_TIMEOUT = 180 | ||
| DOCKER_PULL_TIMEOUT = 600 | ||
| DOCKER_TAG_TIMEOUT = 60 | ||
|
|
||
|
|
||
| def _act_available() -> bool: | ||
| return JobExecutor().has_act | ||
|
|
||
|
|
||
| def _docker_available() -> bool: | ||
| try: | ||
| JobExecutor().check_docker() | ||
| return True | ||
| except DockerNotAvailableError: | ||
| return False | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def require_act_and_docker() -> None: | ||
| """Skip the entire integration session when act or Docker is unavailable.""" | ||
| if not _act_available(): | ||
| pytest.skip("act is not installed") | ||
| if not _docker_available(): | ||
| pytest.skip("Docker is not available") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def act_runner_image(require_act_and_docker: None) -> str: | ||
| """Pull the act runner image used for ubuntu-latest jobs.""" | ||
| try: | ||
| pull = subprocess.run( | ||
| ["docker", "pull", ACT_RUNNER_IMAGE], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=DOCKER_PULL_TIMEOUT, | ||
| ) | ||
| except subprocess.TimeoutExpired: | ||
| pytest.skip( | ||
| f"timed out pulling {ACT_RUNNER_IMAGE} after {DOCKER_PULL_TIMEOUT}s" | ||
| ) | ||
| if pull.returncode != 0: | ||
| pytest.skip( | ||
| f"could not pull {ACT_RUNNER_IMAGE}: " | ||
| f"{pull.stderr.strip() or pull.stdout.strip()}" | ||
| ) | ||
| return ACT_RUNNER_IMAGE | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def capy_image_tag(act_runner_image: str, require_act_and_docker: None) -> str: | ||
| """Tag the act runner image as the derived capy name for localci run.""" | ||
| from localci.core.workflow import WorkflowAnalyzer | ||
|
|
||
| # Derive tag from test.yml; test-fail.yml uses the same matrix.include shape today. | ||
| # If failure fixture matrix diverges, derive from that workflow (or both) instead. | ||
| workflow_path = FIXTURE_PROJECT / ".github/workflows/test.yml" | ||
|
henry0816191 marked this conversation as resolved.
|
||
| entry = WorkflowAnalyzer().analyze(workflow_path).jobs[INTEGRATION_JOB_ID].matrix[0] | ||
| tag = derive_image_tag(entry) | ||
| assert tag is not None | ||
|
|
||
| try: | ||
| tag_result = subprocess.run( | ||
| ["docker", "tag", act_runner_image, tag], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=DOCKER_TAG_TIMEOUT, | ||
| ) | ||
| except subprocess.TimeoutExpired: | ||
| pytest.skip( | ||
| f"timed out tagging {act_runner_image} as {tag} after {DOCKER_TAG_TIMEOUT}s" | ||
| ) | ||
| if tag_result.returncode != 0: | ||
| pytest.skip( | ||
| f"could not tag {act_runner_image} as {tag}: " | ||
| f"{tag_result.stderr.strip() or tag_result.stdout.strip()}" | ||
| ) | ||
| return tag | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def integration_project(tmp_path: Path) -> tuple[Path, Path]: | ||
| """Copy fixture project and return (project_root, logs_dir).""" | ||
| dest = tmp_path / "project" | ||
| shutil.copytree(FIXTURE_PROJECT, dest) | ||
|
|
||
| logs_dir = tmp_path / "logs" | ||
| logs_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| config_path = dest / ".localci.yml" | ||
| config = yaml.safe_load(config_path.read_text()) | ||
| config["logging"]["directory"] = str(logs_dir) | ||
| config_path.write_text( | ||
| yaml.dump(config, default_flow_style=False, sort_keys=False) | ||
| ) | ||
|
|
||
| return dest, logs_dir | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| """Integration tests for JobExecutor + act subprocess boundary.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from localci.core.command_builder import ActCommandBuilder | ||
| from localci.core.executor import JobExecutor, JobResult, JobStatus | ||
| from localci.core.workflow import MatrixEntry, WorkflowAnalyzer | ||
|
|
||
| from .conftest import INTEGRATION_JOB_ID, INTEGRATION_TIMEOUT | ||
|
|
||
| pytestmark = pytest.mark.integration | ||
|
|
||
|
|
||
| def _workflow_path(name: str, project_dir: Path) -> Path: | ||
| return project_dir / ".github/workflows" / name | ||
|
|
||
|
|
||
| def _build_and_run( | ||
| workflow_name: str, | ||
| logs_dir: Path, | ||
| act_runner_image: str, | ||
| project_dir: Path, | ||
| ) -> tuple[JobResult, MatrixEntry]: | ||
| workflow_path = _workflow_path(workflow_name, project_dir) | ||
| analyzer = WorkflowAnalyzer() | ||
| workflow = analyzer.analyze(workflow_path) | ||
| entry = workflow.jobs[INTEGRATION_JOB_ID].matrix[0] | ||
|
|
||
| builder = ActCommandBuilder( | ||
| workflow_file=workflow_path, | ||
| project_dir=project_dir, | ||
| job_id=INTEGRATION_JOB_ID, | ||
| ) | ||
| cmd = builder.build(entry, image_tag=act_runner_image) | ||
| executor = JobExecutor(logs_dir=logs_dir) | ||
| result = executor.run( | ||
| cmd, | ||
| matrix_index=entry.index, | ||
| matrix_name=entry.name, | ||
| timeout=INTEGRATION_TIMEOUT, | ||
| stream_output=False, | ||
| ) | ||
| return result, entry | ||
|
|
||
|
|
||
| def test_successful_job_execution( | ||
| integration_project: tuple[Path, Path], | ||
| act_runner_image: str, | ||
| ) -> None: | ||
| project, logs_dir = integration_project | ||
| result, _ = _build_and_run("test.yml", logs_dir, act_runner_image, project) | ||
|
|
||
| assert result.status == JobStatus.PASSED | ||
| assert result.exit_code == 0 | ||
| assert result.stdout or result.stderr | ||
| assert result.log_file is not None | ||
| assert result.log_file.exists() | ||
|
|
||
|
|
||
| def test_failing_job_extract_error( | ||
| integration_project: tuple[Path, Path], | ||
| act_runner_image: str, | ||
| ) -> None: | ||
| project, logs_dir = integration_project | ||
| result, _ = _build_and_run( | ||
| "test-fail.yml", logs_dir, act_runner_image, project | ||
| ) | ||
|
|
||
| assert result.status == JobStatus.FAILED | ||
| assert result.exit_code is not None | ||
| assert result.exit_code != 0 | ||
|
|
||
| captured = result.stderr or result.stdout | ||
| assert captured.strip() | ||
|
|
||
| extracted = JobExecutor._extract_error(captured) | ||
| assert result.error_message == extracted | ||
| assert result.error_message is not None | ||
|
|
||
| lower = result.error_message.lower() | ||
| assert any(kw in lower for kw in ("failed", "error", "exit")) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.