feat: кнопка Запустить с выводом stdout (P0.1) - #13
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e082a5067
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function showCodeOutput(questionId, result) { | ||
| const node = document.querySelector(`#output-${questionId}`); | ||
| if (!node) return; | ||
| node.textContent = result.timed_out ? 'Превышено время выполнения.' : result.error || result.stderr || result.stdout || 'Нет вывода.'; |
There was a problem hiding this comment.
Preserve stdout when execution also raises
When learner code prints output and then raises an exception, such as print('before'); 1 / 0, the endpoint returns both stdout and error, but this priority chain selects the error and discards everything printed before it. The new output pane therefore hides diagnostic output in precisely the failure cases where it is most useful; render stdout together with the error/stderr rather than selecting only the first nonempty field.
Useful? React with 👍 / 👎.
| actual = eval(test['call'], namespace, namespace) | ||
| checks.append({'passed': actual == test['expected'], 'actual': repr(actual), 'expected': repr(test['expected'])}) | ||
| print(json.dumps({'ok': all(item['passed'] for item in checks), 'checks': checks}, ensure_ascii=False)) | ||
| print(json.dumps({'ok': all(item['passed'] for item in checks), 'checks': checks, 'stdout': output.getvalue()}, ensure_ascii=False)) |
There was a problem hiding this comment.
Escape captured stdout before emitting runner JSON
When valid learner code prints a lone surrogate escape such as print('\ud800'), placing the raw captured value in an ensure_ascii=False JSON document makes the runner's final print raise UnicodeEncodeError; the exception handler then repeats the same failing serialization, and the parent reports a generic checker failure with no stdout. This also regresses ordinary code checks because raw stdout was not previously included in the payload; serialize with surrogate-safe escaping or sanitize the captured text.
Useful? React with 👍 / 👎.
Кнопка «▶ Запустить» + блок вывода stdout/stderr/timeout в редакторе кода. Backend: POST /api/code/run на существующем безопасном раннере без ослабления AST-фильтров. Тесты: 10 passed.