Skip to content

Commit

Permalink
Sync process recipes in addition to complete_process recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewlacy committed Jun 8, 2024
1 parent 93c8448 commit 925c684
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
6 changes: 4 additions & 2 deletions crates/brioche-core/src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ impl Recipe {

pub fn is_expensive_to_bake(&self) -> bool {
match self {
Recipe::Download(_) | Recipe::CompleteProcess(_) | Recipe::Sync { .. } => true,
Recipe::Download(_)
| Recipe::Process(_)
| Recipe::CompleteProcess(_)
| Recipe::Sync { .. } => true,
Recipe::File { .. }
| Recipe::Directory(_)
| Recipe::Symlink { .. }
| Recipe::Unarchive(_)
| Recipe::Process(_)
| Recipe::CreateFile { .. }
| Recipe::CreateDirectory(_)
| Recipe::Cast { .. }
Expand Down
1 change: 1 addition & 0 deletions crates/brioche-core/src/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ pub async fn descendent_project_bakes(
INNER JOIN recipes AS output_artifacts ON
output_artifacts.recipe_hash = bakes.output_hash
WHERE input_recipes.recipe_json->>'type' IN (
'process',
'complete_process',
'download',
'sync'
Expand Down
61 changes: 61 additions & 0 deletions crates/brioche-core/tests/sync_from_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,64 @@ async fn test_sync_from_registry_complete_process() -> anyhow::Result<()> {

Ok(())
}

#[tokio::test]
async fn test_sync_from_registry_process() -> anyhow::Result<()> {
let (brioche, mut context) = brioche_test::brioche_test().await;

// Create a process recipe
let process_recipe = brioche_core::recipe::ProcessRecipe {
command: tpl("/usr/bin/env"),
args: vec![tpl("sh"), tpl("-c"), tpl("dummy_recipe")],
platform: brioche_core::platform::Platform::X86_64Linux,
..brioche_test::default_process()
};
let process_recipe_hash = Recipe::Process(process_recipe.clone()).hash();

let dummy_blob = brioche_test::blob(&brioche, "dummy value").await;
let mocked_output = brioche_test::file(dummy_blob, false);

// Mock the registry to return the output artifact for the process
// recipe. This should be the only registry request, needed since the
// output artifact and blob have already been saved locally
let mut registry_mocks = vec![];
registry_mocks.push(
context
.registry_server
.mock(
"GET",
&*format!(
"/v0/recipes/{}/bake?brioche={}",
process_recipe_hash,
brioche_core::VERSION,
),
)
.with_body(serde_json::to_string(
&brioche_core::registry::GetBakeResponse {
output_hash: mocked_output.hash(),
output_artifact: mocked_output.clone(),
referenced_recipes: HashSet::new(),
referenced_blobs: HashSet::new(),
},
)?)
.create(),
);

// Bake the process recipe, which should be a cache hit to the registry
let output_artifact = brioche_core::bake::bake(
&brioche,
WithMeta::without_meta(Recipe::Process(process_recipe.clone())),
&BakeScope::Anonymous,
)
.await?;

// Ensure that we got the mock back
assert_eq!(output_artifact.value, mocked_output);

// Ensure all the registry mocks got called as expected
for registry_mock in registry_mocks {
registry_mock.assert_async().await;
}

Ok(())
}
22 changes: 20 additions & 2 deletions crates/brioche-core/tests/sync_to_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,26 @@ async fn test_sync_to_registry_process_and_complete_process() -> anyhow::Result<
.create(),
);

// Create a mock to ensure that the result for complete_process
// gets created
// Create a mock to ensure that the result for process and complete_process
// get created
registry_mocks.push(
context
.registry_server
.mock(
"POST",
&*format!(
"/v0/recipes/{}/bake?brioche={}",
process_recipe_hash,
brioche_core::VERSION
),
)
.with_body(serde_json::to_string(
&brioche_core::registry::CreateBakeResponse {
canonical_output_hash: mocked_output.hash(),
},
)?)
.create(),
);
registry_mocks.push(
context
.registry_server
Expand Down

0 comments on commit 925c684

Please sign in to comment.