Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: files changed src/openhuman/skills/bundled/mod_tests.rs

Steven Enamakele812614bb734
diff --git a/src/openhuman/skills/bundled/mod_tests.rs b/src/openhuman/skills/bundled/mod_tests.rs
new file mode 100644
index 0000000000..81eac7998a
--- /dev/null
+++ b/src/openhuman/skills/bundled/mod_tests.rs
@@ -0,0 +1,151 @@
+//! Tests for the compiled-in skill table and its materialisation.
+
+use super::*;
+
+const A: BundledFile = BundledFile {
+ path: "WORKFLOW.md",
+ contents: "---\nname: sample\ndescription: a sample\n---\n\nbody\n",
+};
+const B: BundledFile = BundledFile {
+ path: "references/detail.md",
+ contents: "detail\n",
+};
+
+const SAMPLE: BundledSkill = BundledSkill {
+ dir_name: "sample",
+ files: &[A, B],
+};
+
+#[test]
+fn every_shipped_bundle_is_valid() {
+ // The one assertion that covers the real table. `validate` exists because
+ // a bad `dir_name` or a `..` in a file path would write outside the
+ // workspace; a shipped build never runs it, so this is where it runs.
+ for skill in BUNDLED {
+ skill
+ .validate()
+ .unwrap_or_else(|e| panic!("bundled skill `{}` is invalid: {e}", skill.dir_name));
+ }
+}
+
+#[test]
+fn shipped_bundle_names_are_unique() {
+ // Two entries with one `dir_name` would write over each other, and which
+ // one won would depend on table order.
+ let mut seen = std::collections::HashSet::new();
+ for skill in BUNDLED {
+ assert!(
+ seen.insert(skill.dir_name),
+ "two bundled skills both claim `{}`",
+ skill.dir_name
+ );
+ }
+}
+
+#[test]
+fn the_digest_covers_paths_as_well_as_contents() {
+ // The length-prefix rule from `digest`'s docs: moving a byte between two
+ // files, or renaming a file, must change the digest. Without prefixing,
+ // both of these collide with SAMPLE.
+ let moved = BundledSkill {
+ dir_name: "sample",
+ files: &[
+ BundledFile { path: "WORKFLOW.md", contents: A.contents },
+ BundledFile { path: "references/detail.md", contents: "detai" },
+ ],
+ };
+ let renamed = BundledSkill {
+ dir_name: "sample",
+ files: &[A, BundledFile { path: "references/other.md", contents: B.contents }],
+ };
+ assert_ne!(SAMPLE.digest(), moved.digest());
+ assert_ne!(SAMPLE.digest(), renamed.digest());
+}
+
+#[test]
+fn a_traversal_path_is_rejected() {
+ for bad in ["../escape.md", "refs/../../escape.md", "/etc/passwd", "refs//x.md"] {
+ let skill = BundledSkill {
+ dir_name: "sample",
+ files: &[A, BundledFile { path: bad, contents: "x" }],
+ };
+ assert!(
+ skill.validate().is_err(),
+ "`{bad}` must be rejected as a bundled file path"
+ );
+ }
+}
+
+#[test]
+fn a_bundle_with_no_manifest_is_rejected() {
+ // Discovery only loads a directory holding WORKFLOW.md / SKILL.md /
+ // skill.json. A bundle without one would be written out and then silently
+ // never appear — the worst failure mode available, because nothing errors.
+ let skill = BundledSkill {
+ dir_name: "sample",
+ files: &[BundledFile { path: "references/detail.md", contents: "x" }],
+ };
+ assert!(skill.validate().is_err());
+}
+
+#[test]
+fn install_writes_the_files_and_is_idempotent() {
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let root = builtin_root(tmp.path());
+
+ assert!(install_one(&root, &SAMPLE).expect("first install"));
+ let body = std::fs::read_to_string(root.join("sample").join("WORKFLOW.md")).expect("body");
+ assert_eq!(body, A.contents);
+ let detail =
+ std::fs::read_to_string(root.join("sample").join("references/detail.md")).expect("detail");
+ assert_eq!(detail, B.contents);
+
+ // Second call must not rewrite — the digest matches.
+ assert!(!install_one(&root, &SAMPLE).expect("second install"));
+}
+
+#[test]
+fn a_version_bump_removes_a_file_the_new_version_dropped() {
+ // The reason `install_one` deletes instead of overwriting. A stale
+ // reference doc left behind would keep answering `read_workflow_resource`
+ // after the skill stopped shipping it.
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let root = builtin_root(tmp.path());
+ assert!(install_one(&root, &SAMPLE).expect("install v1"));
+
+ let v2 = BundledSkill { dir_name: "sample", files: &[A] };
+ assert!(install_one(&root, &v2).expect("install v2"));
+ assert!(
+ !root.join("sample").join("references/detail.md").exists(),
+ "the dropped reference file must not survive the upgrade"
+ );
+}
+
+#[test]
+fn an_interrupted_install_is_redone() {
+ // The digest is written last on purpose. Simulate the interruption by
+ // removing it: the next install must rewrite rather than trust the
+ // directory.
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let root = builtin_root(tmp.path());
+ assert!(install_one(&root, &SAMPLE).expect("install"));
+ std::fs::remove_file(root.join("sample").join(".digest")).expect("remove digest");
+ assert!(
+ install_one(&root, &SAMPLE).expect("reinstall"),
+ "a bundle with no digest must be rewritten"
+ );
+}
+
+#[test]
+fn install_reports_rather_than_fails_the_boot() {
+ // `install` is called from workspace init. A workspace it cannot write
+ // must not stop the core from starting.
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let report = install(tmp.path());
+ assert!(report.failed.is_empty(), "clean workspace must install: {report:?}");
+ assert_eq!(
+ report.written.len() + report.unchanged.len(),
+ BUNDLED.len(),
+ "every bundled skill must be accounted for"
+ );
+}