Skip to content
Merged
21 changes: 21 additions & 0 deletions .github/actions/setup-linux-sandbox/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# kilocode_change - new file
name: "Setup Linux Sandbox"
description: "Build the Linux bubblewrap helper"
runs:
using: "composite"
steps:
- name: Setup Zig
run: |
curl --fail --location --retry 3 \
https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz \
--output "$RUNNER_TEMP/zig.tar.xz"
echo "473ec26806133cf4d1918caf1a410f8403a13d979726a9045b421b685031a982 $RUNNER_TEMP/zig.tar.xz" | sha256sum --check --status
tar -xJf "$RUNNER_TEMP/zig.tar.xz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/zig-linux-x86_64-0.14.0" >> "$GITHUB_PATH"
shell: bash

- name: Build bubblewrap helper
run: |
bun packages/opencode/script/kilocode/bubblewrap.ts --arch x64 --output "$RUNNER_TEMP/bwrap"
echo "KILO_BWRAP_PATH=$RUNNER_TEMP/bwrap" >> "$GITHUB_ENV"
shell: bash
113 changes: 81 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
pull-requests: read
outputs:
settings: ${{ steps.matrix.outputs.settings }}
general: ${{ steps.matrix.outputs.general }}
steps:
- name: Checkout repository
if: github.event_name != 'workflow_dispatch'
Expand Down Expand Up @@ -57,14 +58,16 @@ jobs:
env:
GENERAL: ${{ github.event_name != 'pull_request' || steps.filter.outputs.general == 'true' }}
run: |
if [ "$GENERAL" = "true" ]; then
echo 'settings=[{"name":"linux","host":"blacksmith-4vcpu-ubuntu-2404","run":true},{"name":"macos","host":"macos-15","run":true},{"name":"windows","host":"blacksmith-4vcpu-windows-2025","run":true}]' >> "$GITHUB_OUTPUT"
if [ "$GENERAL" != "true" ]; then
echo 'general=false' >> "$GITHUB_OUTPUT"
echo 'settings=[{"os":"linux","index":1,"total":1,"host":"blacksmith-4vcpu-ubuntu-2404","run":false,"packages":false}]' >> "$GITHUB_OUTPUT"
exit 0
fi
echo 'settings=[{"name":"linux","host":"blacksmith-4vcpu-ubuntu-2404","run":false}]' >> "$GITHUB_OUTPUT"
echo 'general=true' >> "$GITHUB_OUTPUT"
echo 'settings=[{"os":"linux","index":1,"total":2,"host":"blacksmith-4vcpu-ubuntu-2404","run":true,"packages":true},{"os":"linux","index":2,"total":2,"host":"blacksmith-4vcpu-ubuntu-2404","run":true,"packages":false},{"os":"macos","index":1,"total":1,"host":"macos-15","run":true,"packages":true},{"os":"windows","index":1,"total":4,"host":"blacksmith-4vcpu-windows-2025","run":true,"packages":true},{"os":"windows","index":2,"total":4,"host":"blacksmith-4vcpu-windows-2025","run":true,"packages":false},{"os":"windows","index":3,"total":4,"host":"blacksmith-4vcpu-windows-2025","run":true,"packages":false},{"os":"windows","index":4,"total":4,"host":"blacksmith-4vcpu-windows-2025","run":true,"packages":false}]' >> "$GITHUB_OUTPUT"

unit:
name: unit (${{ matrix.settings.name }})
name: ${{ !matrix.settings.run && 'unit (unchanged)' || matrix.settings.total > 1 && format('unit ({0}, {1}/{2})', matrix.settings.os, matrix.settings.index, matrix.settings.total) || format('unit ({0})', matrix.settings.os) }}
needs: changes
strategy:
fail-fast: false
Expand Down Expand Up @@ -107,21 +110,9 @@ jobs:
uses: ./.github/actions/setup-bun

