refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from types import SimpleNamespace
|
|
|
|
|
from unittest.mock import AsyncMock
|
|
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
import src.services.provider.adapters.gemini_cli.rust_http as gemini_cli_rust_http_mod
|
2026-04-03 14:59:58 +08:00
|
|
|
import src.services.request.execution_runtime_client as runtime_client_mod
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
from src.services.provider.adapters.gemini_cli.client import (
|
|
|
|
|
load_code_assist,
|
|
|
|
|
onboard_user,
|
|
|
|
|
)
|
2026-04-03 14:59:58 +08:00
|
|
|
from src.services.request.execution_runtime_client import (
|
|
|
|
|
ExecutionRuntimeClientError,
|
|
|
|
|
ExecutionRuntimeSyncResult,
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_load_code_assist_uses_rust_executor(
|
|
|
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
|
|
|
) -> None:
|
|
|
|
|
monkeypatch.setattr(gemini_cli_rust_http_mod.config, "executor_backend", "rust")
|
|
|
|
|
monkeypatch.setattr(
|
2026-04-03 14:59:58 +08:00
|
|
|
runtime_client_mod.ExecutionRuntimeClient,
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
"execute_sync_json",
|
|
|
|
|
AsyncMock(
|
2026-04-03 14:59:58 +08:00
|
|
|
return_value=ExecutionRuntimeSyncResult(
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
status_code=200,
|
|
|
|
|
headers={"content-type": "application/json"},
|
|
|
|
|
response_json={"cloudaicompanionProject": "project-1"},
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
|
"src.clients.http_client.HTTPClientPool.get_proxy_client",
|
|
|
|
|
AsyncMock(side_effect=AssertionError("python fallback should not run")),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = await load_code_assist("access-token", proxy_config=None, timeout_seconds=12.0)
|
|
|
|
|
|
|
|
|
|
assert result["cloudaicompanionProject"] == "project-1"
|
2026-04-03 14:59:58 +08:00
|
|
|
plan = runtime_client_mod.ExecutionRuntimeClient.execute_sync_json.await_args.args[0]
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
assert plan.method == "POST"
|
|
|
|
|
assert plan.url.endswith("/v1internal:loadCodeAssist")
|
|
|
|
|
assert plan.provider_api_format == "gemini_cli:load_code_assist"
|
|
|
|
|
assert plan.body.json_body == {
|
|
|
|
|
"metadata": {
|
|
|
|
|
"ideType": "ANTIGRAVITY",
|
|
|
|
|
"platform": "PLATFORM_UNSPECIFIED",
|
|
|
|
|
"pluginType": "GEMINI",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_load_code_assist_falls_back_to_python_when_rust_unavailable(
|
|
|
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
|
|
|
) -> None:
|
|
|
|
|
monkeypatch.setattr(gemini_cli_rust_http_mod.config, "executor_backend", "rust")
|
|
|
|
|
monkeypatch.setattr(
|
2026-04-03 14:59:58 +08:00
|
|
|
runtime_client_mod.ExecutionRuntimeClient,
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
"execute_sync_json",
|
2026-04-03 14:59:58 +08:00
|
|
|
AsyncMock(side_effect=ExecutionRuntimeClientError("executor down")),
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
)
|
|
|
|
|
fake_client = SimpleNamespace(
|
|
|
|
|
post=AsyncMock(
|
|
|
|
|
return_value=httpx.Response(
|
|
|
|
|
status_code=200,
|
|
|
|
|
request=httpx.Request("POST", "https://example.invalid/v1internal:loadCodeAssist"),
|
|
|
|
|
json={"cloudaicompanionProject": "project-fallback"},
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
|
"src.clients.http_client.HTTPClientPool.get_proxy_client",
|
|
|
|
|
AsyncMock(return_value=fake_client),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = await load_code_assist("access-token", proxy_config=None, timeout_seconds=12.0)
|
|
|
|
|
|
|
|
|
|
assert result["cloudaicompanionProject"] == "project-fallback"
|
|
|
|
|
fake_client.post.assert_awaited_once()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_onboard_user_uses_rust_executor(
|
|
|
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
|
|
|
) -> None:
|
|
|
|
|
monkeypatch.setattr(gemini_cli_rust_http_mod.config, "executor_backend", "rust")
|
|
|
|
|
monkeypatch.setattr(
|
2026-04-03 14:59:58 +08:00
|
|
|
runtime_client_mod.ExecutionRuntimeClient,
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
"execute_sync_json",
|
|
|
|
|
AsyncMock(
|
2026-04-03 14:59:58 +08:00
|
|
|
return_value=ExecutionRuntimeSyncResult(
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
status_code=200,
|
|
|
|
|
headers={"content-type": "application/json"},
|
|
|
|
|
response_json={
|
|
|
|
|
"done": True,
|
|
|
|
|
"response": {"cloudaicompanionProject": {"id": "project-onboarded"}},
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
monkeypatch.setattr(
|
|
|
|
|
"src.clients.http_client.HTTPClientPool.get_proxy_client",
|
|
|
|
|
AsyncMock(side_effect=AssertionError("python fallback should not run")),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
project_id = await onboard_user(
|
|
|
|
|
"access-token",
|
|
|
|
|
tier_id="legacy",
|
|
|
|
|
proxy_config=None,
|
|
|
|
|
timeout_seconds=15.0,
|
|
|
|
|
max_attempts=1,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert project_id == "project-onboarded"
|
2026-04-03 14:59:58 +08:00
|
|
|
plan = runtime_client_mod.ExecutionRuntimeClient.execute_sync_json.await_args.args[0]
|
refactor: 拆分 Rust gateway/executor 大文件为模块目录结构,拆分 Python gateway.py 为子模块
Rust 侧:
- executor.rs 拆分为 executor/ 目录 (plan_builders, stream, sync, submission)
- 新增 kiro_stream/, local_finalize/, local_stream/ 模块目录
- 新增 video_tasks.rs
- 测试文件 ai_execute/files/video 拆分为子目录
- handlers/headers/control/constants 扩展支持新模块
Python 侧:
- gateway.py 拆分为 24 个子模块 (routes, shared, contract, chat, cli, video, files, finalize, reporting 等)
- 新增 antigravity/gemini_cli/kiro 的 rust_http 适配层
- upstream_fetcher 增加 Rust sidecar 支持
- executor_plan/candidate/pipeline 适配调整
测试:
- 对应拆分 test_internal_gateway_routes 为子目录
- 新增 rust_http 相关测试
2026-03-23 17:19:15 +08:00
|
|
|
assert plan.method == "POST"
|
|
|
|
|
assert plan.url.endswith("/v1internal:onboardUser")
|
|
|
|
|
assert plan.provider_api_format == "gemini_cli:onboard_user"
|
|
|
|
|
assert plan.body.json_body["tierId"] == "legacy"
|