Add scripted return status support for TestNode mocks#1169
Merged
Conversation
284e62c to
a191c15
Compare
Introduce `return_status_script` on TestNodeConfig, allowing a mock's completion status to be computed at runtime from blackboard state instead of being fixed. When set, it takes precedence over `return_status`; it may reference the NodeStatus names (SUCCESS/FAILURE/...) and is rejected if it resolves to IDLE. The NodeStatus enum names are injected only into the return_status_script environment. The pre-existing success_script/failure_script/post_script continue to evaluate against the node's own enums, so a blackboard entry named like a status (e.g. "SUCCESS") is not shadowed. To pay the ABI break only once, TestNode's state is moved behind a PImpl, so future changes to it no longer alter the layout consumers link against (mirroring StatusChangeLogger). The new return_status_script field is appended at the end of TestNodeConfig, preserving the byte offsets of the existing fields. Also add JSON validation rejecting a TestNodeConfig with neither a return_status nor a return_status_script, and a tutorial example (t15_nodes_mocking_strict_failure) demonstrating the strict-failure flow. Addresses #995. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
a191c15 to
3e68a16
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Rebased and cleaned-up version of #1125 by @pepeRossRobotics (original authorship preserved on the commit).
Adds
return_status_scripttoTestNodeConfig, so a mock's completion status can be computed at runtime from blackboard state instead of being fixed. When set, it takes precedence overreturn_status, may reference theNodeStatusnames (SUCCESS/FAILURE/…), and is rejected if it resolves toIDLE.Also adds JSON validation rejecting a config with neither
return_statusnorreturn_status_script, and a tutorial example (t15_nodes_mocking_strict_failure) demonstrating the strict-failure flow.Addresses #995.
What changed vs #1125
#1125 was written before
success_script/failure_script/post_scriptand the enum-resolution tests (#1166) landed onmaster, and its branch carried merge commits plus some unrelated edits. This branch:mastervia merge commits (convert_impl.hpp,safe_any.hpp,xml_parsing.cpp,tree_node.cpp,gtest_basic_types.cpp,gtest_ports.cpp), leaving just the feature.gtest_wakeup.cppedits so the file is identical tomaster(keeping the Fixes WakeUp test flakiness #1164steady_clockflakiness fix).Reconciliation with #1166
The original change injected the
NodeStatusenum names into the script environment for every TestNode script. That broke the semantics locked by #1166: a blackboard entry named like a status (e.g.SUCCESS) got shadowed by the enum, and registered scripting enums were lost.Fix: the
NodeStatusnames are injected only into thereturn_status_scriptenvironment (built at runtime fromconfig().enums).success_script/failure_script/post_scriptkeep evaluating against the node's own enums, exactly as before. The feature needs the status names only inreturn_status_script, so nothing is lost.Test plan
cmake -S . -B build -DBTCPP_EXAMPLES=ON && cmake --build build— clean.post_scriptenum tests from test(test_node): cover script enum resolution #1166 and the 5 newreturn_status_scripttests.t15_nodes_mocking_strict_failurebuilds and runs.clang-format-21clean on all touched files.🤖 Generated with Claude Code