|
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 | """Coverage for deterministic runtime env discovery.""" |
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
5 | 7 | from pithos.env_discovery import collect_env_hints, env_names_from_examples |
6 | 8 |
|
7 | 9 |
|
@@ -77,3 +79,58 @@ def test_collect_env_hints_ignores_skipped_directories(tmp_path): |
77 | 79 | report = collect_env_hints(repo) |
78 | 80 |
|
79 | 81 | assert "PITHOS_TEST_DEPENDENCY_SECRET" not in report.required_names() |
| 82 | + |
| 83 | + |
| 84 | +def test_collect_env_hints_ignores_symlinked_inputs(tmp_path): |
| 85 | + repo = tmp_path / "app" |
| 86 | + repo.mkdir() |
| 87 | + outside = tmp_path / "outside" |
| 88 | + outside.mkdir() |
| 89 | + outside_env = outside / "external.env" |
| 90 | + outside_env.write_text("PITHOS_TEST_OUTSIDE_EXAMPLE=value\n", encoding="utf-8") |
| 91 | + outside_workflow = outside / "workflow.yml" |
| 92 | + outside_workflow.write_text( |
| 93 | + "env:\n PITHOS_TEST_OUTSIDE_WORKFLOW: ${{ secrets.PITHOS_TEST_OUTSIDE_WORKFLOW }}\n", |
| 94 | + encoding="utf-8", |
| 95 | + ) |
| 96 | + outside_source = outside / "external.py" |
| 97 | + outside_source.write_text( |
| 98 | + 'import os\nsecret = os.getenv("PITHOS_TEST_OUTSIDE_SOURCE")\n', |
| 99 | + encoding="utf-8", |
| 100 | + ) |
| 101 | + try: |
| 102 | + (repo / ".env.example").symlink_to(outside_env) |
| 103 | + workflows = repo / ".github" / "workflows" |
| 104 | + workflows.mkdir(parents=True) |
| 105 | + (workflows / "ci.yml").symlink_to(outside_workflow) |
| 106 | + (repo / "linked.py").symlink_to(outside_source) |
| 107 | + except OSError as e: |
| 108 | + pytest.skip(f"symlinks unavailable: {e}") |
| 109 | + |
| 110 | + report = collect_env_hints(repo) |
| 111 | + |
| 112 | + assert "PITHOS_TEST_OUTSIDE_EXAMPLE" not in report.observed_names() |
| 113 | + assert "PITHOS_TEST_OUTSIDE_WORKFLOW" not in report.observed_names() |
| 114 | + assert "PITHOS_TEST_OUTSIDE_SOURCE" not in report.observed_names() |
| 115 | + assert env_names_from_examples(repo) == [] |
| 116 | + |
| 117 | + |
| 118 | +def test_collect_env_hints_ignores_symlinked_workflow_directory(tmp_path): |
| 119 | + repo = tmp_path / "app" |
| 120 | + repo.mkdir() |
| 121 | + outside_workflows = tmp_path / "outside-workflows" |
| 122 | + outside_workflows.mkdir() |
| 123 | + (outside_workflows / "ci.yml").write_text( |
| 124 | + "env:\n PITHOS_TEST_OUTSIDE_WORKFLOW_DIR: value\n", |
| 125 | + encoding="utf-8", |
| 126 | + ) |
| 127 | + try: |
| 128 | + github_dir = repo / ".github" |
| 129 | + github_dir.mkdir() |
| 130 | + (github_dir / "workflows").symlink_to(outside_workflows, target_is_directory=True) |
| 131 | + except OSError as e: |
| 132 | + pytest.skip(f"symlinks unavailable: {e}") |
| 133 | + |
| 134 | + report = collect_env_hints(repo) |
| 135 | + |
| 136 | + assert "PITHOS_TEST_OUTSIDE_WORKFLOW_DIR" not in report.observed_names() |
0 commit comments