fix: adress pr comments

This commit is contained in:
Shirone
2026-01-21 16:00:40 +01:00
parent afa93dde0d
commit b73885e04a
5 changed files with 99 additions and 61 deletions

View File

@@ -13,16 +13,25 @@ import { getErrorMessage, logError } from '../common.js';
export function createStartTestsHandler(settingsService?: SettingsService) { export function createStartTestsHandler(settingsService?: SettingsService) {
return async (req: Request, res: Response): Promise<void> => { return async (req: Request, res: Response): Promise<void> => {
try { try {
const { worktreePath, projectPath, testFile } = req.body as { const body = req.body;
worktreePath: string;
projectPath?: string; // Validate request body
testFile?: string; 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) { if (!worktreePath) {
res.status(400).json({ res.status(400).json({
success: false, success: false,
error: 'worktreePath is required', error: 'worktreePath is required and must be a string',
}); });
return; return;
} }
@@ -42,12 +51,6 @@ export function createStartTestsHandler(settingsService?: SettingsService) {
const projectSettings = await settingsService.getProjectSettings(settingsPath); const projectSettings = await settingsService.getProjectSettings(settingsPath);
const testCommand = projectSettings?.testCommand; const testCommand = projectSettings?.testCommand;
// Debug logging
console.log('[StartTests] settingsPath:', settingsPath);
console.log('[StartTests] projectSettings:', JSON.stringify(projectSettings, null, 2));
console.log('[StartTests] testCommand:', testCommand);
console.log('[StartTests] testCommand type:', typeof testCommand);
if (!testCommand) { if (!testCommand) {
res.status(400).json({ res.status(400).json({
success: false, success: false,

View File

@@ -12,14 +12,23 @@ import { getErrorMessage, logError } from '../common.js';
export function createStopTestsHandler() { export function createStopTestsHandler() {
return async (req: Request, res: Response): Promise<void> => { return async (req: Request, res: Response): Promise<void> => {
try { try {
const { sessionId } = req.body as { const body = req.body;
sessionId: string;
}; // 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) { if (!sessionId) {
res.status(400).json({ res.status(400).json({
success: false, success: false,
error: 'sessionId is required', error: 'sessionId is required and must be a string',
}); });
return; return;
} }

View File

@@ -14,6 +14,39 @@ import type { Request, Response } from 'express';
import { getTestRunnerService } from '../../../services/test-runner-service.js'; import { getTestRunnerService } from '../../../services/test-runner-service.js';
import { getErrorMessage, logError } from '../common.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() { export function createGetTestLogsHandler() {
return async (req: Request, res: Response): Promise<void> => { return async (req: Request, res: Response): Promise<void> => {
try { try {
@@ -30,20 +63,18 @@ export function createGetTestLogsHandler() {
if (result.success && result.result) { if (result.success && result.result) {
const session = testRunnerService.getSession(sessionId); const session = testRunnerService.getSession(sessionId);
res.json({ res.json(
success: true, buildLogsResponse(
result: { {
sessionId: result.result.sessionId, sessionId: result.result.sessionId,
worktreePath: session?.worktreePath, worktreePath: session?.worktreePath,
command: session?.command, command: session?.command,
status: result.result.status,
testFile: session?.testFile, testFile: session?.testFile,
logs: result.result.output, exitCode: session?.exitCode,
startedAt: result.result.startedAt,
finishedAt: result.result.finishedAt,
exitCode: session?.exitCode ?? null,
}, },
}); result.result
)
);
} else { } else {
res.status(404).json({ res.status(404).json({
success: false, success: false,
@@ -61,20 +92,18 @@ export function createGetTestLogsHandler() {
const result = testRunnerService.getSessionOutput(activeSession.id); const result = testRunnerService.getSessionOutput(activeSession.id);
if (result.success && result.result) { if (result.success && result.result) {
res.json({ res.json(
success: true, buildLogsResponse(
result: { {
sessionId: activeSession.id, sessionId: activeSession.id,
worktreePath: activeSession.worktreePath, worktreePath: activeSession.worktreePath,
command: activeSession.command, command: activeSession.command,
status: result.result.status,
testFile: activeSession.testFile, testFile: activeSession.testFile,
logs: result.result.output,
startedAt: result.result.startedAt,
finishedAt: result.result.finishedAt,
exitCode: activeSession.exitCode, exitCode: activeSession.exitCode,
}, },
}); result.result
)
);
} else { } else {
res.status(404).json({ res.status(404).json({
success: false, success: false,
@@ -94,20 +123,18 @@ export function createGetTestLogsHandler() {
const result = testRunnerService.getSessionOutput(mostRecent.sessionId); const result = testRunnerService.getSessionOutput(mostRecent.sessionId);
if (result.success && result.result) { if (result.success && result.result) {
res.json({ res.json(
success: true, buildLogsResponse(
result: { {
sessionId: mostRecent.sessionId, sessionId: mostRecent.sessionId,
worktreePath: mostRecent.worktreePath, worktreePath: mostRecent.worktreePath,
command: mostRecent.command, command: mostRecent.command,
status: result.result.status,
testFile: mostRecent.testFile, testFile: mostRecent.testFile,
logs: result.result.output,
startedAt: result.result.startedAt,
finishedAt: result.result.finishedAt,
exitCode: mostRecent.exitCode, exitCode: mostRecent.exitCode,
}, },
}); result.result
)
);
return; return;
} }
} }

View File

@@ -614,7 +614,6 @@ export function WorktreePanel({
onStopTests={handleStopTests} onStopTests={handleStopTests}
onViewTestLogs={handleViewTestLogs} onViewTestLogs={handleViewTestLogs}
hasInitScript={hasInitScript} hasInitScript={hasInitScript}
hasTestCommand={hasTestCommand}
/> />
)} )}

View File

@@ -174,7 +174,7 @@ export function useTestRunners(worktreePath?: string) {
const result = await api.worktree.getTestLogs(worktreePath); const result = await api.worktree.getTestLogs(worktreePath);
if (result.success && result.result) { if (result.success && result.result) {
const { sessionId, runner, status, testFile, logs, startedAt, finishedAt, exitCode } = const { sessionId, command, status, testFile, logs, startedAt, finishedAt, exitCode } =
result.result; result.result;
// Only add if we don't already have this session // Only add if we don't already have this session
@@ -183,7 +183,7 @@ export function useTestRunners(worktreePath?: string) {
startSession({ startSession({
sessionId, sessionId,
worktreePath, worktreePath,
runner, command,
status, status,
testFile, testFile,
startedAt, startedAt,