Use newline-only headers and semantic browser grading (0.5.0)
Browse filesNo trailing indentation in prompts; preserve fenced body whitespace and Python helpers. Accept semantic HTML attribute/text equivalents; browser behavior and parser syntax are reported independently. Add diagnostic hidden-test pass rate; primary all-tests-required macro score unchanged. Fixed 350 data/test/reference files unchanged. Live browser validation still outstanding.
- README.md +22 -8
- SHA256SUMS +14 -12
- completion.py +11 -8
- examples/base-prompts.json +23 -23
- examples/local-test-report.json +4 -3
- generation_settings.py +1 -1
- manifest.json +1 -1
- metrics.py +8 -1
- pyproject.toml +1 -1
- runners/common.py +12 -7
- runners/semantic.py +40 -0
- sandbox/supervisor.py +2 -2
- sandbox/worker.py +22 -15
- tests/test_completion.py +16 -4
- tests/test_semantic.py +53 -0
README.md
CHANGED
|
@@ -25,7 +25,7 @@ configs:
|
|
| 25 |
---
|
| 26 |
# SmolScript
|
| 27 |
|
| 28 |
-
An original execution-based benchmark of basic programming for 25M–350M parameter language models. Evaluator **0.
|
| 29 |
|
| 30 |
**Release status: execution-unverified candidate.** All 350 default records have been generated and statically validated. No complete reference execution run or model baseline is claimed. The authoring environment has no Docker/Podman daemon; all 350 default reference solutions and their negative controls still require execution in the supplied sandbox image. See `validation_report.json` for the machine-readable audit. Do not treat this candidate as a validated leaderboard release until `python validate.py` succeeds.
|
| 31 |
|
|
@@ -85,7 +85,7 @@ python evaluate.py --model HuggingFaceTB/SmolLM2-135M --output results.json --re
|
|
| 85 |
python evaluate.py --model HuggingFaceTB/SmolLM2-135M --language python rust --difficulty easy --output subset.json
|
| 86 |
```
|
| 87 |
|
| 88 |
-
One fixed completion prompt (`smolscript-base-completion-
|
| 89 |
|
| 90 |
Existing files require `--resume`. Settings, dataset/runner hashes, image ID and selected IDs must match. Completed task results are checkpointed atomically; a generated response is saved before execution, so an execution interruption can reuse it. Partial runs never receive a full score. Use one process per output path (a file lock enforces this). Context overflow is an explicit failure; input prompts are never silently truncated.
|
| 91 |
|
|
@@ -95,7 +95,7 @@ For externally generated code, create JSONL records `{"id":"...","code":"..."}`
|
|
| 95 |
python evaluate.py --predictions predictions.jsonl --output results.json
|
| 96 |
```
|
| 97 |
|
| 98 |
-
Externally supplied predictions use complete source code (raw code or a single fenced code block). Model inference stores raw continuations and deterministically assembles the supplied prefix before scoring. Multiple or unfinished fences are rejected. Function tasks receive fixed stdin/stdout wrappers. Compiled languages compile once per task, then run a fresh process per test. HTML is parsed with html5lib and checked in Chromium with document scripts disabled. CSS is
|
| 99 |
|
| 100 |
## Metrics
|
| 101 |
|
|
@@ -125,7 +125,7 @@ The default split and both local/Modal evaluators now use the same fixed 350 IDs
|
|
| 125 |
|
| 126 |
The language budgets (before a 32-token moderate-task allowance, capped at 256) are Python 128, JavaScript 192, HTML 160, CSS 96, C++ 224, C 256, Lua 160, C# 256, Rust 256. They depend only on language/difficulty, never reference solutions. `--max-new-tokens N` overrides these budgets for a separately recorded experiment; `--batch-size N` overrides the default 64. A response that hits its cap is scored as generated; incorrect or incomplete code still fails the normal execution tests. Generation statistics include token-limit completions, OOM retries, final batch size, elapsed generation time and measured token throughput.
|
| 127 |
|
| 128 |
-
Example: `python evaluate.py --model HuggingFaceTB/SmolLM2-135M --batch-size 64 --output results-v030.json`. Generated batches are checkpointed before execution, and resume skips their inference. Numerical batching differences can change greedy outputs for near-tied logits. This release reduces the task count from 1,000 to 350 and retains the fast decoding budgets introduced in 0.2.0. Its scores must not be merged with earlier editions. Template IDs are `smolscript-0.
|
| 129 |
|
| 130 |
|
| 131 |
## Browser timeout handling
|
|
@@ -144,7 +144,7 @@ CSS styles are inserted synchronously with a DOM style element; the evaluator do
|
|
| 144 |
The Modal path first checks runtime availability and a trusted CSS computed-style/distractor probe, before model generation. Worker processes use explicit subprocess UID/GID settings and private writable HOME/XDG/TMP directories; no Python pre-exec callback is used in the threaded launcher. These changes preserve the fixed 350-example dataset and scoring definition. End-to-end Modal browser verification is still required; local tests cover the injection protocol, diagnostic fields, preflight failure and watchdog behavior.
|
| 145 |
|
| 146 |
|
| 147 |
-
## Base-model completion protocol (0.
|
| 148 |
|
| 149 |
The same completion template is used for every model, including instruction models. There is no chat wrapper, conversational instruction block, worked solution, reference implementation, test input, expected answer, or answer-dependent repair. Example prompt ending:
|
| 150 |
|
|
@@ -152,13 +152,27 @@ The same completion template is used for every model, including instruction mode
|
|
| 152 |
# Starting with n, double it, then take the last decimal digit of its absolute value. Return the result.
|
| 153 |
# Integer n from -120 to 120.
|
| 154 |
def solve(n):
|
| 155 |
-
|
| 156 |
```
|
| 157 |
|
| 158 |
-
The
|
| 159 |
|
| 160 |
The supplied prefix is attached to the generated continuation. Answer-independent lexical scope extraction keeps the first completed function/class body and discards trailing prose. Python uses indentation tokens; braced languages count delimiters while ignoring ordinary strings/comments (and supported regex/raw/verbatim strings); Lua counts block keywords. These are constrained completion delimiters, not general language parsers. Syntax and behavior are still checked inside the sandbox. Missing delimiters, malformed indentation, expressions, and return values are never repaired, and no closing suffix is invented. Complete entry-point definitions emitted from scratch, including a single fenced code block, are accepted as deterministic formatting alternatives.
|
| 161 |
|
| 162 |
Raw continuations and assembled `evaluated_code` are saved separately. The standalone `--predictions` path continues to accept complete code and bypasses the completion prefix. All 350 supplied reference bodies roundtrip through assembly (Python body AST equality, other languages source equality); this is a static assembly check, not complete runtime validation. Full isolated reference execution and a new KLM benchmark run remain outstanding.
|
| 163 |
|
| 164 |
-
Use a **new output path** for `smolscript-0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
---
|
| 26 |
# SmolScript
|
| 27 |
|
| 28 |
+
An original execution-based benchmark of basic programming for 25M–350M parameter language models. Evaluator **0.5.0**, **350 default examples** (fixed dataset edition 0.3.0), nine languages, MIT license.
|
| 29 |
|
| 30 |
**Release status: execution-unverified candidate.** All 350 default records have been generated and statically validated. No complete reference execution run or model baseline is claimed. The authoring environment has no Docker/Podman daemon; all 350 default reference solutions and their negative controls still require execution in the supplied sandbox image. See `validation_report.json` for the machine-readable audit. Do not treat this candidate as a validated leaderboard release until `python validate.py` succeeds.
|
| 31 |
|
|
|
|
| 85 |
python evaluate.py --model HuggingFaceTB/SmolLM2-135M --language python rust --difficulty easy --output subset.json
|
| 86 |
```
|
| 87 |
|
| 88 |
+
One fixed completion prompt (`smolscript-base-completion-v3`), one generation, seed 0, greedy decoding, no beam search, and versioned task budgets from 96 to 256 tokens. Starting batch size is 64, with automatic CUDA OOM backoff. Prompts are grouped by token budget and length; KV caching and supported last-token logits optimizations are enabled. Progress is reported between batches, avoiding per-token GPU-to-CPU synchronization. The same completion template is used for base and instruction models; no model-specific chat template is applied. The model revision resolves to an immutable commit and is retained on resume. Use `--revision SHA` for an explicit pin. Prompts contain task comments, the input domain, supplied standard-library imports, web fixtures/base styles where needed, and a function/markup prefix. Models continue the supplied source directly. References, public examples, hidden tests, and expected answers are never sent to the model.
|
| 89 |
|
| 90 |
Existing files require `--resume`. Settings, dataset/runner hashes, image ID and selected IDs must match. Completed task results are checkpointed atomically; a generated response is saved before execution, so an execution interruption can reuse it. Partial runs never receive a full score. Use one process per output path (a file lock enforces this). Context overflow is an explicit failure; input prompts are never silently truncated.
|
| 91 |
|
|
|
|
| 95 |
python evaluate.py --predictions predictions.jsonl --output results.json
|
| 96 |
```
|
| 97 |
|
| 98 |
+
Externally supplied predictions use complete source code (raw code or a single fenced code block). Model inference stores raw continuations and deterministically assembles the supplied prefix before scoring. Multiple or unfinished fences are rejected. Function tasks receive fixed stdin/stdout wrappers. Compiled languages compile once per task, then run a fresh process per test. HTML is parsed with html5lib and checked in Chromium with document scripts disabled. CSS syntax is reported with tinycss2 and behavior is tested against a fixed fixture at the specified widths. Browser tests assert DOM/computed styles and geometry, without image similarity.
|
| 99 |
|
| 100 |
## Metrics
|
| 101 |
|
|
|
|
| 125 |
|
| 126 |
The language budgets (before a 32-token moderate-task allowance, capped at 256) are Python 128, JavaScript 192, HTML 160, CSS 96, C++ 224, C 256, Lua 160, C# 256, Rust 256. They depend only on language/difficulty, never reference solutions. `--max-new-tokens N` overrides these budgets for a separately recorded experiment; `--batch-size N` overrides the default 64. A response that hits its cap is scored as generated; incorrect or incomplete code still fails the normal execution tests. Generation statistics include token-limit completions, OOM retries, final batch size, elapsed generation time and measured token throughput.
|
| 127 |
|
| 128 |
+
Example: `python evaluate.py --model HuggingFaceTB/SmolLM2-135M --batch-size 64 --output results-v030.json`. Generated batches are checkpointed before execution, and resume skips their inference. Numerical batching differences can change greedy outputs for near-tied logits. This release reduces the task count from 1,000 to 350 and retains the fast decoding budgets introduced in 0.2.0. Its scores must not be merged with earlier editions. Template IDs are `smolscript-0.5.0` and `cognirank2-v5`; use a new output path. No GPU throughput speedup is claimed without a measured run.
|
| 129 |
|
| 130 |
|
| 131 |
## Browser timeout handling
|
|
|
|
| 144 |
The Modal path first checks runtime availability and a trusted CSS computed-style/distractor probe, before model generation. Worker processes use explicit subprocess UID/GID settings and private writable HOME/XDG/TMP directories; no Python pre-exec callback is used in the threaded launcher. These changes preserve the fixed 350-example dataset and scoring definition. End-to-end Modal browser verification is still required; local tests cover the injection protocol, diagnostic fields, preflight failure and watchdog behavior.
|
| 145 |
|
| 146 |
|
| 147 |
+
## Base-model completion protocol (0.5.0)
|
| 148 |
|
| 149 |
The same completion template is used for every model, including instruction models. There is no chat wrapper, conversational instruction block, worked solution, reference implementation, test input, expected answer, or answer-dependent repair. Example prompt ending:
|
| 150 |
|
|
|
|
| 152 |
# Starting with n, double it, then take the last decimal digit of its absolute value. Return the result.
|
| 153 |
# Integer n from -120 to 120.
|
| 154 |
def solve(n):
|
|
|
|
| 155 |
```
|
| 156 |
|
| 157 |
+
The prompt ends immediately after the header newline, with no trailing spaces or tabs. The model supplies its own body indentation. Python headers omit type annotations. JavaScript, C, C++, C#, Rust and Lua receive their function/method openings (including the C# class), and applicable supplied imports. HTML receives a task comment followed by `<`; CSS receives its fixture/context and task as a CSS comment. `examples/base-prompts.json` contains an example for each language. `completion.py` is the authoritative prompt and assembly implementation.
|
| 158 |
|
| 159 |
The supplied prefix is attached to the generated continuation. Answer-independent lexical scope extraction keeps the first completed function/class body and discards trailing prose. Python uses indentation tokens; braced languages count delimiters while ignoring ordinary strings/comments (and supported regex/raw/verbatim strings); Lua counts block keywords. These are constrained completion delimiters, not general language parsers. Syntax and behavior are still checked inside the sandbox. Missing delimiters, malformed indentation, expressions, and return values are never repaired, and no closing suffix is invented. Complete entry-point definitions emitted from scratch, including a single fenced code block, are accepted as deterministic formatting alternatives.
|
| 160 |
|
| 161 |
Raw continuations and assembled `evaluated_code` are saved separately. The standalone `--predictions` path continues to accept complete code and bypasses the completion prefix. All 350 supplied reference bodies roundtrip through assembly (Python body AST equality, other languages source equality); this is a static assembly check, not complete runtime validation. Full isolated reference execution and a new KLM benchmark run remain outstanding.
|
| 162 |
|
| 163 |
+
Use a **new output path** for `smolscript-0.5.0` / `cognirank2-v5`. Dataset edition/selection 0.3.0 remains fixed; only the evaluation prompt/assembly protocol changes. Old scores are not comparable and must be rerun for leaderboard comparisons. Token budgets, deterministic greedy decoding, batch size 64, eight isolated Modal scoring workers, tests and weights remain the same.
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
## Behavioral equivalence (0.5.0)
|
| 167 |
+
|
| 168 |
+
Correctness is determined by the executable tests, never by source similarity. Newline-only function openings now leave indentation generation to the model. Fenced body completions preserve indentation, and valid Python source with module-level helper functions is retained.
|
| 169 |
+
|
| 170 |
+
HTML checks accept semantic equivalents: case-insensitive enumerated attribute values (`method="POST"`/`"post"`, `dir="RTL"`/`"rtl"`), equivalent hidden/boolean states, numeric attribute representations, and class-token ordering. Required elements, nesting, targets and content still matter. URL, ID, name and ordinary text values are not indiscriminately lowercased. Attribute lookup errors and missing required attributes still fail.
|
| 171 |
+
|
| 172 |
+
For ordinary HTML text, collapsible ASCII whitespace is normalized; preformatted text retains significant whitespace, and `pre-line` preserves line breaks. Extra inline spans with the same text can satisfy the same text check. JavaScript string outputs and programming string tasks retain exact observable content. CSS compares computed styles, so equivalent selectors, shorthands and color notations can pass when they produce all required styles and leave distractors unchanged.
|
| 173 |
+
|
| 174 |
+
HTML/CSS syntax reporting is now independent of behavioral testing: the native browser may recover from a parsing issue and still satisfy every assertion. Such a task can pass behavior while Syntax Success reports false. Full HTML documents and fragments are parsed in the appropriate mode. JavaScript syntax failures still prevent execution. No model source is rewritten to repair errors.
|
| 175 |
+
|
| 176 |
+
The optional `hidden_test_pass_rate` diagnostic averages test-pass fractions per task and then macro-averages across languages. It shows partial functional success. The official SmolScript Score remains all-tests-required Pass@1, macro-averaged across nine languages; this diagnostic does not affect CogniRank weights. It does not award credit for comments describing a solution that was not implemented.
|
| 177 |
+
|
| 178 |
+
These scoring/format changes require a new output path (`smolscript-0.5.0`, `cognirank2-v5`). All 350 tasks, reference implementations and hidden test files remain byte-identical. The local equivalence controls use observation fixtures and a mocked browser; full real-browser reference validation remains outstanding.
|
SHA256SUMS
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
ff73ee904edc9381bd1ea24847e41c6176aec22ba4b63321e8354562f24ba5ce .gitignore
|
| 2 |
8719af4397a8387b8f04140613943545f8ecd90f06529dcab9e68a94927d13fe LICENSE
|
| 3 |
-
|
| 4 |
2447d09ae445094c1ae59df644b46e3ca2f4cc64de630966b94bd5db8b8bf0ac archive/v0.1.0/hidden.jsonl
|
| 5 |
1926bca1b0c6b2244554577135a9c3c305b18fd834c654803b4e8480fff0d3d9 archive/v0.1.0/smolscript.jsonl
|
| 6 |
7bf25948750648aa036bdf277cfd7c38597c98aa06131e805628b9055a7938d9 archive/v0.1.0/smolscript.parquet
|
|
@@ -9,28 +9,28 @@ ed646bff1e37aaa95e039cabd8a3d58ed18485179de096e37f5ddf7a7223966e README.md
|
|
| 9 |
1c17c3515e86e2c4bc25c84b45b9f086c87efd98e1d75a7f4b42772b9d88176e archive/v0.2.0/smolscript.jsonl
|
| 10 |
358eae399dac7564ea5fb8753734f189aea3932994a22779d543bdcce847e050 archive/v0.2.0/smolscript.parquet
|
| 11 |
34c7244ea9160ba090e7c3bc1802ca68cc882f8ee9c29736ea8529d499977677 archive/v0.2.0/solutions.jsonl
|
| 12 |
-
|
| 13 |
9f9798909d3ab3631a457de1bc7e573c546ed3f3b0f78e6bcb82780e280b37b3 data/smolscript.jsonl
|
| 14 |
ad56c7186df28d84a23912a7fa2ec28b6762240a33b7b2a49412ce5b47319862 data/smolscript.parquet
|
| 15 |
0eaebae91f30afdebb84183619620f3eb73257ba3ab7c09572f0a982c5c99cd6 evaluate.py
|
| 16 |
-
|
| 17 |
-
|
| 18 |
713855348ffc53f49b03a0df47b67294fe2d3593054636eec12b9f184fb3534e examples/result-format.json
|
| 19 |
-
|
| 20 |
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 generators/__init__.py
|
| 21 |
8f14ca3a1a122d0d4ab34420e0c5493299166554aa296ec503af3e53e1847485 generators/build.py
|
| 22 |
e1cf493b995f15470c56c097b73e7403ae06f74f5d12cbb3a43ce522514d8577 generators/code.py
|
| 23 |
60be0a7ac6fcd3dfd8b663fc19af189aba3acfdd923219dc6cc1972033380240 generators/specs.py
|
| 24 |
c800d0237c7f4342fb636b6e54f15616a9547406f165e7ad7f96965cd6b9a4d1 generators/subset.py
|
| 25 |
ae6a8d5109035027b71df7eb7297e7c0b811a4a98c649e1729a3fe2a2c09c5bf generators/web.py
|
| 26 |
-
|
| 27 |
-
|
| 28 |
e00a185b961e80e1e1e86e6ddf97ec470d10e1c7b2bed44eb221af42a0eb6972 private_tests/hidden.jsonl
|
| 29 |
-
|
| 30 |
d736311f2645f4bdc7bac3316d858788118af4d551290d3924299f96935bd886 references/solutions.jsonl
|
| 31 |
5a3cb2a82cf3784c41fc9f9046fe6806d5bbe7ce8ae415a9ed1c373abcfe7826 runners/__init__.py
|
| 32 |
965bc9e3dabfc3fba4b745994b43118c456be477edcc34a3ba929ebf39e19ce9 runners/c_runner.py
|
| 33 |
-
|
| 34 |
17c846633f3730669790ee2f11fc93661648eedc950c96d47996d0db4514672b runners/cpp_runner.py
|
| 35 |
e87545f911f6f25238b1f84ed0ac1602900676b77cb3dd5f1560cd62e0b931e4 runners/csharp_runner.py
|
| 36 |
96e542ceb76e18759aa8f19fd87beef3612e535f7b9f04944a6bdf1e2fddffec runners/css_runner.py
|
|
@@ -43,11 +43,13 @@ e87545f911f6f25238b1f84ed0ac1602900676b77cb3dd5f1560cd62e0b931e4 runners/csharp
|
|
| 43 |
efabd7a4b829eb917116a2f51358a8fa8056370dbb57f6b6a9646c1cd342ffc5 runners/python_runner.py
|
| 44 |
63514e35b2687742ea6453e15d089da5a6cb4ab57ca0100da6189b187511ecf7 runners/rust_runner.py
|
| 45 |
d9ebf5141e3c1928879865050bf3ad7773613084fe62a0ff7eac8d1ea69f8cc4 runners/sandbox.py
|
|
|
|
| 46 |
53098a63b7d2053a4d8494c340e63d924646255c297d31e78c0025ef552c6cd6 sandbox/Dockerfile
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
c155b14ce8fa94dd4a179c22e6ab13accadffcf3571f384d27985ba916cbf864 tests/test_core.py
|
|
|
|
| 51 |
14f40a4b954c81dcf6cb8a2bdf361023e8cea36b54b31e40657f92f39433c124 tests/test_watchdog.py
|
| 52 |
ffba2ed9eabec6186a7568ff0535c9733841b661f7c1e420770dbeb47d87dbae validate.py
|
| 53 |
845d1ef1d45133e04908e1ff187281b9af9f4e48c2bec1994f91b1b191d5d563 validation_report.json
|
|
|
|
| 1 |
ff73ee904edc9381bd1ea24847e41c6176aec22ba4b63321e8354562f24ba5ce .gitignore
|
| 2 |
8719af4397a8387b8f04140613943545f8ecd90f06529dcab9e68a94927d13fe LICENSE
|
| 3 |
+
27c3710b398dde92dd98ff5632398ed85e954a31b8d94705b7a85a565d253966 README.md
|
| 4 |
2447d09ae445094c1ae59df644b46e3ca2f4cc64de630966b94bd5db8b8bf0ac archive/v0.1.0/hidden.jsonl
|
| 5 |
1926bca1b0c6b2244554577135a9c3c305b18fd834c654803b4e8480fff0d3d9 archive/v0.1.0/smolscript.jsonl
|
| 6 |
7bf25948750648aa036bdf277cfd7c38597c98aa06131e805628b9055a7938d9 archive/v0.1.0/smolscript.parquet
|
|
|
|
| 9 |
1c17c3515e86e2c4bc25c84b45b9f086c87efd98e1d75a7f4b42772b9d88176e archive/v0.2.0/smolscript.jsonl
|
| 10 |
358eae399dac7564ea5fb8753734f189aea3932994a22779d543bdcce847e050 archive/v0.2.0/smolscript.parquet
|
| 11 |
34c7244ea9160ba090e7c3bc1802ca68cc882f8ee9c29736ea8529d499977677 archive/v0.2.0/solutions.jsonl
|
| 12 |
+
c88b809ee731ea2e98b3ff987bd95fd815ba473979a8bec61f37b5646be80dd0 completion.py
|
| 13 |
9f9798909d3ab3631a457de1bc7e573c546ed3f3b0f78e6bcb82780e280b37b3 data/smolscript.jsonl
|
| 14 |
ad56c7186df28d84a23912a7fa2ec28b6762240a33b7b2a49412ce5b47319862 data/smolscript.parquet
|
| 15 |
0eaebae91f30afdebb84183619620f3eb73257ba3ab7c09572f0a982c5c99cd6 evaluate.py
|
| 16 |
+
90d902ef697281c2336a488b6b7ddb287e48ac10ed6a5bf2d5299da8d6d97450 examples/base-prompts.json
|
| 17 |
+
c86d561ca339e05e75e1d55ec0cc8e11e88fb1d1d31853eacbb0ab1d622b5c2c examples/local-test-report.json
|
| 18 |
713855348ffc53f49b03a0df47b67294fe2d3593054636eec12b9f184fb3534e examples/result-format.json
|
| 19 |
+
63f1c72b12b69f075dd581081feb3950256ef8bfdc99c02721e7ce514a3c981f generation_settings.py
|
| 20 |
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 generators/__init__.py
|
| 21 |
8f14ca3a1a122d0d4ab34420e0c5493299166554aa296ec503af3e53e1847485 generators/build.py
|
| 22 |
e1cf493b995f15470c56c097b73e7403ae06f74f5d12cbb3a43ce522514d8577 generators/code.py
|
| 23 |
60be0a7ac6fcd3dfd8b663fc19af189aba3acfdd923219dc6cc1972033380240 generators/specs.py
|
| 24 |
c800d0237c7f4342fb636b6e54f15616a9547406f165e7ad7f96965cd6b9a4d1 generators/subset.py
|
| 25 |
ae6a8d5109035027b71df7eb7297e7c0b811a4a98c649e1729a3fe2a2c09c5bf generators/web.py
|
| 26 |
+
9c6439595a13166be57748d43264983ae19cb8ac0a73b7f929cab931e51c8d1d manifest.json
|
| 27 |
+
873a82296884a7b6d17b942e61aa0fec515ccdb0da3cc43947b2dc2157b78bab metrics.py
|
| 28 |
e00a185b961e80e1e1e86e6ddf97ec470d10e1c7b2bed44eb221af42a0eb6972 private_tests/hidden.jsonl
|
| 29 |
+
26e3ba6e29aa21f7098662128f5973b110a138bb1019096cfcdf03a81032bebb pyproject.toml
|
| 30 |
d736311f2645f4bdc7bac3316d858788118af4d551290d3924299f96935bd886 references/solutions.jsonl
|
| 31 |
5a3cb2a82cf3784c41fc9f9046fe6806d5bbe7ce8ae415a9ed1c373abcfe7826 runners/__init__.py
|
| 32 |
965bc9e3dabfc3fba4b745994b43118c456be477edcc34a3ba929ebf39e19ce9 runners/c_runner.py
|
| 33 |
+
6e141f7d88826077366a1f22d96fdb483b9404484d7a763d95c34afe6abb54b6 runners/common.py
|
| 34 |
17c846633f3730669790ee2f11fc93661648eedc950c96d47996d0db4514672b runners/cpp_runner.py
|
| 35 |
e87545f911f6f25238b1f84ed0ac1602900676b77cb3dd5f1560cd62e0b931e4 runners/csharp_runner.py
|
| 36 |
96e542ceb76e18759aa8f19fd87beef3612e535f7b9f04944a6bdf1e2fddffec runners/css_runner.py
|
|
|
|
| 43 |
efabd7a4b829eb917116a2f51358a8fa8056370dbb57f6b6a9646c1cd342ffc5 runners/python_runner.py
|
| 44 |
63514e35b2687742ea6453e15d089da5a6cb4ab57ca0100da6189b187511ecf7 runners/rust_runner.py
|
| 45 |
d9ebf5141e3c1928879865050bf3ad7773613084fe62a0ff7eac8d1ea69f8cc4 runners/sandbox.py
|
| 46 |
+
57326ba34adabc061352dcc0ca703c7dcf0ec656df1d66254e3f21795991952a runners/semantic.py
|
| 47 |
53098a63b7d2053a4d8494c340e63d924646255c297d31e78c0025ef552c6cd6 sandbox/Dockerfile
|
| 48 |
+
179daec1a38a9d5eba0d37235cf1e8793ce8454f32e79220f0825ef62ff30c96 sandbox/supervisor.py
|
| 49 |
+
053547265479e5e2781852cfb6a0612caa3c85a47b5ec56a59a6cda9d4aedc90 sandbox/worker.py
|
| 50 |
+
8b3c872c1ee88d65e400b8712a27b184698f697fb52e1e87b9ed6eb7c0b433dd tests/test_completion.py
|
| 51 |
c155b14ce8fa94dd4a179c22e6ab13accadffcf3571f384d27985ba916cbf864 tests/test_core.py
|
| 52 |
+
704facc31065766122bf57346d0ae063e1e3c708fc1f97747c23ca8810c8789b tests/test_semantic.py
|
| 53 |
14f40a4b954c81dcf6cb8a2bdf361023e8cea36b54b31e40657f92f39433c124 tests/test_watchdog.py
|
| 54 |
ffba2ed9eabec6186a7568ff0535c9733841b661f7c1e420770dbeb47d87dbae validate.py
|
| 55 |
845d1ef1d45133e04908e1ff187281b9af9f4e48c2bec1994f91b1b191d5d563 validation_report.json
|
completion.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
import io
|
| 3 |
import re
|
| 4 |
import tokenize
|
| 5 |
-
PROMPT_VERSION='smolscript-base-completion-
|
| 6 |
SIGNATURES={
|
| 7 |
'python':{'scalar':'def solve(n):','string':'def solve(s):','array':'def solve(values):'},
|
| 8 |
'javascript':{'scalar':'function solve(n)','string':'function solve(s)','array':'function solve(values)','dom':'function setup()'},
|
|
@@ -18,11 +18,11 @@ def prefix(row):
|
|
| 18 |
if lang=='html':return '<'
|
| 19 |
if lang=='css':return ''
|
| 20 |
header=SIGNATURES[lang][kind]
|
| 21 |
-
if lang=='python':return header+'\n
|
| 22 |
-
if lang=='lua':return header+'\n
|
| 23 |
-
if kind=='dom':return header+' {\n
|
| 24 |
-
if lang=='csharp':return 'public class Solution {\n'+header+' {\n
|
| 25 |
-
return header+' {\n
|
| 26 |
|
| 27 |
def prompt(row):
|
| 28 |
from runners.protocol import HEADERS
|
|
@@ -137,7 +137,7 @@ def assemble(row,continuation):
|
|
| 137 |
text=continuation
|
| 138 |
if text.lstrip().startswith('```'):
|
| 139 |
from runners.common import extract_code
|
| 140 |
-
text=extract_code(text)
|
| 141 |
expected=prefix(row)
|
| 142 |
starts={
|
| 143 |
'python':r'^def\s+solve\s*\(', 'javascript':r'^(?:async\s+)?function\s+(?:solve|setup)\s*\(',
|
|
@@ -154,7 +154,10 @@ def assemble(row,continuation):
|
|
| 154 |
elif lang in starts and re.match(starts[lang],text.lstrip()):code=text.lstrip()
|
| 155 |
elif lang=='html' and text.lstrip().startswith('<'):code=text.lstrip()
|
| 156 |
else:code=expected+text
|
| 157 |
-
if lang=='python' and not complete_python:
|
|
|
|
|
|
|
|
|
|
| 158 |
elif lang=='lua':code=code[:_lua_end(code)]
|
| 159 |
elif lang not in ('html','css','python'):code=code[:_brace_end(code)]
|
| 160 |
return code.rstrip()+'\n'
|
|
|
|
| 2 |
import io
|
| 3 |
import re
|
| 4 |
import tokenize
|
| 5 |
+
PROMPT_VERSION='smolscript-base-completion-v3'
|
| 6 |
SIGNATURES={
|
| 7 |
'python':{'scalar':'def solve(n):','string':'def solve(s):','array':'def solve(values):'},
|
| 8 |
'javascript':{'scalar':'function solve(n)','string':'function solve(s)','array':'function solve(values)','dom':'function setup()'},
|
|
|
|
| 18 |
if lang=='html':return '<'
|
| 19 |
if lang=='css':return ''
|
| 20 |
header=SIGNATURES[lang][kind]
|
| 21 |
+
if lang=='python':return header+'\n'
|
| 22 |
+
if lang=='lua':return header+'\n'
|
| 23 |
+
if kind=='dom':return header+' {\n'
|
| 24 |
+
if lang=='csharp':return 'public class Solution {\n'+header+' {\n'
|
| 25 |
+
return header+' {\n'
|
| 26 |
|
| 27 |
def prompt(row):
|
| 28 |
from runners.protocol import HEADERS
|
|
|
|
| 137 |
text=continuation
|
| 138 |
if text.lstrip().startswith('```'):
|
| 139 |
from runners.common import extract_code
|
| 140 |
+
text=extract_code(text,preserve_indentation=True)
|
| 141 |
expected=prefix(row)
|
| 142 |
starts={
|
| 143 |
'python':r'^def\s+solve\s*\(', 'javascript':r'^(?:async\s+)?function\s+(?:solve|setup)\s*\(',
|
|
|
|
| 154 |
elif lang in starts and re.match(starts[lang],text.lstrip()):code=text.lstrip()
|
| 155 |
elif lang=='html' and text.lstrip().startswith('<'):code=text.lstrip()
|
| 156 |
else:code=expected+text
|
| 157 |
+
if lang=='python' and not complete_python:
|
| 158 |
+
import ast
|
| 159 |
+
try:ast.parse(code)
|
| 160 |
+
except SyntaxError:code=code[:_python_end(code)]
|
| 161 |
elif lang=='lua':code=code[:_lua_end(code)]
|
| 162 |
elif lang not in ('html','css','python'):code=code[:_brace_end(code)]
|
| 163 |
return code.rstrip()+'\n'
|
examples/base-prompts.json
CHANGED
|
@@ -2,64 +2,64 @@
|
|
| 2 |
{
|
| 3 |
"id": "smolscript-python-0015",
|
| 4 |
"language": "python",
|
| 5 |
-
"prompt_version": "smolscript-base-completion-
|
| 6 |
-
"completion_prompt": "# Starting with n, double it, then take the last decimal digit of its absolute value. Return the result.\n# Integer n from -120 to 120.\ndef solve(n):\n
|
| 7 |
-
"supplied_prefix": "def solve(n):\n
|
| 8 |
},
|
| 9 |
{
|
| 10 |
"id": "smolscript-javascript-0010",
|
| 11 |
"language": "javascript",
|
| 12 |
-
"prompt_version": "smolscript-base-completion-
|
| 13 |
-
"completion_prompt": "// Starting with ASCII string s, replace each run of spaces with one space, then keep the first floor(length/2) characters. Return the result.\n// ASCII s of at most 80 characters, without newlines.\nfunction solve(s) {\n
|
| 14 |
-
"supplied_prefix": "function solve(s) {\n
|
| 15 |
},
|
| 16 |
{
|
| 17 |
"id": "smolscript-html-0003",
|
| 18 |
"language": "html",
|
| 19 |
-
"prompt_version": "smolscript-base-completion-
|
| 20 |
"completion_prompt": "<!-- Create an h1 heading reading Welcome. On its outer element, set right-to-left direction via dir. -->\n<",
|
| 21 |
"supplied_prefix": "<"
|
| 22 |
},
|
| 23 |
{
|
| 24 |
"id": "smolscript-css-0010",
|
| 25 |
"language": "css",
|
| 26 |
-
"prompt_version": "smolscript-base-completion-
|
| 27 |
"completion_prompt": "/* HTML fixture: <div id=\"scope\"><div id=\"target\" class=\"target\" data-kind=\"card\">Alpha<span>One</span><span>Two</span></div><div class=\"other\">Beta</div></div><div class=\"target\" id=\"outside\">Outside</div> Existing CSS: * { box-sizing: content-box; } .target,.other { border: 1px solid black; width:200px; height:80px; min-width:0; max-width:none; margin:0; padding:0; display:block; position:static; } Style every element with class target: set font-weight to 700. Leave other elements unchanged. */\n",
|
| 28 |
"supplied_prefix": ""
|
| 29 |
},
|
| 30 |
{
|
| 31 |
"id": "smolscript-cpp-0003",
|
| 32 |
"language": "cpp",
|
| 33 |
-
"prompt_version": "smolscript-base-completion-
|
| 34 |
-
"completion_prompt": "// Starting with n, clamp it to the inclusive range -5 to 5, then subtract it from ten. Return the result.\n// Integer n from -120 to 120.\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <cstdlib>\nlong long solve(long long n) {\n
|
| 35 |
-
"supplied_prefix": "long long solve(long long n) {\n
|
| 36 |
},
|
| 37 |
{
|
| 38 |
"id": "smolscript-c-0001",
|
| 39 |
"language": "c",
|
| 40 |
-
"prompt_version": "smolscript-base-completion-
|
| 41 |
-
"completion_prompt": "// Starting with n, replace it with 1 if negative, otherwise 0, then add one. Return the result.\n// Integer n from -120 to 120.\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\nlong long solve(long long n) {\n
|
| 42 |
-
"supplied_prefix": "long long solve(long long n) {\n
|
| 43 |
},
|
| 44 |
{
|
| 45 |
"id": "smolscript-lua-0001",
|
| 46 |
"language": "lua",
|
| 47 |
-
"prompt_version": "smolscript-base-completion-
|
| 48 |
-
"completion_prompt": "-- Starting with n, replace it with 1 if negative, otherwise 0, then add one. Return the result.\n-- Integer n from -120 to 120.\nfunction solve(n)\n
|
| 49 |
-
"supplied_prefix": "function solve(n)\n
|
| 50 |
},
|
| 51 |
{
|
| 52 |
"id": "smolscript-csharp-0003",
|
| 53 |
"language": "csharp",
|
| 54 |
-
"prompt_version": "smolscript-base-completion-
|
| 55 |
-
"completion_prompt": "// Starting with n, clamp it to the inclusive range -5 to 5, then subtract it from ten. Return the result.\n// Integer n from -120 to 120.\nusing System;\nusing System.Linq;\nusing System.Collections.Generic;\npublic class Solution {\npublic static long Solve(long n) {\n
|
| 56 |
-
"supplied_prefix": "public class Solution {\npublic static long Solve(long n) {\n
|
| 57 |
},
|
| 58 |
{
|
| 59 |
"id": "smolscript-rust-0002",
|
| 60 |
"language": "rust",
|
| 61 |
-
"prompt_version": "smolscript-base-completion-
|
| 62 |
-
"completion_prompt": "// Starting with ASCII string s, convert lowercase ASCII letters to uppercase, then convert uppercase ASCII letters to lowercase. Return the result.\n// ASCII s of at most 80 characters, without newlines.\nuse std::io::{self, Read};\nfn solve(mut s: String) -> String {\n
|
| 63 |
-
"supplied_prefix": "fn solve(mut s: String) -> String {\n
|
| 64 |
}
|
| 65 |
]
|
|
|
|
| 2 |
{
|
| 3 |
"id": "smolscript-python-0015",
|
| 4 |
"language": "python",
|
| 5 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 6 |
+
"completion_prompt": "# Starting with n, double it, then take the last decimal digit of its absolute value. Return the result.\n# Integer n from -120 to 120.\ndef solve(n):\n",
|
| 7 |
+
"supplied_prefix": "def solve(n):\n"
|
| 8 |
},
|
| 9 |
{
|
| 10 |
"id": "smolscript-javascript-0010",
|
| 11 |
"language": "javascript",
|
| 12 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 13 |
+
"completion_prompt": "// Starting with ASCII string s, replace each run of spaces with one space, then keep the first floor(length/2) characters. Return the result.\n// ASCII s of at most 80 characters, without newlines.\nfunction solve(s) {\n",
|
| 14 |
+
"supplied_prefix": "function solve(s) {\n"
|
| 15 |
},
|
| 16 |
{
|
| 17 |
"id": "smolscript-html-0003",
|
| 18 |
"language": "html",
|
| 19 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 20 |
"completion_prompt": "<!-- Create an h1 heading reading Welcome. On its outer element, set right-to-left direction via dir. -->\n<",
|
| 21 |
"supplied_prefix": "<"
|
| 22 |
},
|
| 23 |
{
|
| 24 |
"id": "smolscript-css-0010",
|
| 25 |
"language": "css",
|
| 26 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 27 |
"completion_prompt": "/* HTML fixture: <div id=\"scope\"><div id=\"target\" class=\"target\" data-kind=\"card\">Alpha<span>One</span><span>Two</span></div><div class=\"other\">Beta</div></div><div class=\"target\" id=\"outside\">Outside</div> Existing CSS: * { box-sizing: content-box; } .target,.other { border: 1px solid black; width:200px; height:80px; min-width:0; max-width:none; margin:0; padding:0; display:block; position:static; } Style every element with class target: set font-weight to 700. Leave other elements unchanged. */\n",
|
| 28 |
"supplied_prefix": ""
|
| 29 |
},
|
| 30 |
{
|
| 31 |
"id": "smolscript-cpp-0003",
|
| 32 |
"language": "cpp",
|
| 33 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 34 |
+
"completion_prompt": "// Starting with n, clamp it to the inclusive range -5 to 5, then subtract it from ten. Return the result.\n// Integer n from -120 to 120.\n#include <iostream>\n#include <string>\n#include <vector>\n#include <algorithm>\n#include <cstdlib>\nlong long solve(long long n) {\n",
|
| 35 |
+
"supplied_prefix": "long long solve(long long n) {\n"
|
| 36 |
},
|
| 37 |
{
|
| 38 |
"id": "smolscript-c-0001",
|
| 39 |
"language": "c",
|
| 40 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 41 |
+
"completion_prompt": "// Starting with n, replace it with 1 if negative, otherwise 0, then add one. Return the result.\n// Integer n from -120 to 120.\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\nlong long solve(long long n) {\n",
|
| 42 |
+
"supplied_prefix": "long long solve(long long n) {\n"
|
| 43 |
},
|
| 44 |
{
|
| 45 |
"id": "smolscript-lua-0001",
|
| 46 |
"language": "lua",
|
| 47 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 48 |
+
"completion_prompt": "-- Starting with n, replace it with 1 if negative, otherwise 0, then add one. Return the result.\n-- Integer n from -120 to 120.\nfunction solve(n)\n",
|
| 49 |
+
"supplied_prefix": "function solve(n)\n"
|
| 50 |
},
|
| 51 |
{
|
| 52 |
"id": "smolscript-csharp-0003",
|
| 53 |
"language": "csharp",
|
| 54 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 55 |
+
"completion_prompt": "// Starting with n, clamp it to the inclusive range -5 to 5, then subtract it from ten. Return the result.\n// Integer n from -120 to 120.\nusing System;\nusing System.Linq;\nusing System.Collections.Generic;\npublic class Solution {\npublic static long Solve(long n) {\n",
|
| 56 |
+
"supplied_prefix": "public class Solution {\npublic static long Solve(long n) {\n"
|
| 57 |
},
|
| 58 |
{
|
| 59 |
"id": "smolscript-rust-0002",
|
| 60 |
"language": "rust",
|
| 61 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 62 |
+
"completion_prompt": "// Starting with ASCII string s, convert lowercase ASCII letters to uppercase, then convert uppercase ASCII letters to lowercase. Return the result.\n// ASCII s of at most 80 characters, without newlines.\nuse std::io::{self, Read};\nfn solve(mut s: String) -> String {\n",
|
| 63 |
+
"supplied_prefix": "fn solve(mut s: String) -> String {\n"
|
| 64 |
}
|
| 65 |
]
|
examples/local-test-report.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"unit_tests": {
|
| 3 |
-
"passed":
|
| 4 |
"command": "python -m unittest discover -s tests -q"
|
| 5 |
},
|
| 6 |
"python_reference_ast_parse": 44,
|
|
@@ -21,7 +21,7 @@
|
|
| 21 |
"rust": 39
|
| 22 |
},
|
| 23 |
"blocked_reason": "Docker/Podman unavailable; full isolated reference and negative-control execution remains unverified.",
|
| 24 |
-
"model_baselines": "No 0.
|
| 25 |
"gpu_throughput_benchmark": "not run",
|
| 26 |
"watchdog_policy": "phase-watchdog-v1",
|
| 27 |
"watchdog_test_execution": "trusted synthetic workers; candidate generations not executed on host",
|
|
@@ -31,5 +31,6 @@
|
|
| 31 |
"method": "Python body AST equality; other languages source equality",
|
| 32 |
"execution": false
|
| 33 |
},
|
| 34 |
-
"prompt_version": "smolscript-base-completion-
|
|
|
|
| 35 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"unit_tests": {
|
| 3 |
+
"passed": 34,
|
| 4 |
"command": "python -m unittest discover -s tests -q"
|
| 5 |
},
|
| 6 |
"python_reference_ast_parse": 44,
|
|
|
|
| 21 |
"rust": 39
|
| 22 |
},
|
| 23 |
"blocked_reason": "Docker/Podman unavailable; full isolated reference and negative-control execution remains unverified.",
|
| 24 |
+
"model_baselines": "No 0.5.0 model baseline run",
|
| 25 |
"gpu_throughput_benchmark": "not run",
|
| 26 |
"watchdog_policy": "phase-watchdog-v1",
|
| 27 |
"watchdog_test_execution": "trusted synthetic workers; candidate generations not executed on host",
|
|
|
|
| 31 |
"method": "Python body AST equality; other languages source equality",
|
| 32 |
"execution": false
|
| 33 |
},
|
| 34 |
+
"prompt_version": "smolscript-base-completion-v3",
|
| 35 |
+
"equivalence_controls": "semantic attribute/text observations and mocked browser; no live browser execution"
|
| 36 |
}
|
generation_settings.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""Versioned decoding policy; never reads references or hidden answers."""
|
| 2 |
-
PROTOCOL='smolscript-0.
|
| 3 |
DEFAULT_BATCH_SIZE=64
|
| 4 |
MAX_NEW_TOKENS=256
|
| 5 |
|
|
|
|
| 1 |
"""Versioned decoding policy; never reads references or hidden answers."""
|
| 2 |
+
PROTOCOL='smolscript-0.5.0'
|
| 3 |
DEFAULT_BATCH_SIZE=64
|
| 4 |
MAX_NEW_TOKENS=256
|
| 5 |
|
manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"evaluation_protocol": "smolscript-0.
|
| 3 |
"version": "smolscript-0.3.0",
|
| 4 |
"examples": 350,
|
| 5 |
"languages": {
|
|
|
|
| 1 |
{
|
| 2 |
+
"evaluation_protocol": "smolscript-0.5.0",
|
| 3 |
"version": "smolscript-0.3.0",
|
| 4 |
"examples": 350,
|
| 5 |
"languages": {
|
metrics.py
CHANGED
|
@@ -9,10 +9,17 @@ def aggregate(results,expected_ids,full_run=True):
|
|
| 9 |
for r in results:groups[r['language']].append(r)
|
| 10 |
accuracy={lang:100*sum(bool(r['passed']) for r in group)/len(group) for lang,group in sorted(groups.items())}
|
| 11 |
syntax={lang:100*sum(bool(r['syntax_success']) for r in group)/len(group) for lang,group in sorted(groups.items())}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
if full_run and set(groups)!=set(LANGUAGES):raise ValueError('Missing language')
|
| 13 |
score=sum(accuracy.values())/len(accuracy)
|
| 14 |
result={'scope':'full' if full_run else 'filtered','examples':len(results),'pass_at_1':score,
|
| 15 |
-
'syntax_success':sum(syntax.values())/len(syntax),
|
|
|
|
|
|
|
| 16 |
'per_language_syntax_success':syntax,'micro_accuracy':100*sum(r['passed'] for r in results)/len(results)}
|
| 17 |
result['smolscript_score' if full_run else 'filtered_macro_score']=score
|
| 18 |
return result
|
|
|
|
| 9 |
for r in results:groups[r['language']].append(r)
|
| 10 |
accuracy={lang:100*sum(bool(r['passed']) for r in group)/len(group) for lang,group in sorted(groups.items())}
|
| 11 |
syntax={lang:100*sum(bool(r['syntax_success']) for r in group)/len(group) for lang,group in sorted(groups.items())}
|
| 12 |
+
def fraction(row):
|
| 13 |
+
tests=row.get('tests')
|
| 14 |
+
if tests is None:return float(bool(row['passed']))
|
| 15 |
+
return sum(bool(t['passed']) for t in tests)/len(tests) if tests else 0.0
|
| 16 |
+
test_rates={lang:100*sum(fraction(r) for r in group)/len(group) for lang,group in sorted(groups.items())}
|
| 17 |
if full_run and set(groups)!=set(LANGUAGES):raise ValueError('Missing language')
|
| 18 |
score=sum(accuracy.values())/len(accuracy)
|
| 19 |
result={'scope':'full' if full_run else 'filtered','examples':len(results),'pass_at_1':score,
|
| 20 |
+
'syntax_success':sum(syntax.values())/len(syntax),
|
| 21 |
+
'hidden_test_pass_rate':sum(test_rates.values())/len(test_rates),
|
| 22 |
+
'per_language_test_pass_rate':test_rates,'per_language_accuracy':accuracy,
|
| 23 |
'per_language_syntax_success':syntax,'micro_accuracy':100*sum(r['passed'] for r in results)/len(results)}
|
| 24 |
result['smolscript_score' if full_run else 'filtered_macro_score']=score
|
| 25 |
return result
|
pyproject.toml
CHANGED
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=68"]
|
|
| 3 |
build-backend = "setuptools.build_meta"
|
| 4 |
[project]
|
| 5 |
name = "smolscript"
|
| 6 |
-
version = "0.
|
| 7 |
description = "A small-model multilingual execution benchmark"
|
| 8 |
requires-python = ">=3.11"
|
| 9 |
license = {text = "MIT"}
|
|
|
|
| 3 |
build-backend = "setuptools.build_meta"
|
| 4 |
[project]
|
| 5 |
name = "smolscript"
|
| 6 |
+
version = "0.5.0"
|
| 7 |
description = "A small-model multilingual execution benchmark"
|
| 8 |
requires-python = ">=3.11"
|
| 9 |
license = {text = "MIT"}
|
runners/common.py
CHANGED
|
@@ -2,12 +2,15 @@ import re
|
|
| 2 |
from decimal import Decimal,InvalidOperation
|
| 3 |
|
| 4 |
|
| 5 |
-
def extract_code(text):
|
| 6 |
-
text=text.strip()
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
if len(blocks)>1:raise ValueError('Multiple code blocks are ambiguous')
|
| 10 |
-
if '```'
|
| 11 |
return text+'\n'
|
| 12 |
|
| 13 |
|
|
@@ -38,11 +41,13 @@ class FunctionRunner:
|
|
| 38 |
|
| 39 |
class BrowserRunner:
|
| 40 |
def evaluate(self,row,code,hidden,sandbox):
|
|
|
|
| 41 |
scenarios=[];expected=[]
|
| 42 |
for t in hidden['tests']:
|
| 43 |
widths=sorted(set(c.get('viewport',800) for c in t['checks']))
|
| 44 |
for width in widths:
|
| 45 |
-
checks=[c
|
|
|
|
| 46 |
# Deliberately do not send expected values into the sandbox.
|
| 47 |
scenarios.append({'viewport':width,'steps':t.get('steps',[]),
|
| 48 |
'checks':[{k:v for k,v in c.items() if k not in ('value','viewport')} for c in checks]})
|
|
@@ -56,6 +61,6 @@ class BrowserRunner:
|
|
| 56 |
for j,c in enumerate(checks):
|
| 57 |
observed=actual['actual'][j] if actual and j<len(actual['actual']) else None
|
| 58 |
target=actual['baseline'][j] if actual and c['kind']=='unchanged' else c.get('value',True)
|
| 59 |
-
passed=bool(actual and not actual['error'] and j<len(actual['actual']) and observed
|
| 60 |
results.append({'scenario':i,'test':j,'passed':passed,'actual':observed,'error':actual['error'] if actual else 'syntax failure'})
|
| 61 |
return {'syntax_success':response['syntax_success'],'passed':bool(results) and all(r['passed'] for r in results),'tests':results,'candidate_timeout':response.get('candidate_timeout',False)}
|
|
|
|
| 2 |
from decimal import Decimal,InvalidOperation
|
| 3 |
|
| 4 |
|
| 5 |
+
def extract_code(text,preserve_indentation=False):
|
| 6 |
+
text=text.strip('\r\n') if preserve_indentation else text.strip()
|
| 7 |
+
# Closing fences must occupy their own line; backticks inside a string are code.
|
| 8 |
+
blocks=re.findall(r'^[ \t]*```[^\r\n`]*\r?\n(.*?)^[ \t]*```[ \t]*(?=\r?$)',text,re.S|re.M)
|
| 9 |
+
if len(blocks)==1:
|
| 10 |
+
body=blocks[0].rstrip('\r\n') if preserve_indentation else blocks[0].strip()
|
| 11 |
+
return body+'\n'
|
| 12 |
if len(blocks)>1:raise ValueError('Multiple code blocks are ambiguous')
|
| 13 |
+
if re.search(r'^[ \t]*```',text,re.M):raise ValueError('Unclosed code fence')
|
| 14 |
return text+'\n'
|
| 15 |
|
| 16 |
|
|
|
|
| 41 |
|
| 42 |
class BrowserRunner:
|
| 43 |
def evaluate(self,row,code,hidden,sandbox):
|
| 44 |
+
from runners.semantic import matches
|
| 45 |
scenarios=[];expected=[]
|
| 46 |
for t in hidden['tests']:
|
| 47 |
widths=sorted(set(c.get('viewport',800) for c in t['checks']))
|
| 48 |
for width in widths:
|
| 49 |
+
checks=[dict(c,kind='html_text') if row['language']=='html' and c['kind']=='text' else c
|
| 50 |
+
for c in t['checks'] if c.get('viewport',800)==width]
|
| 51 |
# Deliberately do not send expected values into the sandbox.
|
| 52 |
scenarios.append({'viewport':width,'steps':t.get('steps',[]),
|
| 53 |
'checks':[{k:v for k,v in c.items() if k not in ('value','viewport')} for c in checks]})
|
|
|
|
| 61 |
for j,c in enumerate(checks):
|
| 62 |
observed=actual['actual'][j] if actual and j<len(actual['actual']) else None
|
| 63 |
target=actual['baseline'][j] if actual and c['kind']=='unchanged' else c.get('value',True)
|
| 64 |
+
passed=bool(actual and not actual['error'] and j<len(actual['actual']) and matches(c,observed,target))
|
| 65 |
results.append({'scenario':i,'test':j,'passed':passed,'actual':observed,'error':actual['error'] if actual else 'syntax failure'})
|
| 66 |
return {'syntax_success':response['syntax_success'],'passed':bool(results) and all(r['passed'] for r in results),'tests':results,'candidate_timeout':response.get('candidate_timeout',False)}
|
runners/semantic.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Behavioral normalization for browser observations; never inspect solutions."""
|
| 2 |
+
from decimal import Decimal,InvalidOperation
|
| 3 |
+
import re
|
| 4 |
+
ASCII_SPACE=re.compile(r'[ \t\r\n\f]+')
|
| 5 |
+
BOOLEAN={'disabled','checked','selected','required','multiple','readonly','autofocus','open','reversed'}
|
| 6 |
+
CASE_INSENSITIVE={'method','dir','type','contenteditable','lang','enctype','formmethod'}
|
| 7 |
+
FLOATING={'max','min'}
|
| 8 |
+
INTEGER={'rows','cols','tabindex','colspan','rowspan','width','height'}
|
| 9 |
+
|
| 10 |
+
def matches(check,observed,target):
|
| 11 |
+
kind=check['kind']
|
| 12 |
+
if kind=='html_text':
|
| 13 |
+
if not isinstance(observed,dict) or 'text' not in observed:return False
|
| 14 |
+
text=observed['text']
|
| 15 |
+
if observed.get('white_space') in ('pre','pre-wrap','break-spaces'):
|
| 16 |
+
return text.replace('\r\n','\n')==target.replace('\r\n','\n')
|
| 17 |
+
if observed.get('white_space')=='pre-line':
|
| 18 |
+
collapse=lambda s:'\n'.join(re.sub(r'[ \t\f]+',' ',line).strip() for line in s.replace('\r\n','\n').split('\n'))
|
| 19 |
+
return collapse(text)==collapse(target)
|
| 20 |
+
return ASCII_SPACE.sub(' ',text).strip()==ASCII_SPACE.sub(' ',target).strip()
|
| 21 |
+
if kind!='attribute':return observed==target
|
| 22 |
+
if observed is not None and not isinstance(observed,str):return False
|
| 23 |
+
name=check['name'].lower()
|
| 24 |
+
if name=='class':return set((observed or '').split())==set((target or '').split())
|
| 25 |
+
if name in BOOLEAN:return (observed is not None)==(target is not None)
|
| 26 |
+
if name=='hidden':
|
| 27 |
+
def state(v):return 'absent' if v is None else 'until-found' if v.lower()=='until-found' else 'hidden'
|
| 28 |
+
return state(observed)==state(target)
|
| 29 |
+
if observed is None or target is None:return observed==target
|
| 30 |
+
if name in CASE_INSENSITIVE:return observed.lower()==target.lower()
|
| 31 |
+
if name in INTEGER:
|
| 32 |
+
a=re.match(r'^[ \t\r\n\f]*([+-]?[0-9]+)',observed)
|
| 33 |
+
b=re.match(r'^[ \t\r\n\f]*([+-]?[0-9]+)',target)
|
| 34 |
+
return bool(a and b and int(a.group(1))==int(b.group(1)))
|
| 35 |
+
if name in FLOATING or (name=='value' and re.search(r'\b(?:progress|meter)\b',check.get('selector',''))):
|
| 36 |
+
try:
|
| 37 |
+
a,b=Decimal(observed),Decimal(target)
|
| 38 |
+
if a.is_finite() and b.is_finite():return a==b
|
| 39 |
+
except (InvalidOperation,TypeError,ValueError):pass
|
| 40 |
+
return observed==target
|
sandbox/supervisor.py
CHANGED
|
@@ -40,12 +40,12 @@ def supervise(request, worker='/opt/smolscript/worker.py', worker_uid=None, work
|
|
| 40 |
browser=payload.get('diagnostic') or payload.get('kind') in ('html','css','dom')
|
| 41 |
limit=(candidate_seconds if candidate else startup_seconds) if browser else total_seconds
|
| 42 |
if now-phase_started>limit or now-started>total_seconds:
|
| 43 |
-
if candidate and state.get('syntax_success')
|
| 44 |
observations=list(state.get('observations',[]))
|
| 45 |
for _ in range(len(payload.get('scenarios',[]))-len(observations)):
|
| 46 |
observations.append({'actual':[],'baseline':[],
|
| 47 |
'error':'CandidateTimeout: browser execution exceeded its wall-time limit'})
|
| 48 |
-
return {'syntax_success':
|
| 49 |
stderr.seek(0)
|
| 50 |
detail=stderr.read(2000).decode('utf8','replace')
|
| 51 |
raise RuntimeError('SmolScript worker timed out during browser/runtime setup; evaluation incomplete; '
|
|
|
|
| 40 |
browser=payload.get('diagnostic') or payload.get('kind') in ('html','css','dom')
|
| 41 |
limit=(candidate_seconds if candidate else startup_seconds) if browser else total_seconds
|
| 42 |
if now-phase_started>limit or now-started>total_seconds:
|
| 43 |
+
if candidate and isinstance(state.get('syntax_success'),bool):
|
| 44 |
observations=list(state.get('observations',[]))
|
| 45 |
for _ in range(len(payload.get('scenarios',[]))-len(observations)):
|
| 46 |
observations.append({'actual':[],'baseline':[],
|
| 47 |
'error':'CandidateTimeout: browser execution exceeded its wall-time limit'})
|
| 48 |
+
return {'syntax_success':state['syntax_success'],'observations':observations,'candidate_timeout':True}
|
| 49 |
stderr.seek(0)
|
| 50 |
detail=stderr.read(2000).decode('utf8','replace')
|
| 51 |
raise RuntimeError('SmolScript worker timed out during browser/runtime setup; evaluation incomplete; '
|
sandbox/worker.py
CHANGED
|
@@ -10,11 +10,11 @@ import tempfile
|
|
| 10 |
from protocol import COMMANDS,wrap_source
|
| 11 |
|
| 12 |
|
| 13 |
-
def publish_state(phase,observations=None,scenario=None,operation=None):
|
| 14 |
path=os.environ.get('SMOLSCRIPT_WORKER_STATE')
|
| 15 |
if not path:return
|
| 16 |
target=Path(path);tmp=target.with_suffix('.tmp')
|
| 17 |
-
tmp.write_text(json.dumps({'phase':phase,'syntax_success':
|
| 18 |
'scenario':scenario,'operation':operation,'observations':observations or []}))
|
| 19 |
tmp.replace(target)
|
| 20 |
|
|
@@ -67,6 +67,7 @@ def observe(page,check):
|
|
| 67 |
return kind==='layout_column' ? Math.abs(x.x-y.x)<1 && y.y>=x.bottom : Math.abs(x.y-y.y)<1 && y.x>=x.right; }''',kind)
|
| 68 |
if kind=='exists':return loc.count()>0
|
| 69 |
if loc.count()!=1:return {'error':'selector must resolve to exactly one element','count':loc.count()}
|
|
|
|
| 70 |
if kind=='text':return loc.text_content()
|
| 71 |
if kind=='attribute':return loc.get_attribute(check['name'])
|
| 72 |
if kind=='value':return loc.input_value()
|
|
@@ -90,7 +91,11 @@ def browser(request):
|
|
| 90 |
kind=request['kind'];code=request['code']
|
| 91 |
if kind=='html':
|
| 92 |
import html5lib
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
syntax=not parser.errors
|
| 95 |
elif kind=='css':
|
| 96 |
import tinycss2
|
|
@@ -107,29 +112,31 @@ def browser(request):
|
|
| 107 |
else:
|
| 108 |
Path('candidate.js').write_text(code)
|
| 109 |
syntax=execute(['node','--check','candidate.js'],'',5)['exit_code']==0
|
| 110 |
-
if not syntax:return {'syntax_success':False,'observations':[]}
|
| 111 |
observations=[]
|
| 112 |
-
|
|
|
|
|
|
|
| 113 |
with sync_playwright() as p:
|
| 114 |
# Container namespace, seccomp, uid, cgroups and disabled networking are
|
| 115 |
# the mandatory boundary; no browser flag substitutes for that boundary.
|
| 116 |
-
|
| 117 |
b=p.chromium.launch(headless=True,timeout=20000,args=['--disable-dev-shm-usage'])
|
| 118 |
try:
|
| 119 |
for index,scenario in enumerate(request['scenarios']):
|
| 120 |
-
|
| 121 |
page=b.new_page(viewport={'width':scenario.get('viewport',800),'height':600},java_script_enabled=kind=='dom')
|
| 122 |
page.set_default_timeout(request['timeout_seconds']*1000)
|
| 123 |
page.route('**/*',lambda route:route.abort())
|
| 124 |
actual=[];baseline=[];error=None
|
| 125 |
-
|
| 126 |
page.set_content(request['fixture'],wait_until='domcontentloaded')
|
| 127 |
if request.get('base_css'):
|
| 128 |
-
|
| 129 |
inject_css(page,request['base_css'])
|
| 130 |
-
|
| 131 |
baseline=[observe(page,c) if c['kind']=='unchanged' else None for c in scenario['checks']]
|
| 132 |
-
|
| 133 |
try:
|
| 134 |
if kind=='html':page.set_content(code,wait_until='domcontentloaded')
|
| 135 |
elif kind=='css':inject_css(page,code)
|
|
@@ -146,13 +153,13 @@ def browser(request):
|
|
| 146 |
actual=[observe(page,c) for c in scenario['checks']]
|
| 147 |
except Exception as e:error=type(e).__name__+': '+str(e)[:500]
|
| 148 |
observations.append({'actual':actual,'baseline':baseline,'error':error})
|
| 149 |
-
|
| 150 |
page.close()
|
| 151 |
-
|
| 152 |
finally:
|
| 153 |
-
|
| 154 |
b.close()
|
| 155 |
-
return {'syntax_success':
|
| 156 |
|
| 157 |
|
| 158 |
def main():
|
|
|
|
| 10 |
from protocol import COMMANDS,wrap_source
|
| 11 |
|
| 12 |
|
| 13 |
+
def publish_state(phase,observations=None,scenario=None,operation=None,syntax_success=True):
|
| 14 |
path=os.environ.get('SMOLSCRIPT_WORKER_STATE')
|
| 15 |
if not path:return
|
| 16 |
target=Path(path);tmp=target.with_suffix('.tmp')
|
| 17 |
+
tmp.write_text(json.dumps({'phase':phase,'syntax_success':syntax_success,
|
| 18 |
'scenario':scenario,'operation':operation,'observations':observations or []}))
|
| 19 |
tmp.replace(target)
|
| 20 |
|
|
|
|
| 67 |
return kind==='layout_column' ? Math.abs(x.x-y.x)<1 && y.y>=x.bottom : Math.abs(x.y-y.y)<1 && y.x>=x.right; }''',kind)
|
| 68 |
if kind=='exists':return loc.count()>0
|
| 69 |
if loc.count()!=1:return {'error':'selector must resolve to exactly one element','count':loc.count()}
|
| 70 |
+
if kind=='html_text':return loc.evaluate('(e)=>({text:e.textContent,white_space:getComputedStyle(e).whiteSpace})')
|
| 71 |
if kind=='text':return loc.text_content()
|
| 72 |
if kind=='attribute':return loc.get_attribute(check['name'])
|
| 73 |
if kind=='value':return loc.input_value()
|
|
|
|
| 91 |
kind=request['kind'];code=request['code']
|
| 92 |
if kind=='html':
|
| 93 |
import html5lib
|
| 94 |
+
import re
|
| 95 |
+
parser=html5lib.HTMLParser()
|
| 96 |
+
document=re.match(r'(?is)\s*(?:<!--.*?-->\s*)*(?:<!doctype\s|<html(?:\s|>))',code)
|
| 97 |
+
if document:parser.parse(code)
|
| 98 |
+
else:parser.parseFragment(code)
|
| 99 |
syntax=not parser.errors
|
| 100 |
elif kind=='css':
|
| 101 |
import tinycss2
|
|
|
|
| 112 |
else:
|
| 113 |
Path('candidate.js').write_text(code)
|
| 114 |
syntax=execute(['node','--check','candidate.js'],'',5)['exit_code']==0
|
| 115 |
+
if not syntax and kind=='dom':return {'syntax_success':False,'observations':[]}
|
| 116 |
observations=[]
|
| 117 |
+
def state(phase,observations=None,scenario=None,operation=None):
|
| 118 |
+
publish_state(phase,observations,scenario,operation,syntax_success=syntax)
|
| 119 |
+
state('browser_startup',operation='playwright_driver')
|
| 120 |
with sync_playwright() as p:
|
| 121 |
# Container namespace, seccomp, uid, cgroups and disabled networking are
|
| 122 |
# the mandatory boundary; no browser flag substitutes for that boundary.
|
| 123 |
+
state('browser_startup',operation='chromium_launch')
|
| 124 |
b=p.chromium.launch(headless=True,timeout=20000,args=['--disable-dev-shm-usage'])
|
| 125 |
try:
|
| 126 |
for index,scenario in enumerate(request['scenarios']):
|
| 127 |
+
state('fixture_setup',observations,index,'new_page')
|
| 128 |
page=b.new_page(viewport={'width':scenario.get('viewport',800),'height':600},java_script_enabled=kind=='dom')
|
| 129 |
page.set_default_timeout(request['timeout_seconds']*1000)
|
| 130 |
page.route('**/*',lambda route:route.abort())
|
| 131 |
actual=[];baseline=[];error=None
|
| 132 |
+
state('fixture_setup',observations,index,'fixture_document')
|
| 133 |
page.set_content(request['fixture'],wait_until='domcontentloaded')
|
| 134 |
if request.get('base_css'):
|
| 135 |
+
state('fixture_setup',observations,index,'base_css')
|
| 136 |
inject_css(page,request['base_css'])
|
| 137 |
+
state('fixture_setup',observations,index,'baseline_observations')
|
| 138 |
baseline=[observe(page,c) if c['kind']=='unchanged' else None for c in scenario['checks']]
|
| 139 |
+
state('candidate',observations,index,'candidate_execution')
|
| 140 |
try:
|
| 141 |
if kind=='html':page.set_content(code,wait_until='domcontentloaded')
|
| 142 |
elif kind=='css':inject_css(page,code)
|
|
|
|
| 153 |
actual=[observe(page,c) for c in scenario['checks']]
|
| 154 |
except Exception as e:error=type(e).__name__+': '+str(e)[:500]
|
| 155 |
observations.append({'actual':actual,'baseline':baseline,'error':error})
|
| 156 |
+
state('candidate',observations[:-1],index,'page_close')
|
| 157 |
page.close()
|
| 158 |
+
state('fixture_setup',observations,index)
|
| 159 |
finally:
|
| 160 |
+
state('browser_cleanup',observations)
|
| 161 |
b.close()
|
| 162 |
+
return {'syntax_success':syntax,'observations':observations}
|
| 163 |
|
| 164 |
|
| 165 |
def main():
|
tests/test_completion.py
CHANGED
|
@@ -13,14 +13,17 @@ class CompletionTests(unittest.TestCase):
|
|
| 13 |
for row in self.rows:
|
| 14 |
text=prompt(row)
|
| 15 |
self.assertTrue(text.endswith(prefix(row)))
|
|
|
|
|
|
|
|
|
|
| 16 |
changed={**row,'reference_solution':'SECRET_REFERENCE','tests':[{'input':'SECRET_INPUT','expected':'SECRET_ANSWER'}]}
|
| 17 |
self.assertEqual(prompt(changed),text)
|
| 18 |
self.assertNotIn('Return code only',text)
|
| 19 |
self.assertNotIn('function function',text)
|
| 20 |
def test_python_has_no_type_annotation_boilerplate(self):
|
| 21 |
row=next(r for r in self.rows if r['language']=='python')
|
| 22 |
-
self.assertEqual(prefix(row),'def solve(n):\n
|
| 23 |
-
text=assemble(row,'return abs(2*n)%10\n\nQuestion: explain this code')
|
| 24 |
ast.parse(text);self.assertNotIn('Question:',text)
|
| 25 |
def test_every_reference_body_roundtrips_without_solution_repairs(self):
|
| 26 |
refs={r['id']:r['reference_solution'] for r in load(ROOT/'references/solutions.jsonl')}
|
|
@@ -28,7 +31,7 @@ class CompletionTests(unittest.TestCase):
|
|
| 28 |
lang=row['language'];ref=refs[row['id']]
|
| 29 |
if lang=='html':tail=ref[1:]
|
| 30 |
elif lang=='css':tail=ref
|
| 31 |
-
elif lang=='python':tail=ref.split('\n',1)[1]
|
| 32 |
else:
|
| 33 |
self.assertTrue(ref.startswith(prefix(row)),row['id'])
|
| 34 |
tail=ref[len(prefix(row)):]
|
|
@@ -52,11 +55,20 @@ class CompletionTests(unittest.TestCase):
|
|
| 52 |
def test_truncated_body_is_not_given_missing_braces(self):
|
| 53 |
row=next(r for r in self.rows if r['language']=='javascript')
|
| 54 |
self.assertFalse(assemble(row,'return 3;').rstrip().endswith('}'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def test_complete_function_and_fenced_output_are_accepted(self):
|
| 56 |
row=next(r for r in self.rows if r['language']=='python')
|
| 57 |
whole='def solve(n):\n return abs(n)\n'
|
| 58 |
self.assertEqual(assemble(row,whole),whole)
|
| 59 |
-
self.
|
|
|
|
|
|
|
| 60 |
self.assertEqual(assemble(row,'```python\n'+whole+'```'),whole)
|
| 61 |
with self.assertRaises(ValueError):assemble(row,'```python\nreturn n')
|
| 62 |
|
|
|
|
| 13 |
for row in self.rows:
|
| 14 |
text=prompt(row)
|
| 15 |
self.assertTrue(text.endswith(prefix(row)))
|
| 16 |
+
if row['language'] not in ('html','css'):
|
| 17 |
+
self.assertTrue(prefix(row).endswith('\n'))
|
| 18 |
+
self.assertFalse(text.endswith((' ', '\t')))
|
| 19 |
changed={**row,'reference_solution':'SECRET_REFERENCE','tests':[{'input':'SECRET_INPUT','expected':'SECRET_ANSWER'}]}
|
| 20 |
self.assertEqual(prompt(changed),text)
|
| 21 |
self.assertNotIn('Return code only',text)
|
| 22 |
self.assertNotIn('function function',text)
|
| 23 |
def test_python_has_no_type_annotation_boilerplate(self):
|
| 24 |
row=next(r for r in self.rows if r['language']=='python')
|
| 25 |
+
self.assertEqual(prefix(row),'def solve(n):\n')
|
| 26 |
+
text=assemble(row,' return abs(2*n)%10\n\nQuestion: explain this code')
|
| 27 |
ast.parse(text);self.assertNotIn('Question:',text)
|
| 28 |
def test_every_reference_body_roundtrips_without_solution_repairs(self):
|
| 29 |
refs={r['id']:r['reference_solution'] for r in load(ROOT/'references/solutions.jsonl')}
|
|
|
|
| 31 |
lang=row['language'];ref=refs[row['id']]
|
| 32 |
if lang=='html':tail=ref[1:]
|
| 33 |
elif lang=='css':tail=ref
|
| 34 |
+
elif lang=='python':tail=ref.split('\n',1)[1]
|
| 35 |
else:
|
| 36 |
self.assertTrue(ref.startswith(prefix(row)),row['id'])
|
| 37 |
tail=ref[len(prefix(row)):]
|
|
|
|
| 55 |
def test_truncated_body_is_not_given_missing_braces(self):
|
| 56 |
row=next(r for r in self.rows if r['language']=='javascript')
|
| 57 |
self.assertFalse(assemble(row,'return 3;').rstrip().endswith('}'))
|
| 58 |
+
def test_python_continuation_can_define_a_module_helper(self):
|
| 59 |
+
row=next(r for r in self.rows if r['language']=='python')
|
| 60 |
+
body=' return double(n)\n\ndef double(x):\n return 2*x\n'
|
| 61 |
+
code=assemble(row,body)
|
| 62 |
+
self.assertEqual([node.name for node in ast.parse(code).body],['solve','double'])
|
| 63 |
+
self.assertEqual(code,prefix(row)+body)
|
| 64 |
+
|
| 65 |
def test_complete_function_and_fenced_output_are_accepted(self):
|
| 66 |
row=next(r for r in self.rows if r['language']=='python')
|
| 67 |
whole='def solve(n):\n return abs(n)\n'
|
| 68 |
self.assertEqual(assemble(row,whole),whole)
|
| 69 |
+
self.assertEqual(assemble(row,'```python\n return abs(n)\n```'),whole)
|
| 70 |
+
self.assertIn('return "```"',assemble(row,'```python\n return "```"\n```'))
|
| 71 |
+
self.assertIn('return "```"',assemble(row,' return "```"'))
|
| 72 |
self.assertEqual(assemble(row,'```python\n'+whole+'```'),whole)
|
| 73 |
with self.assertRaises(ValueError):assemble(row,'```python\nreturn n')
|
| 74 |
|
tests/test_semantic.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.util
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import sys
|
| 4 |
+
import unittest
|
| 5 |
+
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT))
|
| 6 |
+
from runners.semantic import matches
|
| 7 |
+
from metrics import aggregate
|
| 8 |
+
|
| 9 |
+
class SemanticTests(unittest.TestCase):
|
| 10 |
+
def test_equivalent_attributes(self):
|
| 11 |
+
for name,observed,expected in [('hidden','hidden',''),('hidden','HIDDEN',''),('method','POST','post'),
|
| 12 |
+
('dir','RTL','rtl'),('contenteditable','TRUE','true'),('type','BUTTON','button'),
|
| 13 |
+
('rows','03','3'),('max','10.0','10'),('class','b a','a b'),('class','',None)]:
|
| 14 |
+
self.assertTrue(matches({'kind':'attribute','name':name},observed,expected),(name,observed))
|
| 15 |
+
def test_wrong_attributes_and_errors_rejected(self):
|
| 16 |
+
for name,observed,expected in [('hidden',None,''),('hidden','until-found',''),('method','GET','post'),
|
| 17 |
+
('name','Email','email'),('href','/Help','/help'),('rows','4','3'),('class','a extra','a'),('lang',{'error':'missing'},'en'),('value','01','1'),('rows','1e1','10')]:
|
| 18 |
+
self.assertFalse(matches({'kind':'attribute','name':name},observed,expected),(name,observed))
|
| 19 |
+
def test_html_visible_whitespace_and_inline_markup_text(self):
|
| 20 |
+
c={'kind':'html_text'}
|
| 21 |
+
self.assertTrue(matches(c,{'text':'\n Welcome\treader \n','white_space':'normal'},'Welcome reader'))
|
| 22 |
+
self.assertFalse(matches(c,{'text':'Welcome stranger','white_space':'normal'},'Welcome reader'))
|
| 23 |
+
self.assertFalse(matches(c,{'text':' x = 1 ','white_space':'pre'},'x = 1'))
|
| 24 |
+
self.assertFalse(matches(c,{'text':'Hello\nreader','white_space':'pre-line'},'Hello reader'))
|
| 25 |
+
self.assertTrue(matches({'kind':'attribute','name':'value','selector':'progress'},'4.0','4'))
|
| 26 |
+
self.assertFalse(matches({'kind':'text'},' Ab 9 ','Ab 9'))
|
| 27 |
+
def test_partial_credit_visible_without_claiming_solution(self):
|
| 28 |
+
rows=[{'id':'x','language':'python','passed':False,'syntax_success':True,
|
| 29 |
+
'tests':[{'passed':True},{'passed':False}]}]
|
| 30 |
+
result=aggregate(rows,['x'],full_run=False)
|
| 31 |
+
self.assertEqual(result['filtered_macro_score'],0)
|
| 32 |
+
self.assertEqual(result['hidden_test_pass_rate'],50)
|
| 33 |
+
def test_browser_behavior_can_pass_with_recoverable_parser_errors(self):
|
| 34 |
+
# Controlled fake browser: tests the worker's parse/behavior separation,
|
| 35 |
+
# without executing generated code or launching a host browser.
|
| 36 |
+
from unittest.mock import Mock,patch
|
| 37 |
+
from types import SimpleNamespace
|
| 38 |
+
import contextlib
|
| 39 |
+
sys.path.insert(0,str(ROOT/'runners'))
|
| 40 |
+
spec=importlib.util.spec_from_file_location('semantic_worker',ROOT/'sandbox/worker.py')
|
| 41 |
+
worker=importlib.util.module_from_spec(spec);spec.loader.exec_module(worker)
|
| 42 |
+
page=Mock();browser=Mock();browser.new_page.return_value=page
|
| 43 |
+
@contextlib.contextmanager
|
| 44 |
+
def playwright():yield SimpleNamespace(chromium=SimpleNamespace(launch=lambda **kw:browser))
|
| 45 |
+
modules={'playwright':SimpleNamespace(),'playwright.sync_api':SimpleNamespace(sync_playwright=playwright,TimeoutError=TimeoutError),
|
| 46 |
+
'tinycss2':SimpleNamespace(parse_stylesheet=lambda *a,**k:[SimpleNamespace(type='error')])}
|
| 47 |
+
with patch.dict(sys.modules,modules),patch.object(worker,'observe',return_value='rgb(10, 20, 30)'):
|
| 48 |
+
result=worker.browser({'kind':'css','code':'#x {color:rgb(10,20,30)} invalid;',
|
| 49 |
+
'fixture':'<p id="x">x</p>','timeout_seconds':3,'scenarios':[{'checks':[{'kind':'style','selector':'#x','property':'color'}]}]})
|
| 50 |
+
self.assertFalse(result['syntax_success']);self.assertIsNone(result['observations'][0]['error'])
|
| 51 |
+
self.assertEqual(result['observations'][0]['actual'],['rgb(10, 20, 30)'])
|
| 52 |
+
|
| 53 |
+
if __name__=='__main__':unittest.main()
|