Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/ai-sdlc-gates/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '[]'
Expand Down Expand Up @@ -201,6 +204,19 @@ Describe 'Test-GitleaksBaseline' {
Should -Invoke gitleaks -Times 0 -Exactly
}

It 'exits <Code> and scans nothing when git cannot read the folder, so a refused checkout never passes, <Where>' -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' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
18 changes: 9 additions & 9 deletions .claude/skills/ai-sdlc-gates/sync-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@
".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",
".claude/skills/ai-sdlc-gates/scripts/Test-PushSendsNothingNew.Tests.ps1": "1162c5d0e7a30ffef915d4d443b6f2527b399228",
".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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions .claude/skills/ai-sdlc-hooks/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions .claude/skills/ai-sdlc-hooks/githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -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)..."
Expand Down
49 changes: 49 additions & 0 deletions .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 26 additions & 5 deletions .claude/skills/ai-sdlc-hooks/scripts/AiSdlcSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,28 @@ 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
$useLocal = if ($want -eq '1') { $true } elseif ($want -eq '0') { $false } else { Test-AiSdlcNetworkPath -RepoRoot $RepoRoot }

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
Expand All @@ -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)) {
Expand Down
Loading
Loading