Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/agents/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,10 +988,18 @@ mod tests {
format!(r#"{{"contract_version": {contract}, "id": "{id}", "label": "An Agent", "repo": "acme/funes-pi"}}"#)
}

/// A registry root closed to other writers, as funes makes its own.
fn registry_root() -> tempfile::TempDir {
tempfile::Builder::new()
.permissions(std::fs::Permissions::from_mode(0o755))
.tempdir()
.unwrap()
}

/// Write an integration at `root/<dir_name>` declaring `manifest`, whose `setup` runs `body`.
fn integration(root: &Path, dir_name: &str, manifest: &str, body: &str) -> PathBuf {
let dir = root.join(dir_name);
std::fs::create_dir_all(&dir).unwrap();
create_owned(&dir).unwrap();
std::fs::write(dir.join("manifest.json"), manifest).unwrap();
let setup = dir.join(SETUP);
std::fs::write(&setup, format!("#!/bin/sh\n{body}\n")).unwrap();
Expand All @@ -1001,7 +1009,7 @@ mod tests {

#[test]
fn a_setup_others_could_have_written_is_refused() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
let dir = integration(root.path(), "pi", &manifest("pi", CONTRACT_VERSION), "true");
assert!(open(root.path(), "pi").is_ok());

Expand Down Expand Up @@ -1563,7 +1571,7 @@ mod tests {
/// source is even looked for.
#[tokio::test]
async fn an_id_that_is_not_one_is_refused_before_anything_is_written() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
for id in ["../docs", "Pi", "a/b", ""] {
let err = provision(root.path(), id, None).await.unwrap_err().to_string();
assert!(err.contains("not an integration id"), "{id:?}: {err}");
Expand All @@ -1576,7 +1584,7 @@ mod tests {

#[test]
fn the_mismatched_integrations_are_listed_with_their_contract() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
integration(root.path(), "pi", &manifest("pi", CONTRACT_VERSION), "true");
integration(root.path(), "codex", &manifest("codex", CONTRACT_VERSION + 1), "true");
integration(root.path(), "hermes", "not json", "true");
Expand All @@ -1588,7 +1596,7 @@ mod tests {

#[test]
fn an_unknown_id_names_what_is_registered() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
integration(root.path(), "pi", &manifest("pi", CONTRACT_VERSION), "true");
integration(root.path(), "codex", &manifest("codex", CONTRACT_VERSION), "true");
assert_eq!(registered_ids(root.path()), vec!["codex", "pi"]);
Expand All @@ -1604,7 +1612,7 @@ mod tests {

#[test]
fn the_id_must_be_the_directory_name_and_facet_safe() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
integration(root.path(), "pi", &manifest("codex", CONTRACT_VERSION), "true");
let err = open(root.path(), "pi").unwrap_err().to_string();
assert!(err.contains("directory name"), "{err}");
Expand All @@ -1616,7 +1624,7 @@ mod tests {

#[test]
fn a_manifest_declares_its_release_and_publisher() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
integration(
root.path(),
"pi",
Expand Down Expand Up @@ -1657,7 +1665,7 @@ mod tests {

#[test]
fn a_manifest_is_rejected_rather_than_guessed() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
integration(
root.path(),
"pi",
Expand All @@ -1679,7 +1687,7 @@ mod tests {

#[test]
fn setup_must_exist_and_be_executable() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
let dir = integration(root.path(), "pi", &manifest("pi", CONTRACT_VERSION), "true");

let setup = dir.join(SETUP);
Expand All @@ -1696,7 +1704,7 @@ mod tests {
/// funes has no record of installing, are refreshed on every run.
#[test]
fn only_an_install_named_with_from_runs_as_installed() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
integration(root.path(), "pi", &manifest("pi", CONTRACT_VERSION), "true");
let manifest: Manifest = serde_json::from_str(&manifest("pi", CONTRACT_VERSION)).unwrap();
assert!(refreshes_on_every_run(root.path(), "pi"), "no record");
Expand Down Expand Up @@ -1724,7 +1732,7 @@ mod tests {
/// digest: the same digest from another source, or another digest, is not it.
#[test]
fn the_installed_release_is_known_by_its_recorded_digest() {
let root = tempfile::tempdir().unwrap();
let root = registry_root();
integration(root.path(), "pi", &manifest("pi", CONTRACT_VERSION), "true");
let manifest: Manifest = serde_json::from_str(&manifest("pi", CONTRACT_VERSION)).unwrap();
let release = Release {
Expand Down
8 changes: 5 additions & 3 deletions tests/add_fifth_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod support;
use funes::inference::EmbeddingModel;
use funes::memory::dataset;
use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::os::unix::fs::{DirBuilderExt, PermissionsExt};
use std::path::{Path, PathBuf};
use std::process::{Command, Output};

Expand Down Expand Up @@ -99,7 +99,7 @@ fn bundle(dir: &Path, id: &str, contract: u32, tag: &str) -> PathBuf {
/// [`bundle`], declaring `repo` as where it is published from.
fn bundle_published_by(dir: &Path, id: &str, repo: &str, contract: u32, tag: &str) -> PathBuf {
let dir = dir.to_path_buf();
fs::create_dir_all(&dir).unwrap();
fs::DirBuilder::new().recursive(true).mode(0o755).create(&dir).unwrap();
fs::write(
dir.join("manifest.json"),
format!(r#"{{"contract_version":{contract},"id":"{id}","label":"Clyde","repo":"{repo}","version":"1.0.0"}}"#),
Expand Down Expand Up @@ -1394,7 +1394,9 @@ fn the_memory_bound_through_one_agent_is_the_hosts() {
// wrote, is no binding and no disagreement.
fs::remove_file(&bound).unwrap();
let older = |id: &str, memory: &str| {
fs::write(home.join(format!(".funes/agents/{id}.memory")), format!("{memory}\n")).unwrap()
let note = home.join(format!(".funes/agents/{id}.memory"));
fs::write(&note, format!("{memory}\n")).unwrap();
fs::set_permissions(&note, fs::Permissions::from_mode(0o644)).unwrap();
};
older("clyde", memory);
older("dotty", "local");
Expand Down
Loading