Repository navigation
refactor(chat): read the action-kind vocabulary from the store that owns it #7825
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/chat-action-kind-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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """The Chat action-kind vocabulary has one owner, so a new kind cannot land twice. | ||
|
|
||
| ``loopx/chat_action_store.py`` decides which action kinds a proposal may be stored | ||
| for, and ``loopx/chat_server.py`` publishes that same set to hosts. | ||
| ``loopx/chat_actions.py`` kept a byte-identical copy under a different name and | ||
| gated dispatch on it, so a kind added to one side stayed invisible to the other | ||
| and a proposal could be accepted by the service while the store rejected it. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import ast | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from loopx import chat_action_store, chat_actions | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
| OWNER_PATH = "loopx/chat_action_store.py" | ||
| OWNER_NAME = "ACTION_KINDS" | ||
| KIND_VALUE = frozenset( | ||
| { | ||
| "agent.bind", | ||
| "gate.resolve", | ||
| "goal.acceptance.check", | ||
| "goal.create", | ||
| "goal.lifecycle", | ||
| "goal.update", | ||
| "heartbeat.bind", | ||
| "monitor.create", | ||
| "monitor.update", | ||
| "operation.execute", | ||
| "run.correct", | ||
| "team.plan", | ||
| "todo.create", | ||
| "todo.update", | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def set_literal(node: ast.AST) -> frozenset[str] | None: | ||
| """Return the string members of a set literal, including a frozenset call.""" | ||
| if isinstance(node, ast.Call) and getattr(node.func, "id", "") == "frozenset": | ||
| if not node.args: | ||
| return None | ||
| node = node.args[0] | ||
| if not isinstance(node, ast.Set): | ||
| return None | ||
| members: set[str] = set() | ||
| for element in node.elts: | ||
| if not isinstance(element, ast.Constant) or not isinstance(element.value, str): | ||
| return None | ||
| members.add(element.value) | ||
| return frozenset(members) | ||
|
|
||
|
|
||
| def modules_holding_the_vocabulary() -> list[str]: | ||
| offenders: list[str] = [] | ||
| for path in sorted(REPO_ROOT.glob("loopx/**/*.py")): | ||
| relative = path.relative_to(REPO_ROOT).as_posix() | ||
| try: | ||
| tree = ast.parse(path.read_text(encoding="utf-8")) | ||
| except (SyntaxError, UnicodeDecodeError): # pragma: no cover - guarded tree | ||
| continue | ||
| for statement in tree.body: | ||
| if not isinstance(statement, ast.Assign): | ||
| continue | ||
| vocabulary = set_literal(statement.value) | ||
| if vocabulary == KIND_VALUE: | ||
| offenders.append(relative) | ||
| break | ||
| return offenders | ||
|
|
||
|
|
||
| def test_the_store_owns_the_declared_action_kind_vocabulary() -> None: | ||
| assert frozenset(chat_action_store.ACTION_KINDS) == KIND_VALUE | ||
|
|
||
|
|
||
| def test_the_action_service_applies_the_owner_object() -> None: | ||
| assert chat_actions.SUPPORTED_ACTION_KINDS is chat_action_store.ACTION_KINDS | ||
|
|
||
|
|
||
| def test_no_module_outside_the_owner_holds_its_own_copy() -> None: | ||
| assert modules_holding_the_vocabulary() == [OWNER_PATH] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("action_kind", sorted(KIND_VALUE)) | ||
| def test_every_declared_kind_is_dispatchable(action_kind: str) -> None: | ||
| assert action_kind in chat_actions.SUPPORTED_ACTION_KINDS | ||
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] 把带类型的集合赋值纳入 census:这里仅接受 ast.Assign,独立反例
LOCAL_COPY: set[str] = {...同样14项...}会漏过,而普通赋值会被正确拦下;包含全部17项原断言的隔离检查仍通过。建议同时处理 ast.AnnAssign,或明确限定扫描器的覆盖声明。这是未来回退检测的非阻塞建议,当前生产别名导入及运行行为已验证。