Re-run the generator in-memory against the committed api-schema.json and compare to the committed SerialStudio.js/.lua/sdk-symbols.json. A mismatch means prelude.js or generate-sdk.py changed without a regenerate.
(repo_root: Path)
| 2627 | |
| 2628 | |
| 2629 | def _sdk_staleness_violations(repo_root: Path) -> list[Violation]: |
| 2630 | """Re-run the generator in-memory against the committed api-schema.json and |
| 2631 | compare to the committed SerialStudio.js/.lua/sdk-symbols.json. A mismatch |
| 2632 | means prelude.js or generate-sdk.py changed without a regenerate.""" |
| 2633 | out: list[Violation] = [] |
| 2634 | schema = repo_root / "app" / "rcc" / "api" / "api-schema.json" |
| 2635 | gen = repo_root / "scripts" / "generate-sdk.py" |
| 2636 | if not schema.exists() or not gen.exists(): |
| 2637 | return out |
| 2638 | |
| 2639 | try: |
| 2640 | spec = importlib.util.spec_from_file_location("generate_sdk", gen) |
| 2641 | mod = importlib.util.module_from_spec(spec) |
| 2642 | sys.modules["generate_sdk"] = mod |
| 2643 | spec.loader.exec_module(mod) |
| 2644 | commands = json.loads(schema.read_text(encoding="utf-8")) |
| 2645 | commands = mod.drop_namespace_collisions(commands) |
| 2646 | expected = { |
| 2647 | "app/rcc/api/SerialStudio.js": mod.emit_js(commands), |
| 2648 | "app/rcc/api/SerialStudio.lua": mod.emit_lua(commands), |
| 2649 | "app/rcc/api/sdk-symbols.json": json.dumps( |
| 2650 | mod.collect_symbols(commands), indent=2 |
| 2651 | ) |
| 2652 | + "\n", |
| 2653 | } |
| 2654 | except Exception as exc: |
| 2655 | # Never crash a commit if the generator's internals moved; surface why |
| 2656 | # the staleness check was skipped so a silent miss stays debuggable. |
| 2657 | print(f"[code-verify] sdk-out-of-date check skipped: {exc}", file=sys.stderr) |
| 2658 | return out |
| 2659 | |
| 2660 | for rel, want in expected.items(): |
| 2661 | f = repo_root / rel |
| 2662 | if not f.exists(): |
| 2663 | continue |
| 2664 | if f.read_text(encoding="utf-8") != want: |
| 2665 | out.append( |
| 2666 | Violation( |
| 2667 | f, |
| 2668 | 1, |
| 2669 | "sdk-out-of-date", |
| 2670 | "committed SDK differs from generate-sdk.py output for the " |
| 2671 | "current api-schema.json; run scripts/sanitize-commit.py " |
| 2672 | "(after SerialStudio --dump-api-schema if commands changed)", |
| 2673 | ) |
| 2674 | ) |
| 2675 | return out |
| 2676 | |
| 2677 | |
| 2678 | def main(argv: list[str]) -> int: |
no test coverage detected