2 Commits
master ... cli

Author SHA1 Message Date
3f8a6fdff6 w 2025-06-07 02:30:36 -07:00
c5274ff194 entire cli 2025-06-07 02:23:30 -07:00
7 changed files with 251 additions and 15 deletions

129
Cargo.lock generated

@ -54,6 +54,56 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys 0.59.0",
]
[[package]]
name = "arrayref"
version = "0.3.9"
@ -234,6 +284,61 @@ dependencies = [
"windows-link",
]
[[package]]
name = "clap"
version = "4.5.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "cli"
version = "0.1.0"
dependencies = [
"clap",
"maps-validation",
"rbx_binary",
]
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "const-oid"
version = "0.9.6"
@ -897,6 +1002,12 @@ dependencies = [
"serde",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.15"
@ -1138,6 +1249,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]]
name = "openssl"
version = "0.10.73"
@ -1901,6 +2018,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "submissions-api"
version = "0.7.2"
@ -2273,6 +2396,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "vcpkg"
version = "0.2.15"

@ -2,5 +2,6 @@
members = [
"validation",
"validation/api",
"validation/cli",
]
resolver = "2"

@ -0,0 +1,9 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = { version = "4.5.39", features = ["derive"] }
maps-validation = { path = ".." }
rbx_binary = "1.0.0"

@ -0,0 +1,73 @@
use clap::{Args,Parser,Subcommand};
use std::path::{Path,PathBuf};
#[derive(Parser)]
#[command(author,version,about,long_about=None)]
#[command(propagate_version=true)]
struct Cli{
#[command(subcommand)]
command:Commands,
}
#[derive(Subcommand)]
enum Commands{
Check(CheckCommand),
}
#[derive(Args)]
struct CheckCommand{
files:Vec<PathBuf>,
}
fn main(){
let cli=Cli::parse();
match cli.command{
Commands::Check(command)=>command.run().unwrap(),
}
}
#[allow(dead_code)]
#[derive(Debug)]
enum CheckError{
Io(std::io::Error),
Binary(maps_validation::rbx_util::ReadDomError),
CheckDom(maps_validation::rbx_util::GetRootInstanceError),
}
fn check(path:&Path)->Result<(),CheckError>{
let name=path.file_name().unwrap_or_default().to_str().unwrap_or_default();
let file=std::fs::read(path).map_err(CheckError::Io)?;
let dom=maps_validation::rbx_util::read_dom(file.as_slice()).map_err(CheckError::Binary)?;
let check=maps_validation::message_handler::MessageHandler::check_dom(&dom).map_err(CheckError::CheckDom)?;
match check.result(){
Ok(_map_info)=>(),//println!("good {}",map_info.display_name),
Err(Ok(check_list))=>println!("bad {name} Error: {}",check_list.summary()),
Err(Err(e))=>println!("ugly {name} Error: {e}"),
}
Ok(())
}
impl CheckCommand{
fn run(self)->Result<(),()>{
let mut handles=Vec::new();
for path in self.files{
if path.is_file(){
handles.push(std::thread::spawn(move||{
if let Err(e)=check(path.as_path()){
let name=path.file_name().unwrap_or_default().to_str().unwrap_or_default();
println!("ugly {name} Error: {e:?}");
}
}));
}
}
for handle in handles{
handle.join().unwrap();
}
Ok(())
}
}

@ -371,6 +371,7 @@ impl<ID:Copy+Eq+std::hash::Hash,T> SetDifferenceCheckContextAtLeastOne<ID,T>{
}
/// Info lifted out of a fully compliant map
#[derive(Debug)]
pub struct MapInfoOwned{
pub display_name:String,
pub creator:String,
@ -382,7 +383,7 @@ struct Exists;
struct Absent;
/// The result of every map check.
struct MapCheck<'a>{
pub struct MapCheck<'a>{
// === METADATA CHECKS ===
// The root must be of class Model
model_class:StringCheck<'a,(),&'static str>,
@ -511,7 +512,7 @@ impl<'a> ModelInfo<'a>{
}
impl MapCheck<'_>{
fn result(self)->Result<MapInfoOwned,Result<MapCheckList,serde_json::Error>>{
pub fn result(self)->Result<MapInfoOwned,Result<MapCheckList,serde_json::Error>>{
match self{
MapCheck{
model_class:StringCheck(Ok(())),
@ -586,10 +587,10 @@ impl<D:std::fmt::Display> std::fmt::Display for Duplicates<D>{
}
#[derive(serde::Serialize)]
struct CheckSummary{
pub struct CheckSummary{
name:&'static str,
summary:String,
passed:bool,
pub passed:bool,
details:serde_json::Value,
}
impl CheckSummary{
@ -780,17 +781,18 @@ impl MapCheck<'_>{
}
#[derive(serde::Serialize)]
struct MapCheckList{
checks:Box<[CheckSummary;16]>,
pub struct MapCheckList{
pub checks:Box<[CheckSummary;16]>,
}
impl MapCheckList{
fn summary(&self)->String{
pub fn summary(&self)->String{
Separated::new("; ",||self.checks.iter().filter_map(|check|
(!check.passed).then_some(check.summary.as_str())
)).to_string()
}
}
#[derive(Debug)]
pub struct Summary{
pub summary:String,
pub json:serde_json::Value,
@ -824,14 +826,7 @@ impl crate::message_handler::MessageHandler{
// decode dom (slow!)
let dom=maybe_gzip.read_with(read_dom,read_dom).map_err(Error::ModelFileDecode)?;
// extract the root instance
let model_instance=get_root_instance(&dom).map_err(Error::GetRootInstance)?;
// extract information from the model
let model_info=get_model_info(&dom,model_instance);
// convert the model information into a structured report
let map_check=model_info.check();
let map_check=Self::check_dom(&dom).map_err(Error::GetRootInstance)?;
// check the report, generate an error message if it fails the check
let status=match map_check.result(){
@ -845,4 +840,16 @@ impl crate::message_handler::MessageHandler{
Ok(CheckReportAndVersion{status,version})
}
pub fn check_dom(dom:&rbx_dom_weak::WeakDom)->Result<MapCheck,GetRootInstanceError>{
// extract the root instance
let model_instance=get_root_instance(&dom)?;
// extract information from the model
let model_info=get_model_info(&dom,model_instance);
// convert the model information into a structured report
let map_check=model_info.check();
Ok(map_check)
}
}

16
validation/src/lib.rs Normal file

@ -0,0 +1,16 @@
pub mod rbx_util;
pub mod message_handler;
pub mod nats_types;
pub mod types;
pub mod download;
pub mod check;
pub mod check_mapfix;
pub mod check_submission;
pub mod create;
pub mod create_mapfix;
pub mod create_submission;
pub mod upload_mapfix;
pub mod upload_submission;
pub mod validator;
pub mod validate_mapfix;
pub mod validate_submission;

@ -40,6 +40,7 @@ fn find_first_child_name_and_class<'a>(dom:&'a rbx_dom_weak::WeakDom,instance:&r
instance.children().iter().filter_map(|&r|dom.get_by_ref(r)).find(|inst|inst.name==name&&inst.class==class)
}
#[derive(Debug)]
pub enum GameID{
Bhop=1,
Surf=2,