From 36905f8f03ea9871e52a9dce29866b6615fc221e Mon Sep 17 00:00:00 2001 From: Volodymyr Vreshch Date: Sun, 22 Nov 2026 03:21:17 +0100 Subject: [PATCH] fix(apphost): the folder's app entry wins after a rebuild --- packages/apphost/src/host-document.test.ts | 30 +++++++++++++++++++++- packages/apphost/src/host-document.ts | 8 +++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/packages/apphost/src/host-document.test.ts b/packages/apphost/src/host-document.test.ts index 58e7d225..6ead21c7 100644 --- a/packages/apphost/src/host-document.test.ts +++ b/packages/apphost/src/host-document.test.ts @@ -2,7 +2,13 @@ import { createServer, type Server } from 'node:http'; import { type AddressInfo } from 'node:net'; import { afterEach, describe, expect, it } from 'vitest'; import { type Entries } from './entries.js'; -import { DOC_READ_MS, hostDocumentOf, readChildDocument, type LastGood } from './host-document.js'; +import { + DOC_READ_MS, + hostDocumentOf, + readChildDocument, + withAppRow, + type LastGood, +} from './host-document.js'; import { type Lane } from './lane.js'; import { type Entry, type State } from './supervisor.js'; @@ -141,3 +147,25 @@ describe('hostDocumentOf: the host document from the discovery of each child (J. }); const app = { title: 'A', entry: '/app/a/app-0123456789.js', css: '/app/a/app-0123456789.css' }; + +describe('withAppRow: the folder row wins after an app-only rebuild', () => { + const old = { ...app, icon: 'box', order: 2 }; + const fresh = { title: 'A', entry: '/app/a/app-ffffffffff.js', css: '/app/a/app-ffffffffff.css' }; + const running = (row?: typeof old) => + ({ id: 'a', state: 'running', parts: ['api', 'app'], app: row }) as never; + + it('names the new entry and css and keeps the other fields of the child row', () => { + const out = withAppRow(running(old), fresh); + expect(out.app).toEqual({ ...old, entry: fresh.entry, css: fresh.css }); + }); + + it('with no folder row, the child row stands unchanged', () => { + const entry = running(old); + expect(withAppRow(entry, undefined)).toBe(entry); + }); + + it('with no child row, the folder row is the app row and the app part is listed', () => { + const out = withAppRow({ id: 'a', state: 'running', parts: ['api'] } as never, fresh); + expect(out).toMatchObject({ parts: ['api', 'app'], app: fresh }); + }); +}); diff --git a/packages/apphost/src/host-document.ts b/packages/apphost/src/host-document.ts index 6c00f52e..55568bbc 100644 --- a/packages/apphost/src/host-document.ts +++ b/packages/apphost/src/host-document.ts @@ -45,11 +45,11 @@ const answersOf = async (entry: Entry, lastGood: LastGood): Promise => const toldOf = ({ state }: Entry): CallerState | undefined => state === 'starting' || state === 'failed' ? state : undefined; -// On a machine the daemon serves /app/{id}/ from the folder: its row stands when no document names one. -const withAppRow = (entry: HostEntry, row: AppRow | undefined): HostEntry => { - if (entry.app || !row) return entry; +// On a machine the daemon serves /app/{id}/ from the folder: its entry and css win over the child's (an app-only rebuild). +export const withAppRow = (entry: HostEntry, row: AppRow | undefined): HostEntry => { + if (!row) return entry; const parts = SERVES_KINDS.filter((k) => k === 'app' || entry.parts.includes(k)); - return { ...entry, parts, app: row }; + return { ...entry, parts, app: { ...entry.app, ...row } }; }; const statesOf = (all: Entry[]): Record => {