# kilocode_change start
- name: Setup Zig for Linux sandbox helper
- name: Setup Linux sandbox helper
if: matrix.settings.run && runner.os == 'Linux'
run: |
curl --fail --location --retry 3 \
https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz \
--output "$RUNNER_TEMP/zig.tar.xz"
echo "473ec26806133cf4d1918caf1a410f8403a13d979726a9045b421b685031a982 $RUNNER_TEMP/zig.tar.xz" | sha256sum --check --status
tar -xJf "$RUNNER_TEMP/zig.tar.xz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/zig-linux-x86_64-0.14.0" >> "$GITHUB_PATH"

- name: Build Linux sandbox helper
if: matrix.settings.run && runner.os == 'Linux'
run: |
bun packages/opencode/script/kilocode/bubblewrap.ts --arch x64 --output "$RUNNER_TEMP/bwrap"
echo "KILO_BWRAP_PATH=$RUNNER_TEMP/bwrap" >> "$GITHUB_ENV"
uses: ./.github/actions/setup-linux-sandbox
# kilocode_change end
- name: Configure git identity
if: matrix.settings.run
Expand All @@ -134,31 +125,30 @@ jobs:
uses: actions/cache@v5 # kilocode_change
with:
path: .turbo/cache # kilocode_change
key: turbo-${{ runner.os }}-${{ hashFiles('turbo.json', '**/package.json') }}-${{ github.sha }}
key: turbo-${{ runner.os }}-${{ hashFiles('turbo.json', 'bun.lock') }}-${{ matrix.settings.os }}-${{ matrix.settings.index }}-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}-${{ hashFiles('turbo.json', '**/package.json') }}-
turbo-${{ runner.os }}-${{ hashFiles('turbo.json', 'bun.lock') }}-${{ matrix.settings.os }}-${{ matrix.settings.index }}-
turbo-${{ runner.os }}-${{ hashFiles('turbo.json', 'bun.lock') }}-
turbo-${{ runner.os }}-

- name: Run unit tests
- name: Run non-CLI unit tests
if: matrix.settings.run && matrix.settings.packages
run: bun turbo test:ci --filter='!@kilocode/cli' --filter='!@kilocode/kilo-jetbrains'

- name: Run CLI unit tests
if: matrix.settings.run
run: bun turbo test:ci --filter='!@kilocode/kilo-jetbrains'
run: bun turbo test:ci --filter='@kilocode/cli'
env:
KILO_EXPERIMENTAL_DISABLE_FILEWATCHER: ${{ runner.os == 'Windows' && 'true' || 'false' }}
KILO_TEST_PROFILE: ${{ runner.os == 'macOS' && github.event_name == 'pull_request' && 'darwin' || '' }} # kilocode_change

# kilocode_change start
- name: Run HttpApi exerciser gates
if: matrix.settings.run && runner.os == 'Linux'
working-directory: packages/opencode
run: bun run test:httpapi
# kilocode_change end
KILO_TEST_PROFILE: ${{ matrix.settings.os == 'macos' && 'darwin' || '' }}
Comment thread
marius-kilocode marked this conversation as resolved.
Resolved
KILO_TEST_SHARD: ${{ format('{0}/{1}', matrix.settings.index, matrix.settings.total) }}

- name: Publish unit reports # kilocode_change
if: always() && matrix.settings.run
uses: mikepenz/action-junit-report@bccf2e31636835cf0874589931c4116687171386 # v6.4.0
with:
report_paths: packages/*/.artifacts/unit/junit.xml
check_name: "unit results (${{ matrix.settings.name }})"
annotate_only: true
detailed_summary: true
include_time_in_summary: true
fail_on_failure: false
Expand All @@ -167,13 +157,52 @@ jobs:
if: always() && matrix.settings.run
uses: actions/upload-artifact@v7 # kilocode_change
with:
name: unit-${{ matrix.settings.name }}-${{ github.run_attempt }}
name: unit-${{ matrix.settings.os }}-${{ matrix.settings.index }}-${{ github.run_attempt }}
include-hidden-files: true
if-no-files-found: ignore
retention-days: 7
path: packages/*/.artifacts/unit/junit.xml
# kilocode_change end

