Skip to repository content92 lines · 2.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T04:07:27.452Z 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
test.rs
1mod assertions;
2mod marked_text;
3
4pub use assertions::*;
5pub use marked_text::*;
6
7use std::ffi::OsStr;
8use std::path::{Path, PathBuf};
9use tempfile::TempDir;
10
11pub struct TempTree {
12 _temp_dir: TempDir,
13 path: PathBuf,
14}
15
16impl TempTree {
17 pub fn new(tree: serde_json::Value) -> Self {
18 let dir = TempDir::new().unwrap();
19 let path = std::fs::canonicalize(dir.path()).unwrap();
20 write_tree(path.as_path(), tree);
21
22 Self {
23 _temp_dir: dir,
24 path,
25 }
26 }
27
28 pub fn path(&self) -> &Path {
29 self.path.as_path()
30 }
31}
32
33fn write_tree(path: &Path, tree: serde_json::Value) {
34 use serde_json::Value;
35 use std::fs;
36
37 if let Value::Object(map) = tree {
38 for (name, contents) in map {
39 let mut path = PathBuf::from(path);
40 path.push(name);
41 match contents {
42 Value::Object(_) => {
43 fs::create_dir(&path).unwrap();
44
45 #[cfg(not(target_family = "wasm"))]
46 #[allow(clippy::disallowed_methods)]
47 if path.file_name() == Some(OsStr::new(".git")) {
48 let output = std::process::Command::new("git")
49 .args(["init", "-b", "main"])
50 .current_dir(path.parent().unwrap())
51 .env("GIT_CONFIG_GLOBAL", "")
52 .env("GIT_CONFIG_SYSTEM", "")
53 .output()
54 .expect("failed to init git repo");
55 assert!(
56 output.status.success(),
57 "git init failed: {}",
58 String::from_utf8_lossy(&output.stderr)
59 );
60 }
61
62 write_tree(&path, contents);
63 }
64 Value::Null => {
65 fs::create_dir(&path).unwrap();
66 }
67 Value::String(contents) => {
68 fs::write(&path, contents).unwrap();
69 }
70 _ => {
71 panic!("JSON object must contain only objects, strings, or null");
72 }
73 }
74 }
75 } else {
76 panic!("You must pass a JSON object to this helper")
77 }
78}
79
80pub fn sample_text(rows: usize, cols: usize, start_char: char) -> String {
81 let mut text = String::new();
82 for row in 0..rows {
83 let c: char = (start_char as u32 + row as u32) as u8 as char;
84 let mut line = c.to_string().repeat(cols);
85 if row < rows - 1 {
86 line.push('\n');
87 }
88 text += &line;
89 }
90 text
91}
92