e2e.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. name: E2E (real DeepSeek API)
  2. # Real-API end-to-end suite (`pnpm run test:e2e`). Unlike ci.yml this job
  3. # consumes the DEEPSEEK_API_KEY_EXTERNAL secret (mapped to the env var
  4. # DEEPSEEK_API_KEY the tests read) and hits the external API at
  5. # https://api.deepseek.com (DEEPSEEK_BASE_URL is pinned to it explicitly so a
  6. # stray repo-root .env can't redirect the run).
  7. #
  8. # pull_request IS a trigger, but GitHub withholds repo secrets from BOTH forked
  9. # PRs and Dependabot PRs (the latter are same-repo, fork==false, but still
  10. # keyless). The job-level `if:` below skips the whole job for those untrusted
  11. # PRs. The Dependabot test keys on the PR AUTHOR (pull_request.user.login), not
  12. # github.actor (the run trigger) — a maintainer reopening a Dependabot PR would
  13. # make github.actor human while the PR is still keyless. When the job runs, the
  14. # secret is expected, so the preflight hard-fails if it's missing (a missing
  15. # secret would otherwise make the self-skipping suite report a false green). A
  16. # job skipped by a job-level `if:` reports as a SUCCESSFUL check, so this
  17. # workflow is safe to use as a required status check if desired.
  18. #
  19. # SECURITY — NEVER change this trigger to `pull_request_target`. `pull_request`
  20. # checks out and runs the PR's HEAD code WITHOUT secrets for forks, which is what
  21. # keeps an untrusted fork from exfiltrating the key. `pull_request_target` runs
  22. # in the BASE repo's context WITH secrets while still able to check out untrusted
  23. # fork code — a textbook key-leak vector, especially once this repo is public.
  24. # The fork/secret model and its public-repo implications are recorded in
  25. # .agents/notes/implemented/testing/2026-06-19-real-api-e2e-ci.md.
  26. #
  27. # Note: scheduled triggers are auto-disabled after 60 days of repo inactivity;
  28. # push/pull_request/workflow_dispatch act as backstops.
  29. on:
  30. workflow_dispatch:
  31. push:
  32. branches: [main, master]
  33. pull_request:
  34. schedule:
  35. # 00:17 UTC nightly = 08:17 Asia/Shanghai — off the top-of-hour cron stampede.
  36. - cron: '17 0 * * *'
  37. # Cancel a superseded PR run (it is on a stale commit); never cancel a
  38. # push/schedule run — it is already producing the post-merge/nightly signal.
  39. concurrency:
  40. group: ${{ github.workflow }}-${{ github.ref }}
  41. cancel-in-progress: ${{ github.event_name == 'pull_request' }}
  42. # Least privilege: this job only reads the repo to run tests.
  43. permissions:
  44. contents: read
  45. jobs:
  46. e2e:
  47. runs-on: ubuntu-latest
  48. name: e2e
  49. # Run on every trusted event. Skip untrusted PRs (forks + Dependabot) where
  50. # the secret is withheld — they would otherwise hard-fail the preflight.
  51. if: >-
  52. github.event_name != 'pull_request'
  53. || !(github.event.pull_request.head.repo.fork || github.event.pull_request.user.login == 'dependabot[bot]')
  54. # Bounded file parallelism (DSH_E2E_MAX_WORKERS), 120s/test, retry 2. 45m
  55. # still bounds retry storms against a slow API while the happy path fans out.
  56. timeout-minutes: 45
  57. steps:
  58. - uses: actions/checkout@v6
  59. - uses: actions/setup-node@v6
  60. with:
  61. node-version: 24
  62. - name: Enable corepack (pnpm)
  63. run: corepack enable
  64. - name: Resolve pnpm store path
  65. id: pnpm-store
  66. run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
  67. - uses: actions/cache@v4
  68. with:
  69. path: ${{ steps.pnpm-store.outputs.path }}
  70. key: ${{ runner.os }}-node-24-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
  71. restore-keys: |
  72. ${{ runner.os }}-node-24-pnpm-
  73. - name: Install (immutable)
  74. run: pnpm install --frozen-lockfile
  75. # The with-key escalation e2e self-skips without a usable runner. Install
  76. # bwrap so trusted CI exercises it; the userns knob is best-effort and the
  77. # test's functional probe decides.
  78. - name: Install bubblewrap (unrestrict userns)
  79. run: |
  80. sudo apt-get update -q
  81. sudo apt-get install -yq bubblewrap
  82. sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 \
  83. || echo "apparmor userns knob absent — the functional probe decides"
  84. # Guard against a false green: the e2e suites self-skip when the key is
  85. # absent, so a missing/misconfigured secret would otherwise pass as
  86. # "all skipped". This job only runs on trusted events (the `if:` above
  87. # excludes keyless PRs), so the secret MUST be present — fail loudly if not.
  88. - name: Preflight (require DEEPSEEK_API_KEY)
  89. env:
  90. # Repo secret DEEPSEEK_API_KEY_EXTERNAL holds the external-API key;
  91. # the tests read process.env.DEEPSEEK_API_KEY, so map it across here.
  92. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  93. run: |
  94. set -euo pipefail
  95. if [ -z "${DEEPSEEK_API_KEY:-}" ]; then
  96. echo "::error::DEEPSEEK_API_KEY is empty. The e2e suite would self-skip and"
  97. echo "::error::report a false green. Configure the repo secret DEEPSEEK_API_KEY_EXTERNAL."
  98. exit 1
  99. fi
  100. echo "DEEPSEEK_API_KEY present."
  101. # The e2e suites boot the example bins in `lib` mode (DSH_EXAMPLE_MODE=lib):
  102. # the built artifact under plain Node, resolving plugins through real package
  103. # exports — the shape a real consumer runs. That requires a prior build.
  104. - name: Build (lib for the e2e example bins)
  105. run: pnpm run build
  106. # Real-API end-to-end tests only. The keyless gates (lint/typecheck/
  107. # coverage/snapshot/etc.) already run in ci.yml on every push/PR.
  108. # DEEPSEEK_BASE_URL is pinned to the external API; the secret is scoped to
  109. # this step (and preflight) only — never exposed to checkout/setup/install.
  110. - name: E2E tests (real DeepSeek API)
  111. env:
  112. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  113. DEEPSEEK_BASE_URL: https://api.deepseek.com
  114. DSH_E2E_MAX_WORKERS: 14
  115. DSH_EXAMPLE_MODE: lib
  116. run: pnpm run test:e2e