# kilocode_change start
httpapi:
name: HttpApi exerciser
needs: changes
if: needs.changes.outputs.general == 'true'
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 15
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Setup Bun
uses: ./.github/actions/setup-bun

- name: Setup Linux sandbox helper
uses: ./.github/actions/setup-linux-sandbox

- name: Configure git identity
run: |
git config --global user.email "kilo-maintainer[bot]@users.noreply.github.com"
git config --global user.name "kilo-maintainer[bot]"

- name: Cache Turbo
uses: actions/cache@v5
with:
path: .turbo/cache
key: turbo-${{ runner.os }}-${{ hashFiles('turbo.json', 'bun.lock') }}-httpapi-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}-${{ hashFiles('turbo.json', 'bun.lock') }}-httpapi-
turbo-${{ runner.os }}-${{ hashFiles('turbo.json', 'bun.lock') }}-
turbo-${{ runner.os }}-

- name: Run HttpApi exerciser gates
run: bun turbo test:httpapi --filter='@kilocode/cli'
# kilocode_change end

# kilocode_change start
jetbrains:
name: jetbrains
Expand All @@ -185,18 +214,38 @@ jobs:
# kilocode_change end

# kilocode_change start
unit-required:
name: unit (linux)
runs-on: blacksmith-4vcpu-ubuntu-2404
needs:
- unit
if: always()
steps:
- name: Verify unit matrix passed
run: |
echo "unit=${{ needs.unit.result }}"
test "${{ needs.unit.result }}" = "success"

