Repository navigation
fix: The constitution gate cannot run on an SELinux host, and says the validator is missing (#38) #46
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
Merged
fix: The constitution gate cannot run on an SELinux host, and says the validator is missing (#38) #46
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| #!/usr/bin/env python3 | ||
| """`validate` must tell an unreadable checkout from one missing a file. | ||
|
|
||
| An SELinux label or mode that blocks listing the cached constitution checkout | ||
| used to surface as "missing validate-constitution.py", sending the reader to | ||
| the constitution tag instead of the label. This makes `os.listdir` raise and | ||
| asserts the diagnostic names the checkout and the cause, and a plain missing | ||
| file still gets the missing-file message. | ||
|
|
||
| Run: tests/test_validate_checkout.py (needs nothing but python3) | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import contextlib | ||
| import importlib.machinery | ||
| import importlib.util | ||
| import io | ||
| import sys | ||
| import tempfile | ||
| from pathlib import Path | ||
| from unittest import mock | ||
|
|
||
| VALIDATE = Path(__file__).resolve().parent.parent / "validate" | ||
|
|
||
|
|
||
| def load(): | ||
| loader = importlib.machinery.SourceFileLoader("sdlc_validate", str(VALIDATE)) | ||
| spec = importlib.util.spec_from_loader("sdlc_validate", loader) | ||
| module = importlib.util.module_from_spec(spec) | ||
| loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| def run(module, cache: Path, manifest: Path, listdir=None) -> tuple[int, str]: | ||
| err = io.StringIO() | ||
| patches = [ | ||
| mock.patch.object(module, "CACHE", cache), | ||
| mock.patch.object(sys, "argv", ["validate", str(manifest)]), | ||
| ] | ||
| if listdir is not None: | ||
| patches.append(mock.patch.object(module.os, "listdir", listdir)) | ||
| with contextlib.ExitStack() as stack: | ||
| for p in patches: | ||
| stack.enter_context(p) | ||
| stack.enter_context(contextlib.redirect_stderr(err)) | ||
| try: | ||
| module.main() | ||
| code = 0 | ||
| except SystemExit as exc: | ||
| code = exc.code | ||
| return code, err.getvalue() | ||
|
|
||
|
|
||
| def main() -> int: | ||
| module = load() | ||
| failed = 0 | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| root = Path(tmp) | ||
| manifest = root / "constitution.md" | ||
| manifest.write_text("> **Inherits:** constitution v1.2.3\n", encoding="utf-8") | ||
| cache = root / "cache" | ||
| checkout = cache / "constitution" / "v1.2.3" | ||
| (checkout / ".git").mkdir(parents=True) | ||
|
|
||
| def denied(_path): | ||
| raise PermissionError(13, "Permission denied") | ||
|
|
||
| code, err = run(module, cache, manifest, listdir=denied) | ||
| checks = [ | ||
| ("unreadable: exits CANNOT_RUN", code == module.CANNOT_RUN), | ||
| ("unreadable: says cannot read", "cannot read the constitution checkout" in err), | ||
| ("unreadable: names the path", str(checkout) in err), | ||
| ("unreadable: carries the error", "Permission denied" in err), | ||
| ("unreadable: not the missing-file message", "is missing" not in err), | ||
| ] | ||
| code, err = run(module, cache, manifest) | ||
| checks += [ | ||
| ("missing file: exits CANNOT_RUN", code == module.CANNOT_RUN), | ||
| ("missing file: says is missing", "is missing validate-constitution.py" in err), | ||
| ] | ||
| for name, ok in checks: | ||
| print(f"{'ok ' if ok else 'FAIL'} {name}") | ||
| failed += not ok | ||
| print() | ||
| print("validate checkout diagnostics " + ("FAILED" if failed else "PASSED")) | ||
| return 1 if failed else 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MEDIUM (Test Coverage): The new unreadable-checkout error path has no corresponding test in the changes shown. This behavior distinguishes a directory that cannot be listed from one where the validator file is missing, so an untested regression could restore the misleading missing-file diagnostic.
Suggestion: Add a test that makes
os.listdir(checkout)raiseOSErrorand verifies validation reports that it cannot read the constitution checkout, including the relevant path or error context.Evidence:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in a01fcf0