Fix M9.8c review findings in the engineering client
Resolve pointer ownership per SDL event so same-batch panel clicks, wheel and click-to-focus typing never reach the world; keep the Tab toggle independent of idempotent external capture release; own launcher phase and remote session together so Local fixture ends any remote attempt; wrap notices beside a reserved close column within a bounded stack. Adds client-panels test and host/session, same-batch and host-order Tab regressions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "evo/client/launcher.hpp"
|
||||
#include "evo/client/outcome_log.hpp"
|
||||
#include "evo/client/selection.hpp"
|
||||
#include "evo/client/session_host.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
@@ -13,6 +14,7 @@
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
@@ -244,6 +246,88 @@ void outcome_log() {
|
||||
log.evicted() == 201 - OutcomeLog::capacity);
|
||||
CHECK(log.entries().back().sequence == 201);
|
||||
}
|
||||
// Host/session boundary: the visible mode and the session lifetime change together.
|
||||
struct Server {
|
||||
bool available{};
|
||||
int steps{}, welcomes{}, intentions{}, alive{};
|
||||
};
|
||||
class FakeSession {
|
||||
public:
|
||||
explicit FakeSession(Server& server) : server_{&server} {
|
||||
++server_->alive;
|
||||
}
|
||||
FakeSession(FakeSession&& other) noexcept : server_{std::exchange(other.server_, nullptr)} {}
|
||||
FakeSession& operator=(FakeSession&&) = delete;
|
||||
FakeSession(const FakeSession&) = delete;
|
||||
FakeSession& operator=(const FakeSession&) = delete;
|
||||
~FakeSession() {
|
||||
if (server_ != nullptr)
|
||||
--server_->alive;
|
||||
}
|
||||
void step(std::chrono::steady_clock::time_point, const Intention& intention, UiState&,
|
||||
Launcher& launcher) {
|
||||
++server_->steps;
|
||||
if (!server_->available) {
|
||||
launcher.observe(ConnectSignal::lost);
|
||||
return;
|
||||
}
|
||||
if (!welcomed_) {
|
||||
welcomed_ = true;
|
||||
++server_->welcomes; // Spends a grant.
|
||||
launcher.observe(ConnectSignal::welcome);
|
||||
}
|
||||
if (intention.move_x != 0 || intention.move_y != 0)
|
||||
++server_->intentions;
|
||||
}
|
||||
|
||||
private:
|
||||
Server* server_;
|
||||
bool welcomed_{};
|
||||
};
|
||||
void session_host() {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
UiState ui;
|
||||
const Intention move{1, 0, 1000, 0};
|
||||
Server server;
|
||||
SessionHost<FakeSession> host;
|
||||
CHECK(!host.connect(std::nullopt) && host.session() == nullptr);
|
||||
// Connecting -> Local fixture: the attempt ends; a later server sees nothing.
|
||||
CHECK(host.connect(FakeSession{server}) && server.alive == 1);
|
||||
host.step(now, move, ui);
|
||||
CHECK(server.steps == 1 && host.launcher().phase() == LaunchPhase::connecting);
|
||||
host.enter_fixture();
|
||||
CHECK(server.alive == 0 && host.launcher().phase() == LaunchPhase::fixture);
|
||||
server.available = true;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
host.step(now, move, ui);
|
||||
CHECK(server.steps == 1 && server.welcomes == 0 && server.intentions == 0);
|
||||
// Failed -> Local fixture: the failure already dropped the session.
|
||||
host.cancel();
|
||||
server.available = false;
|
||||
CHECK(host.connect(FakeSession{server}));
|
||||
for (int i = 0; i < Launcher::max_attempts_without_welcome; ++i)
|
||||
host.step(now, move, ui);
|
||||
CHECK(host.launcher().phase() == LaunchPhase::failed && server.alive == 0);
|
||||
host.enter_fixture();
|
||||
server.available = true;
|
||||
host.step(now, move, ui);
|
||||
CHECK(server.welcomes == 0 && server.intentions == 0 && host.session() == nullptr);
|
||||
// Ordinary live use still works, and Cancel ends it.
|
||||
host.cancel();
|
||||
CHECK(host.connect(FakeSession{server}));
|
||||
host.step(now, move, ui);
|
||||
CHECK(host.launcher().phase() == LaunchPhase::connected && server.welcomes == 1 &&
|
||||
server.intentions == 1);
|
||||
host.cancel();
|
||||
host.step(now, move, ui);
|
||||
CHECK(server.alive == 0 && server.intentions == 1 &&
|
||||
host.launcher().phase() == LaunchPhase::choosing);
|
||||
// Connect is refused outside choosing/failed and leaves no session behind.
|
||||
host.enter_fixture();
|
||||
// (Separate statements: the by-value argument may live until the full expression ends.)
|
||||
CHECK(!host.connect(FakeSession{server}));
|
||||
CHECK(server.alive == 0 && host.session() == nullptr);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
@@ -251,6 +335,7 @@ int main() try {
|
||||
selection();
|
||||
launcher();
|
||||
outcome_log();
|
||||
session_host();
|
||||
std::puts("client UI model tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user