Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES})
include(cmake/EmbedTextFiles.cmake)
pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps
Pokemon/Navigation/Pokemon_NavigationTestMaps.h PokemonAutomation::Pokemon navigation_test_map_json)
pa_embed_text_files(SerialProgramsLib Source/PokemonBDSP/Programs/AutoStory/Simulation/ConsoleFailures
PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h
PokemonAutomation::NintendoSwitch::PokemonBDSP console_failure_json)
# Prepared data is validated by the shared publisher tooling. No source-map
# fallback or network download is performed during configuration.
set(POKESIM_TOOLS_SOURCE "$ENV{POKESIM_TOOLS_SOURCE}" CACHE PATH "Pinned PokemonSimulation tools checkout")
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h"
#include "Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WildBattlePolicy_Tests.h"
#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.h"
#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h"
#include "Programs/RngManipulation/PokemonBDSP_StarterRng_Tests.h"
#include "PokemonBDSP_Tests.h"

Expand All @@ -40,7 +41,7 @@



void add_tests(UnitTestDatabase& database){

Check warning on line 44 in SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::add_tests( UnitTestDatabase & database): function_lines=30 (advisory above 25, limit 50)
add_tests_DialogDetector(database);
add_tests_MenuDetector(database);
add_tests_AutoStory_Actions(database);
Expand All @@ -64,6 +65,7 @@
add_tests_AutoStory_StorySim(database);
add_tests_AutoStory_StoryMonteCarlo(database);
add_tests_AutoStory_SimFailureCases(database);
add_tests_AutoStory_ConsoleFailureReplay(database);
add_tests_AutoStory_FaultSweep(database);
add_tests_AutoStory_SimGolden(database);
add_tests_AutoStory_StoryActions(database);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"about": "lab-B 2026-11-12 18:27-18:42, 01.02: by_the_east_mouth's counted taps went two tiles past the leg's end onto the Gate's east warp, its fade unseen; into_oreburgh then saw no fade and no OreburghCity banner.",
"checkpoint": "01.02",
"faults": [
{"kind": "moved_further", "step": "by_the_east_mouth", "direction": "east", "tiles": 2, "fade": "unseen", "far_pose_of": "into_oreburgh"}
],
"failed": {"step": "into_oreburgh", "error": "no_banner"},
"frame": "",
"evidence": [
"[Leg] by_the_east_mouth leg 7: east 3 planned, moved 2, dead_reckoned at (26, 22)",
"into_oreburgh: no fade and no OreburghCity banner in 4 taps east"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"about": "lab-B 2026-11-12 20:20:50, 01.02 past_curtis, after the same one tile of drift as 21:02 (Curtis stopped the east walk at 9 tiles, a fight left tiles 13-16 possible): the hold east to find us again ran along row 22 and out the Gate's east door, its fade unseen; the program took it as ending at (16, 22) and walked on in Oreburgh City, which it took for the Gate, until into_oreburgh saw no banner at 20:23:09.",
"checkpoint": "01.02",
"faults": [
{"kind": "person_stands", "name": "camper_1", "tile": [17, 22]},
{"kind": "scene_ends_further", "step": "the_hiker", "direction": "east", "tiles": 1},
{"kind": "hold_through_warp", "step": "past_curtis", "direction": "east", "fade": "unseen", "far_pose_of": "into_oreburgh"}
],
"failed": {"step": "into_oreburgh", "error": "no_banner"},
"frame": "",
"evidence": [
"[Walk] past curtis: east 3 (to wall) to find us again: screen change 266.96 at 1200 ms (the fade), then limit after 1850 ms",
"[Route] past curtis: found again at OreburghGate (16, 22), after 1 hold(s)."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"about": "lab-B 2026-11-12 21:02:53, 01.02 past_curtis: the player stood one tile east of the table's (7, 22) after the Hiker's scene (hikers_trigger's step east, the scene after it; the same drift as 20:15), so the east walk from the believed (7, 22) met Camper Curtis's sight line on column 17 after 9 tiles, not 10, and he stopped it at (17, 22) while the program believed (15-16, 22). Its recovery hold east then ran 12 tiles, out of the Gate.",
"checkpoint": "01.02",
"faults": [
{"kind": "person_stands", "name": "camper_1", "tile": [17, 22]},
{"kind": "scene_ends_further", "step": "the_hiker", "direction": "east", "tiles": 1}
],
"failed": {"step": "past_curtis", "error": "operation_failed: past curtis: east 1 (to wall) to find us again: still moving after 12 tiles, past the wall 1 tiles away at most: position unknown."},
"frame": "20261112-210253120715-attempt0.png",
"evidence": [
"[Event] 01.02/7 hikers_trigger: a step east, limit.",
"[Walk] past curtis: east 13 (open): blocked after 8800 ms, 9 moved chunks",
"[Route] someone the map lacks is at OreburghGate (17, 22)",
"[Leg] past_curtis leg 1: east, moved 9, seen at (15, 22),(16, 22)"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* BDSP AutoStory - Console failure data
*
* From: https://github.com/PokemonAutomation/
*
* The fault files in ConsoleFailures/, built into the program
* (cmake/EmbedTextFiles.cmake): (file name, text), sorted by name.
*
*/

#ifndef PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureData_H
#define PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureData_H

#include <string>
#include <utility>
#include <vector>

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


// (file name without ".json", text) of each fault file.
const std::vector<std::pair<std::string, std::string>>& console_failure_json();


} // namespace PokemonBDSP
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/* BDSP AutoStory - Console failure replay tests
*
* From: https://github.com/PokemonAutomation/
*
* Every fault file (Pokemon_LegReplay.h) of a console failure runs here on
* the story simulation: trainers, NPCs and walls come from the map, only
* the file's faults are injected, and the checkpoint it names must pass.
* A file is red on the program that failed on the console and green on the
* program that fixed it. No case has code of its own.
*
*/

#include <algorithm>
#include <format>
#include <string>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h"
#include "Pokemon/AutoStory/Types/Pokemon_GridPose.h"
#include "Pokemon/Navigation/Pokemon_LegReplay.h"
#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h"
#include "PokemonBDSP_AutoStory_ConsoleFailureData.h"
#include "PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h"
#include "PokemonBDSP_AutoStory_StorySim.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{

namespace{

using Pokemon::ConsoleFailure;
using Pokemon::ReplayFault;
using Pokemon::ReplayFaultKind;
using Pokemon::StoryStep;

const StoryStep* find_step(const std::vector<StoryCheckpoint>& rows, const std::string& row, const std::string& name){
for (const StoryCheckpoint& checkpoint : rows){
if (checkpoint.id != row){
continue;
}
for (const StoryStep& step : checkpoint.steps){
if (step.name == name){
return &step;
}
}
}
return nullptr;
}

SimFade sim_fade_of(Pokemon::ReplayFade fade){
switch (fade){
case Pokemon::ReplayFade::UNSEEN:
return SimFade::UNSEEN;
case Pokemon::ReplayFade::BLACK:
return SimFade::BLACK;
case Pokemon::ReplayFade::DIM:
return SimFade::DIM;
case Pokemon::ReplayFade::WHITE:
return SimFade::WHITE;
}
return SimFade::UNSEEN;
}

// The walk that goes on past its end, as the fault says.
SimSlide slide_of(const ConsoleFailure& failure, const std::vector<StoryCheckpoint>& rows, const ReplayFault& fault){
SimSlide slide{
.step = fault.step, .direction = fault.direction, .tiles = fault.tiles,
.fade = sim_fade_of(fault.fade), .banner_up = fault.banner_up,
};
if (fault.far_pose_of.empty()){
return slide;
}
const StoryStep* landing = find_step(rows, failure.checkpoint, fault.far_pose_of);
if (landing == nullptr || !landing->pose_after){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION,
std::format("{}: step {} has no pose after it", failure.name, fault.far_pose_of));
}
slide.far = Pokemon::pose_of(*landing->pose_after);
return slide;
}

// The faults as the simulation's knobs.
void inject(const ConsoleFailure& failure, const std::vector<StoryCheckpoint>& rows, SimMisses& misses, SimWorldKnobs& knobs){

Check warning on line 84 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::inject( const ConsoleFailure & failure , const std :: vector<StoryCheckpoint> & rows , SimMisses & misses , SimWorldKnobs & knobs): function_lines=35 (advisory above 25, limit 50)
if (failure.start){
knobs.start_at = Pokemon::pose_of(Pokemon::GridPose{
failure.start->map, {failure.start->tile}, *failure.start_facing
});
}
for (const ReplayFault& fault : failure.faults){
switch (fault.kind){
case ReplayFaultKind::FADE_MISSED:
misses.fade = fault.index;
break;
case ReplayFaultKind::BANNER_MISSED:
misses.banner = fault.index;
break;
case ReplayFaultKind::MOVED_FURTHER:
knobs.slides.push_back(slide_of(failure, rows, fault));
break;
case ReplayFaultKind::HOLD_THROUGH_WARP:
knobs.hold_slides.push_back(slide_of(failure, rows, fault));
break;
case ReplayFaultKind::SCENE_ENDS_FURTHER:
knobs.scene_slides.push_back(slide_of(failure, rows, fault));
break;
case ReplayFaultKind::PERSON_STANDS:
knobs.standing[fault.name] = fault.tile;
break;
case ReplayFaultKind::MOVED_LESS:
// The BDSP story sim takes each hold as walked; only the FRLG overworld sim shortens holds.
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format(
"{}: the fault \"{}\" is not one the BDSP story simulation injects",
failure.name, Pokemon::replay_fault_kind_name(fault.kind)
));
}
}
}

struct ReplayInput{
std::string name;
std::string text;
};
struct ReplayExpectation{
};
struct ReplayCase{
ReplayInput input;
ReplayExpectation expectation;
};

// The note the sim leaves when a fault really happened; empty for kinds with no note.
std::string fault_marker(ReplayFaultKind kind){
switch (kind){
case ReplayFaultKind::MOVED_FURTHER: return "[Sim] slid";
case ReplayFaultKind::HOLD_THROUGH_WARP: return "[Sim] held through a warp";
case ReplayFaultKind::SCENE_ENDS_FURTHER: return "[Sim] scene ended";
default: return "";
}
}

// The cases are discovered from the embedded fault JSONs, so a new console failure needs no
// C++ edit; the code-health test-case table rule does not fit a data-driven test.
class Test_ConsoleFailureReplay : public UnitTest{

Check failure on line 143 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

test-case: construct each UnitTest from one case struct with name, input and expectation fields (input and expectation structs, the name outside the input); register a named table of designated cases in a range-for
public:
explicit Test_ConsoleFailureReplay(ReplayCase test_case)
: UnitTest(std::format("PokemonBDSP::AutoStory - Console failure replay: {}", test_case.input.name))
, m_case(std::move(test_case))
{}
virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{

Check warning on line 149 in SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonBDSP::Test_ConsoleFailureReplay::run( Logger & logger , CancellableScope &) const: function_lines=35 (advisory above 25, limit 50)
try{
const ConsoleFailure failure = Pokemon::parse_console_failure(m_case.input.name, m_case.input.text);
const std::vector<StoryCheckpoint> rows = story_checkpoints();
if (find_step(rows, failure.checkpoint, failure.failed_step) == nullptr){
return std::format("{}: the step {} it failed at is not in {}", m_case.input.name, failure.failed_step, failure.checkpoint);
}
SimMisses misses{.fade = {}, .banner = {}};
SimWorldKnobs knobs;
inject(failure, rows, misses, knobs);
SimExecutor executor(logger, std::move(misses), std::move(knobs));
const Pokemon::SegmentReport report = run_rows_on(executor, logger, {.from = failure.checkpoint, .to = failure.checkpoint}, rows);
// A fault that never happened on the sim replays nothing.
for (const ReplayFault& fault : failure.faults){
const std::string marker = fault_marker(fault.kind);
if (marker.empty()){
continue;
}
const auto& notes = executor.notes();
if (std::none_of(notes.begin(), notes.end(), [&](const std::string& note){ return note.find(marker) != std::string::npos; })){
return std::format("{}: the {} fault at {} never happened on the sim", m_case.input.name,
Pokemon::replay_fault_kind_name(fault.kind), fault.step);
}
}
if (report.completed){
return true;
}
return std::format("stopped in {}: {} (the console failed at {}: {})", executor.result().failed_step,
executor.result().error, failure.failed_step, failure.failed_error);
}catch (Exception& e){
return std::format("{}: {}", e.name(), e.message());
}catch (std::exception& e){
return std::string(e.what());
}
}

private:
ReplayCase m_case;
};

} // namespace

void add_tests_AutoStory_ConsoleFailureReplay(UnitTestDatabase& database){
std::vector<ReplayCase> cases;
for (const auto& [name, text] : console_failure_json()){
cases.push_back({.input = {name, text}, .expectation = {}});
}
for (const ReplayCase& item : cases){
database.add<Test_ConsoleFailureReplay>(item);
}
}

} // namespace PokemonBDSP
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* BDSP AutoStory - Console failure replay tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests_H
#define PokemonAutomation_PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonBDSP{


// One test per fault file in ConsoleFailures/: the checkpoint it names runs
// on the story simulation with only the file's faults injected, and must pass.
void add_tests_AutoStory_ConsoleFailureReplay(UnitTestDatabase& database);


} // namespace PokemonBDSP
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
3 changes: 3 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,9 @@ file(GLOB LIBRARY_SOURCES
Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walk_Tests.h
Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.cpp
Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h
Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureData.h
Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.cpp
Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_ConsoleFailureReplay_Tests.h
Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp
Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.h
Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim.cpp
Expand Down
Loading