From 788b3375968a1868c17d2bad1fb78a5f80e423a0 Mon Sep 17 00:00:00 2001 From: Exelo Date: Mon, 23 Nov 2026 02:34:07 +0100 Subject: [PATCH 1/5] fix(editor): focus and describe the error view of the loading screen The trust prompt of /load and the error views of /load and /project/[id] replaced the live progress block without moving focus, so focus fell to the page body and nothing was read out. The title now takes focus each time an error is shown, with the hint as its description. Closes #261 --- apps/editor/e2e/load-page.spec.ts | 23 +++++++++++++++++++++++ apps/editor/src/lib/editor/Loading.svelte | 20 ++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 apps/editor/e2e/load-page.spec.ts diff --git a/apps/editor/e2e/load-page.spec.ts b/apps/editor/e2e/load-page.spec.ts new file mode 100644 index 00000000..40bbc03d --- /dev/null +++ b/apps/editor/e2e/load-page.spec.ts @@ -0,0 +1,23 @@ +import { expect, test } from './test'; + +test('the trust prompt takes focus and reads its warning', async ({ page }) => { + /** A relative path always asks. */ + await page.goto('/load?path=pong'); + const title = page.getByRole('heading', { name: 'Open pong?', level: 1 }); + await expect(title).toBeFocused(); + await expect(title).toHaveAccessibleDescription(/lets the editor run its code/); +}); + +test('an error that replaces the loading view takes focus', async ({ page }) => { + await page.goto('/load?path=missing-folder'); + await page.getByRole('button', { name: 'Open in restricted mode', exact: true }).click(); + const title = page.getByRole('heading', { name: 'No project folder at missing-folder' }); + await expect(title).toBeFocused(); + await expect(title).toHaveAccessibleDescription(/Check the path/); +}); + +test('the error of a project page takes focus', async ({ page }) => { + await page.goto('/project/not-a-project'); + /** Its wording is the project page's: only the heading is checked. */ + await expect(page.getByRole('heading', { level: 1 })).toBeFocused(); +}); diff --git a/apps/editor/src/lib/editor/Loading.svelte b/apps/editor/src/lib/editor/Loading.svelte index ad67c575..432ee089 100644 --- a/apps/editor/src/lib/editor/Loading.svelte +++ b/apps/editor/src/lib/editor/Loading.svelte @@ -12,6 +12,15 @@ const { step = '', description, progress = 0, error }: Props = $props(); let running = $state(); + /** + * Moves focus to the error's title each time an error replaces what was shown, so it is read + * out (its hint as the description) rather than focus falling to the page body. + */ + const focusOn = (shown: ErrorDescription) => (title: HTMLElement) => { + void shown; + title.focus(); + }; + const run = async (label: string, action: () => void | Promise) => { running = label; try { @@ -25,8 +34,15 @@

NanoForge

