testing-with-api-mocks — ai-security testing-with-api-mocks, toolhive-studio, community, ai-security, ide skills, continue, copilot, developer-tools, mcp-client, model-context-protocol

v1.0.0

关于此技能

非常适合需要使用MSW进行自动API模拟的高效测试的AI代理 Start here for all API mocking in tests. Covers auto-generation, fixtures, and when to use other skills. Required reading before creating, refactoring, or modifying any test involving API calls.

# 核心主题

stacklok stacklok
[116]
[13]
更新于: 3/3/2026

Killer-Skills Review

Decision support comes first. Repository text comes second.

Reference-Only Page Review Score: 4/11

This page remains useful for operators, but Killer-Skills treats it as reference material instead of a primary organic landing page.

Concrete use-case guidance Explicit limitations and caution
Review Score
4/11
Quality Score
49
Canonical Locale
en
Detected Body Locale
en

非常适合需要使用MSW进行自动API模拟的高效测试的AI代理 Start here for all API mocking in tests. Covers auto-generation, fixtures, and when to use other skills. Required reading before creating, refactoring, or modifying any test involving API calls.

核心价值

赋予代理简化MCP服务器和ToolHive应用程序的开发过程的能力,通过使用MSW创建自动生成的基于模式的模拟,从而实现API端点的高效测试并减少开发时间

适用 Agent 类型

非常适合需要使用MSW进行自动API模拟的高效测试的AI代理

赋予的主要能力 · testing-with-api-mocks

自动化API模拟生成用于测试
简化MCP服务器的开发过程
使用自动生成的模拟高效地测试ToolHive应用程序

! 使用限制与门槛

  • 需要MSW(模拟服务工作者)设置
  • 仅限于具有现有模式的API端点

Why this page is reference-only

  • - Current locale does not satisfy the locale-governance contract.
  • - The page lacks a strong recommendation layer.
  • - The underlying skill quality score is below the review floor.

Source Boundary

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

精选合集复核

这个技能已进入哪些精选合集的复核范围

这部分展示的是 Killer-Skills 如何在精选合集里收录、复核和维护这个技能,帮助你看到它在真实选择路径中的位置,而不只是继续放大上游 README。

已复核合集

优先安装的开发工作流工具

复核于 2026-04-17

已于 2026-04-17 按编码工作流适配度、安装清晰度、评审与测试价值以及发布护栏完成复核。现在这页被重新定位为“安装优先”的开发工作流入口,而不是模糊的工具盘点。

之所以优先强化这页,是因为带着开发意图进来的用户,通常需要的是一套能先安装、验证,并在真实编码闭环里证明可用的工具链,再决定是否在团队内标准化。

收录 12 项 由 Killer-Skills 编辑审查流程维护,重点核验安装、文档与开发工作流可用性。
已复核合集

优先安装的 TypeScript 工作流工具

复核于 2026-04-17

已于 2026-04-17 按 TypeScript 工作流适配度、安装清晰度、操作交接和日常产品工程价值完成复核。现在这页被重新定位为“安装优先”的 TypeScript 入口,而不是泛化语言榜单。

之所以优先强化这页,是因为带着 TypeScript 意图进来的用户,通常需要的是一份可以快速安装、验证并带入真实类型化交付闭环的候选清单。

收录 12 项 由 Killer-Skills 编辑审查流程维护,重点核验安装、文档与 TypeScript 工作流可用性。
已复核合集

面向重构与评审场景的 Cursor 工具

复核于 2026-04-17

已于 2026-04-17 按安装清晰度、维护者可靠性、重构支持与交接就绪度完成复核。我们保留的是那些能帮助 Cursor 团队从本地提效走向可重复团队习惯的工具。

来到这页的人通常已经在 Cursor 中写代码了。接下来他们需要的,不是另一张泛化集成页,而是一份围绕重构、评审、测试、规则同步与交接缩小过的清单。

收录 9 项 由 Killer-Skills 编辑审查与每月合集复查共同维护。
评审后的下一步

先决定动作,再继续看上游仓库材料

Killer-Skills 的主价值不应该停在“帮你打开仓库说明”,而是先帮你判断这项技能是否值得安装、是否应该回到可信集合复核,以及是否已经进入工作流落地阶段。

实验室 Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

常见问题与安装步骤

以下问题与步骤与页面结构化数据保持一致,便于搜索引擎理解页面内容。

