Skip to content

tests(toolbox-code): add e2e tests #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5f1b2b0
feat: add authenticated parameters support
kurtisvg Mar 30, 2025
34bec37
chore: add asyncio dep
kurtisvg Mar 30, 2025
f0024bf
chore: run itest
kurtisvg Mar 30, 2025
a646285
chore: add type hint
kurtisvg Mar 30, 2025
0dc7034
fix: call tool instead of client
kurtisvg Mar 30, 2025
61d32aa
chore: correct arg name
kurtisvg Mar 31, 2025
744ade9
feat: add support for bound parameters
kurtisvg Mar 31, 2025
b875771
chore: add tests for bound parameters
kurtisvg Mar 31, 2025
138d8d9
docs: update syntax error on readme (#121)
Yuan325 Mar 31, 2025
e2f5b4d
ci: added release please config (#112)
twishabansal Apr 1, 2025
280a79f
added basic e2e tests
twishabansal Apr 1, 2025
63808ce
change license year
twishabansal Apr 1, 2025
55f5ca0
add test deps
twishabansal Apr 1, 2025
ed16488
fix tests
twishabansal Apr 1, 2025
f0991ab
fix tests
twishabansal Apr 1, 2025
cc6d568
fix tests
twishabansal Apr 1, 2025
1f63b0d
add new test case
twishabansal Apr 1, 2025
66e88ab
fix docstring
twishabansal Apr 1, 2025
1fa1b7a
added todo
twishabansal Apr 1, 2025
12af5fa
cleanup
twishabansal Apr 1, 2025
9c3ba38
add bind param test case
twishabansal Apr 1, 2025
d75828e
make bind params dynamic
twishabansal Apr 1, 2025
fef1f7f
try fix test errors
twishabansal Apr 1, 2025
cd701b7
lint
twishabansal Apr 1, 2025
7a5a1bd
remove redundant test
twishabansal Apr 1, 2025
e343e78
test fix
twishabansal Apr 1, 2025
11d62b4
fix docstring
twishabansal Apr 1, 2025
87e00cc
feat: add authenticated parameters support
kurtisvg Mar 30, 2025
6b263ad
chore: add asyncio dep
kurtisvg Mar 30, 2025
5fe541f
chore: run itest
kurtisvg Mar 30, 2025
e9d7a31
chore: add type hint
kurtisvg Mar 30, 2025
58c55cf
fix: call tool instead of client
kurtisvg Mar 30, 2025
c1a482a
chore: correct arg name
kurtisvg Mar 31, 2025
c1ac2cd
chore: address feedback
kurtisvg Apr 2, 2025
bcba462
chore: address more feedback
kurtisvg Apr 2, 2025
c8491a9
feat: add support for bound parameters
kurtisvg Mar 31, 2025
c26c453
chore: add tests for bound parameters
kurtisvg Mar 31, 2025
3abe9e4
chore: address feedback
kurtisvg Apr 2, 2025
3200f00
Merge branch 'kvg-bound-params' into twisha-core-e2e
twishabansal Apr 2, 2025
9482f37
revert package file changes
twishabansal Apr 2, 2025
6dca7f9
fix error message
twishabansal Apr 2, 2025
4d562bd
revert package files
twishabansal Apr 2, 2025
cc7ccad
lint
twishabansal Apr 2, 2025
84e66a6
fix error message
twishabansal Apr 2, 2025
fe2a332
Update packages/toolbox-core/tests/test_e2e.py
twishabansal Apr 2, 2025
b05ea39
add new test case
twishabansal Apr 2, 2025
7d3b77a
change docstring to reflect new test cases
twishabansal Apr 2, 2025
16e38e9
Merge branch 'main' into twisha-core-e2e
twishabansal Apr 3, 2025
755d3e9
clean up docstring
twishabansal Apr 3, 2025
738b984
lint
twishabansal Apr 3, 2025
7683063
Move tests to different classes
twishabansal Apr 3, 2025
1ab6ae7
Merge branch 'main' into twisha-core-e2e
twishabansal Apr 3, 2025
49203ac
add timeout
twishabansal Apr 3, 2025
2f758ca
Merge remote-tracking branch 'origin/twisha-core-e2e' into twisha-cor…
twishabansal Apr 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/toolbox-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ test = [
"isort==6.0.1",
"mypy==1.15.0",
"pytest==8.3.5",
"pytest-aioresponses==0.3.0"
"pytest-aioresponses==0.3.0",
"pytest-asyncio==0.25.3",
"google-cloud-secret-manager==2.23.2",
"google-cloud-storage==3.1.0",
]
[build-system]
requires = ["setuptools"]
Expand Down
64 changes: 57 additions & 7 deletions packages/toolbox-core/src/toolbox_core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional
import re
import types
from typing import Any, Callable, Mapping, Optional, Union

from aiohttp import ClientSession

from .protocol import ManifestSchema, ToolSchema
from .tool import ToolboxTool
from .tool import ToolboxTool, identify_required_authn_params


class ToolboxClient:
Expand Down Expand Up @@ -53,14 +54,42 @@ def __init__(
session = ClientSession()
self.__session = session

def __parse_tool(self, name: str, schema: ToolSchema) -> ToolboxTool:
def __parse_tool(
self,
name: str,
schema: ToolSchema,
auth_token_getters: dict[str, Callable[[], str]],
all_bound_params: Mapping[str, Union[Callable[[], Any], Any]],
) -> ToolboxTool:
"""Internal helper to create a callable tool from its schema."""
# sort into reg, authn, and bound params
params = []
authn_params: dict[str, list[str]] = {}
bound_params: dict[str, Callable[[], str]] = {}
auth_sources: set[str] = set()
for p in schema.parameters:
if p.authSources: # authn parameter
authn_params[p.name] = p.authSources
auth_sources.update(p.authSources)
elif p.name in all_bound_params: # bound parameter
bound_params[p.name] = all_bound_params[p.name]
else: # regular parameter
params.append(p)

authn_params = identify_required_authn_params(
authn_params, auth_token_getters.keys()
)

tool = ToolboxTool(
session=self.__session,
base_url=self.__base_url,
name=name,
desc=schema.description,
params=[p.to_param() for p in schema.parameters],
params=[p.to_param() for p in params],
# create a read-only values for the maps to prevent mutation
required_authn_params=types.MappingProxyType(authn_params),
auth_service_token_getters=types.MappingProxyType(auth_token_getters),
bound_params=types.MappingProxyType(bound_params),
)
return tool

Expand Down Expand Up @@ -99,6 +128,8 @@ async def close(self):
async def load_tool(
self,
name: str,
auth_token_getters: dict[str, Callable[[], str]] = {},
bound_params: Mapping[str, Union[Callable[[], Any], Any]] = {},
) -> ToolboxTool:
"""
Asynchronously loads a tool from the server.
Expand All @@ -109,6 +140,12 @@ async def load_tool(

Args:
name: The unique name or identifier of the tool to load.
auth_token_getters: A mapping of authentication service names to
callables that return the corresponding authentication token.
bound_params: A mapping of parameter names to bind to specific values or
callables that are called to produce values as needed.



Returns:
ToolboxTool: A callable object representing the loaded tool, ready
Expand All @@ -127,19 +164,29 @@ async def load_tool(
if name not in manifest.tools:
# TODO: Better exception
raise Exception(f"Tool '{name}' not found!")
tool = self.__parse_tool(name, manifest.tools[name])
tool = self.__parse_tool(
name, manifest.tools[name], auth_token_getters, bound_params
)

return tool

async def load_toolset(
self,
name: str,
auth_token_getters: dict[str, Callable[[], str]] = {},
bound_params: Mapping[str, Union[Callable[[], Any], Any]] = {},
) -> list[ToolboxTool]:
"""
Asynchronously fetches a toolset and loads all tools defined within it.

Args:
name: Name of the toolset to load tools.
auth_token_getters: A mapping of authentication service names to
callables that return the corresponding authentication token.
bound_params: A mapping of parameter names to bind to specific values or
callables that are called to produce values as needed.



Returns:
list[ToolboxTool]: A list of callables, one for each tool defined
Expand All @@ -152,5 +199,8 @@ async def load_toolset(
manifest: ManifestSchema = ManifestSchema(**json)

# parse each tools name and schema into a list of ToolboxTools
tools = [self.__parse_tool(n, s) for n, s in manifest.tools.items()]
tools = [
self.__parse_tool(n, s, auth_token_getters, bound_params)
for n, s in manifest.tools.items()
]
return tools
Loading