Files
deepseek-harness/scripts/preview-workflow.spec.ts
T
imccyu 129c915498 build: split build:src and build:test, and schedule build in parallel
pnpm run build ran every step in one serial chain, including the two
noEmit aggregate programs (tests, scripts, benchmarks, website) that no
artifact step consumes, so the Host aggregate check alone delayed tsdown by
about 66 s.

- build:src (scripts/build.ts --scope src) builds every artifact in the
  existing order and writes the client build record; it replaces the
  removed --artifacts-only flag and the libraries CLI mode.
- build:test (--scope test) type-checks only the Host and Client aggregate
  programs with tsc -p, concurrently, without compiling references or
  checking prerequisites.
- build runs both as one dependency graph through run-gates' new
  runAggregate: each aggregate check starts once its face's packages are
  compiled, and Client compilation stays after the Host bundle that writes
  the Typert /remote declarations. DSH_GATE_CONCURRENCY=1 serializes it;
  DSH_GATE_FAIL_FAST=1 stops the remaining steps at the first failure.
  Passing steps print one PASS line (DSH_GATE_VERBOSE=1 shows their output).
- PR artifact builds (e2e, release, preview, Node 22 compatibility) and the
  Python builder (--build-src) use build:src; dev:web and dev:desktop use
  build:src. test:*, bench, typecheck and the required consumer/Windows
  lanes keep the complete build.
- lint, lint:fix, doc-typecheck and the Typert contracts gate prepare with
  host-libraries (Host package compilation + Host bundle) instead of
  build:lib:host; their own checks never read the aggregate root or the
  Desktop bundle.

Parallel and serial build produce byte-identical lib/, Web dist and client
build record; a test-only type error fails build and build:test while
build:src passes.

Refs #5852
2026-10-11 18:19:23 +08:00

64 lines
3.5 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 workflow = yaml.load(readFileSync(resolve(import.meta.dirname, '../.github/workflows/build-preview-cloudflare.yml'), 'utf8')) as {
on: unknown
permissions: unknown
concurrency: unknown
env: Record<string, string>
jobs: Record<'preview', {
'runs-on': string
steps: Array<{ name?: string; uses?: string; run?: string; with?: Record<string, unknown>; env?: Record<string, string> }>
}>
}
const preview = workflow.jobs.preview
describe('PR preview workflow', () => {
it('keeps every PR author on the selected GitHub-hosted runner', () => {
expect(Object.keys(workflow.jobs)).toEqual(['preview'])
expect(preview['runs-on']).toBe('ubuntu-24.04')
expect(workflow.on).toEqual({ pull_request: { types: ['opened', 'synchronize', 'reopened'] } })
expect(workflow.permissions).toEqual({ contents: 'read', 'pull-requests': 'write' })
expect(preview.steps.find(step => step.uses === 'actions/[email protected]')?.with).toEqual({ 'persist-credentials': false })
})
it('keeps the immutable complete artifact build and restore-only dependency cache', () => {
expect(workflow.env.PRIMARY_NODE_VERSION).toBe('24')
expect(workflow.env.DSH_TELEMETRY_DISABLED).toBe('1')
const commands = preview.steps.map(step => step.run)
expect(commands).toContain('pnpm install --frozen-lockfile')
expect(commands).toContain('pnpm run build:src')
expect(commands).toContain('pnpm --filter @deepseek-ai/dsh-web-frontend run build:preview')
expect(commands.indexOf('pnpm run build:src')).toBeLessThan(commands.indexOf('pnpm --filter @deepseek-ai/dsh-web-frontend run build:preview'))
expect(preview.steps.filter(step => step.uses?.startsWith('actions/cache'))).toHaveLength(1)
expect(preview.steps.find(step => step.uses === 'actions/cache/[email protected]')?.with).toMatchObject({
key: "${{ runner.os }}-node-${{ env.PRIMARY_NODE_VERSION }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}",
})
})
it('retains per-PR deployment, protected image verification, and idempotent URL comments', () => {
expect(workflow.concurrency).toEqual({
group: 'build-preview-cloudflare-${{ github.event.pull_request.number }}',
'cancel-in-progress': true,
})
expect(workflow.env.CF_PROJECT).toBe('dsh-build-preview')
const shape = preview.steps.find(step => step.name === 'Shape the upload')!
expect(shape.run).toContain("find apps/web/dist -name '*.map' -delete")
expect(shape.run).toContain('cp apps/web/dist/preview.html apps/web/dist/index.html')
const deploy = preview.steps.find(step => step.name === 'Upload to Cloudflare Pages')!
expect(deploy.run).toContain('npx --yes wrangler@4 pages deploy apps/web/dist')
expect(deploy.run).toContain('--branch "pr-${{ github.event.pull_request.number }}"')
const verify = preview.steps.find(step => step.name === 'Verify the protected deployment serves the image')!
expect(verify.run).toContain('/preview/vfs-image.tar.gz')
expect(verify.run).toContain('"$code" != "200"')
expect(verify.run).toContain('content-encoding:')
expect(verify.run).toContain('"$magic" != "1f8b"')
expect(verify.env?.CF_ACCESS_CLIENT_SECRET).toBe('${{ secrets.CF_ACCESS_CLIENT_SECRET }}')
const comment = preview.steps.find(step => step.name === 'Comment the preview URL')!
expect(comment.run).toContain('<!-- dsh-preview-url -->')
expect(comment.run).toContain('gh pr comment "$PR" --body-file -')
})
})