From 5a443b067858d8991ec3eaf82cb7fb7858d3a64a Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 05:45:34 +1300 Subject: [PATCH] app/: the public demo reset (sc-8900): domain::demo::reset rebuilds visualci/demo through the real pipeline (its owner, organization and public project made if missing, a visualci organization that isn't the demo's refused, the builds and their group rows deleted, the demo's four builds sent again with one approved, not charged); demo:reset runs daily with its heartbeat --- app/src/console/demo.rs | 28 +++ app/src/console/mod.rs | 8 +- app/src/domain/demo.rs | 419 ++++++++++++++++++++++++++++++++++++++++ app/src/domain/mod.rs | 1 + app/src/lib.rs | 1 + app/tests/demo.rs | 84 ++++++++ 6 files changed, 538 insertions(+), 3 deletions(-) create mode 100644 app/src/console/demo.rs create mode 100644 app/src/domain/demo.rs create mode 100644 app/tests/demo.rs diff --git a/app/src/console/demo.rs b/app/src/console/demo.rs new file mode 100644 index 00000000..b48f5f37 --- /dev/null +++ b/app/src/console/demo.rs @@ -0,0 +1,28 @@ +//! `demo:reset`, daily: rebuild the public demo, visualci/demo, from scratch (`domain::demo`), undoing anything done to +//! it since. Pushes its result to `VISUALCI_DEMO_HEARTBEAT_URL` (and `_TOKEN`): Gatus alerts on a failed run and on a +//! day with no run. + +use laravel::console::{Console, clap, command}; + +use super::heartbeat; +use crate::domain::demo; +use crate::storage::BlobStore; + +#[derive(clap::Parser)] +#[command(name = "demo:reset")] +pub struct DemoReset; + +#[command] +impl DemoReset { + async fn handle(self, console: &mut Console) -> laravel::Result<()> { + let result = async { + let store = BlobStore::current().await?; + Box::pin(demo::reset(&store, &crate::http::api::builds::renderer_version())).await + } + .await; + heartbeat::push("VISUALCI_DEMO_HEARTBEAT", result.as_ref().map(|_| ()).map_err(ToString::to_string)).await; + let builds = result?; + console.line(format!("demo reset: {}/{} has {builds} builds", demo::ORG, demo::PROJECT)); + Ok(()) + } +} diff --git a/app/src/console/mod.rs b/app/src/console/mod.rs index 294fe017..947d50e8 100644 --- a/app/src/console/mod.rs +++ b/app/src/console/mod.rs @@ -1,11 +1,12 @@ -//! The schedule (`laravel schedule:run` every minute, in production a CronJob): the builds sweep every five minutes, -//! retention and the groups check daily, each run pushing its result to a heartbeat so a task that failed or stopped -//! running alerts. +//! The schedule (`laravel schedule:run` every minute, in production a CronJob): the builds sweep every five minutes; +//! retention, the groups check and the demo reset daily. Each run pushes its result to a heartbeat, so a task that +//! failed or stopped running alerts. use laravel::schedule::{self, Schedule}; // The heartbeat every scheduled task pushes to (`crate::heartbeat`). pub use crate::heartbeat; +pub mod demo; pub mod retention; #[schedule::tasks] @@ -13,6 +14,7 @@ fn schedule(schedule: &mut Schedule) { schedule.call(sweep_builds).name("builds-sweep").every_five_minutes().without_overlapping().on_one_runner(); schedule.command("retention:prune").daily_at("03:00").without_overlapping().on_one_runner(); schedule.command("groups:check").daily_at("04:00").without_overlapping().on_one_runner(); + schedule.command("demo:reset").name("demo-reset").daily_at("05:00").without_overlapping().on_one_runner(); } /// [`crate::domain::processing::sweep`], with its heartbeat (`VISUALCI_BUILDS_SWEEP_HEARTBEAT_URL` and `_TOKEN`). diff --git a/app/src/domain/demo.rs b/app/src/domain/demo.rs new file mode 100644 index 00000000..c7c744ba --- /dev/null +++ b/app/src/domain/demo.rs @@ -0,0 +1,419 @@ +//! The public demo, visualci/demo (app.visualci.com/visualci/demo): its builds show every kind of change (screenshots, a +//! PDF page, JSON, HTML and text; added and removed snapshots), so a new person or agent sees a real review before +//! sending anything. Anyone can read it; nobody outside the demo organization can change it, and [`reset`] (the daily +//! `demo:reset`) rebuilds it from scratch, undoing anything that did. +//! +//! The builds go through the real pipeline (snapshot registration, finalizing, processing), so the demo shows what the +//! app produces. PDFs are the exception: their renders are recorded as done, with page images drawn here, since +//! drawing needs the render node. The demo isn't charged: builds are processed directly, not by the job that charges. + +use std::io::Cursor; + +use image::{ImageFormat, Rgba, RgbaImage}; +use laravel::db; +use laravel::model::create; + +use super::build_settings::BuildSettings; +use super::builds::CreateParams; +use super::renders::RenderPage; +use super::snapshots::SnapshotParams; +use crate::models::{Build, Membership, Organization, Project, User}; +use crate::storage::BlobStore; + +/// The demo's organization and project: app.visualci.com/visualci/demo. +pub const ORG: &str = "visualci"; +pub const PROJECT: &str = "demo"; +/// The demo organization's only member, who approves one of its builds. +pub const OWNER_EMAIL: &str = "demo@visualci.com"; + +/// Rebuild the demo; returns how many builds it has. +/// +/// # Errors +/// On a database or storage error, or when the `visualci` organization exists and isn't the demo's. +pub async fn reset(store: &BlobStore, renderer_version: &str) -> laravel::Result { + let owner = match User::query().filter(User::email.eq(OWNER_EMAIL)).first().await? { + Some(u) => u, + None => { + create!(User { pid: laravel::str::uuid7(), name: "VisualCI demo", email: OWNER_EMAIL, staff: false }) + .await? + } + }; + // The demo's own account isn't a sign-up: nobody is emailed about it, and /status doesn't wait for it. + let owner_id = owner.id; + db::query!("UPDATE users SET signup_notified_at = now() WHERE id = {owner_id} AND signup_notified_at IS NULL") + .update() + .await?; + let org = match Organization::query().filter(Organization::slug.eq(ORG)).first().await? { + Some(org) => org, + None => { + let org = create!(Organization { pid: laravel::str::uuid7(), slug: ORG, name: "VisualCI" }).await?; + create!(Membership { organization_id: org.id, user_id: owner_id, role: "admin", source: "created" }) + .await?; + org + } + }; + let member = Membership::query() + .filter(Membership::organization_id.eq(org.id) & Membership::user_id.eq(owner_id)) + .exists() + .await?; + if !member { + return Err(laravel::Error::msg(format!("the {ORG} organization exists and isn't the demo's"))); + } + let project = + match Project::query().filter(Project::organization_id.eq(org.id) & Project::slug.eq(PROJECT)).first().await? { + Some(p) => p, + None => { + create!(Project { pid: laravel::str::uuid7(), organization_id: org.id, slug: PROJECT, name: "Demo" }) + .await? + } + }; + // Start over: the builds go, and their snapshots, pages and baselines with them. + let project_id = project.id; + db::query!("UPDATE projects SET public = true WHERE id = {project_id}").update().await?; + // Its builds read groups from each other (`build_groups.source_build_id`, which has no ON DELETE so a held build is + // never deleted from under a reader): every one goes, so their group rows go first, in the same transaction. + db::transaction(async |_| { + db::query!( + "DELETE FROM build_groups WHERE build_id IN (SELECT id FROM builds WHERE project_id = {project_id}) \ + OR source_build_id IN (SELECT id FROM builds WHERE project_id = {project_id})" + ) + .delete() + .await?; + db::query!("DELETE FROM builds WHERE project_id = {project_id}").delete().await + }) + .await?; + let project = Project::find_or_fail(project_id).await?; + Seeder { store, renderer_version }.web_builds(&project, owner_id).await?; + let builds: i64 = + db::query!("SELECT COUNT(*) FROM builds WHERE project_id = {project_id}").scalar().await?.unwrap_or(0); + Ok(usize::try_from(builds).unwrap_or_default()) +} + +struct Seeder<'a> { + store: &'a BlobStore, + renderer_version: &'a str, +} + +/// One snapshot to send in a build. +enum Item { + Image { name: &'static str, png: Vec }, + Text { name: &'static str, content_type: &'static str, text: String }, + Pdf { name: &'static str, pages: Vec }, +} + +#[derive(Clone)] +struct PdfPage { + /// Lines of text, drawn as bars and recorded as the page's text. + lines: Vec<&'static str>, + accent: [u8; 3], +} + +fn error(e: impl std::fmt::Display) -> laravel::Error { + laravel::Error::msg(e.to_string()) +} + +impl Seeder<'_> { + /// The web app: a baseline, an unchanged build, a PR with every kind of change, and a branch whose change + /// `reviewer` approves. + async fn web_builds(&self, web: &Project, reviewer: i64) -> laravel::Result<()> { + let base = || { + vec![ + Item::Image { name: "dashboard/1440-light", png: screen(720, 450, Screen::default()) }, + Item::Image { name: "dashboard/390-light", png: screen(195, 420, Screen::default()) }, + Item::Image { + name: "settings/1440-light", + png: screen(720, 450, Screen { cards: 2, ..Screen::default() }), + }, + Item::Image { + name: "signup/1440-light", + png: screen(720, 450, Screen { cards: 1, ..Screen::default() }), + }, + Item::Pdf { name: "receipt.pdf", pages: receipt(false) }, + Item::Text { name: "api/orders.json", content_type: "application/json", text: orders_json(false) }, + Item::Text { name: "emails/welcome.html", content_type: "text/html", text: welcome_html(false) }, + Item::Text { name: "cli/help.txt", content_type: "text/plain", text: help_text(false) }, + ] + }; + let c1 = "a1b2c3d4e5f60718293a4b5c6d7e8f9012345678"; + let c2 = "b2c3d4e5f60718293a4b5c6d7e8f901234567890"; + self.build(web, c1, "main", None, &[], base()).await?; + self.build(web, c2, "main", None, &[c1], base()).await?; + + // PR #42: every kind of change. + let changed = vec![ + Item::Image { + name: "dashboard/1440-light", + png: screen(720, 450, Screen { button: [22, 163, 74], ..Screen::default() }), + }, + // The phone page grew taller: a resized pair. + Item::Image { + name: "dashboard/390-light", + png: screen(195, 520, Screen { footer: true, ..Screen::default() }), + }, + Item::Image { + name: "settings/1440-light", + png: screen(720, 450, Screen { cards: 2, ..Screen::default() }), + }, + Item::Image { + name: "checkout/1440-light", + png: screen(720, 450, Screen { cards: 4, ..Screen::default() }), + }, + Item::Pdf { name: "receipt.pdf", pages: receipt(true) }, + Item::Text { name: "api/orders.json", content_type: "application/json", text: orders_json(true) }, + Item::Text { name: "emails/welcome.html", content_type: "text/html", text: welcome_html(true) }, + Item::Text { name: "cli/help.txt", content_type: "text/plain", text: help_text(true) }, + ]; + let c3 = "c3d4e5f60718293a4b5c6d7e8f9012345678901a"; + self.build(web, c3, "checkout-redesign", Some(42), &[c2], changed).await?; + + // A branch whose changes are approved. + let mut footer = base(); + footer[2] = Item::Image { + name: "settings/1440-light", + png: screen(720, 450, Screen { cards: 2, footer: true, ..Screen::default() }), + }; + let c4 = "d4e5f60718293a4b5c6d7e8f9012345678901a2b"; + let reviewed = self.build(web, c4, "fix-footer", Some(41), &[c2], footer).await?; + let via = super::reviews::Via::default(); + Box::pin(super::reviews::review(reviewed, Some(reviewer), &via, "approve", None, None)) + .await? + .map_err(error)?; + Ok(()) + } + + /// Send a build through the pipeline and return it, completed. + async fn build( + &self, + project: &Project, + commit: &str, + branch: &str, + pr_number: Option, + parents: &[&str], + items: Vec, + ) -> laravel::Result { + let params = CreateParams { + commit: commit.to_string(), + branch: branch.to_string(), + pr_number, + parent_commits: parents.iter().map(ToString::to_string).collect(), + mode: "ci".to_string(), + name: "default".to_string(), + shard_total: 1, + subset: false, + nonce: None, + config: None, + environment: Some("ci".to_string()), + environment_info: None, + }; + let outcome = |r: Result>| match r { + Ok(b) => Ok(b), + Err(Ok(invalid)) => Err(error(invalid)), + Err(Err(e)) => Err(e), + }; + let build = outcome(super::builds::create(project, ¶ms, None).await)?; + let settings = BuildSettings::new(project, &build); + for item in items { + let snapshot = self.snapshot(project, item).await?; + snapshot.validate().map_err(error)?; + super::snapshots::register(&build, &settings, self.renderer_version, &snapshot).await?.map_err(error)?; + } + let build = outcome(super::builds::finalize_shard(build, None, false).await)?; + let id = build.id; + let concluded = Box::pin(db::transaction(async |_| { + super::processing::lock(id).await?; + let build = Build::find_or_fail(id).await?; + super::processing::process(build, self.store, self.renderer_version).await + })) + .await?; + if !concluded { + return Err(laravel::Error::msg(format!("demo build {id} didn't conclude"))); + } + Build::find_or_fail(id).await + } + + /// Store an item's bytes and describe it the way the CLI would. + async fn snapshot(&self, project: &Project, item: Item) -> laravel::Result { + let params = |name: &str, kind: &str, fingerprint: String, sha256: String, size: i64, content_type: &str| { + SnapshotParams { + name: name.to_string(), + platform: if kind == "image" { "chrome-linux".to_string() } else { String::new() }, + kind: kind.to_string(), + fingerprint, + sha256, + size, + content_type: content_type.to_string(), + threshold: None, + ignore_anti_aliasing: None, + engine: None, + format: None, + meta: serde_json::json!({}), + ignore: None, + } + }; + let size_of = |bytes: &[u8]| i64::try_from(bytes.len()).unwrap_or(i64::MAX); + Ok(match item { + Item::Image { name, png } => { + let fingerprint = visualci_core::image_hash::fingerprint_bytes(&png).map_err(error)?; + let size = size_of(&png); + let blob = super::blobs::put(self.store, png, "image/png").await?; + params(name, "image", fingerprint, blob.sha256, size, "image/png") + } + Item::Text { name, content_type, text } => { + let fingerprint = visualci_core::sha256_hex(text.as_bytes()); + let size = size_of(text.as_bytes()); + let blob = super::blobs::put(self.store, text.into_bytes(), content_type).await?; + params(name, "text", fingerprint, blob.sha256, size, content_type) + } + Item::Pdf { name, pages } => { + // The "PDF" is the pages' description; its render is recorded as done with the drawn pages. + let mut rendered = Vec::new(); + for page in &pages { + let png = page_png(page); + let image_fingerprint = visualci_core::image_hash::fingerprint_bytes(&png).map_err(error)?; + let text = page.lines.join("\n"); + let blob = super::blobs::put(self.store, png, "image/png").await?; + rendered.push(RenderPage { + image: blob.sha256, + image_fingerprint, + fingerprint: visualci_core::sha256_hex(text.as_bytes()), + width: PAGE_W, + height: PAGE_H, + text_sha: String::new(), + text, + }); + } + let source: String = rendered.iter().map(|p| p.fingerprint.as_str()).collect(); + let fingerprint = visualci_core::sha256_hex(source.as_bytes()); + let blob = super::blobs::put(self.store, source.into_bytes(), "application/pdf").await?; + let renderer_key = super::projects::renderer_key(&project.renderer, project.dpi, self.renderer_version); + let render = + super::renders::find_or_queue(project.id, &fingerprint, &renderer_key, &blob.sha256).await?; + if render.state != "done" { + super::renders::complete(render, &rendered).await?; + } + params(name, "document", fingerprint, blob.sha256, blob.size, "application/pdf") + } + }) + } +} + +// Drawing. Simple flat shapes, so the images are small and the same on every machine. + +const PAGE_W: u32 = 420; +const PAGE_H: u32 = 594; + +fn png(image: &RgbaImage) -> Vec { + let mut out = Cursor::new(Vec::new()); + image.write_to(&mut out, ImageFormat::Png).expect("encoding a PNG in memory"); + out.into_inner() +} + +fn rect(image: &mut RgbaImage, x: u32, y: u32, w: u32, h: u32, rgb: [u8; 3]) { + let (iw, ih) = image.dimensions(); + for py in y.min(ih)..(y + h).min(ih) { + for px in x.min(iw)..(x + w).min(iw) { + image.put_pixel(px, py, Rgba([rgb[0], rgb[1], rgb[2], 255])); + } + } +} + +#[derive(Clone, Copy)] +struct Screen { + cards: u32, + button: [u8; 3], + footer: bool, +} + +impl Default for Screen { + fn default() -> Self { + Self { cards: 3, button: [37, 99, 235], footer: false } + } +} + +/// A made-up app screen: a top bar, a heading, a button and a row of cards. +fn screen(w: u32, h: u32, s: Screen) -> Vec { + let mut image = RgbaImage::from_pixel(w, h, Rgba([248, 250, 252, 255])); + rect(&mut image, 0, 0, w, 36, [15, 23, 42]); + rect(&mut image, 16, 12, 60, 12, [226, 232, 240]); + rect(&mut image, 24, 60, w / 3, 18, [30, 41, 59]); + rect(&mut image, 24, 88, w / 2, 8, [148, 163, 184]); + rect(&mut image, 24, 110, 96.min(w - 48), 28, s.button); + let gap = 16; + let card_w = (w - 48 - gap * (s.cards - 1)) / s.cards; + for i in 0..s.cards { + let x = 24 + i * (card_w + gap); + rect(&mut image, x, 160, card_w, 140.min(h.saturating_sub(200)), [255, 255, 255]); + rect(&mut image, x + 12, 176, card_w.saturating_sub(24), 10, [100, 116, 139]); + rect(&mut image, x + 12, 196, card_w / 2, 8, [203, 213, 225]); + } + if s.footer { + rect(&mut image, 0, h - 40, w, 40, [226, 232, 240]); + rect(&mut image, 24, h - 26, 120, 10, [100, 116, 139]); + } + png(&image) +} + +/// A PDF page: a coloured header band and a grey bar per line of text, as wide as the line. +fn page_png(page: &PdfPage) -> Vec { + let mut image = RgbaImage::from_pixel(PAGE_W, PAGE_H, Rgba([255, 255, 255, 255])); + rect(&mut image, 32, 32, PAGE_W - 64, 40, page.accent); + for (i, line) in page.lines.iter().enumerate() { + let width = (u32::try_from(line.len()).unwrap_or(u32::MAX).saturating_mul(6)).min(PAGE_W - 64); + let y = 96 + u32::try_from(i).unwrap_or(0) * 22; + rect(&mut image, 32, y, width, 9, [71, 85, 105]); + } + png(&image) +} + +fn receipt(changed: bool) -> Vec { + let blue = [37, 99, 235]; + let mut pages = vec![ + PdfPage { + lines: vec!["Receipt #10422", "Acme Inc.", "20 November 2026", "Billed to: Example Customer"], + accent: blue, + }, + PdfPage { + lines: if changed { + vec!["Widget x 2 $40.00", "Gadget x 1 $25.00", "Subtotal $65.00", "Total $71.50"] + } else { + vec!["Widget x 2 $40.00", "Gadget x 1 $25.00", "Total $65.00"] + }, + accent: blue, + }, + ]; + if changed { + pages.push(PdfPage { + lines: vec!["Tax summary", "GST 10% $6.50", "Registered for GST"], + accent: [22, 163, 74], + }); + } + pages +} + +fn orders_json(changed: bool) -> String { + let currency = if changed { r#", "currency": "USD""# } else { "" }; + format!( + "{{\n \"orders\": [\n {{ \"id\": \"ord_1001\", \"status\": \"paid\", \"total\": 6500{currency} }},\n \ + {{ \"id\": \"ord_1002\", \"status\": \"{}\", \"total\": 1200{currency} }}\n ],\n \"has_more\": false\n}}\n", + if changed { "refunded" } else { "pending" } + ) +} + +fn welcome_html(changed: bool) -> String { + format!( + "\n\n

Welcome to Acme

\n

Thanks for signing up.

\n \ + {}\n\n\n", + if changed { "Start your trial" } else { "Get started" } + ) +} + +fn help_text(changed: bool) -> String { + let mut text = String::from( + "Usage: acme \n\nCommands:\n login Sign in\n deploy Deploy the current directory\n", + ); + if changed { + text.push_str(" rollback Go back to the previous deploy\n"); + } + text.push_str(" logs Show recent logs\n"); + text +} diff --git a/app/src/domain/mod.rs b/app/src/domain/mod.rs index 00ec4344..516d3582 100644 --- a/app/src/domain/mod.rs +++ b/app/src/domain/mod.rs @@ -9,6 +9,7 @@ pub mod changeset; pub mod comments; pub mod compare; pub mod credits; +pub mod demo; pub mod detail; pub mod diffs; pub mod downloads; diff --git a/app/src/lib.rs b/app/src/lib.rs index f763f2e6..95033310 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -78,5 +78,6 @@ pub fn configure() -> ApplicationBuilder { .with_commands(|commands, _| { commands.add::(); commands.add::(); + commands.add::(); }) } diff --git a/app/tests/demo.rs b/app/tests/demo.rs new file mode 100644 index 00000000..6dbccf70 --- /dev/null +++ b/app/tests/demo.rs @@ -0,0 +1,84 @@ +//! The public demo (visualci/demo): `demo:reset` rebuilds it through the real pipeline, the same every time, and +//! refuses a `visualci` organization that isn't the demo's. + +use app::domain::demo; +use app::models::{Build, Organization, Project}; +use app::testing::fixtures; +use laravel::db; +use laravel::testing::prelude::*; +use serde_json::{Value, json}; + +/// Everything a visitor sees of the demo's builds, without ids or times. +async fn summary() -> laravel::Result { + let org = Organization::query().filter(Organization::slug.eq(demo::ORG)).first().await?.expect("the demo org"); + let project = Project::query() + .filter(Project::organization_id.eq(org.id) & Project::slug.eq(demo::PROJECT)) + .first() + .await? + .expect("the demo project"); + let mut builds = Vec::new(); + for b in Build::query().filter(Build::project_id.eq(project.id)).get().await? { + let snapshots: Vec = app::domain::snapshots::of_build(b.id) + .await? + .iter() + .map(|s| json!([s.name, s.platform, s.kind, s.state])) + .collect(); + builds.push(json!({ + "number": b.number, "branch": b.branch, "pr": b.pr_number, "state": b.state, + "review_state": b.review_state, "conclusion": b.conclusion, "snapshots": snapshots, + })); + } + builds.sort_by_key(|b| b["number"].as_i64()); + Ok(json!({ "public": project.public, "builds": builds })) +} + +#[laravel::test] +async fn the_demo_is_rebuilt_the_same_every_time(app: Application) -> laravel::Result<()> { + Box::pin(same_every_time(app)).await +} + +async fn same_every_time(app: Application) -> laravel::Result<()> { + let store = fixtures::blob_store().await?; + assert_eq!(Box::pin(demo::reset(&store, "1")).await?, 4); + let first = summary().await?; + assert_eq!(first["public"], true); + let builds = first["builds"].as_array().unwrap(); + assert!(builds.iter().all(|b| b["state"] == "completed"), "{first:#}"); + // The pull request shows every kind of change, and the reviewed branch is approved. + let pr = builds.iter().find(|b| b["pr"] == 42).expect("PR #42"); + let states: Vec<&str> = pr["snapshots"].as_array().unwrap().iter().filter_map(|s| s[3].as_str()).collect(); + for state in ["changed", "added", "removed"] { + assert!(states.contains(&state), "PR #42 has a {state} snapshot: {states:?}"); + } + let kinds: Vec<&str> = pr["snapshots"].as_array().unwrap().iter().filter_map(|s| s[2].as_str()).collect(); + for kind in ["image", "document", "text"] { + assert!(kinds.contains(&kind), "PR #42 has a {kind}: {kinds:?}"); + } + let reviewed = builds.iter().find(|b| b["pr"] == 41).expect("PR #41"); + assert_eq!(reviewed["review_state"], "approved", "{reviewed}"); + + // The owner isn't a sign-up anyone is told about. + let owner = demo::OWNER_EMAIL; + let notified: Option = + db::query!("SELECT COUNT(*) FROM users WHERE email = {owner} AND signup_notified_at IS NOT NULL") + .scalar() + .await?; + assert_eq!(notified, Some(1)); + + // Anything done to it since is undone, and a second run gives the same demo. + let changed = Build::query().first().await?.unwrap(); + let id = changed.id; + db::query!("UPDATE builds SET review_state = 'rejected' WHERE id = {id}").update().await?; + app.command("demo:reset").await.assert_successful().assert_output_contains("visualci/demo has 4 builds"); + assert_eq!(summary().await?, first); + Ok(()) +} + +#[laravel::test] +async fn the_demo_refuses_a_visualci_organization_that_is_not_its_own(_app: Application) -> laravel::Result<()> { + let store = fixtures::blob_store().await?; + fixtures::organization(demo::ORG).await?; + let refused = Box::pin(demo::reset(&store, "1")).await; + assert!(refused.is_err_and(|e| e.to_string().contains("isn't the demo's"))); + Ok(()) +}