Skip to content

fix(bench): speculative_bench panics on a user-supplied --target path with no file name #1242

Description

@inureyes

speculative_bench calls .file_name().unwrap() on a path taken directly from the --target CLI argument. Path::file_name() returns None for paths ending in .. or a trailing slash component that normalizes away, so a user who passes such a path gets a bare unwrap panic instead of a diagnostic.

Evidence

src/bin/speculative_bench.rs:829:

let row = if synthetic.target_subdir == target.file_name().unwrap().to_string_lossy() {

target comes straight from the command line. PathBuf::from("models/foo/..").file_name() and similar inputs return None, and the unwrap() aborts the whole bench run with a panic backtrace rather than telling the operator what was wrong with the argument.

Suggested fix

One to three lines. Either tolerate the missing file name:

let target_name = target.file_name().map(|n| n.to_string_lossy()).unwrap_or_default();

or fail early with a context error such as --target must name a model directory before the comparison. Either is fine; the second gives the operator a clearer message.

Acceptance criteria

  • Running speculative_bench with a --target path ending in .. or a trailing slash prints a readable error naming the --target argument, not a panic
  • The canonical models/<name> path comparison at src/bin/speculative_bench.rs:829 behaves exactly as before for normal paths

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:benchmarkBenchmark harness and performance measurement (bench_*.sh, /update-benchmarks)area:cliCommand-line interface / CLI flagsgood first issueGood for newcomerspriority:lowLow prioritystatus:readyReady to be worked ontype:bugBug fixes, error corrections, or issue resolutions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions