Spike, not the final UI: it answers whether flare-ui can drive Alkane OS's on-box pages, and what it costs. What works: - schema/alkane-bb.json authors the sidebar as data (3 sections, 14 tabs); - src/bin/ui-spike.rs renders it through flare_ui::nav + flare_ui::shell, so the unified sidebar, ordering and surface filtering come from the schema rather than from hand-written HTML; - the render uses the shared bf- design tokens, the same ones the rest of the suite uses. Size, measured rather than assumed (armv7, release, stripped): ui-baseline 323 KiB (maud + serde_json, no flare-ui) ui-spike 771 KiB (flare-ui + wschema + sha2) marginal 448 KiB Vendoring: third-party/flare-ui is the full v0.2.9 tree pinned in flare-ui/flare-ui.lock (a partial archive does not compile, since the crate include_str!s assets from dash-editor/). vendor/ is re-generated as a cargo directory source with the new registry dependencies (maud, sha2, typenum, digest, generic-array, block-buffer, crypto-common, cfg-if, etc.) so the build still works offline. third-party/README.md records how to re-pin.
321 lines
10 KiB
Rust
321 lines
10 KiB
Rust
//! End-to-end tests of `wschema-cli verify-lock` and `gen-lock` on a
|
|
//! throwaway consumer tree.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::{Command, Output};
|
|
|
|
const BASE: &str = "data/schema/base.json";
|
|
const OUT_C: &str = "ui-src/gen/schema_gen.c";
|
|
const OUT_H: &str = "ui-src/gen/schema_gen.h";
|
|
|
|
fn run(root: &Path, args: &[&str]) -> Output {
|
|
Command::new(env!("CARGO_BIN_EXE_wschema-cli"))
|
|
.args(args)
|
|
.args(["--root", root.to_str().unwrap()])
|
|
.output()
|
|
.unwrap()
|
|
}
|
|
|
|
fn text(b: &[u8]) -> String {
|
|
String::from_utf8_lossy(b).into_owned()
|
|
}
|
|
|
|
fn write(root: &Path, rel: &str, body: &[u8]) {
|
|
let p = root.join(rel);
|
|
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
|
|
std::fs::write(p, body).unwrap();
|
|
}
|
|
|
|
/// git's blob id, computed the slow obvious way with the git binary when it
|
|
/// exists, so the test does not trust the code it tests.
|
|
fn blob(body: &[u8]) -> String {
|
|
let dir = scratch_dir("blob");
|
|
std::fs::write(dir.join("f"), body).unwrap();
|
|
let out = Command::new("git")
|
|
.args(["hash-object", "f"])
|
|
.current_dir(&dir)
|
|
.output()
|
|
.expect("git is needed for this test");
|
|
text(&out.stdout).trim().to_string()
|
|
}
|
|
|
|
fn scratch_dir(name: &str) -> PathBuf {
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
|
let id = COUNT.fetch_add(1, Ordering::SeqCst);
|
|
let d = std::env::temp_dir().join(format!(
|
|
"wschema-cli-lock-{}-{name}-{id}",
|
|
std::process::id()
|
|
));
|
|
let _ = std::fs::remove_dir_all(&d);
|
|
std::fs::create_dir_all(&d).unwrap();
|
|
d
|
|
}
|
|
|
|
/// A consumer tree: two vendored files under one tree, a base schema, two
|
|
/// generated outputs, and a gen.lock written by `gen-lock`.
|
|
fn consumer(name: &str) -> PathBuf {
|
|
let root = scratch_dir(name);
|
|
let a = b"pub fn a() {}\n".as_slice();
|
|
let b = b"pub fn b() {}\n".as_slice();
|
|
write(&root, "vendor/flare-ui/crates/wschema/src/a.rs", a);
|
|
write(&root, "vendor/flare-ui/crates/wschema/src/b.rs", b);
|
|
let lock = format!(
|
|
"# flare-ui files vendored here.\ntag v0.2.0\ncommit {}\n\
|
|
tree crates/wschema vendor/flare-ui/crates/wschema\n\
|
|
{} crates/wschema/src/a.rs vendor/flare-ui/crates/wschema/src/a.rs\n\
|
|
{} crates/wschema/src/b.rs vendor/flare-ui/crates/wschema/src/b.rs\n",
|
|
"1".repeat(40),
|
|
blob(a),
|
|
blob(b)
|
|
);
|
|
write(&root, "flare-ui.lock", lock.as_bytes());
|
|
let base = std::fs::read(format!(
|
|
"{}/../../corpus/schema/warden-base.json",
|
|
env!("CARGO_MANIFEST_DIR")
|
|
))
|
|
.unwrap();
|
|
write(&root, BASE, &base);
|
|
write(&root, OUT_C, b"/* generated */\nint x;\n");
|
|
write(&root, OUT_H, b"/* generated */\nextern int x;\n");
|
|
let out = run(
|
|
&root,
|
|
&[
|
|
"gen-lock",
|
|
"--generator",
|
|
"gen-panel-c",
|
|
"1",
|
|
"--base",
|
|
BASE,
|
|
"--output",
|
|
OUT_H,
|
|
"--output",
|
|
OUT_C,
|
|
],
|
|
);
|
|
assert_eq!(out.status.code(), Some(0), "{}", text(&out.stderr));
|
|
root
|
|
}
|
|
|
|
fn verify(root: &Path, extra: &[&str]) -> (Option<i32>, String) {
|
|
let mut args = vec!["verify-lock"];
|
|
args.extend_from_slice(extra);
|
|
let out = run(root, &args);
|
|
(out.status.code(), text(&out.stdout) + &text(&out.stderr))
|
|
}
|
|
|
|
#[test]
|
|
fn gen_lock_records_tag_hash_generator_and_sorted_outputs() {
|
|
let root = consumer("record");
|
|
let g = std::fs::read_to_string(root.join("gen.lock")).unwrap();
|
|
let hash = Command::new(env!("CARGO_BIN_EXE_wschema-cli"))
|
|
.args(["hash", "--effective", root.join(BASE).to_str().unwrap()])
|
|
.output()
|
|
.unwrap();
|
|
let hash = text(&hash.stdout).trim().to_string();
|
|
let lines: Vec<&str> = g.lines().filter(|l| !l.starts_with('#')).collect();
|
|
assert_eq!(
|
|
lines,
|
|
vec![
|
|
"flare-ui v0.2.0".to_string(),
|
|
"generator gen-panel-c 1".to_string(),
|
|
format!("schema {hash}"),
|
|
format!("base {BASE}"),
|
|
format!("output {} {OUT_C}", blob(b"/* generated */\nint x;\n")),
|
|
format!(
|
|
"output {} {OUT_H}",
|
|
blob(b"/* generated */\nextern int x;\n")
|
|
),
|
|
]
|
|
);
|
|
// Writing it twice gives the same bytes.
|
|
let again = run(
|
|
&root,
|
|
&[
|
|
"gen-lock",
|
|
"--generator",
|
|
"gen-panel-c",
|
|
"1",
|
|
"--base",
|
|
BASE,
|
|
"--output",
|
|
OUT_C,
|
|
"--output",
|
|
OUT_H,
|
|
],
|
|
);
|
|
assert_eq!(again.status.code(), Some(0));
|
|
assert_eq!(std::fs::read_to_string(root.join("gen.lock")).unwrap(), g);
|
|
}
|
|
|
|
#[test]
|
|
fn a_clean_tree_passes() {
|
|
let root = consumer("clean");
|
|
let (code, out) = verify(&root, &["--gen", "--generator", "gen-panel-c", "1"]);
|
|
assert_eq!(code, Some(0), "{out}");
|
|
assert!(
|
|
out.contains("2 files match flare-ui v0.2.0; gen.lock holds for 2 output(s)"),
|
|
"{out}"
|
|
);
|
|
}
|
|
|
|
/// A named way to break a consumer tree and the message it must produce.
|
|
type Case = (&'static str, fn(&Path), &'static str);
|
|
|
|
#[test]
|
|
fn every_vendored_defect_fails() {
|
|
let cases: [Case; 3] = [
|
|
(
|
|
"drift",
|
|
|r| write(r, "vendor/flare-ui/crates/wschema/src/a.rs", b"// edited\n"),
|
|
"drift: vendor/flare-ui/crates/wschema/src/a.rs",
|
|
),
|
|
(
|
|
"missing",
|
|
|r| std::fs::remove_file(r.join("vendor/flare-ui/crates/wschema/src/b.rs")).unwrap(),
|
|
"missing: vendor/flare-ui/crates/wschema/src/b.rs",
|
|
),
|
|
(
|
|
"unlisted",
|
|
|r| write(r, "vendor/flare-ui/crates/wschema/src/extra/c.rs", b"\n"),
|
|
"unlisted: vendor/flare-ui/crates/wschema/src/extra/c.rs",
|
|
),
|
|
];
|
|
for (name, break_it, want) in cases {
|
|
let root = consumer(name);
|
|
break_it(&root);
|
|
let (code, out) = verify(&root, &[]);
|
|
assert_eq!(code, Some(1), "{name}: {out}");
|
|
assert!(out.contains(want), "{name}: {out}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn every_gen_defect_fails() {
|
|
let cases: [Case; 4] = [
|
|
(
|
|
"lock-bump",
|
|
|r| {
|
|
let l = std::fs::read_to_string(r.join("flare-ui.lock")).unwrap();
|
|
write(r, "flare-ui.lock", l.replace("v0.2.0", "v0.3.0").as_bytes());
|
|
},
|
|
"generated at flare-ui v0.2.0, flare-ui.lock pins v0.3.0",
|
|
),
|
|
(
|
|
"schema-edit",
|
|
|r| {
|
|
let b = std::fs::read_to_string(r.join(BASE)).unwrap();
|
|
let edited = b.replacen("\"label\": \"", "\"label\": \"X", 1);
|
|
assert_ne!(b, edited);
|
|
write(r, BASE, edited.as_bytes());
|
|
},
|
|
"the effective schema is",
|
|
),
|
|
(
|
|
"hand-edit",
|
|
|r| write(r, OUT_C, b"/* generated */\nint y;\n"),
|
|
"gen: ui-src/gen/schema_gen.c is",
|
|
),
|
|
(
|
|
"output-gone",
|
|
|r| std::fs::remove_file(r.join(OUT_H)).unwrap(),
|
|
"gen: missing output ui-src/gen/schema_gen.h",
|
|
),
|
|
];
|
|
for (name, break_it, want) in cases {
|
|
let root = consumer(name);
|
|
break_it(&root);
|
|
let (code, out) = verify(&root, &[]);
|
|
assert_eq!(code, Some(1), "{name}: {out}");
|
|
assert!(out.contains(want), "{name}: {out}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn generator_and_presence_rules() {
|
|
let root = consumer("generator");
|
|
let (code, out) = verify(&root, &["--generator", "gen-panel-c", "2"]);
|
|
assert_eq!(code, Some(1), "{out}");
|
|
assert!(out.contains("came from gen-panel-c 1, this tree ships gen-panel-c 2"));
|
|
std::fs::remove_file(root.join("gen.lock")).unwrap();
|
|
let (code, out) = verify(&root, &[]);
|
|
assert_eq!(code, Some(0), "flare has no gen.lock: {out}");
|
|
assert!(out.contains("no gen.lock"), "{out}");
|
|
let (code, out) = verify(&root, &["--gen"]);
|
|
assert_eq!(code, Some(1), "{out}");
|
|
assert!(out.contains("gen: no gen.lock"), "{out}");
|
|
let (code, _) = verify(&root, &["--generator", "gen-panel-c", "1"]);
|
|
assert_eq!(
|
|
code,
|
|
Some(2),
|
|
"--generator without a gen.lock is a usage error"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn malformed_locks_and_usage_exit_2() {
|
|
let root = consumer("malformed");
|
|
write(&root, "gen.lock", b"flare-ui v0.2.0\n");
|
|
let (code, out) = verify(&root, &[]);
|
|
assert_eq!(code, Some(2), "{out}");
|
|
assert!(out.contains("gen.lock: no 'generator' line"), "{out}");
|
|
write(&root, "flare-ui.lock", b"tag v0.2.0\n");
|
|
let (code, out) = verify(&root, &[]);
|
|
assert_eq!(code, Some(2), "{out}");
|
|
assert!(out.contains("flare-ui.lock: no 'commit' line"), "{out}");
|
|
assert_eq!(verify(&root, &["--bogus"]).0, Some(2));
|
|
let out = run(&root, &["gen-lock", "--base", BASE, "--output", OUT_C]);
|
|
assert_eq!(out.status.code(), Some(2), "gen-lock needs --generator");
|
|
let out = run(
|
|
&root,
|
|
&[
|
|
"gen-lock",
|
|
"--generator",
|
|
"g",
|
|
"1",
|
|
"--base",
|
|
"../x.json",
|
|
"--output",
|
|
OUT_C,
|
|
],
|
|
);
|
|
assert_eq!(out.status.code(), Some(2));
|
|
}
|
|
|
|
/// verify-lock and `scripts/vendor.sh check` agree on the same tree, so CI
|
|
/// can run either. Needs git and bash.
|
|
#[test]
|
|
fn agrees_with_vendor_sh_check() {
|
|
let script = format!("{}/../../scripts/vendor.sh", env!("CARGO_MANIFEST_DIR"));
|
|
for (name, edit) in [("same", false), ("differs", true)] {
|
|
let root = consumer(name);
|
|
let st = Command::new("git")
|
|
.args(["init", "-q"])
|
|
.current_dir(&root)
|
|
.status()
|
|
.unwrap();
|
|
assert!(st.success());
|
|
if edit {
|
|
write(
|
|
&root,
|
|
"vendor/flare-ui/crates/wschema/src/b.rs",
|
|
b"// edited\n",
|
|
);
|
|
}
|
|
let sh = Command::new("bash")
|
|
.args([script.as_str(), "check"])
|
|
.current_dir(&root)
|
|
.output()
|
|
.unwrap();
|
|
let (code, out) = verify(&root, &[]);
|
|
assert_eq!(
|
|
sh.status.success(),
|
|
code == Some(0),
|
|
"{name}: vendor.sh {:?} vs verify-lock {code:?}\n{}\n{out}",
|
|
sh.status,
|
|
text(&sh.stdout)
|
|
);
|
|
assert_eq!(code, Some(if edit { 1 } else { 0 }), "{name}: {out}");
|
|
}
|
|
}
|