Preserve structured diagnostics, source attribution, phase outcomes and revision context through compiler, Studio, LSP, MCP and JavaFX. Add project service discovery and resilient VS Code reconnection. Correct all eight reproduced PBS production failures in expression context, sibling executable bindings and nominal owner identity. Consolidate specs, lessons, immutable baseline evidence and the maintained source-to-guest qualification runner. Validation: required Gradle gate recorded 724 tests, with 711 passed and 13 skipped. Full corpus passed 168 compilation observations and 108 guest runs (104 successes and four deliberate faults); supplemental controls passed 42 compilations and 16 guest runs. TypeScript compilation, two Node discovery tests and discussion validation passed.
179 lines
15 KiB
Python
179 lines
15 KiB
Python
#!/usr/bin/env python3
|
|
"""Research corpus for AGD-0113. Only writes evidence and isolated scratch projects."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
ROOT = HERE.parents[3]
|
|
INSTALL = ROOT / "prometeu-app/build/install/prometeu-app"
|
|
JAVA = INSTALL / "runtime/bin/java"
|
|
JAVAC = INSTALL / "runtime/bin/javac"
|
|
MANIFEST = {"name": "caseapp", "version": "1.0.0", "language": "pbs", "stdlib": "1", "target": "Game", "dependencies": []}
|
|
|
|
|
|
def digest(data):
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
|
|
def corpus():
|
|
cases = []
|
|
|
|
def add(case_id, family, description, files, control=None, expected="compiled", runtime="passed"):
|
|
files = {"prometeu.json": json.dumps(MANIFEST, indent=2) + "\n", **files}
|
|
cases.append({"id": case_id, "family": family, "description": description,
|
|
"control": control, "expectedCompile": expected, "expectedRuntime": runtime,
|
|
"files": files, "sourceSha256": digest(json.dumps(files, sort_keys=True).encode())})
|
|
|
|
def one(case_id, family, description, body, control=None):
|
|
add(case_id, family, description, {"src/mod.barrel": "pub fn frame() -> void;\n", "src/main.pbs": body}, control)
|
|
|
|
check = "[Frame] fn frame() -> void { if !check() { let failure=1/0; } }\n"
|
|
data = "declare struct Probe() { fn value() -> int { return 1; } }\ndeclare global data: Probe = new Probe();\n"
|
|
one("F1-local", "call-comparison-return", "Control: method result materialized before comparison", data + "fn check() -> bool { let value=data.value(); return value!=0; }\n" + check)
|
|
one("F1-direct", "call-comparison-return", "Method call compared directly in returned expression", data + "fn check() -> bool { return data.value()!=0; }\n" + check, "F1-local")
|
|
one("F1-two-calls", "call-comparison-return", "Two method calls as comparison operands", data + "fn check() -> bool { return data.value()==data.value(); }\n" + check, "F1-local")
|
|
service = "declare service Probe { fn value() -> int { return 1; } fn check() -> bool { return this.value()!=0; } }\n"
|
|
one("F1-service-this", "call-comparison-return", "Service receiver this inside a returned comparison", service + "[Frame] fn frame() -> void { if !Probe.check() { let failure=1/0; } }\n", "F1-local")
|
|
one("F1-service-local", "call-comparison-return", "Control: identical service call materialized before returned comparison", service.replace("return this.value()!=0;", "let value=this.value(); return value!=0;") + "[Frame] fn frame() -> void { if !Probe.check() { let failure=1/0; } }\n")
|
|
one("F1-condition", "call-comparison-return", "Control: direct method comparison in an if condition", data + "[Frame] fn frame() -> void { if data.value()!=1 { let failure=1/0; } }\n")
|
|
|
|
effects = "declare global calls: int=0;\nfn next() -> int { calls+=1; return calls; }\nfn add(a: int,b: int) -> int { return a+b; }\n"
|
|
one("F2-locals", "nested-call-expression", "Control: effectful call arguments stored in locals", effects + "[Frame] fn frame() -> void { calls=0; let a=next(); let b=next(); let value=add(a,b); if value!=3 || calls!=2 { let failure=1/0; } }\n")
|
|
one("F2-arguments", "nested-call-expression", "Effectful call arguments evaluate once, left to right", effects + "[Frame] fn frame() -> void { calls=0; let value=add(next(),next()); if value!=3 || calls!=2 { let failure=1/0; } }\n", "F2-locals")
|
|
one("F2-expression", "nested-call-expression", "Effectful calls nested inside arithmetic argument", effects + "[Frame] fn frame() -> void { calls=0; let value=add(next()+next(),next()); if value!=6 || calls!=3 { let failure=1/0; } }\n", "F2-locals")
|
|
one("F2-struct-method", "nested-call-expression", "Struct method used as another method argument", data + "fn add(a: int,b: int) -> int { return a+b; }\n[Frame] fn frame() -> void { let value=add(data.value(),data.value()); if value!=2 { let failure=1/0; } }\n", "F2-locals")
|
|
|
|
one("F3-single-file", "same-module-files", "Control: function and caller in the same file", "fn increment(value: int) -> int { return value+1; }\n[Frame] fn frame() -> void { let value=increment(2); if value!=3 { let failure=1/0; } }\n")
|
|
add("F3-function", "same-module-files", "mod function called from another file", {"src/mod.barrel": "pub fn frame() -> void;\nmod fn increment(value: int) -> int;\n", "src/helpers.pbs": "fn increment(value: int) -> int { return value+1; }\n", "src/main.pbs": "[Frame] fn frame() -> void { let value=increment(2); if value!=3 { let failure=1/0; } }\n"}, "F3-single-file")
|
|
add("F3-global", "same-module-files", "mod global mutated from another file", {"src/mod.barrel": "pub fn frame() -> void;\nmod global count;\n", "src/state.pbs": "declare global count: int=0;\n", "src/main.pbs": "[Frame] fn frame() -> void { count=4; if count!=4 { let failure=1/0; } }\n"})
|
|
add("F3-service", "same-module-files", "mod service called from another file", {"src/mod.barrel": "pub fn frame() -> void;\nmod service Helper;\n", "src/helpers.pbs": "declare service Helper { fn value() -> int { return 3; } }\n", "src/main.pbs": "[Frame] fn frame() -> void { let value=Helper.value(); if value!=3 { let failure=1/0; } }\n"})
|
|
one("F3-global-local", "same-module-files", "Control: identical global and caller in the same file", "declare global count: int=0;\n[Frame] fn frame() -> void { count=4; if count!=4 { let failure=1/0; } }\n")
|
|
one("F3-service-local", "same-module-files", "Control: identical service and caller in the same file", "declare service Helper { fn value() -> int { return 3; } }\n[Frame] fn frame() -> void { let value=Helper.value(); if value!=3 { let failure=1/0; } }\n")
|
|
add("F3-file-private", "same-module-files", "Negative control: function absent from barrel stays file-private", {"src/mod.barrel": "pub fn frame() -> void;\n", "src/helpers.pbs": "fn increment(value: int) -> int { return value+1; }\n", "src/main.pbs": "[Frame] fn frame() -> void { let value=increment(2); }\n"}, "F3-function", expected="rejected", runtime="not_run")
|
|
|
|
def rooms(case_id, name_a, name_b, dependency, direct=False):
|
|
a_import = "import { B } from @caseapp:b;\n" if dependency else ""
|
|
a_return = "let own=room.value(); let other=B.value(); return own+other;" if dependency else "let own=room.value(); return own;"
|
|
if direct:
|
|
a_return = "return room.value()+B.value();" if dependency else "return room.value();"
|
|
expected = 3 if dependency else 1
|
|
files = {"src/mod.barrel": "pub fn frame() -> void;\n", "src/main.pbs": f"import {{ A }} from @caseapp:a;\nimport {{ B }} from @caseapp:b;\n[Frame] fn frame() -> void {{ let value=A.value(); if value!={expected} {{ let failure=1/0; }} let other=B.value(); if other!=2 {{ let failure=1/0; }} }}\n"}
|
|
for module, service_name, typ, value in [("a", "A", name_a, 1), ("b", "B", name_b, 2)]:
|
|
files[f"src/{module}/mod.barrel"] = f"pub service {service_name};\nmod struct {typ};\n"
|
|
files[f"src/{module}/data.pbs"] = f"declare struct {typ}() {{ fn value() -> int {{ return {value}; }} }}\n"
|
|
method = a_return if module == "a" else "return room.value();"
|
|
files[f"src/{module}/main.pbs"] = (a_import if module == "a" else "") + f"declare global room: {typ} = new {typ}();\ndeclare service {service_name} {{ fn value() -> int {{ {method} }} }}\n"
|
|
add(case_id, "homonymous-types", f"Types {name_a}/{name_b}; dependency={dependency}; direct={direct}", files,
|
|
None if case_id == "F4-distinct" else "F4-distinct")
|
|
|
|
rooms("F4-distinct", "ARoomData", "BRoomData", True)
|
|
rooms("F4-same-no-dependency", "RoomData", "RoomData", False)
|
|
rooms("F4-same-dependency", "RoomData", "RoomData", True)
|
|
rooms("F4-rename-a", "StartRoomData", "RoomData", True)
|
|
rooms("F4-same-direct", "RoomData", "RoomData", True, True)
|
|
alias_case = {"src/mod.barrel": "pub fn frame() -> void;\n", "src/main.pbs": "import { RoomData as LeftData } from @caseapp:a;\nimport { RoomData as RightData } from @caseapp:b;\ndeclare global left: LeftData = new LeftData(1);\ndeclare global right: RightData = new RightData(2);\n[Frame] fn frame() -> void { let a=left.value(); let b=right.value(); if a!=1 || b!=2 { let failure=1/0; } }\n"}
|
|
for module in ("a", "b"):
|
|
alias_case[f"src/{module}/mod.barrel"] = "pub struct RoomData;\n"
|
|
alias_case[f"src/{module}/main.pbs"] = "declare struct RoomData(number: int) { fn value() -> int { return this.number; } }\n"
|
|
add("F4-public-aliases", "homonymous-types", "Two distinct nominal RoomData declarations imported with aliases", alias_case, "F4-distinct")
|
|
|
|
def imported(case_id, type_name, alias=None, positional=False):
|
|
local = alias or type_name
|
|
ctor = f"new {local}(10)" if positional else f"new {local}.make(10)"
|
|
imported_name = f"{type_name} as {alias}" if alias else type_name
|
|
files = {"src/mod.barrel": "pub fn frame() -> void;\n",
|
|
"src/main.pbs": f"import {{ {imported_name} }} from @caseapp:scene;\nimport {{ Link }} from @caseapp:link;\ndeclare global scene: {local} = {ctor};\n[Frame] fn frame() -> void {{ let value=Link.read(scene); if value!=10 {{ let failure=1/0; }} }}\n",
|
|
"src/scene/mod.barrel": f"pub struct {type_name};\n",
|
|
"src/scene/main.pbs": f"declare struct {type_name}(value: int) {{ ctor make(value: int) {{ this.value=value; }} fn read() -> int {{ return this.value; }} }}\n",
|
|
"src/link/mod.barrel": "pub service Link;\n",
|
|
"src/link/main.pbs": f"import {{ {type_name} }} from @caseapp:scene;\ndeclare service Link {{ fn read(scene: {type_name}) -> int {{ return scene.read(); }} }}\n"}
|
|
add(case_id, "imported-struct-construction", f"Imported {type_name}, alias={alias}, positional={positional}", files,
|
|
None if case_id == "F5-shopvisit" else "F5-shopvisit")
|
|
|
|
imported("F5-shopvisit", "ShopVisit")
|
|
imported("F5-scene", "Scene")
|
|
imported("F5-scene-alias", "Scene", "WorldScene")
|
|
imported("F5-scene-positional", "Scene", positional=True)
|
|
one("runtime-trap-control", "harness-control", "Deliberate guest fault proves frame assertions are executed", "[Frame] fn frame() -> void { let failure=1/0; }\n")
|
|
cases[-1]["expectedRuntime"] = "fault"
|
|
for case in cases:
|
|
if case["id"] == "F1-service-this": case["control"] = "F1-service-local"
|
|
if case["id"] == "F3-global": case["control"] = "F3-global-local"
|
|
if case["id"] == "F3-service": case["control"] = "F3-service-local"
|
|
return cases
|
|
|
|
|
|
def classpath(mode):
|
|
installed = str(INSTALL / "lib/*")
|
|
if mode == "installed":
|
|
return installed
|
|
modules = ["prometeu-infra", "prometeu-animation", "prometeu-compiler/prometeu-compiler-core",
|
|
"prometeu-compiler/prometeu-frontend-api", "prometeu-compiler/frontends/prometeu-frontend-pbs",
|
|
"prometeu-compiler/prometeu-frontend-registry", "prometeu-compiler/prometeu-deps",
|
|
"prometeu-compiler/prometeu-build-pipeline"]
|
|
entries = [str(ROOT / m / suffix) for m in modules for suffix in ["build/classes/java/main", "build/resources/main"]
|
|
if (ROOT / m / suffix).exists()]
|
|
return os.pathsep.join(entries + [installed])
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--mode", choices=["checkout", "installed"], default="checkout")
|
|
parser.add_argument("--select", help="Comma-separated case IDs; default is the full corpus")
|
|
parser.add_argument("--public", action="store_true", help="Also check the production public compile entrypoint")
|
|
args = parser.parse_args()
|
|
cases = corpus()
|
|
(HERE / "cases.json").write_text(json.dumps({"schemaVersion": 1, "cases": cases}, indent=2) + "\n")
|
|
selected = set(args.select.split(",")) if args.select else None
|
|
if selected:
|
|
assert selected <= {c["id"] for c in cases}, selected
|
|
cases = [c for c in cases if c["id"] in selected]
|
|
scratch = Path(tempfile.mkdtemp(prefix=f"agd113-{args.mode}-"))
|
|
cp = classpath(args.mode)
|
|
subprocess.run([str(JAVAC), "-proc:none", "-cp", cp, "-d", str(scratch / "classes"), str(HERE / "Agd113Probe.java")], check=True)
|
|
report_dir = HERE / "reports" / args.mode
|
|
report_dir.mkdir(parents=True, exist_ok=True)
|
|
prior = json.loads((report_dir / "summary.json").read_text()) if (report_dir / "summary.json").exists() else {}
|
|
summary = {"schemaVersion": 1, "mode": args.mode, "scratch": str(scratch), "cases": prior.get("cases", [])}
|
|
for case in cases:
|
|
for optimization in ["optimized", "unoptimized"]:
|
|
for public in ([False, True] if args.public and optimization == "optimized" else [False]):
|
|
suffix = optimization + ("-public" if public else "")
|
|
project = scratch / case["id"] / suffix
|
|
for path, source in case["files"].items():
|
|
target = project / path
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text(source)
|
|
report = report_dir / f"{case['id']}-{suffix}.json"
|
|
cmd = [str(JAVA), "-cp", os.pathsep.join([str(scratch / "classes"), cp]), "Agd113Probe", str(project), optimization, str(report)]
|
|
if public:
|
|
cmd.append("public")
|
|
started = time.monotonic()
|
|
completed = subprocess.run(cmd, cwd=scratch, capture_output=True, text=True, timeout=50)
|
|
if completed.returncode:
|
|
report.write_text(json.dumps({"status": "probe_failure", "returncode": completed.returncode,
|
|
"stdout": completed.stdout, "stderr": completed.stderr}, indent=2) + "\n")
|
|
result = json.loads(report.read_text())
|
|
result["caseId"] = case["id"]
|
|
result["sourceSha256"] = case["sourceSha256"]
|
|
result["durationSeconds"] = round(time.monotonic() - started, 3)
|
|
result["stderr"] = completed.stderr
|
|
report.write_text(json.dumps(result, indent=2) + "\n")
|
|
summary["cases"] = [i for i in summary["cases"] if (i["id"], i["optimization"], i["public"]) != (case["id"], optimization, public)]
|
|
summary["cases"].append({"id": case["id"], "optimization": optimization, "public": public,
|
|
"expectedCompile": case["expectedCompile"], "status": result["status"],
|
|
"report": str(report.relative_to(HERE))})
|
|
print(args.mode, case["id"], suffix, result["status"], flush=True)
|
|
(report_dir / "summary.json").write_text(json.dumps(summary, indent=2) + "\n")
|
|
print("Scratch:", scratch, flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|