Skip to content

Add scripted return status support for TestNode mocks#1169

Merged
facontidavide merged 1 commit into
masterfrom
feature/testnode-return-status-script
Jul 15, 2026
Merged

Add scripted return status support for TestNode mocks#1169
facontidavide merged 1 commit into
masterfrom
feature/testnode-return-status-script

Conversation

@facontidavide

Copy link
Copy Markdown
Collaborator

Summary

Rebased and cleaned-up version of #1125 by @pepeRossRobotics (original authorship preserved on the commit).

Adds return_status_script to TestNodeConfig, so a mock's completion status can be computed at runtime from blackboard state instead of being fixed. When set, it takes precedence over return_status, may reference the NodeStatus names (SUCCESS/FAILURE/…), and is rejected if it resolves to IDLE.

Also adds JSON validation rejecting a config with neither return_status nor return_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_script and the enum-resolution tests (#1166) landed on master, and its branch carried merge commits plus some unrelated edits. This branch:

  • Linearizes the 4 original commits into one (the Windows-cmake commit became empty after conflict resolution and was dropped), preserving @pepeRossRobotics's authorship.
  • Drops the changes that only came in from master via 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.
  • Reverts the unrelated gtest_wakeup.cpp edits so the file is identical to master (keeping the Fixes WakeUp test flakiness #1164 steady_clock flakiness fix).

Reconciliation with #1166

The original change injected the NodeStatus enum 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 NodeStatus names are injected only into the return_status_script environment (built at runtime from config().enums). success_script/failure_script/post_script keep evaluating against the node's own enums, exactly as before. The feature needs the status names only in return_status_script, so nothing is lost.

Test plan

  • cmake -S . -B build -DBTCPP_EXAMPLES=ON && cmake --build build — clean.
  • Full suite: 509/509 pass, including the 2 post_script enum tests from test(test_node): cover script enum resolution #1166 and the 5 new return_status_script tests.
  • t15_nodes_mocking_strict_failure builds and runs.
  • clang-format-21 clean on all touched files.

🤖 Generated with Claude Code

@facontidavide facontidavide force-pushed the feature/testnode-return-status-script branch from 284e62c to a191c15 Compare July 15, 2026 13:37
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>
@facontidavide facontidavide force-pushed the feature/testnode-return-status-script branch from a191c15 to 3e68a16 Compare July 15, 2026 14:16
@sonarqubecloud

Copy link
Copy Markdown

@facontidavide facontidavide merged commit c3ffb7f into master Jul 15, 2026
16 of 17 checks passed
@facontidavide facontidavide deleted the feature/testnode-return-status-script branch July 15, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants