Skillpedia
الوكلاء280k · #262

ai-regression-testing

ما الذي تفعله

تساعد هذه المهارة على اختبار كودك تلقائيًا، خاصة عندما يكتبه الذكاء الاصطناعي ويراجعه. تضمن ألا تؤدي إصلاحات الأخطاء إلى مشكلات جديدة، مع التركيز على الاختبار دون الاعتماد على قاعدة بيانات.

متى تستخدمها

  • ✓عندما يعدّل الذكاء الاصطناعي أجزاء مهمة من الكود (مسارات الواجهة البرمجية، ومنطق الخادم).
  • ✓بعد إصلاح خطأ، للتأكد من أنه لن يعود.
  • ✓عند استخدام وضع «صندوق الحماية» (sandbox) أو وضع المحاكاة (mock) لاختبار الكود دون قاعدة البيانات الحقيقية.

رابط المهارة

https://github.com/affaan-m/ECC/blob/main/skills/ai-regression-testing/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/affaan-m/ECC/blob/main/skills/ai-regression-testing/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“تحقق مما إذا كانت واجهة الملف الشخصي للمستخدم تعيد جميع الحقول المطلوبة، بما فيها «notification_settings».”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تعمل بإعداد بيئة اختبار سريعة تحاكي التطبيق دون الحاجة إلى قاعدة بيانات حقيقية. ثم تكتب اختبارات محددة للتأكد من أن إصلاحات الأخطاء لم تكسر أجزاء أخرى من الكود، خاصة عبر أوضاع التشغيل المختلفة (مثل صندوق الحماية مقابل الإنتاج).

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

AI Regression Testing

Testing patterns specifically designed for AI-assisted development, where the same model writes code and reviews it — creating systematic blind spots that only automated tests can catch.

When to Activate

  • AI agent (Claude Code, Cursor, Codex) has modified API routes or backend logic
  • A bug was found and fixed — need to prevent re-introduction
  • Project has a sandbox/mock mode that can be leveraged for DB-free testing
  • Running /bug-check or similar review commands after code changes
  • Multiple code paths exist (sandbox vs production, feature flags, etc.)

The Core Problem

When an AI writes code and then reviews its own work, it carries the same assumptions into both steps. This creates a predictable failure pattern:

AI writes fix → AI reviews fix → AI says "looks correct" → Bug still exists

Real-world example (observed in production):

Fix 1: Added notification_settings to API response
  → Forgot to add it to the SELECT query
  → AI reviewed and missed it (same blind spot)

Fix 2: Added it to SELECT query
  → TypeScript build error (column not in generated types)
  → AI reviewed Fix 1 but didn't catch the SELECT issue

Fix 3: Changed to SELECT *
  → Fixed production path, forgot sandbox path
  → AI reviewed and missed it AGAIN (4th occurrence)

Fix 4: Test caught it instantly on first run PASS:

The pattern: sandbox/production path inconsistency is the #1 AI-introduced regression.

Sandbox-Mode API Testing

Most projects with AI-friendly architecture have a sandbox/mock mode. This is the key to fast, DB-free API testing.

Setup (Vitest + Next.js App Router)

// vitest.config.ts
import { defineConfig } from "vitest/config";
import path from "path";

export default defineConfig({
  test: {
    environment: "node",
    globals: true,
    include: ["__tests__/**/*.test.ts"],
    setupFiles: ["__tests__/setup.ts"],
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "."),
    },
  },
});
// __tests__/setup.ts
// Force sandbox mode — no database needed
process.env.SANDBOX_MODE = "true";
process.env.NEXT_PUBLIC_SUPABASE_URL = "";
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY = "";

Test Helper for Next.js API Routes

// __tests__/helpers.ts
import { NextRequest } from "next/server";

export function createTestRequest(
  url: string,
  options?: {
    method?: string;
    body?: Record<string, unknown>;
    headers?: Record<string, string>;
    sandboxUserId?: string;
  },
): NextRequest {
  const { method = "GET", body, headers = {}, sandboxUserId } = options || {};
  const fullUrl = url.startsWith("http") ? url : `http://localhost:3000${url}`;
  const reqHeaders: Record<string, string> = { ...headers };

  if (sandboxUserId) {
    reqHeaders["x-sandbox-user-id"] = sandboxUserId;
  }

  const init: { method: string; headers: Record<string, string>; body?: string } = {
    method,
    headers: reqHeaders,
  };

  if (body) {
    init.body = JSON.stringify(body);
    reqHeaders["content-type"] = "application/json";
  }

  return new NextRequest(fullUrl, init);
}

export async function parseResponse(response: Response) {
  const json = await response.json();
  return { status: response.status, json };
}

Writing Regression Tests

The key principle: write tests for bugs that were found, not for code that works.

// __tests__/api/user/profile.test.ts
import { describe, it, expect } from "vitest";
import { createTestRequest, parseResponse } from "../../helpers";
import { GET, PATCH } from "@/app/api/user/profile/route";

// Define the contract — what fields MUST be in the response
const REQUIRED_FIELDS = [
  "id",
  "email",
  "full_name",
  "phone",
  "role",
  "created_at",
  "avatar_url",
  "notification_settings",  // ← Added after bug found it missing
];

describe("GET /api/user/profile", () => {
  it("returns all required fields", async () => {
    const req = createTestRequest("/api/user/profile");
    const res = await GET(req);
    const { status, json } = await parseResponse(res);

    expect(status).toBe(200);
    for (const field of REQUIRED_FIELDS) {
      expect(json.data).toHaveProperty(field);
    }
  });

  // Regression test — this exact bug was introduced by AI 4 times
  it("notification_settings is not undefined (BUG-R1 regression)", async () => {
    const req = createTestRequest("/api/user/profile");
    const res = await GET(req);

…
الأسئلة الشائعة

لماذا نختبر عندما يكتب الذكاء الاصطناعي الكود ويراجعه؟

عندما يكتب الذكاء الاصطناعي الكود ويراجعه بنفسه، قد تكون لديه النقاط العمياء نفسها، فينسى فحص شيء مهم في الخطوتين. الاختبارات الآلية تكشف هذه الأخطاء.

ما هو «وضع صندوق الحماية» (sandbox)؟

هو وضع اختبار يحاكي سلوك التطبيق دون الاتصال بقاعدة بيانات حقيقية. وهذا يجعل الاختبارات أسرع وأسهل في الإعداد.

ما أكثر خطأ تساعد هذه المهارة على منعه؟

أكثر الأخطاء شيوعًا هو أن يعمل الإصلاح في بيئة (مثل الإنتاج) ثم ينكسر في بيئة أخرى (مثل صندوق الحماية)، أو العكس. وهذه المهارة تفحص مثل هذه التناقضات.

التفاصيل

الوصف الأصلي من المؤلف

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

repo: affaan-m/ECC

الشعبية

نجوم GitHub
280k
الترتيب
#262
الترخيص
MIT
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة