From 21d6f904680c1819630de7aba87dfaa7783dcbef Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Thu, 12 Nov 2026 19:20:51 +0100 Subject: [PATCH 1/3] Restore the terminal prompt after wf dev startup errors (#560) --- docs/CHANGELOG.md | 1 + docs/DEVELOPER_ENVIRONMENT.md | 3 +++ js/developer/environment/bundles.json | 2 +- js/developer/environment/development.mjs | 3 +++ test/developer/specs/development-specs.mjs | 21 +++++++++++++++ test/web/developer-specs.mjs | 30 +++++++++++++++++++++- 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b411c95f..965a5f3a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -25,6 +25,7 @@ these entries stays in the GitHub releases and the Git history. ### Fixed +- Restore the terminal prompt with exit code 1 when `wf dev` starts without a project or a selectable entry; compilation errors still keep watching for edits (#560). - Read all six developer integration reports in CTest after a part fails, and keep the successful parts' dependent tests runnable, also when the session's native deadline ends it (#556). - On Windows, `wf install`, `wf build` and `wf test` no longer fail with `rename: Access is denied` while another process, such as an antivirus scan, still reads the files just written: the developer store tries the rename again for up to 635 ms; `wf test` also empties the directory of an interrupted run (#542). - Run the commit attribution regression checks with older Git versions by dropping the unsupported `git log --no-graph` option (#525). diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index eb94ea16..8c2d796b 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -495,6 +495,9 @@ files; the developer HTTP provider serves only the environment and preview direc `wf dev [entry.tsx|name]` selects `entries.main` or the sole entry when omitted, builds, opens the preview and keeps running until Ctrl+C. It reuses one compiler Worker and esbuild context across rebuilds. +An initial configuration error, such as a missing project or an omitted entry that cannot be selected, +ends the command with exit code 1 and restores the terminal prompt. Once compilation starts, errors +keep the watcher running so that editing the inputs can recover, including after a failed first build. Changing the selected entry or locked graph recreates the context. It uses the installed lock, without resolving packages or downloading dependencies; `wf install`/`wf restore` remain explicit actions. diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 3131d35f..1e01d3d6 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -19,7 +19,7 @@ "js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3", "js/developer/environment/runtime.mjs": "2c9ef449c44ddbdcc327ffb126e61c3e8e8076edbe73a0dce99e3dc9bb42b5a9", "js/developer/environment/automation.mjs": "79405c89ba7025c1774bc13c9b78d814a07592755dcde018c8659a8015c4b8ed", - "js/developer/environment/development.mjs": "168a2619c4d74544eed2b2ae1121e87c3afc776dc6140a3c7d1ba1d0d6168cd8", + "js/developer/environment/development.mjs": "bbc07483d1282b4f765bf3d597653ee182a2a11ea264c2d3ae383f1cf8850dd3", "js/developer/environment/testing.mjs": "aeb584505fab5957b9c02e78536e12f7d7f3d12f8adb2e17f1a1a6e395e43f3c", "js/developer/environment/terminal.mjs": "7ffcf7ac6ef63c35cdf5ef70284b384525b13ba18422af069289e53b6c4f6be1", "js/developer/environment/workspace.mjs": "4fe794b140515579c4f80a226d8b1beca254a3488e2e4d9f6ba580e077a11558", diff --git a/js/developer/environment/development.mjs b/js/developer/environment/development.mjs index cd0435f3..98dce333 100644 --- a/js/developer/environment/development.mjs +++ b/js/developer/environment/development.mjs @@ -238,6 +238,9 @@ export async function dev(args, {bridge, signal, preview: frame, write = () => { } catch (error) { if (active.aborted) throw stopped(); if (error?.code === 'busy') { await waitForPoll(active); continue; } + // Watching starts with the compiler. Invalid initial configuration must finish the command; + // compilation errors (including the first build) and later configuration edits remain recoverable. + if (!session) throw error; diagnostic = diagnosticsText(error); report('failed'); write(diagnostic + '\n'); diff --git a/test/developer/specs/development-specs.mjs b/test/developer/specs/development-specs.mjs index e9827bed..0e2ad3a2 100644 --- a/test/developer/specs/development-specs.mjs +++ b/test/developer/specs/development-specs.mjs @@ -12,6 +12,27 @@ describe('wf dev', () => { const encode = text => new TextEncoder().encode(text); const lock = {format: 1, roots: {}, packages: {}}; + for (const [label, manifest, message] of [ + ['without a project', null, /No webfront.project.json: run wf init/], + ['without an entry', {format: 1, name: 'empty', version: '0.1.0'}, /Usage: wf dev /], + ]) it(`rejects ${label} without waiting for Ctrl+C or starting a compiler`, async () => { + const {bridge} = memoryBridge(new Map(manifest ? [['webfront.project.json', encode(JSON.stringify(manifest))]] : [])); + const controller = new AbortController(); + // Bound the regression: the broken command stays in its polling loop until this aborts it. + const timer = setTimeout(() => controller.abort(), 1000); + const states = [], output = []; + const frame = new EventTarget(); + frame.addEventListener('webfront-dev-status', event => states.push(event.detail.state)); + const worker = spyOn(globalThis, 'Worker').and.throwError('The compiler must not start'); + try { + await rejects(dev([], {bridge, signal: controller.signal, preview: frame, write: text => output.push(text)}), message); + expect(controller.signal.aborted).toBe(false); + expect(worker).not.toHaveBeenCalled(); + expect(states.at(-1)).toBe('stopped'); + expect(output).toEqual([]); + } finally { clearTimeout(timer); controller.abort(); } + }); + it('one esbuild context reads changed imports, reports syntax errors and recovers', async () => { const files = new Map([['main.ts', encode("import {value} from './value'; console.log(value)")], ['value.ts', encode('export const value = 1')]]); const context = await bundleContext(await esbuild(), {entry: 'main.ts', lock, readProject: async path => { diff --git a/test/web/developer-specs.mjs b/test/web/developer-specs.mjs index 0fcff488..d25c1fa6 100644 --- a/test/web/developer-specs.mjs +++ b/test/web/developer-specs.mjs @@ -1240,8 +1240,16 @@ try { host.style.cssText = 'width:640px;height:240px'; document.body.append(host); let exitedWith = null; + let startupFiles; + const terminalBridge = {socket: webFront.socket, cppFunction: name => name !== 'webfront.developer.read' ? webFront.cppFunction(name) : + async (path, offset) => { + if (!startupFiles || !['webfront.project.json', 'webfront-packages.lock.json'].includes(path)) + return webFront.cppFunction(name)(path, offset); + if (!startupFiles.has(path)) throw new Error('Cannot read project file: ' + path); + return startupFiles.get(path).subarray(offset, offset + 256 * 1024); + }}; // The test sets the terminal's size itself: an observer following the element would race with it. - const mounted = async () => runtime.mount({bridge: webFront, config, terminal: host, preview: context.preview, onExit: code => { exitedWith = code; }, fitToElement: false}); + const mounted = async () => runtime.mount({bridge: terminalBridge, config, terminal: host, preview: context.preview, onExit: code => { exitedWith = code; }, fitToElement: false}); const {terminal, editor} = await mounted(); terminal.resize(80, 12); const buffer = () => terminal.buffer.active; @@ -1263,6 +1271,26 @@ try { const lastRows = count => rows().slice(cursorRow() - count + 1, cursorRow() + 1); await type('echo hello\r'); assert(JSON.stringify(lastRows(3)) === JSON.stringify(['> echo hello', 'hello', '> ']), `A C++ command must run from the terminal: ${lastRows(3)}`); + // Initial dev errors must finish the session command, without requiring Ctrl+C (#560). + for (const [manifest, message] of [[null, 'No webfront.project.json: run wf init'], + [{format: 1, name: 'empty', version: '0.1.0'}, 'Usage: wf dev ']]) { + startupFiles = new Map(manifest ? [['webfront.project.json', new TextEncoder().encode(JSON.stringify(manifest))]] : []); + try { + terminal.input('wf dev\r'); + await delay(10); + for (let attempt = 0; attempt < 200 && editor.busy; ++attempt) await delay(10); + assert(!editor.busy, 'An invalid wf dev invocation must finish without Ctrl+C'); + await editor.whenIdle(); + await rendered(); + assert(editor.status === 1 && rows().some(row => row.includes(message)) && lastRows(1)[0] === '> ', + `wf dev must report its error and restore the prompt: ${lastRows(4)}`); + await type('echo recovered\r'); + assert(editor.status === 0 && lastRows(2)[0] === 'recovered', 'The next command must run after the startup error'); + } finally { + startupFiles = undefined; + if (editor.busy) await type('\x03'); + } + } // Cell widths: CJK, emoji, a flag, a ZWJ sequence and a combining mark. await type('ę¼¢å­—šŸ˜€šŸ‡«šŸ‡·šŸ‘Øā€šŸ‘©ā€šŸ‘§éx'); assert(buffer().cursorX === 2 + 2 + 2 + 2 + 2 + 2 + 1 + 1, `Wide characters must take two cells: ${buffer().cursorX}`); From cd2196a0bbc25562100dc86aa7540e4fd39f8586 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Thu, 12 Nov 2026 20:20:53 +0100 Subject: [PATCH 2/3] Limit wf dev startup exits to a missing project or entry (#560) Only a missing project or an unselectable entry ends the command at startup. Malformed or unreadable manifests and locks, and compiler start failures, stay recoverable and are reported through diagnosticsText with a failed status. --- docs/DEVELOPER_ENVIRONMENT.md | 6 +++--- js/developer/environment/development.mjs | 13 ++++++++----- test/developer/specs/development-specs.mjs | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index 8c2d796b..0a249ad4 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -495,9 +495,9 @@ files; the developer HTTP provider serves only the environment and preview direc `wf dev [entry.tsx|name]` selects `entries.main` or the sole entry when omitted, builds, opens the preview and keeps running until Ctrl+C. It reuses one compiler Worker and esbuild context across rebuilds. -An initial configuration error, such as a missing project or an omitted entry that cannot be selected, -ends the command with exit code 1 and restores the terminal prompt. Once compilation starts, errors -keep the watcher running so that editing the inputs can recover, including after a failed first build. +At startup only a missing project or an omitted entry that cannot be selected ends the command with exit +code 1 and restores the terminal prompt. Any other error (an unreadable or malformed manifest or lock, a +compilation error, including a failed first build) keeps the watcher running so that editing the inputs can recover. Changing the selected entry or locked graph recreates the context. It uses the installed lock, without resolving packages or downloading dependencies; `wf install`/`wf restore` remain explicit actions. diff --git a/js/developer/environment/development.mjs b/js/developer/environment/development.mjs index 98dce333..a01cf49f 100644 --- a/js/developer/environment/development.mjs +++ b/js/developer/environment/development.mjs @@ -220,8 +220,11 @@ export async function dev(args, {bridge, signal, preview: frame, write = () => { catch (error) { if (configReads.get(path) !== 'missing') throw error; } } const project = await loadProject(bridge); - if (!project.manifest && args[0] === undefined) throw new Error(noManifest); - const entry = resolveEntry(project.manifest, args[0], 'wf dev '); + let entry; + try { + if (!project.manifest && args[0] === undefined) throw new Error(noManifest); + entry = resolveEntry(project.manifest, args[0], 'wf dev '); + } catch (error) { error.invalidStart = true; throw error; } if (!session || session.closed) session = compilerSession(bridge, active); const files = await session.rebuild({entry, lock: project.lock ?? {format: 1, roots: {}, packages: {}}}); files.set('index.html', previewPage(files)); @@ -238,9 +241,9 @@ export async function dev(args, {bridge, signal, preview: frame, write = () => { } catch (error) { if (active.aborted) throw stopped(); if (error?.code === 'busy') { await waitForPoll(active); continue; } - // Watching starts with the compiler. Invalid initial configuration must finish the command; - // compilation errors (including the first build) and later configuration edits remain recoverable. - if (!session) throw error; + // A missing project or an omitted entry at startup finishes the command; every other failure + // (unreadable or malformed files, compilation errors, later edits) stays recoverable. + if (!session && error?.invalidStart) throw error; diagnostic = diagnosticsText(error); report('failed'); write(diagnostic + '\n'); diff --git a/test/developer/specs/development-specs.mjs b/test/developer/specs/development-specs.mjs index 0e2ad3a2..a9633984 100644 --- a/test/developer/specs/development-specs.mjs +++ b/test/developer/specs/development-specs.mjs @@ -33,6 +33,26 @@ describe('wf dev', () => { } finally { clearTimeout(timer); controller.abort(); } }); + it('keeps watching when the manifest is malformed at startup', async () => { + const {bridge} = memoryBridge(new Map([['webfront.project.json', encode('{not json')]])); + const controller = new AbortController(); + const states = [], output = []; + const frame = new EventTarget(); + frame.addEventListener('webfront-dev-status', event => { + states.push(event.detail.state); + if (event.detail.state === 'failed') controller.abort(); + }); + const worker = spyOn(globalThis, 'Worker').and.throwError('The compiler must not start'); + const timer = setTimeout(() => controller.abort(), 5000); + try { + await dev([], {bridge, signal: controller.signal, preview: frame, write: text => output.push(text)}).then( + () => fail('dev must not resolve'), () => {}); + expect(states).toContain('failed'); + expect(output.join('')).not.toBe(''); + expect(worker).not.toHaveBeenCalled(); + } finally { clearTimeout(timer); controller.abort(); } + }); + it('one esbuild context reads changed imports, reports syntax errors and recovers', async () => { const files = new Map([['main.ts', encode("import {value} from './value'; console.log(value)")], ['value.ts', encode('export const value = 1')]]); const context = await bundleContext(await esbuild(), {entry: 'main.ts', lock, readProject: async path => { From 8281a3ed0f91e9c25c247ff4020b7fb326bf7689 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Thu, 12 Nov 2026 22:24:03 +0100 Subject: [PATCH 3/3] Prepare developer 0.9.2 and refresh source checksums (#560) --- docs/CHANGELOG.md | 2 +- js/developer/environment/bundles.json | 4 ++-- js/developer/tools/distribution.json | 2 +- test/web/developer-specs.mjs | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 965a5f3a..5006370b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -25,7 +25,7 @@ these entries stays in the GitHub releases and the Git history. ### Fixed -- Restore the terminal prompt with exit code 1 when `wf dev` starts without a project or a selectable entry; compilation errors still keep watching for edits (#560). +- Restore the terminal prompt with exit code 1 when `wf dev` starts without a project or a selectable entry; compilation errors still keep watching for edits. Environment sources 0.9.2, not published yet (#560). - Read all six developer integration reports in CTest after a part fails, and keep the successful parts' dependent tests runnable, also when the session's native deadline ends it (#556). - On Windows, `wf install`, `wf build` and `wf test` no longer fail with `rename: Access is denied` while another process, such as an antivirus scan, still reads the files just written: the developer store tries the rename again for up to 635 ms; `wf test` also empties the directory of an interrupted run (#542). - Run the commit attribution regression checks with older Git versions by dropping the unsupported `git log --no-graph` option (#525). diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 1e01d3d6..e2ffd529 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -19,7 +19,7 @@ "js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3", "js/developer/environment/runtime.mjs": "2c9ef449c44ddbdcc327ffb126e61c3e8e8076edbe73a0dce99e3dc9bb42b5a9", "js/developer/environment/automation.mjs": "79405c89ba7025c1774bc13c9b78d814a07592755dcde018c8659a8015c4b8ed", - "js/developer/environment/development.mjs": "bbc07483d1282b4f765bf3d597653ee182a2a11ea264c2d3ae383f1cf8850dd3", + "js/developer/environment/development.mjs": "1f32f911610c72ad3e935de1c2b138fa275ce9eda04bb63c824d5e09923305a6", "js/developer/environment/testing.mjs": "aeb584505fab5957b9c02e78536e12f7d7f3d12f8adb2e17f1a1a6e395e43f3c", "js/developer/environment/terminal.mjs": "7ffcf7ac6ef63c35cdf5ef70284b384525b13ba18422af069289e53b6c4f6be1", "js/developer/environment/workspace.mjs": "4fe794b140515579c4f80a226d8b1beca254a3488e2e4d9f6ba580e077a11558", @@ -40,7 +40,7 @@ "js/developer/environment/embed.mjs": "3d3b5036c34c23a1fa0512c1eea42f26d5f30e054545b61fe83a5c378b74e09e", "examples/life/ui/main.tsx": "7b1ff285d2a6b8f897ef12df872886e61ef4b24e2358a9423b76b38ab75c85d3", "examples/life/ui/style.css": "9bb55eb0f0a3287e5b7dc78af9d69608b87ff42c4d9c8a653bc83a52fe293c44", - "js/developer/tools/distribution.json": "0de03c0bd22fdcfe87c686d6c1456d26eeb57b09b03d0d680bb81557906f31a0", + "js/developer/tools/distribution.json": "1f2934587eeed1c88630e1693f7ddc91c65315d08a151b6427a3edac36368690", "js/developer/tools/archive.mjs": "da63bb9d796ddfd24ed945b15c53f66a0400eb177886fd4f1c8fd10cafb5a91b", "js/developer/tools/distribution.mjs": "43dfdccc912693db46fd095fd78ae79325abab672d99f89fd569914ef3499cad", "js/developer/scripts/build.mjs": "def3c0ccecbc776b76e20571d015f9a1f23a267c0bd6c0c7a07a81ce9293a663", diff --git a/js/developer/tools/distribution.json b/js/developer/tools/distribution.json index 9d3e51b7..eaaba418 100644 --- a/js/developer/tools/distribution.json +++ b/js/developer/tools/distribution.json @@ -1,4 +1,4 @@ { - "version": "0.9.1", + "version": "0.9.2", "baseUrl": "https://dist.webfront.fr/" } diff --git a/test/web/developer-specs.mjs b/test/web/developer-specs.mjs index d25c1fa6..8bdd7bb5 100644 --- a/test/web/developer-specs.mjs +++ b/test/web/developer-specs.mjs @@ -161,8 +161,10 @@ try { const scriptOutput = []; const runContext = (signal = new AbortController().signal) => ({...context, signal, write: text => { scriptOutput.push(text); console.log(text); }}); const printed = async text => { - for (let attempt = 0; !scriptOutput.some(line => line.includes(text)); ++attempt) { - if (attempt === 200) throw new Error(`The script did not print ${text}`); + // Starting a real Worker and compiling WASM can take more than five seconds while the other panes build. + const deadline = performance.now() + 30000; + while (!scriptOutput.some(line => line.includes(text))) { + if (performance.now() >= deadline) throw new Error(`The script did not print ${text} within 30 seconds`); await delay(25); } };