From 7a340f2b42cf1e3c0e1d8fe46c3ac9556dcf3103 Mon Sep 17 00:00:00 2001 From: "lusendong.6789" Date: Sun, 15 Nov 2026 19:07:30 +0800 Subject: [PATCH] Load provider options only for the selected capability editor Signed-off-by: lusendong.6789 Signed-off-by: lusendong.6789 Co-authored-by: TRAE CLI --- .../rfcs/monorepo-distribution-split-v0.md | 24 ++++ .../monorepo-distribution-split-v0.zh-CN.md | 20 +++ loopx/capabilities/configuration_ui.py | 13 +- .../test_capability_configuration_ui.py | 121 ++++++++++++++++++ 4 files changed, 175 insertions(+), 3 deletions(-) diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.md index 6eef01a39b..5c194b4321 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.md @@ -4537,3 +4537,27 @@ view shows its independently checked result in the same conversation. improvement, original-ten acceptance or C1 cutover. Preserve prior sources, failures and seals; full original-goal regression still precedes completion and EdgeBench preparation. + +### 2026-11-15 — Resolve provider options for the requested capability editor + +- **Gap:** resolving even a disabled periodic-report subscription constructed + every editor definition and queried unselected `codex_chat` profile and + steward options. Unavailable unrelated providers could block its metadata. +- **Delta:** the existing editor queries the original profile owner only for + `codex_chat`, and the original steward vocabulary helper only for + `codex_chat` or `steward_executor`. Selected fields, scopes, nullable options, + helper ordering/errors, configuration precedence and detached outputs retain + their contracts; unknown editors remain read-only without provider discovery. +- **Evidence:** all 20 registered editor definitions and unknown/empty inputs + have complete baseline/candidate comparisons, including nullable resolution + and detached outputs. Fresh unavailable-provider counterexamples and selected + owner positive/negative checks pass. Earlier Core evidence from + `main@2b156284c4f4` and C1 #8266 snapshot `1a3740cf9e6e` plus only an editor + overlay is preserved within that original scope. Requalification builds + separate installed Core wheels from `main@fef679d18192` plus this editor and + its conflict-free merge with current C1 `1a3740cf9e6e`; both pass metadata + checks and File/SQLite execution, replay and readback. +- **Boundary:** this narrows metadata discovery, not installed capability + contents or activation. Full Settings journeys, actual-model adoption, total + cost, natural process drain, complete D2/D5 closure, R1/M3, full C1 acceptance + and its default cutover remain unqualified. diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md index 54af114ba9..45b420baa1 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md @@ -3510,3 +3510,23 @@ workspace 批准和脚本模型工作。桌面视图在采用检查后显示原 窗口,不证明真实计时等价或性能收益。它不完成 D2/D5、真实模型/上下文采用、完整成本改善、原十项验收 或 C1 切换。保留历史源码、失败和 seal;完成前仍需完整原目标回归,随后才准备 EdgeBench。 + +### 2026-11-15 — 仅为请求的 capability editor 求 provider options + +- **缺口:**即使解析未启用的 periodic-report 订阅,也会构造全部 editor definitions, + 查询未选中的 `codex_chat` profiles 和 steward options;无关 provider 不可用时 + 会阻断本次 metadata。 +- **增量:**现有 editor 仅为 `codex_chat` 查询原 profile owner,仅为 `codex_chat` + 或 `steward_executor` 查询原 steward vocabulary helper。所选字段、scopes、 + nullable options、helper 顺序与异常、配置 precedence 和 detached outputs 保留 + 原契约;unknown editor 仍只读,且不查询 provider。 +- **证据:**全部 20 个已注册 editor、unknown/empty 输入有完整基线与候选对照, + 包括 nullable resolution 和 detached outputs。新进程中的 provider 不可用反例 + 及所选原 owner 的正反例通过。此前 `main@2b156284c4f4` 与 C1 #8266 snapshot + `1a3740cf9e6e` 仅 overlay editor 的 Core 证据保留在原范围内。重新资格化分别 + 从 `main@fef679d18192` 加入本 editor,以及它与当前 C1 `1a3740cf9e6e` 的无 + 冲突合并来源构建独立真实 Core wheel;均通过 metadata 检查及 File/SQLite + 执行、回放和回读。 +- **边界:**本次收窄 metadata discovery,不改变安装的 capability 内容或 activation。 + 全 Settings 旅程、真实模型采纳、总成本、自然进程 drain、完整 D2/D5 闭包、 + R1/M3、完整 C1 验收及其默认切换仍未资格化。 diff --git a/loopx/capabilities/configuration_ui.py b/loopx/capabilities/configuration_ui.py index 9be1689c3d..e991c2d0e9 100644 --- a/loopx/capabilities/configuration_ui.py +++ b/loopx/capabilities/configuration_ui.py @@ -83,8 +83,15 @@ def capability_configuration_editor( # The steward namespace owns its closed vocabulary, so the editor offers the # same values instead of restating them: a form cannot submit an executor or # effort the owning namespace would reject. - steward_endpoints, steward_efforts = _steward_executor_editor_options() - from .native_chat.machine_defaults import codex_profile_options + steward_endpoints, steward_efforts = ( + _steward_executor_editor_options() + if capability_id in ("codex_chat", "steward_executor") else ([], []) + ) + codex_profiles: list[str] = [] + if capability_id == "codex_chat": + from .native_chat.machine_defaults import codex_profile_options + + codex_profiles = codex_profile_options() definitions: dict[str, dict[str, Any]] = { "context_delivery": { "supported_scopes": ["machine"], "writable_scopes": ["machine"], @@ -100,7 +107,7 @@ def capability_configuration_editor( "supported_scopes": ["machine"], "writable_scopes": ["machine"], "fields": [ _field("codex_profile", "Codex configuration profile", "select", nullable=True, - options=codex_profile_options(), description="Existing native account/configuration home; credentials are not copied."), + options=codex_profiles, description="Existing native account/configuration home; credentials are not copied."), _field("model", "Conversation model", "text", nullable=True, description="For example gpt-6.1-sol. Blank inherits this Codex profile's default."), _field("reasoning_effort", "Reasoning effort", "select", nullable=True, diff --git a/tests/capabilities/test_capability_configuration_ui.py b/tests/capabilities/test_capability_configuration_ui.py index c9eee87560..fce9397390 100644 --- a/tests/capabilities/test_capability_configuration_ui.py +++ b/tests/capabilities/test_capability_configuration_ui.py @@ -1,5 +1,9 @@ from __future__ import annotations +import json +import subprocess +import sys + import pytest from loopx.capabilities.configuration_ui import ( @@ -19,6 +23,123 @@ ) +@pytest.fixture(autouse=True) +def isolated_native_profile_discovery(tmp_path, monkeypatch): + from loopx import codex_app_thread_activity + + discover = codex_app_thread_activity.codex_homes + monkeypatch.setattr( + codex_app_thread_activity, "codex_homes", + lambda: discover(env={}, user_home=tmp_path), + ) + + +@pytest.mark.parametrize("capability_id", [ + "context_delivery", "goal_capability_organization", "goal_storage", + "todo_replan_cadence", "periodic_report", "manager_runtime", + "steward_executor", "multi_subagent", "peer_task_coordination", + "explore_graph", "explore_harness", "change_quality_qualification", + "progress_review", "pull_request_review", "local_authority_shadow", + "coordination_runtime_shadow", "lark_kanban_heartbeat_sync", "reward_memory", + "lark_event_inbox", "unregistered-editor", "", +]) +def test_editor_does_not_load_unselected_provider(capability_id, tmp_path): + source = '''import importlib.abc,json,sys +capability=sys.argv[1] +blocked=['loopx.capabilities.native_chat'] +if capability!='steward_executor':blocked.append('loopx.capabilities.steward_executor') +class UnavailableProvider(importlib.abc.MetaPathFinder): + def find_spec(self,fullname,path=None,target=None): + if any(fullname==name or fullname.startswith(name+'.') for name in blocked): + raise ImportError('unselected provider unavailable') +sys.meta_path.insert(0,UnavailableProvider()) +from loopx.capabilities.configuration_ui import capability_configuration_editor,resolve_capability_configuration +editor=capability_configuration_editor(capability) +assert editor['schema_version']=='capability_configuration_editor_v0' +assert not any(any(name==root or name.startswith(root+'.') for root in blocked) for name in sys.modules) +if capability=='periodic_report': + resolved=resolve_capability_configuration(capability,capability_default={'enabled':False,'timezone':'UTC'}) + assert resolved['source']=='capability_default' and resolved['configuration']=={'enabled':False,'timezone':'UTC'} +print(json.dumps(editor)) +''' + result = subprocess.run( + [sys.executable, "-I", "-c", source, capability_id], + cwd=tmp_path, capture_output=True, text=True, timeout=30, + ) + assert result.returncode == 0, result.stderr + editor = json.loads(result.stdout) + if capability_id in ("unregistered-editor", ""): + assert editor == { + "schema_version": "capability_configuration_editor_v0", + "editable": False, "supported_scopes": [], "writable_scopes": [], + "fields": [], + "read_only_reason": "No Dashboard editor is registered for this capability.", + } + + +def test_codex_editor_uses_existing_profile_owner_and_nullable_options(tmp_path): + from loopx.capabilities.steward_executor.machine_defaults import steward_reasoning_efforts + + (tmp_path / ".codex").mkdir() + (tmp_path / ".codex-blue").mkdir() + (tmp_path / ".codex-red").mkdir() + (tmp_path / ".codex_bad").mkdir() + fields = {row["key"]: row for row in capability_configuration_editor("codex_chat")["fields"]} + assert fields["codex_profile"]["options"] == ["codex", "codex-blue", "codex-red"] + assert fields["codex_profile"]["nullable"] is True + assert fields["reasoning_effort"]["options"] == list(steward_reasoning_efforts()) + assert fields["model"]["nullable"] is True + assert fields["service_tier"]["nullable"] is True + + +@pytest.mark.parametrize("capability_id,expected", [ + ("codex_chat", ["endpoints", "efforts", "profiles"]), + ("steward_executor", ["endpoints", "efforts"]), +]) +def test_selected_editor_preserves_existing_owner_order(capability_id, expected, monkeypatch): + from loopx import codex_app_thread_activity + from loopx.capabilities.steward_executor import machine_defaults + + calls = [] + + def observed(owner, name, label): + original = getattr(owner, name) + + def call(): + calls.append(label) + return original() + + monkeypatch.setattr(owner, name, call) + + observed(machine_defaults, "steward_executor_endpoints", "endpoints") + observed(machine_defaults, "steward_reasoning_efforts", "efforts") + observed(codex_app_thread_activity, "codex_homes", "profiles") + capability_configuration_editor(capability_id) + assert calls == expected + + +@pytest.mark.parametrize("capability_id,provider", [ + ("codex_chat", "native_chat"), ("steward_executor", "steward_executor"), +]) +def test_editor_exposes_selected_provider_unavailability(capability_id, provider, tmp_path): + source = '''import importlib.abc,sys +class UnavailableProvider(importlib.abc.MetaPathFinder): + def find_spec(self,fullname,path=None,target=None): + root='loopx.capabilities.'+sys.argv[2] + if fullname==root or fullname.startswith(root+'.'):raise ImportError('selected provider unavailable') +sys.meta_path.insert(0,UnavailableProvider()) +from loopx.capabilities.configuration_ui import capability_configuration_editor +try:capability_configuration_editor(sys.argv[1]) +except ImportError as error:assert str(error)=='selected provider unavailable' +else:raise AssertionError('selected provider failure was hidden') +''' + result = subprocess.run( + [sys.executable, "-I", "-c", source, capability_id, provider], + cwd=tmp_path, capture_output=True, text=True, timeout=30, + ) + assert result.returncode == 0, result.stderr + + def test_machine_catalog_only_uses_dashboard_supported_editor_kinds() -> None: """A Goal-only descriptor must not make the whole machine page unreadable."""