Skip to content

Commit 6b4f4e5

Browse files
authored
Defer Chat and release qualification execution imports (#10110)
Signed-off-by: lusendong.6789 <lusendong.6789@bytedance.com>
1 parent fd6a429 commit 6b4f4e5

8 files changed

Lines changed: 51 additions & 18 deletions

File tree

‎loopx/chat/server_defaults.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Bind defaults shared by the CLI and the local Chat service."""
2+
3+
DEFAULT_CHAT_HOST = "127.0.0.1"
4+
DEFAULT_CHAT_PORT = 8767

‎loopx/chat_server.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
GOAL_SOURCE_STRATEGIES_PATH, GoalSourceRequestMixin,
115115
)
116116
from .chat.todo_detail import TodoDetailRequestMixin
117+
from .chat.server_defaults import (
118+
DEFAULT_CHAT_HOST as DEFAULT_CHAT_HOST,
119+
DEFAULT_CHAT_PORT as DEFAULT_CHAT_PORT,
120+
)
117121
from .hosts.kiro_cli import KIRO_CLI_BIN
118122
from .paths import resolve_runtime_root
119123
from .release_manifest import release_runtime_identity
@@ -138,8 +142,6 @@
138142
)
139143

140144

141-
DEFAULT_CHAT_HOST = "127.0.0.1"
142-
DEFAULT_CHAT_PORT = 8767
143145
DEFAULT_CHAT_PATH = "/chat/"
144146
DEFAULT_CHAT_STATUS_PATH = "/status.json"
145147
CHAT_CAPABILITIES_PATH = "/api/chat/capabilities"

‎loopx/cli_commands/canary.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
build_smoke_fleet_health,
4040
render_smoke_fleet_health_markdown,
4141
)
42-
from ..control_plane.testing.release_commit_qualification import (
43-
render_exact_release_commit_qualification_markdown,
44-
)
4542
from ..control_plane.projects.registry_codec import load_registry
4643
from ..paths import resolve_runtime_root
4744
from .canary_release_qualification import (
@@ -675,6 +672,10 @@ def handle_canary_command(
675672
)
676673
renderer = render_smoke_fleet_health_markdown
677674
elif args.canary_command == "release-qualification":
675+
from ..control_plane.testing.release_commit_qualification import (
676+
render_exact_release_commit_qualification_markdown,
677+
)
678+
678679
payload = build_canary_release_qualification_payload(args)
679680
renderer = render_exact_release_commit_qualification_markdown
680681
elif args.canary_command == "plan":

‎loopx/cli_commands/canary_release_qualification.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
from pathlib import Path
77

88
from ..control_plane.runtime.public_safety import public_safe_compact_text
9-
from ..control_plane.testing.release_commit_qualification import (
10-
EXACT_RELEASE_COMMIT_RECEIPT_SCHEMA_VERSION,
11-
build_exact_release_commit_qualification,
12-
collect_release_source_identity,
13-
)
149

1510

1611
def register_canary_release_qualification_command(
@@ -69,6 +64,12 @@ def register_canary_release_qualification_command(
6964

7065

7166
def build_canary_release_qualification_payload(args: argparse.Namespace) -> dict[str, object]:
67+
from ..control_plane.testing.release_commit_qualification import (
68+
EXACT_RELEASE_COMMIT_RECEIPT_SCHEMA_VERSION,
69+
build_exact_release_commit_qualification,
70+
collect_release_source_identity,
71+
)
72+
7273
try:
7374
raw = json.loads(args.manifest_json.expanduser().read_text(encoding="utf-8"))
7475
if not isinstance(raw, dict):

‎loopx/cli_commands/support_control.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
import argparse
44
from collections.abc import Callable
55
from pathlib import Path
6+
from typing import Any
67

78
from ..cli_runtime import (
89
_handle_registry_inspection_command,
910
_register_registry_inspection_commands,
1011
)
11-
from ..chat_server import (
12-
DEFAULT_CHAT_HOST,
13-
DEFAULT_CHAT_PORT,
14-
serve_chat,
15-
)
12+
from ..chat.server_defaults import DEFAULT_CHAT_HOST, DEFAULT_CHAT_PORT
1613
from ..dashboard_launcher import launch_dashboard
1714
from ..runtime_activation import replace_managed_loopx_chat as replace_existing_loopx_chat
1815
from ..heartbeat_prequota import (
@@ -121,6 +118,12 @@ def register_support_control_commands(
121118
register_chat_and_dashboard_commands(subparsers, add_subcommand_format)
122119

123120

121+
def serve_chat(**options: Any) -> None:
122+
from ..chat_server import serve_chat as start_chat
123+
124+
start_chat(**options)
125+
126+
124127
def register_serve_status_command(subparsers: argparse._SubParsersAction) -> None:
125128
serve_status_parser = subparsers.add_parser(
126129
"serve-status", help="Serve live status JSON for the local dashboard."

‎loopx/cli_commands/support_control_chat.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pathlib import Path
1313
from typing import Any
1414

15-
from ..chat_server import DEFAULT_CHAT_HOST, DEFAULT_CHAT_PORT
15+
from ..chat.server_defaults import DEFAULT_CHAT_HOST, DEFAULT_CHAT_PORT
1616
from ..hosts.kiro_cli import KIRO_CLI_BIN
1717
from ..paths import default_public_scan_root
1818
from .support_control_agent_runtime import (

‎loopx/dashboard_launcher.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from urllib.parse import quote
1313
import webbrowser
1414

15+
from .chat.server_defaults import DEFAULT_CHAT_HOST, DEFAULT_CHAT_PORT
1516
from .cli_commands.support_control_agent_runtime import ensure_agent_runtime_path
1617
from .hosts.kiro_cli import KIRO_CLI_BIN
1718
from .release_manifest import release_runtime_identity
@@ -211,8 +212,8 @@ def launch_dashboard(
211212
runtime_root_override: Path | None = None,
212213
scan_roots: list[Path] | None = None,
213214
limit: int = 20,
214-
host: str = "127.0.0.1",
215-
port: int = 8767,
215+
host: str = DEFAULT_CHAT_HOST,
216+
port: int = DEFAULT_CHAT_PORT,
216217
goal_id: str | None = None,
217218
codex_bin: str = "codex",
218219
claude_bin: str = "claude",

‎tests/test_cli_entrypoint.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ def run_isolated_script(
127127
)
128128

129129

130+
def test_full_parser_registers_chat_and_release_routes_before_loading_execution():
131+
result = run_isolated_script('''
132+
import sys
133+
from loopx.cli import build_parser
134+
135+
parser = build_parser()
136+
chat = parser.parse_args(["chat"])
137+
dashboard = parser.parse_args(["dashboard"])
138+
release = parser.parse_args([
139+
"canary", "release-qualification", "--manifest-json", "receipt.json",
140+
])
141+
assert (chat.host, chat.port) == ("127.0.0.1", 8767)
142+
assert (dashboard.host, dashboard.port) == (chat.host, chat.port)
143+
assert release.canary_command == "release-qualification"
144+
assert release.manifest_json.name == "receipt.json"
145+
assert "loopx.chat_server" not in sys.modules
146+
assert "loopx.control_plane.testing.release_commit_qualification" not in sys.modules
147+
''')
148+
assert result.returncode == 0, (result.stdout, result.stderr)
149+
150+
130151
def run_cli_main(
131152
module: str,
132153
argv: list[str],

0 commit comments

Comments
 (0)