oc-harness-setup 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/.docs/unwired-routing.md +16 -15
  2. package/AGENTS.md +105 -68
  3. package/CHANGELOG.md +91 -0
  4. package/GLOSSARY.md +46 -0
  5. package/LICENSE +1 -1
  6. package/README.md +48 -60
  7. package/agents/cleaner.md +86 -0
  8. package/agents/critic.md +79 -0
  9. package/agents/historian.md +92 -0
  10. package/agents/maintainer.md +106 -0
  11. package/agents/ops.md +69 -0
  12. package/agents/orchestrator.md +48 -18
  13. package/agents/researcher.md +72 -0
  14. package/agents/verifier.md +84 -0
  15. package/agents/worker.md +87 -0
  16. package/bin/cli.js +349 -133
  17. package/commands/close.md +11 -0
  18. package/commands/evolve.md +11 -0
  19. package/commands/fast.md +11 -0
  20. package/commands/goal.md +11 -0
  21. package/commands/search.md +11 -0
  22. package/commands/swarm.md +11 -0
  23. package/opencode.jsonc +39 -79
  24. package/package.json +13 -6
  25. package/reference/README.md +12 -14
  26. package/reference/canon.md +71 -0
  27. package/reference/context.md +35 -0
  28. package/reference/enforcement.md +6 -0
  29. package/reference/flow.md +19 -0
  30. package/reference/gates.md +23 -0
  31. package/reference/harness.md +15 -0
  32. package/reference/hygiene.md +13 -0
  33. package/reference/memory.md +13 -0
  34. package/reference/models.md +19 -24
  35. package/reference/phases.md +23 -0
  36. package/reference/repos.md +49 -0
  37. package/reference/tools.md +35 -0
  38. package/scripts/harness-doctor.ps1 +83 -0
  39. package/skills/close/SKILL.md +36 -0
  40. package/skills/evolve/SKILL.md +76 -0
  41. package/skills/fast/SKILL.md +36 -0
  42. package/skills/goal/SKILL.md +65 -0
  43. package/skills/search/SKILL.md +68 -0
  44. package/skills/swarm/SKILL.md +69 -0
  45. package/state-seed/lessons.md +22 -0
  46. package/state-seed/template.md +12 -0
  47. package/agents/build.md +0 -20
  48. package/agents/explore.md +0 -26
  49. package/agents/general.md +0 -19
  50. package/agents/plan.md +0 -29
  51. package/agents/reviewer.md +0 -22
  52. package/agents/vault.md +0 -73
  53. package/commands/build.md +0 -7
  54. package/commands/checkpoint.md +0 -7
  55. package/commands/code-simplify.md +0 -7
  56. package/commands/gauntlet.md +0 -7
  57. package/commands/handoff.md +0 -7
  58. package/commands/keeper.md +0 -7
  59. package/commands/kill.md +0 -11
  60. package/commands/plan.md +0 -7
  61. package/commands/retro.md +0 -15
  62. package/commands/review.md +0 -7
  63. package/commands/ship.md +0 -7
  64. package/commands/spec.md +0 -7
  65. package/commands/test.md +0 -7
  66. package/commands/webperf.md +0 -7
  67. package/reference/auto-mandate.md +0 -11
  68. package/reference/backup-convention.md +0 -9
  69. package/reference/clean-mandate.md +0 -13
  70. package/reference/editor-parity.md +0 -7
  71. package/reference/gc-scripts.md +0 -8
  72. package/reference/intent-routing.md +0 -14
  73. package/reference/lifecycle.md +0 -15
  74. package/reference/model-keeper.md +0 -46
  75. package/reference/model-test.md +0 -176
  76. package/reference/oc-source-map.md +0 -162
  77. package/reference/owner-pin.md +0 -31
  78. package/reference/roster.md +0 -15
  79. package/reference/session-scope.md +0 -9
  80. package/reference/session-state.md +0 -13
  81. package/reference/swarm.md +0 -32
  82. package/scripts/backup-config.ps1 +0 -42
  83. package/scripts/gc-branch.ps1 +0 -196
  84. package/scripts/gc-bump.ps1 +0 -198
  85. package/scripts/gc-clean.ps1 +0 -648
  86. package/scripts/gc-commit.ps1 +0 -143
  87. package/scripts/gc-merge.ps1 +0 -272
  88. package/scripts/gc-pr.ps1 +0 -190
  89. package/scripts/gc-push.ps1 +0 -111
  90. package/scripts/gc-read.ps1 +0 -150
  91. package/scripts/gc-rebase.ps1 +0 -162
  92. package/scripts/gc-release.ps1 +0 -225
  93. package/scripts/gc-stage.ps1 +0 -103
  94. package/scripts/gc-status.ps1 +0 -127
  95. package/scripts/gc-sync.ps1 +0 -65
  96. package/scripts/gc.core.ps1 +0 -715
  97. package/scripts/gc.smoke.ps1 +0 -779
  98. package/scripts/interrupt-session.ps1 +0 -65
  99. package/scripts/logbook/README.md +0 -108
  100. package/scripts/logbook/logbook.test.ts +0 -440
  101. package/scripts/logbook/logbook.ts +0 -797
  102. package/scripts/pirep/README.md +0 -147
  103. package/scripts/pirep/pirep.test.ts +0 -735
  104. package/scripts/pirep/pirep.ts +0 -836
  105. package/scripts/testflight/README.md +0 -112
  106. package/scripts/testflight/testflight.test.ts +0 -512
  107. package/scripts/testflight/testflight.ts +0 -806
  108. package/skills/_shared/SOURCES.md +0 -26
  109. package/skills/_shared/references/accessibility-checklist.md +0 -160
  110. package/skills/_shared/references/definition-of-done.md +0 -67
  111. package/skills/_shared/references/observability-checklist.md +0 -92
  112. package/skills/_shared/references/orchestration-patterns.md +0 -155
  113. package/skills/_shared/references/performance-checklist.md +0 -236
  114. package/skills/_shared/references/security-checklist.md +0 -245
  115. package/skills/_shared/references/testing-patterns.md +0 -235
  116. package/skills/api-and-interface-design/SKILL.md +0 -14
  117. package/skills/browser-testing-with-devtools/SKILL.md +0 -303
  118. package/skills/code-simplification/SKILL.md +0 -14
  119. package/skills/creative-writing/SKILL.md +0 -96
  120. package/skills/debugging-and-error-recovery/SKILL.md +0 -15
  121. package/skills/flight-deck/SKILL.md +0 -17
  122. package/skills/frontend-ui-engineering/SKILL.md +0 -16
  123. package/skills/gauntlet/SKILL.md +0 -21
  124. package/skills/git-ceremony/SKILL.md +0 -27
  125. package/skills/grilling/SKILL.md +0 -18
  126. package/skills/observability-and-instrumentation/SKILL.md +0 -18
  127. package/skills/performance-optimization/SKILL.md +0 -16
  128. package/skills/pilot-report/SKILL.md +0 -18
  129. package/skills/planning-and-task-breakdown/SKILL.md +0 -16
  130. package/skills/security-and-hardening/SKILL.md +0 -18
  131. package/skills/source-driven-development/SKILL.md +0 -16
  132. package/skills/spec-driven-development/SKILL.md +0 -26
  133. package/skills/test-driven-development/SKILL.md +0 -18
  134. package/skills/test-flight/SKILL.md +0 -14
  135. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  136. package/skills/writing-for-agents/SKILL.md +0 -89
