use std::collections::BTreeSet;
use std::fs;
use std::path::PathBuf;
const BUILD_WORKFLOW: &str = "build.yml";
const DELIVERY_WORKFLOW: &str = "delivery.yml";
const REQUIRED_CHECK: &str = "Wire compat";
const AGGREGATED_HALVES: [&str; 2] = ["wire-compat-rust", "wire-compat-js"];
const WIRE_FILTER: [&str; 7] = [
"pg-core/**",
"pg-wasm/**",
"pg-compat/**",
"pg-compat-js/**",
"Cargo.lock",
"Cargo.toml",
".github/workflows/build.yml",
];
const SEMVER_FILTER: [&str; 7] = [
"pg-core/**",
"pg-wasm/**",
"Cargo.toml",
"Cargo.lock",
"scripts/semver-checks.sh",
"scripts/semver-checks-test.sh",
".github/workflows/build.yml",
];
const SEAL_COMMAND: &str = "cargo run --locked -p pg-core --features stream --example seal-samples";
const CHANGELOG_COVERAGE_REPORT_COMMAND: &str = "scripts/changelog-coverage-report.sh";
const REPORTING_LOOP_MARKERS: [&str; 2] = ["gh issue create", "existing_titles"];
const WASM_PUBLISH_VERSION_COMMAND: &str =
r#"npm version "${{ needs.release-plz-release.outputs.pg_core_version }}""#;
const CHANGELOG_COVERAGE_TEST_COMMAND: &str = "scripts/changelog-coverage-test.sh";
const CHANGELOG_COVERAGE_REPORT_TEST_COMMAND: &str = "scripts/changelog-coverage-report-test.sh";
const RULESET_DRIFT_REPORT_COMMAND: &str = "scripts/ruleset-drift-report.sh";
const RULESET_DRIFT_REPORT_TEST_COMMAND: &str = "scripts/ruleset-drift-report-test.sh";
const WASM_ASSEMBLE_MANIFEST_HEREDOC_MARKER: &str = "const pkg = {";
const WASM_ASSEMBLE_COPY_MANIFEST: &str = "cp ../package.json package.json";
const WASM_ASSEMBLE_COPY_README: &str = "cp ../README.md README.md";
const WASM_PACKAGE_CHECK_COMMAND: &str = "scripts/wasm-package-check.sh pg-wasm/pkg";
const WASM_PACKAGE_CHECK_TEST_COMMAND: &str = "scripts/wasm-package-check-test.sh";
const MAP_BUDGET_TEST_COMMAND: &str = "scripts/map-budget-test.sh";
const CHANGED_PATHS_TEST_COMMAND: &str = "scripts/changed-paths-test.sh";
const WASM_BROWSER_TEST_RUN_COMMAND: &str =
"run: wasm-pack test --release --headless --${{ matrix.browser }} ./pg-wasm";
const WASM_BROWSER_TEST_BACKSLASH_MARKER: &str = "--\\${{ matrix.browser }}";
const WASM_BROWSER_MATRIX: [&str; 3] = ["chrome", "firefox", "safari"];
const OPEN_COMMAND: &str = "cargo test --manifest-path pg-compat/Cargo.toml --locked";
const GATE_CONDITION: &str = "steps.gate.outputs.run == 'true'";
const PUSH_OVERRIDE: &str = r#""$GITHUB_EVENT_NAME" == "push""#;
const SEALED_OUTPUT: &str = "needs.wire-compat-rust.outputs.sealed == 'success'";
const PULL_REQUEST_TYPES: [&str; 4] = ["opened", "synchronize", "reopened", "edited"];
fn workflow_path(file: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join(".github/workflows")
.join(file)
}
fn workflow(file: &str) -> String {
let path = workflow_path(file);
fs::read_to_string(&path)
.unwrap_or_else(|e| panic!("read {}: {e}", path.display()))
.replace("\r\n", "\n")
}
fn job(workflow: &str, id: &str, file: &str) -> String {
let body = workflow
.split_once("\njobs:\n")
.unwrap_or_else(|| panic!("no top-level `jobs:` in {}", workflow_path(file).display()))
.1;
let needle = format!(" {id}:");
let mut lines = body.lines().skip_while(|line| line.trim_end() != needle);
assert!(
lines.next().is_some(),
"{} has no job `{id}:`, so whatever this test asserts about it is vacuous",
workflow_path(file).display(),
);
lines
.take_while(|line| line.trim().is_empty() || line.starts_with(" "))
.collect::<Vec<_>>()
.join("\n")
}
fn job_ids(workflow: &str) -> Vec<String> {
let body = workflow
.split_once("\njobs:\n")
.expect("no top-level `jobs:`")
.1;
body.lines()
.filter_map(|line| {
let rest = line.strip_prefix(" ")?;
if rest.starts_with(char::is_whitespace) || rest.starts_with('#') {
return None;
}
rest.strip_suffix(':').map(str::to_owned)
})
.collect()
}
fn field(job: &str, key: &str) -> Option<String> {
let needle = format!("{key}:");
job.lines()
.filter_map(|line| line.strip_prefix(" "))
.filter(|rest| !rest.starts_with(char::is_whitespace) && !rest.starts_with('-'))
.find_map(|rest| rest.strip_prefix(&needle))
.map(|value| value.trim().to_owned())
}
fn steps(job: &str) -> Vec<String> {
let mut steps: Vec<String> = Vec::new();
for line in job.lines().skip_while(|line| line.trim() != "steps:") {
if line.starts_with(" - ") {
steps.push(String::new());
}
if let Some(step) = steps.last_mut() {
step.push_str(line);
step.push('\n');
}
}
steps
}
fn step_with<'a>(steps: &'a [String], needle: &str, file: &str) -> &'a str {
let found: Vec<&String> = steps.iter().filter(|step| step.contains(needle)).collect();
assert_eq!(
found.len(),
1,
"expected exactly one step containing {needle:?} in {}, found {}",
workflow_path(file).display(),
found.len(),
);
found[0]
}
fn filter_paths(job: &str) -> BTreeSet<String> {
let mut lines = job.lines().skip_while(|line| line.trim() != "FILTERS: |");
let header = lines.next().expect("no `FILTERS: |` block in the job");
let indent = header.len() - header.trim_start().len();
lines
.take_while(|line| line.trim().is_empty() || line.len() - line.trim_start().len() > indent)
.map(str::trim)
.filter_map(|line| line.strip_prefix("- "))
.map(|path| path.trim_matches('\'').to_owned())
.collect()
}
fn expected(paths: &[&str]) -> BTreeSet<String> {
paths.iter().map(|p| (*p).to_owned()).collect()
}
#[test]
fn the_required_check_name_still_names_the_aggregator() {
let workflow = workflow(BUILD_WORKFLOW);
let named: Vec<String> = job_ids(&workflow)
.into_iter()
.filter(|id| {
field(&job(&workflow, id, BUILD_WORKFLOW), "name").as_deref() == Some(REQUIRED_CHECK)
})
.collect();
assert_eq!(
named.len(),
1,
"the `main: required checks` ruleset (bypass_actors: []) requires the context \
{REQUIRED_CHECK:?}, and {} jobs in {} carry that name: {named:?}. A ruleset \
requiring a context no job produces blocks nothing, so renaming this job disarms \
the gate instead of breaking it -- rename the ruleset's context in the same change \
(`gh api repos/privacybydesign/postguard/rules/branches/main`).",
named.len(),
workflow_path(BUILD_WORKFLOW).display(),
);
let aggregator = job(&workflow, &named[0], BUILD_WORKFLOW);
let needs: BTreeSet<String> = field(&aggregator, "needs")
.expect("the aggregator has no `needs:`")
.trim_matches(['[', ']'].as_slice())
.split(',')
.map(|need| need.trim().to_owned())
.collect();
assert_eq!(
needs,
expected(&AGGREGATED_HALVES),
"the job named {REQUIRED_CHECK:?} does not aggregate both halves of the wire gate, \
so the repo's sole required check would go green on a run where one half never \
passed",
);
assert_eq!(
field(&aggregator, "if").as_deref(),
Some("${{ !cancelled() }}"),
"the job named {REQUIRED_CHECK:?} must run even when an upstream half failed, or a \
red half leaves the required check pending instead of failing it",
);
for half in AGGREGATED_HALVES {
assert!(
aggregator.contains(&format!(r#""${{{{ needs.{half}.result }}}}" != "success""#)),
"the job named {REQUIRED_CHECK:?} never reads `{half}`'s result, so it reports \
success however that half ended",
);
}
assert!(
aggregator.contains("exit 1"),
"the job named {REQUIRED_CHECK:?} reads both halves' results and then exits zero \
regardless, so the repo's sole required check can never go red",
);
}
#[test]
fn a_retitled_or_retargeted_pr_still_re_runs_the_gates() {
let workflow = workflow(BUILD_WORKFLOW);
let triggers = workflow
.split_once("\njobs:\n")
.expect("no top-level `jobs:`")
.0;
let types: BTreeSet<String> = triggers
.lines()
.map(str::trim)
.find_map(|line| line.strip_prefix("types:"))
.expect("the `pull_request` trigger declares no `types:`")
.trim()
.trim_matches(['[', ']'].as_slice())
.split(',')
.map(|kind| kind.trim().to_owned())
.collect();
assert_eq!(
types,
expected(&PULL_REQUEST_TYPES),
"the `pull_request` trigger no longer re-runs on the events these gates' verdicts \
depend on. `edited` is the one that is not a default: without it a retitle leaves \
the semver gate's verdict attached to the title it was computed from, and a base \
retarget leaves the path filter's attached to the old base",
);
}
#[test]
fn the_rust_wire_gate_still_seals_and_opens_what_it_claims_to() {
let job = job(
&workflow(BUILD_WORKFLOW),
"wire-compat-rust",
BUILD_WORKFLOW,
);
let steps = steps(&job);
assert_eq!(
filter_paths(&job),
expected(&WIRE_FILTER),
"wire-compat-rust's path filter and this test disagree about what can change the \
sealed bytes. A path dropped here does not fail the gate, it silently stops it \
firing; if the filter was widened on purpose, widen WIRE_FILTER with it",
);
let gate = step_with(&steps, "id: gate", BUILD_WORKFLOW);
assert!(
gate.contains(PUSH_OVERRIDE),
"wire-compat-rust's gate step no longer bypasses the path filter on `push`. On a \
push the filter diffs only the push that triggered it, so a commit that reached \
`main` without this gate running is never re-checked -- and the job still reports \
green, because \"filter said no\" and \"gate passed\" are the same success (#299)",
);
let seal = step_with(&steps, "id: seal", BUILD_WORKFLOW);
assert!(
seal.contains(SEAL_COMMAND),
"wire-compat-rust does not seal with `{SEAL_COMMAND}`, so the bytes the published \
readers open are not the ones this tree produces",
);
assert!(
seal.contains(GATE_CONDITION),
"wire-compat-rust's seal step is not behind `{GATE_CONDITION}`, so it no longer \
shares one decision with the open step and the `push` override can be applied to \
one and forgotten on the other",
);
let open = step_with(&steps, OPEN_COMMAND, BUILD_WORKFLOW);
assert!(
open.contains(GATE_CONDITION),
"wire-compat-rust's open step is not behind `{GATE_CONDITION}`, so it no longer \
shares one decision with the seal step",
);
assert!(
job.contains("sealed: ${{ steps.seal.outcome }}"),
"wire-compat-rust no longer publishes `sealed` from the seal step's outcome, which is \
the only thing wire-compat-js gates on -- without it the Node half runs on nothing, \
or not at all",
);
}
#[test]
fn the_js_wire_gate_still_opens_the_bytes_the_rust_half_sealed() {
let job = job(&workflow(BUILD_WORKFLOW), "wire-compat-js", BUILD_WORKFLOW);
let steps = steps(&job);
assert_eq!(
field(&job, "needs").as_deref(),
Some("wire-compat-rust"),
"wire-compat-js no longer depends on wire-compat-rust, so it cannot be holding both \
readers to the same bytes",
);
assert_eq!(
field(&job, "if").as_deref(),
Some("${{ !cancelled() }}"),
"wire-compat-js must still run when the Rust half failed: a red seal is exactly when \
it is worth knowing whether the JS readers broke the same way, and the artifact is \
uploaded before that job's read step for this reason",
);
let download = step_with(&steps, "actions/download-artifact", BUILD_WORKFLOW);
assert!(
download.contains(SEALED_OUTPUT),
"wire-compat-js's download is not gated on `{SEALED_OUTPUT}`, so it no longer keys \
off the same outcome the seal did and the two halves can drift over whether to run",
);
let install = step_with(&steps, "run: npm ci", BUILD_WORKFLOW);
assert!(
install.contains("working-directory: pg-compat-js"),
"wire-compat-js no longer installs the pinned readers with `npm ci` in pg-compat-js, \
so the gate measures whatever npm resolves rather than the declared support window",
);
let open = step_with(&steps, "run: npm test", BUILD_WORKFLOW);
assert!(
open.contains(SEALED_OUTPUT) && open.contains("working-directory: pg-compat-js"),
"wire-compat-js does not run `npm test` in pg-compat-js behind `{SEALED_OUTPUT}`, so \
the published npm readers are not being pointed at the sealed set",
);
}
#[test]
fn the_semver_gate_still_calls_the_script_this_repo_pins() {
let job = job(&workflow(BUILD_WORKFLOW), "semver-checks", BUILD_WORKFLOW);
let steps = steps(&job);
assert_eq!(
filter_paths(&job),
expected(&SEMVER_FILTER),
"semver-checks's path filter and this test disagree about which changes can break a \
published API. A path dropped here silently stops the gate firing; if the filter \
was widened on purpose, widen SEMVER_FILTER with it",
);
step_with(&steps, "./scripts/semver-checks-test.sh", BUILD_WORKFLOW);
let check = step_with(&steps, "./scripts/semver-checks.sh", BUILD_WORKFLOW);
assert!(
check.contains("SEMVER_RELEASE_TYPE: ${{ steps.declared.outputs.release_type }}"),
"semver-checks no longer passes SEMVER_RELEASE_TYPE from the declaration step, so \
either every breaking change fails the gate or none of them do",
);
let declared = step_with(&steps, "id: declared", BUILD_WORKFLOW);
assert!(
declared.contains("PR_TITLE: ${{ github.event.pull_request.title }}"),
"the breaking-change declaration is no longer read off the PR title. It cannot be \
read from the PR body: squash_merge_commit_message is COMMIT_MESSAGES, so the body \
never reaches the commit release-plz reads",
);
assert!(
declared.contains("release_type=major"),
"the declaration step no longer emits `release_type=major`, so the `!` in a PR title \
grants nothing and a declared break fails the gate anyway",
);
}
#[test]
fn the_registry_gate_still_reads_the_ruleset_back() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(&steps, RULESET_DRIFT_REPORT_COMMAND, BUILD_WORKFLOW);
step_with(&steps, "scripts/ruleset-drift-test.sh", BUILD_WORKFLOW);
assert!(
job.contains("actions/checkout"),
"the registry gate no longer checks the repo out, so the script it runs is not there",
);
let aggregator = self::job(&workflow(BUILD_WORKFLOW), "wire-compat", BUILD_WORKFLOW);
assert!(
!aggregator.contains("ruleset-drift"),
"the registry gate has been wired into the sole required check. It reads a live API, \
so an outage there would block every merge; keep it a separate, non-required context",
);
}
#[test]
fn every_job_this_test_reads_is_still_found() {
let workflow = workflow(BUILD_WORKFLOW);
let ids = job_ids(&workflow);
for id in [
"wire-compat-rust",
"wire-compat-js",
"semver-checks",
"wire-compat",
"ruleset-drift",
] {
assert!(
ids.contains(&id.to_owned()),
"{} has no job `{id}`, and this test is what was supposed to notice",
workflow_path(BUILD_WORKFLOW).display(),
);
let body = job(&workflow, id, BUILD_WORKFLOW);
assert!(
field(&body, "name").is_some() && !steps(&body).is_empty(),
"job `{id}` read back as {} lines with no name or no steps, so the reader in \
this file no longer understands {}",
body.lines().count(),
workflow_path(BUILD_WORKFLOW).display(),
);
}
assert_ne!(
job(&workflow, "wire-compat", BUILD_WORKFLOW),
job(&workflow, "wire-compat-rust", BUILD_WORKFLOW),
"the job reader is matching on a prefix, so `wire-compat` and `wire-compat-rust` \
read back as the same block",
);
}
#[test]
fn the_delivery_workflow_still_checks_changelog_coverage() {
let job = job(
&workflow(DELIVERY_WORKFLOW),
"changelog-coverage",
DELIVERY_WORKFLOW,
);
let steps = steps(&job);
let check = step_with(&steps, CHANGELOG_COVERAGE_REPORT_COMMAND, DELIVERY_WORKFLOW);
for marker in REPORTING_LOOP_MARKERS {
assert!(
!check.contains(marker),
"the `changelog-coverage` step contains {marker:?} -- the reporting loop is back \
in the YAML instead of staying inside scripts/changelog-coverage-report.sh, which \
is the defect #429 exists to remove",
);
}
}
#[test]
fn no_workflow_step_captures_dollar_question_mark() {
for file in [BUILD_WORKFLOW, DELIVERY_WORKFLOW] {
let workflow = workflow(file);
for id in job_ids(&workflow) {
let job = job(&workflow, &id, file);
for step in steps(&job) {
assert!(
!step.contains("=$?"),
"job `{id}` in {} has a step that captures `$?`. A `run:` block with no \
`shell:` key executes as `bash -e {{0}}`, so a non-zero exit from the \
command immediately before the capture aborts the step before the capture \
is ever reached -- see #429, which removed the one occurrence this repo \
had (delivery.yml's old inline changelog-coverage loop)",
workflow_path(file).display(),
);
}
}
}
}
#[test]
fn the_wasm_publish_still_takes_its_version_from_pg_core() {
let job = job(
&workflow(DELIVERY_WORKFLOW),
"publish-wasm",
DELIVERY_WORKFLOW,
);
let steps = steps(&job);
let publish = step_with(&steps, "Set version and publish", DELIVERY_WORKFLOW);
assert!(
publish.contains(WASM_PUBLISH_VERSION_COMMAND),
"publish-wasm's `Set version and publish` step no longer sets the npm version from \
`pg_core_version`, so `pg-wasm/CHANGELOG.md`'s pointer to pg-core's changelog is no \
longer true for versions published from here on",
);
}
#[test]
fn the_release_pr_is_opened_with_the_release_app_token() {
let job = job(
&workflow(DELIVERY_WORKFLOW),
"release-plz-pr",
DELIVERY_WORKFLOW,
);
let steps = steps(&job);
let mint = step_with(
&steps,
"actions/create-github-app-token@",
DELIVERY_WORKFLOW,
);
for secret in ["secrets.RELEASE_APP_ID", "secrets.RELEASE_APP_PRIVATE_KEY"] {
assert!(
mint.contains(secret),
"release-plz-pr's App-token step no longer reads `{secret}`",
);
}
assert!(
mint.contains("id: token"),
"the App-token step lost `id: token`, which the release-plz step reads its token from",
);
let run = step_with(&steps, "command: release-pr", DELIVERY_WORKFLOW);
assert!(
run.contains("GITHUB_TOKEN: ${{ steps.token.outputs.token || secrets.GITHUB_TOKEN }}"),
"release-plz-pr no longer gives release-plz the release App's token first, so the \
release PR is opened by GITHUB_TOKEN again",
);
}
#[test]
fn an_image_manifest_is_not_published_past_a_failed_scan() {
let delivery = workflow(DELIVERY_WORKFLOW);
for (finalize, scan) in [
("finalize-docker", "scan-docker"),
("finalize-cryptify", "scan-cryptify"),
] {
let job = job(&delivery, finalize, DELIVERY_WORKFLOW);
let condition = job
.lines()
.map(str::trim)
.find(|line| line.starts_with("if:"))
.unwrap_or_else(|| panic!("{finalize} has no job-level `if:`"));
let gate = format!("needs.{scan}.result == 'success'");
assert!(
condition.contains(&gate),
"{finalize}'s condition is `{condition}`, which does not require `{gate}`: under \
`always()` a failed scan no longer stops the manifest from being published",
);
}
}
#[test]
fn the_wasm_publish_authenticates_by_oidc_and_carries_no_token() {
let job = job(
&workflow(DELIVERY_WORKFLOW),
"publish-wasm",
DELIVERY_WORKFLOW,
);
assert!(
job.lines().any(|line| line.trim() == "id-token: write"),
"publish-wasm no longer has `id-token: write`, so npm cannot get the OIDC token trusted \
publishing exchanges for a publish credential",
);
for token in ["NPM_TOKEN", "NODE_AUTH_TOKEN"] {
assert!(
!job.lines()
.filter(|line| !line.trim_start().starts_with('#'))
.any(|line| line.contains(token)),
"publish-wasm references `{token}`: a long-lived npm token is back, and npm will use \
it instead of the trusted publisher",
);
}
assert!(
!job.lines()
.any(|line| line.trim_start().starts_with("environment:")),
"publish-wasm has an `environment:`; the trusted publisher on npmjs.com is configured \
without one, so the OIDC claim no longer matches and the publish is refused",
);
}
#[test]
fn the_wasm_assemble_step_copies_the_committed_manifest_and_readme() {
let job = job(
&workflow(DELIVERY_WORKFLOW),
"publish-wasm",
DELIVERY_WORKFLOW,
);
let steps = steps(&job);
let assemble = step_with(&steps, "Assemble package", DELIVERY_WORKFLOW);
assert!(
assemble.contains(WASM_ASSEMBLE_COPY_MANIFEST)
&& assemble.contains(WASM_ASSEMBLE_COPY_README),
"publish-wasm's `Assemble package` step no longer copies both the committed \
`pg-wasm/package.json` and `pg-wasm/README.md` into the assembled directory, so the \
published package is still missing whichever copy is gone",
);
assert!(
!assemble.contains(WASM_ASSEMBLE_MANIFEST_HEREDOC_MARKER),
"publish-wasm's `Assemble package` step still writes the manifest from a `node -e` \
heredoc alongside the copy of the committed `pg-wasm/package.json` -- whichever runs \
last silently decides what actually gets published",
);
}
#[test]
fn the_wasm_package_is_checked_before_it_is_published() {
let job = job(
&workflow(DELIVERY_WORKFLOW),
"publish-wasm",
DELIVERY_WORKFLOW,
);
let steps = steps(&job);
step_with(&steps, WASM_PACKAGE_CHECK_COMMAND, DELIVERY_WORKFLOW);
step_with(&steps, "Set version and publish", DELIVERY_WORKFLOW);
let check_pos = steps
.iter()
.position(|step| step.contains(WASM_PACKAGE_CHECK_COMMAND))
.expect("just asserted this step exists");
let publish_pos = steps
.iter()
.position(|step| step.contains("Set version and publish"))
.expect("just asserted this step exists");
assert!(
check_pos < publish_pos,
"publish-wasm runs {WASM_PACKAGE_CHECK_COMMAND:?} at step {check_pos} but publishes at \
step {publish_pos} -- a check that runs after `npm publish` protects nothing",
);
}
#[test]
fn the_changelog_coverage_checkers_self_test_runs_in_ci() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(&steps, CHANGELOG_COVERAGE_TEST_COMMAND, BUILD_WORKFLOW);
let checkout = step_with(&steps, "actions/checkout", BUILD_WORKFLOW);
assert!(
checkout.contains("fetch-depth: 0"),
"ruleset-drift's checkout no longer fetches full history and tags, so \
changelog-coverage-test.sh's fixtures -- real tags in this repo's \
history -- make changelog-coverage.sh report exit 2 (undetermined) \
on every one of them instead of exercising the case",
);
}
#[test]
fn the_changelog_coverage_reporters_self_test_runs_in_ci() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(
&steps,
CHANGELOG_COVERAGE_REPORT_TEST_COMMAND,
BUILD_WORKFLOW,
);
let checkout = step_with(&steps, "actions/checkout", BUILD_WORKFLOW);
assert!(
checkout.contains("fetch-depth: 0"),
"ruleset-drift's checkout no longer fetches full history and tags, so \
changelog-coverage-report-test.sh's fixtures -- real tags in this \
repo's history, driven through the real scripts/changelog-coverage.sh \
-- make it report exit 2 (undetermined) on every one of them instead \
of exercising the case",
);
}
#[test]
fn the_ruleset_drift_gate_files_what_it_finds() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
assert!(
job.contains("issues: write"),
"the `ruleset-drift` job no longer declares `issues: write`, so its reporter's \
`gh issue create` would 403 at the exact moment the gate has something to say",
);
let report = step_with(&steps, RULESET_DRIFT_REPORT_COMMAND, BUILD_WORKFLOW);
assert!(
report
.lines()
.any(|line| line.trim() == format!("run: {RULESET_DRIFT_REPORT_COMMAND}")),
"the `ruleset-drift` job's reporter step is no longer a bare invocation of \
{RULESET_DRIFT_REPORT_COMMAND:?} on its own `run:` line",
);
for marker in REPORTING_LOOP_MARKERS {
assert!(
!report.contains(marker),
"the reporter step contains {marker:?} -- the filing loop has crept back into the \
YAML instead of staying inside {RULESET_DRIFT_REPORT_COMMAND}, the defect this \
gate exists to remove",
);
}
assert!(
report.contains("GH_TOKEN"),
"the reporter step no longer passes `GH_TOKEN`, so both its dedupe read and any \
`gh issue create` it attempts would run unauthenticated against the runner's shared \
60/hour budget",
);
}
#[test]
fn the_ruleset_drift_reporters_self_test_runs_in_ci() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(&steps, RULESET_DRIFT_REPORT_TEST_COMMAND, BUILD_WORKFLOW);
}
#[test]
fn the_wasm_package_checkers_self_test_runs_in_ci() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(&steps, WASM_PACKAGE_CHECK_TEST_COMMAND, BUILD_WORKFLOW);
}
#[test]
fn the_map_budget_checkers_self_test_runs_in_ci() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(&steps, MAP_BUDGET_TEST_COMMAND, BUILD_WORKFLOW);
}
#[test]
fn the_changed_paths_scripts_self_test_runs_in_ci() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(&steps, CHANGED_PATHS_TEST_COMMAND, BUILD_WORKFLOW);
}
#[test]
fn the_wasm_browser_job_has_an_honest_timeout_and_no_retry_wrapper() {
let job = job(
&workflow(BUILD_WORKFLOW),
"test-wasm-browsers",
BUILD_WORKFLOW,
);
assert!(
field(&job, "timeout-minutes").is_some(),
"test-wasm-browsers has no job-level `timeout-minutes`, so a wedged browser session \
runs to GitHub's 6-hour default -- the pre-#416 failure amplified roughly 18x over \
even the retry wrapper's own 20-minute budget",
);
assert!(
!job.contains("uses: nick-fields/retry"),
"test-wasm-browsers still uses `nick-fields/retry`, which re-rolls a genuine test \
failure (`retry_on: error`) but never retries the one failure shape this job has \
actually hit -- a timeout is not `error` in that action's taxonomy, so \
`max_attempts: 2` never engaged on 2026-09-03's three wedged safari runs",
);
let steps = steps(&job);
let run = step_with(&steps, "wasm-pack test", BUILD_WORKFLOW);
assert!(
run.contains(WASM_BROWSER_TEST_RUN_COMMAND),
"test-wasm-browsers no longer runs {WASM_BROWSER_TEST_RUN_COMMAND:?} as a bare `run:` \
step -- either the browser flag changed or the step is wrapped in an action again",
);
assert!(
!run.contains(WASM_BROWSER_TEST_BACKSLASH_MARKER),
"test-wasm-browsers' `wasm-pack test` step still carries the literal backslash from \
build.yml:107 ({WASM_BROWSER_TEST_BACKSLASH_MARKER:?}) -- it only ever worked because \
`nick-fields/retry`'s `command:` input handed the string to a shell that stripped it \
before `wasm-pack` saw it, and a bare `run:` gets no such stripping",
);
for browser in WASM_BROWSER_MATRIX {
assert!(
job.contains(&format!("browser: {browser}")),
"test-wasm-browsers' matrix no longer includes `{browser}` -- #416 decided all \
three browsers stay, `safari` included, the one that actually wedged",
);
}
}
#[test]
fn the_wasm_browser_timeout_is_pinned_above_safaris_observed_tail() {
let job = job(
&workflow(BUILD_WORKFLOW),
"test-wasm-browsers",
BUILD_WORKFLOW,
);
let line = job
.lines()
.find(|line| line.trim_start().starts_with("WASM_BINDGEN_TEST_TIMEOUT:"))
.unwrap_or_else(|| {
panic!(
"test-wasm-browsers sets no `WASM_BINDGEN_TEST_TIMEOUT` in {}",
workflow_path(BUILD_WORKFLOW).display(),
)
});
let value = line
.trim()
.strip_prefix("WASM_BINDGEN_TEST_TIMEOUT:")
.unwrap()
.trim();
assert_eq!(
value, "70",
"test-wasm-browsers' WASM_BINDGEN_TEST_TIMEOUT is {value}, not 70 -- #453 measured \
Safari's green suite at up to 30.9s against a whole-run clock, so a value near that \
duration (30 clipped four real runs) fails intermittently rather than every time, and \
only a check on the literal value catches a later edit drifting it back down",
);
}
#[test]
fn the_dotnet_package_is_packed_from_this_runs_native_libraries() {
let workflow = workflow(DELIVERY_WORKFLOW);
let pack = job(&workflow, "pack-dotnet", DELIVERY_WORKFLOW);
assert_eq!(
field(&pack, "needs").as_deref(),
Some("build-ffi"),
"pack-dotnet no longer takes its native libraries from this run's build-ffi matrix",
);
step_with(&steps(&pack), "scripts/nupkg-check.sh", DELIVERY_WORKFLOW);
let publish = job(&workflow, "publish-dotnet", DELIVERY_WORKFLOW);
let needs = field(&publish, "needs").unwrap_or_default();
assert!(
needs.contains("pack-dotnet") && needs.contains("release-plz-release"),
"publish-dotnet needs {needs:?}; it must publish the package pack-dotnet built in \
this run, on the release release-plz made in this run",
);
for (id, body) in [("pack-dotnet", &pack), ("publish-dotnet", &publish)] {
assert!(
!body.contains("gh release download"),
"{id} downloads a released pg-ffi again instead of using this run's (#256)",
);
}
assert!(
!publish.contains("dotnet pack"),
"publish-dotnet packs a package of its own instead of publishing the one \
pack-dotnet built and checked",
);
}
#[test]
fn the_dotnet_publish_is_held_to_the_pg_core_release() {
let publish = job(
&workflow(DELIVERY_WORKFLOW),
"publish-dotnet",
DELIVERY_WORKFLOW,
);
assert_eq!(
field(&publish, "if").as_deref(),
Some("needs.release-plz-release.outputs.pg_core_version != ''"),
"publish-dotnet no longer runs on exactly the pg-core releases",
);
assert_eq!(
field(&publish, "environment").as_deref(),
Some("nuget"),
"publish-dotnet lost its `environment: nuget`, which the nuget.org \
trusted-publishing policy is scoped to",
);
let steps = steps(&publish);
let check = step_with(&steps, "scripts/nupkg-check.sh", DELIVERY_WORKFLOW);
assert!(
check.contains("needs.release-plz-release.outputs.pg_core_version")
&& check.contains(r#"scripts/nupkg-check.sh "$RUNNER_TEMP/nupkg" "$PG_CORE_VERSION""#),
"publish-dotnet no longer checks the package's version against the pg-core release \
before pushing it",
);
let position = |needle: &str| {
steps
.iter()
.position(|step| step.contains(needle))
.unwrap_or_else(|| panic!("publish-dotnet has no step containing {needle:?}"))
};
assert!(
position("scripts/nupkg-check.sh") < position("dotnet nuget push"),
"publish-dotnet pushes the package before checking it",
);
}
#[test]
fn the_dotnet_lane_tests_against_the_native_library_it_just_built() {
let job = job(&workflow(BUILD_WORKFLOW), "dotnet", BUILD_WORKFLOW);
let steps = steps(&job);
let position = |needle: &str| {
steps
.iter()
.position(|step| step.contains(needle))
.unwrap_or_else(|| panic!("the dotnet job has no step containing {needle:?}"))
};
assert!(
position("pg-ffi/build.sh") < position("dotnet test pg-dotnet/E4A.PostGuard.slnx"),
"the dotnet job must build pg-ffi from this checkout before it runs the .NET tests",
);
}
#[test]
fn the_dotnet_publish_scripts_self_tests_run_in_ci() {
let job = job(&workflow(BUILD_WORKFLOW), "ruleset-drift", BUILD_WORKFLOW);
let steps = steps(&job);
step_with(&steps, "scripts/nuget-login-test.sh", BUILD_WORKFLOW);
step_with(&steps, "scripts/nupkg-check-test.sh", BUILD_WORKFLOW);
}