Skip to content

Commit c7eb03b

Browse files
Merge branch 'master' into lib
2 parents 76002b1 + 37f7cd5 commit c7eb03b

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

frontend/submission/task_platform.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {CodecastPlatform} from '../stepper/codecast_platform';
1111
import {delay} from '../player/sagas';
1212
import {BlockDocument, BufferType} from '../buffers/buffer_types';
1313
import {getBlocklyCodeFromXml} from '../stepper/js';
14+
import {extractTestsFromTask} from './tests';
15+
import {currentTaskChange, updateTaskTests} from '../task/task_slice';
1416

1517
export function* getTaskFromId(taskId: string, token: string, platform: string): Generator<any, TaskServer|null> {
1618
const state = yield* appSelect();
@@ -146,8 +148,15 @@ export function* longPollServerSubmissionResults(submissionId: string, submissio
146148
const state = yield* appSelect();
147149
const {taskPlatformUrl} = state.options;
148150

151+
const hasTests = state.task.currentTask.tests?.length;
152+
const totalUrl = `${taskPlatformUrl}/submissions/${submissionId}?longPolling${!hasTests ? '&withTests' : ''}`;
153+
154+
const newCurrentTask = {...state.task.currentTask};
155+
newCurrentTask.tests = [...state.task.currentTask.tests];
156+
let needUpdateTests = false;
157+
149158
while (true) {
150-
const result = (yield* call(asyncGetJson, taskPlatformUrl + '/submissions/' + submissionId + '?longPolling')) as TaskSubmissionServerResult|null;
159+
const result = (yield* call(asyncGetJson, totalUrl)) as TaskSubmissionServerResult|null;
151160
if (result.evaluated) {
152161
for (let test of result.tests) {
153162
test.score = test.score / 100;
@@ -156,16 +165,28 @@ export function* longPollServerSubmissionResults(submissionId: string, submissio
156165
}
157166

158167
// If the test has a clientId, change the id of the test to use the client id
159-
if (test?.test?.clientId) {
168+
if (test.test?.clientId) {
160169
const userTest = state.task.taskTests.find(otherTest => otherTest.id === test.test.clientId);
161170
if (userTest) {
162171
test.test.id = userTest.id;
163172
test.testId = userTest.id;
164173
}
165174
}
175+
if (test.test?.id && !state.task.currentTask.tests.find(otherTest => otherTest.id === test.test.id)) {
176+
newCurrentTask.tests.push(test.test);
177+
needUpdateTests = true;
178+
}
179+
}
180+
181+
if (needUpdateTests) {
182+
const taskVariant = state.options.taskVariant;
183+
const tests = extractTestsFromTask(newCurrentTask, taskVariant);
184+
yield* put(currentTaskChange(newCurrentTask));
185+
yield* put(updateTaskTests(tests));
166186
}
167187

168188
yield* put(submissionUpdateTaskSubmission({id: submissionIndex, submission: {...serverSubmission, evaluated: true, result}}));
189+
169190
callback(result);
170191

171192
return;

frontend/submission/task_submission.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {getTaskPlatformMode, recordingProgressSteps, TaskPlatformMode} from '../
2525
import {TaskActionTypes, updateCurrentTestId} from '../task/task_slice';
2626
import {LibraryTestResult} from '../task/libs/library_test_result';
2727
import {DeferredPromise} from '../utils/app';
28-
import {getTaskLevelTests, selectSubmissionsPaneEnabled} from './submission_selectors';
28+
import {getTaskLevelTests, selectSubmissionsPaneEnabled, selectTaskTests} from './submission_selectors';
2929
import {isServerTask, isTestPublic, TaskAnswer, TaskTestGroupType} from '../task/task_types';
3030
import {platformAnswerGraded} from '../task/platform/actionTypes';
3131
import {getMessage} from '../lang';
@@ -217,7 +217,7 @@ class TaskSubmissionExecutor {
217217
}
218218

219219
*gradeAnswerServer(parameters: PlatformTaskGradingParameters): Generator<any, PlatformTaskGradingResult, any> {
220-
const {level, answer, answerToken, scope} = parameters;
220+
const {answer, answerToken, scope} = parameters;
221221
const state = yield* appSelect();
222222
const platform = answer.platform;
223223
const userTests = SubmissionExecutionScope.MyTests === scope ? getTaskLevelTests(state).filter(test => TaskTestGroupType.User === test.groupType) : [];
@@ -253,7 +253,7 @@ class TaskSubmissionExecutor {
253253
const submissionId = submissionData.submissionId;
254254
submissionExecutionTasks[submissionIndex] = yield* fork([this, this.gradeAnswerLongPolling], submissionIndex, serverSubmission, submissionId);
255255

256-
return submissionExecutionTasks[submissionIndex].result();
256+
return submissionExecutionTasks[submissionIndex].toPromise();
257257
} catch (ex: any) {
258258
yield* put(submissionUpdateTaskSubmission({
259259
id: submissionIndex,
@@ -288,8 +288,30 @@ class TaskSubmissionExecutor {
288288
if (submissionResult.compilationError) {
289289
yield* put(submissionChangeDisplayedError(SubmissionErrorType.CompilationError));
290290
} else {
291-
const selectedTestId = yield* appSelect(state => state.task.currentTestId);
292-
// Refresh display by showing the test id that was previously selected
291+
let selectedTestId = yield* appSelect(state => state.task.currentTestId);
292+
293+
// Refresh display by showing the first test of the submission that is failing
294+
if (submissionResult.tests?.length) {
295+
const newTaskTests = yield* appSelect(selectTaskTests);
296+
let newTestId = null;
297+
for (let i = 0; i < newTaskTests.length; i++) {
298+
const submissionTestResult = submissionResult.tests.find(test => test.testId === newTaskTests[i].id);
299+
if (submissionTestResult) {
300+
if (null === newTestId) {
301+
newTestId = i;
302+
}
303+
if (submissionResult?.score < 1) {
304+
newTestId = i;
305+
break;
306+
}
307+
}
308+
}
309+
310+
if (null !== newTestId) {
311+
selectedTestId = newTestId
312+
}
313+
}
314+
293315
if (null !== selectedTestId) {
294316
yield* put(updateCurrentTestId({testId: selectedTestId}));
295317
}

frontend/task/platform/platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export function* taskGradeAnswerEventSaga ({payload: {answer, answerToken, succe
484484
log.getLogger('tests').debug('info answer', level);
485485

486486
// Score is between 0 and 1
487-
const {score, message, scoreToken} = yield* call([taskGrader, taskGrader.gradeAnswer],{level, answer: answerObject[level]});
487+
const {score, message, scoreToken} = yield* call([taskGrader, taskGrader.gradeAnswer], {level, answer: answerObject[level]});
488488

489489
versionsScore[level] = score;
490490
if (level === currentLevel) {

0 commit comments

Comments
 (0)