A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(agent): a claim the project makes, added while the project is open
yhh82a95bf71495
diff --git a/desktop/electron/main.ts b/desktop/electron/main.tsindex a809d8fd7..e6d29960d 100644--- a/desktop/electron/main.ts+++ b/desktop/electron/main.ts@@ -907,6 +907,16 @@ async function refreshStanding(): Promise<void> {.catch(() => standingCriteria);}+/**+ * An edit that did not come through the editor's own door — an outside editor,+ * a git checkout, a pull. A watch that cannot name what changed (`paths` empty)+ * is taken as "maybe the manifest": claims that silently did not load look+ * exactly like a project that never had any.+ */+function onProjectFilesChanged(paths: readonly string[]): void {+ if (paths.length === 0 || paths.includes(PROJECT_MANIFEST_FILE)) void refreshStanding();+}+async function adoptRoot(root: string): Promise<string | undefined> {// Held copies name paths under the OLD root; nothing about them is restorable// into this one, and offering a revert that would write into a project the@@ -914,7 +924,7 @@ async function adoptRoot(root: string): Promise<string | undefined> {if (projectRoot !== root) await journal.discardAll();projectRoot = root;await refreshStanding();- if (win) startProjectWatch(root, win.webContents);+ if (win) startProjectWatch(root, win.webContents, onProjectFilesChanged);// The compiler follows the project. Built lazily on the first question, so an// open pays nothing for a service it may never be asked one.adoptProjectScripts(root);diff --git a/desktop/electron/projectWatcher.ts b/desktop/electron/projectWatcher.tsindex bbd64b1e8..01cb1573a 100644--- a/desktop/electron/projectWatcher.ts+++ b/desktop/electron/projectWatcher.ts@@ -49,8 +49,15 @@ export function stopProjectWatch(): void {* Watch `root` and push `project:fsChanged` to `wc` (debounced + coalesced) on* any change outside the ignored set. Replaces any existing watch. Failure to* watch is non-fatal — the editor's own mutations still refresh optimistically.+ *+ * `onChanged` gets the same coalesced set, for the main-process state that is+ * read off project files and would otherwise go stale behind an outside edit.*/-export function startProjectWatch(root: string, wc: WebContents): void {+export function startProjectWatch(+ root: string,+ wc: WebContents,+ onChanged?: (paths: readonly string[]) => void,+): void {stopProjectWatch();try {watcher = watch(root, { recursive: true }, (_event, filename) => {@@ -68,6 +75,7 @@ export function startProjectWatch(root: string, wc: WebContents): void {const paths = [...pending];pending = new Set();timer = null;+ onChanged?.(paths);if (!wc.isDestroyed()) wc.send('project:fsChanged', { paths });}, DEBOUNCE_MS);});diff --git a/desktop/tests/project-watcher.test.ts b/desktop/tests/project-watcher.test.tsnew file mode 100644index 000000000..a2b6b8247--- /dev/null+++ b/desktop/tests/project-watcher.test.ts@@ -0,0 +1,64 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file The watcher's second reader.+ *+ * Main keeps state read off project files — the standing acceptance claims — and+ * an edit that did not come through the editor's own door left it stale. Silently:+ * claims that never loaded look exactly like a project that has none, so a turn+ * they should have failed comes back passed.+ */+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdtemp, writeFile, rm } from 'node:fs/promises';+import { tmpdir } from 'node:os';+import path from 'node:path';+import type { WebContents } from 'electron';+import { startProjectWatch, stopProjectWatch } from '../electron/projectWatcher';++let root = '';++const until = async (done: () => boolean, ms = 4000): Promise<void> => {+ const end = Date.now() + ms;+ while (!done() && Date.now() < end) await new Promise((r) => { setTimeout(r, 25); });+};++beforeEach(async () => {+ root = await mkdtemp(path.join(tmpdir(), 'estella-watch-test-'));+});++afterEach(async () => {+ stopProjectWatch();+ await rm(root, { recursive: true, force: true });+});++describe('what the watcher tells main', () => {+ it('hands it the same change set it pushes to the window', async () => {+ const seen: string[][] = [];+ const sent: { paths: string[] }[] = [];+ const wc = {+ isDestroyed: () => false,+ send: (_channel: string, payload: { paths: string[] }) => { sent.push(payload); },+ } as unknown as WebContents;++ startProjectWatch(root, wc, (paths) => { seen.push([...paths]); });+ await writeFile(path.join(root, 'project.esproject'), '{"name":"P"}', 'utf8');+ await until(() => seen.length > 0 && sent.length > 0);++ expect(seen[0]).toContain('project.esproject');+ expect(sent[0].paths).toEqual(seen[0]);+ });++ it('watches without one', async () => {+ const sent: unknown[] = [];+ const wc = {+ isDestroyed: () => false,+ send: (_channel: string, payload: unknown) => { sent.push(payload); },+ } as unknown as WebContents;++ startProjectWatch(root, wc);+ await writeFile(path.join(root, 'a.esscene'), '{}', 'utf8');+ await until(() => sent.length > 0);++ expect(sent).toHaveLength(1);+ });+});