Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d887e93
Log one line naming the slot and quest for every BBQ reroll
dayfine Oct 23, 2026
7cf661b
Log BBQ boards and quest attempts through BBQLogger
dayfine Oct 21, 2026
bc5f592
Merge origin/bbq/verified-reroll into bbq/reroll-log-line
dayfine Oct 30, 2026
89327ce
Merge origin/bbq/tests-file into bbq/diagnostics-and-baseline
dayfine Oct 30, 2026
5b267ff
Merge bbq/tests-file into bbq/diagnostics-and-baseline
dayfine Nov 2, 2026
c7fef9a
Merge bbq/verified-reroll into bbq/reroll-log-line
dayfine Nov 2, 2026
556186c
Merge origin/bbq/verified-reroll into bbq/reroll-log-line
dayfine Nov 3, 2026
18ac703
Merge origin/bbq/tests-file into bbq/diagnostics-and-baseline
dayfine Nov 3, 2026
06da8c6
Merge origin/bbq/verified-reroll into bbq/reroll-log-line
dayfine Nov 4, 2026
2f60462
Merge origin/bbq/tests-file into bbq/diagnostics-and-baseline
dayfine Nov 4, 2026
6e9871d
Merge origin/bbq/verified-reroll into bbq/reroll-log-line
dayfine Nov 6, 2026
bba2924
Merge origin/bbq/tests-file into bbq/diagnostics-and-baseline
dayfine Nov 6, 2026
1411932
Consolidate reroll diagnostics into the canonical BBQ logger
dayfine Nov 6, 2026
57002fb
Initialize the default expected log color for Windows Clang
dayfine Nov 6, 2026
dbc3c74
Separate BBQ quest dispatch and retry execution from quest implementa…
dayfine Nov 6, 2026
be6feea
Include the environment definition used by the extracted dispatcher
dayfine Nov 6, 2026
12e2180
Clarify BBQ diagnostic arguments and register logger cases through th…
dayfine Nov 6, 2026
490c83c
Place the panel-result explanation beside the quest reader
dayfine Nov 6, 2026
722af5a
Undo linter-driven quest execution split and retain the existing disp…
dayfine Nov 7, 2026
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* BBQ Diagnostic Logger
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <sstream>
#include <string_view>
#include "Common/Cpp/PrettyPrint.h"
#include "PokemonSV_BBQLogger.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{


namespace{

constexpr std::string_view UNKNOWN = "unknown";

std::string_view quest_label(BBQuests quest){
const std::string& slug = BBQuests_enum_to_string(quest);
return slug.empty() ? UNKNOWN : std::string_view(slug);
}

void append_elapsed(std::ostream& out, std::string_view field, BBQAttemptLog::Clock::duration elapsed){
const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
out << ' ' << field << "_ms=" << milliseconds.count()
<< ' ' << field << "=\"" << duration_to_string(milliseconds) << '\"';
}

} // namespace


void BBQLogger::board(bool panel_detected, const std::vector<BBQuests>& quests){
std::ostringstream out;
out << "BBQ event=board panel_detected=" << panel_detected << " quests=";
bool first = true;
for (BBQuests quest : quests){
if (!first){
out << ',';
}
first = false;
out << quest_label(quest);
}
m_logger.log(out.str());
}

void BBQLogger::reroll_attempt(size_t slot, BBQuests quest){
m_logger.log(
"Rerolling quest " + std::to_string(slot + 1) + " (" + std::string(quest_label(quest)) + ")."
);
}

void BBQLogger::battle_entry_timeout(BBQuests quest){
std::ostringstream out;
out << "BBQ quest=" << quest_label(quest) << " event=battle_entry outcome=timeout";
m_logger.log(out.str());
}

void BBQLogger::retry_exhausted(BBQuests quest){
std::ostringstream out;
out << "BBQ quest=" << quest_label(quest) << " event=retry_exhausted recovery=skip_current_batch";
m_logger.log(out.str(), COLOR_RED);
}


BBQAttemptLog::BBQAttemptLog(
Logger& logger, BBQuests quest,
unsigned attempt, unsigned limit,
Clock::time_point start
)
: m_logger(logger), m_start(start), m_route_end(start)
{
std::ostringstream out;
out << "BBQ quest=" << quest_label(quest) << " attempt=" << attempt << " limit=" << limit;
m_attempt_description = out.str();
out << " event=start";
m_logger.log(out.str());
}

void BBQAttemptLog::route_return(Clock::time_point end){
m_route_end = end;
std::ostringstream out;
out << m_attempt_description << " event=route_return";
append_elapsed(out, "elapsed", end - m_start);
m_logger.log(out.str());
}

