Repository navigation
refactor(progress-review): read the pending reason from the policy that owns it #7826
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
loopx-agent
merged 1 commit into
loopx-project:main
from
keoyyo85:refactor/progress-review-pending-reason-owner
Nov 1, 2026
Merged
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
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
108 changes: 108 additions & 0 deletions
108
tests/architecture/test_progress_review_pending_reason_owner.py
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,108 @@ | ||
| """One owner decides the reason a scoped progress-review receipt carries no verdict. | ||
|
|
||
| ``loopx/control_plane/work_items/progress_review_policy.py`` owns the | ||
| progress-review vocabulary that both the capability receipt and the control-plane | ||
| consumer read, and both already imported ``PROGRESS_REVIEW_SIGNALS`` from it. The | ||
| pending reason was the exception: each side declared ``"pending_evaluation"`` | ||
| under its own name, so a rename on one side would leave the other silently | ||
| comparing against a reason that no longer exists. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import ast | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from loopx.capabilities.progress_review import receipt | ||
| from loopx.control_plane.work_items import ( | ||
| external_progress_review, | ||
| progress_review_policy, | ||
| ) | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
| OWNER_PATH = "loopx/control_plane/work_items/progress_review_policy.py" | ||
| OWNER_NAME = "PROGRESS_REVIEW_PENDING_REASON" | ||
| OWNER_MODULE = "progress_review_policy" | ||
| REASON_VALUE = "pending_evaluation" | ||
|
|
||
|
|
||
| def reason_assignments(source: str) -> list[str]: | ||
| """Names bound to the pending-reason literal anywhere in a module.""" | ||
| tree = ast.parse(source) | ||
| held: list[str] = [] | ||
| for node in ast.walk(tree): | ||
| if isinstance(node, (ast.Assign, ast.AnnAssign)): | ||
| targets = ( | ||
| node.targets | ||
| if isinstance(node, ast.Assign) | ||
| else [node.target] | ||
| if node.target is not None | ||
| else [] | ||
| ) | ||
| for target in targets: | ||
| if ( | ||
| isinstance(target, ast.Name) | ||
| and isinstance(node.value, ast.Constant) | ||
| and node.value.value == REASON_VALUE | ||
| ): | ||
| held.append(target.id) | ||
| return held | ||
|
|
||
|
|
||
| def modules_holding_the_reason() -> list[str]: | ||
| holders: list[str] = [] | ||
| for path in sorted(REPO_ROOT.glob("loopx/**/*.py")): | ||
| try: | ||
| held = reason_assignments(path.read_text(encoding="utf-8")) | ||
| except (SyntaxError, UnicodeDecodeError): # pragma: no cover - guarded tree | ||
| continue | ||
| if held: | ||
| holders.append(path.relative_to(REPO_ROOT).as_posix()) | ||
| return holders | ||
|
|
||
|
|
||
| def owner_import_levels(source: str) -> dict[str, int]: | ||
| """Local names bound by an import from the owner module, with their levels.""" | ||
| bindings: dict[str, int] = {} | ||
| for node in ast.walk(ast.parse(source)): | ||
| if isinstance(node, ast.ImportFrom) and (node.module or "").endswith(OWNER_MODULE): | ||
| for alias in node.names: | ||
| bindings[alias.asname or alias.name] = node.level | ||
| return bindings | ||
|
|
||
|
|
||
| def test_the_policy_owner_states_the_reason() -> None: | ||
| assert progress_review_policy.PROGRESS_REVIEW_PENDING_REASON == REASON_VALUE | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("module", "local_name"), | ||
| [ | ||
| (receipt, "PROGRESS_REVIEW_PENDING_REASON"), | ||
| (external_progress_review, "EXTERNAL_PROGRESS_REVIEW_PENDING_REASON"), | ||
| ], | ||
| ids=["capability-receipt", "external-review"], | ||
| ) | ||
| def test_each_consumer_imports_the_owner_name_and_carries_its_value( | ||
| module: object, local_name: str | ||
| ) -> None: | ||
| source = Path(module.__file__).read_text(encoding="utf-8") # type: ignore[attr-defined] | ||
|
|
||
| assert owner_import_levels(source).get(local_name), ( | ||
| f"{local_name} must be imported from {OWNER_MODULE}, not re-declared locally" | ||
| ) | ||
| assert getattr(module, local_name) == REASON_VALUE | ||
|
|
||
|
|
||
| def test_no_module_outside_the_owner_holds_the_reason() -> None: | ||
| assert modules_holding_the_reason() == [OWNER_PATH] | ||
|
|
||
|
|
||
| def test_the_reason_stays_distinct_from_the_unevaluated_vocabulary() -> None: | ||
| # The receipt reason is input; the classifier projects it onto its own | ||
| # `"pending"` outcome reason, so the two vocabularies must not merge. | ||
| assert REASON_VALUE not in ( | ||
| external_progress_review.EXTERNAL_PROGRESS_REVIEW_UNEVALUATED_REASONS | ||
| ) | ||
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.
[P3] 验证最终绑定是否仍来自 owner:保留当前导入,随后追加
PROGRESS_REVIEW_PENDING_REASON = "pending_" + "evaluation"(另一消费者使用其旧公开名),导入存在检查、值相等检查和字面量 census 全部仍通过。独立执行两个修改后的消费者及原5项断言已复现。建议检测导入名的后续赋值,或收窄“禁止计算副本”的覆盖声明;当前生产代码的 owner 导入正确,此项非阻塞。