Update the browser, editor, settings, and installer

This commit is contained in:
Knotty Wyvern
2026-10-12 14:46:21 -07:00
parent 909894b9c8
commit f6eaa52949
163 changed files with 146260 additions and 534 deletions
+39 -8
View File
@@ -269,6 +269,16 @@ fn directory_files(path: &Path) -> Result<BTreeMap<String, Vec<u8>>> {
fn tree_hash(path: &Path) -> Result<String> {
Ok(fingerprint(&directory_files(path)?))
}
fn valid_version(version: &str) -> bool {
let parts: Vec<_> = version.split('.').collect();
if parts.len() != 3 || parts[..2].iter().any(|part| {
part.is_empty() || !part.bytes().all(|byte| byte.is_ascii_digit())
}) {
return false;
}
let digits = parts[2].bytes().take_while(|byte| byte.is_ascii_digit()).count();
digits > 0 && parts[2][digits..].bytes().all(|byte| byte.is_ascii_lowercase())
}
fn package(source: &Path) -> Result<Package> {
let mut files = BTreeMap::new();
let mut names = BTreeSet::new();
@@ -340,13 +350,8 @@ fn package(source: &Path) -> Result<Package> {
{
return Err("The manifest needs a name, author, description, and version.".into());
}
if manifest.version.split('.').count() != 3
|| !manifest
.version
.split('.')
.all(|n| !n.is_empty() && n.bytes().all(|c| c.is_ascii_digit()))
{
return Err("Use a plugin version such as 1.0.0.".into());
if !valid_version(&manifest.version) {
return Err("Use a plugin version such as 1.0.0 or 1.0.0a.".into());
}
relative(&manifest.entry)?;
if !manifest.entry.ends_with(".js") && !manifest.entry.ends_with(".mjs") {
@@ -1460,6 +1465,9 @@ mod tests {
#[test]
fn author_packager_produces_an_installable_repeatable_zip() {
let mut f = Fixture::new();
let manifest = fs::read_to_string(f.source.join("plugin.json"))
.unwrap().replace("1.0.0", "1.0.0a");
fs::write(f.source.join("plugin.json"), manifest).unwrap();
fs::create_dir(f.source.join("assets")).unwrap();
fs::write(f.source.join("assets/style.css"), "body { color: red; }").unwrap();
let script = Path::new(env!("CARGO_MANIFEST_DIR")).join("../scripts/packagePlugin.mjs");
@@ -1478,7 +1486,7 @@ mod tests {
);
};
build();
let path = output.join("org.test.demo-1.0.0.zip");
let path = output.join("org.test.demo-1.0.0a.zip");
let first = fs::read(&path).unwrap();
build();
assert_eq!(first, fs::read(&path).unwrap());
@@ -1490,6 +1498,7 @@ mod tests {
assert!(row.error.is_none(), "{:?}", row.error);
f.service.install("main", &row.token, false).unwrap();
let installed = f.service.row("org.test.demo").unwrap();
assert_eq!(installed.manifest.version, "1.0.0a");
assert!(!installed.enabled);
assert_eq!(
fs::read(Path::new(&installed.path).join("assets/style.css")).unwrap(),
@@ -1550,6 +1559,28 @@ mod tests {
.is_none());
}
#[test]
fn hotfix_versions_validate_and_survive_zip_install() {
for version in ["0.2.28", "0.2.28a", "0.2.28b", "0.2.28aa", "1.0.1000z"] {
assert!(valid_version(version), "{version}");
}
for version in ["", "1.0", "1.0.0.0", "1.0.a", "1.0.0A", "1.0.0a1", "1.0.0-beta", "1.0.0+build", "1.0.0é"] {
assert!(!valid_version(version), "{version}");
}
let mut f = Fixture::new();
let manifest = fs::read_to_string(f.source.join("plugin.json"))
.unwrap().replace("1.0.0", "0.2.28a");
let path = f.root.join("hotfix.zip");
archive(&path, &[("plugin.json", manifest.as_bytes()), ("main.js", b"export function activate() {}")]);
assert_eq!(package(&path).unwrap().manifest.version, "0.2.28a");
let row = f.service.inspect("main", path);
assert!(row.error.is_none());
f.service.install("main", &row.token, true).unwrap();
let mut reopened = Service::open(f.root.join("app")).unwrap();
let snapshot = reopened.snapshot().unwrap();
assert_eq!(snapshot.plugins[0].manifest.version, "0.2.28a");
assert!(snapshot.plugins[0].enabled);
}
#[test]
fn validates_paths_ids_limits_and_versions() {
for name in [
"../file",