Langsung ke konten
Skillpedia
Agen280k ยท #262

ai-regression-testing

Fungsinya

Tool ini membantu menguji kode Anda secara otomatis, terutama ketika kode tersebut ditulis dan ditinjau oleh AI. Tool ini memastikan perbaikan bug tidak memunculkan masalah baru, dengan fokus pada pengujian tanpa ketergantungan pada database.

Kapan dipakai

  • โœ“Ketika AI mengubah bagian kode yang penting (rute API, logika backend).
  • โœ“Setelah memperbaiki bug, untuk memastikan bug tersebut tidak muncul kembali.
  • โœ“Ketika menggunakan mode 'sandbox' atau 'mock' untuk menguji tanpa database asli.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/affaan-m/ECC/blob/main/skills/ai-regression-testing/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit โ†’

Contoh permintaan ke AI

โ€œUji apakah API profil pengguna saya mengembalikan semua field yang dibutuhkan, termasuk 'notification_settings'.โ€

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Tool ini bekerja dengan menyiapkan lingkungan pengujian yang cepat yang mensimulasikan aplikasi Anda tanpa membutuhkan database asli. Setelah itu, tool menulis pengujian khusus untuk memeriksa apakah perbaikan bug tidak merusak bagian kode lain, terutama di berbagai mode operasi (seperti sandbox dan production).

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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);

โ€ฆ
Pertanyaan umum

Mengapa perlu menguji jika AI yang menulis dan meninjau kodenya?

Ketika AI yang sama menulis dan meninjau kode, bisa jadi ada 'titik buta' yang sama, sehingga hal penting terlewat di kedua proses tersebut. Pengujian otomatis dapat menangkap kesalahan semacam ini.

Apa itu 'sandbox mode'?

Sandbox mode adalah mode pengujian yang mensimulasikan perilaku aplikasi Anda tanpa terhubung ke database asli. Dengan begitu, pengujian menjadi lebih cepat dan lebih mudah disiapkan.

Apa kesalahan paling umum yang dicegah tool ini?

Kesalahan yang paling umum adalah ketika perbaikan berhasil di satu lingkungan (misalnya production) tetapi rusak di lingkungan lain (misalnya sandbox), atau sebaliknya. Tool ini memeriksa ketidakkonsistenan seperti ini.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
280k
Peringkat
#262
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • โ€ฆ

Skill lain dari repositori ini

Skill serupa