MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _sdk_consistency_violations

Function _sdk_consistency_violations

scripts/code-verify.py:2582–2626  ·  view source on GitHub ↗

Three SDK guards: generated files hand-edited, name-based byte detection reintroduced in the generator, and the committed SDK out of date vs the committed api-schema.json. The staleness check is best-effort: it cannot see commands added in C++ until `--dump-api-schema` refreshes api-sche

(repo_root: Path)

Source from the content-addressed store, hash-verified

2580
2581
2582def _sdk_consistency_violations(repo_root: Path) -> list[Violation]:
2583 """Three SDK guards: generated files hand-edited, name-based byte detection
2584 reintroduced in the generator, and the committed SDK out of date vs the
2585 committed api-schema.json. The staleness check is best-effort: it cannot see
2586 commands added in C++ until `--dump-api-schema` refreshes api-schema.json, so
2587 it only catches a generator/prelude edit that was never regenerated."""
2588 out: list[Violation] = []
2589
2590 gen = repo_root / "scripts" / "generate-sdk.py"
2591 gen_text = gen.read_text(encoding="utf-8") if gen.exists() else ""
2592
2593 # (1) Name-based byte detection must never come back -- encoding is an
2594 # explicit "binary": true schema flag (SchemaBuilder byteProp).
2595 if re.search(r"^\s*BYTE_PARAMS\s*=", gen_text, re.MULTILINE):
2596 out.append(
2597 Violation(
2598 gen,
2599 1,
2600 "sdk-byte-param-by-name",
2601 "generate-sdk.py reintroduced a name-based BYTE_PARAMS set; byte "
2602 'encoding must key on the explicit "binary" schema flag '
2603 "(SchemaBuilder byteProp), not the parameter name",
2604 )
2605 )
2606
2607 # (2) The generated SDK artifacts are emitted, never hand-edited.
2608 for rel in _SDK_GENERATED:
2609 f = repo_root / rel
2610 if not f.exists():
2611 continue
2612 head = f.read_text(encoding="utf-8")[:200]
2613 if "AUTO-GENERATED" not in head and rel.endswith((".js", ".lua")):
2614 out.append(
2615 Violation(
2616 f,
2617 1,
2618 "sdk-generated-edited",
2619 "generated SDK file lost its AUTO-GENERATED banner; regenerate "
2620 "with scripts/sanitize-commit.py instead of editing by hand",
2621 )
2622 )
2623
2624 # (3) Best-effort staleness: re-emit from the committed schema and diff.
2625 out.extend(_sdk_staleness_violations(repo_root))
2626 return out
2627
2628
2629def _sdk_staleness_violations(repo_root: Path) -> list[Violation]:

Callers 1

mainFunction · 0.85

Calls 5

ViolationClass · 0.85
existsMethod · 0.80
searchMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected