🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
👷 ci(desktop): type-check the business overlay before desktop releases and on pull requests (#23152)
Innei78ffe6f827ed
diff --git a/.github/actions/overlay-type-check/action.yml b/.github/actions/overlay-type-check/action.ymlnew file mode 100644index 00000000000..df680e4fb9f--- /dev/null+++ b/.github/actions/overlay-type-check/action.yml@@ -0,0 +1,47 @@+name: Overlay Type Check+description: >-+ Type-check this checkout together with the private business overlay, from the overlay root. Bundling does not type-check, so an overlay that still reads an API this checkout removed would otherwise build, ship and fail at runtime.++inputs:+ node-version:+ description: Node.js version+ required: true+ overlay-repository:+ description: Overlay repository (owner/name)+ required: true+ overlay-ref:+ description: Overlay commit to check against (defaults to the overlay's default branch)+ required: false+ default: ''+ log-name:+ description: File name under the runner temp directory that receives the type check output+ required: false+ default: overlay-type-check.log+ overlay-token:+ description: GitHub token with permission to read the overlay repository+ required: true++runs:+ using: composite+ steps:+ - name: Setup environment+ uses: ./.github/actions/setup-env+ with:+ node-version: ${{ inputs.node-version }}++ - name: Overlay business repository+ uses: ./.github/actions/business-overlay+ with:+ overlay-repository: ${{ inputs.overlay-repository }}+ overlay-ref: ${{ inputs.overlay-ref }}+ overlay-token: ${{ inputs.overlay-token }}++ - name: Install dependencies+ shell: bash+ run: cd .. && pnpm install --node-linker=hoisted++ - name: Type check overlaid sources+ shell: bash+ env:+ LOG_NAME: ${{ inputs.log-name }}+ run: cd .. && bun run type-check 2>&1 | tee "$RUNNER_TEMP/$LOG_NAME"diff --git a/.github/scripts/desktop-overlay-type-check.test.mjs b/.github/scripts/desktop-overlay-type-check.test.mjsnew file mode 100644index 00000000000..8d1c5c98bcf--- /dev/null+++ b/.github/scripts/desktop-overlay-type-check.test.mjs@@ -0,0 +1,78 @@+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { test } from 'node:test';++import { parse } from 'yaml';++const load = async (path) => parse(await readFile(new URL(path, import.meta.url), 'utf8'));++const needsOf = (job) => [job.needs ?? []].flat();++const stepUsing = (job, action) => job.steps.find((step) => step.uses === action);++const typeCheckStep = (job) => stepUsing(job, './.github/actions/overlay-type-check');++const sourceSteps = (job) =>+ job.steps.slice(0, job.steps.indexOf(stepUsing(job, './.github/actions/overlay-token')));++test('core OTA cannot publish before the overlaid sources type-check', async () => {+ const { jobs } = await load('../workflows/release-desktop-core-ota.yml');++ assert.ok(needsOf(jobs.publish).includes('overlay-type-check'));+ assert.doesNotMatch(String(jobs.publish.if), /always\(\)|cancelled\(\)|failure\(\)/);+});++test('core OTA type-checks the overlay revision it builds', async () => {+ const { jobs } = await load('../workflows/release-desktop-core-ota.yml');+ const built = stepUsing(jobs['build-core'], './.github/actions/desktop-build-setup');++ assert.equal(+ typeCheckStep(jobs['overlay-type-check']).with['overlay-ref'],+ built.with['cloud-ref'],+ );+});++for (const channel of ['canary', 'beta', 'stable']) {+ const loadJobs = async () => (await load(`../workflows/release-desktop-${channel}.yml`)).jobs;++ test(`a full ${channel} release cannot build before the overlaid sources type-check`, async () => {+ const jobs = await loadJobs();++ assert.ok(needsOf(jobs.build).includes('overlay-type-check'));+ assert.doesNotMatch(String(jobs.build.if), /always\(\)|failure\(\)/);+ });++ test(`a full ${channel} release type-checks the sources it builds`, async () => {+ const jobs = await loadJobs();+ const built = stepUsing(jobs.build, './.github/actions/desktop-build-setup');++ assert.equal(+ typeCheckStep(jobs['overlay-type-check']).with['overlay-ref'],+ built.with['cloud-ref'],+ );+ assert.deepEqual(sourceSteps(jobs['overlay-type-check']), sourceSteps(jobs.build));+ });+}++test('the type check runs from the overlay root against the pinned overlay revision', async () => {+ const { runs } = await load('../actions/overlay-type-check/action.yml');+ const overlay = stepUsing(runs, './.github/actions/business-overlay');+ const check = runs.steps.at(-1);++ assert.equal(overlay.with['overlay-ref'], '${{ inputs.overlay-ref }}');+ assert.ok(runs.steps.indexOf(overlay) < runs.steps.indexOf(check));+ assert.match(check.run, /cd \.\.[\s\S]*bun run type-check/);+});++test('a pull request is judged against its base under the same overlay revision', async () => {+ const { jobs } = await load('../workflows/overlay-type-check.yml');+ const { steps } = jobs['overlay-type-check'];+ const [head, base] = steps.filter((step) => step.uses === './.github/actions/overlay-type-check');++ assert.equal(head['continue-on-error'], true);+ assert.equal(base.with['overlay-ref'], '${{ env.OVERLAY_REF }}');+ assert.match(+ steps.at(-1).run,+ new RegExp(`overlayTypeErrors\\.mjs .*${base.with['log-name']}.*${head.with['log-name']}`),+ );+});diff --git a/.github/scripts/overlayTypeErrors.mjs b/.github/scripts/overlayTypeErrors.mjsnew file mode 100644index 00000000000..829a85de3d1--- /dev/null+++ b/.github/scripts/overlayTypeErrors.mjs@@ -0,0 +1,49 @@+import { readFile } from 'node:fs/promises';+import { fileURLToPath } from 'node:url';++const TYPE_ERROR = /^(.+?)\(\d+,\d+\): error (TS\d+): (.*)$/;++const errorKeys = (log) =>+ log+ .split('\n')+ .map((line) => line.trim().match(TYPE_ERROR))+ .filter(Boolean)+ .map(([, file, code, message]) => `${file}: ${code}: ${message}`);++export const newErrors = (baseLog, headLog) => {+ const unmatched = new Map();+ for (const key of errorKeys(baseLog)) unmatched.set(key, (unmatched.get(key) ?? 0) + 1);++ return errorKeys(headLog).filter((key) => {+ const left = unmatched.get(key) ?? 0;+ if (left === 0) return true;+ unmatched.set(key, left - 1);+ return false;+ });+};++const main = async ([basePath, headPath]) => {+ const baseLog = await readFile(basePath, 'utf8').catch(() => '');+ const headLog = await readFile(headPath, 'utf8');++ if (errorKeys(headLog).length === 0) {+ console.log('::error::The overlay type check failed without reporting a type error');+ return 1;+ }++ const introduced = newErrors(baseLog, headLog);+ if (introduced.length === 0) {+ console.log('::notice::Every overlay type error already exists on the base branch');+ return 0;+ }++ console.log(+ `::error::This pull request introduces ${introduced.length} type error(s) in the business overlay`,+ );+ for (const error of introduced) console.log(error);+ return 1;+};++if (process.argv[1] === fileURLToPath(import.meta.url)) {+ process.exitCode = await main(process.argv.slice(2));+}diff --git a/.github/scripts/overlayTypeErrors.test.mjs b/.github/scripts/overlayTypeErrors.test.mjsnew file mode 100644index 00000000000..6842a71a46d--- /dev/null+++ b/.github/scripts/overlayTypeErrors.test.mjs@@ -0,0 +1,72 @@+import assert from 'node:assert/strict';+import { execFile } from 'node:child_process';+import { mkdtemp, rm, writeFile } from 'node:fs/promises';+import os from 'node:os';+import path from 'node:path';+import { test } from 'node:test';+import { fileURLToPath } from 'node:url';+import { promisify } from 'node:util';++import { newErrors } from './overlayTypeErrors.mjs';++const exec = promisify(execFile);+const cli = fileURLToPath(new URL('overlayTypeErrors.mjs', import.meta.url));++const missingKey =+ "src/features/AgentShareSettings/LimitsSection.tsx(98,33): error TS2339: Property 'agentShareStatus' does not exist on type '{ topic: KeyFactory<[id: string]>; }'.";+const implicitAny =+ "src/features/AgentShareSettings/ProfileSection/index.tsx(116,11): error TS7031: Binding element 'offset' implicitly has an 'any' type.";++const run = async (t, base, head) => {+ const dir = await mkdtemp(path.join(os.tmpdir(), 'overlay-type-errors-'));+ t.after(() => rm(dir, { force: true, recursive: true }));+ const files = [path.join(dir, 'base.log'), path.join(dir, 'head.log')];+ if (base !== undefined) await writeFile(files[0], base);+ await writeFile(files[1], head);+ return exec('node', [cli, ...files]).then(+ ({ stdout }) => ({ code: 0, stdout }),+ ({ code, stdout }) => ({ code, stdout }),+ );+};++test('reports a type error the base does not have', () => {+ assert.deepEqual(newErrors(implicitAny, [implicitAny, missingKey].join('\n')), [+ "src/features/AgentShareSettings/LimitsSection.tsx: TS2339: Property 'agentShareStatus' does not exist on type '{ topic: KeyFactory<[id: string]>; }'.",+ ]);+});++test('ignores an error that only moved to another line', () => {+ assert.deepEqual(newErrors(missingKey, missingKey.replace('(98,33)', '(120,7)')), []);+});++test('reports a repeat of an error the base has once', () => {+ const repeated = [missingKey, missingKey.replace('(98,33)', '(140,9)')].join('\n');++ assert.equal(newErrors(missingKey, repeated).length, 1);+});++test('fails a pull request that adds a type error', async (t) => {+ const { code, stdout } = await run(t, implicitAny, [implicitAny, missingKey].join('\n'));++ assert.equal(code, 1);+ assert.match(stdout, /agentShareStatus/);+ assert.doesNotMatch(stdout, /offset/);+});++test('passes a pull request whose only type errors exist on its base', async (t) => {+ const { code } = await run(t, missingKey, `$ tsrs --noEmit\n${missingKey}\n`);++ assert.equal(code, 0);+});++test('fails when the type check broke without reporting a type error', async (t) => {+ const { code } = await run(t, '', 'ERR_PNPM_FETCH_404 install failed');++ assert.equal(code, 1);+});++test('counts every error as new when the base produced no log', async (t) => {+ const { code } = await run(t, undefined, missingKey);++ assert.equal(code, 1);+});diff --git a/.github/workflows/overlay-type-check.yml b/.github/workflows/overlay-type-check.ymlnew file mode 100644index 00000000000..cd78f5ed5a4--- /dev/null+++ b/.github/workflows/overlay-type-check.yml@@ -0,0 +1,72 @@+name: Overlay Type Check++on:+ pull_request:+ branches: [canary]+ paths-ignore:+ - 'docs/**'+ - '**/*.md'+ - '**/*.mdx'++concurrency:+ group: overlay-type-check-${{ github.event.pull_request.number }}+ cancel-in-progress: true++permissions:+ contents: read++env:+ NODE_VERSION: '24.11.1'++jobs:+ overlay-type-check:+ name: Overlay type check+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v7+ with:+ fetch-depth: 2++ - name: Create overlay token+ id: overlay-token+ uses: ./.github/actions/overlay-token+ with:+ app-id: ${{ vars.LOBEHUB_BOT_APP_ID }}+ private-key: ${{ secrets.LOBEHUB_BOT_APP_PRIVATE_KEY }}+ repository: ${{ vars.OVERLAY_REPOSITORY }}++ - name: Type check this pull request with the overlay+ id: head+ if: steps.overlay-token.outputs.token != ''+ continue-on-error: true+ uses: ./.github/actions/overlay-type-check+ with:+ log-name: head.log+ node-version: ${{ env.NODE_VERSION }}+ overlay-repository: ${{ vars.OVERLAY_REPOSITORY }}+ overlay-token: ${{ steps.overlay-token.outputs.token }}++ # The overlay follows this branch with a delay, so the base can already fail+ # for reasons this pull request did not cause; only errors it adds count.+ - name: Check out the base with this pull request's workflow tooling+ if: steps.head.outcome == 'failure'+ run: |+ set -euo pipefail+ head_sha="$(git rev-parse HEAD)"+ git checkout --force --detach HEAD^1+ git checkout "$head_sha" -- .github++ - name: Type check the base with the same overlay+ if: steps.head.outcome == 'failure'+ continue-on-error: true+ uses: ./.github/actions/overlay-type-check+ with:+ log-name: base.log+ node-version: ${{ env.NODE_VERSION }}+ overlay-ref: ${{ env.OVERLAY_REF }}+ overlay-repository: ${{ vars.OVERLAY_REPOSITORY }}+ overlay-token: ${{ steps.overlay-token.outputs.token }}++ - name: Fail on type errors this pull request introduces+ if: steps.head.outcome == 'failure'+ run: node .github/scripts/overlayTypeErrors.mjs "$RUNNER_TEMP/base.log" "$RUNNER_TEMP/head.log"diff --git a/.github/workflows/release-desktop-beta.yml b/.github/workflows/release-desktop-beta.ymlindex e4dc08b44ea..c4c121d4a71 100644--- a/.github/workflows/release-desktop-beta.yml+++ b/.github/workflows/release-desktop-beta.yml@@ -111,9 +111,34 @@ jobs:- name: Lintrun: bun run lint- build:+ overlay-type-check:+ name: Overlay type checkneeds: [check-beta]if: needs.check-beta.outputs.is_beta == 'true'+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v7++ - name: Create overlay token+ id: overlay-token+ uses: ./.github/actions/overlay-token+ with:+ app-id: ${{ vars.LOBEHUB_BOT_APP_ID }}+ private-key: ${{ secrets.LOBEHUB_BOT_APP_PRIVATE_KEY }}+ repository: ${{ vars.OVERLAY_REPOSITORY }}++ - name: Type check overlaid sources+ if: steps.overlay-token.outputs.token != ''+ uses: ./.github/actions/overlay-type-check+ with:+ node-version: ${{ env.NODE_VERSION }}+ overlay-ref: ${{ needs.check-beta.outputs.cloud_ref }}+ overlay-repository: ${{ vars.OVERLAY_REPOSITORY }}+ overlay-token: ${{ steps.overlay-token.outputs.token }}++ build:+ needs: [check-beta, overlay-type-check]+ if: needs.check-beta.outputs.is_beta == 'true'name: Build Desktop Appruns-on: ${{ matrix.os }}strategy:diff --git a/.github/workflows/release-desktop-canary.yml b/.github/workflows/release-desktop-canary.ymlindex 6acf65ab114..03988795eb9 100644--- a/.github/workflows/release-desktop-canary.yml+++ b/.github/workflows/release-desktop-canary.yml@@ -274,12 +274,37 @@ jobs:- name: Lintrun: bun run lint+ overlay-type-check:+ name: Overlay type check+ needs: [calculate-version]+ if: ${{ !cancelled() && needs.calculate-version.result == 'success' }}+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v7++ - name: Create overlay token+ id: overlay-token+ uses: ./.github/actions/overlay-token+ with:+ app-id: ${{ vars.LOBEHUB_BOT_APP_ID }}+ private-key: ${{ secrets.LOBEHUB_BOT_APP_PRIVATE_KEY }}+ repository: ${{ vars.OVERLAY_REPOSITORY }}++ - name: Type check overlaid sources+ if: steps.overlay-token.outputs.token != ''+ uses: ./.github/actions/overlay-type-check+ with:+ node-version: ${{ env.NODE_VERSION }}+ overlay-ref: ${{ needs.calculate-version.outputs.cloud_ref }}+ overlay-repository: ${{ vars.OVERLAY_REPOSITORY }}+ overlay-token: ${{ steps.overlay-token.outputs.token }}+# ============================================# 多平台构建# ============================================build:- needs: [calculate-version, test]- if: ${{ !cancelled() && needs.calculate-version.result == 'success' && needs.test.result == 'success' }}+ needs: [calculate-version, test, overlay-type-check]+ if: ${{ !cancelled() && needs.calculate-version.result == 'success' && needs.test.result == 'success' && needs.overlay-type-check.result == 'success' }}name: Build Desktop Appruns-on: ${{ matrix.os }}strategy:diff --git a/.github/workflows/release-desktop-core-ota.yml b/.github/workflows/release-desktop-core-ota.ymlindex 32636d1f50a..71450f1eade 100644--- a/.github/workflows/release-desktop-core-ota.yml+++ b/.github/workflows/release-desktop-core-ota.yml@@ -288,6 +288,31 @@ jobs:steps-json: ${{ toJSON(steps) }}job-status: ${{ job.status }}+ overlay-type-check:+ name: Overlay type check+ needs: [gate]+ if: needs.gate.outputs.requires_full_release == 'false'+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v7++ - name: Create overlay token+ id: overlay-token+ uses: ./.github/actions/overlay-token+ with:+ app-id: ${{ vars.LOBEHUB_BOT_APP_ID }}+ private-key: ${{ secrets.LOBEHUB_BOT_APP_PRIVATE_KEY }}+ repository: ${{ vars.OVERLAY_REPOSITORY }}++ - name: Type check overlaid sources+ if: steps.overlay-token.outputs.token != ''+ uses: ./.github/actions/overlay-type-check+ with:+ node-version: ${{ env.NODE_VERSION }}+ overlay-ref: ${{ needs.gate.outputs.cloud_ref }}+ overlay-repository: ${{ vars.OVERLAY_REPOSITORY }}+ overlay-token: ${{ steps.overlay-token.outputs.token }}+build-core:name: Build core (${{ matrix.platform }})needs: [gate]@@ -418,7 +443,7 @@ jobs:publish:name: Publish core (${{ inputs.channel }})- needs: [gate, build-core]+ needs: [gate, build-core, overlay-type-check]if: needs.gate.outputs.requires_full_release == 'false'runs-on: ubuntu-latestoutputs:diff --git a/.github/workflows/release-desktop-stable.yml b/.github/workflows/release-desktop-stable.ymlindex d7eff3d860c..c18dd1a5cf5 100644--- a/.github/workflows/release-desktop-stable.yml+++ b/.github/workflows/release-desktop-stable.yml@@ -267,11 +267,66 @@ jobs:echo "complete_matrix=$([ "$count" -eq 4 ] && echo true || echo false)"} >> "$GITHUB_OUTPUT"+ overlay-type-check:+ name: Overlay type check+ needs: [check-stable]+ if: needs.check-stable.outputs.build_required == 'true'+ runs-on: ubuntu-latest+ steps:+ - name: Checkout release tooling+ uses: actions/checkout@v7+ with:+ ref: ${{ github.workflow_sha }}++ - name: Preserve release tooling+ shell: bash+ run: |+ set -euo pipefail+ mkdir -p "$RUNNER_TEMP/desktop-release-tooling"+ cp -R .github "$RUNNER_TEMP/desktop-release-tooling/"+ tooling_sha="$(git rev-parse HEAD)"+ echo "DESKTOP_TOOLING_SHA=$tooling_sha" >> "$GITHUB_ENV"++ - name: Checkout product sources+ uses: actions/checkout@v7+ with:+ ref: ${{ needs.check-stable.outputs.oss_sha }}++ - name: Verify product sources and restore tooling+ shell: bash+ env:+ RELEASE_OSS_SHA: ${{ needs.check-stable.outputs.oss_sha }}+ CLOUD_REF: ${{ needs.check-stable.outputs.cloud_ref }}+ SOURCES_HASH: ${{ needs.check-stable.outputs.sources_hash }}+ run: |+ set -euo pipefail+ [ "$(git rev-parse HEAD)" = "$RELEASE_OSS_SHA" ] || { echo '::error::Product source SHA mismatch'; exit 1; }+ mkdir -p .github+ cp -R "$RUNNER_TEMP/desktop-release-tooling/.github/." .github/+ node .github/scripts/desktopReleaseCli.mjs verify-checkout++ - name: Create overlay token+ id: overlay-token+ uses: ./.github/actions/overlay-token+ with:+ app-id: ${{ vars.LOBEHUB_BOT_APP_ID }}+ private-key: ${{ secrets.LOBEHUB_BOT_APP_PRIVATE_KEY }}+ repository: ${{ vars.OVERLAY_REPOSITORY }}++ - name: Type check overlaid sources+ if: steps.overlay-token.outputs.token != ''+ uses: ./.github/actions/overlay-type-check+ with:+ node-version: ${{ env.NODE_VERSION }}+ overlay-ref: ${{ needs.check-stable.outputs.cloud_ref }}+ overlay-repository: ${{ vars.OVERLAY_REPOSITORY }}+ overlay-token: ${{ steps.overlay-token.outputs.token }}+# ============================================# 多平台构建# ============================================build:- needs: [check-stable, configure-build]+ needs: [check-stable, configure-build, overlay-type-check]if: needs.check-stable.outputs.build_required == 'true'name: Build Desktop Appruns-on: ${{ matrix.os }}diff --git a/.github/workflows/test.yml b/.github/workflows/test.ymlindex 83c7ef48f84..24e7e936a7e 100644--- a/.github/workflows/test.yml+++ b/.github/workflows/test.yml@@ -86,7 +86,7 @@ jobs:run: node --test .github/scripts/hotfixWorkflow.test.mjs- name: Verify desktop release workflows- run: node --test .github/scripts/desktop-publish-s3.test.mjs .github/scripts/release-desktop-canary.test.mjs+ run: node --test .github/scripts/desktop-publish-s3.test.mjs .github/scripts/release-desktop-canary.test.mjs .github/scripts/desktop-overlay-type-check.test.mjs .github/scripts/overlayTypeErrors.test.mjs- name: Test CLI build configuration, bundle and model-facing docsrun: bunx vitest run --config vitest.config.mts --silent='passed-only' tsdown.config.test.ts bundle.test.ts src/modelFacingDocs.test.ts