Public/Test-CCDependencies.ps1

function Test-CCDependencies {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)][string]$Path,
        [string]$Standard = 'core',
        [string]$Config
    )

    $cfg = Get-CCRepoConfig -Path $Path -Standard $Standard -ConfigFile $Config
    $disabled = $cfg['disabled_checks'] ?? @()
    $results = @()

    # DEP-001: Lockfile committed
    if ('DEP-001' -notin $disabled -and $cfg['require_lockfile']) {
        $lockfiles = @(
            'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml',   # JS
            'Pipfile.lock', 'poetry.lock',                          # Python
            'packages.lock.json',                                    # .NET
            'Gemfile.lock',                                          # Ruby
            'Cargo.lock'                                             # Rust
        )

        # Only check if a package manager is detected
        $hasPackageManager = (Test-Path (Join-Path $Path 'package.json')) -or
                             (Test-Path (Join-Path $Path 'Pipfile')) -or
                             (Test-Path (Join-Path $Path 'pyproject.toml')) -or
                             (Test-Path (Join-Path $Path 'Gemfile')) -or
                             (Test-Path (Join-Path $Path 'Cargo.toml')) -or
                             (Get-ChildItem $Path -Filter '*.csproj' -Recurse -Depth 2 -ErrorAction SilentlyContinue)

        if ($hasPackageManager) {
            $hasLock = $lockfiles | Where-Object { Test-Path (Join-Path $Path $_) } | Select-Object -First 1
            $results += New-CCRepoCheckResult -CheckId 'DEP-001' -Category 'Dependencies' `
                -Item 'Lockfile' `
                -Status $(if ($hasLock) { 'Pass' } else { 'Fail' }) `
                -Severity 'Error' `
                -Message $(if ($hasLock) { "Lockfile found: $hasLock" } else { "No lockfile found (package manager detected)" }) `
                -Standard $Standard
        }
        else {
            $results += New-CCRepoCheckResult -CheckId 'DEP-001' -Category 'Dependencies' `
                -Item 'Lockfile' -Status 'Skipped' -Severity 'Info' `
                -Message "No package manager detected — lockfile check skipped" -Standard $Standard
        }
    }

    # DEP-002: Dependabot or Renovate configured
    if ('DEP-002' -notin $disabled -and $cfg['require_dep_automation']) {
        $hasDependabot = Test-Path (Join-Path $Path '.github/dependabot.yml')
        $hasRenovate = (Test-Path (Join-Path $Path 'renovate.json')) -or
                       (Test-Path (Join-Path $Path '.renovaterc')) -or
                       (Test-Path (Join-Path $Path '.renovaterc.json'))

        $results += New-CCRepoCheckResult -CheckId 'DEP-002' -Category 'Dependencies' `
            -Item 'Dependency automation' `
            -Status $(if ($hasDependabot -or $hasRenovate) { 'Pass' } else { 'Fail' }) `
            -Severity 'Warning' `
            -Message $(if ($hasDependabot) { 'Dependabot configured' } elseif ($hasRenovate) { 'Renovate configured' } else { 'No dependency automation (dependabot/renovate) found' }) `
            -Standard $Standard `
            -FixAvailable $true `
            -FixAction 'Create .github/dependabot.yml'
    }

    $results
}