plugin-test

A testing guide for Zhin.js plugins using Vitest, a JavaScript and TypeScript testing framework. It focuses on checking command and tool behavior, ordinary business logic, and the plugin package’s required structure.

In plain words
What is it for?
Use it to write tests, increase coverage, verify command or agent-tool execution, test package exports and manifests, and run the project’s test or coverage commands.
Why use it?
It helps test the parts of a plugin directly without the cost of starting a complete bot. It also keeps tests aligned with the current Plugin Runtime instead of older lifecycle APIs.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/zhinjs/zhin/plugin-test
Any agent
npx skills add zhinjs/zhin --skill plugin-test
Clone the repo
git clone --depth 1 https://github.com/zhinjs/zhin

Made for: Claude Code, Codex.

Per session 51 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 855 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00051 $0.00855
Opus 5 $0.00026 $0.00428
Sonnet 5 $0.00010 $0.00171
Haiku 4.5 $0.00005 $0.00085

Measured 2d ago against content hash 06b03069c589, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

plugin-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

packages/toolkit/create-zhin/template/skills/plugin-test/SKILL.md · 107 lines

How it starts

The opening of the file, as written. The whole thing — 107 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Zhin 插件测试(Plugin Runtime)

为 Plugin Runtime 插件写 Vitest 测试。不要再测 new Plugin('/path') / usePlugin / MessageCommand 旧生命周期——CLI 路径是 zhin runtime start

适用场景

  • 「帮我写测试」「增加覆盖率」「测试这个命令」
  • 新功能配套测试、发布前验证

环境

pnpm test
pnpm test:watch
pnpm test:coverage

全局 API 已注入(describe / it / expect / vi)。根 vitest.config.tsglobals: true,匹配 **/*.test.ts

优先测什么

层级 测什么 怎么测
命令逻辑 defineCommandexecute 直接调用 definition,传入 mock params/args/input
工具逻辑 defineAgentToolexecute 同上,mock inputSchema 入参
纯函数 / 服务 业务模块 普通单元测,不碰 Runtime
装配契约 package zhin manifest、default export 轻量:import default 是 PluginDefinition

集成级「起完整 bot」成本高;优先单测 execute。需要端到端时用 examples/minimal-bot / Sandbox 手测,或仓库已有 Runtime 测试 helper(搜 definePlugin / PluginScope 相关测试)。

模板:命令 execute

import { describe, it, expect } from 'vitest';
import hello from '../commands/hello.js';

describe('commands/hello', () => {
  it('returns greeting', async () => {
    const result = await hello.execute({
      params: {},
      args: [],
      input: { $content: 'hello' },
      config: {},
    } as never);
    expect(result).toBe('Hello!');
  });
});

带参数的命令对 params.name 断言即可。

模板:工具 execute

import { describe, it, expect } from 'vitest';
import weather from '../tools/get_weather.js';

describe('tools/get_weather', () => {
  it('formats city weather', async () => {
    const text = await weather.execute({ city: '上海' }, {} as never);
    expect(text).toContain('上海');
  });
});

禁止

// ❌ 旧经典 Plugin 生命周期
import { Plugin } from '@zhin.js/core'
root = new Plugin('/test/root.ts')
plugin = new Plugin('/plugins/my-plugin/src/index.ts', root)

// ❌ 依赖 usePlugin / MessageCommand 的测试

验证清单

  • pnpm --filter <pkg> test 通过
  • 新命令/工具有至少一条正向用例
  • 边界(缺参、空串)按需求覆盖
  • 不引入对 zhin.js/node / bootstrapNode 的依赖

输出格式

## 测试摘要
- 覆盖:`commands/...` / `tools/...`
- 命令:`pnpm --filter <pkg> test`

Read the full file on GitHub · 107 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 107 lines · 51 tokens per session scan A 06b03069c589

Subscribe to this mod's changes

plugin-test is a skill published in the GitHub repository zhinjs/zhin (135 stars, last pushed 5d ago), licensed MIT. It adds 51 tokens to every session and 855 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

test-driven-development

TDD: enforce RED-GREEN-REFACTOR, tests before code.

mateaix/mateclaw · 20 tokens

coding

Use when five specialized coding agents (linter, perf, refactor, security, test) that enforce quality gates across the development lifecycle. From lint enforcement through performance profiling, refactoring, security auditing, and test coverage. Use when working with coding agents.

oyi77/1ai-skills · 54 tokens

build-monetized-app

Use when the task is building a new app on Eliza Cloud that earns money — chat apps, agent apps, MCP-backed tools, anything that calls the cloud's chat/messages/inference endpoints on behalf of users. Covers app registration, container deploy, markup configuration, affiliate header, app charge requests, x402 payment…

elizaOS/eliza · 126 tokens

contribute-to-eliza

Finish and prove a scoped elizaOS GitHub issue, or independently review and repair an open elizaOS pull request. Use when contributing compute to elizaOS by selecting unclaimed work, implementing or reviewing changes, adding real tests and evidence, validating artifacts, or preparing a contribution for maintainer…

elizaOS/eliza · 68 tokens

discord

Use when you need to control Discord from Otto via the discord tool: send messages, react, post or upload stickers, upload emojis, run polls, manage threads/pins/search, create/edit/delete channels and categories, fetch permissions or member/role/channel info, set bot presence/activity, or handle moderation actions in…

elizaOS/eliza · 70 tokens

eliza-cloud-buy-domain

Use whenever a user wants to register or buy a custom domain for an Eliza Cloud app — including in the same request as building the app ("build me X and put it on Y.com"). Uses Cloudflare as registrar after explicit user confirmation, paid from the user's existing cloud credit balance. Pairs with build-monetized-app…

elizaOS/eliza · 125 tokens