Repository navigation
336 lines (308 loc) · 18.7 KB
/
Copy pathconsumer-leg.yml
File metadata and controls
336 lines (308 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# The distributed-build consumer leg. Every other lane in this repository tests the server built
# from the pinned commit (the `external/opencode` submodule, run from source through bun); this one
# installs the build upstream actually publishes for that pin - `npm install -g @opencode/cli` at
# the version spec/SNAPSHOT.md names - and runs the same suite against it. That is the difference
# between "built from the pinned commit" and "tested against the distributed build", and it is the
# only lane that would notice upstream removing an operation from a published build on its own.
#
# The suite's own steps manage no server, by design. `OPENCODE_SDK_TESTS_SERVER_COMMAND` points the
# exact-pin fixture (tests/OpenCode.Sdk.Tests/Harness/PinnedOpenCodeServerFixture.cs) at the
# installed command, and the
# fixture keeps doing what it always does: isolated XDG roots, the repository-owned RPC plugin
# seeded through OPENCODE_CONFIG_CONTENT, a generated password, readiness and teardown through the
# SDK's own launcher, logs retained on request. A workflow that re-implemented any of that would be
# testing itself rather than the SDK. The HQ step starts and stops its own isolated
# `opencode serve`.
#
# It stays human-triggered plus weekly rather than joining CI: it downloads a platform CLI build per
# run, and it depends on the npm registry being reachable, which no pull-request gate should.
#
# Nothing here needs a token. GITHUB_TOKEN's default read scope is enough (no package is consumed
# from GitHub Packages, and no artifact is published), so the lane also runs unchanged on a fork.
name: "Consumer leg"
on:
workflow_dispatch:
inputs:
cli_version:
description: "npm @opencode/cli version to install. Empty reads the pin from spec/SNAPSHOT.md."
required: false
default: ""
schedule:
# Weekly, Mondays 05:17 UTC. Off the hour so the run does not queue behind the top-of-hour
# rush on hosted runners.
- cron: "17 5 * * 1"
permissions:
contents: read
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: false
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
jobs:
consumer-leg:
name: "Consumer leg (${{ matrix.name }})"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
name: Linux
- os: windows-latest
name: Windows
steps:
# Submodules are checked out even though the live legs drive the npm build: the test
# project's simulated-server fixtures (SimulatedDriveServerFixture, ADR-0022) still run the
# pinned source, and this lane runs the whole assembly rather than a filtered slice.
- name: Checkout
uses: actions/checkout@v7
with:
submodules: true
- name: Setup .NET SDK
uses: actions/setup-dotnet@v6
with:
# The pinned GA .NET 11 SDK carries only the .NET 11 runtime; the 10.0 SDK
# is installed beside it for the net10.0 test legs.
global-json-file: global.json
dotnet-version: 10.0.x
- name: Setup Node LTS
uses: actions/setup-node@v7
with:
node-version: lts/*
# spec/SNAPSHOT.md's identity table is the single owner of the pin, and its "Upstream release
# tag" row is what `refresh-spec --apply` rewrites. The npm version is that tag without its
# leading "v" - SNAPSHOT.md says so in prose beside the table, as it read at the v2.0.3 pin
# ("This pin is the release tag `v2.0.3`, so `npm install -g @opencode/cli@2.0.3` installs a
# server built from exactly this commit"). The dispatch input overrides it, which is how a
# candidate build is tried without editing the pin.
- name: Resolve the distributed build version
id: cli
shell: pwsh
env:
CLI_VERSION_INPUT: ${{ inputs.cli_version }}
run: |
$ErrorActionPreference = "Stop"
$version = $env:CLI_VERSION_INPUT
$source = "workflow_dispatch input"
if ([string]::IsNullOrWhiteSpace($version)) {
$source = "spec/SNAPSHOT.md"
$pattern = '^\|\s*Upstream release tag\s*\|\s*`v?([^`|]+)`\s*\|'
$row = Select-String -LiteralPath "spec/SNAPSHOT.md" -Pattern $pattern | Select-Object -First 1
if (-not $row) {
throw "spec/SNAPSHOT.md has no 'Upstream release tag' row; the pinned version cannot be read."
}
$version = $row.Matches[0].Groups[1].Value
}
$version = $version.Trim()
if ($version -notmatch '^[0-9][0-9A-Za-z.\-+]*$') {
throw "'$version' (from $source) is not a version this job will install."
}
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
Write-Host "Distributed build under test: @opencode/cli@$version (from $source)."
- name: Install the distributed build
shell: pwsh
env:
CLI_VERSION: ${{ steps.cli.outputs.version }}
run: |
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
npm install -g "@opencode/cli@$env:CLI_VERSION"
# The installed command must be the version that was asked for, before anything attributes a
# result to it. Observed shape on 2.0.2: `opencode --version` prints "opencode v2.0.2". The
# version the server *serves* is evidence the run produces on its own: the fixture prints it
# for every attach, and the standalone leg prints its health answer.
- name: Assert the installed version
shell: pwsh
env:
CLI_VERSION: ${{ steps.cli.outputs.version }}
run: |
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
$reported = (& opencode --version | Select-Object -First 1).Trim()
$actual = ($reported -replace '^opencode\s+', '') -replace '^v', ''
if ($actual -cne $env:CLI_VERSION) {
throw "opencode --version reported '$reported'; expected $env:CLI_VERSION."
}
Write-Host "opencode --version: $reported"
# Bun, ripgrep and the pinned server's dependencies: the simulated-server fixtures in this
# assembly still run the pinned source, so the runtime CI installs is needed here too.
- name: Setup pinned server runtime
uses: ./.github/actions/setup-pinned-server
- name: Build
run: dotnet build --configuration Release
# The whole assembly, unfiltered, with one variable changed: the fixture starts `opencode
# serve` (resolved from PATH by the SDK launcher, PATHEXT and npm's .cmd shim included)
# instead of bun over the submodule source. Everything else about the owned path is the same,
# which is what makes the result comparable with CI's.
#
# KEEP_LOGS retains the server's stdout/stderr for the artifact even on a green run, and
# --results-directory is what decides where the fixture writes them (TestResultsDirectory
# reads that argument), so the logs and this step's own transcript land in one uploadable
# place.
#
# No --nologo: it suppresses the Microsoft.Testing.Platform banner and the run summary with
# it, which is the line the count guard below reads - and a run whose summary is missing is
# indistinguishable from a run that executed nothing.
- name: Test against the distributed build
shell: pwsh
env:
OPENCODE_SDK_TESTS_SERVER_COMMAND: "opencode|serve"
OPENCODE_SDK_TESTS_KEEP_LOGS: "1"
run: |
$ErrorActionPreference = "Stop"
$results = Join-Path $env:GITHUB_WORKSPACE "TestResults/consumer-leg"
$null = New-Item -ItemType Directory -Force -Path $results
& dotnet test --project tests/OpenCode.Sdk.Tests/OpenCode.Sdk.Tests.csproj `
--configuration Release --no-build --framework net10.0 `
-- --results-directory $results 2>&1 | Tee-Object -FilePath (Join-Path $results "test-run.log")
if ($LASTEXITCODE -ne 0) {
throw "dotnet test exited with $LASTEXITCODE."
}
# A green run that ran nothing is the failure mode this guard exists for: a filter that
# matched no test, a runner that reported zero, or a suite that silently lost most of itself.
# The floor is deliberately coarse - it is not a count assertion against the pin, it is the
# line between "the suite ran" and "something swallowed it".
- name: Guard the executed test count
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$minimum = 500
$log = Join-Path $env:GITHUB_WORKSPACE "TestResults/consumer-leg/test-run.log"
# The runner colours the summary, so the line starts with an ANSI escape; strip them
# before matching (the local pipe carries none, which is how the anchor slipped through).
$lines = Get-Content -LiteralPath $log | ForEach-Object { $_ -replace "`e\[[0-9;]*m", "" }
$summary = $lines | Select-String -Pattern '^\s*total:\s*(\d+)\s*$' | Select-Object -Last 1
if (-not $summary) {
throw "The test log carries no run summary; nothing proves a test executed."
}
$total = [int]$summary.Matches[0].Groups[1].Value
Write-Host "Executed tests: $total"
if ($total -lt $minimum) {
throw "Only $total tests ran; at least $minimum were expected on this framework."
}
# The playground apps, as a consumer builds and runs them, against the distributed build. Each
# starts or reaches its own isolated server and needs no model.
- name: Playground AotCli publishes natively and inspects a repository
shell: pwsh
env:
XDG_CONFIG_HOME: ${{ runner.temp }}/consumer-leg-aotcli/config
XDG_DATA_HOME: ${{ runner.temp }}/consumer-leg-aotcli/data
XDG_STATE_HOME: ${{ runner.temp }}/consumer-leg-aotcli/state
XDG_CACHE_HOME: ${{ runner.temp }}/consumer-leg-aotcli/cache
OPENCODE_DISABLE_MODELS_FETCH: "1"
run: |
$ErrorActionPreference = "Stop"
$rid = if ($IsWindows) { "win-x64" } else { "linux-x64" }
$out = Join-Path $env:RUNNER_TEMP "aotcli"
& dotnet publish playground/aotcli/OpenCode.Playground.AotCli --configuration Release --runtime $rid --output $out
if ($LASTEXITCODE -ne 0) { throw "The AotCli publish exited with $LASTEXITCODE." }
# A scratch repository with one commit and one change, so the branch and the change are known.
$repo = Join-Path $env:RUNNER_TEMP "aotcli-repo"
$null = New-Item -ItemType Directory -Force -Path $repo
git -C $repo init --quiet --initial-branch main
Set-Content -LiteralPath (Join-Path $repo "notes.txt") -Value "one"
git -C $repo add notes.txt
git -C $repo -c user.name=ci -c user.email=ci@example.invalid commit --quiet --message first
Set-Content -LiteralPath (Join-Path $repo "notes.txt") -Value "two"
$exe = Join-Path $out ("OpenCode.Playground.AotCli" + $(if ($IsWindows) { ".exe" } else { "" }))
$log = Join-Path $env:GITHUB_WORKSPACE "TestResults/consumer-leg/aotcli.log"
$lines = @(& $exe $repo 2>&1 | Tee-Object -FilePath $log)
if ($LASTEXITCODE -ne 0) { throw "AotCli exited with $LASTEXITCODE." }
if ($lines[-1] -cne "AotCli: inspected") { throw "AotCli's last line was '$($lines[-1])', not 'AotCli: inspected'." }
if (-not ($lines -ceq "branch: main")) { throw "AotCli printed no 'branch: main' line." }
# The worker's contract with a service manager: when the server it started ends under it, it
# stops with exit code 1 rather than restarting the server itself. The step kills the server's
# whole process tree, since on Windows the reported PID is npm's shim (`cmd.exe`). Trees are
# killed through .NET, so no native exit code is left for the runner's closing `exit`.
- name: Playground Worker stops with 1 when its server ends
shell: pwsh
env:
XDG_CONFIG_HOME: ${{ runner.temp }}/consumer-leg-worker/config
XDG_DATA_HOME: ${{ runner.temp }}/consumer-leg-worker/data
XDG_STATE_HOME: ${{ runner.temp }}/consumer-leg-worker/state
XDG_CACHE_HOME: ${{ runner.temp }}/consumer-leg-worker/cache
OPENCODE_DISABLE_MODELS_FETCH: "1"
run: |
$ErrorActionPreference = "Stop"
$work = Join-Path $env:RUNNER_TEMP "worker-cwd"
$null = New-Item -ItemType Directory -Force -Path $work
$log = Join-Path $env:GITHUB_WORKSPACE "TestResults/consumer-leg/worker.log"
$worker = Start-Process -FilePath "dotnet" -ArgumentList "run", "--project", (Join-Path $env:GITHUB_WORKSPACE "playground/worker/OpenCode.Playground.Worker"), "--configuration", "Release" -WorkingDirectory $work -PassThru -RedirectStandardOutput $log -RedirectStandardError "$log.err"
$null = $worker.Handle # keeps the exit code readable after the process ends
try {
$started = $null
for ($i = 0; $i -lt 600 -and -not $started -and -not $worker.HasExited; $i++) {
Start-Sleep -Milliseconds 500
$started = Select-String -LiteralPath $log -Pattern 'worker: server (\S+) started, pid (\d+)' -ErrorAction SilentlyContinue | Select-Object -First 1
}
if (-not $started) { throw "The worker never reported its server started." }
$serverPid = [int]$started.Matches[0].Groups[2].Value
(Get-Process -Id $serverPid).Kill($true)
if (-not $worker.WaitForExit(60000)) { throw "The worker did not stop within 60 s of its server ending." }
}
finally {
if (-not $worker.HasExited) { $worker.Kill($true) }
}
if ($worker.ExitCode -ne 1) { throw "The worker exited with $($worker.ExitCode), not 1." }
if (-not (Select-String -LiteralPath $log -SimpleMatch "; stopping with exit code 1")) { throw "The worker logged no stop with exit code 1." }
# HQ connects to an explicit endpoint, so the step starts an isolated server, seeds a session
# whose title only this run knows, and boots HQ against it. Seeing that title on HQ's board
# proves HQ reached the isolated server and not some other one. HQ renders over its live
# connection only, so the page is read through the runner's own headless Chrome.
- name: Playground HQ boots against an explicit endpoint
shell: pwsh
env:
XDG_CONFIG_HOME: ${{ runner.temp }}/consumer-leg-hq/config
XDG_DATA_HOME: ${{ runner.temp }}/consumer-leg-hq/data
XDG_STATE_HOME: ${{ runner.temp }}/consumer-leg-hq/state
XDG_CACHE_HOME: ${{ runner.temp }}/consumer-leg-hq/cache
OPENCODE_DISABLE_MODELS_FETCH: "1"
run: |
$ErrorActionPreference = "Stop"
$logs = Join-Path $env:GITHUB_WORKSPACE "TestResults/consumer-leg"
$port = 4196
$password = [guid]::NewGuid().ToString("N")
$sentinel = "sentinel-" + [guid]::NewGuid().ToString("N")
$cred = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("opencode:$password"))
$headers = @{ Authorization = "Basic $cred" }
$env:OPENCODE_PASSWORD = $password
$server = Start-Process -FilePath (Get-Command opencode -CommandType Application | Select-Object -First 1).Source -ArgumentList "serve", "--hostname", "127.0.0.1", "--port", "$port" -PassThru -RedirectStandardOutput (Join-Path $logs "hq-server.out") -RedirectStandardError (Join-Path $logs "hq-server.err")
Remove-Item Env:OPENCODE_PASSWORD
$hq = $null
$chrome = $null
try {
for ($i = 0; $i -lt 120; $i++) { try { $null = Invoke-RestMethod "http://127.0.0.1:$port/api/info" -Headers $headers -TimeoutSec 2; break } catch { Start-Sleep -Milliseconds 500 } }
$directory = Join-Path $env:RUNNER_TEMP "hq-sentinel"
$null = New-Item -ItemType Directory -Force -Path $directory
$body = @{ title = $sentinel; location = @{ directory = $directory } } | ConvertTo-Json -Compress
$null = Invoke-RestMethod "http://127.0.0.1:$port/api/session" -Method Post -Headers $headers -ContentType "application/json" -Body $body -TimeoutSec 30
# HQ's launch profile binds 127.0.0.1:5199 in Development, as a developer runs it.
$env:OpenCode__Endpoint = "http://127.0.0.1:$port"
$env:OpenCode__Password = $password
$hq = Start-Process -FilePath "dotnet" -ArgumentList "run", "--project", "playground/hq/OpenCode.Playground.Hq", "--configuration", "Release" -PassThru -RedirectStandardOutput (Join-Path $logs "hq.out") -RedirectStandardError (Join-Path $logs "hq.err")
$healthy = $false
for ($i = 0; $i -lt 240 -and -not $healthy; $i++) { try { $healthy = (Invoke-WebRequest "http://127.0.0.1:5199/health" -TimeoutSec 2).StatusCode -eq 200 } catch { $healthy = $false } finally { if (-not $healthy) { Start-Sleep -Milliseconds 500 } } }
if (-not $healthy) { throw "HQ never answered /health." }
$browser = if ($IsWindows) { "C:\Program Files\Google\Chrome\Application\chrome.exe" } else { (Get-Command google-chrome).Source }
$flags = @("--headless=new", "--disable-gpu", "--no-first-run", "--user-data-dir=$(Join-Path $env:RUNNER_TEMP 'hq-chrome')", "--remote-debugging-port=9222", "--remote-allow-origins=*")
if ($IsLinux) { $flags += "--no-sandbox" } # AppArmor blocks Chrome's sandbox on ubuntu-24.04; this browser loads only HQ's loopback page.
$chrome = Start-Process -FilePath $browser -ArgumentList ($flags + "about:blank") -PassThru
for ($i = 0; $i -lt 60; $i++) { try { $null = Invoke-RestMethod "http://127.0.0.1:9222/json/version" -TimeoutSec 2; break } catch { Start-Sleep -Milliseconds 500 } }
& bun .github/scripts/hq-sentinel.ts 9222 "http://127.0.0.1:5199/" $sentinel 60000
if ($LASTEXITCODE -ne 0) { throw "HQ's board never showed the seeded session." }
}
finally {
foreach ($process in $chrome, $hq, $server) { if ($process -and -not $process.HasExited) { $process.Kill($true) } }
}
- name: Upload consumer leg artifacts
if: always()
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: consumer-leg-${{ matrix.name }}-${{ github.run_number }}
# Already git-ignored by the repository's [Tt]est[Rr]esult*/ rule, so the run leaves no
# untracked junk behind in a local reproduction either.
path: TestResults/consumer-leg/**
retention-days: 7