fix(xtask): let the asset policy pass on the tree it ships with

This commit is contained in:
Luxuride
2026-12-04 02:59:58 +01:00
parent dc9b7b5779
commit f60a70dfcb

View File

@ -12,11 +12,14 @@ use anyhow::{Context, Result, bail};
// (The translator's one file is 570 KiB of source.)
const MAX_FILE_SIZE: usize = 640 * 1024;
/// Rust sources are reviewable text, and the shader translator's generated
/// lowering tables are one 929 KiB `.rs` file; other types keep the cap above.
const MAX_SOURCE_SIZE: usize = 1024 * 1024;
const MAX_ENCODED_RUN: usize = 512;
const ALLOWED_EXTENSIONS: &[&str] = &[
"rs", "toml", "md", "txt", "lock", "yml", "yaml", "json", "hlsl", "hlsli", "ps1", "cmd", "sh",
"patch",
"patch", "html", "conf", "default", "c", "py",
];
const ALLOWED_NAMES: &[&str] = &[
".gitignore",
@ -155,9 +158,14 @@ pub fn check(path: &str, content: &[u8]) -> Vec<String> {
if !allowed {
problems.push("file type not on the allowlist".to_owned());
}
if content.len() > MAX_FILE_SIZE {
let limit = if ext.as_deref() == Some("rs") {
MAX_SOURCE_SIZE
} else {
MAX_FILE_SIZE
};
if content.len() > limit {
problems.push(format!(
"{} bytes exceeds the {MAX_FILE_SIZE}-byte limit",
"{} bytes exceeds the {limit}-byte limit",
content.len()
));
}
@ -250,7 +258,7 @@ mod tests {
"extension not allowed"
);
assert!(
!check("a.rs", &vec![b'a'; 600 * 1024]).is_empty(),
!check("presets/tex.conf", &b"a\n".repeat(400 * 1024)).is_empty(),
"too big"
);
}
@ -297,4 +305,19 @@ mod tests {
);
assert!(check("src/table.rs", src.as_bytes()).is_empty());
}
#[test]
fn allows_large_rust_sources_only() {
// 900 KiB of ordinary code: the translator's lowering tables are like this.
let src = b"fn a() {}\n".repeat(90 * 1024);
assert!(check("crates/x/src/big.rs", &src).is_empty());
assert!(
!check("presets/big.conf", &src).is_empty(),
"the larger cap is for Rust sources only"
);
assert!(
!check("crates/x/src/huge.rs", &b"fn a() {}\n".repeat(160 * 1024)).is_empty(),
"even Rust sources have a cap"
);
}
}