MCPcopy Create free account
hub / github.com/AI45Lab/Code / test_registry_truncates_large_tool_output

Function test_registry_truncates_large_tool_output

core/src/tools/registry.rs:545–595  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

543
544 #[tokio::test]
545 async fn test_registry_truncates_large_tool_output() {
546 let registry = ToolRegistry::new(PathBuf::from("/tmp"));
547 let trace_sink = InMemoryTraceSink::default();
548 registry.set_trace_sink(Arc::new(trace_sink.clone()));
549 registry.register(Arc::new(LargeOutputTool));
550
551 let result = registry
552 .execute("large_output", &serde_json::json!({}))
553 .await
554 .unwrap();
555
556 assert_eq!(result.exit_code, 0);
557 assert!(result.output.contains("[tool output truncated:"));
558 assert!(result
559 .output
560 .contains("Full output artifact: a3s://tool-output/large_output/"));
561 assert!(result.output.len() < super::super::MAX_OUTPUT_SIZE + 512);
562 let metadata = result.metadata.expect("artifact metadata");
563 assert_eq!(
564 metadata["artifact"]["original_bytes"],
565 serde_json::json!(super::super::MAX_OUTPUT_SIZE + 1)
566 );
567 assert_eq!(
568 metadata["artifact"]["shown_bytes"],
569 serde_json::json!(super::super::MAX_OUTPUT_SIZE)
570 );
571 assert!(metadata["artifact"]["artifact_id"]
572 .as_str()
573 .unwrap()
574 .starts_with("tool-output:large_output:"));
575 assert!(metadata["artifact"]["artifact_uri"]
576 .as_str()
577 .unwrap()
578 .starts_with("a3s://tool-output/large_output/"));
579
580 let artifact_uri = metadata["artifact"]["artifact_uri"].as_str().unwrap();
581 let artifact = registry
582 .get_artifact(artifact_uri)
583 .expect("full output artifact");
584 assert_eq!(artifact.tool_name, "large_output");
585 assert_eq!(artifact.original_bytes, super::super::MAX_OUTPUT_SIZE + 1);
586 assert_eq!(artifact.shown_bytes, super::super::MAX_OUTPUT_SIZE);
587 assert_eq!(
588 artifact.content,
589 "x".repeat(super::super::MAX_OUTPUT_SIZE + 1)
590 );
591
592 let events = trace_sink.events();
593 assert_eq!(events.len(), 1);
594 assert_eq!(events[0].artifact_uris, vec![artifact_uri]);
595 }
596
597 #[tokio::test]
598 async fn test_registry_execute_raw_success() {

Callers

nothing calls this directly

Calls 8

expectMethod · 0.80
set_trace_sinkMethod · 0.45
cloneMethod · 0.45
registerMethod · 0.45
executeMethod · 0.45
as_strMethod · 0.45
get_artifactMethod · 0.45
eventsMethod · 0.45

Tested by

no test coverage detected