pub(crate) fn record_examples_for_publish(
store: &lex_store::Store,
stages: &[lex_ast::Stage],
outcome: &lex_store::PublishOutcome,
) {
use std::collections::BTreeMap;
let op_for_stage: BTreeMap<String, String> = outcome
.ops
.iter()
.filter_map(|op| {
op.kind.get("stage_id").and_then(|v| v.as_str())
.map(|sid| (sid.to_string(), op.op_id.clone()))
})
.collect();
for stage in stages {
let lex_ast::Stage::FnDecl(fd) = stage else { continue };
if fd.examples.is_empty() {
continue;
}
let Some(sid) = lex_ast::stage_id(stage) else { continue };
let op_id = op_for_stage.get(&sid).cloned()
.or_else(|| outcome.head_op.clone());
if let Some(op_id) = op_id {
if let Err(e) = store.record_examples_passed(&sid, &op_id, fd.examples.len()) {
eprintln!("warn: record_examples_passed({sid}) failed: {e}");
}
}
}
}