fix(dashboard): target page reloads findings, SBOM and CRA status when a scan finishes
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 13m14s
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 13m14s
The scan history on the target page already polled while a run was running, but the cards above it (offene Befunde, SBOM components and known vulnerabilities, CRA status, detected facts) were loaded once and stayed at their old values until a manual reload. ScanRunList now reports a run it saw running that has finished (on_finished), and the target page reloads those resources then. The transition is a pure function with a unit test. A poll no longer re-expects an already expected started scan, so the list stops polling right after the run finishes instead of up to a minute later. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
1 parent
e1bf9e861c
commit
5fe9562536
2 files changed
+77
-10
No files matched your search
@@ -33,18 +33,30 @@ const EXPECT_RUN_POLLS: u32 = 12;
|
||||
/// `started` counts the scans started on this page: each one makes the list
|
||||
/// look again until the new run shows up, even when every run before it
|
||||
/// had finished.
|
||||
///
|
||||
/// `on_finished` is called when a run seen running here has finished, so the
|
||||
/// page can reload what the scan changed (findings, SBOM, CRA status).
|
||||
#[component]
|
||||
pub fn ScanRunList(target_id: String, started: Option<Signal<u32>>) -> Element {
|
||||
pub fn ScanRunList(
|
||||
target_id: String,
|
||||
started: Option<Signal<u32>>,
|
||||
on_finished: Option<EventHandler<()>>,
|
||||
) -> Element {
|
||||
let lang = use_lang()();
|
||||
let id = use_signal(|| target_id.clone());
|
||||
// A scan was started here and its run has not been seen running yet.
|
||||
let mut expect_run = use_signal(|| false);
|
||||
// How many of the `started` scans were already expected: a poll reruns
|
||||
// the resource, and must not expect the same scan again.
|
||||
let mut expected_starts = use_signal(|| 0u32);
|
||||
// Only the browser build restarts it (the polling below).
|
||||
#[cfg_attr(not(feature = "web"), allow(unused_mut))]
|
||||
let mut runs = use_resource(move || async move {
|
||||
// Reading `started` reruns this as soon as a scan is started.
|
||||
if let Some(started) = started {
|
||||
if started() > 0 {
|
||||
let count = started();
|
||||
if count > *expected_starts.peek() {
|
||||
expected_starts.set(count);
|
||||
expect_run.set(true);
|
||||
}
|
||||
}
|
||||
@@ -58,13 +70,16 @@ pub fn ScanRunList(target_id: String, started: Option<Signal<u32>>) -> Element {
|
||||
let Some(Some(list)) = runs.read().clone() else {
|
||||
return;
|
||||
};
|
||||
for run in &list {
|
||||
let id = run.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||
if run.status == ScanRunStatus::Running {
|
||||
expect_run.set(false);
|
||||
seen_running.write().insert(id);
|
||||
} else if seen_running.peek().contains(&id) && !finished_here.peek().contains(&id) {
|
||||
finished_here.write().insert(id);
|
||||
let (running, finished) =
|
||||
run_transitions(&list, &seen_running.peek(), &finished_here.peek());
|
||||
if !running.is_empty() {
|
||||
expect_run.set(false);
|
||||
seen_running.write().extend(running);
|
||||
}
|
||||
if !finished.is_empty() {
|
||||
finished_here.write().extend(finished);
|
||||
if let Some(on_finished) = on_finished {
|
||||
on_finished.call(());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -134,6 +149,26 @@ pub fn ScanRunList(target_id: String, started: Option<Signal<u32>>) -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
/// What one look at the history changed: the ids of the runs now running,
|
||||
/// and of those seen running before that have finished since (each only once).
|
||||
fn run_transitions(
|
||||
runs: &[ScanRun],
|
||||
seen_running: &HashSet<String>,
|
||||
finished_here: &HashSet<String>,
|
||||
) -> (Vec<String>, Vec<String>) {
|
||||
let mut running = Vec::new();
|
||||
let mut finished = Vec::new();
|
||||
for run in runs {
|
||||
let id = run.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||
if run.status == ScanRunStatus::Running {
|
||||
running.push(id);
|
||||
} else if seen_running.contains(&id) && !finished_here.contains(&id) {
|
||||
finished.push(id);
|
||||
}
|
||||
}
|
||||
(running, finished)
|
||||
}
|
||||
|
||||
/// One run: a status line, then its error and skipped stages, if any.
|
||||
fn scan_run_card(run: &ScanRun, lang: Lang) -> Element {
|
||||
let (badge, status) = status_badge(&run.status);
|
||||
@@ -457,6 +492,28 @@ pub fn phase(phase: &ScanPhase) -> Text {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_run_seen_running_counts_as_finished_once() {
|
||||
let mut run = ScanRun::new("t".into(), compliance_core::models::ScanTrigger::Manual);
|
||||
// A run without an id is keyed by the empty string.
|
||||
let id = String::new();
|
||||
let none = HashSet::new();
|
||||
|
||||
let (running, finished) = run_transitions(std::slice::from_ref(&run), &none, &none);
|
||||
assert_eq!((running, finished), (vec![id.clone()], vec![]));
|
||||
|
||||
run.status = ScanRunStatus::Completed;
|
||||
let seen = HashSet::from([id.clone()]);
|
||||
let (running, finished) = run_transitions(std::slice::from_ref(&run), &seen, &none);
|
||||
assert_eq!((running, finished), (vec![], vec![id.clone()]));
|
||||
|
||||
// Already reported, or never seen running (an old run): nothing new.
|
||||
let (_, finished) = run_transitions(std::slice::from_ref(&run), &seen, &seen);
|
||||
assert!(finished.is_empty());
|
||||
let (_, finished) = run_transitions(std::slice::from_ref(&run), &none, &none);
|
||||
assert!(finished.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_stepper_marks_done_current_and_pending_phases() {
|
||||
let mut run = ScanRun::new("t".into(), compliance_core::models::ScanTrigger::Manual);
|
||||
|
||||
@@ -277,7 +277,17 @@ pub fn TargetPage(id: String) -> Element {
|
||||
div { class: "target-columns",
|
||||
section { class: "card",
|
||||
div { class: "target-card-head", h3 { {tx::SCAN_RUNS.get(lang)} } }
|
||||
div { class: "target-card-body", ScanRunList { target_id: id.clone(), started: scans_started } }
|
||||
div { class: "target-card-body", ScanRunList {
|
||||
target_id: id.clone(),
|
||||
started: scans_started,
|
||||
// A finished scan changed the findings, the SBOM and
|
||||
// the CRA status: load them again.
|
||||
on_finished: move |_| {
|
||||
status.restart();
|
||||
open_findings.restart();
|
||||
target.restart();
|
||||
},
|
||||
} }
|
||||
}
|
||||
section { class: "card",
|
||||
div { class: "target-card-head", h3 { {tx::SCOPE.get(lang)} } }
|
||||
|
||||
Reference in new issue
Block a user