Add unit tests for the MCP prompt and tool zod schemas

Open Beginner friendly
#458 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
testing

Research direction

Start in lib/assistant.js and find how loadMCP() registers the explain_flow prompt and predict_next tool; then inspect the existing test setup for its in-process client. Add the accepted and rejected input cases listed in the issue, checking rejection without asserting error wording. Done when the tests catch the reported schema-key regression and pass with zod 3.25.x and 4.x.

Written by the indexing model from the issue text.

Description

Description

The explain_flow prompt and predict_next tool schemas in lib/assistant.js have no unit test coverage. A broken schema key went unnoticed because CI stayed green: [z.string()]: z.any() in the predict_next sourceNode schema creates a literal "[object Object]" key, which became required under zod 4 and made every call fail (fixed in #456).

Proposal

Add tests that call the registered prompt and tool through the in-process client returned by loadMCP():

  1. predict_next accepted: minimal sourceNode, sourceNode with extra properties, with and without flow, sourcePort 0 and above.
  2. predict_next rejected: missing sourceNode, missing or non-string id, flow item without id, non-number sourcePort.
  3. explain_flow accepted: a valid node array, and the 23 and 100000 character bounds.
  4. explain_flow rejected: missing nodes, not starting with [ or ending with ], 22 and 100001 characters.
  5. Wording: assert on rejection, not on error message text, so tests survive zod major upgrades.

Acceptance

Tests fail when a key like the one in #456 is reintroduced, and pass on both zod 3.25.x and 4.x.

Dominant language
JavaScript
Stars
6
Forks
5
Avg merge
1d 5m
Merged PRs (30d)
29

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from FlowFuse/nr-assistant

All issues in FlowFuse/nr-assistant

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.