diff --git a/components/espcontrol/configuration_release_policy.h b/components/espcontrol/configuration_release_policy.h index dc515d047..f65985f17 100644 --- a/components/espcontrol/configuration_release_policy.h +++ b/components/espcontrol/configuration_release_policy.h @@ -12,10 +12,10 @@ namespace espcontrol::configuration { constexpr LegacyConfigurationMode PANEL_CONFIG_LEGACY_MODE = LegacyConfigurationMode::NATIVE_ONLY; constexpr std::array PANEL_CONFIG_STORAGE_READ_VERSIONS = {1, 2}; -constexpr uint16_t PANEL_CONFIG_DURABLE_WRITE_VERSION = 1; +constexpr uint16_t PANEL_CONFIG_DURABLE_WRITE_VERSION = 2; constexpr uint16_t PANEL_CONFIG_STORAGE_READ_NAVIGATION_DEPTH = 2; -constexpr uint16_t PANEL_CONFIG_STORAGE_WRITE_NAVIGATION_DEPTH = 1; -static_assert(PANEL_CONFIG_DURABLE_WRITE_VERSION == CURRENT_CONFIGURATION_DOCUMENT_VERSION); +constexpr uint16_t PANEL_CONFIG_STORAGE_WRITE_NAVIGATION_DEPTH = 2; +static_assert(PANEL_CONFIG_DURABLE_WRITE_VERSION == 1 || PANEL_CONFIG_DURABLE_WRITE_VERSION == 2); static_assert(PANEL_CONFIG_STORAGE_READ_NAVIGATION_DEPTH >= 1 && PANEL_CONFIG_STORAGE_READ_NAVIGATION_DEPTH <= 2); static_assert(PANEL_CONFIG_STORAGE_WRITE_NAVIGATION_DEPTH >= 1 && PANEL_CONFIG_STORAGE_WRITE_NAVIGATION_DEPTH <= PANEL_CONFIG_STORAGE_READ_NAVIGATION_DEPTH); diff --git a/components/espcontrol/panel_config_service_validator.h b/components/espcontrol/panel_config_service_validator.h index c73f7e18b..50660bf6c 100644 --- a/components/espcontrol/panel_config_service_validator.h +++ b/components/espcontrol/panel_config_service_validator.h @@ -6,7 +6,7 @@ namespace espcontrol::configuration { -// Ship both readers while the durable writer stays v1. Firmware supplies the +// Read both stored formats and save using the release policy. Firmware supplies the // same PSRAM-only temporary allocator as the service; no index is retained. class PanelConfigDocumentValidator final : public ConfigurationDocumentValidator { @@ -20,9 +20,11 @@ class PanelConfigDocumentValidator final document_version) != PANEL_CONFIG_STORAGE_READ_VERSIONS.end(); } bool supports_write_version(uint16_t version) const override { + // Flat layouts can still fit in v1 when their v2 representation exceeds + // the storage limit. Replacement admission separately protects nested pages. return version == PANEL_CONFIG_DURABLE_WRITE_VERSION || (version == 1 && supports_version(1) && PANEL_CONFIG_DURABLE_WRITE_VERSION == 2 && - PANEL_CONFIG_LEGACY_MODE == LegacyConfigurationMode::READ_IMPORT_ONLY); + PANEL_CONFIG_LEGACY_MODE != LegacyConfigurationMode::DUAL_WRITE); } uint16_t write_version() const override { return PANEL_CONFIG_DURABLE_WRITE_VERSION; } diff --git a/docs/features/subpages.md b/docs/features/subpages.md index 328430ac1..491d4f0db 100644 --- a/docs/features/subpages.md +++ b/docs/features/subpages.md @@ -29,7 +29,9 @@ To customise the **Back** card, select it in the web preview and click **Edit**. You can also right-click an empty space on the home screen and choose **Create Subpage**. -Subpages can contain Switch, Lights, Action, Local Action, Option Select, Webhook, Trigger, Sensor, Local Sensor, Doors & Windows, Presence, Slider, Fans, Vacuum, Lawn Mower, Cover, Garage Door, Lock, Alarm, Date & Time, Clock, World Clock, Weather, Camera, Media, Climate, Internal Switches, and Screen Lock cards. Subpages cannot contain another Subpage card. +Subpages can contain Switch, Lights, Action, Local Action, Option Select, Webhook, Trigger, Sensor, Local Sensor, Doors & Windows, Presence, Slider, Fans, Vacuum, Lawn Mower, Cover, Garage Door, Lock, Alarm, Date & Time, Clock, World Clock, Weather, Camera, Media, Climate, Internal Switches, and Screen Lock cards. + +The web editor offers **Subpage** as a card type inside a first-level subpage when the panel supports saving nested subpages. Use **Back** to return one level at a time. Firmware v2.17.0 can open saved second-level subpages. ## Automate Panel Navigation and Controls diff --git a/product/release_contract.json b/product/release_contract.json index 3ee1785b5..5351911a6 100644 --- a/product/release_contract.json +++ b/product/release_contract.json @@ -1,12 +1,12 @@ { "schemaVersion": 1, "productModelVersion": 2, - "panelConfigDocumentVersion": 1, + "panelConfigDocumentVersion": 2, "panelConfigReadVersions": [1, 2], - "panelConfigWriteVersion": 1, + "panelConfigWriteVersion": 2, "panelConfigReadNavigationDepth": 2, - "panelConfigWriteNavigationDepth": 1, - "panelConfigMinimumReaderRelease": null, + "panelConfigWriteNavigationDepth": 2, + "panelConfigMinimumReaderRelease": "v2.17.0", "webAssetVersion": 2, "panelConfigCompatibility": { "phase": "native-only", diff --git a/scripts/check_release_contract.py b/scripts/check_release_contract.py index e99cc3828..e5c94e688 100644 --- a/scripts/check_release_contract.py +++ b/scripts/check_release_contract.py @@ -20,7 +20,6 @@ DEVICE_MANIFEST = ROOT / "devices" / "manifest.json" WEB_MANIFEST = ROOT / "docs" / "public" / "webserver" / "web-assets.json" DOCUMENT_HEADER = ROOT / "components" / "espcontrol" / "panel_config_document.h" -SERVICE_HEADER = ROOT / "components" / "espcontrol" / "configuration_service.h" CAPABILITIES_HEADER = ROOT / "components" / "espcontrol" / "panel_config_capabilities.h" COMPATIBILITY_POLICY = ROOT / "components" / "espcontrol" / "configuration_release_policy.h" FIRMWARE_MODES = { @@ -172,7 +171,7 @@ def verify(*, product_model_path: Path = PRODUCT_MODEL, assert product_model["modelVersion"] == contract["productModelVersion"], ( "Product Model version disagrees with release contract" ) - document_version = constant(SERVICE_HEADER, "CURRENT_CONFIGURATION_DOCUMENT_VERSION") + document_version = constant(compatibility_policy_path, "PANEL_CONFIG_DURABLE_WRITE_VERSION") capabilities = CAPABILITIES_HEADER.read_text(encoding="utf-8") assert "PANEL_CONFIG_DURABLE_WRITE_VERSION" in capabilities, ( "firmware capabilities do not advertise the PanelConfig document version" @@ -183,7 +182,7 @@ def verify(*, product_model_path: Path = PRODUCT_MODEL, assert document_version == contract["panelConfigDocumentVersion"], ( "PanelConfig document version disagrees with release contract" ) - assert constant(compatibility_policy_path, "PANEL_CONFIG_DURABLE_WRITE_VERSION") == document_version == contract.get("panelConfigWriteVersion"), ( + assert document_version == contract.get("panelConfigWriteVersion"), ( "durable write policy disagrees with release contract" ) assert constant(compatibility_policy_path, "PANEL_CONFIG_STORAGE_READ_NAVIGATION_DEPTH") == read_depth and \ @@ -236,6 +235,7 @@ def self_test() -> None: future = json.loads(json.dumps(contract)) future["panelConfigCompatibility"]["phase"] = "dual-write" future["panelConfigDocumentVersion"] = future["panelConfigWriteVersion"] = 2 + future["panelConfigWriteNavigationDepth"] = 1 for floor, history, expected in [ (None, [], False), ("v2.10.0", [], False), @@ -253,7 +253,7 @@ def self_test() -> None: read_import_contract = json.loads(json.dumps(contract)) read_import_contract["panelConfigCompatibility"]["phase"] = "read-import-only" read_import_contract.update(panelConfigDocumentVersion=2, panelConfigWriteVersion=2, - panelConfigMinimumReaderRelease="v2.10.0") + panelConfigWriteNavigationDepth=1, panelConfigMinimumReaderRelease="v2.10.0") def published(phase: str, tag: str) -> dict: manifest_contract = json.loads(json.dumps(read_import_contract)) @@ -309,6 +309,8 @@ def published(phase: str, tag: str) -> dict: native_only_policy = native_only_contract["panelConfigCompatibility"] native_only_policy["phase"] = "native-only" native_only_policy["legacyGatewayRelease"] = "v2.15.0" + native_only_contract.update(panelConfigDocumentVersion=1, panelConfigWriteVersion=1, + panelConfigWriteNavigationDepth=1, panelConfigMinimumReaderRelease=None) def published_v1(phase: str, tag: str) -> dict: release = published(phase, tag) release["manifest"]["releaseContract"].update( diff --git a/tests/firmware/panel_config_capabilities_test.cpp b/tests/firmware/panel_config_capabilities_test.cpp index c5a01db7d..8ccbbf118 100644 --- a/tests/firmware/panel_config_capabilities_test.cpp +++ b/tests/firmware/panel_config_capabilities_test.cpp @@ -46,9 +46,9 @@ int main() { &capabilities_size) && std::strstr(capabilities.data(), "\"document_versions\":[1,2]") != nullptr && std::strstr(capabilities.data(), "\"default_document_version\":1") != nullptr && - std::strstr(capabilities.data(), "\"durable_document_version\":1") != nullptr && + std::strstr(capabilities.data(), "\"durable_document_version\":2") != nullptr && std::strstr(capabilities.data(), "\"max_navigation_depth\":2") != nullptr && - std::strstr(capabilities.data(), "\"writable_navigation_depth\":1") != nullptr && + std::strstr(capabilities.data(), "\"writable_navigation_depth\":2") != nullptr && std::strstr(capabilities.data(), "\"max_v2_document_bytes\":524288") != nullptr && std::strstr(capabilities.data(), "\"preserves_inactive_records\":true") != nullptr && std::strstr(capabilities.data(), "\"read\":true") != nullptr && diff --git a/tests/firmware/panel_config_dual_boot_test.cpp b/tests/firmware/panel_config_dual_boot_test.cpp index 8cf58b377..45ff29478 100644 --- a/tests/firmware/panel_config_dual_boot_test.cpp +++ b/tests/firmware/panel_config_dual_boot_test.cpp @@ -11,11 +11,12 @@ #include "page_store_runtime.h" #include "panel_config_legacy_adapter.h" #include "panel_config_runtime_adapter.h" -#include "panel_config_service_validator.h" +#include "panel_config_test_policies.h" using namespace espcontrol; using namespace espcontrol::configuration; using namespace espcontrol::pages; +using espcontrol::configuration::test::DepthOnePanelConfigPolicy; using Bytes=std::vector; using Row=PanelConfigV2Record; using Kind=PanelConfigV2Kind; @@ -93,7 +94,7 @@ struct Fixture { Backend backend;ConfigurationStore store{backend};Text order,color; std::array buttons;std::array,32> chunks; PanelConfigTextBindings bindings;PanelConfigLegacyAdapter legacy{bindings,allocate,release}; - PanelConfigDocumentValidator validator{allocate,release};ConfigurationService service{store,legacy,&validator}; + DepthOnePanelConfigPolicy<1> validator{allocate,release};ConfigurationService service{store,legacy,&validator}; Arena arena;PageStoreRuntime runtime; explicit Fixture(const DeviceUiLimits &limits):runtime(limits,arena,128*1024) { bindings.set_device_profile(limits.device_profile);bindings.set_button_order(&order);bindings.set_button_on_color(&color); @@ -303,7 +304,7 @@ void imports_cannot_enable_v2_writes() { bool mirror(uint16_t,const uint8_t *,size_t)override {assert(false);return false;} } legacy; legacy.document=native(DEVICE_UI_PROFILES[8],false); - Backend backend;ConfigurationStore store(backend);PanelConfigDocumentValidator validator(allocate,release); + Backend backend;ConfigurationStore store(backend);DepthOnePanelConfigPolicy<1> validator(allocate,release); ConfigurationService service(store,legacy,&validator);Bytes output(32768); assert(validator.supports_version(2)&&!validator.supports_write_version(2)); assert(service.load(output.data(),output.size()).status==ServiceStatus::UNSUPPORTED_VERSION); @@ -317,5 +318,5 @@ int main() { publication_repair_and_transient_buffers(); permanent_legacy_limit_does_not_retry_writes(); profiles();unavailable_and_publication();imports_cannot_enable_v2_writes();assert(allocations.empty()); - std::cout<<"PASS actual ECDO v2 boot, v1 write policy, all nine ordinary/maximum profiles, inactive/empty preservation, compatibility fencing and allocation failures; transient service/compatibility peak="< renderer(const DeviceUiLimits& limits,Aren default:assert(false);return {}; } } -// Test-only future policy. Stable product policy remains the declared v1 writer. -struct FutureGraphWriter:ConfigurationDocumentValidator { - PanelConfigDocumentValidator content{allocate,release}; - bool supports_version(uint16_t version)const override{return content.supports_version(version);} - uint16_t write_version()const override{return 2;} - bool supports_write_version(uint16_t version)const override{return version==1||version==2;} - bool checks_replacements(uint16_t version)const override{return content.checks_replacements(version);} - bool replacement_needs_document(uint16_t current,uint16_t incoming)const override{return content.replacement_needs_document(current,incoming);} - ServiceStatus replacement_status(uint16_t current,const uint8_t*bytes,size_t size,uint16_t incoming)const override { - return content.replacement_status(current,bytes,size,incoming); - } - bool validate(uint16_t version,const uint8_t*bytes,size_t size)const override{return content.validate(version,bytes,size);} - ServiceStatus validation_status(uint16_t version,const uint8_t*bytes,size_t size)const override{return content.validation_status(version,bytes,size);} -}; -struct FutureFlatWriter:FutureGraphWriter { - ServiceStatus write_validation_status(uint16_t version,const uint8_t*bytes,size_t size)const override { - return content.write_validation_status(version,bytes,size); - } -}; +using espcontrol::configuration::test::DepthOnePanelConfigPolicy; struct Fixture { - Backend backend;ConfigurationStore store{backend};Legacy legacy;PanelConfigDocumentValidator validator{allocate,release}; + Backend backend;ConfigurationStore store{backend};Legacy legacy;DepthOnePanelConfigPolicy<1> validator{allocate,release}; ConfigurationService service;ConfigurationMainLoop queue;Arena arena; RendererPort port;std::unique_ptr render_resources;PageRuntimeResourcesGroup<1> resources; PageStoreRuntime runtime;PanelConfigReadHandler reader;PanelConfigWriteHandler writer; explicit Fixture(const DeviceUiLimits &limits,const ConfigurationDocumentValidator*policy=nullptr, LegacyConfigurationMode mode=LegacyConfigurationMode::DUAL_WRITE):legacy(limits), - service(store,legacy,policy?policy:&validator,nullptr,0,mode),port(limits),render_resources(renderer(limits,arena,port)), + service(store,legacy,policy ? policy : &validator,nullptr,0,mode),port(limits),render_resources(renderer(limits,arena,port)), resources({{render_resources.get()}}),runtime(limits,arena,128*1024,&resources) { service.set_runtime_adapter(&runtime); bind_panel_config_http_context(service,queue,40*1024,allocate,release,"user","password"); @@ -603,7 +585,7 @@ void oversized_flat_v2_uses_lossless_durable_v1() { }(); assert(source.size() < 40932 && v2.size() > 40932); for (const char *format : {"1", "2"}) { - FutureGraphWriter policy; + PanelConfigDocumentValidator policy{allocate,release}; Fixture f(DEVICE_UI_PROFILES[4], &policy, LegacyConfigurationMode::READ_IMPORT_ONLY); const auto &input = *format == '1' ? source : v2; const auto saved = f.put(input, format, *format == '1' ? "\"1\"" : "\"v2-1\""); @@ -638,14 +620,14 @@ void oversized_flat_v2_uses_lossless_durable_v1() { } void original_format_survives_a_future_writer_conversion() { { - FutureGraphWriter policy;Fixture fixture(DEVICE_UI_PROFILES[8],&policy); + PanelConfigDocumentValidator policy{allocate,release};Fixture fixture(DEVICE_UI_PROFILES[8],&policy); const auto old=fixture.get("1").response; const auto saved=fixture.put(old,nullptr,"\"1\""); assert(status(saved)==204&&saved.sent_headers.at("X-Panel-Config-Durable-Version")=="2"); assert(records(fixture.get("1").response)==records(old)); } for(bool restored:{false,true}) { - FutureGraphWriter policy;Fixture fixture(DEVICE_UI_PROFILES[8],&policy); + PanelConfigDocumentValidator policy{allocate,release};Fixture fixture(DEVICE_UI_PROFILES[8],&policy); const auto old=fixture.get("1").response,old_v2=fixture.get("2").response; const auto nested=nested_document();fixture.seed_v2(nested); if(restored) { @@ -670,7 +652,7 @@ void original_format_survives_a_future_writer_conversion() { assert(fixture.get("2").response==old_v2&&fixture.runtime.active().generation()==3); } for(bool http:{false,true}) { - FutureGraphWriter policy;Fixture fixture(DEVICE_UI_PROFILES[8],&policy); + PanelConfigDocumentValidator policy{allocate,release};Fixture fixture(DEVICE_UI_PROFILES[8],&policy); const auto old=fixture.get("1").response,old_v2=fixture.get("2").response; const auto nested=nested_document();bool replaced=false; const auto preferences=fixture.legacy.preference_writes(); @@ -682,7 +664,7 @@ void original_format_survives_a_future_writer_conversion() { } } void native_graph_publication_returns_success() { - FutureGraphWriter policy; + PanelConfigDocumentValidator policy{allocate,release}; Fixture fixture(DEVICE_UI_PROFILES[8],&policy,LegacyConfigurationMode::READ_IMPORT_ONLY); const auto old=fixture.get("1").response; const auto source=nested_document(); @@ -715,7 +697,7 @@ void native_graph_publication_returns_success() { assert(!fixture.service.compatibility_state().retry_pending()); } void flat_v2_writer_rejects_nested_http_publication() { - FutureFlatWriter policy; + DepthOnePanelConfigPolicy<2> policy{allocate,release}; Fixture fixture(DEVICE_UI_PROFILES[8],&policy,LegacyConfigurationMode::READ_IMPORT_ONLY); const auto original=fixture.get("2").response; const auto nested=nested_document(); diff --git a/tests/firmware/panel_config_legacy_writer_test.cpp b/tests/firmware/panel_config_legacy_writer_test.cpp index 80e1fd185..a56b1aa75 100644 --- a/tests/firmware/panel_config_legacy_writer_test.cpp +++ b/tests/firmware/panel_config_legacy_writer_test.cpp @@ -9,7 +9,7 @@ #include #include "panel_config_legacy_adapter.h" -#include "panel_config_service_validator.h" +#include "panel_config_test_policies.h" #include "panel_config_compatibility_view.h" #include "nested_page_fixture.h" #include "durable_format_fixture.h" @@ -70,26 +70,7 @@ struct Runtime : ConfigurationRuntimeAdapter { version = format; active.assign(data, data + size); ++activations; return true; } }; -// Exercise the next policy through the real validator, without enabling it in -// the production release contract or weakening replacement admission. -struct FutureWriter : ConfigurationDocumentValidator { - PanelConfigDocumentValidator content{allocate, release}; - bool supports_version(uint16_t v) const override { return content.supports_version(v); } - uint16_t write_version() const override { return 2; } - bool supports_write_version(uint16_t v) const override { return v == 1 || v == 2; } - bool checks_replacements(uint16_t v) const override { return content.checks_replacements(v); } - bool replacement_needs_document(uint16_t current, uint16_t incoming) const override { return content.replacement_needs_document(current, incoming); } - ServiceStatus replacement_status(uint16_t current, const uint8_t* data, size_t size, uint16_t incoming) const override { return content.replacement_status(current, data, size, incoming); } - bool validate(uint16_t v, const uint8_t* data, size_t size) const override { return content.validate(v, data, size); } - ServiceStatus validation_status(uint16_t v, const uint8_t* data, size_t size) const override { return content.validation_status(v, data, size); } -}; -// Select the future v2 storage format while retaining the real product's -// declared depth-one write validation and depth-two reader. -struct FlatFutureWriter : FutureWriter { - ServiceStatus write_validation_status(uint16_t version, const uint8_t* data, size_t size) const override { - return content.write_validation_status(version, data, size); - } -}; +using espcontrol::configuration::test::DepthOnePanelConfigPolicy; struct Fixture { Backend backend; ConfigurationStore store{backend}; @@ -97,11 +78,11 @@ struct Fixture { PanelConfigTextBindings bindings; PanelConfigLegacyAdapter legacy{bindings, allocate, release}; Runtime runtime; - PanelConfigDocumentValidator stable{allocate, release}; - FutureWriter future; + DepthOnePanelConfigPolicy<1> stable{allocate, release}; + PanelConfigDocumentValidator writer{allocate, release}; ConfigurationService service; explicit Fixture(const DeviceUiLimits& limits, bool next = true) - : service(store, legacy, next ? static_cast(&future) : &stable, + : service(store, legacy, next ? static_cast(&writer) : &stable, nullptr, 0, next ? LegacyConfigurationMode::READ_IMPORT_ONLY : LegacyConfigurationMode::DUAL_WRITE) { bindings.set_device_profile(limits.device_profile); bindings.set_button_order(&order); @@ -209,7 +190,7 @@ void large_legacy_bootstrap(size_t roots, size_t slot_capacity) { auto expected = records(original, 1); expected[std::to_string(int(PanelConfigRecordType::SETTING)) + ":0:button_on_color"] = "AABBCC"; assert(records(read(f), 1) == expected && f.runtime.version == 1); - ConfigurationService reboot(f.store, f.legacy, &f.future, nullptr, 0, LegacyConfigurationMode::READ_IMPORT_ONLY); + ConfigurationService reboot(f.store, f.legacy, &f.writer, nullptr, 0, LegacyConfigurationMode::READ_IMPORT_ONLY); reboot.set_buffer_allocator(allocate, release); reboot.set_runtime_adapter(&f.runtime); const auto booted = reboot.load_and_apply_runtime(output.data(), output.size()); assert(booted.ok() && booted.document_version == 1 && booted.generation == edited.generation); @@ -270,7 +251,7 @@ void preserve_flat_native(const DeviceUiLimits& limits) { // A fresh service instance reads the native snapshot; it must not import // stale preferences or rewrite native IDs/order during boot. f.order.state = "stale"; f.color.state = "stale"; f.button.state = "stale"; - ConfigurationService reboot(f.store, f.legacy, &f.future, nullptr, 0, LegacyConfigurationMode::READ_IMPORT_ONLY); + ConfigurationService reboot(f.store, f.legacy, &f.writer, nullptr, 0, LegacyConfigurationMode::READ_IMPORT_ONLY); reboot.set_buffer_allocator(allocate, release); reboot.set_runtime_adapter(&f.runtime); const auto writes_after = f.backend.writes; @@ -422,7 +403,7 @@ void native_global_publication(const DeviceUiLimits& limits) { assert(f.service.retry_compatibility(output.data(), output.size()).ok()); assert(f.backend.writes == writes && read(f) == original); f.order.state = "stale"; f.color.state = "stale"; - ConfigurationService reboot(f.store, f.legacy, &f.future, nullptr, 0, LegacyConfigurationMode::READ_IMPORT_ONLY); + ConfigurationService reboot(f.store, f.legacy, &f.writer, nullptr, 0, LegacyConfigurationMode::READ_IMPORT_ONLY); reboot.set_buffer_allocator(allocate, release); reboot.set_runtime_adapter(&f.runtime); const auto boot = reboot.load_and_apply_runtime(output.data(), output.size()); @@ -446,7 +427,7 @@ void native_global_publication(const DeviceUiLimits& limits) { assert(f.order.writes == 0 && f.color.writes == 0 && f.button.writes == 0 && child.writes == 0); // Releases still promising a complete downgrade mirror continue to reject // this layout before any durable publication. - ConfigurationService dual(f.store, f.legacy, &f.future); + ConfigurationService dual(f.store, f.legacy, &f.writer); dual.set_runtime_adapter(&f.runtime); dual.set_buffer_allocator(allocate, release); assert(dual.save(2, recolored.data(), recolored.size()).status == ServiceStatus::CAPACITY_EXCEEDED); @@ -524,7 +505,7 @@ void flat_writer_preserves_nested_reading(const DeviceUiLimits& limits) { const auto nested = wire(nested_globals(limits)); assert(f.service.save(2, nested.data(), nested.size()).ok()); const auto writes = f.backend.writes; - FlatFutureWriter policy; + DepthOnePanelConfigPolicy<2> policy{allocate, release}; ConfigurationService service(f.store, f.legacy, &policy, nullptr, 0, LegacyConfigurationMode::READ_IMPORT_ONLY); service.set_buffer_allocator(allocate, release); service.set_runtime_adapter(&f.runtime); diff --git a/tests/firmware/panel_config_test_policies.h b/tests/firmware/panel_config_test_policies.h new file mode 100644 index 000000000..b623d135f --- /dev/null +++ b/tests/firmware/panel_config_test_policies.h @@ -0,0 +1,45 @@ +#pragma once + +#include "panel_config_service_validator.h" + +namespace espcontrol::configuration::test { + +// Model the earlier readers independently of the current release policy. +template +class DepthOnePanelConfigPolicy final : public ConfigurationDocumentValidator { + public: + DepthOnePanelConfigPolicy(ConfigurationBuffer::Allocate allocate, + ConfigurationBuffer::Release release) + : content_(allocate, release) {} + + bool supports_version(uint16_t version) const override { return content_.supports_version(version); } + bool supports_write_version(uint16_t version) const override { + return version == 1 || version == WriteVersion; + } + uint16_t write_version() const override { return WriteVersion; } + + bool validate(uint16_t version, const uint8_t *data, size_t size) const override { + return content_.validate(version, data, size); + } + ServiceStatus validation_status(uint16_t version, const uint8_t *data, size_t size) const override { + return content_.validation_status(version, data, size); + } + ServiceStatus write_validation_status(uint16_t version, const uint8_t *data, size_t size) const override { + if (version == 2) return content_.replacement_status(2, data, size, 1); + return content_.validation_status(version, data, size); + } + + bool checks_replacements(uint16_t incoming) const override { return content_.checks_replacements(incoming); } + bool replacement_needs_document(uint16_t current, uint16_t incoming) const override { + return content_.replacement_needs_document(current, incoming); + } + ServiceStatus replacement_status(uint16_t current, const uint8_t *data, size_t size, + uint16_t incoming) const override { + return content_.replacement_status(current, data, size, incoming); + } + + private: + PanelConfigDocumentValidator content_; +}; + +} // namespace espcontrol::configuration::test