@@ -22,6 +22,7 @@ type TestConfig struct {
2222 Config json.RawMessage `json:"config"`
2323 TestPort int `json:"test_port"`
2424 XrayPath string `json:"xray_path"`
25+ FragmentConfig json.RawMessage `json:"fragment_config,omitempty"`
2526}
2627
2728type TestResult struct {
@@ -56,14 +57,25 @@ func main() {
5657 }
5758 defer os .Remove (tmpFile .Name ())
5859
60+
61+ outbounds := []json.RawMessage {c .Config }
62+
63+ if len (c .FragmentConfig ) > 0 && string (c .FragmentConfig ) != "null" {
64+ fragmentOutbound := map [string ]interface {}{
65+ "protocol" : "freedom" ,
66+ "tag" : "fragment" ,
67+ "settings" : map [string ]json.RawMessage {
68+ "fragment" : c .FragmentConfig ,
69+ },
70+ }
71+ fragmentBytes , _ := json .Marshal (fragmentOutbound )
72+ outbounds = append (outbounds , json .RawMessage (fragmentBytes ))
73+ }
74+
5975 fullConfig := map [string ]interface {}{
60- "log" : map [string ]string {
61- "loglevel" : "debug" , // Enable debug logging for detailed output
62- },
63- "inbounds" : []map [string ]interface {}{
64- {"protocol" : "socks" , "port" : c .TestPort , "listen" : "127.0.0.1" , "settings" : map [string ]interface {}{"auth" : "noauth" , "udp" : true }},
65- },
66- "outbounds" : []json.RawMessage {c .Config },
76+ "log" : map [string ]string {"loglevel" : "warning" }, // Use "warning" to reduce noise
77+ "inbounds" : []map [string ]interface {}{{"protocol" : "socks" , "port" : c .TestPort , "listen" : "127.0.0.1" , "settings" : map [string ]interface {}{"auth" : "noauth" , "udp" : true }}},
78+ "outbounds" : outbounds ,
6779 }
6880
6981 configBytes , _ := json .Marshal (fullConfig )
@@ -75,7 +87,6 @@ func main() {
7587
7688 cmd := exec .CommandContext (ctx , c .XrayPath , "-c" , tmpFile .Name ())
7789
78- // Capture Xray's stdout and stderr
7990 var xrayOutput bytes.Buffer
8091 cmd .Stdout = & xrayOutput
8192 cmd .Stderr = & xrayOutput
@@ -89,16 +100,12 @@ func main() {
89100
90101 ping , status := testProxy (c .TestPort )
91102
92- // If the test fails, append Xray's log to the status for debugging
93103 if status != "success" {
94104 logStr := string (xrayOutput .Bytes ())
95-
96- // ! FIX: Use 'strings.ReplaceAll' to make the log a single line. No more 're'.
97105 logStr = strings .ReplaceAll (logStr , "\n " , " " )
98106 logStr = strings .ReplaceAll (logStr , "\r " , "" )
99-
100107 if len (logStr ) > 250 {
101- logStr = logStr [:250 ] // Shorten the log for cleaner output
108+ logStr = logStr [:250 ]
102109 }
103110 status = fmt .Sprintf ("%s | xray_log: %s" , status , logStr )
104111 }
0 commit comments