Skip to content

cleanup validateHandlePathExists#26469

Open
CraigMacomber wants to merge 3 commits intomicrosoft:mainfrom
CraigMacomber:validateHandlePathExists
Open

cleanup validateHandlePathExists#26469
CraigMacomber wants to merge 3 commits intomicrosoft:mainfrom
CraigMacomber:validateHandlePathExists

Conversation

@CraigMacomber
Copy link
Contributor

Description

cleanup validateHandlePathExists

Reviewer Guidance

The review process is outlined on this wiki page.

Copilot AI review requested due to automatic review settings February 18, 2026 03:58
@CraigMacomber CraigMacomber requested a review from a team as a code owner February 18, 2026 03:58
const pathParts = handle.split("/").slice(1);
const currentPath = pathParts[0];
let found = false;
for (const [key, summaryObject] of Object.entries(summaryTree.tree)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looping over all the keys of an object to find currentPath is a very silly way to find a given key on an object. Now I just use the [] operator.

Comment on lines 178 to 185
assert(
summaryObject.type === SummaryType.Tree || summaryObject.type === SummaryType.Handle,
`Handle path ${currentPath} should be for a subtree or a handle`,
currentObject.type === SummaryType.Handle,
`Handle path ${handle} should be for a subtree or a handle`,
);
if (summaryObject.type === SummaryType.Tree) {
validateHandlePathExists(`/${pathParts.slice(1).join("/")}`, summaryObject);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the way this if and assert were structured needlessly checked the Tree case twice, and also silently ignored the case when the path resolved to a handle and there was still more path to check. I have refactored this and added an assert.fail in the unhandled case to fail tests instead of silently not validating paths inside handles.

Copy link
Contributor

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 refactors the validateHandlePathExists helper function in a test file to simplify the logic for validating handle paths in summary trees. The refactoring replaces a recursive implementation with an iterative approach that uses a loop and explicit type checking.

Changes:

  • Replaced recursive implementation with iterative loop-based approach
  • Converted JSDoc comment to single-line comments
  • Added explicit validation that handle paths start with "/" and contain at least one segment
  • Simplified the tree traversal logic with clearer type guards

);
}
}
assert(found, `Handle path ${currentPath} not found in summary tree`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These asserts are needlessly hard to interpret as they only contain a single element of the path. I have rewritten the function to be iterative instead of recursive so the whole path is in scope for better error, and we avoid splitting the string again at every level.

* The handle path is split by "/" into pathParts where the first element should exist in the root
* of the summary tree, the second element in the first element's subtree, and so on.
*/
const pathParts = handle.split("/").slice(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if there was part of the path before the first slash, this silently ignored it, which seems wrong, so I assert instead.

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.

1 participant

Comments