@andresmassello/uscha 1.73.0 → 1.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +1 -1
- package/uscha-kit/.claude/skills/uscha-devloop/qa_ledger.py +176 -0
- package/uscha-kit/.claude-plugin/plugin.json +2 -2
- package/uscha-kit/.codex-plugin/plugin.json +1 -1
- package/uscha-kit/README.md +1 -1
- package/uscha-kit/VERSION +1 -1
- package/uscha-kit/reports/junit/.bootstrap-cases.json +1 -0
- package/uscha-kit/skills/uscha-devloop/qa_ledger.py +176 -0
- package/uscha-kit/uscha.config.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Requires **Python 3.8+** on the machine (the engine is Python stdlib — no pip
|
|
|
40
40
|
runtime dependencies). The npm package is a thin router; the canonical installer is
|
|
41
41
|
`uscha-kit/install-uscha.py`.
|
|
42
42
|
|
|
43
|
-
**Kit v1.
|
|
43
|
+
**Kit v1.74.0** <!-- uscha:version --> · [uscha.dev](https://uscha.dev) ·
|
|
44
44
|
[changelog](https://github.com/andresmassello/uscha/blob/main/uscha-kit/CHANGELOG.md)
|
|
45
45
|
(the per-release changelogs live in the repo, not in the npm tarball)
|
|
46
46
|
|
|
@@ -76,7 +76,7 @@ and see which file, which test, and when.
|
|
|
76
76
|
| `/uscha-mirador` | Bird's-eye HTML dashboard: readiness, trail, acceptance, loops |
|
|
77
77
|
| `/uscha-status` | One-line progress readout, in chat |
|
|
78
78
|
|
|
79
|
-
**A measurement engine** (`qa_ledger.py`,
|
|
79
|
+
**A measurement engine** (`qa_ledger.py`, 46 subcommands, Python stdlib) that ingests
|
|
80
80
|
evidence from **11 language stacks** — maven, gradle, ant, python, node, go, rust, dotnet,
|
|
81
81
|
cpp, swift, flutter — and computes a readiness score with hard caps and visible provenance.
|
|
82
82
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andresmassello/uscha",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.74.0",
|
|
4
4
|
"description": "Spec-driven development for LLM coding agents: 9 skills + a stdlib evidence engine. Facts block, guesses advise; the human approves.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Andres Massello",
|
|
@@ -5298,6 +5298,162 @@ def cmd_compile_ingest(args):
|
|
|
5298
5298
|
sys.exit(0)
|
|
5299
5299
|
|
|
5300
5300
|
|
|
5301
|
+
# --------------------------------------------------------------------------- #
|
|
5302
|
+
# bootstrap (Diamond M4: a bounded subsystem's identity is carried by its
|
|
5303
|
+
# canonical package + a WITHHELD oracle, not by its implementation. The oracle
|
|
5304
|
+
# runner is a measured fact and decides "same system"; variance is advisory
|
|
5305
|
+
# evidence that the implementations genuinely differ. ADR-017.)
|
|
5306
|
+
# --------------------------------------------------------------------------- #
|
|
5307
|
+
_BOOTSTRAP_CASE_TIMEOUT = 15 # a compiled hook must decide fast
|
|
5308
|
+
|
|
5309
|
+
|
|
5310
|
+
def _run_oracle_case(impl_path, case):
|
|
5311
|
+
"""Run ONE withheld oracle case against a compiled implementation: feed the case's stdin
|
|
5312
|
+
(raw_stdin verbatim if present, else json.dumps(payload)) to `python <impl>`, and compare
|
|
5313
|
+
the process exit code to `expected_exit`. Deterministic execution -- the oracle is a
|
|
5314
|
+
`measured` fact, never an LLM judgment. Returns a per-case result dict."""
|
|
5315
|
+
if "raw_stdin" in case:
|
|
5316
|
+
stdin = case["raw_stdin"]
|
|
5317
|
+
else:
|
|
5318
|
+
stdin = json.dumps(case.get("payload"))
|
|
5319
|
+
try:
|
|
5320
|
+
r = subprocess.run([sys.executable, impl_path], input=stdin, capture_output=True,
|
|
5321
|
+
text=True, encoding="utf-8", errors="replace",
|
|
5322
|
+
timeout=_BOOTSTRAP_CASE_TIMEOUT)
|
|
5323
|
+
got, err = r.returncode, None
|
|
5324
|
+
except subprocess.TimeoutExpired:
|
|
5325
|
+
got, err = None, "timeout"
|
|
5326
|
+
except OSError as exc:
|
|
5327
|
+
got, err = None, "could not run impl: %s" % exc
|
|
5328
|
+
want = case.get("expected_exit")
|
|
5329
|
+
return {"name": case.get("name"), "expected": want, "got": got,
|
|
5330
|
+
"ok": (err is None and got == want), "error": err}
|
|
5331
|
+
|
|
5332
|
+
|
|
5333
|
+
def cmd_bootstrap_oracle(args):
|
|
5334
|
+
"""Run a WITHHELD oracle suite (ADR-017) against a compiled implementation. The oracle
|
|
5335
|
+
predates and is physically separate from every compiler input; this runner is the
|
|
5336
|
+
maker!=checker wall made executable. Exit 0 iff every case matches its expected exit,
|
|
5337
|
+
else 1 -- a measured behavioural fact about whether this implementation is the same
|
|
5338
|
+
system. It runs the implementation as a subprocess and consults no model."""
|
|
5339
|
+
try:
|
|
5340
|
+
with open(args.oracle, encoding="utf-8-sig") as fh:
|
|
5341
|
+
oracle = json.load(fh)
|
|
5342
|
+
except (OSError, ValueError) as exc:
|
|
5343
|
+
print("[qa_ledger] bootstrap-oracle: unreadable oracle %s: %s" % (args.oracle, exc),
|
|
5344
|
+
file=sys.stderr)
|
|
5345
|
+
sys.exit(2)
|
|
5346
|
+
cases = oracle.get("cases")
|
|
5347
|
+
if not isinstance(cases, list) or not cases:
|
|
5348
|
+
print("[qa_ledger] bootstrap-oracle: oracle has no cases", file=sys.stderr)
|
|
5349
|
+
sys.exit(2)
|
|
5350
|
+
if not os.path.isfile(args.impl):
|
|
5351
|
+
print("[qa_ledger] bootstrap-oracle: no implementation at %s" % args.impl,
|
|
5352
|
+
file=sys.stderr)
|
|
5353
|
+
sys.exit(2)
|
|
5354
|
+
results = [_run_oracle_case(args.impl, c) for c in cases]
|
|
5355
|
+
passed = sum(1 for r in results if r["ok"])
|
|
5356
|
+
failed = [r for r in results if not r["ok"]]
|
|
5357
|
+
report = {"impl": args.impl, "oracle": args.oracle, "total": len(results),
|
|
5358
|
+
"passed": passed, "failed": len(failed),
|
|
5359
|
+
"oracle_green": not failed, "results": results}
|
|
5360
|
+
if args.ledger and args.repo:
|
|
5361
|
+
ledger = _load(args.ledger)
|
|
5362
|
+
_repo_node(ledger, args.repo)
|
|
5363
|
+
rec = {"impl": os.path.basename(args.impl), "oracle": os.path.basename(args.oracle),
|
|
5364
|
+
"total": len(results), "passed": passed, "failed": len(failed),
|
|
5365
|
+
"oracle_green": not failed,
|
|
5366
|
+
"failing": [r["name"] for r in failed], "at": _now()}
|
|
5367
|
+
ledger.setdefault("bootstrap_oracle", []).append(rec)
|
|
5368
|
+
_save(args.ledger, ledger)
|
|
5369
|
+
if args.json:
|
|
5370
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5371
|
+
else:
|
|
5372
|
+
print("BOOTSTRAP-ORACLE %s: %d/%d cases pass -- %s"
|
|
5373
|
+
% (os.path.basename(args.impl), passed, len(results),
|
|
5374
|
+
"ORACLE GREEN (same system on this suite)" if not failed
|
|
5375
|
+
else "ORACLE RED (%d divergence(s))" % len(failed)))
|
|
5376
|
+
for r in failed:
|
|
5377
|
+
print(" x %s: expected exit %s, got %s%s"
|
|
5378
|
+
% (r["name"], r["expected"], r["got"],
|
|
5379
|
+
" (%s)" % r["error"] if r["error"] else ""))
|
|
5380
|
+
sys.exit(0 if not failed else 1)
|
|
5381
|
+
|
|
5382
|
+
|
|
5383
|
+
def _impl_metrics(path):
|
|
5384
|
+
"""Structural fingerprint of one implementation: physical LOC, AST node count, function
|
|
5385
|
+
and class counts, and the set of imported top-level modules. Deterministic; no judgment."""
|
|
5386
|
+
try:
|
|
5387
|
+
with open(path, encoding="utf-8", errors="replace") as fh:
|
|
5388
|
+
src = fh.read()
|
|
5389
|
+
except OSError as exc:
|
|
5390
|
+
return {"path": path, "error": "unreadable: %s" % exc}
|
|
5391
|
+
loc = sum(1 for ln in src.splitlines() if ln.strip())
|
|
5392
|
+
try:
|
|
5393
|
+
tree = ast.parse(src)
|
|
5394
|
+
except SyntaxError as exc:
|
|
5395
|
+
return {"path": path, "loc": loc, "error": "unparseable: %s" % exc}
|
|
5396
|
+
funcs = classes = nodes = 0
|
|
5397
|
+
imports = set()
|
|
5398
|
+
for nd in ast.walk(tree):
|
|
5399
|
+
nodes += 1
|
|
5400
|
+
if isinstance(nd, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
5401
|
+
funcs += 1
|
|
5402
|
+
elif isinstance(nd, ast.ClassDef):
|
|
5403
|
+
classes += 1
|
|
5404
|
+
elif isinstance(nd, ast.Import):
|
|
5405
|
+
for a in nd.names:
|
|
5406
|
+
imports.add(a.name.split(".")[0])
|
|
5407
|
+
elif isinstance(nd, ast.ImportFrom):
|
|
5408
|
+
if nd.module:
|
|
5409
|
+
imports.add(nd.module.split(".")[0])
|
|
5410
|
+
return {"path": path, "loc": loc, "ast_nodes": nodes, "functions": funcs,
|
|
5411
|
+
"classes": classes, "imports": sorted(imports),
|
|
5412
|
+
"sha256": hashlib.sha256(src.encode("utf-8")).hexdigest()}
|
|
5413
|
+
|
|
5414
|
+
|
|
5415
|
+
def cmd_bootstrap_variance(args):
|
|
5416
|
+
"""Prove independent compilations of the same canonical package genuinely DIFFER (ADR-017).
|
|
5417
|
+
Reports per-implementation structural metrics and pairwise divergence. ADVISORY: variance
|
|
5418
|
+
is evidence the implementations differ, never a certificate of 'same system' (only the
|
|
5419
|
+
oracle certifies that) and never a gate -- it cannot change an exit code."""
|
|
5420
|
+
metrics = [_impl_metrics(p) for p in args.impls]
|
|
5421
|
+
pairs = []
|
|
5422
|
+
good = [m for m in metrics if "error" not in m]
|
|
5423
|
+
for i in range(len(good)):
|
|
5424
|
+
for j in range(i + 1, len(good)):
|
|
5425
|
+
a, b = good[i], good[j]
|
|
5426
|
+
ia, ib = set(a["imports"]), set(b["imports"])
|
|
5427
|
+
jac = (len(ia & ib) / len(ia | ib)) if (ia or ib) else 1.0
|
|
5428
|
+
pairs.append({"a": os.path.basename(a["path"]), "b": os.path.basename(b["path"]),
|
|
5429
|
+
"byte_identical": a["sha256"] == b["sha256"],
|
|
5430
|
+
"loc_delta": abs(a["loc"] - b["loc"]),
|
|
5431
|
+
"ast_node_delta": abs(a["ast_nodes"] - b["ast_nodes"]),
|
|
5432
|
+
"function_delta": abs(a["functions"] - b["functions"]),
|
|
5433
|
+
"import_jaccard": round(jac, 3)})
|
|
5434
|
+
all_distinct = all(not p["byte_identical"] for p in pairs) if pairs else None
|
|
5435
|
+
report = {"implementations": metrics, "pairs": pairs, "all_distinct": all_distinct,
|
|
5436
|
+
"advisory": True}
|
|
5437
|
+
if args.json:
|
|
5438
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5439
|
+
else:
|
|
5440
|
+
for m in metrics:
|
|
5441
|
+
if "error" in m:
|
|
5442
|
+
print("VARIANCE %s: %s" % (os.path.basename(m["path"]), m["error"]))
|
|
5443
|
+
else:
|
|
5444
|
+
print("VARIANCE %s: %d loc, %d ast-nodes, %d fn, %d cls, imports=%s"
|
|
5445
|
+
% (os.path.basename(m["path"]), m["loc"], m["ast_nodes"],
|
|
5446
|
+
m["functions"], m["classes"], ",".join(m["imports"]) or "-"))
|
|
5447
|
+
for p in pairs:
|
|
5448
|
+
print(" %s vs %s: %s | dloc=%d dnodes=%d import_jaccard=%.2f"
|
|
5449
|
+
% (p["a"], p["b"], "IDENTICAL" if p["byte_identical"] else "distinct",
|
|
5450
|
+
p["loc_delta"], p["ast_node_delta"], p["import_jaccard"]))
|
|
5451
|
+
if all_distinct is not None:
|
|
5452
|
+
print(" all implementations distinct: %s (advisory, never gates)"
|
|
5453
|
+
% ("yes" if all_distinct else "NO -- convergence, a weak result"))
|
|
5454
|
+
sys.exit(0)
|
|
5455
|
+
|
|
5456
|
+
|
|
5301
5457
|
# --------------------------------------------------------------------------- #
|
|
5302
5458
|
# facts (T0 / SYSTEM-FACTS: public claims become compiled artifacts of repo
|
|
5303
5459
|
# facts -- Diamond applied to Diamond. ADR-012.)
|
|
@@ -9390,6 +9546,26 @@ def build_parser():
|
|
|
9390
9546
|
pcmi.add_argument("--json", action="store_true")
|
|
9391
9547
|
pcmi.set_defaults(func=cmd_compile_ingest)
|
|
9392
9548
|
|
|
9549
|
+
pbo = sub.add_parser(
|
|
9550
|
+
"bootstrap-oracle",
|
|
9551
|
+
help="run a WITHHELD oracle suite against a compiled implementation (ADR-017); exit 0 "
|
|
9552
|
+
"iff every case matches its expected exit -- the maker!=checker wall, executable")
|
|
9553
|
+
pbo.add_argument("--impl", required=True, help="the compiled implementation to run")
|
|
9554
|
+
pbo.add_argument("--oracle", required=True, help="the withheld ORACLE.json case suite")
|
|
9555
|
+
pbo.add_argument("--ledger", default=None, help="optional: persist the measured result")
|
|
9556
|
+
pbo.add_argument("--repo", default=None, help="repo scope when --ledger is given")
|
|
9557
|
+
pbo.add_argument("--json", action="store_true")
|
|
9558
|
+
pbo.set_defaults(func=cmd_bootstrap_oracle)
|
|
9559
|
+
|
|
9560
|
+
pbv = sub.add_parser(
|
|
9561
|
+
"bootstrap-variance",
|
|
9562
|
+
help="structural metrics + pairwise divergence proving independent compilations "
|
|
9563
|
+
"genuinely differ (ADR-017); ADVISORY evidence, never a gate")
|
|
9564
|
+
pbv.add_argument("--impls", required=True, nargs="+",
|
|
9565
|
+
help="two or more compiled implementations to compare")
|
|
9566
|
+
pbv.add_argument("--json", action="store_true")
|
|
9567
|
+
pbv.set_defaults(func=cmd_bootstrap_variance)
|
|
9568
|
+
|
|
9393
9569
|
pcr = sub.add_parser("cleanroom",
|
|
9394
9570
|
help="run a command against a CLEAN checkout of one commit in a throwaway worktree (ADR-008)")
|
|
9395
9571
|
pcr.add_argument("--ledger", default="QA-LEDGER.json")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
|
|
3
3
|
"name": "uscha",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.74.0",
|
|
5
5
|
"displayName": "Uscha",
|
|
6
|
-
"description": "Spec-driven development for LLM coding agents: 9 skills (discovery, adr-refine, reverse-discovery, characterize, devloop, sysdoc, rubric, mirador, status) + a stdlib measurement engine (qa_ledger.py,
|
|
6
|
+
"description": "Spec-driven development for LLM coding agents: 9 skills (discovery, adr-refine, reverse-discovery, characterize, devloop, sysdoc, rubric, mirador, status) + a stdlib measurement engine (qa_ledger.py, 46 subcommands + universal installer + npm/npx router). Facts block, guesses advise; the human approves.",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Andres Massello",
|
|
9
9
|
"url": "https://github.com/andresmassello"
|
package/uscha-kit/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# uscha-kit
|
|
2
2
|
|
|
3
|
-
**Kit version:** v1.
|
|
3
|
+
**Kit version:** v1.74.0 <!-- uscha:version --> · **[uscha.dev](https://uscha.dev)**
|
|
4
4
|
|
|
5
5
|
Spec-driven orchestrator + multi-repo QA for Claude Code, with a deterministic ledger.
|
|
6
6
|
**Nine skills** (`uscha-discovery`, `uscha-adr-refine`, `uscha-devloop`, `uscha-sysdoc`, `uscha-reverse-discovery`,
|
package/uscha-kit/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
uscha-kit 1.
|
|
1
|
+
uscha-kit 1.74.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"AC-BS-01": true, "AC-BS-02": true, "AC-BS-03": true, "AC-BS-04": true, "AC-BS-05": true, "AC-BS-06": true}
|
|
@@ -5298,6 +5298,162 @@ def cmd_compile_ingest(args):
|
|
|
5298
5298
|
sys.exit(0)
|
|
5299
5299
|
|
|
5300
5300
|
|
|
5301
|
+
# --------------------------------------------------------------------------- #
|
|
5302
|
+
# bootstrap (Diamond M4: a bounded subsystem's identity is carried by its
|
|
5303
|
+
# canonical package + a WITHHELD oracle, not by its implementation. The oracle
|
|
5304
|
+
# runner is a measured fact and decides "same system"; variance is advisory
|
|
5305
|
+
# evidence that the implementations genuinely differ. ADR-017.)
|
|
5306
|
+
# --------------------------------------------------------------------------- #
|
|
5307
|
+
_BOOTSTRAP_CASE_TIMEOUT = 15 # a compiled hook must decide fast
|
|
5308
|
+
|
|
5309
|
+
|
|
5310
|
+
def _run_oracle_case(impl_path, case):
|
|
5311
|
+
"""Run ONE withheld oracle case against a compiled implementation: feed the case's stdin
|
|
5312
|
+
(raw_stdin verbatim if present, else json.dumps(payload)) to `python <impl>`, and compare
|
|
5313
|
+
the process exit code to `expected_exit`. Deterministic execution -- the oracle is a
|
|
5314
|
+
`measured` fact, never an LLM judgment. Returns a per-case result dict."""
|
|
5315
|
+
if "raw_stdin" in case:
|
|
5316
|
+
stdin = case["raw_stdin"]
|
|
5317
|
+
else:
|
|
5318
|
+
stdin = json.dumps(case.get("payload"))
|
|
5319
|
+
try:
|
|
5320
|
+
r = subprocess.run([sys.executable, impl_path], input=stdin, capture_output=True,
|
|
5321
|
+
text=True, encoding="utf-8", errors="replace",
|
|
5322
|
+
timeout=_BOOTSTRAP_CASE_TIMEOUT)
|
|
5323
|
+
got, err = r.returncode, None
|
|
5324
|
+
except subprocess.TimeoutExpired:
|
|
5325
|
+
got, err = None, "timeout"
|
|
5326
|
+
except OSError as exc:
|
|
5327
|
+
got, err = None, "could not run impl: %s" % exc
|
|
5328
|
+
want = case.get("expected_exit")
|
|
5329
|
+
return {"name": case.get("name"), "expected": want, "got": got,
|
|
5330
|
+
"ok": (err is None and got == want), "error": err}
|
|
5331
|
+
|
|
5332
|
+
|
|
5333
|
+
def cmd_bootstrap_oracle(args):
|
|
5334
|
+
"""Run a WITHHELD oracle suite (ADR-017) against a compiled implementation. The oracle
|
|
5335
|
+
predates and is physically separate from every compiler input; this runner is the
|
|
5336
|
+
maker!=checker wall made executable. Exit 0 iff every case matches its expected exit,
|
|
5337
|
+
else 1 -- a measured behavioural fact about whether this implementation is the same
|
|
5338
|
+
system. It runs the implementation as a subprocess and consults no model."""
|
|
5339
|
+
try:
|
|
5340
|
+
with open(args.oracle, encoding="utf-8-sig") as fh:
|
|
5341
|
+
oracle = json.load(fh)
|
|
5342
|
+
except (OSError, ValueError) as exc:
|
|
5343
|
+
print("[qa_ledger] bootstrap-oracle: unreadable oracle %s: %s" % (args.oracle, exc),
|
|
5344
|
+
file=sys.stderr)
|
|
5345
|
+
sys.exit(2)
|
|
5346
|
+
cases = oracle.get("cases")
|
|
5347
|
+
if not isinstance(cases, list) or not cases:
|
|
5348
|
+
print("[qa_ledger] bootstrap-oracle: oracle has no cases", file=sys.stderr)
|
|
5349
|
+
sys.exit(2)
|
|
5350
|
+
if not os.path.isfile(args.impl):
|
|
5351
|
+
print("[qa_ledger] bootstrap-oracle: no implementation at %s" % args.impl,
|
|
5352
|
+
file=sys.stderr)
|
|
5353
|
+
sys.exit(2)
|
|
5354
|
+
results = [_run_oracle_case(args.impl, c) for c in cases]
|
|
5355
|
+
passed = sum(1 for r in results if r["ok"])
|
|
5356
|
+
failed = [r for r in results if not r["ok"]]
|
|
5357
|
+
report = {"impl": args.impl, "oracle": args.oracle, "total": len(results),
|
|
5358
|
+
"passed": passed, "failed": len(failed),
|
|
5359
|
+
"oracle_green": not failed, "results": results}
|
|
5360
|
+
if args.ledger and args.repo:
|
|
5361
|
+
ledger = _load(args.ledger)
|
|
5362
|
+
_repo_node(ledger, args.repo)
|
|
5363
|
+
rec = {"impl": os.path.basename(args.impl), "oracle": os.path.basename(args.oracle),
|
|
5364
|
+
"total": len(results), "passed": passed, "failed": len(failed),
|
|
5365
|
+
"oracle_green": not failed,
|
|
5366
|
+
"failing": [r["name"] for r in failed], "at": _now()}
|
|
5367
|
+
ledger.setdefault("bootstrap_oracle", []).append(rec)
|
|
5368
|
+
_save(args.ledger, ledger)
|
|
5369
|
+
if args.json:
|
|
5370
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5371
|
+
else:
|
|
5372
|
+
print("BOOTSTRAP-ORACLE %s: %d/%d cases pass -- %s"
|
|
5373
|
+
% (os.path.basename(args.impl), passed, len(results),
|
|
5374
|
+
"ORACLE GREEN (same system on this suite)" if not failed
|
|
5375
|
+
else "ORACLE RED (%d divergence(s))" % len(failed)))
|
|
5376
|
+
for r in failed:
|
|
5377
|
+
print(" x %s: expected exit %s, got %s%s"
|
|
5378
|
+
% (r["name"], r["expected"], r["got"],
|
|
5379
|
+
" (%s)" % r["error"] if r["error"] else ""))
|
|
5380
|
+
sys.exit(0 if not failed else 1)
|
|
5381
|
+
|
|
5382
|
+
|
|
5383
|
+
def _impl_metrics(path):
|
|
5384
|
+
"""Structural fingerprint of one implementation: physical LOC, AST node count, function
|
|
5385
|
+
and class counts, and the set of imported top-level modules. Deterministic; no judgment."""
|
|
5386
|
+
try:
|
|
5387
|
+
with open(path, encoding="utf-8", errors="replace") as fh:
|
|
5388
|
+
src = fh.read()
|
|
5389
|
+
except OSError as exc:
|
|
5390
|
+
return {"path": path, "error": "unreadable: %s" % exc}
|
|
5391
|
+
loc = sum(1 for ln in src.splitlines() if ln.strip())
|
|
5392
|
+
try:
|
|
5393
|
+
tree = ast.parse(src)
|
|
5394
|
+
except SyntaxError as exc:
|
|
5395
|
+
return {"path": path, "loc": loc, "error": "unparseable: %s" % exc}
|
|
5396
|
+
funcs = classes = nodes = 0
|
|
5397
|
+
imports = set()
|
|
5398
|
+
for nd in ast.walk(tree):
|
|
5399
|
+
nodes += 1
|
|
5400
|
+
if isinstance(nd, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
5401
|
+
funcs += 1
|
|
5402
|
+
elif isinstance(nd, ast.ClassDef):
|
|
5403
|
+
classes += 1
|
|
5404
|
+
elif isinstance(nd, ast.Import):
|
|
5405
|
+
for a in nd.names:
|
|
5406
|
+
imports.add(a.name.split(".")[0])
|
|
5407
|
+
elif isinstance(nd, ast.ImportFrom):
|
|
5408
|
+
if nd.module:
|
|
5409
|
+
imports.add(nd.module.split(".")[0])
|
|
5410
|
+
return {"path": path, "loc": loc, "ast_nodes": nodes, "functions": funcs,
|
|
5411
|
+
"classes": classes, "imports": sorted(imports),
|
|
5412
|
+
"sha256": hashlib.sha256(src.encode("utf-8")).hexdigest()}
|
|
5413
|
+
|
|
5414
|
+
|
|
5415
|
+
def cmd_bootstrap_variance(args):
|
|
5416
|
+
"""Prove independent compilations of the same canonical package genuinely DIFFER (ADR-017).
|
|
5417
|
+
Reports per-implementation structural metrics and pairwise divergence. ADVISORY: variance
|
|
5418
|
+
is evidence the implementations differ, never a certificate of 'same system' (only the
|
|
5419
|
+
oracle certifies that) and never a gate -- it cannot change an exit code."""
|
|
5420
|
+
metrics = [_impl_metrics(p) for p in args.impls]
|
|
5421
|
+
pairs = []
|
|
5422
|
+
good = [m for m in metrics if "error" not in m]
|
|
5423
|
+
for i in range(len(good)):
|
|
5424
|
+
for j in range(i + 1, len(good)):
|
|
5425
|
+
a, b = good[i], good[j]
|
|
5426
|
+
ia, ib = set(a["imports"]), set(b["imports"])
|
|
5427
|
+
jac = (len(ia & ib) / len(ia | ib)) if (ia or ib) else 1.0
|
|
5428
|
+
pairs.append({"a": os.path.basename(a["path"]), "b": os.path.basename(b["path"]),
|
|
5429
|
+
"byte_identical": a["sha256"] == b["sha256"],
|
|
5430
|
+
"loc_delta": abs(a["loc"] - b["loc"]),
|
|
5431
|
+
"ast_node_delta": abs(a["ast_nodes"] - b["ast_nodes"]),
|
|
5432
|
+
"function_delta": abs(a["functions"] - b["functions"]),
|
|
5433
|
+
"import_jaccard": round(jac, 3)})
|
|
5434
|
+
all_distinct = all(not p["byte_identical"] for p in pairs) if pairs else None
|
|
5435
|
+
report = {"implementations": metrics, "pairs": pairs, "all_distinct": all_distinct,
|
|
5436
|
+
"advisory": True}
|
|
5437
|
+
if args.json:
|
|
5438
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5439
|
+
else:
|
|
5440
|
+
for m in metrics:
|
|
5441
|
+
if "error" in m:
|
|
5442
|
+
print("VARIANCE %s: %s" % (os.path.basename(m["path"]), m["error"]))
|
|
5443
|
+
else:
|
|
5444
|
+
print("VARIANCE %s: %d loc, %d ast-nodes, %d fn, %d cls, imports=%s"
|
|
5445
|
+
% (os.path.basename(m["path"]), m["loc"], m["ast_nodes"],
|
|
5446
|
+
m["functions"], m["classes"], ",".join(m["imports"]) or "-"))
|
|
5447
|
+
for p in pairs:
|
|
5448
|
+
print(" %s vs %s: %s | dloc=%d dnodes=%d import_jaccard=%.2f"
|
|
5449
|
+
% (p["a"], p["b"], "IDENTICAL" if p["byte_identical"] else "distinct",
|
|
5450
|
+
p["loc_delta"], p["ast_node_delta"], p["import_jaccard"]))
|
|
5451
|
+
if all_distinct is not None:
|
|
5452
|
+
print(" all implementations distinct: %s (advisory, never gates)"
|
|
5453
|
+
% ("yes" if all_distinct else "NO -- convergence, a weak result"))
|
|
5454
|
+
sys.exit(0)
|
|
5455
|
+
|
|
5456
|
+
|
|
5301
5457
|
# --------------------------------------------------------------------------- #
|
|
5302
5458
|
# facts (T0 / SYSTEM-FACTS: public claims become compiled artifacts of repo
|
|
5303
5459
|
# facts -- Diamond applied to Diamond. ADR-012.)
|
|
@@ -9390,6 +9546,26 @@ def build_parser():
|
|
|
9390
9546
|
pcmi.add_argument("--json", action="store_true")
|
|
9391
9547
|
pcmi.set_defaults(func=cmd_compile_ingest)
|
|
9392
9548
|
|
|
9549
|
+
pbo = sub.add_parser(
|
|
9550
|
+
"bootstrap-oracle",
|
|
9551
|
+
help="run a WITHHELD oracle suite against a compiled implementation (ADR-017); exit 0 "
|
|
9552
|
+
"iff every case matches its expected exit -- the maker!=checker wall, executable")
|
|
9553
|
+
pbo.add_argument("--impl", required=True, help="the compiled implementation to run")
|
|
9554
|
+
pbo.add_argument("--oracle", required=True, help="the withheld ORACLE.json case suite")
|
|
9555
|
+
pbo.add_argument("--ledger", default=None, help="optional: persist the measured result")
|
|
9556
|
+
pbo.add_argument("--repo", default=None, help="repo scope when --ledger is given")
|
|
9557
|
+
pbo.add_argument("--json", action="store_true")
|
|
9558
|
+
pbo.set_defaults(func=cmd_bootstrap_oracle)
|
|
9559
|
+
|
|
9560
|
+
pbv = sub.add_parser(
|
|
9561
|
+
"bootstrap-variance",
|
|
9562
|
+
help="structural metrics + pairwise divergence proving independent compilations "
|
|
9563
|
+
"genuinely differ (ADR-017); ADVISORY evidence, never a gate")
|
|
9564
|
+
pbv.add_argument("--impls", required=True, nargs="+",
|
|
9565
|
+
help="two or more compiled implementations to compare")
|
|
9566
|
+
pbv.add_argument("--json", action="store_true")
|
|
9567
|
+
pbv.set_defaults(func=cmd_bootstrap_variance)
|
|
9568
|
+
|
|
9393
9569
|
pcr = sub.add_parser("cleanroom",
|
|
9394
9570
|
help="run a command against a CLEAN checkout of one commit in a throwaway worktree (ADR-008)")
|
|
9395
9571
|
pcr.add_argument("--ledger", default="QA-LEDGER.json")
|