Files
cookbook/tools/tests/test_cookbook.py
T
ClaudeandClaude Opus 5.5 4673f0afb6
ci / check (push) Successful in 32s
Arc LLM Cookbook: recipes, validator, site, demo content
Recipes for running the bench-standard models fastest on Intel Arc GPUs,
each backed by a bench.sh result folder in results/. tools/cookbook.py
validates recipes against their runs and generates the number tables
and site/index.html. All results are synthetic DEMO data so far, made by
tools/demo/make_demo.py; nothing has been measured yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 15:34:00 +01:00

136 lines
4.9 KiB
Python

"""cookbook.py: command matching, generated blocks, Markdown, and validate on
copies of this repo with one thing broken."""
import json
import os
import shutil
import sys
from pathlib import Path
import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import cookbook # noqa: E402
RECIPE = "recipes/qwen3.8-27b/arc-pro-b65/vllm-single-user.md"
def test_command_words_ignores_layout_and_comments():
a = "docker run --rm \\\n -e A=1 img \\\n --flag 'x y'\n"
b = "# start it\ndocker run --rm -e A=1 img --flag 'x y'"
assert cookbook.command_words(a) == cookbook.command_words(b)
assert cookbook.command_words("x --flag 1") != cookbook.command_words("x --flag 2")
def test_command_words_redacts_like_bench_sh():
assert cookbook.command_words("HF_TOKEN=abc vllm serve m --api-key s3cret") == \
["HF_TOKEN=<redacted>", "vllm", "serve", "m", "--api-key", "<redacted>"]
def test_slug_matches_bench_sh():
assert cookbook.slug("Arc Pro B65") == "arc-pro-b65"
assert cookbook.slug("llama.cpp") == "llama.cpp"
assert cookbook.slug("Qwen3.8-27B") == "qwen3.8-27b"
def test_fill_replaces_only_the_block():
text = "a\n<!-- cookbook:x -->\nold\n<!-- /cookbook:x -->\nb\n"
assert cookbook.fill(text, "x", "new") == "a\n<!-- cookbook:x -->\nnew\n<!-- /cookbook:x -->\nb\n"
with pytest.raises(ValueError):
cookbook.fill(text, "y", "new")
def test_launch_block_takes_the_first_sh_block_under_launch():
body = "## Requirements\n```sh\nnot this\n```\n## Launch\ntext\n```sh\nthis\n```\n```sh\nnor this\n```\n"
assert cookbook.launch_block(body) == "this\n"
assert cookbook.launch_block("## Other\n```sh\nx\n```\n") is None
def test_md_to_html():
out = cookbook.md_to_html("## Head\n\n| a | b |\n|---|---|\n| `x` | [l](u.md) |\n\n- one\n- **two**\n\n"
"```sh\n<cmd>\n```\n", link=lambda u: "L:" + u)
assert '<h2 id="head">Head</h2>' in out
assert "<td><code>x</code></td>" in out and '<a href="L:u.md">l</a>' in out
assert "<ul><li>one</li><li><strong>two</strong></li></ul>" in out
assert "<pre><code>&lt;cmd&gt;</code></pre>" in out
# ---------------------------------------------------------------- the repo itself
def test_repo_validates_and_is_built():
cb = cookbook.Cookbook()
assert cb.errors == []
for path, text in cb.outputs().items():
assert path.read_text(encoding="utf-8") == text, f"{path} is out of date: run cookbook.py build"
def test_verified_needs_two_submitters():
cb = cookbook.Cookbook()
status = {r["id"]: r["status"] for r in cb.recipes}
assert status["qwen3.8-27b/arc-pro-b65/vllm-single-user"] == "verified by 2"
assert status["qwen3.8-27b/arc-pro-b65/vllm-throughput"] == "one submitter"
# ---------------------------------------------------------------- broken copies
@pytest.fixture
def repo(tmp_path):
root = tmp_path / "cookbook"
shutil.copytree(cookbook.ROOT, root, ignore=shutil.ignore_patterns(".git", "__pycache__", "*.html"))
for d in (root / "results").iterdir(): # validate only needs the reports to exist
if d.is_dir():
(d / f"{d.name}.html").touch()
return root
def edit(path, old, new):
text = path.read_text(encoding="utf-8")
assert old in text
path.write_text(text.replace(old, new, 1), encoding="utf-8")
def errors(root):
return "\n".join(cookbook.Cookbook(root).errors)
def test_copy_is_clean(repo):
assert errors(repo) == ""
def test_quick_run_cannot_back_a_recipe(repo):
edit(repo / RECIPE, '"261026_demo-2_qwen3.8-27b_vllm_1x-arc-pro-b65"',
'"261022_demo_qwen3.8-27b_vllm_1x-arc-pro-b65_quick_2"')
assert "is a quick run" in errors(repo)
def test_declared_values_must_match(repo):
edit(repo / RECIPE, 'kv = "fp16"', 'kv = "fp8"')
assert "kv is 'fp8' in the recipe but 'fp16' in the run" in errors(repo)
def test_launch_command_must_be_the_benchmarked_one(repo):
edit(repo / RECIPE, "--max-num-seqs 1", "--max-num-seqs 2")
assert "server-cmd.txt is not the recipe's launch command" in errors(repo)
def test_only_arc_gpus(repo):
edit(repo / RECIPE, 'gpu = "Arc Pro B65"', 'gpu = "RTX 4090"')
e = errors(repo)
assert "not an Intel Arc GPU" in e and "should be recipes/" in e
def test_edited_results_are_caught(repo):
d = repo / "results" / "261022_demo_qwen3.8-27b_vllm_1x-arc-pro-b65"
meta = json.loads((d / "meta.json").read_text(encoding="utf-8"))
meta["notes"]["spec"] = "none"
(d / "meta.json").write_text(json.dumps(meta), encoding="utf-8")
assert "differ (edited?)" in errors(repo)
def test_placeholder_digest_only_for_demo(repo):
(repo / "results" / "261019_demo_qwen3.5-9b_llama.cpp_1x-arc-pro-b65" / "DEMO").unlink()
e = errors(repo)
assert "all-zero placeholder" in e
def test_tried_needs_an_existing_result(repo):
edit(repo / "tried/qwen3.5-9b/arc-pro-b65.md", "_quick_2", "_quick_9")
assert "is not in results/" in errors(repo)