fix(aihr): reject unknown interview questions
This commit is contained in:
+9
@@ -74,6 +74,7 @@ public class AihrInterviewService {
|
||||
requireSessionOwner(session, ownerIdentity);
|
||||
}
|
||||
if (session != null && request != null && !isBlank(request.questionId())) {
|
||||
requireKnownQuestion(session, request.questionId());
|
||||
session.answers().put(request.questionId(), answerText);
|
||||
}
|
||||
int baseScore = answerText.isBlank() ? 0 : Math.min(92, 62 + Math.min(answerText.length() / 4, 30));
|
||||
@@ -106,6 +107,7 @@ public class AihrInterviewService {
|
||||
if (request != null && request.answers() != null) {
|
||||
request.answers().forEach((questionId, answer) -> {
|
||||
if (!isBlank(questionId)) {
|
||||
requireKnownQuestion(session, questionId);
|
||||
session.answers().put(questionId, clean(answer));
|
||||
}
|
||||
});
|
||||
@@ -623,6 +625,13 @@ public class AihrInterviewService {
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireKnownQuestion(InterviewSession session, String questionId) {
|
||||
boolean known = session.questions().stream().anyMatch(question -> question.questionId().equals(questionId));
|
||||
if (!known) {
|
||||
throw new IllegalArgumentException("面试题不存在");
|
||||
}
|
||||
}
|
||||
|
||||
private CandidateProfile dynamicCandidate(String candidateId, String candidateName, String positionCode) {
|
||||
CandidateProfile template = candidates.get("zhang-ming");
|
||||
String cleanId = clean(candidateId);
|
||||
|
||||
+38
@@ -220,6 +220,44 @@ class AihrInterviewServiceTest {
|
||||
verify(jdbcTemplate, never()).update(anyString(), org.mockito.ArgumentMatchers.<Object[]>any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("dev")
|
||||
void interviewAnswerRejectsUnknownQuestion() {
|
||||
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-unknown-question", "候选人", "customer-service", "mobile"));
|
||||
|
||||
IllegalArgumentException error = assertThrows(IllegalArgumentException.class, () -> service.answer(
|
||||
new AnswerRequest(started.sessionId(), "q999", "伪造题目回答", null)
|
||||
));
|
||||
|
||||
assertEquals("面试题不存在", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("dev")
|
||||
void interviewFinishRejectsUnknownQuestion() {
|
||||
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-finish-unknown-question", "候选人", "customer-service", "mobile"));
|
||||
|
||||
IllegalArgumentException error = assertThrows(IllegalArgumentException.class, () -> service.finish(
|
||||
new FinishRequest(started.sessionId(), Map.of(
|
||||
"q1", "确认诉求并安抚情绪",
|
||||
"q2", "说明费用和整改安排",
|
||||
"q3", "同步责任人和反馈时间",
|
||||
"q999", "伪造题目回答"
|
||||
))
|
||||
));
|
||||
|
||||
assertEquals("面试题不存在", error.getMessage());
|
||||
verify(jdbcTemplate, never()).update(anyString(), org.mockito.ArgumentMatchers.<Object[]>any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Tag("dev")
|
||||
void reviewResultRejectsOutOfRangeScore() {
|
||||
|
||||
Reference in New Issue
Block a user