120 lines
5.2 KiB
TypeScript
120 lines
5.2 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import { resolve } from 'node:path'
|
|
import * as yaml from 'js-yaml'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
const root = resolve(import.meta.dirname, '..')
|
|
const runnerPrivatePnpmDestination = '${{ runner.temp }}/setup-pnpm'
|
|
|
|
describe('CI workflow', () => {
|
|
it('isolates every pnpm action setup destination per runner', () => {
|
|
const workflow: unknown = yaml.load(readFileSync(resolve(root, '.github/workflows/ci.yml'), 'utf8'))
|
|
if (!isRecord(workflow) || !isRecord(workflow.jobs)) throw new TypeError('CI workflow must define jobs')
|
|
|
|
const setups = Object.entries(workflow.jobs).flatMap(([jobName, job]) => {
|
|
if (!isRecord(job) || !Array.isArray(job.steps)) return []
|
|
return job.steps.flatMap((step) => {
|
|
if (!isRecord(step) || typeof step.uses !== 'string' || !step.uses.startsWith('pnpm/action-setup@')) return []
|
|
return [{ jobName, step }]
|
|
})
|
|
})
|
|
|
|
expect(setups.length).toBeGreaterThan(0)
|
|
for (const { jobName, step } of setups) {
|
|
expect(step, `${jobName} must not share pnpm/action-setup's default destination`).toMatchObject({
|
|
with: { dest: runnerPrivatePnpmDestination },
|
|
})
|
|
}
|
|
})
|
|
|
|
it('runs the required Windows contract on a native hosted runner', () => {
|
|
const workflow = loadWorkflow('.github/workflows/ci.yml')
|
|
if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.windows)) {
|
|
throw new TypeError('CI workflow must define the windows job')
|
|
}
|
|
|
|
const windows = workflow.jobs.windows
|
|
if (!Array.isArray(windows.steps)) throw new TypeError('windows job must define steps')
|
|
const steps: unknown[] = windows.steps
|
|
const commandSteps = steps.filter((step): step is Record<string, unknown> & { run: string } => (
|
|
isRecord(step) && typeof step.run === 'string'
|
|
))
|
|
|
|
expect(windows['runs-on']).toBe('windows-2025')
|
|
expect(windows.name).toBe('windows node 24 / native complete')
|
|
expect(windows.env).toMatchObject({ DSH_COVERAGE_MAX_WORKERS: '1' })
|
|
expect(commandSteps).toHaveLength(3)
|
|
expect(commandSteps.every(step => step.shell === 'pwsh')).toBe(true)
|
|
expect(commandSteps.map(step => step.run)).toContain('pnpm run check:ci:windows-complete')
|
|
expect(JSON.stringify(windows)).not.toMatch(/wine/i)
|
|
expect(workflow.jobs).not.toHaveProperty('wine-apt-cache')
|
|
})
|
|
|
|
it('keeps supported LSP source under native Windows coverage', () => {
|
|
const config = readFileSync(resolve(root, 'vitest.config.ts'), 'utf8')
|
|
|
|
expect(config).not.toContain('packages/lsp/lsp-local/src/connection.ts')
|
|
expect(config).not.toContain('packages/lsp/lsp-local/src/index.ts')
|
|
expect(config).not.toContain('packages/lsp/lsp-local/src/instance.ts')
|
|
})
|
|
})
|
|
|
|
describe('E2B e2e workflow', () => {
|
|
it('is manual-only and fails loud before running the focused live suite', () => {
|
|
const workflow = loadWorkflow('.github/workflows/e2b-e2e.yml')
|
|
expect(workflow.on).toEqual({ workflow_dispatch: null })
|
|
if (!isRecord(workflow.jobs) || !isRecord(workflow.jobs.e2b) || !Array.isArray(workflow.jobs.e2b.steps)) {
|
|
throw new TypeError('E2B e2e workflow must define the e2b job steps')
|
|
}
|
|
|
|
const steps = workflow.jobs.e2b.steps.filter(isRecord)
|
|
const preflight = steps.find(step => step.name === 'Preflight (require E2B API key)')
|
|
const e2b = steps.find(step => step.name === 'E2B tests (live sandbox)')
|
|
|
|
expect(preflight).toMatchObject({
|
|
env: { E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}' },
|
|
})
|
|
expect(preflight?.run).toContain('E2B_API_KEY_EXTERNAL repository secret')
|
|
expect(e2b).toMatchObject({
|
|
env: {
|
|
E2B_API_KEY: '${{ secrets.E2B_API_KEY_EXTERNAL }}',
|
|
DSH_E2E_MAX_WORKERS: '1',
|
|
DSH_EXAMPLE_MODE: 'lib',
|
|
},
|
|
})
|
|
expect(e2b?.run).toContain('packages/e2b/e2b/tests/composition.e2e.ts')
|
|
})
|
|
})
|
|
|
|
describe('Issue lifecycle workflow', () => {
|
|
it('uses review signals instead of rerunning when a draft becomes ready', () => {
|
|
const lifecycle = loadWorkflow('.github/workflows/issue-lifecycle.yml')
|
|
const lifecyclePullRequest = workflowEvent(lifecycle, 'pull_request')
|
|
const lifecycleReview = workflowEvent(lifecycle, 'pull_request_review')
|
|
const policy = loadWorkflow('.github/workflows/issue-policy.yml')
|
|
const policyPullRequest = workflowEvent(policy, 'pull_request')
|
|
|
|
expect(lifecyclePullRequest.types).not.toContain('ready_for_review')
|
|
expect(lifecyclePullRequest.types).toContain('review_requested')
|
|
expect(lifecycleReview.types).toContain('submitted')
|
|
expect(policyPullRequest.types).toContain('ready_for_review')
|
|
})
|
|
})
|
|
|
|
function loadWorkflow(path: string): Record<string, unknown> {
|
|
const workflow: unknown = yaml.load(readFileSync(resolve(root, path), 'utf8'))
|
|
if (!isRecord(workflow)) throw new TypeError(`${path} must define a workflow`)
|
|
return workflow
|
|
}
|
|
|
|
function workflowEvent(workflow: Record<string, unknown>, event: string): Record<string, unknown> {
|
|
if (!isRecord(workflow.on) || !isRecord(workflow.on[event])) {
|
|
throw new TypeError(`workflow must define the ${event} event`)
|
|
}
|
|
return workflow.on[event]
|
|
}
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
}
|