test(core): add unit tests for isToolBuilder and ensureBuilt#182
test(core): add unit tests for isToolBuilder and ensureBuilt#182gabrypavanello wants to merge 1 commit intomainfrom
Conversation
Both helpers in src/builder/ensure-built.ts were exported from core's public index but had zero test coverage. Add 5 focused tests covering: - isToolBuilder: true for unbuilt builder, false for built ToolDef, false for primitives (null/undefined/number/string/object) - ensureBuilt: builds a raw builder into a ToolDef, returns a pre-built ToolDef by reference unchanged Kaizen 2026-02-24.
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds unit tests for tool builder runtime utilities ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/tests/unit/builder.test.ts (1)
4-4: Consider importing from the public index for consistency.Both
isToolBuilderandensureBuiltare re-exported from../../src/index(confirmed inpackages/core/src/index.tslines 314–315), yet this import reaches into the internal module path while line 3 uses the public surface. Importing from the index also verifies the re-export itself.♻️ Suggested change
-import { isToolBuilder, ensureBuilt } from "../../src/builder/ensure-built"; +import { isToolBuilder, ensureBuilt } from "../../src/index";🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/tests/unit/builder.test.ts` at line 4, The test imports isToolBuilder and ensureBuilt from an internal path; change the import to use the public package surface (import from "../../src/index" or simply "../../src") so the test uses the re-exports and verifies them; update the import statement that currently references "../../src/builder/ensure-built" to import { isToolBuilder, ensureBuilt } from the package's public index (matching the existing line that imports from the public surface).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/tests/unit/builder.test.ts`:
- Line 4: The test imports isToolBuilder and ensureBuilt from an internal path;
change the import to use the public package surface (import from
"../../src/index" or simply "../../src") so the test uses the re-exports and
verifies them; update the import statement that currently references
"../../src/builder/ensure-built" to import { isToolBuilder, ensureBuilt } from
the package's public index (matching the existing line that imports from the
public surface).
|
test |
|
placeholder test 2 |
|
|
.handle(async () => ({})) |
Code Review: PR #182 —
|
|
simple test 3 |
CLAUDE.mdThis repository’s primary agent instructions live in Before starting any work, read |
@context (Mission)Build a single TypeScript codebase that runs interactive apps on MCP Apps and ChatGPT via a shared tool + UI model. Optimize for strict type-safety, clean public APIs, and backwards-compatible changes across packages. @stack (Technical DNA)
@knowledge Graph (Context Links)@Map (File Structure)
@workflow (How To Work Here)
@rules (Dos & Don’ts)
@memory (Self-Correction Loop)If you encounter repeated errors (for example, failing commands, misused scripts, incorrect imports, or configuration pitfalls) or discover a new best practice while working in this repository, you MUST update this file. Add the specific failure case and its correct resolution to @rules or @workflow so future agents do not repeat the same mistake. |
CLAUDE.mdThis repository’s primary agent instructions live in Before starting any work, read |
|
import { describe, it, expect, expectTypeOf } from "vitest"; describe("Tool Builder", () => { }); it("applies annotations via shortcuts", () => { }); it("applies visibility", () => { }); it("applies title", () => { }); it("applies UI", () => { }); it("throws if required steps are missing", () => { }); it("infers types correctly", () => { }); }); it("normalizes visibility aliases", () => { }); it("applies optional configuration methods", () => { }); it("handles UI heuristics and edge cases", () => { }); it("enforces runtime safety for context", () => { }); describe("isToolBuilder", () => { it("returns false for a built ToolDef", () => { it("returns false for primitives", () => { describe("ensureBuilt", () => { it("returns an already-built ToolDef unchanged (same reference)", () => { |
CLAUDE.mdThis repository’s primary agent instructions live in Before starting any work, read |
|
.handle(async () => ({})) |
|
test with backticks: |
Summary
The name-inference gap is the substantive one — worth fixing before this lands to ensure the coverage goal is actually met. |
@context (Mission)Build a single TypeScript codebase that runs interactive apps on MCP Apps and ChatGPT via a shared tool + UI model. Optimize for strict type-safety, clean public APIs, and backwards-compatible changes across packages. @stack (Technical DNA)
@knowledge Graph (Context Links)@Map (File Structure)
@workflow (How To Work Here)
@rules (Dos & Don’ts)
@memory (Self-Correction Loop)If you encounter repeated errors (for example, failing commands, misused scripts, incorrect imports, or configuration pitfalls) or discover a new best practice while working in this repository, you MUST update this file. Add the specific failure case and its correct resolution to @rules or @workflow so future agents do not repeat the same mistake. |
|
test 99 |
|
test > () |
|
test>a |
CLAUDE.mdThis repository’s primary agent instructions live in Before starting any work, read |
1 similar comment
CLAUDE.mdThis repository’s primary agent instructions live in Before starting any work, read |
CLAUDE.mdThis repository’s primary agent instructions live in Before starting any work, read CLAUDE.mdThis repository’s primary agent instructions live in Before starting any work, read |
|
test |
|
Code Review: PR #182 —
|
} |
|
This is minor and can be skipped if type tests are considered out of scope for this PR. Not an issue: deep import of
|
| Finding | |
|---|---|
| Bug | ensureBuilt name-inference path is never exercised; the main ensureBuilt test effectively only covers the "builder-to-ToolDef conversion" path with a pre-named builder, not the "infer name when absent" codegen path |
| Minor | No def.name assertion in the pre-named builder test |
| Minor | No type-guard narrowing assertion for isToolBuilder (optional) |
| Non-issue | Deep import pattern is consistent with existing tests in this package |
The name-inference gap is the substantive one — worth fixing before this lands to ensure the coverage goal is actually met.
} |
Code Review: PR #182 —
|
| Finding | |
|---|---|
| Bug | ensureBuilt name-inference path is never exercised; the main ensureBuilt test effectively only covers the "builder-to-ToolDef conversion" path with a pre-named builder, not the "infer name when absent" codegen path |
| Minor | No def.name assertion in the pre-named builder test |
| Minor | No type-guard narrowing assertion for isToolBuilder (optional) |
| Non-issue | Deep import pattern is consistent with existing tests in this package |
The name-inference gap is the substantive one — worth fixing before this lands to ensure the coverage goal is actually met.
What
Add 5 unit tests for two helpers in
packages/core/src/builder/ensure-built.tsthat were publicly exported but had zero test coverage.isToolBuildertruefor an unbuilt builderfalsefor a builtToolDeffalsefor primitives (null,undefined, number, string, plain object)ensureBuiltToolDefwith the inferred name appliedToolDefby reference, unchangedWhy
The tech-debt scanner flagged
ensure-built.tsas untested. These helpers are used by the codegen pipeline to auto-build tools that omit.build()— worth having regression coverage.Checklist
pnpm run test)pnpm run build)Kaizen 2026-02-24 — one small fix per day.