xonecas.io
8447
Co

conveyor / commit 4c87399

Test the trial's edges on a throwaway library

A branch that doesn't build, two that conflict, a follow-up built on the
trial, and a discard. It builds the real app into its own target dir.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-09 4c87399d842fc0e32b7ec2d153809acdcfd75335 parent 7e2cc40

3 files changed

DESIGN.md+1−0
@@ -202,6 +202,7 @@ Ctrl+click ─► conveyord: widgets ticket (kind, instance chain, tree, shared,
202202 - **Widgets are programs**: own state, input, files in `cx.dir`, threads, `curl`, and `cx.animate()` for frame-rate redraws.
203203 - **The click is the context.** A build ticket carries the clicked kind, the instance and its parents with the point in each, every instance on screen, the shared values, and the conversation about that kind so far. The form shows the same conversation, so following up is one more Ctrl+click.
204204 - **Merges are the user's.** A finished build goes on trial: the app runs from a worktree (`~/.local/share/conveyor/trial`) of main plus every build in review, so a temporary widget lives in the real app until its toast's Keep merges it or Discard sends it back to draft. A build that doesn't compile, or conflicts with those on trial, never goes on trial. A build made while others are on trial starts from them, so keeping it keeps what it was built on.
205+- **The trial's edges are tested**: a branch that doesn't build, two that conflict, a follow-up built on the trial, a discard (`cargo test --release -p conveyor trial`, on a throwaway library and target dir).
205206 - **Placement is explicit.** The app places nothing unless the agent ran `conveyor place`. Guessing placed widgets twice, four times over.
206207 - **Widgets act from anywhere.** `cx.act(|live| ..)` does from `view`, `update` and `event` what the free functions do from handlers.
207208 - **Hidden work survives restarts.** Instances exist once rendered; `cx.keep_running()` from `update` makes the app bring one back after a restart even when nothing shows it.
crates/conveyor/src/library.rs+4−0
@@ -180,3 +180,7 @@ pub fn builds() -> Vec<Value> {
180180 Some(json!({"id": t.id, "kind": b.kind, "targets": b.targets, "changed": b.changed, "place": b.place}))
181181 }).collect()
182182 }
183+
184+#[cfg(test)]
185+#[path = "library_tests.rs"]
186+mod tests;
crates/conveyor/src/library_tests.rs+82−0
@@ -0,0 +1,82 @@
1+//! The trial's edges, on a throwaway library: a branch that doesn't build, two that conflict,
2+//! a follow-up built on the trial, and a discard. It builds the real app, into its own target
3+//! dir, so the first run takes minutes: cargo test --release -p conveyor trial -- --nocapture
4+use super::*;
5+use std::path::PathBuf;
6+
7+const WIDGET: &str = "use super::api::*;\nuse rune::{El, col};\n\
8+ pub const WIDGET: Widget = Widget { title: \"T\", size: (10.0, 10.0), new: |_| Box::new(T) };\n\
9+ pub struct T;\nimpl View for T { fn view(&self, _: &Cx) -> El { col() } }\n";
10+
11+fn run(dir: &Path, args: &[&str]) -> String {
12+ git(dir, "", &[&COMMIT[..], args].concat()).unwrap()
13+}
14+
15+/// Whether `rev` is in `of`'s history.
16+fn has(rev: &str, of: &str) -> bool {
17+ git(&paths::library(), "", &["merge-base", "--is-ancestor", rev, of]).is_ok()
18+}
19+
20+fn state(id: u32) -> String {
21+ store::ticket(SLUG, id).unwrap().state
22+}
23+
24+/// A build ticket whose agent wrote `text` to widgets/`file` on branch t-<id>, from `from`.
25+fn build(from: &str, file: &str, text: &str) -> (u32, String) {
26+ let id = store::create(SLUG, file, "", "running");
27+ let (lib, w, branch) = (paths::library(), paths::data().join("author"), format!("t-{id}"));
28+ run(&lib, &["worktree", "add", "-q", "-B", &branch, &w.to_string_lossy(), from]);
29+ fs::write(w.join("widgets").join(file), text).unwrap();
30+ run(&w, &["add", "-A"]);
31+ run(&w, &["commit", "-qm", file]);
32+ run(&lib, &["worktree", "remove", "--force", &w.to_string_lossy()]);
33+ (id, branch)
34+}
35+
36+#[test]
37+fn trial_edges() {
38+ let root = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/trial-test"));
39+ let _ = fs::remove_dir_all(root.join("home"));
40+ // Safe: this is the only test that touches the environment. cargo and rustup keep their
41+ // real homes, so the app's build finds the toolchain.
42+ let real = PathBuf::from(std::env::var("HOME").unwrap());
43+ unsafe {
44+ std::env::set_var("CARGO_HOME", std::env::var("CARGO_HOME").map_or(real.join(".cargo"), PathBuf::from));
45+ std::env::set_var("RUSTUP_HOME", std::env::var("RUSTUP_HOME").map_or(real.join(".rustup"), PathBuf::from));
46+ std::env::set_var("HOME", root.join("home"));
47+ std::env::set_var("CARGO_TARGET_DIR", root.join("target"));
48+ }
49+ fs::create_dir_all(paths::projects()).unwrap();
50+ ensure().unwrap();
51+ let p = store::project(SLUG).unwrap();
52+ let main_root = fs::read_to_string(paths::library().join("widgets/root.rs")).unwrap();
53+
54+ // A branch that doesn't build never goes on trial, and the trial is main again.
55+ let (bad, branch) = build("main", "broken.rs", "not rust");
56+ let err = try_out(&p, bad, &branch).unwrap_err();
57+ assert!(err.contains("doesn't build") && err.contains("broken.rs"), "{err}");
58+ assert!(!has(&branch, "trial") && state(bad) == "running");
59+
60+ // Two branches that change the same lines: the second stays off the trial.
61+ let (b, branch_b) = build("main", "root.rs", &format!("{main_root}// b\n"));
62+ try_out(&p, b, &branch_b).unwrap();
63+ assert_eq!(state(b), "review");
64+ let (c, branch_c) = build("main", "root.rs", &format!("{main_root}// c\n"));
65+ assert!(try_out(&p, c, &branch_c).unwrap_err().contains("conflicts"));
66+ assert!(has(&branch_b, "trial") && !has(&branch_c, "trial"));
67+
68+ // A follow-up starts from the trial; keeping it keeps what it was built on.
69+ let (d, branch_d) = build("trial", "d.rs", WIDGET);
70+ try_out(&p, d, &branch_d).unwrap();
71+ keep(d).unwrap();
72+ assert!(state(d) == "done" && has(&branch_d, "main") && has(&branch_b, "main"));
73+ keep(b).unwrap();
74+ assert_eq!(state(b), "done");
75+
76+ // Discard: back to draft, out of the trial.
77+ let (e, branch_e) = build("main", "e.rs", WIDGET);
78+ try_out(&p, e, &branch_e).unwrap();
79+ assert!(has(&branch_e, "trial"));
80+ discard(e).unwrap();
81+ assert!(state(e) == "draft" && !has(&branch_e, "trial") && !has(&branch_e, "main"));
82+}