面向 AI 编程智能体的网络测试
在 3G 下运行端到端测试,而 AI 智能体自己的连接不会变慢。借助 Lagsmith 内置的 MCP 服务器,Claude Code、Cursor、Codex、Claude Desktop 和 Windsurf 可以控制被测 App 的网络。
> 在 3G 下运行结账 UI 测试,让支付 API 返回 503,告诉我哪里出了问题。
我先在模拟器中找到这个 App。
lagsmith - list_targets (MCP)
simulators: iPhone 17 Pro (booted)apps: com.pantryhq.Pantry, com.apple.mobilesafari, …presets: Edge, 3G, DSL, LTE, WiFi, Very Bad Network, 100% Loss
lagsmith - set_network (MCP)(app: "com.pantryhq.Pantry", simulator: "booted", preset: "3G")
{"ok": true, "rule": "Pantry", "preset": "3G", "conditions": {"down": 780, "up": 330, "latency": 200}}
lagsmith - fail_endpoint (MCP)(app: "com.pantryhq.Pantry", simulator: "booted",
pattern: "api.pantryhq.app/v1/payments", kind: "status", value: 503)
{"ok": true, "endpoints": [{"pattern": "api.pantryhq.app/v1/payments", "kind": "status", "value": 503}]}
lagsmith - relaunch_app (MCP)(app: "com.pantryhq.Pantry", simulator: "booted")
{"ok": true, "relaunched": ["Pantry on iPhone 17 Pro"]}
Bash(xcodebuild test -scheme PantryUITests -only-testing:PantryUITests/CheckoutTests
-destination 'platform=iOS Simulator,name=iPhone 17 Pro')
Test Suite 'CheckoutTests' started✓ testCartLoads (4.8 s)✓ testApplyCoupon (6.1 s)✗ testPlaceOrder (30.0 s): Failed to find "Order confirmed" within 30 sExecuted 3 tests, with 1 failure
lagsmith - get_requests (MCP)(app: "com.pantryhq.Pantry", simulator: "booted",
filter: "host:api.pantryhq.app is:failed", include_bodies: true)
POST https://api.pantryhq.app/v1/payments 503 injected by Lagsmith 2 msPOST https://api.pantryhq.app/v1/payments 503 injected by Lagsmith 1 msPOST https://api.pantryhq.app/v1/payments 503 injected by Lagsmith 1 ms(3 requests, 0.4 s apart)
lagsmith - reset_network (MCP)(app: "com.pantryhq.Pantry", simulator: "booted")
{"ok": true, "preset": "No Throttling"}
找到了。在 3G 下,购物车和优惠券流程都正常,但当支付接口返回 503 时:
1. PaymentService 没有退避地重试 3 次(间隔 0.4 秒),然后静默放弃。
2. 结账界面的加载指示器会一直转下去:支付失败时没有错误状态,
所以 testPlaceOrder 在等待“Order confirmed”时超时。
要我在 CheckoutView 中加入指数退避和带“重试”按钮的错误状态,
然后在相同条件下重新运行测试吗?
为整台 Mac 限速的问题
AI 智能体要通过网络与它的模型通信。如果开启 Network Link Conditioner 这类作用于整台 Mac 的限速,智能体就会和它正在测试的 App 一起慢得像蜗牛。Lagsmith 只为被测 App 限速。
智能体能做什么
- 列出模拟器及其 App
- 设置和重置 App 的网络条件
- 在启用请求监控的情况下重新启动 App
- 读取 App 的请求
- 让端点失败或模拟端点
所以你可以这样提问:“在 3G 下重新启动 App,登录,然后告诉我哪些请求超过了两秒”,或者“让 /v1/feed 返回 500,检查 App 是否显示错误状态。”
设置方法
- 安装 Lagsmith,并允许它的网络扩展。
- 将 Lagsmith 的 MCP 服务器添加到你的智能体。对于 Claude Code,运行:
在用 Cursor、Codex、Claude Desktop 或 Windsurf?查看各自的设置方法。
claude mcp add --scope user lagsmith -- "/Applications/Lagsmith.app/Contents/MacOS/lagsmith-mcp" - 让你的智能体在慢速或故障网络下运行测试。
常见问题
Lagsmith 支持哪些 AI 智能体?
任何支持 MCP 的智能体,包括 Claude Code、Cursor、Codex、Claude Desktop 和 Windsurf。
为 App 限速会拖慢我的智能体吗?
不会。Lagsmith 只为被测 App 限速,智能体自己的连接保持全速。
MCP 服务器需要单独安装吗?
不需要。它内置在 Lagsmith App 中。
免费版包含 MCP 服务器吗?
自动化(包括面向 AI 智能体的 MCP)属于 Pro 功能。每次安装都会先开始 14 天 Pro 试用。
下载 Mac 版
免费下载,含 14 天 Pro 试用。无需账户,无需银行卡。macOS 13 Ventura 或更高版本。