feat(suppress): author + persist per-app template suppressions (§11 tail S2)

The declarative half — a `[suppress]` block persists as markers; no runtime
effect yet (S3 consumes them).

- manifest: `[suppress]` table on an app with `triggers = [...]` (handler
  script names) + `routes = [...]` (paths), `deny_unknown_fields`; rejected
  on a `[group]` (a group just wouldn't declare the template).
- suppression_repo.rs: app-keyed `list_for_app` / `insert` / `delete_tx`
  over `(app_id, target_kind, reference)`, mirroring extension_point_repo
  minus the owner polymorphism.
- apply_service: the extension-point marker-reconcile pattern —
  `Bundle.suppress_triggers/_routes`, `Plan.suppressions`,
  `CurrentState.suppressions`, `load_current(App)` load, `diff_suppressions`
  (key `"{kind}:{reference}"`, split on the first `:` so a route param path
  survives), create + prune reconcile blocks, `validate_bundle_for` group
  reject, `ApplyReport` counters.
- CLI: `build_bundle` carries the two vecs; `pic plan` + apply report gain a
  suppressions row (DTOs + display).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-07-01 07:32:26 +02:00
parent 18ac9f5afa
commit 32cb6c1f1f
9 changed files with 302 additions and 2 deletions

View File

@@ -1429,6 +1429,8 @@ pub struct PlanDto {
pub extension_points: Vec<ChangeDto>,
#[serde(default)]
pub collections: Vec<ChangeDto>,
#[serde(default)]
pub suppressions: Vec<ChangeDto>,
/// Fingerprint of the live state this plan was computed against; carried
/// in `.picloud/` and replayed to `apply` for the bound-plan check.
#[serde(default)]
@@ -1471,6 +1473,8 @@ pub struct NodePlanDto {
pub extension_points: Vec<ChangeDto>,
#[serde(default)]
pub collections: Vec<ChangeDto>,
#[serde(default)]
pub suppressions: Vec<ChangeDto>,
}
/// Response of `POST .../apply`: counts of what changed.
@@ -1507,6 +1511,10 @@ pub struct ApplyReportDto {
#[serde(default)]
pub collections_deleted: u32,
#[serde(default)]
pub suppressions_created: u32,
#[serde(default)]
pub suppressions_deleted: u32,
#[serde(default)]
pub warnings: Vec<String>,
}

View File

@@ -98,6 +98,13 @@ pub async fn run(
"+{} -{}",
report.collections_created, report.collections_deleted
),
)
.field(
"suppressions",
format!(
"+{} -{}",
report.suppressions_created, report.suppressions_deleted
),
);
for w in &report.warnings {
block.field("warning", w.clone());
@@ -179,6 +186,13 @@ pub async fn run_tree(
"+{} -{}",
report.collections_created, report.collections_deleted
),
)
.field(
"suppressions",
format!(
"+{} -{}",
report.suppressions_created, report.suppressions_deleted
),
);
for w in &report.warnings {
block.field("warning", w.clone());

View File

@@ -140,6 +140,7 @@ fn scaffold_manifest(slug: &str, name: &str) -> Manifest {
triggers: crate::manifest::ManifestTriggers::default(),
secrets: crate::manifest::ManifestSecrets::default(),
vars: std::collections::BTreeMap::new(),
suppress: crate::manifest::ManifestSuppress::default(),
}
}

View File

@@ -64,7 +64,7 @@ fn render_tree(plan: &TreePlanDto, mode: OutputMode) {
let mut table = Table::new(["node", "kind", "op", "resource", "detail"]);
for n in &plan.nodes {
let node = format!("{}:{}", n.kind, n.slug);
let groups: [(&str, &Vec<ChangeDto>); 7] = [
let groups: [(&str, &Vec<ChangeDto>); 8] = [
("script", &n.scripts),
("route", &n.routes),
("trigger", &n.triggers),
@@ -72,6 +72,7 @@ fn render_tree(plan: &TreePlanDto, mode: OutputMode) {
("var", &n.vars),
("extension_point", &n.extension_points),
("collection", &n.collections),
("suppression", &n.suppressions),
];
for (rk, changes) in groups {
for c in changes {
@@ -168,6 +169,8 @@ pub fn build_bundle(manifest: &Manifest, base_dir: &Path) -> Result<Value> {
.into_iter()
.map(|(name, kind)| json!({ "name": name, "kind": kind }))
.collect::<Vec<_>>(),
"suppress_triggers": manifest.suppress.triggers,
"suppress_routes": manifest.suppress.routes,
}))
}
@@ -182,7 +185,7 @@ fn tagged(kind: &str, spec: impl Serialize) -> Result<Value> {
fn render(plan: &PlanDto, mode: OutputMode) {
let mut table = Table::new(["kind", "op", "resource", "detail"]);
let groups: [(&str, &Vec<ChangeDto>); 7] = [
let groups: [(&str, &Vec<ChangeDto>); 8] = [
("script", &plan.scripts),
("route", &plan.routes),
("trigger", &plan.triggers),
@@ -190,6 +193,7 @@ fn render(plan: &PlanDto, mode: OutputMode) {
("var", &plan.vars),
("extension_point", &plan.extension_points),
("collection", &plan.collections),
("suppression", &plan.suppressions),
];
for (kind, changes) in groups {
for c in changes {

View File

@@ -234,6 +234,7 @@ pub async fn run(app_ident: &str, dir: &Path, force: bool, mode: OutputMode) ->
names: secrets.iter().map(|s| s.name.clone()).collect(),
},
vars: manifest_vars,
suppress: crate::manifest::ManifestSuppress::default(),
};
std::fs::write(&manifest_path, manifest.to_toml()?)

View File

@@ -50,6 +50,10 @@ pub struct Manifest {
/// The overlay merges per-env, last-write-wins by key.
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub vars: BTreeMap<String, toml::Value>,
/// `[suppress]` (§11 tail) — per-app opt-out of inherited group templates.
/// App-only; a `[group]` carrying it is rejected in [`Manifest::parse`].
#[serde(default, skip_serializing_if = "ManifestSuppress::is_empty")]
pub suppress: ManifestSuppress,
}
impl Manifest {
@@ -73,6 +77,12 @@ impl Manifest {
// (cron/queue/email) stay app-only — they need per-app state/secrets →
// materialization.
if m.group.is_some() {
if !m.suppress.is_empty() {
anyhow::bail!(
"a [group] cannot declare [suppress] — only an app opts out of \
inherited templates; a group simply doesn't declare the template"
);
}
let t = &m.triggers;
if !t.cron.is_empty() || !t.queue.is_empty() || !t.email.is_empty() {
anyhow::bail!(
@@ -492,6 +502,27 @@ impl ManifestSecrets {
}
}
/// `[suppress]` (§11 tail) — per-app opt-out of inherited group templates.
/// `triggers = [...]` names handler SCRIPTS whose inherited triggers this app
/// declines; `routes = [...]` names PATHS whose inherited route this app
/// declines (404s instead of serving). App-only — a `[group]` carrying
/// `[suppress]` is a hard parse error.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManifestSuppress {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub triggers: Vec<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub routes: Vec<String>,
}
impl ManifestSuppress {
#[must_use]
pub fn is_empty(&self) -> bool {
self.triggers.is_empty() && self.routes.is_empty()
}
}
// ---- serde skip/default helpers ----
fn is_endpoint(kind: &ScriptKind) -> bool {
@@ -584,6 +615,7 @@ mod tests {
("region".to_string(), toml::Value::String("eu".into())),
("max-retries".to_string(), toml::Value::Integer(3)),
]),
suppress: ManifestSuppress::default(),
}
}
@@ -688,6 +720,7 @@ mod tests {
triggers: ManifestTriggers::default(),
secrets: ManifestSecrets::default(),
vars: BTreeMap::new(),
suppress: ManifestSuppress::default(),
};
let text = m.to_toml().unwrap();
assert!(!text.contains("[[scripts]]"), "got:\n{text}");
@@ -749,6 +782,34 @@ mod tests {
);
}
#[test]
fn app_suppress_parses_group_suppress_rejected() {
// §11 tail: an [app] declares [suppress] to opt out of inherited
// templates — script names (triggers) + paths (routes).
let m = Manifest::parse(
"[app]\nslug = \"blog\"\nname = \"Blog\"\n\n\
[suppress]\ntriggers = [\"audit\"]\nroutes = [\"/hello\"]\n",
)
.expect("app [suppress] must parse");
assert_eq!(m.suppress.triggers, ["audit"]);
assert_eq!(m.suppress.routes, ["/hello"]);
// A [group] cannot suppress — it simply wouldn't declare the template.
let err = Manifest::parse(
"[group]\nslug = \"acme\"\nname = \"ACME\"\n\n\
[suppress]\ntriggers = [\"audit\"]\n",
)
.expect_err("group [suppress] is rejected");
assert!(err.to_string().contains("suppress"), "got: {err}");
// An unknown key inside [suppress] is a hard error (deny_unknown_fields).
let typo = "[app]\nslug = \"x\"\nname = \"X\"\n\n[suppress]\ntrigger = [\"a\"]\n";
assert!(
Manifest::parse(typo).is_err(),
"an unknown key in [suppress] must be rejected"
);
}
#[test]
fn group_manifest_parses_and_rejects_app_only_blocks() {
// A [group] node: scripts + vars, no [app].