void BBQAttemptLog::result(bool completed, Clock::time_point end){
std::ostringstream out;
out << m_attempt_description << " event=result outcome="
<< (completed ? "absent_from_board" : "still_on_board");
append_elapsed(out, "verification", end - m_route_end);
append_elapsed(out, "total", end - m_start);
m_logger.log(out.str());
}


} // namespace PokemonSV
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* BBQ Diagnostic Logger
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonSV_BBQLogger_H
#define PokemonAutomation_PokemonSV_BBQLogger_H

#include <chrono>
#include <string>
#include <vector>
#include "Common/Cpp/Logging/AbstractLogger.h"
#include "VideoGames/PokemonSV/Options/PokemonSV_BBQuests.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{


// Formats one-line "BBQ ..." diagnostic events through an existing Logger.
// Does no image I/O and no controller input.
class BBQLogger{
public:
explicit BBQLogger(Logger& logger) : m_logger(logger) {}

// The quest board as read from one panel snapshot: whether the panel was
// detected, and the quests in board order.
void board(bool panel_detected, const std::vector<BBQuests>& quests);

// Logs a zero-based board slot before attempting its reroll, including failures.
void reroll_attempt(size_t slot, BBQuests quest);

// A catch quest gave up waiting for the battle menu after navigating to its target.
void battle_entry_timeout(BBQuests quest);

// A quest used all of its attempts and the rest of the batch will be skipped.
void retry_exhausted(BBQuests quest);

private:
Logger& m_logger;
};


