Skip to repository content157 lines · 5.3 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T05:23:58.315Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
icon_family.rs
1use std::{collections::BTreeMap, fs, path::PathBuf};
2
3use serde::Deserialize;
4use sha2::{Digest, Sha256};
5
6const PINNED_PNG_SHA256: &str =
7 "1f80f8d36d459e2bf62c3d1fcb05f42cf6c2a26b84aeb320eb89bedbb489d551";
8const PINNED_ICNS_SHA256: &str =
9 "f6d748c1765161ec785f55137afd548cf1ff23de12d2de14383e8a01c697654d";
10
11#[derive(Debug, Deserialize)]
12struct Manifest {
13 channel_badges: String,
14 pinned_source: PinnedSource,
15 outputs: BTreeMap<String, OutputRecord>,
16}
17
18#[derive(Debug, Deserialize)]
19struct PinnedSource {
20 png_path: String,
21 png_sha256: String,
22 png_pixels: [u32; 2],
23 icns_path: String,
24 icns_sha256: String,
25}
26
27#[derive(Debug, Deserialize)]
28struct OutputRecord {
29 sha256: String,
30 format: String,
31 #[serde(default)]
32 pixels: Option<[u32; 2]>,
33 #[serde(default)]
34 sizes: Option<Vec<u32>>,
35 derived_from: String,
36}
37
38fn resources_root() -> PathBuf {
39 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../zed/resources")
40}
41
42fn sha256_file(path: &std::path::Path) -> String {
43 let bytes = fs::read(path).unwrap_or_else(|error| panic!("read {}: {error}", path.display()));
44 let mut hasher = Sha256::new();
45 hasher.update(&bytes);
46 format!("{:x}", hasher.finalize())
47}
48
49fn png_dimensions(path: &std::path::Path) -> [u32; 2] {
50 let bytes = fs::read(path).unwrap_or_else(|error| panic!("read {}: {error}", path.display()));
51 assert!(
52 bytes.starts_with(b"\x89PNG\r\n\x1a\n"),
53 "{} is not a PNG",
54 path.display()
55 );
56 let width = u32::from_be_bytes(bytes[16..20].try_into().expect("png width"));
57 let height = u32::from_be_bytes(bytes[20..24].try_into().expect("png height"));
58 [width, height]
59}
60
61fn load_manifest() -> (PathBuf, Manifest) {
62 let root = resources_root();
63 let manifest_path = root.join("icon_family/manifest.json");
64 let text = fs::read_to_string(&manifest_path)
65 .unwrap_or_else(|error| panic!("read {}: {error}", manifest_path.display()));
66 let manifest: Manifest = serde_json::from_str(&text)
67 .unwrap_or_else(|error| panic!("parse {}: {error}", manifest_path.display()));
68 (root, manifest)
69}
70
71#[test]
72fn pinned_openagents_icon_sources_match_release_digests() {
73 let (root, manifest) = load_manifest();
74
75 assert_eq!(manifest.channel_badges, "deferred");
76 assert_eq!(manifest.pinned_source.png_sha256, PINNED_PNG_SHA256);
77 assert_eq!(manifest.pinned_source.icns_sha256, PINNED_ICNS_SHA256);
78 assert_eq!(manifest.pinned_source.png_pixels, [1024, 1024]);
79
80 let png_path = root.join(&manifest.pinned_source.png_path);
81 let icns_path = root.join(&manifest.pinned_source.icns_path);
82 assert_eq!(sha256_file(&png_path), PINNED_PNG_SHA256);
83 assert_eq!(sha256_file(&icns_path), PINNED_ICNS_SHA256);
84 assert_eq!(png_dimensions(&png_path), [1024, 1024]);
85}
86
87#[test]
88fn generated_package_icons_match_manifest_digests_and_dimensions() {
89 let (root, manifest) = load_manifest();
90
91 let expected_outputs = [
92 "Document.icns",
93 "app-icon-dev.png",
94 "app-icon-dev@2x.png",
95 "app-icon-nightly.png",
96 "app-icon-nightly@2x.png",
97 "app-icon-preview.png",
98 "app-icon-preview@2x.png",
99 "app-icon.png",
100 "app-icon@2x.png",
101 "windows/app-icon-dev.ico",
102 "windows/app-icon-nightly.ico",
103 "windows/app-icon-preview.ico",
104 "windows/app-icon.ico",
105 ];
106 assert_eq!(
107 manifest.outputs.keys().cloned().collect::<Vec<_>>(),
108 expected_outputs
109 );
110
111 for (relative_path, record) in &manifest.outputs {
112 let path = root.join(relative_path);
113 assert_eq!(
114 sha256_file(&path),
115 record.sha256,
116 "digest mismatch for {relative_path}"
117 );
118
119 match record.format.as_str() {
120 "png" => {
121 let pixels = record.pixels.expect("png outputs record pixels");
122 assert_eq!(png_dimensions(&path), pixels, "{relative_path} pixels");
123 assert!(
124 record.derived_from.ends_with("openagents-icon.png"),
125 "{relative_path} must derive from the pinned PNG"
126 );
127 }
128 "icns" => {
129 let bytes = fs::read(&path).expect("read icns");
130 assert!(
131 bytes.starts_with(b"icns"),
132 "{relative_path} missing icns magic"
133 );
134 assert!(
135 record.derived_from.ends_with("openagents-icon.icns"),
136 "{relative_path} must derive from the pinned ICNS"
137 );
138 }
139 "ico" => {
140 let bytes = fs::read(&path).expect("read ico");
141 assert_eq!(
142 &bytes[0..4],
143 &[0, 0, 1, 0],
144 "{relative_path} missing ico magic"
145 );
146 let sizes = record.sizes.as_ref().expect("ico outputs record sizes");
147 assert_eq!(sizes, &vec![16, 32, 48, 256]);
148 assert!(
149 record.derived_from.ends_with("openagents-icon.png"),
150 "{relative_path} must derive from the pinned PNG"
151 );
152 }
153 other => panic!("unexpected icon format {other} for {relative_path}"),
154 }
155 }
156}
157