-
Notifications
You must be signed in to change notification settings - Fork 0
Adopt Skylos dead-code detection #234
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
Open
leynos
wants to merge
6
commits into
main
Choose a base branch
from
use-skylos-for-dead-code-detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b04fce
Add Skylos dead-code detection
leynos f8475f6
Harden Skylos lint documentation
leynos 77bf9a3
Scope colour spelling exemption
leynos 3abd94a
Document caller-specific Skylos reasons
leynos 06a6106
Specify Skylos runtime callers
leynos 20471c8
Add Skylos whitelist helper
leynos 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,7 @@ target/ | |
| .claude/ | ||
| .memdb/ | ||
| .grepai/ | ||
| .skylos/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
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
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
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,93 @@ | ||
| """Contract tests for the blocking Skylos dead-code lint gate.""" | ||
|
|
||
| import shutil | ||
| import subprocess | ||
| import tomllib | ||
| import typing as typ | ||
| from pathlib import Path | ||
|
|
||
| REPOSITORY_ROOT = Path(__file__).resolve().parents[1] | ||
|
|
||
|
|
||
| def _pyproject() -> dict[str, object]: | ||
| """Load the repository's Python project configuration.""" | ||
| return tomllib.loads( | ||
| (REPOSITORY_ROOT / "pyproject.toml").read_text(encoding="utf-8") | ||
| ) | ||
|
|
||
|
|
||
| def test_skylos_is_a_pinned_external_tool() -> None: | ||
| """Keep Skylos out of the project environment and pin its tool release.""" | ||
| config = _pyproject() | ||
| dependency_groups = typ.cast("dict[str, list[str]]", config["dependency-groups"]) | ||
|
|
||
| dependencies = dependency_groups["dev"] | ||
| assert not any(dependency.startswith("skylos") for dependency in dependencies), ( | ||
| "Expected Skylos to be separately provisioned from the development " | ||
| "dependency group." | ||
| ) | ||
| makefile = (REPOSITORY_ROOT / "Makefile").read_text(encoding="utf-8") | ||
| assert "SKYLOS_VERSION = 4.33.2" in makefile, ( | ||
| "Expected the separately provisioned Skylos tool version to be exact." | ||
| ) | ||
| assert "--from 'skylos==$(SKYLOS_VERSION)' skylos" in makefile, ( | ||
| "Expected Skylos to run from its separately provisioned tool environment." | ||
| ) | ||
|
|
||
|
|
||
| def test_skylos_configuration_is_strict_and_reasoned() -> None: | ||
| """Require reasons for every configured Skylos exception.""" | ||
| config = _pyproject() | ||
| tool_config = typ.cast("dict[str, object]", config["tool"]) | ||
| skylos = typ.cast("dict[str, object]", tool_config["skylos"]) | ||
| whitelist = typ.cast("dict[str, object]", skylos["whitelist"]) | ||
| documented = typ.cast("dict[str, str]", whitelist["documented"]) | ||
| assert all(reason.strip() for reason in documented.values()), ( | ||
| "Expected every documented Skylos whitelist entry to have a reason." | ||
| ) | ||
|
|
||
| dead_code = typ.cast("dict[str, object]", skylos["dead_code"]) | ||
| entrypoints = typ.cast("list[dict[str, object]]", dead_code["entrypoints"]) | ||
| assert entrypoints, "Expected verified runtime entry points to be documented." | ||
| assert all( | ||
| isinstance(reason := entrypoint.get("reason"), str) and reason.strip() | ||
| for entrypoint in entrypoints | ||
| ), "Expected every Skylos dead-code entry point to have a reason." | ||
|
|
||
| gate = typ.cast("dict[str, object]", skylos["gate"]) | ||
| assert gate["strict"] is True, "Expected the Skylos gate to run in strict mode." | ||
|
|
||
|
|
||
| def test_make_lint_runs_local_blocking_dead_code_scan() -> None: | ||
| """Keep the Skylos invocation deterministic and production-scoped.""" | ||
| make_executable = shutil.which("make") | ||
| assert make_executable is not None, "Expected make to be available for the test." | ||
|
|
||
| result = subprocess.run( # noqa: S603 - test executes make without a shell | ||
| [make_executable, "--no-print-directory", "--dry-run", "lint"], | ||
| cwd=REPOSITORY_ROOT, | ||
| check=False, | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| assert result.returncode == 0, "Expected make lint dry run to succeed." | ||
| skylos_commands = [ | ||
| line | ||
| for line in result.stdout.splitlines() | ||
| if "skylos --config-file pyproject.toml" in line | ||
| ] | ||
| assert len(skylos_commands) == 1, ( | ||
| "Expected make lint to expand exactly one blocking Skylos command." | ||
| ) | ||
| skylos_command = skylos_commands[0] | ||
| assert "cmd_mox --category" in skylos_command, ( | ||
| "Expected the blocking Skylos command to use production-only targets." | ||
| ) | ||
| assert " tests" not in skylos_command, ( | ||
| "Expected tests to be excluded from the production Skylos graph." | ||
| ) | ||
| assert ( | ||
| "--category dead_code --gate --format concise --no-upload " | ||
| "--no-provenance --no-grep-verify" in skylos_command | ||
| ), "Expected the blocking Skylos command to retain its gate flags." |
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
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.