@@ -2818,14 +2818,11 @@ mod tests {
28182818
28192819 #[ test]
28202820 fn test_fs_read_bytes_capped ( ) {
2821- // Request a huge len (well above MAX_FS_READ) on a small file.
2822- // Without the cap this would try to allocate terabytes and OOM.
28232821 let root = tmpdir ( "readcap" ) ;
28242822 fs:: write ( root. join ( "small.bin" ) , b"hello" ) . unwrap ( ) ;
28252823 let mut reg = ToolRegistry :: new ( ) ;
28262824 FsSandbox :: new ( & root) . unwrap ( ) . register ( & mut reg) ;
28272825
2828- // Ask for 1 TiB — the cap should silently clamp to MAX_FS_READ.
28292826 let req = br#"{"name":"fs_read_bytes","args":{"path":"small.bin","len":1099511627776}}"# ;
28302827 let resp = reg. dispatch ( req) ;
28312828 let s = std:: str:: from_utf8 ( & resp) . unwrap ( ) ;
@@ -2835,14 +2832,8 @@ mod tests {
28352832
28362833 #[ test]
28372834 fn test_sleep_capped ( ) {
2838- // Verify the cap constant and that sleeping with a huge value
2839- // completes quickly (the cap brings it down to 60 s max, but we
2840- // pass 0 to keep the test instant — the important thing is
2841- // confirming the cap constant exists and has the right value).
28422835 assert_eq ! ( MAX_SLEEP_NS , 60_000_000_000 ) ;
28432836
2844- // Dispatch a sleep with ns=0 through the real handler to confirm
2845- // the code path works.
28462837 let mut tools = ToolRegistry :: new ( ) ;
28472838 let exit_code = Arc :: new ( AtomicI32 :: new ( 0 ) ) ;
28482839 register_internal_tools ( & mut tools, & exit_code, None , None ) ;
@@ -2852,4 +2843,27 @@ mod tests {
28522843 let s = std:: str:: from_utf8 ( & resp) . unwrap ( ) ;
28532844 assert ! ( !s. contains( "\" error\" " ) , "sleep(0) should succeed: {s}" ) ;
28542845 }
2846+
2847+ #[ test]
2848+ fn net_getsockopt_returns_correct_type_for_dgram ( ) {
2849+ let mut reg = ToolRegistry :: new ( ) ;
2850+ let policy = NetworkPolicy :: AllowAll ;
2851+ register_net_tools ( & mut reg, & policy, None ) ;
2852+
2853+ let req = br#"{"name":"net_socket","args":{"family":2,"type":2}}"# ;
2854+ let resp = std:: str:: from_utf8 ( & reg. dispatch ( req) ) . unwrap ( ) . to_string ( ) ;
2855+ let v: serde_json:: Value = serde_json:: from_str ( & resp) . unwrap ( ) ;
2856+ let fd = v[ "result" ] [ "fd" ] . as_u64 ( ) . unwrap ( ) ;
2857+
2858+ let req =
2859+ format ! ( r#"{{"name":"net_getsockopt","args":{{"fd":{fd},"level":1,"optname":3}}}}"# ) ;
2860+ let resp = std:: str:: from_utf8 ( & reg. dispatch ( req. as_bytes ( ) ) )
2861+ . unwrap ( )
2862+ . to_string ( ) ;
2863+ let v: serde_json:: Value = serde_json:: from_str ( & resp) . unwrap ( ) ;
2864+ assert_eq ! (
2865+ v[ "result" ] [ "value" ] , 2 ,
2866+ "SO_TYPE should return 2 (DGRAM), got: {resp}"
2867+ ) ;
2868+ }
28552869}
0 commit comments