重整cmake

This commit is contained in:
2026-08-11 15:11:56 +08:00
parent 5401a14708
commit 274dd4c044
12 changed files with 307 additions and 157 deletions
+65 -22
View File
@@ -76,6 +76,11 @@ nlohmann::json patch_controls(Gallery_Plot_Session& session, nlohmann::json patc
Gallery_Request_Kind::Patch, request.dump())));
}
void send_client_feedback(Gallery_Plot_Session& session, std::string_view encoded) {
EXPECT_FALSE(session.handle(gallery_request(
Gallery_Request_Kind::Feedback, std::string(encoded))).has_value());
}
template <class Predicate>
bool wait_for_condition(Predicate&& predicate,
std::chrono::milliseconds timeout = std::chrono::milliseconds(750)) {
@@ -147,6 +152,10 @@ TEST(RenderiveWebBridge, DecodesOnlyEventMessages) {
R"({"category":"event","type":"gallery_refresh"})");
ASSERT_TRUE(refresh.has_value());
EXPECT_EQ(std::get<Gallery_Request>(*refresh).kind, Gallery_Request_Kind::Refresh);
const auto feedback = Web_Event_Adapter::decode(
R"({"category":"event","type":"gallery_feedback","client_metrics":{}})");
ASSERT_TRUE(feedback.has_value());
EXPECT_EQ(std::get<Gallery_Request>(*feedback).kind, Gallery_Request_Kind::Feedback);
const auto bounded = Web_Event_Adapter::decode(
R"({"category":"event","type":"resize","width":1e100,"height":-1e100})");
@@ -191,6 +200,7 @@ TEST(RenderiveWebGallery, AdminiveCatalogCoversEveryControlCaseAndThreeModes) {
EXPECT_EQ(catalog.at("category"), "gallery");
EXPECT_EQ(catalog.at("type"), "catalog");
EXPECT_EQ(catalog.at("protocol"), "renderive.control-gallery");
EXPECT_EQ(catalog.at("protocol_version"), 4);
EXPECT_EQ(catalog.at("case_descriptor").at("protocol"), "adminive.resource");
EXPECT_EQ(catalog.at("cases").size(), 8U);
EXPECT_EQ(catalog.at("frame_modes").size(), 3U);
@@ -310,6 +320,8 @@ TEST(RenderiveWebGallery, EveryPublishedControlValidatesItsCompleteInputContract
EXPECT_TRUE(ids.insert(id).second);
EXPECT_FALSE(control.at("api").get<std::string>().empty());
EXPECT_FALSE(control.at("group").get<std::string>().empty());
const auto& amis = control.at("amis");
EXPECT_EQ(amis.at("name"), id);
const std::string input = control.at("input");
const auto apply = [&](const nlohmann::json& value) {
@@ -325,16 +337,28 @@ TEST(RenderiveWebGallery, EveryPublishedControlValidatesItsCompleteInputContract
};
if (input == "boolean") {
EXPECT_EQ(amis.at("type"), "switch");
const bool alternative = !control.at("value").get<bool>();
const auto accepted = apply(alternative);
ASSERT_TRUE(accepted.candidate.has_value());
EXPECT_EQ(std::get<bool>(accepted.candidate->values.at(id)), alternative);
expect_rejected(1);
} else if (input == "number") {
EXPECT_EQ(amis.at("type"), "input-number");
EXPECT_TRUE(amis.at("required").get<bool>());
const double minimum = control.at("minimum");
const double maximum = control.at("maximum");
const double current = control.at("value");
const double step = std::max(control.at("step").get<double>(), 1e-9);
EXPECT_DOUBLE_EQ(amis.at("min"), minimum);
EXPECT_DOUBLE_EQ(amis.at("max"), maximum);
EXPECT_DOUBLE_EQ(amis.at("step"), control.at("step").get<double>());
EXPECT_DOUBLE_EQ(amis.at("validations").at("minimum"), minimum);
EXPECT_DOUBLE_EQ(amis.at("validations").at("maximum"), maximum);
if (control.at("integer").get<bool>()) {
EXPECT_EQ(amis.at("precision"), 0);
EXPECT_TRUE(amis.at("validations").at("isInt").get<bool>());
}
double alternative = current + step;
if (alternative > maximum)
alternative = current - step;
@@ -356,7 +380,11 @@ TEST(RenderiveWebGallery, EveryPublishedControlValidatesItsCompleteInputContract
expect_rejected(std::clamp(std::floor(current) + 0.5,
minimum + 0.5, maximum - 0.5));
} else if (input == "select") {
EXPECT_EQ(amis.at("type"), "select");
EXPECT_TRUE(amis.at("required").get<bool>());
EXPECT_FALSE(amis.at("clearable").get<bool>());
const auto& options = control.at("options");
EXPECT_EQ(amis.at("options").size(), options.size());
ASSERT_FALSE(options.empty());
const std::string current = control.at("value");
const auto alternative = std::find_if(
@@ -371,6 +399,10 @@ TEST(RenderiveWebGallery, EveryPublishedControlValidatesItsCompleteInputContract
expect_rejected("__invalid_gallery_option__");
expect_rejected(7);
} else if (input == "color") {
EXPECT_EQ(amis.at("type"), "input-color");
EXPECT_TRUE(amis.at("required").get<bool>());
EXPECT_FALSE(amis.at("clearable").get<bool>());
EXPECT_EQ(amis.at("validations").at("matchRegexp"), "^#[0-9A-Fa-f]{6}$");
const std::string value = control.at("value") == "#123456" ?
"#654321" : "#123456";
const auto accepted = apply(value);
@@ -380,6 +412,8 @@ TEST(RenderiveWebGallery, EveryPublishedControlValidatesItsCompleteInputContract
expect_rejected(7);
} else {
ASSERT_EQ(input, "text");
EXPECT_EQ(amis.at("type"), "input-text");
EXPECT_EQ(amis.at("validations").at("maxLength"), 160);
std::string value = control.at("value").get<std::string>() + "_qa";
const auto accepted = apply(value);
ASSERT_TRUE(accepted.candidate.has_value());
@@ -415,6 +449,13 @@ TEST(RenderiveWebGallery, EveryPublishedActionDispatchesToItsCanvasAndFrameMode)
EXPECT_TRUE(ids.insert(id).second);
EXPECT_FALSE(action.at("api").get<std::string>().empty());
EXPECT_FALSE(action.at("group").get<std::string>().empty());
const std::string argument_input = action.at("argument_input");
if (!argument_input.empty()) {
const auto& amis = action.at("argument_amis");
EXPECT_EQ(amis.at("name"), "action_" + id);
EXPECT_TRUE(amis.at("required").get<bool>());
EXPECT_EQ(amis.at("type"), argument_input == "number" ? "input-number" : "input-text");
}
Gallery_Plot_Session session;
ASSERT_EQ(response_json(session.handle(gallery_request(
@@ -796,6 +837,7 @@ TEST(RenderiveWebGallery, BackendPublishesAmisValidationSchemas) {
ASSERT_NE(max_fps, controls.end());
const auto& max_fps_amis = max_fps->at("amis");
EXPECT_EQ(max_fps_amis.at("type"), "input-number");
EXPECT_TRUE(max_fps_amis.at("required").get<bool>());
EXPECT_DOUBLE_EQ(max_fps_amis.at("min").get<double>(), 0.01);
EXPECT_DOUBLE_EQ(max_fps_amis.at("max").get<double>(), 1'000'000'000.0);
EXPECT_DOUBLE_EQ(max_fps_amis.at("validations").at("minimum").get<double>(), 0.01);
@@ -804,6 +846,8 @@ TEST(RenderiveWebGallery, BackendPublishesAmisValidationSchemas) {
return item.at("id") == "background_color";
});
ASSERT_NE(background, controls.end());
EXPECT_TRUE(background->at("amis").at("required").get<bool>());
EXPECT_FALSE(background->at("amis").at("clearable").get<bool>());
EXPECT_EQ(background->at("amis").at("validations").at("matchRegexp"),
"^#[0-9A-Fa-f]{6}$");
const auto patched = Gallery_Protocol::apply_patch(
@@ -825,6 +869,7 @@ TEST(RenderiveWebGallery, BackendPublishesAmisValidationSchemas) {
const auto& burst_amis = burst->at("argument_amis");
EXPECT_EQ(burst_amis.at("type"), "input-number");
EXPECT_EQ(burst_amis.at("name"), "action_mode_enqueue_burst");
EXPECT_TRUE(burst_amis.at("required").get<bool>());
}
TEST(RenderiveWebGallery, ActionsMutateLiveCore2ObjectsAndReturnTelemetry) {
@@ -1082,10 +1127,10 @@ TEST(RenderiveWebGallery, ConsumerFeedbackCannotBeBypassedByForegroundReschedule
{"frequency_limit_enabled", false},
{"consumer_feedback_enabled", true}
}).at("type"), "case_state");
auto observed = response_json(session.handle(gallery_request(
Gallery_Request_Kind::Refresh,
R"({"category":"event","type":"gallery_refresh","client_metrics":{"transport_fps":25,"presentation_fps":25,"websocket_buffered_bytes":0,"changed_pixel_frames":1,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":5,"display_interval_ms":40,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})")));
auto observer = observed.at("telemetry").at("kernel_observer");
send_client_feedback(session,
R"({"category":"event","type":"gallery_feedback","client_metrics":{"transport_fps":25,"presentation_fps":25,"websocket_buffered_bytes":0,"changed_pixel_frames":1,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":5,"display_interval_ms":40,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})");
auto observed = refresh_telemetry(session);
auto observer = observed.at("kernel_observer");
EXPECT_FALSE(observer.at("frequency_limit_enabled").get<bool>());
EXPECT_TRUE(observer.at("consumer_feedback_enabled").get<bool>());
EXPECT_EQ(observer.at("consumer_interval_ns"), 40'000'000);
@@ -1121,11 +1166,11 @@ TEST(RenderiveWebGallery, WebRuntimeMetricsPublishKernelSmoothedConsumerFeedback
Gallery_Request_Kind::Patch,
R"({"category":"event","type":"gallery_patch","patch":{"max_render_fps":1000000000}})"))).at("type"),
"case_state");
auto observed = response_json(session.handle(gallery_request(
Gallery_Request_Kind::Refresh,
R"({"category":"event","type":"gallery_refresh","client_metrics":{"transport_fps":50,"presentation_fps":50,"websocket_buffered_bytes":0,"changed_pixel_frames":10,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":80,"display_interval_ms":20,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})")));
auto observer = observed.at("telemetry").at("kernel_observer");
auto limit = observed.at("telemetry").at("low_latency_limit");
send_client_feedback(session,
R"({"category":"event","type":"gallery_feedback","client_metrics":{"transport_fps":50,"presentation_fps":50,"websocket_buffered_bytes":0,"changed_pixel_frames":10,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":80,"display_interval_ms":20,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})");
auto observed = refresh_telemetry(session);
auto observer = observed.at("kernel_observer");
auto limit = observed.at("low_latency_limit");
EXPECT_TRUE(observer.at("frequency_limit_enabled").get<bool>());
EXPECT_TRUE(observer.at("consumer_feedback_enabled").get<bool>());
EXPECT_EQ(observer.at("consumer_sample_interval_ns"), 20'000'000);
@@ -1135,10 +1180,10 @@ TEST(RenderiveWebGallery, WebRuntimeMetricsPublishKernelSmoothedConsumerFeedback
EXPECT_EQ(observer.at("consumer_interval_ns"), 20'000'000);
EXPECT_EQ(observer.at("limit_state"), "consumer_limited");
EXPECT_EQ(limit.at("consumer_feedback_source"), "presentation");
observed = response_json(session.handle(gallery_request(
Gallery_Request_Kind::Refresh,
R"({"category":"event","type":"gallery_refresh","client_metrics":{"transport_fps":45,"presentation_fps":45,"websocket_buffered_bytes":0,"changed_pixel_frames":20,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":4,"display_interval_ms":22,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})")));
observer = observed.at("telemetry").at("kernel_observer");
send_client_feedback(session,
R"({"category":"event","type":"gallery_feedback","client_metrics":{"transport_fps":45,"presentation_fps":45,"websocket_buffered_bytes":0,"changed_pixel_frames":20,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":4,"display_interval_ms":22,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})");
observed = refresh_telemetry(session);
observer = observed.at("kernel_observer");
EXPECT_EQ(observer.at("consumer_sample_interval_ns"), 22'000'000);
EXPECT_EQ(observer.at("consumer_smoothed_interval_ns"), 21'000'000);
EXPECT_EQ(observer.at("consumer_variation_ns"), 125'000);
@@ -1173,10 +1218,10 @@ TEST(RenderiveWebGallery, ConsumerFeedbackSourcesCanBeSelectedIndependentlyAndMa
{"consumer_presentation_feedback_enabled", false},
{"consumer_manual_feedback_enabled", false}
}).at("type"), "case_state");
auto observed = response_json(session.handle(gallery_request(
Gallery_Request_Kind::Refresh,
R"({"category":"event","type":"gallery_refresh","client_metrics":{"transport_fps":25,"presentation_fps":60,"websocket_buffered_bytes":0,"changed_pixel_frames":1,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":5,"display_interval_ms":16,"display_interval_latest_ms":16,"display_interval_p95_ms":17,"display_jitter_ms":1,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})")));
auto observer = observed.at("telemetry").at("kernel_observer");
send_client_feedback(session,
R"({"category":"event","type":"gallery_feedback","client_metrics":{"transport_fps":25,"presentation_fps":60,"websocket_buffered_bytes":0,"changed_pixel_frames":1,"duplicate_pixel_frames":0,"frame_request_timeout_count":0,"frame_round_trip_ms":5,"display_interval_ms":16,"display_interval_latest_ms":16,"display_interval_p95_ms":17,"display_jitter_ms":1,"overwritten_pixel_frames":0,"last_pixel_receive_age_ms":1,"last_pixel_change_age_ms":1}})");
auto observed = refresh_telemetry(session);
auto observer = observed.at("kernel_observer");
EXPECT_EQ(observer.at("consumer_feedback_source"), "pixel");
EXPECT_EQ(observer.at("consumer_pixel_interval_ns"), 40'000'000);
EXPECT_EQ(observer.at("consumer_presentation_interval_ns"), 16'000'000);
@@ -1290,11 +1335,9 @@ TEST(RenderiveWebGallery, ProductionLowLatencySessionRendersWithoutPixelPulls) {
ASSERT_TRUE(wait_for_condition([&session] {
return successful_render_count(session) >= 4;
}));
const auto observed = session.handle(gallery_request(
Gallery_Request_Kind::Refresh,
R"({"category":"event","type":"gallery_refresh","client_metrics":{"transport_fps":120,"presentation_fps":60,"websocket_buffered_bytes":0,"changed_pixel_frames":17,"duplicate_pixel_frames":3,"frame_request_timeout_count":2,"frame_round_trip_ms":4.5,"display_interval_ms":16.7,"display_interval_latest_ms":16.9,"display_interval_p95_ms":17.4,"display_jitter_ms":0.7,"overwritten_pixel_frames":5,"last_pixel_receive_age_ms":8.5,"last_pixel_change_age_ms":12.5}})"));
ASSERT_TRUE(observed.has_value());
const auto telemetry = parse_json(observed->payload).at("telemetry");
send_client_feedback(session,
R"({"category":"event","type":"gallery_feedback","client_metrics":{"transport_fps":120,"presentation_fps":60,"websocket_buffered_bytes":0,"changed_pixel_frames":17,"duplicate_pixel_frames":3,"frame_request_timeout_count":2,"frame_round_trip_ms":4.5,"display_interval_ms":16.7,"display_interval_latest_ms":16.9,"display_interval_p95_ms":17.4,"display_jitter_ms":0.7,"overwritten_pixel_frames":5,"last_pixel_receive_age_ms":8.5,"last_pixel_change_age_ms":12.5}})");
const auto telemetry = refresh_telemetry(session);
const auto& performance = telemetry.at("performance");
EXPECT_TRUE(performance.at("automatic_low_latency_scheduler").get<bool>());
EXPECT_GE(performance.at("successful_render_count").get<std::uint64_t>(), 4U);