Baseline: tree as shared
This commit is contained in:
1679 files changed
+1024562
No files matched your search
@@ -0,0 +1,96 @@
|
||||
"""Mojo Quest: 85 tickets, each a completed solution and a broken starter.
|
||||
|
||||
Mojo Quest checks every solution and starter against the real compiler in its
|
||||
own CI, so this is the most trustworthy behavioural corpus there is: each
|
||||
solution must compile, run, exit 0 and print exactly its expected output (or,
|
||||
for `source` tickets, contain an idiom), and each starter must fail that check.
|
||||
|
||||
The ticket data lives in a TypeScript module (src/data/issues.ts). Node reads
|
||||
it with type stripping (Node 22.6 or newer); nothing is re-implemented here.
|
||||
|
||||
Writes:
|
||||
quest/manifest.json one item per solution and per starter
|
||||
quest/solutions/<id>.mojo verbatim from exercises/, licence header included
|
||||
quest/starters/<id>.mojo the starter text from issues.ts
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from ..common import PipelineError, dialect_flags, write_json, write_text
|
||||
from . import Context, fresh_dir
|
||||
|
||||
NAME = "quest"
|
||||
SOURCE = "mojo-quest"
|
||||
INPUTS = ["src/data/issues.ts", "exercises"]
|
||||
|
||||
_DUMP = """
|
||||
const m = await import(process.argv[1]);
|
||||
process.stdout.write(JSON.stringify(m.issues));
|
||||
"""
|
||||
|
||||
|
||||
def load_issues(root) -> list[dict]:
|
||||
node = shutil.which("node")
|
||||
if not node:
|
||||
raise PipelineError("the quest processor needs Node 22.6+ on PATH (Mojo Quest keeps its tickets in TypeScript)")
|
||||
issues_ts = root / "src" / "data" / "issues.ts"
|
||||
proc = subprocess.run(
|
||||
[node, "--experimental-strip-types", "--no-warnings", "--input-type=module", "-e", _DUMP, issues_ts.as_uri()],
|
||||
capture_output=True, text=True, timeout=120,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
raise PipelineError(f"node could not load {issues_ts.name}: {proc.stderr.strip()[:400]}")
|
||||
data = json.loads(proc.stdout)
|
||||
if not isinstance(data, list) or not data:
|
||||
raise PipelineError("issues.ts exported no issues")
|
||||
return data
|
||||
|
||||
|
||||
def check_of(validation: dict) -> dict:
|
||||
if validation.get("kind") == "run":
|
||||
return {"stdout": validation["expectedStdout"]}
|
||||
if validation.get("kind") == "source":
|
||||
return {"patterns": list(validation["patterns"]), "flags": validation.get("flags", ""), "message": validation.get("message", "")}
|
||||
raise PipelineError(f"unknown Mojo Quest validation kind {validation.get('kind')!r}")
|
||||
|
||||
|
||||
def run(ctx: Context) -> dict:
|
||||
out = fresh_dir(NAME)
|
||||
issues = load_issues(ctx.root)
|
||||
items = []
|
||||
missing = []
|
||||
for issue in issues:
|
||||
iid = issue["id"]
|
||||
stem = iid.replace("-", "_")
|
||||
sol = ctx.root / "exercises" / f"{stem}.mojo"
|
||||
check = check_of(issue["validation"])
|
||||
meta = {k: issue.get(k) for k in ("concept", "title", "topic", "docUrl", "file", "hint")}
|
||||
if sol.exists():
|
||||
text = sol.read_text(encoding="utf-8")
|
||||
write_text(out / "solutions" / f"{stem}.mojo", text)
|
||||
items.append({
|
||||
"id": f"quest/{iid}/solution", "file": f"solutions/{stem}.mojo", "mode": "run",
|
||||
"expect": {"kind": "pass", "check": check}, "dialect": dialect_flags(text, ctx.pin),
|
||||
"meta": meta, "provenance": ctx.prov(f"exercises/{stem}.mojo"),
|
||||
})
|
||||
else:
|
||||
missing.append(iid)
|
||||
starter = issue.get("starter")
|
||||
if starter:
|
||||
write_text(out / "starters" / f"{stem}.mojo", starter)
|
||||
items.append({
|
||||
"id": f"quest/{iid}/starter", "file": f"starters/{stem}.mojo", "mode": "run",
|
||||
"expect": {"kind": "fail", "check": check}, "dialect": dialect_flags(starter, ctx.pin),
|
||||
"meta": meta, "provenance": ctx.prov(f"src/data/issues.ts#{iid}"),
|
||||
})
|
||||
if missing:
|
||||
ctx.warn(f"quest: {len(missing)} ticket(s) have no solution file: {', '.join(missing[:8])}")
|
||||
write_json(out / "manifest.json", {"processor": NAME, "items": items})
|
||||
kinds = {}
|
||||
for i in items:
|
||||
kinds[i["expect"]["kind"]] = kinds.get(i["expect"]["kind"], 0) + 1
|
||||
return {"tickets": len(issues), "items": len(items), "byExpectation": kinds,
|
||||
"runChecks": sum(1 for i in issues if i["validation"]["kind"] == "run")}
|
||||
Reference in new issue
Block a user