@@ -92,145 +92,141 @@ run_run_all() {
9292 timeout 3s bash ./run-all.sh
9393}
9494
95+ run_mcp_case () {
96+ local tempo_enabled=$1
97+ local sa_mode=$2
98+ local version=${3:- latest}
99+ if [[ " $tempo_enabled " == " true" ]]; then
100+ export TEMPO_EXTRA_ARGS=" --query-frontend.mcp-server.enabled=true"
101+ else
102+ unset TEMPO_EXTRA_ARGS
103+ fi
104+ export STUB_SA_MODE=" $sa_mode "
105+ run run_run_all " $version "
106+ }
107+
108+ assert_contains () {
109+ local needle=$1
110+ [[ " $output " == * " $needle " * ]]
111+ }
112+
113+ assert_not_contains () {
114+ local needle=$1
115+ [[ " $output " != * " $needle " * ]]
116+ }
117+
118+ assert_has_file () {
119+ [ -f " $1 " ]
120+ }
121+
122+ assert_no_file () {
123+ [ ! -f " $1 " ]
124+ }
125+
126+ assert_file_contains () {
127+ grep -Fq " $2 " " $1 "
128+ }
129+
130+ assert_file_not_contains () {
131+ ! grep -Fq " $2 " " $1 "
132+ }
133+
95134@test " docs URL uses main for latest" {
96135 local expected=" https://github.com/grafana/docker-otel-lgtm/blob/main/docs/mcp-integration.md"
97- local expected_line=" Docs: $expected "
98136 run run_run_all latest
99- [[ " $output " == * " $expected_line " * ]]
100- [[ " $output " != * " /blob/vlatest/" * ]]
137+ assert_contains " Docs: $expected "
138+ assert_not_contains " /blob/vlatest/"
101139}
102140
103141@test " docs URL uses main when version is empty" {
104142 local expected=" https://github.com/grafana/docker-otel-lgtm/blob/main/docs/mcp-integration.md"
105- local expected_line=" Docs: $expected "
106143 run run_run_all " "
107- [[ " $output " == * " $expected_line " * ]]
144+ assert_contains " Docs: $expected "
108145}
109146
110147@test " docs URL uses main for main tag" {
111148 local expected=" https://github.com/grafana/docker-otel-lgtm/blob/main/docs/mcp-integration.md"
112- local expected_line=" Docs: $expected "
113149 run run_run_all main
114- [[ " $output " == * " $expected_line " * ]]
115- [[ " $output " != * " /blob/vmain/" * ]]
150+ assert_contains " Docs: $expected "
151+ assert_not_contains " /blob/vmain/"
116152}
117153
118154@test " printed MCP commands escape configurable paths" {
119155 local configdir=" $TESTDIR /etc/lgtm with spaces"
120156 local escaped_configdir=${configdir// / \\ }
121157 CONFIGDIR=" $configdir " run run_run_all latest
122- [[ " $output " == * " bash <(docker exec lgtm cat ${escaped_configdir} /claude-mcp-setup.sh)" * ]]
123- [[ " $output " == * " docker exec lgtm cat ${escaped_configdir} /mcp.json" * ]]
158+ assert_contains " bash <(docker exec lgtm cat ${escaped_configdir} /claude-mcp-setup.sh)"
159+ assert_contains " docker exec lgtm cat ${escaped_configdir} /mcp.json"
124160}
125161
126162@test " docs URL prefixes bare release version with v" {
127163 local expected
128164 expected=" https://github.com/grafana/docker-otel-lgtm/blob/v1.2.3-test/docs/mcp-integration.md"
129- local expected_line=" Docs: $expected "
130165 run run_run_all 1.2.3-test
131- [[ " $output " == * " $expected_line " * ]]
166+ assert_contains " Docs: $expected "
132167}
133168
134169@test " docs URL does not double-prefix version that already starts with v" {
135170 local expected
136171 expected=" https://github.com/grafana/docker-otel-lgtm/blob/v1.2.3-test/docs/mcp-integration.md"
137- local expected_line=" Docs: $expected "
138172 run run_run_all v1.2.3-test
139- [[ " $output " == * " $expected_line " * ]]
140- [[ " $output " != * " /blob/vv1.2.3-test/" * ]]
173+ assert_contains " Docs: $expected "
174+ assert_not_contains " /blob/vv1.2.3-test/"
141175}
142176
143- @test " MCP bootstrap writes helper artifacts with expected contents" {
144- export TEMPO_EXTRA_ARGS=" --query-frontend.mcp-server.enabled=true"
145- export STUB_SA_MODE=success
146-
147- run run_run_all latest
148- [ -f " $CONFIGDIR /mcp.json" ]
149- [ -f " $CONFIGDIR /claude-mcp-setup.sh" ]
150- [ -f " $TOKENFILE " ]
151-
152- grep -Fq \
153- ' "GRAFANA_URL": "http://localhost:3000"' \
154- " $CONFIGDIR /mcp.json"
155- grep -Fq \
156- ' "GRAFANA_SERVICE_ACCOUNT_TOKEN": "token123"' \
157- " $CONFIGDIR /mcp.json"
158- grep -Fq ' "url": "http://localhost:3200/api/mcp"' " $CONFIGDIR /mcp.json"
159-
160- grep -Fq \
161- ' claude mcp add grafana -e "GRAFANA_URL=http://localhost:3000"' \
162- " $CONFIGDIR /claude-mcp-setup.sh"
163- grep -Fq ' GRAFANA_SERVICE_ACCOUNT_TOKEN=token123' " $CONFIGDIR /claude-mcp-setup.sh"
164- grep -Fq \
165- ' claude mcp add --transport http tempo "http://localhost:3200/api/mcp"' \
166- " $CONFIGDIR /claude-mcp-setup.sh"
167-
168- grep -Fqx ' token123' " $TOKENFILE "
177+ @test " tempo enabled with service account writes both MCP servers" {
178+ run_mcp_case true success latest
179+ assert_contains " Tempo MCP: server enabled at http://localhost:3200/api/mcp"
180+ assert_contains " Grafana MCP: server enabled with service account token"
181+ assert_contains " - 3200: Tempo endpoint (MCP at http://localhost:3200/api/mcp)"
182+ assert_has_file " $CONFIGDIR /mcp.json"
183+ assert_has_file " $CONFIGDIR /claude-mcp-setup.sh"
184+ assert_has_file " $TOKENFILE "
185+ assert_file_contains " $CONFIGDIR /mcp.json" ' "grafana"'
186+ assert_file_contains " $CONFIGDIR /mcp.json" ' "tempo"'
187+ assert_file_contains " $CONFIGDIR /mcp.json" ' GRAFANA_SERVICE_ACCOUNT_TOKEN": "token123"'
188+ assert_file_contains " $CONFIGDIR /claude-mcp-setup.sh" ' claude mcp add grafana'
189+ assert_file_contains " $CONFIGDIR /claude-mcp-setup.sh" ' claude mcp add --transport http tempo'
190+ assert_file_contains " $TOKENFILE " ' token123'
169191}
170192
171- @test " enabled tempo with service account writes both MCP servers" {
172- export TEMPO_EXTRA_ARGS=" --query-frontend.mcp-server.enabled=true"
173- export STUB_SA_MODE=success
174-
175- run run_run_all latest
176- [[ " $output " == * " Tempo MCP: server enabled at http://localhost:3200/api/mcp" * ]]
177- [[ " $output " == * " Grafana MCP: server enabled with service account token" * ]]
178- [[ " $output " == * " - 3200: Tempo endpoint (MCP at http://localhost:3200/api/mcp)" * ]]
179-
180- grep -Fq ' "grafana"' " $CONFIGDIR /mcp.json"
181- grep -Fq ' "tempo"' " $CONFIGDIR /mcp.json"
182- grep -Fq ' GRAFANA_SERVICE_ACCOUNT_TOKEN": "token123"' " $CONFIGDIR /mcp.json"
183- grep -Fq ' claude mcp add grafana' " $CONFIGDIR /claude-mcp-setup.sh"
184- grep -Fq \
185- ' claude mcp add --transport http tempo "http://localhost:3200/api/mcp"' \
186- " $CONFIGDIR /claude-mcp-setup.sh"
187- grep -Fqx ' token123' " $TOKENFILE "
193+ @test " tempo disabled with service account writes grafana-only MCP config" {
194+ run_mcp_case false success latest
195+ assert_contains " Tempo MCP: server disabled; enable with"
196+ assert_contains " TEMPO_EXTRA_ARGS=--query-frontend.mcp-server.enabled=true"
197+ assert_contains " Grafana MCP: server enabled with service account token"
198+ assert_contains " - 3200: Tempo endpoint"
199+ assert_not_contains " - 3200: Tempo endpoint (MCP at http://localhost:3200/api/mcp)"
200+ assert_has_file " $CONFIGDIR /mcp.json"
201+ assert_has_file " $CONFIGDIR /claude-mcp-setup.sh"
202+ assert_has_file " $TOKENFILE "
203+ assert_file_contains " $CONFIGDIR /mcp.json" ' "grafana"'
204+ assert_file_not_contains " $CONFIGDIR /mcp.json" ' "tempo"'
205+ assert_file_contains " $CONFIGDIR /claude-mcp-setup.sh" ' claude mcp add grafana'
206+ assert_file_not_contains " $CONFIGDIR /claude-mcp-setup.sh" ' claude mcp add --transport http tempo'
188207}
189208
190- @test " disabled tempo with service account writes grafana-only MCP config" {
191- unset TEMPO_EXTRA_ARGS
192- export STUB_SA_MODE=success
193-
194- run run_run_all latest
195- [[ " $output " == * " Tempo MCP: server disabled;" * ]]
196- [[ " $output " == * " TEMPO_EXTRA_ARGS=--query-frontend.mcp-server.enabled=true" * ]]
197- [[ " $output " == * " Grafana MCP: server enabled with service account token" * ]]
198- [[ " $output " == * " - 3200: Tempo endpoint" * ]]
199- [[ " $output " != * " - 3200: Tempo endpoint (MCP at http://localhost:3200/api/mcp)" * ]]
200-
201- grep -Fq ' "grafana"' " $CONFIGDIR /mcp.json"
202- run ! grep -Fq ' "tempo"' " $CONFIGDIR /mcp.json"
203- grep -Fq ' claude mcp add grafana' " $CONFIGDIR /claude-mcp-setup.sh"
204- run ! grep -Fq ' claude mcp add --transport http tempo' " $CONFIGDIR /claude-mcp-setup.sh"
209+ @test " tempo enabled without service account writes tempo-only MCP config" {
210+ run_mcp_case true missing latest
211+ assert_contains " Tempo MCP: server enabled at http://localhost:3200/api/mcp"
212+ assert_contains " Grafana MCP: server unavailable; could not create service account token"
213+ assert_has_file " $CONFIGDIR /mcp.json"
214+ assert_has_file " $CONFIGDIR /claude-mcp-setup.sh"
215+ assert_no_file " $TOKENFILE "
216+ assert_file_not_contains " $CONFIGDIR /mcp.json" ' "grafana"'
217+ assert_file_contains " $CONFIGDIR /mcp.json" ' "tempo"'
218+ assert_file_not_contains " $CONFIGDIR /claude-mcp-setup.sh" ' claude mcp add grafana'
219+ assert_file_contains " $CONFIGDIR /claude-mcp-setup.sh" ' claude mcp add --transport http tempo'
205220}
206221
207- @test " enabled tempo without service account writes tempo-only MCP config" {
208- export TEMPO_EXTRA_ARGS=" --query-frontend.mcp-server.enabled=true"
209- export STUB_SA_MODE=missing
210-
211- run run_run_all latest
212- [[ " $output " == * " Tempo MCP: server enabled at http://localhost:3200/api/mcp" * ]]
213- [[ " $output " == * " Grafana MCP: server unavailable; could not create service account token" * ]]
214-
215- run ! grep -Fq ' "grafana"' " $CONFIGDIR /mcp.json"
216- grep -Fq ' "tempo"' " $CONFIGDIR /mcp.json"
217- run ! grep -Fq ' claude mcp add grafana' " $CONFIGDIR /claude-mcp-setup.sh"
218- grep -Fq \
219- ' claude mcp add --transport http tempo "http://localhost:3200/api/mcp"' \
220- " $CONFIGDIR /claude-mcp-setup.sh"
221- [ ! -f " $TOKENFILE " ]
222- }
223-
224- @test " disabled tempo without service account writes empty MCP config" {
225- unset TEMPO_EXTRA_ARGS
226- export STUB_SA_MODE=missing
227-
228- run run_run_all latest
229- [[ " $output " == * " Tempo MCP: server disabled;" * ]]
230- [[ " $output " == * " TEMPO_EXTRA_ARGS=--query-frontend.mcp-server.enabled=true" * ]]
231- [[ " $output " == * " Grafana MCP: server unavailable; could not create service account token" * ]]
232-
233- grep -Fq ' "mcpServers": {}' " $CONFIGDIR /mcp.json"
234- run ! grep -Fq ' claude mcp add ' " $CONFIGDIR /claude-mcp-setup.sh"
235- [ ! -f " $TOKENFILE " ]
222+ @test " tempo disabled without service account writes empty MCP config" {
223+ run_mcp_case false missing latest
224+ assert_contains " Tempo MCP: server disabled; enable with"
225+ assert_contains " TEMPO_EXTRA_ARGS=--query-frontend.mcp-server.enabled=true"
226+ assert_contains " Grafana MCP: server unavailable; could not create service account token"
227+ assert_has_file " $CONFIGDIR /mcp.json"
228+ assert_has_file " $CONFIGDIR /claude-mcp-setup.sh"
229+ assert_no_file " $TOKENFILE "
230+ assert_file_contains " $CONFIGDIR /mcp.json" ' "mcpServers": {}'
231+ assert_file_not_contains " $CONFIGDIR /claude-mcp-setup.sh" ' claude mcp add '
236232}
0 commit comments