diff --git a/Cargo.lock b/Cargo.lock index aa1493fb..cc0c17ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -241,10 +241,12 @@ checksum = "cf2c09e5a796b8989e7555cbe097ddd3c3ffa4c02392b9b4ad0d7cd48b1af5c2" dependencies = [ "autocfg", "camino", + "chrono", "const-fnv1a-hash", "iddqd", "impls", "indexmap", + "uuid", ] [[package]] @@ -1051,6 +1053,16 @@ dependencies = [ "rustc-hash", ] +[[package]] +name = "uuid" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b672338555252d43fd2240c714dc444b8c6fb0a5c5335e65a07bba7742735ddb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "version_check" version = "0.9.5" diff --git a/crates/bough-core/Cargo.toml b/crates/bough-core/Cargo.toml index 8e28b5e7..0d8d8c93 100644 --- a/crates/bough-core/Cargo.toml +++ b/crates/bough-core/Cargo.toml @@ -6,8 +6,9 @@ license.workspace = true [dependencies] bough-typed-hash = { path = "../bough-typed-hash" } -facet = "0.44" +facet = { version = "0.44", features = ["uuid", "chrono"] } facet-json = "0.44.1" +chrono = "0.4.44" facet-toml = "0.44" facet-value = "0.44" figue = "2.0.0" @@ -18,7 +19,6 @@ tree-sitter-javascript = "0.25" tree-sitter-typescript = "0.23" wait-timeout = "0.2" walkdir = "2.5.0" -chrono = "0.4.44" [dev-dependencies] tempfile = "3.26" diff --git a/crates/bough-core/SESSION_SPEC.md b/crates/bough-core/SESSION_SPEC.md index b69c6d97..1489b4a0 100644 --- a/crates/bough-core/SESSION_SPEC.md +++ b/crates/bough-core/SESSION_SPEC.md @@ -2,3 +2,9 @@ core[session.init] `Session::::new(config: Config) -> Result` + +core[session.mutations_in_base] +`Session::mutations_in_base -> &HashSet` returns all the possible mutations found in the base + +core[session.mutations_on_disk] +`Session::mutations_on_disk -> Iter<&MutationState>` returns all mutations diff --git a/crates/bough-core/src/lib.rs b/crates/bough-core/src/lib.rs index 6f9185a1..3f6e5159 100644 --- a/crates/bough-core/src/lib.rs +++ b/crates/bough-core/src/lib.rs @@ -6,9 +6,9 @@ mod file; mod language; mod mutant; mod mutation; -mod outcome; mod phase; mod session; +mod state; mod test_id; mod twig; mod workspace; diff --git a/crates/bough-core/src/mutant.rs b/crates/bough-core/src/mutant.rs index 05c55d03..04f05eec 100644 --- a/crates/bough-core/src/mutant.rs +++ b/crates/bough-core/src/mutant.rs @@ -27,7 +27,7 @@ pub struct MutantHash([u8; 32]); // core[impl mutant.twig] // core[impl mutant.kind] // core[impl mutant.span] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, facet::Facet)] pub struct Mutant { lang: LanguageId, twig: Twig, @@ -147,7 +147,7 @@ impl TypedHashable for BasedMutant<'_> { } // core[impl span.point] -#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto)] +#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto, Hash, facet::Facet)] pub struct Span { start: Point, end: Point, @@ -170,7 +170,7 @@ impl Span { // core[impl point.line] // core[impl point.col] // core[impl point.byte] -#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto)] +#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto, Hash, facet::Facet)] pub struct Point { line: usize, col: usize, @@ -195,13 +195,15 @@ impl Point { } } -#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto)] +#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto, Hash, facet::Facet)] +#[repr(u8)] pub enum BinaryOpMutationKind { Add, Sub, } -#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto)] +#[derive(Debug, Clone, PartialEq, Eq, bough_typed_hash::HashInto, Hash, facet::Facet)] +#[repr(u8)] pub enum MutantKind { StatementBlock, Condition, @@ -781,8 +783,7 @@ mod tests { std::fs::write(dir1.path().join("src/a.js"), "const a = 1;").unwrap(); let base1 = Base::new( dir1.path().to_path_buf(), - TwigsIterBuilder::new() - .with_include_glob("src/**/*.js") + TwigsIterBuilder::new().with_include_glob("src/**/*.js"), ) .unwrap(); @@ -791,8 +792,7 @@ mod tests { std::fs::write(dir2.path().join("src/a.js"), "const b = 2;").unwrap(); let base2 = Base::new( dir2.path().to_path_buf(), - TwigsIterBuilder::new() - .with_include_glob("src/**/*.js") + TwigsIterBuilder::new().with_include_glob("src/**/*.js"), ) .unwrap(); @@ -930,8 +930,7 @@ mod tests { } let base = Base::new( dir.path().to_path_buf(), - TwigsIterBuilder::new() - .with_include_glob("src/**/*.js") + TwigsIterBuilder::new().with_include_glob("src/**/*.js"), ) .unwrap(); (dir, base) diff --git a/crates/bough-core/src/mutation.rs b/crates/bough-core/src/mutation.rs index 45a777f7..671fcc9b 100644 --- a/crates/bough-core/src/mutation.rs +++ b/crates/bough-core/src/mutation.rs @@ -2,9 +2,6 @@ use super::language::driver_for_lang; use crate::mutant::Mutant; use bough_typed_hash::{HashInto, TypedHashable}; -#[derive(bough_typed_hash::TypedHash)] -pub struct MutationHash([u8; 32]); - // core[impl mutation.iter.mutant] pub struct MutationIter<'a> { mutant: &'a Mutant, @@ -41,7 +38,7 @@ impl<'a> Iterator for MutationIter<'a> { // core[impl mutation.mutant] // core[impl mutation.subst] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, facet::Facet, TypedHashable)] pub struct Mutation { pub(crate) mutant: Mutant, pub(crate) subst: String, @@ -57,21 +54,6 @@ impl Mutation { } } -// core[impl mutation.hash.typed-hashable] -impl TypedHashable for Mutation { - type Hash = MutationHash; -} - -// core[impl mutation.hash.mutant] -// core[impl mutation.hash.subst] -impl HashInto for Mutation { - fn hash_into(&self, state: &mut bough_typed_hash::ShaState) -> Result<(), std::io::Error> { - self.mutant.hash_into(state)?; - self.subst.hash_into(state)?; - Ok(()) - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/bough-core/src/outcome.rs b/crates/bough-core/src/outcome.rs deleted file mode 100644 index c2159cb5..00000000 --- a/crates/bough-core/src/outcome.rs +++ /dev/null @@ -1,25 +0,0 @@ -use facet::Facet; - -use crate::mutation::Mutation; - -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Facet)] -#[facet(rename_all = "PascalCase")] -#[repr(u8)] -pub enum Outcome { - #[default] - Missed, - Caught, -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct MutationOutcome { - outcome: Option, - // outcome_at: chrono::DateTime, - mutation: Mutation, -} - -// impl HashInto for MutationOutcome { -// fn hash_into(&self, state: &mut bough_typed_hash::ShaState) -> Result<(), std::io::Error> { -// self.mutation.hash_into(state) -// } -// } diff --git a/crates/bough-core/src/session.rs b/crates/bough-core/src/session.rs index 207c3b7b..8e57ec91 100644 --- a/crates/bough-core/src/session.rs +++ b/crates/bough-core/src/session.rs @@ -1,8 +1,14 @@ -use std::path::PathBuf; +use std::{collections::HashSet, path::PathBuf}; -use crate::{LanguageId, base::Base, file::Error, twig::TwigsIterBuilder}; +use bough_typed_hash::TypedHashable; + +use crate::{ + LanguageId, base::Base, facet_disk_store::FacetDiskStore, mutation::Mutation, state::State, + twig::TwigsIterBuilder, +}; trait Config { + fn get_bough_state_dir(&self) -> PathBuf; fn get_base_root_path(&self) -> PathBuf; fn get_base_include_globs(&self) -> impl Iterator; fn get_base_exclude_globs(&self) -> impl Iterator; @@ -12,17 +18,25 @@ trait Config { fn get_lang_exclude_globs(&self, language_id: LanguageId) -> impl Iterator; } +pub enum Error { + File(crate::file::Error), + Io(std::io::Error), +} + pub struct TestConfig {} pub struct Session { config: C, base: Base, workspaces: Vec, + mutations_in_base: HashSet, } impl Session { // core[impl session.init] pub fn new(config: C) -> Result { + let workspaces = vec![]; + let mut base_twigs_iter_builder = TwigsIterBuilder::new(); for include in config.get_base_include_globs() { base_twigs_iter_builder = base_twigs_iter_builder.with_include_glob(include); @@ -44,39 +58,29 @@ impl Session { base.add_mutator(lang, lang_twigs_iter_builder); } - let workspaces = vec![]; + let mutations_in_base = base.mutations().collect::, _>>()?; + let mutations_state = FacetDiskStore::<::Hash, State>::new( + config.get_bough_state_dir().join("state"), + ); Ok(Self { config, base, workspaces, + mutations_in_base, }) } } -impl Config for TestConfig { - fn get_base_root_path(&self) -> PathBuf { - todo!() - } - - fn get_base_include_globs(&self) -> impl Iterator { - vec![].into_iter() - } - - fn get_base_exclude_globs(&self) -> impl Iterator { - vec![].into_iter() - } - - fn get_lang_include_globs(&self, language_id: LanguageId) -> impl Iterator { - vec![].into_iter() - } - - fn get_lang_exclude_globs(&self, language_id: LanguageId) -> impl Iterator { - vec![].into_iter() +impl From for Error { + fn from(e: crate::file::Error) -> Self { + Error::File(e) } +} - fn get_langs(&self) -> impl Iterator { - vec![].into_iter() +impl From for Error { + fn from(e: std::io::Error) -> Self { + Error::Io(e) } } @@ -112,6 +116,10 @@ mod tests { fn get_langs(&self) -> impl Iterator { vec![].into_iter() } + + fn get_bough_state_dir(&self) -> PathBuf { + todo!() + } } // core[verify session.init] diff --git a/crates/bough-core/src/state.rs b/crates/bough-core/src/state.rs new file mode 100644 index 00000000..a957a98e --- /dev/null +++ b/crates/bough-core/src/state.rs @@ -0,0 +1,24 @@ +use chrono::{DateTime, Utc}; +use facet::Facet; + +use crate::{mutation::Mutation, test_id::TestId}; + +#[derive(Facet)] +#[repr(u8)] +pub enum Status { + Caught, + CaughtByTests(Vec), + Missed, +} + +#[derive(Facet)] +struct Outcome { + status: Status, + at: DateTime, +} + +#[derive(Facet)] +pub struct State { + mutation: Mutation, + outcome: Option, +} diff --git a/crates/bough-core/src/test_id.rs b/crates/bough-core/src/test_id.rs index eadda345..c6ed4902 100644 --- a/crates/bough-core/src/test_id.rs +++ b/crates/bough-core/src/test_id.rs @@ -1 +1,3 @@ -struct TestId(String); +use facet::Facet; +#[derive(Facet)] +pub struct TestId(String); diff --git a/crates/bough-core/src/twig.rs b/crates/bough-core/src/twig.rs index b3e7bbf6..698daee4 100644 --- a/crates/bough-core/src/twig.rs +++ b/crates/bough-core/src/twig.rs @@ -2,7 +2,7 @@ use crate::file::{Error, Root}; use std::path::{Path, PathBuf}; // core[impl file.twig] -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, facet::Facet)] pub struct Twig(PathBuf); impl Twig {