tests: verify the closed Analysis boundary with independent consumers
Add black-box tests for exact source/AST projection, complete heading scopes, explicit reference states, output safety (input/symlink/hardlink/directory and owner-only bytes), Observation digest binding, multi-entry snapshot context and the protocol mutation gate. Upgrade the Python consumer into a full independent semantic validator, add view/lint/knowledge consumer fixtures driven by the real CLI, and run schema plus semantic mutation checks from validate_protocols.
This commit is contained in:
1 parent
99789616a4
commit
6d4209bf32
8 files changed
+1332
-67
No files matched your search
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Lint-like independent consumer of public references and diagnostics.
|
||||
|
||||
Reports unresolved/ambiguous/out-of-scope links with their exact module and
|
||||
source span. It never reads a private AST/IR and never fixes a reference.
|
||||
|
||||
usage: lint_consumer.py ANALYSIS.json
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def line_col(source, span):
|
||||
prefix = source.encode("utf-8")[: span["start"]].decode("utf-8")
|
||||
line = prefix.count("\n") + 1
|
||||
column = len(prefix.rsplit("\n", 1)[-1]) + 1
|
||||
return line, column
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) != 2:
|
||||
raise SystemExit("usage: lint_consumer.py ANALYSIS.json")
|
||||
with open(argv[1], encoding="utf-8") as handle:
|
||||
analysis = json.load(handle)
|
||||
if analysis.get("schema") != "marqdo.analysis":
|
||||
raise SystemExit("lint: unexpected analysis schema")
|
||||
modules = {module["id"]: module for module in analysis["modules"]}
|
||||
problems = 0
|
||||
for module in analysis["modules"]:
|
||||
source = module["source"]
|
||||
for reference in module["references"]:
|
||||
state = reference["state"]
|
||||
if state in ("resolved", "external"):
|
||||
continue
|
||||
line, column = line_col(source, reference["span"])
|
||||
print(
|
||||
f"lint: {reference['url']} state={state} "
|
||||
f"{module['relative_path']}:{line}:{column}"
|
||||
)
|
||||
if state in ("ambiguous",):
|
||||
print("lint: candidates=" + ",".join(reference["candidates"]))
|
||||
problems += 1
|
||||
for diagnostic in analysis["diagnostics"]:
|
||||
if diagnostic["severity"] != "error":
|
||||
continue
|
||||
raise SystemExit(
|
||||
"lint: a successful artifact must not contain an error diagnostic"
|
||||
)
|
||||
for diagnostic in analysis["diagnostics"]:
|
||||
module = modules[diagnostic["module"]]
|
||||
span = diagnostic["span"]
|
||||
location = module["relative_path"]
|
||||
if span is not None:
|
||||
line, column = line_col(module["source"], span)
|
||||
location = f"{location}:{line}:{column}"
|
||||
print(f"lint: {diagnostic['code']} {location}")
|
||||
print(f"lint: unresolved={problems}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
Reference in new issue
Block a user