-
Notifications
You must be signed in to change notification settings - Fork 0
feat: кнопка Запустить с выводом stdout (P0.1) #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # Run Button Implementation Plan | ||
|
|
||
| > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. | ||
|
|
||
| **Goal:** Run code from the lesson editor and display its output without changing runner security limits. | ||
|
|
||
| **Architecture:** Add a small `POST /api/code/run` wrapper around `run_code(code, [])`. Preserve the runner's AST filter and two-second subprocess timeout, while returning its captured stdout and execution error. The existing editor sends to that endpoint and renders the returned output below the editor. | ||
|
|
||
| **Tech Stack:** FastAPI, Pydantic, SQLite app, vanilla JavaScript, CSS, pytest. | ||
|
|
||
| ## Global Constraints | ||
|
|
||
| - Work only in `/root/projects/python-path` on `feat/run-button`; never commit directly to `main`. | ||
| - Keep the current AST safety filter, isolated subprocess, 5,000-character source cap, and 2-second timeout unchanged. | ||
| - Do not add dependencies or delete project files. | ||
|
|
||
| --- | ||
|
|
||
| ### Task 1: Add API regression tests | ||
|
|
||
| **Files:** | ||
| - Modify: `tests/test_api.py` | ||
|
|
||
| **Interfaces:** | ||
| - Consumes: `POST /api/code/run` JSON `{ "code": str, "question_id": str | null }`. | ||
| - Produces: assertions for `{stdout, stderr, error, timed_out}`. | ||
|
|
||
| - [ ] **Step 1: Write failing tests** | ||
|
|
||
| ```python | ||
| response = client.post("/api/code/run", json={"code": "print('hi')"}) | ||
| assert response.json()["stdout"] == "hi\n" | ||
|
|
||
| response = client.post("/api/code/run", json={"code": "import os"}) | ||
| assert response.json()["error"] | ||
| ``` | ||
|
|
||
| - [ ] **Step 2: Run test to verify it fails** | ||
|
|
||
| Run: `uv run pytest tests/test_api.py -q` | ||
| Expected: FAIL because `/api/code/run` does not exist. | ||
|
|
||
| ### Task 2: Implement and render code execution | ||
|
|
||
| **Files:** | ||
| - Modify: `app/evaluator.py` | ||
| - Modify: `app/main.py` | ||
| - Modify: `app/static/app.js` | ||
| - Modify: `app/static/styles.css` | ||
|
|
||
| **Interfaces:** | ||
| - Consumes: `run_code(source, tests)` with `tests=[]`. | ||
| - Produces: `POST /api/code/run` response `{stdout, stderr, error, timed_out}` and a `.code-output` block. | ||
|
|
||
| - [ ] **Step 1: Preserve runner data** | ||
|
|
||
| ```python | ||
| return {"stdout": payload.get("stdout", ""), "stderr": result.stderr, | ||
| "error": payload.get("error"), "timed_out": False} | ||
| ``` | ||
|
|
||
| - [ ] **Step 2: Add endpoint and UI event handler** | ||
|
|
||
| ```python | ||
| @app.post("/api/code/run") | ||
| def run_code_endpoint(payload: CodeRun) -> dict: | ||
| result = run_code(payload.code, []) | ||
| return { | ||
| "stdout": result.get("stdout", ""), | ||
| "stderr": result.get("stderr", ""), | ||
| "error": result.get("error"), | ||
| "timed_out": result.get("timed_out", False), | ||
| } | ||
| ``` | ||
|
|
||
| - [ ] **Step 3: Run focused tests then full suite** | ||
|
|
||
| Run: `uv run pytest tests/test_api.py -q && uv run pytest` | ||
| Expected: PASS. | ||
|
|
||
| - [ ] **Step 4: Commit and push** | ||
|
|
||
| ```bash | ||
| git add -A | ||
| git commit -m "feat: run button with stdout output (P0.1)" | ||
| git push -u origin feat/run-button | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When valid learner code prints a lone surrogate escape such as
print('\ud800'), placing the raw captured value in anensure_ascii=FalseJSON document makes the runner's finalprintraiseUnicodeEncodeError; 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 👍 / 👎.