Skip to content

BBQ Farmer: consolidate board, attempt and reroll diagnostics - #2

Closed
dayfine wants to merge 19 commits into
bbq/verified-rerollfrom
bbq/diagnostics-and-baseline
Closed

dayfine wants to merge 19 commits into
bbq/verified-rerollfrom
bbq/diagnostics-and-baseline

Conversation

@dayfine

@dayfine dayfine commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Base: bbq/verified-reroll (#8). Consolidates #27's reroll logging; child #3 adds separate local screenshot evidence. #27 is closed as redundant.

BBQLogger records board reads, attempt start/route return/result with durations, catch battle-entry timeouts, retry exhaustion and exactly one slot/quest message before each reroll attempt. Structured messages replace duplicate status lines; retry exhaustion stays red. The existing process_and_do_quest() and its dispatch switch remain in place. Inputs, retry limits, supported quest routines and reroll decisions are unchanged. Both disabled-code blocks remain disabled.

Review the logger and call sites, then the tests. RecordingLogger checks exactly-once slot/quest logging across nine reroll outcomes. Six deterministic formatter cases live beside the logger and register through add_tests_BBQ() in PokemonSV_BBQTests.cpp. Labelled arguments explain panel detection and the unknown-quest fallback. The GUI visually wraps long messages; file records remain single-line.

Legacy-size exception approved in review: retaining the existing dispatcher is preferable to a linter-driven split for this logging change. Its function grows from 131 to 135 lines; the file grows from 1452 to 1463. These are the only two code-health findings. They are explicitly accepted for this PR, not silently treated as a green code-health result. The hook was skipped only for the push applying this user-directed waiver after checking all findings; general linter policy is unchanged.

Current head 722af5ac2 removes the execution split. Whitespace checks pass; fresh native CI is running. Earlier native successes at 490c83cfa remain historical and do not replace validation of the restored layout. No console run.

@dayfine
dayfine force-pushed the bbq/quest-identity branch 2 times, most recently from bce23cd to 6c312f2 Compare October 27, 2026 01:25
@dayfine
dayfine force-pushed the bbq/diagnostics-and-baseline branch from 0ceac54 to c8ba680 Compare October 27, 2026 06:12
dayfine added a commit that referenced this pull request Oct 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine
dayfine force-pushed the bbq/diagnostics-and-baseline branch from c8ba680 to 7d24d5f Compare October 28, 2026 03:35
@dayfine
dayfine changed the base branch from bbq/quest-identity to main October 28, 2026 03:35
@dayfine dayfine closed this Oct 28, 2026
@dayfine dayfine reopened this Oct 28, 2026
dayfine and others added 2 commits October 27, 2026 23:53
A reroll's decision was logged when the panel was planned ("Reroll
selected. Rerolling quest."), with no slot or quest, and the reroll
itself logged nothing until it was verified. With two rerolls planned,
the second spent 10 BP ~30 s later with no line of its own (R5 12:45:40,
13:01:31), so log scans counted it as a reroll that was never selected.

reroll_quest(), which every slot reroll goes through, now logs
"Rerolling quest N (slug)." before it opens the panel, whatever the
result. The slug comes from BBQuests_enum_to_string(), as in the quest
reads, or is "unknown" for an undetected quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
BBQ failures are hard to attribute to a specific quest and attempt from
the existing logs. Add one-line "BBQ ..." events:

- board: panel detected and quest slugs in board order, each time
  read_quests() reads the panel
- per attempt: start, route_return and result, with attempt/limit and
  route, verification and total durations
- catch battle-entry timeout, and retry exhaustion

BBQLogger depends only on Logger and the Options/PokemonSV_BBQuests
leaf, so the quest and catch/photo modules call into it without a
dependency back. Durations use explicit steady_clock timestamps so
tests can check them without depending on wall-clock time.

Add four PokemonSV::BBQDiagnosticLogs tests to PokemonSV_BBQTests.cpp,
with a recording logger, covering board formatting, success, failure
with retry exhaustion, and long/zero durations. Controller sequences,
retry limits and reroll policy are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine
dayfine force-pushed the bbq/diagnostics-and-baseline branch from 7d24d5f to 7cf661b Compare October 28, 2026 08:08
@dayfine
dayfine changed the base branch from main to bbq/tests-file October 28, 2026 08:09
@dayfine
dayfine force-pushed the bbq/tests-file branch 2 times, most recently from bf82b48 to daa1de3 Compare October 28, 2026 20:37
dayfine and others added 2 commits October 30, 2026 07:38
@dayfine dayfine added farmer Farming programs game:sv Scarlet/Violet labels Nov 1, 2026
Merge the verified-reroll logging branch, keep the reroll outcome cases, and move diagnostic coverage to table-driven logger tests. Replace duplicate legacy status messages and preserve red retry-exhaustion severity. Native build and test execution remain pending; intended-base code health and logger C++23 syntax checks pass.
@dayfine dayfine changed the title BBQ Farmer: log quest boards and attempts BBQ Farmer: consolidate board, attempt and reroll diagnostics Nov 6, 2026
@dayfine
dayfine changed the base branch from bbq/tests-file to bbq/verified-reroll November 6, 2026 22:31
…e BBQ suite

Preserve both disabled-code blocks. Merge the execution-only prerequisite so logging can be added without unrelated dead-code deletion or worsening legacy function/file size. The prerequisite branch is locally prepared; its first publication is blocked by the hook fallback to main.
…atcher

Keep the logging-only scope requested in review. The user explicitly directed retaining and ignoring the existing legacy size: process_and_do_quest grows from 131 to 135 lines, and its file from 1452 to 1463. These are the only two code-health findings; no general linter threshold is changed.
dayfine added a commit that referenced this pull request Nov 7, 2026
Propagate the user-directed legacy-size exception when merging the dispatcher restoration from #2. Only the existing file/function size findings remain: 1467 versus 1463 lines and 138 versus 135 lines. Do not relax global linter policy or introduce dispatch refactors for this diagnostics change.
dayfine pushed a commit that referenced this pull request Nov 7, 2026
…ation#1612)

* Python: basic pybind11 interface to the microcontroller

Adds _pa_core, a pybind11 module (new PA_PYTHON_BINDINGS cmake option, OFF
by default) that wraps the existing CoreLib class
NintendoSwitch::PybindSwitchProController so Python can act as a Nintendo
Switch controller through a PABotBase2 serial device: status, queued button /
d-pad / stick commands, flush and cancel, button/d-pad constants, and
log-to-stderr/file controls. C++ exceptions surface as RuntimeError;
blocking calls release the GIL.

The pokemon_automation Python package sits on top of it:
SwitchController (button names instead of bitfields), button parsing,
list_serial_ports(), a hardware-free FakeController, a hardware self-test,
and a pytest suite. See SerialPrograms/Source/PythonBindings/README.md.

A new CI workflow builds the GUI-free core plus the module on Ubuntu and
runs the pytest suite. PR PokemonAutomation#1519 is used as a reference.

* Python: stop committing pip egg-info leftovers

* Python: switch to cancel_all_and_wait(); stop miniz.c warnings breaking CoreLib

The rebased branch picked up AbstractController::cancel_all_and_wait()
(cancel + wait for the device to acknowledge the neutral state, returns a
bool), which replaced the old fire-and-forget cancel_all_commands(). Update
the _pa_core binding, the pokemon_automation API (cancel_all_and_wait() now
returns whether the device confirmed; close() uses it to guarantee a neutral
state), the fake controller, the tests, and the docs.

Also compile the third-party 3rdParty-Core/miniz-3.1.1/miniz.c with warnings
off (/W0 on MSVC, -w on GCC/Clang): it is compiled straight into CoreLib, and
newer compilers emit warnings in it that -Werror / /WX turn into build errors.
It includes miniz.h from its own directory, so a SYSTEM include directory
cannot shield it; suppressing the file itself is the portable fix.

* Move the miniz.c warning suppression into pa_apply_base_target_properties()

The old copy in CMakeLists.txt only runs in the full build: with
PA_CORE_ONLY the configure returns before reaching it, so miniz.c was still
compiled with -Werror / /WX in core-only builds. Setting the source property
from pa_apply_base_target_properties() (cmake/CoreLib.cmake) covers both build
modes and every target that uses it; the two now-redundant copies are removed.
Use if(MSVC) instead of if(WIN32) - the flag choice follows the compiler's
command-line dialect (true for cl and for clang-cl), and COMPILE_OPTIONS
instead of the deprecated COMPILE_FLAGS.

* Put the miniz.c warning suppression in the base CMakeLists.txt, before PA_CORE_ONLY

miniz.c is compiled into every target that uses CORE_LIBRARY_SOURCES -
CoreLib in both build modes, and SerialProgramsLib in the full build (which
compiles its own copy of the core sources), so the fix belongs in the base
CMakeLists.txt, not CoreLib.cmake. It must also run before the PA_CORE_ONLY
early return, which is where the old copy at the bottom of the file (from
PokemonAutomation#1098) was, and why core-only builds still failed. Source properties are
global, so one set_source_files_properties() covers all targets; verified
that in a full build both CoreLib's and SerialProgramsLib's miniz.c compile
lines carry the suppression.

* update pybind README

* Python bindings README: small fixes

- 'simulatenously' -> 'simultaneously'
- selftest code block: [port] is not shell syntax; show the optional
  argument as a real example instead
- rename 'Running the test file' to 'Hardware self-test' (the pytest suite
  lives in tests/) and add the missing 'Running the unit tests' section,
  which the Layout section advertises but nothing in the file explained
- add wait() to the method list (it is used in the example)
- drop trailing whitespace

* more README updates

* pybind CI

* update CI

* rename selftest to controller_test

* rename files

* Python: label where the Python code references the C++ code

Add comments naming the C++ source each Python definition mirrors or
depends on (repo-relative paths): the BUTTON_BITS/DPAD_POSITIONS constants
and check_against_core() vs the enums in
NintendoSwitch_ControllerButtons.h; the ControllerBackend protocol,
status/flush/cancel_all_and_wait and press() vs
PybindSwitchProController / AbstractController; the fake and the _core
loader vs the module source and the wrapped class; and the test headers.
Also note that DEFAULT_HOLD_MS/DEFAULT_RELEASE_MS are Python-side defaults
(the C++ issue_buttons() takes explicit durations).

* minor update to switch_connection_test.py

* add comments

* minor update to switch_connection_test.py

* add comments

* Python: name SwitchController commands after the backend methods

The command methods of SwitchController now match the names of the
_p a_core.Controller methods they wrap (and thus the C++
PybindSwitchProController methods):

- press()       -> push_button() / push_dpad() (mixed combos now go to
                   controller_state(); each method rejects the other kind
                   with a pointer to the right method)
- hold()        -> controller_state() (duration_ms first, like the C++
                   signature; no implicit release wait)
- stick(side)   -> push_left_joystick() / push_right_joystick()
- flush()       -> wait_for_all_requests()
- status()      -> current_status()
- name()        -> controller_name()
- wait(), cancel_all_and_wait(), is_ready() and close() already matched.

Button-name parsing is unchanged; _pa_core and FakeController are
untouched. Updated examples in the package docstrings, README,
switch_connection_test.py and the tests (31 tests now, including
rejection of mixed inputs in push_button()/push_dpad()).

* Python: drop the repeat option from push_button()/push_dpad()

Each call now queues exactly one tap, matching the single-command
semantics of the C++ layer; repeated presses are just repeated calls
(or a controller_state() with a longer hold).

* add comments

* Python tests: add a short docstring to every test function

* add comments

* update comments

* Python tests: drop test_matches_cpp_enum, duplicate of test_python_constants_match_cpp

Both tests just call buttons.check_against_core() with the module's
BUTTONS/DPAD_POSITIONS dicts. Keep the one in test_core.py (the
compiled-module file, skipped wholesale when _pa_core is not built).

* add comments

* rename variables

* Python: follow the duration_ms/hold_ms/bitfield renames through all call sites

Two call sites still used the old push_left_joystick(duration_ms=...)
keyword, which now raises TypeError:

- the quick start in pokemon_automation/__init__.py
- the example in the README

Also rename the FakeController parameters to the new backend names
(button_bitfield, dpad_position) so it matches the ControllerBackend
protocol, and fix two stale 'delay = duration + release' docstrings in
test_fake_controller.py.

* Align pybind/Python controller API with the PBF API

Argument order now matches NintendoSwitch_Commands_PushButtons.h
(input first, then timing, no context parameter):

- push_button(button_bitfield, delay_ms, hold_ms, release_ms)
- push_dpad(dpad_position, delay_ms, hold_ms, release_ms)
- push_left_joystick(joystick_position, delay_ms, hold_ms, release_ms)
- push_right_joystick(joystick_position, delay_ms, hold_ms, release_ms)
- controller_state(button_bitfield, dpad_position, left_x, left_y,
  right_x, right_y, duration_ms)  (duration last, like pbf_controller_state)

The pybind controller keeps delay_ms (pbf_*() always uses
delay = hold + release; that combination is what the Python layer
queues). The joysticks take a single (x, y) joystick_position tuple
instead of separate x/y arguments, and the Python
push_left_joystick()/push_right_joystick() only accept coordinates
(parse_stick_position(), no direction-name strings); parse_stick()
keeps string support for controller_state()'s left/right.

* push_*_joystick(): back to separate x, y arguments

On request, the joysticks take separate x, y arguments again instead of
a single (x, y) joystick_position tuple:

- C++: push_left_joystick(x, y, delay_ms, hold_ms, release_ms)
- module: py::arg("x"), py::arg("y"), ...
- Python: sw.push_left_joystick(0.0, 1.0, hold_ms=1500)

No parsing step is needed anymore (x, y are plain numbers; the C++
binding enforces numeric types), so parse_stick_position() was removed
and parse_stick() keeps its (x, y)-pair helper for
controller_state()'s left/right.

* Python push_*_joystick(): accept an (x, y) joystick_position tuple

The Python layer now takes the stick position as a single (x, y)
tuple/list argument, joystick_position, for both push_left_joystick()
and push_right_joystick(). The pair is unpacked at the
ControllerBackend boundary, so _pa_core (and FakeController) keep the
C++-shaped separate x, y arguments:

    sw.push_left_joystick(joystick_position=(0.0, 1.0), hold_ms=1500)

The pair validator is promoted from _parse_stick_pair to a public
parse_stick_pair() (two numbers, in [-1, 1], no strings/None), reused
by parse_stick() and exported from the package.

* update comments. add kwargs

* Python controller_state(): left_joystick/right_joystick as (x, y) tuples

controller_state() now takes the sticks as (x, y) tuples, renamed from
left=/right= to left_joystick=/right_joystick= to match
push_*_joystick(). None (the default) releases the stick; direction-name
strings are no longer accepted there (parse_stick_pair() validates, so
the same error messages as joystick_position apply). The pairs are
unpacked at the ControllerBackend boundary, so _pa_core keeps the
C++-shaped separate left_x/left_y/right_x/right_y arguments.

Also tighten the joystick_position annotations from Sequence[float] to
tuple[float, float] (lists still work at runtime; the annotation now
says exactly what is expected).

* Python controller_state(): split buttons and dpad; push_dpad arg -> dpad

controller_state() now takes buttons and dpad as separate arguments,
matching pbf_controller_state() and the C++ backend
(button_bitfield, dpad_position, ...):

    sw.controller_state("B", "up", left_joystick=(0.0, 1.0), duration_ms=2000)

The buttons argument rejects d-pad directions (and the dpad argument
rejects buttons) with an error pointing at the other argument - the same
rules push_button()/push_dpad() already enforce. The one-string mixed
form ("ZL+up") is no longer accepted.

push_dpad()'s argument is renamed position -> dpad. _pa_core /
FakeController are unchanged (the backend already has them separate).

* update comments

* minor fix

* update switch_connection_test.py

* update comments

* update README

* update comments

* update comments

* update pybind CI

* PythonBindings.cmake: do not download pybind11; error with install steps

Drop the FetchContent fallback. If pybind11 is not found (system
package or pip-installed for the target interpreter), configure now
fails with a FATAL_ERROR that names the interpreter and gives the
install commands, instead of silently git-cloning a pinned pybind11
release during configure. Builds no longer reach the network on their
own. README updated to match.

* update pybind CI

* update comments

* Python bindings: fix doc typos and stale example kwargs

- controller.py: cancel_all_and_wait() docstring cited the old C++\n  parameter name (timeout_millis -> timeout_ms).\n- README: 'insid' -> 'inside', 'run the all tests' -> 'run all the tests',\n  queue examples used a nonexistent duration kwarg (now hold_ms, which is\n  what push_left_joystick() actually takes), and mkdir bin -> mkdir -p bin\n  so the instructions work on a re-run.\n- test_push_right_joystick now actually passes a [x, y] list, matching its\n  docstring (lists are accepted via parse_stick_pair).

* Fix bug: close() serialization
close() no longer lets a command slip in after the cancel: the closed
flag is set under the command lock, and every command method re-checks it
while holding the lock before sending, so commands starting while the
cancel is in flight are rejected.

* fix Empty port name: SerialPABotBase2_Descriptor::open_connection() returns
nullptr for an empty name, leaving m_connection null and crashing
current_status(). The constructor, destructor, controller() and
current_status() now tolerate a null connection ("No connection."), and
SwitchController rejects an empty port up front with a ValueError.

* Fix review bugs: destruction race, empty port

#1 Destruction race (PybindSwitchController.cpp): the connection thread is
joined only when m_connection is destroyed, i.e. after m_controller, m_cv
and m_lock already were. Destroying the controller while a connection is
still establishing (e.g. SwitchController's timeout path) let the connect
thread write to destroyed members. The destructor now resets m_connection
first, so the thread is joined before any member is destroyed.

#2 Empty port name: SerialPABotBase2_Descriptor::open_connection() returns
nullptr for an empty name, leaving m_connection null and crashing
current_status(). The constructor, destructor, controller() and
current_status() now tolerate a null connection ("No connection."), and
SwitchController rejects an empty port up front with a ValueError.

* update README

* update README

* Rename SwitchController to SwitchProController

Matches the C++ class it wraps (PybindSwitchProController) and the
device's controller type (the Pro Controller / wired controller).
No backwards-compat alias: the package is pre-release (0.1.0).

* add comments

* buttons.py: remove the BUTTON_ALIASES table

START/SELECT/L3/LS/R3/RS and the "+"/"-" spellings no longer map to
PLUS/MINUS/LCLICK/RCLICK. "+" remains a separator (a lone "+" parses to
no input), and "-" and the former alias names are now unknown buttons
with the usual ValueError. Removed the now-dead "+"/"-" special cases
in _split()/parse_buttons(), the __init__ export, and the docs; the alias
test now pins the new behavior.

* fix comment

* update comments

* minor update to error message

* update comments

* minor fixes

---------

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
Co-authored-by: jw098 <justin.wong098@gmail.com>
@dayfine

dayfine commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Superseded by consolidated Tree 1 PR #272.

@dayfine dayfine closed this Nov 9, 2026
@dayfine
dayfine deleted the bbq/diagnostics-and-baseline branch November 13, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

farmer Farming programs game:sv Scarlet/Violet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant