Test runner: isolated=false opt-out, ignore free text after the setup url

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Richard ZinkandClaude Sonnet 5.5 committed 2026-11-20 07:23:45 +01:00
1 parent a4d4564b58
commit 96cb866d5c
4 files changed
+20 -3

No files matched your search

+9 -2
View File
@@ -75,6 +75,10 @@ pub struct Started {
/// Parse `.factory/setup.json` into a request (without `work`). `None` when there is nothing to start.
pub fn parse_setup(text: &str) -> Option<StartReq> {
let v: Value = serde_json::from_str(text).ok()?;
// `"isolated": false`: the app cannot run in a container (e.g. a native window); acceptance starts it itself.
if v["isolated"].as_bool() == Some(false) {
return None;
}
let start = v["start"].as_str()?.trim().to_string();
if start.is_empty() {
return None;
@@ -111,8 +115,9 @@ pub fn parse_setup(text: &str) -> Option<StartReq> {
/// Port of `http://host:1234/path` (80/443 by scheme when missing).
pub fn port_of(url: &str) -> Option<u16> {
let (scheme, rest) = url.split_once("://")?;
let host = rest.split('/').next()?;
let (scheme, rest) = url.trim().split_once("://")?;
// Free text after the URL ("http://localhost:8080 (trunk serve)") is ignored.
let host = rest.split(|c: char| c == '/' || c.is_whitespace()).next()?;
match host.rsplit_once(':') {
Some((_, p)) if p.chars().all(|c| c.is_ascii_digit()) && !p.is_empty() => p.parse().ok(),
_ => Some(if scheme == "https" { 443 } else { 80 }),
@@ -548,6 +553,8 @@ mod tests {
assert_eq!(port_of("http://localhost"), Some(80));
assert_eq!(port_of("https://x/y"), Some(443));
assert_eq!(port_of("nonsense"), None);
assert_eq!(port_of("http://localhost:8080 (web build: trunk serve)"), Some(8080));
assert!(parse_setup(r#"{"start":"x","port":1,"isolated":false}"#).is_none());
}
#[test]