Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 82 additions & 1 deletion clients/typescript/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
67 changes: 65 additions & 2 deletions crates/sqlbuild-core/src/plan_display/_helpers/diff_lines.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<String> {
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<String> = 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))
}
1 change: 1 addition & 0 deletions crates/sqlbuild-core/src/plan_display/_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
45 changes: 36 additions & 9 deletions crates/sqlbuild-core/src/plan_display/_helpers/plan_pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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.
Expand All @@ -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"),
Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down
32 changes: 27 additions & 5 deletions crates/sqlbuild-core/src/plan_display/_helpers/plan_sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,6 +73,20 @@ pub(crate) fn emptied(fields: &Map<String, Value>) -> Map<String, Value> {
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<String, Value>,
) -> Map<String, Value> {
let groups: Vec<Value> = 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,
Expand Down Expand Up @@ -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(),
};
Expand All @@ -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()
Expand All @@ -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));
}
Expand Down
Loading
Loading