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 a selected app whose Repository Path is unset at the runs route
[._.]/ Adam Eivye9a3532db8b1
diff --git a/server/lib/aiToolkit/routes/runs.js b/server/lib/aiToolkit/routes/runs.jsindex 2c99caa5cb..01b1d688c7 100644--- a/server/lib/aiToolkit/routes/runs.js+++ b/server/lib/aiToolkit/routes/runs.js@@ -38,6 +38,20 @@ export function createRunsRoutes(runnerService, options = {}) {throw new ServerError('prompt is required', { status: 400 });}+ // A workspace NAME with no PATH means the caller picked an app whose+ // Repository Path is unset — distinct from picking no app at all, which+ // sends neither. Downstream both arrive as an absent `workspacePath` and+ // the run falls back to the host's own directory, so a prompt naming a+ // relative file writes there instead of into the chosen app (#3180). The+ // name is the only signal that a choice was made, and it is already on the+ // wire, so reject here rather than letting the two cases collapse.+ if (workspaceName && !(typeof workspacePath === 'string' && workspacePath.trim())) {+ throw new ServerError(+ `Workspace '${workspaceName}' has no Repository Path — set it for this app, then run again.`,+ { status: 400, code: 'WORKSPACE_PATH_MISSING' }+ );+ }+// `screenshots[]` is untrusted user input that the vision loader// base64-encodes and forwards to the external provider — constrain it to// safe screenshots-dir basenames here so a `../` traversal or absolute pathdiff --git a/server/lib/aiToolkit/routes/runs.test.js b/server/lib/aiToolkit/routes/runs.test.jsindex d76d0caf11..19654ea038 100644--- a/server/lib/aiToolkit/routes/runs.test.js+++ b/server/lib/aiToolkit/routes/runs.test.js@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';import express from 'express';import { request } from '../../testHelper.js';import { createRunsRoutes } from './runs.js';+import { asyncHandler as portosAsyncHandler, errorMiddleware, ServerError } from '../../errorHandler.js';// Route-level harness for POST /api/runs fallback-model execution.//@@ -45,10 +46,13 @@ function runData({ providerType, defaultModel, usedFallback = false, fallbackMod};}+// Sends BOTH workspace fields, as the real client does — a name without a path+// means "app selected but its Repository Path is unset" and is now a 400 (see+// the selected-app-without-a-path suite at the bottom of this file).const post = (app) =>request(app).post('/api/runs')- .send({ providerId: 'p1', model: REQUEST_MODEL, prompt: 'hello', workspaceName: 'ws' });+ .send({ providerId: 'p1', model: REQUEST_MODEL, prompt: 'hello', workspaceName: 'ws', workspacePath: '/srv/repos/ws' });describe('POST /api/runs — fallback-model execution', () => {beforeEach(() => vi.clearAllMocks());@@ -197,3 +201,58 @@ describe('POST /api/runs — fallback-model execution', () => {});});});++describe('POST /api/runs — selected-app-without-a-path guard (#3180)', () => {+ // "No app selected" sends neither field; "app selected whose Repository Path+ // is unset" sends a name but no path. Both reach the runner as an absent+ // workspacePath, so without this guard the second silently ran in the PortOS+ // checkout while the UI showed the app as the chosen workspace.+ // Mounted under PortOS's real error middleware so the 400 body is the canonical+ // envelope — the actionable message naming the app IS the fix, so assert it.+ function makeAppWithEnvelope(rd) {+ const runnerService = { createRun: vi.fn().mockResolvedValue(rd), executeApiRun: vi.fn(), executeCliRun: vi.fn(), executeTuiRun: vi.fn() };+ const app = express();+ app.use(express.json());+ app.use('/api/runs', createRunsRoutes(runnerService, { asyncHandler: portosAsyncHandler, ServerError }));+ app.use(errorMiddleware);+ return { app, runnerService };+ }++ it('rejects a workspaceName with no workspacePath instead of running in the host directory', async () => {+ const { app, runnerService } = makeAppWithEnvelope(runData({ providerType: 'cli', defaultModel: 'm' }));+ const res = await request(app).post('/api/runs').send({+ providerId: 'p1', prompt: 'create HelloWorld.md', workspaceName: 'Primes',+ });+ expect(res.status).toBe(400);+ expect(res.body.error).toMatch(/Primes/);+ expect(res.body.error).toMatch(/Repository Path/);+ expect(res.body.code).toBe('WORKSPACE_PATH_MISSING');+ expect(runnerService.createRun).not.toHaveBeenCalled();+ expect(runnerService.executeCliRun).not.toHaveBeenCalled();+ });++ it('rejects a whitespace-only workspacePath alongside a name', async () => {+ const { app, runnerService } = makeApp(runData({ providerType: 'cli', defaultModel: 'm' }));+ const res = await request(app).post('/api/runs').send({+ providerId: 'p1', prompt: 'go', workspaceName: 'Primes', workspacePath: ' ',+ });+ expect(res.status).toBe(400);+ expect(runnerService.createRun).not.toHaveBeenCalled();+ });++ it('still allows a run with no workspace selected at all', async () => {+ const { app, runnerService } = makeApp(runData({ providerType: 'cli', defaultModel: 'm' }));+ const res = await request(app).post('/api/runs').send({ providerId: 'p1', prompt: 'go' });+ expect(res.status).toBeLessThan(400);+ expect(runnerService.createRun).toHaveBeenCalled();+ });++ it('still allows a run with both a name and a path', async () => {+ const { app, runnerService } = makeApp(runData({ providerType: 'cli', defaultModel: 'm' }));+ const res = await request(app).post('/api/runs').send({+ providerId: 'p1', prompt: 'go', workspaceName: 'Primes', workspacePath: '/srv/repos/primes',+ });+ expect(res.status).toBeLessThan(400);+ expect(runnerService.createRun).toHaveBeenCalled();+ });+});