From a3d9feacc683346c5377ae4cf3603db8c331e860 Mon Sep 17 00:00:00 2001 From: Nusendra Hanggarawan Date: Thu, 29 Oct 2026 10:53:05 +0700 Subject: [PATCH 1/2] fix(templates): drop the stale `icon` field from the render test fixture `cargo test --workspace` has been red on `main` since 72ca33a. One error: error[E0560]: struct `schema::Template` has no field named `icon` --> crates/ployer-templates/src/render_tests.rs:17:9 ac178ed removed `icon` from `schema::Template`. It did not remove the one remaining construction site because that site did not exist on its branch: `render_tests.rs` arrived in b2bbfbf (PR #3), which merged first. Neither PR saw the other. Two things let it through, and both are now written down in DOCUMENTATION.md: 1. ac178ed verified with `cargo check --workspace`, which does not build `#[cfg(test)]` code. The field removal was invisible to it. `cargo test` and `cargo clippy --all-targets` both catch it. 2. CI runs on the PR head, not on the PR merged into `main`, and branches are not required to be up to date. PR #3 and PR #4 were each green and broke `main` together. The fix is the one-line deletion. No behaviour change: `icon` was never read. Also confirms the premise of the report that prompted this change is stale. `ployer-db`'s 72 `from_str` errors were real, but 0f1f6fc already fixed them by renaming the call sites alongside the `ployer-core` constructors; they only reproduce on a checkout behind `origin/main`. Both `ployer-db` and `ployer-api` compile here. Verified on f314846 + this change, SQLX_OFFLINE=true: cargo test --workspace -> 141 passed, 0 failed (ployer-api 53, ployer-core 26, ployer-db 24, ployer-proxy 28, ployer-docker 6, ployer-templates 4) cargo clippy --workspace --all-targets -- -D warnings -> clean (stable) cargo +1.99.1 clippy --workspace --all-targets -- -D warnings -> clean --- DOCUMENTATION.md | 13 +++++++++++++ crates/ployer-templates/src/render_tests.rs | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 70d9fc1..d57afeb 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -111,6 +111,19 @@ why, rather than widening the gate or silencing the lint crate-wide. There are currently six such allows, all `clippy::too_many_arguments` on SQL writers whose arguments are one-per-column. +`cargo check --workspace` is **not** a substitute for either of them. It does not +build `#[cfg(test)]` code, so a struct field removed from a type the tests +construct type-checks clean under `check` and fails under `test`/`--all-targets`. +That is exactly how `ac178ed` (drop the `icon` field) left `main` red: the commit +verified with `cargo check --workspace`, and the only remaining `icon` reference +was in `render_tests.rs`, which `check` never compiled. Use the two commands +above. + +CI runs on the PR head, not on the PR merged into `main`, so two PRs that are +each green can still break `main` together — one removing a field, the other +adding a test that uses it. If your branch has been open across other merges, +rebase onto `main` and re-run the two commands before merging. + `cargo fmt --check` is **not** a gate: the tree predates any formatting discipline and currently has ~325 unformatted hunks spread across nearly every file, so turning it on would either fail immediately or require a tree-wide diff --git a/crates/ployer-templates/src/render_tests.rs b/crates/ployer-templates/src/render_tests.rs index 65ff2f4..9c11e20 100644 --- a/crates/ployer-templates/src/render_tests.rs +++ b/crates/ployer-templates/src/render_tests.rs @@ -14,7 +14,6 @@ fn template_echoing(expr: &str) -> Template { name: "PostgreSQL".to_string(), description: String::new(), category: "database".to_string(), - icon: None, tags: Vec::new(), version: serde_json::Value::String("1.0.0".to_string()), inputs: Vec::new(), From 852355e094acbeef9947f751af6b5ed300718d91 Mon Sep 17 00:00:00 2001 From: Nusendra Hanggarawan Date: Thu, 29 Oct 2026 12:48:03 +0700 Subject: [PATCH 2/2] test(templates): guard the registry's stale `icon` key, and correct the CI note `ac178ed` dropped `icon` from `Template` and `IndexEntry`, but `ployer` and `ployer-website` deploy independently and the published registry still ships the key: all four entries in the live `index.json` carry `"icon"`, and `postgresql.yaml` carries `icon: postgresql.svg` (verified against https://ployer.nusendra.com/templates today). The parser therefore has to keep ignoring it. Adding `#[serde(deny_unknown_fields)]` to either struct would look like tightening and would in fact fail every install on a field nobody reads. Two tests now hold that open. Confirmed to have teeth: with `deny_unknown_fields` added to both structs they fail with unknown field `icon`, expected one of `slug`, `name`, ... and pass without it. Also corrects the CI paragraph this branch added. It claimed CI runs on the PR head; it does not. `actions/checkout@v4` checks out `refs/pull/N/merge`, as the job log for this very PR shows ("HEAD is now at a679483 Merge a3d9fea into f314846"). The real mechanism was staleness plus an absent gate: `ci.yml` did not exist when #3 and #4 merged twelve seconds apart off the same base, and `main` has no branch protection at all, so nothing required a re-run against the moved base. The replacement paragraph documents that instead. --- DOCUMENTATION.md | 44 ++++++++++-- crates/ployer-templates/src/schema.rs | 4 ++ crates/ployer-templates/src/schema_tests.rs | 75 +++++++++++++++++++++ 3 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 crates/ployer-templates/src/schema_tests.rs diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index d57afeb..f33ca80 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -119,10 +119,46 @@ verified with `cargo check --workspace`, and the only remaining `icon` reference was in `render_tests.rs`, which `check` never compiled. Use the two commands above. -CI runs on the PR head, not on the PR merged into `main`, so two PRs that are -each green can still break `main` together — one removing a field, the other -adding a test that uses it. If your branch has been open across other merges, -rebase onto `main` and re-run the two commands before merging. +### A green PR is not a green `main` + +Two PRs that are each green can still break `main` together — one removing a +field, the other adding a test that uses it. That is what happened here, and the +mechanism is worth knowing because the gate alone does not close it. + +CI *does* test the merge result, not the branch tip: on a `pull_request` event +`actions/checkout@v4` checks out `refs/pull/N/merge`. From the job log of the +run that validated this very fix: + +``` +git checkout --progress --force refs/remotes/pull/7/merge +HEAD is now at a679483 Merge a3d9fea... into f314846... +``` + +The catch is that this merge commit is a *snapshot*, recomputed when the PR +changes but not re-tested when `main` moves underneath it. PRs #3 and #4 both +declared base `6777b2c` and were merged twelve seconds apart; #4's green run had +been computed against a `main` that did not yet contain #3's new test file. No +job ever compiled the two together. + +Nothing stopped that merge because `main` has no branch protection +(`GET /repos/nusendra/ployer/branches/main/protection` → 404, "Branch not +protected"): no required status check, and no *Require branches to be up to date +before merging*, which is the setting that would have forced #4 to re-run +against the new base. Until that is enabled, the check is advisory. + +So: if your branch has been open across other merges, rebase onto `main` and +re-run the two commands above before merging. A green tick from a run that +predates the current `main` is not evidence about the `main` you are about to +create. + +Two further notes from the same incident, both still true: + +- `ci.yml` did not exist when #3 and #4 merged — it arrived eleven minutes later + in #6. The first run it ever did on `main` (push `f314846`) failed both jobs on + this exact error, and `main` stayed red for eighteen hours. A gate nobody reads + is not a gate. +- `--all-targets` is what makes clippy catch this class of break. The clippy job + failed here for the same reason the test job did. `cargo fmt --check` is **not** a gate: the tree predates any formatting discipline and currently has ~325 unformatted hunks spread across nearly every diff --git a/crates/ployer-templates/src/schema.rs b/crates/ployer-templates/src/schema.rs index c77787b..949cd3f 100644 --- a/crates/ployer-templates/src/schema.rs +++ b/crates/ployer-templates/src/schema.rs @@ -103,3 +103,7 @@ pub struct OutputItem { pub label: String, pub value: String, } + +#[cfg(test)] +#[path = "schema_tests.rs"] +mod tests; diff --git a/crates/ployer-templates/src/schema_tests.rs b/crates/ployer-templates/src/schema_tests.rs new file mode 100644 index 0000000..d911082 --- /dev/null +++ b/crates/ployer-templates/src/schema_tests.rs @@ -0,0 +1,75 @@ +use super::*; + +// --------------------------------------------------------------------------- +// Cross-repo compatibility: the removed `icon` key +// +// `icon` was dropped from `Template` and `IndexEntry` in ac178ed, but +// `ployer` (this binary) and `ployer-website` (which generates and serves the +// registry) deploy independently. The published catalog still ships the key on +// every entry, so the parser has to keep ignoring it. +// +// Verified against the live registry on 2026-10-29: +// +// $ curl -s https://ployer.nusendra.com/templates/index.json | grep -c '"icon"' +// 4 # jellyfin, mariadb, mongodb, postgresql +// $ curl -s https://ployer.nusendra.com/templates/postgresql.yaml | grep icon +// icon: postgresql.svg +// +// These two tests exist to fail loudly if anyone adds +// `#[serde(deny_unknown_fields)]` to either struct. That attribute looks like +// tightening; here it would make every install fail on a field nobody reads. +// --------------------------------------------------------------------------- + +/// The index is fetched before anything else, so a strict parser here breaks +/// the catalog listing outright — no template is installable. +#[test] +fn an_index_entry_carrying_the_removed_icon_key_still_parses() { + // Shape copied from the live index.json, trimmed to one entry. + let json = r#"{ + "schema_version": 1, + "generated_at": "2026-10-29T04:56:52.749Z", + "templates": [{ + "slug": "postgresql", + "name": "PostgreSQL", + "description": "Object-relational database with strong SQL standards compliance.", + "category": "database", + "icon": "postgresql.svg", + "tags": ["database", "sql", "postgres"], + "version": 1, + "sha256": "00", + "url": "https://ployer.nusendra.com/templates/postgresql.yaml" + }] + }"#; + + let index: RegistryIndex = + serde_json::from_str(json).expect("a stale `icon` key must not break index parsing"); + + assert_eq!(index.templates[0].slug, "postgresql"); + assert_eq!(index.templates[0].tags, ["database", "sql", "postgres"]); +} + +/// Same guarantee one level down: the template YAML served from the registry +/// still declares `icon:`, so `Template` must ignore it too. +#[test] +fn a_template_carrying_the_removed_icon_key_still_parses() { + // Shape copied from the live postgresql.yaml, trimmed to the required keys. + let yaml = r#" +slug: postgresql +name: PostgreSQL +description: Object-relational database with strong SQL standards compliance. +category: database +icon: postgresql.svg +tags: [database, sql, postgres] +version: 1 +compose: | + services: + postgresql: + image: postgres:17-alpine +"#; + + let t: Template = + serde_yaml::from_str(yaml).expect("a stale `icon:` must not break template parsing"); + + assert_eq!(t.slug, "postgresql"); + assert!(t.compose.contains("image: postgres:17-alpine")); +}