{#if error} -

{error.title}

- {#if error.hint}

{error.hint}

{/if} +

+ {error.title} +

+ {#if error.hint}

{error.hint}

{/if} {#if error.actions.length}
{#each error.actions as action (action.label)} From 5de0b8c04261539c6a4825cbb29f8b016e6e75ba Mon Sep 17 00:00:00 2001 From: Exelo Date: Mon, 23 Nov 2026 02:34:13 +0100 Subject: [PATCH 2/5] fix(editor): keep the new project dialog open when creating fails The dialog closed before the request while its trigger was disabled, so focus fell to the page body and a failure showed behind the page. It now stays open until the project is made, with the progress and the error inside it and the entries kept. Closes #316 --- apps/editor/e2e/load-page.spec.ts | 18 +++++++++++++++ apps/editor/src/routes/(editor)/+page.svelte | 23 +++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/apps/editor/e2e/load-page.spec.ts b/apps/editor/e2e/load-page.spec.ts index 40bbc03d..df5fcf22 100644 --- a/apps/editor/e2e/load-page.spec.ts +++ b/apps/editor/e2e/load-page.spec.ts @@ -21,3 +21,21 @@ test('the error of a project page takes focus', async ({ page }) => { /** Its wording is the project page's: only the heading is checked. */ await expect(page.getByRole('heading', { level: 1 })).toBeFocused(); }); + +test('a failed new project keeps its dialog and the focus', async ({ page }) => { + await page.goto('/'); + /** Slow enough for the old dialog to close while the request runs. */ + await page.route('**/rpc/projects.create', async (route) => { + await new Promise((resolve) => setTimeout(resolve, 500)); + await route.continue(); + }); + await page.getByRole('button', { name: 'New project', exact: true }).click(); + const dialog = page.getByRole('dialog', { name: 'New project' }); + /** The e2e workspace has a pong folder: nf new refuses it. */ + await dialog.getByPlaceholder('my-game').fill('pong'); + const submit = dialog.getByRole('button', { name: 'Create project' }); + await submit.click(); + await expect(dialog.getByRole('alert')).toContainText('A folder named pong already exists'); + await expect(dialog.getByPlaceholder('my-game')).toHaveValue('pong'); + await expect(submit).toBeFocused(); +}); diff --git a/apps/editor/src/routes/(editor)/+page.svelte b/apps/editor/src/routes/(editor)/+page.svelte index b7a7764d..f212f31c 100644 --- a/apps/editor/src/routes/(editor)/+page.svelte +++ b/apps/editor/src/routes/(editor)/+page.svelte @@ -93,10 +93,11 @@ error = reason instanceof Error ? reason.message : String(reason); } }; + /** The dialog stays open until the project is made: a failure shows in it, entries kept. */ const create = () => run('Creating project (nf new)', async () => { - creating = false; const { id } = await projectsApi.create(draft); + creating = false; return id; }); @@ -148,16 +149,24 @@ /> - { + error = undefined; + creating = true; + }}>New project {/if} - {#if busy}

{busy}…

{/if} - {#if error}{/if} + {#if !creating} + {#if busy}

{busy}…

{/if} + {#if error}{/if} + {/if} {#if gateways.length}
@@ -221,7 +230,7 @@ class="create" onsubmit={(event) => { event.preventDefault(); - if (draft.name && !nameError) void create(); + if (draft.name && !nameError && !busy) void create(); }} >
+ {#if busy}

{busy}…

{/if} + {#if error}{/if}
{/if} - {#if error.detail}{/if} + {#if error.detail}

{error.detail}

{/if} {:else}
!busy} + onclose={() => (error = undefined)} title="New project" description="Creates a NanoForge game workspace with nf new." > @@ -277,7 +279,13 @@ {#if busy}

{busy}…

{/if} {#if error}{/if}
- + From 36ef7bd19a6eee64e07cb7ca17ccd93885afaaa6 Mon Sep 17 00:00:00 2001 From: Exelo Date: Mon, 23 Nov 2026 11:39:31 +0100 Subject: [PATCH 4/5] fix(editor): say a missing folder of a link is missing before the trust prompt /load?path= now checks the folder with a new projects.locate RPC before asking to trust it. locate runs the same hosted, root folder and stat checks as open, through the same code, and opens nothing: a missing folder or one outside the root folder gets its error at once. Closes #318 --- AGENTS.md | 2 +- apps/editor/e2e/load-page.spec.ts | 13 +++- apps/editor/e2e/workbench.spec.ts | 3 +- .../src/routes/(editor)/load/+page.svelte | 63 +++++++++++-------- .../project/src/service/project-service.ts | 5 ++ .../protocol/src/project/project.contract.ts | 5 ++ .../src/project/project-registry.ts | 19 +++++- .../implementation/projects.implementation.ts | 4 ++ .../server-core/test/project/trust.spec.ts | 36 ++++++++++- 9 files changed, 114 insertions(+), 36 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 48bc212f..657b3278 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -80,7 +80,7 @@ pnpm e2e:last-failure # error-context.md of the last failed test, its last fra - E2E specs import `test` and `expect` from `./test` (`e2e/test.ts`), not from `@playwright/test`: its fixture fails a test when a page throws an uncaught error (known noise goes in its `IGNORED` list), and another stops the game a test leaves playing. - **Never sleep to wait for a save:** `await saved(page)` (`e2e/helpers.ts`) waits for `data-nf-saved` on the page, set while no layout, panel state, settings write or account push is pending (`SettingsService.pending`; a debounce holds a pending save with `settings.hold()`). - `/kit` (dev server only, 404 in a build) shows every kit component in both themes, and the floating layers' order over a dialog. -- E2E specs open projects with `openProject(page, path)` (`e2e/helpers.ts`): `/load?path=` asks before opening a folder that is not an exact recent path (a relative path always asks), and the helper answers **Trust and open**. Server and runtime unit tests open projects with `openTrustedProject` (`@nanoforge-dev/editor-server-core/testing`): a fresh data folder trusts nothing. +- E2E specs open projects with `openProject(page, path)` (`e2e/helpers.ts`): `/load?path=` asks before opening a folder that is not an exact recent path (a relative path always asks), and the helper answers **Trust and open**. A folder that can't be opened (missing, outside the root folder) gets its error without the prompt (`projects.locate`): go to `/load?path=` directly for it, not through `openProject`. Server and runtime unit tests open projects with `openTrustedProject` (`@nanoforge-dev/editor-server-core/testing`): a fresh data folder trusts nothing. - The editor server answers only to loopback host names and `ALLOWED_HOSTS` (DNS rebinding guard): a dev server reached by another name needs it. - `EDITOR_TOKEN` (off by default; `random` makes one per start): a local editor then answers only to a browser that opened the link it prints (`?token=`, which sets an HttpOnly cookie). Dev server and e2e run without it. - The editor's page has a Content Security Policy (`packages/server-core/src/http/shell-csp.ts`; inline scripts by hash, read from `index.html`). A local editor allows `'unsafe-eval'` (the engine's ECS is Emscripten WebAssembly, whose bindings compile strings); a hosted one does not. The e2e fixture fails a test on any CSP violation: a new kind of resource (another origin, a worker type) needs the policy changed with it. diff --git a/apps/editor/e2e/load-page.spec.ts b/apps/editor/e2e/load-page.spec.ts index a4d757ab..5a73600d 100644 --- a/apps/editor/e2e/load-page.spec.ts +++ b/apps/editor/e2e/load-page.spec.ts @@ -8,14 +8,23 @@ test('the trust prompt takes focus and reads its warning', async ({ page }) => { await expect(title).toHaveAccessibleDescription(/lets the editor run its code/); }); -test('an error that replaces the loading view takes focus', async ({ page }) => { - await page.goto('/load?path=missing-folder'); +test('an error that replaces the trust prompt takes focus', async ({ page }) => { + await page.route('**/rpc/projects.open', (route) => route.abort()); + await page.goto('/load?path=pong'); await page.getByRole('button', { name: 'Open in restricted mode', exact: true }).click(); + const title = page.getByRole('heading', { name: 'pong could not be opened' }); + await expect(title).toBeFocused(); + await expect(title).toHaveAccessibleDescription(/Try again/); +}); + +test('a missing folder says so without asking to trust it', async ({ page }) => { + await page.goto('/load?path=missing-folder'); const title = page.getByRole('heading', { name: 'No project folder at missing-folder' }); await expect(title).toBeFocused(); await expect(title).toHaveAccessibleDescription( /Check the path.*No project directory at missing-folder/, ); + await expect(page.getByRole('button', { name: 'Trust and open' })).toHaveCount(0); }); test('the error of a project page takes focus', async ({ page }) => { diff --git a/apps/editor/e2e/workbench.spec.ts b/apps/editor/e2e/workbench.spec.ts index 1af2cd0c..4ee98f64 100644 --- a/apps/editor/e2e/workbench.spec.ts +++ b/apps/editor/e2e/workbench.spec.ts @@ -177,7 +177,8 @@ test('opens a project from a link (nf editor )', async ({ page }) => { await page.waitForURL(/\/project\//); await expect(page.getByRole('tab', { name: 'Files' })).toBeVisible(); - await openProject(page, 'missing-folder'); + /** A missing folder gets no trust prompt. */ + await page.goto('/load?path=missing-folder'); await expect(page.getByText('No project folder at missing-folder')).toBeVisible(); await page.getByRole('button', { name: 'Back to projects' }).click(); await expect(page.getByLabel('Project folder')).toBeVisible(); diff --git a/apps/editor/src/routes/(editor)/load/+page.svelte b/apps/editor/src/routes/(editor)/load/+page.svelte index 55811333..c096f999 100644 --- a/apps/editor/src/routes/(editor)/load/+page.svelte +++ b/apps/editor/src/routes/(editor)/load/+page.svelte @@ -18,7 +18,8 @@ * * Opening a trusted local folder runs its code (`nanoforge.config.ts`, plugins, builds), and * any web page can link here: a folder that is not in the recent projects asks first, to trust - * it or to open it in restricted mode (its code off). A hosted editor opens projects by their id + * it or to open it in restricted mode (its code off). A folder that can't be opened (missing, + * outside the root folder) says so without asking. A hosted editor opens projects by their id * only, never by path. */ const editor = getEditor(); @@ -134,32 +135,40 @@ actions: [{ ...back, primary: true }], }; } else { - void known(ref.path).then((trusted) => { - if (disposed) return; - if (trusted) return void open(); - error = { - title: `Open ${ref.path}?`, - hint: 'Trusting a folder lets the editor run its code on this computer: its nanoforge.config.ts, its plugins, its builds and games. Trust it only if you trust where it comes from; otherwise open it in restricted mode, with its code off.', - actions: [ - { - label: 'Trust and open', - primary: true, - run: () => { - error = undefined; - void open(true); - }, - }, - { - label: 'Open in restricted mode', - run: () => { - error = undefined; - void open(); - }, - }, - back, - ], - }; - }); + void editor.projects + .locate(ref.path) + .then(() => known(ref.path)) + .then( + (trusted) => { + if (disposed) return; + if (trusted) return void open(); + error = { + title: `Open ${ref.path}?`, + hint: 'Trusting a folder lets the editor run its code on this computer: its nanoforge.config.ts, its plugins, its builds and games. Trust it only if you trust where it comes from; otherwise open it in restricted mode, with its code off.', + actions: [ + { + label: 'Trust and open', + primary: true, + run: () => { + error = undefined; + void open(true); + }, + }, + { + label: 'Open in restricted mode', + run: () => { + error = undefined; + void open(); + }, + }, + back, + ], + }; + }, + (reason: unknown) => { + if (!disposed) error = describe(reason, ref); + }, + ); } return () => { disposed = true; diff --git a/packages/project/src/service/project-service.ts b/packages/project/src/service/project-service.ts index c675599f..897fe7c7 100644 --- a/packages/project/src/service/project-service.ts +++ b/packages/project/src/service/project-service.ts @@ -64,6 +64,11 @@ export class ProjectService implements Disposable { if (this._current.get() === current) this.close(); } + /** Throws, as `open` would, when a local folder can't be opened: nothing opens, no code runs. */ + async locate(path: string): Promise { + await this._rpc.api(ProjectsContract).locate({ path }); + } + recent(): Promise { return this._rpc.api(ProjectsContract).recent(null); } diff --git a/packages/protocol/src/project/project.contract.ts b/packages/protocol/src/project/project.contract.ts index 0181952d..53d90516 100644 --- a/packages/protocol/src/project/project.contract.ts +++ b/packages/protocol/src/project/project.contract.ts @@ -13,6 +13,11 @@ export const ProjectsContract = defineContract('projects', { input: ProjectRef, output: OpenedProject, }, + /** + * Local editors: checks that a folder could be opened, without opening it or running its + * code. Throws as `open` does: FORBIDDEN (hosted editor, outside the root folder), NOT_FOUND. + */ + locate: { input: z.object({ path: z.string() }), output: z.null() }, recent: { input: z.null(), output: z.array(RecentProject) }, forget: { input: z.object({ id: ProjectId }), output: z.null() }, /** diff --git a/packages/server-core/src/project/project-registry.ts b/packages/server-core/src/project/project-registry.ts index 7674d099..a09a92fe 100644 --- a/packages/server-core/src/project/project-registry.ts +++ b/packages/server-core/src/project/project-registry.ts @@ -238,7 +238,22 @@ export class ProjectRegistry implements Disposable { this._onDidClose.dispose(); } + /** + * Checks that a local folder could be opened, without opening it or running its code: throws as + * `open` does (FORBIDDEN on a hosted editor or outside the root folder, NOT_FOUND). + */ + async locate(path: string): Promise { + await this._localFolder(path); + } + private async _openLocal(path: string): Promise { + const real = await this._localFolder(path); + const trusted = await this.trust.isTrusted(real); + return this._getOrCreate(shortHash(real), real, { path: real }, real, trusted); + } + + /** The real path of a local project's folder, inside the root folder. */ + private async _localFolder(path: string): Promise { if (this._env.mode === 'ONLINE') { throw new RpcError('FORBIDDEN', 'Local projects cannot be opened on a hosted editor'); } @@ -249,9 +264,7 @@ export class ProjectRegistry implements Disposable { } const info = await stat(target).catch(() => undefined); if (!info?.isDirectory()) throw new RpcError('NOT_FOUND', `No project directory at ${path}`); - const real = await realpath(target); - const trusted = await this.trust.isTrusted(real); - return this._getOrCreate(shortHash(real), real, { path: real }, real, trusted); + return realpath(target); } private async _openGateway(session: Session, gatewayId: string): Promise { diff --git a/packages/server-core/src/rpc/implementation/projects.implementation.ts b/packages/server-core/src/rpc/implementation/projects.implementation.ts index 9e8596a0..7274a94b 100644 --- a/packages/server-core/src/rpc/implementation/projects.implementation.ts +++ b/packages/server-core/src/rpc/implementation/projects.implementation.ts @@ -117,6 +117,10 @@ export const implementProjectsRpc = ( const project = await projects.open(session, ref); return { id: project.id, name: project.name, trusted: project.trusted }; }, + locate: async ({ path }) => { + await projects.locate(path); + return null; + }, isTrusted: ({ id }, { session }) => projects.get(session, id).trusted, trust: async ({ id }, { session }) => { await projects.trustProject(projects.get(session, id)); diff --git a/packages/server-core/test/project/trust.spec.ts b/packages/server-core/test/project/trust.spec.ts index f5615d33..71300c57 100644 --- a/packages/server-core/test/project/trust.spec.ts +++ b/packages/server-core/test/project/trust.spec.ts @@ -42,9 +42,9 @@ afterEach(() => { rmSync(workspace, { recursive: true, force: true }); }); -const start = () => { +const start = (extra: Record = {}) => { const editor = createEditorServer({ - env: loadEnv({ NODE_ENV: 'test', FS_ROOT: workspace, DATA_DIR: dataDir }, workspace), + env: loadEnv({ NODE_ENV: 'test', FS_ROOT: workspace, DATA_DIR: dataDir, ...extra }, workspace), version: '1.0.0', }); servers.push(editor); @@ -78,6 +78,38 @@ describe('folder trust', () => { expect((await again.api(ProjectsContract).open({ path: 'pong' })).trusted).toBe(true); }); + it('locates a folder without opening it or running its code', async () => { + const projects = start().api(ProjectsContract); + /** Trusted: opening it would run its config. */ + await projects.trust({ id: (await projects.open({ path: 'pong' })).id }); + expect(existsSync(marker)).toBe(false); + + await expect(projects.locate({ path: 'pong' })).resolves.toBeNull(); + expect(existsSync(marker)).toBe(false); + await expect(projects.locate({ path: 'missing-folder' })).rejects.toMatchObject({ + code: 'NOT_FOUND', + }); + await expect(projects.locate({ path: 'pong/nanoforge.config.ts' })).rejects.toMatchObject({ + code: 'NOT_FOUND', + }); + await expect(projects.locate({ path: '../outside' })).rejects.toMatchObject({ + code: 'FORBIDDEN', + }); + + /** A hosted editor opens projects by id: an existing and a missing folder get one refusal. */ + const hosted = start({ PUBLIC_MODE: 'ONLINE', API_KEY: 'key', SESSION_SECRET: 'x'.repeat(32) }); + const refusal = (path: string) => + hosted + .api(ProjectsContract) + .locate({ path }) + .then( + () => 'located', + (error: { code: string; message: string }) => `${error.code}: ${error.message}`, + ); + expect(await refusal('pong')).toBe(await refusal('missing-folder')); + expect(await refusal('pong')).not.toBe('located'); + }); + it('trusts the folders opened before trust existed', async () => { mkdirSync(dataDir, { recursive: true }); const path = await realpath(join(workspace, 'pong')); From f80f2f6d2154c55ca52514c39f5650c52b9fdc3a Mon Sep 17 00:00:00 2001 From: Exelo Date: Mon, 23 Nov 2026 18:45:10 +0100 Subject: [PATCH 5/5] fix(editor): locate a linked folder and read the recent projects together The load page runs projects.locate and the recent projects check at once. A registry test pins that a hosted editor refuses locate before it looks at the folder: one refusal for an existing, a missing and an outside folder. --- .../src/routes/(editor)/load/+page.svelte | 61 ++++++++--------- .../test/project/project-registry.spec.ts | 66 +++++++++++++++++++ 2 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 packages/server-core/test/project/project-registry.spec.ts diff --git a/apps/editor/src/routes/(editor)/load/+page.svelte b/apps/editor/src/routes/(editor)/load/+page.svelte index c096f999..5e500bfd 100644 --- a/apps/editor/src/routes/(editor)/load/+page.svelte +++ b/apps/editor/src/routes/(editor)/load/+page.svelte @@ -135,40 +135,37 @@ actions: [{ ...back, primary: true }], }; } else { - void editor.projects - .locate(ref.path) - .then(() => known(ref.path)) - .then( - (trusted) => { - if (disposed) return; - if (trusted) return void open(); - error = { - title: `Open ${ref.path}?`, - hint: 'Trusting a folder lets the editor run its code on this computer: its nanoforge.config.ts, its plugins, its builds and games. Trust it only if you trust where it comes from; otherwise open it in restricted mode, with its code off.', - actions: [ - { - label: 'Trust and open', - primary: true, - run: () => { - error = undefined; - void open(true); - }, + void Promise.all([editor.projects.locate(ref.path), known(ref.path)]).then( + ([, trusted]) => { + if (disposed) return; + if (trusted) return void open(); + error = { + title: `Open ${ref.path}?`, + hint: 'Trusting a folder lets the editor run its code on this computer: its nanoforge.config.ts, its plugins, its builds and games. Trust it only if you trust where it comes from; otherwise open it in restricted mode, with its code off.', + actions: [ + { + label: 'Trust and open', + primary: true, + run: () => { + error = undefined; + void open(true); }, - { - label: 'Open in restricted mode', - run: () => { - error = undefined; - void open(); - }, + }, + { + label: 'Open in restricted mode', + run: () => { + error = undefined; + void open(); }, - back, - ], - }; - }, - (reason: unknown) => { - if (!disposed) error = describe(reason, ref); - }, - ); + }, + back, + ], + }; + }, + (reason: unknown) => { + if (!disposed) error = describe(reason, ref); + }, + ); } return () => { disposed = true; diff --git a/packages/server-core/test/project/project-registry.spec.ts b/packages/server-core/test/project/project-registry.spec.ts new file mode 100644 index 00000000..7b62ef88 --- /dev/null +++ b/packages/server-core/test/project/project-registry.spec.ts @@ -0,0 +1,66 @@ +import { cpSync, mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; + +import { LoggerService } from '@nanoforge-dev/editor-kernel'; + +import type { ApiClient } from '../../src/api/api-client'; +import { loadEnv } from '../../src/env/load-env'; +import type { GitService } from '../../src/git/git-service'; +import { ProjectRegistry } from '../../src/project/project-registry'; + +let workspace: string; +let registry: ProjectRegistry; + +beforeEach(() => { + workspace = mkdtempSync(join(import.meta.dirname, '../.tmp-registry-')); + cpSync(join(import.meta.dirname, '../fixtures/pong-network'), join(workspace, 'pong'), { + recursive: true, + }); + const env = loadEnv( + { + NODE_ENV: 'test', + PUBLIC_MODE: 'ONLINE', + API_KEY: 'key', + SESSION_SECRET: 'x'.repeat(32), + FS_ROOT: workspace, + DATA_DIR: join(mkdtempSync(join(tmpdir(), 'nf-data-')), 'editor'), + }, + workspace, + ); + /** Hosted `locate` reaches neither git nor the API. */ + const unused = new Proxy( + {}, + { + get: (_target, key) => () => { + throw new Error(`unexpected call to ${String(key)}`); + }, + }, + ); + registry = new ProjectRegistry( + env, + unused as GitService, + unused as ApiClient, + new LoggerService().getLogger('projects'), + ); +}); + +afterEach(() => { + registry.dispose(); + rmSync(workspace, { recursive: true, force: true }); +}); + +describe('ProjectRegistry.locate', () => { + it('refuses on a hosted editor before looking at the folder', async () => { + const refusal = (path: string) => + registry.locate(path).then( + () => 'located', + (error: { code: string; message: string }) => `${error.code}: ${error.message}`, + ); + /** One answer for an existing, a missing and an outside folder: nothing about them leaks. */ + const answers = await Promise.all(['pong', 'missing-folder', '../outside'].map(refusal)); + expect(answers).toEqual(Array(3).fill(answers[0])); + expect(answers[0]).toMatch(/^FORBIDDEN: /); + }); +});