-
Notifications
You must be signed in to change notification settings - Fork 10.7k
TUI: enforce core boundary #17399
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
TUI: enforce core boundary #17399
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """Verify codex-tui does not depend on or import codex-core directly.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| import sys | ||
| import tomllib | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[2] | ||
| TUI_ROOT = ROOT / "codex-rs" / "tui" | ||
| TUI_MANIFEST = TUI_ROOT / "Cargo.toml" | ||
| FORBIDDEN_PACKAGE = "codex-core" | ||
| FORBIDDEN_SOURCE_PATTERNS = ( | ||
| re.compile(r"\bcodex_core::"), | ||
| re.compile(r"\buse\s+codex_core\b"), | ||
| re.compile(r"\bextern\s+crate\s+codex_core\b"), | ||
| ) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| failures = [] | ||
| failures.extend(manifest_failures()) | ||
| failures.extend(source_failures()) | ||
|
|
||
| if not failures: | ||
| return 0 | ||
|
|
||
| print("codex-tui must not depend on or import codex-core directly.") | ||
| print( | ||
| "Use the app-server protocol/client boundary instead; temporary embedded " | ||
| "startup gaps belong behind codex_app_server_client::legacy_core." | ||
| ) | ||
| print() | ||
| for failure in failures: | ||
| print(f"- {failure}") | ||
|
|
||
| return 1 | ||
|
|
||
|
|
||
| def manifest_failures() -> list[str]: | ||
| manifest = tomllib.loads(TUI_MANIFEST.read_text()) | ||
| failures = [] | ||
| for section_name, dependencies in dependency_sections(manifest): | ||
| if FORBIDDEN_PACKAGE in dependencies: | ||
| failures.append( | ||
| f"{relative_path(TUI_MANIFEST)} declares `{FORBIDDEN_PACKAGE}` " | ||
| f"in `[{section_name}]`" | ||
| ) | ||
| return failures | ||
|
|
||
|
|
||
| def dependency_sections(manifest: dict) -> list[tuple[str, dict]]: | ||
| sections: list[tuple[str, dict]] = [] | ||
| for section_name in ("dependencies", "dev-dependencies", "build-dependencies"): | ||
| dependencies = manifest.get(section_name) | ||
| if isinstance(dependencies, dict): | ||
| sections.append((section_name, dependencies)) | ||
|
|
||
| for target_name, target in manifest.get("target", {}).items(): | ||
| if not isinstance(target, dict): | ||
| continue | ||
| for section_name in ("dependencies", "dev-dependencies", "build-dependencies"): | ||
| dependencies = target.get(section_name) | ||
| if isinstance(dependencies, dict): | ||
| sections.append((f'target.{target_name}.{section_name}', dependencies)) | ||
|
|
||
| return sections | ||
|
|
||
|
|
||
| def source_failures() -> list[str]: | ||
| failures = [] | ||
| for path in sorted(TUI_ROOT.glob("**/*.rs")): | ||
| text = path.read_text() | ||
| for line_number, line in enumerate(text.splitlines(), start=1): | ||
| if any(pattern.search(line) for pattern in FORBIDDEN_SOURCE_PATTERNS): | ||
| failures.append(f"{relative_path(path)}:{line_number} imports `codex_core`") | ||
| return failures | ||
|
|
||
|
|
||
| def relative_path(path: Path) -> str: | ||
| return str(path.relative_to(ROOT)) | ||
|
|
||
|
|
||
| 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.