From b432d7cfaa2655d3f14ae85694a3b8f47d280a4b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 12:15:12 -0800 Subject: [PATCH 01/34] AutoStory tests: name each case outside its input Code Health's test-case rule wants each UnitTest built from one case struct of name, input and expectation, with the name outside the input. Move every case's name from its Input to the case itself, nest the RngHandoff input and expectation structs, and give the first-save, captured-transition and move-mechanics cases explicit names (the same test names as before). Assertions and test bodies are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon_StoryEnginePolicy_Tests.cpp | 74 ++++++++-------- .../Engine/Pokemon_StoryEngineRuns_Tests.cpp | 56 ++++++------ .../Engine/Pokemon_StoryEngine_Tests.cpp | 52 +++++------ .../AutoStory/Pokemon_Interrupts_Tests.cpp | 84 +++++++++++------- .../AutoStory/Pokemon_SceneJudges_Tests.cpp | 10 ++- .../AutoStory/Pokemon_StoryActions_Tests.cpp | 22 +++-- .../Pokemon_StoryInterrupts_Tests.cpp | 85 +++++++++++------- .../Pokemon_StoryRngHandoff_Tests.cpp | 37 ++++---- .../AutoStory/Pokemon_StoryRun_Tests.cpp | 77 ++++++++++------- .../AutoStory/Pokemon_Transitions_Tests.cpp | 77 +++++++++++------ .../Pokemon_ConnectedMaps_Tests.cpp | 60 ++++++++----- .../Navigation/Pokemon_LegPlanner_Tests.cpp | 37 +++++--- .../Navigation/Pokemon_LegWalker_Tests.cpp | 31 ++++--- .../Navigation/Pokemon_MapData_Tests.cpp | 31 ++++--- .../Pokemon_MoveMechanics_Tests.cpp | 10 ++- .../Navigation/Pokemon_RouteLog_Tests.cpp | 45 ++++++---- .../Navigation/Pokemon_RuntimeMap_Tests.cpp | 86 +++++++++---------- .../Navigation/Pokemon_WallRecovery_Tests.cpp | 38 +++++--- .../Simulation/Pokemon_SimFaults_Tests.cpp | 16 ++-- .../Simulation/Pokemon_SimGolden_Tests.cpp | 18 ++-- .../Pokemon_StoryRangeOptions_Tests.cpp | 16 ++-- ...okemonFRLG_AutoStoryScreenEvents_Tests.cpp | 13 +-- 22 files changed, 572 insertions(+), 403 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp index 90ecc3d4db..e65b730dbf 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp @@ -86,7 +86,6 @@ StoryGame engine_game(std::optional candies){ struct EngineCase{ // One engine run of 00.31 in `phase`, the player ending on `end_map`. struct Input{ - std::string_view name; std::string_view phase; HashRecord hash = HashRecord::MATCHING; std::string_view steps = TALK_STEPS; @@ -104,36 +103,37 @@ struct EngineCase{ std::string_view line = {}; }; + std::string_view name; Input input; Expectation expectation; }; const EngineCase ENGINE_CASES[] = { - {.input = {.name = "testing never saves", .phase = "testing"}, + {.name = "testing never saves", .input = {.phase = "testing"}, .expectation = {.mode = StorySaveMode::NONE, .saves = 0, .line = "[Save] 00.31: phase testing: save mode none"}}, - {.input = {.name = "verification saves at the end", .phase = "verification"}, + {.name = "verification saves at the end", .input = {.phase = "verification"}, .expectation = {.mode = StorySaveMode::AFTER_VERIFICATION, .saves = 1, .line = "[Save] 00.31: saved"}}, - {.input = {.name = "reproduction saves", .phase = "reproduction"}, + {.name = "reproduction saves", .input = {.phase = "reproduction"}, .expectation = {.mode = StorySaveMode::PER_CHECKPOINT, .saves = 1, .line = "[Save] 00.31: phase reproduction: save mode per_checkpoint"}}, - {.input = {.name = "stale steps_hash is testing", .phase = "verification", .hash = HashRecord::STALE}, + {.name = "stale steps_hash is testing", .input = {.phase = "verification", .hash = HashRecord::STALE}, .expectation = {.mode = StorySaveMode::NONE, .saves = 0, .line = "[Save] 00.31: phase verification but steps_hash mismatch (recorded sha256:old, now "}}, - {.input = {.name = "no steps_hash is testing", .phase = "reproduction", .hash = HashRecord::MISSING}, + {.name = "no steps_hash is testing", .input = {.phase = "reproduction", .hash = HashRecord::MISSING}, .expectation = {.mode = StorySaveMode::NONE, .saves = 0, .line = "[Save] 00.31: phase reproduction but steps_hash mismatch (recorded none, now "}}, - {.input = {.name = "B4F false pass fails postconditions", .phase = "verification", .end_map = "RocketHideout_B4F"}, + {.name = "B4F false pass fails postconditions", .input = {.phase = "verification", .end_map = "RocketHideout_B4F"}, .expectation = {.mode = StorySaveMode::AFTER_VERIFICATION, .verdict = CheckpointVerdict::FAILED, .saves = 0, .line = "[Postcondition] 00.31 map: failed: expected RocketHideout_B3F, read RocketHideout_B4F"}}, - {.input = {.name = "unread bag is not checked", .phase = "verification", .candies = std::nullopt}, + {.name = "unread bag is not checked", .input = {.phase = "verification", .candies = std::nullopt}, .expectation = {.mode = StorySaveMode::AFTER_VERIFICATION, .saves = 1, .line = "[Postcondition] 00.31: 3 passed, 0 failed, 1 not checked: incomplete"}}, - {.input = {.name = "wrong candy count fails", .phase = "reproduction", .candies = 1}, + {.name = "wrong candy count fails", .input = {.phase = "reproduction", .candies = 1}, .expectation = {.mode = StorySaveMode::PER_CHECKPOINT, .verdict = CheckpointVerdict::FAILED, .saves = 0, .line = "[Postcondition] 00.31 item RARE_CANDY: failed: expected 2, read 1"}}, - {.input = {.name = "failed run never saves", .phase = "reproduction", .end_map = ""}, + {.name = "failed run never saves", .input = {.phase = "reproduction", .end_map = ""}, .expectation = {.mode = StorySaveMode::PER_CHECKPOINT, .verdict = CheckpointVerdict::FAILED, .saves = 0, .line = "[Save] 00.31: run failed: not saved"}}, - {.input = {.name = "save step skipped while verifying", .phase = "verification", .steps = SAVE_STEPS}, + {.name = "save step skipped while verifying", .input = {.phase = "verification", .steps = SAVE_STEPS}, .expectation = {.mode = StorySaveMode::AFTER_VERIFICATION, .saves = 1, .line = "[Save] save step skipped: save mode after_verification"}}, - {.input = {.name = "save step saves in reproduction", .phase = "reproduction", .steps = SAVE_STEPS}, + {.name = "save step saves in reproduction", .input = {.phase = "reproduction", .steps = SAVE_STEPS}, .expectation = {.mode = StorySaveMode::PER_CHECKPOINT, .saves = 2, .line = "[Step] save_here SAVE/default: ok"}}, }; @@ -166,7 +166,7 @@ std::string check_engine(const EngineCase& test, CancellableScope& scope){ FakeStoryBackend backend({.looks = engine_looks(test.input.end_map)}, scope); StoryEngine engine(game, backend); StoryCheckpoint checkpoint = read_story_checkpoint( - parse_json(checkpoint_0031(test.input.phase, test.input.steps)), test.input.name, engine.registry().specs() + parse_json(checkpoint_0031(test.input.phase, test.input.steps)), test.name, engine.registry().specs() ); if (test.input.hash != HashRecord::MISSING){ checkpoint.metadata.verified = StoryVerification{ @@ -188,7 +188,7 @@ std::string check_engine(const EngineCase& test, CancellableScope& scope){ class StoryEngineSaveTest : public UnitTest{ public: explicit StoryEngineSaveTest(EngineCase test) - : UnitTest(std::format("Pokemon::StoryEngine save - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine save - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ @@ -204,7 +204,6 @@ class StoryEngineSaveTest : public UnitTest{ struct HashCase{ // Two checkpoints' events, hashed with the built-in actions. struct Input{ - std::string_view name; std::string_view a; std::string_view b; }; @@ -216,6 +215,7 @@ struct HashCase{ std::optional hash_a = std::nullopt; }; + std::string_view name; Input input; Expectation expectation; }; @@ -223,18 +223,18 @@ struct HashCase{ inline constexpr std::string_view ROUTE_B3F = R"([{"id": "go", "kind": "route", "args": {"target": {"map": "RocketHideout_B3F", "tiles": [[12, 13]]}}}])"; const HashCase HASH_CASES[] = { - {.input = {.name = "pinned", .a = ROUTE_B3F, .b = ROUTE_B3F}, + {.name = "pinned", .input = {.a = ROUTE_B3F, .b = ROUTE_B3F}, .expectation = {.same = true, .hash_a = "sha256:13bc877c960a15cd0ed2f37248fa8336308b048a865623dde7654d41ac7147b8"}}, - {.input = {.name = "whitespace is not hashed", .a = R"([{"id": "t", "kind": "talk"}])", .b = R"([ { "id":"t", "kind":"talk" } ])"}, + {.name = "whitespace is not hashed", .input = {.a = R"([{"id": "t", "kind": "talk"}])", .b = R"([ { "id":"t", "kind":"talk" } ])"}, .expectation = {.same = true}}, - {.input = {.name = "why differs", .a = R"([{"id": "t", "kind": "talk", "why": "a"}])", .b = R"([{"id": "t", "kind": "talk", "why": "b"}])"}, + {.name = "why differs", .input = {.a = R"([{"id": "t", "kind": "talk", "why": "a"}])", .b = R"([{"id": "t", "kind": "talk", "why": "b"}])"}, .expectation = {.same = false}}, - {.input = {.name = "written fallback differs", .a = R"([{"id": "f", "kind": "battle"}])", .b = R"([{"id": "f", "kind": "battle", "args": {"may_lose": false}}])"}, + {.name = "written fallback differs", .input = {.a = R"([{"id": "f", "kind": "battle"}])", .b = R"([{"id": "f", "kind": "battle", "args": {"may_lose": false}}])"}, .expectation = {.same = false}}, - {.input = {.name = "another target differs", .a = ROUTE_B3F, + {.name = "another target differs", .input = { .a = ROUTE_B3F, .b = R"([{"id": "go", "kind": "route", "args": {"target": {"map": "RocketHideout_B3F", "tiles": [[12, 14]]}}}])"}, .expectation = {.same = false}}, - {.input = {.name = "another step name differs", .a = R"([{"id": "t", "kind": "talk"}])", .b = R"([{"id": "u", "kind": "talk"}])"}, + {.name = "another step name differs", .input = {.a = R"([{"id": "t", "kind": "talk"}])", .b = R"([{"id": "u", "kind": "talk"}])"}, .expectation = {.same = false}}, }; @@ -244,8 +244,8 @@ std::string hash_of(std::string_view events, std::string_view source){ } std::string check_hash(const HashCase& test){ - const std::string a = hash_of(test.input.a, test.input.name); - const std::string b = hash_of(test.input.b, test.input.name); + const std::string a = hash_of(test.input.a, test.name); + const std::string b = hash_of(test.input.b, test.name); if ((a == b) != test.expectation.same){ return std::format("{}{}: {}, {}", "expected the hashes ", (test.expectation.same ? "equal" : "different"), a, b); } @@ -258,7 +258,7 @@ std::string check_hash(const HashCase& test){ class StoryStepsHashTest : public UnitTest{ public: explicit StoryStepsHashTest(HashCase test) - : UnitTest(std::format("Pokemon::StoryEngine steps_hash - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine steps_hash - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -274,7 +274,6 @@ class StoryStepsHashTest : public UnitTest{ struct MetadataCase{ // A checkpoint's "metadata", read. struct Input{ - std::string_view name; std::string_view metadata; }; @@ -286,20 +285,21 @@ struct MetadataCase{ size_t items = 0; }; + std::string_view name; Input input; Expectation expectation; }; const MetadataCase METADATA_CASES[] = { - {.input = {.name = "none is testing", .metadata = ""}, + {.name = "none is testing", .input = {.metadata = ""}, .expectation = {.phase = StoryPhase::TESTING}}, - {.input = {.name = "verified", .metadata = R"(, "metadata": {"phase": "verification", "verified": {"steps_hash": "sha256:ab", "build": "1", "date": "d", "runs": "3/3"}})"}, + {.name = "verified", .input = {.metadata = R"(, "metadata": {"phase": "verification", "verified": {"steps_hash": "sha256:ab", "build": "1", "date": "d", "runs": "3/3"}})"}, .expectation = {.phase = StoryPhase::VERIFICATION, .steps_hash = "sha256:ab"}}, - {.input = {.name = "postconditions", .metadata = R"(, "metadata": {"phase": "reproduction", "postconditions": {"items": [{"item": "LIFT_KEY", "quantity": 1}]}})"}, + {.name = "postconditions", .input = {.metadata = R"(, "metadata": {"phase": "reproduction", "postconditions": {"items": [{"item": "LIFT_KEY", "quantity": 1}]}})"}, .expectation = {.phase = StoryPhase::REPRODUCTION, .items = 1}}, - {.input = {.name = "unknown phase", .metadata = R"(, "metadata": {"phase": "tested"})"}, + {.name = "unknown phase", .input = {.metadata = R"(, "metadata": {"phase": "tested"})"}, .expectation = {.error = "unknown phase tested"}}, - {.input = {.name = "unknown field", .metadata = R"(, "metadata": {"phase": "testing", "runs": 3})"}, + {.name = "unknown field", .input = {.metadata = R"(, "metadata": {"phase": "testing", "runs": 3})"}, .expectation = {.error = "unsupported field runs"}}, }; @@ -328,7 +328,7 @@ std::string check_metadata(const MetadataCase& test){ class StoryMetadataTest : public UnitTest{ public: explicit StoryMetadataTest(MetadataCase test) - : UnitTest(std::format("Pokemon::StoryEngine metadata - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine metadata - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -345,7 +345,6 @@ struct ScreenCase{ // What a look showed, classified by ScreenMachine states that match on // observations. struct Input{ - std::string_view name; std::vector events; }; @@ -354,15 +353,16 @@ struct ScreenCase{ std::optional state = std::nullopt; }; + std::string_view name; Input input; Expectation expectation; }; const ScreenCase SCREEN_CASES[] = { - {.input = {.name = "battle first", .events = {ScreenEvent::BATTLE_STARTED, ScreenEvent::DIALOG_BOX}}, .expectation = {.state = "battle"}}, - {.input = {.name = "text", .events = {ScreenEvent::DIALOG_BOX}}, .expectation = {.state = "text"}}, - {.input = {.name = "overworld", .events = {ScreenEvent::PLAYER_CAN_MOVE}}, .expectation = {.state = "overworld"}}, - {.input = {.name = "image-only state skipped", .events = {ScreenEvent::FADE_WHITE}}, .expectation = {}}, + {.name = "battle first", .input = {.events = {ScreenEvent::BATTLE_STARTED, ScreenEvent::DIALOG_BOX}}, .expectation = {.state = "battle"}}, + {.name = "text", .input = {.events = {ScreenEvent::DIALOG_BOX}}, .expectation = {.state = "text"}}, + {.name = "overworld", .input = {.events = {ScreenEvent::PLAYER_CAN_MOVE}}, .expectation = {.state = "overworld"}}, + {.name = "image-only state skipped", .input = {.events = {ScreenEvent::FADE_WHITE}}, .expectation = {}}, }; ScreenState observation_state(std::string name, ScreenEvent event){ @@ -400,7 +400,7 @@ std::string check_screen(const ScreenCase& test){ class ScreenObservationTest : public UnitTest{ public: explicit ScreenObservationTest(ScreenCase test) - : UnitTest(std::format("Pokemon::StoryEngine screen observation - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine screen observation - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp index 145551ad73..bbed998383 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp @@ -587,7 +587,6 @@ std::string segment_no_reload_for_console_only(CancellableScope& scope){ // only when the one before saved at its end (#329). struct SegmentCase{ struct Input{ - std::string_view name; StoryPhase phase; // Which checkpoint fails once: 0 or 1. size_t flaky = 0; @@ -599,18 +598,19 @@ struct SegmentCase{ size_t saves = 0; }; + std::string_view name; Input input; Expectation expectation; }; const SegmentCase SEGMENT_CASES[] = { - {.input = {.name = "first retries while testing", .phase = StoryPhase::TESTING, .flaky = 0}, + {.name = "first retries while testing", .input = {.phase = StoryPhase::TESTING, .flaky = 0}, .expectation = {.completed = true, .reloads = 1, .saves = 0}}, - {.input = {.name = "second does not retry while testing", .phase = StoryPhase::TESTING, .flaky = 1}, + {.name = "second does not retry while testing", .input = {.phase = StoryPhase::TESTING, .flaky = 1}, .expectation = {.completed = false, .reloads = 0, .saves = 0}}, - {.input = {.name = "second does not retry while verifying", .phase = StoryPhase::VERIFICATION, .flaky = 1}, + {.name = "second does not retry while verifying", .input = {.phase = StoryPhase::VERIFICATION, .flaky = 1}, .expectation = {.completed = false, .reloads = 0, .saves = 0}}, - {.input = {.name = "second retries after a reproduction save", .phase = StoryPhase::REPRODUCTION, .flaky = 1}, + {.name = "second retries after a reproduction save", .input = {.phase = StoryPhase::REPRODUCTION, .flaky = 1}, .expectation = {.completed = true, .reloads = 1, .saves = 2}}, }; @@ -640,7 +640,7 @@ std::string check_segment(const SegmentCase& test, CancellableScope& scope){ class StorySegmentTest : public UnitTest{ public: explicit StorySegmentTest(SegmentCase test) - : UnitTest(std::format("Pokemon::StoryEngine segment - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine segment - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ @@ -655,7 +655,6 @@ class StorySegmentTest : public UnitTest{ // reload and pass lines and attempt counts as its own loop had. struct RetryCase{ struct Input{ - std::string_view name; // Calls of the checkpoint's action that fail before one passes. size_t failures = 0; size_t attempts = 0; @@ -668,18 +667,19 @@ struct RetryCase{ std::vector lines; }; + std::string_view name; Input input; Expectation expectation; }; const RetryCase RETRY_CASES[] = { - {.input = {.name = "pass after a reload", .failures = 1, .attempts = 3}, + {.name = "pass after a reload", .input = {.failures = 1, .attempts = 3}, .expectation = {.passed = true, .attempts = 2, .lines = { "[Checkpoint] 01: failed, resetting for attempt 2/3", "[Test] reload", "[Checkpoint] 01: passed on attempt 2 (1 reset)", }}}, - {.input = {.name = "stop after the last attempt", .failures = 5, .attempts = 2}, + {.name = "stop after the last attempt", .input = {.failures = 5, .attempts = 2}, .expectation = {.passed = false, .attempts = 2, .lines = { "[Checkpoint] 01: failed, resetting for attempt 2/2", "[Test] reload", @@ -711,7 +711,7 @@ std::string check_retry(const RetryCase& test, CancellableScope& scope){ class StoryRetryTest : public UnitTest{ public: explicit StoryRetryTest(RetryCase test) - : UnitTest(std::format("Pokemon::StoryEngine retry - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine retry - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ @@ -749,7 +749,6 @@ std::string verify_saves_after_all_passed(CancellableScope& scope){ struct RunsCase{ // One check above, by name. struct Input{ - std::string_view name; std::string (*check)(CancellableScope& scope); }; @@ -758,33 +757,34 @@ struct RunsCase{ std::string_view error = {}; }; + std::string_view name; Input input; Expectation expectation; }; const RunsCase RUNS_CASES[] = { - {.input = {.name = "zone checkpoint on a fake backend", .check = &zone_checkpoint_runs}, .expectation = {}}, - {.input = {.name = "zone start with tiles fails the lint", .check = &zone_rejects_tiles}, .expectation = {}}, - {.input = {.name = "tile start with a place fails the lint", .check = &grid_rejects_places}, .expectation = {}}, - {.input = {.name = "zone game rejects tile args", .check = &zone_rejects_tile_args}, .expectation = {}}, - {.input = {.name = "tile actions only with tiles", .check = &tile_actions_only_with_tiles}, .expectation = {}}, - {.input = {.name = "stick and heading", .check = &stick_and_heading}, .expectation = {}}, - {.input = {.name = "buttons by name", .check = &buttons_by_name}, .expectation = {}}, - {.input = {.name = "waiting states may stay still", .check = &still_states}, .expectation = {}}, - {.input = {.name = "readers opt in to postconditions", .check = &readers_opt_in}, .expectation = {}}, - {.input = {.name = "observation machine ends", .check = &observation_machine_ends}, .expectation = {}}, - {.input = {.name = "observation machine fails", .check = &observation_machine_fails}, .expectation = {}}, - {.input = {.name = "handler sees its step", .check = &handler_sees_step}, .expectation = {}}, - {.input = {.name = "save gets its checkpoint", .check = &save_gets_checkpoint}, .expectation = {}}, - {.input = {.name = "console_only refused off console", .check = &console_only_refused}, .expectation = {}}, - {.input = {.name = "no reload for console_only", .check = &segment_no_reload_for_console_only}, .expectation = {}}, - {.input = {.name = "verify saves after all passed", .check = &verify_saves_after_all_passed}, .expectation = {}}, + {.name = "zone checkpoint on a fake backend", .input = {.check = &zone_checkpoint_runs}, .expectation = {}}, + {.name = "zone start with tiles fails the lint", .input = {.check = &zone_rejects_tiles}, .expectation = {}}, + {.name = "tile start with a place fails the lint", .input = {.check = &grid_rejects_places}, .expectation = {}}, + {.name = "zone game rejects tile args", .input = {.check = &zone_rejects_tile_args}, .expectation = {}}, + {.name = "tile actions only with tiles", .input = {.check = &tile_actions_only_with_tiles}, .expectation = {}}, + {.name = "stick and heading", .input = {.check = &stick_and_heading}, .expectation = {}}, + {.name = "buttons by name", .input = {.check = &buttons_by_name}, .expectation = {}}, + {.name = "waiting states may stay still", .input = {.check = &still_states}, .expectation = {}}, + {.name = "readers opt in to postconditions", .input = {.check = &readers_opt_in}, .expectation = {}}, + {.name = "observation machine ends", .input = {.check = &observation_machine_ends}, .expectation = {}}, + {.name = "observation machine fails", .input = {.check = &observation_machine_fails}, .expectation = {}}, + {.name = "handler sees its step", .input = {.check = &handler_sees_step}, .expectation = {}}, + {.name = "save gets its checkpoint", .input = {.check = &save_gets_checkpoint}, .expectation = {}}, + {.name = "console_only refused off console", .input = {.check = &console_only_refused}, .expectation = {}}, + {.name = "no reload for console_only", .input = {.check = &segment_no_reload_for_console_only}, .expectation = {}}, + {.name = "verify saves after all passed", .input = {.check = &verify_saves_after_all_passed}, .expectation = {}}, }; class StoryEngineRunsTest : public UnitTest{ public: explicit StoryEngineRunsTest(RunsCase test) - : UnitTest(std::format("Pokemon::StoryEngine runs - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine runs - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp index 5aa882f997..e06c533cc9 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp @@ -131,7 +131,6 @@ struct RegistryCase{ // A step checked and, when it lints clean, dispatched on a backend that // shows talk text once, then the overworld. struct Input{ - std::string_view name; StoryStep step; }; @@ -143,30 +142,31 @@ struct RegistryCase{ std::string_view inputs = {}; }; + std::string_view name; Input input; Expectation expectation; }; const RegistryCase REGISTRY_CASES[] = { - {.input = {.name = "legs tap each tile", .step = make_step(StoryStepKind::LEGS, "", {{"legs", std::vector{{Direction::NORTH, 2}, {Direction::EAST, 1}}}})}, + {.name = "legs tap each tile", .input = {.step = make_step(StoryStepKind::LEGS, "", {{"legs", std::vector{{Direction::NORTH, 2}, {Direction::EAST, 1}}}})}, .expectation = {.inputs = "tap north, tap north, tap east"}}, - {.input = {.name = "legs empty", .step = make_step(StoryStepKind::LEGS, "", {{"legs", std::vector{}}})}, + {.name = "legs empty", .input = {.step = make_step(StoryStepKind::LEGS, "", {{"legs", std::vector{}}})}, .expectation = {.lint = "no legs"}}, - {.input = {.name = "face without direction", .step = make_step(StoryStepKind::STEP, "face", {})}, + {.name = "face without direction", .input = {.step = make_step(StoryStepKind::STEP, "face", {})}, .expectation = {.lint = "missing argument \"direction\" (the way to step or face)"}}, - {.input = {.name = "unknown game action", .step = make_step(StoryStepKind::GAME, "take_wrap", {})}, + {.name = "unknown game action", .input = {.step = make_step(StoryStepKind::GAME, "take_wrap", {})}, .expectation = {.lint = "unknown action \"take_wrap\" for GAME"}}, - {.input = {.name = "talk", .step = make_step(StoryStepKind::TALK, "", {})}, + {.name = "talk", .input = {.step = make_step(StoryStepKind::TALK, "", {})}, .expectation = {.inputs = "press A, press A"}}, - {.input = {.name = "answer no", .step = make_step(StoryStepKind::ANSWER, "", {{"yes", false}})}, + {.name = "answer no", .input = {.step = make_step(StoryStepKind::ANSWER, "", {{"yes", false}})}, .expectation = {.inputs = "press B"}}, - {.input = {.name = "battle", .step = make_step(StoryStepKind::BATTLE, "", {})}, + {.name = "battle", .input = {.step = make_step(StoryStepKind::BATTLE, "", {})}, .expectation = {.inputs = "battle"}}, - {.input = {.name = "ready needs the game", .step = make_step(StoryStepKind::READY, "", {{"target", on_map("CeruleanCity")}})}, + {.name = "ready needs the game", .input = {.step = make_step(StoryStepKind::READY, "", {{"target", on_map("CeruleanCity")}})}, .expectation = {.failure = "unsupported_step"}}, - {.input = {.name = "game route replaces the built-in", .step = make_step(StoryStepKind::ROUTE, "", {{"target", on_map("Route4")}})}, + {.name = "game route replaces the built-in", .input = {.step = make_step(StoryStepKind::ROUTE, "", {{"target", on_map("Route4")}})}, .expectation = {.inputs = "hold north 100ms run"}}, - {.input = {.name = "save without the game's save", .step = make_step(StoryStepKind::SAVE, "", {})}, + {.name = "save without the game's save", .input = {.step = make_step(StoryStepKind::SAVE, "", {})}, .expectation = {.failure = "unsupported_step"}}, }; @@ -195,7 +195,7 @@ std::string check_registry(const RegistryCase& test, CancellableScope& scope){ class StoryActionRegistryTest : public UnitTest{ public: explicit StoryActionRegistryTest(RegistryCase test) - : UnitTest(std::format("Pokemon::StoryEngine registry - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine registry - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ @@ -213,7 +213,6 @@ struct RunnerCase{ // shows the overworld, with `flags` set and the "door_open" reader // reading `door_open`. struct Input{ - std::string_view name; std::string_view step; std::vector flags = {}; std::optional door_open = std::nullopt; @@ -226,22 +225,23 @@ struct RunnerCase{ std::string_view pose_map = {}; }; + std::string_view name; Input input; Expectation expectation; }; const RunnerCase RUNNER_CASES[] = { - {.input = {.name = "skip_if a flag", .step = R"({"id": "s", "kind": "talk", "skip_if": ["got_candy"]})", .flags = {"got_candy"}}, + {.name = "skip_if a flag", .input = {.step = R"({"id": "s", "kind": "talk", "skip_if": ["got_candy"]})", .flags = {"got_candy"}}, .expectation = {.line = "[Step] s TALK/default: skipped"}}, - {.input = {.name = "skip_if a reader", .step = R"({"id": "s", "kind": "talk", "skip_if": ["door_open"]})", .door_open = 1}, + {.name = "skip_if a reader", .input = {.step = R"({"id": "s", "kind": "talk", "skip_if": ["door_open"]})", .door_open = 1}, .expectation = {.line = "[Step] s TALK/default: skipped"}}, - {.input = {.name = "skip_if a reader that says no", .step = R"({"id": "s", "kind": "scene", "skip_if": ["door_open"]})", .door_open = 0}, + {.name = "skip_if a reader that says no", .input = {.step = R"({"id": "s", "kind": "scene", "skip_if": ["door_open"]})", .door_open = 0}, .expectation = {.line = "[Step] s MASH/default: ok"}}, - {.input = {.name = "skip_if nobody answers", .step = R"({"id": "s", "kind": "scene", "skip_if": ["door_open"]})"}, + {.name = "skip_if nobody answers", .input = {.step = R"({"id": "s", "kind": "scene", "skip_if": ["door_open"]})"}, .expectation = {.line = "[Step] s MASH/default: ok"}}, - {.input = {.name = "declared end pose", .step = R"({"id": "s", "kind": "scene", "declared_after": {"map": "Route1", "tiles": [[1, 2]]}})"}, + {.name = "declared end pose", .input = {.step = R"({"id": "s", "kind": "scene", "declared_after": {"map": "Route1", "tiles": [[1, 2]]}})"}, .expectation = {.line = "[Step] s MASH/default: ok", .pose_map = "Route1"}}, - {.input = {.name = "talk to nobody fails", .step = R"({"id": "s", "kind": "talk"})"}, + {.name = "talk to nobody fails", .input = {.step = R"({"id": "s", "kind": "talk"})"}, .expectation = {.failure = "talk_no_text", .line = "[Step] s TALK/default: failed: talk_no_text: A opened no text box"}}, }; @@ -252,7 +252,7 @@ std::string check_runner(const RunnerCase& test, CancellableScope& scope){ StoryStepRunner runner(registry, backend); RunState state; state.flags.insert(test.input.flags.begin(), test.input.flags.end()); - const StoryStep step = read_story_step(parse_json(std::string(test.input.step)), test.input.name, registry.specs()); + const StoryStep step = read_story_step(parse_json(std::string(test.input.step)), test.name, registry.specs()); const Outcome outcome = runner.run(step, state); if (outcome.failure != test.expectation.failure){ return std::format("expected failure \"{}\", got \"{}\"", test.expectation.failure, to_string(outcome)); @@ -270,7 +270,7 @@ std::string check_runner(const RunnerCase& test, CancellableScope& scope){ class StoryStepRunnerTest : public UnitTest{ public: explicit StoryStepRunnerTest(RunnerCase test) - : UnitTest(std::format("Pokemon::StoryEngine runner - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine runner - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ @@ -286,7 +286,6 @@ class StoryStepRunnerTest : public UnitTest{ struct WarpCase{ // take_warp north to B3F, from B4F, on a scripted game. struct Input{ - std::string_view name; std::vector> looks; }; @@ -295,19 +294,20 @@ struct WarpCase{ std::string_view failure = {}; }; + std::string_view name; Input input; Expectation expectation; }; const WarpCase WARP_CASES[] = { - {.input = {.name = "fade then B3F", .looks = { + {.name = "fade then B3F", .input = { .looks = { look({}, on_map("RocketHideout_B4F")), look({ScreenEvent::FADE_BLACK}), look({ScreenEvent::PLAYER_CAN_MOVE}, on_map("RocketHideout_B3F")), }}, .expectation = {}}, // The screen darkens at the stairs but no fade starts and the map // stays B4F: the old wait took this for arrived (00.31's false pass). - {.input = {.name = "black_without_warp", .looks = {look({ScreenEvent::SCREEN_STILL}, on_map("RocketHideout_B4F"))}}, + {.name = "black_without_warp", .input = {.looks = {look({ScreenEvent::SCREEN_STILL}, on_map("RocketHideout_B4F"))}}, .expectation = {.failure = "warp_no_fade"}}, - {.input = {.name = "fade back to B4F", .looks = {look({ScreenEvent::FADE_BLACK}), look({ScreenEvent::PLAYER_CAN_MOVE}, on_map("RocketHideout_B4F"))}}, + {.name = "fade back to B4F", .input = {.looks = {look({ScreenEvent::FADE_BLACK}), look({ScreenEvent::PLAYER_CAN_MOVE}, on_map("RocketHideout_B4F"))}}, .expectation = {.failure = "warp_wrong_map"}}, }; @@ -334,7 +334,7 @@ std::string check_warp(const WarpCase& test, CancellableScope& scope){ class StoryTakeWarpTest : public UnitTest{ public: explicit StoryTakeWarpTest(WarpCase test) - : UnitTest(std::format("Pokemon::StoryEngine take_warp - {}", test.input.name)) + : UnitTest(std::format("Pokemon::StoryEngine take_warp - {}", test.name)) , m_case(std::move(test)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Interrupts_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Interrupts_Tests.cpp index 423d4769eb..c011ce3c26 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Interrupts_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Interrupts_Tests.cpp @@ -181,12 +181,12 @@ UnitTestResult test_watcher_log(){ struct InterruptsCase{ struct Input{ - std::string name; UnitTestResult (*body)(); }; struct Expectation{ }; + std::string name; Input input; Expectation expectation; }; @@ -194,7 +194,7 @@ struct InterruptsCase{ class Test_Interrupts : public UnitTest{ public: explicit Test_Interrupts(InterruptsCase test_case) - : UnitTest(std::format("Pokemon::Interrupts - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::Interrupts - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -209,7 +209,6 @@ class Test_Interrupts : public UnitTest{ struct ClassifyCase{ // A synthetic scene, and the window of it to judge. struct Input{ - std::string name; std::vector frames; int until_ms = 0; InterruptKnobs knobs = {}; @@ -220,6 +219,7 @@ struct ClassifyCase{ std::string verdict; }; + std::string name; Input input; Expectation expectation; }; @@ -227,7 +227,7 @@ struct ClassifyCase{ class Test_InterruptClassify : public UnitTest{ public: explicit Test_InterruptClassify(ClassifyCase test_case) - : UnitTest(std::format("Pokemon::Interrupts - classify: {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::Interrupts - classify: {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -246,7 +246,6 @@ class Test_InterruptClassify : public UnitTest{ struct StepTimeCase{ // A synthetic scene, classified over all of it, and the lags to time it. struct Input{ - std::string name; std::vector frames; int until_ms = 0; std::vector lags; @@ -256,6 +255,7 @@ struct StepTimeCase{ std::string step; }; + std::string name; Input input; Expectation expectation; }; @@ -263,7 +263,7 @@ struct StepTimeCase{ class Test_InterruptStepTime : public UnitTest{ public: explicit Test_InterruptStepTime(StepTimeCase test_case) - : UnitTest(std::format("Pokemon::Interrupts - step time: {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::Interrupts - step time: {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -285,123 +285,147 @@ class Test_InterruptStepTime : public UnitTest{ const InterruptsCase INTERRUPTS_CASES[] = { { - .input = {"the log keeps rises and falls in order, timed", test_log_records_rises_and_falls}, + .name = "the log keeps rises and falls in order, timed", + .input = {test_log_records_rises_and_falls}, .expectation = {}, }, { - .input = {"a full log drops its oldest changes and says so", test_log_overflow_and_clear}, + .name = "a full log drops its oldest changes and says so", + .input = {test_log_overflow_and_clear}, .expectation = {}, }, { - .input = {"an empty log is no interrupt and no fade", test_empty_log}, + .name = "an empty log is no interrupt and no fade", + .input = {test_empty_log}, .expectation = {}, }, { - .input = {"a warp is down, held, back up, not the same scene", test_judge_warp}, + .name = "a warp is down, held, back up, not the same scene", + .input = {test_judge_warp}, .expectation = {}, }, { - .input = {"a watcher keeps a timed log", test_watcher_log}, + .name = "a watcher keeps a timed log", + .input = {test_watcher_log}, .expectation = {}, }, }; const ClassifyCase CLASSIFY_CASES[] = { { - .input = {"an encounter's white flash, then the battle", + .name = "an encounter's white flash, then the battle", + .input = { {{0, WALK}, {1000, WHITE}, {1300, ScreenEvents()}, {3000, BATTLE}}, 3000}, .expectation = {"wild encounter: +1000 ms white fade rose, +3000 ms battle started rose"}, }, { - .input = {"a wild battle's opening text comes after its flash", + .name = "a wild battle's opening text comes after its flash", + .input = { {{0, WALK}, {1000, WHITE}, {1300, BATTLE_TEXT}, {2500, BATTLE}}, 2500}, .expectation = {"wild encounter: +1000 ms white fade rose, +2500 ms battle started rose"}, }, { - .input = {"a trainer's lines, a pause, the battle's fade", + .name = "a trainer's lines, a pause, the battle's fade", + .input = { {{0, WALK}, {1000, BOX}, {2000, WALK}, {6000, BLACK}, {6400, BATTLE}}, 6400}, .expectation = {"trainer sight: +1000 ms dialog box rose, +6000 ms black fade rose, +6400 ms battle started rose"}, }, { - .input = {"a trainer's lines, then the battle with no fade seen", + .name = "a trainer's lines, then the battle with no fade seen", + .input = { {{0, WALK}, {1000, BOX}, {2000, BATTLE}}, 2000}, .expectation = {"trainer sight: +1000 ms dialog box rose, +2000 ms battle started rose"}, }, { - .input = {"a box and no battle", {{0, WALK}, {1000, BOX}}, 20000}, + .name = "a box and no battle", + .input = {{{0, WALK}, {1000, BOX}}, 20000}, .expectation = {"dialog: +1000 ms dialog box rose"}, }, { - .input = {"a cave exit's white fade, and no battle for 8 s", + .name = "a cave exit's white fade, and no battle for 8 s", + .input = { {{0, WALK}, {1000, WHITE}, {1600, WALK}}, 12000}, .expectation = {"warp: +1000 ms white fade rose, +1600 ms white fade fell"}, }, { - .input = {"a white fade too recent to rule out a battle", + .name = "a white fade too recent to rule out a battle", + .input = { {{0, WALK}, {1000, WHITE}, {1600, WALK}}, 4000}, .expectation = {"unsettled: +1000 ms white fade rose, +1600 ms white fade fell"}, }, { - .input = {"a fade still showing", {{0, WALK}, {1000, BLACK}}, 3000}, + .name = "a fade still showing", + .input = {{{0, WALK}, {1000, BLACK}}, 3000}, .expectation = {"unsettled: +1000 ms black fade rose"}, }, { - .input = {"a banner after the white settles it at once", + .name = "a banner after the white settles it at once", + .input = { {{0, WALK}, {1000, WHITE}, {1600, WALK}, {2000, BANNER}}, 2500}, .expectation = {"warp: +1000 ms white fade rose, +1600 ms white fade fell, +2000 ms location banner rose"}, }, { - .input = {"a box during a fade is the scene cut's", + .name = "a box during a fade is the scene cut's", + .input = { {{0, WALK}, {1000, BLACK}, {1300, ScreenEvents{ScreenEvent::FADE_BLACK, ScreenEvent::DIALOG_BOX}}, {1800, BOX}, {3000, WALK}}, 12000}, .expectation = {"warp: +1000 ms black fade rose, +1800 ms black fade fell"}, }, { - .input = {"a door's fade long before a battle is not the battle's", + .name = "a door's fade long before a battle is not the battle's", + .input = { {{0, WALK}, {500, BLACK}, {900, WALK}, {20000, BATTLE}}, 20000}, .expectation = {"wild encounter: +20000 ms battle started rose"}, }, { - .input = {"a box up before the window is not this interrupt's", + .name = "a box up before the window is not this interrupt's", + .input = { {{0, BOX}, {1000, WALK}, {3000, WHITE}, {3300, WALK}, {5000, BATTLE}}, 5000, {}, 500}, .expectation = {"wild encounter: +3000 ms white fade rose, +5000 ms battle started rose"}, }, { - .input = {"a one-frame flicker is no fade with a hold to meet", + .name = "a one-frame flicker is no fade with a hold to meet", + .input = { {{0, WALK}, {1000, BLACK}, {1050, WALK}}, 12000, {.min_fade_hold = 200ms}}, .expectation = {"none"}, }, { - .input = {"a one-frame fade is a warp by default", + .name = "a one-frame fade is a warp by default", + .input = { {{0, WALK}, {1000, BLACK}, {1050, WALK}}, 12000}, .expectation = {"warp: +1000 ms black fade rose, +1050 ms black fade fell"}, }, { - .input = {"a walk with nothing in it", {{0, WALK}}, 5000}, + .name = "a walk with nothing in it", + .input = {{{0, WALK}}, 5000}, .expectation = {"none"}, }, }; const StepTimeCase STEP_TIME_CASES[] = { { - .input = {"a wild battle's box, its fade untimed", + .name = "a wild battle's box, its fade untimed", + .input = { {{0, WALK}, {1500, BLACK}, {2000, ScreenEvents()}, {4400, BATTLE}}, 6000, {{ScreenEvent::BATTLE_STARTED, 3700ms}}}, .expectation = {"+700 ms"}, }, { - .input = {"the first timed rise wins", + .name = "the first timed rise wins", + .input = { {{0, WALK}, {1500, BLACK}, {2000, ScreenEvents()}, {4400, BATTLE}}, 6000, {{ScreenEvent::BATTLE_STARTED, 3700ms}, {ScreenEvent::FADE_BLACK, 1000ms}}}, .expectation = {"+500 ms"}, }, { - .input = {"no lags, no time", + .name = "no lags, no time", + .input = { {{0, WALK}, {4400, BATTLE}}, 6000, {}}, .expectation = {"none"}, }, { - .input = {"no interrupt, no time", + .name = "no interrupt, no time", + .input = { {{0, WALK}}, 6000, {{ScreenEvent::BATTLE_STARTED, 3700ms}}}, .expectation = {"none"}, }, diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_SceneJudges_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_SceneJudges_Tests.cpp index a567c1db2a..3416ce65b4 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_SceneJudges_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_SceneJudges_Tests.cpp @@ -116,13 +116,13 @@ UnitTestResult test_talk_over(){ struct SceneJudgesCase{ struct Input{ - std::string name; UnitTestResult (*body)(); }; struct Expectation{ }; + std::string name; Input input; Expectation expectation; }; @@ -130,7 +130,7 @@ struct SceneJudgesCase{ class Test_SceneJudges : public UnitTest{ public: explicit Test_SceneJudges(SceneJudgesCase test_case) - : UnitTest(std::format("Pokemon::SceneJudges - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::SceneJudges - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -146,11 +146,13 @@ class Test_SceneJudges : public UnitTest{ const SceneJudgesCase SCENE_JUDGES_CASES[] = { { - .input = {"a warp is the first fade and the first banner seen", test_warp_seen}, + .name = "a warp is the first fade and the first banner seen", + .input = {test_warp_seen}, .expectation = {}, }, { - .input = {"talk-over from scripted events", test_talk_over}, + .name = "talk-over from scripted events", + .input = {test_talk_over}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.cpp index a4e8020210..1da22e8c9a 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.cpp @@ -255,7 +255,6 @@ UnitTestResult test_guard_stop_rethrows(){ struct StoryActionsCase{ struct Input{ - std::string_view name; UnitTestResult (*test)(); }; @@ -263,6 +262,7 @@ struct StoryActionsCase{ std::string_view description; }; + std::string_view name; Input input; Expectation expectation; }; @@ -270,7 +270,7 @@ struct StoryActionsCase{ class Test_StoryActions : public UnitTest{ public: explicit Test_StoryActions(StoryActionsCase scenario) - : UnitTest(std::format("Pokemon::StoryActions - {}", scenario.input.name)) + : UnitTest(std::format("Pokemon::StoryActions - {}", scenario.name)) , m_scenario(scenario) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -283,27 +283,33 @@ class Test_StoryActions : public UnitTest{ const StoryActionsCase STORY_ACTIONS_CASES[] = { { - .input = {.name = "table: exact, then any kind, then the kind's default", .test = test_lookup_order}, + .name = "table: exact, then any kind, then the kind's default", + .input = {.test = test_lookup_order}, .expectation = {.description = "finds the most specific action, or none"}, }, { - .input = {.name = "table: a second action for a key throws", .test = test_duplicate_actions_throw}, + .name = "table: a second action for a key throws", + .input = {.test = test_duplicate_actions_throw}, .expectation = {.description = "keeps the first action and rejects nameless any-kind actions"}, }, { - .input = {.name = "lint: steps without an action", .test = test_lint_names_steps_without_actions}, + .name = "lint: steps without an action", + .input = {.test = test_lint_names_steps_without_actions}, .expectation = {.description = "names each step the table has no action for"}, }, { - .input = {.name = "executor: the table, then the binding", .test = test_executor_uses_table_then_binding}, + .name = "executor: the table, then the binding", + .input = {.test = test_executor_uses_table_then_binding}, .expectation = {.description = "a step without a table action is the binding's or unsupported, guarded before every step"}, }, { - .input = {.name = "executor: a console failure fails the step", .test = test_guard_turns_failures_into_outcomes}, + .name = "executor: a console failure fails the step", + .input = {.test = test_guard_turns_failures_into_outcomes}, .expectation = {.description = "turns OperationFailedException into operation_failed and tells the guard"}, }, { - .input = {.name = "executor: a stop row rethrows", .test = test_guard_stop_rethrows}, + .name = "executor: a stop row rethrows", + .input = {.test = test_guard_stop_rethrows}, .expectation = {.description = "rethrows on a stop row and passes other exceptions through"}, }, }; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryInterrupts_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryInterrupts_Tests.cpp index e994e11745..29a64ef7eb 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryInterrupts_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryInterrupts_Tests.cpp @@ -665,7 +665,6 @@ UnitTestResult test_settle_of_a_look(){ struct StoryInterruptsCase{ struct Input{ - std::string_view name; UnitTestResult (*test)(); }; @@ -673,6 +672,7 @@ struct StoryInterruptsCase{ std::string_view description; }; + std::string_view name; Input input; Expectation expectation; }; @@ -680,7 +680,7 @@ struct StoryInterruptsCase{ class Test_StoryInterrupts : public UnitTest{ public: explicit Test_StoryInterrupts(StoryInterruptsCase scenario) - : UnitTest(std::format("Pokemon::StoryInterrupts - {}", scenario.input.name)) + : UnitTest(std::format("Pokemon::StoryInterrupts - {}", scenario.name)) , m_scenario(scenario) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -693,111 +693,138 @@ class Test_StoryInterrupts : public UnitTest{ const StoryInterruptsCase STORY_INTERRUPTS_CASES[] = { { - .input = {.name = "no interrupts set: no look", .test = test_no_interrupts_set}, + .name = "no interrupts set: no look", + .input = {.test = test_no_interrupts_set}, .expectation = {.description = "the executor runs the step as before"}, }, { - .input = {.name = "a quiet screen: one look, then the step", .test = test_quiet_screen}, + .name = "a quiet screen: one look, then the step", + .input = {.test = test_quiet_screen}, .expectation = {.description = "nothing cleared, the pose kept"}, }, { - .input = {.name = "a wild encounter before a step", .test = test_wild_encounter}, + .name = "a wild encounter before a step", + .input = {.test = test_wild_encounter}, .expectation = {.description = "the wild handler, then the step"}, }, { - .input = {.name = "a trainer's sight before a step", .test = test_trainer_sight}, + .name = "a trainer's sight before a step", + .input = {.test = test_trainer_sight}, .expectation = {.description = "the trainer handler, then the step"}, }, { - .input = {.name = "a dialog before a step", .test = test_dialog}, + .name = "a dialog before a step", + .input = {.test = test_dialog}, .expectation = {.description = "the dialog handler, then the step"}, }, { - .input = {.name = "a warp before a step", .test = test_warp}, + .name = "a warp before a step", + .input = {.test = test_warp}, .expectation = {.description = "the warp handler, the pose lost, then the step"}, }, { - .input = {.name = "a step that starts on it", .test = test_step_starts_on_it}, + .name = "a step that starts on it", + .input = {.test = test_step_starts_on_it}, .expectation = {.description = "a MASH's box is the step's, not an interrupt"}, }, { - .input = {.name = "a handler that fails fails the step", .test = test_handler_fails_the_step}, + .name = "a handler that fails fails the step", + .input = {.test = test_handler_fails_the_step}, .expectation = {.description = "interrupt_failed, the step not run"}, }, { - .input = {.name = "a kind with no handler fails the step", .test = test_unhandled_kind}, + .name = "a kind with no handler fails the step", + .input = {.test = test_unhandled_kind}, .expectation = {.description = "unhandled_interrupt, the step not run"}, }, { - .input = {.name = "unsettled: look again until it settles", .test = test_unsettled_looks_again}, + .name = "unsettled: look again until it settles", + .input = {.test = test_unsettled_looks_again}, .expectation = {.description = "a white with no battle after it is a warp"}, }, { - .input = {.name = "unsettled: at most max_looks looks", .test = test_unsettled_is_bounded}, + .name = "unsettled: at most max_looks looks", + .input = {.test = test_unsettled_is_bounded}, .expectation = {.description = "a door's fade: interrupt_unsettled after three looks"}, }, { - .input = {.name = "unsettled: a battle's opening before a battle step", .test = test_unsettled_before_a_battle}, + .name = "unsettled: a battle's opening before a battle step", + .input = {.test = test_unsettled_before_a_battle}, .expectation = {.description = "the step's, after one look"}, }, { - .input = {.name = "unsettled: a wild battle's opening before a walk", .test = test_wild_opening_before_a_walk}, + .name = "unsettled: a wild battle's opening before a walk", + .input = {.test = test_wild_opening_before_a_walk}, .expectation = {.description = "waits for the battle, clears it, then the walk"}, }, { - .input = {.name = "unsettled: a trainer battle's opening before a walk", .test = test_trainer_opening_before_a_walk}, + .name = "unsettled: a trainer battle's opening before a walk", + .input = {.test = test_trainer_opening_before_a_walk}, .expectation = {.description = "waits for the battle, fights it, then the walk"}, }, { - .input = {.name = "unsettled: at most max_opening_looks for an opening", .test = test_opening_is_bounded}, + .name = "unsettled: at most max_opening_looks for an opening", + .input = {.test = test_opening_is_bounded}, .expectation = {.description = "a white with no battle: interrupt_unsettled"}, }, { - .input = {.name = "a failed step an interrupt explains runs again", .test = test_failed_outcome_explained}, + .name = "a failed step an interrupt explains runs again", + .input = {.test = test_failed_outcome_explained}, .expectation = {.description = "cleared after the failure, then the step again"}, }, { - .input = {.name = "a thrown step an interrupt explains runs again", .test = test_thrown_failure_explained}, + .name = "a thrown step an interrupt explains runs again", + .input = {.test = test_thrown_failure_explained}, .expectation = {.description = "the console's failure too"}, }, { - .input = {.name = "a failed step with nothing on screen fails", .test = test_failure_not_explained}, + .name = "a failed step with nothing on screen fails", + .input = {.test = test_failure_not_explained}, .expectation = {.description = "the step's own failure, run once"}, }, { - .input = {.name = "too many interrupts fail the step", .test = test_too_many_interrupts}, + .name = "too many interrupts fail the step", + .input = {.test = test_too_many_interrupts}, .expectation = {.description = "the step's failure once max_per_step are cleared"}, }, { - .input = {.name = "table: one handler a kind that can be cleared", .test = test_table_rejects}, + .name = "table: one handler a kind that can be cleared", + .input = {.test = test_table_rejects}, .expectation = {.description = "rejects NONE, UNSETTLED and a second handler"}, }, { - .input = {.name = "the screen before each step, for the log", .test = test_screen_before_each_step}, + .name = "the screen before each step, for the log", + .input = {.test = test_screen_before_each_step}, .expectation = {.description = "a fade still down is told, and fails unsettled; a quiet overworld is settled"}, }, { - .input = {.name = "how a look ended", .test = test_settle_of_a_look}, + .name = "how a look ended", + .input = {.test = test_settle_of_a_look}, .expectation = {.description = "the last frame's events and how long they held"}, }, { - .input = {.name = "the HOME menu before a step", .test = test_home_menu_before_a_step}, + .name = "the HOME menu before a step", + .input = {.test = test_home_menu_before_a_step}, .expectation = {.description = "told as HOME; game_not_running before any input"}, }, { - .input = {.name = "the HOME menu stops the segment", .test = test_home_menu_stops_the_segment}, + .name = "the HOME menu stops the segment", + .input = {.test = test_home_menu_stops_the_segment}, .expectation = {.description = "no recovery in place, no reload"}, }, { - .input = {.name = "a handler that throws fails the step", .test = test_handler_throws}, + .name = "a handler that throws fails the step", + .input = {.test = test_handler_throws}, .expectation = {.description = "interrupt_failed, the step not run, nothing escapes"}, }, { - .input = {.name = "a handler that throws after a failed step", .test = test_handler_throws_after_a_failure}, + .name = "a handler that throws after a failed step", + .input = {.test = test_handler_throws_after_a_failure}, .expectation = {.description = "the step's own failure, nothing escapes"}, }, { - .input = {.name = "the HOME menu after a failed step", .test = test_home_menu_after_a_failed_step}, + .name = "the HOME menu after a failed step", + .input = {.test = test_home_menu_after_a_failed_step}, .expectation = {.description = "game_not_running instead of the step's failure, run once"}, }, }; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp index a5733d5bce..3754b5e250 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRngHandoff_Tests.cpp @@ -19,24 +19,22 @@ namespace Pokemon{ namespace{ -struct RngHandoffInput{ - std::string_view name; - UnitTestResult (*body)(Logger& logger); -}; - -struct RngHandoffExpectation{ - std::string_view description; -}; - struct RngHandoffTestCase{ - RngHandoffInput input; - RngHandoffExpectation expectation; + struct Input{ + UnitTestResult (*body)(Logger& logger); + }; + struct Expectation{ + std::string_view description; + }; + std::string_view name; + Input input; + Expectation expectation; }; class Test_RngHandoff : public UnitTest{ public: explicit Test_RngHandoff(RngHandoffTestCase scenario) - : UnitTest("Pokemon::StoryRngHandoff - " + std::string(scenario.input.name)) + : UnitTest("Pokemon::StoryRngHandoff - " + std::string(scenario.name)) , m_scenario(scenario) {} @@ -154,23 +152,28 @@ UnitTestResult test_stop_report(Logger& logger){ const RngHandoffTestCase RNG_HANDOFF_CASES[] = { { - .input = {.name = "RUN takes precedence over STOP", .body = test_mode}, + .name = "RUN takes precedence over STOP", + .input = {.body = test_mode}, .expectation = {.description = "RUN wins when both options are on"}, }, { - .input = {.name = "a stop reports its message and lines", .body = test_stop_report}, + .name = "a stop reports its message and lines", + .input = {.body = test_stop_report}, .expectation = {.description = "log, overlay and notification text agree"}, }, { - .input = {.name = "a success is ok", .body = test_success}, + .name = "a success is ok", + .input = {.body = test_success}, .expectation = {.description = "an ok outcome after one call"}, }, { - .input = {.name = "a failure throws without a retry", .body = test_failure}, + .name = "a failure throws without a retry", + .input = {.body = test_failure}, .expectation = {.description = "OperationFailedException after one call"}, }, { - .input = {.name = "a user's turn is returned, not an error", .body = test_user_turn}, + .name = "a user's turn is returned, not an error", + .input = {.body = test_user_turn}, .expectation = {.description = "the message comes back; a failure still throws"}, }, }; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.cpp index b1c187331b..0582397300 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryRun_Tests.cpp @@ -64,7 +64,6 @@ struct FakeGame{ // A start as the program asks for it, and what the game must have done. struct StartCase{ struct Input{ - std::string name; StoryStart start; std::string place_error; StoryPreflight preflight; @@ -75,6 +74,7 @@ struct StartCase{ size_t rereads; bool save_loaded; }; + std::string name; Input input; Expectation expectation; }; @@ -99,7 +99,7 @@ std::string_view start_name(StoryStart start){ class Test_StoryStart : public UnitTest{ public: Test_StoryStart(StartCase test_case) - : UnitTest(std::format("Pokemon::StoryRun - start: {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryRun - start: {}", test_case.name)) , m_case(std::move(test_case)) {} @@ -137,37 +137,45 @@ const StartCase START_CASES[] = { // A game left at a later checkpoint must not be walked from: a // checkpoint with a save loads that save first. { - .input = {.name = "a checkpoint with a save loads it first", .start = StoryStart::FROM_SAVE, .place_error = "", .preflight = READY}, + .name = "a checkpoint with a save loads it first", + .input = {.start = StoryStart::FROM_SAVE, .place_error = "", .preflight = READY}, .expectation = {.succeeds = true, .loads = 1, .rereads = 1, .save_loaded = true}, }, { - .input = {.name = "a save in the wrong place fails before rereading it", .start = StoryStart::FROM_SAVE, .place_error = "The save is in Pewter City.", .preflight = READY}, + .name = "a save in the wrong place fails before rereading it", + .input = {.start = StoryStart::FROM_SAVE, .place_error = "The save is in Pewter City.", .preflight = READY}, .expectation = {.succeeds = false, .loads = 1, .rereads = 0, .save_loaded = false}, }, { - .input = {.name = "a new game loads nothing", .start = StoryStart::NEW_GAME, .place_error = "", .preflight = READY}, + .name = "a new game loads nothing", + .input = {.start = StoryStart::NEW_GAME, .place_error = "", .preflight = READY}, .expectation = {.succeeds = true, .loads = 0, .rereads = 0, .save_loaded = false}, }, { - .input = {.name = "a live start loads nothing", .start = StoryStart::LIVE, .place_error = "", .preflight = READY}, + .name = "a live start loads nothing", + .input = {.start = StoryStart::LIVE, .place_error = "", .preflight = READY}, .expectation = {.succeeds = true, .loads = 0, .rereads = 0, .save_loaded = false}, }, // The game is on the HOME menu: every press would go to the console's // menus, so the preflight stops the run before any press. { - .input = {.name = "the HOME menu stops the run before the load", .start = StoryStart::FROM_SAVE, .place_error = "", .preflight = ON_HOME}, + .name = "the HOME menu stops the run before the load", + .input = {.start = StoryStart::FROM_SAVE, .place_error = "", .preflight = ON_HOME}, .expectation = {.succeeds = false, .loads = 0, .rereads = 0, .save_loaded = false}, }, { - .input = {.name = "the HOME menu stops a live start", .start = StoryStart::LIVE, .place_error = "", .preflight = ON_HOME}, + .name = "the HOME menu stops a live start", + .input = {.start = StoryStart::LIVE, .place_error = "", .preflight = ON_HOME}, .expectation = {.succeeds = false, .loads = 0, .rereads = 0, .save_loaded = false}, }, { - .input = {.name = "dead video stops the run before the load", .start = StoryStart::FROM_SAVE, .place_error = "", .preflight = NO_VIDEO}, + .name = "dead video stops the run before the load", + .input = {.start = StoryStart::FROM_SAVE, .place_error = "", .preflight = NO_VIDEO}, .expectation = {.succeeds = false, .loads = 0, .rereads = 0, .save_loaded = false}, }, { - .input = {.name = "a controller not ready stops the run before the load", .start = StoryStart::FROM_SAVE, .place_error = "", .preflight = NO_CONTROLLER}, + .name = "a controller not ready stops the run before the load", + .input = {.start = StoryStart::FROM_SAVE, .place_error = "", .preflight = NO_CONTROLLER}, .expectation = {.succeeds = false, .loads = 0, .rereads = 0, .save_loaded = false}, }, }; @@ -177,12 +185,12 @@ const StartCase START_CASES[] = { // the story's, naming every check that failed. struct PreflightCase{ struct Input{ - std::string name; StoryPreflight preflight; }; struct Expectation{ std::string outcome; }; + std::string name; Input input; Expectation expectation; }; @@ -190,7 +198,7 @@ struct PreflightCase{ class Test_StoryPreflight : public UnitTest{ public: Test_StoryPreflight(PreflightCase test_case) - : UnitTest(std::format("Pokemon::StoryRun - preflight: {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryRun - preflight: {}", test_case.name)) , m_case(std::move(test_case)) {} @@ -207,13 +215,15 @@ class Test_StoryPreflight : public UnitTest{ }; const PreflightCase PREFLIGHT_CASES[] = { - {.input = {.name = "a ready console passes", .preflight = READY}, .expectation = {.outcome = ""}}, + {.name = "a ready console passes", .input = {.preflight = READY}, .expectation = {.outcome = ""}}, { - .input = {.name = "the HOME menu", .preflight = ON_HOME}, + .name = "the HOME menu", + .input = {.preflight = ON_HOME}, .expectation = {.outcome = "precondition_failed: the game is not running"}, }, { - .input = {.name = "every check failed", .preflight = StoryPreflight{}}, + .name = "every check failed", + .input = {.preflight = StoryPreflight{}}, .expectation = {.outcome = "precondition_failed: no live video; the controller is not ready; the game is not running"}, }, }; @@ -229,6 +239,7 @@ struct FirstSaveCase{ struct Expectation{ bool saves; }; + std::string_view name; Input input; Expectation expectation; }; @@ -236,7 +247,7 @@ struct FirstSaveCase{ class Test_StoryFirstSave : public UnitTest{ public: Test_StoryFirstSave(FirstSaveCase test_case) - : UnitTest(std::format("Pokemon::StoryRun - first save: {}", start_name(test_case.input.start))) + : UnitTest(std::format("Pokemon::StoryRun - first save: {}", test_case.name)) , m_case(test_case) {} @@ -252,22 +263,22 @@ class Test_StoryFirstSave : public UnitTest{ }; const FirstSaveCase FIRST_SAVE_CASES[] = { - {.input = {.start = StoryStart::NEW_GAME}, .expectation = {.saves = true}}, - {.input = {.start = StoryStart::FROM_SAVE}, .expectation = {.saves = false}}, - {.input = {.start = StoryStart::LIVE}, .expectation = {.saves = false}}, + {.name = "a new game", .input = {.start = StoryStart::NEW_GAME}, .expectation = {.saves = true}}, + {.name = "its save", .input = {.start = StoryStart::FROM_SAVE}, .expectation = {.saves = false}}, + {.name = "the game as it is", .input = {.start = StoryStart::LIVE}, .expectation = {.saves = false}}, }; // A failed attempt's reload loads the save through the game. struct ReloadCase{ struct Input{ - std::string name; }; struct Expectation{ size_t loads; size_t rereads; std::string log_line; }; + std::string name; Input input; Expectation expectation; }; @@ -275,7 +286,7 @@ struct ReloadCase{ class Test_StoryReload : public UnitTest{ public: Test_StoryReload(const ReloadCase& test_case) - : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.name)) , m_case(test_case) {} @@ -298,7 +309,8 @@ class Test_StoryReload : public UnitTest{ const ReloadCase RELOAD_CASES[] = { { - .input = {.name = "a retry reloads the save"}, + .name = "a retry reloads the save", + .input = {}, .expectation = {.loads = 1, .rereads = 1, .log_line = "[Story] retry: loading the save"}, }, }; @@ -308,7 +320,6 @@ const ReloadCase RELOAD_CASES[] = { // nothing in the game: no reload, no save, no reset to HOME. struct FailureCase{ struct Input{ - std::string name; std::string checkpoint; std::string event; std::string stopped_after; @@ -316,6 +327,7 @@ struct FailureCase{ struct Expectation{ std::string message; }; + std::string name; Input input; Expectation expectation; }; @@ -323,7 +335,7 @@ struct FailureCase{ class Test_StoryFailureLeavesGame : public UnitTest{ public: Test_StoryFailureLeavesGame(const FailureCase& test_case) - : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.name)) , m_case(test_case) {} @@ -361,7 +373,8 @@ class Test_StoryFailureLeavesGame : public UnitTest{ const FailureCase FAILURE_CASES[] = { { - .input = {.name = "a failed run leaves the game where it failed", .checkpoint = "00.04b", .event = "talk_mom", .stopped_after = "00.05"}, + .name = "a failed run leaves the game where it failed", + .input = {.checkpoint = "00.04b", .event = "talk_mom", .stopped_after = "00.05"}, .expectation = {.message = "AutoStory stopped at 00.04b talk_mom: expect_failed: dialogue opened"}, }, }; @@ -370,12 +383,12 @@ const FailureCase FAILURE_CASES[] = { // A completed run logs and returns the line the finish notification sends. struct FinishedCase{ struct Input{ - std::string name; std::string last_checkpoint; }; struct Expectation{ std::string line; }; + std::string name; Input input; Expectation expectation; }; @@ -383,7 +396,7 @@ struct FinishedCase{ class Test_StoryFinished : public UnitTest{ public: Test_StoryFinished(const FinishedCase& test_case) - : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.name)) , m_case(test_case) {} @@ -406,7 +419,8 @@ class Test_StoryFinished : public UnitTest{ const FinishedCase FINISHED_CASES[] = { { - .input = {.name = "a completed run is done through its last checkpoint", .last_checkpoint = "00.05"}, + .name = "a completed run is done through its last checkpoint", + .input = {.last_checkpoint = "00.05"}, .expectation = {.line = "AutoStory: done through 00.05."}, }, }; @@ -415,13 +429,13 @@ const FinishedCase FINISHED_CASES[] = { // A verify run short of its passes throws with the summary. struct VerifyCase{ struct Input{ - std::string name; std::string checkpoint; size_t passes; }; struct Expectation{ std::string message; }; + std::string name; Input input; Expectation expectation; }; @@ -429,7 +443,7 @@ struct VerifyCase{ class Test_StoryVerifyFailed : public UnitTest{ public: Test_StoryVerifyFailed(const VerifyCase& test_case) - : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryRun - {}", test_case.name)) , m_case(test_case) {} @@ -459,7 +473,8 @@ class Test_StoryVerifyFailed : public UnitTest{ const VerifyCase VERIFY_CASES[] = { { - .input = {.name = "an unverified checkpoint fails with its summary", .checkpoint = "00.15b", .passes = 1}, + .name = "an unverified checkpoint fails with its summary", + .input = {.checkpoint = "00.15b", .passes = 1}, .expectation = {.message = "AutoStory verify: 00.15b 1/3 passed, 2 needed."}, }, }; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Transitions_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Transitions_Tests.cpp index a91b6fa631..46dd8f100b 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Transitions_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_Transitions_Tests.cpp @@ -85,7 +85,6 @@ std::string run_tracker(const std::vector& spans, TransitionTracker& track struct TrackCase{ // A synthetic stream of frames, through one game's profile. struct Input{ - std::string name; std::vector spans; const FadeProfile* profile = &BDSP_FADE_PROFILE; bool compare = true; @@ -99,6 +98,7 @@ struct TrackCase{ std::string warp = ""; }; + std::string name; Input input; Expectation expectation; }; @@ -106,7 +106,7 @@ struct TrackCase{ class Test_TransitionTracker : public UnitTest{ public: explicit Test_TransitionTracker(TrackCase test_case) - : UnitTest(std::format("Pokemon::Transitions - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::Transitions - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -178,6 +178,7 @@ struct CapturedCase{ struct Expectation{ }; + std::string name; Input input; Expectation expectation; }; @@ -218,7 +219,7 @@ std::string track_captured_case(const Filesystem::Path& folder, const FadeProfil class Test_CapturedTransitions : public UnitTest{ public: explicit Test_CapturedTransitions(CapturedCase test_case) - : UnitTest(std::format("Pokemon::Transitions - captured frames: {}", test_case.input.game)) + : UnitTest(std::format("Pokemon::Transitions - captured frames: {}", test_case.name)) , m_input(std::move(test_case.input)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -247,7 +248,6 @@ class Test_CapturedTransitions : public UnitTest{ struct TransitionsCase{ struct Input{ - std::string name; UnitTestResult (*body)(); }; @@ -255,6 +255,7 @@ struct TransitionsCase{ struct Expectation{ }; + std::string name; Input input; Expectation expectation; }; @@ -262,7 +263,7 @@ struct TransitionsCase{ class Test_Transitions : public UnitTest{ public: explicit Test_Transitions(TransitionsCase test_case) - : UnitTest(std::format("Pokemon::Transitions - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::Transitions - {}", test_case.name)) , m_input(std::move(test_case.input)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -278,92 +279,110 @@ class Test_Transitions : public UnitTest{ const TrackCase TRACK_CASES[] = { { - .input = {"a door: falls, holds, rises onto another scene", + .name = "a door: falls, holds, rises onto another scene", + .input = { {{0, 100, ROUTE}, {200, 200, FALLING_DARK}, {300, 700, DARK}, {800, 800, FALLING_DARK}, {900, 1000, HOUSE}}}, .expectation = {"black fade +200 ms, peak +300 ms, rise +800 ms, end +900 ms, other scene", "warped"}, }, { - .input = {"a missed short fade: falling, then another scene", + .name = "a missed short fade: falling, then another scene", + .input = { {{0, 100, ROUTE}, {200, 200, FALLING_DARK}, {300, 400, HOUSE}}}, .expectation = {"black fade +200 ms, peak unseen, rise unseen, end +300 ms, other scene", "warped"}, }, { - .input = {"a missed fade is not reported with no scene comparison", + .name = "a missed fade is not reported with no scene comparison", + .input = { {{0, 100, ROUTE}, {200, 200, FALLING_DARK}, {300, 400, HOUSE}}, &BDSP_FADE_PROFILE, false}, .expectation = {"none"}, }, { - .input = {"a dip back onto the same scene is no transition", + .name = "a dip back onto the same scene is no transition", + .input = { {{0, 100, ROUTE}, {200, 300, FALLING_DARK}, {400, 500, ROUTE}}}, .expectation = {"none"}, }, { - .input = {"a one-frame black onto the same scene is too short", + .name = "a one-frame black onto the same scene is too short", + .input = { {{0, 100, ROUTE}, {200, 200, DARK}, {300, 400, ROUTE}}}, .expectation = {"black fade +200 ms, peak +200 ms, rise +300 ms, end +300 ms, same scene", "same scene after the fade"}, }, { - .input = {"a one-frame black, scene unknown, is too short", + .name = "a one-frame black, scene unknown, is too short", + .input = { {{0, 100, ROUTE}, {200, 200, DARK}, {300, 400, ROUTE}}, &BDSP_FADE_PROFILE, false}, .expectation = {"black fade +200 ms, peak +200 ms, rise +300 ms, end +300 ms, scene unknown", "fade too short"}, }, { - .input = {"an encounter's flash: a short white, back on the scene", + .name = "an encounter's flash: a short white, back on the scene", + .input = { {{0, 100, ROUTE}, {200, 200, WHITE}, {300, 400, ROUTE}}}, .expectation = {"flash +200 ms, peak +200 ms, rise +300 ms, end +300 ms, same scene", "an encounter's flash"}, }, { - .input = {"a cave exit: a long white onto another scene", + .name = "a cave exit: a long white onto another scene", + .input = { {{0, 100, CAVE}, {200, 200, FALLING_WHITE}, {300, 800, WHITE}, {900, 900, FALLING_WHITE}, {1000, 1100, ROUTE}}}, .expectation = {"white fade +200 ms, peak +300 ms, rise +900 ms, end +1000 ms, other scene", "warped"}, }, { - .input = {"a white between a flash and a fade, scene unknown, is unsure", + .name = "a white between a flash and a fade, scene unknown, is unsure", + .input = { {{0, 100, ROUTE}, {200, 400, WHITE}, {500, 600, ROUTE}}, &BDSP_FADE_PROFILE, false}, .expectation = {"white, flash or fade +200 ms, peak +200 ms, rise +500 ms, end +500 ms, scene unknown", "a white, flash or fade"}, }, { - .input = {"a short white onto another scene may be the battle: unsure", + .name = "a short white onto another scene may be the battle: unsure", + .input = { {{0, 100, ROUTE}, {200, 200, WHITE}, {300, 400, HOUSE}}}, .expectation = {"white, flash or fade +200 ms, peak +200 ms, rise +300 ms, end +300 ms, other scene", "a white, flash or fade"}, }, { - .input = {"FRLG has no white fade: a long white is a flash", + .name = "FRLG has no white fade: a long white is a flash", + .input = { {{0, 100, CAVE}, {300, 800, WHITE}, {1000, 1100, ROUTE}}, &FRLG_FADE_PROFILE}, .expectation = {"flash +300 ms, peak +300 ms, rise +1000 ms, end +1000 ms, other scene", "an encounter's flash"}, }, { - .input = {"the Oreburgh Gate's dim floor is no fade, a door from it is", + .name = "the Oreburgh Gate's dim floor is no fade, a door from it is", + .input = { {{0, 100, ROUTE}, {200, 3000, DIM_FLOOR}, {3100, 3400, DARK}, {3500, 3600, HOUSE}}}, .expectation = {"black fade +3100 ms, peak +3100 ms, rise +3500 ms, end +3500 ms, other scene", "warped"}, }, { - .input = {"a street at night is no fade", {{0, 5000, NIGHT}}}, + .name = "a street at night is no fade", + .input = {{{0, 5000, NIGHT}}}, .expectation = {"none"}, }, { - .input = {"a cave mouth's fade rises into a dim cave", + .name = "a cave mouth's fade rises into a dim cave", + .input = { {{0, 100, ROUTE}, {200, 500, DARK}, {600, 2500, DIM_FLOOR}}}, .expectation = {"black fade +200 ms, peak +200 ms, rise +600 ms, end +1700 ms, other scene", "warped"}, }, { - .input = {"empty frames in a scene start no fade", + .name = "empty frames in a scene start no fade", + .input = { {{0, 100, ROUTE}, {200, 300, EMPTY}, {400, 500, ROUTE}}}, .expectation = {"none"}, }, { - .input = {"an empty frame in a fall is skipped", + .name = "an empty frame in a fall is skipped", + .input = { {{0, 100, ROUTE}, {200, 200, EMPTY}, {300, 300, FALLING_DARK}, {400, 600, DARK}}}, .expectation = {"none", "fade still showing"}, }, { - .input = {"an empty frame in the rise does not move the rise", + .name = "an empty frame in the rise does not move the rise", + .input = { {{0, 100, ROUTE}, {200, 200, FALLING_DARK}, {300, 500, DARK}, {600, 600, FALLING_DARK}, {700, 700, EMPTY}, {800, 900, HOUSE}}}, .expectation = {"black fade +200 ms, peak +300 ms, rise +600 ms, end +800 ms, other scene", "warped"}, }, { - .input = {"a fade in progress is still showing", + .name = "a fade in progress is still showing", + .input = { {{0, 100, ROUTE}, {200, 200, FALLING_DARK}, {300, 600, DARK}}}, .expectation = {"none", "fade still showing"}, }, @@ -371,22 +390,26 @@ const TrackCase TRACK_CASES[] = { const TransitionsCase TRANSITIONS_CASES[] = { { - .input = {"a screen that stays dark times out", test_timeout}, + .name = "a screen that stays dark times out", + .input = {test_timeout}, .expectation = {}, }, { - .input = {"a video frame's sample", test_sample_of_frame}, + .name = "a video frame's sample", + .input = {test_sample_of_frame}, .expectation = {}, }, }; const CapturedCase CAPTURED_CASES[] = { { - .input = {"PokemonBDSP", &BDSP_FADE_PROFILE}, + .name = "PokemonBDSP", + .input = {.game = "PokemonBDSP", .profile = &BDSP_FADE_PROFILE}, .expectation = {}, }, { - .input = {"PokemonFRLG", &FRLG_FADE_PROFILE}, + .name = "PokemonFRLG", + .input = {.game = "PokemonFRLG", .profile = &FRLG_FADE_PROFILE}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp index 788bfe9b84..924ea6fdd5 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp @@ -83,7 +83,6 @@ std::optional mismatch(const ConnectedMaps& world, const std::optio struct StepCase{ struct Input{ - std::string_view name; NamedPlace from; Direction direction; }; @@ -91,6 +90,7 @@ struct StepCase{ struct Expectation{ std::optional place; }; + std::string_view name; Input input; Expectation expectation; }; @@ -98,7 +98,7 @@ struct StepCase{ class Test_ConnectedMaps_Step : public UnitTest{ public: explicit Test_ConnectedMaps_Step(StepCase scenario) - : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.name)), m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const ConnectedMaps world(test_maps()); @@ -115,43 +115,53 @@ class Test_ConnectedMaps_Step : public UnitTest{ const StepCase STEP_CASES[] = { { - .input = {.name = "a step on the same map", .from = {"Town", {1, 1}}, .direction = Direction::EAST}, + .name = "a step on the same map", + .input = {.from = {"Town", {1, 1}}, .direction = Direction::EAST}, .expectation = {.place = NamedPlace{"Town", {2, 1}}}, }, { - .input = {.name = "north onto the route, shifted by its offset", .from = {"Town", {0, 0}}, .direction = Direction::NORTH}, + .name = "north onto the route, shifted by its offset", + .input = {.from = {"Town", {0, 0}}, .direction = Direction::NORTH}, .expectation = {.place = NamedPlace{"Route", {1, 2}}}, }, { - .input = {.name = "south off the route into the town", .from = {"Route", {1, 2}}, .direction = Direction::SOUTH}, + .name = "south off the route into the town", + .input = {.from = {"Route", {1, 2}}, .direction = Direction::SOUTH}, .expectation = {.place = NamedPlace{"Town", {0, 0}}}, }, { - .input = {.name = "east into the lake", .from = {"Town", {3, 2}}, .direction = Direction::EAST}, + .name = "east into the lake", + .input = {.from = {"Town", {3, 2}}, .direction = Direction::EAST}, .expectation = {.place = NamedPlace{"Lake", {0, 2}}}, }, { - .input = {.name = "west into the town", .from = {"Lake", {0, 1}}, .direction = Direction::WEST}, + .name = "west into the town", + .input = {.from = {"Lake", {0, 1}}, .direction = Direction::WEST}, .expectation = {.place = NamedPlace{"Town", {3, 1}}}, }, { - .input = {.name = "north out of the lake onto the route's last column", .from = {"Lake", {0, 0}}, .direction = Direction::NORTH}, + .name = "north out of the lake onto the route's last column", + .input = {.from = {"Lake", {0, 0}}, .direction = Direction::NORTH}, .expectation = {.place = NamedPlace{"Route", {5, 2}}}, }, { - .input = {.name = "north out of the lake past the route's span", .from = {"Lake", {1, 0}}, .direction = Direction::NORTH}, + .name = "north out of the lake past the route's span", + .input = {.from = {"Lake", {1, 0}}, .direction = Direction::NORTH}, .expectation = {.place = std::nullopt}, }, { - .input = {.name = "an edge no map joins", .from = {"Town", {0, 1}}, .direction = Direction::WEST}, + .name = "an edge no map joins", + .input = {.from = {"Town", {0, 1}}, .direction = Direction::WEST}, .expectation = {.place = std::nullopt}, }, { - .input = {.name = "past the joined map's span", .from = {"Route", {0, 2}}, .direction = Direction::SOUTH}, + .name = "past the joined map's span", + .input = {.from = {"Route", {0, 2}}, .direction = Direction::SOUTH}, .expectation = {.place = std::nullopt}, }, { - .input = {.name = "a map off the world grid joins nothing", .from = {"House", {1, 0}}, .direction = Direction::NORTH}, + .name = "a map off the world grid joins nothing", + .input = {.from = {"House", {1, 0}}, .direction = Direction::NORTH}, .expectation = {.place = std::nullopt}, }, }; @@ -159,13 +169,13 @@ const StepCase STEP_CASES[] = { struct WarpCase{ struct Input{ - std::string_view name; MapWarp warp; }; // Where the warp should put the player, or nothing for nowhere. struct Expectation{ std::optional place; }; + std::string_view name; Input input; Expectation expectation; }; @@ -173,7 +183,7 @@ struct WarpCase{ class Test_ConnectedMaps_Warp : public UnitTest{ public: explicit Test_ConnectedMaps_Warp(WarpCase scenario) - : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.name)), m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const ConnectedMaps world(test_maps()); @@ -188,19 +198,23 @@ class Test_ConnectedMaps_Warp : public UnitTest{ const WarpCase WARP_CASES[] = { { - .input = {.name = "a warp to a loaded map's point", .warp = {.to = WarpDestination{"House", "door"}}}, + .name = "a warp to a loaded map's point", + .input = {.warp = {.to = WarpDestination{"House", "door"}}}, .expectation = {.place = NamedPlace{"House", {0, 1}}}, }, { - .input = {.name = "a warp to a map that isn't loaded", .warp = {.to = WarpDestination{"Cave", "door"}}}, + .name = "a warp to a map that isn't loaded", + .input = {.warp = {.to = WarpDestination{"Cave", "door"}}}, .expectation = {.place = std::nullopt}, }, { - .input = {.name = "a warp to a point the map lacks", .warp = {.to = WarpDestination{"House", "stairs"}}}, + .name = "a warp to a point the map lacks", + .input = {.warp = {.to = WarpDestination{"House", "stairs"}}}, .expectation = {.place = std::nullopt}, }, { - .input = {.name = "a warp that leads nowhere", .warp = {}}, + .name = "a warp that leads nowhere", + .input = {.warp = {}}, .expectation = {.place = std::nullopt}, }, }; @@ -208,13 +222,13 @@ const WarpCase WARP_CASES[] = { struct StalePlaceCase{ struct Input{ - std::string_view name; size_t map; }; struct Expectation{ // Whether reading the place throws InternalProgramError. bool rejected = false; }; + std::string_view name; Input input; Expectation expectation; }; @@ -225,7 +239,7 @@ struct StalePlaceCase{ class Test_ConnectedMaps_StalePlace : public UnitTest{ public: explicit Test_ConnectedMaps_StalePlace(StalePlaceCase scenario) - : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.name)), m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const ConnectedMaps world(test_maps()); @@ -247,9 +261,9 @@ class Test_ConnectedMaps_StalePlace : public UnitTest{ }; const StalePlaceCase STALE_PLACE_CASES[] = { - {.input = {.name = "the last map index is read", .map = 3}, .expectation = {.rejected = false}}, - {.input = {.name = "a map index one past the last is rejected", .map = 4}, .expectation = {.rejected = true}}, - {.input = {.name = "a map index far past the last is rejected", .map = 1000}, .expectation = {.rejected = true}}, + {.name = "the last map index is read", .input = {.map = 3}, .expectation = {.rejected = false}}, + {.name = "a map index one past the last is rejected", .input = {.map = 4}, .expectation = {.rejected = true}}, + {.name = "a map index far past the last is rejected", .input = {.map = 1000}, .expectation = {.rejected = true}}, }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegPlanner_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegPlanner_Tests.cpp index eea9549166..5a41cd61d8 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegPlanner_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegPlanner_Tests.cpp @@ -331,7 +331,6 @@ UnitTestResult test_unreachable(){ struct LegPlannerTestCase{ struct Input{ - std::string name; UnitTestResult (*test)(); }; @@ -339,6 +338,7 @@ struct LegPlannerTestCase{ std::string_view description; }; + std::string name; Input input; Expectation expectation; }; @@ -346,7 +346,7 @@ struct LegPlannerTestCase{ class Test_LegPlanner : public UnitTest{ public: explicit Test_LegPlanner(LegPlannerTestCase scenario) - : UnitTest(std::format("Pokemon::LegPlanner - {}", scenario.input.name)) + : UnitTest(std::format("Pokemon::LegPlanner - {}", scenario.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -359,47 +359,58 @@ class Test_LegPlanner : public UnitTest{ const LegPlannerTestCase LEG_PLANNER_CASES[] = { { - .input = {.name = "prefers legs that end at a wall", .test = test_prefers_wall_legs}, + .name = "prefers legs that end at a wall", + .input = {.test = test_prefers_wall_legs}, .expectation = {.description = "ends last leg against a wall rather than in the open"}, }, { - .input = {.name = "a person is not a wall", .test = test_person_is_not_a_wall}, + .name = "a person is not a wall", + .input = {.test = test_person_is_not_a_wall}, .expectation = {.description = "does not treat an NPC obstacle as a wall to stop against"}, }, { - .input = {.name = "avoids tall grass", .test = test_avoids_grass}, + .name = "avoids tall grass", + .input = {.test = test_avoids_grass}, .expectation = {.description = "routes around tall grass tiles when cheaper"}, }, { - .input = {.name = "one-way tile", .test = test_one_way_tile}, + .name = "one-way tile", + .input = {.test = test_one_way_tile}, .expectation = {.description = "respects directional one-way constraints"}, }, { - .input = {.name = "a warp ends the leg", .test = test_warp_ends_leg}, + .name = "a warp ends the leg", + .input = {.test = test_warp_ends_leg}, .expectation = {.description = "terminates the current leg upon entering a warp"}, }, { - .input = {.name = "turns to face the goal", .test = test_goal_facing}, + .name = "turns to face the goal", + .input = {.test = test_goal_facing}, .expectation = {.description = "adds a final turn leg to match required goal orientation"}, }, { - .input = {.name = "nothing through a wall", .test = test_unreachable}, + .name = "nothing through a wall", + .input = {.test = test_unreachable}, .expectation = {.description = "returns empty plan when destination is blocked"}, }, { - .input = {.name = "a leg through grass is wild", .test = test_wild_leg}, + .name = "a leg through grass is wild", + .input = {.test = test_wild_leg}, .expectation = {.description = "marks leg as wild when stepping through grass"}, }, { - .input = {.name = "an open stop after grass is weighed", .test = test_open_wild_stop}, + .name = "an open stop after grass is weighed", + .input = {.test = test_open_wild_stop}, .expectation = {.description = "prefers wall stops over open stops following grass"}, }, { - .input = {.name = "the weight needs a wild step", .test = test_open_stop_without_grass}, + .name = "the weight needs a wild step", + .input = {.test = test_open_stop_without_grass}, .expectation = {.description = "does not penalize open stop when route has no grass"}, }, { - .input = {.name = "a new leg is not wild", .test = test_wild_ends_with_leg}, + .name = "a new leg is not wild", + .input = {.test = test_wild_ends_with_leg}, .expectation = {.description = "clears wild status on subsequent non-grass legs"}, }, }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp index 10e2593ab0..b192fef4b7 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp @@ -226,7 +226,6 @@ UnitTestResult test_watch_along(){ struct LegWalkerTestCase{ struct Input{ - std::string name; UnitTestResult (*test)(); }; @@ -234,6 +233,7 @@ struct LegWalkerTestCase{ std::string_view description; }; + std::string name; Input input; Expectation expectation; }; @@ -241,7 +241,7 @@ struct LegWalkerTestCase{ class Test_LegWalker : public UnitTest{ public: explicit Test_LegWalker(LegWalkerTestCase scenario) - : UnitTest(std::format("Pokemon::LegWalker - {}", scenario.input.name)) + : UnitTest(std::format("Pokemon::LegWalker - {}", scenario.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -254,39 +254,48 @@ class Test_LegWalker : public UnitTest{ const LegWalkerTestCase LEG_WALKER_CASES[] = { { - .input = {.name = "hold times", .test = test_hold_times}, + .name = "hold times", + .input = {.test = test_hold_times}, .expectation = {.description = "verifies open and wall leg hold durations"}, }, { - .input = {.name = "tiles before an interrupt", .test = test_tiles_before_interrupt}, + .name = "tiles before an interrupt", + .input = {.test = test_tiles_before_interrupt}, .expectation = {.description = "computes traversed tiles before an interrupt occurred"}, }, { - .input = {.name = "a wall leg is walked again", .test = test_wall_leg_walked_again}, + .name = "a wall leg is walked again", + .input = {.test = test_wall_leg_walked_again}, .expectation = {.description = "re-executes entire wall leg following an interrupt"}, }, { - .input = {.name = "an open leg walks the rest", .test = test_open_leg_rest_walked}, + .name = "an open leg walks the rest", + .input = {.test = test_open_leg_rest_walked}, .expectation = {.description = "walks only the remaining tiles on an open leg"}, }, { - .input = {.name = "an open leg interrupted at its end", .test = test_open_leg_interrupted_at_end}, + .name = "an open leg interrupted at its end", + .input = {.test = test_open_leg_interrupted_at_end}, .expectation = {.description = "does not re-walk an open leg interrupted at its final tile"}, }, { - .input = {.name = "gives up after too many interruptions", .test = test_too_many_interruptions}, + .name = "gives up after too many interruptions", + .input = {.test = test_too_many_interruptions}, .expectation = {.description = "throws when interrupt count exceeds limit"}, }, { - .input = {.name = "an open leg stops at an interrupt", .test = test_open_leg_stops}, + .name = "an open leg stops at an interrupt", + .input = {.test = test_open_leg_stops}, .expectation = {.description = "aborts remaining movement when stop_on_interrupt is set"}, }, { - .input = {.name = "a wall leg blocked by a sign stops", .test = test_wall_leg_blocked}, + .name = "a wall leg blocked by a sign stops", + .input = {.test = test_wall_leg_blocked}, .expectation = {.description = "aborts wall movement when blocked prematurely repeatedly"}, }, { - .input = {.name = "a watcher along a hold never stops it", .test = test_watch_along}, + .name = "a watcher along a hold never stops it", + .input = {.test = test_watch_along}, .expectation = {.description = "WatchAlong keeps its watcher's firing and returns false"}, }, }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp index fcf299992e..9710d915bd 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp @@ -403,7 +403,6 @@ UnitTestResult test_built_in_maps(){ struct MapDataTestCase{ struct Input{ - std::string name; UnitTestResult (*test)(); }; @@ -411,6 +410,7 @@ struct MapDataTestCase{ std::string_view description; }; + std::string name; Input input; Expectation expectation; }; @@ -418,7 +418,7 @@ struct MapDataTestCase{ class Test_MapData : public UnitTest{ public: explicit Test_MapData(MapDataTestCase scenario) - : UnitTest(std::format("Pokemon::MapData - {}", scenario.input.name)) + : UnitTest(std::format("Pokemon::MapData - {}", scenario.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -474,39 +474,48 @@ UnitTestResult test_tiles_to_door(){ const MapDataTestCase MAP_DATA_CASES[] = { { - .input = {.name = "the valid map", .test = test_valid_map}, + .name = "the valid map", + .input = {.test = test_valid_map}, .expectation = {.description = "parses full map with all properties and layers"}, }, { - .input = {.name = "lists may be left out", .test = test_lists_may_be_left_out}, + .name = "lists may be left out", + .input = {.test = test_lists_may_be_left_out}, .expectation = {.description = "allows optional collection fields to be omitted"}, }, { - .input = {.name = "glyphs round-trip", .test = test_glyphs_round_trip}, + .name = "glyphs round-trip", + .input = {.test = test_glyphs_round_trip}, .expectation = {.description = "converts between tile characters and enum kinds"}, }, { - .input = {.name = "each error class", .test = test_each_error_class}, + .name = "each error class", + .input = {.test = test_each_error_class}, .expectation = {.description = "rejects invalid JSON syntax and malformed map schemas"}, }, { - .input = {.name = "a map shaped like BDSP's", .test = test_bdsp_shaped_map}, + .name = "a map shaped like BDSP's", + .input = {.test = test_bdsp_shaped_map}, .expectation = {.description = "parses BDSP-specific world offsets, trainers, and triggers"}, }, { - .input = {.name = "a map shaped like FRLG's", .test = test_frlg_shaped_map}, + .name = "a map shaped like FRLG's", + .input = {.test = test_frlg_shaped_map}, .expectation = {.description = "parses FRLG-specific elevations, flags, and warp directions"}, }, { - .input = {.name = "each error class of the game fields", .test = test_each_error_class_of_game_fields}, + .name = "each error class of the game fields", + .input = {.test = test_each_error_class_of_game_fields}, .expectation = {.description = "validates constraints on game-specific map fields"}, }, { - .input = {.name = "maps built into the program", .test = test_built_in_maps}, + .name = "maps built into the program", + .input = {.test = test_built_in_maps}, .expectation = {.description = "loads and verifies embedded test map assets"}, }, { - .input = {.name = "tiles to door raycasting", .test = test_tiles_to_door}, + .name = "tiles to door raycasting", + .input = {.test = test_tiles_to_door}, .expectation = {.description = "counts tile distance along a corridor to a door or wall"}, }, }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp index fced1d74eb..a8e9ba6f93 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp @@ -20,7 +20,6 @@ namespace{ struct MoveMechanicsCase{ struct Input{ - std::string_view game; MoveMechanics mechanics; }; struct Expectation{ @@ -28,6 +27,7 @@ struct MoveMechanicsCase{ // timed holds). OpenLegPress open_legs_on_foot; }; + std::string_view name; Input input; Expectation expectation; }; @@ -78,7 +78,7 @@ std::optional wrong_open_legs(std::string_view gait_name, const Gai class Test_MoveMechanics : public UnitTest{ public: explicit Test_MoveMechanics(MoveMechanicsCase scenario) - : UnitTest(std::format("Pokemon::MoveMechanics - {}", scenario.input.game)), m_scenario(std::move(scenario)) + : UnitTest(std::format("Pokemon::MoveMechanics - {}", scenario.name)), m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const MoveMechanics& game = m_scenario.input.mechanics; @@ -107,11 +107,13 @@ class Test_MoveMechanics : public UnitTest{ const MoveMechanicsCase MOVE_MECHANICS_CASES[] = { { - .input = {.game = "BDSP", .mechanics = BDSP_MOVE_MECHANICS}, + .name = "BDSP", + .input = {.mechanics = BDSP_MOVE_MECHANICS}, .expectation = {.open_legs_on_foot = OpenLegPress::STEP_TAPS}, }, { - .input = {.game = "FRLG", .mechanics = FRLG_MOVE_MECHANICS}, + .name = "FRLG", + .input = {.mechanics = FRLG_MOVE_MECHANICS}, .expectation = {.open_legs_on_foot = OpenLegPress::TIMED_HOLD}, }, }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RouteLog_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RouteLog_Tests.cpp index 5715211f01..27594906ca 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RouteLog_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RouteLog_Tests.cpp @@ -24,12 +24,12 @@ namespace{ struct RouteLogTestCase{ struct Input{ - std::string name; std::string line; }; struct Expectation{ std::string expected; }; + std::string name; Input input; Expectation expectation; }; @@ -37,14 +37,14 @@ struct RouteLogTestCase{ class Test_RouteLog : public UnitTest{ public: explicit Test_RouteLog(RouteLogTestCase scenario) - : UnitTest(std::format("Pokemon::RouteLog - {}", scenario.input.name)) + : UnitTest(std::format("Pokemon::RouteLog - {}", scenario.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ if (m_scenario.input.line != m_scenario.expectation.expected){ return std::format( "{}: expected \"{}\", got \"{}\".", - m_scenario.input.name, m_scenario.expectation.expected, m_scenario.input.line + m_scenario.name, m_scenario.expectation.expected, m_scenario.input.line ); } return true; @@ -79,28 +79,33 @@ const std::vector FRLG_LEGS{{.leg = NORTH_OPEN, .after = FRLG_N const RouteLogTestCase CASES[] = { { - .input = {.name = "to a wall", .line = to_string(EAST_TO_WALL)}, + .name = "to a wall", + .input = {.line = to_string(EAST_TO_WALL)}, .expectation = {.expected = "east 15 (to wall)"}, }, { - .input = {.name = "open", .line = to_string(NORTH_OPEN)}, + .name = "open", + .input = {.line = to_string(NORTH_OPEN)}, .expectation = {.expected = "north 8 (open)"}, }, { - .input = {.name = "onto a warp", .line = to_string(SOUTH_WARP)}, + .name = "onto a warp", + .input = {.line = to_string(SOUTH_WARP)}, .expectation = {.expected = "south 1 (warp)"}, }, { - .input = {.name = "surf", .line = to_string(SURF_EAST)}, + .name = "surf", + .input = {.line = to_string(SURF_EAST)}, .expectation = {.expected = "surf east"}, }, { - .input = {.name = "face", .line = to_string(FACE_WEST)}, + .name = "face", + .input = {.line = to_string(FACE_WEST)}, .expectation = {.expected = "face west"}, }, { + .name = "plan from a set of tiles", .input = { - .name = "plan from a set of tiles", .line = route_plan_line("To the grass", BDSP_FROM, BDSP_LEGS), }, .expectation = { @@ -110,8 +115,8 @@ const RouteLogTestCase CASES[] = { }, }, { + .name = "plan from one tile", .input = { - .name = "plan from one tile", .line = route_plan_line("00.05/2 below_mart_door", FRLG_TILE, FRLG_LEGS), }, .expectation = { @@ -119,12 +124,13 @@ const RouteLogTestCase CASES[] = { }, }, { - .input = {.name = "plan from an unknown tile", .line = route_plan_line("x", {}, {})}, + .name = "plan from an unknown tile", + .input = {.line = route_plan_line("x", {}, {})}, .expectation = {.expected = "x: plan from an unknown tile:"}, }, { + .name = "leg as it starts", .input = { - .name = "leg as it starts", .line = route_leg_line(1, 5, BDSP_LEGS[0]), }, .expectation = { @@ -132,8 +138,8 @@ const RouteLogTestCase CASES[] = { }, }, { + .name = "walked", .input = { - .name = "walked", .line = route_leg_end_line("To the grass", EAST_TO_WALL, BDSP_WALL, EndBasis::WALKED, ""), }, .expectation = { @@ -141,8 +147,8 @@ const RouteLogTestCase CASES[] = { }, }, { + .name = "assumed", .input = { - .name = "assumed", .line = route_leg_end_line("r", NORTH_OPEN, FRLG_TILE, EndBasis::ASSUMED, "after a wild battle"), }, .expectation = { @@ -150,8 +156,8 @@ const RouteLogTestCase CASES[] = { }, }, { + .name = "unknown", .input = { - .name = "unknown", .line = route_leg_end_line("r", NORTH_OPEN, {}, EndBasis::UNKNOWN, "stopped by a wild battle"), }, .expectation = { @@ -159,8 +165,8 @@ const RouteLogTestCase CASES[] = { }, }, { + .name = "replan where seen", .input = { - .name = "replan where seen", .line = route_replan_line("To the grass", EAST_TO_WALL, "stopped early after about 3 tiles", BDSP_FROM), }, .expectation = { @@ -168,12 +174,13 @@ const RouteLogTestCase CASES[] = { }, }, { - .input = {.name = "found again", .line = route_found_line("r", FRLG_TILE, 2)}, + .name = "found again", + .input = {.line = route_found_line("r", FRLG_TILE, 2)}, .expectation = {.expected = "r: found again at Route1 (12, 21), after 2 hold(s)."}, }, { + .name = "trainer", .input = { - .name = "trainer", .line = route_trainer_line("To the grass", "Youngster Tristan", TRAINER_SEEN), }, .expectation = { @@ -181,8 +188,8 @@ const RouteLogTestCase CASES[] = { }, }, { + .name = "arrived", .input = { - .name = "arrived", .line = route_arrived_line("To the grass", ARRIVED), }, .expectation = { diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp index 81a28b60e1..2f2d022c9a 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp @@ -21,7 +21,6 @@ namespace{ struct RuntimeMapCase{ struct Input{ - std::string_view name; std::string_view fields; }; @@ -30,6 +29,7 @@ struct RuntimeMapCase{ std::string_view normalized_fields = {}; }; + std::string_view name; Input input; Expectation expectation; }; @@ -66,46 +66,46 @@ const std::string GOLDEN_V1 = R"( )"; const RuntimeMapCase RUNTIME_MAP_CASES[] = { - {.input = {.name = "pickup derived name and default quantity", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"source_event":3,"item":"potion"}])"}, .expectation = {.normalized_fields = R"("objects":[{"x":0,"y":1,"kind":"item","name":"item_3","source_event":3,"item":"potion","quantity":1}])"}}, - {.input = {.name = "pickup explicit name and multiple quantity", .fields = R"("format":"pokesim-runtime-map/2","items":[{"name":"gift_cache","coord":[0,1],"source_event":3,"item":"potion","quantity":4}])"}, .expectation = {.normalized_fields = R"("objects":[{"x":0,"y":1,"kind":"item","name":"gift_cache","source_event":3,"item":"potion","quantity":4}])"}}, - {.input = {.name = "pickup named quantity default", .fields = R"("format":"pokesim-runtime-map/2","items":[{"name":"pickup","coord":[0,1],"item":"potion"}])"}, .expectation = {.normalized_fields = R"("objects":[{"x":0,"y":1,"kind":"item","name":"pickup","item":"potion","quantity":1}])"}}, - {.input = {.name = "pickup missing event", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion"}])"}, .expectation = {.error = "source_event"}}, - {.input = {.name = "pickup negative event", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion","source_event":-1}])"}, .expectation = {.error = "source_event"}}, - {.input = {.name = "pickup boolean event", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion","source_event":true}])"}, .expectation = {.error = "source_event"}}, - {.input = {.name = "pickup overflow event", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion","source_event":2147483648}])"}, .expectation = {.error = "source_event"}}, - {.input = {.name = "pickup zero quantity", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":0}])"}, .expectation = {.error = "quantity"}}, - {.input = {.name = "pickup negative quantity", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":-1}])"}, .expectation = {.error = "quantity"}}, - {.input = {.name = "pickup boolean quantity", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":true}])"}, .expectation = {.error = "quantity"}}, - {.input = {.name = "pickup null quantity", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":null}])"}, .expectation = {.error = "quantity"}}, - {.input = {.name = "pickup float quantity", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":1.5}])"}, .expectation = {.error = "quantity"}}, - {.input = {.name = "pickup empty item", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":""}])"}, .expectation = {.error = "item"}}, - - {.input = {.name = "complete normalized-value parity", .fields = GOLDEN_V2}, .expectation = {.normalized_fields = GOLDEN_V1}}, - {.input = {.name = "implicit v1", .fields = R"("objects":[{"name":"npc","kind":"npc","x":0,"y":0}])"}, .expectation = {}}, - {.input = {.name = "explicit v1", .fields = R"("format":"pokesim-runtime-map/1")"}, .expectation = {}}, - {.input = {.name = "v2 empty map", .fields = R"("format":"pokesim-runtime-map/2")"}, .expectation = {}}, - {.input = {.name = "v2 coordinates and inclusive wander", .fields = R"("format":"pokesim-runtime-map/2","npcs":[{"name":"npc","coord":[0,0],"wander":{"min":[0,0],"max":[1,1]}}])"}, .expectation = {}}, - {.input = {.name = "unsupported version", .fields = R"("format":"pokesim-runtime-map/99")"}, .expectation = {.error = "format"}}, - {.input = {.name = "nonstring version", .fields = R"("format":2)"}, .expectation = {.error = "format"}}, - {.input = {.name = "v1 typed section", .fields = R"("npcs":[])"}, .expectation = {.error = "npcs"}}, - {.input = {.name = "v2 legacy section", .fields = R"("format":"pokesim-runtime-map/2","objects":[])"}, .expectation = {.error = "objects"}}, - {.input = {.name = "mixed v2 position", .fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0,0],"x":0}])"}, .expectation = {.error = "warps[0].coord"}}, - {.input = {.name = "mixed v1 position", .fields = R"("warps":[{"x":0,"y":0,"coord":[0,0]}])"}, .expectation = {.error = "warps[0].coord"}}, - {.input = {.name = "missing v2 position", .fields = R"("format":"pokesim-runtime-map/2","warps":[{}])"}, .expectation = {.error = "warps[0].coord"}}, - {.input = {.name = "short position", .fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0]}])"}, .expectation = {.error = "warps[0].coord"}}, - {.input = {.name = "long position", .fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0,0,0]}])"}, .expectation = {.error = "warps[0].coord"}}, - {.input = {.name = "floating coordinate", .fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0.5,0]}])"}, .expectation = {.error = "coord[0]"}}, - {.input = {.name = "boolean coordinate", .fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[false,0]}])"}, .expectation = {.error = "coord[0]"}}, - {.input = {.name = "overflow coordinate", .fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[2147483648,0]}])"}, .expectation = {.error = "coord[0]"}}, - {.input = {.name = "outside map", .fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[3,0]}])"}, .expectation = {.error = "outside"}}, - {.input = {.name = "mixed wander", .fields = R"("format":"pokesim-runtime-map/2","npcs":[{"name":"npc","coord":[0,0],"wander":{"min":[0,0],"max":[1,1],"x0":0}}])"}, .expectation = {.error = "wander.min"}}, - {.input = {.name = "reversed wander", .fields = R"("format":"pokesim-runtime-map/2","npcs":[{"name":"npc","coord":[0,0],"wander":{"min":[1,1],"max":[0,0]}}])"}, .expectation = {.error = "min <= max"}}, - {.input = {.name = "redundant kind", .fields = R"("format":"pokesim-runtime-map/2","signs":[{"name":"sign","coord":[0,0],"kind":"sign"}])"}, .expectation = {.error = "kind"}}, - {.input = {.name = "starter interaction", .fields = R"("format":"pokesim-runtime-map/2","interactables":[{"name":"ball","coord":[0,0],"interaction":{"kind":"starter_choice","species":"squirtle"}}])"}, .expectation = {}}, - {.input = {.name = "interaction has item", .fields = R"("format":"pokesim-runtime-map/2","interactables":[{"coord":[0,0],"interaction":{"kind":"starter_choice"},"item":"potion"}])"}, .expectation = {.error = "item reward"}}, - {.input = {.name = "interaction missing kind", .fields = R"("format":"pokesim-runtime-map/2","interactables":[{"coord":[0,0],"interaction":{}}])"}, .expectation = {.error = "interaction"}}, - {.input = {.name = "item has interaction", .fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,0],"interaction":{"kind":"starter_choice"}}])"}, .expectation = {.error = "interactables"}}, - {.input = {.name = "bad coordinate event", .fields = R"("format":"pokesim-runtime-map/2","coord_events":[{"coord":[0,true]}])"}, .expectation = {.error = "coord_events[0].coord[1]"}}, + {.name = "pickup derived name and default quantity", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"source_event":3,"item":"potion"}])"}, .expectation = {.normalized_fields = R"("objects":[{"x":0,"y":1,"kind":"item","name":"item_3","source_event":3,"item":"potion","quantity":1}])"}}, + {.name = "pickup explicit name and multiple quantity", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"name":"gift_cache","coord":[0,1],"source_event":3,"item":"potion","quantity":4}])"}, .expectation = {.normalized_fields = R"("objects":[{"x":0,"y":1,"kind":"item","name":"gift_cache","source_event":3,"item":"potion","quantity":4}])"}}, + {.name = "pickup named quantity default", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"name":"pickup","coord":[0,1],"item":"potion"}])"}, .expectation = {.normalized_fields = R"("objects":[{"x":0,"y":1,"kind":"item","name":"pickup","item":"potion","quantity":1}])"}}, + {.name = "pickup missing event", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion"}])"}, .expectation = {.error = "source_event"}}, + {.name = "pickup negative event", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion","source_event":-1}])"}, .expectation = {.error = "source_event"}}, + {.name = "pickup boolean event", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion","source_event":true}])"}, .expectation = {.error = "source_event"}}, + {.name = "pickup overflow event", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"item":"potion","source_event":2147483648}])"}, .expectation = {.error = "source_event"}}, + {.name = "pickup zero quantity", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":0}])"}, .expectation = {.error = "quantity"}}, + {.name = "pickup negative quantity", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":-1}])"}, .expectation = {.error = "quantity"}}, + {.name = "pickup boolean quantity", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":true}])"}, .expectation = {.error = "quantity"}}, + {.name = "pickup null quantity", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":null}])"}, .expectation = {.error = "quantity"}}, + {.name = "pickup float quantity", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":"potion","quantity":1.5}])"}, .expectation = {.error = "quantity"}}, + {.name = "pickup empty item", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,1],"name":"p","item":""}])"}, .expectation = {.error = "item"}}, + + {.name = "complete normalized-value parity", .input = {.fields = GOLDEN_V2}, .expectation = {.normalized_fields = GOLDEN_V1}}, + {.name = "implicit v1", .input = {.fields = R"("objects":[{"name":"npc","kind":"npc","x":0,"y":0}])"}, .expectation = {}}, + {.name = "explicit v1", .input = {.fields = R"("format":"pokesim-runtime-map/1")"}, .expectation = {}}, + {.name = "v2 empty map", .input = {.fields = R"("format":"pokesim-runtime-map/2")"}, .expectation = {}}, + {.name = "v2 coordinates and inclusive wander", .input = {.fields = R"("format":"pokesim-runtime-map/2","npcs":[{"name":"npc","coord":[0,0],"wander":{"min":[0,0],"max":[1,1]}}])"}, .expectation = {}}, + {.name = "unsupported version", .input = {.fields = R"("format":"pokesim-runtime-map/99")"}, .expectation = {.error = "format"}}, + {.name = "nonstring version", .input = {.fields = R"("format":2)"}, .expectation = {.error = "format"}}, + {.name = "v1 typed section", .input = {.fields = R"("npcs":[])"}, .expectation = {.error = "npcs"}}, + {.name = "v2 legacy section", .input = {.fields = R"("format":"pokesim-runtime-map/2","objects":[])"}, .expectation = {.error = "objects"}}, + {.name = "mixed v2 position", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0,0],"x":0}])"}, .expectation = {.error = "warps[0].coord"}}, + {.name = "mixed v1 position", .input = {.fields = R"("warps":[{"x":0,"y":0,"coord":[0,0]}])"}, .expectation = {.error = "warps[0].coord"}}, + {.name = "missing v2 position", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{}])"}, .expectation = {.error = "warps[0].coord"}}, + {.name = "short position", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0]}])"}, .expectation = {.error = "warps[0].coord"}}, + {.name = "long position", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0,0,0]}])"}, .expectation = {.error = "warps[0].coord"}}, + {.name = "floating coordinate", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[0.5,0]}])"}, .expectation = {.error = "coord[0]"}}, + {.name = "boolean coordinate", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[false,0]}])"}, .expectation = {.error = "coord[0]"}}, + {.name = "overflow coordinate", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[2147483648,0]}])"}, .expectation = {.error = "coord[0]"}}, + {.name = "outside map", .input = {.fields = R"("format":"pokesim-runtime-map/2","warps":[{"coord":[3,0]}])"}, .expectation = {.error = "outside"}}, + {.name = "mixed wander", .input = {.fields = R"("format":"pokesim-runtime-map/2","npcs":[{"name":"npc","coord":[0,0],"wander":{"min":[0,0],"max":[1,1],"x0":0}}])"}, .expectation = {.error = "wander.min"}}, + {.name = "reversed wander", .input = {.fields = R"("format":"pokesim-runtime-map/2","npcs":[{"name":"npc","coord":[0,0],"wander":{"min":[1,1],"max":[0,0]}}])"}, .expectation = {.error = "min <= max"}}, + {.name = "redundant kind", .input = {.fields = R"("format":"pokesim-runtime-map/2","signs":[{"name":"sign","coord":[0,0],"kind":"sign"}])"}, .expectation = {.error = "kind"}}, + {.name = "starter interaction", .input = {.fields = R"("format":"pokesim-runtime-map/2","interactables":[{"name":"ball","coord":[0,0],"interaction":{"kind":"starter_choice","species":"squirtle"}}])"}, .expectation = {}}, + {.name = "interaction has item", .input = {.fields = R"("format":"pokesim-runtime-map/2","interactables":[{"coord":[0,0],"interaction":{"kind":"starter_choice"},"item":"potion"}])"}, .expectation = {.error = "item reward"}}, + {.name = "interaction missing kind", .input = {.fields = R"("format":"pokesim-runtime-map/2","interactables":[{"coord":[0,0],"interaction":{}}])"}, .expectation = {.error = "interaction"}}, + {.name = "item has interaction", .input = {.fields = R"("format":"pokesim-runtime-map/2","items":[{"coord":[0,0],"interaction":{"kind":"starter_choice"}}])"}, .expectation = {.error = "interactables"}}, + {.name = "bad coordinate event", .input = {.fields = R"("format":"pokesim-runtime-map/2","coord_events":[{"coord":[0,true]}])"}, .expectation = {.error = "coord_events[0].coord[1]"}}, }; std::string map_document(std::string_view fields){ @@ -148,7 +148,7 @@ std::string check_runtime_case(const RuntimeMapCase& test){ class RuntimeMapTest : public UnitTest{ public: explicit RuntimeMapTest(const RuntimeMapCase& test) - : UnitTest(std::format("Navigation/RuntimeMap/{}", test.input.name)), m_test(test){} + : UnitTest(std::format("Navigation/RuntimeMap/{}", test.name)), m_test(test){} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const std::string error = check_runtime_case(m_test); return error.empty() ? UnitTestResult(true) : UnitTestResult(error); @@ -177,7 +177,7 @@ int main(int argc, char* argv[]){ int failed = 0; for (const auto& test : PokemonAutomation::Pokemon::RUNTIME_MAP_CASES){ const std::string error = PokemonAutomation::Pokemon::check_runtime_case(test); - std::cout << test.input.name << ": " << (error.empty() ? "PASS" : error) << std::endl; + std::cout << test.name << ": " << (error.empty() ? "PASS" : error) << std::endl; failed += !error.empty(); } if (argc == 2){ diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_WallRecovery_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_WallRecovery_Tests.cpp index e3a68cfaa6..420d34b27a 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_WallRecovery_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_WallRecovery_Tests.cpp @@ -71,7 +71,6 @@ std::string describe_holds(std::span holds){ // Inputs and expectations are separate aggregates; each registered test owns one row. struct CorridorTestCase{ struct Input{ - std::string name; std::vector positions; std::optional person; size_t budget; @@ -82,6 +81,7 @@ struct CorridorTestCase{ std::vector holds; }; + std::string name; Input input; Expectation expectation; }; @@ -89,7 +89,7 @@ struct CorridorTestCase{ class Test_WallRecovery : public UnitTest{ public: explicit Test_WallRecovery(CorridorTestCase scenario) - : UnitTest(std::format("Pokemon::WallRecovery - {}", scenario.input.name)), m_scenario(std::move(scenario)) + : UnitTest(std::format("Pokemon::WallRecovery - {}", scenario.name)), m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const auto& input = m_scenario.input; @@ -112,35 +112,43 @@ class Test_WallRecovery : public UnitTest{ const CorridorTestCase CORRIDOR_CASES[] = { { - .input = {.name = "empty", .positions = {}, .person = std::nullopt, .budget = 3}, + .name = "empty", + .input = {.positions = {}, .person = std::nullopt, .budget = 3}, .expectation = {.first_anchor = std::nullopt, .holds = {}}, }, { - .input = {.name = "already known", .positions = {4}, .person = std::nullopt, .budget = 0}, + .name = "already known", + .input = {.positions = {4}, .person = std::nullopt, .budget = 0}, .expectation = {.first_anchor = 4, .holds = {}}, }, { - .input = {.name = "both tiles", .positions = {2, 3}, .person = std::nullopt, .budget = 3}, + .name = "both tiles", + .input = {.positions = {2, 3}, .person = std::nullopt, .budget = 3}, .expectation = {.first_anchor = 0, .holds = {{.direction = Direction::WEST, .tiles = 3}}}, }, { - .input = {.name = "three shortfall endpoints", .positions = {3, 4, 5}, .person = std::nullopt, .budget = 3}, + .name = "three shortfall endpoints", + .input = {.positions = {3, 4, 5}, .person = std::nullopt, .budget = 3}, .expectation = {.first_anchor = 0, .holds = {{.direction = Direction::WEST, .tiles = 5}}}, }, { - .input = {.name = "shortest hold first", .positions = {8, 9}, .person = std::nullopt, .budget = 3}, + .name = "shortest hold first", + .input = {.positions = {8, 9}, .person = std::nullopt, .budget = 3}, .expectation = {.first_anchor = 10, .holds = {{.direction = Direction::EAST, .tiles = 2}}}, }, { - .input = {.name = "person is not an anchor", .positions = {2, 3}, .person = 1, .budget = 3}, + .name = "person is not an anchor", + .input = {.positions = {2, 3}, .person = 1, .budget = 3}, .expectation = {.first_anchor = 10, .holds = {{.direction = Direction::EAST, .tiles = 8}}}, }, { - .input = {.name = "person splits belief", .positions = {2, 8}, .person = 5, .budget = 3}, + .name = "person splits belief", + .input = {.positions = {2, 8}, .person = 5, .budget = 3}, .expectation = {.first_anchor = std::nullopt, .holds = {}}, }, { - .input = {.name = "budget exhausted", .positions = {2, 3}, .person = std::nullopt, .budget = 0}, + .name = "budget exhausted", + .input = {.positions = {2, 3}, .person = std::nullopt, .budget = 0}, .expectation = {.first_anchor = std::nullopt, .holds = {}}, }, }; @@ -189,7 +197,6 @@ class CornerPolicy{ struct CornerTestCase{ struct Input{ - std::string name; std::array positions; size_t budget; }; @@ -199,6 +206,7 @@ struct CornerTestCase{ std::vector holds; }; + std::string name; Input input; Expectation expectation; }; @@ -206,7 +214,7 @@ struct CornerTestCase{ class Test_WallRecoveryCorner : public UnitTest{ public: explicit Test_WallRecoveryCorner(CornerTestCase scenario) - : UnitTest(std::format("Pokemon::WallRecovery - {}", scenario.input.name)), m_scenario(std::move(scenario)) + : UnitTest(std::format("Pokemon::WallRecovery - {}", scenario.name)), m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const auto& input = m_scenario.input; @@ -231,11 +239,13 @@ class Test_WallRecoveryCorner : public UnitTest{ const CornerTestCase CORNER_CASES[] = { { - .input = {.name = "one hold cannot localize both axes", .positions = {{{.x = 2, .y = 3}, {.x = 3, .y = 4}}}, .budget = 1}, + .name = "one hold cannot localize both axes", + .input = {.positions = {{{.x = 2, .y = 3}, {.x = 3, .y = 4}}}, .budget = 1}, .expectation = {.first_anchor = std::nullopt, .holds = {}}, }, { - .input = {.name = "two holds converge at northwest corner", .positions = {{{.x = 2, .y = 3}, {.x = 3, .y = 4}}}, .budget = 2}, + .name = "two holds converge at northwest corner", + .input = {.positions = {{{.x = 2, .y = 3}, {.x = 3, .y = 4}}}, .budget = 2}, .expectation = {.first_anchor = TilePos{.x = 0, .y = 0}, .holds = {{.direction = Direction::NORTH, .tiles = 4}, {.direction = Direction::WEST, .tiles = 3}}}, }, diff --git a/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimFaults_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimFaults_Tests.cpp index 73b884ff6f..b3cea104ab 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimFaults_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimFaults_Tests.cpp @@ -27,7 +27,6 @@ namespace{ struct SimFaultsTestCase{ struct Input{ - std::string name; UnitTestResult (*body)(); }; @@ -35,6 +34,7 @@ struct SimFaultsTestCase{ std::string_view description; }; + std::string name; Input input; Expectation expectation; }; @@ -42,7 +42,7 @@ struct SimFaultsTestCase{ class Test_SimFaults : public UnitTest{ public: explicit Test_SimFaults(SimFaultsTestCase scenario) - : UnitTest("Pokemon::Navigation - Sim faults: " + scenario.input.name) + : UnitTest("Pokemon::Navigation - Sim faults: " + scenario.name) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -159,12 +159,12 @@ UnitTestResult test_classes_match_enum(){ } const SimFaultsTestCase SIM_FAULTS_CASES[] = { - {.input = {.name = "none named faults none", .body = test_none_named}, .expectation = {.description = "3 chances, none faulted"}}, - {.input = {.name = "the named chances are faulted, from 1", .body = test_named_from_one}, .expectation = {.description = "1 and 3 of 4 faulted"}}, - {.input = {.name = "a chance never reached is not faulted", .body = test_never_reached}, .expectation = {.description = "2 of 3 faulted, 9 never reached"}}, - {.input = {.name = "no chances, nothing counted", .body = test_no_chances}, .expectation = {.description = "0 chances, none faulted"}}, - {.input = {.name = "each class has its own name", .body = test_class_names}, .expectation = {.description = "no two classes share a name"}}, - {.input = {.name = "fault_classes() lists every class in order", .body = test_classes_match_enum}, .expectation = {.description = "the list is the enum's values, in order"}}, + {.name = "none named faults none", .input = {.body = test_none_named}, .expectation = {.description = "3 chances, none faulted"}}, + {.name = "the named chances are faulted, from 1", .input = {.body = test_named_from_one}, .expectation = {.description = "1 and 3 of 4 faulted"}}, + {.name = "a chance never reached is not faulted", .input = {.body = test_never_reached}, .expectation = {.description = "2 of 3 faulted, 9 never reached"}}, + {.name = "no chances, nothing counted", .input = {.body = test_no_chances}, .expectation = {.description = "0 chances, none faulted"}}, + {.name = "each class has its own name", .input = {.body = test_class_names}, .expectation = {.description = "no two classes share a name"}}, + {.name = "fault_classes() lists every class in order", .input = {.body = test_classes_match_enum}, .expectation = {.description = "the list is the enum's values, in order"}}, }; } // namespace diff --git a/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimGolden_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimGolden_Tests.cpp index 552dcd42cb..528ba4c828 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimGolden_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Simulation/Pokemon_SimGolden_Tests.cpp @@ -24,7 +24,6 @@ namespace{ struct SimGoldenTestCase{ struct Input{ - std::string name; UnitTestResult (*body)(Logger& logger); }; @@ -32,6 +31,7 @@ struct SimGoldenTestCase{ std::string_view description; }; + std::string name; Input input; Expectation expectation; }; @@ -39,7 +39,7 @@ struct SimGoldenTestCase{ class Test_SimGolden : public UnitTest{ public: explicit Test_SimGolden(SimGoldenTestCase scenario) - : UnitTest("Pokemon::Navigation - Sim golden: " + scenario.input.name) + : UnitTest("Pokemon::Navigation - Sim golden: " + scenario.name) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ @@ -127,13 +127,13 @@ UnitTestResult test_missing_golden_fails(Logger& logger){ } const SimGoldenTestCase SIM_GOLDEN_CASES[] = { - {.input = {.name = "the golden's path is beside the test's source", .body = test_path_beside_source}, .expectation = {}}, - {.input = {.name = "the text is a comment line, then a line each", .body = test_text}, .expectation = {}}, - {.input = {.name = "CRLF and LF text compare the same", .body = test_same_text_ignoring_crlf}, .expectation = {}}, - {.input = {.name = "the first differing line is reported", .body = test_first_differing_line}, .expectation = {}}, - {.input = {.name = "a line more or less is reported", .body = test_extra_line}, .expectation = {}}, - {.input = {.name = "goldens are written with exactly one CRLF a line", .body = test_with_crlf}, .expectation = {}}, - {.input = {.name = "a missing golden fails", .body = test_missing_golden_fails}, .expectation = {}}, + {.name = "the golden's path is beside the test's source", .input = {.body = test_path_beside_source}, .expectation = {}}, + {.name = "the text is a comment line, then a line each", .input = {.body = test_text}, .expectation = {}}, + {.name = "CRLF and LF text compare the same", .input = {.body = test_same_text_ignoring_crlf}, .expectation = {}}, + {.name = "the first differing line is reported", .input = {.body = test_first_differing_line}, .expectation = {}}, + {.name = "a line more or less is reported", .input = {.body = test_extra_line}, .expectation = {}}, + {.name = "goldens are written with exactly one CRLF a line", .input = {.body = test_with_crlf}, .expectation = {}}, + {.name = "a missing golden fails", .input = {.body = test_missing_golden_fails}, .expectation = {}}, }; } // namespace diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp index a0f621aafa..fce811e4c6 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRangeOptions_Tests.cpp @@ -52,7 +52,6 @@ struct StoryRangeCase{ // The start and end set by slug, as saved settings load them; empty // leaves the default. struct Input{ - std::string name; std::string start_slug; std::string end_slug; }; @@ -64,6 +63,7 @@ struct StoryRangeCase{ bool valid; }; + std::string name; Input input; Expectation expectation; }; @@ -71,7 +71,7 @@ struct StoryRangeCase{ class Test_StoryRange : public UnitTest{ public: Test_StoryRange(StoryRangeCase test_case) - : UnitTest(std::format("Pokemon::StoryRangeOptions - {}", test_case.input.name)) + : UnitTest(std::format("Pokemon::StoryRangeOptions - {}", test_case.name)) , m_case(std::move(test_case)) {} @@ -106,19 +106,23 @@ class Test_StoryRange : public UnitTest{ const StoryRangeCase STORY_RANGE_CASES[] = { { - .input = {.name = "the whole database by default", .start_slug = "", .end_slug = ""}, + .name = "the whole database by default", + .input = {.start_slug = "", .end_slug = ""}, .expectation = {.start = 0, .end = 2, .valid = true}, }, { - .input = {.name = "slugs are whole-list indexes, indexes are the dropdown's", .start_slug = "3", .end_slug = "4"}, + .name = "slugs are whole-list indexes, indexes are the dropdown's", + .input = {.start_slug = "3", .end_slug = "4"}, .expectation = {.start = 1, .end = 2, .valid = true}, }, { - .input = {.name = "one checkpoint", .start_slug = "3", .end_slug = "3"}, + .name = "one checkpoint", + .input = {.start_slug = "3", .end_slug = "3"}, .expectation = {.start = 1, .end = 1, .valid = true}, }, { - .input = {.name = "a start after the end is refused", .start_slug = "4", .end_slug = "2"}, + .name = "a start after the end is refused", + .input = {.start_slug = "4", .end_slug = "2"}, .expectation = {.start = 2, .end = 0, .valid = false}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp index 8b33b4dbb0..63744d1d16 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp @@ -27,7 +27,6 @@ namespace{ struct ScreenEventsCase{ struct Input{ - std::string name; // The frame's colour; none for no frame. std::optional color; }; @@ -36,6 +35,7 @@ struct ScreenEventsCase{ ScreenEvents events; }; + std::string name; Input input; Expectation expectation; }; @@ -43,7 +43,7 @@ struct ScreenEventsCase{ class Test_AutoStoryScreenEvents : public UnitTest{ public: explicit Test_AutoStoryScreenEvents(ScreenEventsCase test_case) - : UnitTest(std::format("PokemonFRLG::AutoStoryScreenEvents - {}", test_case.input.name)) + : UnitTest(std::format("PokemonFRLG::AutoStoryScreenEvents - {}", test_case.name)) , m_case(std::move(test_case)) {} @@ -71,15 +71,18 @@ class Test_AutoStoryScreenEvents : public UnitTest{ const ScreenEventsCase SCREEN_EVENTS_CASES[] = { { - .input = {"no frame shows nothing", std::nullopt}, + .name = "no frame shows nothing", + .input = {std::nullopt}, .expectation = {{}}, }, { - .input = {"a black screen is a black fade only", 0xff000000}, + .name = "a black screen is a black fade only", + .input = {0xff000000}, .expectation = {{ScreenEvent::FADE_BLACK}}, }, { - .input = {"a white screen is a white fade only", 0xffffffff}, + .name = "a white screen is a white fade only", + .input = {0xffffffff}, .expectation = {{ScreenEvent::FADE_WHITE}}, }, }; From 6af16df738e4f926bc7b5a8f5822c630a6895a47 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:27:13 -0800 Subject: [PATCH 02/34] AutoStory: failures carry their class; a shared fault sweep by class An Outcome may carry its StoryFailureClass (outcome_failed's third argument, for a game's own failure names); failure_class_of() falls back to the shared list's class for the name. The engine's failure lines ([Event], [Checkpoint], [Step], [Segment], [Verify]) end with "(class=)" when the class is known, and an OperationFailedException that leaves an event is logged as class=operation_failed. Pokemon_StoryFaultSweep: a game gives its sweep as data (rows, an injector per sim fault, the known-failing list); the engine makes one test per class and row, named ", ", judges it, and checks the known-failing list names only its tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Engine/Pokemon_StoryEngine.cpp | 5 +- .../Engine/Pokemon_StoryEngine_Tests.cpp | 2 +- .../Engine/Pokemon_StoryStepRunner.cpp | 3 +- .../AutoStory/Pokemon_AutoStory_Tests.h | 2 + .../Pokemon/AutoStory/Pokemon_StoryEvents.cpp | 14 +- .../AutoStory/Pokemon_StoryEvents_Tests.cpp | 56 ++- .../AutoStory/Pokemon_StoryFaultSweep.cpp | 159 +++++++++ .../AutoStory/Pokemon_StoryFaultSweep.h | 98 ++++++ .../Pokemon_StoryFaultSweep_Tests.cpp | 329 ++++++++++++++++++ .../AutoStory/Pokemon_StoryFaultSweep_Tests.h | 23 ++ .../Pokemon/AutoStory/Pokemon_StoryOutcome.h | 12 +- .../AutoStory/Pokemon_StoryOutcomeClass.cpp | 35 ++ .../AutoStory/Pokemon_StoryOutcomeClass.h | 35 ++ .../AutoStory/Pokemon_StorySegments.cpp | 5 +- SerialPrograms/cmake/SourceFiles.cmake | 6 + 15 files changed, 772 insertions(+), 12 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp index b874795b8a..c1acee52b6 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp @@ -11,6 +11,7 @@ #include #include "Pokemon/AutoStory/Pokemon_CheckpointAttempts.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" +#include "Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h" #include "Pokemon_StoryEngine.h" namespace PokemonAutomation{ @@ -289,7 +290,7 @@ SegmentReport StoryEngine::run_segment( report.failed_checkpoint = checkpoint.id; report.failed_event = result.run.failed_name; report.failure = run_failure(result); - m_backend.log(std::format("[Segment] {}: failed at {}: {}", id, checkpoint.id, to_string(report.failure))); + m_backend.log(std::format("[Segment] {}: failed at {}: {}", id, checkpoint.id, to_string_with_class(report.failure))); return report; } start_saved = result.saved; @@ -329,7 +330,7 @@ VerifyReport StoryEngine::verify_checkpoint(const StoryCheckpoint& che report.saved = result.saved; m_backend.log(std::format( "[Verify] {}: run {}/{} {}", checkpoint.id, run, policy.runs, - passed ? std::string("passed") : std::format("failed: {}", to_string(run_failure(result))) + passed ? std::string("passed") : std::format("failed: {}", to_string_with_class(run_failure(result))) )); if (repeats_on_reload(result.run.failure)){ report.failure = result.run.failure; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp index 5aa882f997..f11ac6ab9f 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine_Tests.cpp @@ -242,7 +242,7 @@ const RunnerCase RUNNER_CASES[] = { {.input = {.name = "declared end pose", .step = R"({"id": "s", "kind": "scene", "declared_after": {"map": "Route1", "tiles": [[1, 2]]}})"}, .expectation = {.line = "[Step] s MASH/default: ok", .pose_map = "Route1"}}, {.input = {.name = "talk to nobody fails", .step = R"({"id": "s", "kind": "talk"})"}, - .expectation = {.failure = "talk_no_text", .line = "[Step] s TALK/default: failed: talk_no_text: A opened no text box"}}, + .expectation = {.failure = "talk_no_text", .line = "[Step] s TALK/default: failed: talk_no_text: A opened no text box (class=screen_unread)"}}, }; std::string check_runner(const RunnerCase& test, CancellableScope& scope){ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryStepRunner.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryStepRunner.cpp index c372203458..300ec4f33c 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryStepRunner.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryStepRunner.cpp @@ -6,6 +6,7 @@ #include #include +#include "Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h" #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "Pokemon_StoryStepRunner.h" @@ -53,7 +54,7 @@ Outcome StoryStepRunner::act(const StoryStep& step, RunState& state){ } m_backend.log(std::format( "[Step] {} {}: {}", step.name, step_label(step), - outcome.succeeded() ? "ok" : std::format("failed: {}", to_string(outcome)) + outcome.succeeded() ? "ok" : std::format("failed: {}", to_string_with_class(outcome)) )); return outcome; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h index 71ad803cdd..509594f6ca 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -25,6 +25,7 @@ #include "Pokemon_StoryActions_Tests.h" #include "Pokemon_StoryEvents_Tests.h" #include "Pokemon_StoryFailureClasses_Tests.h" +#include "Pokemon_StoryFaultSweep_Tests.h" #include "Pokemon_StoryInterrupts_Tests.h" #include "Pokemon_StoryLog_Tests.h" #include "Pokemon_StoryRngHandoff_Tests.h" @@ -48,6 +49,7 @@ inline void add_tests_AutoStory(UnitTestDatabase& database){ add_tests_CheckpointRetry(database); add_tests_StoryLog(database); add_tests_StoryFailureClasses(database); + add_tests_StoryFaultSweep(database); add_tests_StoryRngHandoff(database); add_tests_StoryRangeOptions(database); add_tests_StoryEvents(database); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp index c2cb6142df..1dd6975bff 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp @@ -8,7 +8,9 @@ #include #include #include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" #include "Pokemon_StoryEvents.h" +#include "Pokemon_StoryOutcomeClass.h" namespace PokemonAutomation{ namespace Pokemon{ @@ -80,10 +82,11 @@ Outcome outcome_unchanged(){ return outcome; } -Outcome outcome_failed(std::string failure, std::string detail){ +Outcome outcome_failed(std::string failure, std::string detail, std::optional failure_class){ Outcome outcome; outcome.failure = std::move(failure); outcome.detail = std::move(detail); + outcome.failure_class = failure_class; return outcome; } std::string to_string(const Outcome& outcome){ @@ -350,16 +353,19 @@ Outcome run_event(EventRun& run){ } outcome = std::move(*stop); } - log_status(std::format("failed: {}", to_string(outcome)), run); + log_status(std::format("failed: {}", to_string_with_class(outcome)), run); return outcome; } } -// What the exception being handled says, for a log line. +// What the exception being handled says, for a log line, with its class +// when the engine knows it. std::string current_exception_text(){ try{ throw; + }catch (OperationFailedException& e){ + return std::format("{}: {} ({})", e.name(), e.message(), story_failure_class_tag(StoryFailureClass::OPERATION_FAILED)); }catch (Exception& e){ return std::format("{}: {}", e.name(), e.message()); }catch (std::exception& e){ @@ -387,7 +393,7 @@ CheckpointReport stop_checkpoint(EventLogger& log, const std::string& id, Outcom std::string where = report.failed_event == 0 ? "" : std::format(" at {} {}", report.failed_event, report.failed_name); - log(checkpoint_log_line(id, std::format("failed{}: {}", where, to_string(failure)))); + log(checkpoint_log_line(id, std::format("failed{}: {}", where, to_string_with_class(failure)))); report.failure = std::move(failure); return report; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents_Tests.cpp index cafb66cd54..78b3d5796c 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents_Tests.cpp @@ -15,8 +15,10 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" #include "Pokemon_StoryEvents.h" #include "Pokemon_StoryEvents_Tests.h" +#include "Pokemon_StoryOutcomeClass.h" #include "Pokemon_TilePose.h" namespace PokemonAutomation{ @@ -248,7 +250,8 @@ UnitTestResult test_stop_names_failed_event(){ return "Nothing after the failed event should run."; } if (!lines.has("[Event] 00.04/2 talk_mom: recover: stop (expect_failed): four rows cover the mat to the TV") - || lines.lines.back() != "[Checkpoint] 00.04: failed at 2 talk_mom: expect_failed: dialogue opened" + || !lines.has("[Event] 00.04/2 talk_mom: failed: expect_failed: dialogue opened (class=state_check_failed)") + || lines.lines.back() != "[Checkpoint] 00.04: failed at 2 talk_mom: expect_failed: dialogue opened (class=state_check_failed)" ){ return std::format("Unexpected log:{}", lines.all()); } @@ -276,6 +279,49 @@ UnitTestResult test_unmatched_failure_stops(){ return true; } +// A game's own failure name with the class the game gives it. +UnitTestResult test_failure_names_its_class(){ + Checkpoint checkpoint = make_checkpoint(); + checkpoint.events.push_back(make_event("probe_for_mom", [](RunState&){ + return outcome_failed("probe_exhausted", "4 rows", StoryFailureClass::POSE_LOST); + })); + RunState state; + Lines lines; + EventLogger log = lines.logger(); + const CheckpointReport report = run_checkpoint(state, checkpoint, log); + if (failure_class_of(report.failure) != StoryFailureClass::POSE_LOST){ + return std::format("Expected the report's failure of class pose_lost:{}", lines.all()); + } + if (!lines.has("[Event] 00.04/1 probe_for_mom: failed: probe_exhausted: 4 rows (class=pose_lost)") + || lines.lines.back() != "[Checkpoint] 00.04: failed at 1 probe_for_mom: probe_exhausted: 4 rows (class=pose_lost)" + ){ + return std::format("Unexpected log:{}", lines.all()); + } + return true; +} + +// A game's action that throws OperationFailedException: the exception goes +// on, the log names its class. +UnitTestResult test_throw_names_its_class(){ + Checkpoint checkpoint = make_checkpoint(); + checkpoint.events.push_back(make_event("talk_mom", [](RunState&) -> Outcome{ + throw OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, "no dialog"); + })); + RunState state; + Lines lines; + EventLogger log = lines.logger(); + try{ + run_checkpoint(state, checkpoint, log); + return "Expected the exception to go on."; + }catch (OperationFailedException&){} + if (!lines.has("[Event] 00.04/1 talk_mom: failed: OperationFailedException: no dialog (class=operation_failed)") + || lines.lines.back() != "[Checkpoint] 00.04: failed at 1 talk_mom: OperationFailedException: no dialog (class=operation_failed)" + ){ + return std::format("Unexpected log:{}", lines.all()); + } + return true; +} + Interrupt wild_battle(ResumePolicy resume, World& world){ Interrupt interrupt; interrupt.name = "wild_battle"; @@ -664,6 +710,14 @@ const StoryEventTestCase STORY_EVENT_CASES[] = { .input = {.name = "an unanswered failure stops", .test = test_unmatched_failure_stops}, .expectation = {.description = "stops checkpoint execution when failure has no handler"}, }, + { + .input = {.name = "a failure names its class", .test = test_failure_names_its_class}, + .expectation = {.description = "logs the class a game gives its own failure name"}, + }, + { + .input = {.name = "a throw names its class", .test = test_throw_names_its_class}, + .expectation = {.description = "logs operation_failed for an OperationFailedException that goes on"}, + }, { .input = {.name = "an interrupt mid-event", .test = test_interrupt_mid_event}, .expectation = {.description = "handles asynchronous interruption during event execution"}, diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp new file mode 100644 index 0000000000..892571c42b --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp @@ -0,0 +1,159 @@ +/* Story Fault Sweep + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_StoryFaultSweep.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +// Whether `cell` passes with `result`: logs a table row per failing +// variant, with the class's tag. +UnitTestResult judge_cell(Logger& logger, const FaultSweepCell& cell, const FaultSweepResult& result){ + const std::string tag = story_failure_class_tag(cell.failure_class); + if (result.not_swept){ + logger.log(std::format("Fault sweep {} ({}): not swept, {}", cell.row, tag, *result.not_swept)); + return true; + } + logger.log(std::format("Fault sweep {} ({}): {} variants, {} fail.", cell.row, tag, result.variants, result.failures.size())); + if (result.failures.empty()){ + return true; + } + std::string message = std::format("{} of {} variants fail {} ({}):", result.failures.size(), result.variants, cell.row, tag); + for (const FaultSweepFailure& failure : result.failures){ + logger.log(std::format("| {} | {} | {} | {} | {} |", cell.row, failure.step, tag, failure.variant, failure.stopped)); + message += std::format("\n {} {}: {}", failure.step, failure.variant, failure.stopped); + } + return message; +} + +// `result` turned over when `name` is on the known-failing list. +UnitTestResult judge_known_failing(Logger& logger, const StoryFaultSweep& sweep, const std::string& name, UnitTestResult result){ + const auto known = sweep.known_failing.find(name); + if (known == sweep.known_failing.end()){ + return result; + } + if (result.result == UnitTestResult::PASSED){ + return std::format("on KNOWN_FAILING ({}) but passes now: take it off the list.", known->second); + } + logger.log(std::format("Known failing until {}: {}", known->second, result.message)); + return true; +} + +class Test_FaultSweepCell : public UnitTest{ +public: + Test_FaultSweepCell(std::shared_ptr sweep, FaultSweepCell cell) + : UnitTest(fault_sweep_test_name(sweep->test_prefix, cell)) + , m_sweep(std::move(sweep)) + , m_cell(std::move(cell)) + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + UnitTestResult result; + try{ + const FaultSweepResult swept = m_sweep->injectors.at(m_cell.fault)(logger, m_cell.row); + result = judge_cell(logger, m_cell, swept); + }catch (Exception& e){ + result = std::format("{}: {}", e.name(), e.message()); + } + return judge_known_failing(logger, *m_sweep, name(), std::move(result)); + } + +private: + const std::shared_ptr m_sweep; + const FaultSweepCell m_cell; +}; + +class Test_KnownFailingNames : public UnitTest{ +public: + explicit Test_KnownFailingNames(std::shared_ptr sweep) + : UnitTest(std::format("{} - Fault sweep: known failing names its tests", sweep->test_prefix)) + , m_sweep(std::move(sweep)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::vector stale = known_failing_without_a_test(*m_sweep); + if (stale.empty()){ + return true; + } + std::string message = "KNOWN_FAILING names no test (renamed?):"; + for (const std::string& name : stale){ + message += std::format("\n {}", name); + } + return message; + } + +private: + const std::shared_ptr m_sweep; +}; + +} // namespace + + +std::vector fault_sweep_cells(const StoryFaultSweep& sweep){ + std::vector cells; + for (const StoryFailureClassInfo& info : story_failure_classes()){ + for (FaultClass fault : info.injected_by){ + if (!sweep.injectors.contains(fault)){ + continue; + } + for (const std::string& row : sweep.rows){ + cells.push_back(FaultSweepCell{.failure_class = info.failure_class, .fault = fault, .row = row}); + } + } + } + return cells; +} + +std::string fault_sweep_test_name(std::string_view test_prefix, const FaultSweepCell& cell){ + return std::format("{} - Fault sweep: {}, {}", test_prefix, cell.row, story_failure_class_info(cell.failure_class).id); +} + +std::vector classes_not_swept(const StoryFaultSweep& sweep){ + std::vector missed; + for (const StoryFailureClassInfo& info : story_failure_classes()){ + for (FaultClass fault : info.injected_by){ + if (!sweep.injectors.contains(fault)){ + missed.push_back(info.failure_class); + break; + } + } + } + return missed; +} + +std::vector known_failing_without_a_test(const StoryFaultSweep& sweep){ + std::set names; + for (const FaultSweepCell& cell : fault_sweep_cells(sweep)){ + names.insert(fault_sweep_test_name(sweep.test_prefix, cell)); + } + std::vector stale; + for (const auto& item : sweep.known_failing){ + if (!names.contains(item.first)){ + stale.push_back(item.first); + } + } + return stale; +} + +void add_fault_sweep_tests(UnitTestDatabase& database, std::shared_ptr sweep){ + for (FaultSweepCell& cell : fault_sweep_cells(*sweep)){ + database.add(sweep, std::move(cell)); + } + database.add(std::move(sweep)); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h new file mode 100644 index 0000000000..53b27c134a --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h @@ -0,0 +1,98 @@ +/* Story Fault Sweep + * + * From: https://github.com/PokemonAutomation/ + * + * The fault sweeps every game runs on its sim: each class of failure the + * consoles showed (Pokemon_StoryFailureClasses.h) injected at every row + * of a game's story, not only where it was seen. A game gives its sweep as + * data: its rows, an injector per sim fault its sim can inject, and the + * sweeps it fails today. This makes one test per class and row, named by + * the class's id, and judges it the same way for every game. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryFaultSweep_H +#define PokemonAutomation_Pokemon_StoryFaultSweep_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/Navigation/Simulation/Pokemon_SimFaults.h" +#include "Pokemon_StoryFailureClasses.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// One injected variant that failed its row. +struct FaultSweepFailure{ + // The row's step the fault was injected at. + std::string step; + // Which variant of the fault: "warp 1", "seed 16". + std::string variant; + // How the row stopped or where it ended instead. + std::string stopped; +}; + +// What injecting one fault over one row found. +struct FaultSweepResult{ + size_t variants = 0; + std::vector failures = {}; + // Why the row was not swept (it fails clean, the fault has no chance + // in it); nothing when it was. + std::optional not_swept = std::nullopt; +}; + +// A game's injector of one sim fault: runs every variant of it over the +// row named `row`. +using FaultInjector = std::function; + +// A game's fault sweep, as data. +struct StoryFaultSweep{ + // The start of every test's name: "PokemonFRLG::AutoStory". + std::string test_prefix; + // The story's rows to sweep, by id, in story order. + std::vector rows; + // An injector per sim fault the game's sim can inject. + std::map injectors; + // The sweeps the program fails today, by test name, with the likely + // fix: such a test passes while it fails, and fails once it passes. + std::map known_failing = {}; +}; + +// One test of a sweep: one sim fault over one row. +struct FaultSweepCell{ + StoryFailureClass failure_class; + FaultClass fault; + std::string row; +}; + +// Every test of `sweep`: the classes in the shared list's order, each +// over every row. +std::vector fault_sweep_cells(const StoryFaultSweep& sweep); +// " - Fault sweep: 11.01, warp_no_op". +std::string fault_sweep_test_name(std::string_view test_prefix, const FaultSweepCell& cell); + +// The classes the shared list injects by a sim fault that `sweep` has no +// injector for, in the list's order: what the game cannot sweep yet. +std::vector classes_not_swept(const StoryFaultSweep& sweep); +// The names on `sweep`'s known-failing list that no test has, as after a +// rename. +std::vector known_failing_without_a_test(const StoryFaultSweep& sweep); + +// Adds a test per cell of `sweep`, and one that its known-failing list +// names only its tests. +void add_fault_sweep_tests(UnitTestDatabase& database, std::shared_ptr sweep); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp new file mode 100644 index 0000000000..0073c32617 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp @@ -0,0 +1,329 @@ +/* Story Fault Sweep Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The shared sweep against a fake game: two rows, injectors that report + * what a test sets, and a known-failing list. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon_StoryFaultSweep.h" +#include "Pokemon_StoryFaultSweep_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +constexpr std::string_view PREFIX = "Fake::AutoStory"; + +// An injector that reports `result` for every row. +FaultInjector reporting(FaultSweepResult result){ + return [result = std::move(result)](Logger&, const std::string&){ + return result; + }; +} + +FaultSweepResult clean_result(){ + return FaultSweepResult{.variants = 3, .failures = {}, .not_swept = std::nullopt}; +} + +FaultSweepResult failing_result(){ + return FaultSweepResult{ + .variants = 3, + .failures = {{.step = "fly_celadon", .variant = "warp 1", .stopped = "ended in Lavender Town"}}, + .not_swept = std::nullopt, + }; +} + +// A fake game's sweep: rows 01.01 and 01.02, the given injectors. +StoryFaultSweep fake_sweep(std::map injectors, std::map known_failing = {}){ + return StoryFaultSweep{ + .test_prefix = std::string(PREFIX), + .rows = {"01.01", "01.02"}, + .injectors = std::move(injectors), + .known_failing = std::move(known_failing), + }; +} + + +// The tests add_fault_sweep_tests() makes, by name. +struct SweepNamesTestCase{ + struct Input{ + std::vector injected; + }; + + struct Expectation{ + std::vector names; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +class Test_SweepNames : public UnitTest{ +public: + explicit Test_SweepNames(SweepNamesTestCase test_case) + : UnitTest(std::format("Pokemon::StoryFaultSweep - tests: {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::map injectors; + for (FaultClass fault : m_case.input.injected){ + injectors.emplace(fault, reporting(clean_result())); + } + std::vector names; + for (const FaultSweepCell& cell : fault_sweep_cells(fake_sweep(std::move(injectors)))){ + names.emplace_back(fault_sweep_test_name(PREFIX, cell)); + } + if (names != m_case.expectation.names){ + std::string got; + for (const std::string& name : names){ + got += std::format("\n {}", name); + } + return std::format("Unexpected tests:{}", got); + } + return true; + } + +private: + const SweepNamesTestCase m_case; +}; + +const SweepNamesTestCase SWEEP_NAMES_CASES[] = { + { + .name = "classes in the list's order, then rows", + .input = {.injected = {FaultClass::LATE_FADE, FaultClass::WARP_NO_OP}}, + .expectation = {.names = { + "Fake::AutoStory - Fault sweep: 01.01, warp_no_op", + "Fake::AutoStory - Fault sweep: 01.02, warp_no_op", + "Fake::AutoStory - Fault sweep: 01.01, late_fade", + "Fake::AutoStory - Fault sweep: 01.02, late_fade", + }}, + }, + { + .name = "a sim fault named by its story class", + .input = {.injected = {FaultClass::DARK_CAVE}}, + .expectation = {.names = { + "Fake::AutoStory - Fault sweep: 01.01, dark_map", + "Fake::AutoStory - Fault sweep: 01.02, dark_map", + }}, + }, + { + .name = "no injectors", + .input = {.injected = {}}, + .expectation = {.names = {}}, + }, +}; + + +// One sweep test made by add_fault_sweep_tests(), run. +struct SweepRunTestCase{ + struct Input{ + FaultSweepResult result; + // The test's known-failing fix, if it is on the list. + std::optional known_failing; + }; + + struct Expectation{ + bool passes; + // What the failure message starts with, when it fails. + std::string message; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +class Test_SweepRun : public UnitTest{ +public: + explicit Test_SweepRun(SweepRunTestCase test_case) + : UnitTest(std::format("Pokemon::StoryFaultSweep - run: {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{ + const std::string test_name = "Fake::AutoStory - Fault sweep: 01.02, warp_no_op"; + std::map known_failing; + if (m_case.input.known_failing){ + known_failing.emplace(test_name, *m_case.input.known_failing); + } + UnitTestDatabase database; + add_fault_sweep_tests(database, std::make_shared(fake_sweep( + {{FaultClass::WARP_NO_OP, reporting(m_case.input.result)}}, std::move(known_failing) + ))); + const auto test = database.find(test_name); + if (test == database.end()){ + return std::format("No test \"{}\".", test_name); + } + const UnitTestResult result = test->second->run(logger, scope); + const bool passed = result.result == UnitTestResult::PASSED; + if (passed != m_case.expectation.passes){ + return std::format("Expected {}, got: {}", m_case.expectation.passes ? "a pass" : "a failure", result.message); + } + if (!passed && !result.message.starts_with(m_case.expectation.message)){ + return std::format("Expected a message starting \"{}\", got \"{}\"", m_case.expectation.message, result.message); + } + return true; + } + +private: + const SweepRunTestCase m_case; +}; + +const SweepRunTestCase SWEEP_RUN_CASES[] = { + { + .name = "every variant passes", + .input = {.result = clean_result(), .known_failing = std::nullopt}, + .expectation = {.passes = true, .message = ""}, + }, + { + .name = "a variant fails", + .input = {.result = failing_result(), .known_failing = std::nullopt}, + .expectation = { + .passes = false, + .message = "1 of 3 variants fail 01.02 (class=warp_no_op):\n fly_celadon warp 1: ended in Lavender Town", + }, + }, + { + .name = "a row not swept", + .input = {.result = FaultSweepResult{.variants = 0, .failures = {}, .not_swept = "the row fails clean"}, .known_failing = std::nullopt}, + .expectation = {.passes = true, .message = ""}, + }, + { + .name = "a known failure", + .input = {.result = failing_result(), .known_failing = "check the fly lands"}, + .expectation = {.passes = true, .message = ""}, + }, + { + .name = "a known failure that passes now", + .input = {.result = clean_result(), .known_failing = "check the fly lands"}, + .expectation = {.passes = false, .message = "on KNOWN_FAILING (check the fly lands) but passes now: take it off the list."}, + }, +}; + + +// The sweep's list checks against the shared classes. +struct SweepListTestCase{ + struct Input{ + std::vector injected; + std::vector known_failing; + }; + + struct Expectation{ + std::vector missed; + std::vector stale_known_failing; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +class Test_SweepList : public UnitTest{ +public: + explicit Test_SweepList(SweepListTestCase test_case) + : UnitTest(std::format("Pokemon::StoryFaultSweep - list: {}", test_case.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::map injectors; + for (FaultClass fault : m_case.input.injected){ + injectors.emplace(fault, reporting(clean_result())); + } + std::map known_failing; + for (const std::string& name : m_case.input.known_failing){ + known_failing.emplace(name, "a fix"); + } + const StoryFaultSweep sweep = fake_sweep(std::move(injectors), std::move(known_failing)); + if (classes_not_swept(sweep) != m_case.expectation.missed){ + return std::format("Unexpected classes not swept: {}", classes_not_swept(sweep).size()); + } + if (known_failing_without_a_test(sweep) != m_case.expectation.stale_known_failing){ + return std::format("Unexpected stale known-failing names: {}", known_failing_without_a_test(sweep).size()); + } + return true; + } + +private: + const SweepListTestCase m_case; +}; + +using C = StoryFailureClass; + +const SweepListTestCase SWEEP_LIST_CASES[] = { + { + .name = "a game that injects all but one", + .input = { + .injected = { + FaultClass::SCENE_END_POSE, FaultClass::SCENE_EARLY, FaultClass::BATTLE_OPENING, FaultClass::WILD_BATTLES, + FaultClass::LATE_FADE, FaultClass::SLOW_FADE_IN, FaultClass::WARP_NO_OP, FaultClass::DARK_CAVE, + FaultClass::LOST_TAP, FaultClass::UNSEEN_STEP, + }, + .known_failing = {}, + }, + .expectation = {.missed = {C::MOUNT_LOST}, .stale_known_failing = {}}, + }, + { + .name = "a game that injects none", + .input = {.injected = {}, .known_failing = {}}, + .expectation = { + .missed = { + C::LOST_TAP, C::UNSEEN_STEP, C::MOUNT_LOST, C::WARP_NO_OP, C::LATE_FADE, C::SLOW_FADE_IN, + C::DARK_MAP, C::SCENE_END_POSE, C::SCENE_EARLY, C::BATTLE_OPENING, C::WILD_BATTLES, + }, + .stale_known_failing = {}, + }, + }, + { + .name = "a known failure under an old name", + .input = { + .injected = {FaultClass::WARP_NO_OP}, + .known_failing = { + "Fake::AutoStory - Fault sweep: 01.01, warp_no_op", + "Fake::AutoStory - Fault sweep: 01.01, warp no-op", + }, + }, + .expectation = { + .missed = { + C::LOST_TAP, C::UNSEEN_STEP, C::MOUNT_LOST, C::LATE_FADE, C::SLOW_FADE_IN, + C::DARK_MAP, C::SCENE_END_POSE, C::SCENE_EARLY, C::BATTLE_OPENING, C::WILD_BATTLES, + }, + .stale_known_failing = {"Fake::AutoStory - Fault sweep: 01.01, warp no-op"}, + }, + }, +}; + +} // namespace + + +void add_tests_StoryFaultSweep(UnitTestDatabase& database){ + for (const SweepNamesTestCase& test_case : SWEEP_NAMES_CASES){ + database.add(test_case); + } + for (const SweepRunTestCase& test_case : SWEEP_RUN_CASES){ + database.add(test_case); + } + for (const SweepListTestCase& test_case : SWEEP_LIST_CASES){ + database.add(test_case); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.h new file mode 100644 index 0000000000..41d4443e73 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.h @@ -0,0 +1,23 @@ +/* Story Fault Sweep Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryFaultSweep_Tests_H +#define PokemonAutomation_Pokemon_StoryFaultSweep_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers unit tests for the shared fault sweep. +void add_tests_StoryFaultSweep(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcome.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcome.h index a752df6972..66a1e1a083 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcome.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcome.h @@ -17,6 +17,7 @@ #include #include #include "Common/Cpp/MoveOnlyFunction.h" +#include "Pokemon_StoryFailureClasses.h" #include "Pokemon_StoryLog.h" #include "Pokemon_StoryPose.h" @@ -36,6 +37,10 @@ struct Outcome{ // check, a TM the lead already knows. A reload of the same save undoes // nothing it did. bool changed_nothing = false; + // The failure's class, when the action knows it: a game's own failure + // name ("probe_exhausted") has none in the shared list until the game + // gives it one here. Nothing: the class the list gives `failure`. + std::optional failure_class = std::nullopt; bool succeeded() const; }; @@ -44,7 +49,12 @@ Outcome outcome_ok(std::optional pose = std::nullopt); // outcome_ok() with `changed_nothing`. Outcome outcome_unchanged(); // Constructs a failed event outcome with reason and optional diagnostic detail. -Outcome outcome_failed(std::string failure, std::string detail = ""); +// `failure_class` is for a name the shared list does not class (a game's +// own); without it the list's class for `failure` holds. +Outcome outcome_failed( + std::string failure, std::string detail = "", + std::optional failure_class = std::nullopt +); // "probe_exhausted: 4 rows": the failure and its detail, if any. std::string to_string(const Outcome& outcome); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.cpp new file mode 100644 index 0000000000..064bb87ee4 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.cpp @@ -0,0 +1,35 @@ +/* Story Outcome Class + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_StoryOutcomeClass.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +std::optional failure_class_of(const Outcome& outcome){ + if (outcome.succeeded()){ + return std::nullopt; + } + if (outcome.failure_class){ + return outcome.failure_class; + } + return story_failure_class_of_outcome(outcome.failure); +} + +std::string to_string_with_class(const Outcome& outcome){ + const std::optional failure_class = failure_class_of(outcome); + if (!failure_class){ + return to_string(outcome); + } + return std::format("{} ({})", to_string(outcome), story_failure_class_tag(*failure_class)); +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h new file mode 100644 index 0000000000..ec692db6ab --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h @@ -0,0 +1,35 @@ +/* Story Outcome Class + * + * From: https://github.com/PokemonAutomation/ + * + * The class (Pokemon_StoryFailureClasses.h) of a failed Outcome, and the + * text a failure's log line ends with. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryOutcomeClass_H +#define PokemonAutomation_Pokemon_StoryOutcomeClass_H + +#include +#include +#include "Pokemon_StoryFailureClasses.h" +#include "Pokemon_StoryOutcome.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// The class of a failed `outcome`: its own, else the shared list's for its +// name. Nothing for a success or a name no class lists. +std::optional failure_class_of(const Outcome& outcome); + +// to_string() and the class, as a failure's log line ends: +// "expect_failed: has_parcel (class=state_check_failed)"; without a class, +// to_string() alone. +std::string to_string_with_class(const Outcome& outcome); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySegments.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySegments.cpp index c46ab2764e..2ff6960ed0 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySegments.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySegments.cpp @@ -8,6 +8,7 @@ #include #include "Pokemon_CheckpointAttempts.h" #include "Pokemon_StoryLog.h" +#include "Pokemon_StoryOutcomeClass.h" #include "Pokemon_StorySegments.h" namespace PokemonAutomation{ @@ -220,7 +221,7 @@ SegmentReport stop_segment(const std::string& id, Outcome failure, SegmentHooks& where += std::format(" {}", report.failed_event); } } - say(std::format("[Segment] {}: failed{}: {}", id, where, to_string(failure)), hooks); + say(std::format("[Segment] {}: failed{}: {}", id, where, to_string_with_class(failure)), hooks); report.failure = std::move(failure); return report; } @@ -286,7 +287,7 @@ bool verify_run( "[Verify] {}: run {}/{} failed{}: {}", spec.id, run, policy.runs, result.failed_name.empty() ? "" : std::format(" at {}", result.failed_name), - to_string(result.failure) + to_string_with_class(result.failure) ), hooks); return false; } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index c0a64f7488..8ced757f2a 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1636,6 +1636,10 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.h Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses_Tests.cpp Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses_Tests.h + Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp + Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h + Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp + Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryInterrupts.cpp Source/Pokemon/AutoStory/Pokemon_StoryInterrupts.h Source/Pokemon/AutoStory/Pokemon_StoryInterrupts_Tests.cpp @@ -1645,6 +1649,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.cpp Source/Pokemon/AutoStory/Pokemon_StoryLog_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryOutcome.h + Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.cpp + Source/Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h Source/Pokemon/AutoStory/Pokemon_StoryPose.h Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.cpp Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.h From 5334a11890b85dd9fd81eea8603f262c15774223 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:28:26 -0800 Subject: [PATCH 03/34] AutoStory fault sweep: nest Failure and Injector in their structs Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_StoryFaultSweep.cpp | 2 +- .../AutoStory/Pokemon_StoryFaultSweep.h | 32 +++++++++---------- .../Pokemon_StoryFaultSweep_Tests.cpp | 8 ++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp index 892571c42b..3ee4d68bc0 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.cpp @@ -30,7 +30,7 @@ UnitTestResult judge_cell(Logger& logger, const FaultSweepCell& cell, const Faul return true; } std::string message = std::format("{} of {} variants fail {} ({}):", result.failures.size(), result.variants, cell.row, tag); - for (const FaultSweepFailure& failure : result.failures){ + for (const FaultSweepResult::Failure& failure : result.failures){ logger.log(std::format("| {} | {} | {} | {} | {} |", cell.row, failure.step, tag, failure.variant, failure.stopped)); message += std::format("\n {} {}: {}", failure.step, failure.variant, failure.stopped); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h index 53b27c134a..9b85141408 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep.h @@ -31,37 +31,37 @@ namespace PokemonAutomation{ namespace Pokemon{ -// One injected variant that failed its row. -struct FaultSweepFailure{ - // The row's step the fault was injected at. - std::string step; - // Which variant of the fault: "warp 1", "seed 16". - std::string variant; - // How the row stopped or where it ended instead. - std::string stopped; -}; - // What injecting one fault over one row found. struct FaultSweepResult{ + // One injected variant that failed its row. + struct Failure{ + // The row's step the fault was injected at. + std::string step; + // Which variant of the fault: "warp 1", "seed 16". + std::string variant; + // How the row stopped or where it ended instead. + std::string stopped; + }; + size_t variants = 0; - std::vector failures = {}; + std::vector failures = {}; // Why the row was not swept (it fails clean, the fault has no chance // in it); nothing when it was. std::optional not_swept = std::nullopt; }; -// A game's injector of one sim fault: runs every variant of it over the -// row named `row`. -using FaultInjector = std::function; - // A game's fault sweep, as data. struct StoryFaultSweep{ + // A game's injector of one sim fault: runs every variant of it over + // the row named `row`. + using Injector = std::function; + // The start of every test's name: "PokemonFRLG::AutoStory". std::string test_prefix; // The story's rows to sweep, by id, in story order. std::vector rows; // An injector per sim fault the game's sim can inject. - std::map injectors; + std::map injectors; // The sweeps the program fails today, by test name, with the likely // fix: such a test passes while it fails, and fails once it passes. std::map known_failing = {}; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp index 0073c32617..00a62c9817 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFaultSweep_Tests.cpp @@ -28,7 +28,7 @@ namespace{ constexpr std::string_view PREFIX = "Fake::AutoStory"; // An injector that reports `result` for every row. -FaultInjector reporting(FaultSweepResult result){ +StoryFaultSweep::Injector reporting(FaultSweepResult result){ return [result = std::move(result)](Logger&, const std::string&){ return result; }; @@ -47,7 +47,7 @@ FaultSweepResult failing_result(){ } // A fake game's sweep: rows 01.01 and 01.02, the given injectors. -StoryFaultSweep fake_sweep(std::map injectors, std::map known_failing = {}){ +StoryFaultSweep fake_sweep(std::map injectors, std::map known_failing = {}){ return StoryFaultSweep{ .test_prefix = std::string(PREFIX), .rows = {"01.01", "01.02"}, @@ -80,7 +80,7 @@ class Test_SweepNames : public UnitTest{ {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - std::map injectors; + std::map injectors; for (FaultClass fault : m_case.input.injected){ injectors.emplace(fault, reporting(clean_result())); } @@ -241,7 +241,7 @@ class Test_SweepList : public UnitTest{ {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - std::map injectors; + std::map injectors; for (FaultClass fault : m_case.input.injected){ injectors.emplace(fault, reporting(clean_result())); } From 09576788f4d51283811188908a9f40cbf906cb0e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:41:49 -0800 Subject: [PATCH 04/34] Story data codec: drop the stale PokemonSimulation native conformance run The shared wire cases at PokemonSimulation 866613f (and its main) still use the old pose (certainty/where) and per-kind step fields; since the #312 review the native reader reads steps as an action plus typed args, so every kind case without args failed. The Python reader still checks those cases; the native codec is covered by its own CTest cases. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .github/workflows/story-data.yml | 4 ---- devtools/story-data-tests/README.md | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/story-data.yml b/.github/workflows/story-data.yml index 545299ac51..8576b19548 100644 --- a/.github/workflows/story-data.yml +++ b/.github/workflows/story-data.yml @@ -28,7 +28,3 @@ jobs: - run: cmake -S devtools/story-data-tests -B build-story-data -DCMAKE_BUILD_TYPE=Debug - run: cmake --build build-story-data --config Debug -j4 - run: ctest --test-dir build-story-data -C Debug --output-on-failure - - if: runner.os != 'Windows' - run: ./build-story-data/StoryDataTests publisher/data/story/wire-conformance.json - - if: runner.os == 'Windows' - run: ./build-story-data/Debug/StoryDataTests.exe publisher/data/story/wire-conformance.json diff --git a/devtools/story-data-tests/README.md b/devtools/story-data-tests/README.md index 310cea3ea3..a2081dc492 100644 --- a/devtools/story-data-tests/README.md +++ b/devtools/story-data-tests/README.md @@ -6,7 +6,6 @@ Run without Qt, controllers, profiles or game saves: cmake -S devtools/story-data-tests -B build/story-data-tests cmake --build build/story-data-tests -j4 ctest --test-dir build/story-data-tests --output-on-failure -build/story-data-tests/StoryDataTests /path/to/PokemonSimulation/data/story/wire-conformance.json ``` For a multi-configuration generator, add `--config Debug` to the build, @@ -14,15 +13,18 @@ For a multi-configuration generator, add `--config Debug` to the build, The same native cases are registered in the application's unit-test runner. `Pokemon_StoryStepJson` encodes and reads the common `StoryCheckpoint`, -`StoryStep` and tile-based `Pose` records. It retains action order, alternative -tiles, certainty, absent facing and explicit false/zero values. Unknown fields, -action/position tags and invalid primitive types fail. Native default values -are omitted canonically; encoding does not establish semantic route validity. +`StoryStep` and `GridPose` records. It keeps action order, alternative tiles +and absent facing, and fills arg fallbacks. Unknown fields, kinds, actions and +args, invalid primitive types and missing required args fail. Encoding does not +establish semantic route validity. -The portable workflow also reads the 31 synthetic conformance cases at +The portable workflow checks the Python reader against the synthetic +conformance cases at [PokemonSimulation revision 866613f](https://github.com/dayfine/PokemonSimulation/tree/866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3/data/story). -Python reads the same input/expectation records. This fixture revision is a -contract-test dependency, not an approved map-resource revision. +Those cases still use the older pose and per-kind step fields, so the native +reader, which reads steps as an action plus typed args, no longer runs them. +This fixture revision is a contract-test dependency, not an approved +map-resource revision. See the [shared checkpoint contract](https://github.com/dayfine/PokemonSimulation/blob/866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3/docs/story/CHECKPOINT_CONTRACT.md) for the field boundary and proposed common requirements, state, save/retry and From ee797a42e82fc64e24b5877a5f148cd7df9db6f2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:43:14 -0800 Subject: [PATCH 05/34] ScreenEvents tests: the case's name outside its input (code health test-case) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ScreenEvents/ScreenEvents_Tests.cpp | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp index cc6d9f828b..14a1483558 100644 --- a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp @@ -132,23 +132,22 @@ UnitTestResult test_watcher(){ } -struct ScreenEventsInput{ - std::string name; - std::function body; -}; - -struct ScreenEventsExpectation{ -}; - struct ScreenEventsCase{ - ScreenEventsInput input; - ScreenEventsExpectation expectation; + struct Input{ + std::function body; + }; + struct Expectation{ + }; + + std::string name; + Input input; + Expectation expectation; }; class Test_ScreenEvents : public UnitTest{ public: explicit Test_ScreenEvents(ScreenEventsCase test_case) - : UnitTest(std::format("CommonTools::ScreenEvents - {}", test_case.input.name)) + : UnitTest(std::format("CommonTools::ScreenEvents - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -164,15 +163,18 @@ class Test_ScreenEvents : public UnitTest{ const ScreenEventsCase SCREEN_EVENTS_CASES[] = { { - .input = {"a set of events, its fade and its log text", test_set_and_describe}, + .name = "a set of events, its fade and its log text", + .input = {.body = test_set_and_describe}, .expectation = {}, }, { - .input = {"a fade is uniform, dark or white; a textured floor is none", test_fade_of_screen}, + .name = "a fade is uniform, dark or white; a textured floor is none", + .input = {.body = test_fade_of_screen}, .expectation = {}, }, { - .input = {"an observer as a watcher records and stops", test_watcher}, + .name = "an observer as a watcher records and stops", + .input = {.body = test_watcher}, .expectation = {}, }, }; From a44ab0594b1efcda3aea9733417670ffba4995fe Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:45:01 -0800 Subject: [PATCH 06/34] ScreenEvents: comments say why without lab runs or PR numbers (#313 review) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/CommonTools/ScreenEvents/ScreenFades.h | 9 ++++----- .../Inference/NintendoSwitch_HomeScreenObserver.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenFades.h b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenFades.h index ad452c0761..a153f49246 100644 --- a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenFades.h +++ b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenFades.h @@ -22,11 +22,10 @@ ScreenEvents fade_events(WarpFade fade); WarpFade fade_in(const ScreenEvents& events); -// A fade is uniform over the middle 80% of the screen, the shared -// Black/WhiteScreenWatcher's stddev test (upstream #1717): a dim cave floor -// is textured, so it is no fade (BDSP's Oreburgh Gate, mean 46, lab-B -// 2026-11-08). Check against the Gate's frames on the console before -// tightening. +// A fade is uniform over the middle 80% of the screen, the same stddev +// test as the shared Black/WhiteScreenWatcher: a dim cave floor (mean +// about 46 a channel) is textured, so it is no fade. A tighter bound +// needs checking against such dim floors first. constexpr double FADE_MAX_STDDEV_SUM = 10; // Dark goes to an rgb sum of 225, as a cave mouth's fade is dim, 45 to 64 // a channel, not black. diff --git a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeScreenObserver.h b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeScreenObserver.h index 1916a70edf..c5ebbff0e2 100644 --- a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeScreenObserver.h +++ b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeScreenObserver.h @@ -21,8 +21,8 @@ namespace NintendoSwitch{ // A game's observer behind a look at the Switch itself: a frame showing // the HOME menu shows SWITCH_HOME_MENU and nothing else, as a game's -// detectors may read HOME's plain screen as a quiet overworld (BDSP, -// lab-B 2026-11-09). Every other frame is the game's to read. +// detectors may read HOME's plain screen as a quiet overworld. Every +// other frame is the game's to read. class SwitchHomeObserver : public ScreenEventObserver{ public: SwitchHomeObserver(ConsoleHandle& console, ScreenEventObserver& game); From 68e4ecf59fbece31ac8b3974eb3265fee5402e3c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:46:11 -0800 Subject: [PATCH 07/34] AutoStory: a single step after the last target leaves the end pose unknown (#312 review) checkpoint_end_pose() stopped looking back only at LEGS, so a STEP after a route kept the route's target as the end and the tile check failed a run that worked. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.cpp | 3 ++- .../Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.h | 2 +- .../Pokemon/AutoStory/Pokemon_StorySavePolicy_Tests.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.cpp index 644c138f22..d4881de3bd 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.cpp @@ -185,7 +185,8 @@ std::optional checkpoint_end_pose(const StoryCheckpoint& checkpoint){ if (std::optional target = pose_arg(*step)){ return target; } - if (step->kind == StoryStepKind::LEGS){ + // Taps and single steps move the player without saying where to. + if (step->kind == StoryStepKind::LEGS || step->kind == StoryStepKind::STEP){ return std::nullopt; } } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.h index 8e1b0c496a..c04c0e8e7e 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.h @@ -66,7 +66,7 @@ struct PostconditionReport{ // Where `checkpoint` ends: its postconditions' position, else the last // step's declared pose or target. Unset when a step after that moves the -// player in a way the plan does not place (taps of legs). +// player in a way the plan does not place (taps of legs, a single step). std::optional checkpoint_end_pose(const StoryCheckpoint& checkpoint); // Checks the end position (map, tile among the pose's tiles, facing), diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySavePolicy_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySavePolicy_Tests.cpp index 2e1ecac7f9..b836256ce2 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySavePolicy_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StorySavePolicy_Tests.cpp @@ -378,6 +378,14 @@ UnitTestResult test_end_pose_from_the_plan(){ if (!end || end->map != "RocketHideout_B3F" || end->tiles != std::vector{TilePos{12, 13}}){ return "Expected the last route's target as the end."; } + StoryCheckpoint stepped = checkpoint; + StoryStep step; + step.kind = StoryStepKind::STEP; + step.name = "one more"; + stepped.steps.push_back(std::move(step)); + if (checkpoint_end_pose(stepped)){ + return "A step after the last target leaves the end unknown."; + } StoryStep legs; legs.kind = StoryStepKind::LEGS; legs.name = "taps"; From 6935936d939822ec3ffb466bda887c4503a31e92 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:47:06 -0800 Subject: [PATCH 08/34] AutoStory engine: name the text press timing (#332 review) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp index 6a6481ccba..fb3d51c36c 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBuiltinActions.cpp @@ -26,6 +26,10 @@ namespace{ inline constexpr size_t MAX_TEXT_LOOKS = 80; // Looks for a text box to open after a talk's A. inline constexpr size_t MAX_OPEN_LOOKS = 20; +// A press through text or an answer: held, then released before the next +// look, the same for every text press so they read alike in the log. +inline constexpr std::chrono::milliseconds TEXT_PRESS_HOLD{80}; +inline constexpr std::chrono::milliseconds TEXT_PRESS_RELEASE{120}; // The action of a built-in that needs the game's own code. @@ -54,7 +58,7 @@ Outcome mash_to_overworld(StoryBackend& backend){ if (now.events.has(ScreenEvent::PLAYER_CAN_MOVE) && !now.events.has(ScreenEvent::DIALOG_BOX)){ return outcome_ok(); } - backend.press(NintendoSwitch::BUTTON_A, 80ms, 120ms); + backend.press(NintendoSwitch::BUTTON_A, TEXT_PRESS_HOLD, TEXT_PRESS_RELEASE); } return outcome_failed("mash_no_overworld", std::format("no overworld after {} looks", MAX_TEXT_LOOKS)); } @@ -69,7 +73,7 @@ Outcome mash(StoryBackend& backend, const StoryActionCall&, RunState&) template Outcome talk(StoryBackend& backend, const StoryActionCall&, RunState&){ using namespace std::chrono_literals; - backend.press(NintendoSwitch::BUTTON_A, 80ms, 120ms); + backend.press(NintendoSwitch::BUTTON_A, TEXT_PRESS_HOLD, TEXT_PRESS_RELEASE); for (size_t c = 0; c < MAX_OPEN_LOOKS; c++){ if (backend.observe().events.has(ScreenEvent::DIALOG_BOX)){ return mash_to_overworld(backend); @@ -114,7 +118,7 @@ Outcome face(StoryBackend& backend, const StoryActionCall& call, RunSt template Outcome answer(StoryBackend& backend, const StoryActionCall& call, RunState&){ using namespace std::chrono_literals; - backend.press(story_arg(call.args, "yes") ? NintendoSwitch::BUTTON_A : NintendoSwitch::BUTTON_B, 80ms, 120ms); + backend.press(story_arg(call.args, "yes") ? NintendoSwitch::BUTTON_A : NintendoSwitch::BUTTON_B, TEXT_PRESS_HOLD, TEXT_PRESS_RELEASE); return outcome_ok(); } From aabb3499c74c6c7010859f6f3ca1101da7215fa3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 14:43:54 -0800 Subject: [PATCH 09/34] AutoStory engine: no retry after a SAVE step saved part-way A reload after that save would land mid-checkpoint while the retry runs from step 1. The engine now records the save and ends the checkpoint's attempts there. --- .../AutoStory/Engine/Pokemon_StoryEngine.cpp | 21 +++++++--- .../AutoStory/Engine/Pokemon_StoryEngine.h | 11 +++-- .../Engine/Pokemon_StoryEnginePolicy.h | 3 ++ .../Engine/Pokemon_StoryEngineRuns_Tests.cpp | 41 ++++++++++++++++--- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp index a0db19df53..ccfd146863 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.cpp @@ -68,12 +68,12 @@ class RunnerExecutor : public StoryStepExecutor{ // `game` with its SAVE step "save" saving `current` only while `mode` is // PER_CHECKPOINT: a checkpoint under test or verification must not save -// part-way. +// part-way. Sets `saved` when it saves. template StoryGame with_gated_save_step( - StoryGame game, const StorySaveMode& mode, const StoryCheckpoint* const& current + StoryGame game, const StorySaveMode& mode, const StoryCheckpoint* const& current, bool& saved ){ - StoryActionHandler gated = [&mode, ¤t, save = game.save]( + StoryActionHandler gated = [&mode, ¤t, &saved, save = game.save]( StoryBackend& backend, const StoryActionCall&, RunState& ){ if (mode != StorySaveMode::PER_CHECKPOINT){ @@ -83,7 +83,9 @@ StoryGame with_gated_save_step( if (!save || current == nullptr){ return outcome_failed("unsupported_step", "save needs StoryGame::save"); } - return save(backend, *current); + Outcome outcome = save(backend, *current); + saved = saved || outcome.succeeded(); + return outcome; }; game.actions.push_back({.spec = {.kind = StoryStepKind::SAVE, .name = "save", .args = {}}, .handler = std::move(gated)}); return game; @@ -181,7 +183,7 @@ ObservedState observed_state(const Observation& observation){ template StoryEngine::StoryEngine(const StoryGame& game, StoryBackend& backend) - : m_game(with_gated_save_step(game, m_save_mode, m_checkpoint)) + : m_game(with_gated_save_step(game, m_save_mode, m_checkpoint, m_saved_part_way)) , m_backend(backend) , m_registry(m_game) , m_runner(m_registry, backend) @@ -222,7 +224,9 @@ StoryEngineReport StoryEngine::run_once( m_backend.log(report.save.reason); m_save_mode = report.save.mode; m_checkpoint = &checkpoint; + m_saved_part_way = false; report.run = run_steps(checkpoint, state); + report.saved_part_way = m_saved_part_way; m_save_mode = StorySaveMode::NONE; m_checkpoint = nullptr; if (!report.run.completed){ @@ -266,6 +270,13 @@ StoryEngineReport StoryEngine::run_with_retries( if (report.verdict == CheckpointVerdict::PASSED){ return AttemptResult::PASSED; } + if (report.saved_part_way){ + m_backend.log(std::format( + "[Checkpoint] {}: a save step saved part-way, so a reload would not return to its start: no retry", + checkpoint.id + )); + return AttemptResult::FINAL; + } return repeats_on_reload(report.run.failure) ? AttemptResult::FINAL : AttemptResult::FAILED; }, .reset = [&](size_t next_attempt){ diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h index e7cabbcf9a..185ab5dc52 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h @@ -70,9 +70,10 @@ class StoryEngine{ // `attempts_per_checkpoint` runs, only when a reload returns to the // save it started from: the first checkpoint's, or one the checkpoint // before it saved at its end. In none and after_verification modes - // (#329) that leaves only the first. No reload either for a failure - // every attempt would repeat: a lint, a console_only action, the game - // not running. Logs "[Segment] : ..." lines. + // that leaves only the first. No reload once a SAVE step has saved + // part-way through the attempt (the reload would land there), nor for + // a failure every attempt would repeat: a lint, a console_only action, + // the game not running. Logs "[Segment] : ..." lines. SegmentReport run_segment( std::string_view id, std::span checkpoints, size_t attempts_per_checkpoint, RunState& state @@ -109,9 +110,11 @@ class StoryEngine{ const StoryCheckpoint& checkpoint, SavePoint point, size_t attempts, RunState& state, CheckpointRun& run ); - // Declared first: m_game's save step reads them. + // Declared first: m_game's save step reads them, and sets + // m_saved_part_way when it saves. StorySaveMode m_save_mode = StorySaveMode::NONE; const StoryCheckpoint* m_checkpoint = nullptr; + bool m_saved_part_way = false; StoryGame m_game; StoryBackend& m_backend; StoryActionRegistry m_registry; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy.h b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy.h index 0856147d0b..197fce0023 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy.h @@ -52,6 +52,9 @@ struct StoryEngineReport{ // Checked after steps that completed. std::optional postconditions = std::nullopt; bool saved = false; + // A SAVE step among its steps saved: a reload now returns there, not + // to the save the checkpoint started from. + bool saved_part_way = false; }; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp index 851f380bcc..ecfc8a691b 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp @@ -7,7 +7,7 @@ * the heading reading, the choice and interact events, a screen machine * over observations, the step in an action's call, the checkpoint in the * save, the segment and verify loops, console-only actions, declared poses - * read as the game's pose type, and tile actions only for tile games. + * of the game's kind only, and tile actions only for tile games. * Then what PLZA found on the engine: readers opt in to the postcondition * check, inputs logged by button name, waiting states may stay still, and * the stick's release. @@ -517,15 +517,21 @@ std::string handler_sees_step(CancellableScope& scope){ return *seen == "opening / the long intro" ? "" : std::format("expected the step, got \"{}\"", *seen); } +StoryStep save_step(std::string name){ + StoryStep step; + step.kind = StoryStepKind::SAVE; + step.name = std::move(name); + return step; +} + // Gap 6: the save is told its checkpoint, at the end and at a SAVE step. std::string save_gets_checkpoint(CancellableScope& scope){ StoryGame game = flaky_game(0); FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); StoryEngine engine(game, backend); - StoryStep save; - save.kind = StoryStepKind::SAVE; - save.name = "save_here"; - const StoryCheckpoint checkpoint = in_phase(checkpoint_of("02.01", {game_step("walk", "fine"), save}), StoryPhase::REPRODUCTION, engine); + const StoryCheckpoint checkpoint = in_phase( + checkpoint_of("02.01", {game_step("walk", "fine"), save_step("save_here")}), StoryPhase::REPRODUCTION, engine + ); RunState state; const StoryEngineReport report = engine.run_checkpoint(checkpoint, SavePoint::CHECKPOINT_END, state); if (!report.saved){ @@ -535,6 +541,30 @@ std::string save_gets_checkpoint(CancellableScope& scope){ return saves == 2 ? "" : std::format("expected 2 saves of 02.01, got {}: {}", saves, joined(backend.lines())); } +// A SAVE step part-way through a checkpoint moves the save: a reload +// after a later failure would not return to the checkpoint's start, so +// the segment stops there instead of retrying from step 1. +std::string no_retry_after_a_save_step(CancellableScope& scope){ + StoryGame game = flaky_game(1); + FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); + StoryEngine engine(game, backend); + const std::vector checkpoints{in_phase( + checkpoint_of("02.01", {game_step("walk", "fine"), save_step("save_here"), game_step("talk", "flaky")}), + StoryPhase::REPRODUCTION, engine + )}; + RunState state; + const SegmentReport report = engine.run_segment("seg", checkpoints, 3, state); + if (report.completed || report.failed_event != "talk" || report.failure.failure != "flaky_failed"){ + return std::format("expected the segment to stop at talk, got {}: {}", to_string(report.failure), joined(backend.lines())); + } + if (count_lines(backend, "[Test] reload") != 0){ + return std::format("expected no reload: {}", joined(backend.lines())); + } + return has_line(backend, "[Checkpoint] 02.01: a save step saved part-way, so a reload would not return to its start: no retry") + ? "" + : std::format("expected the no-retry line: {}", joined(backend.lines())); +} + // Gap 8: a console_only action is refused, before any input, on a backend // that is no console; it runs on one. StoryGame console_game(){ @@ -913,6 +943,7 @@ const RunsCase RUNS_CASES[] = { {.name = "observation machine fails", .input = {.check = &observation_machine_fails}, .expectation = {}}, {.name = "handler sees its step", .input = {.check = &handler_sees_step}, .expectation = {}}, {.name = "save gets its checkpoint", .input = {.check = &save_gets_checkpoint}, .expectation = {}}, + {.name = "no retry after a save step", .input = {.check = &no_retry_after_a_save_step}, .expectation = {}}, {.name = "console_only refused off console", .input = {.check = &console_only_refused}, .expectation = {}}, {.name = "no reload for console_only", .input = {.check = &segment_no_reload_for_console_only}, .expectation = {}}, {.name = "verify saves after all passed", .input = {.check = &verify_saves_after_all_passed}, .expectation = {}}, From 77ece85c57402f0a4c1c0ae649c84868cc02ee2a Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 14:43:54 -0800 Subject: [PATCH 10/34] AutoStory: SAVE steps in testing, once_per_save in JSON, save option text A test pins that the engine's SAVE step saves nothing in a testing run; StoryStepExecutor::run says a game off the engine must gate it itself. The step reader accepts once_per_save. The Save and Verify Mode texts say when After verification saves. --- .../Pokemon/AutoStory/Data/Pokemon_StoryStepJson.cpp | 7 ++++++- .../AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp | 6 ++++++ .../AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp | 2 ++ .../Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.h | 7 +++++-- .../Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h | 4 ++-- .../Pokemon/AutoStory/Types/Pokemon_StoryStepKind.h | 2 +- .../Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp | 8 +++++--- .../Source/Pokemon/Options/Pokemon_StoryRunOptions.h | 7 ++++--- 8 files changed, 31 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson.cpp index 3d39269e07..095cbd5014 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson.cpp @@ -324,7 +324,9 @@ DeclaredPose read_declared_pose(const JsonValue& value, std::string_view source) } StoryStep read_story_step(const JsonValue& value, std::string_view source, std::span actions){ - const JsonObject& root = fields(value, {"id", "kind", "why", "action", "args", "skip_if", "declared_after"}, source); + const JsonObject& root = fields( + value, {"id", "kind", "why", "action", "args", "skip_if", "declared_after", "once_per_save"}, source + ); StoryStep result; result.name = root.get_string_throw("id"); if (result.name.empty()){ @@ -344,6 +346,9 @@ StoryStep read_story_step(const JsonValue& value, std::string_view source, std:: if (const JsonValue* field = root.get_value("declared_after")){ result.pose_after = read_declared_pose(*field, source); } + if (const JsonValue* field = root.get_value("once_per_save")){ + result.once_per_save = field->to_boolean_throw(std::string(source)); + } return result; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp index 69f213ad13..5af96acd8f 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp @@ -79,6 +79,12 @@ const WireCase CASES[] = { return expect(step.kind == StoryStepKind::GAME && step.why == "source reason" && step.action == "profile" && step.skip_if == std::vector{"flag"} && step.pose_after == after, "every shared field read"); }}}, + {.input = {.name = "once per save", .json = R"({"id":"heal","kind":"game_action","action":"profile","once_per_save":true})"}, .expectation = {.check = [](const ReadRecord& record){ + return expect(step_of(record).once_per_save, "a once_per_save step"); + }}}, + {.input = {.name = "every time by default", .json = R"({"id":"heal","kind":"game_action","action":"profile"})"}, .expectation = {.check = [](const ReadRecord& record){ + return expect(!step_of(record).once_per_save, "a step run every time"); + }}}, {.input = {.name = "route fills its fallback", .json = R"({"id":"r","kind":"route","args":{"target":{"map":"A","tiles":[[1,2]]}}})"}, .expectation = {.check = [](const ReadRecord& record){ const StoryActionArgs expected = {{"fight_wild", false}, {"target", GridPose{.map = "A", .tiles = {{1, 2}}, .facing = std::nullopt}}}; return expect(step_of(record).args == expected, "the target and fight_wild false"); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp index e65b730dbf..c1f7b74094 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEnginePolicy_Tests.cpp @@ -131,6 +131,8 @@ const EngineCase ENGINE_CASES[] = { {.name = "failed run never saves", .input = {.phase = "reproduction", .end_map = ""}, .expectation = {.mode = StorySaveMode::PER_CHECKPOINT, .verdict = CheckpointVerdict::FAILED, .saves = 0, .line = "[Save] 00.31: run failed: not saved"}}, + {.name = "save step skipped while testing", .input = {.phase = "testing", .steps = SAVE_STEPS}, + .expectation = {.mode = StorySaveMode::NONE, .saves = 0, .line = "[Save] save step skipped: save mode none"}}, {.name = "save step skipped while verifying", .input = {.phase = "verification", .steps = SAVE_STEPS}, .expectation = {.mode = StorySaveMode::AFTER_VERIFICATION, .saves = 1, .line = "[Save] save step skipped: save mode after_verification"}}, {.name = "save step saves in reproduction", .input = {.phase = "reproduction", .steps = SAVE_STEPS}, diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.h index 1e00c6840d..dfc22dd35b 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.h @@ -51,7 +51,7 @@ namespace Pokemon{ // How a game does its story steps: an interface with no data. run() is the // game's: it does the step's kind its own way (FRLG and BDSP bind kinds and -// variants to actions in a table), and returns unsupported_step() for a +// action names to handlers in a table), and returns unsupported_step() for a // kind it has no way of doing. class StoryStepExecutor{ public: @@ -62,7 +62,10 @@ class StoryStepExecutor{ // who can see us again, the row's own settings). Does nothing by default. virtual void begin_attempt(const StoryCheckpoint& data); - // Does `step`, from the run so far. + // Does `step`, from the run so far. A SAVE step must save only when + // the run's save mode allows a save part-way (PER_CHECKPOINT): nothing + // here knows the mode. The story engine's own SAVE action does this + // for a game on the engine. virtual Outcome run(const StoryStep& step, RunState& state) = 0; // Whether the condition named in a step's skip_if holds: by default, diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h index 04ad331908..c06b0f52c5 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StorySaveMode.h @@ -3,8 +3,8 @@ * From: https://github.com/PokemonAutomation/ * * When an AutoStory run may save the game. A run's own verdict can be - * wrong (FRLG 00.31, 2026-11-10: a warp leg confirmed B3F while still on - * B4F), and a save made then overwrites the only good one. So a segment + * wrong (a warp confirmed on the next floor while the player is still on + * the one before), and a save made then overwrites the only good one. So a segment * under test never saves, a verified one saves once at its end, and only * a playthrough of verified segments saves at each checkpoint. * diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.h index 2e43aa8118..a3670b8c6c 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryStepKind.h @@ -32,7 +32,7 @@ enum class StoryStepKind{ SHOP, // `items` from a shop SAVE, // save the game where the player stands READY, // before a big battle: items, and the nurse at `target` if they can't - GAME, // a step only this game has, named by `variant` + GAME, // a step only this game has, named by `action` }; // Returns the readable string representation of a story step kind. diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp index c1217c26fd..5f401eebc5 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.cpp @@ -51,7 +51,8 @@ std::string story_checkpoint_label(const StoryCheckpoint& checkpoint){ StoryVerifyOptions::StoryVerifyOptions() : GroupOption( - "Verify Mode: run the start checkpoint (also the end) from its save several times, never saving at its end", + "Verify Mode: run the start checkpoint (also the end) from its save several times. " + "Only with Save set to After verification does the last run save at its end, when every run passed", LockMode::LOCK_WHILE_RUNNING, EnableMode::DEFAULT_DISABLED ) @@ -108,8 +109,9 @@ StoryRunOptions::StoryRunOptions(const StringSelectDatabase& checkpoints, const ) , SAVE_MODE( "Save:
When the run saves the game. A failed run never saves. " - "None keeps the save the run started from; After verification saves once at the end, after the checkpoint " - "passed 2-3 times; Each checkpoint is for a playthrough of verified checkpoints.", + "None keeps the save the run started from. After verification saves once, at the end of a run that passed " + "(in Verify Mode, at the end of the last run, when every run passed). Each checkpoint saves after each " + "checkpoint that passed, for a playthrough of verified checkpoints.", StorySaveMode_Database(), LockMode::LOCK_WHILE_RUNNING, StorySaveMode::NONE diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h index 178985d2f0..fb8a1b704c 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_StoryRunOptions.h @@ -44,9 +44,10 @@ std::string story_checkpoint_label(const StoryCheckpoint& checkpoint); // Verify mode, off by default (verify_checkpoint()): the start checkpoint -// RUNS times from its save, never saving at its end; verified when at -// least PASSES pass. For a battle that has lost twice or more, given its -// own checkpoint saved right before it. +// RUNS times from its save; verified when at least PASSES pass. Only the +// last run may save, at its end, when SAVE_MODE is After verification +// and every run passed. For a battle that has lost twice or more, given +// its own checkpoint saved right before it. class StoryVerifyOptions : public GroupOption{ public: StoryVerifyOptions(); From 8cd38a88d719fa403b2db0227b9beb7d33d5e382 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 14:43:54 -0800 Subject: [PATCH 11/34] AutoStory engine: drop the unused StoryPoseTraits::from_declared() Declared poses reach the run as the event layer's pose; a zone's spot and heading are not carried until a game has a position reader. --- .../Pokemon/AutoStory/Engine/MIGRATION.md | 6 +++--- .../Engine/Pokemon_StoryPoseConcept.h | 19 ++++++++----------- .../AutoStory/Engine/Pokemon_ZonePose.h | 3 --- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/MIGRATION.md b/SerialPrograms/Source/Pokemon/AutoStory/Engine/MIGRATION.md index c2c674c1bb..eef09ecdc4 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/MIGRATION.md +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/MIGRATION.md @@ -69,13 +69,13 @@ Each move deletes that game's executor; the last one deletes `StoryStepExecutor` readers. - **PLZA** (ZonePose, in the engine with its instantiations and `observed_state()`): a declared pose (`"start"`, a step's `"declared_after"`) is a place, `{"place": "HotelZ"}` with an - optional `"spot"` and `"heading"` (`ZoneDeclared`, read by - `StoryPoseTraits::from_declared()`). Walks are `TIMED_LEGS` args; tile args fail + optional `"spot"` and `"heading"` (`ZoneDeclared`). The run keeps only the place, as a map + with no tiles; spot and heading wait for a position reader. Walks are `TIMED_LEGS` args; tile args fail the lint. Turns are `stick()` after the camera recenter; the minimap arrow is the `"heading"` reading. A new pose type: a struct with `pose_matches` / `pose_text`, a `StoryPoseTraits` specialization -(`TILE_MOVES`, `Declared`, `from_declared()`), and an explicit instantiation line in each engine +(`TILE_MOVES`, `Declared`), and an explicit instantiation line in each engine `.cpp`. ## Moves in shared code when the last executor goes diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryPoseConcept.h b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryPoseConcept.h index 653e881f2d..6969ff5290 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryPoseConcept.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryPoseConcept.h @@ -6,7 +6,7 @@ * off the game is a target, a line of text for the log, and its traits * (StoryPoseTraits): whether the player moves tile by tile, and which kind * of declared pose (Types/Pokemon_DeclaredPose.h) a checkpoint declares - * for it (its start, a step's end) and how that reads as this type. The + * for it (its start, a step's end). The * tile games (FRLG, BDSP) use GridPose; a game that moves freely brings * its own type (PLZA: ZonePose, a zone until it has a position reader). * @@ -37,8 +37,11 @@ namespace Pokemon{ // The kind of pose a checkpoint of this game declares in its JSON // ("start", a step's "declared_after"). The lint fails a // checkpoint that declares the other kind (check_declared()). -// static PoseType from_declared(const Declared& declared); -// That declared pose as this type. +// +// A declared pose reaches the run as the event layer's pose +// (grid_pose_of() in Pokemon_StoryStepExecutor.h): a zone's place reads +// as a map with no tiles, and its spot and heading are not carried. They +// wait for a game with a position reader to compare them against. template struct StoryPoseTraits; @@ -47,22 +50,16 @@ template <> struct StoryPoseTraits{ static constexpr bool TILE_MOVES = true; using Declared = TileDeclared; - static GridPose from_declared(const TileDeclared& declared){ - return GridPose{.map = declared.map, .tiles = declared.tiles, .facing = declared.facing}; - } }; // A pose the engine can carry: pose_matches(actual, target) and // pose_text(pose), found by argument-dependent lookup, and its traits. template -concept StoryPose = std::copyable && requires( - const PoseType& actual, const PoseType& target, - const typename StoryPoseTraits::Declared& declared -){ +concept StoryPose = std::copyable && requires(const PoseType& actual, const PoseType& target){ { pose_matches(actual, target) } -> std::convertible_to; { pose_text(actual) } -> std::convertible_to; { StoryPoseTraits::TILE_MOVES } -> std::convertible_to; - { StoryPoseTraits::from_declared(declared) } -> std::same_as; + typename StoryPoseTraits::Declared; }; // Whether `declared` is the kind of pose a game of `PoseType` declares. diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_ZonePose.h b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_ZonePose.h index 2931604251..13993e1ef5 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_ZonePose.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_ZonePose.h @@ -42,9 +42,6 @@ template <> struct StoryPoseTraits{ static constexpr bool TILE_MOVES = false; using Declared = ZoneDeclared; - static ZonePose from_declared(const ZoneDeclared& declared){ - return ZonePose{.zone = declared.place}; - } }; From 0825ffb67703a5310948fc648b60fbc072927be0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 14:43:54 -0800 Subject: [PATCH 12/34] AutoStory: tell INTEGER_ROWS from TIMED_LEGS; assert one arg type per value INTEGER_ROWS stays: FRLG's foe_threats and BDSP's avoid args use it. --- .../Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h index 8e47cbbbed..f1a9fb5d50 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionArg.h @@ -75,9 +75,10 @@ using StoryArgValue = std::variant< std::vector, // LEGS std::vector, // WORDS std::vector, // ITEMS - std::vector>, // INTEGER_ROWS: [[0, 4500], [90, 0]] - std::vector // TIMED_LEGS: [[0, 4500], [90, 1200]] + std::vector>, // INTEGER_ROWS: rows of any length, [[12, 7], [3, 9, 1], []] + std::vector // TIMED_LEGS: [turn degrees, ms] pairs, [[0, 4500], [90, 1200]] >; +static_assert(std::variant_size_v == (size_t)StoryArgType::TIMED_LEGS + 1, "one StoryArgType per StoryArgValue type"); // A step's arguments by key. using StoryActionArgs = std::map>; From c4a58f79c43372c96f01ab1e5bef28052e6f3b65 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 14:43:54 -0800 Subject: [PATCH 13/34] AutoStory story files: check reload_when_chained in a user's run too A user's run skips dev-only rows, so the row a reload follows there must autosave as well. --- .../AutoStory/Data/Pokemon_StoryFiles.cpp | 28 +++++++++++++---- .../AutoStory/Data/Pokemon_StoryFiles.h | 30 ++++++++++++++----- .../Data/Pokemon_StoryFiles_Tests.cpp | 18 +++++++++++ 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp index cb1824b759..b7b108c311 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp @@ -61,19 +61,35 @@ void check_in_story_order( } } +namespace{ + +// Throws ParseException naming `source` unless `previous` ends on the +// game's autosave in `rows`; `run` says in whose run ("" or " in a +// user's run"). +void check_reload_after( + std::optional previous, const StoryRows& rows, std::string_view run, std::string_view source +){ + if (!previous || !rows.autosaves.contains(*previous)){ + throw ParseException(std::format( + "{}: reload_when_chained after a checkpoint that does not end on the game's autosave{}: the reload would load an older save", + source, run + )); + } +} + +} // namespace + void add_story_row( std::string_view id, const StoryRowExecution& execution, RowSave start, - std::optional previous_id, std::string_view source, StoryRows& rows + const PreviousRows& previous, std::string_view source, StoryRows& rows ){ if (execution.reload != StoryReload::NEVER){ if (start == RowSave::WITHOUT_SAVE){ throw ParseException(std::format("{}: reload_when_chained on a checkpoint with no save to reload", source)); } - if (!previous_id || !rows.autosaves.contains(*previous_id)){ - throw ParseException(std::format( - "{}: reload_when_chained after a checkpoint that does not end on the game's autosave: the reload would load an older save", - source - )); + check_reload_after(previous.in_dev_run, rows, "", source); + if (!execution.dev_only && previous.in_user_run != previous.in_dev_run){ + check_reload_after(previous.in_user_run, rows, " in a user's run", source); } rows.reload_when_chained.emplace(id); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.h b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.h index 7b423becd6..f6d2b1da3a 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.h @@ -121,13 +121,21 @@ enum class RowSave{ WITHOUT_SAVE, // a new game }; +// The rows a row follows in play: in a developer's run, and in a user's, +// which skips the dev-only rows. None for the first row. +struct PreviousRows{ + std::optional in_dev_run; + std::optional in_user_run; +}; + // Adds row `id` to the sets of `rows`. Throws ParseException naming -// `source` when it reloads and starts WITHOUT_SAVE or the row before it, -// `previous_id`, does not end on the game's autosave: a reload loads the -// last save, which must be that autosave. +// `source` when it reloads and starts WITHOUT_SAVE or a row it follows +// (`previous`: in a developer's run; and in a user's, unless it is +// dev-only itself) does not end on the game's autosave: a reload loads +// the last save, which must be that autosave. void add_story_row( std::string_view id, const StoryRowExecution& execution, RowSave start, - std::optional previous_id, std::string_view source, StoryRows& rows + const PreviousRows& previous, std::string_view source, StoryRows& rows ); // The dev file `dev`'s row, in place of the built-in file `builtin_name`: @@ -182,15 +190,23 @@ StoryData load_story_data( return reader.plays_before(a.row.checkpoint, b.row.checkpoint); }); } - // A reload loads the save the row before it in play ends on. + // A reload loads the save the row before it in play ends on, in a + // developer's run and in a user's. + std::optional last_user_row; for (auto& [row, source] : rows){ const bool new_game = reader.starts_without_save && reader.starts_without_save(row.checkpoint); + const detail::PreviousRows previous{ + .in_dev_run = data.checkpoints.empty() ? std::nullopt : std::optional(data.checkpoints.back().id), + .in_user_run = last_user_row ? std::optional(data.checkpoints[*last_user_row].id) : std::nullopt, + }; detail::add_story_row( row.checkpoint.id, row.execution, new_game ? detail::RowSave::WITHOUT_SAVE : detail::RowSave::FROM_SAVE, - data.checkpoints.empty() ? std::nullopt : std::optional(data.checkpoints.back().id), - source, data + previous, source, data ); + if (!row.execution.dev_only){ + last_user_row = data.checkpoints.size(); + } data.checkpoints.push_back(std::move(row.checkpoint)); } return data; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp index 5ba2235da8..8b1d06bb5a 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp @@ -184,6 +184,24 @@ const LoadCase LOAD_CASES[] = { .input = {.builtin = {{"test-01.00.plan", file_text("01.00", R"({"save": "menu"})")}, ROW_1}}, .expectation = {.error = "test-01.01.plan: reload_when_chained after a checkpoint that does not end on the game's autosave"}, }, + { + .name = "reload_when_chained after a dev-only autosave row, the user's row before it not autosaving, fails", + .input = {.builtin = { + {"test-01.00.plan", file_text("01.00", R"({"save": "menu"})")}, + {"test-01.005.plan", file_text("01.005", R"({"dev_only": true, "save": "autosave"})")}, + ROW_1, + }}, + .expectation = {.error = "test-01.01.plan: reload_when_chained after a checkpoint that does not end on the game's autosave in a user's run"}, + }, + { + .name = "reload_when_chained after a dev-only row, both rows before it autosaving", + .input = {.builtin = { + ROW_0, + {"test-01.005.plan", file_text("01.005", R"({"dev_only": true, "save": "autosave"})")}, + ROW_1, + }}, + .expectation = {.summary = "rows 01.00 01.005 01.01 | titles Row Row Row | autosave 01.00 01.005 | chained 01.01 | always | dev_only 01.005 | dev "}, + }, { .name = "reload_when_chained on the first row fails", .input = {.builtin = {ROW_1}}, From 644442dbbe676e2a4536d7c06daebdf0a077c4c5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 14:43:54 -0800 Subject: [PATCH 14/34] AutoStory failure classes: function-local table, checked lookup story_failure_class_info() throws for a class with no row in its place, and a test checks every class has one. --- .../AutoStory/Pokemon_StoryFailureClasses.cpp | 397 ++++++++++-------- .../AutoStory/Pokemon_StoryFailureClasses.h | 4 +- .../Pokemon_StoryFailureClasses_Tests.cpp | 15 + 3 files changed, 239 insertions(+), 177 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.cpp index ec7b5f582d..02e34cea33 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include "Common/Cpp/Exceptions.h" #include "Pokemon_StoryFailureClasses.h" namespace PokemonAutomation{ @@ -20,186 +22,222 @@ constexpr std::string_view TAG_PREFIX = "class="; using C = StoryFailureClass; using R = StoryFailureClassInfo::Retry; -const std::vector CLASSES{ - // The run and the console. - { - C::GAME_NOT_RUNNING, "game_not_running", - "the Switch HOME menu shows instead of the game", - "the HOME menu read at a step's start or after a failure", - {}, {"game_not_running"}, R::STOP, - }, - { - C::LAUNCH_FAILED, "launch_failed", - "getting from HOME to the game's overworld failed", - "the launch driver: no game tile, a screen that ignores its press, no overworld in time", - {}, {"launch_failed"}, R::STOP, - }, - { - C::WRONG_START, "wrong_start", - "the game is not at the checkpoint's start: another save, an older one, another place", - "the checkpoint's start checks and the preflight", - {}, {"start_failed", "wrong_save", "precondition_failed"}, R::STOP, - }, - { - C::RELOAD_FAILED, "reload_failed", - "reloading the checkpoint's save failed", - "the game's reload hook", - {}, {"reload_failed"}, R::STOP, - }, - { - C::SAVE_FAILED, "save_failed", - "saving at the checkpoint's end failed", - "the game's save hook", - {}, {"save_failed"}, R::RELOAD, - }, - { - C::STORY_ERROR, "story_error", - "the story's data or code is wrong: a step, range or action the program cannot run", - "the engine's lint and lookups, before or as a step starts", - {}, +// The run and the console. +std::vector run_rows(){ + return { { - "unsupported_step", "unknown_checkpoint", "bad_range", "empty_segment", - "bad_verify_policy", "lint_failed", "no_save_hook", "console_only", + C::GAME_NOT_RUNNING, "game_not_running", + "the Switch HOME menu shows instead of the game", + "the HOME menu read at a step's start or after a failure", + {}, {"game_not_running"}, R::STOP, }, - R::STOP, - }, + { + C::LAUNCH_FAILED, "launch_failed", + "getting from HOME to the game's overworld failed", + "the launch driver: no game tile, a screen that ignores its press, no overworld in time", + {}, {"launch_failed"}, R::STOP, + }, + { + C::WRONG_START, "wrong_start", + "the game is not at the checkpoint's start: another save, an older one, another place", + "the checkpoint's start checks and the preflight", + {}, {"start_failed", "wrong_save", "precondition_failed"}, R::STOP, + }, + { + C::RELOAD_FAILED, "reload_failed", + "reloading the checkpoint's save failed", + "the game's reload hook", + {}, {"reload_failed"}, R::STOP, + }, + { + C::SAVE_FAILED, "save_failed", + "saving at the checkpoint's end failed", + "the game's save hook", + {}, {"save_failed"}, R::RELOAD, + }, + { + C::STORY_ERROR, "story_error", + "the story's data or code is wrong: a step, range or action the program cannot run", + "the engine's lint and lookups, before or as a step starts", + {}, + { + "unsupported_step", "unknown_checkpoint", "bad_range", "empty_segment", + "bad_verify_policy", "lint_failed", "no_save_hook", "console_only", + }, + R::STOP, + }, + + }; +} - // Walking. - { - C::LOST_TAP, "lost_tap", - "a tap the game drops", - "the walker reads the player where the tap started", - {FaultClass::LOST_TAP}, {}, R::RETRY_STEP, - }, - { - C::UNSEEN_STEP, "unseen_step", - "a step tap that moved the player, read as not moved", - "the walker finds the player a tile past where it read", - {FaultClass::UNSEEN_STEP}, {}, R::RETRY_STEP, - }, - { - C::WALK_SHORT, "walk_short", - "a walk or hold ended short of its tile", - "the walker's position check at a wall or landmark", - {}, {}, R::RETRY_STEP, - }, - { - C::BLOCKED, "blocked", - "something on the way stops the walk: a person, a wall the map does not have", - "the walker's progress check: no tile gained", - {}, {}, R::RETRY_STEP, - }, - { - C::MOUNT_LOST, "mount_lost", - "off the Bicycle (or another mount) at a leg that rides", - "the walker's tiles per tap", - {FaultClass::MOUNT_LOST}, {}, R::RETRY_STEP, - }, - { - C::POSE_LOST, "pose_lost", - "where the player is or faces is unknown or not what the map says", - "the localizer: no pose, another map, another facing", - {}, {}, R::RELOAD, - }, +// Walking. +std::vector walk_rows(){ + return { + { + C::LOST_TAP, "lost_tap", + "a tap the game drops", + "the walker reads the player where the tap started", + {FaultClass::LOST_TAP}, {}, R::RETRY_STEP, + }, + { + C::UNSEEN_STEP, "unseen_step", + "a step tap that moved the player, read as not moved", + "the walker finds the player a tile past where it read", + {FaultClass::UNSEEN_STEP}, {}, R::RETRY_STEP, + }, + { + C::WALK_SHORT, "walk_short", + "a walk or hold ended short of its tile", + "the walker's position check at a wall or landmark", + {}, {}, R::RETRY_STEP, + }, + { + C::BLOCKED, "blocked", + "something on the way stops the walk: a person, a wall the map does not have", + "the walker's progress check: no tile gained", + {}, {}, R::RETRY_STEP, + }, + { + C::MOUNT_LOST, "mount_lost", + "off the Bicycle (or another mount) at a leg that rides", + "the walker's tiles per tap", + {FaultClass::MOUNT_LOST}, {}, R::RETRY_STEP, + }, + { + C::POSE_LOST, "pose_lost", + "where the player is or faces is unknown or not what the map says", + "the localizer: no pose, another map, another facing", + {}, {}, R::RELOAD, + }, - // Warps and fades. - { - C::WARP_NO_OP, "warp_no_op", - "a step onto a warp shows the fade's black but does not warp", - "the map or tile after the fade is the one before it", - {FaultClass::WARP_NO_OP}, {}, R::RETRY_STEP, - }, - { - C::LATE_FADE, "late_fade", - "a warp's fade shows late or is missed", - "the fade watcher: the warp unconfirmed, the player on a map the walk did not plan", - {FaultClass::LATE_FADE}, {}, R::RETRY_STEP, - }, - { - C::SLOW_FADE_IN, "slow_fade_in", - "a warp's fade-in runs long: a move right after it goes nowhere", - "the first move after a fade does not move the player", - {FaultClass::SLOW_FADE_IN}, {}, R::RETRY_STEP, - }, - { - C::DARK_MAP, "dark_map", - "a dark map (a cave without Flash) the readers cannot see", - "the floor reads dim; the walker's and the scene's reads fail there", - {FaultClass::DARK_CAVE}, {}, R::STOP, - }, + }; +} - // Scenes, talks and battles. - { - C::SCENE_END_POSE, "scene_end_pose", - "a step whose end the game sets leaves the player on a tile next to the expected one", - "the next walk starts or ends a tile off", - {FaultClass::SCENE_END_POSE}, {}, R::RETRY_STEP, - }, - { - C::SCENE_EARLY, "scene_early", - "a scene starts on the last tiles of the walk before it", - "the walk is interrupted by the scene's dialogue", - {FaultClass::SCENE_EARLY}, {}, R::RETRY_STEP, - }, - { - C::BATTLE_OPENING, "battle_opening", - "a battle's opening is still playing when a step starts", - "the step's first read is not the overworld or battle menu it expects", - {FaultClass::BATTLE_OPENING}, {}, R::RETRY_STEP, - }, - { - C::WILD_BATTLES, "wild_battles", - "more wild battles than a clean run meets", - "the interrupt handler clears each; too many in a step fail it", - {FaultClass::WILD_BATTLES}, {"too_many_interrupts"}, R::RETRY_STEP, - }, - { - C::INTERRUPT_FAILED, "interrupt_failed", - "something interrupted a step and was not cleared", - "the interrupt handler: no handler, a failed clear, the screen not settled", - {}, {"unhandled_interrupt", "interrupt_failed", "interrupt_unsettled", "interrupted"}, R::RELOAD, - }, - { - C::SCREEN_UNREAD, "screen_unread", - "a screen the step waits for (dialogue, banner, overworld, prompt) is not seen", - "the step's detector times out", - {}, {"talk_no_text", "mash_no_overworld"}, R::RELOAD, - }, - { - C::MENU_FAILED, "menu_failed", - "a menu action (mart, PC, item, TM, Fly) did not do what it was to", - "the menu's readers: the item, count or choice not as planned", - {}, {}, R::RELOAD, - }, - { - C::BATTLE_LOST, "battle_lost", - "a battle lost or not won: a blackout", - "the battle's end screen or the blackout's heal spot", - {}, {}, R::RELOAD, - }, - { - C::STATE_CHECK_FAILED, "state_check_failed", - "a check of the game's state failed: an event's expects, the checkpoint's end", - "the event's expects and requires, the checkpoint's end and postconditions", - {}, {"expect_failed", "require_failed", "end_failed", "postconditions_failed"}, R::RELOAD, - }, - { - C::OPERATION_FAILED, "operation_failed", - "a game's action threw, with no class of its own", - "an OperationFailedException out of a step", - {}, {"operation_failed"}, R::RELOAD, - }, - { - C::SIM_MISMATCH, "sim_mismatch", - "a simulated run left the story: the sim and the table disagree", - "the story sim's end checks (sim runs only)", - {}, {}, R::STOP, - }, -}; +// Warps and fades. +std::vector warp_rows(){ + return { + { + C::WARP_NO_OP, "warp_no_op", + "a step onto a warp shows the fade's black but does not warp", + "the map or tile after the fade is the one before it", + {FaultClass::WARP_NO_OP}, {}, R::RETRY_STEP, + }, + { + C::LATE_FADE, "late_fade", + "a warp's fade shows late or is missed", + "the fade watcher: the warp unconfirmed, the player on a map the walk did not plan", + {FaultClass::LATE_FADE}, {}, R::RETRY_STEP, + }, + { + C::SLOW_FADE_IN, "slow_fade_in", + "a warp's fade-in runs long: a move right after it goes nowhere", + "the first move after a fade does not move the player", + {FaultClass::SLOW_FADE_IN}, {}, R::RETRY_STEP, + }, + { + C::DARK_MAP, "dark_map", + "a dark map (a cave without Flash) the readers cannot see", + "the floor reads dim; the walker's and the scene's reads fail there", + {FaultClass::DARK_CAVE}, {}, R::STOP, + }, + + }; +} + +// Scenes, talks and battles. +std::vector scene_rows(){ + return { + { + C::SCENE_END_POSE, "scene_end_pose", + "a step whose end the game sets leaves the player on a tile next to the expected one", + "the next walk starts or ends a tile off", + {FaultClass::SCENE_END_POSE}, {}, R::RETRY_STEP, + }, + { + C::SCENE_EARLY, "scene_early", + "a scene starts on the last tiles of the walk before it", + "the walk is interrupted by the scene's dialogue", + {FaultClass::SCENE_EARLY}, {}, R::RETRY_STEP, + }, + { + C::BATTLE_OPENING, "battle_opening", + "a battle's opening is still playing when a step starts", + "the step's first read is not the overworld or battle menu it expects", + {FaultClass::BATTLE_OPENING}, {}, R::RETRY_STEP, + }, + { + C::WILD_BATTLES, "wild_battles", + "more wild battles than a clean run meets", + "the interrupt handler clears each; too many in a step fail it", + {FaultClass::WILD_BATTLES}, {"too_many_interrupts"}, R::RETRY_STEP, + }, + }; +} + +// Interrupts, reads, menus and checks. +std::vector check_rows(){ + return { + { + C::INTERRUPT_FAILED, "interrupt_failed", + "something interrupted a step and was not cleared", + "the interrupt handler: no handler, a failed clear, the screen not settled", + {}, {"unhandled_interrupt", "interrupt_failed", "interrupt_unsettled", "interrupted"}, R::RELOAD, + }, + { + C::SCREEN_UNREAD, "screen_unread", + "a screen the step waits for (dialogue, banner, overworld, prompt) is not seen", + "the step's detector times out", + {}, {"talk_no_text", "mash_no_overworld"}, R::RELOAD, + }, + { + C::MENU_FAILED, "menu_failed", + "a menu action (mart, PC, item, TM, Fly) did not do what it was to", + "the menu's readers: the item, count or choice not as planned", + {}, {}, R::RELOAD, + }, + { + C::BATTLE_LOST, "battle_lost", + "a battle lost or not won: a blackout", + "the battle's end screen or the blackout's heal spot", + {}, {}, R::RELOAD, + }, + { + C::STATE_CHECK_FAILED, "state_check_failed", + "a check of the game's state failed: an event's expects, the checkpoint's end", + "the event's expects and requires, the checkpoint's end and postconditions", + {}, {"expect_failed", "require_failed", "end_failed", "postconditions_failed"}, R::RELOAD, + }, + { + C::OPERATION_FAILED, "operation_failed", + "a game's action threw, with no class of its own", + "an OperationFailedException out of a step", + {}, {"operation_failed"}, R::RELOAD, + }, + { + C::SIM_MISMATCH, "sim_mismatch", + "a simulated run left the story: the sim and the table disagree", + "the story sim's end checks (sim runs only)", + {}, {}, R::STOP, + }, + }; +} + +// Every class, in the enum's order. Function-local, so a static +// initializer in another file may read it. +const std::vector& class_rows(){ + static const std::vector CLASSES = []{ + std::vector rows; + for (std::vector group : {run_rows(), walk_rows(), warp_rows(), scene_rows(), check_rows()}){ + rows.insert(rows.end(), std::make_move_iterator(group.begin()), std::make_move_iterator(group.end())); + } + return rows; + }(); + return CLASSES; +} // The class whose id is `id`; nothing for an unknown id. std::optional find_story_failure_class(std::string_view id){ - for (const StoryFailureClassInfo& info : CLASSES){ + for (const StoryFailureClassInfo& info : class_rows()){ if (info.id == id){ return info.failure_class; } @@ -211,15 +249,22 @@ std::optional find_story_failure_class(std::string_view id){ const std::vector& story_failure_classes(){ - return CLASSES; + return class_rows(); } const StoryFailureClassInfo& story_failure_class_info(StoryFailureClass failure_class){ - return CLASSES[static_cast(failure_class)]; + const std::vector& classes = class_rows(); + const size_t index = static_cast(failure_class); + if (index >= classes.size() || classes[index].failure_class != failure_class){ + throw InternalProgramError( + nullptr, PA_CURRENT_FUNCTION, std::format("Story failure class {} has no row in its place.", index) + ); + } + return classes[index]; } std::optional story_failure_class_of(FaultClass fault){ - for (const StoryFailureClassInfo& info : CLASSES){ + for (const StoryFailureClassInfo& info : class_rows()){ if (std::ranges::find(info.injected_by, fault) != info.injected_by.end()){ return info.failure_class; } @@ -228,7 +273,7 @@ std::optional story_failure_class_of(FaultClass fault){ } std::optional story_failure_class_of_outcome(std::string_view failure){ - for (const StoryFailureClassInfo& info : CLASSES){ + for (const StoryFailureClassInfo& info : class_rows()){ if (std::ranges::find(info.outcomes, failure) != info.outcomes.end()){ return info.failure_class; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.h index 4cf5f9003d..5537ef88df 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses.h @@ -54,6 +54,7 @@ enum class StoryFailureClass{ BATTLE_LOST, STATE_CHECK_FAILED, OPERATION_FAILED, + // The last: the tests check that every class up to it has a row. SIM_MISMATCH, }; @@ -87,7 +88,8 @@ struct StoryFailureClassInfo{ // Every class, in the enum's order. const std::vector& story_failure_classes(); -// The row of `failure_class`. +// The row of `failure_class`. Throws InternalProgramError when the list +// has no row for it in the enum's place. const StoryFailureClassInfo& story_failure_class_info(StoryFailureClass failure_class); // The class a sim fault injects. Every FaultClass has one (the tests diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses_Tests.cpp index df17c2aefd..07fbd66ff3 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryFailureClasses_Tests.cpp @@ -18,6 +18,7 @@ #include #include #include +#include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Pokemon_StoryFailureClasses.h" @@ -151,6 +152,19 @@ UnitTestResult rows_in_enum_order(){ return true; } +UnitTestResult every_class_has_a_row(){ + const size_t count = static_cast(StoryFailureClass::SIM_MISMATCH) + 1; + if (story_failure_classes().size() != count){ + return std::format("{} rows for {} classes", story_failure_classes().size(), count); + } + try{ + story_failure_class_info(static_cast(count)); + }catch (const InternalProgramError&){ + return true; + } + return std::string("a class past the last row did not throw"); +} + UnitTestResult every_sim_fault_maps_to_one_class(){ for (FaultClass fault : fault_classes()){ size_t rows = 0; @@ -236,6 +250,7 @@ UnitTestResult no_class_without_a_tag(){ const ListCheckTestCase LIST_CHECKS[] = { {.name = "rows in the enum's order", .input = {rows_in_enum_order}, .expectation = {"story_failure_class_info() indexes by the enum"}}, + {.name = "every class has a row", .input = {every_class_has_a_row}, .expectation = {"no class reads past the table"}}, {.name = "every sim fault maps to one class", .input = {every_sim_fault_maps_to_one_class}, .expectation = {"the sweeps' faults all have a class"}}, {.name = "no outcome name in two classes", .input = {no_outcome_in_two_classes}, .expectation = {"a failure name has one class"}}, {.name = "ids round-trip", .input = {ids_round_trip}, .expectation = {"each id is unique and its tag alone reads back"}}, From a80d9f3d71567cc6bd1d3a7f34142ad5d7b96c25 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 14:43:55 -0800 Subject: [PATCH 15/34] ScreenEvents: assert the event count; ScreenEventLog tests Covers the first frame's rises, rose/fell edges, the capacity drop and describe(). --- .../ScreenEvents/ScreenEventTypes.h | 1 + .../ScreenEvents/ScreenEvents_Tests.cpp | 91 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEventTypes.h b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEventTypes.h index 73b4b12a77..e9d05d5052 100644 --- a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEventTypes.h +++ b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEventTypes.h @@ -36,6 +36,7 @@ enum class ScreenEvent : uint8_t{ }; // How many ScreenEvent values there are. constexpr size_t SCREEN_EVENT_COUNT = 11; +static_assert((size_t)ScreenEvent::SWITCH_HOME_MENU + 1 == SCREEN_EVENT_COUNT, "SWITCH_HOME_MENU is the last ScreenEvent"); // "dialog box", for the log. std::string screen_event_name(ScreenEvent event); diff --git a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp index 14a1483558..04720d2aa6 100644 --- a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp @@ -11,8 +11,10 @@ #include #include #include +#include "Common/Cpp/Time.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "ScreenEventLog.h" #include "ScreenEventTypes.h" #include "ScreenFades.h" #include "ScreenEvents.h" @@ -179,10 +181,99 @@ const ScreenEventsCase SCREEN_EVENTS_CASES[] = { }, }; +namespace{ + +// A stream of frames into a ScreenEventLog, and its describe() text. +struct ScreenEventLogCase{ + struct Frame{ + int ms; + std::vector events; + }; + struct Input{ + size_t capacity; + std::vector frames; + }; + struct Expectation{ + // describe() of the log, times from the first frame. + std::string text; + size_t dropped; + }; + + std::string name; + Input input; + Expectation expectation; +}; + +class Test_ScreenEventLog : public UnitTest{ +public: + explicit Test_ScreenEventLog(ScreenEventLogCase test_case) + : UnitTest(std::format("CommonTools::ScreenEventLog - {}", test_case.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + ScreenEventLog log(m_case.input.capacity); + const WallClock origin = current_time(); + for (const ScreenEventLogCase::Frame& frame : m_case.input.frames){ + ScreenEvents events; + for (ScreenEvent event : frame.events){ + events.set(event, true); + } + log.record(events, origin + Milliseconds(frame.ms)); + } + if (log.dropped() != m_case.expectation.dropped){ + return std::format("dropped(): expected {}, got {}", m_case.expectation.dropped, log.dropped()); + } + return expect_equal("describe()", describe(log, origin), m_case.expectation.text); + } + +private: + ScreenEventLogCase m_case; +}; + +} // namespace + +const ScreenEventLogCase SCREEN_EVENT_LOG_CASES[] = { + { + .name = "no frames", + .input = {.capacity = 8, .frames = {}}, + .expectation = {.text = "no changes", .dropped = 0}, + }, + { + .name = "the first frame's events all rise", + .input = {.capacity = 8, .frames = {{.ms = 0, .events = {ScreenEvent::DIALOG_BOX, ScreenEvent::SCREEN_STILL}}}}, + .expectation = {.text = "+0 ms dialog box rose\n+0 ms screen still rose\n", .dropped = 0}, + }, + { + .name = "only changes are kept, rising and falling", + .input = {.capacity = 8, .frames = { + {.ms = 0, .events = {ScreenEvent::PLAYER_CAN_MOVE}}, + {.ms = 100, .events = {ScreenEvent::PLAYER_CAN_MOVE}}, + {.ms = 200, .events = {ScreenEvent::FADE_BLACK}}, + {.ms = 900, .events = {}}, + }}, + .expectation = { + .text = "+0 ms player can move rose\n+200 ms black fade rose\n+200 ms player can move fell\n+900 ms black fade fell\n", + .dropped = 0, + }, + }, + { + .name = "the oldest changes drop past the capacity", + .input = {.capacity = 2, .frames = { + {.ms = 0, .events = {ScreenEvent::DIALOG_BOX}}, + {.ms = 100, .events = {}}, + {.ms = 200, .events = {ScreenEvent::CHOICE_BOX}}, + }}, + .expectation = {.text = "(1 older changes dropped)\n+100 ms dialog box fell\n+200 ms choice box rose\n", .dropped = 1}, + }, +}; + void add_tests_ScreenEvents(UnitTestDatabase& database){ for (const auto& item : SCREEN_EVENTS_CASES){ database.add(item); } + for (const auto& item : SCREEN_EVENT_LOG_CASES){ + database.add(item); + } } From c004f55a030f3fadec5ee600c9f13da70d67b500 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 15:15:55 -0800 Subject: [PATCH 16/34] Story data codec: run PokemonSimulation's shared wire cases natively again StoryDataTests takes the path of a pokesim-story-wire-cases/2 file, reads each case with the native pose, step and checkpoint readers and checks the accept/reject and the record read. The workflow pins PokemonSimulation 4e023f3 (#104, cases in the action-plus-args form) and runs it on all three platforms. --- .github/workflows/story-data.yml | 6 +- .../Data/Pokemon_StoryStepJson_Tests.cpp | 15 +- devtools/story-data-tests/CMakeLists.txt | 7 +- devtools/story-data-tests/README.md | 11 +- devtools/story-data-tests/StoryWireCases.cpp | 410 ++++++++++++++++++ devtools/story-data-tests/StoryWireCases.h | 30 ++ 6 files changed, 469 insertions(+), 10 deletions(-) create mode 100644 devtools/story-data-tests/StoryWireCases.cpp create mode 100644 devtools/story-data-tests/StoryWireCases.h diff --git a/.github/workflows/story-data.yml b/.github/workflows/story-data.yml index 8576b19548..045f398256 100644 --- a/.github/workflows/story-data.yml +++ b/.github/workflows/story-data.yml @@ -15,7 +15,7 @@ jobs: with: repository: dayfine/PokemonSimulation # Synthetic contract cases, not an approved map/resource pin. - ref: 866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3 + ref: 4e023f3d57022c68018f95f6fc0a4c0722d53adf path: publisher - uses: actions/setup-python@v6 with: @@ -28,3 +28,7 @@ jobs: - run: cmake -S devtools/story-data-tests -B build-story-data -DCMAKE_BUILD_TYPE=Debug - run: cmake --build build-story-data --config Debug -j4 - run: ctest --test-dir build-story-data -C Debug --output-on-failure + - if: runner.os != 'Windows' + run: ./build-story-data/StoryDataTests publisher/data/story/wire-conformance.json + - if: runner.os == 'Windows' + run: ./build-story-data/Debug/StoryDataTests.exe publisher/data/story/wire-conformance.json diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp index 5af96acd8f..37797c093e 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryStepJson_Tests.cpp @@ -3,8 +3,9 @@ * From: https://github.com/PokemonAutomation/ * * Each case reads a record from JSON: accepted cases check the values - * read, rejected cases check that the read fails. The Python reader's - * shared case file is checked on the Python side. + * read, rejected cases check that the read fails. The standalone + * StoryDataTests also checks PokemonSimulation's shared case file when given + * its path (devtools/story-data-tests/StoryWireCases.h). * */ @@ -17,7 +18,9 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonValue.h" #include "Pokemon_StoryStepJson.h" -#ifndef PA_STORY_DATA_STANDALONE +#ifdef PA_STORY_DATA_STANDALONE +#include "devtools/story-data-tests/StoryWireCases.h" +#else #include "Pokemon_StoryStepJson_Tests.h" #endif @@ -279,7 +282,11 @@ void add_tests_StoryStepJson(UnitTestDatabase& database){ #ifdef PA_STORY_DATA_STANDALONE -int main(){ +// With a path, check PokemonSimulation's shared wire-case file instead. +int main(int argc, char** argv){ + if (argc == 2){ + return PokemonAutomation::Pokemon::check_story_wire_cases(argv[1]) != 0; + } int failed = 0; for (const auto& test : PokemonAutomation::Pokemon::CASES){ const std::string error = PokemonAutomation::Pokemon::check_case(test); diff --git a/devtools/story-data-tests/CMakeLists.txt b/devtools/story-data-tests/CMakeLists.txt index c8fe360274..ceedca0b0d 100644 --- a/devtools/story-data-tests/CMakeLists.txt +++ b/devtools/story-data-tests/CMakeLists.txt @@ -10,6 +10,8 @@ set(STORY "${ROOT}/SerialPrograms/Source/Pokemon/AutoStory") add_executable(StoryDataTests "${STORY}/Data/Pokemon_StoryStepJson.cpp" "${STORY}/Data/Pokemon_StoryStepJson_Tests.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/StoryWireCases.cpp" + "${ROOT}/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Direction.cpp" "${STORY}/Pokemon_BuiltinStoryActions.cpp" "${STORY}/Types/Pokemon_StoryActionArg.cpp" "${STORY}/Types/Pokemon_StoryActionSpec.cpp" @@ -25,7 +27,10 @@ add_executable(StoryDataTests "${ROOT}/Common/Cpp/Strings/Unicode.cpp") # Reuse the Qt/controller-free support sources; each codec has its own test main. get_target_property(STORY_DATA_SOURCES StoryDataTests SOURCES) -list(REMOVE_ITEM STORY_DATA_SOURCES "${STORY}/Data/Pokemon_StoryStepJson_Tests.cpp") +list(REMOVE_ITEM STORY_DATA_SOURCES + "${STORY}/Data/Pokemon_StoryStepJson_Tests.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/StoryWireCases.cpp" + "${ROOT}/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Direction.cpp") add_executable(AuthoredCheckpointTests ${STORY_DATA_SOURCES} "${STORY}/Data/Pokemon_AuthoredCheckpointJson.cpp" "${STORY}/Data/Pokemon_AuthoredCheckpointJson_Tests.cpp") diff --git a/devtools/story-data-tests/README.md b/devtools/story-data-tests/README.md index c9d9b8caec..941227d5c4 100644 --- a/devtools/story-data-tests/README.md +++ b/devtools/story-data-tests/README.md @@ -6,6 +6,7 @@ Run without Qt, controllers, profiles or game saves: cmake -S devtools/story-data-tests -B build/story-data-tests cmake --build build/story-data-tests -j4 ctest --test-dir build/story-data-tests --output-on-failure +build/story-data-tests/StoryDataTests /path/to/PokemonSimulation/data/story/wire-conformance.json ``` For a multi-configuration generator, add `--config Debug` to the build, @@ -18,13 +19,15 @@ facing, and fills arg fallbacks. Unknown fields, kinds, actions and invalid primitive types fail. The C++ side has no writer; its tests check the values read. -The portable workflow checks the Python reader against the synthetic -conformance cases at -[PokemonSimulation revision 866613f](https://github.com/dayfine/PokemonSimulation/tree/866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3/data/story). +Given a path, `StoryDataTests` reads PokemonSimulation's synthetic +conformance cases (`pokesim-story-wire-cases/2`) with the native readers and +checks each accept/reject and value read (`StoryWireCases.cpp`). The portable +workflow runs it and the Python reader on the same cases at +[PokemonSimulation revision 4e023f3](https://github.com/dayfine/PokemonSimulation/tree/4e023f3d57022c68018f95f6fc0a4c0722d53adf/data/story). This fixture revision is a contract-test dependency, not an approved map-resource revision. -See the [shared checkpoint contract](https://github.com/dayfine/PokemonSimulation/blob/866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3/docs/story/CHECKPOINT_CONTRACT.md) +See the [shared checkpoint contract](https://github.com/dayfine/PokemonSimulation/blob/4e023f3d57022c68018f95f6fc0a4c0722d53adf/docs/story/CHECKPOINT_CONTRACT.md) for the field boundary and proposed common requirements, state, save/retry and handoff envelope. Both games can use those policies; their menu/detector/action bindings remain game specific. diff --git a/devtools/story-data-tests/StoryWireCases.cpp b/devtools/story-data-tests/StoryWireCases.cpp new file mode 100644 index 0000000000..fa8b2eb33e --- /dev/null +++ b/devtools/story-data-tests/StoryWireCases.cpp @@ -0,0 +1,410 @@ +/* Story Wire Cases + * + * From: https://github.com/PokemonAutomation/ + * + * The C++ side has no story JSON writer, so this test turns each record + * read back into the wire form the case file expects, with defaults + * omitted as the Python reader omits them, and compares the two as JSON. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Compiler.h" +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Filesystem/FileIO.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpointMetadata.h" +#include "StoryWireCases.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + + +// The wire names of the step kinds, as Pokemon_StoryStepJson.cpp reads them. +constexpr std::array, 15> KINDS{{ + {StoryStepKind::NEW_GAME, "new_game"}, + {StoryStepKind::OPTIONS, "options"}, + {StoryStepKind::ROUTE, "route"}, + {StoryStepKind::LEGS, "legs"}, + {StoryStepKind::STEP, "step"}, + {StoryStepKind::TALK, "talk"}, + {StoryStepKind::ANSWER, "answer"}, + {StoryStepKind::MASH, "scene"}, + {StoryStepKind::BATTLE, "battle"}, + {StoryStepKind::TRAIN, "train"}, + {StoryStepKind::HEAL, "heal"}, + {StoryStepKind::SHOP, "shop"}, + {StoryStepKind::SAVE, "save"}, + {StoryStepKind::READY, "ready"}, + {StoryStepKind::GAME, "game_action"}, +}}; + +// The wire names of the arg types, in StoryArgType's order. +constexpr std::array ARG_TYPES{ + "boolean", "integer", "word", "direction", "grid_pose", + "legs", "words", "items", "integer_rows", "timed_legs", +}; +static_assert(ARG_TYPES.size() == (size_t)StoryArgType::TIMED_LEGS + 1, "one wire name per StoryArgType"); + + +std::string_view kind_name(StoryStepKind kind){ + for (const auto& [value, name] : KINDS){ + if (value == kind){ + return name; + } + } + throw ParseException("Step kind with no wire name."); +} + +StoryStepKind kind_of(std::string_view name){ + for (const auto& [value, label] : KINDS){ + if (label == name){ + return value; + } + } + throw ParseException(std::format("Unknown step kind {}.", name)); +} + +StoryArgType arg_type_of(std::string_view name){ + for (size_t i = 0; i < ARG_TYPES.size(); i++){ + if (ARG_TYPES[i] == name){ + return (StoryArgType)i; + } + } + throw ParseException(std::format("Unknown arg type {}.", name)); +} + + +JsonValue strings_json(const std::vector& list){ + JsonArray out; + for (const std::string& item : list){ + out.push_back(JsonValue(item)); + } + return JsonValue(std::move(out)); +} + +JsonValue items_json(const std::vector& list){ + JsonArray out; + for (const StoryItem& item : list){ + JsonObject row; + row["item"] = JsonValue(item.item); + row["quantity"] = JsonValue((int64_t)item.quantity); + out.push_back(JsonValue(std::move(row))); + } + return JsonValue(std::move(out)); +} + +JsonValue tile_pose_json(const std::string& map, const std::vector& tiles, const std::optional& facing){ + JsonArray tile_list; + for (const TilePos& tile : tiles){ + JsonArray pair; + pair.push_back(JsonValue((int64_t)tile.x)); + pair.push_back(JsonValue((int64_t)tile.y)); + tile_list.push_back(JsonValue(std::move(pair))); + } + JsonObject out; + out["map"] = JsonValue(map); + out["tiles"] = JsonValue(std::move(tile_list)); + if (facing){ + out["facing"] = JsonValue(direction_name(*facing)); + } + return JsonValue(std::move(out)); +} + +JsonValue grid_pose_json(const GridPose& pose){ + return tile_pose_json(pose.map, pose.tiles, pose.facing); +} + +JsonValue declared_pose_json(const DeclaredPose& pose){ + if (const TileDeclared* tile = std::get_if(&pose)){ + return tile_pose_json(tile->map, tile->tiles, tile->facing); + } + const ZoneDeclared& zone = std::get(pose); + JsonObject out; + out["place"] = JsonValue(zone.place); + if (zone.spot){ + out["spot"] = JsonValue(*zone.spot); + } + if (zone.heading){ + out["heading"] = JsonValue((int64_t)*zone.heading); + } + return JsonValue(std::move(out)); +} + + +// An arg value in its wire form. +struct ArgJson{ + JsonValue operator()(bool value) const{ + return JsonValue(value); + } + JsonValue operator()(int64_t value) const{ + return JsonValue(value); + } + JsonValue operator()(const std::string& value) const{ + return JsonValue(value); + } + JsonValue operator()(Direction value) const{ + return JsonValue(direction_name(value)); + } + JsonValue operator()(const GridPose& value) const{ + return grid_pose_json(value); + } + JsonValue operator()(const std::vector& value) const{ + JsonArray out; + for (const StoryLeg& leg : value){ + JsonObject row; + row["direction"] = JsonValue(direction_name(leg.direction)); + row["tiles"] = JsonValue((int64_t)leg.tiles); + out.push_back(JsonValue(std::move(row))); + } + return JsonValue(std::move(out)); + } + JsonValue operator()(const std::vector& value) const{ + return strings_json(value); + } + JsonValue operator()(const std::vector& value) const{ + return items_json(value); + } + JsonValue operator()(const std::vector>& value) const{ + JsonArray out; + for (const std::vector& row : value){ + JsonArray numbers; + for (int64_t number : row){ + numbers.push_back(JsonValue(number)); + } + out.push_back(JsonValue(std::move(numbers))); + } + return JsonValue(std::move(out)); + } + JsonValue operator()(const std::vector& value) const{ + JsonArray out; + for (const StoryTimedLeg& leg : value){ + JsonArray pair; + pair.push_back(JsonValue((int64_t)leg.turn)); + pair.push_back(JsonValue((int64_t)leg.ms)); + out.push_back(JsonValue(std::move(pair))); + } + return JsonValue(std::move(out)); + } +}; + +JsonValue step_json(const StoryStep& step){ + JsonObject out; + out["id"] = JsonValue(step.name); + out["kind"] = JsonValue(std::string(kind_name(step.kind))); + if (!step.why.empty()){ + out["why"] = JsonValue(step.why); + } + if (!step.action.empty()){ + out["action"] = JsonValue(step.action); + } + if (!step.args.empty()){ + JsonObject args; + for (const auto& [key, value] : step.args){ + args[key] = std::visit(ArgJson{}, value); + } + out["args"] = JsonValue(std::move(args)); + } + if (!step.skip_if.empty()){ + out["skip_if"] = strings_json(step.skip_if); + } + if (step.pose_after){ + out["declared_after"] = declared_pose_json(*step.pose_after); + } + if (step.once_per_save){ + out["once_per_save"] = JsonValue(true); + } + return JsonValue(std::move(out)); +} + +JsonObject verified_json(const StoryVerification& verified){ + JsonObject out; + out["steps_hash"] = JsonValue(verified.steps_hash); + for (const auto& [key, value] : {std::pair{"build", &verified.build}, {"date", &verified.date}, {"runs", &verified.runs}}){ + if (!value->empty()){ + out[key] = JsonValue(*value); + } + } + return out; +} + +JsonObject postconditions_json(const StoryPostconditions& postconditions){ + JsonObject out; + if (postconditions.position){ + out["position"] = grid_pose_json(*postconditions.position); + } + if (!postconditions.items.empty()){ + out["items"] = items_json(postconditions.items); + } + if (!postconditions.flags.empty()){ + out["flags"] = strings_json(postconditions.flags); + } + return out; +} + +JsonObject metadata_json(const StoryCheckpoint& checkpoint){ + JsonObject out; + if (checkpoint.metadata.phase != StoryPhase::TESTING){ + out["phase"] = JsonValue(story_phase_name(checkpoint.metadata.phase)); + } + if (checkpoint.metadata.verified){ + out["verified"] = JsonValue(verified_json(*checkpoint.metadata.verified)); + } + if (!checkpoint.metadata.source.empty()){ + out["source"] = JsonValue(checkpoint.metadata.source); + } + JsonObject postconditions = postconditions_json(checkpoint.postconditions); + if (!postconditions.empty()){ + out["postconditions"] = JsonValue(std::move(postconditions)); + } + return out; +} + +JsonValue checkpoint_json(const StoryCheckpoint& checkpoint){ + JsonObject out; + out["id"] = JsonValue(checkpoint.id); + out["title"] = JsonValue(checkpoint.title); + if (checkpoint.start){ + out["start"] = declared_pose_json(*checkpoint.start); + } + JsonArray events; + for (const StoryStep& step : checkpoint.steps){ + events.push_back(step_json(step)); + } + out["events"] = JsonValue(std::move(events)); + JsonObject metadata = metadata_json(checkpoint); + if (!metadata.empty()){ + out["metadata"] = JsonValue(std::move(metadata)); + } + return JsonValue(std::move(out)); +} + + +// An arg's fallback, read as its type through a one-arg step. +StoryArgValue read_fallback(const StoryArgSpec& spec, const JsonValue& fallback){ + const std::vector one{{ + .kind = StoryStepKind::GAME, + .name = "fallback", + .args = {{.key = spec.key, .type = spec.type, .required = true, .fallback = std::nullopt, .why = ""}}, + }}; + JsonObject args; + args[spec.key] = fallback.clone(); + JsonObject step; + step["id"] = JsonValue("fallback"); + step["kind"] = JsonValue("game_action"); + step["action"] = JsonValue("fallback"); + step["args"] = JsonValue(std::move(args)); + return read_story_step(JsonValue(std::move(step)), "fallback", one).args.at(spec.key); +} + +StoryArgSpec read_arg_spec(const JsonObject& arg){ + StoryArgSpec spec{ + .key = arg.get_string_throw("key"), + .type = arg_type_of(arg.get_string_throw("type")), + .required = false, + .fallback = std::nullopt, + .why = "", + }; + if (const JsonValue* required = arg.get_value("required")){ + spec.required = required->to_boolean_throw(); + } + if (const JsonValue* fallback = arg.get_value("fallback")){ + spec.fallback = read_fallback(spec, *fallback); + } + return spec; +} + +// The built-in actions plus the case file's. +std::vector read_actions(const JsonArray& list){ + std::vector actions(builtin_story_actions().begin(), builtin_story_actions().end()); + for (const JsonValue& item : list){ + const JsonObject& action = item.to_object_throw(); + StoryActionSpec spec{.kind = kind_of(action.get_string_throw("kind")), .name = action.get_string_throw("name"), .args = {}}; + for (const JsonValue& arg : action.get_array_throw("args")){ + spec.args.push_back(read_arg_spec(arg.to_object_throw())); + } + actions.push_back(std::move(spec)); + } + return actions; +} + + +// The record `value` reads as, in wire form; throws ParseException if +// the reader rejects it. +JsonValue read_record(std::string_view record, const JsonValue& value, std::string_view name, std::span actions){ + if (record == "pose"){ + return grid_pose_json(read_grid_pose(value, name)); + } + if (record == "declared"){ + return declared_pose_json(read_declared_pose(value, name)); + } + if (record == "step"){ + return step_json(read_story_step(value, name, actions)); + } + if (record == "checkpoint"){ + return checkpoint_json(read_story_checkpoint(value, name, actions)); + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("Unknown record {}.", record)); +} + +// Empty if the case passes, else why it failed. +std::string check_case(const JsonObject& test, std::span actions){ + const JsonObject& input = test.get_object_throw("input"); + const JsonObject& expectation = test.get_object_throw("expectation"); + const std::string name = input.get_string_throw("name"); + const JsonValue* rejected = expectation.get_value("rejected"); + const bool want_rejected = rejected != nullptr && rejected->to_boolean_throw(); + JsonValue read; + try{ + read = read_record(input.get_string_throw("record"), input.get_value_throw("value"), name, actions); + }catch (const ParseException& error){ + return want_rejected ? "" : std::format("Unexpected parse failure: {}", error.message()); + } + if (want_rejected){ + return std::format("Expected rejection, read {}", read.dump(-1)); + } + const JsonValue& expected = expectation.get_value_throw("read"); + if (read != expected){ + return std::format("Read {}, expected {}", read.dump(-1), expected.dump(-1)); + } + return ""; +} + + +} // namespace + + +size_t check_story_wire_cases(const std::string& path){ + const JsonValue root = parse_json(file_to_string(path)); + const JsonObject& file = root.to_object_throw(path); + const std::vector actions = read_actions(file.get_array_throw("actions")); + size_t total = 0; + size_t failed = 0; + for (const JsonValue& item : file.get_array_throw("cases")){ + const JsonObject& test = item.to_object_throw(path); + const std::string error = check_case(test, actions); + std::cout << test.get_object_throw("input").get_string_throw("name") << ": " << (error.empty() ? "PASS" : error) << '\n'; + total++; + failed += !error.empty(); + } + std::cout << std::format("{} of {} shared wire cases passed.", total - failed, total) << '\n'; + return failed; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/devtools/story-data-tests/StoryWireCases.h b/devtools/story-data-tests/StoryWireCases.h new file mode 100644 index 0000000000..c4d740bd2c --- /dev/null +++ b/devtools/story-data-tests/StoryWireCases.h @@ -0,0 +1,30 @@ +/* Story Wire Cases + * + * From: https://github.com/PokemonAutomation/ + * + * Checks the native story readers against PokemonSimulation's shared wire + * cases (format pokesim-story-wire-cases/2, data/story/wire-conformance.json), + * the same cases its Python reader runs. + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryWireCases_H +#define PokemonAutomation_Pokemon_StoryWireCases_H + +#include + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Read each case in the file at `path` with the native reader for its +// record, and compare: a case expected rejected must fail to read; any other +// must read the expected record. Prints one line per case and a total, and +// returns the number of failed cases. A malformed case file throws. +size_t check_story_wire_cases(const std::string& path); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif From 107ce7b71258952aa216d44132b8637e10d6ed93 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 15:17:51 -0800 Subject: [PATCH 17/34] Game languages: say why FRLG lists six languages and Gen 8-9 one Spanish Answers the #312 review: the Switch FireRed/LeafGreen are the GBA releases reissued, one version per language with no in-game option, so all six languages stay (as in upstream's FRLG programs). Gen 8-9 games have one Spanish, so one "es". Code that reads text takes the language option. --- .../Pokemon/Options/Pokemon_GameLanguages.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h index eec094dfaf..b2f53a0839 100644 --- a/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h +++ b/SerialPrograms/Source/Pokemon/Options/Pokemon_GameLanguages.h @@ -4,7 +4,10 @@ * * The languages each game can be played in, as dropdown databases for a * program's language option. A program offers its game's set, so a user - * can't pick a language the game doesn't have. + * can't pick a language the game doesn't have. Every language a game ships + * in is listed, tested on console or not: code that needs the language + * (reading text) takes this option, never assumes one, and says so where + * it has no reader for a language. * */ @@ -21,11 +24,16 @@ namespace Pokemon{ // The nine languages of the Switch games of generations 8 and 9: Sword and // Shield, Brilliant Diamond and Shining Pearl, Legends: Arceus, Scarlet and // Violet, Legends: Z-A. Japanese, English, French, Italian, German, -// Spanish, Korean, Chinese (Simplified and Traditional). +// Spanish, Korean, Chinese (Simplified and Traditional). The games have one +// Spanish (Spain), hence one "es". const EnumDropdownDatabase& Gen8ToGen9Languages_Database(); -// The six languages of FireRed and LeafGreen: Japanese, English, French, -// Italian, German, Spanish. +// The six languages of FireRed and LeafGreen, the Game Boy Advance +// releases the Switch versions reissue: Japanese, English, French, Italian, +// German, Spanish. On Switch each language is a separate version with no +// in-game language option (Nintendo of America sells English, French and +// Spanish, the latter two in their European form), so the user picks the +// version they own. The same six as upstream's FRLG programs. const EnumDropdownDatabase& FireRedLeafGreenLanguages_Database(); From 019fa241be4e7c7d8f1d55be5ccf4f734e3637fe Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 15:28:54 -0800 Subject: [PATCH 18/34] Fix shared story engine review nits --- .../ScreenEvents/ScreenEvents_Tests.cpp | 6 +- .../AutoStory/Data/Pokemon_StoryFiles.cpp | 28 +- .../Data/Pokemon_StoryFiles_Tests.cpp | 8 + .../Engine/Pokemon_StoryEngineRuns_Tests.cpp | 296 +----------- .../Engine/Pokemon_StoryEngineRuns_Tests.h | 3 +- .../Pokemon_StoryEngineSaveRetry_Tests.cpp | 442 ++++++++++++++++++ .../Pokemon_StoryEngineSaveRetry_Tests.h | 23 + .../AutoStory/Pokemon_AutoStory_Tests.h | 2 + .../AutoStory/Pokemon_StoryFailureClasses.cpp | 12 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 10 files changed, 514 insertions(+), 308 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineSaveRetry_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineSaveRetry_Tests.h diff --git a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp index 04720d2aa6..7b61ab9227 100644 --- a/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/CommonTools/ScreenEvents/ScreenEvents_Tests.cpp @@ -186,17 +186,17 @@ namespace{ // A stream of frames into a ScreenEventLog, and its describe() text. struct ScreenEventLogCase{ struct Frame{ - int ms; + int ms = 0; std::vector events; }; struct Input{ - size_t capacity; + size_t capacity = 0; std::vector frames; }; struct Expectation{ // describe() of the log, times from the first frame. std::string text; - size_t dropped; + size_t dropped = 0; }; std::string name; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp index b7b108c311..3c958c9feb 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles.cpp @@ -63,16 +63,32 @@ void check_in_story_order( namespace{ +// Which row sequence the reload check applies to. +enum class RunKind{ + DEVELOPER, + USER, +}; + +// Text naming `run` in a reload error. +std::string_view run_suffix(RunKind run){ + switch (run){ + case RunKind::DEVELOPER: + return ""; + case RunKind::USER: + return " in a user's run"; + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown story run kind."); +} + // Throws ParseException naming `source` unless `previous` ends on the -// game's autosave in `rows`; `run` says in whose run ("" or " in a -// user's run"). +// game's autosave in `rows`, for `run`. void check_reload_after( - std::optional previous, const StoryRows& rows, std::string_view run, std::string_view source + std::optional previous, const StoryRows& rows, RunKind run, std::string_view source ){ if (!previous || !rows.autosaves.contains(*previous)){ throw ParseException(std::format( "{}: reload_when_chained after a checkpoint that does not end on the game's autosave{}: the reload would load an older save", - source, run + source, run_suffix(run) )); } } @@ -87,9 +103,9 @@ void add_story_row( if (start == RowSave::WITHOUT_SAVE){ throw ParseException(std::format("{}: reload_when_chained on a checkpoint with no save to reload", source)); } - check_reload_after(previous.in_dev_run, rows, "", source); + check_reload_after(previous.in_dev_run, rows, RunKind::DEVELOPER, source); if (!execution.dev_only && previous.in_user_run != previous.in_dev_run){ - check_reload_after(previous.in_user_run, rows, " in a user's run", source); + check_reload_after(previous.in_user_run, rows, RunKind::USER, source); } rows.reload_when_chained.emplace(id); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp index 8b1d06bb5a..54d4b9b78b 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_StoryFiles_Tests.cpp @@ -184,6 +184,14 @@ const LoadCase LOAD_CASES[] = { .input = {.builtin = {{"test-01.00.plan", file_text("01.00", R"({"save": "menu"})")}, ROW_1}}, .expectation = {.error = "test-01.01.plan: reload_when_chained after a checkpoint that does not end on the game's autosave"}, }, + { + .name = "a dev-only reload after a user row that does not autosave fails", + .input = {.builtin = { + {"test-01.00.plan", file_text("01.00", R"({"save": "menu"})")}, + {"test-01.01.plan", file_text("01.01", R"({"dev_only": true, "reload_when_chained": true})")}, + }}, + .expectation = {.error = "test-01.01.plan: reload_when_chained after a checkpoint that does not end on the game's autosave"}, + }, { .name = "reload_when_chained after a dev-only autosave row, the user's row before it not autosaving, fails", .input = {.builtin = { diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp index ecfc8a691b..9f4a51a3d8 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryEngineRuns_Tests.cpp @@ -5,12 +5,11 @@ * What a game needs from the engine to drop its own workarounds (the PLZA * move, #335): a scripted backend for any pose type, the move stick and * the heading reading, the choice and interact events, a screen machine - * over observations, the step in an action's call, the checkpoint in the - * save, the segment and verify loops, console-only actions, declared poses - * of the game's kind only, and tile actions only for tile games. + * over observations, the step in an action's call, declared poses of the + * game's kind only, and tile actions only for tile games. * Then what PLZA found on the engine: readers opt in to the postcondition * check, inputs logged by button name, waiting states may stay still, and - * the stick's release. + * the stick's release. It also checks the engine's breakpoints. * */ @@ -60,15 +59,6 @@ bool has_line(const FakeStoryBackend& backend, std::string_view line){ return false; } -template -size_t count_lines(const FakeStoryBackend& backend, std::string_view line){ - size_t count = 0; - for (const std::string& each : backend.lines()){ - count += each == line ? 1 : 0; - } - return count; -} - template std::string expect_inputs(const FakeStoryBackend& backend, std::string_view expected){ const std::string got = joined(backend.inputs()); @@ -98,16 +88,6 @@ StoryCheckpoint checkpoint_of(std::string id, std::vector steps){ return checkpoint; } -// `checkpoint` in `phase`, verified with its steps as they are now. -template -StoryCheckpoint in_phase(StoryCheckpoint checkpoint, StoryPhase phase, const StoryEngine& engine){ - checkpoint.metadata.phase = phase; - checkpoint.metadata.verified = StoryVerification{ - .steps_hash = engine.steps_hash(checkpoint), .build = "abc", .date = "2026-11-10", .runs = "3/3", - }; - return checkpoint; -} - // A GAME action of no args. template StoryAction game_action(std::string name, StoryActionHandler handler){ @@ -517,265 +497,6 @@ std::string handler_sees_step(CancellableScope& scope){ return *seen == "opening / the long intro" ? "" : std::format("expected the step, got \"{}\"", *seen); } -StoryStep save_step(std::string name){ - StoryStep step; - step.kind = StoryStepKind::SAVE; - step.name = std::move(name); - return step; -} - -// Gap 6: the save is told its checkpoint, at the end and at a SAVE step. -std::string save_gets_checkpoint(CancellableScope& scope){ - StoryGame game = flaky_game(0); - FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); - StoryEngine engine(game, backend); - const StoryCheckpoint checkpoint = in_phase( - checkpoint_of("02.01", {game_step("walk", "fine"), save_step("save_here")}), StoryPhase::REPRODUCTION, engine - ); - RunState state; - const StoryEngineReport report = engine.run_checkpoint(checkpoint, SavePoint::CHECKPOINT_END, state); - if (!report.saved){ - return "expected the checkpoint to save at its end"; - } - const size_t saves = count_lines(backend, "[Test] save 02.01"); - return saves == 2 ? "" : std::format("expected 2 saves of 02.01, got {}: {}", saves, joined(backend.lines())); -} - -// A SAVE step part-way through a checkpoint moves the save: a reload -// after a later failure would not return to the checkpoint's start, so -// the segment stops there instead of retrying from step 1. -std::string no_retry_after_a_save_step(CancellableScope& scope){ - StoryGame game = flaky_game(1); - FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); - StoryEngine engine(game, backend); - const std::vector checkpoints{in_phase( - checkpoint_of("02.01", {game_step("walk", "fine"), save_step("save_here"), game_step("talk", "flaky")}), - StoryPhase::REPRODUCTION, engine - )}; - RunState state; - const SegmentReport report = engine.run_segment("seg", checkpoints, 3, state); - if (report.completed || report.failed_event != "talk" || report.failure.failure != "flaky_failed"){ - return std::format("expected the segment to stop at talk, got {}: {}", to_string(report.failure), joined(backend.lines())); - } - if (count_lines(backend, "[Test] reload") != 0){ - return std::format("expected no reload: {}", joined(backend.lines())); - } - return has_line(backend, "[Checkpoint] 02.01: a save step saved part-way, so a reload would not return to its start: no retry") - ? "" - : std::format("expected the no-retry line: {}", joined(backend.lines())); -} - -// Gap 8: a console_only action is refused, before any input, on a backend -// that is no console; it runs on one. -StoryGame console_game(){ - StoryGame game = flaky_game(0); - StoryAction menu = game_action("open_menu", [](StoryBackend& backend, const StoryActionCall&, RunState&){ - backend.press(NintendoSwitch::BUTTON_X, 80ms, 120ms); - return outcome_ok(); - }); - menu.spec.console_only = true; - game.actions.push_back(std::move(menu)); - return game; -} - -std::string console_only_refused(CancellableScope& scope){ - const StoryGame game = console_game(); - const StoryActionRegistry registry(game); - RunState state; - FakeStoryBackend script({}, scope); - const Outcome refused = registry.dispatch(script, game_step("menu", "open_menu"), state); - if (refused.failure != CONSOLE_ONLY || refused.detail != "open_menu runs only on a console, not on a script backend"){ - return std::format("expected console_only, got {}", to_string(refused)); - } - const std::string none = expect_inputs(script, ""); - if (!none.empty()){ - return none; - } - FakeStoryBackend console({.kind = StoryBackendKind::CONSOLE}, scope); - if (!registry.dispatch(console, game_step("menu", "open_menu"), state).succeeded()){ - return "expected the action to run on a console"; - } - return expect_inputs(console, "press X"); -} - -// Gap 7 and 8: no reload for a console_only failure, which every attempt -// would repeat. -std::string segment_no_reload_for_console_only(CancellableScope& scope){ - const StoryGame game = console_game(); - FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); - StoryEngine engine(game, backend); - const std::vector checkpoints{checkpoint_of("01", {game_step("menu", "open_menu")})}; - RunState state; - const SegmentReport report = engine.run_segment("seg", checkpoints, 3, state); - if (report.completed || report.failure.failure != CONSOLE_ONLY || report.failed_event != "menu"){ - return std::format("expected the segment to stop on console_only at menu, got {}", to_string(report.failure)); - } - return count_lines(backend, "[Test] reload") == 0 ? "" : "expected no reload"; -} - -// Gap 7: the first checkpoint is retried after a reload; one after it -// only when the one before saved at its end (#329). -struct SegmentCase{ - struct Input{ - StoryPhase phase; - // Which checkpoint fails once: 0 or 1. - size_t flaky = 0; - }; - - struct Expectation{ - bool completed = false; - size_t reloads = 0; - size_t saves = 0; - }; - - std::string_view name; - Input input; - Expectation expectation; -}; - -const SegmentCase SEGMENT_CASES[] = { - {.name = "first retries while testing", .input = {.phase = StoryPhase::TESTING, .flaky = 0}, - .expectation = {.completed = true, .reloads = 1, .saves = 0}}, - {.name = "second does not retry while testing", .input = {.phase = StoryPhase::TESTING, .flaky = 1}, - .expectation = {.completed = false, .reloads = 0, .saves = 0}}, - {.name = "second does not retry while verifying", .input = {.phase = StoryPhase::VERIFICATION, .flaky = 1}, - .expectation = {.completed = false, .reloads = 0, .saves = 0}}, - {.name = "second retries after a reproduction save", .input = {.phase = StoryPhase::REPRODUCTION, .flaky = 1}, - .expectation = {.completed = true, .reloads = 1, .saves = 2}}, -}; - -std::string check_segment(const SegmentCase& test, CancellableScope& scope){ - const StoryGame game = flaky_game(1); - FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); - StoryEngine engine(game, backend); - std::vector checkpoints; - for (size_t c = 0; c < 2; c++){ - const std::string action = c == test.input.flaky ? "flaky" : "fine"; - checkpoints.push_back(in_phase(checkpoint_of(std::format("0{}", c + 1), {game_step("walk", action)}), test.input.phase, engine)); - } - RunState state; - const SegmentReport report = engine.run_segment("seg", checkpoints, 3, state); - const size_t reloads = count_lines(backend, "[Test] reload"); - const size_t saves = count_lines(backend, "[Test] save 01") + count_lines(backend, "[Test] save 02"); - if (report.completed != test.expectation.completed || reloads != test.expectation.reloads || saves != test.expectation.saves){ - return std::format( - "expected completed {}, {} reloads, {} saves; got {}, {}, {}: {}", - test.expectation.completed, test.expectation.reloads, test.expectation.saves, - report.completed, reloads, saves, joined(backend.lines()) - ); - } - return report.reloads == reloads ? "" : "expected the report to count each reload"; -} - -class StorySegmentTest : public UnitTest{ -public: - explicit StorySegmentTest(SegmentCase test) - : UnitTest(std::format("Pokemon::StoryEngine segment - {}", test.name)) - , m_case(std::move(test)) - {} - virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ - const std::string error = check_segment(m_case, scope); - return error.empty() ? UnitTestResult(true) : UnitTestResult(error); - } -private: - SegmentCase m_case; -}; - -// The engine's retries run through run_checkpoint_attempts(): the same -// reload and pass lines and attempt counts as its own loop had. -struct RetryCase{ - struct Input{ - // Calls of the checkpoint's action that fail before one passes. - size_t failures = 0; - size_t attempts = 0; - }; - - struct Expectation{ - bool passed = false; - size_t attempts = 0; - // Lines the run writes once each. - std::vector lines; - }; - - std::string_view name; - Input input; - Expectation expectation; -}; - -const RetryCase RETRY_CASES[] = { - {.name = "pass after a reload", .input = {.failures = 1, .attempts = 3}, - .expectation = {.passed = true, .attempts = 2, .lines = { - "[Checkpoint] 01: failed, resetting for attempt 2/3", - "[Test] reload", - "[Checkpoint] 01: passed on attempt 2 (1 reset)", - }}}, - {.name = "stop after the last attempt", .input = {.failures = 5, .attempts = 2}, - .expectation = {.passed = false, .attempts = 2, .lines = { - "[Checkpoint] 01: failed, resetting for attempt 2/2", - "[Test] reload", - }}}, -}; - -std::string check_retry(const RetryCase& test, CancellableScope& scope){ - const StoryGame game = flaky_game(test.input.failures); - FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); - StoryEngine engine(game, backend); - const std::vector checkpoints{checkpoint_of("01", {game_step("walk", "flaky")})}; - RunState state; - const SegmentReport report = engine.run_segment("seg", checkpoints, test.input.attempts, state); - const CheckpointRun& run = report.runs.at(0); - if (run.passed != test.expectation.passed || run.attempts != test.expectation.attempts){ - return std::format( - "expected passed {} after {} attempts, got {} after {}: {}", - test.expectation.passed, test.expectation.attempts, run.passed, run.attempts, joined(backend.lines()) - ); - } - for (std::string_view line : test.expectation.lines){ - if (count_lines(backend, line) != 1){ - return std::format("expected \"{}\" once: {}", line, joined(backend.lines())); - } - } - return ""; -} - -class StoryRetryTest : public UnitTest{ -public: - explicit StoryRetryTest(RetryCase test) - : UnitTest(std::format("Pokemon::StoryEngine retry - {}", test.name)) - , m_case(std::move(test)) - {} - virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ - const std::string error = check_retry(m_case, scope); - return error.empty() ? UnitTestResult(true) : UnitTestResult(error); - } -private: - RetryCase m_case; -}; - -// Gap 7: verify runs a checkpoint 3 times from one save, saving only at -// the end of the last, and only when every run passed. -std::string verify_saves_after_all_passed(CancellableScope& scope){ - for (size_t failures = 0; failures < 2; failures++){ - const StoryGame game = flaky_game(failures); - FakeStoryBackend backend({.looks = {look({ScreenEvent::PLAYER_CAN_MOVE})}}, scope); - StoryEngine engine(game, backend); - const StoryCheckpoint checkpoint = in_phase(checkpoint_of("00.15b", {game_step("battle", "flaky")}), StoryPhase::VERIFICATION, engine); - RunState state; - const VerifyReport report = engine.verify_checkpoint(checkpoint, VerifyPolicy{.runs = 3, .passes_needed = 2}, state); - const size_t saves = count_lines(backend, "[Test] save 00.15b"); - const size_t reloads = count_lines(backend, "[Test] reload"); - const size_t passes = 3 - failures; - if (!report.verified || report.passes != passes || reloads != 2 || saves != (failures == 0 ? 1 : 0) || report.saved != (failures == 0)){ - return std::format( - "{} failures: expected verified, {} passes, 2 reloads, {} saves; got {}, {}, {}, {}", - failures, passes, failures == 0 ? 1 : 0, report.verified, report.passes, reloads, saves - ); - } - } - return ""; -} - - // A game whose "mark" action records "run " and whose pause hook // records "pause