Package: code-exercises
Generated from api/packages/code-exercises
Source: api/packages/code-exercises. The sections after the README are extracted from the code on every docs build.
README
Section titled “README”The code exercise topic type (ADR 0170, milestone AX-1): a topic holds starter files and visible tests; the learner edits the files and runs the tests in the browser, in an isolated sandbox with no network (JavaScript and TypeScript), and each run is stored as a practice attempt.
- Model
Ulams\CodeExercises\Models\CodeExerciseTopic, tabletopic_code_exercises:language(javascript,typescript),filesandvisible_tests(lists of{path, content}),timeout_ms(500 to 30000),completion_rule(on_pass,on_attempt),pass_score,text(Markdown task).runtimeisbrowserandgradingispracticeuntil the server runner exists (AX-4). - No admin CRUD. Topics are created and changed through the topic API (
POST /api/admin/topics,topicable_type=Ulams\CodeExercises\Models\CodeExerciseTopic; the lists may be JSON strings in multipart forms). Permissions and tenant isolation are those of the topic API. - Everything an author sends is untrusted input (
ExerciseFilesValidator): at most 20 files and 10 test files, 64 KB each and 256 KB together, relative paths of plain characters (no.., no hidden names, no absolute paths), an extension allow-list per language (config.php), UTF-8 text without NUL bytes, no duplicate paths. The files are stored and sent to the browser as text; this package never runs them. - The runner is a set of static files in
resources/runtime/code-runner/<version>/, built fromfront/code-runner(yarn workspace @ulams/code-runner build; CI fails when the committed files are stale) and served from the tenant content origin under/runtime/code-runner/<version>/bypackages/uploads(ContentFileController, prefixruntime).RunnerHeaderssets the content security policy of each file; the two policies are data inresources/runner-csp.json, which the front-end tests read as well.esbuild.wasm(14 MB) is not in git:bin/fetch-esbuild.shdownloads it, pinned by checksum, into the image. - Results are practice grades.
POST /api/code-exercises/topics/{topic}/attemptstakes the result of each visible test, recomputes the score on the server, stores an attempt withverified = false, moves the topic’s progress by its completion rule (CourseProgressRepositoryContract) and dispatchesCodeAttemptFinished, which learner-insights turns into thecode.attempt_finishedsignal. Nothing that issues certificates or checks compliance reads these attempts as a grade.
| Method | Path | Notes |
|---|---|---|
| POST | /api/code-exercises/launches/{topic} |
learner (attend gate): {runner: {url, version}, exercise, attempts}; 404 when disabled or not an exercise, 503 without a content origin |
| POST | /api/code-exercises/topics/{topic}/attempts |
learner, throttled (attempts_per_minute, default 20): {results: [{name, status: pass|fail|error, message?}], files_hash?, runner?, duration_ms?}; answers {attempt, status} |
| GET | /api/code-exercises/topics/{topic}/attempts |
the caller’s own attempts, newest first |
| GET | /api/admin/code-exercises/topics/{topic}/preview |
author preview, same shape as a launch, nothing tracked |
| GET | /api/admin/code-exercises/topics/{topic}/attempts |
teacher report: every learner’s attempts, paginated |
Settings
Section titled “Settings”ulams_code_exercises.enabled (default on) is an administrable config key; CODE_EXERCISES_ENABLED and
CODE_EXERCISES_RUNTIME_PATH are environment variables.
./vendor/bin/phpunit --testsuite code-exercises.
Topic types
Section titled “Topic types”CodeExerciseTopic
API endpoints
Section titled “API endpoints”| Method | Path | Auth | Action |
|---|---|---|---|
POST |
/api/code-exercises/launches/{topic} |
yes | CodeExerciseController@launch |
POST |
/api/code-exercises/topics/{topic}/attempts |
yes | CodeExerciseController@store |
GET |
/api/code-exercises/topics/{topic}/attempts |
yes | CodeExerciseController@mine |
GET |
/api/admin/code-exercises/topics/{topic}/preview |
yes | CodeExerciseController@preview |
GET |
/api/admin/code-exercises/topics/{topic}/attempts |
yes | CodeExerciseController@report |
Permissions
Section titled “Permissions”None.
Settings
Section titled “Settings”Registered with AdministrableConfig::registerConfig (editable in the admin panel under Configuration → Settings).
| Key | Rules | Public | Read-only |
|---|---|---|---|
ulams_code_exercises.enabled |
required, boolean | yes |
Events
Section titled “Events”| Event | Description | Notification templates |
|---|---|---|
CodeAttemptFinished |
A learner finished a run of a code exercise’s tests. Ids and numbers only; learner-insights turns it into the code.attempt_finished signal (ADR 0057). |
Artisan commands
Section titled “Artisan commands”None.
Scheduled jobs
Section titled “Scheduled jobs”None.
Environment variables read
Section titled “Environment variables read”CODE_EXERCISES_ENABLED, CODE_EXERCISES_RUNTIME_PATH