From 46f1c500ceeea30c417bfdeddab3cdae83c2bd00 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:00:23 +0000 Subject: [PATCH 01/19] feat(server): acknowledge ongoing attention conditions as audit events The Overview's attention list could only acknowledge runs, so a known condition that couldn't be fixed today, such as a late source, an overdue schedule or nodes out of date, stayed at the top for everyone. - POST /api/control/locations/{location}/targets/{target}/attention-acknowledgements marks a condition handled as it looks now: a key (its kind and subject) and a shape (counts, members, error codes; never message text, which can hold relative times), or withdraws the mark. GET lists each condition's latest acknowledgement from the last two days, with who, when and until when. - An acknowledgement holds for 24 hours. Acknowledging the same shape again while it holds changes nothing; a new shape, or a lapsed acknowledgement, is recorded again. Comparing a later state with the shape is left to the client, which knows what makes each condition worse. - Same permission and retries as acknowledging a run: anyone who can see the target's runs, and an event ID applies once. Each change is an `attention.acknowledged` or `attention.acknowledgement_withdrawn` audit event, so there is no new table, and it signals the target's runs topic, so open Overviews reload. --- clients/typescript/src/schema.d.ts | 138 +++++++++++++ .../src/acknowledgements/constants.rs | 16 ++ .../main/acknowledge_person_attention.rs | 132 ++++++++++++ .../list_person_attention_acknowledgements.rs | 71 +++++++ .../src/acknowledgements/main/mod.rs | 2 + .../src/acknowledgements/mod.rs | 5 +- .../src/acknowledgements/models.rs | 29 +++ .../authentication/password_sessions.rs | 5 + .../_helpers/resources/person_operations.rs | 56 ++++- .../sqlbuild-orchestration/src/api/models.rs | 2 + .../src/store/_helpers/changes.rs | 14 +- .../src/store/models.rs | 2 + .../api/test_attention_acknowledgements.rs | 195 ++++++++++++++++++ .../tests/api/test_contracts.rs | 2 + 14 files changed, 661 insertions(+), 8 deletions(-) create mode 100644 crates/sqlbuild-orchestration/src/acknowledgements/constants.rs create mode 100644 crates/sqlbuild-orchestration/src/acknowledgements/main/acknowledge_person_attention.rs create mode 100644 crates/sqlbuild-orchestration/src/acknowledgements/main/list_person_attention_acknowledgements.rs create mode 100644 crates/sqlbuild-orchestration/tests/api/test_attention_acknowledgements.rs diff --git a/clients/typescript/src/schema.d.ts b/clients/typescript/src/schema.d.ts index e2282f59ae..a31a2a3ce9 100644 --- a/clients/typescript/src/schema.d.ts +++ b/clients/typescript/src/schema.d.ts @@ -274,6 +274,22 @@ export interface paths { patch?: never; trace?: never; }; + "/api/control/locations/{location_id}/targets/{target}/attention-acknowledgements": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get: operations["listAttentionAcknowledgements"]; + put?: never; + post: operations["acknowledgeAttention"]; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/control/locations/{location_id}/targets/{target}/catalog": { parameters: { query?: never; @@ -1631,6 +1647,39 @@ export interface components { decision_id?: string | null; error: string; }; + /** @description A condition whose latest acknowledgement event marks it handled. */ + AttentionAcknowledgement: { + /** Format: date-time */ + acknowledged_at: string; + /** @description The person's name, or the audit actor when the person no longer exists. */ + acknowledged_by: string; + key: string; + shape: Record; + /** + * Format: date-time + * @description When the acknowledgement lapses even if the condition never changes. + */ + until: string; + }; + /** + * @description Marks an ongoing attention condition handled, as it looks now, or withdraws the mark; retried with + * the same event ID it applies once. + */ + AttentionAcknowledgementRequest: { + acknowledged: boolean; + /** Format: uuid */ + event_id: string; + /** + * @description The condition: its kind and subject, stable while it lasts, such as `stale_sources` or + * `event:tick_overdue:`. + */ + key: string; + /** + * @description What the condition looked like (counts, members, error codes), which later states are compared + * with; a JSON object of at most 8 KiB. Never message text, which can hold relative times. + */ + shape: Record; + }; AuthenticationDenial: { error: string; /** Format: uuid */ @@ -4911,6 +4960,95 @@ export interface operations { }; }; }; + listAttentionAcknowledgements: { + parameters: { + query?: never; + header?: never; + path: { + location_id: string; + target: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Conditions marked handled in the last two days, lapsed ones included */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["AttentionAcknowledgement"][]; + }; + }; + /** @description Session rejected */ + 401: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["ApiErrorBody"]; + }; + }; + }; + }; + acknowledgeAttention: { + parameters: { + query?: never; + header: { + "x-sqb-csrf": string; + }; + path: { + location_id: string; + target: string; + }; + cookie?: never; + }; + requestBody: { + content: { + "application/json": components["schemas"]["AttentionAcknowledgementRequest"]; + }; + }; + responses: { + /** @description Whether the condition's acknowledgement changed */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["MutationResponse"]; + }; + }; + /** @description The key or shape is invalid, or the event ID was reused */ + 400: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + /** @description Session rejected */ + 401: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["ApiErrorBody"]; + }; + }; + }; + }; readPersonCatalog: { parameters: { query: { diff --git a/crates/sqlbuild-orchestration/src/acknowledgements/constants.rs b/crates/sqlbuild-orchestration/src/acknowledgements/constants.rs new file mode 100644 index 0000000000..d2661c8fe1 --- /dev/null +++ b/crates/sqlbuild-orchestration/src/acknowledgements/constants.rs @@ -0,0 +1,16 @@ +//! Limits of attention acknowledgements. + +use chrono::Duration; + +/// An acknowledged condition comes back after this long even if it never changes. +pub(crate) fn attention_snooze() -> Duration { + Duration::hours(24) +} +/// Listed acknowledgements: a lapsed one stays readable for a day, so the Overview can say why the condition is back. +pub(crate) fn attention_listing_window() -> Duration { + Duration::hours(48) +} +pub(crate) const MAX_KEY_CHARS: usize = 256; +pub(crate) const MAX_SHAPE_BYTES: usize = 8 * 1024; +pub(crate) const ACKNOWLEDGED: &str = "attention.acknowledged"; +pub(crate) const WITHDRAWN: &str = "attention.acknowledgement_withdrawn"; diff --git a/crates/sqlbuild-orchestration/src/acknowledgements/main/acknowledge_person_attention.rs b/crates/sqlbuild-orchestration/src/acknowledgements/main/acknowledge_person_attention.rs new file mode 100644 index 0000000000..2160a67a0b --- /dev/null +++ b/crates/sqlbuild-orchestration/src/acknowledgements/main/acknowledge_person_attention.rs @@ -0,0 +1,132 @@ +//! Anyone who can see a location's runs marks an attention condition handled, as it looks now, as an +//! audit event; the same permission and retry rules as acknowledging a run. + +use serde_json::{Value, json}; +use uuid::Uuid; + +use crate::acknowledgements::constants::{ + ACKNOWLEDGED, MAX_KEY_CHARS, MAX_SHAPE_BYTES, WITHDRAWN, attention_snooze, +}; +use crate::acknowledgements::models::AttentionAcknowledgementRequest; +use crate::authorization::main::decisions::authorize_listing::authorize_listing; +use crate::credentials::main::audit::append_audit::append_audit; +use crate::credentials::models::{AuditContext, DefaultRole}; +use crate::store::errors::ControlError; +use crate::store::main::{begin::begin, commit::commit, query::query}; +use crate::store::models::{Change, ControlStore, Parameter, TransactionMode}; + +fn validate(request: &AttentionAcknowledgementRequest) -> Result<(), ControlError> { + let key = request.key.as_str(); + if key.trim().is_empty() + || key.chars().count() > MAX_KEY_CHARS + || key.chars().any(char::is_control) + { + return Err(ControlError::Invalid(format!( + "attention key must be 1 to {MAX_KEY_CHARS} characters without control characters" + ))); + } + if !request.shape.is_object() { + return Err(ControlError::Invalid( + "attention shape must be a JSON object".into(), + )); + } + if request.shape.to_string().len() > MAX_SHAPE_BYTES { + return Err(ControlError::Invalid(format!( + "attention shape must be at most {MAX_SHAPE_BYTES} bytes" + ))); + } + Ok(()) +} + +/// Returns whether the condition's acknowledgement changed. Acknowledging again applies when the shape +/// differs or the last acknowledgement has lapsed; each change signals the target's runs, so open +/// Overviews reload. +pub async fn acknowledge_person_attention( + store: &ControlStore, + (context, credentials): (&AuditContext, Uuid), + (location_id, target, request): (Uuid, &str, &AttentionAcknowledgementRequest), + default_role: DefaultRole, +) -> Result { + let (transaction, context) = authorize_listing( + begin(store, TransactionMode::Write).await?, + (context, credentials), + (location_id, target), + default_role, + ) + .await?; + validate(request)?; + let body = + serde_json::to_value(request).map_err(|error| ControlError::Invalid(error.to_string()))?; + let (transaction, retried) = query( + transaction, + "SELECT scope_json FROM sqb_security_audit WHERE event_id=$1", + vec![Parameter::Id(request.event_id)], + ) + .await?; + if let Some(previous) = retried.first() { + if previous["scope_json"].get("request") != Some(&body) { + return Err(ControlError::Invalid( + "acknowledgement event ID already has different content".into(), + )); + } + commit(transaction).await?; + return Ok(false); + } + let (transaction, latest) = query( + transaction, + &format!( + "SELECT action, occurred_at, scope_json ->> 'shape' AS shape FROM sqb_security_audit \ + WHERE action IN ('{ACKNOWLEDGED}','{WITHDRAWN}') AND scope_json ->> 'location_id'=$1 \ + AND scope_json ->> 'target'=$2 AND scope_json ->> 'key'=$3 ORDER BY storage_id DESC LIMIT 1" + ), + vec![ + Parameter::Text(location_id.to_string()), + Parameter::Text(target.into()), + Parameter::Text(request.key.clone()), + ], + ) + .await?; + let previous = latest.first(); + let acknowledged = previous.is_some_and(|row| row["action"].as_str() == Some(ACKNOWLEDGED)); + let shape: Value = previous + .and_then(|row| row["shape"].as_str()) + .and_then(|text| serde_json::from_str(text).ok()) + .unwrap_or(Value::Null); + let at = previous.and_then(|row| { + serde_json::from_value::>(row["occurred_at"].clone()).ok() + }); + let holding = acknowledged + && shape == request.shape + && at.is_some_and(|at| transaction.now < at + attention_snooze()); + // Acknowledging is a no-op while the same shape's acknowledgement holds; withdrawing, while none stands. + let unchanged = if request.acknowledged { + holding + } else { + !acknowledged + }; + if unchanged { + commit(transaction).await?; + return Ok(false); + } + let action = if request.acknowledged { + ACKNOWLEDGED + } else { + WITHDRAWN + }; + let mut transaction = append_audit( + transaction, + &context, + (request.event_id, action), + ( + json!({"location_id": location_id, "target": target, "key": request.key, "shape": request.shape, "request": body}), + json!({"acknowledged": acknowledged, "shape": shape}), + json!({"acknowledged": request.acknowledged, "shape": request.shape}), + ), + ) + .await?; + transaction + .changes + .insert(Change::Attention(location_id, target.into())); + commit(transaction).await?; + Ok(true) +} diff --git a/crates/sqlbuild-orchestration/src/acknowledgements/main/list_person_attention_acknowledgements.rs b/crates/sqlbuild-orchestration/src/acknowledgements/main/list_person_attention_acknowledgements.rs new file mode 100644 index 0000000000..2bd54880e7 --- /dev/null +++ b/crates/sqlbuild-orchestration/src/acknowledgements/main/list_person_attention_acknowledgements.rs @@ -0,0 +1,71 @@ +//! A condition's acknowledgement is its latest acknowledgement event, projected from the audit log. + +use std::collections::BTreeMap; + +use chrono::{DateTime, Utc}; +use serde_json::Value; +use uuid::Uuid; + +use crate::acknowledgements::constants::{ + ACKNOWLEDGED, WITHDRAWN, attention_listing_window, attention_snooze, +}; +use crate::acknowledgements::models::AttentionAcknowledgement; +use crate::authorization::main::decisions::authorize_listing::authorize_listing; +use crate::credentials::models::{AuditContext, DefaultRole}; +use crate::store::errors::ControlError; +use crate::store::main::{begin::begin, commit::commit, query::query}; +use crate::store::models::{ControlStore, Parameter, TransactionMode}; + +/// Conditions whose latest event acknowledges them, from the last two days; a lapsed one is listed with +/// its `until`, so the Overview can say why the condition is back. +pub async fn list_person_attention_acknowledgements( + store: &ControlStore, + (context, credentials): (&AuditContext, Uuid), + (location_id, target): (Uuid, &str), + default_role: DefaultRole, +) -> Result, ControlError> { + let (transaction, _) = authorize_listing( + begin(store, TransactionMode::Write).await?, + (context, credentials), + (location_id, target), + default_role, + ) + .await?; + let since = transaction.now - attention_listing_window(); + let (transaction, rows) = query( + transaction, + &format!( + "SELECT a.action, COALESCE(p.name, a.actor) AS actor, a.occurred_at, a.scope_json ->> 'key' AS key, \ + a.scope_json ->> 'shape' AS shape \ + FROM sqb_security_audit a LEFT JOIN sqb_principals p ON 'principal:' || CAST(p.principal_id AS TEXT)=a.actor \ + WHERE a.occurred_at >= $1 AND a.action IN ('{ACKNOWLEDGED}','{WITHDRAWN}') \ + AND a.scope_json ->> 'location_id'=$2 AND a.scope_json ->> 'target'=$3 ORDER BY a.storage_id" + ), + vec![ + Parameter::Time(since), + Parameter::Text(location_id.to_string()), + Parameter::Text(target.into()), + ], + ) + .await?; + commit(transaction).await?; + let mut latest: BTreeMap> = BTreeMap::new(); + for row in rows { + let key = row["key"].as_str().unwrap_or_default().to_owned(); + let acknowledged_at: DateTime = serde_json::from_value(row["occurred_at"].clone()) + .map_err(|error| ControlError::Schema(format!("acknowledgement time: {error}")))?; + let marked = + (row["action"].as_str() == Some(ACKNOWLEDGED)).then(|| AttentionAcknowledgement { + key: key.clone(), + shape: row["shape"] + .as_str() + .and_then(|text| serde_json::from_str(text).ok()) + .unwrap_or(Value::Null), + acknowledged_by: row["actor"].as_str().unwrap_or_default().into(), + acknowledged_at, + until: acknowledged_at + attention_snooze(), + }); + latest.insert(key, marked); + } + Ok(latest.into_values().flatten().collect()) +} diff --git a/crates/sqlbuild-orchestration/src/acknowledgements/main/mod.rs b/crates/sqlbuild-orchestration/src/acknowledgements/main/mod.rs index 7078a48559..1641de4de1 100644 --- a/crates/sqlbuild-orchestration/src/acknowledgements/main/mod.rs +++ b/crates/sqlbuild-orchestration/src/acknowledgements/main/mod.rs @@ -1,2 +1,4 @@ +pub mod acknowledge_person_attention; pub mod acknowledge_person_run; pub mod list_person_acknowledgements; +pub mod list_person_attention_acknowledgements; diff --git a/crates/sqlbuild-orchestration/src/acknowledgements/mod.rs b/crates/sqlbuild-orchestration/src/acknowledgements/mod.rs index 4fe9f2045f..3fd2b1ad5f 100644 --- a/crates/sqlbuild-orchestration/src/acknowledgements/mod.rs +++ b/crates/sqlbuild-orchestration/src/acknowledgements/mod.rs @@ -1,4 +1,7 @@ -//! People mark problem runs handled for everyone who can see them; the audit log holds every change. +//! People mark problem runs, and ongoing attention conditions, handled for everyone who can see them; +//! the audit log holds every change, so acknowledgements need no table of their own. + +pub(crate) mod constants; pub mod main; pub mod models; diff --git a/crates/sqlbuild-orchestration/src/acknowledgements/models.rs b/crates/sqlbuild-orchestration/src/acknowledgements/models.rs index 3f6c3b108f..22c810f778 100644 --- a/crates/sqlbuild-orchestration/src/acknowledgements/models.rs +++ b/crates/sqlbuild-orchestration/src/acknowledgements/models.rs @@ -21,3 +21,32 @@ pub struct RunAcknowledgement { pub acknowledged_by: String, pub acknowledged_at: DateTime, } + +/// Marks an ongoing attention condition handled, as it looks now, or withdraws the mark; retried with +/// the same event ID it applies once. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)] +#[serde(deny_unknown_fields)] +pub struct AttentionAcknowledgementRequest { + pub event_id: Uuid, + /// The condition: its kind and subject, stable while it lasts, such as `stale_sources` or + /// `event:tick_overdue:`. + pub key: String, + /// What the condition looked like (counts, members, error codes), which later states are compared + /// with; a JSON object of at most 8 KiB. Never message text, which can hold relative times. + #[schema(value_type = Object)] + pub shape: serde_json::Value, + pub acknowledged: bool, +} + +/// A condition whose latest acknowledgement event marks it handled. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)] +pub struct AttentionAcknowledgement { + pub key: String, + #[schema(value_type = Object)] + pub shape: serde_json::Value, + /// The person's name, or the audit actor when the person no longer exists. + pub acknowledged_by: String, + pub acknowledged_at: DateTime, + /// When the acknowledgement lapses even if the condition never changes. + pub until: DateTime, +} diff --git a/crates/sqlbuild-orchestration/src/api/_helpers/authentication/password_sessions.rs b/crates/sqlbuild-orchestration/src/api/_helpers/authentication/password_sessions.rs index fd5bbbf923..6bf4479d6c 100644 --- a/crates/sqlbuild-orchestration/src/api/_helpers/authentication/password_sessions.rs +++ b/crates/sqlbuild-orchestration/src/api/_helpers/authentication/password_sessions.rs @@ -147,6 +147,11 @@ pub(crate) fn person_routes() -> Router { get(crate::api::_helpers::resources::person_operations::acknowledgements) .post(crate::api::_helpers::resources::person_operations::acknowledge), ) + .route( + "/api/control/locations/{location_id}/targets/{target}/attention-acknowledgements", + get(crate::api::_helpers::resources::person_operations::attention_acknowledgements) + .post(crate::api::_helpers::resources::person_operations::acknowledge_attention), + ) .route( "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/nodes", get(crate::api::_helpers::resources::person_reads::run_nodes), diff --git a/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_operations.rs b/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_operations.rs index 8cf1037ddb..c11ec0ede3 100644 --- a/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_operations.rs +++ b/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_operations.rs @@ -6,9 +6,14 @@ use axum::extract::{Path, Query, State}; use axum::{Extension, Json}; use uuid::Uuid; +use crate::acknowledgements::main::acknowledge_person_attention::acknowledge_person_attention; use crate::acknowledgements::main::acknowledge_person_run::acknowledge_person_run; use crate::acknowledgements::main::list_person_acknowledgements::list_person_acknowledgements; -use crate::acknowledgements::models::{AcknowledgementRequest, RunAcknowledgement}; +use crate::acknowledgements::main::list_person_attention_acknowledgements::list_person_attention_acknowledgements; +use crate::acknowledgements::models::{ + AcknowledgementRequest, AttentionAcknowledgement, AttentionAcknowledgementRequest, + RunAcknowledgement, +}; use crate::api::errors::ApiError; use crate::api::models::{MutationResponse, RunsQuery}; use crate::credentials::models::AuthenticatedPerson; @@ -211,6 +216,55 @@ pub(crate) async fn acknowledgements( )) } +#[utoipa::path(post, path = "/api/control/locations/{location_id}/targets/{target}/attention-acknowledgements", operation_id = "acknowledgeAttention", + params(("location_id" = Uuid, Path), ("target" = String, Path), ("x-sqb-csrf" = String, Header)), + request_body = AttentionAcknowledgementRequest, + responses((status = 200, body = MutationResponse, description = "Whether the condition's acknowledgement changed"), + (status = 400, description = "The key or shape is invalid, or the event ID was reused"), + (status = 401, description = "Session rejected"), + (status = 403, body = crate::api::models::ApiErrorBody)), security(("session" = []), ("cliSession" = [])))] +pub(crate) async fn acknowledge_attention( + (State(store), Extension(context)): (State, Extension), + (Path((location_id, target)), Extension(default_role)): ( + Path<(Uuid, String)>, + Extension, + ), + Extension(AuthenticatedPerson(principal, _)): Extension, + Json(request): Json, +) -> Result, ApiError> { + Ok(Json(MutationResponse { + applied: acknowledge_person_attention( + &store, + (&context, principal), + (location_id, &target, &request), + default_role, + ) + .await?, + })) +} + +#[utoipa::path(get, path = "/api/control/locations/{location_id}/targets/{target}/attention-acknowledgements", operation_id = "listAttentionAcknowledgements", + params(("location_id" = Uuid, Path), ("target" = String, Path)), + responses((status = 200, body = Vec, description = "Conditions marked handled in the last two days, lapsed ones included"), + (status = 401, description = "Session rejected"), + (status = 403, body = crate::api::models::ApiErrorBody)), security(("session" = []), ("cliSession" = [])))] +pub(crate) async fn attention_acknowledgements( + (State(store), Extension(context)): (State, Extension), + Extension(default_role): Extension, + Path((location_id, target)): Path<(Uuid, String)>, + Extension(AuthenticatedPerson(principal, _)): Extension, +) -> Result>, ApiError> { + Ok(Json( + list_person_attention_acknowledgements( + &store, + (&context, principal), + (location_id, &target), + default_role, + ) + .await?, + )) +} + #[utoipa::path(post, path = "/api/control/triggers", operation_id = "changeTrigger", params(("x-sqb-csrf" = String, Header)), request_body = TriggerChangeRequest, responses((status = 200, body = MutationResponse), (status = 401, description = "Session rejected"), diff --git a/crates/sqlbuild-orchestration/src/api/models.rs b/crates/sqlbuild-orchestration/src/api/models.rs index 8e3ab58dcc..fdb08acbb7 100644 --- a/crates/sqlbuild-orchestration/src/api/models.rs +++ b/crates/sqlbuild-orchestration/src/api/models.rs @@ -29,6 +29,8 @@ use crate::api::_helpers::resources::{ person_operations::recent_runs, person_operations::acknowledge, person_operations::acknowledgements, + person_operations::acknowledge_attention, + person_operations::attention_acknowledgements, person_reads::run_nodes, person_reads::nodes, person_reads::node_states, diff --git a/crates/sqlbuild-orchestration/src/store/_helpers/changes.rs b/crates/sqlbuild-orchestration/src/store/_helpers/changes.rs index cd23dd0052..40f03db514 100644 --- a/crates/sqlbuild-orchestration/src/store/_helpers/changes.rs +++ b/crates/sqlbuild-orchestration/src/store/_helpers/changes.rs @@ -43,12 +43,12 @@ pub(crate) async fn resolve_changes( continue; } let scope = match &change { - Change::Snapshot(location_id, target) | Change::NodeStatus(location_id, target) => { - ChangedScope { - location_id: *location_id, - target: target.clone(), - } - } + Change::Snapshot(location_id, target) + | Change::NodeStatus(location_id, target) + | Change::Attention(location_id, target) => ChangedScope { + location_id: *location_id, + target: target.clone(), + }, Change::Run(id) | Change::Trigger(id) => { let sql = if matches!(change, Change::Run(_)) { "SELECT location_id, target FROM sqb_runs WHERE run_id=$1" @@ -73,6 +73,8 @@ pub(crate) async fn resolve_changes( Change::Trigger(_) => vec![ChangeTopic::Ticks], Change::Snapshot(..) => vec![ChangeTopic::Snapshot, ChangeTopic::NodeStatus], Change::NodeStatus(..) => vec![ChangeTopic::NodeStatus], + // The Overview reads its attention list with the runs, so it reloads on their topic. + Change::Attention(..) => vec![ChangeTopic::Runs], Change::Credentials => continue, }; for topic in topics { diff --git a/crates/sqlbuild-orchestration/src/store/models.rs b/crates/sqlbuild-orchestration/src/store/models.rs index 874305b955..196587bd2e 100644 --- a/crates/sqlbuild-orchestration/src/store/models.rs +++ b/crates/sqlbuild-orchestration/src/store/models.rs @@ -98,6 +98,8 @@ pub(crate) enum Change { Trigger(Uuid), Snapshot(Uuid, String), NodeStatus(Uuid, String), + /// An attention condition of a location's target was acknowledged or withdrawn. + Attention(Uuid, String), Credentials, } diff --git a/crates/sqlbuild-orchestration/tests/api/test_attention_acknowledgements.rs b/crates/sqlbuild-orchestration/tests/api/test_attention_acknowledgements.rs new file mode 100644 index 0000000000..7b46496b4c --- /dev/null +++ b/crates/sqlbuild-orchestration/tests/api/test_attention_acknowledgements.rs @@ -0,0 +1,195 @@ +//! A person who can see a location's runs marks an ongoing condition handled as it looks now; everyone +//! reads who did and until when, a changed condition can be acknowledged again, and the mark withdrawn. + +use serde_json::{Value, json}; +use uuid::Uuid; + +use crate::api::models::{ApiAuthentication, HumanLogin}; +use crate::api::tests::denials_helpers::person_send; +use crate::api::tests::helpers::{start_api_with_authentication, stop_api}; +use crate::credentials::tests::location_helpers::create_location; +use crate::credentials::tests::role_helpers::role_fixture; +use crate::store::main::migrate_store::migrate_store; +use crate::store::tests::store_helpers::{close_test_store, open_test_store, run}; +use crate::store::tests::store_test_types::Backend; + +#[test] +fn given_an_ongoing_condition_when_a_person_acknowledges_it_then_everyone_reads_its_shape_until_it_changes_or_is_withdrawn() + { + for backend in [Backend::Sqlite, Backend::Postgres] { + run(async { + let Some(fixture) = open_test_store(backend).await else { + return; + }; + let store = &fixture.store; + migrate_store(store).await.expect("migrate"); + let roles = role_fixture(store).await; + let inventory = create_location(store, "inventory", "orders-admin") + .await + .expect("location"); + let api = start_api_with_authentication( + store, + ApiAuthentication { + login: HumanLogin::Password("https://control.example.com".into()), + ..ApiAuthentication::default() + }, + ) + .await; + let client = reqwest::Client::new(); + let administrator = ( + roles.administrator.bearer.as_str(), + roles.administrator.csrf.as_str(), + ); + let url = format!( + "{}/api/control/locations/{inventory}/targets/development/attention-acknowledgements", + api.url + ); + let send = |body: Option| { + let (url, client) = (url.clone(), client.clone()); + async move { + let response = + person_send(&client, (&url, administrator.0, administrator.1), body).await; + ( + response.status().as_u16(), + response.json::().await.unwrap_or(Value::Null), + ) + } + }; + let request = |key: &str, shape: Value, acknowledged: bool| json!({"event_id": Uuid::now_v7(), "key": key, "shape": shape, "acknowledged": acknowledged}); + let one_source = json!({"members": ["raw__payments:warn"]}); + let acknowledge = request("stale_sources", one_source.clone(), true); + + let first = send(Some(acknowledge.clone())).await; + let retried = send(Some(acknowledge.clone())).await; + let mut conflicting = acknowledge.clone(); + conflicting["shape"] = json!({"members": []}); + let reused = send(Some(conflicting)).await; + let again = send(Some(request("stale_sources", one_source.clone(), true))).await; + let bad_key = send(Some(request("", json!({}), true))).await; + let bad_shape = send(Some(request( + "stale_sources", + json!(["not", "an", "object"]), + true, + ))) + .await; + let large = send(Some(request( + "stale_sources", + json!({"members": vec!["x".repeat(64); 200]}), + true, + ))) + .await; + assert_eq!( + [ + first.0, + retried.0, + reused.0, + again.0, + bad_key.0, + bad_shape.0, + large.0 + ], + [200, 200, 400, 200, 400, 400, 400], + "{backend:?}: statuses" + ); + assert_eq!( + [ + &first.1["applied"], + &retried.1["applied"], + &again.1["applied"] + ], + [&json!(true), &json!(false), &json!(false)], + "{backend:?}: a retry, or the same shape again while it holds, changes nothing" + ); + + let listed = send(None).await.1; + assert_eq!( + listed.as_array().map(Vec::len), + Some(1), + "{backend:?}: {listed}" + ); + assert_eq!( + ( + &listed[0]["key"], + &listed[0]["shape"], + &listed[0]["acknowledged_by"] + ), + (&json!("stale_sources"), &one_source, &json!("orders-admin")) + ); + let at: chrono::DateTime = + serde_json::from_value(listed[0]["acknowledged_at"].clone()).expect("time"); + let until: chrono::DateTime = + serde_json::from_value(listed[0]["until"].clone()).expect("until"); + assert_eq!( + until - at, + chrono::Duration::hours(24), + "{backend:?}: the snooze" + ); + + // Worse, then acknowledged again as it looks now. + let two_sources = json!({"members": ["raw__payments:warn", "raw__refunds:error"]}); + let worse = send(Some(request("stale_sources", two_sources.clone(), true))).await; + let other = send(Some(request( + "event:tick_overdue:segments_hourly", + json!({"code": "tick_overdue"}), + true, + ))) + .await; + let listed = send(None).await.1; + assert_eq!( + (worse.1["applied"].clone(), other.1["applied"].clone()), + (json!(true), json!(true)) + ); + assert_eq!( + listed + .as_array() + .expect("listing") + .iter() + .map(|a| (a["key"].clone(), a["shape"].clone())) + .collect::>(), + [ + ( + json!("event:tick_overdue:segments_hourly"), + json!({"code": "tick_overdue"}) + ), + (json!("stale_sources"), two_sources) + ], + "{backend:?}: the latest shape per condition" + ); + + let withdrawn = send(Some(request("stale_sources", json!({}), false))).await; + let withdrawn_again = send(Some(request("stale_sources", json!({}), false))).await; + let listed = send(None).await.1; + assert_eq!( + ( + withdrawn.1["applied"].clone(), + withdrawn_again.1["applied"].clone() + ), + (json!(true), json!(false)) + ); + assert_eq!( + listed + .as_array() + .expect("listing") + .iter() + .map(|a| a["key"].clone()) + .collect::>(), + [json!("event:tick_overdue:segments_hourly")] + ); + + // Another target's conditions are its own. + let elsewhere = person_send( + &client, + (&format!("{}/api/control/locations/{inventory}/targets/production/attention-acknowledgements", api.url), administrator.0, administrator.1), + None, + ) + .await; + let elsewhere = elsewhere.json::().await.unwrap_or(Value::Null); + assert!( + elsewhere.as_array().is_none_or(Vec::is_empty), + "{backend:?}: {elsewhere}" + ); + stop_api(api).await; + close_test_store(fixture).await; + }); + } +} diff --git a/crates/sqlbuild-orchestration/tests/api/test_contracts.rs b/crates/sqlbuild-orchestration/tests/api/test_contracts.rs index ea45183fa8..c72ebecf8f 100644 --- a/crates/sqlbuild-orchestration/tests/api/test_contracts.rs +++ b/crates/sqlbuild-orchestration/tests/api/test_contracts.rs @@ -40,6 +40,8 @@ mod statistics_helpers; mod statistics_retention; #[path = "test_acknowledgements.rs"] mod test_acknowledgements; +#[path = "test_attention_acknowledgements.rs"] +mod test_attention_acknowledgements; #[path = "test_catalog_reads.rs"] mod test_catalog_reads; #[path = "test_changes.rs"] From 54a8e8f2aeddbd033e64a736b918e11f413ded5c Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:33:08 +0000 Subject: [PATCH 02/19] feat(ui): acknowledge any attention item; conditions come back when they change - Every item on the Overview's attention list has an "Ack" button: short muted text with a bell, always visible, stronger while its row is hovered. Its accessible name is "Acknowledge" and its tooltip says what it does. - A run is acknowledged for good, as before. An ongoing condition (nodes out of date, late sources, a location or schedule event, a blocked queue, a low calendar) is acknowledged as it looks now, through the new attention-acknowledgements endpoint, and comes back on the list, saying why, when it gets worse: - more nodes changed or behind; - a new late source, or one passing its error threshold; - a higher severity; - a blocked run waiting on something new; - it resolved and came back, as a new event; - its 24 hours end. Shapes hold kinds, subjects, severities and counts, never message text, which holds relative times. Large ones stay small: nodes out of date compare by counts, and more than 50 late sources by counts. - "Acknowledged (N)" lists both kinds with who and when, "for good" or "hidden until it changes", and Undo. - An acknowledged location outage no longer takes its overdue schedules along: they stand on their own. --- ui/e2e/attention-ack.spec.ts | 40 ++++++++++ ui/src/lib/api/client.ts | 3 + ui/src/lib/api/http-client.ts | 31 +++++++- ui/src/lib/api/http-overview.test.ts | 7 +- ui/src/lib/api/http-overview.ts | 9 ++- ui/src/lib/api/mock/build.ts | 3 +- ui/src/lib/api/mock/mock-client.ts | 6 ++ ui/src/lib/api/mock/operate-store.ts | 15 ++++ ui/src/lib/api/types/build.ts | 33 ++++++-- .../build-area/attention-conditions.test.ts | 73 +++++++++++++++++ ui/src/lib/build-area/attention-conditions.ts | 79 +++++++++++++++++++ ui/src/lib/build-area/attention.test.ts | 10 +++ ui/src/lib/build-area/attention.ts | 3 +- ui/src/routes/+page.svelte | 45 ++++++++--- 14 files changed, 329 insertions(+), 28 deletions(-) create mode 100644 ui/e2e/attention-ack.spec.ts create mode 100644 ui/src/lib/build-area/attention-conditions.test.ts create mode 100644 ui/src/lib/build-area/attention-conditions.ts diff --git a/ui/e2e/attention-ack.spec.ts b/ui/e2e/attention-ack.spec.ts new file mode 100644 index 0000000000..6a894ae140 --- /dev/null +++ b/ui/e2e/attention-ack.spec.ts @@ -0,0 +1,40 @@ +import { expect, test } from '@playwright/test'; + +// The Overview's attention list: every item can be acknowledged. A run is hidden for good; an ongoing +// condition until it changes. Both move to "Acknowledged (N)", where anyone can undo them. +test.use({ viewport: { width: 1600, height: 1000 } }); + +test('acknowledging a condition moves it under Acknowledged until it changes, and Undo brings it back', async ({ page }) => { + await page.goto('/?mock'); + const issues = page.locator('section.health .issues'); + const row = issues.locator('.issue', { hasText: 'past the freshness threshold' }); + await expect(row).toBeVisible({ timeout: 20_000 }); + + const ack = row.getByRole('button', { name: 'Acknowledge' }); + await expect(ack).toHaveText('Ack'); + await expect(ack).toHaveAttribute('title', /until it changes/); + await ack.click(); + await expect(row).toHaveCount(0); + + const handled = page.locator('section.health .handled'); + await expect(handled.getByRole('button', { name: /^Acknowledged \(1\)$/ })).toBeVisible(); + await handled.getByRole('button', { name: /^Acknowledged/ }).click(); + const acknowledged = handled.locator('.issue', { hasText: 'past the freshness threshold' }); + await expect(acknowledged).toContainText('Acknowledged by you'); + await expect(acknowledged).toContainText('hidden until it changes'); + + await acknowledged.getByRole('button', { name: 'Undo' }).click(); + await expect(issues.locator('.issue', { hasText: 'past the freshness threshold' })).toBeVisible(); + await expect(handled).toHaveCount(0); +}); + +test('a run is acknowledged for good', async ({ page }) => { + await page.goto('/?mock'); + const row = page.locator('section.health .issues .issue', { hasText: 'core_build partial' }); + await expect(row).toBeVisible({ timeout: 20_000 }); + await expect(row.getByRole('button', { name: 'Acknowledge' })).toHaveAttribute('title', /^Hide this from the attention list for everyone\./); + await row.getByRole('button', { name: 'Acknowledge' }).click(); + const handled = page.locator('section.health .handled'); + await handled.getByRole('button', { name: /^Acknowledged/ }).click(); + await expect(handled.locator('.issue', { hasText: 'core_build partial' })).toContainText('for good'); +}); diff --git a/ui/src/lib/api/client.ts b/ui/src/lib/api/client.ts index eda383756c..03c8f825fc 100644 --- a/ui/src/lib/api/client.ts +++ b/ui/src/lib/api/client.ts @@ -34,6 +34,7 @@ import type { IgnoredAuditFailure, RunCostRow, CostSummary, + ConditionShape, NodeBuildCost, NodeStates, Snapshot, @@ -129,6 +130,8 @@ export interface ApiClient extends PlatformApi { timeline(scope: Scope, window: { since: string; until: string }): Promise; /** Marks a run handled for everyone who can see it, or withdraws the mark; recorded in the audit log. */ acknowledgeRun(scope: Scope, runId: string, acknowledged: boolean): Promise; + /** Acknowledge an ongoing condition as it looks now (`shape`), until it changes, or withdraw that. */ + acknowledgeCondition(scope: Scope, key: string, shape: ConditionShape, acknowledged: boolean): Promise; /** Writes a `cancel_requested` fact; the scheduler then signals the worker. */ cancelRun(scope: Scope, runId: string): Promise; /** `nodes` is required for `selected` and ignored otherwise. */ diff --git a/ui/src/lib/api/http-client.ts b/ui/src/lib/api/http-client.ts index a75a3a54af..acc517f432 100644 --- a/ui/src/lib/api/http-client.ts +++ b/ui/src/lib/api/http-client.ts @@ -21,7 +21,7 @@ import { toSelectionEvaluation, toSelectionVocabulary } from './http-selection'; import type { ChangeSubscription, ChangedChannel, ChangedSignal, ConnectionState } from './signals'; import type { AuthMode, Bootstrap, Capability, Location, NavCounts, PlatformEvent, Scope, Snapshot, WarehouseSync } from './types'; import type { Account, AuditEntry, AuditQuery, ConnectionTest, LocationDetail, ServerSettings, WarehouseConnection, LocationSummary, PlatformEventQuery, PlatformEventRecord, PlatformHealth, MaintenanceHistory, ProviderConnection, RoleAssignment, RoleAssignmentRequest, RoleDefinition, RoleDetail } from './types/platform'; -import type { Acknowledgement, CatalogNode, CatalogNodeDetail, Check, CheckDetail, CheckEvidence, CheckSql, NodeStates, NodeStatusDelta, Overview, SnapshotChange, ColumnLineage } from './types/build'; +import type { Acknowledgement, CatalogNode, CatalogNodeDetail, Check, CheckDetail, CheckEvidence, CheckSql, NodeStates, NodeStatusDelta, Overview, SnapshotChange, ColumnLineage, AttentionAcknowledgement, ConditionShape } from './types/build'; import type { AdhocRunCheck, AdhocRunRequest, BulkRunResult, SelectionEvaluation, SelectionRequest, SelectionVocabulary, PlanDiff, PlanPage, PlanPageSection, PlanResult, QueueEntry, Timeline, Job, JobDetail, JobLaunchOptions, RerunMode, SnapshotNode, Run, RunDetail, RunListQuery, RunRowPage, RunRowQuery, RunTabCounts, Trigger, TriggerDetail, TriggerState, RunEventPage, RunNodeError, RunOutputLine, RunStatement, IgnoredAuditFailure, RunCostRow, CostSummary, NodeBuildCost, StatementSql } from './types/operate'; type Wire = components['schemas']; @@ -50,6 +50,7 @@ const SUPPORTED: ReadonlySet = new Set([ 'listRunOutput', 'getRunNodeError', 'acknowledgeRun', + 'acknowledgeCondition', 'cancelRun', 'cancelMatchingRuns', 'rerunRun', @@ -508,6 +509,15 @@ export function createHttpClient({ baseUrl = '', onUnauthorized, fetch: answer, if (response.status === 401) onUnauthorized(); if (!response.ok) throw new ApiError(errorText(error, response), response.status); }, + async acknowledgeCondition(scope: Scope, key: string, shape: ConditionShape, acknowledged: boolean): Promise { + const { locationId, target } = parseLocationKey(scope.locationId); + const { error, response } = await http.POST('/api/control/locations/{location_id}/targets/{target}/attention-acknowledgements', { + body: { event_id: crypto.randomUUID(), key, shape, acknowledged }, + params: { path: { location_id: locationId, target }, header: { 'x-sqb-csrf': csrfToken(document.cookie) } } + }); + if (response.status === 401) onUnauthorized(); + if (!response.ok) throw new ApiError(errorText(error, response), response.status); + }, async rerunRun(scope: Scope, runId: string, mode: Exclude): Promise { const source = await requireRun(scope, runId); const body = { run_id: crypto.randomUUID(), source_run_id: runId, from_failure: mode === 'from_failure', priority: source.priority, reason: 'Rerun from the web UI' }; @@ -859,7 +869,8 @@ export function createHttpClient({ baseUrl = '', onUnauthorized, fetch: answer, listing ?? implemented.listCatalogNodes(scope), implemented.listSnapshotChanges(scope, { limit: 100 }), implemented.listPlatformEvents(), - acknowledgementsOf(scope) + acknowledgementsOf(scope), + attentionAcknowledgementsOf(scope) ]); // Every listing needs view on all of the target, so a partial viewer gets no counts at all. const read = await reads.catch((error: unknown) => { @@ -867,8 +878,8 @@ export function createHttpClient({ baseUrl = '', onUnauthorized, fetch: answer, throw error; }); if (!read) return null; - const [runs, checks, nodes, changes, events, acknowledgements] = read; - return overviewOf({ runs, checks, nodes, changes, events, acknowledgements, now: Date.now() }); + const [runs, checks, nodes, changes, events, acknowledgements, conditions] = read; + return overviewOf({ runs, checks, nodes, changes, events, acknowledgements, conditions, now: Date.now() }); }, listChecks: async (scope: Scope): Promise => (await checkResults(scope)).map(toCheck), getCheck: async (scope: Scope, id: string): Promise => checkDetailOf(await checkResults(scope, id)), @@ -1135,6 +1146,18 @@ export function createHttpClient({ baseUrl = '', onUnauthorized, fetch: answer, return new Map(data.map((a) => [a.run_id, { by: a.acknowledged_by, at: a.acknowledged_at }])); } + /** Conditions marked handled in the last two days, lapsed ones included; none from a server or recording without them. */ + async function attentionAcknowledgementsOf(scope: Scope): Promise { + const { locationId, target } = parseLocationKey(scope.locationId); + const { data, error, response } = await http.GET('/api/control/locations/{location_id}/targets/{target}/attention-acknowledgements', { + params: { path: { location_id: locationId, target } } + }); + if (response.status === 401) onUnauthorized(); + if (response.status === 404) return []; + if (!data) throw new ApiError(errorText(error, response), response.status); + return data.map((a) => ({ key: a.key, shape: a.shape as ConditionShape, by: a.acknowledged_by, at: a.acknowledged_at, until: a.until })); + } + /** Triggers with their latest tick and the newest listed run each started. */ async function triggersOf(scope: Scope): Promise { const [wires, runs] = await Promise.all([listedTriggers(scope), recentRuns(scope)]); diff --git a/ui/src/lib/api/http-overview.test.ts b/ui/src/lib/api/http-overview.test.ts index 83f0766e05..2bf33351f7 100644 --- a/ui/src/lib/api/http-overview.test.ts +++ b/ui/src/lib/api/http-overview.test.ts @@ -52,6 +52,7 @@ describe('overview from live reads', () => { changes: [change(1, [['added', 'model:orders'], ['added', 'seed:regions'], ['removed', 'model:old']]), change(24 * 8, [['added', 'model:totals']])], events: [event('scheduler', true), event('cleared', false)], acknowledgements: new Map([['orders-new', { by: 'ada', at: hoursAgo(1) }]]), + conditions: [], now }); @@ -95,12 +96,14 @@ describe('overview from live reads', () => { it('counts each stale node once, and leaves late sources unknown', () => { expect(overview.metrics.stale).toEqual({ nodes: 2, changed: 1, behind: 2, sources: null }); - expect(overview.attention.find((i) => i.kind === 'stale_models')).toEqual({ kind: 'stale_models', changed: ['model:orders'], behind: ['model:orders', 'model:events'] }); + expect(overview.attention.find((i) => i.kind === 'stale_models')).toMatchObject({ kind: 'stale_models', changed: ['model:orders'], behind: ['model:orders', 'model:events'] }); + // An ongoing condition, which can be acknowledged until it changes; no acknowledgement is listed. + expect(overview.attention.find((i) => i.kind === 'stale_models')).toMatchObject({ condition: { key: 'stale_models', shape: { counts: { changed: 1, behind: 2 } }, acknowledged: null, lapsed: null } }); }); it('leaves parts without a server read empty instead of zero', () => { expect(overview.metrics.cost).toBeNull(); - const unknown = overviewOf({ runs: [], checks: [], nodes: [{ ...node('model:a', 'table', 'models/a.sql'), stale: null }], changes: [], events: [], acknowledgements: new Map(), now }); + const unknown = overviewOf({ runs: [], checks: [], nodes: [{ ...node('model:a', 'table', 'models/a.sql'), stale: null }], changes: [], events: [], acknowledgements: new Map(), conditions: [], now }); expect(unknown.groups).toBeNull(); }); }); diff --git a/ui/src/lib/api/http-overview.ts b/ui/src/lib/api/http-overview.ts index 56f25a02c4..43cca22dd0 100644 --- a/ui/src/lib/api/http-overview.ts +++ b/ui/src/lib/api/http-overview.ts @@ -1,7 +1,8 @@ import { topFolder } from '$lib/lineage/catalog-graph'; import { recentDeploys } from '$lib/build-area/overview-panels'; +import { withConditions } from '$lib/build-area/attention-conditions'; import { checkCountsOf } from './http-catalog'; -import type { Acknowledgement, AttentionItem, AttentionRun, CatalogNode, Check, GroupStatus, Overview, PlatformEvent, Run, SnapshotChange } from './types'; +import type { Acknowledgement, AttentionAcknowledgement, AttentionItem, AttentionRun, CatalogNode, Check, GroupStatus, Overview, PlatformEvent, Run, SnapshotChange } from './types'; const DAY = 24 * 60 * 60 * 1000; const MODEL_KINDS = new Set(['view', 'table', 'incremental']); @@ -18,6 +19,8 @@ export type OverviewInputs = { events: PlatformEvent[]; /** Problem runs marked handled, by run ID. */ acknowledgements: Map; + /** Conditions' latest acknowledgements. */ + conditions: AttentionAcknowledgement[]; now: number; }; @@ -65,7 +68,7 @@ export function groupStatusOf(nodes: CatalogNode[]): GroupStatus[] { * does not check source freshness, so late sources stay unknown. Groups are top-level folders, and * group status is null when the server reports no build state. There is no cost read, so the page hides cost. */ -export function overviewOf({ runs, checks, nodes, changes, events, acknowledgements, now }: OverviewInputs): Overview { +export function overviewOf({ runs, checks, nodes, changes, events, acknowledgements, conditions, now }: OverviewInputs): Overview { const acknowledged = (r: Run) => acknowledgements.get(r.id) ?? null; const topLevel = runs.filter((r) => !r.parentRunId); const recent = topLevel.filter((r) => Date.parse(r.queuedAt) >= now - DAY); @@ -103,7 +106,7 @@ export function overviewOf({ runs, checks, nodes, changes, events, acknowledgeme stale: { nodes: staleNodes, changed: changed.length, behind: behind.length, sources: null }, cost: null }, - attention, + attention: withConditions(attention, conditions, now), groups: nodes.some((n) => n.stale !== null) ? groupStatusOf(nodes) : null, recentChanges: recentDeploys(changes), latestRun: latest ? { id: latest.id, status: latest.status, endedAt: latest.endedAt } : null diff --git a/ui/src/lib/api/mock/build.ts b/ui/src/lib/api/mock/build.ts index d34e2c7725..887b5e2935 100644 --- a/ui/src/lib/api/mock/build.ts +++ b/ui/src/lib/api/mock/build.ts @@ -5,6 +5,7 @@ import { ApiError } from '../client'; import { groupStatusOf, problemRunsOf } from '../http-overview'; +import { withConditions } from '$lib/build-area/attention-conditions'; import { recentDeploys } from '$lib/build-area/overview-panels'; import type { AttentionItem, @@ -301,7 +302,7 @@ export class MockBuild { // The mock holds one day of costed runs; the server's baseline is the rolling average of the same window. cost: cost === null ? null : { last24h: round(cost), baseline: round(cost * 0.78), baselineDays: 7, unit: 'credits' } }, - attention, + attention: withConditions(attention, this.#ctx.operate.conditionAcknowledgements(), now), groups: groupStatusOf(nodes), recentChanges: recentDeploys(this.#changes(scope)), latestRun: latest ? { id: latest.id, status: latest.status, endedAt: latest.endedAt } : null diff --git a/ui/src/lib/api/mock/mock-client.ts b/ui/src/lib/api/mock/mock-client.ts index 2a95b83540..a607baf555 100644 --- a/ui/src/lib/api/mock/mock-client.ts +++ b/ui/src/lib/api/mock/mock-client.ts @@ -5,6 +5,7 @@ import { LocalChangeBus, type ConnectionState } from '../signals'; import { stateOf } from '../node-states'; import type { AdhocRunCheck, + ConditionShape, SelectionEvaluation, SelectionRequest, SelectionVocabulary, @@ -318,6 +319,11 @@ export class MockApiClient implements ApiClient { this.#operate.acknowledgeRun(runId, acknowledged, 'you'); } + async acknowledgeCondition(scope: Scope, key: string, shape: ConditionShape, acknowledged: boolean): Promise { + this.#location(scope); + this.#operate.acknowledgeCondition(key, shape, acknowledged, 'you'); + } + async rerunRun(scope: Scope, runId: string, mode: Exclude): Promise { this.#location(scope); return this.#operate.rerunRun(scope, runId, mode); diff --git a/ui/src/lib/api/mock/operate-store.ts b/ui/src/lib/api/mock/operate-store.ts index 542cfb6100..29e63833f9 100644 --- a/ui/src/lib/api/mock/operate-store.ts +++ b/ui/src/lib/api/mock/operate-store.ts @@ -9,6 +9,8 @@ import type { LocalChangeBus } from '../signals'; import { memberLinks, pairKey } from '$lib/lineage/member-graph'; import type { Acknowledgement, + AttentionAcknowledgement, + ConditionShape, CatalogNode, WaitReason, AdhocPermission, @@ -846,9 +848,22 @@ export class MockOperate { /** Problem runs marked handled, by run ID. */ #acknowledgements = new Map(); + #conditionAcks = new Map(); acknowledgement(runId: string): Acknowledgement | null { return this.#acknowledgements.get(runId) ?? null; } + /** Conditions' latest acknowledgements, as the server lists them. */ + conditionAcknowledgements(): AttentionAcknowledgement[] { + return [...this.#conditionAcks.values()]; + } + /** As the server: holds for 24 hours, and acknowledging the same shape again while it holds changes nothing. */ + acknowledgeCondition(key: string, shape: ConditionShape, acknowledged: boolean, by: string): void { + if (!acknowledged) return void this.#conditionAcks.delete(key); + const held = this.#conditionAcks.get(key); + const now = Date.now(); + if (held && JSON.stringify(held.shape) === JSON.stringify(shape) && now < Date.parse(held.until)) return; + this.#conditionAcks.set(key, { key, shape, by, at: new Date(now).toISOString(), until: new Date(now + 86_400_000).toISOString() }); + } acknowledgeRun(runId: string, acknowledged: boolean, by: string): void { if (acknowledged) this.#acknowledgements.set(runId, { by, at: new Date().toISOString() }); else this.#acknowledgements.delete(runId); diff --git a/ui/src/lib/api/types/build.ts b/ui/src/lib/api/types/build.ts index 43a32d1a54..52b77481bf 100644 --- a/ui/src/lib/api/types/build.ts +++ b/ui/src/lib/api/types/build.ts @@ -374,14 +374,37 @@ export type AttentionRun = Pick; + /** Members that make it worse when a new one appears, such as `:`. */ + members?: string[]; + /** Severity, least first; a higher one is worse. */ + severity?: number; + /** Which occurrence it is: a different one means it resolved and came back. */ + occurrence?: string; +}; +/** A condition's latest acknowledgement, as the server lists it; `until` is when it lapses even unchanged. */ +export type AttentionAcknowledgement = { key: string; shape: ConditionShape; by: string; at: Iso; until: Iso }; +/** An ongoing condition on the attention list, acknowledged until it changes. */ +export type AttentionCondition = { + /** Its kind and subject, stable while it lasts, such as `stale_sources`. */ + key: string; + shape: ConditionShape; + /** Holds until the condition gets worse, resolves and comes back, or `until` passes. */ + acknowledged: (Acknowledgement & { until: Iso }) | null; + /** Why an acknowledgement no longer holds, while the condition is back on the list. */ + lapsed: { reason: string; by: string; at: Iso } | null; +}; export type AttentionItem = | { kind: 'run_problem'; run: AttentionRun; acknowledged: Acknowledgement | null } | { kind: 'run_unresponsive'; run: AttentionRun; lastHeartbeatAt: Iso | null; acknowledged: Acknowledgement | null } - | { kind: 'stale_models'; changed: string[]; behind: string[] } - | { kind: 'stale_sources'; sources: ({ key: string } & SourceFreshness)[] } - | { kind: 'platform_event'; event: PlatformEvent } - | { kind: 'queue_blocked'; runId: string; jobKey: string | null; queuedAt: Iso; waits: QueueWait[] } - | { kind: 'calendar_low'; triggerId: string; triggerName: string; detail: string }; + | { kind: 'stale_models'; changed: string[]; behind: string[]; condition?: AttentionCondition } + | { kind: 'stale_sources'; sources: ({ key: string } & SourceFreshness)[]; condition?: AttentionCondition } + | { kind: 'platform_event'; event: PlatformEvent; condition?: AttentionCondition } + | { kind: 'queue_blocked'; runId: string; jobKey: string | null; queuedAt: Iso; waits: QueueWait[]; condition?: AttentionCondition } + | { kind: 'calendar_low'; triggerId: string; triggerName: string; detail: string; condition?: AttentionCondition }; export type OverviewMetrics = { models: { total: number; addedThisWeek: number; removedThisWeek: number }; diff --git a/ui/src/lib/build-area/attention-conditions.test.ts b/ui/src/lib/build-area/attention-conditions.test.ts new file mode 100644 index 0000000000..75dc35a8bb --- /dev/null +++ b/ui/src/lib/build-area/attention-conditions.test.ts @@ -0,0 +1,73 @@ +import { describe, expect, it } from 'vitest'; +import type { AttentionAcknowledgement, AttentionItem, PlatformEvent } from '$lib/api'; +import { acknowledgementOf, conditionOf, withConditions } from './attention-conditions'; + +const now = Date.parse('2026-11-18T12:00:00Z'); +const iso = (hoursFromNow: number) => new Date(now + hoursFromNow * 3_600_000).toISOString(); +const event = (extra: Partial = {}): PlatformEvent => ({ + id: 'ev-1', + kind: 'tick_overdue', + severity: 'warning', + occurredAt: iso(-1), + active: true, + locationId: 'loc-1', + subject: 'segments_hourly', + message: 'The segments_hourly schedule should have started a run 12 minutes ago.', + ...extra +}); +const stale = (changed: number, behind: number): AttentionItem => ({ + kind: 'stale_models', + changed: Array.from({ length: changed }, (_, i) => `model:c${i}`), + behind: Array.from({ length: behind }, (_, i) => `model:b${i}`) +}); +const source = (key: string, status: 'warn' | 'error') => ({ key, status, loadedAt: iso(-2), checkedAt: iso(0), warnAfterSeconds: 1800, errorAfterSeconds: 7200 }); +/** The acknowledgement of `item` as it looks now, made `hoursAgo` ago. */ +const acknowledged = (item: AttentionItem, hoursAgo = 1): AttentionAcknowledgement => { + const { key, shape } = conditionOf(item)!; + return { key, shape, by: 'ada', at: iso(-hoursAgo), until: iso(24 - hoursAgo) }; +}; +const stateOf = (item: AttentionItem, acks: AttentionAcknowledgement[], at = now) => { + const [shown] = withConditions([item], acks, at); + const condition = 'condition' in shown ? shown.condition : undefined; + return { acknowledged: !!acknowledgementOf(shown), lapsed: condition?.lapsed?.reason ?? null }; +}; + +describe('acknowledging a condition until it changes', () => { + it('keys a condition by its kind and subject, and leaves runs to their own acknowledgement', () => { + expect(conditionOf(stale(2, 3))).toEqual({ key: 'stale_models', noun: 'node', shape: { counts: { changed: 2, behind: 3 } } }); + expect(conditionOf({ kind: 'platform_event', event: event() })?.key).toBe('event:tick_overdue:loc-1:segments_hourly'); + expect(conditionOf({ kind: 'run_problem', run: { id: 'r' } as never, acknowledged: null })).toBeNull(); + }); + + it('holds while the condition is the same or better', () => { + const ack = acknowledged(stale(2, 3)); + expect(stateOf(stale(2, 3), [ack])).toEqual({ acknowledged: true, lapsed: null }); + expect(stateOf(stale(1, 0), [ack])).toEqual({ acknowledged: true, lapsed: null }); + }); + + it('comes back, saying why, when it gets worse', () => { + expect(stateOf(stale(2, 5), [acknowledged(stale(2, 3))])).toEqual({ acknowledged: false, lapsed: '2 more nodes behind since it was acknowledged' }); + const sources: AttentionItem = { kind: 'stale_sources', sources: [source('raw__orders', 'warn')] }; + const escalated: AttentionItem = { kind: 'stale_sources', sources: [source('raw__orders', 'error')] }; + expect(stateOf(escalated, [acknowledged(sources)]).lapsed).toBe('1 more source past their error threshold since it was acknowledged'); + expect(stateOf({ kind: 'platform_event', event: event({ severity: 'critical' }) }, [acknowledged({ kind: 'platform_event', event: event() })]).lapsed).toBe('it became more severe'); + }); + + it('ignores a changed message, which can hold relative times', () => { + const before: AttentionItem = { kind: 'platform_event', event: event() }; + const later: AttentionItem = { kind: 'platform_event', event: event({ message: 'The segments_hourly schedule should have started a run 40 minutes ago.' }) }; + expect(stateOf(later, [acknowledged(before)])).toEqual({ acknowledged: true, lapsed: null }); + }); + + it('comes back when it resolved and recurred, or after 24 hours', () => { + const before: AttentionItem = { kind: 'platform_event', event: event() }; + expect(stateOf({ kind: 'platform_event', event: event({ id: 'ev-2' }) }, [acknowledged(before)]).lapsed).toBe('it resolved and came back'); + expect(stateOf(stale(2, 3), [acknowledged(stale(2, 3), 25)]).lapsed).toBe('its 24-hour acknowledgement ended'); + }); + + it('keeps large shapes small: many sources compare by their counts', () => { + const many: AttentionItem = { kind: 'stale_sources', sources: Array.from({ length: 80 }, (_, i) => source(`raw__s${i}`, 'warn')) }; + expect(conditionOf(many)?.shape).toEqual({ counts: { warn: 80, error: 0 } }); + expect(JSON.stringify(conditionOf(stale(10_000, 10_000))!.shape).length).toBeLessThan(100); + }); +}); diff --git a/ui/src/lib/build-area/attention-conditions.ts b/ui/src/lib/build-area/attention-conditions.ts new file mode 100644 index 0000000000..b066a5da75 --- /dev/null +++ b/ui/src/lib/build-area/attention-conditions.ts @@ -0,0 +1,79 @@ +// Ongoing conditions on the Overview's attention list, and whether an acknowledgement still holds. +// A run is acknowledged for good; a condition only until it changes: it gets worse, it resolves and +// comes back, or the acknowledgement's 24 hours end. The server stores each acknowledgement with the +// condition's shape when it was acknowledged; this module says what a condition's shape is and what +// counts as worse. Shapes hold kinds, subjects, severities and counts, never message text, which can +// hold relative times ("12 minutes ago"). Pure. + +import type { AttentionAcknowledgement, AttentionCondition, AttentionItem, ConditionShape } from '$lib/api'; +import { plural } from '$lib/format/plural'; + +/** Members kept in a shape; beyond this a condition is compared by its counts only, to keep the stored shape small. */ +const MAX_MEMBERS = 50; +const SEVERITY: Record = { info: 0, warning: 1, critical: 2, warn: 1, error: 2 }; + +/** A condition's key and shape, and what its members are called; null for runs, which are acknowledged for good. */ +export function conditionOf(item: AttentionItem): { key: string; shape: ConditionShape; noun: string } | null { + switch (item.kind) { + case 'stale_models': + return { key: 'stale_models', noun: 'node', shape: { counts: { changed: new Set(item.changed).size, behind: new Set(item.behind).size } } }; + case 'stale_sources': { + const members = item.sources.map((s) => `${s.key}:${s.status}`).sort(); + const counts = { warn: item.sources.filter((s) => s.status === 'warn').length, error: item.sources.filter((s) => s.status === 'error').length }; + return { key: 'stale_sources', noun: 'source', shape: members.length <= MAX_MEMBERS ? { counts, members } : { counts } }; + } + case 'platform_event': { + const e = item.event; + return { key: `event:${e.kind}:${e.locationId ?? ''}:${e.subject ?? ''}`, noun: 'event', shape: { severity: SEVERITY[e.severity] ?? 0, occurrence: e.id } }; + } + case 'queue_blocked': + return { key: `queue:${item.runId}`, noun: 'wait', shape: { members: [...new Set(item.waits.map((w) => w.kind))].sort() } }; + case 'calendar_low': + return { key: `calendar:${item.triggerId}`, noun: 'warning', shape: {} }; + case 'run_problem': + case 'run_unresponsive': + return null; + } +} + +const COUNT_LABEL: Record = { changed: 'changed', behind: 'behind', warn: 'late', error: 'past their error threshold' }; + +/** Why an acknowledgement no longer holds at `now`, or null while it does. */ +export function lapseOf(stored: ConditionShape, current: ConditionShape, until: string, now: number, noun: string): string | null { + if (stored.occurrence !== undefined && current.occurrence !== undefined && stored.occurrence !== current.occurrence) return 'it resolved and came back'; + if ((current.severity ?? 0) > (stored.severity ?? 0)) return 'it became more severe'; + for (const [name, count] of Object.entries(current.counts ?? {})) { + const more = count - (stored.counts?.[name] ?? 0); + if (more > 0) return `${plural(more, `more ${noun}`)} ${COUNT_LABEL[name] ?? name} since it was acknowledged`; + } + if (stored.members && current.members) { + const added = current.members.filter((m) => !stored.members!.includes(m)).length; + if (added) return `${plural(added, `new ${noun}`)} since it was acknowledged`; + } + if (now >= Date.parse(until)) return 'its 24-hour acknowledgement ended'; + return null; +} + +/** The items with their conditions, each acknowledged while its acknowledgement holds and otherwise saying why it lapsed. */ +export function withConditions(items: AttentionItem[], acknowledgements: readonly AttentionAcknowledgement[], now: number): AttentionItem[] { + const byKey = new Map(acknowledgements.map((a) => [a.key, a])); + return items.map((item) => { + const found = conditionOf(item); + if (!found) return item; + const ack = byKey.get(found.key); + const reason = ack ? lapseOf(ack.shape, found.shape, ack.until, now, found.noun) : null; + const condition: AttentionCondition = { + key: found.key, + shape: found.shape, + acknowledged: ack && !reason ? { by: ack.by, at: ack.at, until: ack.until } : null, + lapsed: ack && reason ? { reason, by: ack.by, at: ack.at } : null + }; + return { ...item, condition } as AttentionItem; + }); +} + +/** Whether an item is acknowledged now: a run by its own mark, a condition while its acknowledgement holds. */ +export function acknowledgementOf(item: AttentionItem): { by: string; at: string; until?: string } | null { + if ('acknowledged' in item) return item.acknowledged; + return ('condition' in item && item.condition?.acknowledged) || null; +} diff --git a/ui/src/lib/build-area/attention.test.ts b/ui/src/lib/build-area/attention.test.ts index e4de69c642..7927b80561 100644 --- a/ui/src/lib/build-area/attention.test.ts +++ b/ui/src/lib/build-area/attention.test.ts @@ -30,6 +30,16 @@ describe('overview alerts', () => { ]); }); + it('keeps an overdue schedule as its own alert when its outage is acknowledged, so it isn’t hidden with it', () => { + const broken = event('broken', 'location_broken', 'shop'); + const acknowledged = { ...broken, condition: { key: 'event:location_broken:shop:', shape: {}, acknowledged: { by: 'ada', at: ago(1), until: ago(-600) }, lapsed: null } } as AttentionItem; + const views = attentionViews([acknowledged, event('late-shop', 'tick_overdue', 'shop', { message: 'hourly is late' })], now); + expect(views.map(({ view }) => [view.key, view.consequences.length])).toEqual([ + ['event:broken', 0], + ['event:late-shop', 0] + ]); + }); + it('keeps an overdue schedule as its own alert when nothing explains it', () => { const views = attentionViews([event('late', 'tick_overdue', 'shop'), event('broken', 'location_broken', 'marketing')], now); expect(views.map(({ view }) => view.key)).toEqual(['event:late', 'event:broken']); diff --git a/ui/src/lib/build-area/attention.ts b/ui/src/lib/build-area/attention.ts index 5bd97bc743..38dc82c461 100644 --- a/ui/src/lib/build-area/attention.ts +++ b/ui/src/lib/build-area/attention.ts @@ -174,7 +174,8 @@ const waitRun = (wait: QueueWait): string | null => ('runId' in wait ? wait.runI */ function causeOf(item: AttentionItem, items: AttentionItem[]): string | null { if (item.kind === 'platform_event' && item.event.kind === 'tick_overdue') { - const events = items.flatMap((i) => (i.kind === 'platform_event' ? [i.event] : [])); + // An acknowledged cause has left the list, so what follows from it stands on its own. + const events = items.flatMap((i) => (i.kind === 'platform_event' && !i.condition?.acknowledged ? [i.event] : [])); const location = events.find((e) => e.kind === 'location_broken' && e.locationId === item.event.locationId); const scheduler = events.find((e) => e.kind === 'scheduler_no_leader'); const cause = location ?? scheduler; diff --git a/ui/src/routes/+page.svelte b/ui/src/routes/+page.svelte index af09f5686c..bea80a0641 100644 --- a/ui/src/routes/+page.svelte +++ b/ui/src/routes/+page.svelte @@ -22,10 +22,11 @@ import { createResource } from '$lib/state/resource.svelte'; import { catalogNodes, useCatalogNodes } from '$lib/state/catalog.svelte'; import { folderCatalogHref, folderSelections } from '$lib/selection/folders'; - import { formatAgo } from '$lib/format/time'; + import { formatAgo, formatStamp } from '$lib/format/time'; import { runStatusLabel } from '$lib/status'; import { attentionViews, type AttentionTone } from '$lib/build-area/attention'; import type { AttentionItem } from '$lib/api'; + import { acknowledgementOf } from '$lib/build-area/attention-conditions'; import { formatCredits } from '$lib/build-area/labels'; import { nodeChangeLine, summarizeChange } from '$lib/build-area/changes'; import { quietDeployLine, recentDeployRows, visibleFolders } from '$lib/build-area/overview-panels'; @@ -55,20 +56,29 @@ info: InfoIcon }; const viewed = $derived(attentionViews(data?.attention ?? [], app.now, catalogNodes.view.changedBuild)); - const acknowledgementOf = (item: AttentionItem) => ('acknowledged' in item ? item.acknowledged : null); + // A run is acknowledged for good; an ongoing condition until it changes (see attention-conditions). + const conditionFor = (item: AttentionItem) => ('condition' in item ? (item.condition ?? null) : null); + const ACK_HELP = { + run: 'Hide this from the attention list for everyone. It stays under Acknowledged, where anyone can undo it.', + condition: 'Hide this from the attention list for everyone, until it changes: it gets worse, resolves and comes back, or 24 hours pass. It stays under Acknowledged, where anyone can undo it.' + }; + const canAck = (item: AttentionItem) => ('acknowledged' in item ? canAcknowledge : !!conditionFor(item) && canAcknowledgeConditions); // Acknowledged problems no longer need attention: they leave the count and the banner's tone. const issues = $derived(viewed.filter(({ item }) => !acknowledgementOf(item))); const handled = $derived(viewed.filter(({ item }) => acknowledgementOf(item))); let showHandled = $state(false); let acknowledging = $state(null); let acknowledgeError = $state(null); - async function acknowledge(runId: string, acknowledged: boolean) { + /** Acknowledges an item, or undoes that: a run by its ID, a condition as it looks now. */ + async function acknowledge(item: AttentionItem, key: string, acknowledged: boolean) { const scope = app.scope; + const condition = conditionFor(item); if (!scope || acknowledging) return; - acknowledging = runId; + acknowledging = key; acknowledgeError = null; try { - await app.client.acknowledgeRun(scope, runId, acknowledged); + if ('acknowledged' in item) await app.client.acknowledgeRun(scope, item.run.id, acknowledged); + else if (condition) await app.client.acknowledgeCondition(scope, condition.key, condition.shape, acknowledged); await overview.refresh(); } catch (error) { acknowledgeError = error instanceof Error ? error.message : String(error); @@ -98,6 +108,7 @@ const showGroups = $derived(!!data?.groups?.length); const showTimeline = $derived(app.client.supports('timeline')); const canAcknowledge = $derived(app.client.supports('acknowledgeRun')); + const canAcknowledgeConditions = $derived(app.client.supports('acknowledgeCondition')); const FAILING_CHECKS_HREF = '/checks?outcome=failing'; @@ -158,6 +169,10 @@
{view.title}

{view.detail}

+ {#if conditionFor(item)?.lapsed} + {@const lapsed = conditionFor(item)!.lapsed!} +

Back on the list: {lapsed.reason} (acknowledged by {lapsed.by} {formatAgo(lapsed.at, app.now)}).

+ {/if} {#if view.consequences.length}
    {#each view.consequences as c, i (i)}
  • {c.text}
  • {/each} @@ -166,9 +181,10 @@
{view.since} - {#if 'acknowledged' in item && canAcknowledge} - {/if} @@ -187,7 +203,7 @@ {/if} {#if handled.length}
- (showHandled = !showHandled)} class="h-[34px] pr-3.5 pl-[17px] text-[12px]">Acknowledged · {handled.length} + (showHandled = !showHandled)} class="h-[34px] pr-3.5 pl-[17px] text-[12px]">Acknowledged ({handled.length}) {#if showHandled}
{#each handled as { item, view } (view.key)} @@ -196,12 +212,12 @@
{view.title} -

{ack ? `Acknowledged by ${ack.by} · ${formatAgo(ack.at, app.now)}` : ''}

+

{ack ? `Acknowledged by ${ack.by} · ${formatAgo(ack.at, app.now)} · ${ack.until ? `hidden until it changes, or until ${formatStamp(ack.until).slice(5, 16)}` : 'for good'}` : ''}

{view.since} - {#if 'acknowledged' in item && canAcknowledge} - + {#if canAck(item)} + {/if} {view.action} → @@ -344,6 +360,11 @@ .issue-actions { justify-content: flex-end; gap: 10px; } .issue-actions a { color: var(--primary); font-weight: 500; white-space: nowrap; } .handled { border-top: 1px solid var(--inner-line); } + .lapsed { margin: 4px 0 0; color: var(--sb-warning); font-size: 12px; } + /* Ack: muted text with a bell, always visible; on row hover it gains a border and full colour. */ + .issue :global(.ack) { height: 24px; padding: 0 8px; border: 1px solid transparent; color: var(--muted-foreground); font-size: 12px; font-weight: 500; } + .issue:hover :global(.ack), .issue :global(.ack:focus-visible) { border-color: var(--border); background: var(--sb-hover); color: var(--foreground); } + .issue :global(.ack:hover) { border-color: var(--muted-foreground); } .issue.muted .issue-title { color: var(--muted-foreground); font-weight: 500; } .ack-error { margin: 0; padding: 8px 17px; border-top: 1px solid var(--inner-line); color: var(--sb-error); font-size: 12px; } .issue-icon { display: grid; width: 22px; height: 22px; place-items: center; border-radius: 2px; } From df6522487f98df27b60db6002f36529cbb3da1b4 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:33:23 +0000 Subject: [PATCH 03/19] fix(server): describe an attention shape as any JSON in the API contract It was declared an empty object, which the TypeScript client generated as an object that may hold no properties. --- clients/typescript/src/schema.d.ts | 4 ++-- crates/sqlbuild-orchestration/src/acknowledgements/models.rs | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/clients/typescript/src/schema.d.ts b/clients/typescript/src/schema.d.ts index a31a2a3ce9..368f66ca88 100644 --- a/clients/typescript/src/schema.d.ts +++ b/clients/typescript/src/schema.d.ts @@ -1654,7 +1654,7 @@ export interface components { /** @description The person's name, or the audit actor when the person no longer exists. */ acknowledged_by: string; key: string; - shape: Record; + shape: unknown; /** * Format: date-time * @description When the acknowledgement lapses even if the condition never changes. @@ -1678,7 +1678,7 @@ export interface components { * @description What the condition looked like (counts, members, error codes), which later states are compared * with; a JSON object of at most 8 KiB. Never message text, which can hold relative times. */ - shape: Record; + shape: unknown; }; AuthenticationDenial: { error: string; diff --git a/crates/sqlbuild-orchestration/src/acknowledgements/models.rs b/crates/sqlbuild-orchestration/src/acknowledgements/models.rs index 22c810f778..02b2e499bd 100644 --- a/crates/sqlbuild-orchestration/src/acknowledgements/models.rs +++ b/crates/sqlbuild-orchestration/src/acknowledgements/models.rs @@ -33,7 +33,6 @@ pub struct AttentionAcknowledgementRequest { pub key: String, /// What the condition looked like (counts, members, error codes), which later states are compared /// with; a JSON object of at most 8 KiB. Never message text, which can hold relative times. - #[schema(value_type = Object)] pub shape: serde_json::Value, pub acknowledged: bool, } @@ -42,7 +41,6 @@ pub struct AttentionAcknowledgementRequest { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)] pub struct AttentionAcknowledgement { pub key: String, - #[schema(value_type = Object)] pub shape: serde_json::Value, /// The person's name, or the audit actor when the person no longer exists. pub acknowledged_by: String, From f937164a9d99dd8eec538a5d4b53c2a7e9152695 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:54:59 +0000 Subject: [PATCH 04/19] feat(ui): the catalog's folders as an expandable tree; the Overview card shows at most eight MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The catalog gains "By folder" beside Nodes (kept in `?view=folders`): every folder with Current, Changed, Behind and Failed, its subfolders' nodes included, as a tree. - Each folder opens in place, onto its subfolders and then its own nodes (stale and failed first, the first 20, then "N more in →"). Expand all and Collapse all. - Sorting by any column applies within each level. "Needs attention only" leaves out fully current folders and nodes. - A folder's name, or one of its counts, opens those nodes (of that status) in the list. The catalog now reads `?status=` for such links. - Clicking anywhere else on a folder's label (its chevron, icon, "N subfolders" or empty space) opens or closes it. A click on a link, or one that selects text, never does. The chevron stays a button with aria-expanded, so the keyboard works it. - Full width, like the node list: the name takes the spare room, the bar a fixed 160 px before fixed count columns, so all four counts show from 1280 px up. The shared DataTable draws only the rows in view. - The Overview's Build status card shows at most eight folders, most urgent first, and links to "All N folders (M need attention) →". Before, every folder needing attention also showed, so on a project where most need attention the cap did nothing. - The large mock project answers `path:` selections from its own nodes. --- ui/e2e/folder-tree.spec.ts | 94 ++++++++ ui/src/lib/api/mock/large-project.ts | 11 + ui/src/lib/build-area/folder-tree.test.ts | 66 ++++++ ui/src/lib/build-area/folder-tree.ts | 117 ++++++++++ ui/src/lib/build-area/overview-panels.test.ts | 16 +- ui/src/lib/build-area/overview-panels.ts | 13 +- .../components/build-area/folder-tree.svelte | 205 ++++++++++++++++++ ui/src/routes/+page.svelte | 15 +- ui/src/routes/catalog/+page.svelte | 26 ++- 9 files changed, 538 insertions(+), 25 deletions(-) create mode 100644 ui/e2e/folder-tree.spec.ts create mode 100644 ui/src/lib/build-area/folder-tree.test.ts create mode 100644 ui/src/lib/build-area/folder-tree.ts create mode 100644 ui/src/lib/components/build-area/folder-tree.svelte diff --git a/ui/e2e/folder-tree.spec.ts b/ui/e2e/folder-tree.spec.ts new file mode 100644 index 0000000000..83fe5fbbe2 --- /dev/null +++ b/ui/e2e/folder-tree.spec.ts @@ -0,0 +1,94 @@ +import { expect, test, type Page } from '@playwright/test'; + +// The catalog's folders as a tree: clicking anywhere on a folder's label opens or closes it, except on +// its name, which, like each count, opens those nodes in the list instead. +test.use({ viewport: { width: 1600, height: 1000 } }); + +const open = async (page: Page) => { + await page.goto('/catalog?mock&large&view=folders'); + const tree = page.getByTestId('folder-tree'); + await expect(tree.locator('tr[data-path]').first()).toBeVisible({ timeout: 20_000 }); + return tree; +}; +/** The first top-level folder with subfolders. */ +const parentRow = (page: Page) => page.getByTestId('folder-tree').locator('tr[aria-level="1"]', { has: page.getByTestId('folder-toggle') }).first(); + +test('a click anywhere on a folder’s label, but its name, opens and closes it', async ({ page }) => { + await open(page); + const row = parentRow(page); + const path = await row.getAttribute('data-path'); + const toggle = row.getByTestId('folder-toggle'); + const children = page.locator(`tr[data-path^="${path}/"]`); + await expect(toggle).toHaveAttribute('aria-expanded', 'false'); + await expect(children).toHaveCount(0); + + // Empty space at the right of the label. + const label = row.getByTestId('folder-label'); + const box = (await label.boundingBox())!; + await page.mouse.click(box.x + box.width - 12, box.y + box.height / 2); + await expect(toggle).toHaveAttribute('aria-expanded', 'true'); + expect(await children.count()).toBeGreaterThan(0); + expect(await label.evaluate((td) => getComputedStyle(td).cursor)).toBe('pointer'); + + // The folder icon. + await label.locator('svg').nth(1).click(); + await expect(toggle).toHaveAttribute('aria-expanded', 'false'); + // The "N subfolders" text. + await label.locator('small').click(); + await expect(toggle).toHaveAttribute('aria-expanded', 'true'); + + // The chevron is a button that the keyboard works too. + await toggle.focus(); + await page.keyboard.press('Enter'); + await expect(toggle).toHaveAttribute('aria-expanded', 'false'); + await page.keyboard.press('Space'); + await expect(toggle).toHaveAttribute('aria-expanded', 'true'); +}); + +test('selecting text on a label does not open or close the folder', async ({ page }) => { + await open(page); + const row = parentRow(page); + const small = row.getByTestId('folder-label').locator('small'); + const box = (await small.boundingBox())!; + await page.mouse.move(box.x + 1, box.y + box.height / 2); + await page.mouse.down(); + await page.mouse.move(box.x + box.width - 1, box.y + box.height / 2, { steps: 5 }); + await page.mouse.up(); + expect(await page.evaluate(() => window.getSelection()?.toString().length ?? 0)).toBeGreaterThan(0); + await expect(row.getByTestId('folder-toggle')).toHaveAttribute('aria-expanded', 'false'); +}); + +test('a folder’s name opens its nodes in the list, without opening or closing it', async ({ page }) => { + await open(page); + const row = parentRow(page); + const path = (await row.getAttribute('data-path'))!; + // Watch the toggle: the tree goes away once the list opens, so a toggle would only show as a change. + await row.getByTestId('folder-toggle').evaluate((button) => { + const w = window as unknown as { toggled: number }; + w.toggled = 0; + new MutationObserver(() => (w.toggled += 1)).observe(button, { attributes: true, attributeFilter: ['aria-expanded'] }); + }); + // Opened in a new tab, the tree stays, so a toggle would show directly. + const [tab] = await Promise.all([page.context().waitForEvent('page'), row.getByTestId('folder-name').click({ modifiers: ['Control'] })]); + await tab.close(); + await expect(row.getByTestId('folder-toggle')).toHaveAttribute('aria-expanded', 'false'); + await row.getByTestId('folder-name').click(); + await expect(page.getByTestId('folder-tree')).toHaveCount(0); + expect(await page.evaluate(() => (window as unknown as { toggled: number }).toggled)).toBe(0); + await expect(page).not.toHaveURL(/view=folders/); + // The selection is evaluated a moment later; then the list holds just the folder's nodes. + await expect(page.getByText(/^\d+ of \d+ nodes$/)).toHaveText(/^(\d+) of (?!\1 )\d+ nodes$/); + const shown = (await page.locator('table.catalog tbody tr .cell-name a').allInnerTexts()).map((s) => s.trim()); + expect(shown.length).toBeGreaterThan(0); + expect(shown.filter((name) => !name.startsWith(path.split('/')[0])), path).toEqual([]); +}); + +test('a folder’s count opens just those nodes', async ({ page }) => { + const tree = await open(page); + const count = tree.getByTestId('folder-count-changed').first(); + const n = Number(await count.innerText()); + await count.click(); + await expect(page.getByTestId('folder-tree')).toHaveCount(0); + await expect(page.getByText(new RegExp(`^${n} of \\d+ nodes$`))).toBeVisible(); + await expect(page.locator('table.catalog tbody tr')).toHaveCount(n); +}); diff --git a/ui/src/lib/api/mock/large-project.ts b/ui/src/lib/api/mock/large-project.ts index 02104efa43..acc6cb0584 100644 --- a/ui/src/lib/api/mock/large-project.ts +++ b/ui/src/lib/api/mock/large-project.ts @@ -76,6 +76,17 @@ export function largeProject(client: ApiClient): ApiClient { return planModelDiff(doc, model); }; } + // Folder links select `path:`, which the large project answers from its own nodes. + if (prop === 'evaluateSelection') { + return async (...[scope, request]: Parameters) => { + const paths = request.select.split(/\s+/).filter((t) => t.startsWith('path:')).map((t) => t.slice(5).replace(/\/$/, '')); + if (!paths.length || request.select.split(/\s+/).some((t) => t && !t.startsWith('path:')) || request.exclude.trim()) return target.evaluateSelection(scope, request); + const real = await target.listCatalogNodes(scope); + const template = real.find((n) => n.kind === 'table') ?? real[0]; + const keys = largeProjectNodes(template).filter((n) => paths.some((p) => n.path.startsWith(`${p}/`))).map((n) => n.key).sort(); + return { snapshotId: null, count: keys.length, keys, nextOffset: null, error: null }; + }; + } if (prop !== 'listCatalogNodes') return typeof value === 'function' ? value.bind(target) : value; return async (...args: Parameters) => { const real = await target.listCatalogNodes(...args); diff --git a/ui/src/lib/build-area/folder-tree.test.ts b/ui/src/lib/build-area/folder-tree.test.ts new file mode 100644 index 0000000000..516003de7b --- /dev/null +++ b/ui/src/lib/build-area/folder-tree.test.ts @@ -0,0 +1,66 @@ +import { describe, expect, it } from 'vitest'; +import type { CatalogNode, StaleReason } from '$lib/api'; +import { folderPaths, folderTree, visibleTreeRows, type TreeRow } from './folder-tree'; + +const behind = [{ reason: 'behind', upstream: [], detail: '', since: '2026-11-18T00:00:00Z' }] as StaleReason[]; +const node = (key: string, path: string, extra: Partial = {}): CatalogNode => + ({ key, kind: 'table', path, group: null, upstream: [], stale: [], lastOutcome: 'success', lastBuild: { builtAt: '2026-11-18T00:00:00Z' }, ...extra }) as CatalogNode; + +const nodes = [ + node('card_events', 'models/payments/providers/card/card_events.sql', { stale: behind }), + node('card_daily', 'models/payments/providers/card/card_daily.sql'), + node('bank_events', 'models/payments/providers/bank/bank_events.sql'), + node('settled', 'models/payments/settlement/settled.sql', { lastOutcome: 'failed' }), + node('payments_summary', 'models/payments/payments_summary.sql'), + node('orders', 'models/orders/marts/orders.sql'), + node('raw_orders', 'sources/shop.yml', { kind: 'source' }) +]; +const label = (r: TreeRow) => (r.kind === 'folder' ? `${' '.repeat(r.folder.depth)}${r.folder.group}${r.expandable ? (r.expanded ? ' v' : ' >') : ''}` : r.kind === 'node' ? `${' '.repeat(r.depth)}· ${r.node.key}` : `${' '.repeat(r.folder.depth + 1)}+${r.hidden} more`); +const rows = (opts: Partial[1]> = {}) => + visibleTreeRows(folderTree(nodes), { expanded: new Set(), sort: 'urgency', reverse: false, attentionOnly: false, listNodes: false, ...opts }).map(label); + +describe('the catalog folder tree', () => { + it('counts each folder with its subfolders, and selects exactly its nodes', () => { + const [payments, orders] = folderTree(nodes); + expect([payments.path, payments.total, payments.current, payments.behind, payments.failed]).toEqual(['payments', 5, 3, 1, 1]); + expect(payments.selection).toBe('path:models/payments'); + expect(payments.children.map((c) => [c.path, c.total, c.selection])).toEqual([ + ['payments/providers', 3, 'path:models/payments/providers'], + ['payments/settlement', 1, 'path:models/payments/settlement'] + ]); + expect(payments.members.map((n) => n.key)).toEqual(['payments_summary']); + expect(orders.total).toBe(1); + expect(folderPaths(folderTree(nodes))).toEqual(['payments', 'payments/providers', 'payments/providers/card', 'payments/providers/bank', 'payments/settlement', 'orders', 'orders/marts']); + }); + + it('expands in place, most urgent first within each level', () => { + expect(rows()).toEqual(['payments >', 'orders >']); + expect(rows({ expanded: new Set(['payments', 'payments/providers']) })).toEqual(['payments v', ' settlement', ' providers v', ' card', ' bank', 'orders >']); + expect(rows({ expanded: new Set(['payments']), sort: 'group' })).toEqual(['orders >', 'payments v', ' providers >', ' settlement']); + }); + + it('lists a folder’s own nodes after its subfolders when asked, capped with a row for the rest', () => { + expect(rows({ expanded: new Set(['payments', 'payments/providers/card']), listNodes: true, nodeLimit: 1 })).toEqual(['payments v', ' settlement >', ' providers >', ' · payments_summary', 'orders >']); + expect(rows({ expanded: new Set(['payments', 'payments/providers', 'payments/providers/card']), listNodes: true, nodeLimit: 1 })).toEqual([ + 'payments v', + ' settlement >', + ' providers v', + ' card v', + ' · card_events', + ' +1 more', + ' bank >', + ' · payments_summary', + 'orders >' + ]); + }); + + it('leaves out fully current folders and nodes when showing only what needs attention', () => { + expect(rows({ attentionOnly: true, expanded: new Set(['payments', 'payments/providers', 'payments/providers/card']), listNodes: true })).toEqual([ + 'payments v', + ' settlement >', + ' providers v', + ' card v', + ' · card_events' + ]); + }); +}); diff --git a/ui/src/lib/build-area/folder-tree.ts b/ui/src/lib/build-area/folder-tree.ts new file mode 100644 index 0000000000..40d791948f --- /dev/null +++ b/ui/src/lib/build-area/folder-tree.ts @@ -0,0 +1,117 @@ +// The catalog's folders as a tree, each folder with where its nodes stand (its subfolders' included), +// a catalog selection for exactly its nodes, and the nodes sitting in it directly. One pass. Pure. + +import type { CatalogNode, GroupStatus } from '$lib/api'; +import { shortName } from '$lib/build-area/labels'; +import { folderOf } from '$lib/lineage/catalog-graph'; +import { needsAttention } from './overview-panels'; +import { sortFolders } from './overview-panels'; + +export type FolderNode = GroupStatus & { + /** From the project's top, such as `payments/providers`; `group` is its last part. */ + path: string; + depth: number; + children: FolderNode[]; + /** Nodes in this folder itself, not in a subfolder. */ + members: CatalogNode[]; + /** A catalog selection of every node in it, subfolders included. */ + selection: string; +}; + +const dirOf = (path: string) => (path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : ''); + +export type FolderSort = 'urgency' | 'group' | 'current' | 'changed' | 'behind' | 'failed'; + +/** Folders sorted by a column: most urgent first, names A to Z, or counts largest first; `reverse` turns it round. */ +export function sortFolderRows(rows: readonly T[], by: FolderSort, reverse = false): T[] { + const urgent = sortFolders(rows) as T[]; + if (by === 'urgency') return reverse ? urgent.reverse() : urgent; + const rank = new Map(urgent.map((r, i) => [r, i])); + const sign = reverse ? -1 : 1; + return [...rows].sort((a, b) => (by === 'group' ? sign * a.group.localeCompare(b.group) : sign * (b[by] - a[by]) || rank.get(a)! - rank.get(b)!)); +} + +/** The top-level folders, each holding its subfolders, unsorted. Sources are left out, as on the Overview. */ +export function folderTree(nodes: readonly CatalogNode[]): FolderNode[] { + const byPath = new Map(); + const top: FolderNode[] = []; + for (const n of nodes) { + if (n.kind === 'source') continue; + const folder = folderOf(n); + const dir = dirOf(n.path); + // The file-system folder the catalog folder starts at, such as `models/`; null when the folder is a declared group. + const root = dir === folder || dir.endsWith(`/${folder}`) ? dir.slice(0, dir.length - folder.length) : null; + const parts = folder.split('/'); + const stale = n.stale ?? []; + const isChanged = stale.some((s) => s.reason !== 'behind'); + const isBehind = stale.some((s) => s.reason === 'behind'); + const isFailed = n.lastOutcome === 'failed'; + const isCurrent = !stale.length && !isFailed && !!n.lastBuild; + let parent: FolderNode | null = null; + for (let i = 0; i < parts.length; i++) { + const path = parts.slice(0, i + 1).join('/'); + let f = byPath.get(path); + if (!f) { + f = { group: parts[i], path, depth: i, total: 0, current: 0, changed: 0, behind: 0, failed: 0, children: [], members: [], selection: '', root, keys: [] }; + byPath.set(path, f); + (parent ? parent.children : top).push(f); + } + if (f.root !== root) f.root = null; + f.total += 1; + f.current += Number(isCurrent); + f.changed += Number(isChanged); + f.behind += Number(isBehind); + f.failed += Number(isFailed); + f.keys.push(shortName(n.key)); + if (i === parts.length - 1) f.members.push(n); + parent = f; + } + } + for (const f of byPath.values()) { + f.selection = f.root !== null ? `path:${f.root}${f.path}` : [...new Set(f.keys)].join(' '); + delete (f as { root?: unknown }).root; + delete (f as { keys?: unknown }).keys; + } + return top; +} + +/** Every folder path in the tree, for Expand all. */ +export function folderPaths(tree: readonly FolderNode[]): string[] { + return tree.flatMap((f) => [f.path, ...folderPaths(f.children)]); +} + +export type TreeRow = + | { kind: 'folder'; folder: FolderNode; expandable: boolean; expanded: boolean } + | { kind: 'node'; node: CatalogNode; depth: number } + | { kind: 'more'; folder: FolderNode; hidden: number }; + +const nodeNeedsAttention = (n: CatalogNode) => n.lastOutcome === 'failed' || !!n.stale?.length; + +/** + * The rows on screen: folders sorted within each level, an expanded folder's subfolders under it and, + * with `listNodes`, its own nodes after them, up to `nodeLimit` and then a row for the rest. With + * `attentionOnly`, fully current folders and nodes are left out. + */ +export function visibleTreeRows( + tree: readonly FolderNode[], + options: { expanded: ReadonlySet; sort: FolderSort; reverse: boolean; attentionOnly: boolean; listNodes: boolean; nodeLimit?: number } +): TreeRow[] { + const { expanded, sort, reverse, attentionOnly, listNodes, nodeLimit = 20 } = options; + const rows: TreeRow[] = []; + const walk = (level: readonly FolderNode[]) => { + for (const folder of sortFolderRows(attentionOnly ? level.filter(needsAttention) : level, sort, reverse)) { + const members = attentionOnly ? folder.members.filter(nodeNeedsAttention) : folder.members; + const expandable = folder.children.some((c) => !attentionOnly || needsAttention(c)) || (listNodes && members.length > 0); + const open = expandable && expanded.has(folder.path); + rows.push({ kind: 'folder', folder, expandable, expanded: open }); + if (!open) continue; + walk(folder.children); + if (!listNodes) continue; + const shown = [...members].sort((a, b) => Number(nodeNeedsAttention(b)) - Number(nodeNeedsAttention(a)) || shortName(a.key).localeCompare(shortName(b.key))); + for (const node of shown.slice(0, nodeLimit)) rows.push({ kind: 'node', node, depth: folder.depth + 1 }); + if (shown.length > nodeLimit) rows.push({ kind: 'more', folder, hidden: shown.length - nodeLimit }); + } + }; + walk(tree); + return rows; +} diff --git a/ui/src/lib/build-area/overview-panels.test.ts b/ui/src/lib/build-area/overview-panels.test.ts index 944fb8553d..29e7255cc6 100644 --- a/ui/src/lib/build-area/overview-panels.test.ts +++ b/ui/src/lib/build-area/overview-panels.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { GroupStatus, SnapshotChange } from '$lib/api'; -import { quietDeployLine, recentDeployRows, recentDeploys, sortFolders, visibleFolders } from './overview-panels'; +import { quietDeployLine, recentDeployRows, recentDeploys, sortFolders, cappedFolders } from './overview-panels'; const HOUR = 60 * 60 * 1000; const now = Date.parse('2026-11-16T12:00:00Z'); @@ -69,16 +69,14 @@ describe('build status by folder', () => { expect(sorted.map((g) => g.group)).toEqual(['returns', 'billing', 'inventory', 'alpha', 'customers', 'orders']); }); - it('shows eight folders, plus any beyond that need attention, until expanded', () => { + it('shows at most eight folders, most urgent first, however many need attention', () => { const calm = Array.from({ length: 12 }, (_, i) => folder(`calm_${String(i).padStart(2, '0')}`, 20 - i)); const attention = Array.from({ length: 10 }, (_, i) => folder(`busy_${i}`, 1, 0, 0, 1)); - expect(visibleFolders(calm, false)).toMatchObject({ hidden: 4 }); - expect(visibleFolders(calm, false).rows.map((g) => g.group)).toEqual(calm.slice(0, 8).map((g) => g.group)); - const mixed = visibleFolders([...calm, ...attention], false); - expect(mixed.rows).toHaveLength(10); + expect(cappedFolders(calm).rows.map((g) => g.group)).toEqual(calm.slice(0, 8).map((g) => g.group)); + const mixed = cappedFolders([...calm, ...attention]); + expect(mixed.rows).toHaveLength(8); expect(mixed.rows.every((g) => g.behind)).toBe(true); - expect(mixed.hidden).toBe(12); - expect(visibleFolders([...calm, ...attention], true)).toMatchObject({ hidden: 0 }); - expect(visibleFolders([...calm, ...attention], true).rows).toHaveLength(22); + expect([mixed.total, mixed.attention]).toEqual([22, 10]); + expect(cappedFolders(calm.slice(0, 3))).toMatchObject({ total: 3, attention: 0 }); }); }); diff --git a/ui/src/lib/build-area/overview-panels.ts b/ui/src/lib/build-area/overview-panels.ts index e18de01a36..cb54545890 100644 --- a/ui/src/lib/build-area/overview-panels.ts +++ b/ui/src/lib/build-area/overview-panels.ts @@ -6,7 +6,7 @@ import { plural } from '$lib/format/plural'; /** Deploys that changed something the Recent changes panel shows. */ export const RECENT_DEPLOYS = 4; -/** Folders the Build status panel shows before "Show all"; folders that need attention always show. */ +/** Folders the Overview's Build status card shows at most; the catalog's folder view lists them all. */ export const FOLDER_ROWS = 8; /** Whether a deploy changed any definition: a node, a job or trigger, a role or the environment. */ @@ -74,12 +74,9 @@ export function sortFolders(groups: readonly GroupStatus[]): GroupStatus[] { } /** - * The folder rows to show, sorted: the first `limit`, plus every folder beyond that needs attention, - * or all of them when expanded. `hidden` counts the rest, for "Show all N folders". + * The Overview card's folders: at most `limit`, most urgent first, however many need attention (the + * catalog's folder view lists them all), with how many there are and how many need attention. */ -export function visibleFolders(groups: readonly GroupStatus[], expanded: boolean, limit = FOLDER_ROWS): { rows: GroupStatus[]; hidden: number } { - const sorted = sortFolders(groups); - if (expanded) return { rows: sorted, hidden: 0 }; - const rows = sorted.filter((g, i) => i < limit || needsAttention(g)); - return { rows, hidden: sorted.length - rows.length }; +export function cappedFolders(groups: readonly GroupStatus[], limit = FOLDER_ROWS): { rows: GroupStatus[]; total: number; attention: number } { + return { rows: sortFolders(groups).slice(0, limit), total: groups.length, attention: groups.filter(needsAttention).length }; } diff --git a/ui/src/lib/components/build-area/folder-tree.svelte b/ui/src/lib/components/build-area/folder-tree.svelte new file mode 100644 index 0000000000..c8383f829f --- /dev/null +++ b/ui/src/lib/components/build-area/folder-tree.svelte @@ -0,0 +1,205 @@ + + +
+
+ {tree.length} folders · 0}>{needing} need attention + + + {#if sort !== 'urgency' || reverse}{/if} + + +
+ + {#snippet head(c)} + {#if c.id !== 'bar'} + + {/if} + {/snippet} + {#snippet row(r)} + {#if r.kind === 'folder'} + {@const f = r.folder} + + labelClick(e, r)} data-testid="folder-label"> +
+ {#if r.expandable} + + {:else} + + {/if} + {#if r.expanded}{:else}{/if} + open(e, f.selection)} title="Open {f.path} in the catalog" data-testid="folder-name">{f.group} + {#if !r.expanded && f.children.length}{f.children.length} subfolders{/if} +
+ + + + + + + + + {f.current}/{f.total} + {#each COUNTS as c (c.id)} + {@const n = f[c.id]} + {#if n} open(e, f.selection, c.id)} style:color={c.tone} title="Open its {n} {c.id} nodes in the catalog" data-testid="folder-count-{c.id}">{n}{:else}—{/if} + {/each} + + {:else if r.kind === 'node'} + {@const n = r.node} + {@const Glyph = nodeIcon[nodeIconKey(n)] ?? nodeIcon.table} + {@const state = nodeState(n)} + + +
+ + {#if linksNodes}{shortName(n.key)}{:else}{shortName(n.key)}{/if} +
+ + {state.label} + + + + + + {:else} + + + + + + + + + + + {/if} + {/snippet} +
+
+ + diff --git a/ui/src/routes/+page.svelte b/ui/src/routes/+page.svelte index bea80a0641..c3e5dda8a1 100644 --- a/ui/src/routes/+page.svelte +++ b/ui/src/routes/+page.svelte @@ -29,7 +29,7 @@ import { acknowledgementOf } from '$lib/build-area/attention-conditions'; import { formatCredits } from '$lib/build-area/labels'; import { nodeChangeLine, summarizeChange } from '$lib/build-area/changes'; - import { quietDeployLine, recentDeployRows, visibleFolders } from '$lib/build-area/overview-panels'; + import { cappedFolders, quietDeployLine, recentDeployRows } from '$lib/build-area/overview-panels'; import { pagesBeyondTarget } from '$lib/nav'; import OverviewCost from './overview-cost.svelte'; @@ -99,10 +99,9 @@ const successRate = $derived(m && finished ? Math.round(((m.runs24h.success + m.runs24h.warn) / finished) * 100) : null); const costChange = $derived(m?.cost && m.cost.baseline ? Math.round(((m.cost.last24h - m.cost.baseline) / m.cost.baseline) * 100) : null); const groups = $derived(data?.groups ?? []); - let showAllFolders = $state(false); - const folders = $derived(visibleFolders(groups, showAllFolders)); - // Whether collapsing hides any folders; folders that need attention always show. - const collapsedHidden = $derived(visibleFolders(groups, false).hidden); + // At most eight folders, most urgent first; the catalog's folder view lists them all. + const folders = $derived(cappedFolders(groups)); + const ALL_FOLDERS_HREF = '/catalog?view=folders'; const deployRows = $derived(recentDeployRows(data?.recentChanges ?? [])); // Parts without a server read stay hidden rather than showing zeros, and wait for the read so they don't appear and vanish. const showGroups = $derived(!!data?.groups?.length); @@ -288,8 +287,8 @@ {:else}
{#if overview.data === undefined && !overview.error}{:else}Nothing deployed yet.{/if}
{/each} - {#if collapsedHidden} - + {#if folders.total > folders.rows.length} + All {folders.total} folders ({folders.attention} need attention) → {/if}
{/if} @@ -360,6 +359,8 @@ .issue-actions { justify-content: flex-end; gap: 10px; } .issue-actions a { color: var(--primary); font-weight: 500; white-space: nowrap; } .handled { border-top: 1px solid var(--inner-line); } + .all-folders { align-self: flex-start; margin: 6px 16px 4px; color: var(--primary); font-size: 12px; font-weight: 500; } + .all-folders:hover { text-decoration: underline; } .lapsed { margin: 4px 0 0; color: var(--sb-warning); font-size: 12px; } /* Ack: muted text with a bell, always visible; on row hover it gains a border and full colour. */ .issue :global(.ack) { height: 24px; padding: 0 8px; border: 1px solid transparent; color: var(--muted-foreground); font-size: 12px; font-weight: 500; } diff --git a/ui/src/routes/catalog/+page.svelte b/ui/src/routes/catalog/+page.svelte index 942ac55509..dcf94d62ee 100644 --- a/ui/src/routes/catalog/+page.svelte +++ b/ui/src/routes/catalog/+page.svelte @@ -25,6 +25,7 @@ import { folderOf } from '$lib/lineage/catalog-graph'; import { app } from '$lib/state/app.svelte'; import { useCatalogNodes } from '$lib/state/catalog.svelte'; + import FolderTree from '$lib/components/build-area/folder-tree.svelte'; import DataTable from '$lib/components/list/data-table.svelte'; import type { TableColumn } from '$lib/components/list/table-columns'; import { formatAgo, formatStamp } from '$lib/format/time'; @@ -40,7 +41,25 @@ const params = page.url.searchParams; let query = $state(params.get('q') ?? ''); let kindFilter = $state<'all' | KindTab>(parseKindTab(params.get('kind')) ?? 'all'); - let statusFilter = $state(params.get('stale') ? ['stale'] : []); + const STATUS_FILTERS: StatusFilter[] = ['stale', 'changed', 'behind', 'failed', 'warn']; + // `?status=` comes from links such as a folder's failed count; `?stale=1` from older ones. + let statusFilter = $state([...(params.get('stale') ? ['stale' as const] : []), ...STATUS_FILTERS.filter((s) => params.getAll('status').includes(s))]); + // The nodes grouped by folder, as a tree, or listed; kept in `?view=`. + let byFolder = $state(params.get('view') === 'folders'); + async function showFolders(on: boolean) { + byFolder = on; + const url = new URL(page.url); + if (on) url.searchParams.set('view', 'folders'); + else url.searchParams.delete('view'); + await goto(url, { replaceState: true, noScroll: true, keepFocus: true }); + } + /** Opens a folder's nodes, or its nodes of one status, in the list. The view leaves the URL first, so the + * selection bar then writes its selection onto that URL, after it, not at the same time. */ + async function openFolder(select: string, status: string | null) { + statusFilter = status ? [status as StatusFilter] : []; + await showFolders(false); + selection.select = select; + } // What `sqb build -s … --exclude …` selects, kept in the URL; Status only changes the view. const selection = createSelection({ url: true, replaces: ['group'] }); // Older links name top-level folders with `?group=`: once the nodes are known, each becomes its selection. @@ -140,6 +159,7 @@ : []} > {#snippet filters()} + {#if showBuildState} showFolders(v === 'folders')} />{/if} {#if picked.size}{/if} +{#if byFolder && showBuildState} + +{:else} n.key} rowHeight={ROW_H} resource={catalog} empty={all.length ? 'No nodes match the filter.' : 'Nothing deployed yet.'}> {#snippet row(n)} {@const Glyph = nodeIcon[nodeIconKey(n)] ?? nodeIcon.table} @@ -188,6 +211,7 @@ {/snippet} +{/if}