fix(aihr): require interview answers before scoring

This commit is contained in:
2026-07-14 14:31:54 +08:00
parent 82197cb50e
commit c4f98b9ab6
4 changed files with 23 additions and 0 deletions
@@ -110,6 +110,9 @@ public class AihrInterviewService {
}
});
}
if (session.questions().stream().noneMatch(question -> !isBlank(session.answers().get(question.questionId())))) {
throw new IllegalArgumentException("请先提交至少一条有效面试回答");
}
ScoreResult score = scoreWithModel(session).orElseGet(() -> localScore(session));
String time = LocalDateTime.now().format(TIME_FORMAT);
List<QuestionRecordResponse> questions = questionRecords(session);
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -185,6 +186,23 @@ class AihrInterviewServiceTest {
assertTrue(serviceSource.contains("reviewed_time = NULL"));
}
@Test
@Tag("dev")
void interviewFinishRequiresAtLeastOneRealAnswer() {
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
AihrModelSeedService modelService = mock(AihrModelSeedService.class);
when(modelService.tryChat(anyString(), anyString(), anyDouble())).thenReturn(Optional.empty());
AihrInterviewService service = new AihrInterviewService(new ObjectMapper(), modelService, jdbcTemplate);
var started = service.start(new StartRequest("candidate-empty", "候选人", "customer-service", "mobile"));
IllegalArgumentException error = assertThrows(IllegalArgumentException.class, () -> service.finish(
new FinishRequest(started.sessionId(), Map.of())
));
assertEquals("请先提交至少一条有效面试回答", error.getMessage());
verify(jdbcTemplate, never()).update(anyString(), org.mockito.ArgumentMatchers.<Object[]>any());
}
@Test
@Tag("dev")
void reviewResultRejectsOutOfRangeScore() {