Skip to content

Commit b53dd03

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

6 files changed

Lines changed: 104 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ jobs:
4646
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae
4747
with:
4848
path: .pytest_cache
49-
key: pytest-cache-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.ref_name }}-${{ github.sha }}
49+
key: pytest-cache-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.ref_name }}-${{
50+
github.sha }}
5051
restore-keys: |
5152
pytest-cache-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.ref_name }}-
5253
- name: Run unit tests
5354
run: make test-unit
5455
- name: Run entire test suite
55-
run: make test-integration
56+
# run: make test-integration
57+
run: uv run pytest
58+
./tests/system/test_ai_agentic_test_app.py::TestAgenticApp::test_remote_tools_have_tags

tests/system/__init__.py

Whitespace-only changes.

tests/system/test_ai_agentic_test_app.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,33 @@ def test_agentic_app_with_remote_tools(self) -> None:
107107
app.delete()
108108
self.restart_splunk() # app removal requires a restart
109109

110+
def test_remote_tools_have_tags(self) -> None:
111+
pytest.importorskip("langchain_openai")
112+
self.requires_splunk_10_2()
113+
114+
# Skip test in case the instance does not have a /splunk-mcp-server.tgz file.
115+
try:
116+
resp = self.service.get("agentic_app/has_mcp_app_file")
117+
assert resp.status == 200
118+
except HTTPError as e:
119+
if e.status == 404:
120+
pytest.skip("Splunk MCP Server App file not found on Splunk instance")
121+
raise
122+
123+
app = self.service.apps.create(name="/splunk-mcp-server.tgz", filename=True) # pyright: ignore[reportUnknownVariableType]
124+
125+
resp = self.service.post(
126+
"agentic_app/tags",
127+
body=self.test_llm_settings.model_dump_json(),
128+
)
129+
130+
assert resp.status == 200
131+
body = str(resp.body) # pyright: ignore[reportUnknownArgumentType]
132+
assert "tags" in body
133+
134+
app.delete()
135+
self.restart_splunk() # app removal requires a restart
136+
110137
def requires_splunk_10_2(self) -> None:
111138
if self.service.splunk_version[0] < 10 or self.service.splunk_version[1] < 2:
112139
pytest.skip("Python 3.13 not available on splunk < 10.2")

tests/system/test_apps/ai_agentic_test_app/bin/indexes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
import os
1616
import sys
17+
from typing import override
1718

1819
sys.path.insert(0, "/splunklib-deps")
1920
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "lib"))
2021

21-
from typing import override
22-
2322
from pydantic import BaseModel, Field
2423

2524
from splunklib.ai.agent import Agent
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 typing import override
19+
20+
sys.path.insert(0, "/splunklib-deps")
21+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "lib"))
22+
23+
24+
from splunklib.ai.agent import Agent
25+
from splunklib.ai.tool_settings import RemoteToolSettings, ToolAllowlist, ToolSettings
26+
from tests.cre_testlib import CRETestHandler
27+
28+
# BUG: For some reason the CRE process is started with a overridden trust store path, that
29+
# does not exist on the filesystem. As a workaround in such case if it does not exist,
30+
# remove the env, this causes the default CAs to be used instead.
31+
CA_TRUST_STORE = "/opt/splunk/openssl/cert.pem"
32+
if os.environ.get("SSL_CERT_FILE") == CA_TRUST_STORE and not os.path.exists(
33+
CA_TRUST_STORE
34+
):
35+
os.environ["SSL_CERT_FILE"] = ""
36+
37+
# This app uses the splunk_get_indexes remote tool (from Splunk MCP Server App).
38+
# Requires that the MCP Server App is installed.
39+
40+
41+
class ToolTagsHandler(CRETestHandler):
42+
@override
43+
async def run(self) -> None:
44+
async with Agent(
45+
model=await self.model(),
46+
system_prompt="You are a helpful Splunk assistant",
47+
tool_settings=ToolSettings(
48+
local=False,
49+
remote=RemoteToolSettings(
50+
allowlist=ToolAllowlist(names=["splunk_get_indexes"])
51+
),
52+
),
53+
service=self.service,
54+
) as agent:
55+
assert len(agent.tools) > 0, "No remote tools loaded"
56+
57+
assert len([t for t in agent.tools if len(t.tags) > 0]) > 0, (
58+
f"No tools have tags. Tools: {[t.name for t in agent.tools]}"
59+
)
60+
61+
self.response.write(
62+
json.dumps(
63+
{"tools": [{"name": t.name, "tags": t.tags} for t in agent.tools]}
64+
)
65+
)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ match = /agentic_app/has_mcp_app_file
1515
scripttype = python
1616
handler = mcp_app_file_exists.Handler
1717
python.required = 3.13
18+
19+
[script:tool_tags]
20+
match = /agentic_app/tags
21+
scripttype = python
22+
handler = tags.ToolTagsHandler
23+
python.required = 3.13

0 commit comments

Comments
 (0)