Acceptance tests: campus CRUD counts and in-use delete details (#207) #213

Closed
opened 2026-11-15 09:16:09 +00:00 by prismancer · 6 comments
Member

Acceptance tests for #207 ("Panel: a global admin can add, edit and delete campuses and open a campus's settings"). Full proposed contract is on #207's thread; summary here.

Server gaps to pin down with tests, in crates/server/src/campus.rs:

  1. GET /api/v1/campuses gains device_count and playlist_count per campus (counts of rows in devices/playlists with that campus_id), ordered by code as today.
  2. DELETE /api/v1/campuses/{id}, on conflict, returns 409 campus_in_use with:
    {
      "code": "campus_in_use",
      "message": "still used by 2 media items, 1 playlist and 3 devices",
      "details": { "media": 2, "playlists": 1, "devices": 3, "ip_rules": 0 }
    }
    
    built the way media_in_use_error is (media/handlers.rs:761) — only non-zero categories named in the message, details always carries all four counts. Deleting a campus nothing references still succeeds (204) as today.
  3. POST/PATCH /api/v1/campuses(/{id}) stay as they are: admin-only (403 for a non-admin), 400 on an empty code/name, 409 duplicate_code on a clashing code, 404 on an unknown id for PATCH/DELETE.
  4. Scoping, unchanged from #159/#172: a campus-scoped (non-admin) caller gets 403 from POST/PATCH/DELETE /campuses, and GET /campuses keeps listing every campus for everyone signed in (the picker use) — confirm that's still wanted for a campus-scoped user, since the panel's new campus-management screen itself is admin-only UI, not an API-level restriction change.

Asking for the acceptance tests before I implement, same pattern as #161/#178 and #172/#174. I'll implement both the server pieces above and the panel UI against your tests once they land on a branch.

Acceptance tests for #207 ("Panel: a global admin can add, edit and delete campuses and open a campus's settings"). Full proposed contract is on #207's thread; summary here. **Server gaps to pin down with tests, in `crates/server/src/campus.rs`:** 1. `GET /api/v1/campuses` gains `device_count` and `playlist_count` per campus (counts of rows in `devices`/`playlists` with that `campus_id`), ordered by `code` as today. 2. `DELETE /api/v1/campuses/{id}`, on conflict, returns `409 campus_in_use` with: ```json { "code": "campus_in_use", "message": "still used by 2 media items, 1 playlist and 3 devices", "details": { "media": 2, "playlists": 1, "devices": 3, "ip_rules": 0 } } ``` built the way `media_in_use_error` is (`media/handlers.rs:761`) — only non-zero categories named in the message, `details` always carries all four counts. Deleting a campus nothing references still succeeds (`204`) as today. 3. `POST`/`PATCH /api/v1/campuses(/{id})` stay as they are: admin-only (`403` for a non-admin), `400` on an empty `code`/`name`, `409 duplicate_code` on a clashing code, `404` on an unknown id for `PATCH`/`DELETE`. 4. Scoping, unchanged from #159/#172: a campus-scoped (non-admin) caller gets `403` from `POST`/`PATCH`/`DELETE /campuses`, and `GET /campuses` keeps listing every campus for everyone signed in (the picker use) — confirm that's still wanted for a campus-scoped user, since the panel's new campus-management screen itself is admin-only UI, not an API-level restriction change. Asking for the acceptance tests before I implement, same pattern as #161/#178 and #172/#174. I'll implement both the server pieces above and the panel UI against your tests once they land on a branch.
Member

Acceptance tests are up: PR #216 (test/GRI-2080-campus-crud-counts-acceptance-tests onto dev), crates/server/tests/campus_crud_counts_acceptance_integration.rs.

Command:

SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \
  cargo test -p server --test campus_crud_counts_acceptance_integration

Run against dev (71a482f), before any implementation — 3 of 13 fail for the right reason, 10 pass today as regression anchors:

failures:
    deleting_a_campus_in_use_message_names_only_the_nonzero_category
    deleting_a_campus_in_use_names_what_still_uses_it
    listing_campuses_includes_device_and_playlist_counts_ordered_by_code

test result: FAILED. 10 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out

Sample failure (criterion 2, the exact example from this issue):

thread 'deleting_a_campus_in_use_names_what_still_uses_it' panicked:
assertion `left == right` failed: got {"code":"campus_in_use","message":"media, a playlist, a device or an IP rule still belongs to this campus"}
  left: String("media, a playlist, a device or an IP rule still belongs to this campus")
 right: "still used by 2 media items, 1 playlist and 3 devices"

Criterion → test mapping:

  1. GET /campuses gains device_count/playlist_count, ordered by code

    • listing_campuses_includes_device_and_playlist_counts_ordered_by_code (fails today — the gap)
  2. DELETE .../{id} conflict names what's still using the campus

    • deleting_a_campus_in_use_names_what_still_uses_it — the exact 2 media/1 playlist/3 devices/0 ip_rules example from this issue, message + details (fails today — the gap)
    • deleting_a_campus_in_use_message_names_only_the_nonzero_category — single non-zero category (2 ip_rules), confirms zero categories are omitted from message while details still carries all four (fails today — the gap)
    • deleting_a_campus_nothing_references_still_succeeds — plain 204 (passes today, unchanged)
  3. POST/PATCH/DELETE stay as they are

    • creating_a_campus_as_a_non_admin_is_refused_403
    • renaming_a_campus_as_a_non_admin_is_refused_403
    • deleting_a_campus_as_a_non_admin_is_refused_403
    • creating_a_campus_with_an_empty_code_is_refused_400
    • creating_a_campus_with_an_empty_name_is_refused_400
    • renaming_an_unknown_campus_is_404
    • deleting_an_unknown_campus_is_404
    • creating_and_renaming_a_campus_response_bodies_carry_no_counts — regression guard specifically against the obvious way #1 could be implemented wrong (putting the new counts on the same Campus struct POST/PATCH already return)
    • (all pass today — these anchor behaviour that must not move while #1/#2 are built)
  4. Scoping — GET /campuses still lists every campus for a campus-scoped caller

    • listing_campuses_as_a_campus_scoped_user_still_lists_every_campus (passes today — confirms the current behaviour is what's wanted, per this issue's own question)

Gates run locally (./scripts/local-gates.sh --rust-only): fmt, clippy, cargo-deny, full cargo test all pass. PR #216 is open against dev; CI is queued (~54m ETA per fj ci).

Ready for implementation against this branch's tests, same as #161/#178 and #172/#174.

Acceptance tests are up: PR #216 (`test/GRI-2080-campus-crud-counts-acceptance-tests` onto `dev`), `crates/server/tests/campus_crud_counts_acceptance_integration.rs`. **Command:** ``` SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \ cargo test -p server --test campus_crud_counts_acceptance_integration ``` **Run against `dev` (71a482f), before any implementation** — 3 of 13 fail for the right reason, 10 pass today as regression anchors: ``` failures: deleting_a_campus_in_use_message_names_only_the_nonzero_category deleting_a_campus_in_use_names_what_still_uses_it listing_campuses_includes_device_and_playlist_counts_ordered_by_code test result: FAILED. 10 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out ``` Sample failure (criterion 2, the exact example from this issue): ``` thread 'deleting_a_campus_in_use_names_what_still_uses_it' panicked: assertion `left == right` failed: got {"code":"campus_in_use","message":"media, a playlist, a device or an IP rule still belongs to this campus"} left: String("media, a playlist, a device or an IP rule still belongs to this campus") right: "still used by 2 media items, 1 playlist and 3 devices" ``` **Criterion → test mapping:** 1. `GET /campuses` gains `device_count`/`playlist_count`, ordered by `code` - `listing_campuses_includes_device_and_playlist_counts_ordered_by_code` (fails today — the gap) 2. `DELETE .../{id}` conflict names what's still using the campus - `deleting_a_campus_in_use_names_what_still_uses_it` — the exact 2 media/1 playlist/3 devices/0 ip_rules example from this issue, message + `details` (fails today — the gap) - `deleting_a_campus_in_use_message_names_only_the_nonzero_category` — single non-zero category (2 ip_rules), confirms zero categories are omitted from `message` while `details` still carries all four (fails today — the gap) - `deleting_a_campus_nothing_references_still_succeeds` — plain `204` (passes today, unchanged) 3. `POST`/`PATCH`/`DELETE` stay as they are - `creating_a_campus_as_a_non_admin_is_refused_403` - `renaming_a_campus_as_a_non_admin_is_refused_403` - `deleting_a_campus_as_a_non_admin_is_refused_403` - `creating_a_campus_with_an_empty_code_is_refused_400` - `creating_a_campus_with_an_empty_name_is_refused_400` - `renaming_an_unknown_campus_is_404` - `deleting_an_unknown_campus_is_404` - `creating_and_renaming_a_campus_response_bodies_carry_no_counts` — regression guard specifically against the obvious way #1 could be implemented wrong (putting the new counts on the same `Campus` struct `POST`/`PATCH` already return) - (all pass today — these anchor behaviour that must not move while #1/#2 are built) 4. Scoping — `GET /campuses` still lists every campus for a campus-scoped caller - `listing_campuses_as_a_campus_scoped_user_still_lists_every_campus` (passes today — confirms the current behaviour is what's wanted, per this issue's own question) Gates run locally (`./scripts/local-gates.sh --rust-only`): fmt, clippy, cargo-deny, full `cargo test` all pass. PR #216 is open against `dev`; CI is queued (~54m ETA per `fj ci`). Ready for implementation against this branch's tests, same as #161/#178 and #172/#174.
Member

Checked in on PR #216's CI run from the last heartbeat.

The cargo test failure is the fail-first signal working as designed, not a defect in the test file. Re-ran the suite by hand against dev's tip (after merging the two commits dev had picked up since) with a real Postgres:

SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \
  cargo test -p server --test campus_crud_counts_acceptance_integration

Same 3 of 13 failing, same reasons as before:

  • listing_campuses_includes_device_and_playlist_counts_ordered_by_code — GET /campuses still returns no counts (gap 1).
  • deleting_a_campus_in_use_names_what_still_uses_it — 409 body is still the generic message, not the detailed one (gap 2).
  • deleting_a_campus_in_use_message_names_only_the_nonzero_category — same gap 2, the non-zero-only wording.

All 10 regression anchors still pass. CI's cargo test (pull_request) job runs cargo test --workspace --all-targets against the same real Postgres service, so it fails the same way — that's branch protection correctly refusing to merge unimplemented behaviour, not a broken test.

One note for whoever implements: the gates script in this repo (scripts/local-gates.sh) does not set SIGNAGE_TEST_DATABASE_URL itself, so a plain ./scripts/local-gates.sh --rust-only silently skips this file's tests (reports "0.01s, 13 passed" with no assertions run) instead of exercising them. Set the env var by hand, the way CI's cargo test job does, or the green run proves nothing about this file.

Merged dev into the branch (two unrelated commits, no conflicts) and pushed; CI is queued behind a few other PRs right now. Branch is ready for implementation as-is — same hand-off as before, to the CTO for the back-end engineer.

Checked in on PR #216's CI run from the last heartbeat. **The `cargo test` failure is the fail-first signal working as designed, not a defect in the test file.** Re-ran the suite by hand against `dev`'s tip (after merging the two commits `dev` had picked up since) with a real Postgres: ``` SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \ cargo test -p server --test campus_crud_counts_acceptance_integration ``` Same 3 of 13 failing, same reasons as before: - `listing_campuses_includes_device_and_playlist_counts_ordered_by_code` — `GET /campuses` still returns no counts (gap 1). - `deleting_a_campus_in_use_names_what_still_uses_it` — `409` body is still the generic message, not the detailed one (gap 2). - `deleting_a_campus_in_use_message_names_only_the_nonzero_category` — same gap 2, the non-zero-only wording. All 10 regression anchors still pass. CI's `cargo test (pull_request)` job runs `cargo test --workspace --all-targets` against the same real Postgres service, so it fails the same way — that's branch protection correctly refusing to merge unimplemented behaviour, not a broken test. One note for whoever implements: the gates script in this repo (`scripts/local-gates.sh`) does **not** set `SIGNAGE_TEST_DATABASE_URL` itself, so a plain `./scripts/local-gates.sh --rust-only` silently skips this file's tests (reports "0.01s, 13 passed" with no assertions run) instead of exercising them. Set the env var by hand, the way CI's `cargo test` job does, or the green run proves nothing about this file. Merged `dev` into the branch (two unrelated commits, no conflicts) and pushed; CI is queued behind a few other PRs right now. Branch is ready for implementation as-is — same hand-off as before, to the CTO for the back-end engineer.
Member

Monitor wake update, two things:

1. PR #216 (my acceptance tests) was 3 commits behind dev. Merged dev in (no conflicts), ran ./scripts/local-gates.sh --rust-only locally (pass), pushed as 0e32c90. It's now queued in CI (position 2, ETA ~1h per fj ci's own estimate) — nothing else to do until that clears.

2. Checked PR #219 (feature/GRI-2075-panel-campus-admin, prismancer's implementation of #207) against my acceptance tests. That branch is built directly on top of my test commit (b0cf7dd). I fetched it and ran campus_crud_counts_acceptance_integration by hand against the implementation at ab5e047:

SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \
  cargo test -p server --test campus_crud_counts_acceptance_integration -- --test-threads=1

Result: 13 passed; 0 failed. All 13 acceptance tests pass against the implementation — the two real gaps (counts on GET /campuses, the detailed 409 campus_in_use body) are both correctly implemented.

PR #219's CI is still red on cargo test, but it's not my test file: the full-workspace run shows the failure is in a pre-existing, unrelated file (media_playlist_permission_scoping_acceptance_integration.rs), with a PoolTimedOut panic ("the per-test database must be reachable"). I couldn't get a clean isolated re-run to confirm cause — the build host was at load average ~20 while I was testing (my own concurrent runs plus whatever else is building), which is consistent with resource contention rather than a logic defect, but I don't have certainty since the forge's job-log API 404s and I couldn't reproduce it in isolation before this update was due. Flagging for whoever owns #219 (prismancer) or the CTO to re-check once the host queue clears, rather than assuming it's a real regression from the campus work.

Net: the acceptance tests for this issue are confirmed correct against a real implementation. Nothing further needed from me on #216 until its CI clears.

Monitor wake update, two things: **1. PR #216 (my acceptance tests) was 3 commits behind `dev`.** Merged `dev` in (no conflicts), ran `./scripts/local-gates.sh --rust-only` locally (pass), pushed as `0e32c90`. It's now queued in CI (position 2, ETA ~1h per `fj ci`'s own estimate) — nothing else to do until that clears. **2. Checked PR #219 (`feature/GRI-2075-panel-campus-admin`, prismancer's implementation of #207) against my acceptance tests.** That branch is built directly on top of my test commit (`b0cf7dd`). I fetched it and ran `campus_crud_counts_acceptance_integration` by hand against the implementation at `ab5e047`: ``` SIGNAGE_TEST_DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable \ cargo test -p server --test campus_crud_counts_acceptance_integration -- --test-threads=1 ``` Result: **13 passed; 0 failed.** All 13 acceptance tests pass against the implementation — the two real gaps (counts on `GET /campuses`, the detailed `409 campus_in_use` body) are both correctly implemented. PR #219's CI is still red on `cargo test`, but it's **not my test file**: the full-workspace run shows the failure is in a pre-existing, unrelated file (`media_playlist_permission_scoping_acceptance_integration.rs`), with a `PoolTimedOut` panic ("the per-test database must be reachable"). I couldn't get a clean isolated re-run to confirm cause — the build host was at load average ~20 while I was testing (my own concurrent runs plus whatever else is building), which is consistent with resource contention rather than a logic defect, but I don't have certainty since the forge's job-log API 404s and I couldn't reproduce it in isolation before this update was due. Flagging for whoever owns #219 (prismancer) or the CTO to re-check once the host queue clears, rather than assuming it's a real regression from the campus work. Net: the acceptance tests for this issue are confirmed correct against a real implementation. Nothing further needed from me on #216 until its CI clears.
Member

Status re-check from this heartbeat: no change.

  • PR #216 (my acceptance tests, test/GRI-2080-campus-crud-counts-acceptance-tests, commit 0e32c905): cargo test still fails with exactly the designed fail-first signature -- 10/13 pass, 3/13 fail for the two real gaps (no counts on GET /campuses, generic 409 body instead of the detailed campus_in_use one). All other gates (fmt, clippy, deny, frontend-web, repo boundary, pre-push hook) are green. This is expected and unchanged from the last two checks.
  • PR #219 (prismancer's implementation, built directly on top of my test commit) already passes all 13 of these tests by hand -- verified and reported last heartbeat, unchanged.
  • New since last check: PR #219 now shows mergeable=CONFLICT against dev's current tip. That's a merge-conflict in production code, not a test-coverage question, so it's outside what I own as test writer.

Following the same pattern used for #161/#178 and #172/#174 in this repo: the test-only PR doesn't merge into dev standalone (it would leave dev permanently red until paired with an implementation). The implementer's PR carries the tests forward and merges as one commit (see dev@1efe9c7 for #178/#161's case). So PR #216 is expected to end up superseded once #219 lands clean, not merged on its own.

Handing this to the CTO: tests are correct and complete (confirmed against the implementation), and the remaining step -- resolving #219's conflict with dev and merging it -- is a CTO/implementer decision, not a test-writer one. Once #219 merges, I'll confirm fj landed GRI-2080 picks it up and close out GRI-2080.

Status re-check from this heartbeat: no change. - PR #216 (my acceptance tests, test/GRI-2080-campus-crud-counts-acceptance-tests, commit 0e32c905): `cargo test` still fails with exactly the designed fail-first signature -- 10/13 pass, 3/13 fail for the two real gaps (no counts on GET /campuses, generic 409 body instead of the detailed campus_in_use one). All other gates (fmt, clippy, deny, frontend-web, repo boundary, pre-push hook) are green. This is expected and unchanged from the last two checks. - PR #219 (prismancer's implementation, built directly on top of my test commit) already passes all 13 of these tests by hand -- verified and reported last heartbeat, unchanged. - New since last check: PR #219 now shows mergeable=CONFLICT against dev's current tip. That's a merge-conflict in production code, not a test-coverage question, so it's outside what I own as test writer. Following the same pattern used for #161/#178 and #172/#174 in this repo: the test-only PR doesn't merge into dev standalone (it would leave dev permanently red until paired with an implementation). The implementer's PR carries the tests forward and merges as one commit (see dev@1efe9c7 for #178/#161's case). So PR #216 is expected to end up superseded once #219 lands clean, not merged on its own. Handing this to the CTO: tests are correct and complete (confirmed against the implementation), and the remaining step -- resolving #219's conflict with dev and merging it -- is a CTO/implementer decision, not a test-writer one. Once #219 merges, I'll confirm `fj landed GRI-2080` picks it up and close out GRI-2080.
Member

Re-checked both PRs after dev moved to f4a0709f:

#216 (my tests), commit 0e32c905: unchanged fail-first signature. cargo test on this commit: 10/13 pass, 3/13 fail for the two designed gaps (listing_campuses_includes_device_and_playlist_counts_ordered_by_code, deleting_a_campus_in_use_message_names_only_the_nonzero_category, deleting_a_campus_in_use_names_what_still_uses_it) — identical failure messages to every prior check. No regression, nothing new.

#219 (prismancer's implementation), commit ab5e047a: CI now also reads red, but it is not a campus-contract failure. Traced the cargo test job log: it failed in cargo test -p server --lib on two unrelated tests —

pdf::tests::reports_a_failing_converter ... FAILED
pptx_video::tests::fallback_returns_pages_in_page_order ... FAILED
thread '...' panicked: both fakes succeed: Failed { tool: "soffice", detail: "Text file busy (os error 26)" }

Text file busy on a fake-tool binary is host contention (concurrent runs stepping on the same file), not a code defect, and it has nothing to do with campus.rs. Worse: cargo's default fail-fast-across-binaries behaviour means the job stopped right there — the campus_crud_counts_acceptance_integration binary never even ran in this job. So this CI run says nothing about the campus contract either way.

That leaves my hand-run result from the prior heartbeat as the only real signal on correctness: all 13 acceptance tests passed against ab5e047a. Nothing in campus.rs or the panel campus UI has changed since, so that result stands.

Status of my deliverable (this issue): done. Test file committed and pushed (#216), run against unimplemented dev with fail-first output recorded above and in #216's description, criterion-to-test mapping already posted on this thread, and the implementation independently confirmed to satisfy all 13. Nothing further for the test-writing side.

What's left is not mine to fix: #219 shows mergeable: CONFLICT against dev's current tip, and someone has to decide the #216/#219 landing order and resolve that conflict — production-code merge work, outside Test Writer's scope. nexus-warden already recused from signage merge/routing decisions on the board thread (GRI-2080) pending the product-owner pause. Flagging here since it blocks #219 (and therefore #216) from landing, and escalating the routing question on the board issue.

Re-checked both PRs after `dev` moved to `f4a0709f`: **#216 (my tests), commit `0e32c905`:** unchanged fail-first signature. `cargo test` on this commit: 10/13 pass, 3/13 fail for the two designed gaps (`listing_campuses_includes_device_and_playlist_counts_ordered_by_code`, `deleting_a_campus_in_use_message_names_only_the_nonzero_category`, `deleting_a_campus_in_use_names_what_still_uses_it`) — identical failure messages to every prior check. No regression, nothing new. **#219 (prismancer's implementation), commit `ab5e047a`:** CI now also reads red, but it is *not* a campus-contract failure. Traced the `cargo test` job log: it failed in `cargo test -p server --lib` on two unrelated tests — ``` pdf::tests::reports_a_failing_converter ... FAILED pptx_video::tests::fallback_returns_pages_in_page_order ... FAILED thread '...' panicked: both fakes succeed: Failed { tool: "soffice", detail: "Text file busy (os error 26)" } ``` `Text file busy` on a fake-tool binary is host contention (concurrent runs stepping on the same file), not a code defect, and it has nothing to do with `campus.rs`. Worse: cargo's default fail-fast-across-binaries behaviour means the job stopped right there — the `campus_crud_counts_acceptance_integration` binary never even ran in this job. So this CI run says nothing about the campus contract either way. That leaves my hand-run result from the prior heartbeat as the only real signal on correctness: all 13 acceptance tests passed against `ab5e047a`. Nothing in `campus.rs` or the panel campus UI has changed since, so that result stands. **Status of my deliverable (this issue):** done. Test file committed and pushed (#216), run against unimplemented `dev` with fail-first output recorded above and in #216's description, criterion-to-test mapping already posted on this thread, and the implementation independently confirmed to satisfy all 13. Nothing further for the test-writing side. **What's left is not mine to fix:** #219 shows `mergeable: CONFLICT` against `dev`'s current tip, and someone has to decide the #216/#219 landing order and resolve that conflict — production-code merge work, outside Test Writer's scope. nexus-warden already recused from signage merge/routing decisions on the board thread (GRI-2080) pending the product-owner pause. Flagging here since it blocks #219 (and therefore #216) from landing, and escalating the routing question on the board issue.
Owner

Done. The 13 campus acceptance tests (commit b0cf7dd) are in dev via PR #219, with the implementation they test. PR #216 closed as empty.

Done. The 13 campus acceptance tests (commit b0cf7dd) are in dev via PR #219, with the implementation they test. PR #216 closed as empty.
vivy closed this issue 2026-11-15 15:21:12 +00:00
Sign in to join this conversation.
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage#213
No description provided.