e2e.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. env:
  46. # CI runs must never report to the production telemetry endpoint baked
  47. # into apps/cli/cordis.yml (AppCLIEntry disables the row when set).
  48. DSH_TELEMETRY_DISABLED: '1'
  49. jobs:
  50. e2e:
  51. runs-on: ubuntu-latest
  52. name: e2e
  53. # Run on every trusted event. Skip untrusted PRs (forks + Dependabot) where
  54. # the secret is withheld — they would otherwise hard-fail the preflight.
  55. if: >-
  56. github.event_name != 'pull_request'
  57. || !(github.event.pull_request.head.repo.fork || github.event.pull_request.user.login == 'dependabot[bot]')
  58. # Profile e2e files can each own several complete dsh subprocess trees, so
  59. # four file workers preserve process/PTY headroom. Tests retain 120s/test
  60. # and retry 2; 45m still bounds retry storms against a slow API.
  61. timeout-minutes: 45
  62. steps:
  63. - uses: actions/checkout@v6
  64. - uses: pnpm/action-setup@v4
  65. - uses: actions/setup-node@v6
  66. with:
  67. node-version: 24
  68. cache: pnpm
  69. - name: Install (immutable)
  70. run: pnpm install --frozen-lockfile
  71. # The with-key escalation e2e self-skips without a usable runner. Prepare
  72. # bwrap so trusted CI exercises it; the functional probe remains the
  73. # authority on whether the runner can use the sandbox.
  74. - name: Prepare bubblewrap (unrestrict userns)
  75. run: bash scripts/prepare-ci-bubblewrap.sh
  76. # Guard against a false green: the e2e suites self-skip when the key is
  77. # absent, so a missing/misconfigured secret would otherwise pass as
  78. # "all skipped". This job only runs on trusted events (the `if:` above
  79. # excludes keyless PRs), so the secret MUST be present — fail loudly if not.
  80. - name: Preflight (require DEEPSEEK_API_KEY)
  81. env:
  82. # Repo secret DEEPSEEK_API_KEY_EXTERNAL holds the external-API key;
  83. # the tests read process.env.DEEPSEEK_API_KEY, so map it across here.
  84. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  85. run: |
  86. set -euo pipefail
  87. if [ -z "${DEEPSEEK_API_KEY:-}" ]; then
  88. echo "::error::DEEPSEEK_API_KEY is empty. The e2e suite would self-skip and"
  89. echo "::error::report a false green. Configure the repo secret DEEPSEEK_API_KEY_EXTERNAL."
  90. exit 1
  91. fi
  92. echo "DEEPSEEK_API_KEY present."
  93. # The e2e suites boot the example bins in `lib` mode (DSH_EXAMPLE_MODE=lib):
  94. # the built artifact under plain Node, resolving plugins through real package
  95. # exports — the shape a real consumer runs. That requires a prior build.
  96. - name: Build (lib for the e2e example bins)
  97. run: pnpm run build:official
  98. # Real-API end-to-end tests only. The keyless gates (lint/typecheck/
  99. # coverage/snapshot/etc.) already run in ci.yml (pull requests) and
  100. # ci-master.yml (master push standby).
  101. # DEEPSEEK_BASE_URL is pinned to the external API; the secret is scoped to
  102. # this step (and preflight) only — never exposed to checkout/setup/install.
  103. - name: E2E tests (real DeepSeek API)
  104. env:
  105. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  106. DEEPSEEK_BASE_URL: https://api.deepseek.com
  107. DSH_E2E_MAX_WORKERS: 4
  108. DSH_EXAMPLE_MODE: lib
  109. run: pnpm run test:e2e