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: add build timeout, persist buildCommand, add tests
Adam Eivyfa3521619fc4
diff --git a/server/lib/validation.test.js b/server/lib/validation.test.jsindex e51f8590e2..b85d958e42 100644--- a/server/lib/validation.test.js+++ b/server/lib/validation.test.js@@ -124,6 +124,44 @@ describe('validation.js', () => {const result = appSchema.safeParse(app);expect(result.success).toBe(true);});++ it('should accept valid devUiPort', () => {+ const app = { name: 'Test', repoPath: '/path', devUiPort: 5555 };+ const result = appSchema.safeParse(app);+ expect(result.success).toBe(true);+ expect(result.data.devUiPort).toBe(5555);+ });++ it('should allow devUiPort to be null', () => {+ const app = { name: 'Test', repoPath: '/path', devUiPort: null };+ const result = appSchema.safeParse(app);+ expect(result.success).toBe(true);+ });++ it('should reject invalid devUiPort', () => {+ const app = { name: 'Test', repoPath: '/path', devUiPort: 70000 };+ const result = appSchema.safeParse(app);+ expect(result.success).toBe(false);+ });++ it('should accept valid buildCommand', () => {+ const app = { name: 'Test', repoPath: '/path', buildCommand: 'npm run build' };+ const result = appSchema.safeParse(app);+ expect(result.success).toBe(true);+ expect(result.data.buildCommand).toBe('npm run build');+ });++ it('should reject buildCommand over 200 characters', () => {+ const app = { name: 'Test', repoPath: '/path', buildCommand: 'a'.repeat(201) };+ const result = appSchema.safeParse(app);+ expect(result.success).toBe(false);+ });++ it('should reject non-string buildCommand', () => {+ const app = { name: 'Test', repoPath: '/path', buildCommand: 123 };+ const result = appSchema.safeParse(app);+ expect(result.success).toBe(false);+ });});describe('appUpdateSchema', () => {diff --git a/server/routes/apps.js b/server/routes/apps.jsindex e7b437462c..1b31d3c0c0 100644--- a/server/routes/apps.js+++ b/server/routes/apps.js@@ -389,11 +389,20 @@ router.post('/:id/build', loadApp, asyncHandler(async (req, res) => {console.log(`🔨 Building ${app.name}: ${buildCommand}`);+ const BUILD_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutesconst result = await new Promise((resolve) => {const child = spawn(cmd, args, { cwd: app.repoPath, shell: false, windowsHide: true });let stdout = '';let stderr = '';+ let settled = false;const MAX = 64 * 1024;+ const timer = setTimeout(() => {+ if (!settled) {+ settled = true;+ child.kill('SIGTERM');+ resolve({ success: false, stderr: `Build timed out after ${BUILD_TIMEOUT_MS / 1000}s`, code: -1 });+ }+ }, BUILD_TIMEOUT_MS);child.stdout.on('data', d => {stdout += d;if (stdout.length > MAX) stdout = stdout.slice(-MAX);@@ -403,10 +412,18 @@ router.post('/:id/build', loadApp, asyncHandler(async (req, res) => {if (stderr.length > MAX) stderr = stderr.slice(-MAX);});child.on('close', code => {- resolve({ success: code === 0, stdout: stdout.trim(), stderr: stderr.trim(), code });+ if (!settled) {+ settled = true;+ clearTimeout(timer);+ resolve({ success: code === 0, stdout: stdout.trim(), stderr: stderr.trim(), code });+ }});child.on('error', err => {- resolve({ success: false, stderr: err.message, code: -1 });+ if (!settled) {+ settled = true;+ clearTimeout(timer);+ resolve({ success: false, stderr: err.message, code: -1 });+ }});});diff --git a/server/routes/apps.test.js b/server/routes/apps.test.jsindex 2268e5efed..ae005f2735 100644--- a/server/routes/apps.test.js+++ b/server/routes/apps.test.js@@ -292,6 +292,85 @@ describe('Apps Routes', () => {});});+ describe('GET /api/apps - devUiPort enrichment', () => {+ it('should include devUiPort derived from process ports.devUi', async () => {+ const mockApps = [{+ id: 'app-001',+ name: 'Test App',+ pm2ProcessNames: ['test-app'],+ repoPath: '/tmp/test',+ processes: [{ name: 'test-app', ports: { devUi: 5555 } }]+ }];+ appsService.getAllApps.mockResolvedValue(mockApps);+ pm2Service.listProcesses.mockResolvedValue([]);++ const response = await request(app).get('/api/apps');++ expect(response.status).toBe(200);+ expect(response.body[0].devUiPort).toBe(5555);+ });++ it('should use explicit devUiPort over derived value', async () => {+ const mockApps = [{+ id: 'app-001',+ name: 'Test App',+ pm2ProcessNames: ['test-app'],+ repoPath: '/tmp/test',+ devUiPort: 4444,+ processes: [{ name: 'test-app', ports: { devUi: 5555 } }]+ }];+ appsService.getAllApps.mockResolvedValue(mockApps);+ pm2Service.listProcesses.mockResolvedValue([]);++ const response = await request(app).get('/api/apps');++ expect(response.status).toBe(200);+ expect(response.body[0].devUiPort).toBe(4444);+ });+ });++ describe('POST /api/apps/:id/build', () => {+ it('should return 404 if app not found', async () => {+ appsService.getAppById.mockResolvedValue(null);++ const response = await request(app).post('/api/apps/app-999/build');++ expect(response.status).toBe(404);+ });++ it('should reject build commands not starting with npm or npx', async () => {+ const mockApp = {+ id: 'app-001',+ name: 'Test App',+ repoPath: '/tmp',+ buildCommand: 'rm -rf /',+ pm2ProcessNames: ['test-app']+ };+ appsService.getAppById.mockResolvedValue(mockApp);++ const response = await request(app).post('/api/apps/app-001/build');++ expect(response.status).toBe(400);+ expect(response.body.code).toBe('INVALID_BUILD_COMMAND');+ });++ it('should return 400 if repo path does not exist', async () => {+ const mockApp = {+ id: 'app-001',+ name: 'Test App',+ repoPath: '/nonexistent/path/that/does/not/exist',+ buildCommand: 'npm run build',+ pm2ProcessNames: ['test-app']+ };+ appsService.getAppById.mockResolvedValue(mockApp);++ const response = await request(app).post('/api/apps/app-001/build');++ expect(response.status).toBe(400);+ expect(response.body.code).toBe('PATH_NOT_FOUND');+ });+ });+describe('GET /api/apps/:id/status', () => {it('should return PM2 status for app processes', async () => {const mockApp = {diff --git a/server/services/apps.js b/server/services/apps.jsindex 09bb45b046..02810a6bf5 100644--- a/server/services/apps.js+++ b/server/services/apps.js@@ -196,6 +196,7 @@ export async function createApp(appData) {uiPort: appData.uiPort || null,devUiPort: appData.devUiPort || null,apiPort: appData.apiPort || null,+ buildCommand: appData.buildCommand || null,startCommands: appData.startCommands || ['npm run dev'],pm2ProcessNames: appData.pm2ProcessNames || [appData.name.toLowerCase().replace(/\s+/g, '-')],envFile: appData.envFile || '.env',