{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "version": "1.0.0",
  "description": "Test quality and code validation configuration for AI-generated code",

  "code_validation": {
    "description": "Pre-test validation for AI-generated code common errors",
    "enabled": true,
    "phases": {
      "L0_compilation": {
        "description": "TypeScript/JavaScript compilation check",
        "enabled": true,
        "commands": {
          "typescript": "npx tsc --noEmit --skipLibCheck",
          "javascript": "node --check"
        },
        "critical": true,
        "failure_blocks_tests": true
      },
      "L0_imports": {
        "description": "Import statement validation",
        "enabled": true,
        "checks": [
          {
            "id": "unresolved_imports",
            "description": "Check for unresolved module imports",
            "pattern": "Cannot find module|Module not found|Unable to resolve",
            "severity": "critical"
          },
          {
            "id": "circular_imports",
            "description": "Check for circular dependencies",
            "tool": "madge",
            "command": "npx madge --circular --extensions ts,tsx,js,jsx",
            "severity": "warning"
          },
          {
            "id": "duplicate_imports",
            "description": "Check for duplicate imports",
            "eslint_rule": "import/no-duplicates",
            "severity": "error"
          },
          {
            "id": "unused_imports",
            "description": "Check for unused imports",
            "eslint_rule": "unused-imports/no-unused-imports",
            "severity": "warning"
          }
        ]
      },
      "L0_variables": {
        "description": "Variable declaration validation",
        "enabled": true,
        "checks": [
          {
            "id": "redeclaration",
            "description": "Check for variable redeclaration",
            "pattern": "Cannot redeclare|Duplicate identifier|has already been declared",
            "severity": "critical"
          },
          {
            "id": "scope_conflict",
            "description": "Check for scope conflicts",
            "eslint_rule": "no-shadow",
            "severity": "error"
          },
          {
            "id": "undefined_vars",
            "description": "Check for undefined variables",
            "eslint_rule": "no-undef",
            "severity": "critical"
          },
          {
            "id": "unused_vars",
            "description": "Check for unused variables",
            "eslint_rule": "@typescript-eslint/no-unused-vars",
            "severity": "warning"
          }
        ]
      },
      "L0_types": {
        "description": "TypeScript type validation",
        "enabled": true,
        "checks": [
          {
            "id": "type_mismatch",
            "description": "Check for type mismatches",
            "pattern": "Type .* is not assignable to type",
            "severity": "critical"
          },
          {
            "id": "missing_types",
            "description": "Check for missing type definitions",
            "pattern": "Could not find a declaration file",
            "severity": "warning"
          },
          {
            "id": "any_abuse",
            "description": "Check for excessive any type usage",
            "eslint_rule": "@typescript-eslint/no-explicit-any",
            "severity": "warning",
            "max_occurrences": 5
          },
          {
            "id": "implicit_any",
            "description": "Check for implicit any",
            "pattern": "implicitly has an 'any' type",
            "severity": "error"
          }
        ]
      }
    },
    "severity_thresholds": {
      "critical": 0,
      "error": 3,
      "warning": 10
    },
    "max_retries": 2,
    "auto_fix": {
      "enabled": true,
      "safe_fixes_only": true,
      "fixable_categories": ["imports", "formatting", "unused_vars"]
    }
  },

  "test_quality": {
    "description": "Test file quality validation (IMPL-001.5)",
    "enabled": true,
    "coverage": {
      "minimum_threshold": 80,
      "branch_threshold": 70,
      "function_threshold": 80,
      "line_threshold": 80
    },
    "anti_patterns": {
      "empty_test_body": {
        "pattern": "it\\(['\"].*['\"],\\s*\\(\\)\\s*=>\\s*\\{\\s*\\}\\)",
        "severity": "critical",
        "description": "Test with empty body"
      },
      "missing_assertion": {
        "pattern": "it\\(['\"].*['\"],.*\\{[^}]*\\}\\)(?![\\s\\S]*expect)",
        "severity": "critical",
        "description": "Test without expect() assertion"
      },
      "skipped_without_reason": {
        "pattern": "(it|describe)\\.skip\\(['\"][^'\"]*['\"](?!.*\\/\\/ )",
        "severity": "error",
        "description": "Skipped test without comment explaining why"
      },
      "todo_test": {
        "pattern": "(it|test)\\.todo\\(",
        "severity": "warning",
        "description": "TODO test placeholder"
      },
      "only_test": {
        "pattern": "(it|describe)\\.only\\(",
        "severity": "critical",
        "description": "Focused test (will skip other tests)"
      }
    },
    "required_test_types": {
      "unit": {
        "min_per_function": 1,
        "must_include": ["happy_path"]
      },
      "negative": {
        "min_per_public_api": 1,
        "description": "Error handling tests for public APIs"
      },
      "edge_case": {
        "required_scenarios": ["null", "undefined", "empty_string", "empty_array", "boundary_values"]
      }
    }
  },

  "ai_specific_checks": {
    "description": "Checks specifically for AI-generated code patterns",
    "enabled": true,
    "checks": [
      {
        "id": "hallucinated_imports",
        "description": "Check for imports of non-existent packages",
        "validation": "npm_package_exists",
        "severity": "critical"
      },
      {
        "id": "inconsistent_naming",
        "description": "Check for naming inconsistencies within file",
        "pattern": "function (\\w+).*\\1(?!\\()",
        "severity": "warning"
      },
      {
        "id": "placeholder_code",
        "description": "Check for AI placeholder comments",
        "patterns": [
          "// TODO: implement",
          "// Add your code here",
          "// Implementation pending",
          "throw new Error\\(['\"]Not implemented['\"]\\)"
        ],
        "severity": "error"
      },
      {
        "id": "mock_in_production",
        "description": "Check for mock/stub code in production files",
        "patterns": [
          "jest\\.mock\\(",
          "sinon\\.",
          "vi\\.mock\\("
        ],
        "exclude_paths": ["**/*.test.*", "**/*.spec.*", "**/test/**", "**/__tests__/**"],
        "severity": "critical"
      }
    ]
  },

  "validation_commands": {
    "typescript_check": {
      "command": "npx tsc --noEmit --skipLibCheck",
      "timeout": 60000,
      "parse_errors": true
    },
    "eslint_check": {
      "command": "npx eslint --format json",
      "timeout": 60000,
      "auto_fix_command": "npx eslint --fix"
    },
    "circular_deps_check": {
      "command": "npx madge --circular --extensions ts,tsx,js,jsx",
      "timeout": 30000
    },
    "package_validation": {
      "command": "npm ls --json",
      "timeout": 30000
    }
  },

  "gate_decisions": {
    "pass_criteria": {
      "critical_issues": 0,
      "error_issues": "<=3",
      "warning_issues": "<=10"
    },
    "actions": {
      "pass": "Proceed to IMPL-001.5 (Test Quality Gate)",
      "soft_fail": "Auto-fix and retry (max 2 attempts)",
      "hard_fail": "Block and report to user with fix suggestions"
    }
  }
}
