From b3c1a666b5f9cdcec94be7480ca978e7fa5397a2 Mon Sep 17 00:00:00 2001 From: Jackson Chen <90215880+Sma1lboy@users.noreply.github.com> Date: Thu, 1 Oct 2026 02:31:36 -0700 Subject: [PATCH] fix: make editor and deployment feedback truthful --- backend/src/project/__tests__/deploy.spec.ts | 42 +++ backend/src/project/deploy.ts | 20 +- docs/testing/editor-feedback.md | 97 +++++ frontend/jest.editor-feedback.config.js | 22 ++ .../__tests__/code-engine.test.tsx | 353 ++++++++++++++++++ .../code-engine/__tests__/code-tab.test.tsx | 195 ++++++++++ .../__tests__/deploy-dialog.test.tsx | 137 +++++++ .../code-engine/__tests__/web-view.test.tsx | 53 +++ .../chat/code-engine/code-engine.tsx | 317 +++++----------- .../chat/code-engine/deploy-dialog.tsx | 69 +++- .../chat/code-engine/save-changes-bar.tsx | 8 +- .../chat/code-engine/tabs/code-tab.tsx | 80 +++- .../components/chat/code-engine/web-view.tsx | 9 + scripts/check-editor-feedback.mjs | 98 +++++ 14 files changed, 1256 insertions(+), 244 deletions(-) create mode 100644 docs/testing/editor-feedback.md create mode 100644 frontend/jest.editor-feedback.config.js create mode 100644 frontend/src/components/chat/code-engine/__tests__/code-engine.test.tsx create mode 100644 frontend/src/components/chat/code-engine/__tests__/code-tab.test.tsx create mode 100644 frontend/src/components/chat/code-engine/__tests__/deploy-dialog.test.tsx create mode 100644 frontend/src/components/chat/code-engine/__tests__/web-view.test.tsx create mode 100644 scripts/check-editor-feedback.mjs diff --git a/backend/src/project/__tests__/deploy.spec.ts b/backend/src/project/__tests__/deploy.spec.ts index 624610b0..b38383cd 100644 --- a/backend/src/project/__tests__/deploy.spec.ts +++ b/backend/src/project/__tests__/deploy.spec.ts @@ -130,6 +130,48 @@ describe('deployToVercel', () => { ); expect(res.ok).toBe(false); expect(res.message).toMatch(/60s/); + expect(res.message).toMatch(/could not confirm/i); + expect(res.message).toContain( + 'Check your Vercel deployments before trying again', + ); + expect(res.message).not.toContain('Nothing was deployed'); + }); + + it('keeps a lost network response uncertain instead of encouraging a duplicate deploy', async () => { + const post = jest.fn(async () => { + throw new Error('connection reset after request body was sent'); + }); + const res = await deployToVercel( + 'tok', + 'p', + [{ file: 'a', data: 'b' }], + post, + ); + expect(post).toHaveBeenCalledTimes(1); + expect(res.ok).toBe(false); + expect(res.message).toContain( + 'Check your Vercel deployments before trying again', + ); + }); + + it('handles a lost response body after Vercel accepts the request', async () => { + const res = await deployToVercel( + 'tok', + 'p', + [{ file: 'a', data: 'b' }], + async () => + ({ + ok: true, + text: async () => { + throw new Error('body stream failed'); + }, + }) as unknown as Response, + ); + expect(res.ok).toBe(false); + expect(res.message).toContain('could not read the deployment result'); + expect(res.message).toContain( + 'Check your Vercel deployments before trying again', + ); }); it('does not claim success when no url comes back', async () => { diff --git a/backend/src/project/deploy.ts b/backend/src/project/deploy.ts index ba632aa5..b18a6335 100644 --- a/backend/src/project/deploy.ts +++ b/backend/src/project/deploy.ts @@ -147,12 +147,23 @@ export async function deployToVercel( url: '', message: (error as Error)?.name === 'TimeoutError' - ? 'Vercel did not respond within 60s. Nothing was deployed.' - : `Could not reach Vercel: ${(error as Error)?.message ?? error}`, + ? 'Vercel did not respond within 60s. We could not confirm the deployment. Check your Vercel deployments before trying again.' + : 'We could not confirm the deployment. Check your Vercel deployments before trying again.', }; } - const body = await res.text(); + let body: string; + try { + body = await res.text(); + } catch { + // The provider may have accepted the POST before the response was lost. + return { + ok: false, + url: '', + message: + 'We could not read the deployment result. Check your Vercel deployments before trying again.', + }; + } const json = (() => { try { return JSON.parse(body); @@ -184,6 +195,7 @@ export async function deployToVercel( : { ok: false, url: '', - message: 'Vercel accepted the deploy but returned no URL.', + message: + 'Vercel accepted the deploy but returned no URL. Check your Vercel deployments before trying again.', }; } diff --git a/docs/testing/editor-feedback.md b/docs/testing/editor-feedback.md new file mode 100644 index 00000000..a9403b4e --- /dev/null +++ b/docs/testing/editor-feedback.md @@ -0,0 +1,97 @@ +# Editor and deployment feedback + +Scope: CF02, CF04, CF05, CF08 (version history), CF09 (preview controls), +CF13 (deployment clipboard), and CF14 from the CodeFox copy audit. + +## Behavior + +- Project preparation is indeterminate. Neither elapsed time nor a saved + presentation flag establishes readiness. Navigating to a different chat + resets its editor/loading state. +- A lost restore response is an unknown outcome. Refresh project files and + version history before another attempt. A known request rejection preserves + the current editor/draft and refreshes history separately. +- Failed or malformed history reads show an error and a functioning retry, + separately from a successfully read empty history. +- Deployment timeouts, lost network responses, and unreadable response bodies + direct the user to check Vercel deployments before retrying. The client does + not claim that nothing was deployed and does not automatically deploy again. +- A deployment URL is only marked copied after the clipboard promise resolves. + Denial or missing clipboard support offers the complete URL in a selectable, + read-only input. Closing/reopening invalidates a pending copy result. +- The save bar names the actions “Discard changes” and “Save file,” wraps at + narrow widths, and retains edits plus the save action after a save failure. +- Preview navigation, zoom, refresh, fullscreen and path controls have + persistent accessible names. This is targeted accessibility coverage, not a + full screen-reader or WCAG audit. + +## Reproduce the automated checks + +Use the repository's pinned pnpm 9.1.0 and a completed dependency installation: + +```sh +pnpm --dir frontend exec jest --config jest.editor-feedback.config.js --runInBand +pnpm --dir backend exec jest src/project/__tests__/deploy.spec.ts --runInBand +node scripts/check-editor-feedback.mjs +pnpm check +pnpm --dir frontend exec tsc --noEmit +pnpm --dir backend exec tsc --noEmit +pnpm --dir frontend build +pnpm --dir backend build +``` + +The component tests render the real affected components with explicit offline +fixtures for project context, the Monaco editor, HTTP/Apollo responses and +clipboard results. They do not sign in, run a paid generation, contact Vercel, +or certify production deployment behavior. The backend tests inject `post` +and never transmit a real token. + +Tests cover waiting beyond six minutes, cached completion, newer navigation, +no-project responses, preserved failed-save edits, discard, failed/malformed +history plus retry, three uncertain restore outcomes, known rejection, +success, stale history responses, delayed/denied/missing clipboard, reopening, +repeated copy and preview accessible names. + +## Verification record + +The dependency-free regression was run against the original implementation +and failed, then passed after the fix. The complete source-check runner has +three pre-existing failures on the baseline: `check-lint-feedback.mjs`, +`check-notes-contract.mjs`, and `check-quota-wired.mjs`. This change adds one +passing check and introduces no additional source-check failure. + +Final validation on 2026-10-01: + +- 24/24 offline frontend component tests passed +- 40/40 backend suites, 280/280 tests passed (including 19 deployment tests) +- Backend production build passed. An earlier frontend production build passed; + the final repeat after the file-loading guard was blocked during Next output + cleanup before compilation (see below) +- Focused frontend (including new tests) and backend lint passed with warnings +- Backend standalone TypeScript check passed +- The completed frontend standalone TypeScript check had the same baseline error: + `src/config/common-path.ts` cannot resolve `fs-extra`/its declarations. The + existing Next configuration ignores build-time type errors; a passing build + is not presented as a passing standalone type check +- Source checks: 38/41 passed; the three failures above also fail on baseline + +Late-save coverage additionally checks file navigation, newer edits during a +save, chat navigation, background refreshes, and a delayed read of the next +file. Content from one file cannot be edited/saved as a newly selected file +before that file's read completes. + +Local browser screenshots are not verified: this environment's cloud browser +blocked localhost. A separate, explicitly mocked before/after fixture harness +was prepared for an isolated repository CI artifact job. It is not included +in this feature change, and no live deployment, account flow, or paid generation +was attempted. + +The final repeated frontend build encountered an infrastructure failure in +Next's cleanup of `.next/standalone`: generated workspace symlinks led into the +shared dependency checkout. Required dependency paths subsequently became +unavailable, so further build/type/baseline reruns were stopped. Final 24-case +component tests and focused lint had already passed on the final source. A +clean independent dependency installation is required for the final build +rerun; do not reuse a shared symlinked workspace for standalone-output cleanup. +The last complete component red run on the original implementation had 21 +failures out of 23 tests; the final delayed-file-read case was added afterward. diff --git a/frontend/jest.editor-feedback.config.js b/frontend/jest.editor-feedback.config.js new file mode 100644 index 00000000..2c98cbff --- /dev/null +++ b/frontend/jest.editor-feedback.config.js @@ -0,0 +1,22 @@ +// Offline component tests for truthful editor/deployment states. No backend, +// account, paid generation, clipboard permission, or Vercel access is needed. +module.exports = { + rootDir: '.', + testEnvironment: 'jsdom', + testMatch: ['/src/components/chat/code-engine/__tests__/*.test.tsx'], + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + tsconfig: { + jsx: 'react-jsx', + module: 'commonjs', + moduleResolution: 'node', + }, + }, + ], + }, + moduleNameMapper: { '^@/(.*)$': '/src/$1' }, + setupFilesAfterEnv: ['@testing-library/jest-dom'], + clearMocks: true, +}; diff --git a/frontend/src/components/chat/code-engine/__tests__/code-engine.test.tsx b/frontend/src/components/chat/code-engine/__tests__/code-engine.test.tsx new file mode 100644 index 00000000..85219d66 --- /dev/null +++ b/frontend/src/components/chat/code-engine/__tests__/code-engine.test.tsx @@ -0,0 +1,353 @@ +import React from 'react'; +import '@testing-library/jest-dom'; +import { + act, + fireEvent, + render, + screen, + waitFor, +} from '@testing-library/react'; +import { CodeEngine } from '../code-engine'; +import { ProjectContext } from '../project-context'; +import { authenticatedFetch } from '@/lib/authenticatedFetch'; +import { toast } from 'sonner'; + +jest.mock('../project-context', () => ({ + ProjectContext: jest.requireActual('react').createContext({}), +})); +jest.mock('@/lib/authenticatedFetch', () => ({ + authenticatedFetch: jest.fn(), +})); +jest.mock('@/app/log/logger', () => ({ + logger: { error: jest.fn(), warn: jest.fn(), info: jest.fn() }, +})); +jest.mock('sonner', () => ({ toast: { error: jest.fn() } })); +jest.mock('framer-motion', () => ({ + AnimatePresence: ({ children }: any) => children, + motion: { + div: ({ children, initial, animate, exit, ...props }: any) => ( +
{children}
+ ), + }, +})); +jest.mock('../responsive-toolbar', () => ({ + __esModule: true, + default: ({ setActiveTab }: any) => ( + + ), +})); +jest.mock('../tabs/preview-tab', () => ({ + __esModule: true, + default: () =>
Preview fixture
, +})); +jest.mock('../tabs/console-tab', () => ({ + __esModule: true, + default: () => null, +})); +jest.mock('../tabs/code-tab', () => ({ + __esModule: true, + default: ({ newCode, updateSavingStatus, setFilePath, fileReady }: any) => ( + <> +