From aec69e9772f8e96dc444b6313867b6e57989a1fd Mon Sep 17 00:00:00 2001 From: Kinflou Date: Sun, 15 Nov 2026 01:10:34 +0800 Subject: [PATCH] Name the main ref and the package config file as constants `refs::main_ref()` becomes the constant `REF_HEAD_MAIN_FILENAME`, and `config::idl::constants::CONGREGATION_EXTENSION` gives way to `config::idl::PACKAGE_EXTENSION` and `PACKAGE_CONFIG_FILENAME` (`config.idp`), so callers no longer format the file name themselves. The `constants` module, which held only that one item, is removed. This changes core's public API: the CLI uses `main_ref()` and moves to the constant when it next pins core. --- core/src/compat.rs | 8 +++--- core/src/package/build/cas/build.rs | 10 +++---- core/src/package/build/cas/mod.rs | 2 +- core/src/package/build/cas/reconcile.rs | 16 +++++------ core/src/package/build/cas/refs.rs | 6 ++--- core/src/package/build/cas/release.rs | 12 ++++----- core/src/package/build/mod.rs | 6 ++--- core/src/package/config/idl/constants.rs | 9 ------- core/src/package/config/idl/mod.rs | 4 ++- core/src/package/config/mod.rs | 8 ++---- core/src/package/deps.rs | 6 ++--- core/tests/cas/compat_tests.rs | 28 ++++++++++---------- core/tests/cas/config_in_commit_tests.rs | 6 ++--- core/tests/cas/dependency_configs_tests.rs | 8 +++--- core/tests/cas/dependency_vendoring_tests.rs | 2 +- core/tests/cas/docs_in_commit_tests.rs | 2 +- core/tests/cas/reconcile_tests.rs | 16 +++++------ core/tests/cas/release_tests.rs | 6 ++--- core/tests/package/schema_loading.rs | 2 +- core/tests/package_config/mod.rs | 4 +-- 20 files changed, 74 insertions(+), 87 deletions(-) delete mode 100644 core/src/package/config/idl/constants.rs diff --git a/core/src/compat.rs b/core/src/compat.rs index 1720412..46580fc 100644 --- a/core/src/compat.rs +++ b/core/src/compat.rs @@ -57,7 +57,7 @@ use crate::package::build::cas::build::{compare, last_release}; use crate::package::build::cas::object_store::ObjectStore; use crate::package::build::cas::objects::{Blob, Commit, EntryMode, Tree}; use crate::package::build::cas::object_store::ensure_compatible_store; -use crate::package::build::cas::refs::{main_ref, read_ref, ref_exists}; +use crate::package::build::cas::refs::{REF_HEAD_MAIN_FILENAME, read_ref, ref_exists}; use crate::package::build::cas::storage::{from_cbor, to_cbor, Hash}; use crate::package::config::ir::context::ProjectContext; use crate::package::config::ir::diff::ConfigChange; @@ -746,11 +746,11 @@ impl Loaded { pub fn facts(project_path: &Path, version: Option<&str>) -> Result { // Read-only, and refuses a store in another format without touching it. ensure_compatible_store(project_path)?; - if !ref_exists(project_path, main_ref()) { + if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) { bail!("nothing built yet: run `comline build` first"); } let store = ObjectStore::new(project_path); - let mut hash = read_ref(project_path, main_ref())?; + let mut hash = read_ref(project_path, REF_HEAD_MAIN_FILENAME)?; loop { let commit = Commit::from_bytes(&store.read(&hash)?)?; if version.map_or(true, |v| v == commit.version) { @@ -786,7 +786,7 @@ pub fn facts_of_working_tree(project_path: &Path, context: &ProjectContext) -> R ensure_compatible_store(project_path)?; let store = ObjectStore::scratch(project_path); let tree = working_tree(project_path, context, &store)?; - if !ref_exists(project_path, main_ref()) { + if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) { let version = first_version().to_string(); let history = history(&store, None, &tree, &release_of(&version))?; return Ok(assemble(&Loaded::of(&store, &tree)?, &history, &version)); diff --git a/core/src/package/build/cas/build.rs b/core/src/package/build/cas/build.rs index 4d7a778..1eefac5 100644 --- a/core/src/package/build/cas/build.rs +++ b/core/src/package/build/cas/build.rs @@ -13,7 +13,7 @@ use std::path::Path; use super::object_store::ObjectStore; use super::objects::{Commit, EntryMode, Tree}; use super::reconcile::{self, read_heads, Heads}; -use super::refs::{main_ref, ref_exists, update_ref}; +use super::refs::{REF_HEAD_MAIN_FILENAME, ref_exists, update_ref}; use super::storage::Hash; use super::version::{dev_version, next_release, VersionBump}; use crate::compat::release_of; @@ -411,7 +411,7 @@ pub fn process_initial_freezing( let commit_hash = store.write(&commit_bytes)?; // Update main ref to point to this commit - update_ref(project_path, main_ref(), &commit_hash)?; + update_ref(project_path, REF_HEAD_MAIN_FILENAME, &commit_hash)?; tracing::info!("CAS: Initial commit {} created", commit_hash); @@ -436,7 +436,7 @@ pub fn process_changes(project_path: &Path, latest_project: &ProjectContext) -> store.init()?; // Read previous commit - if !ref_exists(project_path, main_ref()) { + if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) { // No previous commit, treat as initial return process_initial_freezing(project_path, latest_project); } @@ -474,7 +474,7 @@ pub fn process_changes(project_path: &Path, latest_project: &ProjectContext) -> // Reconciling onto a head whose tree is already the merged one: // nothing to build, but the ref is repaired to that head. if reconciling.is_some() { - update_ref(project_path, main_ref(), &parent_hash)?; + update_ref(project_path, REF_HEAD_MAIN_FILENAME, &parent_hash)?; } let (release, _) = last_release(&store, parent_hash)?; return Ok(BuildInfo { @@ -518,7 +518,7 @@ pub fn process_changes(project_path: &Path, latest_project: &ProjectContext) -> let commit_hash = store.write(&commit_bytes)?; // Update main ref - update_ref(project_path, main_ref(), &commit_hash)?; + update_ref(project_path, REF_HEAD_MAIN_FILENAME, &commit_hash)?; tracing::info!("CAS: New commit {} created ({})", commit_hash, new_version); diff --git a/core/src/package/build/cas/mod.rs b/core/src/package/build/cas/mod.rs index 9c30209..f4d28ac 100644 --- a/core/src/package/build/cas/mod.rs +++ b/core/src/package/build/cas/mod.rs @@ -41,7 +41,7 @@ mod schema; pub use storage::{Hash, compress, decompress}; pub use object_store::ObjectStore; #[cfg(feature = "compiler")] -pub use refs::{update_ref, read_ref, ref_exists, main_ref}; +pub use refs::{update_ref, read_ref, ref_exists, REF_HEAD_MAIN_FILENAME}; pub use version::VersionBump; // Standard Uses diff --git a/core/src/package/build/cas/reconcile.rs b/core/src/package/build/cas/reconcile.rs index 44f5641..9e6d9ae 100644 --- a/core/src/package/build/cas/reconcile.rs +++ b/core/src/package/build/cas/reconcile.rs @@ -37,7 +37,7 @@ use std::path::Path; // Crate Uses use super::object_store::ObjectStore; use super::objects::Commit; -use super::refs::main_ref; +use super::refs::REF_HEAD_MAIN_FILENAME; use super::storage::Hash; // External Uses @@ -87,7 +87,7 @@ pub fn parse_heads(text: &str) -> Result { Section::Base => {} Section::Outside => bail!( "`.comline/{}` has conflict markers and other content: {line:?}", - main_ref() + REF_HEAD_MAIN_FILENAME ), } } @@ -98,7 +98,7 @@ pub fn parse_heads(text: &str) -> Result { _ => Err(eyre!( "`.comline/{}` is conflicted, but {which} side doesn't hold exactly one commit \ hash", - main_ref() + REF_HEAD_MAIN_FILENAME )), } }; @@ -108,9 +108,9 @@ pub fn parse_heads(text: &str) -> Result { /// Read `refs/heads/main`: one head, or two after a Git merge. pub fn read_heads(project_path: &Path) -> Result { - let path = project_path.join(".comline").join(main_ref()); + let path = project_path.join(".comline").join(REF_HEAD_MAIN_FILENAME); if !path.exists() { - bail!("Ref {} does not exist", main_ref()); + bail!("Ref {} does not exist", REF_HEAD_MAIN_FILENAME); } parse_heads(&fs::read_to_string(&path)?) } @@ -132,12 +132,12 @@ pub fn mark_diverged(project_path: &Path, other: &Hash) -> Result<()> { .map_err(|e| eyre!("{other} isn't a commit: {e}"))?; let current = match read_heads(project_path)? { Heads::One(hash) => hash, - Heads::Two(..) => bail!("`.comline/{}` already holds two heads", main_ref()), + Heads::Two(..) => bail!("`.comline/{}` already holds two heads", REF_HEAD_MAIN_FILENAME), }; if current == *other { return Ok(()); } - let path = project_path.join(".comline").join(main_ref()); + let path = project_path.join(".comline").join(REF_HEAD_MAIN_FILENAME); fs::write( path, format!("<<<<<<< current\n{current}\n=======\n{other}\n>>>>>>> reconcile\n"), @@ -252,7 +252,7 @@ pub fn plan(store: &ObjectStore, a: Hash, b: Hash) -> Result { in `.comline/objects` but leaves the line.", ra.version, short(&released_a[0].0), rb.version, short(&released_b[0].0), a, ra.version, b, rb.version, - ref_ = main_ref(), + ref_ = REF_HEAD_MAIN_FILENAME, ); } (Some(_), None) => a, diff --git a/core/src/package/build/cas/refs.rs b/core/src/package/build/cas/refs.rs index f1eac9c..07e4777 100644 --- a/core/src/package/build/cas/refs.rs +++ b/core/src/package/build/cas/refs.rs @@ -44,7 +44,5 @@ pub fn ref_exists(project_path: &Path, ref_name: &str) -> bool { project_path.join(".comline").join(ref_name).exists() } -/// Get the main branch ref path -pub fn main_ref() -> &'static str { - "refs/heads/main" -} +/// Main branch reference path +pub const REF_HEAD_MAIN_FILENAME: &str = "refs/heads/main"; diff --git a/core/src/package/build/cas/release.rs b/core/src/package/build/cas/release.rs index 8d7ac01..30a7644 100644 --- a/core/src/package/build/cas/release.rs +++ b/core/src/package/build/cas/release.rs @@ -13,7 +13,7 @@ use std::path::Path; use super::build::{compare, last_release, Comparison}; use super::object_store::{ensure_compatible_store, ObjectStore}; use super::objects::{Commit, Release, Tree}; -use super::refs::{main_ref, read_ref, ref_exists, update_ref}; +use super::refs::{REF_HEAD_MAIN_FILENAME, read_ref, ref_exists, update_ref}; use super::version::{next_release, VersionBump}; use crate::schema::ir::frozen::cas::commit::create_version_commit; @@ -47,11 +47,11 @@ pub struct ReleaseInfo { /// The latest release in the package's history, if any. pub fn latest_release(project_path: &Path) -> Result> { ensure_compatible_store(project_path)?; - if !ref_exists(project_path, main_ref()) { + if !ref_exists(project_path, REF_HEAD_MAIN_FILENAME) { return Ok(None); } let store = ObjectStore::new(project_path); - let (release, _) = last_release(&store, read_ref(project_path, main_ref())?)?; + let (release, _) = last_release(&store, read_ref(project_path, REF_HEAD_MAIN_FILENAME)?)?; Ok(release.map(|(_, commit)| commit)) } @@ -64,12 +64,12 @@ pub fn release(project_path: &Path, request: &ReleaseRequest) -> Result Result Result { #[cfg(feature = "compiler")] fn require_config_path(package_path: &Path) -> Result { - let config_path = package_path.join(format!("config.{}", CONGREGATION_EXTENSION)); + let config_path = package_path.join(PACKAGE_CONFIG_FILENAME); let config_name = config_path.file_name().unwrap().to_str().unwrap(); if !config_path.exists() { @@ -236,7 +236,7 @@ pub fn build_with( check(&latest_project)?; // Use CAS for immutable version storage - let build_info = if cas::refs::ref_exists(package_path, cas::refs::main_ref()) { + let build_info = if cas::refs::ref_exists(package_path, cas::refs::REF_HEAD_MAIN_FILENAME) { cas::build::process_changes(&package_path, &latest_project)? } else { cas::build::process_initial_freezing(&package_path, &latest_project)? diff --git a/core/src/package/config/idl/constants.rs b/core/src/package/config/idl/constants.rs deleted file mode 100644 index 1cb0714..0000000 --- a/core/src/package/config/idl/constants.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Standard Uses - -// Crate Uses - - -// External Uses - - -pub const CONGREGATION_EXTENSION: &str = "idp"; diff --git a/core/src/package/config/idl/mod.rs b/core/src/package/config/idl/mod.rs index 71eed3d..a310fee 100644 --- a/core/src/package/config/idl/mod.rs +++ b/core/src/package/config/idl/mod.rs @@ -1,6 +1,8 @@ // Relative Modules #[cfg(feature = "compiler")] pub mod grammar; -pub mod constants; // pub mod parser; // pub mod ast; + +pub const PACKAGE_EXTENSION: &str = "idp"; +pub const PACKAGE_CONFIG_FILENAME: &str = concat!("config.", "idp"); diff --git a/core/src/package/config/mod.rs b/core/src/package/config/mod.rs index bb863d8..278260d 100644 --- a/core/src/package/config/mod.rs +++ b/core/src/package/config/mod.rs @@ -8,7 +8,7 @@ pub mod dependency; // NEW: Dependency configuration use std::path::Path; // Crate Uses -use crate::package::config::idl::constants::CONGREGATION_EXTENSION; +use crate::package::config::idl::PACKAGE_CONFIG_FILENAME; // External Uses @@ -16,10 +16,6 @@ use crate::package::config::idl::constants::CONGREGATION_EXTENSION; /// Determines if given path is a package directory by checking minimally /// required files in it pub fn is_package_path(package_path: &Path) -> bool { - let config_path = package_path.join( - format!("config.{}", CONGREGATION_EXTENSION) - ); - - config_path.exists() + package_path.join(PACKAGE_CONFIG_FILENAME).exists() } diff --git a/core/src/package/deps.rs b/core/src/package/deps.rs index acfdf4d..f226446 100644 --- a/core/src/package/deps.rs +++ b/core/src/package/deps.rs @@ -298,15 +298,15 @@ pub(crate) fn resolve_dependency_schemas( /// own CAS history says — this reads the ground truth. fn resolved_version(package_path: &Path) -> String { use crate::package::build::cas::objects::Commit; - use crate::package::build::cas::{main_ref, read_ref, ref_exists, ObjectStore}; + use crate::package::build::cas::{REF_HEAD_MAIN_FILENAME, read_ref, ref_exists, ObjectStore}; - if !ref_exists(package_path, main_ref()) { + if !ref_exists(package_path, REF_HEAD_MAIN_FILENAME) { return "0.0.0-unbuilt".to_string(); } (|| -> Result { let store = ObjectStore::new(package_path); - let commit_hash = read_ref(package_path, main_ref())?; + let commit_hash = read_ref(package_path, REF_HEAD_MAIN_FILENAME)?; let commit = Commit::from_bytes(&store.read(&commit_hash)?)?; Ok(commit.version) })() diff --git a/core/tests/cas/compat_tests.rs b/core/tests/cas/compat_tests.rs index ea6892f..c451439 100644 --- a/core/tests/cas/compat_tests.rs +++ b/core/tests/cas/compat_tests.rs @@ -7,7 +7,7 @@ use std::path::Path; use comline_core::compat::{self, PackageFacts}; use comline_core::package::build::cas::objects::{Commit, Tree}; -use comline_core::package::build::cas::{main_ref, read_ref, ObjectStore}; +use comline_core::package::build::cas::{REF_HEAD_MAIN_FILENAME, read_ref, ObjectStore}; use comline_core::package::build::{build, release, ReleaseRequest, VersionBump}; use tempfile::TempDir; @@ -56,7 +56,7 @@ const V1: &str = "struct User {\n id: u64\n}\n\nprotocol Users {\n functio /// before gives. fn assert_reproducible(dir: &Path) { let store = ObjectStore::new(dir); - let mut hash = read_ref(dir, main_ref()).unwrap(); + let mut hash = read_ref(dir, REF_HEAD_MAIN_FILENAME).unwrap(); loop { let commit = Commit::from_bytes(&store.read(&hash).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); @@ -154,7 +154,7 @@ fn a_release_as_another_version_renames_what_its_builds_led_to() { /// renamed history; every build's stored one still recomputes. fn assert_reproducible_except_releases(dir: &Path) { let store = ObjectStore::new(dir); - let mut hash = read_ref(dir, main_ref()).unwrap(); + let mut hash = read_ref(dir, REF_HEAD_MAIN_FILENAME).unwrap(); loop { let commit = Commit::from_bytes(&store.read(&hash).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); @@ -292,7 +292,7 @@ fn a_version_built_before_facts_gets_them_computed() { let dir = package(V1); build(dir.path()).unwrap(); let store = ObjectStore::new(dir.path()); - let hash = read_ref(dir.path(), main_ref()).unwrap(); + let hash = read_ref(dir.path(), REF_HEAD_MAIN_FILENAME).unwrap(); let commit = Commit::from_bytes(&store.read(&hash).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); let bare = compat::without_facts(&tree); @@ -386,7 +386,7 @@ fn fnumber(facts: &PackageFacts, protocol: &str, function: &str) -> u16 { fn history(dir: &Path) -> compat::History { let store = ObjectStore::new(dir); - compat::history_of_commit(&store, &read_ref(dir, main_ref()).unwrap()).unwrap() + compat::history_of_commit(&store, &read_ref(dir, REF_HEAD_MAIN_FILENAME).unwrap()).unwrap() } #[test] @@ -573,7 +573,7 @@ fn a_version_stored_without_numbers_gets_them_computed_when_read() { let dir = package(V1); build(dir.path()).unwrap(); let store = ObjectStore::new(dir.path()); - let hash = read_ref(dir.path(), main_ref()).unwrap(); + let hash = read_ref(dir.path(), REF_HEAD_MAIN_FILENAME).unwrap(); let mut commit = Commit::from_bytes(&store.read(&hash).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); let stored = compat::read_history(&store, &tree).unwrap().unwrap(); @@ -596,7 +596,7 @@ fn a_version_stored_without_numbers_gets_them_computed_when_read() { old_tree.add_entry(EntryMode::Blob, compat::FACTS_ENTRY.to_string(), blob); commit.tree = store.write(&old_tree.to_bytes().unwrap()).unwrap(); let old_hash = store.write(&commit.to_bytes().unwrap()).unwrap(); - update_ref(dir.path(), main_ref(), &old_hash).unwrap(); + update_ref(dir.path(), REF_HEAD_MAIN_FILENAME, &old_hash).unwrap(); let read = compat::read_history(&store, &old_tree).unwrap().unwrap(); assert!(!read.numbered); @@ -734,7 +734,7 @@ fn the_stored_history_records_the_effective_encodings() { let stored = |dir: &Path, protocol: &str| { let store = ObjectStore::new(dir); - let commit = Commit::from_bytes(&store.read(&read_ref(dir, main_ref()).unwrap()).unwrap()).unwrap(); + let commit = Commit::from_bytes(&store.read(&read_ref(dir, REF_HEAD_MAIN_FILENAME).unwrap()).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); let history = compat::read_history(&store, &tree).unwrap().unwrap(); let protocol = history.protocols.iter().find(|p| p.path.ends_with(protocol)).unwrap(); @@ -786,7 +786,7 @@ fn the_facts_read_the_recorded_encodings() { let dir = package(V1); build(dir.path()).unwrap(); let store = ObjectStore::new(dir.path()); - let hash = read_ref(dir.path(), main_ref()).unwrap(); + let hash = read_ref(dir.path(), REF_HEAD_MAIN_FILENAME).unwrap(); let mut commit = Commit::from_bytes(&store.read(&hash).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); let mut history = compat::read_history(&store, &tree).unwrap().unwrap(); @@ -802,7 +802,7 @@ fn the_facts_read_the_recorded_encodings() { changed.add_entry(EntryMode::Blob, compat::FACTS_ENTRY.to_string(), blob); commit.tree = store.write(&changed.to_bytes().unwrap()).unwrap(); let new_hash = store.write(&commit.to_bytes().unwrap()).unwrap(); - update_ref(dir.path(), main_ref(), &new_hash).unwrap(); + update_ref(dir.path(), REF_HEAD_MAIN_FILENAME, &new_hash).unwrap(); let read = facts(dir.path()); assert!(read.encodings.iter().any(|e| e.kind == "handshake" && e.name == "an-older-default"), "{:?}", read.encodings); @@ -829,7 +829,7 @@ fn released_before_the_flip() -> TempDir { release(dir.path(), &ReleaseRequest::default()).unwrap(); let store = ObjectStore::new(dir.path()); - let hash = read_ref(dir.path(), main_ref()).unwrap(); + let hash = read_ref(dir.path(), REF_HEAD_MAIN_FILENAME).unwrap(); let mut commit = Commit::from_bytes(&store.read(&hash).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); let mut history = compat::read_history(&store, &tree).unwrap().unwrap(); @@ -848,7 +848,7 @@ fn released_before_the_flip() -> TempDir { let facts_blob = store.write(&Blob::new(to_cbor(&history).unwrap()).to_bytes().unwrap()).unwrap(); old.add_entry(EntryMode::Blob, compat::FACTS_ENTRY.to_string(), facts_blob); commit.tree = store.write(&old.to_bytes().unwrap()).unwrap(); - update_ref(dir.path(), main_ref(), &store.write(&commit.to_bytes().unwrap()).unwrap()).unwrap(); + update_ref(dir.path(), REF_HEAD_MAIN_FILENAME, &store.write(&commit.to_bytes().unwrap()).unwrap()).unwrap(); // And its config.idp as it was: stating neither. config(dir.path(), ""); dir @@ -1001,11 +1001,11 @@ fn a_changed_tree_is_numbered_as_its_next_build_would_be() { build(dir.path()).unwrap(); schema(dir.path(), "struct User {\n id: u64\n}\n\nprotocol Users {\n function get(id: u64) -> User;\n function list() -> u32;\n}\n\nprotocol Admin {\n function reset();\n}\n"); - let head = read_ref(dir.path(), main_ref()).unwrap(); + let head = read_ref(dir.path(), REF_HEAD_MAIN_FILENAME).unwrap(); let before = stored_files(dir.path()); let f = working(dir.path()); assert_eq!(stored_files(dir.path()), before, "nothing written"); - assert_eq!(read_ref(dir.path(), main_ref()).unwrap(), head); + assert_eq!(read_ref(dir.path(), REF_HEAD_MAIN_FILENAME).unwrap(), head); build(dir.path()).unwrap(); let built = facts(dir.path()); diff --git a/core/tests/cas/config_in_commit_tests.rs b/core/tests/cas/config_in_commit_tests.rs index 2596f5b..51dfb64 100644 --- a/core/tests/cas/config_in_commit_tests.rs +++ b/core/tests/cas/config_in_commit_tests.rs @@ -27,7 +27,7 @@ fn scaffold(root: &std::path::Path, config: &str) { fn root_tree(root: &std::path::Path) -> (ObjectStore, Tree) { let store = ObjectStore::new(root); - let head = refs::read_ref(root, refs::main_ref()).unwrap(); + let head = refs::read_ref(root, refs::REF_HEAD_MAIN_FILENAME).unwrap(); let commit = Commit::from_bytes(&store.read(&head).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); (store, tree) @@ -69,7 +69,7 @@ fn a_config_only_change_commits_without_bumping_the_version() { scaffold(dir.path(), CONFIG); let v1 = build(dir.path()).unwrap().current_version; - let head1 = refs::read_ref(dir.path(), refs::main_ref()).unwrap(); + let head1 = refs::read_ref(dir.path(), refs::REF_HEAD_MAIN_FILENAME).unwrap(); // Add a declared language — a config-only change, no schema edit. scaffold( @@ -77,7 +77,7 @@ fn a_config_only_change_commits_without_bumping_the_version() { &CONFIG.replace("rust#1.70.0 = {}", "rust#1.70.0 = {}\n python#3.11.0 = {}"), ); let res = build(dir.path()).unwrap(); - let head2 = refs::read_ref(dir.path(), refs::main_ref()).unwrap(); + let head2 = refs::read_ref(dir.path(), refs::REF_HEAD_MAIN_FILENAME).unwrap(); assert_ne!(head1, head2, "a config change creates a new commit"); // A new build, so the next dev count; but nothing calls for a bump. diff --git a/core/tests/cas/dependency_configs_tests.rs b/core/tests/cas/dependency_configs_tests.rs index ff16fa9..3eea945 100644 --- a/core/tests/cas/dependency_configs_tests.rs +++ b/core/tests/cas/dependency_configs_tests.rs @@ -13,7 +13,7 @@ use comline_core::doc::{changelog, frozen_config, frozen_schemas}; use comline_core::inspect; use comline_core::package::build::cas::build::{compare, working_tree, UnseenConfig}; use comline_core::package::build::cas::objects::{Commit, EntryMode, Tree}; -use comline_core::package::build::cas::{main_ref, read_ref, update_ref, ObjectStore}; +use comline_core::package::build::cas::{REF_HEAD_MAIN_FILENAME, read_ref, update_ref, ObjectStore}; use comline_core::package::build::{build, compile_package, VersionBump}; use comline_core::package::config::ir::frozen::cas::blob::{self, StoredConfigs}; use comline_core::schema::ir::diff::{BreakingChange, NewFeature, WireFacts}; @@ -291,7 +291,7 @@ fn the_changelog_uses_the_full_view() { fn head(dir: &Path) -> (ObjectStore, Commit, Tree) { let store = ObjectStore::new(dir); - let hash = read_ref(dir, main_ref()).unwrap(); + let hash = read_ref(dir, REF_HEAD_MAIN_FILENAME).unwrap(); let commit = Commit::from_bytes(&store.read(&hash).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); (store, commit, tree) @@ -375,7 +375,7 @@ fn a_stored_version_gives_the_facts_the_live_package_does() { .collect::>() ); // And what the history recorded is what recomputing it gives. - let hash = read_ref(&dir, main_ref()).unwrap(); + let hash = read_ref(&dir, REF_HEAD_MAIN_FILENAME).unwrap(); assert_eq!( compat::history_of_commit(&store, &hash).unwrap(), compat::compute_history_of_commit(&store, &head(&dir).1, &tree).unwrap() @@ -446,7 +446,7 @@ fn store_as_before_configs_were_kept(dir: &Path) -> Tree { let mut rewritten = commit; rewritten.tree = store.write(&old.to_bytes().unwrap()).unwrap(); let hash = store.write(&rewritten.to_bytes().unwrap()).unwrap(); - update_ref(dir, main_ref(), &hash).unwrap(); + update_ref(dir, REF_HEAD_MAIN_FILENAME, &hash).unwrap(); old } diff --git a/core/tests/cas/dependency_vendoring_tests.rs b/core/tests/cas/dependency_vendoring_tests.rs index 060b983..0d5da2f 100644 --- a/core/tests/cas/dependency_vendoring_tests.rs +++ b/core/tests/cas/dependency_vendoring_tests.rs @@ -42,7 +42,7 @@ fn write_consumer(dir: &Path, schema: &str) { fn root_tree(root: &Path) -> (ObjectStore, Tree) { let store = ObjectStore::new(root); - let head = refs::read_ref(root, refs::main_ref()).unwrap(); + let head = refs::read_ref(root, refs::REF_HEAD_MAIN_FILENAME).unwrap(); let commit = Commit::from_bytes(&store.read(&head).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); (store, tree) diff --git a/core/tests/cas/docs_in_commit_tests.rs b/core/tests/cas/docs_in_commit_tests.rs index 36d8fec..642354e 100644 --- a/core/tests/cas/docs_in_commit_tests.rs +++ b/core/tests/cas/docs_in_commit_tests.rs @@ -21,7 +21,7 @@ specification_version = 1 fn root_tree(root: &std::path::Path) -> (ObjectStore, Commit, Tree) { let store = ObjectStore::new(root); - let head = refs::read_ref(root, refs::main_ref()).unwrap(); + let head = refs::read_ref(root, refs::REF_HEAD_MAIN_FILENAME).unwrap(); let commit = Commit::from_bytes(&store.read(&head).unwrap()).unwrap(); let tree = Tree::from_bytes(&store.read(&commit.tree).unwrap()).unwrap(); (store, commit, tree) diff --git a/core/tests/cas/reconcile_tests.rs b/core/tests/cas/reconcile_tests.rs index c8d6e63..3cd0e72 100644 --- a/core/tests/cas/reconcile_tests.rs +++ b/core/tests/cas/reconcile_tests.rs @@ -9,7 +9,7 @@ use std::path::Path; use comline_core::compat; use comline_core::package::build::cas::objects::Commit; use comline_core::package::build::cas::reconcile::{mark_diverged, read_heads, Heads}; -use comline_core::package::build::cas::{main_ref, read_ref, Hash, ObjectStore}; +use comline_core::package::build::cas::{REF_HEAD_MAIN_FILENAME, read_ref, Hash, ObjectStore}; use comline_core::package::build::{build, latest_release, release, ReleaseRequest}; use tempfile::TempDir; @@ -46,7 +46,7 @@ fn branch(dir: &Path) -> TempDir { } fn head(dir: &Path) -> Hash { - read_ref(dir, main_ref()).unwrap() + read_ref(dir, REF_HEAD_MAIN_FILENAME).unwrap() } fn commit(dir: &Path, hash: &Hash) -> Commit { @@ -60,7 +60,7 @@ fn merge(ours: &Path, theirs: &Path) -> (Hash, Hash) { let (a, b) = (head(ours), head(theirs)); copy_dir(&theirs.join(".comline/objects"), &ours.join(".comline/objects")); fs::write( - ours.join(".comline").join(main_ref()), + ours.join(".comline").join(REF_HEAD_MAIN_FILENAME), format!("<<<<<<< HEAD\n{a}\n=======\n{b}\n>>>>>>> theirs\n"), ) .unwrap(); @@ -76,7 +76,7 @@ fn since(dir: &Path, protocol: &str, function: &str) -> String { /// The two parents of the new head, and that the ref is clean again. fn parents(dir: &Path) -> Vec { - let text = fs::read_to_string(dir.join(".comline").join(main_ref())).unwrap(); + let text = fs::read_to_string(dir.join(".comline").join(REF_HEAD_MAIN_FILENAME)).unwrap(); assert_eq!(text.trim().len(), 64, "the ref is one hash again: {text}"); assert!(matches!(read_heads(dir).unwrap(), Heads::One(_))); commit(dir, &head(dir)).parents @@ -177,21 +177,21 @@ fn releases_on_both_sides_refuse_until_one_is_picked() { release(theirs.path(), &ReleaseRequest::default()).unwrap(); let (a, b) = merge(ours.path(), theirs.path()); - let conflicted = fs::read_to_string(ours.path().join(".comline").join(main_ref())).unwrap(); + let conflicted = fs::read_to_string(ours.path().join(".comline").join(REF_HEAD_MAIN_FILENAME)).unwrap(); let err = build(ours.path()).unwrap_err().to_string(); assert!(err.contains("both branches released"), "{err}"); assert!(err.contains("0.1.0 ("), "names the common ancestor: {err}"); assert!(err.contains(&a.to_hex()) && err.contains(&b.to_hex()), "{err}"); assert!(err.contains("Pick the release to keep"), "{err}"); // Nothing written: the ref is as Git left it. - let after = fs::read_to_string(ours.path().join(".comline").join(main_ref())).unwrap(); + let after = fs::read_to_string(ours.path().join(".comline").join(REF_HEAD_MAIN_FILENAME)).unwrap(); assert_eq!(after, conflicted); // Neither can a release go ahead on a conflicted ref. let err = release(ours.path(), &ReleaseRequest::default()).unwrap_err().to_string(); assert!(err.contains("conflict markers"), "{err}"); // Picking one: the other side's changes build on top of its release. - fs::write(ours.path().join(".comline").join(main_ref()), a.to_hex()).unwrap(); + fs::write(ours.path().join(".comline").join(REF_HEAD_MAIN_FILENAME), a.to_hex()).unwrap(); let built = build(ours.path()).unwrap(); assert_eq!(built.last_release.as_deref(), Some("0.1.1")); assert_eq!(built.current_version, "0.1.2-dev.1"); @@ -210,7 +210,7 @@ fn a_ref_resolved_to_one_side_can_be_marked_diverged_again() { // Resolved by taking ours: their commit is orphaned. let (a, b) = merge(ours.path(), theirs.path()); - fs::write(ours.path().join(".comline").join(main_ref()), a.to_hex()).unwrap(); + fs::write(ours.path().join(".comline").join(REF_HEAD_MAIN_FILENAME), a.to_hex()).unwrap(); mark_diverged(ours.path(), &b).unwrap(); assert_eq!(read_heads(ours.path()).unwrap(), Heads::Two(a, b)); diff --git a/core/tests/cas/release_tests.rs b/core/tests/cas/release_tests.rs index 34b16dc..c375254 100644 --- a/core/tests/cas/release_tests.rs +++ b/core/tests/cas/release_tests.rs @@ -139,17 +139,17 @@ fn nothing_that_calls_for_a_bump_needs_a_raise_to_release() { #[test] fn an_old_history_s_plain_versions_count_as_releases() { use comline_core::package::build::cas::objects::Commit; - use comline_core::package::build::cas::{main_ref, read_ref, update_ref, ObjectStore}; + use comline_core::package::build::cas::{REF_HEAD_MAIN_FILENAME, read_ref, update_ref, ObjectStore}; // A history built before builds and releases were separate: its head is // a plain 0.0.3, written without a release record. let dir = package(); build(dir.path()).unwrap(); let store = ObjectStore::new(dir.path()); - let head = Commit::from_bytes(&store.read(&read_ref(dir.path(), main_ref()).unwrap()).unwrap()).unwrap(); + let head = Commit::from_bytes(&store.read(&read_ref(dir.path(), REF_HEAD_MAIN_FILENAME).unwrap()).unwrap()).unwrap(); let old = Commit::new(head.tree, vec![], "someone".into(), 0, "Patch version bump".into(), "0.0.3".into()); let old_hash = store.write(&old.to_bytes().unwrap()).unwrap(); - update_ref(dir.path(), main_ref(), &old_hash).unwrap(); + update_ref(dir.path(), REF_HEAD_MAIN_FILENAME, &old_hash).unwrap(); assert_eq!(latest_release(dir.path()).unwrap().unwrap().version, "0.0.3"); // Anything new leaves the 0.0 era for 0.1.0. diff --git a/core/tests/package/schema_loading.rs b/core/tests/package/schema_loading.rs index 7469a5a..e1c6eed 100644 --- a/core/tests/package/schema_loading.rs +++ b/core/tests/package/schema_loading.rs @@ -63,7 +63,7 @@ fn test_schema_lifecycle() { assert!(main_ref.exists(), "main ref not created"); // Verify we can read the ref - assert!(refs::ref_exists(&package_path, refs::main_ref()), "main ref should exist"); + assert!(refs::ref_exists(&package_path, refs::REF_HEAD_MAIN_FILENAME), "main ref should exist"); let released = comline_core::package::build::release(&package_path, &Default::default()) .expect("first release"); diff --git a/core/tests/package_config/mod.rs b/core/tests/package_config/mod.rs index 362b956..d8f19ff 100644 --- a/core/tests/package_config/mod.rs +++ b/core/tests/package_config/mod.rs @@ -9,13 +9,13 @@ use std::path::{Path, PathBuf}; // Crate Uses // External Uses -use comline_core::package::config::idl::constants::CONGREGATION_EXTENSION; +use comline_core::package::config::idl::PACKAGE_CONFIG_FILENAME; use once_cell::sync::Lazy; static TEST_PACKAGE_DIR: Lazy<&Path> = Lazy::new(|| Path::new("tests/fixtures/packages/test/")); static TEST_PACKAGE_CONFIG_PATH: Lazy = - Lazy::new(|| TEST_PACKAGE_DIR.join(format!("config.{}", CONGREGATION_EXTENSION))); + Lazy::new(|| TEST_PACKAGE_DIR.join(PACKAGE_CONFIG_FILENAME)); /* #[test]