use serde_yaml::Value;
fn workflow_path() -> std::path::PathBuf {
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(".github/workflows/docs.yml")
}
fn workflow() -> Value {
let raw = std::fs::read_to_string(workflow_path()).expect("read docs.yml");
serde_yaml::from_str(&raw).expect("docs.yml must be valid YAML")
}
fn push_trigger_from(doc: &Value) -> serde_yaml::Mapping {
let on = doc
.get("on")
.or_else(|| doc.get("true")) .expect("`on:` must declare an `on:` block");
let push = on
.get("push")
.unwrap_or_else(|| panic!("`on:` must declare a `push` event; got {on:?}"));
let mapping = push
.as_mapping()
.unwrap_or_else(|| panic!("`on.push` must be a mapping, got {push:?}"));
for key in mapping.keys() {
let name = key.as_str().unwrap_or("<non-string key>");
assert!(
matches!(
name,
"branches" | "branches-ignore" | "paths" | "paths-ignore" | "tags" | "tags-ignore"
),
"unknown `on.push` key `{name}` — the gate cannot prove it is harmless, so it \
refuses to pass. Add it to the whitelist with a reason."
);
}
assert!(
!mapping.contains_key("paths-ignore"),
"`on.push.paths-ignore` silently narrows or inverts the trigger; remove it"
);
assert!(
!mapping.contains_key("branches-ignore"),
"`on.push.branches-ignore` is not part of this deploy contract"
);
let branches = mapping
.get("branches")
.unwrap_or_else(|| panic!("`on.push.branches` is required (must include `master`)"));
let list: Vec<&str> = branches
.as_sequence()
.unwrap_or_else(|| panic!("`on.push.branches` must be a list, got {branches:?}"))
.iter()
.filter_map(|b| b.as_str())
.collect();
assert!(
list.contains(&"master"),
"`on.push.branches` must include `master` (the trunk this repo deploys from); got {list:?}"
);
mapping.clone()
}
fn push_trigger() -> serde_yaml::Mapping {
push_trigger_from(&workflow())
}
fn deploy_triggers() -> Vec<String> {
let push = push_trigger();
let paths = push
.get("paths")
.unwrap_or_else(|| panic!("`on.push.paths` is required; the deploy would never fire"));
let list = paths
.as_sequence()
.unwrap_or_else(|| panic!("`on.push.paths` must be a list, got {paths:?}"));
let triggers: Vec<String> = list
.iter()
.map(|p| {
p.as_str()
.unwrap_or_else(|| panic!("every `paths` entry must be a string, got {p:?}"))
.to_string()
})
.collect();
assert!(!triggers.is_empty(), "`on.push.paths` must not be empty");
triggers
}
const REQUIRED: &[(&str, &str)] = &[
("docs/**", "content, SUMMARY, site config, logo"),
(
"src/**",
"renderer, site builder, embedded JS/assets (incl. the .ts sources of the embedded runtime)",
),
(
"tools/**",
"the compiler that emits the embedded runtime .js from its .ts sources",
),
(
"styles/**",
"scss!-embedded chrome (legacy lane inlines it)",
),
(
"packages/webui/src/**",
"shell components + hydration entry",
),
("packages/webui/scripts/**", "the Node SSR renderer"),
("packages/webui/package.json", "dependency constraints"),
(
"packages/webui/pnpm-workspace.yaml",
"release-age settings decide WHICH hikari ships",
),
(
"packages/webui/vite.config.ts",
"outDir, the /assets/docs/ base, the SSR entry",
),
("Cargo.toml", "crate deps / features"),
("LICENSE", "copied into the output by copy_root_assets"),
(".github/workflows/docs.yml", "this workflow itself"),
];
#[test]
fn deploy_triggers_cover_every_input_that_changes_the_shipped_site() {
let triggers = deploy_triggers();
for (required, why) in REQUIRED {
assert!(
triggers.iter().any(|t| t == required),
"docs.yml push paths must include `{required}` ({why}) — a change there \
ships different bytes but would not redeploy. Parsed: {triggers:?}"
);
}
}
#[test]
fn deploy_triggers_never_list_an_untracked_path() {
let triggers = deploy_triggers();
assert!(
!triggers.iter().any(|t| t.contains("pnpm-lock")),
"packages/webui/pnpm-lock.yaml is gitignored (packages/webui/.gitignore) \
and never tracked, so it can never produce a tracked-diff event; do not \
list it as a deploy trigger. Parsed: {triggers:?}"
);
let ignored = std::process::Command::new("git")
.args(["check-ignore", "-q", "packages/webui/pnpm-lock.yaml"])
.current_dir(env!("CARGO_MANIFEST_DIR"))
.status();
if let Ok(status) = ignored {
if status.code().is_some() {
assert!(
status.success(),
"packages/webui/pnpm-lock.yaml is no longer gitignored — it is \
now tracked and can trigger deploys, so revisit the trigger \
list and the --no-frozen-lockfile choice"
);
}
}
}
#[test]
fn the_parser_reads_only_the_push_event() {
let decoy: Value = serde_yaml::from_str(
"on:\n pull_request:\n branches: [master]\n paths:\n - 'docs/**'\n push:\n branches: [master]\n paths:\n - 'src/**'\n",
)
.unwrap();
let mapping = push_trigger_from(&decoy);
let push_paths: Vec<&str> = mapping["paths"]
.as_sequence()
.unwrap()
.iter()
.filter_map(|p| p.as_str())
.collect();
assert_eq!(
push_paths,
vec!["src/**"],
"the contract must read push.paths, never the first `paths:` in the file"
);
}