Skip to content

test(agentkit): unit tests for apps entrypoints + deploy-pipeline (surface + core logic)#105

Merged
yaozheng-fang merged 2 commits into
feat/agentkit-engineering-standardsfrom
test/agentkit-apps-pipeline-ut
Jul 1, 2026
Merged

test(agentkit): unit tests for apps entrypoints + deploy-pipeline (surface + core logic)#105
yaozheng-fang merged 2 commits into
feat/agentkit-engineering-standardsfrom
test/agentkit-apps-pipeline-ut

Conversation

@tiantt

@tiantt tiantt commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

What

Adds unit tests for the two highest-risk under-tested areas found by a coverage audit: the deployable app server surfaces and the deploy-pipeline / invoke core logic. +339 tests, all offline (no network / docker / uvicorn), 0 source modified.

Overall line coverage 45.9% → 53.7%; apps 9.9% → 76%. Critical functions lifted from ~0% to tested:

function before → after
ve_pipeline.build (build→push→deploy spine) 1.9% → 100%
_upload_to_tos (bucket-ownership security gate) 0% → 70%
_create_new_runtime / _update_existing_runtime 3%/1.8% → 91%/88%
_wait_for_runtime_status 9.5% → 100%
runners/base._http_post_invoke (invoke transport) 1% → 91%
local_docker.build 0.7% → 86%
agent_server_app._invoke_compat (/invoke serving) 0% → 89%

Latent bugs surfaced

Testing the real logic (not padding coverage) surfaced 6 latent source bugs; they are pinned to current behavior here with # NOTE comments and fixed in the stacked fix PR (fix/agentkit-latent-bugs).

Notes

  • Tests introduce Starlette TestClient + asyncio.run (no @pytest.mark.asyncio, since pytest-asyncio is undeclared).
  • Only pre-existing failure in the suite is test_cli_add_harness (an env-leak flake on main); no new failures.

Stack

Base = feat/agentkit-engineering-standards. Merge that first.

🤖 Generated with Claude Code

tiantt and others added 2 commits July 1, 2026 10:48
Targets the two highest-risk under-tested areas found by a coverage audit:
the deployable app server surfaces (apps/, ~9.9% -> 76.3%) and the deploy
pipeline logic (toolkit runners/executors/strategies). Overall line coverage
45.9% -> 50.9%. +258 tests, all offline (no network/docker/uvicorn).

apps/ (Starlette TestClient + asyncio.run, telemetry singletons spied):
- simple_app: health/readiness/liveness + /ping wiring + ping() arg guard
- simple_app_handlers: InvokeHandler signature dispatch + response matrix,
  _convert_to_sse, AsyncTaskHandler, PingHandler
- a2a_app / mcp_app: decorator guards, ping endpoint, env-detect routes/tools
- agent_server: AgentKitAgentLoader + ctor guards; telemetry latency gating
  and error_type formatting; ASGI middleware header-exclusion + finish gating

pipeline (fakes injected via the existing DI seams):
- hybrid_strategy: _should_push_to_cr / _validate_cr_image_url error mapping,
  build/deploy config-updates assembly, invoke/status/destroy passthrough
- base_executor: _classify_error / _handle_exception (pins the ErrorCode
  mapping introduced by the engineering-standards work), preflight handling
- init_executor: render context, template/name validation, project scaffold
- runners/base + ve_agentkit: pure payload/detection helpers, _needs_runtime_
  update env diffing, deploy guard/dispatch, destroy/status mapping

Pins (NOT fixes — this branch is tests-only) three latent source bugs to
their current behavior with # NOTE comments, for a follow-up fix:
- mcp_app tool()/agent_as_a_tool() wrappers: on a tool exception the finally
  passes func_result=result while result is unbound -> UnboundLocalError masks
  the real error and skips telemetry (all 4 wrapper branches).
- simple_app_handlers PingHandler._format_ping_status: self.func.__name__
  raises AttributeError when no ping func is registered.
- simple_app_handlers AsyncTaskHandler.handle: signature omits request,
  violating the BaseHandler.handle(request) contract.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…st surface)

The prior batch raised the coverage number but left the product's core
orchestration ~0%. This batch tests that spine directly with proper fakes,
asserting behavior (error codes, response shapes, collaborator calls),
lifting the critical functions from ~0% to tested:

  ve_pipeline.build (build->push->deploy spine)   1.9% -> 100%
  ve_pipeline._upload_to_tos (bucket-ownership gate) 0% -> 70%
  ve_agentkit._create_new_runtime                    3% -> 91%
  ve_agentkit._update_existing_runtime             1.8% -> 88%
  ve_agentkit._wait_for_runtime_status             9.5% -> 100%
  runners/base._http_post_invoke (invoke transport)  1% -> 91%
  builders/local_docker.build                      0.7% -> 86%
  agent_server_app._invoke_compat (/invoke)          0% -> 89%

Overall coverage 45.9% -> 53.7%. +81 tests, all offline (no network/docker/
uvicorn; polling loops patched). No source modified.

Pins three more latent source bugs to current behavior (# NOTE, for follow-up):
- ve_pipeline._upload_to_tos: the documented ValueError for an unrendered
  {{template}} bucket name is caught by the broad `except Exception` tail and
  re-raised as a generic Exception, so callers can never catch ValueError.
- ve_agentkit._update_existing_runtime: client_token=generate_client_token()
  is passed to UpdateRuntimeRequest, which has no such field and extra="ignore",
  so the idempotency token is silently dropped (Create keeps it, Update sends none).
- builders/local_docker.build: BuildResult.build_logs is typed List[str] but
  the raw str from DockerManager.build_image is assigned directly on both the
  success and failure paths.

Also hardens test_ve_pipeline_upload_tos's AccountDisable assertion to be
cloud-provider-independent (console host varies volcengine vs byteplus and
provider global state leaks across the full suite).

Remaining gap: _execute_build's poll loop is still thin (mocked out to isolate
the build spine) — a follow-up target.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tiantt tiantt force-pushed the feat/agentkit-engineering-standards branch from fedc9c8 to ad13eaf Compare July 1, 2026 02:48
@tiantt tiantt force-pushed the test/agentkit-apps-pipeline-ut branch from d7864d6 to 48e00c6 Compare July 1, 2026 02:49
@yaozheng-fang yaozheng-fang merged commit e369ea0 into feat/agentkit-engineering-standards Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants