feat(utils): add n-ary tree LCA utility#1716
Conversation
Test Coverage ReportChanged files have no coverage data (not instrumented or no tests ran). |
Greptile SummaryThis PR introduces the
Confidence Score: 5/5Safe to merge — new utility package is self-contained, the LCA algorithm is correct for the documented use case, and the core Vitest alias fix is a targeted, low-risk change. The LCA implementation is logically sound for unique-value trees, the test suite covers the documented edge cases, and the core config change only affects test-time module resolution. No changes touch runtime session logic or any shared critical path. No files require special attention beyond the package naming and Vitest version questions already discussed in prior threads.
|
| Filename | Overview |
|---|---|
| packages/utils/src/nary-lca.ts | New post-order DFS LCA implementation; correct for unique-value trees, but hits.length >= 2 heuristic silently misbehaves when duplicate node values are present (already flagged in prior thread) |
| packages/utils/src/tests/nary-lca.test.ts | Good coverage of common cases (ancestors, roots, nulls, single-node), though no test for val1===val2 when both are absent from the tree (code handles it correctly, just untested) |
| packages/core/vitest.config.ts | Adds top-level resolve.alias for @aoagents/ao-core sub-paths so plugin source files loaded by integration tests can resolve core imports back to TypeScript source without needing circular devDeps |
| packages/utils/package.json | New workspace package; uses @composio/ scope (inconsistent with @aoagents/ convention) and vitest ^4.0.18 (consistent with core but not plugins — both concerns flagged in prior thread) |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["findLCA(root, val1, val2)"] --> B["dfs(node)"]
B --> C{node === null?}
C -- yes --> D["return null"]
C -- no --> E["recurse into all children\ncollect non-null results in hits[]"]
E --> F{node.val === val1\nor val2?}
F -- yes --> G["set found1/found2\nreturn node\n(self is LCA or signal)"]
F -- no --> H{hits.length >= 2?}
H -- yes --> I["return node\n(LCA: two targets\nin separate subtrees)"]
H -- no --> J["return hits[0] ?? null\n(propagate single found node)"]
G --> K["candidate = dfs(root)"]
I --> K
J --> K
D --> K
K --> L{found1 && found2?}
L -- no --> M["return null\n(one or both targets absent)"]
L -- yes --> N["return candidate"]
Reviews (3): Last reviewed commit: "test: stabilize core plugin integration ..." | Re-trigger Greptile
eea06f0 to
c6eddb0
Compare
Adds @composio/ao-utils package with findLCA() — post-order DFS implementation that correctly handles ancestor-is-LCA, same-node, and missing-value cases. All 11 tests pass. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
c6eddb0 to
b5e3cd8
Compare
Summary
Validation
Follow-up/replacement for #1712 and #1713.