Fence legacy peers from an unrepresentable custody publication
This commit is contained in:
1 parent
1b57183939
commit
83a57cbe46
7 files changed
+256
-21
No files matched your search
@@ -116,6 +116,7 @@ struct [[= Void::Testing::name("ViewerSessionTests")]] ViewerSessionTests : Void
|
||||
[[= Void::Testing::tag("viewer-session")]] Test test_profile_validation_rejects_initial_and_loaded_mismatches();
|
||||
[[= Void::Testing::tag("viewer-session")]] Test test_pending_optional_load_blocks_host_and_newest_invalid_load_wins();
|
||||
[[= Void::Testing::tag("viewer-session")]] Test test_historical_default_modes_and_guest_leave_keep_default_rules();
|
||||
[[= Void::Testing::tag("viewer-session")]] Test test_legacy_host_requires_representable_published_custody();
|
||||
};
|
||||
|
||||
Test ViewerSessionTests::test_commands_wait_for_commit_and_keep_rejected_drafts_retryable() {
|
||||
@@ -530,7 +531,7 @@ Test ViewerSessionTests::test_historical_default_modes_and_guest_leave_keep_defa
|
||||
if (mode == 2) candidate.world = std::make_unique<World>(17, 32, 32, 2);
|
||||
const auto expected = bytes(*candidate.world);
|
||||
ViewerSession session(std::move(candidate), 2);
|
||||
require(bytes(*session.world()) == expected && session.can_host_legacy());
|
||||
require(bytes(*session.world()) == expected && session.can_host_legacy() == (mode != 2));
|
||||
write(files.root / "legacy.settlement", expected);
|
||||
session.load(files.root / "legacy.settlement");
|
||||
pump_until(session, [](const auto& events) { return has(events, ViewerEventKind::Replaced); });
|
||||
@@ -544,4 +545,37 @@ Test ViewerSessionTests::test_historical_default_modes_and_guest_leave_keep_defa
|
||||
require(!session.world()->staged_beds() && *session.runtime().latest()->rules == defaults && session.can_host_legacy());
|
||||
}
|
||||
|
||||
Test ViewerSessionTests::test_legacy_host_requires_representable_published_custody() {
|
||||
auto candidate = checked(make_colony_checkpoint(ColonyProfile::Default, 2));
|
||||
candidate.world = std::make_unique<World>(43, 32, 32, 2);
|
||||
auto& world = *candidate.world;
|
||||
const auto store = world.add_storage({3, 3}, 5);
|
||||
world.stock_storage(store, ItemType::Plank, 3);
|
||||
world.stock_storage(store, ItemType::StoneBlock, 2);
|
||||
static_cast<void>(world.spawn_agent({1, 3}));
|
||||
world.start_scenario({6, 6});
|
||||
world.queue_production({14, 3}, RecipeId::BuildCabin);
|
||||
for (int tick = 0; tick < 100 && world.agents().front().inventory.empty(); ++tick) world.step();
|
||||
require(world.agents().front().inventory.item_count(ItemType::Plank) == 3 &&
|
||||
world.agents().front().inventory.item_count(ItemType::StoneBlock) == 2);
|
||||
world.stock_storage(store, ItemType::Wood, 5);
|
||||
require(world.legacy_representable());
|
||||
require(world.cancel_production(world.production_orders().front().id) == CommandStatus::Accepted);
|
||||
require(!world.legacy_representable());
|
||||
ViewerSession session(std::move(candidate), 2);
|
||||
const auto published = session.runtime().latest();
|
||||
require(!session.can_host_legacy() && session.can_submit());
|
||||
require(session.world() == published->world && session.runtime().view().state == RuntimeState::Running);
|
||||
TempFiles files;
|
||||
session.save(files.root / "custody.settlement");
|
||||
pump_until(session, [](const auto& events) { return has(events, ViewerEventKind::Saved); });
|
||||
session.load(files.root / "custody.settlement");
|
||||
pump_until(session, [](const auto& events) { return has(events, ViewerEventKind::Replaced); });
|
||||
require(!session.can_host_legacy() && !session.world()->legacy_representable() && session.can_submit());
|
||||
session.new_colony();
|
||||
require(session.changing_world() && !session.can_host_legacy());
|
||||
pump_until(session, [](const auto& events) { return has(events, ViewerEventKind::Replaced); });
|
||||
require(session.can_host_legacy());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in new issue
Block a user