Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Say when app/ is empty in the build check and the stop message (#771)

Fábio Soares41d2175e2589
diff --git a/crates/ai/src/rebuild/kinds/mod.rs b/crates/ai/src/rebuild/kinds/mod.rs
index 87a28567..01f098c6 100644
--- a/crates/ai/src/rebuild/kinds/mod.rs
+++ b/crates/ai/src/rebuild/kinds/mod.rs
@@ -237,6 +237,8 @@ impl Check for BuildCheck {
}
fn run(&self, cx: &mut CheckCx) -> Result<CheckResult, ToolError> {
let (passed, note) = build_check(&cx.ws.app_dir(), cx.ws.app_place(), &cx.ws.manifest.stack, cx.editor(), cx.stop());
+ // #736: a failed build of an empty app/ says first that nothing was written.
+ let note = if !passed && app_is_empty(cx.ws) { format!("{} {note}", no_files_yet(cx.ws)) } else { note };
Ok(CheckResult::new(self.id(), cx.round, passed, note))
}
}
diff --git a/crates/ai/src/rebuild/kinds/website.rs b/crates/ai/src/rebuild/kinds/website.rs
index db18d94c..51e8fcc9 100644
--- a/crates/ai/src/rebuild/kinds/website.rs
+++ b/crates/ai/src/rebuild/kinds/website.rs
@@ -731,11 +731,6 @@ fn missing_site_note(place: &str, empty: bool) -> String {
)
}
-/// Whether a folder holds nothing: no files or folders, or no folder at all.
-fn folder_is_empty(dir: &std::path::Path) -> bool {
- std::fs::read_dir(dir).map(|mut entries| entries.next().is_none()).unwrap_or(true)
-}
-
impl Check for WebVisualCheck {
fn id(&self) -> &'static str {
CheckResult::WEB_VISUAL
@@ -745,9 +740,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 {
- // In a project folder the workspace's own files are there, so only app/ can be empty.
- let empty = !ws.manifest.app_in_root && folder_is_empty(&ws.app_dir());
- return Ok(CheckResult::new(self.id(), round, false, missing_site_note(ws.app_place(), empty)));
+ return Ok(CheckResult::new(self.id(), round, false, missing_site_note(ws.app_place(), app_is_empty(ws))));
};
let base = cx.serve_preview(&site)?;
let out = ws.checks_dir().join(format!("round-{round}"));
diff --git a/crates/ai/src/rebuild/mod.rs b/crates/ai/src/rebuild/mod.rs
index e8652c58..4daa887a 100644
--- a/crates/ai/src/rebuild/mod.rs
+++ b/crates/ai/src/rebuild/mod.rs
@@ -1130,8 +1130,32 @@ impl Worker {
}
fn no_build_progress(ws: &Workspace) -> ToolError {
- ToolError::new(ErrorCode::OverLimit, format!("The build stopped after two builder turns changed no files in {}.", ws.app_place()))
- .with_remediation("Send a new request with a concrete correction, or edit the app's files before trying again.")
+ let stop = format!("The build stopped after two builder turns changed no files in {}.", ws.app_place());
+ // #736: an empty app/ means the builder never wrote the project, whatever its replies said.
+ if app_is_empty(ws) {
+ ToolError::new(ErrorCode::OverLimit, format!("{stop} {}", no_files_yet(ws)))
+ .with_remediation("Send a new request that asks for the project's files in app/ (such as package.json and index.html), or try another builder.")
+ } else {
+ ToolError::new(ErrorCode::OverLimit, stop)
+ .with_remediation("Send a new request with a concrete correction, or edit the app's files before trying again.")
+ }
+}
+
+/// Whether the builder has written nothing into app/ (#736). A project folder always holds the
+/// workspace's own files, so only app/ can be empty.
+fn app_is_empty(ws: &Workspace) -> bool {
+ !ws.manifest.app_in_root && folder_is_empty(&ws.app_dir())
+}
+
+/// Whether a folder holds nothing: no files or folders, or no folder at all.
+fn folder_is_empty(dir: &Path) -> bool {
+ std::fs::read_dir(dir).map(|mut entries| entries.next().is_none()).unwrap_or(true)
+}
+
+/// Said when app/ is empty, so a builder that claims it built the project can't hide that nothing
+/// was written (#736).
+fn no_files_yet(ws: &Workspace) -> String {
+ format!("{} has no files yet, so the builder hasn't written the project.", ws.app_place())
}
/// Why a coding agent can't build: never signed in, or signed in `before` with a sign-in that no
diff --git a/crates/ai/src/rebuild/tests.rs b/crates/ai/src/rebuild/tests.rs
index b4fdc903..484adfb7 100644
--- a/crates/ai/src/rebuild/tests.rs
+++ b/crates/ai/src/rebuild/tests.rs
@@ -1853,6 +1853,54 @@ mod picking_up_a_build {
assert!(ok);
assert_eq!(prompts_given(&b), asked, "and it isn't asked to build again");
}
+
+ /// #736: a builder that says it built the site while app/ has no files stops after two
+ /// unchanged turns, and the build check and the stop both say nothing was written. The
+ /// reporter's release had no such stop, so its check ran 40+ times.
+ #[test]
+ fn an_empty_app_with_a_claimed_build_stops_and_says_nothing_was_written() {
+ let b = bench();
+ let mut ws = Workspace::create(&b.projects, "x", "A website for a bakery", TargetRef::None).unwrap();
+ ws.manifest.agent_session = Some("session-1".into());
+ ws.save().unwrap();
+ std::fs::create_dir_all(ws.capture_dir()).unwrap();
+ std::fs::create_dir_all(ws.app_dir()).unwrap();
+ // The stand-in answers "Done." and writes nothing, as the reported builder did.
+ let opts = RunOptions { backend: Some("Stand-in".into()), ..RunOptions::default() };
+ let run = RebuildRun::start(&b.hub, Workspace::open(&ws.root).unwrap(), opts).unwrap();
+ let ok = loop {
+ match run.rx.recv_timeout(Duration::from_secs(60)) {
+ Ok(RunEvent::Finished { ok, .. }) => break ok,
+ Ok(_) => {}
+ Err(e) => panic!("the run went away: {e}"),
+ }
+ };
+ assert!(!ok);
+ assert_eq!(prompts_given(&b), 2, "a third unchanged turn would spend more without progress");
+ let saved = Workspace::open(&ws.root).unwrap();
+ let build = saved.manifest.checks.iter().find(|c| c.check == CheckResult::BUILD).expect("the build check ran");
+ assert!(build.note.contains("app/ has no files yet, so the builder hasn't written the project."), "{}", build.note);
+ let feed = feed::load(&saved);
+ assert!(
+ feed.iter().any(|i| matches!(i, feed::FeedItem::Error { message, .. }
+ if message.contains("changed no files in app/") && message.contains("app/ has no files yet"))),
+ "the stop says app/ is empty: {feed:?}"
+ );
+ }
+
+ /// The empty-folder wording is only for an empty app/: a folder with files gets the plain stop.
+ #[test]
+ fn the_stop_names_an_empty_app_and_only_then() {
+ let b = bench();
+ let ws = worked_on(&b);
+ let empty = no_build_progress(&ws);
+ assert!(empty.message.contains("app/ has no files yet"), "{empty:?}");
+ assert!(empty.remediation.as_deref().is_some_and(|r| r.contains("asks for the project's files in app/")), "{empty:?}");
+ std::fs::write(ws.app_dir().join("index.html"), "<h1>Bakery</h1>").unwrap();
+ let written = no_build_progress(&ws);
+ assert!(!written.message.contains("has no files"), "{written:?}");
+ assert_eq!(written.message, "The build stopped after two builder turns changed no files in app/.");
+ }
}
fn check_worker(ws: &Workspace, deep: bool) -> Worker {
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 271db94b..89d7e7c4 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -223,6 +223,11 @@ Every round spends the person's money or quota. One that can't do anything shoul
fired on a local Ollama build (the same built-in loop) after two turns that changed nothing
in `app/` ("The build stopped after two builder turns changed no files in app/…"); an
API-key build is still owed
+- [x] #736: the build check and the stop message say when `app/` is empty, so a builder that
+ claims a build can't hide that nothing was written. v0.3.0 (the reporter's release) had no
+ stop after two unchanged turns (#557, merged after it); main stops, and this adds the
+ empty-folder wording to the build check (it failed first, before #749's website check) and
+ to the stop message — claimed: claude, branch bugfix/r5.3-empty-app-loop
### R5.4 Local models can build
Owner: open · Status: todo
diff --git a/docs/pitfalls.md b/docs/pitfalls.md
index 87f19254..840b8bd9 100644
--- a/docs/pitfalls.md
+++ b/docs/pitfalls.md
@@ -63,6 +63,12 @@ comments were acted on; the fixes went to its branch and the threads were answer
`main` had the code without them. Read `gh pr view --json state,headRefOid` before pushing to a PR's
branch, and land anything late in a new PR from `main`.
+**A report checked against main, not the release it ran.** #736 (a build looping on an empty `app/`)
+was read against main, where the stop after two unchanged turns already existed, so it looked fixed.
+The reporter ran v0.3.0, which had neither that stop (#557) nor the empty-folder note (#749); both
+merged the day after it shipped. Before calling a report fixed or still open, find the release it
+names (`git merge-base --is-ancestor <fix> <release tag>`), and check the message text it quotes.
+
## Tests
**A test started a real download on a contributor's machine.** A test called `engines_install` for