@@ -248,13 +248,74 @@ def test_token_show_command_partial_hash(
248248 def test_token_show_command_not_found (self , mock_get_redis , mock_redis , cli_runner ):
249249 """Test token show command with non-existent token."""
250250 mock_get_redis .return_value = mock_redis
251- mock_redis .get .return_value = None
251+ mock_redis .smembers .return_value = set ()
252252
253253 result = cli_runner .invoke (token , ["show" , "nonexistent" ])
254254
255- assert result .exit_code == 0
255+ assert result .exit_code == 1
256256 assert "No token found matching" in result .output
257257
258+ @patch ("agent_memory_server.cli.get_redis_conn" )
259+ def test_token_show_command_not_found_json (
260+ self , mock_get_redis , mock_redis , cli_runner
261+ ):
262+ """Test token show command with non-existent token (JSON output)."""
263+ mock_get_redis .return_value = mock_redis
264+ mock_redis .smembers .return_value = set ()
265+
266+ import json
267+
268+ result = cli_runner .invoke (token , ["show" , "nonexistent" , "--format" , "json" ])
269+
270+ assert result .exit_code == 1
271+ data = json .loads (result .output )
272+ assert "error" in data
273+ assert "No token found matching" in data ["error" ]
274+
275+ @patch ("agent_memory_server.cli.get_redis_conn" )
276+ def test_token_show_command_multiple_matches_json (
277+ self , mock_get_redis , mock_redis , cli_runner
278+ ):
279+ """Test token show command with multiple matches (JSON output)."""
280+ mock_get_redis .return_value = mock_redis
281+
282+ # Create multiple token hashes with same prefix
283+ token_hashes = {
284+ "test_hash_111111111111111111111111111111" ,
285+ "test_hash_222222222222222222222222222222" ,
286+ }
287+
288+ mock_redis .smembers .return_value = token_hashes
289+
290+ import json
291+
292+ result = cli_runner .invoke (token , ["show" , "test_hash" , "--format" , "json" ])
293+
294+ assert result .exit_code == 1
295+ data = json .loads (result .output )
296+ assert "error" in data
297+ assert "Multiple tokens match" in data ["error" ]
298+ assert "matches" in data
299+ assert len (data ["matches" ]) == 2
300+
301+ @patch ("agent_memory_server.cli.get_redis_conn" )
302+ def test_token_show_command_token_not_in_redis_json (
303+ self , mock_get_redis , mock_redis , cli_runner
304+ ):
305+ """Test token show command when token not in Redis (JSON output)."""
306+ mock_get_redis .return_value = mock_redis
307+ mock_redis .get .return_value = None
308+
309+ import json
310+
311+ token_hash = "test_hash_123456789012345678901234567890"
312+ result = cli_runner .invoke (token , ["show" , token_hash , "--format" , "json" ])
313+
314+ assert result .exit_code == 1
315+ data = json .loads (result .output )
316+ assert "error" in data
317+ assert "Token not found" in data ["error" ]
318+
258319 @patch ("agent_memory_server.cli.get_redis_conn" )
259320 def test_token_remove_command_with_confirmation (
260321 self , mock_get_redis , mock_redis , cli_runner
0 commit comments