GUI + CI: code-review-harness fixes, expanded tests, version-logic tests
build-test-release / release (push) Successful in 5m47s
build-test-release / release (push) Successful in 5m47s
Ran the code-review-harness (four parallel reviewers: correctness, reliability, performance, test-coverage) over the GUI crate and fixed every Critical/High finding, plus grew the test + microbenchmark suite that gates the pipeline. Correctness / reliability fixes: - IP column sorted lexically, not numerically. The default view is IP-ascending but Column::Ip fell through to the generic lowercase-string sort key, so 10.255.1.10 sorted before 10.255.1.2 on every launch. Add a numeric IP sort key (u32, exact in f64) and switch view() to decorate-sort-undecorate so a sort key is computed once per row, not twice per comparison. - Scans had no cancellation. Stop/Apply/Play only dropped the receiver, leaving the background thread probing dead hosts (each waits out an asic-rs timeout), and Play could spawn a second concurrent scan + tokio runtime. Add a ScanHandle with an Arc<AtomicBool> cancel flag the loop checks each iteration, a begin_scan() helper that stops the in-flight scan before starting a new one, and Stop now signals cancellation. - Native column drag never rebuilt the control: column_reordered mutated view.order but skipped rebuild_table(), so the store's creation order diverged from display_columns() and cells rendered under the wrong headers on the next scan tick. Rebuild after applying the reorder. - format_si rounding rolled a mantissa up to "1000" without advancing the SI prefix (999.9 W -> "1000 W", a 4-digit result). Round first, then roll over; [99.95,100) drops its decimal. - start_scan used .expect() on thread spawn, which would panic across the wx FFI boundary; it now sends ScanMsg::Failed and returns the handle. Tests / benchmarks (the pipeline's regression gate): - Unit tests 24 -> 41: format_si/format_uptime boundaries, numeric IP sort, upsert-new-IP, Light three-state + pool-slot-out-of-range cells, filter AND/OR, reorder non-permutation guard; scan.rs parse_cidr/prefix_mask, single-host /32, empty/whitespace, short-range single/reversed, parse_targets aggregate cap + error propagation, validate_ranges, targets_to_cidrs non-contiguous, auto-rescan-secs round-trip. - Microbenchmarks 2 -> 9: view default-sort, sort-by-each-column, filtered view, upsert cold-start, parse_line near MAX_ADDRS, parse_targets many ranges, targets_to_cidrs large range. Floors are 5-10x above local numbers. - New ci/test-compute-version.sh: 9 cases for the X.Y.Z logic (first release, pre-bumped X, backend/UI bumps, docs-only no-op, major-wins-over-UI, backend-wins-over-UI, nested ci/ and thirdparty/wx-rs paths). Wired in as a fast-fail CI step. CI: install libssl-dev + pkg-config (openssl-sys); add xauth so the headless self-test actually launches under xvfb (was aborting on "xauth not found"). Deferred (documented in code-review-report.md, guarded by benches): Cow cells, an ip->index map for upsert. Local: 41 tests + 9 benches + 9 shell tests green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
+255
-10
@@ -29,11 +29,19 @@ pub fn format_si(value_base: f64, unit: &str) -> String {
|
||||
v /= 1000.0;
|
||||
i += 1;
|
||||
}
|
||||
let num = if v >= 100.0 {
|
||||
format!("{v:.0}")
|
||||
} else {
|
||||
format!("{v:.1}")
|
||||
};
|
||||
// Round first, then re-check the prefix. A mantissa that rounds up to 1000
|
||||
// (e.g. 999.9 -> "1000") must roll over to the next prefix so the number
|
||||
// never shows more than three integer digits; and a mantissa in [99.95,100)
|
||||
// rounds to "100.0" and should drop its decimal (the >=100 branch's rule).
|
||||
let render = |v: f64| if v >= 100.0 { format!("{v:.0}") } else { format!("{v:.1}") };
|
||||
let mut num = render(v);
|
||||
if (num == "1000" || num == "1000.0") && i < PREFIXES.len() - 1 {
|
||||
v /= 1000.0;
|
||||
i += 1;
|
||||
num = render(v);
|
||||
} else if num == "100.0" {
|
||||
num = "100".to_string();
|
||||
}
|
||||
format!("{num} {}{unit}", PREFIXES[i])
|
||||
}
|
||||
|
||||
@@ -57,6 +65,19 @@ pub fn format_uptime(secs: u64) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pack a dotted-quad IPv4 string into a u32 for numeric ordering, so
|
||||
/// "10.255.1.9" sorts before "10.255.1.10" (a plain string sort gets this
|
||||
/// wrong). Anything unparseable sorts first (0).
|
||||
fn ip_to_u32(s: &str) -> u32 {
|
||||
let mut parts = s.split('.');
|
||||
let mut acc = 0u32;
|
||||
for _ in 0..4 {
|
||||
let octet: u32 = parts.next().and_then(|p| p.trim().parse().ok()).unwrap_or(0);
|
||||
acc = (acc << 8) | (octet & 0xff);
|
||||
}
|
||||
acc
|
||||
}
|
||||
|
||||
/// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the
|
||||
/// scalar fields the table can display. Absent metrics are `None` / empty /
|
||||
/// 0.0 and render as a blank cell.
|
||||
@@ -361,6 +382,8 @@ impl Column {
|
||||
Column::TuningPercent => {
|
||||
SortKey::Num(r.tuning_percent.map(|v| v as f64).unwrap_or(none))
|
||||
}
|
||||
// IP sorts numerically (u32 fits exactly in f64), not lexically.
|
||||
Column::Ip => SortKey::Num(ip_to_u32(&r.ip) as f64),
|
||||
_ => SortKey::Str(self.cell(r).to_lowercase()),
|
||||
}
|
||||
}
|
||||
@@ -522,16 +545,21 @@ impl ViewState {
|
||||
.filter(|&i| self.passes_filters(&rows[i]))
|
||||
.collect();
|
||||
if let Some((col, asc)) = self.sort {
|
||||
idx.sort_by(|&a, &b| {
|
||||
let ka = col.sort_key(&rows[a]);
|
||||
let kb = col.sort_key(&rows[b]);
|
||||
// Decorate-sort-undecorate: compute each row's sort key exactly once
|
||||
// (a string key allocates), not twice per comparison.
|
||||
let mut keyed: Vec<(SortKey, usize)> =
|
||||
idx.iter().map(|&i| (col.sort_key(&rows[i]), i)).collect();
|
||||
keyed.sort_by(|(ka, _), (kb, _)| {
|
||||
let ord = match (ka, kb) {
|
||||
(SortKey::Num(x), SortKey::Num(y)) => x.partial_cmp(&y).unwrap_or(std::cmp::Ordering::Equal),
|
||||
(SortKey::Str(x), SortKey::Str(y)) => x.cmp(&y),
|
||||
(SortKey::Num(x), SortKey::Num(y)) => {
|
||||
x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal)
|
||||
}
|
||||
(SortKey::Str(x), SortKey::Str(y)) => x.cmp(y),
|
||||
_ => std::cmp::Ordering::Equal,
|
||||
};
|
||||
if asc { ord } else { ord.reverse() }
|
||||
});
|
||||
idx = keyed.into_iter().map(|(_, i)| i).collect();
|
||||
}
|
||||
idx
|
||||
}
|
||||
@@ -812,4 +840,221 @@ mod tests {
|
||||
assert!(r.selected, "selection preserved across upsert");
|
||||
assert_eq!(r.hashrate_ths, 12.3, "data updated");
|
||||
}
|
||||
|
||||
// ---- harness-driven additions (correctness + coverage) ----
|
||||
|
||||
#[test]
|
||||
fn format_si_handles_zero_negative_and_nonfinite() {
|
||||
assert_eq!(format_si(0.0, "W"), "0 W");
|
||||
assert_eq!(format_si(-5.0, "W"), "0 W");
|
||||
assert_eq!(format_si(f64::NAN, "W"), "0 W");
|
||||
assert_eq!(format_si(f64::INFINITY, "H/s"), "0 H/s");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_si_rolls_over_at_rounding_boundary() {
|
||||
// A mantissa that rounds up to 1000 must advance the prefix, never print
|
||||
// a 4-digit number (spec: at most 2 digits + 1 decimal after the prefix).
|
||||
assert_eq!(format_si(999.9, "W"), "1.0 kW");
|
||||
assert_eq!(format_si(999_990.0, "W"), "1.0 MW");
|
||||
assert_eq!(format_si(1000.0, "W"), "1.0 kW");
|
||||
// [99.95, 100) rounds to 100 and drops the decimal (>=100 rule).
|
||||
assert_eq!(format_si(99.95, "W"), "100 W");
|
||||
assert_eq!(format_si(45.6, "W"), "45.6 W");
|
||||
assert_eq!(format_si(250.0, "W"), "250 W");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_uptime_boundaries() {
|
||||
assert_eq!(format_uptime(0), "");
|
||||
assert_eq!(format_uptime(59), "59s");
|
||||
assert_eq!(format_uptime(60), "1m");
|
||||
assert_eq!(format_uptime(3599), "59m");
|
||||
assert_eq!(format_uptime(3600), "1h 0m");
|
||||
assert_eq!(format_uptime(86_399), "23h 59m");
|
||||
assert_eq!(format_uptime(86_400), "1d 0h");
|
||||
assert_eq!(format_uptime(90_061), "1d 1h");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ip_column_sorts_numerically() {
|
||||
// A plain string sort puts "10.255.1.10" before "10.255.1.2"; the IP
|
||||
// column must order by numeric value instead.
|
||||
let rows = vec![
|
||||
MinerRow { ip: "10.255.1.10".into(), ..Default::default() },
|
||||
MinerRow { ip: "10.255.1.2".into(), ..Default::default() },
|
||||
MinerRow { ip: "10.255.1.112".into(), ..Default::default() },
|
||||
MinerRow { ip: "10.255.1.9".into(), ..Default::default() },
|
||||
];
|
||||
let idx = ViewState::default().view(&rows); // default = Ip ascending
|
||||
let order: Vec<&str> = idx.iter().map(|&i| rows[i].ip.as_str()).collect();
|
||||
assert_eq!(order, ["10.255.1.2", "10.255.1.9", "10.255.1.10", "10.255.1.112"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upsert_into_new_ip_inserts_and_returns_true() {
|
||||
let mut rows = bench_fleet();
|
||||
let n0 = rows.len();
|
||||
let fresh = MinerRow { ip: "10.9.9.9".into(), ..Default::default() };
|
||||
let is_new = fresh.upsert_into(&mut rows);
|
||||
assert!(is_new, "a never-seen IP is an insert");
|
||||
assert_eq!(rows.len(), n0 + 1);
|
||||
assert!(rows.iter().any(|r| r.ip == "10.9.9.9"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cell_light_three_states() {
|
||||
let on = MinerRow { light_flashing: Some(true), ..Default::default() };
|
||||
let off = MinerRow { light_flashing: Some(false), ..Default::default() };
|
||||
let unknown = MinerRow { light_flashing: None, ..Default::default() };
|
||||
assert_eq!(Column::Light.cell(&on), "on");
|
||||
assert_eq!(Column::Light.cell(&off), "off");
|
||||
assert_eq!(Column::Light.cell(&unknown), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cell_pool_slots_including_out_of_range() {
|
||||
let r = MinerRow {
|
||||
pools: vec![
|
||||
("stratum+tcp://a:1".into(), "wA".into()),
|
||||
("stratum+tcp://b:2".into(), "wB".into()),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(Column::Pool1Url.cell(&r), "stratum+tcp://a:1");
|
||||
assert_eq!(Column::Pool1Worker.cell(&r), "wA");
|
||||
assert_eq!(Column::Pool2Url.cell(&r), "stratum+tcp://b:2");
|
||||
assert_eq!(Column::Pool2Worker.cell(&r), "wB");
|
||||
// Third pool is unconfigured -> blank, not a panic.
|
||||
assert_eq!(Column::Pool3Url.cell(&r), "");
|
||||
assert_eq!(Column::Pool3Worker.cell(&r), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_filters_ands_across_columns() {
|
||||
let rows = vec![
|
||||
MinerRow { ip: "10.0.0.1".into(), is_mining: true, model: "A".into(), ..Default::default() },
|
||||
MinerRow { ip: "10.0.0.2".into(), is_mining: true, model: "B".into(), ..Default::default() },
|
||||
MinerRow { ip: "10.0.0.3".into(), is_mining: false, model: "A".into(), ..Default::default() },
|
||||
];
|
||||
let mut view = ViewState::default();
|
||||
view.filters.insert(Column::Status, HashSet::from(["hashing".to_string()]));
|
||||
view.filters.insert(Column::Model, HashSet::from(["A".to_string()]));
|
||||
let idx = view.view(&rows);
|
||||
assert_eq!(idx.len(), 1, "only the hashing AND model-A row passes");
|
||||
assert_eq!(rows[idx[0]].ip, "10.0.0.1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn passes_filters_ors_within_one_column() {
|
||||
let rows = bench_fleet();
|
||||
let mut view = ViewState::default();
|
||||
view.filters.insert(
|
||||
Column::Status,
|
||||
HashSet::from(["slow".to_string(), "not hashing".to_string()]),
|
||||
);
|
||||
let idx = view.view(&rows);
|
||||
// fixtures: 1 slow + 2 not-hashing.
|
||||
assert_eq!(idx.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apply_visible_reorder_rejects_non_permutation_same_length() {
|
||||
let mut view = ViewState::default();
|
||||
let before = view.order.clone();
|
||||
let hidden = *view
|
||||
.order
|
||||
.iter()
|
||||
.find(|c| **c != Column::Ip && !view.visible.contains(c))
|
||||
.expect("a hidden column exists by default");
|
||||
let mut disp = view.display_columns(); // Ip first, correct length
|
||||
disp[1] = hidden; // same length + Ip first, but no longer a permutation
|
||||
view.apply_visible_reorder(&disp);
|
||||
assert_eq!(view.order, before, "a same-length non-permutation must be ignored");
|
||||
}
|
||||
|
||||
/// Microbenchmark: the DEFAULT view (Ip ascending) at 5000 rows. The existing
|
||||
/// bench_view_pipeline overrides sort to Hashrate, so it never exercised the
|
||||
/// default path (previously a lexical string sort).
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn bench_view_pipeline_default_sort() {
|
||||
use std::time::Instant;
|
||||
let rows = synthetic_fleet(5000);
|
||||
let view = ViewState::default();
|
||||
let iters = 200u32;
|
||||
let t = Instant::now();
|
||||
let mut sink = 0usize;
|
||||
for _ in 0..iters {
|
||||
sink += view.view(&rows).len();
|
||||
}
|
||||
let per = t.elapsed() / iters;
|
||||
println!("bench_view_pipeline_default_sort: {:?}/op (sink={sink})", per);
|
||||
assert!(per.as_millis() < 60, "default (Ip) sort regressed: {per:?}/op");
|
||||
}
|
||||
|
||||
/// Microbenchmark: sort by every column once, at 5000 rows. Guards the
|
||||
/// decorate-sort-undecorate path (string columns must not re-allocate keys
|
||||
/// per comparison).
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn bench_sort_by_each_column() {
|
||||
use std::time::Instant;
|
||||
let rows = synthetic_fleet(5000);
|
||||
let iters = 10u32;
|
||||
let mut worst = std::time::Duration::ZERO;
|
||||
for &col in ALL_COLUMNS.iter() {
|
||||
let mut view = ViewState::default();
|
||||
view.sort = Some((col, false));
|
||||
let t = Instant::now();
|
||||
let mut sink = 0usize;
|
||||
for _ in 0..iters {
|
||||
sink += view.view(&rows).len();
|
||||
}
|
||||
let per = t.elapsed() / iters;
|
||||
if per > worst {
|
||||
worst = per;
|
||||
}
|
||||
assert!(per.as_millis() < 120, "{col:?} sort regressed: {per:?}/op (sink={sink})");
|
||||
}
|
||||
println!("bench_sort_by_each_column: worst column = {:?}/op", worst);
|
||||
}
|
||||
|
||||
/// Microbenchmark: filtered view (one selective predicate) at 5000 rows.
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn bench_view_pipeline_with_filter() {
|
||||
use std::time::Instant;
|
||||
let rows = synthetic_fleet(5000);
|
||||
let mut view = ViewState::default();
|
||||
view.filters.insert(Column::Model, HashSet::from(["Model-3".to_string()]));
|
||||
view.sort = Some((Column::Hashrate, false));
|
||||
let iters = 200u32;
|
||||
let t = Instant::now();
|
||||
let mut sink = 0usize;
|
||||
for _ in 0..iters {
|
||||
sink += view.view(&rows).len();
|
||||
}
|
||||
let per = t.elapsed() / iters;
|
||||
println!("bench_view_pipeline_with_filter: {sink} avg matches, {:?}/op", per);
|
||||
assert!(per.as_millis() < 60, "filtered view() regressed: {per:?}/op");
|
||||
}
|
||||
|
||||
/// Microbenchmark: cold-start fleet population via upsert_into (the O(n) scan
|
||||
/// per insert; documents the quadratic worst case).
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn bench_upsert_cold_start_population() {
|
||||
use std::time::Instant;
|
||||
let n = 3000u32;
|
||||
let fresh = synthetic_fleet(n);
|
||||
let t = Instant::now();
|
||||
let mut rows: Vec<MinerRow> = Vec::new();
|
||||
for r in fresh {
|
||||
r.upsert_into(&mut rows);
|
||||
}
|
||||
let elapsed = t.elapsed();
|
||||
println!("bench_upsert_cold_start_population: {n} rows cold-start = {:?}", elapsed);
|
||||
assert!(elapsed.as_millis() < 2000, "cold-start upsert regressed: {elapsed:?} for {n} rows");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user