Merge pull request #633 from ludovic111/feat/port-pack-report
horizon-port-pack report: coverage per mod, and ATM10 measured
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//! Step 1, import: a Modrinth `.mrpack`, a CurseForge zip, or an instance
|
||||
//! folder (Prism / MultiMC, or a plain `mods/` folder) to `pack.json`.
|
||||
//! Step 1, import: a Modrinth `.mrpack`, a CurseForge zip, an instance
|
||||
//! folder (Prism / MultiMC, or a plain `mods/` folder), or a Crash Assistant
|
||||
//! `modlist.json` (the list packs such as ATM10 publish) to `pack.json`.
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
@@ -37,6 +38,13 @@ pub struct PackFile {
|
||||
/// CurseForge project and file ids.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub curseforge: Option<(u64, u64)>,
|
||||
/// The mod id, name and version a mod list states (`modlist.json`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub mod_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub version: Option<String>,
|
||||
/// The jar on disk (instances only).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub jar: Option<PathBuf>,
|
||||
@@ -63,6 +71,12 @@ pub fn import(path: &Path) -> Result<Pack, String> {
|
||||
if path.is_dir() {
|
||||
return instance(path);
|
||||
}
|
||||
if path.extension().is_some_and(|e| e == "json") {
|
||||
let text = fs::read_to_string(path).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
let list: Value = serde_json::from_str(text.trim_start_matches('\u{feff}'))
|
||||
.map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
return modlist(&list);
|
||||
}
|
||||
let file = fs::File::open(path).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
let mut zip = zip::ZipArchive::new(file).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
if let Some(index) = read_json(&mut zip, "modrinth.index.json")? {
|
||||
@@ -186,6 +200,54 @@ pub fn curseforge(manifest: &Value, names: &[String]) -> Pack {
|
||||
}
|
||||
}
|
||||
|
||||
/// Crash Assistant's `config/crash_assistant/modlist.json`: jar name → mod
|
||||
/// id, name, version and Modrinth SHA-1, with the loader as an entry of its
|
||||
/// own. NeoForge `21.1.x` runs Minecraft 1.21.1.
|
||||
pub fn modlist(list: &Value) -> Result<Pack, String> {
|
||||
let entries = list.as_object().ok_or("modlist.json: not an object")?;
|
||||
let mut pack = Pack {
|
||||
name: "modlist".into(),
|
||||
format: "modlist".into(),
|
||||
..Pack::default()
|
||||
};
|
||||
for (key, e) in entries {
|
||||
let jar = e["jarName"].as_str().unwrap_or(key);
|
||||
if jar.ends_with("(modloader)") {
|
||||
let version = str_of(e, "version");
|
||||
let (loader, v) = version.split_once('-').unwrap_or(("", &version));
|
||||
pack.loader = loader.to_owned();
|
||||
pack.loader_version = v.to_owned();
|
||||
if loader == "neoforge" {
|
||||
let mut parts = v.split('.');
|
||||
if let (Some(a), Some(b)) = (parts.next(), parts.next()) {
|
||||
pack.minecraft = if b == "0" {
|
||||
format!("1.{a}")
|
||||
} else {
|
||||
format!("1.{a}.{b}")
|
||||
};
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let folder = if jar.ends_with(".zip") {
|
||||
"datapacks"
|
||||
} else {
|
||||
"mods"
|
||||
};
|
||||
let text = |k: &str| e[k].as_str().filter(|v| !v.is_empty()).map(str::to_owned);
|
||||
pack.files.push(PackFile {
|
||||
path: format!("{folder}/{jar}"),
|
||||
sha1: text("modrinthHash"),
|
||||
mod_id: text("modId"),
|
||||
name: text("name"),
|
||||
version: text("version"),
|
||||
..PackFile::default()
|
||||
});
|
||||
}
|
||||
pack.files.sort_by(|a, b| a.path.cmp(&b.path));
|
||||
Ok(pack)
|
||||
}
|
||||
|
||||
/// A Prism / MultiMC instance (`mmc-pack.json`), a game folder, or a
|
||||
/// folder of jars: the jars on disk, hashed.
|
||||
fn instance(dir: &Path) -> Result<Pack, String> {
|
||||
@@ -319,6 +381,30 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_a_crash_assistant_mod_list() {
|
||||
let list = serde_json::json!({
|
||||
"neoforge-21.1.259 (modloader)": {"jarName": "neoforge-21.1.259 (modloader)",
|
||||
"modId": "neoforge", "version": "neoforge-21.1.259"},
|
||||
"mcw-doors-1.1.2.jar": {"jarName": "mcw-doors-1.1.2.jar", "modId": "mcwdoors",
|
||||
"modrinthHash": "0123456789abcdef0123456789abcdef01234567"},
|
||||
"sawmill.zip": {"jarName": "sawmill.zip"}
|
||||
});
|
||||
let pack = modlist(&list).unwrap();
|
||||
assert_eq!(
|
||||
(
|
||||
pack.minecraft.as_str(),
|
||||
pack.loader.as_str(),
|
||||
pack.loader_version.as_str()
|
||||
),
|
||||
("1.21.1", "neoforge", "21.1.259")
|
||||
);
|
||||
let paths: Vec<&str> = pack.files.iter().map(|f| f.path.as_str()).collect();
|
||||
assert_eq!(paths, ["datapacks/sawmill.zip", "mods/mcw-doors-1.1.2.jar"]);
|
||||
assert!(pack.files[1].sha1.is_some());
|
||||
assert_eq!(pack.files[1].mod_id.as_deref(), Some("mcwdoors"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_a_curseforge_manifest() {
|
||||
let manifest = json!({"name": "CF", "overrides": "overrides",
|
||||
|
||||
@@ -78,6 +78,7 @@ pub fn build(pack: &Pack, cache: &Cache, work: &Path) -> Vec<Record> {
|
||||
.as_ref()
|
||||
.map(|i| i.mod_id.clone())
|
||||
.filter(|k| !k.is_empty())
|
||||
.or_else(|| f.mod_id.clone())
|
||||
.or_else(|| Some(p("slug")).filter(|s| !s.is_empty()))
|
||||
.unwrap_or(stem);
|
||||
let (client, server) = match project {
|
||||
@@ -97,7 +98,9 @@ pub fn build(pack: &Pack, cache: &Cache, work: &Path) -> Vec<Record> {
|
||||
.as_ref()
|
||||
.map(|i| i.name.clone())
|
||||
.filter(|n| !n.is_empty())
|
||||
.unwrap_or_else(|| p("title"));
|
||||
.or_else(|| Some(p("title")).filter(|t| !t.is_empty()))
|
||||
.or_else(|| f.name.clone())
|
||||
.unwrap_or_default();
|
||||
let (class, tier, confidence) =
|
||||
match known.get(&[key.as_str(), p("slug").as_str(), name.as_str()]) {
|
||||
Some((c, t)) => (c.clone(), t.clone(), "known".to_owned()),
|
||||
@@ -123,8 +126,9 @@ pub fn build(pack: &Pack, cache: &Cache, work: &Path) -> Vec<Record> {
|
||||
.versions
|
||||
.get(sha1)
|
||||
.and_then(|v| v["version_number"].as_str())
|
||||
.unwrap_or("")
|
||||
.to_owned()
|
||||
.map(str::to_owned)
|
||||
.or_else(|| f.version.clone())
|
||||
.unwrap_or_default()
|
||||
}),
|
||||
path: f.path.clone(),
|
||||
class,
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
//! (`tools/neoforge_oracle.py`), blocks and items come from its facts;
|
||||
//! `--resources` limits templates to the blocks Horizon's tables have.
|
||||
//!
|
||||
//! - `report <work>`: the coverage report, per mod ported, partial, not yet
|
||||
//! or not needed with the reason, in `<work>/coverage.json` and
|
||||
//! `coverage.md`.
|
||||
//!
|
||||
//! The work folder belongs to the user: jars and carried-over files stay
|
||||
//! there and are never uploaded or committed.
|
||||
mod carry;
|
||||
@@ -21,10 +25,11 @@ mod inventory;
|
||||
mod jar;
|
||||
mod modrinth;
|
||||
mod oracle;
|
||||
mod report;
|
||||
|
||||
use std::{fs, path::Path, process::ExitCode};
|
||||
|
||||
const USAGE: &str = "usage: horizon-port-pack import <pack> <work> | inventory <work> [--offline] | carry <work> [--resources <prepared>] [<mod id>...]";
|
||||
const USAGE: &str = "usage: horizon-port-pack import <pack> <work> | inventory <work> [--offline] | carry <work> [--resources <prepared>] [<mod id>...] | report <work>";
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
@@ -49,6 +54,7 @@ fn main() -> ExitCode {
|
||||
};
|
||||
carry(w, resources.as_deref(), &rest)
|
||||
}),
|
||||
Some("report") => path(1).and_then(report),
|
||||
_ => Err(USAGE.to_owned()),
|
||||
};
|
||||
match result {
|
||||
@@ -70,6 +76,22 @@ fn read_json<T: serde::de::DeserializeOwned>(path: &Path) -> Result<T, String> {
|
||||
serde_json::from_str(&text).map_err(|e| format!("{}: {e}", path.display()))
|
||||
}
|
||||
|
||||
fn report(work: &Path) -> Result<(), String> {
|
||||
let pack: import::Pack = read_json(&work.join("pack.json"))?;
|
||||
let records: Vec<inventory::Record> = read_json(&work.join("inventory.json"))?;
|
||||
let rows = report::build(&records, work);
|
||||
write_json(&work.join("coverage.json"), &rows)?;
|
||||
let title = format!(
|
||||
"{} ({} {}, Minecraft {})",
|
||||
pack.name, pack.loader, pack.loader_version, pack.minecraft
|
||||
);
|
||||
fs::write(work.join("coverage.md"), report::markdown(&title, &rows))
|
||||
.map_err(|e| format!("coverage.md: {e}"))?;
|
||||
println!("{title}: {} files: {:?}", rows.len(), report::counts(&rows));
|
||||
println!("{}", work.join("coverage.md").display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn import(pack: &Path, work: &Path) -> Result<(), String> {
|
||||
let pack = import::import(pack)?;
|
||||
fs::create_dir_all(work).map_err(|e| format!("{}: {e}", work.display()))?;
|
||||
|
||||
@@ -0,0 +1,428 @@
|
||||
//! Step 7, the coverage report: per mod, ported, partial, not yet or not
|
||||
//! needed, with the reason, and the totals by class, tier and licence
|
||||
//! (`coverage.json`, `coverage.md`). It reads what the other steps wrote:
|
||||
//! the inventory, each mod's `carry-report.json` and its harness result
|
||||
//! (`tools/mod_port_harness.py`).
|
||||
use crate::inventory::Record;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::{collections::BTreeMap, fmt::Write, path::Path};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum Status {
|
||||
Ported,
|
||||
Partial,
|
||||
NotYet,
|
||||
NotNeeded,
|
||||
}
|
||||
impl Status {
|
||||
pub const ALL: [Status; 4] = [
|
||||
Status::Ported,
|
||||
Status::Partial,
|
||||
Status::NotYet,
|
||||
Status::NotNeeded,
|
||||
];
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Status::Ported => "ported",
|
||||
Status::Partial => "partial",
|
||||
Status::NotYet => "not yet",
|
||||
Status::NotNeeded => "not needed",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Row {
|
||||
pub key: String,
|
||||
pub name: String,
|
||||
pub class: String,
|
||||
pub tier: String,
|
||||
pub license: String,
|
||||
/// `permissive`, `copyleft`, `all-rights-reserved`, `restricted`
|
||||
/// (non-commercial or no-derivatives), `custom` or `unknown`.
|
||||
pub license_kind: String,
|
||||
pub status: Status,
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
/// The licence family of an SPDX id or a `mods.toml` licence text.
|
||||
pub fn license_kind(license: &str) -> &'static str {
|
||||
let l = license.to_ascii_lowercase();
|
||||
if l.is_empty() || l.starts_with("unknown") {
|
||||
"unknown"
|
||||
} else if l.contains("-nc") || l.contains("-nd") || l.contains("noncommercial") {
|
||||
"restricted"
|
||||
} else if l.contains("all-rights-reserved") || l.contains("all rights reserved") || l == "arr" {
|
||||
"all-rights-reserved"
|
||||
} else if ["gpl", "mpl", "eupl", "general public"]
|
||||
.iter()
|
||||
.any(|k| l.contains(k))
|
||||
{
|
||||
"copyleft"
|
||||
} else if [
|
||||
"mit",
|
||||
"apache",
|
||||
"bsd",
|
||||
"cc0",
|
||||
"cc-by",
|
||||
"unlicense",
|
||||
"isc",
|
||||
"zlib",
|
||||
]
|
||||
.iter()
|
||||
.any(|k| l.contains(k))
|
||||
{
|
||||
"permissive"
|
||||
} else {
|
||||
"custom"
|
||||
}
|
||||
}
|
||||
|
||||
/// What still blocks a mod of this tier that has not been carried over.
|
||||
fn not_yet(tier: &str) -> &'static str {
|
||||
match tier {
|
||||
"data" => "data tier: carry-over only, no agent; its jar is not in the work folder",
|
||||
"logic" => {
|
||||
"needs mod API 0.3: behaviour callbacks (use, place, break, ticks) and server events"
|
||||
}
|
||||
"machines" => "needs mod API 0.4: block entities, menus, capabilities and mod networking",
|
||||
"deep" => {
|
||||
"needs mod API 0.5: entities, custom renderers and models, dimensions, new vanilla hooks"
|
||||
}
|
||||
"client" => "needs the client interfaces (keys, target, inventory-read, ui, render)",
|
||||
_ => "not classified",
|
||||
}
|
||||
}
|
||||
|
||||
fn not_needed(class: &str) -> &'static str {
|
||||
match class {
|
||||
"library" => "library: its API maps to Horizon's mod API and SDK",
|
||||
"performance" => "performance mod: Horizon's engine is the replacement",
|
||||
"other" => "pack tooling or an engine feature, folded into the pipeline or the engine",
|
||||
"client-ui" => "built into Horizon",
|
||||
_ => "nothing to port",
|
||||
}
|
||||
}
|
||||
|
||||
/// A carried-over mod: ported when its harness passes with nothing left
|
||||
/// out and nothing the templates miss; else partial, with what is missing.
|
||||
fn carried(work: &Path, key: &str) -> Option<(Status, String)> {
|
||||
let dir = work.join("mods").join(key);
|
||||
let carry: Value =
|
||||
serde_json::from_slice(&std::fs::read(dir.join("carry-report.json")).ok()?).ok()?;
|
||||
let count = |k: &str| carry[k].as_object().map_or(0, |o| o.len());
|
||||
let (blocks, items) = (count("blocks"), carry["items"].as_u64().unwrap_or(0));
|
||||
let (left_blocks, left_items) = (count("blocks_unknown"), count("items_unknown"));
|
||||
// A class of its own is code the facts cannot show; anything else the
|
||||
// template misses (shapes, sounds) the harness also reports.
|
||||
let mut differences = 0;
|
||||
let mut own_code = 0;
|
||||
for list in carry["differences"]
|
||||
.as_object()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|(_, v)| v)
|
||||
{
|
||||
let notes: Vec<&str> = list
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(Value::as_str)
|
||||
.collect();
|
||||
if notes.iter().any(|n| n.starts_with("class ")) {
|
||||
own_code += 1;
|
||||
}
|
||||
if notes.iter().any(|n| !n.starts_with("class ")) {
|
||||
differences += 1;
|
||||
}
|
||||
}
|
||||
let mut gaps = Vec::new();
|
||||
if left_blocks > 0 {
|
||||
gaps.push(format!(
|
||||
"{left_blocks} blocks left out (no vanilla template)"
|
||||
));
|
||||
}
|
||||
if left_items > 0 {
|
||||
gaps.push(format!("{left_items} items left out"));
|
||||
}
|
||||
if differences > 0 {
|
||||
gaps.push(format!(
|
||||
"{differences} blocks or items differ from their templates"
|
||||
));
|
||||
}
|
||||
let harness: Option<Value> = std::fs::read(dir.join("harness/result.json"))
|
||||
.ok()
|
||||
.and_then(|b| serde_json::from_slice(&b).ok());
|
||||
let mut checked = 0;
|
||||
match &harness {
|
||||
Some(h) => {
|
||||
for (name, c) in h["checks"].as_object().into_iter().flatten() {
|
||||
let (p, f) = (
|
||||
c["passed"].as_u64().unwrap_or(0),
|
||||
c["failed"].as_u64().unwrap_or(0),
|
||||
);
|
||||
checked += p + f;
|
||||
if f > 0 {
|
||||
gaps.push(format!("{name} {p}/{}", p + f));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => gaps.push("harness not run".into()),
|
||||
}
|
||||
let worldgen = carry["worldgen"].as_u64().unwrap_or(0);
|
||||
if blocks == 0 && items == 0 && checked == 0 {
|
||||
let what = if worldgen > 0 {
|
||||
format!("{worldgen} worldgen files carried, not compared yet")
|
||||
} else {
|
||||
"nothing registered to compare".into()
|
||||
};
|
||||
return Some((Status::Partial, what));
|
||||
}
|
||||
let mut summary = format!("{blocks} blocks, {items} items");
|
||||
if own_code > 0 {
|
||||
let _ = write!(
|
||||
summary,
|
||||
" ({own_code} with code of their own, not compared)"
|
||||
);
|
||||
}
|
||||
if gaps.is_empty() {
|
||||
Some((Status::Ported, format!("{summary}; harness green")))
|
||||
} else {
|
||||
Some((Status::Partial, format!("{summary}; {}", gaps.join("; "))))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(records: &[Record], work: &Path) -> Vec<Row> {
|
||||
let mut rows: Vec<Row> = records
|
||||
.iter()
|
||||
.map(|r| {
|
||||
let (status, reason) = if r.class == "unknown" {
|
||||
let why =
|
||||
"unclassified: its jar (mods.toml, file census) or a reviewed row decides";
|
||||
(Status::NotYet, why.to_owned())
|
||||
} else if r.tier == "none" || matches!(r.class.as_str(), "library" | "performance") {
|
||||
(Status::NotNeeded, not_needed(&r.class).to_owned())
|
||||
} else if let Some(c) = carried(work, &r.key) {
|
||||
c
|
||||
} else {
|
||||
let mut why = not_yet(&r.tier).to_owned();
|
||||
if r.tier == "data" && r.jar.is_some() {
|
||||
why = "data tier: carry-over not run yet".into();
|
||||
}
|
||||
if r.class == "integration" {
|
||||
why = format!("after the mods it joins are ported; {why}");
|
||||
}
|
||||
(Status::NotYet, why)
|
||||
};
|
||||
Row {
|
||||
key: r.key.clone(),
|
||||
name: r.name.clone(),
|
||||
class: r.class.clone(),
|
||||
tier: r.tier.clone(),
|
||||
license: r.license.clone(),
|
||||
license_kind: license_kind(&r.license).to_owned(),
|
||||
status,
|
||||
reason,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
// A mod waits on its dependencies that are not ported.
|
||||
let status: BTreeMap<String, Status> = rows.iter().map(|r| (r.key.clone(), r.status)).collect();
|
||||
for (row, r) in rows.iter_mut().zip(records) {
|
||||
if row.status == Status::NotNeeded {
|
||||
continue;
|
||||
}
|
||||
let waiting: Vec<&str> = r
|
||||
.depends
|
||||
.iter()
|
||||
.filter(|d| status.get(*d) == Some(&Status::NotYet))
|
||||
.map(String::as_str)
|
||||
.collect();
|
||||
if !waiting.is_empty() {
|
||||
let _ = write!(row.reason, "; waits on {}", waiting.join(", "));
|
||||
}
|
||||
}
|
||||
rows
|
||||
}
|
||||
|
||||
/// Rows counted by `field` and status.
|
||||
fn table(rows: &[Row], title: &str, field: fn(&Row) -> &str) -> String {
|
||||
let mut counts: BTreeMap<&str, [usize; 4]> = BTreeMap::new();
|
||||
for r in rows {
|
||||
let i = Status::ALL.iter().position(|s| *s == r.status).unwrap_or(0);
|
||||
counts.entry(field(r)).or_default()[i] += 1;
|
||||
}
|
||||
let mut out = format!(
|
||||
"| {title} | ported | partial | not yet | not needed | all |\n|---|---:|---:|---:|---:|---:|\n"
|
||||
);
|
||||
let mut totals = [0usize; 4];
|
||||
for (k, c) in &counts {
|
||||
let all: usize = c.iter().sum();
|
||||
let _ = writeln!(
|
||||
out,
|
||||
"| {k} | {} | {} | {} | {} | {all} |",
|
||||
c[0], c[1], c[2], c[3]
|
||||
);
|
||||
for (t, n) in totals.iter_mut().zip(c) {
|
||||
*t += n;
|
||||
}
|
||||
}
|
||||
let all: usize = totals.iter().sum();
|
||||
let _ = writeln!(
|
||||
out,
|
||||
"| **all** | **{}** | **{}** | **{}** | **{}** | **{all}** |",
|
||||
totals[0], totals[1], totals[2], totals[3]
|
||||
);
|
||||
out
|
||||
}
|
||||
|
||||
pub fn markdown(pack: &str, rows: &[Row]) -> String {
|
||||
let mut out = format!("# Coverage: {pack}\n\n");
|
||||
out += &table(rows, "class", |r| &r.class);
|
||||
out += "\n";
|
||||
out += &table(rows, "tier", |r| &r.tier);
|
||||
out += "\n";
|
||||
out += &table(rows, "licence", |r| &r.license_kind);
|
||||
out += "\nPorts stay local. Only permissive or copyleft ports could ever be published, and only after Ludovic asks the authors.\n\n";
|
||||
out += "| mod | class | tier | licence | status | why |\n|---|---|---|---|---|---|\n";
|
||||
let mut sorted: Vec<&Row> = rows.iter().collect();
|
||||
sorted.sort_by(|a, b| (a.status, &a.key).cmp(&(b.status, &b.key)));
|
||||
for r in sorted {
|
||||
let _ = writeln!(
|
||||
out,
|
||||
"| {} | {} | {} | {} | {} | {} |",
|
||||
r.key,
|
||||
r.class,
|
||||
r.tier,
|
||||
r.license.replace('|', "/"),
|
||||
r.status.label(),
|
||||
r.reason.replace('|', "/")
|
||||
);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn counts(rows: &[Row]) -> Vec<(&'static str, usize)> {
|
||||
Status::ALL
|
||||
.iter()
|
||||
.map(|s| (s.label(), rows.iter().filter(|r| r.status == *s).count()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn record(key: &str, class: &str, tier: &str, depends: &[&str]) -> Record {
|
||||
Record {
|
||||
key: key.into(),
|
||||
class: class.into(),
|
||||
tier: tier.into(),
|
||||
license: "MIT".into(),
|
||||
depends: depends.iter().map(|d| (*d).to_owned()).collect(),
|
||||
..Record::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn statuses_and_reasons() {
|
||||
let work = std::env::temp_dir().join(format!("horizon-report-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&work);
|
||||
let write = |key: &str, carry: Value, harness: Option<Value>| {
|
||||
let dir = work.join("mods").join(key);
|
||||
std::fs::create_dir_all(dir.join("harness")).unwrap();
|
||||
std::fs::write(dir.join("carry-report.json"), carry.to_string()).unwrap();
|
||||
if let Some(h) = harness {
|
||||
std::fs::write(dir.join("harness/result.json"), h.to_string()).unwrap();
|
||||
}
|
||||
};
|
||||
let green = serde_json::json!({"checks": {"blocks": {"passed": 3, "failed": 0}}});
|
||||
write(
|
||||
"doors",
|
||||
serde_json::json!({"blocks": {"a": "minecraft:oak_door"}, "items": 0,
|
||||
"differences": {"a": ["class m.Door (behaviour beyond DoorBlock)"]}}),
|
||||
Some(green),
|
||||
);
|
||||
write(
|
||||
"paths",
|
||||
serde_json::json!({"blocks": {"a": "minecraft:stone"}, "items": 1,
|
||||
"blocks_unknown": {"b": "no vanilla Block"}}),
|
||||
Some(serde_json::json!({"checks": {"shapes": {"passed": 1, "failed": 2}}})),
|
||||
);
|
||||
let records = [
|
||||
record("doors", "content", "data", &[]),
|
||||
record("paths", "content", "data", &[]),
|
||||
record("lib", "library", "none", &[]),
|
||||
record("machine", "content", "machines", &["lib"]),
|
||||
record("addon", "integration", "logic", &["machine"]),
|
||||
record("mystery", "unknown", "none", &[]),
|
||||
];
|
||||
let rows = build(&records, &work);
|
||||
let by: BTreeMap<&str, &Row> = rows.iter().map(|r| (r.key.as_str(), r)).collect();
|
||||
assert_eq!(by["doors"].status, Status::Ported);
|
||||
assert!(
|
||||
by["doors"].reason.contains("1 with code of their own"),
|
||||
"{}",
|
||||
by["doors"].reason
|
||||
);
|
||||
assert_eq!(by["paths"].status, Status::Partial);
|
||||
assert!(
|
||||
by["paths"].reason.contains("1 blocks left out"),
|
||||
"{}",
|
||||
by["paths"].reason
|
||||
);
|
||||
assert!(
|
||||
by["paths"].reason.contains("shapes 1/3"),
|
||||
"{}",
|
||||
by["paths"].reason
|
||||
);
|
||||
assert_eq!(by["lib"].status, Status::NotNeeded);
|
||||
assert_eq!(by["machine"].status, Status::NotYet);
|
||||
assert!(by["machine"].reason.contains("0.4"));
|
||||
assert!(by["addon"].reason.starts_with("after the mods it joins"));
|
||||
assert!(
|
||||
by["addon"].reason.ends_with("waits on machine"),
|
||||
"{}",
|
||||
by["addon"].reason
|
||||
);
|
||||
assert_eq!(by["mystery"].status, Status::NotYet);
|
||||
assert_eq!(
|
||||
counts(&rows),
|
||||
[
|
||||
("ported", 1),
|
||||
("partial", 1),
|
||||
("not yet", 3),
|
||||
("not needed", 1)
|
||||
]
|
||||
);
|
||||
let md = markdown("test", &rows);
|
||||
assert!(
|
||||
md.contains("| **all** | **1** | **1** | **3** | **1** | **6** |"),
|
||||
"{md}"
|
||||
);
|
||||
std::fs::remove_dir_all(&work).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn licence_families() {
|
||||
assert_eq!(license_kind("MIT"), "permissive");
|
||||
assert_eq!(license_kind("CC0-1.0"), "permissive");
|
||||
assert_eq!(license_kind("LGPL-3.0-only"), "copyleft");
|
||||
assert_eq!(
|
||||
license_kind("GNU Lesser General Public License v3.0"),
|
||||
"copyleft"
|
||||
);
|
||||
assert_eq!(
|
||||
license_kind("LicenseRef-All-Rights-Reserved"),
|
||||
"all-rights-reserved"
|
||||
);
|
||||
assert_eq!(license_kind("CC-BY-NC-SA-4.0"), "restricted");
|
||||
assert_eq!(license_kind("LicenseRef-Stardust-Labs-License"), "custom");
|
||||
assert_eq!(
|
||||
license_kind("unknown (read mods.toml at import)"),
|
||||
"unknown"
|
||||
);
|
||||
}
|
||||
}
|
||||
+33
-3
@@ -262,13 +262,14 @@ inspected:
|
||||
└── coverage.json, coverage.md
|
||||
```
|
||||
|
||||
**Status.** `import`, `inventory` and `carry` run today:
|
||||
**Status.** `import`, `inventory`, `carry` and `report` run today:
|
||||
|
||||
```
|
||||
cargo run -p horizon-port-pack -- import ~/Downloads/pack.mrpack ~/.horizon/ports/pack
|
||||
cargo run -p horizon-port-pack -- inventory ~/.horizon/ports/pack # --offline reuses modrinth.json
|
||||
cargo run -p horizon-port-pack -- carry ~/.horizon/ports/pack # content mods with a jar, or name them
|
||||
# --resources <prepared root>: only templates Horizon's tables have
|
||||
cargo run -p horizon-port-pack -- report ~/.horizon/ports/pack # coverage.json and coverage.md
|
||||
```
|
||||
|
||||
`inventory` reads metadata only: Modrinth answers by file hash, and the jars only if the user's
|
||||
@@ -307,6 +308,7 @@ block's name breaking ties (`_pane`, `_gate`, `_trapdoor`).
|
||||
| CurseForge zip | `manifest.json`: `minecraft.version`, `modLoaders[]`, `files[]` (`projectID`, `fileID`, `required`), `overrides` | the user's installed instance (CurseForge app `minecraftinstance.json` + `mods/`). CurseForge's API needs a key, so we take what the user already downloaded |
|
||||
| Prism / MultiMC instance | `mmc-pack.json` components (`net.minecraft`, `net.neoforged`, `net.fabricmc.fabric-loader`), `instance.cfg`, `.minecraft/mods/*.jar`, packwiz `.pw.toml` files if present | the instance folder |
|
||||
| packwiz | `pack.toml`, `index.toml`, `mods/*.pw.toml` | as listed |
|
||||
| Crash Assistant `modlist.json` | jar name → mod id, name, version, Modrinth SHA-1; the loader entry (NeoForge `21.1.x` is Minecraft 1.21.1). Packs such as ATM10 publish it in their repository | metadata only; jars put in `<work>/jars/` |
|
||||
|
||||
`pack.json` holds the Minecraft version, the loader and its version, each file with its hashes
|
||||
and side, and the overrides (configs, KubeJS scripts, datapacks).
|
||||
@@ -458,8 +460,36 @@ and tag of the declared blocks matches.
|
||||
|
||||
Plus the licence summary (how many ports could be published) and, for a pack, "playable?":
|
||||
whether every required content mod is ported or partial with its blocks and items present.
|
||||
For ATM10 today: 125 of 495 are not needed. The other 370 are not yet ported; 68 of them are
|
||||
data tier, so they need registries and carry-over but no agent.
|
||||
|
||||
`horizon-port-pack report <work>` writes the per-mod rows and the class, tier and licence totals from the inventory, each mod's `carry-report.json`
|
||||
and its harness result. A data-tier mod is **ported** when its harness is green and nothing was
|
||||
left out (blocks with a class of their own are counted and named, since facts cannot show
|
||||
their extra code); **partial** with the failing checks, the blocks left out and what the
|
||||
templates miss; **not yet** with the API tier it waits for, or the dependency; **not needed**
|
||||
for libraries, performance mods, pack tooling and what Horizon has built in. Unclassified mods
|
||||
(the 20 CurseForge-only rows the reviewed table only guesses) count as not yet.
|
||||
|
||||
**ATM10, measured** (`import` of ATM10's `modlist.json` from its repository on 2026-10-16, 496
|
||||
files; `inventory`; `carry` and the harness on the eight mods we downloaded; `report`):
|
||||
|
||||
| class | ported | partial | not yet | not needed | all |
|
||||
|---|---:|---:|---:|---:|---:|
|
||||
| content | 1 | 7 | 268 | 0 | 276 |
|
||||
| library | 0 | 0 | 0 | 77 | 77 |
|
||||
| integration | 0 | 0 | 40 | 3 | 43 |
|
||||
| client-ui | 0 | 0 | 27 | 2 | 29 |
|
||||
| other | 0 | 0 | 1 | 23 | 24 |
|
||||
| unknown | 0 | 0 | 20 | 0 | 20 |
|
||||
| performance | 0 | 0 | 0 | 16 | 16 |
|
||||
| server-only | 0 | 0 | 11 | 0 | 11 |
|
||||
| **all** | **1** | **7** | **367** | **121** | **496** |
|
||||
|
||||
By tier, the 367 not yet: data 57 (carry-over and the harness, no agent: their jars were not
|
||||
downloaded), logic 66 (API 0.3), machines 97 (0.4), deep 92 (0.5), client 35, unclassified 20.
|
||||
Ported: Macaw's Trapdoors. Partial: Macaw's Doors, Fences and Walls, Paths and Pavings,
|
||||
Glassential, Factory Blocks, Cloud Glass (see the harness table) and MVS, whose 784 worldgen
|
||||
files are carried but not yet read by the game. Of the 8, 7 are MIT and one LGPL; nothing is
|
||||
published.
|
||||
|
||||
## Measuring "10x"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user