@@ -1,779 +0,0 @@
1
- #Requires -Version 7.0
2
- <#
3
- .SYNOPSIS
4
- Narrow runnable check for the gc-* git-ceremony script set:
5
- scripts\gc-{core,branch,stage,commit,push,sync,rebase,status,bump,read,release}.ps1.
6
-
7
- .DESCRIPTION
8
- Pins the agent-first contract and the ceremony rails, dependency-free (no
9
- Pester — none is installed on this host), in a throwaway temp repo. All
10
- checks must pass (exit 0); any failure exits 1.
11
-
12
- a. stdout contract: every invocation emits exactly one RESULT: <json>
13
- line, and the ok flag matches the exit code; the default is TERSE
14
- (RESULT line + warnings/failures/security guidance only) and -Detailed
15
- restores the legacy chatter — same exit code and RESULT payload in
16
- every mode, so the mode never changes the contract and a security line
17
- is never hidden.
18
- b. branch ceremony: valid names create and switch; bad type / bad slug /
19
- duplicate fail with exit 2; -Reuse switches without recreating.
20
- c. stage gates: missing paths fail (2); a staged .env with a secret key is
21
- blocked (exit 4), left UNSTAGED, and intact on disk; .env.example is
22
- allowed.
23
- d. commit ceremony: refused on the default branch (2); bad subjects fail
24
- (2); issue refs in the subject are refused (2); a valid subject lands
25
- the exact message and body; nothing staged fails (2).
26
- e. secret gate scans the STAGED BLOB, not the worktree: a secret added
27
- with plain `git add` then edited out of the worktree still blocks the
28
- commit (exit 4).
29
- f. push/sync on a remote-less repo fail/behave cleanly (2 / no-op 0).
30
- g. rebase self-healing: a conflict stops in place (exit 2, state keeps the
31
- rebase) — abort is REFUSED once a file is resolved (it would be
32
- discarded), -Continue finishes it; a fresh conflict then -Abort rolls
33
- back exactly. -Onto rejects a leading dash (no option injection).
34
- h. non-repo root exits 2 with the fix, per the exit-code contract.
35
- i. bare-origin flow: gc-push sets up the upstream and pushes; a default
36
- branch advanced by another clone is fast-forwarded by gc-sync, and a
37
- dirty tree during a needed sync is refused (2).
38
- j. bump ceremony (§8): one source of truth, dirty tree refused, bump table
39
- (minor, major, -Set), downward refused, its own commit with the exact
40
- ceremony subject.
41
- k. gc-pr body precedence (§0): a repo-supplied body (-BodyFile) reaches
42
- `gh pr create` verbatim and suppresses the fixed shape; without it the
43
- fixed What/Why/Check/Risk template is still the fallback; a missing or
44
- empty body file is a loud exit 2 — never a silent empty body.
45
- l. gc-read read-only surface: all six -What selectors emit the standard
46
- RESULT contract; status delegates to gc-status; an unknown selector, a
47
- missing -Rev, and -Limit 0 each fail with exit 2; the surface never
48
- moves HEAD (read-only proof).
49
- m. gc-release (§9): the changelog-section renderer (release body = Version
50
- line + section verbatim; a missing section is a Pre stop) and the script
51
- refusals reachable without network — no remote, dirty tree, non-default
52
- branch — each exit 2 with the fix named, nothing mutated.
53
-
54
- Run: pwsh -File scripts\gc.smoke.ps1
55
- ALWAYS read-only on the host: it touches only a unique temp directory under
56
- the OS temp root, which it deletes in finally. It never runs the real gh —
57
- the gc-pr body checks double `gh` with a temp PATH shim (no network).
58
- #>
59
- Set-StrictMode -Version Latest
60
- $ErrorActionPreference = 'Stop'
61
-
62
- $here = $PSScriptRoot
63
- $pwshExe = (Get-Process -Id $PID).Path
64
- $root = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-smoke-" + [guid]::NewGuid().ToString('N'))
65
- New-Item -ItemType Directory -Path $root -Force | Out-Null
66
- $bareOrigin = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-smoke-" + [guid]::NewGuid().ToString('N') + "-origin.git")
67
- $cloneRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-smoke-" + [guid]::NewGuid().ToString('N') + "-clone")
68
- $plainDir = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-plain-" + [guid]::NewGuid().ToString('N'))
69
- New-Item -ItemType Directory -Path $plainDir -Force | Out-Null
70
- $relDir = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-release-" + [guid]::NewGuid().ToString('N'))
71
- New-Item -ItemType Directory -Path $relDir -Force | Out-Null
72
- $relRepo = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-release-" + [guid]::NewGuid().ToString('N'))
73
- New-Item -ItemType Directory -Path $relRepo -Force | Out-Null
74
-
75
- $script:Failures = 0
76
- $script:Pass = 0
77
- . (Join-Path $here 'gc.core.ps1') # extracted renderers are pinned below (Format-GcPrBody / Convert-GcMergeMode)
78
-
79
- function Assert-That {
80
- param([Parameter(Mandatory)][string]$Name, [Parameter(Mandatory)][bool]$Ok, [string]$Detail = '')
81
- if ($Ok) { Write-Host "[PASS] $Name" -ForegroundColor Green; $script:Pass++ }
82
- else { Write-Host "[FAIL] $Name — $Detail" -ForegroundColor Red; $script:Failures++ }
83
- }
84
-
85
- function Invoke-GcScript {
86
- param([Parameter(Mandatory)][string]$Name, [string[]]$Argv, [string]$Root = $root)
87
- $args = @('-NoProfile','-File',(Join-Path $here "$Name.ps1"),'-RepoRoot',$Root) + @($Argv)
88
- $out = & $pwshExe @args 2>&1
89
- $lines = @($out | ForEach-Object { "$_" })
90
- return [pscustomobject]@{ Code = $LASTEXITCODE; Lines = $lines; Text = ($lines -join "`n") }
91
- }
92
-
93
- function Get-GcResultObject {
94
- <# the parsed RESULT json from a call; $null when the line is missing. #>
95
- param($Call)
96
- $line = @($Call.Lines | Where-Object { $_ -match '^RESULT: ' })
97
- if ($line.Count -ne 1) { return $null }
98
- try { return (($line[0] -replace '^RESULT: ','') | ConvertFrom-Json) } catch { return $null }
99
- }
100
-
101
- function Get-GcCanonicalResult {
102
- <# key-sorted rendering of a RESULT payload — order-insensitive equality. #>
103
- param($Call)
104
- $o = Get-GcResultObject $Call
105
- if ($null -eq $o) { return '<no RESULT>' }
106
- $names = @($o.PSObject.Properties.Name) | Sort-Object
107
- return '{' + (($names | ForEach-Object { "$_=" + (ConvertTo-Json $o.$_ -Compress) }) -join ';') + '}'
108
- }
109
-
110
- function Assert-GcContract {
111
- param([Parameter(Mandatory)]$Call, [Parameter(Mandatory)][string]$Name)
112
- $res = Get-GcResultObject $Call
113
- Assert-That "$Name — exactly one RESULT: line" ($null -ne $res) ($Call.Text)
114
- if ($null -ne $res) {
115
- Assert-That "$Name — RESULT ok flag matches exit code" ($res.ok -eq ($Call.Code -eq 0)) "exit $($Call.Code), ok=$($res.ok)"
116
- }
117
- }
118
-
119
- try {
120
- # -------- setup: fresh repo with an origin-less main -------------------
121
- & git -C $root init -b main 2>&1 | Out-Null
122
- Assert-That 'setup — git init -b main' ($LASTEXITCODE -eq 0) ''
123
- & git -C $root config user.name 'gc smoke' | Out-Null
124
- & git -C $root config user.email 'gc-smoke@test' | Out-Null
125
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'one'
126
- & git -C $root add a.txt | Out-Null
127
- & git -C $root commit -m 'chore: seed repo' | Out-Null
128
-
129
- # -------- status -------------------------------------------------------
130
- $c = Invoke-GcScript 'gc-status'
131
- Assert-GcContract $c 'gc-status on fresh repo'
132
- Assert-That 'gc-status — reports branch main, clean' ($c.Code -eq 0 -and (Get-GcResultObject $c).branch -eq 'main' -and (Get-GcResultObject $c).clean -eq $true) ($c.Text)
133
- Assert-That 'gc-status default is TERSE — stdout is exactly the RESULT line' (
134
- @($c.Lines | Where-Object { $_ -notmatch '^RESULT: ' }).Count -eq 0
135
- ) ($c.Text)
136
-
137
- # -------- gc-read: the read-only surface (never writes) ---------------
138
- $headBeforeRead = (& git -C $root rev-parse HEAD).Trim()
139
- $c = Invoke-GcScript 'gc-read' @('-What','log')
140
- Assert-GcContract $c 'gc-read log'
141
- $log = Get-GcResultObject $c
142
- $firstCommit = if ($log -and $log.commits) { @($log.commits)[0] } else { $null }
143
- Assert-That 'gc-read log — one commit, seed subject' (
144
- $c.Code -eq 0 -and $null -ne $log -and $log.count -eq 1 -and $null -ne $firstCommit -and $firstCommit.subject -eq 'chore: seed repo'
145
- ) ($c.Text)
146
-
147
- $c = Invoke-GcScript 'gc-read' @('-What','status')
148
- Assert-That 'gc-read status — delegates to gc-status (branch main)' (
149
- $c.Code -eq 0 -and (Get-GcResultObject $c).branch -eq 'main'
150
- ) ($c.Text)
151
-
152
- $c = Invoke-GcScript 'gc-read' @('-What','branch-list')
153
- $bl = Get-GcResultObject $c
154
- Assert-That 'gc-read branch-list — main is current, at least one branch' (
155
- $c.Code -eq 0 -and $null -ne $bl -and $bl.current -eq 'main' -and $bl.count -ge 1
156
- ) ($c.Text)
157
-
158
- $c = Invoke-GcScript 'gc-read' @('-What','show','-Rev','HEAD')
159
- Assert-That 'gc-read show -Rev — text carries the commit' (
160
- $c.Code -eq 0 -and (Get-GcResultObject $c).rev -eq 'HEAD' -and (Get-GcResultObject $c).text -match 'seed repo'
161
- ) ($c.Text)
162
-
163
- $c = Invoke-GcScript 'gc-read' @('-What','diff-staged')
164
- Assert-That 'gc-read diff-staged — clean tree is an empty diff' (
165
- $c.Code -eq 0 -and (Get-GcResultObject $c).empty -eq $true
166
- ) ($c.Text)
167
-
168
- $c = Invoke-GcScript 'gc-read' @('-What','diff')
169
- Assert-That 'gc-read diff — clean tree is an empty diff' (
170
- $c.Code -eq 0 -and (Get-GcResultObject $c).empty -eq $true
171
- ) ($c.Text)
172
-
173
- $c = Invoke-GcScript 'gc-read' @('-What','bogus')
174
- Assert-That 'gc-read — unknown -What exits 2 naming the set' (
175
- $c.Code -eq 2 -and $c.Text -match 'not one of'
176
- ) ($c.Text)
177
- Assert-That 'gc-read — FAIL line visible under the terse default (never swallowed)' (
178
- $c.Code -eq 2 -and $c.Text -match '\[gc\] FAIL:'
179
- ) ($c.Text)
180
-
181
- $c = Invoke-GcScript 'gc-read' @('-What','show')
182
- Assert-That 'gc-read show without -Rev exits 2 naming the fix' (
183
- $c.Code -eq 2 -and $c.Text -match '-Rev'
184
- ) ($c.Text)
185
-
186
- $c = Invoke-GcScript 'gc-read' @('-What','log','-Limit','0')
187
- Assert-That 'gc-read log — -Limit 0 refused (2)' ($c.Code -eq 2) ($c.Text)
188
-
189
- Assert-That 'gc-read — read-only: HEAD unmoved' (
190
- (& git -C $root rev-parse HEAD).Trim() -eq $headBeforeRead
191
- ) ''
192
-
193
- # -------- extracted renderers (pinned without gh) ----------------------
194
- $b1 = Format-GcPrBody -What 'cap retry' -Why '' -Check 'n/a' -Risk 'low'
195
- Assert-That 'Format-GcPrBody — Why-omitted shape' ($b1 -eq "What: cap retry`nCheck: n/a`nRisk: low") ('[' + $b1 + ']')
196
- $b2 = Format-GcPrBody -What 'cap retry' -Why 'queue stalled' -Check 'dotnet test' -Risk 'medium'
197
- Assert-That 'Format-GcPrBody — full shape with Why' ($b2 -eq "What: cap retry`nWhy: queue stalled`nCheck: dotnet test`nRisk: medium") ('[' + $b2 + ']')
198
- Assert-That 'Convert-GcMergeMode — flag literals' (
199
- (Convert-GcMergeMode -Mode squash) -eq '--squash' -and
200
- (Convert-GcMergeMode -Mode merge) -eq '--merge' -and
201
- (Convert-GcMergeMode -Mode rebase) -eq '--rebase'
202
- ) ''
203
- # Get-GcMergedMethod: label an already-merged PR from its commit subject
204
- Set-Content -Path (Join-Path $root 'm1.txt') -Value 'x'
205
- & git -C $root add m1.txt 2>&1 | Out-Null
206
- & git -C $root commit -m 'Merge pull request #9 from a/b' 2>&1 | Out-Null
207
- $sha1 = (& git -C $root rev-parse HEAD).Trim()
208
- Set-Content -Path (Join-Path $root 'm2.txt') -Value 'y'
209
- & git -C $root add m2.txt 2>&1 | Out-Null
210
- & git -C $root commit -m 'feat: squashed land (#8)' 2>&1 | Out-Null
211
- $sha2 = (& git -C $root rev-parse HEAD).Trim()
212
- Set-Content -Path (Join-Path $root 'm3.txt') -Value 'z'
213
- & git -C $root add m3.txt 2>&1 | Out-Null
214
- & git -C $root commit -m 'chore: rebased flat' 2>&1 | Out-Null
215
- $sha3 = (& git -C $root rev-parse HEAD).Trim()
216
- Assert-That 'Get-GcMergedMethod — merge/squash/rebase labels' (
217
- (Get-GcMergedMethod -Root $root -Sha $sha1) -eq 'merge' -and
218
- (Get-GcMergedMethod -Root $root -Sha $sha2) -eq 'squash' -and
219
- (Get-GcMergedMethod -Root $root -Sha $sha3) -eq 'rebase'
220
- ) ''
221
-
222
- # -------- branch ceremony ---------------------------------------------
223
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','smoke-change')
224
- Assert-GcContract $c 'gc-branch feat/smoke-change'
225
- Assert-That 'gc-branch — creates and switches' ($c.Code -eq 0 -and (& git -C $root rev-parse --abbrev-ref HEAD).Trim() -eq 'feat/smoke-change') ($c.Text)
226
-
227
- $c = Invoke-GcScript 'gc-branch' @('-Type','nope','-Slug','whatever')
228
- Assert-That 'gc-branch — bad type exits 2' ($c.Code -eq 2) ($c.Text)
229
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','Bad-Slug')
230
- Assert-That 'gc-branch — bad slug exits 2' ($c.Code -eq 2) ($c.Text)
231
-
232
- & git -C $root switch main 2>&1 | Out-Null # off the target branch so the exists-check is reachable
233
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','smoke-change')
234
- Assert-That 'gc-branch — duplicate without -Reuse exits 2' ($c.Code -eq 2) ($c.Text)
235
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','smoke-change','-Reuse')
236
- Assert-That 'gc-branch — -Reuse switches to the existing branch (0)' ($c.Code -eq 0) ($c.Text)
237
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','never-existed','-Reuse')
238
- Assert-That 'gc-branch — -Reuse on missing branch refused (2)' ($c.Code -eq 2) ($c.Text)
239
-
240
- # -------- terse default: chatter off unless -Detailed, never the contract
241
- $cTerse = Invoke-GcScript 'gc-branch' @('-Branch','feat/smoke-change','-Reuse')
242
- $cDetail = Invoke-GcScript 'gc-branch' @('-Branch','feat/smoke-change','-Reuse','-Detailed')
243
- $cQuiet = Invoke-GcScript 'gc-branch' @('-Branch','feat/smoke-change','-Reuse','-Quiet')
244
- $cBoth = Invoke-GcScript 'gc-branch' @('-Branch','feat/smoke-change','-Reuse','-Detailed','-Quiet')
245
- $terseChatter = @($cTerse.Lines | Where-Object { $_ -notmatch '^RESULT: ' }).Count
246
- $detailChatter = @($cDetail.Lines | Where-Object { $_ -notmatch '^RESULT: ' }).Count
247
- $bothChatter = @($cBoth.Lines | Where-Object { $_ -notmatch '^RESULT: ' }).Count
248
- Assert-That 'gc-branch default is TERSE — exit 0, chatter gated to 0 lines' (
249
- $cTerse.Code -eq 0 -and $terseChatter -eq 0
250
- ) "exit $($cTerse.Code); chatter=$terseChatter; $($cTerse.Text)"
251
- Assert-That 'gc-branch -Detailed — restores legacy chatter (exit 0, chatter > 0)' (
252
- $cDetail.Code -eq 0 -and $detailChatter -gt 0
253
- ) "exit $($cDetail.Code); chatter=$detailChatter"
254
- Assert-That 'gc-branch terse/-Detailed/-Quiet — same exit + RESULT payload every mode (chatter never changes the contract)' (
255
- $cQuiet.Code -eq 0 -and $cBoth.Code -eq 0 -and
256
- (Get-GcCanonicalResult $cTerse) -eq (Get-GcCanonicalResult $cDetail) -and
257
- (Get-GcCanonicalResult $cTerse) -eq (Get-GcCanonicalResult $cQuiet) -and
258
- (Get-GcCanonicalResult $cTerse) -eq (Get-GcCanonicalResult $cBoth)
259
- ) "terse=$(Get-GcCanonicalResult $cTerse) detailed=$(Get-GcCanonicalResult $cDetail) both=$(Get-GcCanonicalResult $cBoth)"
260
- Assert-That 'gc-branch -Detailed -Quiet — -Quiet wins, chatter gated to 0 lines' (
261
- $bothChatter -eq 0
262
- ) "chatter=$bothChatter"
263
-
264
- # -------- branch delete ------------------------------------------------
265
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','delete-me')
266
- Assert-That 'gc-branch -Delete setup — create delete-test branch' ($c.Code -eq 0) ($c.Text)
267
- $c = Invoke-GcScript 'gc-branch' @('-Delete','feat/delete-me')
268
- Assert-That 'gc-branch -Delete — current branch refused (2)' ($c.Code -eq 2) ($c.Text)
269
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','smoke-change','-Reuse')
270
- Assert-That 'gc-branch — switch back before deleting' ($c.Code -eq 0) ($c.Text)
271
- $c = Invoke-GcScript 'gc-branch' @('-Delete','main')
272
- Assert-That 'gc-branch -Delete — default branch refused (2)' ($c.Code -eq 2) ($c.Text)
273
- $c = Invoke-GcScript 'gc-branch' @('-Delete','feat/does-not-exist')
274
- Assert-That 'gc-branch -Delete — nonexistent refused (2)' ($c.Code -eq 2) ($c.Text)
275
-
276
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'dirty-for-delete'
277
- $c = Invoke-GcScript 'gc-branch' @('-Delete','feat/delete-me')
278
- Assert-That 'gc-branch -Delete — dirty tree refused (2)' ($c.Code -eq 2) ($c.Text)
279
- $c = Invoke-GcScript 'gc-branch' @('-Delete','feat/does-not-exist')
280
- Assert-That 'gc-branch -Delete — nonexistent beats dirty (does-not-exist msg)' ($c.Code -eq 2 -and $c.Text -match 'does not exist') ($c.Text)
281
- & git -C $root checkout -- a.txt 2>&1 | Out-Null
282
-
283
- $c = Invoke-GcScript 'gc-branch' @('-Delete','feat/delete-me')
284
- Assert-That 'gc-branch -Delete — merged branch deleted (0)' ($c.Code -eq 0 -and (Get-GcResultObject $c).deleted_local -eq $true) ($c.Text)
285
- $gone = $( & git -C $root show-ref --verify --quiet refs/heads/feat/delete-me 2>$null; $LASTEXITCODE -ne 0 )
286
- Assert-That 'gc-branch -Delete — local ref actually gone' $gone ''
287
-
288
- $c = Invoke-GcScript 'gc-branch' @('-Type','chore','-Slug','delete-unmerged')
289
- Assert-That 'gc-branch -Delete setup — create unmerged branch' ($c.Code -eq 0) ($c.Text)
290
- Set-Content -Path (Join-Path $root 'u.txt') -Value 'unmerged'
291
- & git -C $root add u.txt 2>&1 | Out-Null
292
- & git -C $root commit -m 'chore: unmerged work' 2>&1 | Out-Null
293
- $c = Invoke-GcScript 'gc-branch' @('-Delete','chore/delete-unmerged')
294
- Assert-That 'gc-branch -Delete — unmerged refused without -Force (2)' ($c.Code -eq 2) ($c.Text)
295
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','smoke-change','-Reuse')
296
- Assert-That 'gc-branch — off the unmerged branch before force-delete' ($c.Code -eq 0) ($c.Text)
297
- $c = Invoke-GcScript 'gc-branch' @('-Delete','chore/delete-unmerged','-Force')
298
- Assert-That 'gc-branch -Delete — unmerged deleted with -Force (0)' ($c.Code -eq 0 -and (Get-GcResultObject $c).deleted_local -eq $true) ($c.Text)
299
- Assert-That 'gc-branch -Delete -Force — unmerged ref gone' ($( & git -C $root show-ref --verify --quiet refs/heads/chore/delete-unmerged 2>$null; $LASTEXITCODE -ne 0 )) ''
300
-
301
- # -------- staging ------------------------------------------------------
302
- Set-Content -Path (Join-Path $root 'b.txt') -Value 'two'
303
- $c = Invoke-GcScript 'gc-stage' @('-Path','b.txt')
304
- Assert-GcContract $c 'gc-stage b.txt'
305
- Assert-That 'gc-stage — b.txt staged' ($c.Code -eq 0 -and ((Get-GcResultObject $c).staged -contains 'b.txt')) ($c.Text)
306
-
307
- $c = Invoke-GcScript 'gc-stage' @('-Path','missing-file.txt')
308
- Assert-That 'gc-stage — missing path exits 2' ($c.Code -eq 2) ($c.Text)
309
-
310
- $fakeAwsKey = 'AKIA' + 'IOSFODNN7EXAMPLE' # assembled at runtime — no contiguous pattern in source
311
- Set-Content -Path (Join-Path $root '.env') -Value "KEY=$fakeAwsKey"
312
- $c = Invoke-GcScript 'gc-stage' @('-Path','.env')
313
- Assert-GcContract $c 'gc-stage .env with secret key'
314
- Assert-That 'gc-stage — secret blocked with exit 4' ($c.Code -eq 4) ($c.Text)
315
- Assert-That 'gc-stage — exit-4 security code + blocked list in RESULT' (
316
- $c.Code -eq 4 -and (Get-GcResultObject $c).exit -eq 4 -and
317
- @((Get-GcResultObject $c).blocked) -contains '.env'
318
- ) ($c.Text)
319
- Assert-That 'gc-stage — offender + remediation VISIBLE with chatter OFF (terse default)' (
320
- $c.Text -match 'FAIL: secret scan blocked' -and $c.Text -match '\.env' -and
321
- $c.Text -match 'remediation:' -and $c.Text -match '\.gitignore' -and
322
- $c.Text -match 'working tree untouched'
323
- ) ($c.Text)
324
- $staged = @(& git -C $root diff --cached --name-only | ForEach-Object { "$_".Trim() } | Where-Object { $_ })
325
- Assert-That 'gc-stage — secret file left unstaged' ($staged -notcontains '.env') ($staged -join ', ')
326
- Assert-That 'gc-stage — secret file intact on disk' ((Get-Content (Join-Path $root '.env') -Raw).Trim() -eq "KEY=$fakeAwsKey") ''
327
-
328
- Set-Content -Path (Join-Path $root '.env.example') -Value 'KEY=example'
329
- $c = Invoke-GcScript 'gc-stage' @('-Path','.env.example')
330
- Assert-That 'gc-stage — .env.example allowed (0)' ($c.Code -eq 0) ($c.Text)
331
-
332
- Remove-Item -LiteralPath (Join-Path $root '.env') -Force
333
- $c = Invoke-GcScript 'gc-stage' @('-All')
334
- Assert-That 'gc-stage -All — 0 and staged b.txt + .env.example' ($c.Code -eq 0 -and @((Get-GcResultObject $c).staged).Count -eq 2) ($c.Text)
335
-
336
- # -------- commit ceremony ---------------------------------------------
337
- & git -C $root switch main 2>&1 | Out-Null
338
- $headBeforeRefusal = (& git -C $root rev-parse HEAD).Trim()
339
- $c = Invoke-GcScript 'gc-commit' @('-Type','feat','-Summary','nope','-All')
340
- $headAfterRefusal = (& git -C $root rev-parse HEAD).Trim()
341
- Assert-That 'gc-commit — actionable fail-closed default refusal; HEAD unchanged (2)' ($c.Code -eq 2 -and $c.Text -match 'intentionally refusing' -and $c.Text -match 'review state' -and $c.Text -match 'R1' -and $c.Text -match 'secret gate' -and $c.Text -match '§11b' -and $c.Text -match 'unknown or disputed' -and $c.Text -match 'do not retry with raw git' -and $headBeforeRefusal -eq $headAfterRefusal) ($c.Text)
342
- & git -C $root switch feat/smoke-change 2>&1 | Out-Null
343
-
344
- $c = Invoke-GcScript 'gc-commit' @('-Type','feat','-Summary','Adds stuff.')
345
- Assert-That 'gc-commit — trailing period / uppercase exits 2' ($c.Code -eq 2) ($c.Text)
346
- $long = 'add ' + ('x' * 80)
347
- $c = Invoke-GcScript 'gc-commit' @('-Type','feat','-Summary',$long)
348
- Assert-That 'gc-commit — subject over 72 chars exits 2' ($c.Code -eq 2) ($c.Text)
349
- $c = Invoke-GcScript 'gc-commit' @('-Type','feat','-Summary','add login flow #123')
350
- Assert-That 'gc-commit — issue ref in subject refused (2)' ($c.Code -eq 2) ($c.Text)
351
-
352
- $c = Invoke-GcScript 'gc-commit' @('-Type','feat','-Summary','add smoke file','-Body',"covers stage`ncovers commit")
353
- Assert-GcContract $c 'gc-commit valid subject'
354
- Assert-That 'gc-commit — lands the exact subject' ($c.Code -eq 0 -and (& git -C $root log -1 --format=%s).Trim() -eq 'feat: add smoke file') ($c.Text)
355
- Assert-That 'gc-commit — RESULT files count is truthful (2)' ($c.Code -eq 0 -and (Get-GcResultObject $c).files -eq 2) ($c.Text)
356
- Assert-That 'gc-commit — body bullet landed' (((& git -C $root log -1 --format=%B) | Out-String) -match 'covers stage') ''
357
-
358
- # M2 issue-ref shaping: technical prose passes, real refs still caught
359
- Set-Content -Path (Join-Path $root 'c.txt') -Value 'three'
360
- $c = Invoke-GcScript 'gc-stage' @('-Path','c.txt')
361
- Assert-That 'M2 setup — c.txt staged' ($c.Code -eq 0) ($c.Text)
362
- $c = Invoke-GcScript 'gc-commit' @('-Type','feat','-Summary','bump TLS-1.3 to minimum','-All')
363
- Assert-That 'M2 — technical prose (TLS-1.3) accepted (0)' ($c.Code -eq 0 -and (& git -C $root log -1 --format=%s).Trim() -eq 'feat: bump TLS-1.3 to minimum') ($c.Text)
364
- Set-Content -Path (Join-Path $root 'd.txt') -Value 'four'
365
- $c = Invoke-GcScript 'gc-stage' @('-Path','d.txt')
366
- Assert-That 'M2 setup — d.txt staged' ($c.Code -eq 0) ($c.Text)
367
- $c = Invoke-GcScript 'gc-commit' @('-Type','fix','-Summary','add support for ABC-1234 gating','-All')
368
- Assert-That 'M2 — multi-digit ticket ref refused (2)' ($c.Code -eq 2) ($c.Text)
369
- & git -C $root restore --staged d.txt 2>&1 | Out-Null
370
- Remove-Item -LiteralPath (Join-Path $root 'd.txt') -Force
371
-
372
- $c = Invoke-GcScript 'gc-commit' @('-Type','feat','-Summary','nothing staged')
373
- Assert-That 'gc-commit — nothing staged exits 2' ($c.Code -eq 2) ($c.Text)
374
-
375
- # -------- secret gate scans the STAGED BLOB, not the worktree ---------
376
- Set-Content -Path (Join-Path $root 'settings.txt') -Value "KEY=$fakeAwsKey"
377
- & git -C $root add settings.txt 2>&1 | Out-Null # plain git — bypasses gc-stage
378
- Set-Content -Path (Join-Path $root 'settings.txt') -Value 'KEY=benign' # worktree no longer holds the key
379
- $c = Invoke-GcScript 'gc-commit' @('-Type','chore','-Summary','rotate config')
380
- Assert-GcContract $c 'gc-commit over staged secret (blob scan)'
381
- Assert-That 'gc-commit — staged secret blocked via index blob (4)' ($c.Code -eq 4) ($c.Text)
382
- Assert-That 'gc-commit — remediation VISIBLE with chatter OFF (terse default)' (
383
- $c.Code -eq 4 -and $c.Text -match 'remediation:' -and $c.Text -match 'settings\.txt'
384
- ) ($c.Text)
385
- Assert-That 'gc-commit — nothing was committed' ((& git -C $root log -1 --format=%s).Trim() -ne 'chore: rotate config') ''
386
- $staged = @(& git -C $root diff --cached --name-only | ForEach-Object { "$_".Trim() } | Where-Object { $_ })
387
- Assert-That 'gc-commit — secret file unstaged' ($staged -notcontains 'settings.txt') ($staged -join ', ')
388
- & git -C $root restore --staged settings.txt 2>&1 | Out-Null
389
- Remove-Item -LiteralPath (Join-Path $root 'settings.txt') -Force
390
-
391
- # -------- unborn repo + gate trip: exit 4, narrow unstage, tree intact --
392
- # fresh init, no commits: `git restore --staged` cannot resolve HEAD, so the
393
- # gate's cleanup falls back to `git rm --cached` for the offender list only.
394
- $unbornGate = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-smoke-" + [guid]::NewGuid().ToString('N'))
395
- New-Item -ItemType Directory -Path $unbornGate -Force | Out-Null
396
- & git -C $unbornGate init -b main 2>&1 | Out-Null
397
- Set-Content -Path (Join-Path $unbornGate 'notes.txt') -Value 'keep me'
398
- Set-Content -Path (Join-Path $unbornGate 'deploy.key') -Value 'placeholder key material'
399
- $c = Invoke-GcScript 'gc-stage' @('-All') -Root $unbornGate
400
- $uStaged = @(& git -C $unbornGate diff --cached --name-only | ForEach-Object { "$_".Trim() } | Where-Object { $_ })
401
- $uIntact = ((Get-Content (Join-Path $unbornGate 'deploy.key') -Raw).Trim() -eq 'placeholder key material')
402
- Assert-That 'gc-stage unborn repo — gate exits 4, offender unstaged, tree intact' (
403
- $c.Code -eq 4 -and $uStaged -notcontains 'deploy.key' -and $uIntact
404
- ) ("exit $($c.Code); index=[$($uStaged -join ', ')]; intact=$uIntact; " + $c.Text)
405
- Assert-That 'gc-stage unborn repo — offender named + remediation visible with chatter OFF' (
406
- $c.Text -match 'deploy\.key' -and $c.Text -match 'remediation:'
407
- ) ($c.Text)
408
- Remove-Item -LiteralPath $unbornGate -Recurse -Force -ErrorAction SilentlyContinue
409
-
410
- # -------- push / sync on a remote-less repo ----------------------------
411
- $c = Invoke-GcScript 'gc-push'
412
- Assert-That 'gc-push — no remote exits 2, mentions remote' ($c.Code -eq 2 -and $c.Text -match 'remote') ($c.Text)
413
- $c = Invoke-GcScript 'gc-pr' @('-What','nope','-Check','n/a','-Risk','low')
414
- Assert-That 'gc-pr — unpushed head refused before gh (2)' ($c.Code -eq 2 -and $c.Text -match 'push') ($c.Text)
415
- $c = Invoke-GcScript 'gc-sync'
416
- Assert-GcContract $c 'gc-sync on remote-less repo'
417
- Assert-That 'gc-sync — clean no-op (skipped-local)' ($c.Code -eq 0 -and (Get-GcResultObject $c).action -eq 'skipped-local') ($c.Text)
418
-
419
- # unborn default: gc-sync must be a no-op, not a generic exit 1
420
- $unborn = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-smoke-" + [guid]::NewGuid().ToString('N'))
421
- New-Item -ItemType Directory -Path $unborn -Force | Out-Null
422
- & git -C $unborn init -b main 2>&1 | Out-Null
423
- $out = & $pwshExe -NoProfile -File (Join-Path $here 'gc-sync.ps1') -RepoRoot $unborn 2>&1
424
- Assert-That 'gc-sync — unborn default is a no-op (0)' ($LASTEXITCODE -eq 0 -and (($out | Out-String) -match 'unborn')) (($out | Out-String))
425
- Remove-Item -LiteralPath $unborn -Recurse -Force -ErrorAction SilentlyContinue
426
-
427
- # -------- rebase: conflict stop -> abort refusal -> continue -> abort --
428
- & git -C $root switch main 2>&1 | Out-Null
429
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'main change'
430
- & git -C $root commit -am 'chore: main side' 2>&1 | Out-Null
431
- & git -C $root switch feat/smoke-change 2>&1 | Out-Null
432
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'feat change'
433
- & git -C $root commit -am 'chore: feat side' 2>&1 | Out-Null
434
-
435
- $c = Invoke-GcScript 'gc-rebase'
436
- Assert-That 'gc-rebase — conflict stops in place (exit 2, action conflict)' ($c.Code -eq 2 -and (Get-GcResultObject $c).action -eq 'conflict') ($c.Text)
437
- $rebaseDir = (& git -C $root rev-parse --git-path rebase-merge).Trim()
438
- Assert-That 'gc-rebase — rebase state preserved' (Test-Path -LiteralPath (Join-Path $root $rebaseDir)) ''
439
- $c = Invoke-GcScript 'gc-status'
440
- $st = Get-GcResultObject $c
441
- Assert-That 'gc-status — mid-rebase: detached + rebase_in_progress + conflicts' (
442
- $c.Code -eq 0 -and $st.detached -eq $true -and $st.rebase_in_progress -eq $true -and $st.conflicts -ge 1
443
- ) ($c.Text)
444
-
445
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'merged'
446
- & git -C $root add a.txt 2>&1 | Out-Null
447
- $c = Invoke-GcScript 'gc-rebase' @('-Abort')
448
- Assert-That 'gc-rebase — abort refused while resolution exists (2)' ($c.Code -eq 2 -and $c.Text -match 'abort would discard') ($c.Text)
449
- # marker gate: -Continue must refuse to commit leftover conflict markers
450
- Set-Content -Path (Join-Path $root 'a.txt') -Value "merged`n<<<<<<< HEAD leftover"
451
- & git -C $root add a.txt 2>&1 | Out-Null
452
- $c = Invoke-GcScript 'gc-rebase' @('-Continue')
453
- Assert-That 'gc-rebase — marker gate: -Continue refused while markers remain (2)' ($c.Code -eq 2) ($c.Text)
454
- Assert-That 'gc-rebase — marker gate: rebase still in progress' (Test-Path -LiteralPath (Join-Path $root $rebaseDir)) ''
455
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'merged'
456
- & git -C $root add a.txt 2>&1 | Out-Null
457
- $c = Invoke-GcScript 'gc-rebase' @('-Continue')
458
- Assert-GcContract $c 'gc-rebase -Continue after resolution'
459
- Assert-That 'gc-rebase — continue landed the resolution' ($c.Code -eq 0 -and (Get-Content (Join-Path $root 'a.txt') -Raw).Trim() -eq 'merged') ($c.Text)
460
- Assert-That 'gc-rebase — rebase state cleared' (-not (Test-Path -LiteralPath (Join-Path $root $rebaseDir))) ''
461
-
462
- $c = Invoke-GcScript 'gc-rebase' @('-Continue')
463
- Assert-That 'gc-rebase — continue with nothing in progress exits 2' ($c.Code -eq 2) ($c.Text)
464
-
465
- & git -C $root switch main 2>&1 | Out-Null
466
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'main second'
467
- & git -C $root commit -am 'chore: main second' 2>&1 | Out-Null
468
- & git -C $root switch feat/smoke-change 2>&1 | Out-Null
469
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'feat second'
470
- & git -C $root commit -am 'chore: feat second' 2>&1 | Out-Null
471
- $headBefore = (& git -C $root rev-parse HEAD).Trim()
472
- $c = Invoke-GcScript 'gc-rebase'
473
- Assert-That 'gc-rebase — second conflict for abort test (exit 2)' ($c.Code -eq 2) ($c.Text)
474
- # adv-M2: abort must refuse UNSTAGED manual resolution (markers gone in the worktree)
475
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'manual unstaged resolution'
476
- $c = Invoke-GcScript 'gc-rebase' @('-Abort')
477
- Assert-That 'gc-rebase — abort refused for unstaged manual resolution (2)' ($c.Code -eq 2 -and $c.Text -match 'unstaged') ($c.Text)
478
- & git -C $root checkout -m -- a.txt 2>&1 | Out-Null # regenerate the conflict markers
479
- $c = Invoke-GcScript 'gc-rebase' @('-Abort')
480
- Assert-That 'gc-rebase -Abort — exit 0, back on branch' ($c.Code -eq 0 -and (& git -C $root rev-parse --abbrev-ref HEAD).Trim() -eq 'feat/smoke-change') ($c.Text)
481
- Assert-That 'gc-rebase -Abort — content restored, HEAD unchanged' ((Get-Content (Join-Path $root 'a.txt') -Raw).Trim() -eq 'feat second' -and (& git -C $root rev-parse HEAD).Trim() -eq $headBefore) ''
482
-
483
- # -------- add/add (AA) conflict: same-named file added on both sides ----
484
- # both branches carry the same a.txt content now — the ONLY conflict is AA
485
- # (the old conflict logic counted UU entries only; AA must count too)
486
- & git -C $root switch main 2>&1 | Out-Null
487
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'aligned'
488
- & git -C $root commit -am 'chore: align a.txt on main' 2>&1 | Out-Null
489
- & git -C $root switch feat/smoke-change 2>&1 | Out-Null
490
- Set-Content -Path (Join-Path $root 'a.txt') -Value 'aligned'
491
- & git -C $root commit -am 'chore: align a.txt on feat' 2>&1 | Out-Null
492
- Set-Content -Path (Join-Path $root 'shared.txt') -Value 'added on feat'
493
- & git -C $root add shared.txt 2>&1 | Out-Null
494
- & git -C $root commit -m 'chore: feat adds shared.txt' 2>&1 | Out-Null
495
- & git -C $root switch main 2>&1 | Out-Null
496
- Set-Content -Path (Join-Path $root 'shared.txt') -Value 'added on main'
497
- & git -C $root add shared.txt 2>&1 | Out-Null
498
- & git -C $root commit -m 'chore: main adds shared.txt' 2>&1 | Out-Null
499
- & git -C $root merge feat/smoke-change --no-edit 2>&1 | Out-Null # AA conflict expected
500
- $c = Invoke-GcScript 'gc-status'
501
- $st = Get-GcResultObject $c
502
- Assert-That 'gc-status — add/add (AA) conflict counted (conflicts >= 1)' (
503
- $c.Code -eq 0 -and $st.conflicts -ge 1
504
- ) ($c.Text)
505
- & git -C $root merge --abort 2>&1 | Out-Null
506
-
507
- # -------- H1: -Onto rejects a leading dash (no option injection) -------
508
- $c = Invoke-GcScript 'gc-rebase' @('-Onto','--exec=echo pwned')
509
- Assert-That 'gc-rebase — -Onto leading dash refused (2)' ($c.Code -eq 2) ($c.Text)
510
-
511
- # -------- gc-merge on the default branch: clear hint, gh not touched ----
512
- & git -C $root switch main 2>&1 | Out-Null
513
- $c = Invoke-GcScript 'gc-merge'
514
- Assert-That 'gc-merge — on default branch exits 2 with -Branch hint, before gh' ($c.Code -eq 2 -and $c.Text -match '-Branch') ($c.Text)
515
- & git -C $root switch feat/smoke-change 2>&1 | Out-Null
516
-
517
- # -------- non-repo root: contract exit 2 with a fix hint ---------------
518
- $out = & $pwshExe -NoProfile -File (Join-Path $here 'gc-status.ps1') -RepoRoot $plainDir 2>&1
519
- Assert-That 'gc-status — non-repo root exits 2 with fix hint' ($LASTEXITCODE -eq 2 -and (($out | Out-String) -match 'RepoRoot')) (($out | Out-String))
520
-
521
- # -------- bare origin: push upstream, sync fast-forward, dirty refusal --
522
- & git -C $root init --bare $bareOrigin 2>&1 | Out-Null
523
- Assert-That 'bare-origin — git init --bare' ($LASTEXITCODE -eq 0) ''
524
- & git -C $bareOrigin symbolic-ref HEAD refs/heads/main 2>&1 | Out-Null # Windows local clones default to master otherwise
525
- & git -C $root remote add origin $bareOrigin 2>&1 | Out-Null
526
- & git -C $root push -u origin main 2>&1 | Out-Null
527
- Assert-That 'bare-origin — seed main pushed' ($LASTEXITCODE -eq 0) ''
528
- & git -C $root switch feat/smoke-change 2>&1 | Out-Null
529
-
530
- $c = Invoke-GcScript 'gc-push'
531
- Assert-That 'gc-push — sets up the upstream on first push (0)' ($c.Code -eq 0 -and (Get-GcResultObject $c).action -eq 'pushed-with-upstream') ($c.Text)
532
- $c = Invoke-GcScript 'gc-push'
533
- Assert-That 'gc-push — second push is a plain push (0)' ($c.Code -eq 0 -and (Get-GcResultObject $c).action -eq 'pushed') ($c.Text)
534
-
535
- # exit-3 contract preserved WITHOUT the deleted auth probe: a gh call whose
536
- # own message says not-logged-in must still surface as dependency (3), not 1.
537
- $authShimDir = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-authshim-" + [guid]::NewGuid().ToString('N'))
538
- New-Item -ItemType Directory -Path $authShimDir -Force | Out-Null
539
- Set-Content -Path (Join-Path $authShimDir 'gh.ps1') -Value (@(
540
- 'param()',
541
- '[Console]::Error.WriteLine("To get started with GitHub CLI, please run: gh auth login")',
542
- 'exit 1'
543
- ) -join "`n")
544
- $pathSaved3 = $env:PATH
545
- $env:PATH = "$authShimDir;$pathSaved3"
546
- try {
547
- $c = Invoke-GcScript 'gc-pr' @('-Title','chore: auth probe','-What','x')
548
- Assert-That 'gc-pr — gh not-logged-in exits 3 (dependency) with the login fix, probe deleted' (
549
- $c.Code -eq 3 -and (Get-GcResultObject $c).exit -eq 3 -and $c.Text -match 'gh auth login'
550
- ) ($c.Text)
551
- } finally {
552
- $env:PATH = $pathSaved3
553
- Remove-Item -LiteralPath $authShimDir -Recurse -Force -ErrorAction SilentlyContinue
554
- }
555
-
556
- # -------- gc-pr body (§0 precedence): the repo's own body wins, the fixed
557
- # What/Why/Check/Risk shape stays the FALLBACK. gh is DOUBLED by a PATH shim
558
- # (never the real gh, no network): the shim logs every argv it receives, so
559
- # the body actually handed to `gh pr create` is observable without a PR.
560
- $shimDir = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-shim-" + [guid]::NewGuid().ToString('N'))
561
- New-Item -ItemType Directory -Path $shimDir -Force | Out-Null
562
- $shimFile = Join-Path $shimDir 'gh.ps1'
563
- $shimBody = Join-Path $shimDir 'pr-body.md'
564
- $shimEmpty = Join-Path $shimDir 'pr-body-empty.md'
565
- $repoBody = @('## What', '', 'Repo-supplied PR body.', '', '## Verification', '', 'npm run build') -join "`n"
566
- Set-Content -Path $shimBody -Value $repoBody -NoNewline
567
- Set-Content -Path $shimEmpty -Value '' -NoNewline
568
- # the double is SELF-CHECKING: it carries the exact body it must receive and
569
- # reports (exit 7) when `gh pr create` gets anything else — the assertion is
570
- # the real argv, with no side-channel log. `exit` sets $LASTEXITCODE for the
571
- # caller, exactly like the real gh.
572
- $writeShim = {
573
- param([string]$Expect)
574
- $src = @(
575
- 'param()',
576
- ('$expect = ''' + $Expect + ''''),
577
- 'if ($args.Count -ge 1 -and $args[0] -eq ''auth'') { exit 0 }',
578
- 'if ($args.Count -ge 2 -and $args[0] -eq ''pr'' -and $args[1] -eq ''view'') {',
579
- ' if (($args -join '' '') -match ''number,state,headRefOid'') { Write-Output ''no pull requests found''; exit 1 }',
580
- ' Write-Output ''{"number":4242,"url":"https://example.invalid/pull/4242","isDraft":false}''; exit 0',
581
- '}',
582
- 'if ($args.Count -ge 2 -and $args[0] -eq ''pr'' -and $args[1] -eq ''create'') {',
583
- ' $i = [array]::IndexOf($args, ''--body'')',
584
- ' $got = if ($i -ge 0 -and $i + 1 -lt $args.Count) { $args[$i + 1] } else { ''<no --body>'' }',
585
- ' if ($got -ne $expect) { [Console]::Error.WriteLine(''SHIM MISMATCH — create got: ['' + $got + '']''); exit 7 }',
586
- ' exit 0',
587
- '}',
588
- 'exit 0'
589
- ) -join "`n"
590
- Set-Content -Path $shimFile -Value $src
591
- }
592
- $pathSaved = $env:PATH
593
- $env:PATH = "$shimDir;$pathSaved"
594
- try {
595
- # terse default vs -Detailed on a gh verb (shimmed: no network)
596
- & $writeShim $repoBody
597
- $cPrTerse = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-BodyFile',$shimBody)
598
- $cPrDetail = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-BodyFile',$shimBody,'-Detailed')
599
- $prTerseChatter = @($cPrTerse.Lines | Where-Object { $_ -notmatch '^RESULT: ' }).Count
600
- $prDetailChatter = @($cPrDetail.Lines | Where-Object { $_ -notmatch '^RESULT: ' }).Count
601
- Assert-That 'gc-pr default is TERSE (created, chatter 0) and -Detailed restores chatter' (
602
- $cPrTerse.Code -eq 0 -and $prTerseChatter -eq 0 -and
603
- $cPrDetail.Code -eq 0 -and $prDetailChatter -gt 0
604
- ) "terse exit $($cPrTerse.Code)/chat $prTerseChatter; detailed exit $($cPrDetail.Code)/chat $prDetailChatter"
605
-
606
- # (1) repo-supplied body: the file content, verbatim, is what gh receives
607
- & $writeShim $repoBody
608
- $c = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-BodyFile',$shimBody,'-Quiet')
609
- Assert-That 'gc-pr -BodyFile — body reaches gh pr create verbatim (0, created)' (
610
- $c.Code -eq 0 -and (Get-GcResultObject $c).action -eq 'created'
611
- ) $c.Text
612
-
613
- # (2) no override: the fixed What/Why/Check/Risk template is the fallback
614
- & $writeShim "What: cap retry backoff`nCheck: dotnet test`nRisk: low"
615
- $c = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-What','cap retry backoff','-Check','dotnet test','-Quiet')
616
- Assert-That 'gc-pr no override — fixed What/Check/Risk template still the fallback' (
617
- $c.Code -eq 0 -and (Get-GcResultObject $c).action -eq 'created'
618
- ) $c.Text
619
-
620
- $c = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-BodyFile',(Join-Path $shimDir 'nope.md'))
621
- Assert-That 'gc-pr — missing -BodyFile exits 2 naming the fix' ($c.Code -eq 2 -and $c.Text -match 'BodyFile not found') ($c.Text)
622
- $c = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-BodyFile',$shimEmpty)
623
- Assert-That 'gc-pr — empty -BodyFile exits 2 (never a silent empty body)' ($c.Code -eq 2 -and $c.Text -match 'BodyFile is empty') ($c.Text)
624
- $c = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-Body',$repoBody,'-BodyFile',$shimBody)
625
- Assert-That 'gc-pr — -Body + -BodyFile mutually exclusive (2)' ($c.Code -eq 2 -and $c.Text -match 'mutually exclusive') ($c.Text)
626
- $c = Invoke-GcScript 'gc-pr' @('-Title','chore: smoke pr body','-Quiet')
627
- Assert-That 'gc-pr — no body and no -What exits 2 naming -What' ($c.Code -eq 2 -and $c.Text -match '-What is required') ($c.Text)
628
- } finally {
629
- $env:PATH = $pathSaved
630
- Remove-Item -LiteralPath $shimDir -Recurse -Force -ErrorAction SilentlyContinue
631
- }
632
-
633
- # remote-only branch deletion: create + push + -DeleteRemote
634
- $c = Invoke-GcScript 'gc-branch' @('-Type','chore','-Slug','remote-delete-probe')
635
- Assert-That 'gc-branch remote-delete setup — create probe branch' ($c.Code -eq 0) ($c.Text)
636
- Set-Content -Path (Join-Path $root 'probe.txt') -Value 'probe'
637
- & git -C $root add probe.txt 2>&1 | Out-Null
638
- & git -C $root commit -m 'chore: remote delete probe' 2>&1 | Out-Null
639
- $c = Invoke-GcScript 'gc-push'
640
- Assert-That 'gc-branch remote-delete setup — probe pushed' ($c.Code -eq 0) ($c.Text)
641
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','smoke-change','-Reuse')
642
- Assert-That 'gc-branch — off the probe branch' ($c.Code -eq 0) ($c.Text)
643
- $c = Invoke-GcScript 'gc-branch' @('-Delete','chore/remote-delete-probe','-DeleteRemote','-Force')
644
- Assert-That 'gc-branch -Delete -DeleteRemote — local + remote gone (0)' (
645
- $c.Code -eq 0 -and (Get-GcResultObject $c).deleted_local -eq $true -and (Get-GcResultObject $c).deleted_remote -eq $true
646
- ) ($c.Text)
647
- $remoteGone = -not @(& git -C $root ls-remote --heads $bareOrigin 'chore/remote-delete-probe')
648
- Assert-That 'gc-branch -DeleteRemote — origin ref actually gone' $remoteGone ''
649
-
650
- & git -C $root clone -q $bareOrigin $cloneRoot 2>&1 | Out-Null
651
- Set-Content -Path (Join-Path $cloneRoot 'a.txt') -Value 'clone advance'
652
- & git -C $cloneRoot config user.name 'gc smoke' | Out-Null
653
- & git -C $cloneRoot config user.email 'gc-smoke@test' | Out-Null
654
- & git -C $cloneRoot commit -am 'chore: clone advance' 2>&1 | Out-Null
655
- & git -C $cloneRoot push 2>&1 | Out-Null
656
- Assert-That 'clone — origin main advanced' ($LASTEXITCODE -eq 0) ''
657
-
658
- Set-Content -Path (Join-Path $root 'b.txt') -Value 'dirty' # tracked on feat → dirty tree
659
- $c = Invoke-GcScript 'gc-sync'
660
- Assert-That 'gc-sync — dirty tree during needed sync refused (2)' ($c.Code -eq 2) ($c.Text)
661
- & git -C $root checkout -- b.txt 2>&1 | Out-Null # restore, not delete — deletion would stay dirty
662
- $c = Invoke-GcScript 'gc-sync'
663
- Assert-GcContract $c 'gc-sync fast-forward'
664
- Assert-That 'gc-sync — fast-forwarded to origin/main' ($c.Code -eq 0 -and (Get-GcResultObject $c).action -eq 'fast-forwarded') ($c.Text)
665
- $c = Invoke-GcScript 'gc-sync'
666
- Assert-That 'gc-sync — up-to-date second run' ($c.Code -eq 0 -and (Get-GcResultObject $c).action -eq 'up-to-date') ($c.Text)
667
- & git -C $root switch feat/smoke-change 2>&1 | Out-Null
668
-
669
- # -------- bump ceremony -------------------------------------------------
670
- Set-Content -Path (Join-Path $root 'package.json') -Value '{"name":"smoke","version":"1.2.3"}'
671
- Set-Content -Path (Join-Path $root 'b.txt') -Value 'dirty'
672
- $c = Invoke-GcScript 'gc-bump' @('-Minor','-Reason','dirty tree test')
673
- Assert-That 'gc-bump — dirty tree refused (2)' ($c.Code -eq 2) ($c.Text)
674
- & git -C $root checkout -- b.txt 2>&1 | Out-Null
675
- # the manifest itself must be committed before the bump (bump = its own commit)
676
- & git -C $root add package.json 2>&1 | Out-Null
677
- & git -C $root commit -m 'chore: seed manifest' 2>&1 | Out-Null
678
-
679
- $c = Invoke-GcScript 'gc-bump' @('-Minor','-Reason','adds token refresh')
680
- Assert-GcContract $c 'gc-bump minor'
681
- $ver = ((Get-Content (Join-Path $root 'package.json') -Raw) -match '"version"\s*:\s*"1\.3\.0"')
682
- $subj = (($(& git -C $root log -1 --format=%s) | Out-String).Trim())
683
- Assert-That 'gc-bump — 1.2.3 -> 1.3.0 with ceremony subject' ($c.Code -eq 0 -and $ver -and $subj -eq 'chore(release): 1.2.3 -> 1.3.0') ($c.Text)
684
-
685
- $c = Invoke-GcScript 'gc-bump' @('-Major','-Reason','breaking api surface')
686
- Assert-That 'gc-bump — major 1.3.0 -> 2.0.0' ($c.Code -eq 0 -and ((Get-Content (Join-Path $root 'package.json') -Raw) -match '"version"\s*:\s*"2\.0\.0"')) ($c.Text)
687
- $c = Invoke-GcScript 'gc-bump' @('-Set','1.0.0','-Reason','downward')
688
- Assert-That 'gc-bump — downward refused (2)' ($c.Code -eq 2) ($c.Text)
689
- $c = Invoke-GcScript 'gc-bump' @('-Reason','no direction')
690
- Assert-That 'gc-bump — no direction refused (2)' ($c.Code -eq 2) ($c.Text)
691
- $c = Invoke-GcScript 'gc-bump' @('-Set','5.0.0','-Reason','explicit target')
692
- Assert-That 'gc-bump — -Set 5.0.0 lands' ($c.Code -eq 0 -and ((Get-Content (Join-Path $root 'package.json') -Raw) -match '"version"\s*:\s*"5\.0\.0"')) ($c.Text)
693
- $subj = (($(& git -C $root log -1 --format=%s) | Out-String).Trim())
694
- Assert-That 'gc-bump — -Set subject exact' ($subj -eq 'chore(release): 2.0.0 -> 5.0.0') ($subj)
695
- $c = Invoke-GcScript 'gc-bump' @('-Patch','-Reason','battery patch proof')
696
- $ver = ((Get-Content (Join-Path $root 'package.json') -Raw) -match '"version"\s*:\s*"5\.0\.1"')
697
- $subj = (($(& git -C $root log -1 --format=%s) | Out-String).Trim())
698
- Assert-That 'gc-bump — -Patch path 5.0.0 -> 5.0.1' ($c.Code -eq 0 -and $ver -and $subj -eq 'chore(release): 5.0.0 -> 5.0.1') ($c.Text)
699
-
700
- # -------- gc-release (§9): renderers + refusals, no gh/npm/network -----
701
- Set-Content -Path (Join-Path $relDir 'CHANGELOG.md') -Value (@(
702
- '# Changelog','',
703
- '## 2.0.0 (2026-01-01)','',
704
- '### Added','',
705
- '- newest thing','',
706
- '## 1.9.0','',
707
- '### Fixed','',
708
- '- older fix','',
709
- '- second older line'
710
- ) -join "`n")
711
- $sec = @(Get-GcChangelogSection -Root $relDir -Version '2.0.0')
712
- Assert-That 'Get-GcChangelogSection — body without heading, stops at next section' (
713
- $sec.Count -eq 3 -and $sec[0] -eq '### Added' -and $sec[2] -eq '- newest thing'
714
- ) ('[' + ($sec -join '|') + ']')
715
- $secLast = @(Get-GcChangelogSection -Root $relDir -Version '1.9.0')
716
- Assert-That 'Get-GcChangelogSection — last section runs to EOF, blank-trimmed' (
717
- $secLast.Count -eq 5 -and $secLast[4] -eq '- second older line'
718
- ) ('[' + ($secLast -join '|') + ']')
719
- $relBody = Format-GcReleaseBody -Version '2.0.0' -Lines $sec
720
- Assert-That 'Format-GcReleaseBody — Version line + section verbatim' (
721
- $relBody -eq "Version: 2.0.0`n`n### Added`n`n- newest thing"
722
- ) ('[' + $relBody + ']')
723
- $relMissing = $null
724
- try { Get-GcChangelogSection -Root $relDir -Version '9.9.9' | Out-Null } catch { $relMissing = $_ }
725
- Assert-That 'Get-GcChangelogSection — missing section is a Pre stop (2) naming the fix' (
726
- $null -ne $relMissing -and $relMissing.Exception -is [GcException] -and
727
- $relMissing.Exception.Code -eq 2 -and $relMissing.Exception.Message -match 'no section'
728
- ) "$relMissing"
729
-
730
- & git -C $relRepo init -b main 2>&1 | Out-Null
731
- & git -C $relRepo config user.name 'gc smoke' 2>&1 | Out-Null
732
- & git -C $relRepo config user.email 'gc-smoke@test' 2>&1 | Out-Null
733
- Set-Content -Path (Join-Path $relRepo 'seed.txt') -Value 'x'
734
- & git -C $relRepo add seed.txt 2>&1 | Out-Null
735
- & git -C $relRepo commit -m 'chore: seed' 2>&1 | Out-Null
736
- $c = Invoke-GcScript 'gc-release' @('-MovingLatest') -Root $relRepo
737
- Assert-GcContract $c 'gc-release no-remote'
738
- Assert-That 'gc-release — no remote refused (2), names the fix' (
739
- $c.Code -eq 2 -and $c.Text -match 'no git remote'
740
- ) ($c.Text)
741
- Set-Content -Path (Join-Path $relRepo 'dirty.txt') -Value 'y'
742
- $c = Invoke-GcScript 'gc-release' @('-MovingLatest') -Root $relRepo
743
- Assert-GcContract $c 'gc-release dirty tree'
744
- Assert-That 'gc-release — dirty tree refused (2), names clean' (
745
- $c.Code -eq 2 -and $c.Text -match 'not clean'
746
- ) ($c.Text)
747
- Remove-Item -LiteralPath (Join-Path $relRepo 'dirty.txt') -Force
748
- $c = Invoke-GcScript 'gc-branch' @('-Type','feat','-Slug','rel-probe') -Root $relRepo
749
- Assert-That 'gc-release setup — feature branch created' ($c.Code -eq 0) ($c.Text)
750
- $c = Invoke-GcScript 'gc-release' @('-MovingLatest') -Root $relRepo
751
- Assert-That 'gc-release — non-default branch refused (2), names the switch' (
752
- $c.Code -eq 2 -and $c.Text -match "switch to 'main'"
753
- ) ($c.Text)
754
-
755
- # -------- status again: everything reported ----------------------------
756
- $c = Invoke-GcScript 'gc-status'
757
- $st = Get-GcResultObject $c
758
- Assert-That 'gc-status — final snapshot sane' ($c.Code -eq 0 -and $st.branch -eq 'feat/smoke-change' -and $st.default -eq 'main' -and $st.upstream -eq 'origin/feat/smoke-change') ($c.Text)
759
- } catch {
760
- Write-Host "[FAIL] smoke crashed: $($_.Exception.Message)" -ForegroundColor Red
761
- $script:Failures++
762
- } finally {
763
- Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue
764
- Remove-Item -LiteralPath $bareOrigin -Recurse -Force -ErrorAction SilentlyContinue
765
- Remove-Item -LiteralPath $cloneRoot -Recurse -Force -ErrorAction SilentlyContinue
766
- Remove-Item -LiteralPath $plainDir -Recurse -Force -ErrorAction SilentlyContinue
767
- Remove-Item -LiteralPath $relDir -Recurse -Force -ErrorAction SilentlyContinue
768
- Remove-Item -LiteralPath $relRepo -Recurse -Force -ErrorAction SilentlyContinue
769
- }
770
-
771
- Write-Host ''
772
- $total = $script:Pass + $script:Failures
773
- if ($script:Failures -eq 0) {
774
- Write-Host "gc smoke: $script:Pass/$total checks passed" -ForegroundColor Green
775
- exit 0
776
- } else {
777
- Write-Host "gc smoke: $($script:Failures) of $total checks failed" -ForegroundColor Red
778
- exit 1
779
- }