mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 08:13:37 +00:00
Merge remote-tracking branch 'origin/v0.14.0rc' into feature/v0.14.0rc-1768981415660-tt2v
# Conflicts: # apps/ui/src/components/views/project-settings-view/config/navigation.ts # apps/ui/src/components/views/project-settings-view/hooks/use-project-settings-view.ts
This commit is contained in:
@@ -42,6 +42,9 @@ import { createStartDevHandler } from './routes/start-dev.js';
|
||||
import { createStopDevHandler } from './routes/stop-dev.js';
|
||||
import { createListDevServersHandler } from './routes/list-dev-servers.js';
|
||||
import { createGetDevServerLogsHandler } from './routes/dev-server-logs.js';
|
||||
import { createStartTestsHandler } from './routes/start-tests.js';
|
||||
import { createStopTestsHandler } from './routes/stop-tests.js';
|
||||
import { createGetTestLogsHandler } from './routes/test-logs.js';
|
||||
import {
|
||||
createGetInitScriptHandler,
|
||||
createPutInitScriptHandler,
|
||||
@@ -140,6 +143,15 @@ export function createWorktreeRoutes(
|
||||
createGetDevServerLogsHandler()
|
||||
);
|
||||
|
||||
// Test runner routes
|
||||
router.post(
|
||||
'/start-tests',
|
||||
validatePathParams('worktreePath', 'projectPath?'),
|
||||
createStartTestsHandler(settingsService)
|
||||
);
|
||||
router.post('/stop-tests', createStopTestsHandler());
|
||||
router.get('/test-logs', validatePathParams('worktreePath?'), createGetTestLogsHandler());
|
||||
|
||||
// Init script routes
|
||||
router.get('/init-script', createGetInitScriptHandler());
|
||||
router.put('/init-script', validatePathParams('projectPath'), createPutInitScriptHandler());
|
||||
|
||||
92
apps/server/src/routes/worktree/routes/start-tests.ts
Normal file
92
apps/server/src/routes/worktree/routes/start-tests.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* POST /start-tests endpoint - Start tests for a worktree
|
||||
*
|
||||
* Runs the test command configured in project settings.
|
||||
* If no testCommand is configured, returns an error.
|
||||
*/
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
import type { SettingsService } from '../../../services/settings-service.js';
|
||||
import { getTestRunnerService } from '../../../services/test-runner-service.js';
|
||||
import { getErrorMessage, logError } from '../common.js';
|
||||
|
||||
export function createStartTestsHandler(settingsService?: SettingsService) {
|
||||
return async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const body = req.body;
|
||||
|
||||
// Validate request body
|
||||
if (!body || typeof body !== 'object') {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'Request body must be an object',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const worktreePath = typeof body.worktreePath === 'string' ? body.worktreePath : undefined;
|
||||
const projectPath = typeof body.projectPath === 'string' ? body.projectPath : undefined;
|
||||
const testFile = typeof body.testFile === 'string' ? body.testFile : undefined;
|
||||
|
||||
if (!worktreePath) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'worktreePath is required and must be a string',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Get project settings to find the test command
|
||||
// Use projectPath if provided, otherwise use worktreePath
|
||||
const settingsPath = projectPath || worktreePath;
|
||||
|
||||
if (!settingsService) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: 'Settings service not available',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const projectSettings = await settingsService.getProjectSettings(settingsPath);
|
||||
const testCommand = projectSettings?.testCommand;
|
||||
|
||||
if (!testCommand) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error:
|
||||
'No test command configured. Please configure a test command in Project Settings > Testing Configuration.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const testRunnerService = getTestRunnerService();
|
||||
const result = await testRunnerService.startTests(worktreePath, {
|
||||
command: testCommand,
|
||||
testFile,
|
||||
});
|
||||
|
||||
if (result.success && result.result) {
|
||||
res.json({
|
||||
success: true,
|
||||
result: {
|
||||
sessionId: result.result.sessionId,
|
||||
worktreePath: result.result.worktreePath,
|
||||
command: result.result.command,
|
||||
status: result.result.status,
|
||||
testFile: result.result.testFile,
|
||||
message: result.result.message,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: result.error || 'Failed to start tests',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
logError(error, 'Start tests failed');
|
||||
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
||||
}
|
||||
};
|
||||
}
|
||||
58
apps/server/src/routes/worktree/routes/stop-tests.ts
Normal file
58
apps/server/src/routes/worktree/routes/stop-tests.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* POST /stop-tests endpoint - Stop a running test session
|
||||
*
|
||||
* Stops the test runner process for a specific session,
|
||||
* cancelling any ongoing tests and freeing up resources.
|
||||
*/
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
import { getTestRunnerService } from '../../../services/test-runner-service.js';
|
||||
import { getErrorMessage, logError } from '../common.js';
|
||||
|
||||
export function createStopTestsHandler() {
|
||||
return async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const body = req.body;
|
||||
|
||||
// Validate request body
|
||||
if (!body || typeof body !== 'object') {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'Request body must be an object',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const sessionId = typeof body.sessionId === 'string' ? body.sessionId : undefined;
|
||||
|
||||
if (!sessionId) {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'sessionId is required and must be a string',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const testRunnerService = getTestRunnerService();
|
||||
const result = await testRunnerService.stopTests(sessionId);
|
||||
|
||||
if (result.success && result.result) {
|
||||
res.json({
|
||||
success: true,
|
||||
result: {
|
||||
sessionId: result.result.sessionId,
|
||||
message: result.result.message,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: result.error || 'Failed to stop tests',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
logError(error, 'Stop tests failed');
|
||||
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
||||
}
|
||||
};
|
||||
}
|
||||
160
apps/server/src/routes/worktree/routes/test-logs.ts
Normal file
160
apps/server/src/routes/worktree/routes/test-logs.ts
Normal file
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* GET /test-logs endpoint - Get buffered logs for a test runner session
|
||||
*
|
||||
* Returns the scrollback buffer containing historical log output for a test run.
|
||||
* Used by clients to populate the log panel on initial connection
|
||||
* before subscribing to real-time updates via WebSocket.
|
||||
*
|
||||
* Query parameters:
|
||||
* - worktreePath: Path to the worktree (optional if sessionId provided)
|
||||
* - sessionId: Specific test session ID (optional, uses active session if not provided)
|
||||
*/
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
import { getTestRunnerService } from '../../../services/test-runner-service.js';
|
||||
import { getErrorMessage, logError } from '../common.js';
|
||||
|
||||
interface SessionInfo {
|
||||
sessionId: string;
|
||||
worktreePath?: string;
|
||||
command?: string;
|
||||
testFile?: string;
|
||||
exitCode?: number | null;
|
||||
}
|
||||
|
||||
interface OutputResult {
|
||||
sessionId: string;
|
||||
status: string;
|
||||
output: string;
|
||||
startedAt: string;
|
||||
finishedAt?: string | null;
|
||||
}
|
||||
|
||||
function buildLogsResponse(session: SessionInfo, output: OutputResult) {
|
||||
return {
|
||||
success: true,
|
||||
result: {
|
||||
sessionId: session.sessionId,
|
||||
worktreePath: session.worktreePath,
|
||||
command: session.command,
|
||||
status: output.status,
|
||||
testFile: session.testFile,
|
||||
logs: output.output,
|
||||
startedAt: output.startedAt,
|
||||
finishedAt: output.finishedAt,
|
||||
exitCode: session.exitCode ?? null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function createGetTestLogsHandler() {
|
||||
return async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { worktreePath, sessionId } = req.query as {
|
||||
worktreePath?: string;
|
||||
sessionId?: string;
|
||||
};
|
||||
|
||||
const testRunnerService = getTestRunnerService();
|
||||
|
||||
// If sessionId is provided, get logs for that specific session
|
||||
if (sessionId) {
|
||||
const result = testRunnerService.getSessionOutput(sessionId);
|
||||
|
||||
if (result.success && result.result) {
|
||||
const session = testRunnerService.getSession(sessionId);
|
||||
res.json(
|
||||
buildLogsResponse(
|
||||
{
|
||||
sessionId: result.result.sessionId,
|
||||
worktreePath: session?.worktreePath,
|
||||
command: session?.command,
|
||||
testFile: session?.testFile,
|
||||
exitCode: session?.exitCode,
|
||||
},
|
||||
result.result
|
||||
)
|
||||
);
|
||||
} else {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
error: result.error || 'Failed to get test logs',
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If worktreePath is provided, get logs for the active session
|
||||
if (worktreePath) {
|
||||
const activeSession = testRunnerService.getActiveSession(worktreePath);
|
||||
|
||||
if (activeSession) {
|
||||
const result = testRunnerService.getSessionOutput(activeSession.id);
|
||||
|
||||
if (result.success && result.result) {
|
||||
res.json(
|
||||
buildLogsResponse(
|
||||
{
|
||||
sessionId: activeSession.id,
|
||||
worktreePath: activeSession.worktreePath,
|
||||
command: activeSession.command,
|
||||
testFile: activeSession.testFile,
|
||||
exitCode: activeSession.exitCode,
|
||||
},
|
||||
result.result
|
||||
)
|
||||
);
|
||||
} else {
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
error: result.error || 'Failed to get test logs',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// No active session - check for most recent session for this worktree
|
||||
const sessions = testRunnerService.listSessions(worktreePath);
|
||||
if (sessions.result.sessions.length > 0) {
|
||||
// Get the most recent session (list is not sorted, so find it)
|
||||
const mostRecent = sessions.result.sessions.reduce((latest, current) => {
|
||||
const latestTime = new Date(latest.startedAt).getTime();
|
||||
const currentTime = new Date(current.startedAt).getTime();
|
||||
return currentTime > latestTime ? current : latest;
|
||||
});
|
||||
|
||||
const result = testRunnerService.getSessionOutput(mostRecent.sessionId);
|
||||
if (result.success && result.result) {
|
||||
res.json(
|
||||
buildLogsResponse(
|
||||
{
|
||||
sessionId: mostRecent.sessionId,
|
||||
worktreePath: mostRecent.worktreePath,
|
||||
command: mostRecent.command,
|
||||
testFile: mostRecent.testFile,
|
||||
exitCode: mostRecent.exitCode,
|
||||
},
|
||||
result.result
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
res.status(404).json({
|
||||
success: false,
|
||||
error: 'No test sessions found for this worktree',
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Neither sessionId nor worktreePath provided
|
||||
res.status(400).json({
|
||||
success: false,
|
||||
error: 'Either worktreePath or sessionId query parameter is required',
|
||||
});
|
||||
} catch (error) {
|
||||
logError(error, 'Get test logs failed');
|
||||
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user