From c3a57be3fa57994ea9fc68903e97e6c249a8a0ac Mon Sep 17 00:00:00 2001 From: Levi Neuwirth Date: Wed, 15 Jul 2026 13:24:37 +0100 Subject: [PATCH] fix(injections): pin sibling priority regression --- src/process.rs | 10 ++++++++-- src/semantic_render.rs | 36 +++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/process.rs b/src/process.rs index e7d04aa..72b4f15 100644 --- a/src/process.rs +++ b/src/process.rs @@ -3078,9 +3078,15 @@ mod tests { let pidfile = dir.path().join(format!("pid{round}")); let mut sup = ProcessSupervisor::new(); sup.set_group_term_grace(Duration::from_millis(300)); + // Do not let the group leader exit until the background child has + // completed `setsid` and published its pid. Without this readiness + // gate, teardown can TERM the old process group before `setsid` + // runs; the child then dies before creating the pidfile (a race + // exposed consistently by the Ubuntu 20260714 runner image). let script = format!( - "setsid /bin/sh -c 'echo $$ > {}; exec sleep 30' & echo started", - pidfile.display() + "setsid /bin/sh -c 'echo $$ > {pid}; exec sleep 30' & \ + while [ ! -s {pid} ]; do sleep 0.01; done; echo started", + pid = pidfile.display() ); let id = sup.spawn(sh_group_spec("escapee", &script)).expect("spawn"); let ready = drain_until(&mut sup, id, Duration::from_secs(2), |evs| { diff --git a/src/semantic_render.rs b/src/semantic_render.rs index 6eaf0ac..da8dd5c 100644 --- a/src/semantic_render.rs +++ b/src/semantic_render.rs @@ -1761,10 +1761,10 @@ fn scoped_style_spans(state: &EditorState, vp: &DeclaredViewport) -> Vec = Vec::new(); for (layer_idx, layer) in bundle.layers.iter().enumerate() { let Some(query) = layer.highlight_query.as_ref() else { @@ -1794,13 +1794,23 @@ fn scoped_style_spans(state: &EditorState, vp: &DeclaredViewport) -> Vec LayerSpanPriority { + (layer_index as u32, capture_order as u32) +} + /// One styled span from a single injection layer, tagged with a priority /// used to resolve overlaps: `(layer_index, capture_order)`, higher wins. /// `layer_index` is the position in `bundle.layers` — depth-ascending, so a @@ -1813,7 +1823,7 @@ struct StyledLayerSpan { start: u64, end: u64, style: Style, - priority: (u32, u32), + priority: LayerSpanPriority, } /// Flatten possibly-overlapping per-layer styled spans into **disjoint** @@ -3543,19 +3553,27 @@ mod tests { fg: Color::Indexed(2), ..Style::default() }; - // Layer 0 span [0,10) red; layer 1 span [3,6) green (overlapping). + // Both spans are depth-1 siblings. Layer index 2 follows layer index + // 1, so green must win even though their depth/capture order tie. + let sibling_depth = 1; + let earlier = layer_span_priority(1, sibling_depth, 0); + let later = layer_span_priority(2, sibling_depth, 0); + assert!( + earlier < later, + "the later sibling has higher priority despite equal depth" + ); let styled = vec![ StyledLayerSpan { start: 0, end: 10, style: red, - priority: (0, 0), + priority: earlier, }, StyledLayerSpan { start: 3, end: 6, style: green, - priority: (1, 0), + priority: later, }, ]; let out = flatten_layer_spans(&styled);