fc-queue-server: match output names by path instead of index

Now creates a path-to-name lookup `HashMap` from the outputs JSON and
matches each output path to its correct name. Both the `build_outputs`
table insert and GC root registration loops now use the same lookup
to ensure we're consistent.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Id9f4ce0be6131a7c1a8ce6775ab249db6a6a6964
This commit is contained in:
raf 2026-02-28 21:50:45 +03:00
commit 609ac53c3f
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -588,23 +588,35 @@ async fn run_build(
}; };
if build_result.success { if build_result.success {
// Parse output names from build's outputs JSON // Build a reverse lookup map: path -> output_name
let output_names: Vec<String> = build // The outputs JSON is a HashMap<String, String> where keys are output names
// and values are store paths. We need to match paths to names correctly.
let path_to_name: std::collections::HashMap<String, String> = build
.outputs .outputs
.as_ref() .as_ref()
.and_then(|v| v.as_object()) .and_then(|v| v.as_object())
.map(|obj| obj.keys().cloned().collect()) .map(|obj| {
obj
.iter()
.filter_map(|(name, path)| {
path.as_str().map(|p| (p.to_string(), name.clone()))
})
.collect()
})
.unwrap_or_default(); .unwrap_or_default();
// Store build outputs in normalized table // Store build outputs in normalized table
for (i, output_path) in build_result.output_paths.iter().enumerate() { for (i, output_path) in build_result.output_paths.iter().enumerate() {
let output_name = output_names.get(i).cloned().unwrap_or_else(|| { let output_name = path_to_name
if i == 0 { .get(output_path)
"out".to_string() .cloned()
} else { .unwrap_or_else(|| {
format!("out{i}") if i == 0 {
} "out".to_string()
}); } else {
format!("out{i}")
}
});
if let Err(e) = repo::build_outputs::create( if let Err(e) = repo::build_outputs::create(
pool, pool,
@ -624,13 +636,16 @@ async fn run_build(
// Register GC roots and create build products for each output // Register GC roots and create build products for each output
for (i, output_path) in build_result.output_paths.iter().enumerate() { for (i, output_path) in build_result.output_paths.iter().enumerate() {
let output_name = output_names.get(i).cloned().unwrap_or_else(|| { let output_name = path_to_name
if i == 0 { .get(output_path)
build.job_name.clone() .cloned()
} else { .unwrap_or_else(|| {
format!("{}-{i}", build.job_name) if i == 0 {
} build.job_name.clone()
}); } else {
format!("{}-{i}", build.job_name)
}
});
// Register GC root // Register GC root
let mut gc_root_path = None; let mut gc_root_path = None;