add all crates: domain, protocol, application, client, adapters, ESP32 firmware

Server: domain (entities, value objects, ports), protocol (postcard wire types),
application (config service, data projection), adapters (config-memory, tcp-server),
bootstrap (composition root with fake data).

Client: client-domain (layout engine, render tree, HAL ports),
client-application (message handling, repaint commands),
adapters (tcp-client, display-terminal), client-desktop (end-to-end working).

ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking.
Display test verified on hardware — landscape orientation, text rendering works.

60 workspace tests, all passing.
This commit is contained in:
2026-06-18 21:43:59 +02:00
parent 6ad76b98a2
commit 557cceb498
83 changed files with 5844 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
use std::time::Duration;
use domain::{DataSource, DataSourceConfig, DataSourceType, DataSourceValidationError};
fn make_source(source_type: DataSourceType, url: Option<&str>, poll: Duration) -> DataSource {
DataSource {
id: 1,
name: "test".into(),
source_type,
poll_interval: poll,
config: DataSourceConfig {
url: url.map(Into::into),
headers: vec![],
api_key: None,
},
}
}
#[test]
fn http_json_requires_url() {
let source = make_source(DataSourceType::HttpJson, None, Duration::from_secs(60));
let errors = source.validate();
assert!(errors.contains(&DataSourceValidationError::UrlRequired));
}
#[test]
fn webhook_does_not_allow_poll_interval() {
let source = make_source(DataSourceType::Webhook, None, Duration::from_secs(60));
let errors = source.validate();
assert!(errors.contains(&DataSourceValidationError::PollIntervalNotAllowed));
}
#[test]
fn webhook_with_zero_interval_is_valid() {
let source = make_source(DataSourceType::Webhook, None, Duration::ZERO);
let errors = source.validate();
assert!(errors.is_empty());
}
#[test]
fn poll_based_source_requires_nonzero_interval() {
let source = make_source(DataSourceType::Weather, Some("https://api.weather.com"), Duration::ZERO);
let errors = source.validate();
assert!(errors.contains(&DataSourceValidationError::PollIntervalRequired));
}
#[test]
fn valid_poll_source_has_no_errors() {
let source = make_source(DataSourceType::Rss, Some("https://feed.example.com"), Duration::from_secs(300));
let errors = source.validate();
assert!(errors.is_empty());
}

View File

@@ -0,0 +1,33 @@
use std::collections::BTreeMap;
use domain::{KeyMapping, Value};
#[test]
fn extracts_value_at_path_and_renames_key() {
let mapping = KeyMapping {
source_path: "$.main.temp".into(),
target_key: "temperature".into(),
};
let raw = Value::Object(BTreeMap::from([
("main".into(), Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]))),
]));
let result = mapping.extract(&raw);
assert_eq!(result, Some(("temperature".into(), Value::Number(5.4))));
}
#[test]
fn returns_none_when_path_does_not_match() {
let mapping = KeyMapping {
source_path: "$.missing.path".into(),
target_key: "value".into(),
};
let raw = Value::Object(BTreeMap::from([
("other".into(), Value::Number(1.0)),
]));
assert_eq!(mapping.extract(&raw), None);
}

View File

@@ -0,0 +1,66 @@
use std::collections::BTreeSet;
use domain::{
ContainerNode, Direction, Layout, LayoutChild, LayoutNode, LayoutValidationError, Sizing,
WidgetId,
};
fn leaf(id: WidgetId) -> LayoutChild {
LayoutChild {
sizing: Sizing::Flex(1),
node: LayoutNode::Leaf(id),
}
}
fn row(children: Vec<LayoutChild>) -> LayoutNode {
LayoutNode::Container(ContainerNode {
direction: Direction::Row,
gap: 0,
padding: 0,
children,
})
}
#[test]
fn validate_returns_empty_when_all_widgets_exist() {
let layout = Layout { root: row(vec![leaf(1), leaf(2)]) };
let known = BTreeSet::from([1, 2]);
assert!(layout.validate(&known).is_empty());
}
#[test]
fn validate_reports_unknown_widget_ids() {
let layout = Layout { root: row(vec![leaf(1), leaf(99)]) };
let known = BTreeSet::from([1]);
let errors = layout.validate(&known);
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(99)]);
}
#[test]
fn validate_reports_empty_container() {
let layout = Layout { root: row(vec![]) };
let known = BTreeSet::new();
let errors = layout.validate(&known);
assert_eq!(errors, vec![LayoutValidationError::EmptyContainer]);
}
#[test]
fn validate_checks_nested_containers() {
let inner = LayoutChild {
sizing: Sizing::Flex(1),
node: row(vec![leaf(1), leaf(42)]),
};
let layout = Layout { root: row(vec![inner, leaf(2)]) };
let known = BTreeSet::from([1, 2]);
let errors = layout.validate(&known);
assert_eq!(errors, vec![LayoutValidationError::UnknownWidget(42)]);
}
#[test]
fn widget_ids_collects_all_leaf_ids() {
let inner = LayoutChild {
sizing: Sizing::Flex(1),
node: row(vec![leaf(3)]),
};
let layout = Layout { root: row(vec![leaf(1), inner, leaf(2)]) };
assert_eq!(layout.widget_ids(), BTreeSet::from([1, 2, 3]));
}