? FAQ

testing-with-api-mocks 是什么?

非常适合需要使用MSW进行自动API模拟的高效测试的AI代理 Start here for all API mocking in tests. Covers auto-generation, fixtures, and when to use other skills. Required reading before creating, refactoring, or modifying any test involving API calls.

如何安装 testing-with-api-mocks?

运行命令:npx killer-skills add stacklok/toolhive-studio。支持 Cursor、Windsurf、VS Code、Claude Code 等 19+ IDE/Agent。

testing-with-api-mocks 适用于哪些场景?

典型场景包括:自动化API模拟生成用于测试、简化MCP服务器的开发过程、使用自动生成的模拟高效地测试ToolHive应用程序。

testing-with-api-mocks 支持哪些 IDE 或 Agent?

该技能兼容 Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer。可使用 Killer-Skills CLI 一条命令通用安装。

testing-with-api-mocks 有哪些限制?

需要MSW(模拟服务工作者)设置;仅限于具有现有模式的API端点。

安装步骤

  1. 1. 打开终端

    在你的项目目录中打开终端或命令行。

  2. 2. 执行安装命令

    运行:npx killer-skills add stacklok/toolhive-studio。CLI 会自动识别 IDE 或 AI Agent 并完成配置。

  3. 3. 开始使用技能

    testing-with-api-mocks 已启用,可立即在当前项目中调用。

! 参考页模式

此页面仍可作为安装与查阅参考,但 Killer-Skills 不再把它视为主要可索引落地页。请优先阅读上方评审结论,再决定是否继续查看上游仓库说明。

Upstream Repository Material

The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.

Upstream Source

testing-with-api-mocks

安装 testing-with-api-mocks,这是一款面向AI agent workflows and automation的 AI Agent Skill。查看评审结论、使用场景与安装路径。

SKILL.md
Readonly
Upstream Repository Material
The section below is imported from the upstream repository and should be treated as secondary evidence. Use the Killer-Skills review above as the primary layer for fit, risk, and installation decisions.
Supporting Evidence

Testing with API Mocks

This is the starting point for all API mocking in tests. Read this skill first before working on any test that involves API calls.

This project uses MSW (Mock Service Worker) with auto-generated schema-based mocks. When writing tests for code that calls API endpoints, mocks are created automatically.

How It Works

  1. Run a test that triggers an API call (e.g., a component that fetches data)
  2. Mock auto-generates if no fixture exists for that endpoint
  3. Fixture saved to renderer/src/common/mocks/fixtures/<endpoint>/<method>.ts
  4. Subsequent runs use the saved fixture

No manual mock setup is required for basic tests.

Fixture Location

Fixtures are organized by endpoint path and HTTP method:

renderer/src/common/mocks/fixtures/
├── groups/
│   ├── get.ts          # GET /api/v1beta/groups
│   └── post.ts         # POST /api/v1beta/groups
├── workloads/
│   └── get.ts          # GET /api/v1beta/workloads
├── workloads_name/
│   └── get.ts          # GET /api/v1beta/workloads/:name
└── ...

Path parameters like :name become _name in the directory name.

Fixture Structure

Generated fixtures use the AutoAPIMock wrapper with types from the OpenAPI schema:

typescript
1// renderer/src/common/mocks/fixtures/groups/get.ts 2import type { 3 GetApiV1BetaGroupsResponse, 4 GetApiV1BetaGroupsData, 5} from '@common/api/generated/types.gen' 6import { AutoAPIMock } from '@mocks' 7 8export const mockedGetApiV1BetaGroups = AutoAPIMock< 9 GetApiV1BetaGroupsResponse, 10 GetApiV1BetaGroupsData 11>({ 12 groups: [ 13 { name: 'default', registered_clients: ['client-a'] }, 14 { name: 'research', registered_clients: ['client-b'] }, 15 ], 16})

The second type parameter (*Data) provides typed access to request parameters (query, path, body) for conditional overrides.

Naming Convention

Export names follow the pattern: mocked + HTTP method + endpoint path in PascalCase.

  • GET /api/v1beta/groupsmockedGetApiV1BetaGroups
  • POST /api/v1beta/workloadsmockedPostApiV1BetaWorkloads
  • GET /api/v1beta/workloads/:namemockedGetApiV1BetaWorkloadsByName

