obfuskator/crates/noxis-structure-check/src/lib.rs
loki5512344 82794fed78
docs: sync status with code, add AI-resistance research, restyle README
Documentation had drifted from the actual implementation: the noxis
(CLI) and noxis-verify crates were fully built and tested but every
doc called them "not started". Verified against the code (build +
test run) and corrected status across README.md, todo.md,
architecture.md, techniques.md and learnings/{lessons,priorities}.md.

Also:
- restyled README.md (badges, no em dashes, usage examples, dropped
  the redundant "Принципы" section already covered elsewhere)
- added docs/learnings/ai-resistance.md: a sourced writeup of what
  actually works against LLM-driven reverse engineering (Elastic
  Security Labs' Opus 4.6 vs Tigress study, the Acoda paper) and what
  of it applies to noxis, plus concrete todo.md §7 items
- noxis-structure-check: the 250-line/4-file gate was scanning
  docs/**, which fought against writing documentation freely; it now
  only scans crates/*/{src,tests,benches} and only counts .rs files

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-10-08 22:32:30 +02:00

91 lines
2.9 KiB
Rust

//! Compile-time gate for the project structure rules.
//!
//! Every crate calls [`check`] from its `build.rs`, so a file that grows past
//! 250 lines or a directory that fills up with a fifth file fails the build.
mod rules;
pub use rules::{MAX_DIR_FILES, MAX_FILE_LINES, check, scan};
#[cfg(test)]
mod tests {
#![allow(clippy::expect_used, clippy::unwrap_used)]
use std::fs;
use std::path::{Path, PathBuf};
use super::scan;
struct TempDir(PathBuf);
impl TempDir {
fn new(tag: &str) -> Self {
let path =
std::env::temp_dir().join(format!("noxis-structure-{tag}-{}", std::process::id()));
let _ = fs::remove_dir_all(&path);
fs::create_dir_all(&path).expect("create temp dir");
Self(path)
}
}
impl Drop for TempDir {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
fn violations(dir: &Path) -> Vec<String> {
let mut out = Vec::new();
scan(dir, &mut out);
out
}
#[test]
fn rejects_file_over_line_limit() {
let tmp = TempDir::new("long");
fs::write(tmp.0.join("lib.rs"), "fn main() {}\n".repeat(300)).expect("write");
let found = violations(&tmp.0);
assert_eq!(found.len(), 1, "{found:?}");
assert!(found[0].contains("lines >"), "{found:?}");
}
#[test]
fn rejects_directory_over_file_limit() {
let tmp = TempDir::new("many");
for index in 0..super::MAX_DIR_FILES + 1 {
fs::write(tmp.0.join(format!("m{index}.rs")), "").expect("write");
}
let found = violations(&tmp.0);
assert_eq!(found.len(), 1, "{found:?}");
assert!(found[0].contains("files >"), "{found:?}");
}
#[test]
fn accepts_compact_tree() {
let tmp = TempDir::new("ok");
fs::create_dir(tmp.0.join("sub")).expect("mkdir");
fs::write(tmp.0.join("lib.rs"), "pub fn f() {}\n").expect("write");
fs::write(tmp.0.join("sub").join("a.rs"), "pub fn a() {}\n").expect("write");
let found = violations(&tmp.0);
assert!(found.is_empty(), "{found:?}");
}
#[test]
fn ignores_non_limited_extensions() {
let tmp = TempDir::new("ext");
fs::write(tmp.0.join("notes.txt"), "line\n".repeat(300)).expect("write");
let found = violations(&tmp.0);
assert!(found.is_empty(), "{found:?}");
}
#[test]
fn ignores_markdown_size_and_count() {
// Правила — только про Rust-код: `.md` не лимитирован ни по
// строкам, ни в счётчике файлов директории.
let tmp = TempDir::new("md");
for index in 0..super::MAX_DIR_FILES + 3 {
fs::write(tmp.0.join(format!("doc{index}.md")), "line\n".repeat(300)).expect("write");
}
let found = violations(&tmp.0);
assert!(found.is_empty(), "{found:?}");
}
}