required:
name: test (linux)
runs-on: blacksmith-4vcpu-ubuntu-2404
needs:
- changes
- unit
- httpapi
- jetbrains
if: always()
steps:
- name: Verify upstream test jobs passed
run: |
echo "unit=${{ needs.unit.result }}"
echo "httpapi=${{ needs.httpapi.result }}"
echo "jetbrains=${{ needs.jetbrains.result }}"
test "${{ needs.unit.result }}" = "success"
if [ "${{ needs.changes.outputs.general }}" = "true" ]; then
test "${{ needs.httpapi.result }}" = "success"
else
test "${{ needs.httpapi.result }}" = "skipped"
fi
test "${{ needs.jetbrains.result }}" = "success"
# kilocode_change end
33 changes: 20 additions & 13 deletions packages/opencode/script/kilocode/test-profile.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
export namespace TestProfile {
// Broad globs keep platform coverage maintainable as tests are added or renamed.
// Full macOS runs on main remain the backstop for tests outside these areas.
// Full Linux and Windows runs remain the backstop for platform-neutral behavior.
const profiles = {
darwin: {
description: "Darwin-native process, terminal, filesystem, worktree, and runtime coverage",
groups: {
cli: [
"cli/acp/*.test.ts",
"cli/run/{footer.view,run-process,scrollback.surface}.test.{ts,tsx}",
"cli/acp/lifecycle.test.ts",
"cli/run/run-process.test.ts",
"cli/serve/*.test.ts",
"cli/smokes/*.test.ts",
"cli/tui/{app-lifecycle,dialog-prompt,diff-viewer-file-tree,diff-viewer,inline-tool-wrap-snapshot,keymap,plugin-loader-entrypoint,slot-replace,thread,use-event}.test.{ts,tsx}",
"cli/tui/{plugin-lifecycle,plugin-loader-entrypoint,thread}.test.ts",
],
config: [
"config/{config,tui}.test.ts",
"control-plane/workspace.test.ts",
],
filesystem: [
"file/{index,path-traversal,ripgrep}.test.ts",
"file/{index,path-traversal,ripgrep,watcher}.test.ts",
"filesystem/filesystem.test.ts",
"fixture/fixture.test.ts",
"git/*.test.ts",
"image/*.test.ts",
"plugin/{install-concurrency,loader-shared}.test.ts",
"reference/*.test.ts",
"snapshot/*.test.ts",
"tool/{external-directory,glob,grep,read,repo_clone,repo_overview,shell}.test.ts",
"util/{filesystem,module,process,which}.test.ts",
"tool/{apply_patch,edit,glob,grep,read,recall,registry,repo_clone,repo_overview,shell,skill,truncation,write}.test.ts",
"util/{filesystem,glob,module,process,which}.test.ts",
],
kilo: [
"kilocode/{background-process,bin-tree-sitter-env,daemon,external-directory-boundary,indexing-worker,indexing-worktree,mcp-oauth-callback,primary-worktree,snapshot-freeze-repro,snapshot-revert-move,snapshot-seed}.test.ts",
"kilocode/{background-process,daemon,diff-full,external-directory-boundary,indexing-worker,indexing-worktree,interactive-terminal,mcp-oauth-callback,primary-worktree,project-id,read-directory,session-diff-restore,snapshot-cache,snapshot-freeze-repro,snapshot-revert-move,snapshot-seed,task-nesting}.test.ts",
"kilocode/cli/cmd/serve.test.ts",
"kilocode/cli/install-artifact.test.ts",
"kilocode/config/config.test.ts",
"kilocode/sandbox/*.test.ts",
"kilocode/server/{listener-runtime,worktree-list}.test.ts",
"kilocode/server/{config-overlay,listener-runtime,tui-config,worktree-list}.test.ts",
"kilocode/session-export/{e2e,sequence,worker,workspace-provider}.test.ts",
"kilocode/session-export/worker/{storage,zstd}.test.ts",
"kilocode/sessions/*.test.ts",
"kilocode/worktree*.test.ts",
],
process: ["provider/header-timeout.test.ts", "session/{prompt,retry}.test.ts", "shell/*.test.ts"],
process: ["session/prompt.test.ts"],
project: ["project/*.test.ts"],
pty: ["pty/pty-*.test.ts", "server/httpapi-pty*.test.ts"],
pty: ["pty/pty-*.test.ts", "server/httpapi-pty.test.ts"],
server: [
"server/{httpapi-compression,httpapi-experimental,httpapi-file,httpapi-listen,httpapi-workspace-routing,project-init-git,workspace-proxy,worktree-endpoint-repro}.test.ts",
"server/{experimental-session-list,httpapi-experimental,httpapi-file,httpapi-listen,httpapi-workspace-routing,project-init-git,worktree-endpoint-repro}.test.ts",
],
},
},
Expand Down
43 changes: 43 additions & 0 deletions packages/opencode/script/kilocode/test-shard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export namespace TestShard {
export type Info = {
index: number
total: number
}

export function parse(input?: string) {
if (!input) return { ok: true as const, value: undefined }
const match = input.match(/^(\d+)\/(\d+)$/)
if (!match) return { ok: false as const, error: `Invalid test shard "${input}"; expected N/M` }

const value = { index: Number(match[1]), total: Number(match[2]) }
if (
!Number.isSafeInteger(value.index) ||
!Number.isSafeInteger(value.total) ||
value.total < 1 ||
value.total > 1_000 ||
value.index < 1 ||
value.index > value.total
) {
return { ok: false as const, error: `Invalid test shard "${input}"; expected 1 <= N <= M <= 1000` }
}
return { ok: true as const, value }
}

export function order(files: readonly string[], weight: (file: string) => number) {
return files.slice().sort((a, b) => weight(b) - weight(a) || a.localeCompare(b))
}

export function split(files: readonly string[], weight: (file: string) => number, total: number) {
const groups = Array.from({ length: total }, () => ({ files: [] as string[], weight: 0 }))
for (const file of order(files, weight)) {
const group = groups.reduce((best, item) => {
if (item.weight < best.weight) return item
if (item.weight === best.weight && item.files.length < best.files.length) return item
return best
})
group.files.push(file)
group.weight += weight(file)
}
return groups.map((group) => group.files)
}
}
28 changes: 25 additions & 3 deletions packages/opencode/script/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import os from "os"
import path from "path"
import fs from "fs/promises"
import { TestProfile } from "./kilocode/test-profile"
import { TestShard } from "./kilocode/test-shard"

const root = path.resolve(import.meta.dir, "..")
const argv = process.argv.slice(2)
Expand All @@ -31,6 +32,7 @@ if (argv.includes("--help") || argv.includes("-h")) {
" --file-timeout <ms> Per-file process timeout (default: 300000)",
" --retries <N> Extra attempts for failing files (default: 1)",
" --profile <name> Run a curated test profile (env: KILO_TEST_PROFILE)",
" --shard <N/M> Run one balanced file shard (env: KILO_TEST_SHARD)",
" --bail Stop on first failure",
" --dots Show compact dot progress",
" --verbose Show full output for every file",
Expand Down Expand Up @@ -80,8 +82,20 @@ if (flag && env && flag !== env) {
process.exit(2)
}
const profile = flag ?? env
const shardFlag = text("shard")
const shardEnv = process.env.KILO_TEST_SHARD?.trim() || undefined
if (shardFlag && shardEnv && shardFlag !== shardEnv) {
console.error(`Conflicting test shards: --shard=${shardFlag}, KILO_TEST_SHARD=${shardEnv}`)
process.exit(2)
}
const parsed = TestShard.parse(shardFlag ?? shardEnv)
if (!parsed.ok) {
console.error(parsed.error)
process.exit(2)
}
const shard = parsed.value

const valued = new Set(["--concurrency", "--timeout", "--file-timeout", "--retries", "--profile"])
const valued = new Set(["--concurrency", "--timeout", "--file-timeout", "--retries", "--profile", "--shard"])
const patterns = argv.filter((arg, i) => {
if (arg.startsWith("-")) return false
if (i > 0 && valued.has(argv[i - 1])) return false
Expand Down Expand Up @@ -135,7 +149,13 @@ const matched =
patterns.some((pattern) => file.includes(pattern) || path.join("test", file).includes(pattern)),
)
: selected
const files = patterns.length > 0 && !profile ? matched : matched.filter((file) => !skipped.has(file)) // kilocode_change
const candidates = patterns.length > 0 && !profile ? matched : matched.filter((file) => !skipped.has(file)) // kilocode_change
if (shard && shard.total > candidates.length) {
console.error(`Test shard count ${shard.total} exceeds selected file count ${candidates.length}`)
process.exit(2)
}
const weight = (file: string) => Bun.file(path.join(root, "test", file)).size
const files = shard ? TestShard.split(candidates, weight, shard.total)[shard.index - 1] : candidates

if (files.length === 0) {
console.log("No test files found")
Expand Down Expand Up @@ -195,6 +215,7 @@ async function run(file: string): Promise<Result> {
cwd: root,
stdout: "pipe",
stderr: "pipe",
windowsHide: true,
})

const timer = setTimeout(() => {
Expand Down Expand Up @@ -274,12 +295,13 @@ function report(result: Result) {
// ---------------------------------------------------------------------------

console.log(`\nRunning ${bold(String(files.length))} test files with concurrency ${bold(String(concurrency))}`)
if (shard) console.log(`Using balanced test shard ${shard.index}/${shard.total}`)
if (dots) console.log(dim(legend))
console.log()

const start = performance.now()
const results: Result[] = []
const queue = [...files]
const queue = TestShard.order(files, weight)
const stopped = { value: false }

const workers = Array.from({ length: Math.min(concurrency, files.length) }, async () => {
Expand Down
Loading
Loading