Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Self-test of the task set: accept.py must FAIL on the bare seed, PASS on seed + reference/overlay, and never modify the workspace.
|
|
|
|
selftest.py [--vendor DIR] [ID ...] --vendor: directory holding the external seed files (three.module.min.js)
|
|
"""
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, os.path.join(HERE, "..", "delta"))
|
|
import taskfile # noqa: E402
|
|
|
|
|
|
def build(tid, overlay, vendor, dest):
|
|
seed = os.path.join(HERE, tid, "seed")
|
|
if os.path.isdir(seed):
|
|
shutil.copytree(seed, dest)
|
|
else:
|
|
os.makedirs(dest)
|
|
for rel, sha, _n in taskfile.read_task(HERE, tid)["externals"]:
|
|
src = os.path.join(vendor or "", rel)
|
|
if not os.path.isfile(src) or taskfile.sha256_file(src) != sha:
|
|
return "external file %s not available in --vendor" % rel
|
|
shutil.copy(src, os.path.join(dest, rel))
|
|
if overlay:
|
|
ov = os.path.join(HERE, tid, "reference", "overlay")
|
|
for root, _d, files in os.walk(ov):
|
|
for n in files:
|
|
p = os.path.join(root, n)
|
|
t = os.path.join(dest, os.path.relpath(p, ov))
|
|
os.makedirs(os.path.dirname(t), exist_ok=True)
|
|
shutil.copy(p, t)
|
|
return None
|
|
|
|
|
|
def accept(tid, ws):
|
|
t0 = time.time()
|
|
p = subprocess.run([sys.executable, os.path.join(HERE, tid, "accept.py"), ws], capture_output=True, text=True, timeout=900)
|
|
return p.returncode, p.stdout, round(time.time() - t0, 1)
|
|
|
|
|
|
def main():
|
|
args = sys.argv[1:]
|
|
vendor = None
|
|
if args[:1] == ["--vendor"]:
|
|
vendor, args = args[1], args[2:]
|
|
ids = args or taskfile.task_ids(HERE)
|
|
bad = 0
|
|
for tid in ids:
|
|
res = []
|
|
for overlay in (False, True):
|
|
tmp = tempfile.mkdtemp(prefix="selftest-")
|
|
try:
|
|
ws = os.path.join(tmp, "ws")
|
|
err = build(tid, overlay, vendor, ws)
|
|
if err:
|
|
res.append("SKIP (%s)" % err)
|
|
continue
|
|
before = taskfile.workspace_lines(ws)
|
|
rc, out, secs = accept(tid, ws)
|
|
after = taskfile.workspace_lines(ws)
|
|
same = before == after
|
|
ok = (rc != 0) if not overlay else (rc == 0)
|
|
res.append("%s rc=%d %.1fs%s" % ("ok" if ok else "WRONG", rc, secs, "" if same else " WORKSPACE MODIFIED"))
|
|
if not ok or not same:
|
|
bad += 1
|
|
print(out[-1500:])
|
|
finally:
|
|
shutil.rmtree(tmp, ignore_errors=True)
|
|
print("%-18s seed: %-28s seed+overlay: %s" % (tid, res[0], res[1]))
|
|
print("selftest: %s" % ("FAILED" if bad else "all good"))
|
|
sys.exit(1 if bad else 0)
|
|
|
|
|
|
main()
|