Skip to content

Commit 7c169fa

Browse files
committed
Test allowed_operations
1 parent 460c6d2 commit 7c169fa

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/test_openapi_client_edge_cases.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,52 @@ def test_servers_order(self, test_files_path):
5353
assert op.get_server() == "https://inoperation.example.com"
5454
op = config.openapi_spec.find_operation_by_id("missing_operation_id_get")
5555
assert op.get_server() == "http://localhost"
56+
57+
def test_allowed_operations(self):
58+
"""
59+
Although the tool definition is generated from the OpenAPI spec and
60+
firecrawl's API has multiple operations, only the ones we specify in the
61+
allowed_operations list are registered with LLMs via the tool definition.
62+
"""
63+
64+
spec="https://raw.githubusercontent.com/mendableai/firecrawl/main/apps/api/openapi.json"
65+
66+
config = ClientConfig(
67+
openapi_spec=create_openapi_spec(spec),
68+
request_sender=FastAPITestClient(None),
69+
allowed_operations=["scrape"],
70+
)
71+
tools = config.get_tool_definitions()
72+
assert len(tools) == 1
73+
assert tools[0]["function"]["name"] == "scrape"
74+
75+
# test two operations
76+
config = ClientConfig(
77+
openapi_spec=create_openapi_spec(spec),
78+
request_sender=FastAPITestClient(None),
79+
allowed_operations=["scrape", "crawlUrls"],
80+
)
81+
tools = config.get_tool_definitions()
82+
assert len(tools) == 2
83+
assert tools[0]["function"]["name"] == "scrape"
84+
assert tools[1]["function"]["name"] == "crawlUrls"
85+
86+
# test non-existent operation
87+
config = ClientConfig(
88+
openapi_spec=create_openapi_spec(spec),
89+
request_sender=FastAPITestClient(None),
90+
allowed_operations=["scrape", "non-existent-operation"],
91+
)
92+
tools = config.get_tool_definitions()
93+
assert len(tools) == 1
94+
assert tools[0]["function"]["name"] == "scrape"
95+
96+
# test all non-existent operations
97+
config = ClientConfig(
98+
openapi_spec=create_openapi_spec(spec),
99+
request_sender=FastAPITestClient(None),
100+
allowed_operations=["non-existent-operation", "non-existent-operation-2"],
101+
)
102+
tools = config.get_tool_definitions()
103+
assert len(tools) == 0
56104

0 commit comments

Comments
 (0)