// The event sequence and monotonic timing of one quest attempt.
// Timestamps default to now; tests pass fixed values.
class BBQAttemptLog{
public:
using Clock = std::chrono::steady_clock;

// Logs the start of attempt number `attempt` out of `limit`.
BBQAttemptLog(
Logger& logger, BBQuests quest,
unsigned attempt, unsigned limit,
Clock::time_point start = Clock::now()
);

// The quest routine returned; logs the time since start.
void route_return(Clock::time_point end = Clock::now());

// The board was re-read. `completed` means the quest is no longer on it.
// Logs the verification time since route_return() and the total time.
void result(bool completed, Clock::time_point end = Clock::now());

private:
Logger& m_logger;
const Clock::time_point m_start;
Clock::time_point m_route_end;
std::string m_attempt_description;
};


} // namespace PokemonSV
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/* BBQ Diagnostic Logger Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <chrono>
#include <string>
#include <utility>
#include <variant>
#include <vector>
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "PokemonSV_BBQLogger.h"
#include "PokemonSV_BBQLogger_Tests.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{
namespace{

// Captures the production Logger interface without image or controller I/O.
class BBQTestLogger : public Logger{
public:
virtual void log(const std::string& message, Color color) override{
messages.push_back(message);
colors.push_back(color);
}
std::vector<std::string> messages;
std::vector<Color> colors;
};

// One board snapshot and its detection outcome.
struct BoardLogInput{
bool panel_detected;
std::vector<BBQuests> quests;
};

// One timed attempt, including optional timeout and retry-exhaustion events.
struct AttemptLogInput{
BBQuests quest;
unsigned attempt;
unsigned limit;
std::chrono::milliseconds route_duration;
std::chrono::milliseconds verification_duration;
bool completed;
bool battle_timeout = false;
bool retry_exhausted = false;
};

// A row exercises one board read or one complete attempt event sequence.
struct DiagnosticLogInput{
std::string name;
std::variant<BoardLogInput, AttemptLogInput> event;
};

// Exact message order is part of the diagnostics contract.
struct DiagnosticLogExpectation{
std::vector<std::string> messages;
Color final_color{};
};

// Each case keeps all inputs and expected output visible together.
struct DiagnosticLogCase{
DiagnosticLogInput input;
DiagnosticLogExpectation expectation;
};

// Exercise the real formatter with a scripted board observation.
void emit_logs(Logger& logger, const BoardLogInput& input){
BBQLogger(logger).board(input.panel_detected, input.quests);
}

// Fixed monotonic timestamps make durations and event order deterministic.
void emit_logs(Logger& logger, const AttemptLogInput& input){
const BBQAttemptLog::Clock::time_point start{};
if (input.battle_timeout){
BBQLogger(logger).battle_entry_timeout(input.quest);
}
BBQAttemptLog attempt(logger, input.quest, input.attempt, input.limit, start);
attempt.route_return(start + input.route_duration);
attempt.result(input.completed, start + input.route_duration + input.verification_duration);
if (input.retry_exhausted){
BBQLogger(logger).retry_exhausted(input.quest);
}
}

// Report the first missing, unexpected or mismatched message with its index.
class Test_BBQDiagnosticLogs : public UnitTest{
public:
explicit Test_BBQDiagnosticLogs(DiagnosticLogCase test_case)
: UnitTest("PokemonSV::BBQDiagnosticLogs - " + test_case.input.name)
, m_case(std::move(test_case))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
BBQTestLogger logger;
std::visit([&](const auto& input){ emit_logs(logger, input); }, m_case.input.event);
const auto& expected = m_case.expectation.messages;
if (logger.messages.size() != expected.size()){
return "Expected " + std::to_string(expected.size()) + " log messages; read "
+ std::to_string(logger.messages.size()) + ".";
}
for (size_t index = 0; index < expected.size(); index++){
if (logger.messages[index] != expected[index]){
return "Message " + std::to_string(index) + ": expected [" + expected[index]
+ "]; read [" + logger.messages[index] + "].";
}
}
if (logger.colors.back() != m_case.expectation.final_color){
return "Final message color differs from the expected severity.";
}
return true;
}

private:
const DiagnosticLogCase m_case;
};

// Covers board order/unknown/empty output and success, exhaustion and long durations.
const DiagnosticLogCase DIAGNOSTIC_LOG_CASES[] = {
{
.input = {.name = "board-order", .event = BoardLogInput{
.panel_detected = true,
.quests = {BBQuests::photo_swim, BBQuests::sneak_up, BBQuests::auto_10},
}},
.expectation = {.messages = {
"BBQ event=board panel_detected=1 quests=photo-swim,sneak-up,auto-10",
}},
},
{
.input = {.name = "undetected-board", .event = BoardLogInput{
.panel_detected = false, .quests = {BBQuests::UnableToDetect},
}},
.expectation = {.messages = {"BBQ event=board panel_detected=0 quests=unknown"}},
},
{
.input = {.name = "empty-board", .event = BoardLogInput{
.panel_detected = true, .quests = {},
}},
.expectation = {.messages = {"BBQ event=board panel_detected=1 quests="}},
},
{
.input = {.name = "success", .event = AttemptLogInput{
.quest = BBQuests::make_tm, .attempt = 1, .limit = 2,
.route_duration = std::chrono::milliseconds(2000),
.verification_duration = std::chrono::milliseconds(500), .completed = true,
}},
.expectation = {.messages = {
"BBQ quest=make-tm attempt=1 limit=2 event=start",
"BBQ quest=make-tm attempt=1 limit=2 event=route_return elapsed_ms=2000 elapsed=\"2.000 seconds\"",
"BBQ quest=make-tm attempt=1 limit=2 event=result outcome=absent_from_board verification_ms=500 verification=\"0.500 seconds\" total_ms=2500 total=\"2.500 seconds\"",
}},
},
{
.input = {.name = "retry-exhausted", .event = AttemptLogInput{
.quest = BBQuests::catch_any, .attempt = 2, .limit = 2,
.route_duration = std::chrono::milliseconds(3345),
.verification_duration = std::chrono::milliseconds(765), .completed = false,
.battle_timeout = true, .retry_exhausted = true,
}},
.expectation = {.messages = {
"BBQ quest=catch-any event=battle_entry outcome=timeout",
"BBQ quest=catch-any attempt=2 limit=2 event=start",
"BBQ quest=catch-any attempt=2 limit=2 event=route_return elapsed_ms=3345 elapsed=\"3.345 seconds\"",
"BBQ quest=catch-any attempt=2 limit=2 event=result outcome=still_on_board verification_ms=765 verification=\"0.765 seconds\" total_ms=4110 total=\"4.110 seconds\"",
"BBQ quest=catch-any event=retry_exhausted recovery=skip_current_batch",
}, .final_color = COLOR_RED},
},
{
.input = {.name = "long-duration", .event = AttemptLogInput{
.quest = BBQuests::UnableToDetect, .attempt = 256, .limit = 256,
.route_duration = std::chrono::milliseconds(120000),
.verification_duration = std::chrono::milliseconds(0), .completed = false,
}},
.expectation = {.messages = {
"BBQ quest=unknown attempt=256 limit=256 event=start",
"BBQ quest=unknown attempt=256 limit=256 event=route_return elapsed_ms=120000 elapsed=\"2.000 minutes\"",
"BBQ quest=unknown attempt=256 limit=256 event=result outcome=still_on_board verification_ms=0 verification=\"0.000 seconds\" total_ms=120000 total=\"2.000 minutes\"",
}},
},
};

} // namespace

void add_tests_BBQDiagnosticLogs(UnitTestDatabase& database){
for (const DiagnosticLogCase& test_case : DIAGNOSTIC_LOG_CASES){
database.add<Test_BBQDiagnosticLogs>(test_case);
}
}

} // namespace PokemonSV
} // namespace NintendoSwitch
} // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* BBQ Diagnostic Logger Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonSV_BBQLogger_Tests_H
#define PokemonAutomation_PokemonSV_BBQLogger_Tests_H

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

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{

// Registers deterministic event formatting and ordering tests; no console input.
void add_tests_BBQDiagnosticLogs(UnitTestDatabase& database);

} // namespace PokemonSV
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
Loading
Loading