Skip to content

Conversation

@minggangw
Copy link
Member

@minggangw minggangw commented May 20, 2025

Adds support for querying node names with enclaves and retrieving a node’s fully qualified name.

  • Introduce getNodeNamesAndNamespacesWithEnclaves() and getFullyQualifiedName() in the JS API
  • Implement optional enclave retrieval and new fully qualified name binding in C++
  • Add corresponding unit and type-check tests

Fix: #1139

@minggangw minggangw requested a review from Copilot May 20, 2025 05:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds two new Node APIs—one to retrieve node names with their enclaves and another to get a node’s fully qualified name—along with the necessary bindings and tests.

  • Extend C++ bindings to support an “enclaves” flag in getNodeNames and expose getFullyQualifiedName.
  • Add JS wrapper methods getNodeNamesAndNamespacesWithEnclaves and getFullyQualifiedName.
  • Add corresponding TypeScript and runtime tests for the new methods.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

File Description
test/types/index.test-d.ts Added type assertions for getNodeNamesAndNamespacesEnclaves() and getFullyQualifiedName()
test/test-node.js Added runtime tests for the two new methods
src/rcl_node_bindings.cpp Updated GetNodeNames to accept an enclaves flag and added GetFullyQualifiedName binding
lib/node.js Introduced JS methods getNodeNamesAndNamespacesWithEnclaves and getFullyQualifiedName
Comments suppressed due to low confidence (1)

test/types/index.test-d.ts:70

  • Ensure you have a matching TypeScript declaration for NodeNamesQueryResultWithEnclaves (including the enclave field) in your .d.ts files so this test compiles.
expectType<rclnodejs.NodeNamesQueryResultWithEnclaves[]>

expectType<string[]>(node.getNodeNames());
expectType<rclnodejs.NodeNamesQueryResult[]>(node.getNodeNamesAndNamespaces());
expectType<rclnodejs.NodeNamesQueryResultWithEnclaves[]>(
node.getNodeNamesAndNamespacesEnclaves()
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method name mismatch: the implementation and JS wrapper use getNodeNamesAndNamespacesWithEnclaves(), so this test should call that exact name.

Suggested change
node.getNodeNamesAndNamespacesEnclaves()
node.getNodeNamesAndNamespacesWithEnclaves()

Copilot uses AI. Check for mistakes.

Napi::Value GetNodeNames(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();

Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate info.Length() >= 2 and that info[1] is a Boolean before accessing it to prevent out-of-bounds or type errors in the binding.

Suggested change
if (info.Length() < 2 || !info[1].IsBoolean()) {
Napi::TypeError::New(env, "Expected at least two arguments, with the second being a Boolean.")
.ThrowAsJavaScriptException();
return env.Null();
}

Copilot uses AI. Check for mistakes.
@minggangw minggangw requested a review from Copilot May 20, 2025 05:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for querying node names with enclaves and retrieving a node’s fully qualified name.

  • Introduce getNodeNamesAndNamespacesWithEnclaves() and getFullyQualifiedName() in the JS API
  • Implement optional enclave retrieval and new fully qualified name binding in C++
  • Add corresponding unit and type-check tests

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

File Description
test/types/index.test-d.ts Added type tests for the new enclave query and fully qualified name methods
test/test-node.js Added runtime tests for getNodeNamesAndNamespacesWithEnclaves and getFullyQualifiedName
src/rcl_node_bindings.cpp Extended GetNodeNames to optionally fetch enclaves; implemented GetFullyQualifiedName
lib/node.js Wrapped the new bindings as getNodeNamesAndNamespacesWithEnclaves and getFullyQualifiedName

expectType<string[]>(node.getNodeNames());
expectType<rclnodejs.NodeNamesQueryResult[]>(node.getNodeNamesAndNamespaces());
expectType<rclnodejs.NodeNamesQueryResultWithEnclaves[]>(
node.getNodeNamesAndNamespacesEnclaves()
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test calls getNodeNamesAndNamespacesEnclaves(), but the actual method is named getNodeNamesAndNamespacesWithEnclaves(). Update the test to use the correct method name.

Suggested change
node.getNodeNamesAndNamespacesEnclaves()
node.getNodeNamesAndNamespacesWithEnclaves()

Copilot uses AI. Check for mistakes.
RCL_RET_OK,
rcl_get_node_names(node, allocator, &node_names, &node_namespaces),
"Failed to get_node_names.");
if (get_enclaves) {
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The error message used here is generic ("Failed to get_node_names."). Consider updating it to something like "Failed to get node names with enclaves." to clarify which branch failed.

Copilot uses AI. Check for mistakes.
lib/node.js Outdated
Comment on lines 1622 to 1624
* Get the fully qualified name of the node.
*
* @returns {string} - Return String containing the fully qualified name of the node.
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The JSDoc comment for getFullyQualifiedName can be simplified for clarity. For example:

/**
 * @returns {string} Fully qualified node name.
 */
Suggested change
* Get the fully qualified name of the node.
*
* @returns {string} - Return String containing the fully qualified name of the node.
* @returns {string} Fully qualified node name.

Copilot uses AI. Check for mistakes.
@coveralls
Copy link

coveralls commented May 20, 2025

Coverage Status

coverage: 84.763% (+0.02%) from 84.747%
when pulling a387aa2 on minggangw:fix-1139
into 711e42a on RobotWebTools:develop.

@minggangw minggangw merged commit 4405557 into RobotWebTools:develop May 20, 2025
14 checks passed
minggangw added a commit that referenced this pull request May 23, 2025
Adds support for querying node names with enclaves and retrieving a node’s fully qualified name.

- Introduce `getNodeNamesAndNamespacesWithEnclaves()` and `getFullyQualifiedName()` in the JS API  
- Implement optional enclave retrieval and new fully qualified name binding in C++  
- Add corresponding unit and type-check tests

Fix: #1139
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.

Add missing methods for node

2 participants