From e86aee5565349980879e7958f1d7e99c8c3a4576 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Thu, 12 Nov 2026 00:39:55 +0100 Subject: [PATCH] Release v1.4.2: trust the gate checkout on a share, fail a blind secret scan, audit in the worktree --- .claude/skills/ai-sdlc-gates/SKILL.md | 2 +- .../scripts/Test-GitleaksBaseline.Tests.ps1 | 22 +++++++-- .../scripts/Test-GitleaksBaseline.ps1 | 9 ++++ .../skills/ai-sdlc-gates/sync-manifest.json | 18 +++---- .claude/skills/ai-sdlc-hooks/SKILL.md | 4 +- .../skills/ai-sdlc-hooks/githooks/pre-push | 7 +++ .../scripts/AiSdlcSetup.Tests.ps1 | 49 +++++++++++++++++++ .../ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 | 31 ++++++++++-- .../scripts/PrePushHook.Tests.ps1 | 16 +++++- .../ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 | 8 +-- CHANGELOG.md | 12 +++++ apm.lock.yaml | 48 +++++++++--------- core/.apm/skills/ai-sdlc-gates/SKILL.md | 2 +- .../scripts/Test-GitleaksBaseline.Tests.ps1 | 22 +++++++-- .../scripts/Test-GitleaksBaseline.ps1 | 9 ++++ .../skills/ai-sdlc-gates/sync-manifest.json | 18 +++---- core/.apm/skills/ai-sdlc-hooks/SKILL.md | 4 +- .../skills/ai-sdlc-hooks/githooks/pre-push | 7 +++ .../scripts/AiSdlcSetup.Tests.ps1 | 49 +++++++++++++++++++ .../ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 | 31 ++++++++++-- .../scripts/PrePushHook.Tests.ps1 | 16 +++++- .../ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 | 8 +-- core/apm.yml | 2 +- packs/bicep/apm.yml | 2 +- packs/blazor/apm.yml | 2 +- packs/discovery/apm.yml | 2 +- packs/dotnet/apm.yml | 2 +- packs/github-issues/apm.yml | 2 +- packs/github/apm.yml | 2 +- packs/knowledge/apm.yml | 2 +- packs/sonarcloud/apm.yml | 2 +- 31 files changed, 325 insertions(+), 85 deletions(-) diff --git a/.claude/skills/ai-sdlc-gates/SKILL.md b/.claude/skills/ai-sdlc-gates/SKILL.md index b67bb96..8eff90e 100644 --- a/.claude/skills/ai-sdlc-gates/SKILL.md +++ b/.claude/skills/ai-sdlc-gates/SKILL.md @@ -98,7 +98,7 @@ These sit in the same `scripts/` folder but are not gates: - `Create-GitleaksBaseline.ps1` makes a gitleaks baseline with the rule sets pinned in `gitleaks-rules.json`. `Test-GitleaksBaseline.ps1` runs gitleaks against that baseline, or without one when the repository has none. It is the blocking C03 gate of `gates.json`. On a pull request in - GitHub Actions it scans `PR_BASE_SHA..HEAD`, the commits of the pull request, and in a local run `origin/main..HEAD`. + GitHub Actions it scans `PR_BASE_SHA..HEAD`, the commits of the pull request, and in a local run `origin/main..HEAD`. When git cannot read the folder, for example as "dubious ownership", it scans nothing and exits 2 locally and 1 in GitHub Actions, never 0. - `Install-Gitleaks.ps1` installs the gitleaks release pinned in `gitleaks-version.json` and refuses it on a SHA-256 mismatch, as `Install-Apm.ps1` does for APM. - `GitleaksConfig.psm1` writes the gitleaks configuration of a scan: the rules plus an allowlist for diff --git a/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 b/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 index 1c78729..3fe6bb3 100644 --- a/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 +++ b/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 @@ -28,9 +28,12 @@ Describe 'Test-GitleaksBaseline' { } | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $script:PinFile function Invoke-Scan { - param([hashtable]$Options = @{}, [switch]$NoBaseline) - $work = Join-Path $TestDrive ([guid]::NewGuid().ToString('n')) - New-Item -ItemType Directory -Path $work -Force | Out-Null + param([hashtable]$Options = @{}, [switch]$NoBaseline, [switch]$NotARepository) + if ($NotARepository) { + $work = Join-Path $TestDrive ([guid]::NewGuid().ToString('n')) + New-Item -ItemType Directory -Path $work -Force | Out-Null + } + else { $work = New-GitRepo } if (-not $NoBaseline) { $name = if ($Options.ContainsKey('BaselineFileName')) { $Options['BaselineFileName'] } else { 'gitleaks-baseline.json' } Set-Content -LiteralPath (Join-Path $work $name) -Value '[]' @@ -201,6 +204,19 @@ Describe 'Test-GitleaksBaseline' { Should -Invoke gitleaks -Times 0 -Exactly } + It 'exits and scans nothing when git cannot read the folder, so a refused checkout never passes, ' -ForEach @( + @{ Where = 'in GitHub Actions, so the build fails'; Pipeline = $true; Code = 1 } + @{ Where = 'in a local run, as a check that could not run'; Pipeline = $false; Code = 2 } + ) { + if ($Pipeline) { $env:GITHUB_ACTIONS = 'true' } + + $r = Invoke-Scan -NotARepository + + $r.Code | Should -Be $Code -Because $r.Output + $r.Output | Should -Match 'git cannot read the repository' + Should -Invoke gitleaks -Times 0 -Exactly + } + It 'exits 2 in a local run when a failed download leaves a partial file, and removes that file' { $global:PartialRules = $null Mock Invoke-WebRequest { Set-Content -LiteralPath $OutFile -Value '# half of the ru' -NoNewline; $global:PartialRules = $OutFile; throw 'connection reset' } diff --git a/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 b/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 index d90af9f..5f0562f 100644 --- a/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 +++ b/.claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 @@ -141,6 +141,15 @@ if (-not (Get-Command gitleaks -ErrorAction SilentlyContinue)) { exit $notChecked } +# Gitleaks reads the commits through git. When git refuses the repository, for example as "dubious +# ownership" in a checkout whose git data is on a share, gitleaks scans 0 commits and reports no leaks. +# So a folder that git cannot read is "could not check", never a pass. +$null = git -C $currentDirectory rev-parse --verify --quiet HEAD 2>$null +if ($LASTEXITCODE -ne 0) { + Write-Host "git cannot read the repository in $currentDirectory (for example 'dubious ownership'), so gitleaks would scan 0 commits. No secret scan ran." + exit $notChecked +} + if (-not $PSBoundParameters.ContainsKey('LogOpts')) { if ($inPipeline -and $env:PR_BASE_SHA) { $LogOpts = "$($env:PR_BASE_SHA)..HEAD" } elseif (-not $inPipeline -and (git -C $currentDirectory rev-parse --verify --quiet 'origin/main' 2>$null)) { $LogOpts = 'origin/main..HEAD' } diff --git a/.claude/skills/ai-sdlc-gates/sync-manifest.json b/.claude/skills/ai-sdlc-gates/sync-manifest.json index de79663..629d8f7 100644 --- a/.claude/skills/ai-sdlc-gates/sync-manifest.json +++ b/.claude/skills/ai-sdlc-gates/sync-manifest.json @@ -97,8 +97,8 @@ ".claude/skills/ai-sdlc-gates/scripts/Sync-AgentsFile.Tests.ps1": "87533e139944a9dcc50eb45a5109e2ff5f16e63b", ".claude/skills/ai-sdlc-gates/scripts/Sync-AllowRules.ps1": "0466893efb2128502dfe5367058d70231a1c14c3", ".claude/skills/ai-sdlc-gates/scripts/Sync-AllowRules.Tests.ps1": "93de3d86a94954e2a57b6ab417454018efebf041", - ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1": "d90af9f6881677ca4308cd4b67f7e0cd8a628533", - ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1": "1c787298ae7006c185e33ecf53f2b21e721cab03", + ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1": "5f0562f1a1143c8c4e19ef4a7ab446604591ec8d", + ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1": "3fe6bb3be599eb4da41a97d3a16cbd66b0da7c4a", ".claude/skills/ai-sdlc-gates/scripts/Test-PushReceipt.ps1": "54ec6a3e42d488994ee91d0f4993ba5d3366d96a", ".claude/skills/ai-sdlc-gates/scripts/Test-PushReceipt.Tests.ps1": "74968692c13e072622dcc86e75759a5de35a62b4", ".claude/skills/ai-sdlc-gates/scripts/Test-PushSendsNothingNew.ps1": "79da28786523f1f0c908c66032cce19d5b07f541", @@ -106,7 +106,7 @@ ".claude/skills/ai-sdlc-gates/scripts/ToolOutput.psm1": "1175b499e53dbe8b8ee25a177f65940eed07a492", ".claude/skills/ai-sdlc-gates/scripts/ToolOutput.Tests.ps1": "b3f0d8b2ee24547cc0299cff7ecf9163b583b4c5", ".claude/skills/ai-sdlc-gates/skill-catalog.json": "47720be4bb78fa80ba3be4546765c66c0ab313ba", - ".claude/skills/ai-sdlc-gates/SKILL.md": "b67bb9620a5acf979bfb229e2dbd7c6d2a81738c", + ".claude/skills/ai-sdlc-gates/SKILL.md": "8eff90e97ef2585101554b5df5e141cb222c0fc7", ".claude/skills/ai-sdlc-handbook/references/artifact-graph.md": "8e16413affc7aa745d6626d424f637113c9b31cf", ".claude/skills/ai-sdlc-handbook/references/autolearn.md": "a48ad70673bb2e67448628d23d2df7bd972eaccc", ".claude/skills/ai-sdlc-handbook/references/comments.md": "f3da979003caab216d22cf35c0ead91238232a82", @@ -132,9 +132,9 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "4061cda4b50922eb11ba925290c0cb4582806270", - ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "7355c080bd942e8efc7a9cf2b4ff49c341c0651b", - ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "9d6e2ba598e614d561e0facb56cc37d7b8381328", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "bc91ffa955ea59a548d00e2084371cf042e94201", + ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "4fd11f04b75ed9cf4991a1ce44bc4a2405b152a3", + ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "85a64b09bff6d716a0e07fc9d9ee8582015161c2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "117d527a075a78017b0a199703d84a6807797573", @@ -158,12 +158,12 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "b6b1e162200082e545ced70a584bd8ce8bb49f0a", - ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "65d8ba48c4e43ae9b086d632653b0815cc852a1d", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "dc8fc6e96b1afaddebd0bd2e9e47f49612c49335", + ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "372b0a9b02ff673f06e9d2729ca74476f512d155", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1": "21a220ca2ccc65a56ec427a6e74c5a5dbfbfd4ef", - ".claude/skills/ai-sdlc-hooks/SKILL.md": "db734978f41d8a0c98b6b1247ccce8ada5178f54", + ".claude/skills/ai-sdlc-hooks/SKILL.md": "33541a991e789d971017b63d415d0e6518f5047c", ".claude/skills/capture-learning/SKILL.md": "32300ce3189109b0d717f975623e8d7ccec1c821", ".claude/skills/convene-personas/SKILL.md": "449708a02206bec35a83d2f48ca6366c8b78e3a2", ".claude/skills/docs-wiki-conventions/SKILL.md": "0679512fa39815b63da6373ff29bb6eadc52ff24", diff --git a/.claude/skills/ai-sdlc-hooks/SKILL.md b/.claude/skills/ai-sdlc-hooks/SKILL.md index db73497..33541a9 100644 --- a/.claude/skills/ai-sdlc-hooks/SKILL.md +++ b/.claude/skills/ai-sdlc-hooks/SKILL.md @@ -42,7 +42,7 @@ The dotnet pack adds one more: `Deny-StaleGraphQuery.ps1` in `dotnet-code-graph` (`Test-PushReceipt.ps1` in `ai-sdlc-gates`). The pre-flight ran the same gates on that content, and the pull request build still runs them. A push that only deletes refs, or whose commits the remote already has, runs no gate at all. Only the refs of the remote being pushed to count. Both - push hooks judge this with one rule, `Test-PushSendsNothingNew` in `PreflightReceipt.psm1`. It also shows the change-completeness report and the `Last checked` report, which are advisory and never fail the push. On a network share, the gates run on a local checkout of the pushed commit, which is much faster. Last, it + push hooks judge this with one rule, `Test-PushSendsNothingNew` in `PreflightReceipt.psm1`. It also shows the change-completeness report and the `Last checked` report, which are advisory and never fail the push. On a network share, the gates run on a local checkout of the pushed commit, which is much faster. The git data of that checkout stays on the share, so the hook trusts the checkout folder through `GIT_CONFIG_COUNT` (`safe.directory`), only for the gates. Without it, git refused the checkout as "dubious ownership" and the secret scan read 0 commits. Last, it hands the same ref lines on to `git lfs pre-push`, so the LFS objects are uploaded. The other hooks refresh the code graph, and do nothing when the graph tooling is absent. - `githooks/git-lfs-hook` is shared by `pre-push`, `post-checkout`, `post-commit` and `post-merge`. @@ -58,7 +58,7 @@ The dotnet pack adds one more: `Deny-StaleGraphQuery.ps1` in `dotnet-code-graph` the pinned APM with `Install-Apm.ps1` when APM is missing, and warns when an installed APM is not the pinned version. It runs `apm install --frozen`, or plain `apm install` when there is no lock yet. On a network share it runs APM in a local worktree and copies the result back (`Invoke-ApmInstall`), - because APM 0.31.0 left changed skill folders empty there. Then it runs `Initialize-AiSdlc.ps1`. When the knowledge folder (`paths.knowledgeRoot`) is missing, it + because APM 0.31.0 left changed skill folders empty there. `Update-AiSdlc.ps1` runs `apm audit --ci` in that same worktree, because `apm_modules` exists only there. Then it runs `Initialize-AiSdlc.ps1`. When the knowledge folder (`paths.knowledgeRoot`) is missing, it says so, with the `gh repo clone` command when `knowledge.repository` is set. When a blocking setup check fails, it skips `apm install` and says so. It still runs `Initialize-AiSdlc.ps1`, and then exits 1. It works before APM is on the machine, because the repository commits the installed files. diff --git a/.claude/skills/ai-sdlc-hooks/githooks/pre-push b/.claude/skills/ai-sdlc-hooks/githooks/pre-push index 4061cda..bc91ffa 100644 --- a/.claude/skills/ai-sdlc-hooks/githooks/pre-push +++ b/.claude/skills/ai-sdlc-hooks/githooks/pre-push @@ -149,6 +149,13 @@ run_gates() ( trap 'exit 130' INT TERM echo "pre-push: the gates run on a local checkout of $tips, because the repository is on a network share." cd "$gate_root" || return 1 + # The git data of the checkout sits on the share, which another user owns, so git refuses the + # checkout as "dubious ownership". Then gitleaks scanned 0 commits and still passed. This trusts + # the one checkout folder, only for the gates and through the environment; the git config of + # the machine stays as it is. Git on Windows names the folder C:/..., so cygpath converts it. + safe_dir=$(cygpath -m "$gate_root" 2>/dev/null) || safe_dir=$gate_root + n=${GIT_CONFIG_COUNT:-0} + export "GIT_CONFIG_KEY_$n=safe.directory" "GIT_CONFIG_VALUE_$n=$safe_dir" "GIT_CONFIG_COUNT=$((n + 1))" runner="$gate_root/.claude/skills/ai-sdlc-gates/scripts/Invoke-LocalGates.ps1" fi echo "pre-push: running blocking CA gates ($runner -BlockingOnly)..." diff --git a/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 index 9d6e2ba..85a64b0 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 @@ -251,6 +251,55 @@ Describe 'AiSdlcSetup' { Get-ApmDeployedFile -LockPath $lock | Should -Be @('.claude/skills/a', '.claude/skills/a/SKILL.md') } + It 'runs apm audit --ci in the worktree after the install and hands back its exit code, on a share' { + $env:AISDLC_APM_LOCAL_INSTALL = '1' + $script:Calls = [Collections.Generic.List[string]]::new() + Mock apm { + $script:Calls.Add("$($args -join ' ') @ $((Get-Location).Path)") + if ($args[0] -eq 'install') { New-Item -ItemType Directory -Path (Join-Path (Get-Location).Path 'apm_modules') -Force | Out-Null } + $global:LASTEXITCODE = if ($args[0] -eq 'audit') { if (Test-Path -LiteralPath (Join-Path (Get-Location).Path 'apm_modules')) { 0 } else { 1 } } else { 0 } + } + $audit = 9 + + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 0 + + $audit | Should -Be 0 + $script:Calls.Count | Should -Be 2 + $script:Calls[1] | Should -BeLike 'audit --ci @ *' + $script:Calls[1] | Should -Not -BeLike "* @ $((Resolve-Path -LiteralPath $script:Repo).Path)" + } + + It 'leaves the share as it was when the audit fails in the worktree' { + $env:AISDLC_APM_LOCAL_INSTALL = '1' + Set-Content -LiteralPath (Join-Path $script:Repo 'apm.lock.yaml') -Value "deployed_files:`n - .claude/skills/x/SKILL.md" + Mock apm { + if ($args[0] -eq 'install') { Set-Content -LiteralPath (Join-Path (Get-Location).Path '.claude/skills/x/SKILL.md') -Value 'new' } + $global:LASTEXITCODE = if ($args[0] -eq 'audit') { 4 } else { 0 } + } + $audit = 0 + + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 0 + + $audit | Should -Be 4 + (Get-Content -LiteralPath (Join-Path $script:Repo '.claude/skills/x/SKILL.md') -Raw).Trim() | Should -Be 'old' + @(git -C $script:Repo worktree list).Count | Should -Be 1 + } + + It 'runs the audit in the repository itself when it is not on a network share, and only after a good install' { + $script:Calls = [Collections.Generic.List[string]]::new() + Mock apm { $script:Calls.Add($args[0]); $global:LASTEXITCODE = 0 } + $audit = 9 + + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 0 + $audit | Should -Be 0 + $script:Calls | Should -Be @('install', 'audit') + + $script:Calls.Clear() + Mock apm { $script:Calls.Add($args[0]); $global:LASTEXITCODE = 3 } + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 3 + $script:Calls | Should -Be @('install') + } + It 'leaves the repository as it was when apm fails in the worktree' { $env:AISDLC_APM_LOCAL_INSTALL = '1' Mock apm { diff --git a/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 index 7355c08..4fd11f0 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 @@ -208,7 +208,11 @@ function Invoke-ApmInstall { [CmdletBinding()] param( [Parameter(Mandatory)][string]$RepoRoot, - [string[]]$Arguments = @('install') + [string[]]$Arguments = @('install'), + # When given, apm audit --ci runs after a good install, in the same folder, and its exit code goes here. + # On a share that folder is the worktree: only there does apm_modules exist, so an audit on the share + # itself fails on a good install. + [ref]$AuditCode ) $want = $env:AISDLC_APM_LOCAL_INSTALL @@ -216,8 +220,16 @@ function Invoke-ApmInstall { if (-not $useLocal) { Push-Location -LiteralPath $RepoRoot - try { apm @Arguments | Out-Host } finally { Pop-Location } - return $LASTEXITCODE + try { + apm @Arguments | Out-Host + $code = $LASTEXITCODE + if ($code -eq 0 -and $AuditCode) { + apm audit --ci | Out-Host + $AuditCode.Value = $LASTEXITCODE + } + } + finally { Pop-Location } + return $code } # On a share, APM 0.31.0 reported a good install but left the changed skill folders empty, and its lock @@ -243,9 +255,18 @@ function Invoke-ApmInstall { $before = @(Get-ApmDeployedFile -LockPath (Join-Path $RepoRoot 'apm.lock.yaml')) Write-Host "apm runs in a local worktree, because the repository is on a network share: $worktree" Push-Location -LiteralPath $worktree - try { apm @Arguments | Out-Host } finally { Pop-Location } - $code = $LASTEXITCODE + try { + apm @Arguments | Out-Host + $code = $LASTEXITCODE + if ($code -eq 0 -and $AuditCode) { + apm audit --ci | Out-Host + $AuditCode.Value = $LASTEXITCODE + } + } + finally { Pop-Location } if ($code -ne 0) { return $code } + # A failed audit leaves the share as it was, so the caller can stop with nothing changed. + if ($AuditCode -and $AuditCode.Value -ne 0) { return 0 } $after = @(Get-ApmDeployedFile -LockPath (Join-Path $worktree 'apm.lock.yaml')) foreach ($path in @($after + $own | Select-Object -Unique)) { diff --git a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index b6b1e16..dc8fc6e 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -198,7 +198,7 @@ Describe 'The pre-push git hook' { # The committed runner prints "committed"; the working tree holds an uncommitted copy that prints # "worktree". So the output shows which copy ran. function Invoke-PushFromShare { - param([string]$Checkout, [int]$RunnerExit = 0) + param([string]$Checkout, [int]$RunnerExit = 0, [string]$RunnerExtra = '') $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) $gates = Join-Path $root '.claude' 'skills' 'ai-sdlc-gates' 'scripts' New-Item -ItemType Directory -Path $gates -Force | Out-Null @@ -206,7 +206,7 @@ Describe 'The pre-push git hook' { git -C $root config user.email probe@example.invalid git -C $root config user.name probe $runner = Join-Path $gates 'Invoke-LocalGates.ps1' - Set-Content -LiteralPath $runner -Value "Write-Host 'runner copy=committed'; exit $RunnerExit" + Set-Content -LiteralPath $runner -Value "$RunnerExtra`nWrite-Host 'runner copy=committed'; exit $RunnerExit" Set-Content -LiteralPath (Join-Path $gates 'Check-ChangeCompleteness.ps1') -Value "Write-Host 'completeness copy=committed'" git -C $root add . git -C $root commit --quiet -m one --no-verify @@ -238,6 +238,18 @@ Describe 'The pre-push git hook' { $r.Worktrees | Should -Be 1 -Because 'only the main working tree is left' } + It 'trusts only the checkout folder for git in the gates, through the environment, so git does not refuse it as dubious ownership' -Skip:($script:NoSh -or $script:NoPwshShare) { + $extra = 'Write-Host "safe=$(git config --get-all safe.directory | Select-Object -Last 1)|top=$(git rev-parse --show-toplevel)|count=$env:GIT_CONFIG_COUNT"' + $r = Invoke-PushFromShare -Checkout '1' -RunnerExtra $extra + + $r.Code | Should -Be 0 -Because $r.Output + $m = [regex]::Match($r.Output, 'safe=(?[^|]*)\|top=(?[^|]*)\|count=(?\d+)') + $m.Success | Should -BeTrue -Because $r.Output + $m.Groups['safe'].Value.Trim() | Should -Be $m.Groups['top'].Value.Trim() + [int]$m.Groups['count'].Value | Should -BeGreaterOrEqual 1 + $r.Output | Should -Match 'runner copy=committed' + } + It 'refuses the push when a gate fails in the checkout, and still removes it' -Skip:($script:NoSh -or $script:NoPwshShare) { $r = Invoke-PushFromShare -Checkout '1' -RunnerExit 1 diff --git a/.claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 b/.claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 index 65d8ba4..372b0a9 100644 --- a/.claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 +++ b/.claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 @@ -107,11 +107,11 @@ Write-Host "Moved $moved AI.SDLC ref(s) in apm.yml to $Ref; the refs of other so Push-Location $RepoRoot try { - $installCode = Invoke-ApmInstall -RepoRoot $RepoRoot + $auditCode = 0 + $installCode = Invoke-ApmInstall -RepoRoot $RepoRoot -AuditCode ([ref]$auditCode) if ($installCode -ne 0) { throw (Get-ApmInstallFailureHint -ExitCode $installCode) } - apm audit --ci - if ($LASTEXITCODE -ne 0) { - throw "apm audit --ci failed with exit code $LASTEXITCODE, so apm.yml, apm.lock.yaml and the installed files under .claude/ do not agree. Read its output above. Nothing is staged yet." + if ($auditCode -ne 0) { + throw "apm audit --ci failed with exit code $auditCode, so apm.yml, apm.lock.yaml and the installed files under .claude/ do not agree. Read its output above. Nothing is staged yet." } foreach ($p in @('apm.yml', 'apm.lock.yaml', '.claude')) { if (Test-Path -LiteralPath (Join-Path $RepoRoot $p)) { git add -- $p } diff --git a/CHANGELOG.md b/CHANGELOG.md index c47681e..6cd797a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,18 @@ merge is ready to tag, and no second pull request is needed to name the version. Each entry names its issue, as `#42`. +## v1.4.2 - 2026-11-12 + +- On a network share, the pre-push hook runs the gates in a local checkout whose git data stays on the + share. Git refused that checkout as "dubious ownership", so the C03 secret scan read 0 commits and + still passed. The hook now trusts the checkout folder through `GIT_CONFIG_COUNT` (`safe.directory`), + only for the gates; the git config of the machine is not changed (#20). +- `Test-GitleaksBaseline.ps1` checks that git can read the folder before it scans. When it cannot, the + gate exits 2 locally and 1 in GitHub Actions, so a blind scan never passes (#20). +- On a share, `Update-AiSdlc.ps1` runs `apm audit --ci` in the local worktree of the install, where + `apm_modules` exists. On the share itself the audit failed after a good install. A failed audit now + leaves the share as it was (#20). + ## v1.4.1 - 2026-11-11 - On a network share, `Install-AiSdlc.ps1` and `Update-AiSdlc.ps1` run `apm install` in a local git diff --git a/apm.lock.yaml b/apm.lock.yaml index 79e9590..ba33da1 100644 --- a/apm.lock.yaml +++ b/apm.lock.yaml @@ -3,7 +3,7 @@ apm_version: 0.31.0 dependencies: - repo_url: _local/core name: ai-sdlc-core - version: 1.4.1 + version: 1.4.2 package_type: apm_package deployed_files: - .claude/agents/architect.md @@ -246,7 +246,7 @@ dependencies: .claude/skills/adopt-docs/scripts/Test-DocCandidate.Tests.ps1: sha256:7e033f52e49f213fff6237299cc0c9ce103b5955861f50ab5923b73da57c713c .claude/skills/adopt-docs/scripts/Test-DocCandidate.ps1: sha256:0c54a3f64241f5a7af12f552dde3dee7b844fad0f88db2980ce87eca42431946 .claude/skills/adr-conventions/SKILL.md: sha256:819d4d4e8f584dc0dddd8a32cc16669317fe13a89acca9c190ff565f7923340b - .claude/skills/ai-sdlc-gates/SKILL.md: sha256:09165e4e714d27feedf2c07f0da9e3e4ceb485cbb8171b959428705c1247a83e + .claude/skills/ai-sdlc-gates/SKILL.md: sha256:7d0c9edfcb926c58c2e46b03cdf0d5671f2e9a686ae7c6f470127710f559dac2 .claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml: sha256:ee6430668f2f44b6256275645e10f8ab2167b8b6d49990465c5527d1b334abac .claude/skills/ai-sdlc-gates/assets/agents-core.md: sha256:544bb5b78ceaa2ee9eb20203ecdef5d380ecd9b10265cc90d10385d96ed72509 .claude/skills/ai-sdlc-gates/gates.json: sha256:4f2b4947786c623788a7853675754822b7ed8bd55717ad9c47f7c699a0252928 @@ -319,8 +319,8 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/Sync-AgentsFile.ps1: sha256:26d154d3a0e17c5d2e84bc1d388ac7fe292dcf08933e696293b7801cf1a21cd1 .claude/skills/ai-sdlc-gates/scripts/Sync-AllowRules.Tests.ps1: sha256:f5fcd4a5d50f6e617802eaf7ddabf6ec4ae4530dc2f7a4bc7105d4e1b96ee70f .claude/skills/ai-sdlc-gates/scripts/Sync-AllowRules.ps1: sha256:85c9eb910410b46d70124159a7a58599adf0537b3c6200c67de05e40b2d9ed20 - .claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1: sha256:e8a5763be910fade0018de12453febe990fb84c4ec265e7f9757da4459c55f63 - .claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1: sha256:79059d12e703af2ab5534c954f4accd0cce08a102ff8853bef66118fce80a093 + .claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1: sha256:c7bc96388df2b0a6c33a35a8b35bacf96d487375f34e567c00ec1c638f26aeaa + .claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1: sha256:e8b8f218a3886fa25c8a84916dd005ab30169e2983679b4498bbbfd049827826 .claude/skills/ai-sdlc-gates/scripts/Test-PushReceipt.Tests.ps1: sha256:54ed79f8f67be5481ee9613a12bbfa4b71aa508f2d143e661afbe518db8f40ef .claude/skills/ai-sdlc-gates/scripts/Test-PushReceipt.ps1: sha256:12cb640a6acf0d1966b43798f9bbde65bffc76ad05781e5dfc8338599f329158 .claude/skills/ai-sdlc-gates/scripts/Test-PushSendsNothingNew.Tests.ps1: sha256:a47e96755dba99b448c287c9fcb2f584713b31927022a28490e8d04c333b634b @@ -335,7 +335,7 @@ dependencies: .claude/skills/ai-sdlc-gates/scripts/gitleaks-rules.json: sha256:6a8a75c5dbcf2378a1c52d046e34ce275aac7ce08a0ae61408d25c18e1e27014 .claude/skills/ai-sdlc-gates/scripts/gitleaks-version.json: sha256:c54acb854f87a1bbdf0e90c670b72b5de3cd37f7e460d82eca599c3c7af23a84 .claude/skills/ai-sdlc-gates/skill-catalog.json: sha256:5537684656bf189a740ba7e9e7050083af05668d00501ce1e9c6909cb8b91203 - .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:a52a31ec82c3b2c211eeb9ba126b56cc4331a8cac8f01a6605a51d33874d609c + .claude/skills/ai-sdlc-gates/sync-manifest.json: sha256:e96ed9ae2d913ec0c7014f1c43254003b32af1dda025ffa108ae7ac14851c55f .claude/skills/ai-sdlc-handbook/SKILL.md: sha256:548e6b9ad79d3d2afa2f5779835988eeb12c49cda08917c4bbaa9ac0486a47a0 .claude/skills/ai-sdlc-handbook/references/README.md: sha256:654afcaa2b81f560eff93dbdef521b09ced06137a1dbb85d70a4e14ef7502248 .claude/skills/ai-sdlc-handbook/references/artifact-graph.md: sha256:d7ddfe20e5ee6565bcf25f9cef0f578da2a4ab1590033d791b8814d4688fd1f0 @@ -354,7 +354,7 @@ dependencies: .claude/skills/ai-sdlc-handbook/references/personas.md: sha256:7913c3dca6bad93b45624349a12bf976f894eb6ca05c7baa1fa7e3ba802ca69a .claude/skills/ai-sdlc-handbook/references/plan.md: sha256:b632fe2da2369f494ebe2606c4bdc8726eabe3b7615b6ddb0b58fa9b3897a216 .claude/skills/ai-sdlc-handbook/references/skill-usage.md: sha256:9d5414b38d9d6f5bd7dfa9857e8e441bf040b0020f46ac8d3b29b0a476161c61 - .claude/skills/ai-sdlc-hooks/SKILL.md: sha256:95534da6540a369a528b7c911884bd1e720c858feb7d89ef84a135835fcc0b80 + .claude/skills/ai-sdlc-hooks/SKILL.md: sha256:a0afb2d7f676fbb7f51066b4c82a38b2ee3f883acf59a6ef548d1a8f7730a0a8 .claude/skills/ai-sdlc-hooks/gates.json: sha256:dfc8b0003e930167e0fccc366867f423bc0850f3c69477c0e7119aed710bf902 .claude/skills/ai-sdlc-hooks/githooks/git-lfs-hook: sha256:3265310500749e7181a5625517f94e2efa62d48be987ebc9b0396d38e2eeffa6 .claude/skills/ai-sdlc-hooks/githooks/graphify-refresh: sha256:1bc6c7f181aab3a0fdd34bf8907a4884bea2412a56ebdc77a673707e17c046f3 @@ -362,9 +362,9 @@ dependencies: .claude/skills/ai-sdlc-hooks/githooks/post-commit: sha256:4f73a74133b0272725117fa9d962353abb6ed98d9cf5e731cd212fd5ace23271 .claude/skills/ai-sdlc-hooks/githooks/post-merge: sha256:b9f1f47cd3894406451e00c177912baeed66470b0cc18d581a5461330c7c0868 .claude/skills/ai-sdlc-hooks/githooks/post-rewrite: sha256:b7ee1a97b08a9826678829b6c49457fdc4b5ebd53eaf8cdd70f33d26e61c4a79 - .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:b926f356e8fdb8592986a814cae30e0fd2db6d44624dc38bd71b192eff12ca14 - .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1: sha256:8f407ecea08cc3bfbe54091ab581cbc0e7c09ed08ade344d9da994fcf9f8188e - .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:4f38a4bf8f5ad6b0f9514c7e5bd501ccf44f377eb94301b216646e59f8c43c2c + .claude/skills/ai-sdlc-hooks/githooks/pre-push: sha256:9643320b24b09ae2b31503a1050c9ed4af773d2f38a823f2852554e75028dfdd + .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1: sha256:44718d25336418f99ab64bda678d008d7ed824a79551f9b8076ee091e25ea10d + .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1: sha256:0f6991da71af4644215b30d5ff0efddb7659c9b5805bf7044ef1a0080c5865fb .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1: sha256:4c4e1f6b673671125290d78815c72277665a8a618b55fd589f75f3a36e3b80aa .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1: sha256:46d1d83e38e75db41b1f370bc6f49f4800f0234765eac63c53e37b5af7000453 .claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.Tests.ps1: sha256:ea9062bd8b20ad47d488b9838eb5a6c735d73b3148cdcfdd9ebdd60ef708f897 @@ -388,9 +388,9 @@ dependencies: .claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.ps1: sha256:d60cdd2d341487ded3b9fafe40da49f2adfb1cf8f20cf3f8559ea2e80a5f93c6 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1: sha256:9c9859767d2534c45e1c72b47f4b5c64aaa16c32c580df3b5d8bc3dce5cdb2c4 .claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1: sha256:abf763c6cde97dbfc83b25f140e768d66fd9edd3961605b7d058b08a31882875 - .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:e8209185ca6a2cba6e73b3fc803dc0ee1a904665e60344536066b8cc43933be3 + .claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1: sha256:d0a0e1a1d05951b20f46221807fb4cc14f55b41ff3df5bc75b8700303c946d0e .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1: sha256:4f2fe5313c8763f8128ad0e0347da1f2dd485393d20dc5e3a5d75e08aa157ad3 - .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1: sha256:1f538fcbfab38649a8d751f9d5d5b23af7266559763d5bd88f135e1ecae23ef4 + .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1: sha256:96c049c016308e6c2dd7fc2f26377e1cda2a6bdaf102965b82073289cf6d8b2d .claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1: sha256:52f81e945390e61222a2668c8525cb17f17226267e24c52d7792263a07576543 .claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1: sha256:bced551398c063a710aa453dd00317e7f34b43e9db3e213eaf7dde21db2ae58b .claude/skills/capture-learning/SKILL.md: sha256:33452a09b89f55fb665ccb2790027ed1b2c9bd612fb4675013181808cd9dff3f @@ -431,7 +431,7 @@ dependencies: local_path: ./core - repo_url: _local/discovery name: ai-sdlc-discovery - version: 1.4.1 + version: 1.4.2 package_type: apm_package deployed_files: - .claude/skills/draw-customer-journey @@ -448,7 +448,7 @@ dependencies: local_path: ./packs/discovery - repo_url: _local/github name: ai-sdlc-github - version: 1.4.1 + version: 1.4.2 package_type: apm_package deployed_files: - .claude/skills/fix-pr-feedback @@ -538,7 +538,7 @@ dependencies: local_path: ./packs/github - repo_url: _local/github-issues name: ai-sdlc-github-issues - version: 1.4.1 + version: 1.4.2 package_type: apm_package deployed_files: - .claude/agents/draft-reviewer.md @@ -772,7 +772,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:09165e4e714d27feedf2c07f0da9e3e4ceb485cbb8171b959428705c1247a83e + content_hash: sha256:7d0c9edfcb926c58c2e46b03cdf0d5671f2e9a686ae7c6f470127710f559dac2 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-gates/assets/actions/ai-sdlc-pr/action.yml @@ -1429,7 +1429,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:e8a5763be910fade0018de12453febe990fb84c4ec265e7f9757da4459c55f63 + content_hash: sha256:c7bc96388df2b0a6c33a35a8b35bacf96d487375f34e567c00ec1c638f26aeaa - kind: project-relative target: claude value: .claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 @@ -1438,7 +1438,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:79059d12e703af2ab5534c954f4accd0cce08a102ff8853bef66118fce80a093 + content_hash: sha256:e8b8f218a3886fa25c8a84916dd005ab30169e2983679b4498bbbfd049827826 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-gates/scripts/Test-PushReceipt.Tests.ps1 @@ -1573,7 +1573,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:a52a31ec82c3b2c211eeb9ba126b56cc4331a8cac8f01a6605a51d33874d609c + content_hash: sha256:e96ed9ae2d913ec0c7014f1c43254003b32af1dda025ffa108ae7ac14851c55f - kind: project-relative target: claude value: .claude/skills/ai-sdlc-handbook @@ -1762,7 +1762,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:95534da6540a369a528b7c911884bd1e720c858feb7d89ef84a135835fcc0b80 + content_hash: sha256:a0afb2d7f676fbb7f51066b4c82a38b2ee3f883acf59a6ef548d1a8f7730a0a8 - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/gates.json @@ -1834,7 +1834,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:b926f356e8fdb8592986a814cae30e0fd2db6d44624dc38bd71b192eff12ca14 + content_hash: sha256:9643320b24b09ae2b31503a1050c9ed4af773d2f38a823f2852554e75028dfdd - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 @@ -1843,7 +1843,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:8f407ecea08cc3bfbe54091ab581cbc0e7c09ed08ade344d9da994fcf9f8188e + content_hash: sha256:44718d25336418f99ab64bda678d008d7ed824a79551f9b8076ee091e25ea10d - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 @@ -1852,7 +1852,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:4f38a4bf8f5ad6b0f9514c7e5bd501ccf44f377eb94301b216646e59f8c43c2c + content_hash: sha256:0f6991da71af4644215b30d5ff0efddb7659c9b5805bf7044ef1a0080c5865fb - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1 @@ -2068,7 +2068,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:e8209185ca6a2cba6e73b3fc803dc0ee1a904665e60344536066b8cc43933be3 + content_hash: sha256:d0a0e1a1d05951b20f46221807fb4cc14f55b41ff3df5bc75b8700303c946d0e - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1 @@ -2086,7 +2086,7 @@ deployments: owners: - ./core active_owner: ./core - content_hash: sha256:1f538fcbfab38649a8d751f9d5d5b23af7266559763d5bd88f135e1ecae23ef4 + content_hash: sha256:96c049c016308e6c2dd7fc2f26377e1cda2a6bdaf102965b82073289cf6d8b2d - kind: project-relative target: claude value: .claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1 diff --git a/core/.apm/skills/ai-sdlc-gates/SKILL.md b/core/.apm/skills/ai-sdlc-gates/SKILL.md index b67bb96..8eff90e 100644 --- a/core/.apm/skills/ai-sdlc-gates/SKILL.md +++ b/core/.apm/skills/ai-sdlc-gates/SKILL.md @@ -98,7 +98,7 @@ These sit in the same `scripts/` folder but are not gates: - `Create-GitleaksBaseline.ps1` makes a gitleaks baseline with the rule sets pinned in `gitleaks-rules.json`. `Test-GitleaksBaseline.ps1` runs gitleaks against that baseline, or without one when the repository has none. It is the blocking C03 gate of `gates.json`. On a pull request in - GitHub Actions it scans `PR_BASE_SHA..HEAD`, the commits of the pull request, and in a local run `origin/main..HEAD`. + GitHub Actions it scans `PR_BASE_SHA..HEAD`, the commits of the pull request, and in a local run `origin/main..HEAD`. When git cannot read the folder, for example as "dubious ownership", it scans nothing and exits 2 locally and 1 in GitHub Actions, never 0. - `Install-Gitleaks.ps1` installs the gitleaks release pinned in `gitleaks-version.json` and refuses it on a SHA-256 mismatch, as `Install-Apm.ps1` does for APM. - `GitleaksConfig.psm1` writes the gitleaks configuration of a scan: the rules plus an allowlist for diff --git a/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 b/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 index 1c78729..3fe6bb3 100644 --- a/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1 @@ -28,9 +28,12 @@ Describe 'Test-GitleaksBaseline' { } | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $script:PinFile function Invoke-Scan { - param([hashtable]$Options = @{}, [switch]$NoBaseline) - $work = Join-Path $TestDrive ([guid]::NewGuid().ToString('n')) - New-Item -ItemType Directory -Path $work -Force | Out-Null + param([hashtable]$Options = @{}, [switch]$NoBaseline, [switch]$NotARepository) + if ($NotARepository) { + $work = Join-Path $TestDrive ([guid]::NewGuid().ToString('n')) + New-Item -ItemType Directory -Path $work -Force | Out-Null + } + else { $work = New-GitRepo } if (-not $NoBaseline) { $name = if ($Options.ContainsKey('BaselineFileName')) { $Options['BaselineFileName'] } else { 'gitleaks-baseline.json' } Set-Content -LiteralPath (Join-Path $work $name) -Value '[]' @@ -201,6 +204,19 @@ Describe 'Test-GitleaksBaseline' { Should -Invoke gitleaks -Times 0 -Exactly } + It 'exits and scans nothing when git cannot read the folder, so a refused checkout never passes, ' -ForEach @( + @{ Where = 'in GitHub Actions, so the build fails'; Pipeline = $true; Code = 1 } + @{ Where = 'in a local run, as a check that could not run'; Pipeline = $false; Code = 2 } + ) { + if ($Pipeline) { $env:GITHUB_ACTIONS = 'true' } + + $r = Invoke-Scan -NotARepository + + $r.Code | Should -Be $Code -Because $r.Output + $r.Output | Should -Match 'git cannot read the repository' + Should -Invoke gitleaks -Times 0 -Exactly + } + It 'exits 2 in a local run when a failed download leaves a partial file, and removes that file' { $global:PartialRules = $null Mock Invoke-WebRequest { Set-Content -LiteralPath $OutFile -Value '# half of the ru' -NoNewline; $global:PartialRules = $OutFile; throw 'connection reset' } diff --git a/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 b/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 index d90af9f..5f0562f 100644 --- a/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 +++ b/core/.apm/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1 @@ -141,6 +141,15 @@ if (-not (Get-Command gitleaks -ErrorAction SilentlyContinue)) { exit $notChecked } +# Gitleaks reads the commits through git. When git refuses the repository, for example as "dubious +# ownership" in a checkout whose git data is on a share, gitleaks scans 0 commits and reports no leaks. +# So a folder that git cannot read is "could not check", never a pass. +$null = git -C $currentDirectory rev-parse --verify --quiet HEAD 2>$null +if ($LASTEXITCODE -ne 0) { + Write-Host "git cannot read the repository in $currentDirectory (for example 'dubious ownership'), so gitleaks would scan 0 commits. No secret scan ran." + exit $notChecked +} + if (-not $PSBoundParameters.ContainsKey('LogOpts')) { if ($inPipeline -and $env:PR_BASE_SHA) { $LogOpts = "$($env:PR_BASE_SHA)..HEAD" } elseif (-not $inPipeline -and (git -C $currentDirectory rev-parse --verify --quiet 'origin/main' 2>$null)) { $LogOpts = 'origin/main..HEAD' } diff --git a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json index de79663..629d8f7 100644 --- a/core/.apm/skills/ai-sdlc-gates/sync-manifest.json +++ b/core/.apm/skills/ai-sdlc-gates/sync-manifest.json @@ -97,8 +97,8 @@ ".claude/skills/ai-sdlc-gates/scripts/Sync-AgentsFile.Tests.ps1": "87533e139944a9dcc50eb45a5109e2ff5f16e63b", ".claude/skills/ai-sdlc-gates/scripts/Sync-AllowRules.ps1": "0466893efb2128502dfe5367058d70231a1c14c3", ".claude/skills/ai-sdlc-gates/scripts/Sync-AllowRules.Tests.ps1": "93de3d86a94954e2a57b6ab417454018efebf041", - ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1": "d90af9f6881677ca4308cd4b67f7e0cd8a628533", - ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1": "1c787298ae7006c185e33ecf53f2b21e721cab03", + ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.ps1": "5f0562f1a1143c8c4e19ef4a7ab446604591ec8d", + ".claude/skills/ai-sdlc-gates/scripts/Test-GitleaksBaseline.Tests.ps1": "3fe6bb3be599eb4da41a97d3a16cbd66b0da7c4a", ".claude/skills/ai-sdlc-gates/scripts/Test-PushReceipt.ps1": "54ec6a3e42d488994ee91d0f4993ba5d3366d96a", ".claude/skills/ai-sdlc-gates/scripts/Test-PushReceipt.Tests.ps1": "74968692c13e072622dcc86e75759a5de35a62b4", ".claude/skills/ai-sdlc-gates/scripts/Test-PushSendsNothingNew.ps1": "79da28786523f1f0c908c66032cce19d5b07f541", @@ -106,7 +106,7 @@ ".claude/skills/ai-sdlc-gates/scripts/ToolOutput.psm1": "1175b499e53dbe8b8ee25a177f65940eed07a492", ".claude/skills/ai-sdlc-gates/scripts/ToolOutput.Tests.ps1": "b3f0d8b2ee24547cc0299cff7ecf9163b583b4c5", ".claude/skills/ai-sdlc-gates/skill-catalog.json": "47720be4bb78fa80ba3be4546765c66c0ab313ba", - ".claude/skills/ai-sdlc-gates/SKILL.md": "b67bb9620a5acf979bfb229e2dbd7c6d2a81738c", + ".claude/skills/ai-sdlc-gates/SKILL.md": "8eff90e97ef2585101554b5df5e141cb222c0fc7", ".claude/skills/ai-sdlc-handbook/references/artifact-graph.md": "8e16413affc7aa745d6626d424f637113c9b31cf", ".claude/skills/ai-sdlc-handbook/references/autolearn.md": "a48ad70673bb2e67448628d23d2df7bd972eaccc", ".claude/skills/ai-sdlc-handbook/references/comments.md": "f3da979003caab216d22cf35c0ead91238232a82", @@ -132,9 +132,9 @@ ".claude/skills/ai-sdlc-hooks/githooks/post-commit": "f18058f9a38efc164e13801d61bb05329a056109", ".claude/skills/ai-sdlc-hooks/githooks/post-merge": "bb373f33abd09294cda55d7fc4499f32672eb372", ".claude/skills/ai-sdlc-hooks/githooks/post-rewrite": "e4c187dffeeaba569901f3424fae476b17c14927", - ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "4061cda4b50922eb11ba925290c0cb4582806270", - ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "7355c080bd942e8efc7a9cf2b4ff49c341c0651b", - ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "9d6e2ba598e614d561e0facb56cc37d7b8381328", + ".claude/skills/ai-sdlc-hooks/githooks/pre-push": "bc91ffa955ea59a548d00e2084371cf042e94201", + ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1": "4fd11f04b75ed9cf4991a1ce44bc4a2405b152a3", + ".claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1": "85a64b09bff6d716a0e07fc9d9ee8582015161c2", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.ps1": "535543b86886fcc582912ded5373b0bd3d756356", ".claude/skills/ai-sdlc-hooks/scripts/Deny-AgentMerge.Tests.ps1": "c8dfc8a4f31b6ec89a6d680e936e3563afa62bcb", ".claude/skills/ai-sdlc-hooks/scripts/Deny-IncompletePush.ps1": "117d527a075a78017b0a199703d84a6807797573", @@ -158,12 +158,12 @@ ".claude/skills/ai-sdlc-hooks/scripts/Invoke-PostEditCheck.Tests.ps1": "3429e18735428ab387ab58ae276d4195b32e7999", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.ps1": "b54f90deb751d0b0dbf8ee8fbc3f39b3300b3b3d", ".claude/skills/ai-sdlc-hooks/scripts/New-AiSdlcUpdatePullRequest.Tests.ps1": "77e4b627da13ea9887f3918f66bc5b33dfd91c56", - ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "b6b1e162200082e545ced70a584bd8ce8bb49f0a", - ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "65d8ba48c4e43ae9b086d632653b0815cc852a1d", + ".claude/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1": "dc8fc6e96b1afaddebd0bd2e9e47f49612c49335", + ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1": "372b0a9b02ff673f06e9d2729ca74476f512d155", ".claude/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.Tests.ps1": "8db305e438bc7ee404eb5106eacbe5581738f148", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.ps1": "fa3d7f509b6f9a1a935178c1eaf0d1566b7afead", ".claude/skills/ai-sdlc-hooks/scripts/WindowsLongPaths.Tests.ps1": "21a220ca2ccc65a56ec427a6e74c5a5dbfbfd4ef", - ".claude/skills/ai-sdlc-hooks/SKILL.md": "db734978f41d8a0c98b6b1247ccce8ada5178f54", + ".claude/skills/ai-sdlc-hooks/SKILL.md": "33541a991e789d971017b63d415d0e6518f5047c", ".claude/skills/capture-learning/SKILL.md": "32300ce3189109b0d717f975623e8d7ccec1c821", ".claude/skills/convene-personas/SKILL.md": "449708a02206bec35a83d2f48ca6366c8b78e3a2", ".claude/skills/docs-wiki-conventions/SKILL.md": "0679512fa39815b63da6373ff29bb6eadc52ff24", diff --git a/core/.apm/skills/ai-sdlc-hooks/SKILL.md b/core/.apm/skills/ai-sdlc-hooks/SKILL.md index db73497..33541a9 100644 --- a/core/.apm/skills/ai-sdlc-hooks/SKILL.md +++ b/core/.apm/skills/ai-sdlc-hooks/SKILL.md @@ -42,7 +42,7 @@ The dotnet pack adds one more: `Deny-StaleGraphQuery.ps1` in `dotnet-code-graph` (`Test-PushReceipt.ps1` in `ai-sdlc-gates`). The pre-flight ran the same gates on that content, and the pull request build still runs them. A push that only deletes refs, or whose commits the remote already has, runs no gate at all. Only the refs of the remote being pushed to count. Both - push hooks judge this with one rule, `Test-PushSendsNothingNew` in `PreflightReceipt.psm1`. It also shows the change-completeness report and the `Last checked` report, which are advisory and never fail the push. On a network share, the gates run on a local checkout of the pushed commit, which is much faster. Last, it + push hooks judge this with one rule, `Test-PushSendsNothingNew` in `PreflightReceipt.psm1`. It also shows the change-completeness report and the `Last checked` report, which are advisory and never fail the push. On a network share, the gates run on a local checkout of the pushed commit, which is much faster. The git data of that checkout stays on the share, so the hook trusts the checkout folder through `GIT_CONFIG_COUNT` (`safe.directory`), only for the gates. Without it, git refused the checkout as "dubious ownership" and the secret scan read 0 commits. Last, it hands the same ref lines on to `git lfs pre-push`, so the LFS objects are uploaded. The other hooks refresh the code graph, and do nothing when the graph tooling is absent. - `githooks/git-lfs-hook` is shared by `pre-push`, `post-checkout`, `post-commit` and `post-merge`. @@ -58,7 +58,7 @@ The dotnet pack adds one more: `Deny-StaleGraphQuery.ps1` in `dotnet-code-graph` the pinned APM with `Install-Apm.ps1` when APM is missing, and warns when an installed APM is not the pinned version. It runs `apm install --frozen`, or plain `apm install` when there is no lock yet. On a network share it runs APM in a local worktree and copies the result back (`Invoke-ApmInstall`), - because APM 0.31.0 left changed skill folders empty there. Then it runs `Initialize-AiSdlc.ps1`. When the knowledge folder (`paths.knowledgeRoot`) is missing, it + because APM 0.31.0 left changed skill folders empty there. `Update-AiSdlc.ps1` runs `apm audit --ci` in that same worktree, because `apm_modules` exists only there. Then it runs `Initialize-AiSdlc.ps1`. When the knowledge folder (`paths.knowledgeRoot`) is missing, it says so, with the `gh repo clone` command when `knowledge.repository` is set. When a blocking setup check fails, it skips `apm install` and says so. It still runs `Initialize-AiSdlc.ps1`, and then exits 1. It works before APM is on the machine, because the repository commits the installed files. diff --git a/core/.apm/skills/ai-sdlc-hooks/githooks/pre-push b/core/.apm/skills/ai-sdlc-hooks/githooks/pre-push index 4061cda..bc91ffa 100755 --- a/core/.apm/skills/ai-sdlc-hooks/githooks/pre-push +++ b/core/.apm/skills/ai-sdlc-hooks/githooks/pre-push @@ -149,6 +149,13 @@ run_gates() ( trap 'exit 130' INT TERM echo "pre-push: the gates run on a local checkout of $tips, because the repository is on a network share." cd "$gate_root" || return 1 + # The git data of the checkout sits on the share, which another user owns, so git refuses the + # checkout as "dubious ownership". Then gitleaks scanned 0 commits and still passed. This trusts + # the one checkout folder, only for the gates and through the environment; the git config of + # the machine stays as it is. Git on Windows names the folder C:/..., so cygpath converts it. + safe_dir=$(cygpath -m "$gate_root" 2>/dev/null) || safe_dir=$gate_root + n=${GIT_CONFIG_COUNT:-0} + export "GIT_CONFIG_KEY_$n=safe.directory" "GIT_CONFIG_VALUE_$n=$safe_dir" "GIT_CONFIG_COUNT=$((n + 1))" runner="$gate_root/.claude/skills/ai-sdlc-gates/scripts/Invoke-LocalGates.ps1" fi echo "pre-push: running blocking CA gates ($runner -BlockingOnly)..." diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 index 9d6e2ba..85a64b0 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1 @@ -251,6 +251,55 @@ Describe 'AiSdlcSetup' { Get-ApmDeployedFile -LockPath $lock | Should -Be @('.claude/skills/a', '.claude/skills/a/SKILL.md') } + It 'runs apm audit --ci in the worktree after the install and hands back its exit code, on a share' { + $env:AISDLC_APM_LOCAL_INSTALL = '1' + $script:Calls = [Collections.Generic.List[string]]::new() + Mock apm { + $script:Calls.Add("$($args -join ' ') @ $((Get-Location).Path)") + if ($args[0] -eq 'install') { New-Item -ItemType Directory -Path (Join-Path (Get-Location).Path 'apm_modules') -Force | Out-Null } + $global:LASTEXITCODE = if ($args[0] -eq 'audit') { if (Test-Path -LiteralPath (Join-Path (Get-Location).Path 'apm_modules')) { 0 } else { 1 } } else { 0 } + } + $audit = 9 + + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 0 + + $audit | Should -Be 0 + $script:Calls.Count | Should -Be 2 + $script:Calls[1] | Should -BeLike 'audit --ci @ *' + $script:Calls[1] | Should -Not -BeLike "* @ $((Resolve-Path -LiteralPath $script:Repo).Path)" + } + + It 'leaves the share as it was when the audit fails in the worktree' { + $env:AISDLC_APM_LOCAL_INSTALL = '1' + Set-Content -LiteralPath (Join-Path $script:Repo 'apm.lock.yaml') -Value "deployed_files:`n - .claude/skills/x/SKILL.md" + Mock apm { + if ($args[0] -eq 'install') { Set-Content -LiteralPath (Join-Path (Get-Location).Path '.claude/skills/x/SKILL.md') -Value 'new' } + $global:LASTEXITCODE = if ($args[0] -eq 'audit') { 4 } else { 0 } + } + $audit = 0 + + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 0 + + $audit | Should -Be 4 + (Get-Content -LiteralPath (Join-Path $script:Repo '.claude/skills/x/SKILL.md') -Raw).Trim() | Should -Be 'old' + @(git -C $script:Repo worktree list).Count | Should -Be 1 + } + + It 'runs the audit in the repository itself when it is not on a network share, and only after a good install' { + $script:Calls = [Collections.Generic.List[string]]::new() + Mock apm { $script:Calls.Add($args[0]); $global:LASTEXITCODE = 0 } + $audit = 9 + + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 0 + $audit | Should -Be 0 + $script:Calls | Should -Be @('install', 'audit') + + $script:Calls.Clear() + Mock apm { $script:Calls.Add($args[0]); $global:LASTEXITCODE = 3 } + Invoke-ApmInstall -RepoRoot $script:Repo -AuditCode ([ref]$audit) | Should -Be 3 + $script:Calls | Should -Be @('install') + } + It 'leaves the repository as it was when apm fails in the worktree' { $env:AISDLC_APM_LOCAL_INSTALL = '1' Mock apm { diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 index 7355c08..4fd11f0 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1 @@ -208,7 +208,11 @@ function Invoke-ApmInstall { [CmdletBinding()] param( [Parameter(Mandatory)][string]$RepoRoot, - [string[]]$Arguments = @('install') + [string[]]$Arguments = @('install'), + # When given, apm audit --ci runs after a good install, in the same folder, and its exit code goes here. + # On a share that folder is the worktree: only there does apm_modules exist, so an audit on the share + # itself fails on a good install. + [ref]$AuditCode ) $want = $env:AISDLC_APM_LOCAL_INSTALL @@ -216,8 +220,16 @@ function Invoke-ApmInstall { if (-not $useLocal) { Push-Location -LiteralPath $RepoRoot - try { apm @Arguments | Out-Host } finally { Pop-Location } - return $LASTEXITCODE + try { + apm @Arguments | Out-Host + $code = $LASTEXITCODE + if ($code -eq 0 -and $AuditCode) { + apm audit --ci | Out-Host + $AuditCode.Value = $LASTEXITCODE + } + } + finally { Pop-Location } + return $code } # On a share, APM 0.31.0 reported a good install but left the changed skill folders empty, and its lock @@ -243,9 +255,18 @@ function Invoke-ApmInstall { $before = @(Get-ApmDeployedFile -LockPath (Join-Path $RepoRoot 'apm.lock.yaml')) Write-Host "apm runs in a local worktree, because the repository is on a network share: $worktree" Push-Location -LiteralPath $worktree - try { apm @Arguments | Out-Host } finally { Pop-Location } - $code = $LASTEXITCODE + try { + apm @Arguments | Out-Host + $code = $LASTEXITCODE + if ($code -eq 0 -and $AuditCode) { + apm audit --ci | Out-Host + $AuditCode.Value = $LASTEXITCODE + } + } + finally { Pop-Location } if ($code -ne 0) { return $code } + # A failed audit leaves the share as it was, so the caller can stop with nothing changed. + if ($AuditCode -and $AuditCode.Value -ne 0) { return 0 } $after = @(Get-ApmDeployedFile -LockPath (Join-Path $worktree 'apm.lock.yaml')) foreach ($path in @($after + $own | Select-Object -Unique)) { diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 index b6b1e16..dc8fc6e 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/PrePushHook.Tests.ps1 @@ -198,7 +198,7 @@ Describe 'The pre-push git hook' { # The committed runner prints "committed"; the working tree holds an uncommitted copy that prints # "worktree". So the output shows which copy ran. function Invoke-PushFromShare { - param([string]$Checkout, [int]$RunnerExit = 0) + param([string]$Checkout, [int]$RunnerExit = 0, [string]$RunnerExtra = '') $root = Join-Path ([System.IO.Path]::GetTempPath()) ('pre-push-' + [guid]::NewGuid().ToString('n')) $gates = Join-Path $root '.claude' 'skills' 'ai-sdlc-gates' 'scripts' New-Item -ItemType Directory -Path $gates -Force | Out-Null @@ -206,7 +206,7 @@ Describe 'The pre-push git hook' { git -C $root config user.email probe@example.invalid git -C $root config user.name probe $runner = Join-Path $gates 'Invoke-LocalGates.ps1' - Set-Content -LiteralPath $runner -Value "Write-Host 'runner copy=committed'; exit $RunnerExit" + Set-Content -LiteralPath $runner -Value "$RunnerExtra`nWrite-Host 'runner copy=committed'; exit $RunnerExit" Set-Content -LiteralPath (Join-Path $gates 'Check-ChangeCompleteness.ps1') -Value "Write-Host 'completeness copy=committed'" git -C $root add . git -C $root commit --quiet -m one --no-verify @@ -238,6 +238,18 @@ Describe 'The pre-push git hook' { $r.Worktrees | Should -Be 1 -Because 'only the main working tree is left' } + It 'trusts only the checkout folder for git in the gates, through the environment, so git does not refuse it as dubious ownership' -Skip:($script:NoSh -or $script:NoPwshShare) { + $extra = 'Write-Host "safe=$(git config --get-all safe.directory | Select-Object -Last 1)|top=$(git rev-parse --show-toplevel)|count=$env:GIT_CONFIG_COUNT"' + $r = Invoke-PushFromShare -Checkout '1' -RunnerExtra $extra + + $r.Code | Should -Be 0 -Because $r.Output + $m = [regex]::Match($r.Output, 'safe=(?[^|]*)\|top=(?[^|]*)\|count=(?\d+)') + $m.Success | Should -BeTrue -Because $r.Output + $m.Groups['safe'].Value.Trim() | Should -Be $m.Groups['top'].Value.Trim() + [int]$m.Groups['count'].Value | Should -BeGreaterOrEqual 1 + $r.Output | Should -Match 'runner copy=committed' + } + It 'refuses the push when a gate fails in the checkout, and still removes it' -Skip:($script:NoSh -or $script:NoPwshShare) { $r = Invoke-PushFromShare -Checkout '1' -RunnerExit 1 diff --git a/core/.apm/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 b/core/.apm/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 index 65d8ba4..372b0a9 100644 --- a/core/.apm/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 +++ b/core/.apm/skills/ai-sdlc-hooks/scripts/Update-AiSdlc.ps1 @@ -107,11 +107,11 @@ Write-Host "Moved $moved AI.SDLC ref(s) in apm.yml to $Ref; the refs of other so Push-Location $RepoRoot try { - $installCode = Invoke-ApmInstall -RepoRoot $RepoRoot + $auditCode = 0 + $installCode = Invoke-ApmInstall -RepoRoot $RepoRoot -AuditCode ([ref]$auditCode) if ($installCode -ne 0) { throw (Get-ApmInstallFailureHint -ExitCode $installCode) } - apm audit --ci - if ($LASTEXITCODE -ne 0) { - throw "apm audit --ci failed with exit code $LASTEXITCODE, so apm.yml, apm.lock.yaml and the installed files under .claude/ do not agree. Read its output above. Nothing is staged yet." + if ($auditCode -ne 0) { + throw "apm audit --ci failed with exit code $auditCode, so apm.yml, apm.lock.yaml and the installed files under .claude/ do not agree. Read its output above. Nothing is staged yet." } foreach ($p in @('apm.yml', 'apm.lock.yaml', '.claude')) { if (Test-Path -LiteralPath (Join-Path $RepoRoot $p)) { git add -- $p } diff --git a/core/apm.yml b/core/apm.yml index 8c65f66..9acf0dc 100644 --- a/core/apm.yml +++ b/core/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-core -version: "1.4.1" +version: "1.4.2" description: The AI-SDLC core for every repository - workflow skills, review agents, hooks, core gates and the handbook. diff --git a/packs/bicep/apm.yml b/packs/bicep/apm.yml index 94108c4..7f7b429 100644 --- a/packs/bicep/apm.yml +++ b/packs/bicep/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-bicep -version: "1.4.1" +version: "1.4.2" description: The Bicep pack - Bicep conventions for infrastructure templates. diff --git a/packs/blazor/apm.yml b/packs/blazor/apm.yml index fc010d3..1fb4236 100644 --- a/packs/blazor/apm.yml +++ b/packs/blazor/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-blazor -version: "1.4.1" +version: "1.4.2" description: The Blazor pack - portal UI conventions, component authorization and the Razor gates. diff --git a/packs/discovery/apm.yml b/packs/discovery/apm.yml index ea5d0c5..b93fc8f 100644 --- a/packs/discovery/apm.yml +++ b/packs/discovery/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-discovery -version: "1.4.1" +version: "1.4.2" description: The discovery pack - the discovery workflows that write a research summary, a journey map and a hypothesis canvas as markdown files in the repository. diff --git a/packs/dotnet/apm.yml b/packs/dotnet/apm.yml index 4e70c29..a05b235 100644 --- a/packs/dotnet/apm.yml +++ b/packs/dotnet/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-dotnet -version: "1.4.1" +version: "1.4.2" description: The .NET pack - C# conventions, test-first, the .NET gates and the code graph. diff --git a/packs/github-issues/apm.yml b/packs/github-issues/apm.yml index ce9823b..40bb71c 100644 --- a/packs/github-issues/apm.yml +++ b/packs/github-issues/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-github-issues -version: "1.4.1" +version: "1.4.2" description: The GitHub Issues pack - issue conventions and the issue contract gates. diff --git a/packs/github/apm.yml b/packs/github/apm.yml index ce27340..5dce184 100644 --- a/packs/github/apm.yml +++ b/packs/github/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-github -version: "1.4.1" +version: "1.4.2" description: The GitHub pack - pull requests, review threads, pull request delivery metrics and the GitHub Actions workflows. diff --git a/packs/knowledge/apm.yml b/packs/knowledge/apm.yml index 9364313..72bfe11 100644 --- a/packs/knowledge/apm.yml +++ b/packs/knowledge/apm.yml @@ -1,3 +1,3 @@ name: ai-sdlc-knowledge -version: "1.4.1" +version: "1.4.2" description: The knowledge pack - the conventions and the workflow for platform knowledge notes in the knowledge repository. diff --git a/packs/sonarcloud/apm.yml b/packs/sonarcloud/apm.yml index d432346..2e11918 100644 --- a/packs/sonarcloud/apm.yml +++ b/packs/sonarcloud/apm.yml @@ -1,5 +1,5 @@ name: ai-sdlc-sonarcloud -version: "1.4.1" +version: "1.4.2" description: The SonarQube Cloud pack - the SonarQube MCP server for the agent session, and the gate that keeps the token and the organization out of the repository. dependencies: mcp: