From 97fc805712202a38e15d2044fbbf069574167457 Mon Sep 17 00:00:00 2001
From: "google-labs-jules[bot]"
<161369871+google-labs-jules[bot]@users.noreply.github.com>
Date: Tue, 8 Sep 2026 08:22:54 +0000
Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Co?=
=?UTF-8?q?ver=20unwrap=20panics=20in=20web=20module?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
---
stdlib/tests/stdlib_tests.rs | 76 ++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/stdlib/tests/stdlib_tests.rs b/stdlib/tests/stdlib_tests.rs
index f7df969f..0aef7b2a 100644
--- a/stdlib/tests/stdlib_tests.rs
+++ b/stdlib/tests/stdlib_tests.rs
@@ -407,6 +407,82 @@ fn test_regex_operations() {
assert_eq!(res.as_string(), Some("hello TechScript"));
}
+#[test]
+fn test_web_module() {
+ use std::net::TcpListener;
+ use std::panic;
+
+ let registry = StdlibRegistry::new();
+ let web = registry.get_module("std.web").unwrap();
+
+ let mut caps = HashSet::new();
+ caps.insert(Capability::Network);
+ let mut ctx = RuntimeContext::new(RuntimeConfig {
+ strict_mode: false,
+ max_recursion_depth: 1000,
+ enable_assertions: true,
+ capabilities: caps,
+ });
+
+ let start = web.exports.get("start").unwrap();
+ let serve = web.exports.get("serve").unwrap();
+ let stop = web.exports.get("stop").unwrap();
+
+ // Bind a listener to a random port to ensure the port is taken
+ let listener = TcpListener::bind("127.0.0.1:0").unwrap();
+ let port = listener.local_addr().unwrap().port();
+
+ // Test panic on `start` when port is in use
+ let start_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
+ let mut caps = HashSet::new();
+ caps.insert(Capability::Network);
+ let mut ctx2 = RuntimeContext::new(RuntimeConfig {
+ strict_mode: false,
+ max_recursion_depth: 1000,
+ enable_assertions: true,
+ capabilities: caps,
+ });
+ let _ = start.call(
+ &mut ctx2,
+ vec![
+ RuntimeValue::Int(port as i64),
+ RuntimeValue::Str("
Test
".to_string()),
+ ],
+ );
+ }));
+
+ assert!(
+ start_result.is_err(),
+ "Expected `start` to panic due to port already in use"
+ );
+
+ // Make sure we stop the server and cleanup the global bool in case of weirdness,
+ // although the panic meant it wasn't started fully, but `SERVER_RUNNING` is true.
+ let _ = stop.call(&mut ctx, vec![]).unwrap();
+
+
+ // Test panic on `serve` when port is in use
+ let serve_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
+ let mut caps = HashSet::new();
+ caps.insert(Capability::Network);
+ let mut ctx3 = RuntimeContext::new(RuntimeConfig {
+ strict_mode: false,
+ max_recursion_depth: 1000,
+ enable_assertions: true,
+ capabilities: caps,
+ });
+ let _ = serve.call(&mut ctx3, vec![RuntimeValue::Int(port as i64)]);
+ }));
+
+ assert!(
+ serve_result.is_err(),
+ "Expected `serve` to panic due to port already in use"
+ );
+
+ // Reset `SERVER_RUNNING` so other tests aren't affected
+ let _ = stop.call(&mut ctx, vec![]).unwrap();
+}
+
#[test]
fn test_http_module() {
use std::io::{Read, Write};
From ffc86edd3683107afbe570d6ebf97f65f524229b Mon Sep 17 00:00:00 2001
From: "google-labs-jules[bot]"
<161369871+google-labs-jules[bot]@users.noreply.github.com>
Date: Tue, 8 Sep 2026 08:41:12 +0000
Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Co?=
=?UTF-8?q?ver=20unwrap=20panics=20in=20web=20module?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
---
stdlib/tests/stdlib_tests.rs | 1 -
1 file changed, 1 deletion(-)
diff --git a/stdlib/tests/stdlib_tests.rs b/stdlib/tests/stdlib_tests.rs
index 0aef7b2a..00a52c0f 100644
--- a/stdlib/tests/stdlib_tests.rs
+++ b/stdlib/tests/stdlib_tests.rs
@@ -460,7 +460,6 @@ fn test_web_module() {
// although the panic meant it wasn't started fully, but `SERVER_RUNNING` is true.
let _ = stop.call(&mut ctx, vec![]).unwrap();
-
// Test panic on `serve` when port is in use
let serve_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
let mut caps = HashSet::new();
From d2b62f05dd314c9d96442e435c7694ff9c6eda1b Mon Sep 17 00:00:00 2001
From: "google-labs-jules[bot]"
<161369871+google-labs-jules[bot]@users.noreply.github.com>
Date: Tue, 8 Sep 2026 09:10:25 +0000
Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Co?=
=?UTF-8?q?ver=20unwrap=20panics=20in=20web=20module?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
---
stdlib/tests/stdlib_tests.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/stdlib/tests/stdlib_tests.rs b/stdlib/tests/stdlib_tests.rs
index 00a52c0f..17e7e355 100644
--- a/stdlib/tests/stdlib_tests.rs
+++ b/stdlib/tests/stdlib_tests.rs
@@ -429,7 +429,8 @@ fn test_web_module() {
let stop = web.exports.get("stop").unwrap();
// Bind a listener to a random port to ensure the port is taken
- let listener = TcpListener::bind("127.0.0.1:0").unwrap();
+ // Keep it alive to conflict
+ let listener = TcpListener::bind("0.0.0.0:0").unwrap();
let port = listener.local_addr().unwrap().port();
// Test panic on `start` when port is in use