Skip to content

Commit 6a6d779

Browse files
committed
Add test for checking if tags exist
1 parent b53dd03 commit 6a6d779

4 files changed

Lines changed: 85 additions & 2 deletions

File tree

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ markers =
55

66
junit_family =
77
xunit2
8+
9+
log_cli = true
10+
log_cli_level = INFO

tests/system/test_ai_agentic_test_app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
# under the License.
1414

1515

16+
import logging
17+
1618
import pytest
1719

1820
from splunklib.binding import HTTPError
1921
from tests.ai_testlib import AITestCase
2022

23+
logger = logging.getLogger(__name__)
24+
2125

2226
class TestAgenticApp(AITestCase):
2327
def test_agentic_app(self) -> None:
@@ -129,6 +133,7 @@ def test_remote_tools_have_tags(self) -> None:
129133

130134
assert resp.status == 200
131135
body = str(resp.body) # pyright: ignore[reportUnknownArgumentType]
136+
logger.info("tool-tags response: %s", body)
132137
assert "tags" in body
133138

134139
app.delete()
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright © 2011-2026 Splunk, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import json
16+
import os
17+
import sys
18+
from uuid import uuid4
19+
20+
sys.path.insert(0, "/splunklib-deps")
21+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "lib"))
22+
23+
from typing import override
24+
25+
from splunklib.ai.agent import (
26+
_get_splunk_username, # pyright: ignore[reportPrivateUsage]
27+
)
28+
from splunklib.ai.tools import (
29+
_list_all_tools, # pyright: ignore[reportPrivateUsage]
30+
connect_remote_mcp,
31+
)
32+
from tests.cre_testlib import CRETestHandler
33+
34+
# BUG: For some reason the CRE process is started with a overridden trust store path, that
35+
# does not exist on the filesystem. As a workaround in such case if it does not exist,
36+
# remove the env, this causes the default CAs to be used instead.
37+
CA_TRUST_STORE = "/opt/splunk/openssl/cert.pem"
38+
if os.environ.get("SSL_CERT_FILE") == CA_TRUST_STORE and not os.path.exists(
39+
CA_TRUST_STORE
40+
):
41+
os.environ["SSL_CERT_FILE"] = ""
42+
43+
# This handler connects directly to the Splunk MCP Server App and logs the raw
44+
# MCP tool list response, verifying that tool metadata includes tags.
45+
46+
47+
class ToolTagsHandler(CRETestHandler):
48+
@override
49+
async def run(self) -> None:
50+
import asyncio
51+
52+
splunk_username = await asyncio.to_thread(
53+
lambda: _get_splunk_username(self.service)
54+
)
55+
56+
async with connect_remote_mcp(
57+
service=self.service,
58+
app_id="ai_agentic_test_app",
59+
trace_id=str(uuid4()),
60+
splunk_username=splunk_username,
61+
) as session:
62+
assert session is not None, "MCP Server App not available"
63+
64+
raw_tools = await _list_all_tools(session)
65+
66+
assert len(raw_tools) > 0, "No tools returned by MCP Server App"
67+
68+
tools_with_tags = [
69+
t for t in raw_tools if ((t.meta or {}).get("splunk") or {}).get("tags")
70+
]
71+
assert len(tools_with_tags) > 0, (
72+
f"No tools have tags. Raw tools: {json.dumps([t.model_dump() for t in raw_tools], indent=2)}"
73+
)
74+
75+
self.response.write(json.dumps([t.model_dump() for t in raw_tools], indent=2))

tests/system/test_apps/ai_agentic_test_app/default/restmap.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ handler = mcp_app_file_exists.Handler
1717
python.required = 3.13
1818

1919
[script:tool_tags]
20-
match = /agentic_app/tags
20+
match = /agentic_app/tool-tags
2121
scripttype = python
22-
handler = tags.ToolTagsHandler
22+
handler = tool_tags.ToolTagsHandler
2323
python.required = 3.13

0 commit comments

Comments
 (0)