diff --git a/.config/bough.toml b/.config/bough.toml deleted file mode 100644 index 234b6062..00000000 --- a/.config/bough.toml +++ /dev/null @@ -1,8 +0,0 @@ -include = ["**/*"] -exclude = ["**/target/**", "**/node_modules/**", "**/.bough/**"] - -base_root_dir = ".." - -[lang.js] -include = ["**/*.js"] -exclude = ["**/*.test.*", "**/node_modules/**"] diff --git a/crates/bough-docs-cli/src/build.rs b/crates/bough-docs-cli/src/build.rs index 602e4b5d..ecd53a46 100644 --- a/crates/bough-docs-cli/src/build.rs +++ b/crates/bough-docs-cli/src/build.rs @@ -268,8 +268,12 @@ pub fn build() { } fs::create_dir_all(out_dir).expect("failed to create output dir"); - let reference_dir = docs_dir.join("config"); - fs::create_dir_all(&reference_dir).expect("failed to create config docs dir"); + let generated_dir = Path::new("target/bough-docs-generated"); + if generated_dir.exists() { + fs::remove_dir_all(generated_dir).expect("failed to clean generated dir"); + } + let reference_dir = generated_dir.join("config"); + fs::create_dir_all(&reference_dir).expect("failed to create generated config dir"); let reference_md = format!( "---\ntitle: Configuration Reference\n---\n\n{}", crate::facet_reference::make_facet_reference::() @@ -277,13 +281,15 @@ pub fn build() { fs::write(reference_dir.join("reference.md"), reference_md) .expect("failed to write config reference"); - let md_files = collect_md_files(docs_dir); + let mut md_files = collect_md_files(docs_dir); + md_files.extend(collect_md_files(generated_dir)); if md_files.is_empty() { eprintln!("no markdown files found in {}", docs_dir.display()); return; } - let toc = build_toc(docs_dir, docs_dir); + let mut toc = build_toc(docs_dir, docs_dir); + toc.extend(build_toc(generated_dir, generated_dir)); let mut hl = Highlighter::new(); let mut opts = Options::default(); @@ -305,7 +311,10 @@ pub fn build() { .into_owned() }); - let rel = path.strip_prefix(docs_dir).unwrap(); + let rel = path + .strip_prefix(docs_dir) + .or_else(|_| path.strip_prefix(generated_dir)) + .unwrap(); let slug = if rel.file_stem().is_some_and(|s| s == "index") { rel.parent() .map(|p| p.to_string_lossy().into_owned()) diff --git a/crates/bough-docs-cli/src/serve.rs b/crates/bough-docs-cli/src/serve.rs index c110083a..1c6da569 100644 --- a/crates/bough-docs-cli/src/serve.rs +++ b/crates/bough-docs-cli/src/serve.rs @@ -11,7 +11,7 @@ const OUT_DIR: &str = "target/bough-docs-site"; pub fn serve(port: u16) { let addr = format!("0.0.0.0:{port}"); - let server = Arc::new(Server::http(&addr).expect("failed to start server")); + let server = Server::http(&addr).expect("failed to start server"); eprintln!("serving at http://localhost:{port}"); let generation = Arc::new((Mutex::new(0u64), Condvar::new())); @@ -19,8 +19,8 @@ pub fn serve(port: u16) { let watcher_gen = generation.clone(); let watcher_path = watched_path.clone(); - let mut debouncer = new_debouncer( - Duration::from_millis(300), + let mut _debouncer = new_debouncer( + Duration::from_millis(100), move |res: notify_debouncer_mini::DebounceEventResult| { let Ok(events) = res else { return }; let target = watcher_path.lock().unwrap(); @@ -39,29 +39,20 @@ pub fn serve(port: u16) { ) .expect("failed to create file watcher"); - debouncer + _debouncer .watcher() .watch(Path::new(OUT_DIR), RecursiveMode::Recursive) .expect("failed to watch output dir"); let root = Path::new(OUT_DIR); - let pool_size = 4; - let mut handles = Vec::new(); - for _ in 0..pool_size { - let server = server.clone(); - let generation = generation.clone(); - let watched_path = watched_path.clone(); + for request in server.incoming_requests() { + let url_path = request.url().trim_start_matches('/'); + let url_path = url_path.split('?').next().unwrap_or(url_path); - handles.push(std::thread::spawn(move || loop { - let Ok(request) = server.recv() else { - continue; - }; - - let url_path = request.url().trim_start_matches('/'); - let url_path = url_path.split('?').next().unwrap_or(url_path); - - if url_path == "js/dev-server-refresh.js" { + if url_path == "js/dev-server-refresh.js" { + let generation = generation.clone(); + std::thread::spawn(move || { let (lock, cvar) = &*generation; let current = *lock.lock().unwrap(); let _guard = cvar @@ -72,58 +63,52 @@ pub fn serve(port: u16) { Header::from_bytes("Content-Type", "application/javascript").unwrap(); let _ = request .respond(Response::from_string("window.location.reload()").with_header(header)); - continue; - } - - let file_path = if url_path.is_empty() { - root.join("index.html") + }); + continue; + } + + let file_path = if url_path.is_empty() { + root.join("index.html") + } else { + let candidate = root.join(url_path); + if candidate.is_dir() { + candidate.join("index.html") + } else if candidate.exists() { + candidate } else { - let candidate = root.join(url_path); - if candidate.is_dir() { - candidate.join("index.html") - } else if candidate.exists() { - candidate - } else { - candidate.join("index.html") - } - }; - - let Ok(content) = fs::read(&file_path) else { - let _ = request.respond(Response::from_string("404").with_status_code(404)); - continue; - }; - - let content_type = match file_path.extension().and_then(|e| e.to_str()) { - Some("html") => "text/html; charset=utf-8", - Some("css") => "text/css", - Some("js") => "application/javascript", - Some("svg") => "image/svg+xml", - Some("png") => "image/png", - Some("jpg" | "jpeg") => "image/jpeg", - _ => "application/octet-stream", - }; - - if content_type == "text/html; charset=utf-8" { - eprintln!(" {}", request.url()); - *watched_path.lock().unwrap() = fs::canonicalize(&file_path).ok(); + candidate.join("index.html") } - - let content = if content_type == "text/html; charset=utf-8" { - let mut html = String::from_utf8_lossy(&content).into_owned(); - html.push_str("\n"); - html.into_bytes() - } else { - content - }; - - let header = Header::from_bytes("Content-Type", content_type).unwrap(); - let _ = request.respond(Response::from_data(content).with_header(header)); - })); - } - - for h in handles { - h.join().unwrap(); + }; + + let Ok(content) = fs::read(&file_path) else { + let _ = request.respond(Response::from_string("404").with_status_code(404)); + continue; + }; + + let content_type = match file_path.extension().and_then(|e| e.to_str()) { + Some("html") => "text/html; charset=utf-8", + Some("css") => "text/css", + Some("js") => "application/javascript", + Some("svg") => "image/svg+xml", + Some("png") => "image/png", + Some("jpg" | "jpeg") => "image/jpeg", + _ => "application/octet-stream", + }; + + if content_type == "text/html; charset=utf-8" { + eprintln!(" {}", request.url()); + *watched_path.lock().unwrap() = fs::canonicalize(&file_path).ok(); + } + + let content = if content_type == "text/html; charset=utf-8" { + let mut html = String::from_utf8_lossy(&content).into_owned(); + html.push_str("\n"); + html.into_bytes() + } else { + content + }; + + let header = Header::from_bytes("Content-Type", content_type).unwrap(); + let _ = request.respond(Response::from_data(content).with_header(header)); } - - drop(debouncer); } diff --git a/docs/config/index.md b/docs/config/index.md index a337257f..1622d59b 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1,7 +1,6 @@ +++ -title = "Configuring Bough" +title = "Config" +idx = 2 +++ -`bough` follows a principle of config over plugins. To get `bough` to mutate your files you have to tell it what language you're using and how to find your files using globs. - -We provide a menu of configs for languages `bough` supports. +Config diff --git a/docs/config/reference.md b/docs/config/reference.md deleted file mode 100644 index c01b7c0e..00000000 --- a/docs/config/reference.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: Configuration Reference ---- - -## `Config` - -Project configuration. Typically loaded from `bough.config.toml` or equivalent. All fields can also be set via `BOUGH_*` env vars or `--config.*` CLI flags. - -| Field | Type | Description | -|-------|------|-------------| -| `workers` | `u64` | Number of parallel worker processes. Each gets its own workspace copy. Default: 1. *(optional)* | -| `threads` | `u64` | Number of threads bough uses for analysis and mutation discovery. Default: 1. *(optional)* | -| `base_root_dir` | `String` | Root directory of the project source tree. Relative paths are resolved from the config file's directory. Required. | -| `include` | `String[]` | Glob patterns for files to clone into workspaces and scan for mutations. At least one is required. Example: `["src/**", "lib/**"]`. | -| `exclude` | `String[]` | Glob patterns to exclude from workspace cloning and mutation scanning. `.gitignore` patterns, VCS directories, and the `.bough/` state dir are always excluded automatically. | -| `lang` | `Map` | Per-language configuration keyed by language id. At least one language must be configured. | -| `pwd` | `String?` | Working directory for the phase command. Relative to `base_root_dir`. Default: `.`. *(optional)* | -| `env` | `Map?` | Extra environment variables. Phase-level values merge with top-level defaults; set a key to `""` to remove an inherited variable. *(optional)* | -| `timeout` | `TimeoutConfig?` | Timeout limits for the phase command. *(optional)* | -| `test` | `TestPhaseConfig?` | Test phase. Required. The command that runs your test suite. *(optional)* | -| `init` | `PhaseConfig?` | Init phase. Optional command run once per workspace before testing begins. *(optional)* | -| `reset` | `PhaseConfig?` | Reset phase. Optional command run after each mutation test to restore workspace state. *(optional)* | -| `find` | `FindMutationsConfig` | Controls how `bough find` selects and ranks mutations. *(optional)* | - -### `LanguageConfig` - -Per-language file matching and skip rules. - -| Field | Type | Description | -|-------|------|-------------| -| `include` | `String[]` | Glob patterns matching source files for this language. Example: `["**/*.ext"]`. | -| `exclude` | `String[]` | Additional exclude globs for this language, appended after the top-level `exclude` patterns. | -| `skip` | `LanguageSkipConfig?` | Optional rules for skipping certain AST nodes from mutation. *(optional)* | - -#### `LanguageSkipConfig` - -Rules for excluding specific AST nodes from mutation. - -| Field | Type | Description | -|-------|------|-------------| -| `query` | `String[]` | Tree-sitter query patterns. Any AST node matching one of these queries will not be mutated. *(optional)* | - -### `TimeoutConfig` - -Timeout limits for a phase command. At least one of `absolute` or `relative` must be set when the timeout section is present. - -| Field | Type | Description | -|-------|------|-------------| -| `absolute` | `u64?` | Hard cap in seconds. The command is killed after this duration regardless of anything else. *(optional)* | -| `relative` | `f64?` | Multiplier applied to the baseline test duration. E.g. `3.0` means "allow up to 3× the unmutated test time". *(optional)* | - -### `TestPhaseConfig` - -Test phase configuration. Defines the command bough runs to determine whether a mutation is killed. - -| Field | Type | Description | -|-------|------|-------------| -| `cmd` | `String` | Shell command to run the test suite. Required. | -| `pwd` | `String?` | Working directory for the phase command. Relative to `base_root_dir`. Default: `.`. *(optional)* | -| `env` | `Map?` | Extra environment variables. Phase-level values merge with top-level defaults; set a key to `""` to remove an inherited variable. *(optional)* | -| `timeout` | `TimeoutConfig?` | Timeout limits for the phase command. *(optional)* | - -### `PhaseConfig` - -Configuration for an optional phase (init or reset). Omit the section entirely to skip the phase. - -| Field | Type | Description | -|-------|------|-------------| -| `cmd` | `String?` | Shell command to run for this phase. *(optional)* | -| `pwd` | `String?` | Working directory for the phase command. Relative to `base_root_dir`. Default: `.`. *(optional)* | -| `env` | `Map?` | Extra environment variables. Phase-level values merge with top-level defaults; set a key to `""` to remove an inherited variable. *(optional)* | -| `timeout` | `TimeoutConfig?` | Timeout limits for the phase command. *(optional)* | - -### `FindMutationsConfig` - -Settings for `bough find` — controls how many mutations are selected and which ranking factors are used to prioritise them. - -| Field | Type | Description | -|-------|------|-------------| -| `number` | `usize` | Total number of mutations to return. Default: 1. *(optional)* | -| `number_per_file` | `usize` | Maximum mutations to return per source file. Default: 1. *(optional)* | -| `factors` | `Factor[]` | Ranking factors used to score and sort candidate mutations. Default: `[EncompasingMissedMutationsCount, TSNodeDepth]`. *(optional)* | - -#### `Factor` - -- **`FileAuthorCount`** — How many authors have touched this file -- **`MutationSeverity`** — Severity of the mutation operator (e.g. removing a null check vs flipping a comparator) -- **`EncompasingMissedMutationsCount`** — How many mutations have a span that includes this mutation -- **`SiblingMissedMutations`** — How many other surviving mutants exist in the same function -- **`SiblingOperatorDiversity`** — How many distinct mutation operator types survive in the same function -- **`TSNodeDepth`** — How deep into the tree-sitter node graph is this mutation -- **`VcsFileChurn`** — How many times has this file been modified in version control -- **`VcsLineBlameRecency`** — How recently was this line touched - diff --git a/docs/getting-started.md b/docs/getting-started.md deleted file mode 100644 index 2a39a2ac..00000000 --- a/docs/getting-started.md +++ /dev/null @@ -1,31 +0,0 @@ -+++ -title = "Getting Started" -idx = 1 -+++ - -Install bough and run your first mutation test. - -## Installation - -```bash -cargo install bough -``` - -## Configuration - -Create a `bough.toml` in your project root: - -```toml -[language.javascript] -include = ["src/**/*.js"] -test_cmd = "npm test" -``` - -## Usage - -```rust -fn main() { - let x = 1 + 2; - println!("{x}"); -} -``` diff --git a/docs/guides/ci.md b/docs/guides/ci.md deleted file mode 100644 index 90c8bf17..00000000 --- a/docs/guides/ci.md +++ /dev/null @@ -1,6 +0,0 @@ -+++ -title = "CI Integration" -idx = 2 -+++ - -Running bough in CI. diff --git a/docs/guides/configuration.md b/docs/guides/configuration.md deleted file mode 100644 index 1a6c668d..00000000 --- a/docs/guides/configuration.md +++ /dev/null @@ -1,6 +0,0 @@ -+++ -title = "Configuration" -idx = 1 -+++ - -How to configure bough. diff --git a/docs/guides/index.md b/docs/guides/index.md deleted file mode 100644 index ed74a70a..00000000 --- a/docs/guides/index.md +++ /dev/null @@ -1,6 +0,0 @@ -+++ -title = "Guides" -idx = 2 -+++ - -In-depth guides for using bough. diff --git a/docs/setup/index.md b/docs/setup/index.md new file mode 100644 index 00000000..39f0776d --- /dev/null +++ b/docs/setup/index.md @@ -0,0 +1,8 @@ ++++ +title = "Setup" +idx = 1 ++++ + +`bough` follows a principle of config over plugins. To get `bough` to mutate your files you have to tell it what language you're using and how to find your files using globs. + +We provide a menu of configs for languages `bough` supports. diff --git a/docs/installation.md b/docs/setup/installation.md similarity index 100% rename from docs/installation.md rename to docs/setup/installation.md diff --git a/docs/config/javascript.md b/docs/setup/javascript.md similarity index 100% rename from docs/config/javascript.md rename to docs/setup/javascript.md