Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(adk): wait for listeners before asserting on them, and skip the ADKs job when nothing it builds from changed (#9428)

James Damd4836aec8fbb
diff --git a/.github/workflows/rust-check.yml b/.github/workflows/rust-check.yml
index f8205990e..6ff0899a0 100644
--- a/.github/workflows/rust-check.yml
+++ b/.github/workflows/rust-check.yml
@@ -259,8 +259,33 @@ jobs:
# runtime binary, and a client that only agreed with itself would pass. The
# committed wire types are checked against protocol/rpc-schema.json in the
# same job, since that document is what generates them.
+ adk-changes:
+ name: ADK paths
+ runs-on: ubuntu-latest
+ outputs:
+ run: ${{ steps.filter.outputs.run }}
+ steps:
+ # A PR that touches nothing the ADKs build from skips the job's ~5 minute
+ # runtime build. Pushes, dispatches and an unreadable file list run it.
+ - id: filter
+ env:
+ GH_TOKEN: ${{ github.token }}
+ PR: ${{ github.event.pull_request.number }}
+ run: |
+ if [ -z "$PR" ] || ! files=$(gh pr diff "$PR" --repo "$GITHUB_REPOSITORY" --name-only); then
+ echo "run=true" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+ if grep -qE '^(src-tauri/|adk/|packages/adk/|protocol/|package\.json$|yarn\.lock$|\.github/workflows/rust-check\.yml$)' <<< "$files"; then
+ echo "run=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "run=false" >> "$GITHUB_OUTPUT"
+ fi
+
adk:
name: ADKs
+ needs: adk-changes
+ if: needs.adk-changes.outputs.run == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
diff --git a/adk/python/tests/harness.py b/adk/python/tests/harness.py
index 78be3e6f4..291f884f9 100644
--- a/adk/python/tests/harness.py
+++ b/adk/python/tests/harness.py
@@ -248,6 +248,19 @@ def holding(text: str) -> Callable[[_Handler], None]:
return write
+def settle(runtime: Any, timeout: float = 10) -> None:
+ """Return once every listener event queued so far has been delivered.
+
+ Listeners run on the runtime's dispatch thread, not the one iterating a
+ turn, so a turn can finish while its last events are still queued for them.
+ The queue drains in order, so a marker put behind them runs after they do.
+ """
+ done = threading.Event()
+ runtime._notify(lambda _payload: done.set(), None)
+ if not done.wait(timeout):
+ raise AssertionError(f"listeners still busy after {timeout}s")
+
+
class Scratch:
"""A private home and project, removed by :meth:`cleanup`."""
diff --git a/adk/python/tests/test_adk.py b/adk/python/tests/test_adk.py
index 66c4a8c36..d17526145 100644
--- a/adk/python/tests/test_adk.py
+++ b/adk/python/tests/test_adk.py
@@ -24,7 +24,7 @@ from typing import Any, Dict, List
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from jan_adk import PROTOCOL_VERSION, HostTool, JanRpcError, JanRuntime, JanRuntimeError # noqa: E402
-from tests.harness import Provider, Scratch, holding, prose, streamed, tool_call # noqa: E402
+from tests.harness import Provider, Scratch, holding, prose, settle, streamed, tool_call # noqa: E402
BIN = os.environ.get("JAN_BIN")
@@ -101,6 +101,7 @@ class AdkTest(unittest.TestCase):
self.assertTrue(any(e["type"] == "step" for e in events))
# The session hears what the turn hears, so a host can observe a run
# it is not the one iterating.
+ settle(runtime)
self.assertIn("token", seen)
self.assertEqual(session.get_tools()["tools"], [])
@@ -269,6 +270,7 @@ class AdkTest(unittest.TestCase):
turn = session.prompt("what is on the desk?")
list(turn)
self.assertEqual(turn.result().stop_reason, "completed")
+ settle(runtime)
# The host is told the name it declared, not the `host__` name the
# model calls, and a read never asks permission.