v0.1.0-pre.013
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
# file: scripts/audit_khadhroony_workspace_rules.py
|
||||
# version: 6
|
||||
# version: 7
|
||||
|
||||
"""Audit mechanically verifiable rules specific to khadhroony-bot3."""
|
||||
|
||||
@@ -278,6 +278,87 @@ def audit_reserved_decoder_scaffolds(root: pathlib.Path) -> list[Violation]:
|
||||
return violations
|
||||
|
||||
|
||||
def audit_reserved_materializer_scaffolds(root: pathlib.Path) -> list[Violation]:
|
||||
"""Reject temporary materializer markers and incomplete reserved materializers."""
|
||||
|
||||
violations: list[Violation] = []
|
||||
materializer_root = root / "kb-lib/src/materializer"
|
||||
forbidden = (
|
||||
"MIGRATION_BOUNDARIES",
|
||||
"LEGACY_CRATE",
|
||||
"MIGRATION_STATUS",
|
||||
"source-preserved-pending-port",
|
||||
)
|
||||
struct_pattern = re.compile(r"^pub struct (Mt[A-Za-z0-9]+Materializer);$", re.MULTILINE)
|
||||
for path in sorted(materializer_root.rglob("*.rs")):
|
||||
relative = path.relative_to(root).as_posix()
|
||||
text = path.read_text(encoding="utf-8")
|
||||
for marker in forbidden:
|
||||
offset = text.find(marker)
|
||||
if offset >= 0:
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_MT001",
|
||||
relative,
|
||||
text[:offset].count("\n") + 1,
|
||||
f"temporary materializer migration marker `{marker}` is forbidden",
|
||||
)
|
||||
)
|
||||
if not text.startswith("// file:") or "\n//! Reserved " not in text:
|
||||
continue
|
||||
struct_match = struct_pattern.search(text)
|
||||
if struct_match is None:
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_MT002",
|
||||
relative,
|
||||
1,
|
||||
"reserved materializer must expose one `Mt*Materializer` unit struct",
|
||||
)
|
||||
)
|
||||
continue
|
||||
type_name = struct_match.group(1)
|
||||
legacy_implementation = f"impl crate::MtMaterializer for crate::{type_name} {{"
|
||||
if legacy_implementation not in text:
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_MT003",
|
||||
relative,
|
||||
text[: struct_match.start()].count("\n") + 1,
|
||||
f"`{type_name}` must implement `MtMaterializer`",
|
||||
)
|
||||
)
|
||||
api_implementation = f"impl crate::MtApiEventMaterializer for crate::{type_name} {{"
|
||||
if api_implementation not in text:
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_MT004",
|
||||
relative,
|
||||
text[: struct_match.start()].count("\n") + 1,
|
||||
f"`{type_name}` must implement `MtApiEventMaterializer`",
|
||||
)
|
||||
)
|
||||
if "fn accepted_families(&self) -> &'static [crate::MdEventFamily]" not in text:
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_MT005",
|
||||
relative,
|
||||
1,
|
||||
"reserved materializer must declare its inactive family boundary",
|
||||
)
|
||||
)
|
||||
if "crate::MtApiMaterializerExecutionResult::ignored()" not in text:
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_MT006",
|
||||
relative,
|
||||
1,
|
||||
"reserved materializer must return an ignored API result",
|
||||
)
|
||||
)
|
||||
return violations
|
||||
|
||||
|
||||
def audit_token2022_naming(root: pathlib.Path) -> list[Violation]:
|
||||
"""Reject obsolete internal Token2022 spellings while preserving legacy evidence."""
|
||||
|
||||
@@ -421,6 +502,7 @@ def main() -> int:
|
||||
+ audit_kb_lib_tracing(root)
|
||||
+ audit_kb_lib_symbol_prefixes(root)
|
||||
+ audit_reserved_decoder_scaffolds(root)
|
||||
+ audit_reserved_materializer_scaffolds(root)
|
||||
+ audit_token2022_naming(root)
|
||||
+ audit_private_kb_lib_paths_in_active_docs(root)
|
||||
+ audit_solana_types(root)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
# file: scripts/audit_rust_general_rules.py
|
||||
# version: 6
|
||||
# version: 7
|
||||
|
||||
"""Audit mechanically verifiable Rust rules shared by all Rust projects."""
|
||||
|
||||
@@ -38,6 +38,24 @@ def rust_files(root: pathlib.Path) -> list[pathlib.Path]:
|
||||
)
|
||||
|
||||
|
||||
def rustfmt_re_export_key(export_path: str) -> tuple[object, ...]:
|
||||
"""Return the natural path order used by rustfmt for separate imports."""
|
||||
|
||||
path = export_path.removesuffix(";")
|
||||
segments = path.split("::")
|
||||
root_priority = 0 if segments[0] == "self" else 1 if segments[0] == "super" else 2
|
||||
segment_keys: list[tuple[tuple[int, object], ...]] = []
|
||||
for segment in segments:
|
||||
tokens: list[tuple[int, object]] = []
|
||||
for token in re.findall(r"[A-Za-z]+|[0-9]+", segment):
|
||||
if token.isdigit():
|
||||
tokens.append((1, int(token)))
|
||||
else:
|
||||
tokens.append((0, token))
|
||||
segment_keys.append(tuple(tokens))
|
||||
return (root_priority, *segment_keys)
|
||||
|
||||
|
||||
def audit_file(root: pathlib.Path, path: pathlib.Path) -> list[Violation]:
|
||||
"""Audit one Rust source against general rules."""
|
||||
|
||||
@@ -96,7 +114,7 @@ def audit_file(root: pathlib.Path, path: pathlib.Path) -> list[Violation]:
|
||||
violations.append(Violation("RUST016", relative, index, "re-export aliases are forbidden"))
|
||||
previous_export_line: int | None = None
|
||||
previous_export_visibility: str | None = None
|
||||
previous_export_path: str | None = None
|
||||
previous_export_key: tuple[object, ...] | None = None
|
||||
blank_since_export = False
|
||||
for index, line in enumerate(lines, 1):
|
||||
if not line.strip():
|
||||
@@ -121,12 +139,13 @@ def audit_file(root: pathlib.Path, path: pathlib.Path) -> list[Violation]:
|
||||
)
|
||||
)
|
||||
export_path = line.split(" use ", 1)[1]
|
||||
export_key = rustfmt_re_export_key(export_path)
|
||||
if (
|
||||
previous_export_line is not None
|
||||
and previous_export_visibility == visibility
|
||||
and not blank_since_export
|
||||
and previous_export_path is not None
|
||||
and export_path < previous_export_path
|
||||
and previous_export_key is not None
|
||||
and export_key < previous_export_key
|
||||
):
|
||||
violations.append(
|
||||
Violation(
|
||||
@@ -138,12 +157,12 @@ def audit_file(root: pathlib.Path, path: pathlib.Path) -> list[Violation]:
|
||||
)
|
||||
previous_export_line = index
|
||||
previous_export_visibility = visibility
|
||||
previous_export_path = export_path
|
||||
previous_export_key = export_key
|
||||
blank_since_export = False
|
||||
continue
|
||||
previous_export_line = None
|
||||
previous_export_visibility = None
|
||||
previous_export_path = None
|
||||
previous_export_key = None
|
||||
blank_since_export = False
|
||||
if path.name in {"lib.rs", "main.rs"}:
|
||||
for attribute in ("#![warn(missing_docs)]", "#![deny(unreachable_pub)]", "#![forbid(unsafe_code)]"):
|
||||
|
||||
Reference in New Issue
Block a user