Craft Anything: understand how any software works, and craft your own.
Rust
Name every place the website check accepts a site, and where the app really is (#627)
Fábio Soarese9852f8c580a
diff --git a/crates/ai/src/rebuild/kinds/website.rs b/crates/ai/src/rebuild/kinds/website.rsindex b455c6b1..1f109c28 100644--- a/crates/ai/src/rebuild/kinds/website.rs+++ b/crates/ai/src/rebuild/kinds/website.rs@@ -716,6 +716,14 @@ fn states_note(cx: &CheckCx, base: &str, out: &Path, dir: &str, unknowns: &mut V/// builder but don't change the score.pub struct WebVisualCheck;+/// What the check says when there is no site to look at: the places `site_dir` accepts, in the+/// place the app really is ("app/" or "the project folder", #494).+fn missing_site_note(place: &str) -> String {+ format!(+ "No built site found in {place} yet. Expected an index.html in its dist/, build/ or out/ folder, or an index.html straight in {place} when there is no package.json."+ )+}+impl Check for WebVisualCheck {fn id(&self) -> &'static str {CheckResult::WEB_VISUAL@@ -725,7 +733,7 @@ impl Check for WebVisualCheck {let (ws, round) = (cx.ws, cx.round);let widths = cx.build_settings().widths();let Some(site) = site_dir(&ws.app_dir()) else {- return Ok(CheckResult::new(self.id(), round, false, "No built site found in app/dist, app/out or app/build yet."));+ return Ok(CheckResult::new(self.id(), round, false, missing_site_note(ws.app_place())));};let base = cx.serve_preview(&site)?;let out = ws.checks_dir().join(format!("round-{round}"));@@ -817,3 +825,31 @@ impl Check for WebVisualCheck {Ok(CheckResult { similarity: Some(avg), artifacts, pages, unknowns, claims, ..CheckResult::new(self.id(), round, true, notes.join(" | ")) })}}++#[cfg(test)]+mod tests {+ use super::*;++ /// #494: the note names every place `site_dir` accepts, and the place the app really is.+ #[test]+ fn the_missing_site_note_names_what_site_dir_accepts() {+ let note = missing_site_note("app/");+ for named in ["dist/", "build/", "out/", "index.html straight in app/", "no package.json"] {+ assert!(note.contains(named), "{named} in {note}");+ }+ assert!(missing_site_note("the project folder").contains("index.html straight in the project folder"));+ // What it names is what is accepted, and a manifest turns the plain page down.+ for folder in ["dist", "build", "out"] {+ let d = tempfile::tempdir().unwrap();+ std::fs::create_dir_all(d.path().join(folder)).unwrap();+ std::fs::write(d.path().join(folder).join("index.html"), "<html></html>").unwrap();+ assert_eq!(site_dir(d.path()), Some(d.path().join(folder)), "{folder}");+ }+ let d = tempfile::tempdir().unwrap();+ assert_eq!(site_dir(d.path()), None, "nothing built");+ std::fs::write(d.path().join("index.html"), "<html></html>").unwrap();+ assert_eq!(site_dir(d.path()), Some(d.path().to_path_buf()), "a plain page");+ std::fs::write(d.path().join("package.json"), "{}").unwrap();+ assert_eq!(site_dir(d.path()), None, "a page beside a manifest is not a built site");+ }+}diff --git a/crates/ai/src/rebuild/tests.rs b/crates/ai/src/rebuild/tests.rsindex 3622e069..a018b2bf 100644--- a/crates/ai/src/rebuild/tests.rs+++ b/crates/ai/src/rebuild/tests.rs@@ -961,6 +961,32 @@ fn website_kind_compares_only_when_there_is_an_original() {assert_eq!(ids(&scratch), [CheckResult::BUILD]);}+/// #494: the website check, run for real with no site to look at, fails with a note that names the+/// places a site is accepted and where the app is: `app/`, or the project folder for a project+/// that edits its own folder.+#[test]+fn the_website_check_with_no_site_says_where_it_looked() {+ let d = tempfile::tempdir().unwrap();+ for in_root in [false, true] {+ let mut ws = Workspace::create(+ &d.path().join(if in_root { "root" } else { "app" }),+ "Site",+ "Clone it",+ TargetRef::Website { url: "https://example.com".into() },+ )+ .unwrap();+ ws.manifest.app_in_root = in_root;+ let place = if in_root { "the project folder" } else { "app/" };+ let r = check_worker(&ws, false).run_checks(&ws, &kinds::WebsiteKind, 1).unwrap();+ assert_eq!(r.len(), 1);+ assert!(!r[0].passed && r[0].check == CheckResult::WEB_VISUAL, "{:?}", r[0]);+ let note = &r[0].note;+ assert!(note.contains(&format!("No built site found in {place} yet")), "{note}");+ assert!(note.contains(&format!("index.html straight in {place}")) && note.contains("dist/, build/ or out/"), "{note}");+ assert!(in_root || !note.contains("project folder"), "{note}");+ }+}+#[test]fn a_picked_game_is_rebuilt_with_its_own_engine_when_we_can() {let d = tempfile::tempdir().unwrap();diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 9b15c70b..1e034ea0 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -443,8 +443,9 @@ Owner: open · Status: in progress- [ ] Make: a game whose request names a technology the stack table doesn't know (Phaser, Bevy…)still needs the default engine installed to start, though the builder is told to use whatwas named; ask the person, or let such a game start without an engine-- [ ] The website check's "No built site found in app/dist, app/out or app/build yet" leaves out- plain HTML in `app/`, which `site_dir` accepts: name it too (#494)+- [x] The website check's missing-site note names every place `site_dir` accepts (dist/, build/,+ out/, or a plain index.html with no package.json) and the app's real place, "app/" or "the+ project folder" (#494)### R2.8 Clean room means clean roomOwner: maintainers · Status: in progress