[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72ZVT4JQ4V8RBVQY7XC9P9Z":3,"skill-same:01M72ZVT4JQ4V8RBVQY7XC9P9Z":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":28,"repositoryHtmlUrl":29,"repositoryHomepageUrl":6,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M72ZVT4JQ4V8RBVQY7XC9P9Z","ai-regression-testing",null,"AI辅助开发的回归测试策略。沙盒模式API测试，无需依赖数据库，自动化的缺陷检查工作流程，以及捕捉AI盲点的模式，其中同一模型编写和审查代码。","SriramGandhiS\u002FSkills","SriramGandhiS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F211849986?v=4","01M72WQCW12BYX71C6WN584TTA","Sriram S","01M72WQCWTJ2RD0ET1X31AF1RC",1,"MIT","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fskills\u002Feverything-claude-code\u002Fdocs\u002Fzh-CN\u002Fskills\u002Fai-regression-testing\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: ai-regression-testing\ndescription: AI辅助开发的回归测试策略。沙盒模式API测试，无需依赖数据库，自动化的缺陷检查工作流程，以及捕捉AI盲点的模式，其中同一模型编写和审查代码。\norigin: ECC\n---\n\n# AI 回归测试\n\n专为 AI 辅助开发设计的测试模式，其中同一模型编写代码并审查代码——这会形成系统性的盲点，只有自动化测试才能发现。\n\n## 何时激活\n\n* AI 代理（Claude Code、Cursor、Codex）已修改 API 路由或后端逻辑\n* 发现并修复了一个 bug——需要防止重新引入\n* 项目具有沙盒\u002F模拟模式，可用于无需数据库的测试\n* 在代码更改后运行 `\u002Fbug-check` 或类似的审查命令\n* 存在多个代码路径（沙盒与生产环境、功能开关等）\n\n## 核心问题\n\n当 AI 编写代码然后审查其自身工作时，它会将相同的假设带入这两个步骤。这会形成一个可预测的失败模式：\n\n```\nAI 编写修复 → AI 审查修复 → AI 表示“看起来正确” → 漏洞依然存在\n```\n\n**实际示例**（在生产环境中观察到）：\n\n```\n修复 1：向 API 响应添加了 notification_settings\n  → 忘记将其添加到 SELECT 查询中\n  → AI 审核时遗漏了（相同的盲点）\n\n修复 2：将其添加到 SELECT 查询中\n  → TypeScript 构建错误（列不在生成的类型中）\n  → AI 审核了修复 1，但未发现 SELECT 问题\n\n修复 3：改为 SELECT *\n  → 修复了生产路径，忘记了沙箱路径\n  → AI 审核时再次遗漏（第 4 次出现）\n\n修复 4：测试在首次运行时立即捕获了问题 PASS:\n```\n\n模式：**沙盒\u002F生产环境路径不一致**是 AI 引入的 #1 回归问题。\n\n## 沙盒模式 API 测试\n\n大多数具有 AI 友好架构的项目都有一个沙盒\u002F模拟模式。这是实现快速、无需数据库的 API 测试的关键。\n\n### 设置（Vitest + Next.js App Router）\n\n```typescript\n\u002F\u002F vitest.config.ts\nimport { defineConfig } from \"vitest\u002Fconfig\";\nimport path from \"path\";\n\nexport default defineConfig({\n  test: {\n    environment: \"node\",\n    globals: true,\n    include: [\"__tests__\u002F**\u002F*.test.ts\"],\n    setupFiles: [\"__tests__\u002Fsetup.ts\"],\n  },\n  resolve: {\n    alias: {\n      \"@\": path.resolve(__dirname, \".\"),\n    },\n  },\n});\n```\n\n```typescript\n\u002F\u002F __tests__\u002Fsetup.ts\n\u002F\u002F Force sandbox mode — no database needed\nprocess.env.SANDBOX_MODE = \"true\";\nprocess.env.NEXT_PUBLIC_SUPABASE_URL = \"\";\nprocess.env.NEXT_PUBLIC_SUPABASE_ANON_KEY = \"\";\n```\n\n### Next.js API 路由的测试辅助工具\n\n```typescript\n\u002F\u002F __tests__\u002Fhelpers.ts\nimport { NextRequest } from \"next\u002Fserver\";\n\nexport function createTestRequest(\n  url: string,\n  options?: {\n    method?: string;\n    body?: Record\u003Cstring, unknown>;\n    headers?: Record\u003Cstring, string>;\n    sandboxUserId?: string;\n  },\n): NextRequest {\n  const { method = \"GET\", body, headers = {}, sandboxUserId } = options || {};\n  const fullUrl = url.startsWith(\"http\") ? url : `http:\u002F\u002Flocalhost:3000${url}`;\n  const reqHeaders: Record\u003Cstring, string> = { ...headers };\n\n  if (sandboxUserId) {\n    reqHeaders[\"x-sandbox-user-id\"] = sandboxUserId;\n  }\n\n  const init: { method: string; headers: Record\u003Cstring, string>; body?: string } = {\n    method,\n    headers: reqHeaders,\n  };\n\n  if (body) {\n    init.body = JSON.stringify(body);\n    reqHeaders[\"content-type\"] = \"application\u002Fjson\";\n  }\n\n  return new NextRequest(fullUrl, init);\n}\n\nexport async function parseResponse(response: Response) {\n  const json = await response.json();\n  return { status: response.status, json };\n}\n```\n\n### 编写回归测试\n\n关键原则：**为已发现的 bug 编写测试，而不是为正常工作的代码编写测试**。\n\n```typescript\n\u002F\u002F __tests__\u002Fapi\u002Fuser\u002Fprofile.test.ts\nimport { describe, it, expect } from \"vitest\";\nimport { createTestRequest, parseResponse } from \"..\u002F..\u002Fhelpers\";\nimport { GET, PATCH } from \"@\u002Fapp\u002Fapi\u002Fuser\u002Fprofile\u002Froute\";\n\n\u002F\u002F Define the contract — what fields MUST be in the response\nconst REQUIRED_FIELDS = [\n  \"id\",\n  \"email\",\n  \"full_name\",\n  \"phone\",\n  \"role\",\n  \"created_at\",\n  \"avatar_url\",\n  \"notification_settings\",  \u002F\u002F ← Added after bug found it missing\n];\n\ndescribe(\"GET \u002Fapi\u002Fuser\u002Fprofile\", () => {\n  it(\"returns all required fields\", async () => {\n    const req = createTestRequest(\"\u002Fapi\u002Fuser\u002Fprofile\");\n    const res = await GET(req);\n    const { status, json } = await parseResponse(res);\n\n    expect(status).toBe(200);\n    for (const field of REQUIRED_FIELDS) {\n      expect(json.data).toHaveProperty(field);\n    }\n  });\n\n  \u002F\u002F Regression test — this exact bug was introduced by AI 4 times\n  it(\"notification_settings is not undefined (BUG-R1 regression)\", async () => {\n    const req = createTestRequest(\"\u002Fapi\u002Fuser\u002Fprofile\");\n    const res = await GET(req);\n    const { json } = await parseResponse(res);\n\n    expect(\"notification_settings\" in json.data).toBe(true);\n    const ns = json.data.notification_settings;\n    expect(ns === null || typeof ns === \"object\").toBe(true);\n  });\n});\n```\n\n### 测试沙盒\u002F生产环境一致性\n\n最常见的 AI 回归问题：修复了生产环境路径但忘记了沙盒路径（或反之）。\n\n```typescript\n\u002F\u002F Test that sandbox responses match the expected contract\ndescribe(\"GET \u002Fapi\u002Fuser\u002Fmessages (conversation list)\", () => {\n  it(\"includes partner_name in sandbox mode\", async () => {\n    const req = createTestRequest(\"\u002Fapi\u002Fuser\u002Fmessages\", {\n      sandboxUserId: \"user-001\",\n    });\n    const res = await GET(req);\n    const { json } = await parseResponse(res);\n\n    \u002F\u002F This caught a bug where partner_name was added\n    \u002F\u002F to production path but not sandbox path\n    if (json.data.length > 0) {\n      for (const conv of json.data) {\n        expect(\"partner_name\" in conv).toBe(true);\n      }\n    }\n  });\n});\n```\n\n## 将测试集成到 Bug 检查工作流中\n\n### 自定义命令定义\n\n```markdown\n\u003C!-- .claude\u002Fcommands\u002Fbug-check.md -->\n# Bug 检查\n\n## 步骤 1：自动化测试（强制，不可跳过）\n\n在代码审查前**首先**运行以下命令：\n\n    npm run test       # Vitest 测试套件\n    npm run build      # TypeScript 类型检查 + 构建\n\n- 如果测试失败 → 报告为最高优先级 Bug\n- 如果构建失败 → 将类型错误报告为最高优先级\n- 只有在两者都通过后，才能继续到步骤 2\n\n## 步骤 2：代码审查（AI 审查）\n\n1. 沙盒\u002F生产环境路径一致性\n2. API 响应结构是否符合前端预期\n3. SELECT 子句的完整性\n4. 包含回滚的错误处理\n5. 乐观更新的竞态条件\n\n## 步骤 3：对于每个修复的 Bug，提出回归测试方案\n```\n\n### 工作流程\n\n```\nUser: \"バグチェックして\" (or \"\u002Fbug-check\")\n  │\n  ├─ Step 1: npm run test\n  │   ├─ FAIL → 发现机械性错误（无需AI判断）\n  │   └─ PASS → 继续\n  │\n  ├─ Step 2: npm run build\n  │   ├─ FAIL → 发现类型错误\n  │   └─ PASS → 继续\n  │\n  ├─ Step 3: AI代码审查（考虑已知盲点）\n  │   └─ 报告发现的问题\n  │\n  └─ Step 4: 对每个修复编写回归测试\n      └─ 下次bug-check时捕获修复是否破坏功能\n```\n\n## 常见的 AI 回归模式\n\n### 模式 1：沙盒\u002F生产环境路径不匹配\n\n**频率**：最常见（在 4 个回归问题中观察到 3 个）\n\n```typescript\n\u002F\u002F FAIL: AI adds field to production path only\nif (isSandboxMode()) {\n  return { data: { id, email, name } };  \u002F\u002F Missing new field\n}\n\u002F\u002F Production path\nreturn { data: { id, email, name, notification_settings } };\n\n\u002F\u002F PASS: Both paths must return the same shape\nif (isSandboxMode()) {\n  return { data: { id, email, name, notification_settings: null } };\n}\nreturn { data: { id, email, name, notification_settings } };\n```\n\n**用于捕获它的测试**：\n\n```typescript\nit(\"sandbox and production return same fields\", async () => {\n  \u002F\u002F In test env, sandbox mode is forced ON\n  const res = await GET(createTestRequest(\"\u002Fapi\u002Fuser\u002Fprofile\"));\n  const { json } = await parseResponse(res);\n\n  for (const field of REQUIRED_FIELDS) {\n    expect(json.data).toHaveProperty(field);\n  }\n});\n```\n\n### 模式 2：SELECT 子句遗漏\n\n**频率**：在使用 Supabase\u002FPrisma 添加新列时常见\n\n```typescript\n\u002F\u002F FAIL: New column added to response but not to SELECT\nconst { data } = await supabase\n  .from(\"users\")\n  .select(\"id, email, name\")  \u002F\u002F notification_settings not here\n  .single();\n\nreturn { data: { ...data, notification_settings: data.notification_settings } };\n\u002F\u002F → notification_settings is always undefined\n\n\u002F\u002F PASS: Use SELECT * or explicitly include new columns\nconst { data } = await supabase\n  .from(\"users\")\n  .select(\"*\")\n  .single();\n```\n\n### 模式 3：错误状态泄漏\n\n**频率**：中等——当向现有组件添加错误处理时\n\n```typescript\n\u002F\u002F FAIL: Error state set but old data not cleared\ncatch (err) {\n  setError(\"Failed to load\");\n  \u002F\u002F reservations still shows data from previous tab!\n}\n\n\u002F\u002F PASS: Clear related state on error\ncatch (err) {\n  setReservations([]);  \u002F\u002F Clear stale data\n  setError(\"Failed to load\");\n}\n```\n\n### 模式 4：乐观更新未正确回滚\n\n```typescript\n\u002F\u002F FAIL: No rollback on failure\nconst handleRemove = async (id: string) => {\n  setItems(prev => prev.filter(i => i.id !== id));\n  await fetch(`\u002Fapi\u002Fitems\u002F${id}`, { method: \"DELETE\" });\n  \u002F\u002F If API fails, item is gone from UI but still in DB\n};\n\n\u002F\u002F PASS: Capture previous state and rollback on failure\nconst handleRemove = async (id: string) => {\n  const prevItems = [...items];\n  setItems(prev => prev.filter(i => i.id !== id));\n  try {\n    const res = await fetch(`\u002Fapi\u002Fitems\u002F${id}`, { method: \"DELETE\" });\n    if (!res.ok) throw new Error(\"API error\");\n  } catch {\n    setItems(prevItems);  \u002F\u002F Rollback\n    alert(\"削除に失敗しました\");\n  }\n};\n```\n\n## 策略：在发现 Bug 的地方进行测试\n\n不要追求 100% 的覆盖率。相反：\n\n```\n在 \u002Fapi\u002Fuser\u002Fprofile 发现 bug → 为 profile API 编写测试\n在 \u002Fapi\u002Fuser\u002Fmessages 发现 bug → 为 messages API 编写测试\n在 \u002Fapi\u002Fuser\u002Ffavorites 发现 bug → 为 favorites API 编写测试\n在 \u002Fapi\u002Fuser\u002Fnotifications 没有发现 bug → 暂时不编写测试\n```\n\n**为什么这在 AI 开发中有效：**\n\n1. AI 倾向于重复犯**同一类错误**\n2. Bug 集中在复杂区域（身份验证、多路径逻辑、状态管理）\n3. 一旦经过测试，该特定回归问题**就不会再次发生**\n4. 测试数量随着 Bug 修复而有机增长——没有浪费精力\n\n## 快速参考\n\n| AI 回归模式 | 测试策略 | 优先级 |\n|---|---|---|\n| 沙盒\u002F生产环境不匹配 | 断言沙盒模式下响应结构相同 |  高 |\n| SELECT 子句遗漏 | 断言响应中包含所有必需字段 |  高 |\n| 错误状态泄漏 | 断言出错时状态已清理 |  中 |\n| 缺少回滚 | 断言 API 失败时状态已恢复 |  中 |\n| 类型转换掩盖 null | 断言字段不为 undefined |  中 |\n\n## 要 \u002F 不要\n\n**要：**\n\n* 发现 bug 后立即编写测试（如果可能，在修复之前）\n* 测试 API 响应结构，而不是实现细节\n* 将运行测试作为每次 bug 检查的第一步\n* 保持测试快速（在沙盒模式下总计 \u003C 1 秒）\n* 以测试所预防的 bug 来命名测试（例如，\"BUG-R1 regression\"）\n\n**不要：**\n\n* 为从未出现过 bug 的代码编写测试\n* 相信 AI 自我审查可以作为自动化测试的替代品\n* 因为“只是模拟数据”而跳过沙盒路径测试\n* 在单元测试足够时编写集成测试\n* 追求覆盖率百分比——追求回归预防\n","# AI 回归测试\n\n专为 AI 辅助开发设计的测试模式，其中同一模型编写代码并审查代码——这会形成系统性的盲点，只有自动化测试才能发现。\n\n## 何时激活\n\n* AI 代理（Claude Code、Cursor、Codex）已修改 API 路由或后端逻辑\n* 发现并修复了一个 bug——需要防止重新引入\n* 项目具有沙盒\u002F模拟模式，可用于无需数据库的测试\n* 在代码更改后运行 `\u002Fbug-check` 或类似的审查命令\n* 存在多个代码路径（沙盒与生产环境、功能开关等）\n\n## 核心问题\n\n当 AI 编写代码然后审查其自身工作时，它会将相同的假设带入这两个步骤。这会形成一个可预测的失败模式：\n\n```\nAI 编写修复 → AI 审查修复 → AI 表示“看起来正确” → 漏洞依然存在\n```\n\n**实际示例**（在生产环境中观察到）：\n\n```\n修复 1：向 API 响应添加了 notification_settings\n  → 忘记将其添加到 SELECT 查询中\n  → AI 审核时遗漏了（相同的盲点）\n\n修复 2：将其添加到 SELECT 查询中\n  → TypeScript 构建错误（列不在生成的类型中）\n  → AI 审核了修复 1，但未发现 SELECT 问题\n\n修复 3：改为 SELECT *\n  → 修复了生产路径，忘记了沙箱路径\n  → AI 审核时再次遗漏（第 4 次出现）\n\n修复 4：测试在首次运行时立即捕获了问题 PASS:\n```\n\n模式：**沙盒\u002F生产环境路径不一致**是 AI 引入的 #1 回归问题。\n\n## 沙盒模式 API 测试\n\n大多数具有 AI 友好架构的项目都有一个沙盒\u002F模拟模式。这是实现快速、无需数据库的 API 测试的关键。\n\n### 设置（Vitest + Next.js App Router）\n\n```typescript\n\u002F\u002F vitest.config.ts\nimport { defineConfig } from \"vitest\u002Fconfig\";\nimport path from \"path\";\n\nexport default defineConfig({\n  test: {\n    environment: \"node\",\n    globals: true,\n    include: [\"__tests__\u002F**\u002F*.test.ts\"],\n    setupFiles: [\"__tests__\u002Fsetup.ts\"],\n  },\n  resolve: {\n    alias: {\n      \"@\": path.resolve(__dirname, \".\"),\n    },\n  },\n});\n```\n\n```typescript\n\u002F\u002F __tests__\u002Fsetup.ts\n\u002F\u002F Force sandbox mode — no database needed\nprocess.env.SANDBOX_MODE = \"true\";\nprocess.env.NEXT_PUBLIC_SUPABASE_URL = \"\";\nprocess.env.NEXT_PUBLIC_SUPABASE_ANON_KEY = \"\";\n```\n\n### Next.js API 路由的测试辅助工具\n\n```typescript\n\u002F\u002F __tests__\u002Fhelpers.ts\nimport { NextRequest } from \"next\u002Fserver\";\n\nexport function createTestRequest(\n  url: string,\n  options?: {\n    method?: string;\n    body?: Record\u003Cstring, unknown>;\n    headers?: Record\u003Cstring, string>;\n    sandboxUserId?: string;\n  },\n): NextRequest {\n  const { method = \"GET\", body, headers = {}, sandboxUserId } = options || {};\n  const fullUrl = url.startsWith(\"http\") ? url : `http:\u002F\u002Flocalhost:3000${url}`;\n  const reqHeaders: Record\u003Cstring, string> = { ...headers };\n\n  if (sandboxUserId) {\n    reqHeaders[\"x-sandbox-user-id\"] = sandboxUserId;\n  }\n\n  const init: { method: string; headers: Record\u003Cstring, string>; body?: string } = {\n    method,\n    headers: reqHeaders,\n  };\n\n  if (body) {\n    init.body = JSON.stringify(body);\n    reqHeaders[\"content-type\"] = \"application\u002Fjson\";\n  }\n\n  return new NextRequest(fullUrl, init);\n}\n\nexport async function parseResponse(response: Response) {\n  const json = await response.json();\n  return { status: response.status, json };\n}\n```\n\n### 编写回归测试\n\n关键原则：**为已发现的 bug 编写测试，而不是为正常工作的代码编写测试**。\n\n```typescript\n\u002F\u002F __tests__\u002Fapi\u002Fuser\u002Fprofile.test.ts\nimport { describe, it, expect } from \"vitest\";\nimport { createTestRequest, parseResponse } from \"..\u002F..\u002Fhelpers\";\nimport { GET, PATCH } from \"@\u002Fapp\u002Fapi\u002Fuser\u002Fprofile\u002Froute\";\n\n\u002F\u002F Define the contract — what fields MUST be in the response\nconst REQUIRED_FIELDS = [\n  \"id\",\n  \"email\",\n  \"full_name\",\n  \"phone\",\n  \"role\",\n  \"created_at\",\n  \"avatar_url\",\n  \"notification_settings\",  \u002F\u002F ← Added after bug found it missing\n];\n\ndescribe(\"GET \u002Fapi\u002Fuser\u002Fprofile\", () => {\n  it(\"returns all required fields\", async () => {\n    const req = createTestRequest(\"\u002Fapi\u002Fuser\u002Fprofile\");\n    const res = await GET(req);\n    const { status, json } = await parseResponse(res);\n\n    expect(status).toBe(200);\n    for (const field of REQUIRED_FIELDS) {\n      expect(json.data).toHaveProperty(field);\n    }\n  });\n\n  \u002F\u002F Regression test — this exact bug was introduced by AI 4 times\n  it(\"notification_settings is not undefined (BUG-R1 regression)\", async () => {\n    const req = createTestRequest(\"\u002Fapi\u002Fuser\u002Fprofile\");\n    const res = await GET(req);\n    const { json } = await parseResponse(res);\n\n    expect(\"notification_settings\" in json.data).toBe(true);\n    const ns = json.data.notification_settings;\n    expect(ns === null || typeof ns === \"object\").toBe(true);\n  });\n});\n```\n\n### 测试沙盒\u002F生产环境一致性\n\n最常见的 AI 回归问题：修复了生产环境路径但忘记了沙盒路径（或反之）。\n\n```typescript\n\u002F\u002F Test that sandbox responses match the expected contract\ndescribe(\"GET \u002Fapi\u002Fuser\u002Fmessages (conversation list)\", () => {\n  it(\"includes partner_name in sandbox mode\", async () => {\n    const req = createTestRequest(\"\u002Fapi\u002Fuser\u002Fmessages\", {\n      sandboxUserId: \"user-001\",\n    });\n    const res = await GET(req);\n    const { json } = await parseResponse(res);\n\n    \u002F\u002F This caught a bug where partner_name was added\n    \u002F\u002F to production path but not sandbox path\n    if (json.data.length > 0) {\n      for (const conv of json.data) {\n        expect(\"partner_name\" in conv).toBe(true);\n      }\n    }\n  });\n});\n```\n\n## 将测试集成到 Bug 检查工作流中\n\n### 自定义命令定义\n\n```markdown\n\u003C!-- .claude\u002Fcommands\u002Fbug-check.md -->\n# Bug 检查\n\n## 步骤 1：自动化测试（强制，不可跳过）\n\n在代码审查前**首先**运行以下命令：\n\n    npm run test       # Vitest 测试套件\n    npm run build      # TypeScript 类型检查 + 构建\n\n- 如果测试失败 → 报告为最高优先级 Bug\n- 如果构建失败 → 将类型错误报告为最高优先级\n- 只有在两者都通过后，才能继续到步骤 2\n\n## 步骤 2：代码审查（AI 审查）\n\n1. 沙盒\u002F生产环境路径一致性\n2. API 响应结构是否符合前端预期\n3. SELECT 子句的完整性\n4. 包含回滚的错误处理\n5. 乐观更新的竞态条件\n\n## 步骤 3：对于每个修复的 Bug，提出回归测试方案\n```\n\n### 工作流程\n\n```\nUser: \"バグチェックして\" (or \"\u002Fbug-check\")\n  │\n  ├─ Step 1: npm run test\n  │   ├─ FAIL → 发现机械性错误（无需AI判断）\n  │   └─ PASS → 继续\n  │\n  ├─ Step 2: npm run build\n  │   ├─ FAIL → 发现类型错误\n  │   └─ PASS → 继续\n  │\n  ├─ Step 3: AI代码审查（考虑已知盲点）\n  │   └─ 报告发现的问题\n  │\n  └─ Step 4: 对每个修复编写回归测试\n      └─ 下次bug-check时捕获修复是否破坏功能\n```\n\n## 常见的 AI 回归模式\n\n### 模式 1：沙盒\u002F生产环境路径不匹配\n\n**频率**：最常见（在 4 个回归问题中观察到 3 个）\n\n```typescript\n\u002F\u002F FAIL: AI adds field to production path only\nif (isSandboxMode()) {\n  return { data: { id, email, name } };  \u002F\u002F Missing new field\n}\n\u002F\u002F Production path\nreturn { data: { id, email, name, notification_settings } };\n\n\u002F\u002F PASS: Both paths must return the same shape\nif (isSandboxMode()) {\n  return { data: { id, email, name, notification_settings: null } };\n}\nreturn { data: { id, email, name, notification_settings } };\n```\n\n**用于捕获它的测试**：\n\n```typescript\nit(\"sandbox and production return same fields\", async () => {\n  \u002F\u002F In test env, sandbox mode is forced ON\n  const res = await GET(createTestRequest(\"\u002Fapi\u002Fuser\u002Fprofile\"));\n  const { json } = await parseResponse(res);\n\n  for (const field of REQUIRED_FIELDS) {\n    expect(json.data).toHaveProperty(field);\n  }\n});\n```\n\n### 模式 2：SELECT 子句遗漏\n\n**频率**：在使用 Supabase\u002FPrisma 添加新列时常见\n\n```typescript\n\u002F\u002F FAIL: New column added to response but not to SELECT\nconst { data } = await supabase\n  .from(\"users\")\n  .select(\"id, email, name\")  \u002F\u002F notification_settings not here\n  .single();\n\nreturn { data: { ...data, notification_settings: data.notification_settings } };\n\u002F\u002F → notification_settings is always undefined\n\n\u002F\u002F PASS: Use SELECT * or explicitly include new columns\nconst { data } = await supabase\n  .from(\"users\")\n  .select(\"*\")\n  .single();\n```\n\n### 模式 3：错误状态泄漏\n\n**频率**：中等——当向现有组件添加错误处理时\n\n```typescript\n\u002F\u002F FAIL: Error state set but old data not cleared\ncatch (err) {\n  setError(\"Failed to load\");\n  \u002F\u002F reservations still shows data from previous tab!\n}\n\n\u002F\u002F PASS: Clear related state on error\ncatch (err) {\n  setReservations([]);  \u002F\u002F Clear stale data\n  setError(\"Failed to load\");\n}\n```\n\n### 模式 4：乐观更新未正确回滚\n\n```typescript\n\u002F\u002F FAIL: No rollback on failure\nconst handleRemove = async (id: string) => {\n  setItems(prev => prev.filter(i => i.id !== id));\n  await fetch(`\u002Fapi\u002Fitems\u002F${id}`, { method: \"DELETE\" });\n  \u002F\u002F If API fails, item is gone from UI but still in DB\n};\n\n\u002F\u002F PASS: Capture previous state and rollback on failure\nconst handleRemove = async (id: string) => {\n  const prevItems = [...items];\n  setItems(prev => prev.filter(i => i.id !== id));\n  try {\n    const res = await fetch(`\u002Fapi\u002Fitems\u002F${id}`, { method: \"DELETE\" });\n    if (!res.ok) throw new Error(\"API error\");\n  } catch {\n    setItems(prevItems);  \u002F\u002F Rollback\n    alert(\"削除に失敗しました\");\n  }\n};\n```\n\n## 策略：在发现 Bug 的地方进行测试\n\n不要追求 100% 的覆盖率。相反：\n\n```\n在 \u002Fapi\u002Fuser\u002Fprofile 发现 bug → 为 profile API 编写测试\n在 \u002Fapi\u002Fuser\u002Fmessages 发现 bug → 为 messages API 编写测试\n在 \u002Fapi\u002Fuser\u002Ffavorites 发现 bug → 为 favorites API 编写测试\n在 \u002Fapi\u002Fuser\u002Fnotifications 没有发现 bug → 暂时不编写测试\n```\n\n**为什么这在 AI 开发中有效：**\n\n1. AI 倾向于重复犯**同一类错误**\n2. Bug 集中在复杂区域（身份验证、多路径逻辑、状态管理）\n3. 一旦经过测试，该特定回归问题**就不会再次发生**\n4. 测试数量随着 Bug 修复而有机增长——没有浪费精力\n\n## 快速参考\n\n| AI 回归模式 | 测试策略 | 优先级 |\n|---|---|---|\n| 沙盒\u002F生产环境不匹配 | 断言沙盒模式下响应结构相同 |  高 |\n| SELECT 子句遗漏 | 断言响应中包含所有必需字段 |  高 |\n| 错误状态泄漏 | 断言出错时状态已清理 |  中 |\n| 缺少回滚 | 断言 API 失败时状态已恢复 |  中 |\n| 类型转换掩盖 null | 断言字段不为 undefined |  中 |\n\n## 要 \u002F 不要\n\n**要：**\n\n* 发现 bug 后立即编写测试（如果可能，在修复之前）\n* 测试 API 响应结构，而不是实现细节\n* 将运行测试作为每次 bug 检查的第一步\n* 保持测试快速（在沙盒模式下总计 \u003C 1 秒）\n* 以测试所预防的 bug 来命名测试（例如，\"BUG-R1 regression\"）\n\n**不要：**\n\n* 为从未出现过 bug 的代码编写测试\n* 相信 AI 自我审查可以作为自动化测试的替代品\n* 因为“只是模拟数据”而跳过沙盒路径测试\n* 在单元测试足够时编写集成测试\n* 追求覆盖率百分比——追求回归预防\n",{"name":5,"origin":24,"description":7},"ECC","master","d6ca01da0f24a3b0e26e4a8b7b66cbd25d429f5d","skills\u002Feverything-claude-code\u002Fdocs\u002Fzh-CN\u002Fskills\u002Fai-regression-testing",0,"https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills","https:\u002F\u002Fgithub.com\u002FSriramGandhiS","https:\u002F\u002Fsriram.website\u002F","Curious guy who keeps tinkering until something works","2026-05-20 16:21:34",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add SriramGandhiS\u002FSkills --skill ai-regression-testing",{"tool":40,"command":41},"bunx","bunx skills add SriramGandhiS\u002FSkills --skill ai-regression-testing",{"tool":43,"command":44},"pnpm","pnpm dlx skills add SriramGandhiS\u002FSkills --skill ai-regression-testing","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fskills\u002Feverything-claude-code\u002Fdocs\u002Fzh-CN\u002Fskills\u002Fai-regression-testing\u002FSKILL.md",true,[],[49,56,61,67,74,81],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":19},"01M732609EPJWV13PVTX3GT4TM","webgpu-threejs-tsl","Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002Fskills\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],{"skillNo":57,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M7325XM47AGWB6K6C4VXKE6B","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M7325WP6DES69JKC840VMFEP","verification-loop","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M7325TFQF1DZTQ6J3WGQQ1VR","tdd-workflow","Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Ftdd-workflow\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M7325RGV9AY9PK92D2V8KKPW","strategic-compact","Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fstrategic-compact\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M7325MZC28SE86E7NMCNEFS4","security-review","Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment\u002Fsensitive features. Provides comprehensive security checklist and patterns.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review\u002FSKILL.md",[],[]]