From db15587a117c549946ed0095f7c0ad4a6f423452 Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Thu, 5 Nov 2026 02:13:12 +0800 Subject: [PATCH] ci: run full ACP TCK suites against the SDK Run pinned native TCK v1 and v2 suites independently on PRs and main. Record the SDK and TCK snapshots and upload the native JSON, log, and exit code without replacing the TCK verdict. Exercise deterministic cancellation, session lifecycle and replay through the public SDK. Report v2 as diagnostic because the TCK and SDK draft snapshots differ. --- .github/workflows/tck.yml | 109 ++++++++++++++++++++++++ README.md | 2 + docs/tck.md | 19 +++++ mkdocs.yml | 1 + tests/tck/agent_v1.py | 115 +++++++++++++++++++++++++ tests/tck/agent_v2.py | 172 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 418 insertions(+) create mode 100644 .github/workflows/tck.yml create mode 100644 docs/tck.md create mode 100644 tests/tck/agent_v1.py create mode 100644 tests/tck/agent_v2.py diff --git a/.github/workflows/tck.yml b/.github/workflows/tck.yml new file mode 100644 index 00000000..844f50d8 --- /dev/null +++ b/.github/workflows/tck.yml @@ -0,0 +1,109 @@ +name: ACP TCK + +on: + push: + branches: [main] + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +permissions: + contents: read + +env: + TCK_COMMIT: 7c71c4d1af0994e73bdc100c9f7f6b98f2319cda # v0.5.0 + TCK_SPEC_REVISION: 3ea94133bb4e7cfdb1105df75660ff83e66acf62 + PYTHON_VERSION: "3.14.5" + +jobs: + agent-stdio: + name: ${{ matrix.name }} + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + fail-fast: false + matrix: + include: + # TCK v1.32.0 unstable vs SDK schema-v1.35.0. + - protocol: 1 + name: agent-stdio (v1) + sdk-schema: schema + sdk-bindings: src/acp + tck-schema-blob: 4f18b3e7e90d8d65d413d27b750aa87b1fe9024c + tck-meta-blob: 2736f7fc75263e8fe18545de936b905da6e15436 + # Diagnostic: TCK alpha.16 vs SDK alpha.7; keep the native failure visible. + - protocol: 2 + name: agent-stdio (v2 diagnostic) + sdk-schema: schema/v2 + sdk-bindings: src/acp/experimental/v2 + tck-schema-blob: 819dc3d7bea6022f673b7d6a03c6fc2f831b25b8 + tck-meta-blob: 8854425691cc15acdc82569facc1467494e2e7d6 + steps: + - name: Check out SDK + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 + with: + persist-credentials: false + + - name: Install uv + uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e + with: + version: "0.11.14" + enable-cache: true + + - name: Install current SDK checkout + run: uv sync --locked --no-dev --python "$PYTHON_VERSION" + + - name: Check out pinned ACP TCK + uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 + with: + repository: agentclientprotocol/acp-tck + ref: ${{ env.TCK_COMMIT }} + path: build/acp-tck + persist-credentials: false + + - name: Run full ACP TCK suite + shell: bash + env: + PROTOCOL: ${{ matrix.protocol }} + SDK_SCHEMA: ${{ matrix.sdk-schema }} + SDK_BINDINGS: ${{ matrix.sdk-bindings }} + TCK_SCHEMA_BLOB: ${{ matrix.tck-schema-blob }} + TCK_META_BLOB: ${{ matrix.tck-meta-blob }} + run: | + mkdir -p build/tck + tck="$PWD/build/acp-tck" + vendored="$tck/src/tck/v$PROTOCOL/schema" + { + echo "SDK commit: $(git rev-parse HEAD)" + echo "SDK schema: $(cat "$SDK_SCHEMA/VERSION")" + git diff --exit-code HEAD -- "$SDK_SCHEMA" "$SDK_BINDINGS/schema.py" "$SDK_BINDINGS/meta.py" + git ls-files -s -- "$SDK_SCHEMA/schema.json" "$SDK_SCHEMA/meta.json" \ + "$SDK_BINDINGS/schema.py" "$SDK_BINDINGS/meta.py" + sdk_import=$(.venv/bin/python -c 'import acp; print(acp.__file__)') + echo "SDK import: $sdk_import" + test "$sdk_import" = "$PWD/src/acp/__init__.py" + echo "TCK commit: $(git -C "$tck" rev-parse HEAD)" + echo "TCK spec revision: $TCK_SPEC_REVISION" + test "$(git -C "$tck" rev-parse HEAD)" = "$TCK_COMMIT" + grep -F "SCHEMA_REVISION = \"$TCK_SPEC_REVISION\"" "$vendored/../protocol.py" + test "$(git hash-object "$vendored/schema.unstable.json")" = "$TCK_SCHEMA_BLOB" + test "$(git hash-object "$vendored/meta.unstable.json")" = "$TCK_META_BLOB" + echo "TCK schema/meta blobs: $TCK_SCHEMA_BLOB $TCK_META_BLOB" + } 2>&1 | tee build/tck/tck.log + + status=0 + uv run --project "$tck" --locked --no-dev --python "$PYTHON_VERSION" acp-tck \ + --protocol-version "$PROTOCOL" --timeout 5 --cancel-prompt wait_for_cancel \ + --report-json "$PWD/build/tck/report.json" -- \ + "$PWD/.venv/bin/python" "$PWD/tests/tck/agent_v$PROTOCOL.py" \ + >>build/tck/tck.log 2>&1 || status=$? + printf '%s\n' "$status" >build/tck/exit-code.txt + tail -n 30 build/tck/tck.log + exit "$status" + + - name: Upload TCK report, log and exit code + if: always() + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + with: + name: acp-tck-v${{ matrix.protocol }} + path: build/tck/ + if-no-files-found: warn diff --git a/README.md b/README.md index b8aaac8a..3996c55f 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ See real adopters like kimi-cli in the [Use Cases list](https://agentclientproto | Quickstart | | | Use cases | | | Contrib helpers | | +| ACP TCK checks | | | Releasing workflow | | | Examples | | | Tests | | @@ -63,6 +64,7 @@ See real adopters like kimi-cli in the [Use Cases list](https://agentclientproto - `make install` provisions the `uv` virtualenv and installs pre-commit hooks. - `make check` runs Ruff formatting/linting, type analysis, dependency hygiene, and lock verification. - `make test` executes `pytest` (with doctests) inside the managed environment. +- See [ACP TCK checks](docs/tck.md) to run the pinned suites locally. - `ACP_SCHEMA_VERSION= make gen-all` refreshes protocol artifacts when the schema advances. Keep docs and examples current whenever you ship public API or transport changes, and prefer Conventional Commits (`feat:`, `fix:`, etc.) when submitting patches. diff --git a/docs/tck.md b/docs/tck.md new file mode 100644 index 00000000..fc1f869f --- /dev/null +++ b/docs/tck.md @@ -0,0 +1,19 @@ +# Run the ACP TCK locally + +From the SDK root, run the full suite for `version=1` or `version=2`: + +```sh +uv sync --locked --no-dev --python 3.14.5 +mkdir -p build/tck +git clone https://github.com/agentclientprotocol/acp-tck build/acp-tck +git -C build/acp-tck checkout --detach 7c71c4d1af0994e73bdc100c9f7f6b98f2319cda +version=1 +uv run --project build/acp-tck --locked --no-dev --python 3.14.5 acp-tck \ + --protocol-version "$version" --timeout 5 --cancel-prompt wait_for_cancel \ + --report-json "$PWD/build/tck/v$version.json" -- \ + "$PWD/.venv/bin/python" "$PWD/tests/tck/agent_v$version.py" +``` + +The CLI writes its native JSON report and returns its own exit code. CI uploads that report, +the log, and the exit code for each lane, including failures. Treat v2 as diagnostic: the +TCK's alpha.16 snapshot differs from the SDK's alpha.7 snapshot. diff --git a/mkdocs.yml b/mkdocs.yml index 1938cf48..8b706fa9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -13,6 +13,7 @@ nav: - Use Cases: use-cases.md - Web Transport (HTTP/WS): web-transport.md - Experimental Protocol v2: experimental-v2.md + - ACP TCK: tck.md - Experimental Contrib: contrib.md - Releasing: releasing.md - 0.11 Migration Guide: migration-guide-0.11.md diff --git a/tests/tck/agent_v1.py b/tests/tck/agent_v1.py new file mode 100644 index 00000000..296ef79a --- /dev/null +++ b/tests/tck/agent_v1.py @@ -0,0 +1,115 @@ +"""Deterministic ACP v1 agent for exercising the SDK with the external TCK. + +This probe supplies only application state. The SDK owns stdio framing, routing, +model validation, serialization, and JSON-RPC errors. +""" + +from __future__ import annotations + +import asyncio +from typing import Any, cast +from uuid import uuid4 + +from acp import PROTOCOL_VERSION, Agent, Client, RequestError, run_agent +from acp.schema import ( + AgentCapabilities, + AgentMessageChunk, + AudioContentBlock, + CloseSessionResponse, + EmbeddedResourceContentBlock, + ImageContentBlock, + Implementation, + InitializeResponse, + ListSessionsResponse, + NewSessionResponse, + PromptResponse, + ResourceContentBlock, + SessionCapabilities, + SessionCloseCapabilities, + SessionInfo, + SessionListCapabilities, + TextContentBlock, +) + +CANCEL_PROMPT = "wait_for_cancel" +ContentBlock = ( + TextContentBlock | ImageContentBlock | AudioContentBlock | ResourceContentBlock | EmbeddedResourceContentBlock +) + + +class ProbeAgent: + """A plain class so unimplemented Protocol methods do not become handlers.""" + + def __init__(self) -> None: + self._client: Client | None = None + self._sessions: dict[str, SessionInfo] = {} + self._pending: dict[str, asyncio.Event] = {} + + def on_connect(self, client: Client) -> None: + self._client = client + + async def initialize(self, protocol_version: int, **kwargs: Any) -> InitializeResponse: + return InitializeResponse( + protocol_version=PROTOCOL_VERSION, + agent_capabilities=AgentCapabilities( + session_capabilities=SessionCapabilities( + list=SessionListCapabilities(), close=SessionCloseCapabilities() + ), + ), + agent_info=Implementation(name="python-sdk-tck-v1", version="1"), + ) + + async def new_session(self, cwd: str, **kwargs: Any) -> NewSessionResponse: + session_id = uuid4().hex + self._sessions[session_id] = SessionInfo(session_id=session_id, cwd=cwd) + return NewSessionResponse(session_id=session_id) + + async def list_sessions( + self, cwd: str | None = None, cursor: str | None = None, **kwargs: Any + ) -> ListSessionsResponse: + if cursor is not None: + # This in-memory list never issues a continuation cursor. + raise RequestError.invalid_params({"details": "unknown session list cursor"}) + return ListSessionsResponse(sessions=[s for s in self._sessions.values() if cwd is None or s.cwd == cwd]) + + async def close_session(self, session_id: str, **kwargs: Any) -> CloseSessionResponse: + self._sessions.pop(session_id, None) + await self.cancel(session_id) + return CloseSessionResponse() + + async def prompt(self, session_id: str, prompt: list[ContentBlock], **kwargs: Any) -> PromptResponse: + if session_id not in self._sessions: + error = RequestError.resource_not_found() + error.data = {"sessionId": session_id} + raise error + assert self._client is not None + wait_for_cancel = ( + len(prompt) == 1 and isinstance(prompt[0], TextContentBlock) and prompt[0].text == CANCEL_PROMPT + ) + event = asyncio.Event() if wait_for_cancel else None + if event is not None: + self._pending[session_id] = event + try: + await self._client.session_update( + session_id=session_id, + update=AgentMessageChunk(content=TextContentBlock(text="ready")), + ) + if event is not None: + await event.wait() + return PromptResponse(stop_reason="cancelled" if event is not None else "end_turn") + finally: + if event is not None: + self._pending.pop(session_id, None) + + async def cancel(self, session_id: str, **kwargs: Any) -> None: + if event := self._pending.get(session_id): + event.set() + + +async def main() -> None: + # The public Protocol lists optional handlers that this probe intentionally omits. + await run_agent(cast(Agent, ProbeAgent())) + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/tests/tck/agent_v2.py b/tests/tck/agent_v2.py new file mode 100644 index 00000000..47cf7ef1 --- /dev/null +++ b/tests/tck/agent_v2.py @@ -0,0 +1,172 @@ +"""Deterministic ACP v2 agent for exercising the experimental SDK runtime. + +The session capability includes the v2 lifecycle baseline. Protocol framing, +validation, routing, and errors remain the SDK's responsibility. +""" + +from __future__ import annotations + +import asyncio +import contextlib +from typing import Any +from uuid import uuid4 + +from acp.exceptions import RequestError +from acp.experimental.v2 import PROTOCOL_VERSION, run_agent +from acp.experimental.v2.interfaces import Client +from acp.experimental.v2.schema import ( + AgentCapabilities, + AgentMessageChunk, + AgentMessageUpdate, + AudioContentBlock, + CloseSessionResponse, + EmbeddedResourceContentBlock, + IdleSessionStateUpdate, + ImageContentBlock, + Implementation, + InitializeResponse, + ListSessionsResponse, + NewSessionResponse, + OtherContentBlock, + OtherReplayFrom, + PromptResponse, + ReplayFromStartVariant, + ResourceContentBlock, + ResumeSessionResponse, + RunningSessionStateUpdate, + SessionCapabilities, + SessionInfo, + SessionInfoUpdate, + TextContentBlock, + UserMessageUpdate, +) + +CANCEL_PROMPT = "wait_for_cancel" +_CANCEL_FALLBACK_SECONDS = 60 +ContentBlock = ( + TextContentBlock + | ImageContentBlock + | AudioContentBlock + | ResourceContentBlock + | EmbeddedResourceContentBlock + | OtherContentBlock +) + + +class ProbeAgent: + def __init__(self) -> None: + self._client: Client | None = None + self._sessions: dict[str, SessionInfo] = {} + self._history: dict[str, list[UserMessageUpdate | AgentMessageUpdate]] = {} + self._cancel_events: dict[str, asyncio.Event] = {} + self._turns: dict[str, asyncio.Task[None]] = {} + + def on_connect(self, client: Client) -> None: + self._client = client + + async def initialize(self, protocol_version: int, info: Implementation, **kwargs: Any) -> InitializeResponse: + return InitializeResponse( + protocol_version=PROTOCOL_VERSION, + info=Implementation(name="python-sdk-tck-v2", version="1"), + capabilities=AgentCapabilities(session=SessionCapabilities()), + ) + + async def new_session(self, cwd: str, **kwargs: Any) -> NewSessionResponse: + session_id = uuid4().hex + self._sessions[session_id] = SessionInfo(session_id=session_id, cwd=cwd, title="Echo") + self._history[session_id] = [] + return NewSessionResponse(session_id=session_id) + + async def list_sessions( + self, cwd: str | None = None, cursor: str | None = None, **kwargs: Any + ) -> ListSessionsResponse: + if cursor is not None: + raise RequestError.invalid_params({"details": "unknown session list cursor"}) + return ListSessionsResponse(sessions=[s for s in self._sessions.values() if cwd is None or s.cwd == cwd]) + + def _session(self, session_id: str) -> SessionInfo: + if session_id not in self._sessions: + error = RequestError.resource_not_found() + error.data = {"sessionId": session_id} + raise error + return self._sessions[session_id] + + async def resume_session( + self, + session_id: str, + cwd: str, + replay_from: ReplayFromStartVariant | OtherReplayFrom | None = None, + **kwargs: Any, + ) -> ResumeSessionResponse: + session = self._session(session_id) + if isinstance(replay_from, OtherReplayFrom): + raise RequestError.invalid_params({"details": "unsupported replay cursor"}) + assert self._client is not None + if isinstance(replay_from, ReplayFromStartVariant): + for message in self._history[session_id]: + await self._client.session_update(session_id=session_id, update=message) + await self._client.session_update(session_id=session_id, update=SessionInfoUpdate(title=session.title)) + update = RunningSessionStateUpdate() if session_id in self._cancel_events else IdleSessionStateUpdate() + await self._client.session_update(session_id=session_id, update=update) + return ResumeSessionResponse() + + async def close_session(self, session_id: str, **kwargs: Any) -> CloseSessionResponse: + self._sessions.pop(session_id, None) + await self.cancel_session(session_id) + if turn := self._turns.get(session_id): + await turn + self._history.pop(session_id, None) + return CloseSessionResponse() + + async def prompt(self, session_id: str, prompt: list[ContentBlock], **kwargs: Any) -> PromptResponse: + while turn := self._turns.get(session_id): + await asyncio.shield(turn) + self._session(session_id) + message_id = uuid4().hex + event = asyncio.Event() + self._cancel_events[session_id] = event + self._turns[session_id] = asyncio.create_task(self._run_turn(session_id, message_id, prompt, event)) + return PromptResponse(message_id=message_id) + + async def cancel_session(self, session_id: str, **kwargs: Any) -> None: + if event := self._cancel_events.get(session_id): + event.set() + + async def _run_turn( + self, session_id: str, message_id: str, prompt: list[ContentBlock], event: asyncio.Event + ) -> None: + assert self._client is not None + history = self._history[session_id] + try: + message = UserMessageUpdate(message_id=message_id, content=prompt) + history.append(message) + await self._client.session_update(session_id=session_id, update=message) + await self._client.session_update(session_id=session_id, update=RunningSessionStateUpdate()) + + texts = [block.text for block in prompt if isinstance(block, TextContentBlock)] + if texts == [CANCEL_PROMPT]: + with contextlib.suppress(asyncio.TimeoutError): + await asyncio.wait_for(event.wait(), timeout=_CANCEL_FALLBACK_SECONDS) + elif texts: + reply_id = uuid4().hex + for text in texts: + await self._client.session_update( + session_id=session_id, + update=AgentMessageChunk(message_id=reply_id, content=TextContentBlock(text=text)), + ) + history.append(AgentMessageUpdate(message_id=reply_id, content=[TextContentBlock(text="".join(texts))])) + await self._client.session_update( + session_id=session_id, + update=IdleSessionStateUpdate(stop_reason="cancelled" if event.is_set() else "end_turn"), + ) + finally: + self._cancel_events.pop(session_id, None) + self._turns.pop(session_id, None) + + +async def main() -> None: + await run_agent(ProbeAgent()) + + +if __name__ == "__main__": + asyncio.run(main())