Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): reject derived-uiPort edits instead of silently reverting
Adam Eivy423b6bd7c2d7
diff --git a/server/routes/apps.js b/server/routes/apps.jsindex fb0802808b..2e50842f1e 100644--- a/server/routes/apps.js+++ b/server/routes/apps.js@@ -508,6 +508,21 @@ router.put('/:id', asyncHandler(async (req, res, next) => {// literal to rewrite, so it isn't treated as a config edit here.const changedKeys = PORT_KEYS.filter(key =>Number.isInteger(currentPort[key]) && Number.isInteger(data[key]) && data[key] !== currentPort[key]);++ // Derived-uiPort guard. When an app has an API process plus a Vite dev UI+ // but no literal `ports.ui`, the prod UI is served by the API and the+ // displayed `uiPort` is *derived* (= apiPort). There's no independent ui+ // literal to rewrite, so a uiPort edit to anything OTHER than that derived+ // value can't persist — the modal echoes the derived value unchanged on a+ // rename (a no-op), but a genuine change must be rejected rather than+ // silently stored in apps.json only to revert on the next config refresh.+ // The user changes this port by editing the API port instead.+ const derivedUiPort = deriveUiPort(currentPort.uiPort, currentPort.apiPort, currentPort.devUiPort);+ const derivedUiChangeRejected =+ currentPort.uiPort === undefined &&+ Number.isInteger(derivedUiPort) &&+ Number.isInteger(data.uiPort) &&+ data.uiPort !== derivedUiPort;const remap = [];const targetedEdits = []; // shared-value keys: rewritten by process + labelfor (const key of changedKeys) {@@ -522,6 +537,17 @@ router.put('/:id', asyncHandler(async (req, res, next) => {remap.push([oldPort, data[key]]);}+ // Reject a derived-uiPort change before touching the config (it has no+ // literal to write — the user must change the API port). Doing this first+ // keeps the rejected request from persisting any OTHER port edit in the+ // same PUT.+ if (derivedUiChangeRejected) {+ throw new ServerError(+ `Cannot change ${existing.name}'s UI port directly — its prod UI is served by the API server, so the UI port follows the API port. Change the API port instead.`,+ { status: 422, code: 'PORT_NOT_PERSISTABLE' }+ );+ }+// Persist the value-keyed remap (distinct ports) and the targeted edits// (shared-value ports) in ONE atomic write. Doing them as two separate// writes would let the value-keyed pass land on disk before a laterdiff --git a/server/routes/apps.test.js b/server/routes/apps.test.jsindex 09565fa0f3..e79ea0bf9b 100644--- a/server/routes/apps.test.js+++ b/server/routes/apps.test.js@@ -356,6 +356,43 @@ describe('Apps Routes', () => {expect(appsService.updateApp).not.toHaveBeenCalled();});+ it('rejects (422) a change to a derived uiPort (prod UI served by the API, no literal ui port)', async () => {+ // App has an API process + Vite dev UI but no literal ports.ui, so the+ // displayed uiPort is derived (= apiPort). Changing it can't persist —+ // the user must change the API port instead → 422, config untouched.+ const mockApp = { id: 'app-001', name: 'App', type: 'node', repoPath: process.cwd(), apiPort: 6000, uiPort: 6000, devUiPort: 5556 };+ appsService.getAppById.mockResolvedValue(mockApp);+ // Parser yields api + devUi only; ui is derived from api (served-by-API).+ streamingDetect.parseEcosystemFromPath.mockResolvedValue({+ processes: [{ name: 'srv', ports: { api: 6000, devUi: 5556 } }]+ });++ const response = await request(app).put('/api/apps/app-001').send({ uiPort: 7000 });++ expect(response.status).toBe(422);+ expect(streamingDetect.writeEcosystemPortEdits).not.toHaveBeenCalled();+ expect(appsService.updateApp).not.toHaveBeenCalled();+ });++ it('does not reject when a rename echoes the derived uiPort unchanged (served-by-API)', async () => {+ // Same served-by-API shape, but the modal echoes the derived uiPort (6000)+ // unchanged on a rename — a no-op that must NOT 422.+ const mockApp = { id: 'app-001', name: 'App', type: 'node', repoPath: process.cwd(), apiPort: 6000, uiPort: 6000, devUiPort: 5556 };+ appsService.getAppById.mockResolvedValue(mockApp);+ streamingDetect.parseEcosystemFromPath.mockResolvedValue({+ processes: [{ name: 'srv', ports: { api: 6000, devUi: 5556 } }]+ });+ appsService.updateApp.mockResolvedValue({ ...mockApp, name: 'Renamed' });++ const response = await request(app)+ .put('/api/apps/app-001')+ .send({ name: 'Renamed', uiPort: 6000 });++ expect(response.status).toBe(200);+ expect(streamingDetect.writeEcosystemPortEdits).not.toHaveBeenCalled();+ expect(appsService.updateApp).toHaveBeenCalled();+ });+it('does not reject a non-port edit on an app whose top-level ports are not stored (derived)', async () => {// apps.json has no apiPort/uiPort (derived from processes); a rename// submits the echoed display values. Those must not read as port changes.