cli: optionally list exact pipeline refusals during warm-up

This commit is contained in:
steven-seagull27
2026-11-27 06:29:15 +01:00
committed by DoubleGhosty
parent 5fe14b168d
commit b57a837d89
2 changed files with 47 additions and 2 deletions

View File

@ -123,6 +123,9 @@ enum Command {
/// Only the pipelines earlier runs drew with.
#[arg(long)]
used: bool,
/// Print a no-host line with the fingerprint and pipeline key for each refusal.
#[arg(long)]
list_no_host: bool,
/// (What the processes it starts are given.)
#[arg(long, hide = true)]
these: Option<String>,
@ -215,7 +218,9 @@ fn main() -> Result<()> {
}
Command::Shaders { paths, jobs } => translate::precompile(paths, jobs),
#[cfg(windows)]
Command::Warm { jobs, limit, again, used, these } => warm::run(jobs, limit, again, used, these),
Command::Warm { jobs, limit, again, used, list_no_host, these } => {
warm::run(jobs, limit, again, used, list_no_host, these)
}
Command::Run {
exe,
unimplemented,

View File

@ -38,7 +38,14 @@ fn empty_hint(known: usize, early: usize, used: bool) -> Option<&'static str> {
}
}
pub fn run(jobs: Option<usize>, limit: Option<usize>, again: bool, used: bool, these: Option<String>) -> Result<()> {
pub fn run(
jobs: Option<usize>,
limit: Option<usize>,
again: bool,
used: bool,
list_no_host: bool,
these: Option<String>,
) -> Result<()> {
let dir = folder()?;
if let Some(these) = these {
return make(&dir, &these);
@ -94,6 +101,9 @@ pub fn run(jobs: Option<usize>, limit: Option<usize>, again: bool, used: bool, t
let mut rest = chunk;
while !rest.is_empty() {
let result = child(rest, |n, ms, there| {
if let Some(line) = no_host_line(list_no_host, there, &fingerprint, &keys[n]) {
println!("{line}");
}
if ms >= SLOW_MS {
let _ = writeln!(lock(&slow_out), "\n{} {ms:.0}", keys[n]);
}
@ -164,6 +174,11 @@ fn recorded_keys<'a>(records: &'a str, fingerprint: &str) -> HashSet<&'a str> {
.collect()
}
// The same confirmed refusal on --again prints the same pair, even if its archive index changes.
fn no_host_line(list: bool, made_host: bool, fingerprint: &str, key: &str) -> Option<String> {
(list && !made_host).then(|| format!("no-host {fingerprint} {key}"))
}
fn lock<T>(m: &Mutex<T>) -> std::sync::MutexGuard<'_, T> {
m.lock().unwrap_or_else(|e| e.into_inner())
}
@ -326,6 +341,31 @@ fn make(dir: &Path, these: &str) -> Result<()> {
mod tests {
use super::*;
#[test]
fn listing_no_host_results_is_opt_in() {
use clap::Parser;
for (extra, expected) in [(None, false), (Some("--list-no-host"), true)] {
let args = ["victory", "warm"].into_iter().chain(extra);
let cli = crate::Cli::try_parse_from(args).unwrap();
assert!(matches!(cli.command, crate::Command::Warm { list_no_host, .. } if list_no_host == expected));
}
}
#[test]
fn only_confirmed_no_host_results_are_listed_on_request() {
let outcomes = [("one", true), ("two", false), ("three", true)];
let lines = |list, fingerprint| {
outcomes
.iter()
.filter_map(|(key, host)| no_host_line(list, *host, fingerprint, key))
.collect::<Vec<_>>()
};
assert!(lines(false, "build-a").is_empty());
assert_eq!(lines(true, "build-a"), ["no-host build-a two"]);
assert_eq!(lines(true, "build-b"), ["no-host build-b two"]);
assert_eq!(no_host_line(true, false, "build-a", "two").as_deref(), Some("no-host build-a two"));
}
#[test]
fn empty_hint_only_when_there_is_nothing_to_make() {
assert!(empty_hint(0, 0, false).is_some());