Bound engineering UI state and session events for M9.8b

This commit is contained in:
dingo
2026-10-02 08:22:25 -04:00
parent 22c7c341ce
commit a6e8094f57
20 changed files with 327 additions and 19 deletions
+8 -1
View File
@@ -97,9 +97,16 @@ include(CTest)
if(EVO_BUILD_CLIENT OR EVO_BUILD_NETWORK)
# SDL-free client value contracts (M9.3-M9.5), shared by the client and the dev
# session codec. They copy read-only world/biology views, never the reverse.
add_library(evo_client_controls STATIC src/client/camera/camera.cpp src/client/input/input.cpp)
add_library(evo_client_controls STATIC src/client/camera/camera.cpp src/client/input/input.cpp src/client/ui/ui_state.cpp)
target_include_directories(evo_client_controls PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
evo_owned_target(evo_client_controls)
if(BUILD_TESTING)
add_executable(evo-client-state-tests tests/client_ui_state.cpp)
target_link_libraries(evo-client-state-tests PRIVATE evo_client_controls)
evo_owned_target(evo-client-state-tests)
add_test(NAME client-ui-state COMMAND evo-client-state-tests)
set_tests_properties(client-ui-state PROPERTIES TIMEOUT 30 LABELS "client")
endif()
add_library(evo_client_views STATIC src/client/views/environment_view.cpp src/client/views/organism_view.cpp)
target_link_libraries(evo_client_views PUBLIC evo::world evo::biology)
evo_owned_target(evo_client_views)
+3 -3
View File
@@ -19,10 +19,10 @@
{"name": "analysis", "configurePreset": "analysis"},
{"name": "asan", "configurePreset": "asan"},
{"name": "tsan", "configurePreset": "tsan"},
{"name": "client", "configurePreset": "client", "targets": ["evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests"]},
{"name": "client", "configurePreset": "client", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests"]},
{"name": "client-probe", "configurePreset": "client-probe", "targets": ["evo-client-probe"]},
{"name": "network", "configurePreset": "network", "targets": ["evo-network-tests", "evo-dev-session"]},
{"name": "client-network", "configurePreset": "client-network", "targets": ["evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-network-tests", "evo-dev-session"]}
{"name": "network", "configurePreset": "network", "targets": ["evo-client-state-tests", "evo-network-tests", "evo-dev-session"]},
{"name": "client-network", "configurePreset": "client-network", "targets": ["evo-client-state-tests", "evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests", "evo-network-tests", "evo-dev-session"]}
],
"testPresets": [
{"name": "debug", "configurePreset": "debug", "output": {"outputOnFailure": true}},
+3
View File
@@ -146,6 +146,9 @@ class RemoteSession {
std::printf("intent %llu outcome unknown (connection lost)\n",
static_cast<unsigned long long>(e.sequence));
break;
case Kind::backpressure:
std::puts("session event backlog: disconnected; draining before reconnect");
break;
case Kind::exhausted:
std::puts("session grants exhausted; issue a new bundle to reconnect");
break;
+2 -2
View File
@@ -43,13 +43,13 @@ RUN cmake -P tools/prepare-sdl3.cmake \
&& cmake -P tools/prepare-imgui.cmake \
&& cmake --preset client-probe -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_C_COMPILER=clang-19 \
-DEVO_BUILD_CLIENT=ON -DEVO_BUILD_UI_PROBE=ON -DEVO_ENABLE_TIDY=ON -DSDL_X11=ON -DSDL_WAYLAND=OFF \
&& cmake --build build/client-probe --target evo-ui-probe evo-client-probe evo-client evo-client-lifecycle-tests evo-client-environment-tests evo-client-organism-tests --parallel 2 \
&& cmake --build build/client-probe --target evo-client-state-tests evo-ui-probe evo-client-probe evo-client evo-client-lifecycle-tests evo-client-environment-tests evo-client-organism-tests --parallel 2 \
&& ctest --preset client-probe --no-tests=error \
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-probe --renderer software \
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-ui-probe --renderer software \
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-lifecycle-tests \
&& cmake --preset client-probe -DEVO_BUILD_CLIENT=ON -DEVO_SANITIZER=address -DEVO_ENABLE_TIDY=OFF \
&& cmake --build build/client-probe --target evo-ui-probe evo-client evo-client-lifecycle-tests evo-client-environment-tests evo-client-organism-tests --parallel 2 \
&& cmake --build build/client-probe --target evo-client-state-tests evo-ui-probe evo-client evo-client-lifecycle-tests evo-client-environment-tests evo-client-organism-tests --parallel 2 \
&& ctest --preset client-probe --no-tests=error \
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-ui-probe --renderer software \
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-lifecycle-tests
+3 -1
View File
@@ -455,7 +455,9 @@ terrain meshing or procedural creature animation is required.
| 9.8 Validate presentation and package the client | tools/client packaging, tests/client, docs/engineering | 9.1-9.7 | Reproducible native artifact, bounded snapshot/render queues, frame/memory report and documented manual visual checks | Install/run on supported dev platforms; long session, resolution/DPI matrix, headless regression suite | Declaring FUN or multiplayer scalability from a viewer |
**M9.8a (2026-10-02):** isolated Dear ImGui 1.92.9b probe qualified on Windows/Linux;
application UI integration remains next. ADR-0084 is accepted for this probe.
M9.8b adds bounded UI state, protected external input capture and bounded session
event delivery. Launcher and visible widget integration remain M9.8c. ADR-0084
records both scopes.
**M9.8 planning (2026-10-02):** user-confirmed Windows ZIP, temporary Gitea Actions
artifacts, labelled engineering UI/launcher and control rebinding. See the
+15 -1
View File
@@ -1,6 +1,20 @@
# Project status and next steps
## Current gate — 2026-10-01
## Current gate - 2026-10-02
M9.8a: Dear ImGui 1.92.9b is pinned and qualified in an isolated Windows/Linux
SDL3 probe (ADR-0084). M9.8b adds bounded notification/dialog state, protected
external input capture and bounded session events with disconnect/drain/reconnect
backpressure. Tests and limits are recorded in engineering/VALIDATION.md.
Next: M9.8c launcher, visible dialogs/toasts, labelled views and click selection.
The client still displays the prior rectangle UI. Windows packages will be built
locally until a Windows runner exists. Testing is internal; 172.10.1.160 is the
RKE2 control-plane address. VM qualification and the cluster restart drill remain
outstanding, as agreed. See engineering/M9_8_DELIVERY_PLAN.md.
## M9.7 delivered scope
M9.7 connects the engineering client to an authoritative dev region
([ADR-0083](adr/0083-dev-region-sessions.md),
+13
View File
@@ -79,3 +79,16 @@ docs/FONTS.md, imgui_draw.cpp and the stb headers' embedded notices at
packaging. The bundled ProggyForever data also carries notices in imgui_draw.cpp;
include the source notice inventory even when that font is not selected.
Normal headless/client configuration does not require ImGui until explicitly enabled.
## M9.8b application state contract
Accepted for bounded toolkit-independent state. See
[CLIENT_UI_STATE](../engineering/CLIENT_UI_STATE.md): eight notifications with
240-byte text and explicit expiry/overflow; one id-matched modal. Input capture
requested by an external UI cannot be disabled by the legacy Tab shortcut.
Rendering and toolkit focus integration remain M9.8c.
SessionClient's local event delivery is capped at 1024, reserving room for all 256
unresolved intentions plus loss/backpressure events. On backlog it disconnects,
marks views stale and waits for the consumer to drain before reconnecting. Earlier
queued outcomes are preserved. This changes no wire format or biological rules.
+8
View File
@@ -77,3 +77,11 @@ Failure tests inject actual SDL events, including foreign window IDs, with no
test-only production hooks. Real device failures and physical DPI/input require
manual hardware qualification at M9.8. The native client is opt-in and never
enters a server container. Headless configuration does not prepare/load SDL.
M9.8b adds [owned UI state](../engineering/CLIENT_UI_STATE.md): bounded notifications
and one modal, independent of toolkit/render/simulation types. The native adapter
protects externally requested capture from the legacy Tab shortcut. Session event
backpressure preserves queued events, disconnects and resolves remaining local
uncertainty as unknown, then waits for draining before reconnecting. This is not
a durable outcome-history database. The launcher/visible widgets follow in M9.8c.
+22
View File
@@ -0,0 +1,22 @@
# M9.8b UI state and event bounds
Owned, toolkit-independent state; all calls on the client main thread. No authority
or simulation state. Time is explicit monotonic milliseconds supplied by the host.
Notifications: at most eight, text at most 240 bytes; reject invalid/oversized input,
expire by deadline, dismiss by unique id. Overflow evicts oldest and increments a
visible saturating counter. Notifications are not durable outcome history.
Dialogs: one active modal, title at most 96 bytes and body at most 240; opening a
second fails. Close requires the matching id so a stale click cannot close a newer
dialog. IDs never wrap. No credentials or grant bytes enter display messages.
SessionClient keeps at most 1024 queued ClientEvents. At 766 regular events it emits
a local backpressure event, disconnects, and has room for loss plus 256 unknown
intentions. It preserves all previously queued events and pauses reconnect until
take_events drains the queue. This is a local condition, not a protocol change.
Unprocessed wire outcomes remain unknown, never assumed failed or committed.
The native adapter's externally requested capture cannot be disabled by the legacy
Tab toggle. Releasing capture drains already queued input before new world actions.
Rendering dialogs/toasts and wiring toolkit capture occur with the launcher in
M9.8c; these contracts and their tests precede that integration.
+2 -1
View File
@@ -1,6 +1,7 @@
# M9.8 delivery plan
Status: M9.8a isolated toolkit probe complete, 2026-10-02; remaining segments planned.
Status: M9.8a probe and M9.8b owned state/capture/event bounds complete, 2026-10-02;
remaining segments planned.
No application UI or deployment completion is claimed. See ADR-0084 for the toolkit boundary.
## Confirmed scope
+35 -2
View File
@@ -3566,7 +3566,7 @@ were not rebuilt; equivalent regressions above replace them. The `ci-client` Doc
image and Gitea pipeline were not rerun here, and no cluster operation was performed.
## 2026-10-02 — consumed-grant ledger follow-up corrections
## 2026-10-02 — consumed-grant ledger follow-up corrections
Resolved the two c588be2 review findings. Ledger open now acquires a nonblocking
exclusive lifetime lock on a stable sibling file before reading or compacting
@@ -3604,7 +3604,7 @@ repository-relative links and git diff --check. Documentation only: no code test
package build, runner execution, endpoint verification or deployment performed.
## 2026-10-02 — M9.8a pinned engineering UI probe
## 2026-10-02 — M9.8a pinned engineering UI probe
Adopted Dear ImGui 1.92.9b for an isolated SDL3/SDL_Renderer3 compatibility probe;
normal client/headless builds do not require it. Exact upstream commit, locally
@@ -3637,3 +3637,36 @@ explicitly deferred; control-plane IP is not assumed to be a MetalLB endpoint.
Not run: Docker/Gitea image execution, physical GPU/DPI matrix, VM soak, client UI
integration/launcher or packaging acceptance. Existing network and headless simulation
behavior is unchanged; no simulation version or golden was modified.
## 2026-10-02 — M9.8b owned UI state and bounded session events
Implemented toolkit-independent UiState: eight expiring/dismissible notices,
240-byte messages, an observable eviction count, one id-matched modal and explicit
monotonic time. Tests cover 10000-notice bursts, expiry boundary, malformed/oversized
messages, stale time, deadline overflow, modal contention and stale close IDs.
External native UI capture can no longer be escaped through the legacy Tab toggle.
SessionClient queues at most 1024 events, reserves loss/unknown capacity, preserves
queued results, and disconnects on backlog until take_events drains it. The burst
regression accounts for every sent intention as a rejection or unknown, proves no
grant burning while paused and confirms reconnect after drain. Backpressure is a
local event, not a new wire message or simulation rule. Presets and the selective
Docker client targets include the new UI state test executable.
Executed: Windows MSVC client-network configure/build/CTest 7/7; Linux GCC targeted
UI-state/network/native-lifecycle tests 3/3; Clang ASan/UBSan UI-state/network 2/2.
Static analysis initially flagged the new test main's escaping exception; added the
same process error boundary used by other executables. Windows exposed a timing
assumption in the initial one-message-per-sleep burst test; bounded batches replaced
that dependency. The explicit-target Windows preset initially omitted the new test
binary; fixed its target list and reran all seven tests successfully.
Visible dialogs/toasts, launcher and toolkit focus routing remain M9.8c. These are
owned state and adapter contracts, not a claim of finished UI. No Docker/Gitea run,
VM qualification, live cluster test, packaging or deployment was performed.
Final additional checks: Linux GCC state/network/lifecycle 3/3; Clang ASan/UBSan
native lifecycle 1/1; clang-tidy19 on owned state/session implementation,
state/network tests and native adapter/lifecycle tests passed with no owned
diagnostics. Final changed-file formatting passed.
+1
View File
@@ -43,6 +43,7 @@ class Application {
[[nodiscard]] WindowState state() const noexcept;
[[nodiscard]] std::expected<void, Error> poll_events();
[[nodiscard]] std::expected<Step, Error> present(const render::Frame& frame);
// External modal/widget capture cannot be disabled by the legacy Tab toggle.
void set_ui_capture(bool captured) noexcept;
[[nodiscard]] bool ui_captured() const noexcept;
[[nodiscard]] Navigation take_navigation() noexcept;
+49
View File
@@ -0,0 +1,49 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <expected>
#include <optional>
#include <span>
#include <string>
#include <string_view>
#include <vector>
namespace evo::client {
enum class UiError : std::uint8_t { invalid, stale_time, busy, exhausted };
enum class NoticeLevel : std::uint8_t { info, warning, error };
struct Notice {
std::uint64_t id{}, expires_at_ms{};
NoticeLevel level{};
std::string text;
};
struct Dialog {
std::uint64_t id{};
std::string title, body;
};
// Main-thread, bounded presentation state. Never store credentials or authority here.
class UiState {
public:
static constexpr std::size_t max_notices = 8, max_text = 240, max_title = 96;
[[nodiscard]] std::expected<void, UiError> advance(std::uint64_t now_ms);
[[nodiscard]] std::expected<std::uint64_t, UiError>
notify(std::string_view text, NoticeLevel level, std::uint64_t lifetime_ms = 5000);
[[nodiscard]] bool dismiss(std::uint64_t id);
[[nodiscard]] std::expected<std::uint64_t, UiError> open_dialog(std::string_view title,
std::string_view body);
[[nodiscard]] bool close_dialog(std::uint64_t id);
[[nodiscard]] std::span<const Notice> notices() const noexcept {
return notices_;
}
[[nodiscard]] const std::optional<Dialog>& dialog() const noexcept {
return dialog_;
}
[[nodiscard]] std::uint64_t evicted_notices() const noexcept {
return evicted_;
}
private:
std::uint64_t now_{}, next_id_{1}, evicted_{};
std::vector<Notice> notices_;
std::optional<Dialog> dialog_;
};
} // namespace evo::client
+8 -6
View File
@@ -37,11 +37,12 @@ struct ClientEvent {
enum class Kind : std::uint8_t {
welcome,
closed,
lost, // Transport/TLS failure or deadline: no Close received.
result, // IntentResult.
outcome, // IntentOutcome (durable or not committed).
unknown, // Admitted intention whose outcome died with its connection.
exhausted // No grants left; reconnection stops.
lost, // Transport/TLS failure or deadline: no Close received.
result, // IntentResult.
outcome, // IntentOutcome (durable or not committed).
unknown, // Sent intention whose outcome died with its connection.
backpressure, // Local event backlog: reconnect waits for take_events().
exhausted // No grants left; reconnection stops.
} kind{};
Welcome welcome{};
CloseReason reason{};
@@ -52,7 +53,7 @@ struct ClientEvent {
enum class SessionClientError : std::uint8_t { configuration };
class SessionClient {
public:
static constexpr std::size_t max_outstanding = 256;
static constexpr std::size_t max_outstanding = 256, max_events = 1024;
[[nodiscard]] static std::expected<std::unique_ptr<SessionClient>, SessionClientError>
create(SessionClientConfig config);
SessionClient(const SessionClient&) = delete;
@@ -69,6 +70,7 @@ class SessionClient {
[[nodiscard]] std::optional<Welcome> welcome() const noexcept;
[[nodiscard]] std::optional<ViewHeader> latest_view() const noexcept;
[[nodiscard]] std::size_t grants_left() const noexcept;
// Drains at most max_events and resumes reconnect after local backpressure.
[[nodiscard]] std::vector<ClientEvent> take_events();
private:
+3 -1
View File
@@ -50,6 +50,7 @@ struct Application::Impl {
std::optional<Error> failure;
InputState input;
bool backlogged{false};
bool external_capture{false};
std::expected<void, Error> refresh() {
if (!SDL_GetWindowSize(window.get(), &state.logical_width, &state.logical_height) ||
@@ -72,6 +73,7 @@ WindowState Application::state() const noexcept {
return result;
}
void Application::set_ui_capture(bool captured) noexcept {
impl_->external_capture = captured;
if (impl_->input.captured() && !captured) {
// An external UI can release capture with old input still queued in SDL.
// Drain that batch before admitting fresh world presses.
@@ -174,7 +176,7 @@ std::expected<void, Error> Application::poll_events() {
event.key.windowID == id) {
const bool down = event.type == SDL_EVENT_KEY_DOWN;
if (event.key.scancode == SDL_SCANCODE_TAB && down && !event.key.repeat &&
p.state.accepts_input() && !p.backlogged)
p.state.accepts_input() && !p.backlogged && !p.external_capture)
p.input.capture(!p.input.captured());
if (const auto key = input_key(event.key.scancode)) {
if (auto result = p.input.key(*key, down, event.key.repeat); !result)
+56
View File
@@ -0,0 +1,56 @@
#include "evo/client/ui_state.hpp"
#include <algorithm>
#include <limits>
#include <utility>
namespace evo::client {
namespace {
bool valid_text(std::string_view text, std::size_t limit) {
return !text.empty() && text.size() <= limit && text.find('\0') == std::string_view::npos;
}
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
} // namespace
std::expected<void, UiError> UiState::advance(std::uint64_t now_ms) {
if (now_ms < now_)
return std::unexpected(UiError::stale_time);
now_ = now_ms;
std::erase_if(notices_, [&](const Notice& n) { return n.expires_at_ms <= now_; });
return {};
}
std::expected<std::uint64_t, UiError> UiState::notify(std::string_view text, NoticeLevel level,
std::uint64_t lifetime_ms) {
if (!valid_text(text, max_text) || lifetime_ms == 0 || lifetime_ms > maximum - now_ ||
(level != NoticeLevel::info && level != NoticeLevel::warning &&
level != NoticeLevel::error))
return std::unexpected(UiError::invalid);
if (next_id_ == maximum)
return std::unexpected(UiError::exhausted);
Notice notice{next_id_, now_ + lifetime_ms, level, std::string{text}};
if (notices_.size() == max_notices) {
notices_.erase(notices_.begin());
if (evicted_ != maximum)
++evicted_;
}
notices_.push_back(std::move(notice));
return next_id_++;
}
bool UiState::dismiss(std::uint64_t id) {
return std::erase_if(notices_, [&](const Notice& n) { return n.id == id; }) != 0;
}
std::expected<std::uint64_t, UiError> UiState::open_dialog(std::string_view title,
std::string_view body) {
if (!valid_text(title, max_title) || !valid_text(body, max_text))
return std::unexpected(UiError::invalid);
if (dialog_)
return std::unexpected(UiError::busy);
if (next_id_ == maximum)
return std::unexpected(UiError::exhausted);
dialog_.emplace(Dialog{next_id_, std::string{title}, std::string{body}});
return next_id_++;
}
bool UiState::close_dialog(std::uint64_t id) {
if (!dialog_ || dialog_->id != id)
return false;
dialog_.reset();
return true;
}
} // namespace evo::client
+16 -1
View File
@@ -31,6 +31,7 @@ struct SessionClient::Impl {
client::EnvironmentLayer environment;
client::OrganismLayer organisms;
std::vector<ClientEvent> events;
bool awaiting_event_drain{};
void disconnect(Clock::time_point now, std::optional<CloseReason> reason) {
if (step == Step::established || step == Step::awaiting_welcome || reason)
@@ -87,6 +88,13 @@ struct SessionClient::Impl {
return true;
}
bool frame(const OwnedFrame& f, Clock::time_point now) {
// Reserve loss + backpressure + every unresolved intention; never evict an event.
if (events.size() >= max_events - max_outstanding - 2) {
events.push_back({ClientEvent::Kind::backpressure, {}, {}, {}, {}, 0});
awaiting_event_drain = true;
disconnect(now, std::nullopt);
return false;
}
const FrameView v{f.type, f.payload};
last_received = now;
if (step == Step::awaiting_welcome) {
@@ -225,8 +233,14 @@ SessionClient::create(SessionClientConfig config) {
void SessionClient::poll(std::chrono::steady_clock::time_point now) {
auto& m = *impl_;
m.polled_at = now;
if (m.phase == SessionPhase::exhausted)
if (m.awaiting_event_drain || m.phase == SessionPhase::exhausted)
return;
if (m.events.size() >= max_events - max_outstanding - 2) {
m.events.push_back({ClientEvent::Kind::backpressure, {}, {}, {}, {}, 0});
m.awaiting_event_drain = true;
m.disconnect(now, std::nullopt);
return;
}
if (m.phase == SessionPhase::backoff) {
if (now < m.retry_at)
return;
@@ -314,6 +328,7 @@ std::size_t SessionClient::grants_left() const noexcept {
return impl_->config.grants.size() - impl_->next_grant;
}
std::vector<ClientEvent> SessionClient::take_events() {
impl_->awaiting_event_drain = false;
return std::exchange(impl_->events, {});
}
} // namespace evo::network
+3
View File
@@ -186,6 +186,9 @@ void native_input() {
key(SDL_SCANCODE_W, true);
CHECK(app->poll_events());
app->set_ui_capture(true);
key(SDL_SCANCODE_TAB, true); // Legacy shortcut cannot escape an external modal.
key(SDL_SCANCODE_W, true);
CHECK(app->poll_events() && app->ui_captured());
CHECK(required(app->sample_intention(43)).move_y == 0);
key(SDL_SCANCODE_W, true);
CHECK(app->poll_events());
+44
View File
@@ -0,0 +1,44 @@
#include "evo/client/ui_state.hpp"
#include <cstdio>
#include <limits>
#include <stdexcept>
#include <string>
using namespace evo::client;
void check(bool ok) {
if (!ok)
throw std::runtime_error("UI state contract");
}
int main() try {
UiState ui;
check(ui.advance(100).has_value());
auto first = ui.notify("Connected", NoticeLevel::info, 10);
check(first.has_value());
check(ui.advance(109).has_value() && ui.notices().size() == 1);
check(ui.advance(110).has_value() && ui.notices().empty());
check(!ui.dismiss(*first));
check(!ui.advance(109));
check(!ui.notify(std::string(241, 'x'), NoticeLevel::info));
check(!ui.notify(std::string_view{"x\0y", 3}, NoticeLevel::info));
check(!ui.notify("invalid", NoticeLevel::info, 0));
for (int i = 0; i < 10000; ++i)
check(ui.notify("Burst", NoticeLevel::warning).has_value());
check(ui.notices().size() == 8 && ui.evicted_notices() == 9992);
auto dismissed = ui.notices().back().id;
check(ui.dismiss(dismissed));
check(ui.notices().size() == 7 && !ui.dismiss(dismissed));
auto dialog = ui.open_dialog("Disconnect?", "Current intentions may remain unknown.");
check(dialog.has_value());
check(!ui.open_dialog("Other", "Blocked"));
check(!ui.close_dialog(*dialog + 1));
check(ui.close_dialog(*dialog));
auto next = ui.open_dialog("New", "New modal");
check(next.has_value());
check(!ui.close_dialog(*dialog) && ui.dialog().has_value());
check(ui.close_dialog(*next));
check(ui.advance(std::numeric_limits<std::uint64_t>::max()).has_value());
check(!ui.notify("Overflow", NoticeLevel::error, 1));
return 0;
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
}
+33
View File
@@ -662,9 +662,42 @@ void liveness() {
CHECK(h.until([&] { return again->phase() == SessionPhase::established; }));
}
}
void event_backpressure() {
Harness h;
h.tick();
auto c = h.client(grants(7, 3, 100));
CHECK(h.until([&] { return c->latest_view().has_value(); }));
std::uint64_t sent = 0;
CHECK(h.until([&] {
if (c->phase() != SessionPhase::established)
return true;
// Invalid vector: final rejection frees outstanding capacity, but the host
// intentionally never drains its event queue throughout this burst.
for (int batch = 0; batch < 16; ++batch)
if (c->send({sent + 1, 0, 1000, 1000}))
++sent;
return false;
}));
CHECK(c->phase() == SessionPhase::backoff);
const auto remaining = c->grants_left();
for (int i = 0; i < 100; ++i)
c->poll(Clock::now() + std::chrono::seconds{60});
CHECK(c->grants_left() == remaining && c->phase() == SessionPhase::backoff);
CHECK(c->environment().freshness() == client::Freshness::stale);
const auto events = c->take_events();
CHECK(events.size() <= SessionClient::max_events);
CHECK(has(events, ClientEvent::Kind::backpressure) && has(events, ClientEvent::Kind::lost));
const auto accounted = std::ranges::count_if(events, [](const ClientEvent& e) {
return e.kind == ClientEvent::Kind::result || e.kind == ClientEvent::Kind::unknown;
});
CHECK(static_cast<std::uint64_t>(accounted) == sent);
CHECK(h.until([&] { return c->latest_view().has_value(); }));
CHECK(c->phase() == SessionPhase::established);
}
} // namespace
void session_tests() {
event_backpressure();
ledger_exclusive_owner();
ledger_incomplete_records();
connect_view_intents_and_outcomes();