0.5.1-pre.004
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
# file: scripts/audit_khadhroony_workspace_rules.py
|
||||
# version: 19
|
||||
# version: 20
|
||||
|
||||
"""Audit mechanically verifiable rules specific to khadhroony-bot3."""
|
||||
|
||||
@@ -864,6 +864,83 @@ def audit_private_ks_lib_paths_in_active_docs(root: pathlib.Path) -> list[Violat
|
||||
return violations
|
||||
|
||||
|
||||
def audit_environment_namespaces(root: pathlib.Path) -> list[Violation]:
|
||||
"""Require workspace-owned environment variables to use KS_* or KB_* namespaces."""
|
||||
|
||||
violations: list[Violation] = []
|
||||
rust_pattern = re.compile(
|
||||
r'std::env::(?:var|var_os|set_var|remove_var)\(\s*"([A-Z][A-Z0-9_]*)"'
|
||||
)
|
||||
rust_roots = [path.parent for path in sorted(root.glob("ks-*/Cargo.toml"))]
|
||||
desktop = root / "kb-app-demo-desktop"
|
||||
if desktop.is_dir():
|
||||
rust_roots.append(desktop)
|
||||
for rust_root in rust_roots:
|
||||
for path in sorted((rust_root / "src").rglob("*.rs")):
|
||||
relative = path.relative_to(root).as_posix()
|
||||
text = path.read_text(encoding="utf-8")
|
||||
for match in rust_pattern.finditer(text):
|
||||
name = match.group(1)
|
||||
if name.startswith(("KS_", "KB_")):
|
||||
continue
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_ENV001",
|
||||
relative,
|
||||
text[: match.start()].count("\n") + 1,
|
||||
f"workspace-owned environment variable `{name}` must use a `KS_*` or `KB_*` namespace",
|
||||
)
|
||||
)
|
||||
env_example = root / ".env.example"
|
||||
if env_example.is_file():
|
||||
assignment = re.compile(r"^\s*#?\s*([A-Z][A-Z0-9_]*)=")
|
||||
for index, line in enumerate(env_example.read_text(encoding="utf-8").splitlines(), 1):
|
||||
match = assignment.match(line)
|
||||
if match is None or match.group(1).startswith(("KS_", "KB_")):
|
||||
continue
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_ENV002",
|
||||
".env.example",
|
||||
index,
|
||||
f"workspace environment example `{match.group(1)}` must use a `KS_*` or `KB_*` namespace",
|
||||
)
|
||||
)
|
||||
config = root / "config/example.config.json"
|
||||
if config.is_file():
|
||||
text = config.read_text(encoding="utf-8")
|
||||
placeholder = re.compile(r"\$\{([A-Z][A-Z0-9_]*)")
|
||||
for match in placeholder.finditer(text):
|
||||
name = match.group(1)
|
||||
if name.startswith(("KS_", "KB_")):
|
||||
continue
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_ENV003",
|
||||
"config/example.config.json",
|
||||
text[: match.start()].count("\n") + 1,
|
||||
f"configuration placeholder `{name}` must use a `KS_*` or `KB_*` namespace",
|
||||
)
|
||||
)
|
||||
guide = root / "docs/DEVNET_EXECUTION_GUIDE.md"
|
||||
if guide.is_file():
|
||||
text = guide.read_text(encoding="utf-8")
|
||||
exported = re.compile(r"\bexport\s+([A-Z][A-Z0-9_]*)=")
|
||||
for match in exported.finditer(text):
|
||||
name = match.group(1)
|
||||
if name.startswith(("KS_", "KB_")):
|
||||
continue
|
||||
violations.append(
|
||||
Violation(
|
||||
"KH_ENV004",
|
||||
"docs/DEVNET_EXECUTION_GUIDE.md",
|
||||
text[: match.start()].count("\n") + 1,
|
||||
f"operator environment variable `{name}` must use a `KS_*` or `KB_*` namespace",
|
||||
)
|
||||
)
|
||||
return violations
|
||||
|
||||
|
||||
def audit_wincode_resolution(root: pathlib.Path) -> list[Violation]:
|
||||
"""Require the currently compatible Solana wincode dependency family."""
|
||||
|
||||
@@ -946,6 +1023,7 @@ def main() -> int:
|
||||
+audit_token_2022_naming(root)
|
||||
+audit_private_ks_lib_paths_in_active_docs(root)
|
||||
+audit_solana_types(root)
|
||||
+audit_environment_namespaces(root)
|
||||
+audit_wincode_resolution(root)
|
||||
)
|
||||
violations.sort(key=lambda item: (item.code, item.path, item.line, item.message))
|
||||
|
||||
Reference in New Issue
Block a user