From 225fcc3b3790f327053c8b86c8d0b7fdf5ef2dd8 Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Thu, 29 Oct 2026 11:31:47 -0400 Subject: [PATCH] fix discovery relying on hardcoded string --- src/stage2/analysis/discovery.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/stage2/analysis/discovery.rs b/src/stage2/analysis/discovery.rs index e567f26..15beff0 100644 --- a/src/stage2/analysis/discovery.rs +++ b/src/stage2/analysis/discovery.rs @@ -104,14 +104,23 @@ pub(super) fn discover(index: &Index<'_>, pool: &str) -> Result let index_one = position + 1; let created = &graph[phases[0]].code; let values = descriptors(listing, strings, created, *dispatcher.start(), pool)?; + let (input_position, input): (usize, JsValue) = values + .iter() + .enumerate() + .find_map(|(position, text)| { + serde_json::from_str(text) + .ok() + .map(|input| (position, input)) + }) + .with_context(|| format!("probe {index_one} has no input"))?; + // The token is the longest other descriptor: the record's opaque value, beside its + // field names and its JSON input. Its version markers change between builds. let token = values .iter() - .find(|text| text.contains("-1.2.1.1-")) - .context("probe has no token")?; - let input: JsValue = values - .iter() - .find_map(|text| serde_json::from_str(text).ok()) - .with_context(|| format!("probe {index_one} has no input"))?; + .enumerate() + .filter_map(|(position, text)| (position != input_position).then_some(text)) + .max_by_key(|text| text.len()) + .with_context(|| format!("probe {index_one} has no token: {values:?}"))?; let body = &listing.instructions[&states[phases[1]]]; let function = body .effects()