View File

@@ -0,0 +1,77 @@
use std::collections::BTreeMap;
use domain::Value;
#[test]
fn estimated_size_of_string_is_its_byte_length() {
let v = Value::String("hello".into());
assert_eq!(v.estimated_size(), 5);
}
#[test]
fn estimated_size_of_number_is_8_bytes() {
assert_eq!(Value::Number(3.14).estimated_size(), 8);
}
#[test]
fn estimated_size_of_null_and_bool_is_1() {
assert_eq!(Value::Null.estimated_size(), 1);
assert_eq!(Value::Bool(true).estimated_size(), 1);
}
#[test]
fn estimated_size_of_nested_structure_sums_recursively() {
let v = Value::Object(BTreeMap::from([
("key".into(), Value::String("value".into())),
("num".into(), Value::Number(1.0)),
]));
assert_eq!(v.estimated_size(), 19);
}
#[test]
fn estimated_size_of_array_sums_elements() {
let v = Value::Array(vec![
Value::String("abc".into()),
Value::Number(1.0),
]);
assert_eq!(v.estimated_size(), 11);
}
#[test]
fn get_path_returns_none_for_missing_key() {
let data = Value::Object(BTreeMap::from([
("main".into(), Value::Number(1.0)),
]));
assert_eq!(data.get_path("$.missing"), None);
}
#[test]
fn get_path_returns_none_when_traversing_non_object() {
let data = Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]));
assert_eq!(data.get_path("$.temp.nested"), None);
}
#[test]
fn get_path_accesses_array_by_index() {
let data = Value::Object(BTreeMap::from([
("items".into(), Value::Array(vec![
Value::String("first".into()),
Value::String("second".into()),
])),
]));
assert_eq!(
data.get_path("$.items[1]"),
Some(&Value::String("second".into()))
);
}
#[test]
fn get_path_traverses_nested_object() {
let data = Value::Object(BTreeMap::from([
("main".into(), Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]))),
]));
assert_eq!(data.get_path("$.main.temp"), Some(&Value::Number(5.4)));
}

View File

@@ -0,0 +1,110 @@
use std::collections::BTreeMap;
use domain::{DisplayHint, KeyMapping, Value, WidgetConfig};
#[test]
fn extract_applies_all_mappings_to_produce_widget_state() {
let config = WidgetConfig {
id: 1,
name: "weather".into(),
display_hint: DisplayHint::IconValue,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.main.temp".into(), target_key: "temperature".into() },
KeyMapping { source_path: "$.weather[0].icon".into(), target_key: "icon".into() },
],
max_data_size: 2048,
};
let raw = Value::Object(BTreeMap::from([
("main".into(), Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]))),
("weather".into(), Value::Array(vec![
Value::Object(BTreeMap::from([
("icon".into(), Value::String("cloud_rain".into())),
])),
])),
]));
let state = config.extract(&raw);
assert_eq!(state.data.get("temperature"), Some(&Value::Number(5.4)));
assert_eq!(state.data.get("icon"), Some(&Value::String("cloud_rain".into())));
assert_eq!(state.error, None);
}
#[test]
fn extract_truncates_string_values_exceeding_max_data_size() {
let long_text = "a".repeat(3000);
let config = WidgetConfig {
id: 1,
name: "news".into(),
display_hint: DisplayHint::TextBlock,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.text".into(), target_key: "body".into() },
],
max_data_size: 100,
};
let raw = Value::Object(BTreeMap::from([
("text".into(), Value::String(long_text)),
]));
let state = config.extract(&raw);
match state.data.get("body") {
Some(Value::String(s)) => assert!(s.len() <= 100),
other => panic!("expected truncated string, got {:?}", other),
}
}
#[test]
fn extract_respects_max_data_size_across_total_state() {
let config = WidgetConfig {
id: 1,
name: "big".into(),
display_hint: DisplayHint::TextBlock,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.a".into(), target_key: "a".into() },
KeyMapping { source_path: "$.b".into(), target_key: "b".into() },
KeyMapping { source_path: "$.c".into(), target_key: "c".into() },
],
max_data_size: 50,
};
let raw = Value::Object(BTreeMap::from([
("a".into(), Value::String("x".repeat(20))),
("b".into(), Value::String("y".repeat(20))),
("c".into(), Value::String("z".repeat(20))),
]));
let state = config.extract(&raw);
let total: usize = state.data.values().map(|v| v.estimated_size()).sum();
assert!(total <= 50, "total size {total} exceeds max 50");
}
#[test]
fn extract_skips_mappings_that_dont_match() {
let config = WidgetConfig {
id: 1,
name: "weather".into(),
display_hint: DisplayHint::IconValue,
data_source_id: 1,
mappings: vec![
KeyMapping { source_path: "$.temp".into(), target_key: "temperature".into() },
KeyMapping { source_path: "$.missing".into(), target_key: "gone".into() },
],
max_data_size: 2048,
};
let raw = Value::Object(BTreeMap::from([
("temp".into(), Value::Number(5.4)),
]));
let state = config.extract(&raw);
assert_eq!(state.data.len(), 1);
assert_eq!(state.data.get("temperature"), Some(&Value::Number(5.4)));
assert_eq!(state.data.get("gone"), None);
}