Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include "Pokemon/AutoStory/Pokemon_CheckpointAttempts.h"
#include "Pokemon/AutoStory/Pokemon_StoryEvents.h"
#include "Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h"
#include "Pokemon_StoryEngine.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -289,7 +290,7 @@ SegmentReport StoryEngine<PoseType>::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;
Expand Down Expand Up @@ -329,7 +330,7 @@ VerifyReport StoryEngine<PoseType>::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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const RunnerCase RUNNER_CASES[] = {
{.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"}},
{.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"}},
.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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <format>
#include <string>
#include "Pokemon/AutoStory/Pokemon_StoryOutcomeClass.h"
#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h"
#include "Pokemon_StoryStepRunner.h"

Expand Down Expand Up @@ -53,7 +54,7 @@ Outcome StoryStepRunner<PoseType>::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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "Pokemon_SceneJudges_Tests.h"
#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"
Expand All @@ -41,12 +43,14 @@


// Registers every shared AutoStory suite, for the unit test runner.
inline void add_tests_AutoStory(UnitTestDatabase& database){

Check warning on line 46 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::add_tests_AutoStory( UnitTestDatabase & database): function_lines=27 (advisory above 25, limit 50)
add_tests_AutoStorySelect(database);
add_tests_StoryRun(database);
add_tests_StoryRunCounts(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);
Expand Down
14 changes: 10 additions & 4 deletions SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Story Events

Check warning on line 1 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=578 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -8,7 +8,9 @@
#include <format>
#include <utility>
#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "Pokemon_StoryEvents.h"
#include "Pokemon_StoryOutcomeClass.h"

namespace PokemonAutomation{
namespace Pokemon{
Expand Down Expand Up @@ -80,10 +82,11 @@
return outcome;
}

Outcome outcome_failed(std::string failure, std::string detail){
Outcome outcome_failed(std::string failure, std::string detail, std::optional<StoryFailureClass> 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){
Expand Down Expand Up @@ -350,16 +353,19 @@
}
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){
Expand Down Expand Up @@ -387,7 +393,7 @@
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Story Events Tests

Check warning on line 1 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=771 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand All @@ -15,8 +15,10 @@
#include <utility>
#include <vector>
#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{
Expand Down Expand Up @@ -226,7 +228,7 @@
return true;
}

UnitTestResult test_stop_names_failed_event(){

Check warning on line 231 in SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::Pokemon::test_stop_names_failed_event(): function_lines=29 (advisory above 25, limit 50)
World world;
world.rows_off = 1;
Checkpoint checkpoint = make_checkpoint();
Expand All @@ -248,7 +250,8 @@
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());
}
Expand Down Expand Up @@ -276,6 +279,49 @@
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";
Expand Down Expand Up @@ -664,6 +710,14 @@
.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"},
Expand Down
Loading
Loading