From 6044020735ec743d0506dd42a528ab27445018f9 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 16:35:40 -0600 Subject: [PATCH 1/2] =?UTF-8?q?fix(id):=20four=20lib=20tests=20failing=20o?= =?UTF-8?q?n=20main=20=E2=80=94=20fence=20span,=20tags=20socket=20close,?= =?UTF-8?q?=20two=20hosting-blind=20routing=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - markdown: a closing fence line cleared the fence state before its backticks were classified, so they opened a phantom inline span that suppressed newline-destination protection for the rest of the doc. Track fence lines and never treat their backticks as span syntax. - tags_ws: the forwarding loop only watched the broadcast channel, so when the inbound side died (disconnect, close frame, oversized message error) the socket stayed open forever. End the loop when the drain task finishes. - world_ws two_apps_bind_distinct_sockets and routes public_entry_point_honours_a_configured_binding: both handlers 404 when no world is hosted, so world-less test state made the routing assertions measure hosting instead. Host a lobby world in both. The fifth failure, fileops delete_after_repeated_replacements, is tracked separately in #4574. --- pkgs/id/src/web/markdown.rs | 8 +++++++- pkgs/id/src/web/routes.rs | 17 ++++++++++++++++- pkgs/id/src/web/tags_ws.rs | 13 ++++++++++--- pkgs/id/src/web/world_ws.rs | 4 ++-- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/pkgs/id/src/web/markdown.rs b/pkgs/id/src/web/markdown.rs index 9d05351b6b..0676bad492 100644 --- a/pkgs/id/src/web/markdown.rs +++ b/pkgs/id/src/web/markdown.rs @@ -2312,6 +2312,10 @@ fn protect_newline_destinations(markdown: &str) -> (String, Option) { // long as the opener — a shorter fence line inside a longer // fence is literal content, not the end of the block (#1707). let mut fence: Option<(u8, usize)> = None; + // Whether the current line is a fence line (opens, closes, or is + // checked against an open fence): its backticks are fence syntax, + // never an inline code span opener. + let mut fence_line = false; // The open inline code span's backtick run length, when inside // one: span content is literal text, so a destination-shaped // string inside it must not be protected (#1707). @@ -2342,11 +2346,13 @@ fn protect_newline_destinations(markdown: &str) -> (String, Option) { } else { None }; + let was_in_fence = fence.is_some(); match (fence, fence_run) { (None, Some(open)) => fence = Some(open), (Some((ch, n)), Some((cch, cn))) if cch == ch && cn >= n => fence = None, _ => {} } + fence_line = fence_run.is_some() && (was_in_fence || fence.is_some()); // An indented code block starts on a 4+ indented line // after a blank line (or at the start, or continuing an // indented block); a 4+ indented line inside a paragraph @@ -2355,7 +2361,7 @@ fn protect_newline_destinations(markdown: &str) -> (String, Option) { prev_line_indented = in_indented || (indent >= 4 && line_blank && prev_line_indented); prev_line_blank = line_blank; } - let literal_line = fence.is_some() || in_indented; + let literal_line = fence.is_some() || in_indented || fence_line; if !literal_line && span.is_none() && (markdown[i..].starts_with("](<") || markdown[i..].starts_with("]: <")) { let lt = if markdown[i..].starts_with("](<") { i + 2 diff --git a/pkgs/id/src/web/routes.rs b/pkgs/id/src/web/routes.rs index fa49906ab9..6a7aa855b4 100644 --- a/pkgs/id/src/web/routes.rs +++ b/pkgs/id/src/web/routes.rs @@ -2605,7 +2605,22 @@ mod upload_router_tests { // binding through the public API alone (Codex P2 on PR #3894): // parse [interfaces.web] with the re-exported parser and build // the app router with the re-exported constructor. - let (_, state, _dir, _endpoint, _docs) = router_with_state().await; + let (_, mut state, _dir, _endpoint, _docs) = router_with_state().await; + // The world page handler 404s when no world is hosted; host + // one so the assertions below measure routing (the configured + // route registered, the default route absent), not hosting. + state.world = Some(crate::world_hub::WorldHub::single( + crate::world_session::WorldService::new( + crate::world::WorldHandle::spawn( + crate::world::WorldCore::new( + "lobby", + crate::world::WorldLimits::default(), + ) + .unwrap(), + ), + None, + ), + )); let interface = crate::web::web_interface_from_app_toml( "[interfaces.web]\nmode = \"adapter\"\nroute = \"/arena\"\nsocket = \"/ws/arena\"\n", ) diff --git a/pkgs/id/src/web/tags_ws.rs b/pkgs/id/src/web/tags_ws.rs index 245095d0b1..32859497c8 100644 --- a/pkgs/id/src/web/tags_ws.rs +++ b/pkgs/id/src/web/tags_ws.rs @@ -220,7 +220,7 @@ async fn handle_tags_socket(socket: axum::extract::ws::WebSocket, state: AppStat let mut rx = state.tag_store.subscribe(); // Spawn a task to drain inbound messages (keeps the socket alive). - let drain_handle = tokio::spawn(async move { + let mut drain_handle = tokio::spawn(async move { while let Some(Ok(msg)) = receiver.next().await { // Respond to pings, ignore everything else. if let Message::Close(_) = msg { @@ -229,9 +229,16 @@ async fn handle_tags_socket(socket: axum::extract::ws::WebSocket, state: AppStat } }); - // Forward broadcast events to the WebSocket. + // Forward broadcast events to the WebSocket. The loop also ends + // when the inbound side finishes (a disconnect, a close frame, or + // a protocol error such as an oversized message): nobody is + // reading any more, so the socket must close instead of lingering. loop { - match rx.recv().await { + let received = tokio::select! { + received = rx.recv() => received, + _ = &mut drain_handle => break, + }; + match received { Ok(event) => { let json = match serde_json::to_string(&event) { Ok(j) => j, diff --git a/pkgs/id/src/web/world_ws.rs b/pkgs/id/src/web/world_ws.rs index 5cf470f434..ed7cb4a5ec 100644 --- a/pkgs/id/src/web/world_ws.rs +++ b/pkgs/id/src/web/world_ws.rs @@ -1655,12 +1655,12 @@ mod tests { // App A keeps the historical binding; app B binds its own // socket from its [interfaces.web] section (#2325). let addr_a = serve(world_routes().with_state(WorldWebState { - hub: None, + hub: Some(WorldHub::single(WorldService::new(lobby(), None))), cookie_secure: false, })) .await; let addr_b = serve(world_routes_at("/ws/arena").with_state(WorldWebState { - hub: None, + hub: Some(WorldHub::single(WorldService::new(lobby(), None))), cookie_secure: false, })) .await; From 4dba9a62538fced47a14da6d159c173be8414600 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 17:04:01 -0600 Subject: [PATCH 2/2] fix(id): keep archive references on the live file across replacements (#4574) archive_existing transferred the replaced file's metadata onto the new archive, and the transfer discards excluded keys from the source outright. The archive.rename/archive.replace references therefore left the live file on the first replacement (copied onto the archive, then deleted from the live name), so a delete after repeated replacements only ever found the latest archive and orphaned the rest. Snapshot the references before the transfer, keep them off the archive via the identity exclusion list, and restore them onto the live name afterwards. --- pkgs/id/src/fileops.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/pkgs/id/src/fileops.rs b/pkgs/id/src/fileops.rs index bfc07ed6b3..7aa2b0092d 100644 --- a/pkgs/id/src/fileops.rs +++ b/pkgs/id/src/fileops.rs @@ -29,7 +29,17 @@ use thiserror::Error; use crate::tags::{TagStore, now_unix}; -const ARCHIVE_IDENTITY_TAG_KEYS: [&[u8]; 3] = [b"name", b"file", b"path"]; +const ARCHIVE_IDENTITY_TAG_KEYS: [&[u8]; 5] = [ + b"name", + b"file", + b"path", + // Archive references describe the live file's archives, so they + // stay on the live name when its other metadata moves onto an + // archive. Letting one travel onto the archive subject orphans + // every earlier archive from the live file's delete (#4574). + b"archive.rename", + b"archive.replace", +]; /// Errors from file operations, distinguishable so callers can map them to /// protocol errors or HTTP status codes. @@ -241,6 +251,24 @@ impl<'a> FileOps<'a> { let Some(existing) = self.store.tags().get(name).await? else { return Ok(None); }; + // Archive references belong to the live file: they name the + // archives a future delete of this file must also remove. The + // transfer below discards them from this name (and the + // exclusion list keeps them off the archive), so snapshot them + // here and restore them onto the live name afterwards - + // otherwise each replacement orphans every earlier archive. + let mut archive_refs = Vec::new(); + for key in [&b"archive.rename"[..], &b"archive.replace"[..]] { + for tag in self + .tags + .get_by_key(&self.tags.global, name.as_bytes(), key) + .await? + { + if let Some(value) = tag.value.as_ref().and_then(|value| value.as_str()) { + archive_refs.push((key, value.to_owned())); + } + } + } let archive = claim_archive_name(self.store, name, ts, existing.hash) .await .with_context(|| format!("archiving replaced file {name}"))?; @@ -257,6 +285,18 @@ impl<'a> FileOps<'a> { .refresh_identity_tags(&self.tags.global, archive.as_bytes()) .await .with_context(|| format!("refreshing identity for archive {archive}"))?; + for (key, value) in &archive_refs { + self.tags + .set_tag( + &self.tags.global, + name.as_bytes(), + key, + Some(value.as_bytes()), + b"", + ) + .await + .with_context(|| format!("restoring archive references for {name}"))?; + } Ok(Some(archive)) }