Skip to content

bug: tool.registry test fails on CI — custom tool import crashes registry when dependencies are missing #12269

Closed

Description

@mguttmann

Description

The test tool.registry > loads tools with external dependencies without crashing introduced in #12227 (556adad67) fails deterministically on CI:

error: Cannot find package 'cowsay' from '/tmp/opencode-test-xxx/.opencode/tools/cowsay.ts'
(fail) tool.registry > loads tools with external dependencies without crashing [269.71ms]

This blocks all PRs targeting dev — the test (linux) check fails with 881 pass / 1 fail.

Root cause

Two issues:

  1. No error handling in ToolRegistry.state() — await import(match) on line 44 of registry.ts throws when a custom tool has unresolvable dependencies, crashing the entire registry initialization instead of gracefully skipping the broken tool.

  2. Test expects successful load without installing deps — the test creates a package.json with cowsay dependency but the dependency is never installed in the temp directory. Config.waitForDependencies() doesn't trigger the install in the test context. The test then asserts expect(ids).toContain("cowsay") which fails because the import throws.

Impact

Every PR targeting dev fails the test (linux) CI check. This started after #12227 was merged.

Suggested fix

  1. Wrap the import(match) in registry.ts with try/catch — log a warning and skip tools that fail to import
  2. Update the test expectation to not.toContain("cowsay") since the test name says "without crashing" (testing resilience, not successful loading)

PR with fix: incoming

Activity

  1. wlioi commented on Feb 5, 2026

    @wlioi

    Related Issue: Zod TypeError in Custom Tools (#12336)

    I reported a separate but related issue (#12336) about Zod schema validation failures when loading custom tools from the .opencode directory.

    Summary of #12336

    • Error: TypeError: undefined is not an object (evaluating 'schema._zod.def')
    • Location: src/session/prompt.ts:704:62 (in resolveTools)
    • Root cause: Zod 4.1.8 toJSONSchema function lacks defensive checks when processing nested basic types like ZodString/ZodNumber
    • Trigger: Using @opencode-ai/plugin tool() function with Zod schema args

    Connection to this issue

    Both issues involve custom tool loading failures:

    Suggestion

    Consider adding comprehensive error handling for custom tool loading that covers:

    1. Dependency resolution (your PR)
    2. Schema validation (needs separate fix)

    The issue occurs when OpenCode internally calls z.toJSONSchema(item.parameters) during tool resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions