diff --git a/clients/typescript/src/schema.d.ts b/clients/typescript/src/schema.d.ts index 6a1859dfb7..8b024845a3 100644 --- a/clients/typescript/src/schema.d.ts +++ b/clients/typescript/src/schema.d.ts @@ -786,6 +786,22 @@ export interface paths { patch?: never; trace?: never; }; + "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/ignored-audits": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + get: operations["listPersonRunIgnoredAudits"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/nodes": { parameters: { query?: never; @@ -3312,6 +3328,25 @@ export interface components { }; sqb_version: string; }; + /** @description One error-severity audit failure a run or one of its current members let through; never its SQL or evidence. */ + RunIgnoredAuditFailure: { + attached_column_name?: string | null; + attached_target_kind?: string | null; + attached_target_name?: string | null; + audit_name: string; + /** @description The check's identity, as the checks endpoints name it. */ + binding_key?: string | null; + job_key?: string | null; + occurred_at: string; + /** + * Format: uuid + * @description The run that evaluated the audit: the run itself or one of its group members. + */ + run_id: string; + severity: string; + /** Format: int64 */ + violation_count?: number | null; + }; /** @enum {string} */ RunKind: "job" | "group" | "adhoc"; /** @description The `sqb build` selectors one run of a job was narrowed with. */ @@ -5984,7 +6019,7 @@ export interface operations { parameters: { query: { /** @description The section to page */ - section: "full_refresh" | "query_changed" | "function_changed" | "config_changed" | "schema_changed" | "first_run" | "renamed" | "routine_models" | "migrations" | "column_migrations" | "table_type_conversions" | "retention" | "loader_reloads" | "loader_loads" | "source_reloads" | "source_loads" | "changed_functions" | "functions" | "seeds" | "python_nodes" | "held_back" | "unchanged" | "warnings"; + section: "full_refresh" | "query_changed" | "function_changed" | "config_changed" | "schema_changed" | "first_run" | "renamed" | "routine_models" | "migrations" | "column_migrations" | "table_type_conversions" | "retention" | "loader_reloads" | "loader_loads" | "source_reloads" | "source_loads" | "changed_functions" | "functions" | "first_run_seeds" | "changed_seeds" | "unchanged_seeds" | "python_nodes" | "held_back" | "unchanged" | "warnings"; /** @description Rows to skip; 0 by default */ offset?: number; /** @description At most this many rows, capped at 1000 */ @@ -6253,6 +6288,52 @@ export interface operations { }; }; }; + listPersonRunIgnoredAudits: { + parameters: { + query?: never; + header?: never; + path: { + location_id: string; + target: string; + run_id: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description The error-severity audit failures the run and its current group members let through, run by run */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["RunIgnoredAuditFailure"][]; + }; + }; + /** @description Session rejected */ + 401: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + 403: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["ApiErrorBody"]; + }; + }; + /** @description Run not found for a person who may view the whole target */ + 404: { + headers: { + [name: string]: unknown; + }; + content?: never; + }; + }; + }; listPersonRunNodes: { parameters: { query?: never; diff --git a/crates/sqlbuild-core/src/plan_display/_helpers/diff_lines.rs b/crates/sqlbuild-core/src/plan_display/_helpers/diff_lines.rs index b580bff995..9b6fff0bc1 100644 --- a/crates/sqlbuild-core/src/plan_display/_helpers/diff_lines.rs +++ b/crates/sqlbuild-core/src/plan_display/_helpers/diff_lines.rs @@ -1,6 +1,8 @@ -//! A unified diff's added and removed lines, and whether they differ only in whitespace. +//! A unified diff's added and removed lines, whether they differ only in whitespace, and a short config change in words. -use crate::plan_display::constants::DIFF_HEADER_PREFIXES; +use crate::plan_display::constants::{ + CONFIG_CHANGE_KEYS, CONFIG_TOP_LEVEL_INDENT, DIFF_HEADER_PREFIXES, UNSET_CONFIG_VALUE, +}; use crate::plan_display::models::DiffStats; /// The diff's changed lines; whitespace-only when they match with all whitespace out, so case changes count. @@ -41,3 +43,64 @@ fn without_whitespace(lines: &[&str]) -> String { .filter(|character| !character.is_whitespace()) .collect() } + +/// A config diff's changes in one line, such as `full_refresh true → false`, when it changes at most two top-level keys with plain values. +pub(crate) fn config_change(diff: &[String]) -> Option { + let mut values: Vec<(&str, Option<&str>, Option<&str>)> = Vec::new(); + for line in diff { + let removed = line.starts_with('-'); + if DIFF_HEADER_PREFIXES + .iter() + .any(|prefix| line.starts_with(prefix)) + || !(removed || line.starts_with('+')) + { + continue; + } + let (key, value) = config_value(&line[1..])?; + let at = match values.iter().position(|(known, _, _)| *known == key) { + Some(at) => at, + None => { + values.push((key, None, None)); + values.len() - 1 + } + }; + if removed { + values[at].1 = Some(value); + } else { + values[at].2 = Some(value); + } + } + values.retain(|(_, old, new)| old != new); + if values.is_empty() || values.len() > CONFIG_CHANGE_KEYS { + return None; + } + let changes: Vec = values + .into_iter() + .map(|(key, old, new)| { + format!( + "{key} {} → {}", + old.unwrap_or(UNSET_CONFIG_VALUE), + new.unwrap_or(UNSET_CONFIG_VALUE) + ) + }) + .collect(); + Some(changes.join("; ")) +} + +/// One top-level `"key": value` line's key and plain value, the config printed with two-space indents; `None` for a nested key or value, or any other line. +fn config_value(line: &str) -> Option<(&str, &str)> { + let (key, rest) = line + .strip_prefix(CONFIG_TOP_LEVEL_INDENT)? + .strip_prefix('"')? + .split_once('"')?; + let value = rest.strip_prefix(':')?.trim(); + let value = value.strip_suffix(',').unwrap_or(value).trim_end(); + if key.is_empty() || value.ends_with('{') || value.ends_with('[') { + return None; + } + let plain = value + .strip_prefix('"') + .and_then(|inner| inner.strip_suffix('"')) + .unwrap_or(value); + Some((key, plain)) +} diff --git a/crates/sqlbuild-core/src/plan_display/_helpers/mod.rs b/crates/sqlbuild-core/src/plan_display/_helpers/mod.rs index dfac590318..d58fc51df7 100644 --- a/crates/sqlbuild-core/src/plan_display/_helpers/mod.rs +++ b/crates/sqlbuild-core/src/plan_display/_helpers/mod.rs @@ -3,3 +3,4 @@ pub(crate) mod labels; pub(crate) mod migration_sections; pub(crate) mod plan_pages; pub(crate) mod plan_sections; +pub(crate) mod warning_groups; diff --git a/crates/sqlbuild-core/src/plan_display/_helpers/plan_pages.rs b/crates/sqlbuild-core/src/plan_display/_helpers/plan_pages.rs index d2833280c3..b754ee080d 100644 --- a/crates/sqlbuild-core/src/plan_display/_helpers/plan_pages.rs +++ b/crates/sqlbuild-core/src/plan_display/_helpers/plan_pages.rs @@ -5,11 +5,14 @@ use std::collections::{HashMap, HashSet}; use serde_json::Value; use crate::plan_display::_helpers::diff_lines::diff_stats; -use crate::plan_display::constants::{DIFF_STATS_FIELD, NO_CHANGE_REASON, SKIP_ACTION}; +use crate::plan_display::_helpers::warning_groups::warning_groups; +use crate::plan_display::constants::{ + DIFF_STATS_FIELD, FIRST_RUN_REASON, NO_CHANGE_REASON, SKIP_ACTION, +}; use crate::plan_display::models::PlanPageSection; /// Every section, in the order the plan reads, with its name in the API. -pub(crate) const SECTIONS: [(PlanPageSection, &str); 23] = [ +pub(crate) const SECTIONS: [(PlanPageSection, &str); 25] = [ (PlanPageSection::FullRefresh, "full_refresh"), (PlanPageSection::QueryChanged, "query_changed"), (PlanPageSection::FunctionChanged, "function_changed"), @@ -31,7 +34,9 @@ pub(crate) const SECTIONS: [(PlanPageSection, &str); 23] = [ (PlanPageSection::SourceLoads, "source_loads"), (PlanPageSection::ChangedFunctions, "changed_functions"), (PlanPageSection::Functions, "functions"), - (PlanPageSection::Seeds, "seeds"), + (PlanPageSection::FirstRunSeeds, "first_run_seeds"), + (PlanPageSection::ChangedSeeds, "changed_seeds"), + (PlanPageSection::UnchangedSeeds, "unchanged_seeds"), (PlanPageSection::PythonNodes, "python_nodes"), (PlanPageSection::HeldBack, "held_back"), (PlanPageSection::Unchanged, "unchanged"), @@ -89,11 +94,16 @@ impl<'document> PlanRows<'document> { PlanPageSection::SourceLoads => self.loads("source", false), PlanPageSection::ChangedFunctions => self.functions(true), PlanPageSection::Functions => self.functions(false), - PlanPageSection::Seeds => self.seeds(), + PlanPageSection::FirstRunSeeds + | PlanPageSection::ChangedSeeds + | PlanPageSection::UnchangedSeeds => self.seeds(section), PlanPageSection::PythonNodes => self.list("python_nodes"), PlanPageSection::HeldBack => self.changed_list("held_back"), PlanPageSection::Unchanged => self.changed_list("unchanged"), - PlanPageSection::Warnings => self.list("warnings"), + PlanPageSection::Warnings => warning_groups(&self.list("warnings")) + .into_iter() + .flat_map(|group| group.warnings) + .collect(), model_section => self.models(model_section), } } @@ -149,8 +159,10 @@ impl<'document> PlanRows<'document> { }) } - fn seeds(&self) -> Vec<&'document Value> { - self.kept("seeds", |seed| self.runs_node(&node_key("seed", seed))) + fn seeds(&self, section: PlanPageSection) -> Vec<&'document Value> { + self.kept("seeds", |seed| { + self.runs_node(&node_key("seed", seed)) && seed_section(seed) == section + }) } /// The `--changed` run of a model or seed row. @@ -176,7 +188,9 @@ impl<'document> PlanRows<'document> { PlanPageSection::ChangedFunctions | PlanPageSection::Functions => { &[("language", "language"), ("reason", "reason")] } - PlanPageSection::Seeds => &[("reason", "reason")], + PlanPageSection::FirstRunSeeds + | PlanPageSection::ChangedSeeds + | PlanPageSection::UnchangedSeeds => &[("reason", "reason")], PlanPageSection::PythonNodes => &[ ("kind", "kind"), ("identity_status", "identity_status"), @@ -201,7 +215,11 @@ impl<'document> PlanRows<'document> { notes.push(("completed", Some(completed.to_string()))); } PlanPageSection::HeldBack => notes.extend(held_back_notes(row)), - PlanPageSection::Seeds => notes.extend(self.run_notes(&node_key("seed", row))), + PlanPageSection::FirstRunSeeds + | PlanPageSection::ChangedSeeds + | PlanPageSection::UnchangedSeeds => { + notes.extend(self.run_notes(&node_key("seed", row))); + } section if model_rows(section) => { notes.extend(self.run_notes(&node_key("model", row))); notes.extend(model_notes(row)); @@ -310,6 +328,15 @@ pub(crate) fn model_rows(section: PlanPageSection) -> bool { || section == PlanPageSection::RoutineModels } +/// A seed's section by its plan reason: a first run, no change of its own, or any other change. +fn seed_section(seed: &Value) -> PlanPageSection { + match text(seed, "reason") { + FIRST_RUN_REASON => PlanPageSection::FirstRunSeeds, + "" | NO_CHANGE_REASON => PlanPageSection::UnchangedSeeds, + _ => PlanPageSection::ChangedSeeds, + } +} + fn model_section(model: &Value) -> PlanPageSection { let reason = text(model, "reason"); MODEL_REASONS diff --git a/crates/sqlbuild-core/src/plan_display/_helpers/plan_sections.rs b/crates/sqlbuild-core/src/plan_display/_helpers/plan_sections.rs index 0985ac6288..0bdb015abd 100644 --- a/crates/sqlbuild-core/src/plan_display/_helpers/plan_sections.rs +++ b/crates/sqlbuild-core/src/plan_display/_helpers/plan_sections.rs @@ -4,12 +4,15 @@ use std::collections::{HashMap, HashSet}; use serde_json::{Map, Value, json}; +use crate::plan_display::_helpers::diff_lines::config_change; use crate::plan_display::_helpers::plan_pages::{ - Note, PlanRows, SECTIONS, model_rows, node_key, row_diff_stats, row_name, text, warnings_about, + Note, PlanRows, SECTIONS, lines, model_rows, node_key, row_diff_stats, row_name, text, + warnings_about, }; +use crate::plan_display::_helpers::warning_groups::{group_json, warning_groups}; use crate::plan_display::constants::{ - CHANGED_ROW_LISTS, DIFF_STATS_FIELD, MAX_SECTION_NOTES, METADATA_FIELD, MODEL_DIFF_FIELDS, - PLAN_ROW_LISTS, + CHANGED_ROW_LISTS, CONFIG_CHANGE_FIELD, DIFF_STATS_FIELD, MAX_SECTION_NOTES, + MAX_WARNING_GROUPS, METADATA_FIELD, MODEL_DIFF_FIELDS, PLAN_ROW_LISTS, WARNING_GROUPS_FIELD, }; use crate::plan_display::models::PlanPageSection; @@ -70,6 +73,20 @@ pub(crate) fn emptied(fields: &Map) -> Map { summary } +/// The summary's largest warning groups, at most `MAX_WARNING_GROUPS`; the warnings section pages the rest after them. +pub(crate) fn with_warning_groups( + plan: &PlanRows<'_>, + mut summary: Map, +) -> Map { + let groups: Vec = warning_groups(&plan.rows(PlanPageSection::Warnings)) + .iter() + .take(MAX_WARNING_GROUPS) + .map(group_json) + .collect(); + summary.insert(WARNING_GROUPS_FIELD.to_owned(), Value::Array(groups)); + summary +} + /// The rows whose name contains `name`, ignoring case; every row without a name. pub(crate) fn matching<'document>( section: PlanPageSection, @@ -103,7 +120,9 @@ pub(crate) fn page_extras( page: &[&Value], ) -> PageExtras { let kind = match section { - PlanPageSection::Seeds => "seed", + PlanPageSection::FirstRunSeeds + | PlanPageSection::ChangedSeeds + | PlanPageSection::UnchangedSeeds => "seed", section if model_rows(section) => "model", _ => return PageExtras::default(), }; @@ -125,7 +144,7 @@ pub(crate) fn page_extras( } names.insert(name.to_owned()); } - if section != PlanPageSection::Seeds { + if model_rows(section) { extras.warnings = warnings_about(plan.document, &names) .into_iter() .cloned() @@ -146,6 +165,9 @@ pub(crate) fn shown_row(section: PlanPageSection, row: &Value) -> Value { .map(|(field, value)| (field.clone(), value.clone())) .collect(); shown.remove(DIFF_STATS_FIELD); + if let Some(change) = lines(row, "config_diff").and_then(|diff| config_change(&diff)) { + shown.insert(CONFIG_CHANGE_FIELD.to_owned(), Value::String(change)); + } if !stats.is_empty() { shown.insert(DIFF_STATS_FIELD.to_owned(), Value::Object(stats)); } diff --git a/crates/sqlbuild-core/src/plan_display/_helpers/warning_groups.rs b/crates/sqlbuild-core/src/plan_display/_helpers/warning_groups.rs new file mode 100644 index 0000000000..a1522774ad --- /dev/null +++ b/crates/sqlbuild-core/src/plan_display/_helpers/warning_groups.rs @@ -0,0 +1,141 @@ +//! Plan warnings grouped by message template, so one message about many names reads once. + +use std::collections::{HashMap, HashSet}; + +use serde_json::{Value, json}; + +use crate::plan_display::_helpers::plan_pages::text; +use crate::plan_display::constants::{ELIDED_NAME, QUOTE_CHARACTERS}; + +/// One template and its warnings in plan order. +pub(crate) struct WarningGroup<'document> { + pub(crate) template: String, + pub(crate) warnings: Vec<&'document Value>, +} + +/// Warnings grouped by template, largest group first and groups of a size in the order they first appear. +pub(crate) fn warning_groups<'document>( + warnings: &[&'document Value], +) -> Vec> { + let mut groups: Vec> = Vec::new(); + let mut index: HashMap = HashMap::new(); + for warning in warnings { + let template = warning_template(warning); + let at = *index.entry(template.clone()).or_insert_with(|| { + groups.push(WarningGroup { + template, + warnings: Vec::new(), + }); + groups.len() - 1 + }); + groups[at].warnings.push(warning); + } + groups.sort_by_key(|group| std::cmp::Reverse(group.warnings.len())); + groups +} + +/// A group as the summary lists it: its template, size, and the things it names when they repeat. +pub(crate) fn group_json(group: &WarningGroup<'_>) -> Value { + json!({ + "template": group.template, + "count": group.warnings.len(), + "subject": subject(group), + }) +} + +/// A template opening with a noun, such as `scenario …`, whose warnings name fewer of those than they number. +fn subject(group: &WarningGroup<'_>) -> Value { + let noun = group + .template + .split_once(" …") + .map(|(noun, _)| noun) + .filter(|noun| !noun.is_empty() && noun.chars().all(is_word)); + let named: Option> = group + .warnings + .iter() + .map(|warning| named(warning)) + .collect(); + match (noun, named) { + (Some(noun), Some(named)) + if group.warnings.len() > 1 && named.len() < group.warnings.len() => + { + json!({"noun": noun.to_lowercase(), "count": named.len()}) + } + _ => Value::Null, + } +} + +/// The message without its leading model name, with quoted names and generated-looking names elided. +fn warning_template(warning: &Value) -> String { + let message = text(warning, "message"); + let model = text(warning, "model_name"); + let message = message + .strip_prefix(model) + .and_then(|rest| rest.strip_prefix(':')) + .filter(|_| !model.is_empty()) + .map_or(message, str::trim); + let template = elide_generated(&elide_quoted(message)); + match template.strip_suffix('.') { + Some(rest) if rest.ends_with(ELIDED_NAME) => rest.to_owned(), + _ => template, + } +} + +/// Each `'…'`, `` `…` `` or `"…"` span as one elision; an unclosed quote stays. +fn elide_quoted(message: &str) -> String { + let mut out = String::with_capacity(message.len()); + let mut rest = message; + while let Some(character) = rest.chars().next() { + let after = &rest[character.len_utf8()..]; + if QUOTE_CHARACTERS.contains(&character) + && let Some(end) = after.find(character) + { + out.push_str(ELIDED_NAME); + rest = &after[end + character.len_utf8()..]; + } else { + out.push(character); + rest = after; + } + } + out +} + +/// Each word with a digit or a double underscore, as generated names have, as one elision. +fn elide_generated(message: &str) -> String { + let mut out = String::with_capacity(message.len()); + let mut word = String::new(); + for character in message.chars().chain(std::iter::once(' ')) { + if is_word(character) { + word.push(character); + continue; + } + if word.contains("__") || word.chars().any(|letter| letter.is_ascii_digit()) { + out.push_str(ELIDED_NAME); + } else { + out.push_str(&word); + } + word.clear(); + out.push(character); + } + out.pop(); + out +} + +/// The nonempty name a warning's message quotes first. +fn named(warning: &Value) -> Option<&str> { + first_quoted(text(warning, "message")).filter(|name| !name.is_empty()) +} + +/// The text inside the message's first quoted span. +fn first_quoted(message: &str) -> Option<&str> { + let (start, quote) = message.char_indices().find(|(at, character)| { + QUOTE_CHARACTERS.contains(character) + && message[at + character.len_utf8()..].contains(*character) + })?; + let inner = &message[start + quote.len_utf8()..]; + inner.split(quote).next() +} + +const fn is_word(character: char) -> bool { + character.is_ascii_alphanumeric() || character == '_' +} diff --git a/crates/sqlbuild-core/src/plan_display/constants.rs b/crates/sqlbuild-core/src/plan_display/constants.rs index 1a3c792237..7642d785e7 100644 --- a/crates/sqlbuild-core/src/plan_display/constants.rs +++ b/crates/sqlbuild-core/src/plan_display/constants.rs @@ -47,6 +47,8 @@ pub const SYNCED_COPY_DEFER_HELP: &str = "Run re-plans live, including deferral. pub(crate) const SKIP_ACTION: &str = "skip"; /// The reason of a function or seed without a change. pub(crate) const NO_CHANGE_REASON: &str = "no_change"; +/// The reason of a model or seed without a recorded build. +pub(crate) const FIRST_RUN_REASON: &str = "first_run"; /// The plan document field of per-model metadata, which a summary leaves out. pub(crate) const METADATA_FIELD: &str = "metadata"; /// The plan document's row lists, which a summary empties and counts by section instead. @@ -72,3 +74,19 @@ pub(crate) const DIFF_HEADER_PREFIXES: [&str; 3] = ["---", "+++", "@@"]; pub const MODEL_DIFF_FIELDS: [&str; 2] = ["query_diff", "config_diff"]; /// The model field holding the counts of its diffs, kept when the diff text is not. pub const DIFF_STATS_FIELD: &str = "diff_stats"; +/// The model field of a short config change in words, such as `full_refresh true → false`. +pub const CONFIG_CHANGE_FIELD: &str = "config_change"; +/// The most top-level config keys a config change reads in one line. +pub(crate) const CONFIG_CHANGE_KEYS: usize = 2; +/// The indent of a top-level key in a config diff, which prints the config as JSON with two-space indents. +pub(crate) const CONFIG_TOP_LEVEL_INDENT: &str = " "; +/// A config key's value on the side of a change where it is not set. +pub(crate) const UNSET_CONFIG_VALUE: &str = "(unset)"; +/// What a warning template says in place of a quoted or generated name. +pub(crate) const ELIDED_NAME: &str = "…"; +/// The quotes a warning puts around a name. +pub(crate) const QUOTE_CHARACTERS: [char; 3] = ['\'', '`', '"']; +/// The summary field listing warning templates with their counts. +pub(crate) const WARNING_GROUPS_FIELD: &str = "warning_groups"; +/// The most warning groups a summary lists, the largest first; warnings past them page as the rest. +pub(crate) const MAX_WARNING_GROUPS: usize = 50; diff --git a/crates/sqlbuild-core/src/plan_display/main/detach_model_diffs.rs b/crates/sqlbuild-core/src/plan_display/main/detach_model_diffs.rs index 6f7430ef24..8d3163ef57 100644 --- a/crates/sqlbuild-core/src/plan_display/main/detach_model_diffs.rs +++ b/crates/sqlbuild-core/src/plan_display/main/detach_model_diffs.rs @@ -4,11 +4,12 @@ use std::collections::BTreeMap; use serde_json::Value; +use crate::plan_display::_helpers::diff_lines::config_change; use crate::plan_display::_helpers::plan_pages::{lines, row_diff_stats, text}; -use crate::plan_display::constants::{DIFF_STATS_FIELD, MODEL_DIFF_FIELDS}; +use crate::plan_display::constants::{CONFIG_CHANGE_FIELD, DIFF_STATS_FIELD, MODEL_DIFF_FIELDS}; use crate::plan_display::models::PlanModelDiff; -/// The document without model diff text, each model keeping its `diff_stats`, and the text by model. +/// The document without model diff text, each model keeping its `diff_stats` and short `config_change`, and the text by model. pub fn detach_model_diffs(mut document: Value) -> (Value, BTreeMap) { let mut diffs: BTreeMap = BTreeMap::new(); let models = document.get_mut("models").and_then(Value::as_array_mut); @@ -21,12 +22,16 @@ pub fn detach_model_diffs(mut document: Value) -> (Value, BTreeMap Value { let Some(fields) = document .as_object() @@ -13,8 +13,9 @@ pub fn plan_summary(document: &Value) -> Value { else { return document.clone(); }; - let (sections, pages) = section_counts(&PlanRows::new(document)); - let mut summary = emptied(fields); + let plan = PlanRows::new(document); + let (sections, pages) = section_counts(&plan); + let mut summary = with_warning_groups(&plan, emptied(fields)); summary.insert("sections".into(), Value::Array(sections)); summary.insert("pages".into(), Value::Object(pages)); Value::Object(summary) diff --git a/crates/sqlbuild-core/src/plan_display/models.rs b/crates/sqlbuild-core/src/plan_display/models.rs index ab3b885902..6707c45711 100644 --- a/crates/sqlbuild-core/src/plan_display/models.rs +++ b/crates/sqlbuild-core/src/plan_display/models.rs @@ -59,8 +59,12 @@ pub enum PlanPageSection { ChangedFunctions, /// Functions without a change. Functions, - /// Seeds the run loads or reports on. - Seeds, + /// Seeds the run loads for the first time. + FirstRunSeeds, + /// Seeds whose definition or settings changed. + ChangedSeeds, + /// Seeds the run loads or reports on without a change of their own. + UnchangedSeeds, PythonNodes, /// `--changed` nodes held back for a job's own run. HeldBack, diff --git a/crates/sqlbuild-core/src/plan_display/tests/helpers.rs b/crates/sqlbuild-core/src/plan_display/tests/helpers.rs index 62801e5272..d3bf33a6d2 100644 --- a/crates/sqlbuild-core/src/plan_display/tests/helpers.rs +++ b/crates/sqlbuild-core/src/plan_display/tests/helpers.rs @@ -38,16 +38,53 @@ pub(super) fn full_plan() -> serde_json::Value { let mut payments = planned_model("payments", ("create_table", "query_changed")); payments["query_diff"] = serde_json::json!(["-select id", "+SELECT id"]); payments["config_diff"] = serde_json::json!(["- \"tags\": []", "+ \"tags\": [\"finance\"]"]); + let mut totals = planned_model("totals", ("create_table", "config_changed")); + totals["config_diff"] = serde_json::json!([ + "--- a", + "+++ b", + "@@ -1,2 +1,2 @@", + " \"materialized\": \"table\",", + "- \"full_refresh\": true,", + "+ \"full_refresh\": false," + ]); + let mut daily_orders = planned_model("daily_orders", ("create_table", "first_run")); + daily_orders["config_diff"] = serde_json::json!([ + "--- a", + "+++ b", + "@@ -2,3 +2,3 @@", + " \"meta\": {", + "- \"owner\": \"sales\"", + "+ \"owner\": \"finance\"", + " }," + ]); + let mut daily_payments = planned_model("daily_payments", ("create_table", "first_run")); + daily_payments["config_diff"] = serde_json::json!([ + "--- a", + "+++ b", + "@@ -1,3 +1,4 @@", + "- \"materialized\": \"table\"", + "+ \"materialized\": \"table\",", + "+ \"tags\": \"none\"" + ]); + let mut ledger = planned_model("ledger", ("create_table", "schema_changed")); + ledger["config_diff"] = serde_json::json!([ + "- \"grain\": \"hour\",", + "+ \"grain\": \"day\",", + "- \"lookback\": 2,", + "+ \"lookback\": 3,", + "- \"partition_by\": \"event_date\"", + "+ \"partition_by\": \"event_hour\"" + ]); serde_json::json!({ "selected_count": 12, "models": [ orders, payments, planned_model("refunds", ("create_table", "function_changed")), - planned_model("totals", ("create_table", "config_changed")), - planned_model("ledger", ("create_table", "schema_changed")), - planned_model("daily_orders", ("create_table", "first_run")), - planned_model("daily_payments", ("create_table", "first_run")), + totals, + ledger, + daily_orders, + daily_payments, planned_model("old_orders", ("create_table", "renamed")), planned_model("archive", ("create_table", "full_refresh")), planned_model("customers", ("create_view", "no_change")), @@ -56,7 +93,12 @@ pub(super) fn full_plan() -> serde_json::Value { planned_model("skipped_model", ("skip", "no_change")), planned_model("not_run", ("create_view", "no_change")), ], - "seeds": [{"name": "countries", "reason": "first_run"}, {"name": "idle_seed", "reason": "no_change"}], + "seeds": [ + {"name": "countries", "reason": "first_run"}, + {"name": "currency_rates", "reason": "config_changed"}, + {"name": "regions", "reason": "no_change"}, + {"name": "idle_seed", "reason": "no_change"}, + ], "source_loads": [ {"name": "raw_orders", "kind": "loader", "is_reload": true, "write_strategy": "replace"}, {"name": "raw_payments", "kind": "loader", "is_reload": false, "write_strategy": "append"}, @@ -69,8 +111,12 @@ pub(super) fn full_plan() -> serde_json::Value { ], "python_nodes": [{"name": "score_orders", "kind": "task", "phase": "after", "identity_status": "changed"}], "warnings": [ - {"severity": "warning", "message": "orders: already-built dates keep their old results"}, - {"severity": "warning", "message": "scenario 'checkout' is stale", "code": "W1"}, + {"severity": "warning", "model_name": "orders", "message": "orders: already-built dates keep their old results"}, + {"severity": "warning", "message": "scenario 'checkout' step 'pay' is stale", "code": "W1"}, + {"severity": "warning", "message": "model stg__orders_2 has no tests."}, + {"severity": "warning", "message": "scenario 'checkout' step 'ship' is stale", "code": "W1"}, + {"severity": "warning", "message": "model stg__customers_3 has no tests."}, + {"severity": "warning", "message": "scenario 'returns' step `refund` is stale", "code": "W1"}, ], "migrations": [{"model": "old_orders", "origin_model": "orders_v1", "decision": "rename", "completed_at": null}], "column_migrations": [{"model": "ledger", "origin_column": "amt", "destination_column": "amount", "decision": "rename"}], @@ -95,6 +141,8 @@ pub(super) fn full_plan() -> serde_json::Value { {"node": "model:Customer_Notes", "reason": "no completed record", "downstream_of": null}, {"node": "model:events", "reason": "no completed record", "downstream_of": null}, {"node": "seed:countries", "reason": "no completed record", "downstream_of": null}, + {"node": "seed:currency_rates", "reason": "definition changed", "downstream_of": null}, + {"node": "seed:regions", "reason": "no completed record", "downstream_of": null}, ], "held_back": [ {"node": "model:daily_revenue", "refreshed_by": ["finance"]}, @@ -105,8 +153,8 @@ pub(super) fn full_plan() -> serde_json::Value { }) } -/// A first build of `count` table models, as large projects plan it. -pub(super) fn first_build(count: usize) -> serde_json::Value { +/// A first build of `count` table models, as large projects plan it; `changed` runs each under `--changed` with a warning of its own. +pub(super) fn first_build(count: usize, changed: bool) -> serde_json::Value { let models: Vec = (0..count) .map(|index| { let mut model = @@ -117,13 +165,37 @@ pub(super) fn first_build(count: usize) -> serde_json::Value { model }) .collect(); + let names = (0..count).map(|index| format!("model_{index:05}")); + let runs: Vec = names + .clone() + .map(|name| serde_json::json!({"node": format!("model:{name}"), "reason": "no completed record", "downstream_of": null})) + .take(count * usize::from(changed)) + .collect(); + let warnings: Vec = (0..count * usize::from(changed)) + .map(|index| serde_json::json!({"severity": "warning", "message": format!("unusual setting {} on this model", word(index))})) + .collect(); + let decision = [ + serde_json::Value::Null, + serde_json::json!({"counts": ["definition"], "reach": "all", "runs": runs, "held_back": [], "unchanged": []}), + ][usize::from(changed)] + .clone(); serde_json::json!({ "selected_count": count, "models": models, "seeds": [], "source_loads": [], "functions": [], - "python_nodes": [], "warnings": [], "migrations": [], "column_migrations": [], - "table_type_conversions": [], "retention": [], "synced_copy": null, "changed": null, + "python_nodes": [], "warnings": warnings, "migrations": [], "column_migrations": [], + "table_type_conversions": [], "retention": [], "synced_copy": null, + "changed": decision, }) } +/// A distinct three-letter word for each index below 17,576, so no warning template elides it. +fn word(index: usize) -> String { + (0..3) + .map(|place: u32| { + char::from(b'a' + u8::try_from(index / 26_usize.pow(place) % 26).unwrap_or_default()) + }) + .collect() +} + /// A row's name: a model's or migration's, a node key's name, or a warning's message. pub(super) fn row_label(row: &serde_json::Value) -> String { let key = ["name", "model", "node", "message"] diff --git a/crates/sqlbuild-core/src/plan_display/tests/test_plan_pages.rs b/crates/sqlbuild-core/src/plan_display/tests/test_plan_pages.rs index e73f440486..225e604ef0 100644 --- a/crates/sqlbuild-core/src/plan_display/tests/test_plan_pages.rs +++ b/crates/sqlbuild-core/src/plan_display/tests/test_plan_pages.rs @@ -8,8 +8,8 @@ use crate::plan_display::main::plan_summary::plan_summary; use crate::plan_display::models::{DiffStats, PlanPageSection}; use crate::plan_display::tests::helpers::{first_build, full_plan, labels, owned}; use crate::plan_display::tests::test_types::{ - DetachTestCase, DiffStatsTestCase, ModelPageTestCase, NoteTestCase, PageTestCase, - SectionTestCase, SummaryFieldTestCase, SummarySizeTestCase, + ConfigChangeTestCase, DetachTestCase, DiffStatsTestCase, ModelPageTestCase, NoteTestCase, + PageTestCase, SectionTestCase, SummaryFieldTestCase, SummarySizeTestCase, }; #[test] @@ -106,10 +106,20 @@ fn given_a_plan_when_paging_each_section_then_every_section_pages_its_rows_in_pl expected_rows: &["clean_name"], }, SectionTestCase { - description: "seeds --changed runs", - section: PlanPageSection::Seeds, + description: "first-run seeds --changed runs", + section: PlanPageSection::FirstRunSeeds, expected_rows: &["countries"], }, + SectionTestCase { + description: "changed seeds --changed runs", + section: PlanPageSection::ChangedSeeds, + expected_rows: &["currency_rates"], + }, + SectionTestCase { + description: "unchanged seeds --changed runs", + section: PlanPageSection::UnchangedSeeds, + expected_rows: &["regions"], + }, SectionTestCase { description: "Python nodes", section: PlanPageSection::PythonNodes, @@ -126,11 +136,15 @@ fn given_a_plan_when_paging_each_section_then_every_section_pages_its_rows_in_pl expected_rows: &["not_run", "idle_seed"], }, SectionTestCase { - description: "warnings", + description: "warnings, largest group first and each group in plan order", section: PlanPageSection::Warnings, expected_rows: &[ + "scenario 'checkout' step 'pay' is stale", + "scenario 'checkout' step 'ship' is stale", + "scenario 'returns' step `refund` is stale", + "model stg__orders_2 has no tests.", + "model stg__customers_3 has no tests.", "orders: already-built dates keep their old results", - "scenario 'checkout' is stale", ], }, ]; @@ -200,9 +214,12 @@ fn given_a_name_filter_when_paging_then_matching_rows_page_with_their_count() { section: PlanPageSection::Warnings, window: (0, 50), name: Some("checkout"), - expected_rows: &["scenario 'checkout' is stale"], - expected_total: 1, - expected_section_total: 2, + expected_rows: &[ + "scenario 'checkout' step 'pay' is stale", + "scenario 'checkout' step 'ship' is stale", + ], + expected_total: 2, + expected_section_total: 6, }, PageTestCase { description: "nothing matching is an empty page", @@ -316,12 +333,12 @@ fn given_a_plan_when_summarised_then_sections_are_counts_and_no_row_list_is_left }, SummaryFieldTestCase { description: "warnings last", - pointer: "/sections/22/section", + pointer: "/sections/24/section", expected_value: json!("warnings"), }, SummaryFieldTestCase { description: "no section beyond the plan's", - pointer: "/sections/23", + pointer: "/sections/25", expected_value: Value::Null, }, SummaryFieldTestCase { @@ -364,6 +381,30 @@ fn given_a_plan_when_summarised_then_sections_are_counts_and_no_row_list_is_left pointer: "/changed/unchanged", expected_value: json!([]), }, + SummaryFieldTestCase { + description: "seeds count by reason: first run", + pointer: "/pages/first_run_seeds", + expected_value: json!(1), + }, + SummaryFieldTestCase { + description: "seeds count by reason: changed", + pointer: "/pages/changed_seeds", + expected_value: json!(1), + }, + SummaryFieldTestCase { + description: "seeds count by reason: unchanged", + pointer: "/pages/unchanged_seeds", + expected_value: json!(1), + }, + SummaryFieldTestCase { + description: "warnings grouped by template, largest first, with how many things the group names", + pointer: "/warning_groups", + expected_value: json!([ + {"template": "scenario … step … is stale", "count": 3, "subject": {"noun": "scenario", "count": 2}}, + {"template": "model … has no tests.", "count": 2, "subject": null}, + {"template": "already-built dates keep their old results", "count": 1, "subject": null}, + ]), + }, SummaryFieldTestCase { description: "--changed facts stay", pointer: "/changed/reach", @@ -573,13 +614,22 @@ fn given_a_document_whose_diffs_were_detached_when_paged_then_counts_remain_and_ #[test] fn given_a_large_first_build_when_summarised_then_the_summary_stays_small() { - let test_cases = [SummarySizeTestCase { - description: "10,000 first-run models", - models: 10_000, - expected_max_bytes: 1_024, - }]; + let test_cases = [ + SummarySizeTestCase { + description: "10,000 first-run models", + models: 10_000, + changed_with_warnings: false, + expected_max_bytes: 1_024, + }, + SummarySizeTestCase { + description: "10,000 models under --changed, each with a warning of its own", + models: 10_000, + changed_with_warnings: true, + expected_max_bytes: 16_384, + }, + ]; for test_case in test_cases { - let document = first_build(test_case.models); + let document = first_build(test_case.models, test_case.changed_with_warnings); let summary = serde_json::to_vec(&plan_summary(&document)).unwrap_or_default(); @@ -592,3 +642,66 @@ fn given_a_large_first_build_when_summarised_then_the_summary_stays_small() { ); } } + +#[test] +fn given_config_diffs_when_paged_whole_or_detached_then_short_ones_read_as_one_config_change() { + let test_cases = [ + ConfigChangeTestCase { + description: "one plain key changes", + section: PlanPageSection::ConfigChanged, + model: "totals", + expected_change: Some("full_refresh true → false"), + }, + ConfigChangeTestCase { + description: "a key set from nothing to a list, beside a query change", + section: PlanPageSection::QueryChanged, + model: "payments", + expected_change: Some("tags [] → [\"finance\"]"), + }, + ConfigChangeTestCase { + description: "three keys are too many for one line", + section: PlanPageSection::SchemaChanged, + model: "ledger", + expected_change: None, + }, + ConfigChangeTestCase { + description: "a key nested in an object is not a top-level change", + section: PlanPageSection::FirstRun, + model: "daily_orders", + expected_change: None, + }, + ConfigChangeTestCase { + description: "a comma moved by a new last key is not a change of the key before", + section: PlanPageSection::FirstRun, + model: "daily_payments", + expected_change: Some("tags (unset) → none"), + }, + ConfigChangeTestCase { + description: "no config diff", + section: PlanPageSection::QueryChanged, + model: "orders", + expected_change: None, + }, + ]; + for test_case in test_cases { + let whole = full_plan(); + let (detached, _) = detach_model_diffs(whole.clone()); + + let change = |document: &Value| { + plan_section_page(document, test_case.section, ((0, 50), None)) + .rows + .into_iter() + .find(|row| row["name"] == test_case.model) + .and_then(|row| row.get("config_change").cloned()) + }; + assert_eq!( + (change(&whole), change(&detached)), + ( + test_case.expected_change.map(|change| json!(change)), + test_case.expected_change.map(|change| json!(change)), + ), + "{}: the same with the diff text in the document or kept apart", + test_case.description + ); + } +} diff --git a/crates/sqlbuild-core/src/plan_display/tests/test_types.rs b/crates/sqlbuild-core/src/plan_display/tests/test_types.rs index 8fa2dda1bd..f99fa8d4b7 100644 --- a/crates/sqlbuild-core/src/plan_display/tests/test_types.rs +++ b/crates/sqlbuild-core/src/plan_display/tests/test_types.rs @@ -111,5 +111,14 @@ pub(super) struct DetachTestCase { pub(super) struct SummarySizeTestCase { pub(super) description: &'static str, pub(super) models: usize, + /// Every model runs under `--changed`, and each has its own distinct warning. + pub(super) changed_with_warnings: bool, pub(super) expected_max_bytes: usize, } + +pub(super) struct ConfigChangeTestCase { + pub(super) description: &'static str, + pub(super) section: PlanPageSection, + pub(super) model: &'static str, + pub(super) expected_change: Option<&'static str>, +} 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 8f097f891f..fd5bbbf923 100644 --- a/crates/sqlbuild-orchestration/src/api/_helpers/authentication/password_sessions.rs +++ b/crates/sqlbuild-orchestration/src/api/_helpers/authentication/password_sessions.rs @@ -251,6 +251,10 @@ pub(crate) fn person_routes() -> Router { "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/cost", get(crate::api::_helpers::resources::person_reads::run_cost), ) + .route( + "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/ignored-audits", + get(crate::api::_helpers::resources::person_reads::run_ignored_audits), + ) .route( "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/statements", get(crate::api::_helpers::resources::person_reads::run_statements), diff --git a/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_reads.rs b/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_reads.rs index 5f43f7acb6..123eb3a3ac 100644 --- a/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_reads.rs +++ b/crates/sqlbuild-orchestration/src/api/_helpers/resources/person_reads.rs @@ -33,8 +33,8 @@ use crate::platform::models::{ }; use crate::runs::main::listings::list_person_run_nodes::list_person_run_nodes; use crate::runs::models::{ - NodeRunRecord, RunEventRecord, RunNodeFailure, RunNodeRecord, RunOutput, RunStatementRecord, - RunStatementSql, + NodeRunRecord, RunEventRecord, RunIgnoredAuditFailure, RunNodeFailure, RunNodeRecord, + RunOutput, RunStatementRecord, RunStatementSql, }; use crate::scheduler::main::list_person_ticks::list_person_ticks; use crate::scheduler::models::TickRecord; @@ -49,6 +49,7 @@ use crate::warehouse_history::main::read_person_node_costs::read_person_node_cos use crate::warehouse_history::main::read_person_node_runs::read_person_node_runs; use crate::warehouse_history::main::read_person_run_cost::read_person_run_cost; use crate::warehouse_history::main::read_person_run_events::read_person_run_events; +use crate::warehouse_history::main::read_person_run_ignored_audits::read_person_run_ignored_audits; use crate::warehouse_history::main::read_person_run_node_error::read_person_run_node_error; use crate::warehouse_history::main::read_person_run_output::read_person_run_output; use crate::warehouse_history::main::read_person_run_statement_sql::read_person_run_statement_sql; @@ -256,6 +257,29 @@ pub(crate) async fn run_statements( .ok_or_else(|| not_found("run not found")) } +#[utoipa::path(get, path = "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/ignored-audits", operation_id = "listPersonRunIgnoredAudits", + params(("location_id" = Uuid, Path), ("target" = String, Path), ("run_id" = Uuid, Path)), + responses((status = 200, body = Vec, description = "The error-severity audit failures the run and its current group members let through, run by run"), + (status = 401, description = "Session rejected"), (status = 403, body = crate::api::models::ApiErrorBody), + (status = 404, description = "Run not found for a person who may view the whole target")), + security(("session" = []), ("cliSession" = [])))] +pub(crate) async fn run_ignored_audits( + (State(store), Extension(context)): (State, Extension), + Extension(default_role): Extension, + Path((location_id, target, run_id)): Path<(Uuid, String, Uuid)>, + Extension(AuthenticatedPerson(principal, _)): Extension, +) -> Result>, ApiError> { + read_person_run_ignored_audits( + &store, + (&context, principal), + (location_id, &target, run_id), + default_role, + ) + .await? + .map(Json) + .ok_or_else(|| not_found("run not found")) +} + #[utoipa::path(get, path = "/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/cost", operation_id = "readPersonRunCost", params(("location_id" = Uuid, Path), ("target" = String, Path), ("run_id" = Uuid, Path)), responses((status = 200, body = Vec, description = "The latest estimated query cost observation of the run and of each resource and warehouse it used; empty when none was synced"), diff --git a/crates/sqlbuild-orchestration/src/api/_helpers/resources/run_reads.rs b/crates/sqlbuild-orchestration/src/api/_helpers/resources/run_reads.rs index 48fa2906a1..8374a9748e 100644 --- a/crates/sqlbuild-orchestration/src/api/_helpers/resources/run_reads.rs +++ b/crates/sqlbuild-orchestration/src/api/_helpers/resources/run_reads.rs @@ -11,13 +11,13 @@ use crate::api::models::{ReadQuery, ReadResource, RunRecallPath, RunRecallQuery} use crate::credentials::models::TokenIdentity; use crate::runs::main::listings::list_run_nodes::list_run_nodes; use crate::runs::main::listings::list_runs::list_runs; +use crate::runs::main::listings::run_invocations::run_invocations; use crate::runs::models::{RunNodeRecord, RunRecord}; use crate::store::main::begin::begin; use crate::store::main::commit::commit; use crate::store::main::list_recall_invocations::list_recall_invocations; -use crate::store::main::query::query; use crate::store::main::read_recall_view::read_recall_view; -use crate::store::models::{ControlStore, Parameter, TransactionMode}; +use crate::store::models::{ControlStore, TransactionMode}; use crate::store::types::Row; #[utoipa::path(get, path = "/api/locations/{location_id}/targets/{target}/runs", operation_id = "list_runs", @@ -112,22 +112,10 @@ pub(crate) async fn recall( )) } -/// Immutable claim evidence remains available after terminal publication removes liveness. +/// The run's scheduler and worker invocations, read in their own transaction. async fn run_namespaces(store: &ControlStore, run_id: Uuid) -> Result, ApiError> { - let scheduler = format!("scheduler/{run_id}"); - let transaction = begin(store, TransactionMode::Read).await?; - let (transaction, claims) = query( - transaction, - "SELECT payload FROM recall_events WHERE invocation_id=$1 AND event_type='run_claimed' ORDER BY invocation_sequence DESC LIMIT 1", - vec![Parameter::Text(scheduler.clone())], - ).await?; + let (transaction, namespaces) = + run_invocations(begin(store, TransactionMode::Read).await?, run_id).await?; commit(transaction).await?; - let mut namespaces = vec![scheduler]; - if let Some(claim_id) = claims - .first() - .and_then(|row| row["payload"]["claim"]["claim_id"].as_str()) - { - namespaces.push(format!("worker/{claim_id}")); - } Ok(namespaces) } diff --git a/crates/sqlbuild-orchestration/src/api/models.rs b/crates/sqlbuild-orchestration/src/api/models.rs index 35465a9339..912a2902f7 100644 --- a/crates/sqlbuild-orchestration/src/api/models.rs +++ b/crates/sqlbuild-orchestration/src/api/models.rs @@ -35,6 +35,7 @@ use crate::api::_helpers::resources::{ person_reads::node_runs, person_reads::run_events, person_reads::run_statements, + person_reads::run_ignored_audits, person_reads::run_cost, person_reads::cost_summary, person_reads::node_costs, diff --git a/crates/sqlbuild-orchestration/src/platform/_helpers/plans/plan_access.rs b/crates/sqlbuild-orchestration/src/platform/_helpers/plans/plan_access.rs index d4d486f202..78106c215c 100644 --- a/crates/sqlbuild-orchestration/src/platform/_helpers/plans/plan_access.rs +++ b/crates/sqlbuild-orchestration/src/platform/_helpers/plans/plan_access.rs @@ -56,7 +56,10 @@ fn without_code_diffs(record: &mut LocationWorkRecord) { }; for (section, keys) in [ ("python_nodes", &["identity_diff"][..]), - ("models", &["query_diff", "config_diff", "diff_stats"][..]), + ( + "models", + &["query_diff", "config_diff", "diff_stats", "config_change"][..], + ), ] { let entries = document .get_mut(section) diff --git a/crates/sqlbuild-orchestration/src/platform/main/person_reads/read_person_plan_rows.rs b/crates/sqlbuild-orchestration/src/platform/main/person_reads/read_person_plan_rows.rs index 6023a47da9..ab8e0209b0 100644 --- a/crates/sqlbuild-orchestration/src/platform/main/person_reads/read_person_plan_rows.rs +++ b/crates/sqlbuild-orchestration/src/platform/main/person_reads/read_person_plan_rows.rs @@ -69,7 +69,9 @@ fn page_section(section: PlanRowSection) -> PlanPageSection { PlanRowSection::SourceLoads => PlanPageSection::SourceLoads, PlanRowSection::ChangedFunctions => PlanPageSection::ChangedFunctions, PlanRowSection::Functions => PlanPageSection::Functions, - PlanRowSection::Seeds => PlanPageSection::Seeds, + PlanRowSection::FirstRunSeeds => PlanPageSection::FirstRunSeeds, + PlanRowSection::ChangedSeeds => PlanPageSection::ChangedSeeds, + PlanRowSection::UnchangedSeeds => PlanPageSection::UnchangedSeeds, PlanRowSection::PythonNodes => PlanPageSection::PythonNodes, PlanRowSection::HeldBack => PlanPageSection::HeldBack, PlanRowSection::Unchanged => PlanPageSection::Unchanged, diff --git a/crates/sqlbuild-orchestration/src/platform/models.rs b/crates/sqlbuild-orchestration/src/platform/models.rs index cb94f9d599..30b9addc6f 100644 --- a/crates/sqlbuild-orchestration/src/platform/models.rs +++ b/crates/sqlbuild-orchestration/src/platform/models.rs @@ -673,8 +673,12 @@ pub enum PlanRowSection { ChangedFunctions, /// Functions without a change. Functions, - /// Seeds the run loads or reports on. - Seeds, + /// Seeds the run loads for the first time. + FirstRunSeeds, + /// Seeds whose definition or settings changed. + ChangedSeeds, + /// Seeds the run loads or reports on without a change of their own. + UnchangedSeeds, PythonNodes, /// `--changed` nodes held back for a job's own run. HeldBack, diff --git a/crates/sqlbuild-orchestration/src/runs/main/listings/mod.rs b/crates/sqlbuild-orchestration/src/runs/main/listings/mod.rs index 4417930768..4287bf8bce 100644 --- a/crates/sqlbuild-orchestration/src/runs/main/listings/mod.rs +++ b/crates/sqlbuild-orchestration/src/runs/main/listings/mod.rs @@ -3,3 +3,4 @@ pub mod list_person_runs; pub mod list_run_claims; pub mod list_run_nodes; pub mod list_runs; +pub mod run_invocations; diff --git a/crates/sqlbuild-orchestration/src/runs/main/listings/run_invocations.rs b/crates/sqlbuild-orchestration/src/runs/main/listings/run_invocations.rs new file mode 100644 index 0000000000..f379ad426a --- /dev/null +++ b/crates/sqlbuild-orchestration/src/runs/main/listings/run_invocations.rs @@ -0,0 +1,29 @@ +//! A run's Recall invocations: its scheduler's and, once claimed, its worker's; claim evidence outlives terminal publication. + +use uuid::Uuid; + +use crate::store::errors::ControlError; +use crate::store::main::query::query; +use crate::store::models::{ControlTransaction, Parameter}; + +/// `scheduler/`, then `worker/` when the scheduler recorded a claim. +pub(crate) async fn run_invocations( + transaction: ControlTransaction, + run_id: Uuid, +) -> Result<(ControlTransaction, Vec), ControlError> { + let scheduler = format!("scheduler/{run_id}"); + let (transaction, claims) = query( + transaction, + "SELECT payload FROM recall_events WHERE invocation_id=$1 AND event_type='run_claimed' ORDER BY invocation_sequence DESC LIMIT 1", + vec![Parameter::Text(scheduler.clone())], + ) + .await?; + let mut namespaces = vec![scheduler]; + if let Some(claim_id) = claims + .first() + .and_then(|row| row["payload"]["claim"]["claim_id"].as_str()) + { + namespaces.push(format!("worker/{claim_id}")); + } + Ok((transaction, namespaces)) +} diff --git a/crates/sqlbuild-orchestration/src/runs/models.rs b/crates/sqlbuild-orchestration/src/runs/models.rs index 2729b2cebe..a179c87e98 100644 --- a/crates/sqlbuild-orchestration/src/runs/models.rs +++ b/crates/sqlbuild-orchestration/src/runs/models.rs @@ -420,6 +420,23 @@ pub struct RunEventRecord { pub message: Option, } +/// One error-severity audit failure a run or one of its current members let through; never its SQL or evidence. +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)] +pub struct RunIgnoredAuditFailure { + /// The run that evaluated the audit: the run itself or one of its group members. + pub run_id: Uuid, + pub job_key: Option, + pub occurred_at: String, + /// The check's identity, as the checks endpoints name it. + pub binding_key: Option, + pub audit_name: String, + pub attached_target_kind: Option, + pub attached_target_name: Option, + pub attached_column_name: Option, + pub severity: String, + pub violation_count: Option, +} + /// Warehouse statement metadata of a run: kind, timing, counts and outcome, never the SQL text. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, utoipa::ToSchema)] pub struct RunStatementRecord { diff --git a/crates/sqlbuild-orchestration/src/warehouse_history/_helpers/run_recall.rs b/crates/sqlbuild-orchestration/src/warehouse_history/_helpers/run_recall.rs index 840050a339..bff9055c08 100644 --- a/crates/sqlbuild-orchestration/src/warehouse_history/_helpers/run_recall.rs +++ b/crates/sqlbuild-orchestration/src/warehouse_history/_helpers/run_recall.rs @@ -9,9 +9,11 @@ use crate::authorization::main::authorize_listing::authorize_listing; use crate::authorization::main::authorize_person::authorize_person; use crate::credentials::main::audit::append_audit::append_audit; use crate::credentials::models::{Action, AuditContext, DefaultRole, PermissionScope}; -use crate::runs::constants::{MEMBER_RECOVERED_EVENT, MEMBER_RETRYING_EVENT}; +use crate::runs::constants::{MEMBER_RECOVERED_EVENT, MEMBER_RETRYING_EVENT, SUPERSEDED_CHILD}; +use crate::runs::main::listings::run_invocations::run_invocations; use crate::runs::models::{ - RunErrorText, RunEventRecord, RunOutput, RunOutputLine, RunStatementRecord, RunStatementSql, + RunErrorText, RunEventRecord, RunIgnoredAuditFailure, RunOutput, RunOutputLine, + RunStatementRecord, RunStatementSql, }; use crate::store::errors::ControlError; use crate::store::main::decode_row::decode_row; @@ -71,6 +73,26 @@ pub(crate) async fn begin_run_recall( Ok(Some((transaction, scope, Some((context, permission))))) } +/// A run read under listing view, in the transaction that found the run. +pub(crate) async fn run_read( + store: &ControlStore, + credentials: (&AuditContext, Uuid), + (run, default_role): ((Uuid, &str, Uuid), DefaultRole), + read: impl AsyncFnOnce( + ControlTransaction, + &RunRecallScope, + ) -> Result<(ControlTransaction, T), ControlError>, +) -> Result, ControlError> { + let Some((transaction, scope, _)) = + begin_run_recall(store, credentials, run, (default_role, None)).await? + else { + return Ok(None); + }; + let (transaction, result) = read(transaction, &scope).await?; + commit(transaction).await?; + Ok(Some(result)) +} + /// A sensitive run read, authorized for `action` and audited as `audit_action` in the same transaction. pub(crate) async fn sensitive_run_read( store: &ControlStore, @@ -129,20 +151,7 @@ async fn run_recall_scope( other => serde_json::from_value(other.clone()), } .map_err(|error| ControlError::Invalid(error.to_string()))?; - let scheduler = format!("scheduler/{run_id}"); - let (transaction, claims) = query( - transaction, - "SELECT payload FROM recall_events WHERE invocation_id=$1 AND event_type='run_claimed' ORDER BY invocation_sequence DESC LIMIT 1", - vec![Parameter::Text(scheduler.clone())], - ) - .await?; - let mut namespaces = vec![scheduler]; - if let Some(claim_id) = claims - .first() - .and_then(|row| row["payload"]["claim"]["claim_id"].as_str()) - { - namespaces.push(format!("worker/{claim_id}")); - } + let (transaction, namespaces) = run_invocations(transaction, run_id).await?; Ok(( transaction, Some(RunRecallScope { @@ -152,6 +161,54 @@ async fn run_recall_scope( )) } +/// The audit failures the run and its current group members let through, run by run in occurrence order. +pub(crate) async fn ignored_audits_in( + transaction: ControlTransaction, + run_id: Uuid, +) -> Result<(ControlTransaction, Vec), ControlError> { + let (mut transaction, runs) = query( + transaction, + &format!( + "SELECT r.run_id, r.job_key FROM sqb_runs r \ + WHERE r.run_id=$1 OR (r.parent_run_id=$1 AND NOT {SUPERSEDED_CHILD}) ORDER BY r.run_id" + ), + vec![Parameter::Id(run_id)], + ) + .await?; + let mut failures: Vec = Vec::new(); + for run in runs { + let member = Uuid::parse_str(run["run_id"].as_str().unwrap_or_default()) + .map_err(|error| ControlError::Schema(format!("stored run ID: {error}")))?; + let namespaces; + (transaction, namespaces) = run_invocations(transaction, member).await?; + let scope = RunRecallScope { + namespaces, + selection: BTreeSet::new(), + }; + let (filter, parameters) = invocation_filter(&scope, 1); + let rows; + (transaction, rows) = query( + transaction, + &format!( + "SELECT a.occurred_at, e.payload ->> 'binding_key' AS binding_key, a.audit_name, \ + a.attached_target_kind, a.attached_target_name, a.\"column\" AS attached_column_name, \ + a.severity, a.violation_count \ + FROM (SELECT * FROM audit_results WHERE {filter} AND ignored=1) a \ + JOIN recall_events e ON e.invocation_id=a.invocation_id AND e.event_id=a.event_id \ + ORDER BY a.occurred_at, a.event_id" + ), + parameters, + ) + .await?; + for mut row in rows { + row.insert("run_id".into(), run["run_id"].clone()); + row.insert("job_key".into(), run["job_key"].clone()); + failures.push(decode_row(row)?); + } + } + Ok((transaction, failures)) +} + pub(crate) async fn run_events_in( transaction: ControlTransaction, scope: &RunRecallScope, diff --git a/crates/sqlbuild-orchestration/src/warehouse_history/main/mod.rs b/crates/sqlbuild-orchestration/src/warehouse_history/main/mod.rs index fc5c8f546a..cce5cd6b01 100644 --- a/crates/sqlbuild-orchestration/src/warehouse_history/main/mod.rs +++ b/crates/sqlbuild-orchestration/src/warehouse_history/main/mod.rs @@ -10,6 +10,7 @@ pub mod read_person_node_costs; pub mod read_person_node_runs; pub mod read_person_run_cost; pub mod read_person_run_events; +pub mod read_person_run_ignored_audits; pub mod read_person_run_node_error; pub mod read_person_run_output; pub mod read_person_run_statement_sql; diff --git a/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_events.rs b/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_events.rs index bc759e1e14..38de09cc51 100644 --- a/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_events.rs +++ b/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_events.rs @@ -5,9 +5,8 @@ use uuid::Uuid; use crate::credentials::models::{AuditContext, DefaultRole}; use crate::runs::models::RunEventRecord; use crate::store::errors::ControlError; -use crate::store::main::commit::commit; use crate::store::models::ControlStore; -use crate::warehouse_history::_helpers::run_recall::{begin_run_recall, run_events_in}; +use crate::warehouse_history::_helpers::run_recall::{run_events_in, run_read}; /// Events after the storage cursor, oldest first; `None` when the run is not in this location and target. pub async fn read_person_run_events( @@ -16,12 +15,11 @@ pub async fn read_person_run_events( (run, page): ((Uuid, &str, Uuid), (i64, u32)), default_role: DefaultRole, ) -> Result>, ControlError> { - let Some((transaction, scope, _)) = - begin_run_recall(store, credentials, run, (default_role, None)).await? - else { - return Ok(None); - }; - let (transaction, events) = run_events_in(transaction, &scope, page).await?; - commit(transaction).await?; - Ok(Some(events)) + run_read( + store, + credentials, + (run, default_role), + async |transaction, scope| run_events_in(transaction, scope, page).await, + ) + .await } diff --git a/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_ignored_audits.rs b/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_ignored_audits.rs new file mode 100644 index 0000000000..6aed146eb7 --- /dev/null +++ b/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_ignored_audits.rs @@ -0,0 +1,25 @@ +//! The audit failures a run and its current group members let through, with the same view as its statements. + +use uuid::Uuid; + +use crate::credentials::models::{AuditContext, DefaultRole}; +use crate::runs::models::RunIgnoredAuditFailure; +use crate::store::errors::ControlError; +use crate::store::models::ControlStore; +use crate::warehouse_history::_helpers::run_recall::{ignored_audits_in, run_read}; + +/// `None` when the run is not in this location and target. +pub async fn read_person_run_ignored_audits( + store: &ControlStore, + credentials: (&AuditContext, Uuid), + run: (Uuid, &str, Uuid), + default_role: DefaultRole, +) -> Result>, ControlError> { + run_read( + store, + credentials, + (run, default_role), + async |transaction, _| ignored_audits_in(transaction, run.2).await, + ) + .await +} diff --git a/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_statements.rs b/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_statements.rs index 4c6b5b6179..b611e3d140 100644 --- a/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_statements.rs +++ b/crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_statements.rs @@ -5,9 +5,8 @@ use uuid::Uuid; use crate::credentials::models::{AuditContext, DefaultRole}; use crate::runs::models::RunStatementRecord; use crate::store::errors::ControlError; -use crate::store::main::commit::commit; use crate::store::models::ControlStore; -use crate::warehouse_history::_helpers::run_recall::{begin_run_recall, run_statements_in}; +use crate::warehouse_history::_helpers::run_recall::{run_read, run_statements_in}; /// `None` when the run is not in this location and target. pub async fn read_person_run_statements( @@ -16,12 +15,11 @@ pub async fn read_person_run_statements( (run, limit): ((Uuid, &str, Uuid), u32), default_role: DefaultRole, ) -> Result>, ControlError> { - let Some((transaction, scope, _)) = - begin_run_recall(store, credentials, run, (default_role, None)).await? - else { - return Ok(None); - }; - let (transaction, statements) = run_statements_in(transaction, &scope, limit).await?; - commit(transaction).await?; - Ok(Some(statements)) + run_read( + store, + credentials, + (run, default_role), + async |transaction, scope| run_statements_in(transaction, scope, limit).await, + ) + .await } diff --git a/crates/sqlbuild-orchestration/tests/api/test_person_plans.rs b/crates/sqlbuild-orchestration/tests/api/test_person_plans.rs index 4b45899618..f574602ff9 100644 --- a/crates/sqlbuild-orchestration/tests/api/test_person_plans.rs +++ b/crates/sqlbuild-orchestration/tests/api/test_person_plans.rs @@ -339,7 +339,8 @@ fn given_person_plans_when_requested_claimed_and_read_then_they_stay_location_wo } let document = json!({ "models": [{"name": "orders", "action": "create_table", "reason": "first_run", "query_diff": ["-SELECT 1", "+SELECT 2"], "config_diff": ["-a", "+b"]}, - {"name": "customers", "action": "create_view", "reason": "no_change", "config_diff": ["-a", "+b"]}], + {"name": "customers", "action": "create_view", "reason": "no_change", "config_diff": ["-a", "+b"], + "config_change": "full_refresh true → false"}], "warnings": [{"severity": "warning", "message": "connect failed: db_password=orders-pass"}], "python_nodes": [{"name": "orders_export", "identity_diff": {"source_diff": ["-a", "+b"]}}], "timings": {"total_seconds": 1.5, "steps": [{"name": "Reading warehouse state", "seconds": 1.0}, {"name": "Other", "seconds": 0.5}], "planned_from": "synced_state"}, @@ -453,9 +454,8 @@ fn given_person_plans_when_requested_claimed_and_read_then_they_stay_location_wo summary["pages"].clone(), page.total, page.rows.first().map(|row| row["name"].clone()), - page.rows - .first() - .map(|row| row.get("config_diff").is_none()), + page.rows.first().map(|row| row.get("config_diff").is_none() + && row.get("config_change").is_none()), rows(viewer, 1) .await .expect("rows") @@ -554,18 +554,20 @@ fn given_a_plan_whose_document_left_diffs_out_when_read_then_pages_count_them_an "reason": "query_changed", "query_diff": ["-select id", "+select id"]}) }) .chain([ + json!({"name": "totals", "action": "create_table", "reason": "config_changed", + "config_diff": ["- \"full_refresh\": true,", "+ \"full_refresh\": false,"]}), json!({"name": "customers", "action": "create_view", "reason": "config_changed", "config_diff": ["-a", "+b"]}), ]) .collect(); let (detached_plan, detached) = - detach_model_diffs(json!({"models": models[..450].to_vec(), "warnings": []})); + detach_model_diffs(json!({"models": models[..451].to_vec(), "warnings": []})); let document = json!({ "models": detached_plan["models"] .as_array() .into_iter() .flatten() - .chain([&models[450]]) + .chain([&models[451]]) .collect::>(), "warnings": [], }); @@ -676,6 +678,24 @@ fn given_a_plan_whose_document_left_diffs_out_when_read_then_pages_count_them_an and the stored plan never carries them", test_case.description ); + let config_changes: Vec<(serde_json::Value, Option)> = + page(PlanRowSection::ConfigChanged, None) + .await + .expect("rows") + .expect("planned") + .rows + .iter() + .map(|row| (row["name"].clone(), row.get("config_change").cloned())) + .collect(); + assert_eq!( + config_changes, + [ + (json!("totals"), Some(json!("full_refresh true → false"))), + (json!("customers"), None), + ], + "{}: a short config change reads in words whether its diff was detached or not", + test_case.description + ); execute( store, "UPDATE sqb_location_work SET expires_at='2000-01-01T00:00:00Z'", diff --git a/crates/sqlbuild-orchestration/tests/runs/claims/helpers.rs b/crates/sqlbuild-orchestration/tests/runs/claims/helpers.rs index ca5aed6411..114632b912 100644 --- a/crates/sqlbuild-orchestration/tests/runs/claims/helpers.rs +++ b/crates/sqlbuild-orchestration/tests/runs/claims/helpers.rs @@ -5,11 +5,16 @@ use std::num::NonZeroU32; use crate::runs::main::execution::change_run::change_run; use crate::runs::main::execution::claim_next_run::claim_next_run; +use crate::runs::main::execution::publish_run_recall::publish_run_recall; use crate::runs::models::{ - NodeOutcome, RunAuthority, RunChange, RunChangeRequest, RunClaim, RunOutcome, + NodeOutcome, RecallBatch, RecallRecord, RunAuthority, RunChange, RunChangeRequest, RunClaim, + RunOutcome, }; use crate::scheduler::models::SchedulerLease; use crate::store::models::ControlStore; +use serde_json::json; +use sqlbuild_recall::records::models::RecallValue; +use sqlbuild_recall::schema::models::Table; use uuid::Uuid; pub(crate) async fn slot_counts(store: &ControlStore) -> BTreeMap { @@ -66,6 +71,58 @@ pub(crate) async fn succeed_ignoring_audit_failures( .await; } +/// The claimed worker records one `audit_completed` result per `(audit, ignored)` on the claim's `orders` model. +pub(crate) async fn publish_audit_results( + store: &ControlStore, + claim: &RunClaim, + audits: &[(String, bool)], +) { + let records = audits + .iter() + .enumerate() + .map(|(index, (audit, ignored))| { + let severity = ["warn", "error"][usize::from(*ignored)]; + let payload = json!({"audit_name": audit, "audit_definition_name": "not_null", + "evaluation_mode": "violations", "outcome": severity, "severity": severity, + "run_scope_phase": "model", "attachment_kind": "column", "attached_target_kind": "model", + "attached_target_name": "orders", "attached_column_name": "order_id", + "binding_key": format!("orders.{audit}"), "violation_count": index + 2, + "executed_sql": "select 1", "ignored": ignored}); + RecallRecord { + table: Table::Events, + values: BTreeMap::from([ + ("event_id".into(), RecallValue::Text(format!("audit-{audit}"))), + ("event_type".into(), RecallValue::Text("audit_completed".into())), + ("event_schema_version".into(), RecallValue::Integer(1)), + ("event_kind".into(), RecallValue::Text("lifecycle".into())), + ("severity".into(), RecallValue::Text("info".into())), + ( + "occurred_at".into(), + RecallValue::Text(format!("2026-01-01T00:00:{index:02}Z")), + ), + ("producer".into(), RecallValue::Text("sqb".into())), + ("run_id".into(), RecallValue::Text("sqb-run".into())), + ( + "invocation_sequence".into(), + RecallValue::Integer(i64::try_from(index).expect("small index")), + ), + ("payload".into(), RecallValue::Text(payload.to_string())), + ]), + } + }) + .collect(); + publish_run_recall( + store, + (claim.request.run_id, claim.claim_id), + &RecallBatch { + invocation_id: "execution".into(), + records, + }, + ) + .await + .expect("publish audit results"); +} + /// Every selected node and the run end with the given outcomes. pub(crate) async fn finish( store: &ControlStore, diff --git a/crates/sqlbuild-orchestration/tests/runs/test_groups.rs b/crates/sqlbuild-orchestration/tests/runs/test_groups.rs index 6309917fbc..bc415e466a 100644 --- a/crates/sqlbuild-orchestration/tests/runs/test_groups.rs +++ b/crates/sqlbuild-orchestration/tests/runs/test_groups.rs @@ -3,7 +3,8 @@ use std::collections::BTreeMap; use std::num::NonZeroU32; -use crate::credentials::models::AuditContext; +use crate::authorization::main::bootstrap_user::bootstrap_user; +use crate::credentials::models::{AuditContext, DefaultRole}; use crate::runs::main::{ execution::advance_groups::advance_groups, execution::change_run::change_run, execution::claim_next_run::claim_next_run, execution::run_execution::run_execution, @@ -16,11 +17,14 @@ use crate::scheduler::tests::contracts::helpers::acquire_lease; use crate::snapshots::main::publication::publish_snapshot::publish_snapshot; use crate::store::main::migrate_store::migrate_store; use crate::store::tests::helpers::read_recall_events; +use crate::warehouse_history::main::read_person_run_ignored_audits::read_person_run_ignored_audits; use serde_json::json; use uuid::Uuid; use crate::credentials::tests::location_helpers::create_location; -use crate::runs::tests::claim_helpers::{slot_counts, succeed, succeed_ignoring_audit_failures}; +use crate::runs::tests::claim_helpers::{ + publish_audit_results, slot_counts, succeed, succeed_ignoring_audit_failures, +}; use crate::runs::tests::helpers::snapshot; use crate::runs::tests::test_types::{ GroupMemberSettingsTestCase, RunLifecycleTestCase, TransactionFault, @@ -522,6 +526,7 @@ fn given_group_members_with_different_audit_settings_when_run_then_each_keeps_it .await .expect("start virtual parent"); let mut settings = BTreeMap::new(); + let mut members: BTreeMap = BTreeMap::new(); for _ in test_case.members { let claim = claim_next_run(store, &lease, &limits, Some(scope)) .await @@ -533,12 +538,92 @@ fn given_group_members_with_different_audit_settings_when_run_then_each_keeps_it .into_iter() .find(|(name, _, _)| *name == job) .expect("declared member"); + let mut audits: Vec<(String, bool)> = (0..ignored) + .map(|index| (format!("{job}_error_{index}"), true)) + .collect(); + audits.push((format!("{job}_warn"), false)); + publish_audit_results(store, &claim, &audits).await; + members.insert(job.clone(), claim.request.run_id); settings.insert(job, claim.request.settings.clone()); succeed_ignoring_audit_failures(store, &claim, ignored).await; } advance_groups(store, &lease, (&limits, scope)) .await .expect("finish parent"); + let administrator = bootstrap_user(store, &context, "orders-admin") + .await + .expect("administrator"); + let ignored_audits = async |run_id| { + let mut failures: Vec<_> = read_person_run_ignored_audits( + store, + (&context, administrator), + (location, "development", run_id), + DefaultRole::None, + ) + .await + .expect("ignored audits")? + .into_iter() + .map(|failure| { + assert_eq!( + Some(failure.run_id), + failure.job_key.as_ref().map(|job| members[job]), + "each failure names the member run that let it through" + ); + ( + failure.job_key.expect("member job"), + failure.audit_name, + failure.binding_key, + failure.severity, + failure.violation_count, + failure.attached_target_name, + failure.attached_column_name, + ) + }) + .collect(); + failures.sort(); + Some(failures) + }; + let expected = |member: Option<&str>| { + test_case + .members + .iter() + .filter(|(name, _, _)| member.is_none_or(|member| member == *name)) + .flat_map(|(name, _, ignored)| { + (0..*ignored).map(move |index| { + let audit = format!("{name}_error_{index}"); + ( + (*name).to_owned(), + audit.clone(), + Some(format!("orders.{audit}")), + "error".to_owned(), + Some(i64::from(index) + 2), + Some("orders".to_owned()), + Some("order_id".to_owned()), + ) + }) + }) + .collect::>() + }; + assert_eq!( + ignored_audits(request.run_id).await, + Some(expected(None)), + "{}: the group lists every member's ignored failures and none of their passing or warning checks", + test_case.description + ); + for (job, run_id) in &members { + assert_eq!( + ignored_audits(*run_id).await, + Some(expected(Some(job))), + "{}: a member lists only its own", + test_case.description + ); + } + assert_eq!( + ignored_audits(Uuid::now_v7()).await, + None, + "{}: an unknown run is not found", + test_case.description + ); assert_eq!( settings, diff --git a/fensu.toml b/fensu.toml index 9e9faafec2..098fa4fb6a 100644 --- a/fensu.toml +++ b/fensu.toml @@ -1363,7 +1363,7 @@ paths = ["crates/sqlbuild-orchestration/src/api/_helpers/resources/administrator reason = "Each function is one utoipa-annotated axum route: OpenAPI needs one annotated handler per operation, and each body only checks the caller's scope and calls one store operation. Scope checks and store work live in their shared owners." [[dupes.allowlist]] -paths = ["crates/sqlbuild-orchestration/src/authorization/main/list_role_definitions.rs", "crates/sqlbuild-orchestration/src/authorization/main/read_security_audit.rs", "crates/sqlbuild-orchestration/src/credentials/_helpers/active_session.rs", "crates/sqlbuild-orchestration/src/declarations/_helpers/reads.rs", "crates/sqlbuild-orchestration/src/declarations/main/published_job.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_person_jobs.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_person_trigger_changes.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_person_triggers.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_triggers.rs", "crates/sqlbuild-orchestration/src/platform/main/work/read_location_work.rs", "crates/sqlbuild-orchestration/src/platform/main/health/read_person_location_health.rs", "crates/sqlbuild-orchestration/src/platform/main/health/location_health.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/current_snapshot_record.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_person_runs.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_person_run_nodes.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_run_nodes.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_runs.rs", "crates/sqlbuild-orchestration/src/runs/_helpers/lifecycle/reads.rs", "crates/sqlbuild-orchestration/src/warehouse_history/_helpers/checks.rs", "crates/sqlbuild-orchestration/src/scheduler/main/list_person_ticks.rs", "crates/sqlbuild-orchestration/src/store/main/read_records.rs", "crates/sqlbuild-orchestration/src/platform/main/work/location_work.rs", "crates/sqlbuild-orchestration/src/scheduler/main/list_ticks.rs", "crates/sqlbuild-orchestration/src/sensors/_helpers/attempts.rs", "crates/sqlbuild-orchestration/src/sensors/_helpers/facts.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/read_current_record.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/read_snapshot_documents.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/read_snapshot_nodes.rs", "crates/sqlbuild-orchestration/src/warehouse_metadata/main/person_reads/read_person_catalog.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_check.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_checks.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_maintenance.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_microbatch_coverage.rs", "crates/sqlbuild-orchestration/src/warehouse_metadata/main/person_reads/read_person_statistics.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_node_runs.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_events.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_statements.rs", "crates/sqlbuild-orchestration/src/warehouse_history/_helpers/node_runs.rs"] +paths = ["crates/sqlbuild-orchestration/src/authorization/main/list_role_definitions.rs", "crates/sqlbuild-orchestration/src/authorization/main/read_security_audit.rs", "crates/sqlbuild-orchestration/src/credentials/_helpers/active_session.rs", "crates/sqlbuild-orchestration/src/declarations/_helpers/reads.rs", "crates/sqlbuild-orchestration/src/declarations/main/published_job.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_person_jobs.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_person_trigger_changes.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_person_triggers.rs", "crates/sqlbuild-orchestration/src/declarations/main/list_triggers.rs", "crates/sqlbuild-orchestration/src/platform/main/work/read_location_work.rs", "crates/sqlbuild-orchestration/src/platform/main/health/read_person_location_health.rs", "crates/sqlbuild-orchestration/src/platform/main/health/location_health.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/current_snapshot_record.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_person_runs.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_person_run_nodes.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_run_nodes.rs", "crates/sqlbuild-orchestration/src/runs/main/listings/list_runs.rs", "crates/sqlbuild-orchestration/src/runs/_helpers/lifecycle/reads.rs", "crates/sqlbuild-orchestration/src/warehouse_history/_helpers/checks.rs", "crates/sqlbuild-orchestration/src/scheduler/main/list_person_ticks.rs", "crates/sqlbuild-orchestration/src/store/main/read_records.rs", "crates/sqlbuild-orchestration/src/platform/main/work/location_work.rs", "crates/sqlbuild-orchestration/src/scheduler/main/list_ticks.rs", "crates/sqlbuild-orchestration/src/sensors/_helpers/attempts.rs", "crates/sqlbuild-orchestration/src/sensors/_helpers/facts.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/read_current_record.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/read_snapshot_documents.rs", "crates/sqlbuild-orchestration/src/snapshots/main/reads/read_snapshot_nodes.rs", "crates/sqlbuild-orchestration/src/warehouse_metadata/main/person_reads/read_person_catalog.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_check.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_checks.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_maintenance.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_microbatch_coverage.rs", "crates/sqlbuild-orchestration/src/warehouse_metadata/main/person_reads/read_person_statistics.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_node_runs.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_events.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_ignored_audits.rs", "crates/sqlbuild-orchestration/src/warehouse_history/main/read_person_run_statements.rs", "crates/sqlbuild-orchestration/src/warehouse_history/_helpers/node_runs.rs"] reason = "Each is one control-store read with its own SQL and record type. Transactions, person authorization and decoding go through the shared begin_authorized, row_in_target, query_records, read_records and query_bodies helpers; what remains alike is the call shape." [[dupes.allowlist]] diff --git a/ui/e2e/plan-browser.spec.ts b/ui/e2e/plan-browser.spec.ts index bc676121c5..390f52399b 100644 --- a/ui/e2e/plan-browser.spec.ts +++ b/ui/e2e/plan-browser.spec.ts @@ -74,8 +74,8 @@ test('a changed row shows its kind and line counts, and opens its diff a few lin await expect(rows(page).locator('.detail', { hasText: 'config · full_refresh true → false' })).toHaveCount(4); await expect(rows(page).locator('.detail', { hasText: 'config + query · cursor observed_at → event_date' })).toHaveCount(1); if (shots) await page.screenshot({ path: `${shots}/plan-b-changed.png` }); - // Rows carry counts, not diff text: only the small config changes shown inline have been read. - expect(await diffReads(page)).toHaveLength(5); + // Rows carry counts and the server's short config change, not diff text: nothing has been read. + expect(await diffReads(page)).toHaveLength(0); const big = rows(page).filter({ hasText: 'query +71 −50' }).first(); const bigName = await big.locator('.name').innerText(); @@ -141,8 +141,8 @@ test('warnings with one message about different names read as one row, opened to await select(page, 'warnings'); const groups = pane(page).locator('.warning-group'); await expect(groups).toHaveCount(2); - // Warnings group by message once read, so the pane reads them all (up to a cap) in large pages. - expect((await calls(page)).filter((c) => c.section === 'warnings')).toEqual([{ section: 'warnings', offset: 0, limit: 200 }]); + // The server groups them: the pane lists its groups, counted, and reads a group's warnings when it opens. + expect((await calls(page)).filter((c) => c.section === 'warnings')).toEqual([]); await expect(groups.first().locator('.template')).toHaveText('Scenario … provides fixture for unknown model …'); await expect(groups.first()).toContainText('71 in 24 scenarios'); await groups.first().getByRole('button', { name: 'show', exact: true }).click(); @@ -151,6 +151,67 @@ test('warnings with one message about different names read as one row, opened to await groups.first().getByRole('button', { name: 'show all 71' }).click(); await expect(groups.first().locator('li')).toHaveCount(71); await expect(groups.first().getByRole('button', { name: 'show all 71' })).toHaveCount(0); + await groups.nth(1).getByRole('button', { name: 'show', exact: true }).click(); + await expect(groups.nth(1).locator('li')).toHaveCount(3); + await expect(groups.nth(1).locator('li').first()).toContainText('requires source'); + expect((await calls(page)).filter((c) => c.section === 'warnings')).toEqual([ + { section: 'warnings', offset: 0, limit: 20 }, + { section: 'warnings', offset: 20, limit: 51 }, + { section: 'warnings', offset: 71, limit: 3 } + ]); +}); + +test('an open warning group keeps its warnings while other sections load, and reads them once', async ({ page }) => { + await openPlan(page); + await select(page, 'warnings'); + const groups = pane(page).locator('.warning-group'); + await groups.first().getByRole('button', { name: 'show', exact: true }).click(); + await expect(groups.first().locator('li')).toHaveCount(20); + // Another section's page joins the plan; the open group keeps what it read. + await select(page, 'changed'); + await expect.poll(async () => (await calls(page)).some((c) => c.section !== 'warnings')).toBe(true); + await select(page, 'warnings'); + await expect(groups.first().locator('li')).toHaveCount(20); + // Shown, hidden and shown again before the first read returns: one read, each warning once. + await groups.nth(1).getByRole('button', { name: 'show', exact: true }).evaluate((b: HTMLElement) => [b.click(), b.click(), b.click()]); + await expect(groups.nth(1).locator('li')).toHaveCount(3); + await page.waitForTimeout(300); + await expect(groups.nth(1).locator('li')).toHaveCount(3); + expect((await calls(page)).filter((c) => c.section === 'warnings')).toEqual([ + { section: 'warnings', offset: 0, limit: 20 }, + { section: 'warnings', offset: 71, limit: 3 } + ]); + // Another plan's groups start closed and unread. + await page.getByRole('button', { name: 'Plan again' }).click(); + await expect(groups.first().getByRole('button', { name: 'show', exact: true })).toBeVisible({ timeout: 30_000 }); + await expect(groups.locator('li')).toHaveCount(0); +}); + +test('the Checks tab under --changed leaves out the checks of nodes it skips', async ({ page }) => { + const checksTab = async (cmd: string) => { + await page.goto(`/plan?mock&cmd=${encodeURIComponent(cmd)}`); + await expect(page.getByRole('button', { name: 'Plan again' })).toBeVisible({ timeout: 30_000 }); + const tab = page.getByRole('tablist', { name: 'View' }).getByRole('tab', { name: /Checks/ }); + await tab.click(); + return tab; + }; + await expect(await checksTab('sqb build')).toHaveText(/Checks\s*13/); + await expect(page.locator('.graph-note')).toHaveText('13 checks'); + // Seven of them check nodes --changed runs; the rest check nodes held back or unchanged. + await expect(await checksTab('sqb build --changed')).toHaveText(/Checks\s*7/); + await expect(page.locator('.graph-note')).toHaveText('7 checks'); +}); + +test('seeds sit with the models of the same reason: first runs, changes and unchanged', async ({ page }) => { + await openPlan(page, `/plan?mock&large&cmd=${encodeURIComponent('sqb build')}`); + await select(page, 'first_run'); + await expect(pane(page).locator('.subtitle')).toHaveText('672 first run · 2 seeds'); + await select(page, 'changed'); + await expect(pane(page).locator('.subtitle')).toHaveText('87 query · 6 config · 1 function · 1 seed'); + await select(page, 'unchanged'); + await expect(pane(page).locator('.subtitle')).toHaveText('1,507 models · 12 functions · 7 seeds'); + await expect(rows(page)).toHaveCount(50); + if (shots) await page.screenshot({ path: `${shots}/plan-b-seeds.png` }); }); test('a small plan reads as a short index', async ({ page }) => { diff --git a/ui/src/lib/api/client.ts b/ui/src/lib/api/client.ts index ee46b7ee51..eda383756c 100644 --- a/ui/src/lib/api/client.ts +++ b/ui/src/lib/api/client.ts @@ -31,6 +31,7 @@ import type { RunRowPage, RunRowQuery, RunStatement, + IgnoredAuditFailure, RunCostRow, CostSummary, NodeBuildCost, @@ -110,6 +111,8 @@ export interface ApiClient extends PlatformApi { /** Recall events and scheduler facts in storage order, paged by `after`. */ listRunEvents(scope: Scope, runId: string, query?: { after?: number; limit?: number }): Promise; listRunStatements(scope: Scope, runId: string): Promise; + /** The audit failures a run and its group's current member runs let through, run by run. */ + listRunIgnoredAudits(scope: Scope, runId: string): Promise; /** The latest estimated query cost observations of one run; empty until a collection synced. */ listRunCost(scope: Scope, runId: string): Promise; /** Estimated query cost of the runs that started in the last `days` days, by job, warehouse size and node. */ diff --git a/ui/src/lib/api/http-client.ts b/ui/src/lib/api/http-client.ts index 423eccd7ee..a12b202709 100644 --- a/ui/src/lib/api/http-client.ts +++ b/ui/src/lib/api/http-client.ts @@ -16,13 +16,13 @@ import { toPlatformEventRecords, toPlatformEvents, toPlatformHealth } from './ht import { roleDetailOf, toRoleDefinition } from './http-roles'; import { jobDetailOf, runWindowOf, toJob, toTick, toTrigger, toTriggerStateEvent, triggerDetailOf } from './http-jobs'; import { timelineOf } from './http-timeline'; -import { RUN_WINDOW, groupRunNodes, parseRunCursor, planResultOf, queueEntriesOf, toAdhocCheck, runDetailOf, runRowPageOver, runsMatching, runTabCountsOf, toRunNode, toRuns, toRunEvent, toRunOutput, toRunStatements, toRunCostRows, toCostSummary, toNodeBuildCosts } from './http-runs'; +import { RUN_WINDOW, groupRunNodes, parseRunCursor, planResultOf, queueEntriesOf, toAdhocCheck, runDetailOf, runRowPageOver, runsMatching, runTabCountsOf, toRunNode, toRuns, toRunEvent, toRunOutput, toRunStatements, toIgnoredAuditFailures, toRunCostRows, toCostSummary, toNodeBuildCosts } from './http-runs'; 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 { 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, RunCostRow, CostSummary, NodeBuildCost, StatementSql } from './types/operate'; +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']; @@ -42,6 +42,7 @@ const SUPPORTED: ReadonlySet = new Set([ 'timeline', 'listRunEvents', 'listRunStatements', + 'listRunIgnoredAudits', 'listRunCost', 'getCostSummary', 'listNodeCosts', @@ -420,6 +421,12 @@ export function createHttpClient({ baseUrl = '', onUnauthorized, fetch: answer, if (!data) throw new ApiError(errorText(error, response), response.status); return toRunStatements(data, runId); }, + async listRunIgnoredAudits(scope: Scope, runId: string): Promise { + const { data, error, response } = await http.GET('/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/ignored-audits', { params: { path: runPath(scope, runId) } }); + if (response.status === 401) onUnauthorized(); + if (!data) throw new ApiError(errorText(error, response), response.status); + return toIgnoredAuditFailures(data); + }, async listRunCost(scope: Scope, runId: string): Promise { const { data, error, response } = await http.GET('/api/control/locations/{location_id}/targets/{target}/runs/{run_id}/cost', { params: { path: runPath(scope, runId) } }); if (response.status === 401) onUnauthorized(); diff --git a/ui/src/lib/api/http-runs.ts b/ui/src/lib/api/http-runs.ts index ae9ea7f95e..a8eb203cea 100644 --- a/ui/src/lib/api/http-runs.ts +++ b/ui/src/lib/api/http-runs.ts @@ -1,7 +1,7 @@ import type { components } from '$control/schema.d.ts'; import { isActiveRun } from '$lib/status'; import type { Capability, Principal } from './types'; -import type { AdhocRunCheck, LaunchVerb, NodeCounts, PlanChanged, PlanDocument, PlanPage, PlanPageSection, PlanResult, PlanWarning, QueueEntry, QueueWait, Run, RunDetail, RunListQuery, RunNode, RunNodeStatus, RunRow, RunRowPage, RunRowQuery, RunTabCounts, RunEvent, RunEventLevel, RunOutputLine, RunStatement, RunCostRow, CostGroup, CostSummary, NodeBuildCost } from './types/operate'; +import type { AdhocRunCheck, LaunchVerb, NodeCounts, PlanChanged, PlanDocument, PlanPage, PlanPageSection, PlanResult, PlanWarning, QueueEntry, QueueWait, Run, RunDetail, RunListQuery, RunNode, RunNodeStatus, RunRow, RunRowPage, RunRowQuery, RunTabCounts, RunEvent, RunEventLevel, RunOutputLine, RunStatement, IgnoredAuditFailure, RunCostRow, CostGroup, CostSummary, NodeBuildCost } from './types/operate'; import { RECALL_EVENT_TYPES, SCHEDULER_FACTS } from './types/operate'; type Wire = components['schemas']; @@ -39,7 +39,8 @@ export function planResultOf(outcome: Wire['LocationWorkOutcome']): PlanResult { changed: document.changed ?? null, ...(document.ignore_audit_failures ? { ignore_audit_failures: true } : {}), ...(document.pages ? { pages: document.pages } : {}), - ...(document.sections ? { sections: document.sections } : {}) + ...(document.sections ? { sections: document.sections } : {}), + ...(document.warning_groups ? { warning_groups: document.warning_groups } : {}) }, error: null }; @@ -65,7 +66,9 @@ const SECTION_LIST: Record ({ + runId: f.run_id, + jobKey: f.job_key ?? null, + at: f.occurred_at, + checkId: f.binding_key ?? null, + audit: f.audit_name, + node: f.attached_target_name ?? null, + column: f.attached_column_name ?? null, + severity: f.severity, + violationCount: f.violation_count ?? null + })); +} + /** Statement metadata in start order; error text is never sent, only its type and code. */ export function toRunStatements(wire: Wire['RunStatementRecord'][], runId: string): RunStatement[] { return wire.map((s, i) => ({ diff --git a/ui/src/lib/api/mock/build.ts b/ui/src/lib/api/mock/build.ts index b5b5958afe..d34e2c7725 100644 --- a/ui/src/lib/api/mock/build.ts +++ b/ui/src/lib/api/mock/build.ts @@ -21,6 +21,7 @@ import type { CheckOutcome, ColumnLineage, CostChange, + IgnoredAuditFailure, MicrobatchCoverage, NodeBuild, NodeOutcome, @@ -167,6 +168,28 @@ export class MockBuild { // ---- checks ---- + /** The error-severity audits whose latest failure the run, or one of its members, let through. */ + listRunIgnoredAudits(scope: Scope, runId: string): Promise { + const runs = this.#ctx.operate.runAndMembers(runId); + if (!runs.length) throw new ApiError(`Unknown run ${runId}`, 404); + const checks = new Map(this.#checks(scope, this.#states(scope)).map((c) => [c.id, c])); + return this.#ctx.reply( + runs.flatMap((run) => + CHECK_SPECS.filter((spec) => spec.ignoredIn === run.id).map((spec) => ({ + runId: run.id, + jobKey: run.jobKey, + at: checks.get(spec.id)?.latest?.evaluatedAt ?? '', + checkId: spec.id, + audit: spec.name, + node: spec.node, + column: spec.column, + severity: spec.severity, + violationCount: spec.latest.violations ?? null + })) + ) + ); + } + listChecks(scope: Scope): Promise { return this.#ctx.reply(this.#checks(scope, this.#states(scope))); } diff --git a/ui/src/lib/api/mock/large-plan.ts b/ui/src/lib/api/mock/large-plan.ts index c56677d97b..e4846346c5 100644 --- a/ui/src/lib/api/mock/large-plan.ts +++ b/ui/src/lib/api/mock/large-plan.ts @@ -3,6 +3,8 @@ // first runs, renames, loads, Python nodes, repeated warnings and 1,507 routine models. Served as the // server does: a summary, with routine models, held-back and skipped nodes a page at a time. Pure. +import { groupWarnings } from '$lib/run/plan-index'; +import { seedSection } from '$lib/run/plan-text'; import type { PlanDiff, PlanDiffStats, PlanDocument, PlanModel, PlanPage, PlanPageSection, PlanSectionCount, PlanSectionNote, PlanWarning } from '../types'; const DOMAINS = ['orders', 'customers', 'inventory', 'payments', 'shipping', 'returns', 'pricing', 'suppliers', 'regions', 'finance', 'marketing', 'support']; @@ -43,8 +45,8 @@ export function largePlanDocument(changed: boolean): PlanDocument { for (let k = 0; k < 80; k++) models.push(model(i++, 'query_changed', { action: 'create_table', backfill: { action: k % 3 ? 'forward' : 'full', duration: null }, query_diff: queryDiff(i, 1 + ((k * 7) % 90), (k * 5) % 60) })); for (let k = 0; k < 5; k++) models.push(model(i++, 'query_changed', { query_diff: [...HEAD, '@@ -1,2 +1,3 @@', '-select id, amount', '-from orders', '+select id,', '+ amount', '+from orders'] })); for (let k = 0; k < 2; k++) models.push(model(i++, 'query_changed', { query_diff: [...HEAD, '@@ -1,2 +1,2 @@', '-select id from orders', '+SELECT id FROM orders'] })); - for (let k = 0; k < 4; k++) models.push(model(i++, 'config_changed', { config_diff: [...HEAD, '@@ -1,3 +1,3 @@', ' "materialized": "table",', '- "full_refresh": true,', '+ "full_refresh": false,'] })); - models.push(model(i++, 'config_changed', { ...incremental(), config_diff: ['- "cursor": "observed_at",', '+ "cursor": "event_date",'], query_diff: queryDiff(i, 3, 2) })); + for (let k = 0; k < 4; k++) models.push(model(i++, 'config_changed', { config_diff: [...HEAD, '@@ -1,3 +1,3 @@', ' "materialized": "table",', '- "full_refresh": true,', '+ "full_refresh": false,'], config_change: 'full_refresh true → false' })); + models.push(model(i++, 'config_changed', { ...incremental(), config_diff: ['- "cursor": "observed_at",', '+ "cursor": "event_date",'], config_change: 'cursor observed_at → event_date', query_diff: queryDiff(i, 3, 2) })); models.push(model(i++, 'config_changed', { config_diff: ['- "grain": "hour",', '+ "grain": "day",', '- "lookback": 2,', '+ "lookback": 3,', '- "partition_by": "event_date",', '+ "partition_by": "event_hour",'] })); models.push(model(i++, 'function_changed', { changed_functions: ['parse_orders_html'] })); // 672 first runs; a third are incremental, their range the run's own bounds. @@ -56,7 +58,7 @@ export function largePlanDocument(changed: boolean): PlanDocument { return { selected_count: 2400, models, - seeds: Array.from({ length: 10 }, (_, k) => ({ name: `reference_codes_${k}`, reason: 'no_change' })), + seeds: Array.from({ length: 10 }, (_, k) => ({ name: `reference_codes_${k}`, reason: k < 2 ? 'first_run' : k < 3 ? 'config_changed' : 'no_change' })), source_loads: Array.from({ length: 64 }, (_, k) => ({ name: `${DOMAINS[k % DOMAINS.length]}_feed_${k}`, kind: 'source', write_strategy: 'append', cursor_column: 'loaded_at', is_reload: false })), functions: Array.from({ length: 12 }, (_, k) => ({ name: `format_${DOMAINS[k % DOMAINS.length]}_code`, language: 'sql', reason: 'no_change' })), python_nodes: Array.from({ length: 433 }, (_, k) => ({ name: `${DOMAINS[k % DOMAINS.length]}_export_${k}`, kind: 'asset', phase: 'after_models', identity_status: 'known' })), @@ -84,7 +86,7 @@ export function largePlanDocument(changed: boolean): PlanDocument { const MODEL_SECTIONS: PlanPageSection[] = ['full_refresh', 'query_changed', 'function_changed', 'config_changed', 'schema_changed', 'first_run', 'renamed']; /** Every section in plan order, as the server counts them. */ -const SECTIONS: PlanPageSection[] = [...MODEL_SECTIONS, 'routine_models', 'migrations', 'column_migrations', 'table_type_conversions', 'retention', 'loader_reloads', 'loader_loads', 'source_reloads', 'source_loads', 'changed_functions', 'functions', 'seeds', 'python_nodes', 'held_back', 'unchanged', 'warnings']; +const SECTIONS: PlanPageSection[] = [...MODEL_SECTIONS, 'routine_models', 'migrations', 'column_migrations', 'table_type_conversions', 'retention', 'loader_reloads', 'loader_loads', 'source_reloads', 'source_loads', 'changed_functions', 'functions', 'first_run_seeds', 'changed_seeds', 'unchanged_seeds', 'python_nodes', 'held_back', 'unchanged', 'warnings']; const ROW_LISTS = ['models', 'seeds', 'source_loads', 'functions', 'python_nodes', 'warnings', 'migrations', 'column_migrations', 'table_type_conversions', 'retention'] as const; const keyName = (key: string) => key.slice(key.indexOf(':') + 1); @@ -121,8 +123,10 @@ function sectionRows(doc: PlanDocument, section: PlanPageSection): { rows: unkno return named(doc.functions.filter(changedFunction)); case 'functions': return named(doc.functions.filter((f) => !changedFunction(f))); - case 'seeds': - return named(doc.seeds.filter((s) => runsNode(`seed:${s.name}`))); + case 'first_run_seeds': + case 'changed_seeds': + case 'unchanged_seeds': + return named(doc.seeds.filter((s) => runsNode(`seed:${s.name}`) && seedSection(s.reason) === section)); case 'python_nodes': return named(doc.python_nodes); case 'held_back': @@ -130,7 +134,7 @@ function sectionRows(doc: PlanDocument, section: PlanPageSection): { rows: unkno case 'unchanged': return { rows: doc.changed?.unchanged ?? [], name: (row) => keyName(row as string) }; default: - return { rows: doc.warnings, name: (row) => `${(row as PlanWarning).model_name ?? ''} ${(row as PlanWarning).message}` }; + return { rows: groupWarnings(doc.warnings).flatMap((g) => g.warnings), name: (row) => `${(row as PlanWarning).model_name ?? ''} ${(row as PlanWarning).message}` }; } } @@ -149,6 +153,12 @@ function runNotes(doc: PlanDocument, rows: unknown[]): PlanSectionNote[] { return [...counts.values()].sort((a, b) => b.count - a.count); } +/** The things a group's label counts, "71 in 24 scenarios", as the server's `subject`. */ +function subjectOf(label: string): { noun: string; count: number } | null { + const found = / in (\d+) (\w+?)s?$/.exec(label); + return found ? { noun: found[2], count: Number(found[1]) } : null; +} + /** The server's summary of `doc`: its facts, every row list empty, and each section counted. */ export function planSummary(doc: PlanDocument): PlanDocument { const sections: PlanSectionCount[] = SECTIONS.flatMap((section) => { @@ -162,6 +172,7 @@ export function planSummary(doc: PlanDocument): PlanDocument { ...empty, sections, pages: Object.fromEntries(sections.map((s) => [s.section, s.total])), + warning_groups: groupWarnings(doc.warnings).map((g) => ({ template: g.template, count: g.count, subject: subjectOf(g.label) })), changed: doc.changed && { ...doc.changed, runs: [], held_back: [], unchanged: [] }, synced_copy: doc.synced_copy && { ...doc.synced_copy, cursor_window_starts: {} } }; diff --git a/ui/src/lib/api/mock/mock-client.ts b/ui/src/lib/api/mock/mock-client.ts index db861e33ab..2a95b83540 100644 --- a/ui/src/lib/api/mock/mock-client.ts +++ b/ui/src/lib/api/mock/mock-client.ts @@ -32,6 +32,7 @@ import type { RunOutputLine, RunStatement, RunCostRow, + IgnoredAuditFailure, CostSummary, NodeBuildCost, NodeState, @@ -266,6 +267,11 @@ export class MockApiClient implements ApiClient { return this.#operate.listRunStatements(scope, runId); } + async listRunIgnoredAudits(scope: Scope, runId: string): Promise { + this.#location(scope); + return this.#build.listRunIgnoredAudits(scope, runId); + } + async listRunCost(scope: Scope, runId: string): Promise { this.#location(scope); return this.#operate.listRunCost(scope, runId); diff --git a/ui/src/lib/api/mock/operate-store.ts b/ui/src/lib/api/mock/operate-store.ts index 72914d6ec8..542cfb6100 100644 --- a/ui/src/lib/api/mock/operate-store.ts +++ b/ui/src/lib/api/mock/operate-store.ts @@ -289,6 +289,12 @@ export class MockOperate { return this.#ctx.reply(rec ? this.#view(rec, scope) : null); } + /** The run and its group's member runs, for the build mock's ignored audit failures. */ + runAndMembers(runId: string): { id: string; jobKey: string | null }[] { + const rec = this.#byId(runId); + return rec ? [rec, ...this.#children(rec)].map((r) => ({ id: r.run.id, jobKey: r.run.jobKey })) : []; + } + getRunDetail(scope: Scope, runId: string): Promise { const rec = this.#byId(runId); if (!rec) return this.#ctx.reply(null); diff --git a/ui/src/lib/api/types/operate.ts b/ui/src/lib/api/types/operate.ts index 206d09e924..e6ae455140 100644 --- a/ui/src/lib/api/types/operate.ts +++ b/ui/src/lib/api/types/operate.ts @@ -387,6 +387,21 @@ export type RunStatement = { error: string | null; }; +/** One error-severity audit failure a run, or one of its group's member runs, let through (`ignore_audit_failures`). */ +export type IgnoredAuditFailure = { + /** The run that evaluated the audit: the run itself or one of its members. */ + runId: string; + jobKey: string | null; + at: Iso; + /** The check's ID on the Checks page; null when the result named none. */ + checkId: string | null; + audit: string; + node: string | null; + column: string | null; + severity: string; + violationCount: number | null; +}; + /** One statement's SQL, loaded on demand. Null when it was not recorded. */ export type StatementSql = { statementId: string; sql: string | null }; @@ -647,6 +662,8 @@ export type PlanModel = { query_diff?: string[]; /** Unified diff lines of the model's config since its last build. */ config_diff?: string[]; + /** A config change of at most two plain keys in words, such as `full_refresh true → false`. */ + config_change?: string; schema_findings?: { kind: string; column: string; expected_type: string | null; actual_type: string | null }[]; /** A paged row's diff counts in place of its diff text, which `planDiff` reads on demand. */ diff_stats?: { query?: PlanDiffStats; config?: PlanDiffStats }; @@ -660,6 +677,9 @@ export type PlanDiff = { model: string; query_diff?: string[]; config_diff?: str export type PlanWarning = { severity: string; message: string; model_name?: string; code?: string }; +/** One warning template and how many warnings fill it in; `subject` counts the named things it opens with, such as scenarios, when they repeat. */ +export type PlanWarningGroup = { template: string; count: number; subject: { noun: string; count: number } | null }; + /** `sqb plan --json` as the location printed it; sections the page doesn't show are kept as they are. */ export type PlanDocument = { selected_count: number; @@ -683,6 +703,8 @@ export type PlanDocument = { ignore_audit_failures?: boolean; /** A server summary's sections, by size; their rows load a page at a time. */ pages?: Partial>; + /** A server summary's warnings by message template, largest first; the warnings section pages them in this order. */ + warning_groups?: PlanWarningGroup[]; /** A server summary's nonempty sections in plan order, each with the notes its rows share most. */ sections?: PlanSectionCount[]; /** Rows of each paged section loaded so far, which is the offset of its next page. */ @@ -709,7 +731,9 @@ export type PlanPageSection = | 'source_loads' | 'changed_functions' | 'functions' - | 'seeds' + | 'first_run_seeds' + | 'changed_seeds' + | 'unchanged_seeds' | 'python_nodes' | 'held_back' | 'unchanged' diff --git a/ui/src/lib/run/ignored-audits.test.ts b/ui/src/lib/run/ignored-audits.test.ts deleted file mode 100644 index 597e7a4755..0000000000 --- a/ui/src/lib/run/ignored-audits.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import type { Check, CheckEvaluation } from '$lib/api'; -import { ignoredFailuresOf } from './ignored-audits'; - -const check = (id: string, latest: Partial | null): Check => - ({ id, name: id, latest: latest && { id: `ar-${id}`, runId: null, fingerprintRunId: 'other', evaluatedAt: '2026-11-17T00:00:00Z', outcome: 'fail', violationCount: 1, measuredValue: null, evidenceCount: 1, evidenceTruncated: false, ignored: false, ...latest } }) as Check; - -describe('a run’s ignored audit failures', () => { - it('are the checks whose newest result is a failure this run, or a member run, let through', () => { - const checks = [ - check('by-run-id', { ignored: true, fingerprintRunId: 'run-1' }), - check('by-scheduler-run', { ignored: true, runId: 'run-2' }), - check('not-ignored', { fingerprintRunId: 'run-1' }), - check('another-run', { ignored: true, fingerprintRunId: 'run-9' }), - check('never-ran', null) - ]; - expect(ignoredFailuresOf(checks, new Set(['run-1', 'run-2'])).map((c) => c.id)).toEqual(['by-run-id', 'by-scheduler-run']); - }); -}); diff --git a/ui/src/lib/run/ignored-audits.ts b/ui/src/lib/run/ignored-audits.ts deleted file mode 100644 index a8a815f58c..0000000000 --- a/ui/src/lib/run/ignored-audits.ts +++ /dev/null @@ -1,11 +0,0 @@ -// The audit failures a run let through (`ignore_audit_failures`), for its run page. Pure. - -import type { Check } from '$lib/api'; - -/** - * The checks whose newest result is a failure one of `runIds` let through. The server lists only each - * check's newest result, so a failure a later run has since replaced isn't among them. - */ -export function ignoredFailuresOf(checks: Check[], runIds: ReadonlySet): Check[] { - return checks.filter((c) => !!c.latest?.ignored && (runIds.has(c.latest.runId ?? '') || runIds.has(c.latest.fingerprintRunId))); -} diff --git a/ui/src/lib/run/plan-browser.svelte b/ui/src/lib/run/plan-browser.svelte index 31d386d188..5f7b0a4583 100644 --- a/ui/src/lib/run/plan-browser.svelte +++ b/ui/src/lib/run/plan-browser.svelte @@ -6,9 +6,9 @@ import SearchIcon from '@lucide/svelte/icons/search'; import XIcon from '@lucide/svelte/icons/x'; import { to } from '$lib/paths'; - import { mergePlanPage, type PlanDiff, type PlanDocument, type PlanPage, type PlanPageSection } from '$lib/api'; + import { mergePlanPage, type PlanDiff, type PlanDocument, type PlanPage, type PlanPageSection, type PlanWarning } from '$lib/api'; import { warningText } from './plan-text'; - import { AFTER_DIVIDER, WARNINGS_SHOWN, diffPreview, planGroups, planSummaryLine, selectedGroup, withoutRows, type PlanGroupKey, type PlanRow } from './plan-index'; + import { AFTER_DIVIDER, WARNINGS_SHOWN, diffPreview, planGroups, planSummaryLine, selectedGroup, withoutRows, type PlanGroupKey, type PlanRow, type WarningGroup } from './plan-index'; /** * `section` is the group shown, kept in the address by the page; `more` adds the next page of a @@ -38,8 +38,7 @@ const PAGE = 50; /** How long the filter waits for typing to stop before asking the server. */ const FILTER_WAIT_MS = 250; - /** Warnings group by message only once read, so the Warnings pane reads them in larger pages, up to a cap. */ - const WARNING_PAGE = 200; + /** The most warnings one read brings, as the server pages them. */ const WARNINGS_READ = 1000; /** Diffs read on demand, by model; null when the server has none to give. */ @@ -57,14 +56,58 @@ const groups = $derived(planGroups(plan, refresh, diffs)); const group = $derived(selectedGroup(groups, section)); const warningGroups = $derived(group?.warningGroups ?? []); + /** A server summary's groups come counted; each one's warnings are read when it opens, by where they start. */ + let readWarnings = $state>({}); + /** Which warning groups are open, and which show all their warnings, by where their warnings start. */ + let openWarnings = $state>({}); + let allWarnings = $state>({}); + /** The groups being read, by where their warnings start, one read each, and the summary groups they were read for. */ + const readingWarnings = new Set(); + let readFor: unknown = null; + // Another plan's groups start closed and unread; a page of this plan's rows keeps the same groups. + $effect.pre(() => { + if (plan.warning_groups === readFor) return; + readFor = plan.warning_groups; + readWarnings = {}; + readingWarnings.clear(); + openWarnings = {}; + allWarnings = {}; + }); + function readGroup(w: WarningGroup, limit: number) { + const want = Math.min(limit, w.count); + const have = readWarnings[w.offset]?.length ?? 0; + if (w.warnings.length || !load || have >= want || readingWarnings.has(w.offset)) return; + const read = readWarnings; + readingWarnings.add(w.offset); + load('warnings', w.offset + have, want - have, '') + .then((page) => { + // A read another plan replaced lands nowhere. + if (read !== readWarnings) return; + readingWarnings.delete(w.offset); + readWarnings[w.offset] = [...(readWarnings[w.offset] ?? []), ...(page.rows as PlanWarning[])]; + // "show all" asked while the first rows were read. + if (page.rows.length) readGroup(w, allWarnings[w.offset] ? WARNINGS_READ : limit); + }) + .catch((e: unknown) => { + if (read === readWarnings) readingWarnings.delete(w.offset); + loadError = e instanceof Error ? e.message : String(e); + }); + } + function toggleWarnings(w: WarningGroup) { + openWarnings[w.offset] = !openWarnings[w.offset]; + if (openWarnings[w.offset]) readGroup(w, WARNINGS_SHOWN); + } + function showAllWarnings(w: WarningGroup) { + allWarnings[w.offset] = true; + readGroup(w, WARNINGS_READ); + } + const warningsOf = (w: WarningGroup) => (w.warnings.length ? w.warnings : (readWarnings[w.offset] ?? [])); - /** Per group: rows shown, the filter typed and the one asked for, and which diffs and warning groups are open. */ + /** Per group: rows shown, the filter typed and the one asked for, and which diffs are open. */ let shownOf = $state>({}); let filterOf = $state>({}); let askedOf = $state>({}); let openDiff = $state>({}); - let openWarnings = $state>({}); - let allWarnings = $state>({}); let loading = $state(false); let loadError = $state(null); @@ -135,17 +178,11 @@ /** The next server page the group needs to show `shown` rows: its first section with rows still to load. */ const nextPage = $derived(shownGroup?.pages.find((p) => p.loaded < p.total) ?? null); - /** Warnings read so far, of the plan's. */ - const warningsRead = $derived(group?.key === 'warnings' ? group.pages.reduce((n, p) => n + p.loaded, 0) : 0); - - // Load pages until the group holds the rows it shows (the warnings, up to the cap), one at a time. + // Load pages until the group holds the rows it shows, one at a time; warnings are read by group. $effect(() => { const g = shownGroup; const page = nextPage; - const warnings = g?.key === 'warnings'; - const held = warnings ? warningsRead : (g?.rows.length ?? 0); - const want = warnings ? WARNINGS_READ : shown; - if (!g || !page || loading || held >= Math.min(want, g.count)) return; + if (!g || !page || loading || g.key === 'warnings' || g.rows.length >= Math.min(shown, g.count)) return; if (filtering && !serverFilter) return; const current = view; const step = filtering @@ -155,18 +192,13 @@ view = { ...current, doc: viewDoc(current.matches, mergePlanPage(current.doc, page.section, rows)) }; }) : null - : (more?.(page.section, warnings ? WARNING_PAGE : PAGE) ?? null); + : (more?.(page.section, PAGE) ?? null); if (!step) return; loading = true; loadError = null; step.catch((e: unknown) => (loadError = e instanceof Error ? e.message : String(e))).finally(() => (loading = false)); }); - // A small config change reads inline, so the rows shown read theirs. - $effect(() => { - for (const r of visible) if (r.pendingConfig && r.fetch === 'diff') readDiff(r.name); - }); - function showMore() { if (!group) return; shownOf[group.key] = shown + PAGE; @@ -207,21 +239,23 @@ {#if group.key === 'warnings'} - {#if warningsRead < group.count}

{loading ? 'Reading the warnings…' : `Grouping the first ${warningsRead.toLocaleString()} of ${group.count.toLocaleString()} warnings.`}

{/if} - {#each warningGroups as w (w.template)} + {#each warningGroups as w (w.offset)}
{w.template} {w.label} - +
- {#if openWarnings[w.template]} - {@const all = allWarnings[w.template]} + {#if openWarnings[w.offset]} + {@const all = allWarnings[w.offset]} + {@const listed = warningsOf(w)}
    - {#each all ? w.warnings : w.warnings.slice(0, WARNINGS_SHOWN) as one, i (i)}
  • {#if one.code}{one.code} {/if}{one.message}
  • {/each} + {#each all ? listed : listed.slice(0, WARNINGS_SHOWN) as one, i (i)}
  • {#if one.code}{one.code} {/if}{one.message}
  • {/each}
- {#if !all && w.warnings.length > WARNINGS_SHOWN} - + {#if all && listed.length >= WARNINGS_READ && listed.length < w.count} +

The first {listed.length.toLocaleString()} of {w.count.toLocaleString()}.

+ {:else if !all && w.count > WARNINGS_SHOWN} + {/if} {/if}
diff --git a/ui/src/lib/run/plan-index.test.ts b/ui/src/lib/run/plan-index.test.ts index ebf6083489..d9c666c37f 100644 --- a/ui/src/lib/run/plan-index.test.ts +++ b/ui/src/lib/run/plan-index.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { PlanDocument, PlanModel } from '$lib/api'; -import { configChange, cursorWords, diffPreview, diffStats, sectionNote, groupWarnings, planGroups, planSummaryLine, selectedGroup, sharedNote, whitespaceOnly, type PlanRow } from './plan-index'; +import { cursorWords, diffPreview, diffStats, sectionNote, groupWarnings, planGroups, planSummaryLine, selectedGroup, sharedNote, whitespaceOnly, type PlanRow } from './plan-index'; const empty: PlanDocument = { selected_count: 0, @@ -45,18 +45,6 @@ describe('whitespace-only query changes', () => { }); }); -describe('config changes in one line', () => { - it('reads up to two changed keys of the config JSON', () => { - expect(configChange([...head, '- "full_refresh": true,', '+ "full_refresh": false,'])).toBe('full_refresh true → false'); - expect(configChange(['- "cursor": "observed_at",', '+ "cursor": "event_date",', '+ "grain": "day"'])).toBe('cursor observed_at → event_date; grain (unset) → day'); - }); - - it('leaves more keys, or a nested value, to the diff', () => { - expect(configChange(['- "a": 1,', '+ "a": 2,', '- "b": 1,', '+ "b": 2,', '- "c": 1,', '+ "c": 2,'])).toBeNull(); - expect(configChange(['+ "meta": {'])).toBeNull(); - }); -}); - describe('cursor ranges in words', () => { it("words the executor's bound placeholders", () => { expect(cursorWords('range: __SQB_CURSOR_START__ → __SQB_CURSOR_END__')).toBe('range: from the last run → the latest data when the run starts'); @@ -65,7 +53,7 @@ describe('cursor ranges in words', () => { }); describe('notes every row shares', () => { - const row = (name: string, detail: string, notes: string[] = []): PlanRow => ({ name, action: 'table', detail, notes, diff: null, diffOf: null, warnings: [], linked: true, fetch: null, pendingConfig: false }); + const row = (name: string, detail: string, notes: string[] = []): PlanRow => ({ name, action: 'table', detail, notes, diff: null, diffOf: null, warnings: [], linked: true, fetch: null }); it('finds the note every row carries, and none when one differs', () => { expect(sharedNote([row('a', 'no completed record'), row('b', 'no completed record')])).toBe('no completed record'); @@ -108,7 +96,7 @@ describe('the plan index', () => { models: [ model('orders', 'query_changed', { query_diff: [...head, '-select 1', '+select 2'] }), model('payments', 'query_changed', { query_diff: [...head, '-select 1', '+select 1'] }), - model('refunds', 'config_changed', { config_diff: ['- "full_refresh": true,', '+ "full_refresh": false,'] }), + model('refunds', 'config_changed', { config_diff: ['- "full_refresh": true,', '+ "full_refresh": false,'], config_change: 'full_refresh true → false' }), model('customers', 'first_run'), model('regions', 'no_change') ], @@ -168,47 +156,77 @@ describe('a plan from a server summary', () => { models: [ model('orders', 'query_changed', { diff_stats: { query: { added: 82, removed: 104, whitespace_only: false } } }), model('payments', 'query_changed', { diff_stats: { query: { added: 2, removed: 2, whitespace_only: true } } }), - model('refunds', 'config_changed', { diff_stats: { config: { added: 1, removed: 1, whitespace_only: false } } }), + model('refunds', 'config_changed', { config_change: 'full_refresh true → false', diff_stats: { config: { added: 1, removed: 1, whitespace_only: false } } }), + model('ledger', 'config_changed', { diff_stats: { config: { added: 3, removed: 3, whitespace_only: false } } }), model('regions', 'no_change') ], sections: [ { section: 'query_changed', total: 2, notes: [] }, - { section: 'config_changed', total: 1, notes: [] }, + { section: 'config_changed', total: 2, notes: [] }, { section: 'routine_models', total: 1507, notes: [{ kind: 'run_reason', value: 'no completed record', count: 1507 }] }, - { section: 'seeds', total: 10, notes: [{ kind: 'reason', value: 'first_run', count: 2 }] }, - { section: 'unchanged', total: 300, notes: [] } + { section: 'first_run_seeds', total: 2, notes: [] }, + { section: 'unchanged_seeds', total: 10, notes: [] }, + { section: 'unchanged', total: 300, notes: [] }, + { section: 'warnings', total: 74, notes: [] } + ], + pages: { query_changed: 2, config_changed: 2, routine_models: 1507, first_run_seeds: 2, unchanged_seeds: 10, unchanged: 300, warnings: 74 }, + loaded: { query_changed: 2, config_changed: 2, routine_models: 1 }, + warning_groups: [ + { template: 'Scenario … provides fixture for unknown model …', count: 71, subject: { noun: 'scenario', count: 24 } }, + { template: 'Scenario … requires source …', count: 3, subject: null } ], - pages: { query_changed: 2, config_changed: 1, routine_models: 1507, seeds: 10, unchanged: 300 }, - loaded: { query_changed: 2, config_changed: 1, routine_models: 1 }, - changed: { counts: ['definition'], reach: 'all', runs: ['orders', 'payments', 'refunds', 'regions'].map((n) => ({ node: `model:${n}`, reason: n === 'regions' ? 'no completed record' : 'definition changed', downstream_of: null })), held_back: [], unchanged: [] } + changed: { counts: ['definition'], reach: 'all', runs: ['orders', 'payments', 'refunds', 'ledger', 'regions'].map((n) => ({ node: `model:${n}`, reason: n === 'regions' ? 'no completed record' : 'definition changed', downstream_of: null })), held_back: [], unchanged: [] } }; it("counts groups from the server's sections, and pages their rows in plan order", () => { const groups = planGroups(summary); expect(groups.map((g) => [g.key, g.count])).toEqual([ - ['changed', 3], + ['changed', 4], + ['first_run', 2], + ['warnings', 74], ['unchanged', 1517], ['skipped', 300] ]); - const unchanged = groups[1]; - expect(unchanged.subtitle).toBe('1,507 models · 10 seeds · models: no completed record (all 1,507) · seeds: 2 first run'); + const unchanged = groups[3]; + expect(unchanged.subtitle).toBe('1,507 models · 10 seeds · models: no completed record (all 1,507)'); expect(unchanged.rows.map((r) => [r.name, r.action, r.detail])).toEqual([['regions', 'table', '']]); expect(unchanged.pages).toEqual([ { section: 'routine_models', loaded: 1, total: 1507 }, - { section: 'seeds', loaded: 0, total: 10 } + { section: 'unchanged_seeds', loaded: 0, total: 10 } ]); + expect(groups[1].pages).toEqual([{ section: 'first_run_seeds', loaded: 0, total: 2 }]); }); it("reads changed rows' counts from diff_stats, and reads a diff it doesn't carry on demand", () => { const rows = (diffs?: Map) => Object.fromEntries(planGroups(summary, undefined, diffs)[0].rows.map((r) => [r.name, r])); const before = rows(); - expect(before.orders).toMatchObject({ detail: 'query +82 −104', diff: null, fetch: 'diff', pendingConfig: false }); + expect(before.orders).toMatchObject({ detail: 'query +82 −104', diff: null, fetch: 'diff' }); expect(before.payments.detail).toBe('whitespace only'); - // A config change of up to two lines a side is read to show inline. - expect(before.refunds).toMatchObject({ detail: 'config', fetch: 'diff', pendingConfig: true }); - const read = rows(new Map([['refunds', { model: 'refunds', config_diff: ['- "full_refresh": true,', '+ "full_refresh": false,'] }], ['orders', null]])); - expect(read.refunds).toMatchObject({ detail: 'config · full_refresh true → false', fetch: null, diffOf: null }); + // The server's short config change reads inline, with nothing to read; a longer one links to its diff. + expect(before.refunds).toMatchObject({ detail: 'config · full_refresh true → false', fetch: null, diffOf: null }); + expect(before.ledger).toMatchObject({ detail: 'config', fetch: 'diff', diffOf: 'config' }); + const read = rows(new Map([['orders', null]])); // The server has no diff to give, as without permission to read the model's SQL. expect(read.orders).toMatchObject({ detail: 'query +82 −104', diff: null, fetch: 'unavailable' }); }); + + it("lists the server's warning groups, counted and each where its warnings start, before any is read", () => { + const warnings = planGroups(summary).find((g) => g.key === 'warnings')!; + expect(warnings.subtitle).toBe('2 kinds'); + expect(warnings.warningGroups?.map((g) => [g.template, g.label, g.count, g.offset, g.warnings.length])).toEqual([ + ['Scenario … provides fixture for unknown model …', '71 in 24 scenarios', 71, 0, 0], + ['Scenario … requires source …', '3 warnings', 3, 71, 0] + ]); + }); + + it('pages the warnings past the largest groups the summary lists as one more group, after them', () => { + const capped = { ...summary, sections: summary.sections!.map((s) => (s.section === 'warnings' ? { ...s, total: 80 } : s)) }; + const warnings = planGroups(capped).find((g) => g.key === 'warnings')!; + expect(warnings.subtitle).toBe('2 kinds and more'); + expect(warnings.warningGroups?.map((g) => [g.template, g.label, g.count, g.offset])).toEqual([ + ['Scenario … provides fixture for unknown model …', '71 in 24 scenarios', 71, 0], + ['Scenario … requires source …', '3 warnings', 3, 71], + ['Other warnings', '6 warnings of smaller kinds', 6, 74] + ]); + }); }); diff --git a/ui/src/lib/run/plan-index.ts b/ui/src/lib/run/plan-index.ts index 099f2cc097..c9010c859b 100644 --- a/ui/src/lib/run/plan-index.ts +++ b/ui/src/lib/run/plan-index.ts @@ -1,7 +1,7 @@ // The plan page's list as an index and a pane: the plan's sections (plan-text.ts) gathered into a few // groups, one shown at a time, each row one line of name · action · detail. Pure. -import type { PlanDiff, PlanDocument, PlanPageSection, PlanSectionCount, PlanWarning } from '$lib/api'; +import type { PlanDiff, PlanDocument, PlanPageSection, PlanSectionCount, PlanWarning, PlanWarningGroup } from '$lib/api'; import { plural } from '$lib/format/plural'; import { changedSections, loadedRows, looseWarnings, planSections, sectionSize, type PlanEntry, type PlanSection } from './plan-text'; @@ -45,7 +45,9 @@ const GROUP_OF: Record = { warnings: 'warnings', routine_models: 'unchanged', functions: 'unchanged', - seeds: 'unchanged', + first_run_seeds: 'first_run', + changed_seeds: 'changed', + unchanged_seeds: 'unchanged', unchanged: 'skipped' }; /** The kind of change a Changed section counts as, for its breakdown. */ @@ -60,7 +62,9 @@ const CHANGE_KIND: Partial> = { const SECTION_WORD: Partial> = { routine_models: 'models', functions: 'functions', - seeds: 'seeds', + first_run_seeds: 'seeds', + changed_seeds: 'seeds', + unchanged_seeds: 'seeds', renamed: 'renamed', migrations: 'migrations', column_migrations: 'column migrations', @@ -72,14 +76,14 @@ const SECTION_WORD: Partial> = { source_loads: 'source loads' }; const sectionWord = (section: PlanPageSection) => SECTION_WORD[section] ?? section.replace(/_/g, ' '); +/** A count in a breakdown, such as "87 query" or "1 seed": seeds say one or many. */ +const counted = (n: number, word: string) => (word === 'seeds' ? plural(n, 'seed') : `${n.toLocaleString()} ${word}`); /** Sections whose rows are catalog models, so they link to the catalog. */ const MODEL_ROWS = new Set(['query_changed', 'function_changed', 'config_changed', 'schema_changed', 'first_run', 'renamed', 'routine_models', 'migrations', 'column_migrations', 'table_type_conversions', 'retention', 'held_back', 'unchanged']); /** A whole plan's full refresh, which plan-text sums by materialization rather than listing as a section of models. */ const TITLE_SECTION: Record = { 'Full refresh': 'full_refresh' }; /** The notes a section's subtitle can say once for its rows: why `--changed` runs them. */ const ROW_NOTES = new Set(['run_reason', 'reads']); -/** A seed's plan reason in words, for the Seeds breakdown; a current seed goes unsaid. */ -const SEED_REASON: Record = { first_run: 'first run', config_changed: 'changed' }; export type ChangeKind = 'query' | 'config' | 'function' | 'schema'; @@ -105,8 +109,6 @@ export type PlanRow = { kinds?: string[]; /** The row's diff is read on demand ('diff'), or the server has none to give ('unavailable'). */ fetch: 'diff' | 'unavailable' | null; - /** A config change of at most two keys, read on demand to show inline. */ - pendingConfig: boolean; }; export type PlanGroup = { @@ -125,8 +127,11 @@ export type PlanGroup = { sections: PlanPageSection[]; }; -/** A warnings group: one message template and the warnings that fill it in. */ -export type WarningGroup = { template: string; warnings: PlanWarning[]; label: string }; +/** + * A warnings group: one message template, how many warnings fill it in and those read so far. A server + * summary's group starts empty; its warnings are rows `offset` onwards of the warnings section. + */ +export type WarningGroup = { template: string; count: number; offset: number; warnings: PlanWarning[]; label: string }; const DIFF_HEAD = /^(---|\+\+\+|@@)/; const lineClass = (line: string): DiffLine['cls'] => (DIFF_HEAD.test(line) ? 'hunk' : line.startsWith('+') ? 'add' : line.startsWith('-') ? 'del' : ''); @@ -152,25 +157,6 @@ export function whitespaceOnly(diff: string[]): boolean { return (removed.length > 0 || added.length > 0) && side('-') === side('+'); } -/** - * A config diff's changes in one line, such as `full_refresh true → false`, when it changes at most - * `most` top-level keys with plain values; null otherwise, and the row links to the diff instead. - */ -export function configChange(diff: string[], most = 2): string | null { - const values = new Map(); - for (const line of diff) { - if (DIFF_HEAD.test(line) || !(line.startsWith('+') || line.startsWith('-'))) continue; - const m = /^[-+]\s*"([^"]+)":\s*(.*?),?\s*$/.exec(line); - // A nested value, or a line that isn't one key's value, can't be read in one line. - if (!m || /[{[]$/.test(m[2])) return null; - const entry = values.get(m[1]) ?? {}; - entry[line.startsWith('-') ? 'old' : 'new'] = m[2].replace(/^"(.*)"$/, '$1'); - values.set(m[1], entry); - } - if (!values.size || values.size > most) return null; - return [...values].map(([key, v]) => `${key} ${v.old ?? '(unset)'} → ${v.new ?? '(unset)'}`).join('; '); -} - /** The executor's placeholders for a microbatch's bounds, which a preview reports as the range. */ const CURSOR_START = '__SQB_CURSOR_START__'; const CURSOR_END = '__SQB_CURSOR_END__'; @@ -201,9 +187,7 @@ function changedRow(e: PlanEntry, kind: ChangeKind | undefined, linked: boolean, if (e.schema?.length) kinds.add('schema'); const cause = e.detail.find((d) => d.startsWith('cause: function ')); if (cause) kinds.add('function'); - const config = configText?.length ? configChange(configText) : null; - // A config change of at most two keys reads inline once its text is read; until then the row waits for it. - const pendingConfig = !configText && !!configStats && configStats.added <= 2 && configStats.removed <= 2 && fetched === undefined; + const config = e.configChange ?? null; const quiet = !!query?.whitespace_only; const label = KIND_ORDER.filter((k) => kinds.has(k)).join(' + '); const counts = query && !quiet ? `+${query.added} −${query.removed}` : null; @@ -218,7 +202,7 @@ function changedRow(e: PlanEntry, kind: ChangeKind | undefined, linked: boolean, if (cause) parts.push(cause.slice('cause: function '.length)); if (e.schema?.length) parts.push(plural(e.schema.length, 'column')); // The diff the link opens: the query, else a config too long to read inline, else the schema. - const diffOf = query ? 'query' : configStats && !config && !pendingConfig ? 'config' : e.schema?.length ? 'schema' : null; + const diffOf = query ? 'query' : configStats && !config ? 'config' : e.schema?.length ? 'schema' : null; // Whether the row holds the text of the diff its link opens; if not, opening it reads it. const held = diffOf === 'query' ? !!queryText : diffOf === 'config' ? !!configText : true; const diff: DiffLine[] | null = @@ -239,14 +223,13 @@ function changedRow(e: PlanEntry, kind: ChangeKind | undefined, linked: boolean, warnings: e.warnings ?? [], linked, kinds: [...kinds], - fetch: (diffOf && !held && fetched === undefined) || pendingConfig ? 'diff' : diffOf && !held ? 'unavailable' : null, - pendingConfig + fetch: diffOf && !held ? (fetched === undefined ? 'diff' : 'unavailable') : null }; } const plainRow = (e: PlanEntry, linked: boolean): PlanRow => { const [first = '', ...rest] = e.detail.map(cursorWords); - return { name: e.name, action: e.value, detail: first, notes: rest, diff: null, diffOf: null, warnings: e.warnings ?? [], linked, fetch: null, pendingConfig: false }; + return { name: e.name, action: e.value, detail: first, notes: rest, diff: null, diffOf: null, warnings: e.warnings ?? [], linked, fetch: null }; }; /** A note every loaded row shares, such as "no completed record": for a whole plan, which comes without counted notes. */ @@ -302,16 +285,39 @@ export function groupWarnings(warnings: PlanWarning[]): WarningGroup[] { const t = warningTemplate(w); groups.set(t, [...(groups.get(t) ?? []), w]); } - return [...groups] - .map(([template, list]) => { - const noun = /^(\w+) …/.exec(template)?.[1]; - const firsts = new Set(list.map((w) => /'([^']*)'|`([^`]*)`|"([^"]*)"/.exec(w.message)?.slice(1).find(Boolean) ?? '')); - const label = noun && list.length > 1 && firsts.size < list.length ? `${list.length} in ${plural(firsts.size, noun.toLowerCase())}` : plural(list.length, 'warning'); - return { template, warnings: list, label }; - }) - .sort((a, b) => b.warnings.length - a.warnings.length); + const sorted = [...groups].sort((a, b) => b[1].length - a[1].length); + let offset = 0; + return sorted.map(([template, list]) => { + const noun = /^(\w+) …/.exec(template)?.[1]; + const firsts = new Set(list.map((w) => /'([^']*)'|`([^`]*)`|"([^"]*)"/.exec(w.message)?.slice(1).find(Boolean) ?? '')); + const subject = noun && list.length > 1 && firsts.size < list.length ? { noun: noun.toLowerCase(), count: firsts.size } : null; + const group = { template, count: list.length, offset, warnings: list, label: warningGroupLabel(list.length, subject) }; + offset += list.length; + return group; + }); +} + +/** A warning group's size, and how many named things it covers when they repeat: "71 in 24 scenarios". */ +function warningGroupLabel(count: number, subject: PlanWarningGroup['subject']): string { + return subject ? `${count} in ${plural(subject.count, subject.noun)}` : plural(count, 'warning'); } +/** A server summary's warning groups, each starting where the one before ends in the warnings section. */ +function serverWarningGroups(groups: PlanWarningGroup[], total: number): WarningGroup[] { + let offset = 0; + const listed: WarningGroup[] = groups.map((g) => { + const group = { template: g.template, count: g.count, offset, warnings: [], label: warningGroupLabel(g.count, g.subject) }; + offset += g.count; + return group; + }); + // The summary lists only the largest groups; the warnings past them page as one rest. + const rest = total - offset; + return rest > 0 ? [...listed, { template: REST_TEMPLATE, count: rest, offset, warnings: [], label: `${plural(rest, 'warning')} of smaller kinds` }] : listed; +} + +/** The group holding the warnings past a server summary's largest groups. */ +const REST_TEMPLATE = 'Other warnings'; + /** The plan's sections with their sizes and notes: the server summary's, else counted from a whole plan's rows. */ export function sectionCounts(plan: PlanDocument, sections: PlanSection[]): PlanSectionCount[] { if (plan.sections) return plan.sections; @@ -333,7 +339,9 @@ export function planGroups(plan: PlanDocument, refresh: (job: string) => string const textOf = new Map(sections.map((s) => [s.section ?? TITLE_SECTION[s.title], s])); const counts = sectionCounts(plan, sections); const warnings = looseWarnings(plan, sections); - const grouped = warnings.length ? groupWarnings(warnings) : []; + const warningTotal = counts.find((c) => c.section === 'warnings')?.total ?? 0; + const grouped = plan.warning_groups ? serverWarningGroups(plan.warning_groups, warningTotal) : warnings.length ? groupWarnings(warnings) : []; + const warningKinds = plan.warning_groups ? plural(plan.warning_groups.length, 'kind') + (grouped.length > plan.warning_groups.length ? ' and more' : '') : plural(grouped.length, 'kind'); // A whole plan (an older server's, or the mock's) has every row and no counted notes. const whole = !plan.sections; return ORDER.flatMap((key) => { @@ -348,10 +356,6 @@ export function planGroups(plan: PlanDocument, refresh: (job: string) => string const entries = textOf.get(c.section)?.entries ?? []; const loaded = key === 'warnings' ? loadedRows(plan, 'warnings') : entries.length; if (!whole) pages.push({ section: c.section, loaded, total: c.total }); - if (c.section === 'seeds') { - const reasons = c.notes.filter((n) => n.kind === 'reason' && n.value && SEED_REASON[n.value]).map((n) => `${n.count.toLocaleString()} ${SEED_REASON[n.value!]}`); - if (reasons.length) notes.push(`seeds: ${reasons.join(', ')}`); - } // A section's rows follow the one before only once that one is all loaded, so rows read in order. if (key === 'warnings' || !complete) continue; const linked = MODEL_ROWS.has(c.section); @@ -370,13 +374,13 @@ export function planGroups(plan: PlanDocument, refresh: (job: string) => string if (key === 'changed') for (const c of mine) kinds.set(CHANGE_KIND[c.section] ?? sectionWord(c.section), (kinds.get(CHANGE_KIND[c.section] ?? sectionWord(c.section)) ?? 0) + c.total); const breakdown = key === 'changed' - ? [...kinds].sort((a, b) => b[1] - a[1]).map(([k, n]) => `${n.toLocaleString()} ${k}`) + ? [...kinds].sort((a, b) => b[1] - a[1]).map(([k, n]) => counted(n, k)) : key === 'warnings' - ? grouped.length && (whole || loadedRows(plan, 'warnings') >= count) - ? [plural(grouped.length, 'kind')] + ? grouped.length && (whole || plan.warning_groups || loadedRows(plan, 'warnings') >= count) + ? [warningKinds] : [] : mine.length > 1 - ? mine.map((c) => `${c.total.toLocaleString()} ${sectionWord(c.section)}`) + ? mine.map((c) => counted(c.total, sectionWord(c.section))) : []; return [{ key, title: TITLES[key], count, subtitle: [...breakdown, ...notes].join(' · '), rows, pages, sections: mine.map((c) => c.section), ...(key === 'warnings' ? { warningGroups: grouped } : {}) }]; }); diff --git a/ui/src/lib/run/plan-text.ts b/ui/src/lib/run/plan-text.ts index 938ca72d52..a9180cf2ea 100644 --- a/ui/src/lib/run/plan-text.ts +++ b/ui/src/lib/run/plan-text.ts @@ -14,6 +14,8 @@ export type PlanEntry = { detail: string[]; queryDiff?: string[]; configDiff?: string[]; + /** A config change of at most two plain keys in words, as the server reads it from the config diff. */ + configChange?: string; /** A server page's diff counts, in place of the diff text, which is read on demand. */ diffStats?: PlanModel['diff_stats']; schema?: { sign: '+' | '-' | '~'; text: string }[]; @@ -69,6 +71,18 @@ function runsUnderChanged(plan: PlanDocument, key: string): boolean { return nodes.has(key); } +/** The seed sections in plan order, with their titles and what the run does to each seed. */ +const SEED_SECTIONS: [string, PlanPageSection, string][] = [ + ['First-run seeds', 'first_run_seeds', 'load'], + ['Changed seeds', 'changed_seeds', 'reload'], + ['Seeds', 'unchanged_seeds', 'current'] +]; + +/** A seed's section by its plan reason, as the server splits them: a first run, no change of its own, or any other change. */ +export function seedSection(reason: string): PlanPageSection { + return reason === 'first_run' ? 'first_run_seeds' : !reason || reason === 'no_change' ? 'unchanged_seeds' : 'changed_seeds'; +} + /** The seeds the run loads or reports on: under `--changed`, only those it runs. */ export const builtSeeds = (plan: PlanDocument) => plan.seeds.filter((s) => runsUnderChanged(plan, `seed:${s.name}`)); @@ -125,6 +139,7 @@ function changedEntry(m: PlanModel, reason: string, windowStart?: string): PlanE ], queryDiff: m.query_diff, configDiff: m.config_diff, + configChange: m.config_change, diffStats: m.diff_stats, schema: m.schema_findings?.map((f) => { const kind = SCHEMA_SIGNS[f.kind] ?? { sign: '~' as const, label: f.kind }; @@ -176,8 +191,8 @@ export function planSections(plan: PlanDocument): PlanSection[] { }), false, 'routine_models'); } add('Functions', plan.functions.filter((f) => !f.reason || f.reason === 'no_change').map(functionEntry), false, 'functions'); - const seedLabel: Record = { first_run: 'first_run', config_changed: 'seed_changed', no_change: 'current' }; - add('Seeds', builtSeeds(plan).map((s) => ({ name: s.name, value: seedLabel[s.reason] ?? '', detail: [] })), false, 'seeds'); + const seeds = builtSeeds(plan); + for (const [title, section, value] of SEED_SECTIONS) add(title, seeds.filter((s) => seedSection(s.reason) === section).map((s) => ({ name: s.name, value, detail: [] })), false, section); add('Python', plan.python_nodes.map((p) => ({ name: p.name, value: `${p.kind} · ${p.identity_status}`, detail: [] })), false, 'python_nodes'); // A planner warning names its model in `model_name`, or opens its message with it as the CLI prints it; it shows once, with the first entry for that model. const claimed = new Set(); diff --git a/ui/src/routes/plan/+page.svelte b/ui/src/routes/plan/+page.svelte index 48d00b8c3a..6401b7f8e4 100644 --- a/ui/src/routes/plan/+page.svelte +++ b/ui/src/routes/plan/+page.svelte @@ -187,18 +187,51 @@ const byKey = $derived(new Map((catalog.data ?? []).map((n) => [n.key, n]))); const picked = $derived(shown?.selection ?? []); let view = $state<'plan' | 'graph' | 'checks'>('plan'); - /** - * The recorded checks on the models and seeds the command selects, which run after them. The - * selection is the one the command resolves to, as the plan request froze it; the plan's summary - * carries no list of the nodes it builds. - */ - const planChecks = $derived.by(() => { + /** The most rows one read brings, as the server pages them. */ + const ROWS_READ = 1000; + /** Under `--changed`, the nodes it skips: held back or unchanged, read from a server plan's pages when the Checks tab opens. */ + let skippedKeys = $state<{ requestId: string; keys: string[] | null; failed?: boolean } | null>(null); + $effect(() => { + const scope = app.scope; + const requestId = planRequestId; + const sections = plan?.changed ? plan.sections : undefined; + if (view !== 'checks' || !scope || !requestId || !sections || skippedKeys?.requestId === requestId) return; + skippedKeys = { requestId, keys: null }; + (async () => { + const keys: string[] = []; + for (const s of sections.filter((c) => (c.section === 'held_back' || c.section === 'unchanged') && c.total)) { + for (let offset = 0; offset < s.total; offset += ROWS_READ) { + const page = await app.client.planRows(scope, requestId, s.section, offset, ROWS_READ); + keys.push(...(page.rows as (string | { node: string })[]).map((r) => (typeof r === 'string' ? r : r.node))); + } + } + if (planRequestId === requestId) skippedKeys = { requestId, keys }; + })().catch(() => { + // Not retried: a plan whose rows can't be read has usually expired. + if (planRequestId === requestId) skippedKeys = { requestId, keys: null, failed: true }; + }); + }); + /** Node keys `--changed` skips; a whole plan lists them, a server plan's are read above (null until then). */ + const planSkipped = $derived.by(() => { + if (!plan?.changed) return []; + if (!plan.sections) return [...plan.changed.held_back.map((h) => h.node), ...plan.changed.unchanged]; + return skippedKeys?.requestId === planRequestId ? skippedKeys.keys : null; + }); + const keyName = (key: string) => key.slice(key.indexOf(':') + 1); + /** The recorded checks on the models and seeds the command selects, as the plan request froze the selection. */ + const selectedChecks = $derived.by(() => { if (!plan) return []; - const selected = new Set(picked); + const selected = new Set(picked.map(keyName)); return (checkList.data ?? []).filter((c) => (c.attachment === 'model' || c.attachment === 'seed') && !!c.node && selected.has(c.node)); }); + /** Of those, the checks on nodes the build runs, which run after them: all but those `--changed` skips (null until read). */ + const planChecks = $derived.by(() => { + if (!planSkipped) return null; + const skipped = new Set(planSkipped.map(keyName)); + return selectedChecks.filter((c) => !skipped.has(c.node ?? '')); + }); /** The tab shown: a replan with no checks leaves the Checks tab for the plan. */ - const tab = $derived(view === 'checks' && !(shown?.verb === 'build' && planChecks.length) ? 'plan' : view); + const tab = $derived(view === 'checks' && !(shown?.verb === 'build' && selectedChecks.length && planChecks?.length !== 0) ? 'plan' : view); /** A large selection draws only what the plan changes; the whole of it would be unreadable. */ const GRAPH_LIMIT = 150; /** Sections of models the plan changes, read a page each for the graph of a large selection. */ @@ -419,7 +452,7 @@ {#each Object.entries(shown.settings) as [name, value] (name)}{value === true ? name : `${name}=${value}`}{/each} {#if shown.verb === 'build' && plan?.ignore_audit_failures}Audit failures won't stop this build{/if}
- (view = v)} /> + (view = v)} />
{#if shown.verb === 'build' && plan} {#if plan.timings}{/if} @@ -435,8 +468,8 @@
{}} />
{/if} {:else if tab === 'checks' && shown?.verb === 'build' && plan} -

{plural(planChecks.length, 'check')}

- c.id} empty="No checks in this plan."> +

{planChecks ? plural(planChecks.length, 'check') : skippedKeys?.failed ? "Couldn't read the nodes --changed skips; plan again." : 'Reading the nodes --changed skips…'}

+ c.id} empty="No checks in this plan."> {#snippet row(c)} {c.name} diff --git a/ui/src/routes/runs/[id]/ignored-audits-panel.svelte b/ui/src/routes/runs/[id]/ignored-audits-panel.svelte index 050d40b3c7..6614c8e429 100644 --- a/ui/src/routes/runs/[id]/ignored-audits-panel.svelte +++ b/ui/src/routes/runs/[id]/ignored-audits-panel.svelte @@ -1,11 +1,10 @@ {#if count}

{plural(count, 'audit failure')} ignored · audit failures don't stop this job, so the run went on

- {#if found.length} + {#if failures?.length}
    - {#each found as c (c.id)} + {#each failures as f, i (`${f.runId}:${f.checkId ?? f.audit}:${i}`)}
  • - {c.node ?? '—'} - {c.name} - {#if c.latest?.violationCount}{plural(c.latest.violationCount, 'row')} failing{/if} + {#if group && f.jobKey}{f.jobKey}{/if} + {f.node ?? '—'}{f.column ? `.${f.column}` : ''} + {#if f.checkId}{f.audit}{:else}{f.audit}{/if} + {#if f.violationCount}{plural(f.violationCount, 'row')} failing{/if} ignored
  • {/each}
{/if} - {#if unnamed && checks} -

{unnamed === count ? 'Their checks' : `${plural(unnamed, 'more')}: their checks`} have newer results since. Ignored failures on the Checks page

- {:else if failed} -

Couldn't read the checks. Ignored failures on the Checks page

+ {#if failed} +

Couldn't read the failures. Ignored failures on the Checks page

+ {:else if failures && failures.length < count} +

{failures.length ? `${(count - failures.length).toLocaleString()} more no longer recorded` : 'Their results are no longer recorded'}. Ignored failures on the Checks page

{/if}
{/if}