Files
PiCloud/crates/picloud-cli/tests/suppress.rs
MechaCat02 3df37b2b85 docs(suppress): flag advisory-by-default trust model; test dangling-suppress warning (§11 tail review)
Two review findings.

1. Per-app opt-out changes the group-template guarantee from "runs on every
   descendant" to "runs unless the descendant declines" — a footgun for
   compliance hooks (an audit/security trigger a tenant can silently opt out
   of). There is no non-suppressible flag. Document this in design §4.5 +
   CLAUDE.md, and record the deferred mitigation: a `sealed`/`mandatory`
   group-template marker the trigger anti-join + route filter skip (cheap —
   both filters are centralized).

2. The dangling-suppress warning path had no coverage. The suppress journey
   now applies a `[suppress] triggers=["does-not-exist"]`, asserts the apply
   still succeeds and the report warns "no effect".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 18:59:20 +02:00

204 lines
6.9 KiB
Rust

//! §11 tail — per-app opt-out of inherited group templates, end to end via
//! `pic`. A group declares a `[[routes]]` template; a descendant app applies a
//! `[suppress] routes=[...]` block → the inherited path stops serving (verified
//! via `routes match` against the live RouteTable), `pic suppress ls --app`
//! shows it, re-apply is a NoOp; a sibling app still serves it; pruning the
//! `[suppress]` block re-inherits the route.
//!
//! The trigger-side filter + the isolation (sibling unaffected, own-trigger
//! still fires) are pinned deterministically at the repo layer by
//! `manager-core/tests/template_suppression.rs`; this journey exercises the
//! authoring + the orchestrator dispatch path the operator uses.
use std::fs;
use tempfile::TempDir;
use crate::common;
use crate::common::cleanup::{AppGuard, GroupGuard, ScriptGuard};
fn manifest_dir() -> TempDir {
let dir = TempDir::new().expect("tempdir");
fs::create_dir_all(dir.path().join("scripts")).expect("scripts dir");
dir
}
fn group_script_id(env: &common::TestEnv, group: &str, name: &str) -> String {
let ls = common::pic_as(env)
.args(["scripts", "ls", "--group", group])
.output()
.expect("scripts ls");
let table = String::from_utf8(ls.stdout).unwrap();
table
.lines()
.map(common::cells)
.find(|c| c.get(2) == Some(&name))
.and_then(|c| c.first().map(|s| (*s).to_string()))
.unwrap_or_else(|| panic!("group script `{name}` not found:\n{table}"))
}
fn route_matches(env: &common::TestEnv, app: &str, url: &str) -> bool {
let out = common::pic_as(env)
.args(["routes", "match", "--app", app, url])
.output()
.expect("routes match");
let stdout = String::from_utf8(out.stdout).unwrap();
stdout.contains("matched") && stdout.contains("true")
}
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
#[test]
fn app_suppresses_inherited_route_template() {
let Some(fx) = common::fixture_or_skip() else {
return;
};
let env = common::admin_env(fx);
let group = common::unique_slug("sup-grp");
let _g = GroupGuard::new(&env.url, &env.token, &group);
common::pic_as(&env)
.args(["groups", "create", &group])
.assert()
.success();
// Group handler + a route template binding it.
let dir = manifest_dir();
fs::write(
dir.path().join("scripts/ghello.rhai"),
r#"log::info("group route"); "ok""#,
)
.unwrap();
common::pic_as(&env)
.args(["scripts", "deploy"])
.arg(dir.path().join("scripts/ghello.rhai"))
.args(["--group", &group, "--name", "ghello"])
.assert()
.success();
let _gs = ScriptGuard::new(
&env.url,
&env.token,
&group_script_id(&env, &group, "ghello"),
);
let gmanifest = format!(
"[group]\nslug = \"{group}\"\nname = \"SupG\"\n\n\
[[routes]]\nscript = \"ghello\"\npath = \"/ghello\"\npath_kind = \"exact\"\n\
host_kind = \"any\"\n"
);
let gpath = dir.path().join("group.toml");
fs::write(&gpath, &gmanifest).unwrap();
common::pic_as(&env)
.args(["apply", "--file"])
.arg(&gpath)
.assert()
.success();
// Two descendant apps: `blog` will suppress, `shop` will not.
let blog = common::unique_slug("sup-blog");
let shop = common::unique_slug("sup-shop");
let _ba = AppGuard::new(&env.url, &env.token, &blog);
let _sa = AppGuard::new(&env.url, &env.token, &shop);
for app in [&blog, &shop] {
common::pic_as(&env)
.args(["apps", "create", app, "--group", &group])
.assert()
.success();
}
// Both inherit the template initially.
assert!(route_matches(&env, &blog, "http://localhost/ghello"));
assert!(route_matches(&env, &shop, "http://localhost/ghello"));
// blog applies a [suppress] block declining /ghello.
let amanifest = format!(
"[app]\nslug = \"{blog}\"\nname = \"Blog\"\n\n\
[suppress]\nroutes = [\"/ghello\"]\n"
);
let apath = dir.path().join("app.toml");
fs::write(&apath, &amanifest).unwrap();
let out = common::pic_as(&env)
.args(["apply", "--file"])
.arg(&apath)
.output()
.expect("apply blog");
assert!(out.status.success(), "blog apply failed: {out:?}");
// blog no longer serves /ghello; shop still does (per-app boundary).
assert!(
!route_matches(&env, &blog, "http://localhost/ghello"),
"the suppressing app must stop serving the inherited route"
);
assert!(
route_matches(&env, &shop, "http://localhost/ghello"),
"a sibling app that did not suppress must still serve it"
);
// `pic suppress ls --app` shows the marker.
let ls = String::from_utf8(
common::pic_as(&env)
.args(["suppress", "ls", "--app", &blog])
.output()
.unwrap()
.stdout,
)
.unwrap();
assert!(
ls.contains("route") && ls.contains("/ghello"),
"suppress ls should list the route suppression:\n{ls}"
);
// Re-apply is a NoOp (marker already present).
let report = String::from_utf8(
common::pic_as(&env)
.args(["apply", "--file"])
.arg(&apath)
.output()
.unwrap()
.stdout,
)
.unwrap();
assert!(
report.contains("suppressions") && report.contains("+0"),
"re-apply should not create a second suppression:\n{report}"
);
// A suppress reference matching NO inherited template is a soft warning
// (typo guard), not an error — the apply still succeeds.
let dangling = format!(
"[app]\nslug = \"{blog}\"\nname = \"Blog\"\n\n\
[suppress]\nroutes = [\"/ghello\"]\ntriggers = [\"does-not-exist\"]\n"
);
fs::write(&apath, &dangling).unwrap();
let out = common::pic_as(&env)
.args(["apply", "--file"])
.arg(&apath)
.output()
.expect("apply dangling");
assert!(
out.status.success(),
"a dangling suppress must not fail apply"
);
let combined = format!(
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
assert!(
combined.contains("does-not-exist") && combined.to_lowercase().contains("no effect"),
"a dangling suppress must warn that it matches no inherited template:\n{combined}"
);
// Drop the [suppress] block + prune → blog re-inherits the route.
let bare = format!("[app]\nslug = \"{blog}\"\nname = \"Blog\"\n");
fs::write(&apath, &bare).unwrap();
common::pic_as(&env)
.args(["apply", "--file"])
.arg(&apath)
.args(["--prune", "--yes"])
.assert()
.success();
assert!(
route_matches(&env, &blog, "http://localhost/ghello"),
"pruning the suppression must re-inherit the route"
);
}