feat(api): streamline generated app authoring
Move the canonical examples toward generated component-root helpers, typed form decoding, async/state handler registration, and derive-driven app/component registry wiring. Tighten requirements and diagnostics for the server-first, selectorless authoring path. Verified with cargo run -p slhx-xtask -- test, cargo check --workspace, redgate list, redgate refs, redgate health --strict, and git diff --check. req: canonical/001 req: canonical/003 req: canonical/004 req: dx/002 req: derive_app/001 req: component/003 req: form/004 req: axum_integration/003
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
use slhx_techdemo::ui::control_center::{handles, slots};
|
||||
use slhx_techdemo::ui::issue_card::handles as card_handles;
|
||||
use slhx_techdemo::ui::control_center::{self as control, launch_work, simulate_push};
|
||||
use slhx_test::{
|
||||
any_root_selector, document_body_selector, handle_button_selector, handle_selector,
|
||||
island_probe_script, island_readout_selector, keyed_selector, nav_link_selector,
|
||||
scoped_island_readout_selector, target_selector,
|
||||
};
|
||||
use std::process::{Child, Command, Stdio};
|
||||
use std::time::{Duration, Instant};
|
||||
use thirtyfour::prelude::*;
|
||||
@@ -48,63 +52,70 @@ async fn browser_drives_typed_product_end_to_end() -> WebDriverResult<()> {
|
||||
|
||||
let result = async {
|
||||
driver.goto(&format!("http://{APP_ADDR}/")).await?;
|
||||
assert_text(&driver, "A Linear-class work system without a frontend framework").await?;
|
||||
assert_text(
|
||||
&driver,
|
||||
"A Linear-class work system without a frontend framework",
|
||||
)
|
||||
.await?;
|
||||
assert_text(&driver, "Compile checked handles").await?;
|
||||
assert_text(&driver, "No selectors. Generated resources address every target.").await?;
|
||||
assert_text(
|
||||
&driver,
|
||||
"No selectors. Generated resources address every target.",
|
||||
)
|
||||
.await?;
|
||||
assert_text(&driver, "Opaque island bridge").await?;
|
||||
wait_for_runtime(&driver).await?;
|
||||
insert_probe_island(&driver).await?;
|
||||
wait_for_text(&driver, "#probe-island [data-island-readout]", "probe live").await?;
|
||||
wait_for_text(
|
||||
&driver,
|
||||
&scoped_island_readout_selector("#probe-island"),
|
||||
"probe live",
|
||||
)
|
||||
.await?;
|
||||
|
||||
driver
|
||||
.find(By::Css(&handle_selector(handles::simulate_push)))
|
||||
.find(By::Css(&handle_selector(simulate_push)))
|
||||
.await?
|
||||
.click()
|
||||
.await?;
|
||||
wait_for_text(&driver, &slot_selector(slots::notice), "Push simulated").await?;
|
||||
wait_for_text(&driver, "[data-island-readout]", "activity rows").await?;
|
||||
|
||||
driver.find(By::Css("button.primary-action")).await?.click().await?;
|
||||
wait_for_text(&driver, ".work-card[data-key='4']", "Ship typed effects").await?;
|
||||
assert_text(&driver, "width:77%").await?;
|
||||
|
||||
drag_card_to_lane(&driver, 2, "product").await?;
|
||||
wait_for_text(&driver, ".lane[data-lane='product'] .work-card[data-key='2']", "Shipped").await?;
|
||||
wait_for_text(&driver, &slot_selector(slots::notice), "Drag-and-drop move persisted").await?;
|
||||
wait_for_text(&driver, &target_selector(control::notice), "Push simulated").await?;
|
||||
wait_for_text(&driver, island_readout_selector(), "activity rows").await?;
|
||||
|
||||
driver
|
||||
.find(By::Css(&card_button_selector(card_handles::spotlight_work, 2)))
|
||||
.find(By::Css(&handle_button_selector(launch_work)))
|
||||
.await?
|
||||
.click()
|
||||
.await?;
|
||||
wait_for_text(
|
||||
&driver,
|
||||
&slot_selector(slots::inspector),
|
||||
"Stream typed presence · lane=Product · stage=Shipped · impact=7",
|
||||
&keyed_selector(".work-card", 4),
|
||||
"Ship typed updates",
|
||||
)
|
||||
.await?;
|
||||
assert_text(&driver, "width:77%").await?;
|
||||
|
||||
driver
|
||||
.find(By::Css(&card_button_selector(card_handles::advance_work, 3)))
|
||||
.find(By::Css(&handle_selector(simulate_push)))
|
||||
.await?
|
||||
.click()
|
||||
.await?;
|
||||
wait_for_text(&driver, ".lane[data-lane='product'] .work-card[data-key='3']", "Active").await?;
|
||||
wait_for_text(&driver, &target_selector(control::live_feed), "SSE tick").await?;
|
||||
|
||||
driver
|
||||
.find(By::Css(&handle_selector(handles::simulate_push)))
|
||||
.find(By::Css(&nav_link_selector("/architecture")))
|
||||
.await?
|
||||
.click()
|
||||
.await?;
|
||||
wait_for_text(&driver, &slot_selector(slots::live_feed), "SSE tick").await?;
|
||||
|
||||
driver.find(By::Css("a[href='/architecture']")).await?.click().await?;
|
||||
wait_for_text(&driver, &slot_selector(slots::inspector), "Page swap").await?;
|
||||
wait_for_text(&driver, "[data-island-readout]", "activity rows").await?;
|
||||
assert!(driver.current_url().await?.as_str().ends_with("/architecture"));
|
||||
wait_for_text(&driver, &target_selector(control::inspector), "Page swap").await?;
|
||||
wait_for_text(&driver, island_readout_selector(), "activity rows").await?;
|
||||
assert!(driver
|
||||
.current_url()
|
||||
.await?
|
||||
.as_str()
|
||||
.ends_with("/architecture"));
|
||||
|
||||
driver.goto(&format!("http://{APP_ADDR}/")).await?;
|
||||
wait_for_text(&driver, &slot_selector(slots::live_feed), "SSE tick").await?;
|
||||
wait_for_text(&driver, &target_selector(control::live_feed), "SSE tick").await?;
|
||||
|
||||
Ok::<(), WebDriverError>(())
|
||||
}
|
||||
@@ -125,68 +136,15 @@ fn wait_for_tcp(addr: &str) {
|
||||
panic!("timed out waiting for {addr}");
|
||||
}
|
||||
|
||||
fn handle_selector(handle: impl std::fmt::Display) -> String {
|
||||
format!(r#"[data-hid="{handle}"]"#)
|
||||
}
|
||||
|
||||
fn slot_selector(slot: impl std::fmt::Display) -> String {
|
||||
format!(r#"[data-sid="{slot}"]"#)
|
||||
}
|
||||
|
||||
fn card_button_selector(handle_id: impl std::fmt::Display, work_id: u64) -> String {
|
||||
format!(r#"[data-hid="{handle_id}"][data-work-id="{work_id}"]"#)
|
||||
}
|
||||
|
||||
async fn insert_probe_island(driver: &WebDriver) -> WebDriverResult<()> {
|
||||
let root = driver.find(By::Css("[data-slhx-root]")).await?;
|
||||
driver
|
||||
.execute(
|
||||
r#"
|
||||
const root = arguments[0];
|
||||
const island = document.createElement('article');
|
||||
island.id = 'probe-island';
|
||||
island.setAttribute('data-slhx-island', 'orbit');
|
||||
island.setAttribute('data-island-snapshot', '1|1|1|probe waiting');
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 32;
|
||||
canvas.height = 16;
|
||||
island.appendChild(canvas);
|
||||
|
||||
const readout = document.createElement('p');
|
||||
readout.setAttribute('data-island-readout', '');
|
||||
readout.textContent = 'waiting';
|
||||
island.appendChild(readout);
|
||||
|
||||
root.appendChild(island);
|
||||
setTimeout(() => {
|
||||
root.dispatchEvent(new CustomEvent('slhx:island-orbit', { bubbles: true, detail: '7|2|8|probe live' }));
|
||||
}, 25);
|
||||
return true;
|
||||
"#,
|
||||
vec![root.to_json()?],
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn drag_card_to_lane(driver: &WebDriver, work_id: u64, lane: &str) -> WebDriverResult<()> {
|
||||
let card = driver.find(By::Css(format!(".work-card[data-key='{work_id}']"))).await?;
|
||||
let lane = driver.find(By::Css(format!(".lane[data-lane='{lane}']"))).await?;
|
||||
driver
|
||||
.execute(
|
||||
r#"
|
||||
const card = arguments[0];
|
||||
const lane = arguments[1];
|
||||
const data = new DataTransfer();
|
||||
card.dispatchEvent(new DragEvent('dragstart', { bubbles: true, dataTransfer: data }));
|
||||
lane.dispatchEvent(new DragEvent('dragover', { bubbles: true, cancelable: true, dataTransfer: data }));
|
||||
lane.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer: data }));
|
||||
return true;
|
||||
"#,
|
||||
vec![card.to_json()?, lane.to_json()?],
|
||||
)
|
||||
.await?;
|
||||
let root = driver.find(By::Css(any_root_selector())).await?;
|
||||
let script = island_probe_script(
|
||||
"probe-island",
|
||||
"orbit",
|
||||
"1|1|1|probe waiting",
|
||||
"7|2|8|probe live",
|
||||
);
|
||||
driver.execute(&script, vec![root.to_json()?]).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -194,7 +152,10 @@ async fn wait_for_runtime(driver: &WebDriver) -> WebDriverResult<()> {
|
||||
let deadline = Instant::now() + Duration::from_secs(8);
|
||||
loop {
|
||||
let loaded = driver
|
||||
.execute("return !!window.slhx && window.slhx.roots().length > 0", Vec::new())
|
||||
.execute(
|
||||
"return !!window.slhx && window.slhx.roots().length > 0",
|
||||
Vec::new(),
|
||||
)
|
||||
.await?
|
||||
.json()
|
||||
.as_bool()
|
||||
@@ -210,7 +171,7 @@ async fn wait_for_runtime(driver: &WebDriver) -> WebDriverResult<()> {
|
||||
}
|
||||
|
||||
async fn assert_text(driver: &WebDriver, text: &str) -> WebDriverResult<()> {
|
||||
wait_for_text(driver, "body", text).await
|
||||
wait_for_text(driver, document_body_selector(), text).await
|
||||
}
|
||||
|
||||
async fn wait_for_text(driver: &WebDriver, selector: &str, text: &str) -> WebDriverResult<()> {
|
||||
@@ -225,7 +186,12 @@ async fn wait_for_text(driver: &WebDriver, selector: &str, text: &str) -> WebDri
|
||||
}
|
||||
}
|
||||
if Instant::now() >= deadline {
|
||||
let body = driver.find(By::Css("body")).await?.text().await.unwrap_or_default();
|
||||
let body = driver
|
||||
.find(By::Css(document_body_selector()))
|
||||
.await?
|
||||
.text()
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
panic!("timed out waiting for {text:?} in {selector:?}; body={body:?}");
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||
|
||||
+158
-149
@@ -1,10 +1,14 @@
|
||||
use scraper::{Html, Selector};
|
||||
use slhx::{Effect, EffectBatch, Handle, Payload, EFFECT_BATCH_ABI_VERSION};
|
||||
use slhx_axum::SLHX_HANDLE_FIELD;
|
||||
use slhx_techdemo::ui::control_center::{self as control, launch_work, reset_demo, simulate_push};
|
||||
use slhx_techdemo::ui::issue_card::{advance_work, delete_work, spotlight_work};
|
||||
use slhx_techdemo::ui::issue_lane::move_to_lane as move_to_lane_handle;
|
||||
use slhx_techdemo::ui::BUILD_FINGERPRINT;
|
||||
use slhx_techdemo::ui::control_center::handles;
|
||||
use slhx_techdemo::ui::issue_card::handles as card_handles;
|
||||
use slhx_techdemo::ui::issue_lane::handles as lane_handles;
|
||||
use slhx_test::{
|
||||
class_descendant_selector, class_selector, handle_form_body, inspect_wire,
|
||||
island_attribute_name, island_event_name, island_selector, island_snapshot_marker,
|
||||
root_selector, sse_endpoint_marker, strong_text_selector, unknown_handle_form_body,
|
||||
EffectInspector,
|
||||
};
|
||||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
@@ -12,17 +16,6 @@ use std::time::{Duration, Instant};
|
||||
|
||||
const ADDR: &str = "127.0.0.1:3002";
|
||||
|
||||
fn handle_body<I>(handle: Handle<I>, fields: &[(&str, &str)]) -> String {
|
||||
let mut body = format!("{SLHX_HANDLE_FIELD}={handle}");
|
||||
for (name, value) in fields {
|
||||
body.push('&');
|
||||
body.push_str(name);
|
||||
body.push('=');
|
||||
body.push_str(value);
|
||||
}
|
||||
body
|
||||
}
|
||||
|
||||
struct Server {
|
||||
child: Child,
|
||||
}
|
||||
@@ -63,29 +56,32 @@ fn product_is_e2e_working_over_http() {
|
||||
assert_eq!(home.status, 200);
|
||||
assert!(home.header("content-type").contains("text/html"));
|
||||
let document = Html::parse_document(home.text());
|
||||
assert_text(&document, "A Linear-class work system without a frontend framework");
|
||||
assert_text(
|
||||
&document,
|
||||
"A Linear-class work system without a frontend framework",
|
||||
);
|
||||
assert_text(&document, "Compile checked handles");
|
||||
assert_text(&document, "Stream typed presence");
|
||||
assert_selector_count_at_least(&document, "[data-slhx-root=techdemo]", 1);
|
||||
assert_selector_count_at_least(&document, "[data-hid]", 8);
|
||||
assert_selector_count_at_least(&document, "[data-sid]", 7);
|
||||
assert_selector_count_at_least(&document, ".work-card", 3);
|
||||
assert_selector_count_at_least(&document, "[data-slhx-island=orbit]", 1);
|
||||
assert_selector_count_at_least(&document, &root_selector("techdemo"), 1);
|
||||
assert_work_card_count_at_least(&document, 3);
|
||||
assert_selector_count_at_least(&document, &island_selector("orbit"), 1);
|
||||
assert_text(&document, "Opaque island bridge");
|
||||
assert!(home.text().contains("data-island-snapshot="));
|
||||
assert!(home.text().contains("data-slhx-sse=\"/events\""));
|
||||
assert!(home.text().contains(island_snapshot_marker()));
|
||||
assert!(home.text().contains(&sse_endpoint_marker("/events")));
|
||||
assert!(home.text().contains("/island.js"));
|
||||
|
||||
let favicon = get("/favicon.ico");
|
||||
assert_eq!(favicon.status, 204);
|
||||
|
||||
let runtime = get("/slhx.js");
|
||||
assert_eq!(runtime.status, 200);
|
||||
assert!(runtime.header("content-type").contains("javascript"));
|
||||
assert!(runtime.text().contains("const HID = \"data-hid\""));
|
||||
|
||||
let island = get("/island.js");
|
||||
assert_eq!(island.status, 200);
|
||||
assert!(island.header("content-type").contains("javascript"));
|
||||
assert!(island.text().contains("slhx:island-orbit"));
|
||||
assert!(island.text().contains("data-slhx-island"));
|
||||
assert!(island.text().contains(&island_event_name("orbit")));
|
||||
assert!(island.text().contains(island_attribute_name()));
|
||||
assert!(island.text().contains("MutationObserver"));
|
||||
assert!(island.text().contains("removeEventListener"));
|
||||
|
||||
@@ -98,156 +94,183 @@ fn product_is_e2e_working_over_http() {
|
||||
|
||||
let launch = post(
|
||||
"/",
|
||||
&handle_body(
|
||||
handles::launch_work,
|
||||
&handle_form_body(
|
||||
launch_work,
|
||||
&[
|
||||
("title", "Design+hero+moment"),
|
||||
("title", "Design hero moment"),
|
||||
("lane", "product"),
|
||||
("impact", "9"),
|
||||
],
|
||||
),
|
||||
);
|
||||
assert_effect_response(&launch);
|
||||
let launch_batch = launch.batch();
|
||||
let launch_batch = launch.effects();
|
||||
assert_payload_contains(&launch_batch, "Design hero moment");
|
||||
assert_card(&launch_batch, "Design hero moment", "Product", "Draft", "width:99%");
|
||||
assert_card(
|
||||
&launch_batch,
|
||||
"Design hero moment",
|
||||
"Product",
|
||||
"Draft",
|
||||
"width:99%",
|
||||
);
|
||||
assert_payload_contains(&launch_batch, "Launch accepted");
|
||||
assert_payload_contains(&launch_batch, "Launched card #4");
|
||||
assert_emit(&launch_batch, "slhx:island-orbit", "activity rows");
|
||||
assert_emit(&launch_batch, &island_event_name("orbit"), "activity rows");
|
||||
assert!(
|
||||
launch_batch.ops.len() >= 6,
|
||||
launch_batch.op_count() >= 6,
|
||||
"launch should update generated targets and notify the island"
|
||||
);
|
||||
|
||||
let default_impact = post(
|
||||
"/",
|
||||
&handle_body(
|
||||
handles::launch_work,
|
||||
&[("title", "Default+impact"), ("lane", "compiler")],
|
||||
&handle_form_body(
|
||||
launch_work,
|
||||
&[("title", "Default impact"), ("lane", "compiler")],
|
||||
),
|
||||
);
|
||||
assert_effect_response(&default_impact);
|
||||
let default_impact_batch = default_impact.batch();
|
||||
let default_impact_batch = default_impact.effects();
|
||||
assert_payload_contains(&default_impact_batch, "Default impact");
|
||||
assert_card(&default_impact_batch, "Default impact", "Compiler", "Draft", "width:55%");
|
||||
assert_card(
|
||||
&default_impact_batch,
|
||||
"Default impact",
|
||||
"Compiler",
|
||||
"Draft",
|
||||
"width:55%",
|
||||
);
|
||||
|
||||
let low_impact = post(
|
||||
"/",
|
||||
&handle_body(
|
||||
handles::launch_work,
|
||||
&handle_form_body(
|
||||
launch_work,
|
||||
&[
|
||||
("title", "Low+impact"),
|
||||
("title", "Low impact"),
|
||||
("lane", "runtime"),
|
||||
("impact", "0"),
|
||||
],
|
||||
),
|
||||
);
|
||||
assert_effect_response(&low_impact);
|
||||
let low_impact_batch = low_impact.batch();
|
||||
assert_card(&low_impact_batch, "Low impact", "Runtime", "Draft", "width:11%");
|
||||
let low_impact_batch = low_impact.effects();
|
||||
assert_card(
|
||||
&low_impact_batch,
|
||||
"Low impact",
|
||||
"Runtime",
|
||||
"Draft",
|
||||
"width:11%",
|
||||
);
|
||||
|
||||
let high_impact = post(
|
||||
"/",
|
||||
&handle_body(
|
||||
handles::launch_work,
|
||||
&handle_form_body(
|
||||
launch_work,
|
||||
&[
|
||||
("title", "High+impact"),
|
||||
("title", "High impact"),
|
||||
("lane", "runtime"),
|
||||
("impact", "99"),
|
||||
],
|
||||
),
|
||||
);
|
||||
assert_effect_response(&high_impact);
|
||||
let high_impact_batch = high_impact.batch();
|
||||
assert_card(&high_impact_batch, "High impact", "Runtime", "Draft", "width:99%");
|
||||
let high_impact_batch = high_impact.effects();
|
||||
assert_card(
|
||||
&high_impact_batch,
|
||||
"High impact",
|
||||
"Runtime",
|
||||
"Draft",
|
||||
"width:99%",
|
||||
);
|
||||
|
||||
let missing_title = post(
|
||||
"/",
|
||||
&handle_body(handles::launch_work, &[("lane", "runtime"), ("impact", "8")]),
|
||||
&handle_form_body(launch_work, &[("lane", "runtime"), ("impact", "8")]),
|
||||
);
|
||||
assert_effect_response(&missing_title);
|
||||
let missing_title_batch = missing_title.batch();
|
||||
let missing_title_batch = missing_title.effects();
|
||||
assert_payload_contains(&missing_title_batch, "Launch accepted");
|
||||
assert_payload_not_contains(&missing_title_batch, "data-key=\"8\"");
|
||||
assert!(missing_title_batch.payload_excludes_key(8));
|
||||
assert_payload_not_contains(&missing_title_batch, "MUTATED");
|
||||
|
||||
let move_to_lane = post(
|
||||
"/",
|
||||
&handle_body(
|
||||
lane_handles::move_to_lane,
|
||||
&handle_form_body(
|
||||
move_to_lane_handle,
|
||||
&[("work_id", "4"), ("lane", "runtime")],
|
||||
),
|
||||
);
|
||||
assert_effect_response(&move_to_lane);
|
||||
let move_to_lane_batch = move_to_lane.batch();
|
||||
assert_card(&move_to_lane_batch, "Design hero moment", "Runtime", "Active", "width:99%");
|
||||
let move_to_lane_batch = move_to_lane.effects();
|
||||
assert_card(
|
||||
&move_to_lane_batch,
|
||||
"Design hero moment",
|
||||
"Runtime",
|
||||
"Active",
|
||||
"width:99%",
|
||||
);
|
||||
assert_payload_contains(&move_to_lane_batch, "Drag-and-drop move persisted");
|
||||
|
||||
let inspect = post(
|
||||
"/",
|
||||
&handle_body(card_handles::spotlight_work, &[("work_id", "4")]),
|
||||
);
|
||||
let inspect = post("/", &handle_form_body(spotlight_work, &[("work_id", "4")]));
|
||||
assert_effect_response(&inspect);
|
||||
let inspect_batch = inspect.batch();
|
||||
let inspect_batch = inspect.effects();
|
||||
assert_payload_contains(&inspect_batch, "Design hero moment · lane=Runtime");
|
||||
assert_payload_contains(&inspect_batch, "Inspector focused");
|
||||
|
||||
let advance = post(
|
||||
"/",
|
||||
&handle_body(card_handles::advance_work, &[("work_id", "4")]),
|
||||
);
|
||||
let advance = post("/", &handle_form_body(advance_work, &[("work_id", "4")]));
|
||||
assert_effect_response(&advance);
|
||||
let advance_batch = advance.batch();
|
||||
let advance_batch = advance.effects();
|
||||
assert_payload_contains(&advance_batch, "Pipeline advanced");
|
||||
assert_payload_contains(&advance_batch, "<span class=\"pill\">Active</span>");
|
||||
|
||||
let advance_default = post(
|
||||
"/",
|
||||
&handle_body(card_handles::advance_work, &[("work_id", "5")]),
|
||||
);
|
||||
let advance_default = post("/", &handle_form_body(advance_work, &[("work_id", "5")]));
|
||||
assert_effect_response(&advance_default);
|
||||
let advance_default_batch = advance_default.batch();
|
||||
let advance_default_batch = advance_default.effects();
|
||||
assert_payload_contains(&advance_default_batch, "Default impact");
|
||||
assert_card(&advance_default_batch, "Default impact", "Compiler", "Active", "width:55%");
|
||||
|
||||
let ship_default = post(
|
||||
"/",
|
||||
&handle_body(card_handles::advance_work, &[("work_id", "5")]),
|
||||
assert_card(
|
||||
&advance_default_batch,
|
||||
"Default impact",
|
||||
"Compiler",
|
||||
"Active",
|
||||
"width:55%",
|
||||
);
|
||||
assert_effect_response(&ship_default);
|
||||
let ship_default_batch = ship_default.batch();
|
||||
assert_card(&ship_default_batch, "Default impact", "Product", "Shipped", "width:55%");
|
||||
|
||||
let simulated_push = post("/", &handle_body(handles::simulate_push, &[]));
|
||||
let ship_default = post("/", &handle_form_body(advance_work, &[("work_id", "5")]));
|
||||
assert_effect_response(&ship_default);
|
||||
let ship_default_batch = ship_default.effects();
|
||||
assert_card(
|
||||
&ship_default_batch,
|
||||
"Default impact",
|
||||
"Product",
|
||||
"Shipped",
|
||||
"width:55%",
|
||||
);
|
||||
|
||||
let simulated_push = post("/", &handle_form_body(simulate_push, &[]));
|
||||
assert_effect_response(&simulated_push);
|
||||
let push_batch = simulated_push.batch();
|
||||
let push_batch = simulated_push.effects();
|
||||
assert_payload_contains(&push_batch, "SSE tick");
|
||||
assert_payload_contains(&push_batch, "Push simulated · no client app code");
|
||||
assert_payload_contains(&push_batch, "Simulated push event produced the same generated update shape");
|
||||
assert_emit(&push_batch, "slhx:island-orbit", "activity rows");
|
||||
|
||||
let delete_missing = post(
|
||||
"/",
|
||||
&handle_body(card_handles::delete_work, &[("work_id", "999")]),
|
||||
assert_payload_contains(
|
||||
&push_batch,
|
||||
"Simulated push event produced the same generated update shape",
|
||||
);
|
||||
assert_emit(&push_batch, &island_event_name("orbit"), "activity rows");
|
||||
|
||||
let delete_missing = post("/", &handle_form_body(delete_work, &[("work_id", "999")]));
|
||||
assert_effect_response(&delete_missing);
|
||||
let delete_missing_batch = delete_missing.batch();
|
||||
let delete_missing_batch = delete_missing.effects();
|
||||
assert_payload_not_contains(&delete_missing_batch, "Deleted card #999");
|
||||
|
||||
let delete = post(
|
||||
"/",
|
||||
&handle_body(card_handles::delete_work, &[("work_id", "4")]),
|
||||
);
|
||||
let delete = post("/", &handle_form_body(delete_work, &[("work_id", "4")]));
|
||||
assert_effect_response(&delete);
|
||||
let delete_batch = delete.batch();
|
||||
let delete_batch = delete.effects();
|
||||
assert_payload_contains(&delete_batch, "Card removed");
|
||||
assert_payload_contains(&delete_batch, "Deleted card #4");
|
||||
assert_payload_not_contains(&delete_batch, "data-key=\"4\"");
|
||||
assert!(delete_batch.payload_excludes_key(4));
|
||||
assert_payload_contains(&delete_batch, "Default impact");
|
||||
|
||||
let reset = post("/", &handle_body(handles::reset_demo, &[]));
|
||||
let reset = post("/", &handle_form_body(reset_demo, &[]));
|
||||
assert_effect_response(&reset);
|
||||
let reset_batch = reset.batch();
|
||||
let reset_batch = reset.effects();
|
||||
assert_payload_contains(&reset_batch, "Demo reset from Rust state");
|
||||
assert_payload_contains(&reset_batch, "Compile checked handles");
|
||||
|
||||
@@ -257,7 +280,7 @@ fn product_is_e2e_working_over_http() {
|
||||
assert!(sse.text().contains("event: slhx"));
|
||||
assert!(sse.text().contains("data: "));
|
||||
|
||||
let unknown = post("/", &format!("{SLHX_HANDLE_FIELD}=999999"));
|
||||
let unknown = post("/", &unknown_handle_form_body(999999));
|
||||
assert_eq!(unknown.status, 404);
|
||||
assert!(unknown.text().contains("unknown slhx handle id 999999"));
|
||||
}
|
||||
@@ -265,42 +288,37 @@ fn product_is_e2e_working_over_http() {
|
||||
fn assert_effect_response(response: &Response) {
|
||||
assert_eq!(response.status, 200);
|
||||
assert!(response.header("content-type").contains("application/slhx"));
|
||||
assert_eq!(response.header("x-slhx-fingerprint"), BUILD_FINGERPRINT.0.to_string());
|
||||
let batch = response.batch();
|
||||
assert_eq!(batch.abi_version, EFFECT_BATCH_ABI_VERSION);
|
||||
assert!(!batch.ops.is_empty());
|
||||
assert_eq!(
|
||||
response.header("x-slhx-fingerprint"),
|
||||
BUILD_FINGERPRINT.0.to_string()
|
||||
);
|
||||
assert!(!response.effects().is_empty());
|
||||
}
|
||||
|
||||
fn assert_payload_contains(batch: &EffectBatch, needle: &str) {
|
||||
fn assert_payload_contains(batch: &EffectInspector, needle: &str) {
|
||||
assert!(
|
||||
batch.ops.iter().any(|op| match op {
|
||||
Effect::Put { payload, .. } | Effect::Insert { payload, .. } | Effect::Prepend { payload, .. } => payload_value(payload).contains(needle),
|
||||
Effect::Emit { payload, .. } => payload.contains(needle),
|
||||
Effect::Navigate { url, .. } => url.contains(needle),
|
||||
Effect::Remove { .. } | Effect::Move { .. } | Effect::Focus { .. } => false,
|
||||
}),
|
||||
batch.payload_contains(needle),
|
||||
"missing payload {needle:?} in {batch:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
fn assert_emit(batch: &EffectBatch, name: &str, needle: &str) {
|
||||
fn assert_emit(batch: &EffectInspector, name: &str, needle: &str) {
|
||||
assert!(
|
||||
batch.ops.iter().any(|op| match op {
|
||||
Effect::Emit { name: actual, payload } => actual == name && payload.contains(needle),
|
||||
_ => false,
|
||||
}),
|
||||
batch.emits_containing(name, needle),
|
||||
"missing emit {name:?} containing {needle:?} in {batch:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
fn assert_card(batch: &EffectBatch, title: &str, lane: &str, stage: &str, impact_style: &str) {
|
||||
let board = board_html(batch);
|
||||
fn assert_card(batch: &EffectInspector, title: &str, lane: &str, stage: &str, impact_style: &str) {
|
||||
let board = batch
|
||||
.target_html_containing(control::board, "class=\"lanes\"")
|
||||
.expect("board html payload");
|
||||
let document = Html::parse_fragment(&board);
|
||||
let lane_selector = Selector::parse(".lane").unwrap();
|
||||
let card_selector = Selector::parse(".work-card").unwrap();
|
||||
let strong_selector = Selector::parse("strong").unwrap();
|
||||
let stage_selector = Selector::parse(".pill").unwrap();
|
||||
let impact_selector = Selector::parse(".impact i").unwrap();
|
||||
let lane_selector = Selector::parse(&class_selector("lane")).unwrap();
|
||||
let card_selector = Selector::parse(&class_selector("work-card")).unwrap();
|
||||
let strong_selector = Selector::parse(strong_text_selector()).unwrap();
|
||||
let stage_selector = Selector::parse(&class_selector("pill")).unwrap();
|
||||
let impact_selector = Selector::parse(&class_descendant_selector("impact", "i")).unwrap();
|
||||
|
||||
for lane_node in document.select(&lane_selector) {
|
||||
let lane_text = lane_node.text().collect::<Vec<_>>().join(" ");
|
||||
@@ -327,7 +345,10 @@ fn assert_card(batch: &EffectBatch, title: &str, lane: &str, stage: &str, impact
|
||||
.and_then(|node| node.value().attr("style"))
|
||||
.unwrap_or("");
|
||||
assert_eq!(card_stage, stage);
|
||||
assert!(style.contains(impact_style), "style {style:?} missing {impact_style:?}");
|
||||
assert!(
|
||||
style.contains(impact_style),
|
||||
"style {style:?} missing {impact_style:?}"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -335,40 +356,22 @@ fn assert_card(batch: &EffectBatch, title: &str, lane: &str, stage: &str, impact
|
||||
panic!("missing card title={title:?} lane={lane:?} in {board}");
|
||||
}
|
||||
|
||||
fn board_html(batch: &EffectBatch) -> String {
|
||||
batch
|
||||
.ops
|
||||
.iter()
|
||||
.find_map(|op| match op {
|
||||
Effect::Put { payload: Payload::Html(value), .. } if value.contains("class=\"lanes\"") => Some(value.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.expect("board html payload")
|
||||
}
|
||||
|
||||
fn assert_payload_not_contains(batch: &EffectBatch, needle: &str) {
|
||||
fn assert_payload_not_contains(batch: &EffectInspector, needle: &str) {
|
||||
assert!(
|
||||
batch.ops.iter().all(|op| match op {
|
||||
Effect::Put { payload, .. } | Effect::Insert { payload, .. } | Effect::Prepend { payload, .. } => !payload_value(payload).contains(needle),
|
||||
Effect::Emit { payload, .. } => !payload.contains(needle),
|
||||
Effect::Navigate { url, .. } => !url.contains(needle),
|
||||
Effect::Remove { .. } | Effect::Move { .. } | Effect::Focus { .. } => true,
|
||||
}),
|
||||
batch.payload_excludes(needle),
|
||||
"unexpected payload {needle:?} in {batch:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
fn payload_value(payload: &Payload) -> &str {
|
||||
match payload {
|
||||
Payload::Text(value) | Payload::Html(value) => value,
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_text(document: &Html, text: &str) {
|
||||
let body = document.root_element().text().collect::<Vec<_>>().join(" ");
|
||||
assert!(body.contains(text), "missing text {text:?} in {body:?}");
|
||||
}
|
||||
|
||||
fn assert_work_card_count_at_least(document: &Html, expected: usize) {
|
||||
assert_selector_count_at_least(document, &class_selector("work-card"), expected);
|
||||
}
|
||||
|
||||
fn assert_selector_count_at_least(document: &Html, selector: &str, expected: usize) {
|
||||
let selector = Selector::parse(selector).unwrap();
|
||||
let count = document.select(&selector).count();
|
||||
@@ -390,7 +393,9 @@ fn post(path: &str, body: &str) -> Response {
|
||||
|
||||
fn request(method: &str, path: &str, headers: &[(&str, &str)], body: &str) -> Response {
|
||||
let mut stream = TcpStream::connect(ADDR).expect("connect to server");
|
||||
stream.set_read_timeout(Some(Duration::from_secs(5))).unwrap();
|
||||
stream
|
||||
.set_read_timeout(Some(Duration::from_secs(5)))
|
||||
.unwrap();
|
||||
write!(
|
||||
stream,
|
||||
"{method} {path} HTTP/1.1\r\nHost: {ADDR}\r\nConnection: close\r\nContent-Length: {}\r\n",
|
||||
@@ -431,7 +436,11 @@ impl Response {
|
||||
.filter_map(|line| line.split_once(':'))
|
||||
.map(|(name, value)| (name.trim().to_ascii_lowercase(), value.trim().to_string()))
|
||||
.collect();
|
||||
Self { status, headers, body }
|
||||
Self {
|
||||
status,
|
||||
headers,
|
||||
body,
|
||||
}
|
||||
}
|
||||
|
||||
fn header(&self, name: &str) -> &str {
|
||||
@@ -446,7 +455,7 @@ impl Response {
|
||||
std::str::from_utf8(&self.body).unwrap()
|
||||
}
|
||||
|
||||
fn batch(&self) -> EffectBatch {
|
||||
EffectBatch::from_wire(&self.body).unwrap()
|
||||
fn effects(&self) -> EffectInspector {
|
||||
inspect_wire(&self.body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user