Writing a Basic Test

For most tests, just render the component and the mock handles the rest:

typescript
1import { render, screen, waitFor } from '@testing-library/react' 2 3it('displays groups from the API', async () => { 4 render(<GroupsList />) 5 6 await waitFor(() => { 7 expect(screen.getByText('default')).toBeVisible() 8 }) 9})

The auto-generated mock provides realistic fake data based on the OpenAPI schema.

Customizing Fixture Data

If the auto-generated data doesn't suit your test, edit the fixture file directly:

typescript
1// renderer/src/common/mocks/fixtures/groups/get.ts 2export const mockedGetApiV1BetaGroups = AutoAPIMock< 3 GetApiV1BetaGroupsResponse, 4 GetApiV1BetaGroupsData 5>({ 6 groups: [ 7 { name: 'production', registered_clients: ['claude-code'] }, // Custom data 8 { name: 'staging', registered_clients: [] }, 9 ], 10})

This becomes the new default for all tests using this endpoint.

Regenerating a Fixture

To regenerate a fixture with fresh schema-based data:

  1. Delete the fixture file
  2. Run a test that calls that endpoint
  3. New fixture auto-generates
bash
1rm renderer/src/common/mocks/fixtures/groups/get.ts 2pnpm test -- --run <test-file>

Key Imports

typescript
1// Types for API responses and request parameters 2import type { 3 GetApiV1BetaGroupsResponse, 4 GetApiV1BetaGroupsData, 5} from '@common/api/generated/types.gen' 6 7// AutoAPIMock wrapper 8import { AutoAPIMock } from '@mocks' 9 10// Fixture mocks (for test-scoped overrides, see: testing-api-overrides skill) 11import { mockedGetApiV1BetaGroups } from '@mocks/fixtures/groups/get'

204 No Content Endpoints

For endpoints that return 204, create a minimal AutoAPIMock fixture and override the handler in each test:

typescript
1// renderer/src/common/mocks/fixtures/health/get.ts 2import type { 3 GetHealthResponse, 4 GetHealthData, 5} from '@common/api/generated/types.gen' 6import { AutoAPIMock } from '@mocks' 7 8export const mockedGetHealth = AutoAPIMock<GetHealthResponse, GetHealthData>( 9 '' as unknown as GetHealthResponse 10)

Then in tests, use .overrideHandler() to return the appropriate response:

typescript
1import { mockedGetHealth } from '@mocks/fixtures/health/get' 2import { HttpResponse } from 'msw' 3 4it('navigates on health check success', async () => { 5 mockedGetHealth.overrideHandler(() => new HttpResponse(null, { status: 204 })) 6 // ... 7}) 8 9it('handles health check failure', async () => { 10 mockedGetHealth.overrideHandler(() => HttpResponse.error()) 11 // ... 12})

Custom Mocks (Text/Plain Endpoints)

Custom mocks are only needed for text/plain endpoints. The only current example is the logs endpoint:

typescript
1// renderer/src/common/mocks/customHandlers/index.ts 2export const customHandlers = [ 3 http.get(mswEndpoint('/api/v1beta/workloads/:name/logs'), ({ params }) => { 4 const { name } = params 5 const logs = getMockLogs(name as string) 6 return new HttpResponse(logs, { status: 200 }) 7 }), 8]

To override the logs response in tests, use the exported getMockLogs mock:

typescript
1import { getMockLogs } from '@/common/mocks/customHandlers' 2 3getMockLogs.mockReturnValueOnce('Custom log content for this test')
  • testing-api-overrides - Test-scoped overrides and conditional responses for testing filters/params
  • testing-api-assertions - Verifying API calls for mutations (create/update/delete)

相关技能

寻找 testing-with-api-mocks 的替代方案 (Alternative) 或可搭配使用的同类 community Skill?探索以下相关开源技能。

查看全部

openclaw-release-maintainer

Logo of openclaw
openclaw

Your own personal AI assistant. Any OS. Any Platform. The lobster way. 🦞

333.8k
0
AI

widget-generator

Logo of f
f

为prompts.chat的信息反馈系统生成可定制的插件小部件

149.6k
0
AI

flags

Logo of vercel
vercel

React 框架

138.4k
0
浏览器

pr-review

Logo of pytorch
pytorch

Python中具有强大GPU加速的张量和动态神经网络

98.6k
0
开发者工具