diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index a58ace69..1f3d5380 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -20,18 +20,16 @@ jobs: ref: ${{ github.head_ref }} fetch-depth: 0 - - uses: pnpm/action-setup@v2 - with: - version: 8 - + - uses: pnpm/action-setup@v4 + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '22' cache: 'pnpm' - name: Install dependencies - run: pnpm install --no-frozen-lockfile + run: pnpm install --frozen-lockfile - name: Cache pnpm modules uses: actions/cache@v3 @@ -41,31 +39,35 @@ jobs: restore-keys: | ${{ runner.os }}-pnpm- - - name: Format code with Prettier - id: format + - name: Find files changed by this pull request + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | - pnpm exec prettier --write "**/*.{js,jsx,ts,tsx,json,md}" - if [ -n "$(git status --porcelain)" ]; then - echo "FORMAT_HAS_CHANGES=true" >> $GITHUB_ENV - fi - git add . + git diff --name-only --diff-filter=ACMR -z "$BASE_SHA...$HEAD_SHA" -- \ + '*.js' '*.jsx' '*.ts' '*.tsx' '*.json' '*.md' > "$RUNNER_TEMP/codefox-format-files" + git diff --name-only --diff-filter=ACMR -z "$BASE_SHA...$HEAD_SHA" -- \ + '*.js' '*.jsx' '*.ts' '*.tsx' > "$RUNNER_TEMP/codefox-lint-files" - - name: Run ESLint fix - id: lint - continue-on-error: true + - name: Format changed files with Prettier run: | - pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --fix - if [ -n "$(git status --porcelain)" ]; then - echo "LINT_HAS_CHANGES=true" >> $GITHUB_ENV + mapfile -d '' files < "$RUNNER_TEMP/codefox-format-files" + if (( ${#files[@]} )); then + pnpm exec prettier --write --ignore-unknown "${files[@]}" + git add -- "${files[@]}" fi - # Run ESLint again to check remaining issues - pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 || echo "LINT_HAS_ERRORS=true" >> $GITHUB_ENV - git add . - - name: Check TypeScript + - name: Run ESLint fix on changed files run: | - pnpm exec tsc --noEmit - if [ $? -ne 0 ]; then - echo "TS_HAS_ERRORS=true" >> $GITHUB_ENV + mapfile -d '' files < "$RUNNER_TEMP/codefox-lint-files" + if (( ${#files[@]} )); then + pnpm exec eslint --resolve-plugins-relative-to backend --fix "${files[@]}" + git add -- "${files[@]}" fi - - uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a \ No newline at end of file + + - name: Check frontend TypeScript + run: pnpm exec tsc --project frontend/tsconfig.json --noEmit + + - name: Check backend TypeScript + run: pnpm exec tsc --project backend/tsconfig.json --noEmit + - uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml index e48a397d..904a0925 100644 --- a/.github/workflows/backend-ci.yml +++ b/.github/workflows/backend-ci.yml @@ -4,7 +4,11 @@ on: branches: [ main ] paths: - 'backend/**' - - 'codefox-common/**' + - 'package.json' + - 'pnpm-lock.yaml' + - 'pnpm-workspace.yaml' + - 'patches/**' + - '.github/workflows/backend-ci.yml' - 'scripts/**' workflow_dispatch: jobs: @@ -19,12 +23,11 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: '18' + node-version: '22' - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: - version: 8 run_install: false - name: Get pnpm store directory @@ -41,12 +44,8 @@ jobs: ${{ runner.os }}-pnpm-store- - name: Install dependencies - run: pnpm install --no-frozen-lockfile + run: pnpm install --frozen-lockfile - - name: Build codefox-common - working-directory: ./codefox-common - run: pnpm build - - name: Build backend working-directory: ./backend run: pnpm build @@ -66,4 +65,4 @@ jobs: ./backend/node_modules key: ${{ runner.os }}-backend-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-backend-${{ hashFiles('**/pnpm-lock.yaml') }}- \ No newline at end of file + ${{ runner.os }}-backend-${{ hashFiles('**/pnpm-lock.yaml') }}- diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 5526504e..b9b33cc6 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -14,14 +14,12 @@ jobs: with: fetch-depth: 0 - - uses: pnpm/action-setup@v2 - with: - version: 8 - + - uses: pnpm/action-setup@v4 + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: '22' cache: 'pnpm' - name: Get pnpm store directory @@ -39,9 +37,7 @@ jobs: ${{ runner.os }}-pnpm-store- - name: Install dependencies - run: | - cd backend - pnpm install --frozen-lockfile + run: pnpm install --frozen-lockfile - name: Run tests run: | @@ -55,4 +51,4 @@ jobs: directory: ./backend/coverage flags: backend fail_ci_if_error: true - verbose: true \ No newline at end of file + verbose: true diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend-ci.yml index dc3a7292..1616721b 100644 --- a/.github/workflows/frontend-ci.yml +++ b/.github/workflows/frontend-ci.yml @@ -4,7 +4,11 @@ on: branches: [ main ] paths: - 'frontend/**' - - 'codefox-common/**' + - 'package.json' + - 'pnpm-lock.yaml' + - 'pnpm-workspace.yaml' + - 'patches/**' + - '.github/workflows/frontend-ci.yml' - 'scripts/**' workflow_dispatch: jobs: @@ -19,12 +23,11 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: '18' + node-version: '22' - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: - version: 8 run_install: false - name: Get pnpm store directory @@ -41,12 +44,21 @@ jobs: ${{ runner.os }}-pnpm-store- - name: Install dependencies - run: pnpm install --no-frozen-lockfile + run: pnpm install --frozen-lockfile - - name: Build codefox-common - working-directory: ./codefox-common - run: pnpm build - + - name: Run focused frontend tests + working-directory: ./frontend + shell: bash + run: | + shopt -s nullglob + configs=(jest.*.config.js) + if (( ${#configs[@]} == 0 )); then + echo "No focused frontend test configurations in this revision" + fi + for config in "${configs[@]}"; do + pnpm exec jest --config "$config" --runInBand + done + - name: Build frontend working-directory: ./frontend run: pnpm build @@ -62,4 +74,4 @@ jobs: ./frontend/node_modules key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ github.sha }} restore-keys: | - ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}- \ No newline at end of file + ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}- diff --git a/frontend/src/config/common-path.ts b/frontend/src/config/common-path.ts index ed989604..bd4bec09 100644 --- a/frontend/src/config/common-path.ts +++ b/frontend/src/config/common-path.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { existsSync, mkdirSync, promises as fsPromises } from 'fs-extra'; +import { existsSync, mkdirSync, promises as fsPromises } from 'node:fs'; import { createHash } from 'crypto'; // Constants for the frontend root directory diff --git a/scripts/check-ci-workflows.mjs b/scripts/check-ci-workflows.mjs new file mode 100644 index 00000000..20ca91fd --- /dev/null +++ b/scripts/check-ci-workflows.mjs @@ -0,0 +1,123 @@ +#!/usr/bin/env node +/** + * CI must exercise the workspaces that actually exist. The old jobs built a + * deleted package, installed an incompatible pnpm, and ran tsc without a + * project. Keep those failures from hiding the product's checks again. + */ +import assert from 'node:assert/strict'; +import { existsSync, readFileSync } from 'node:fs'; + +const read = (p) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8'); +const workflows = Object.fromEntries( + ['frontend-ci', 'backend-ci', 'autofix', 'codecov'].map((name) => [ + name, + read(`.github/workflows/${name}.yml`), + ]) +); + +for (const [name, source] of Object.entries(workflows)) { + assert.match( + source, + /pnpm\/action-setup@v4/, + `${name} uses an obsolete pnpm setup` + ); + assert.doesNotMatch( + source, + /version: 8\b/, + `${name} overrides the declared pnpm` + ); + assert.match( + source, + /node-version: '22'/, + `${name} cannot run the locked AI SDK` + ); + assert.match( + source, + /pnpm install --frozen-lockfile/, + `${name} ignores the lockfile` + ); + assert.doesNotMatch( + source, + /codefox-common/, + `${name} builds a deleted workspace` + ); + for (const [, dir] of source.matchAll(/working-directory: (\S+)/g)) { + assert.ok( + existsSync(new URL(`../${dir}/package.json`, import.meta.url)), + `${name}: ${dir} is not a workspace` + ); + } +} + +for (const name of ['frontend-ci', 'backend-ci']) { + const source = workflows[name]; + for (const path of [ + 'package.json', + 'pnpm-lock.yaml', + 'pnpm-workspace.yaml', + 'patches/**', + `.github/workflows/${name}.yml`, + ]) { + assert.ok( + source.includes(`- '${path}'`), + `${name} skips changes to ${path}` + ); + } + assert.match( + source, + /run: pnpm check/, + `${name} no longer runs the source guards` + ); +} + +const frontend = workflows['frontend-ci']; +assert.match( + frontend, + /configs=\(jest\.\*\.config\.js\)/, + 'focused frontend suites are not discovered' +); +assert.match( + frontend, + /for config in "\$\{configs\[@\]\}"/, + 'only one frontend suite is run' +); +assert.match( + frontend, + /pnpm exec jest --config "\$config" --runInBand/, + 'focused frontend suites are not executed' +); + +const autofix = workflows.autofix; +for (const workspace of ['frontend', 'backend']) { + assert.ok( + autofix.includes( + `pnpm exec tsc --project ${workspace}/tsconfig.json --noEmit` + ), + `autofix skips the ${workspace} typecheck` + ); +} +assert.doesNotMatch( + autofix, + /continue-on-error/, + 'autofix hides a failed check' +); +assert.match( + autofix, + /git diff --name-only --diff-filter=ACMR -z "\$BASE_SHA\.\.\.\$HEAD_SHA"/, + 'autofix no longer scopes files to the pull request' +); +assert.match( + autofix, + /prettier --write --ignore-unknown "\$\{files\[@\]\}"/, + 'formatting includes unrelated files' +); +assert.match( + autofix, + /eslint --resolve-plugins-relative-to backend --fix "\$\{files\[@\]\}"/, + 'lint fixes include unrelated files' +); +assert.doesNotMatch(autofix, /git add \./, 'autofix stages unrelated changes'); + +console.log( + 'ok — CI targets current workspaces, locked tools, source guards and focused tests' +); diff --git a/scripts/check-lint-feedback.mjs b/scripts/check-lint-feedback.mjs index 2907c6aa..5606016e 100644 --- a/scripts/check-lint-feedback.mjs +++ b/scripts/check-lint-feedback.mjs @@ -119,8 +119,16 @@ assert.equal( // ── The wiring, which is what actually breaks ────────────────────── const agent = read('backend/src/chat/project-agent.ts'); +const instructions = read('backend/src/chat/instructions.ts'); +// Assembly moved out of the harness module. Guard both the caller and the +// callee: checking the helper alone would pass if the agent stopped using it. assert.match( agent, + /const prompt = assemblePrompt\(\{\s*notes,\s*history,\s*handEdits,\s*lint,\s*asked,?\s*\}\)/, + 'the agent no longer passes live findings to the prompt assembler' +); +assert.match( + instructions.slice(instructions.indexOf('export const assemblePrompt')), /\$\{lintNote\(lint\)\}\$\{asked\}/, 'lint findings are no longer in the prompt, or no longer sit last before the request' ); @@ -130,9 +138,22 @@ const controller = read('backend/src/chat/chat.controller.ts'); // restyle, a restore or a hand edit has since changed. assert.match( controller, - /lint:\s*\n?\s*project\.template === 'html'\s*\n?\s*\?\s*await this\.lintPage\(project\.projectPath\)/, + /const lint\s*=\s*project\.template === 'html'\s*\?\s*await this\.lintPage\(project\.projectPath\)/, 'the turn no longer lints the page before running the agent' ); +const agentOptions = controller.match( + /await runProjectAgent\(\{([\s\S]*?)\}\)/ +)?.[1]; +assert.match( + agentOptions ?? '', + /\blint,/, + 'the freshly computed findings never reach the agent' +); +assert.ok( + controller.search(/\bconst lint\s*=/) < + controller.indexOf('await runProjectAgent('), + 'the page is linted only after the agent has already run' +); // The end-of-turn lint is what feeds the panel; both halves have to stay. assert.match( controller, diff --git a/scripts/check-notes-contract.mjs b/scripts/check-notes-contract.mjs index 6119d12b..c25d246c 100644 --- a/scripts/check-notes-contract.mjs +++ b/scripts/check-notes-contract.mjs @@ -41,9 +41,16 @@ assert.match( /Keep NOTES\.md in the project root as its memory/, 'the agent is no longer told to keep NOTES.md' ); -// Read back into the prompt, which is what makes an edit take effect. +// Guard both ends of the extracted assembler: the helper can keep accepting +// notes while the agent accidentally stops forwarding them. assert.match( agent, + /const prompt = assemblePrompt\(\{\s*notes,\s*history,\s*handEdits,\s*lint,\s*asked,?\s*\}\)/, + 'the agent no longer passes project notes to the prompt assembler' +); +// Read back into the prompt, which is what makes an edit take effect. +assert.match( + instructions.slice(instructions.indexOf('export const assemblePrompt')), /\$\{notesNote\(notes\)\}/, 'notes are no longer in the prompt — editing them would change nothing' ); @@ -99,7 +106,7 @@ assert.match( // appends NOTES_SECTION on the Next path too. assert.match( instructions, - /\[INSTRUCTIONS, shape, NOTES_SECTION\]/, + /if \(template !== 'html'\) \{\s*return \[[^\]]*\bNOTES_SECTION\b/, 'Next projects no longer get the notes section — the button should then be page-only' ); diff --git a/scripts/check-quota-wired.mjs b/scripts/check-quota-wired.mjs index f87b11aa..b22efcdc 100644 --- a/scripts/check-quota-wired.mjs +++ b/scripts/check-quota-wired.mjs @@ -85,7 +85,7 @@ assert.match( ); assert.match( controller, - /withUserTurn\(userId, \(\) => this\.pipeAgent\(chatDto, res\)\)/, + /await withUserTurn\(userId, \(\) => this\.pipeAgent\(chatDto, res, userId\)\)/, 'turns are no longer counted while they run', ); // The finally is the whole safety of this: a leaked slot locks the user out