From e757979f1a2afdbe7146066345bb9acd19d3b151 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 17:09:59 +0000 Subject: comments: say why, not what MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every module-level `//!` header is gone, and the comments that remained either re-explained the line below them or had grown into paragraphs. Density went from one comment line per 6.7 lines of code to one per 10. 827 insertions against 2194 deletions across 86 files. What survived: the invariants (I1-I12), the design cross-references into DESIGN.md, and the notes recording a bug that was found and fixed — those are the comments that carry weight, because they answer a question the code cannot answer about itself. What did not: restating a function signature in prose, and narration of the statement underneath. --- tests/config.rs | 64 +++++++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 45 deletions(-) (limited to 'tests/config.rs') diff --git a/tests/config.rs b/tests/config.rs index 20010a7..3737045 100644 --- a/tests/config.rs +++ b/tests/config.rs @@ -1,21 +1,10 @@ -//! The server root: one directory, named once. -//! -//! `--root` selects the directory and `config.json` lives inside it, so the root -//! *is* wherever the config was found; the `root` field in the file is a record -//! of that, not a second knob. Re-joining a relative field onto the config's own -//! directory is what made `--root runtime` become `runtime/runtime/…`: `init` -//! created and migrated one tree, and every command after it ran against a -//! second one with its own empty database. - use std::path::{Path, PathBuf}; use std::process::Command; use aur_build::config::Config; /// The exact shape of the bug: a relative `--root`, saved verbatim, read back by -/// the next command. Relative to the crate root here, which is the cwd cargo -/// gives a test — the same situation as running `--root runtime` from a directory -/// that is not `/`. +/// the next command. #[test] fn a_relative_root_is_absolutized_once_and_never_doubled() { let rel = PathBuf::from("target").join("config-root-test").join("runtime"); @@ -47,8 +36,8 @@ fn a_relative_root_is_absolutized_once_and_never_doubled() { std::fs::remove_dir_all(&rel).unwrap(); } -/// The legacy shape on disk: a config written by an `init` that saved -/// `--root runtime` verbatim. Loading it must not resurrect the doubled tree. +/// The legacy shape on disk: a config written by an `init` that saved `--root +/// runtime` verbatim. Loading it must not resurrect the doubled tree. #[test] fn a_stale_relative_root_in_the_file_is_ignored() { let tmp = tempfile::tempdir().unwrap(); @@ -72,9 +61,8 @@ fn a_root_with_no_config_is_an_error_not_a_fresh_server() { ); } -/// The CLI half of the same rule. The old fallback invented a default config for -/// *any* command, so a typo'd `--root` quietly produced an empty server whose -/// commands reported success against a database with nothing in it. +/// The CLI half of the same rule: the old fallback invented a default config for +/// *any* command, so a typo'd `--root` quietly produced an empty server. #[test] fn the_cli_refuses_a_root_that_was_never_initialized() { let tmp = tempfile::tempdir().unwrap(); @@ -95,8 +83,7 @@ fn the_cli_refuses_a_root_that_was_never_initialized() { assert!(err.contains("init"), "{err}"); } -/// …and `init` is still allowed to run where there is no config yet, which is the -/// only reason the fallback existed. +/// …and `init` is still allowed to run where there is no config yet. #[test] fn init_still_runs_where_there_is_no_config_yet() { let tmp = tempfile::tempdir().unwrap(); @@ -133,15 +120,9 @@ fn an_absolute_root_is_used_verbatim() { assert_eq!(Config::load(dir).unwrap().root, dir); } -// --------------------------------------------------------------------------- -// The sandbox configuration: three kinds, and only three. -// -// This used to be `sandbox_backend: String` matched with a `_ =>` arm that -// produced loopback, so `"kata"` — a real, intended backend — silently meant -// "run the untrusted PKGBUILD as the hub's own user". The kinds are an enum -// now, so the invalid configurations do not parse, and the error says which -// field or which value was wrong. -// --------------------------------------------------------------------------- +// The sandbox configuration: three kinds, and only three. The kinds are an enum +// now, so a configuration that would silently mean "run the untrusted PKGBUILD as +// the hub's own user" does not parse. /// Write a config carrying exactly this `sandbox` value and load it. fn load_sandbox(sandbox: &str) -> Result { @@ -244,7 +225,7 @@ fn an_unknown_kind_names_the_value_and_the_valid_set() { #[test] fn a_config_with_no_sandbox_object_is_the_local_backend() { // The contract with every config.json already on disk: saying nothing means - // loopback, exactly as before. + // loopback. let cfg = load_raw("{\n \"repo_name\": \"aur\"\n}\n").unwrap(); assert!(matches!(cfg.sandbox, aur_build::config::Sandbox::Loopback)); assert_eq!(cfg.repo_name, "aur", "the rest of the config is untouched"); @@ -252,10 +233,8 @@ fn a_config_with_no_sandbox_object_is_the_local_backend() { assert!(cfg.sandbox.shared_workspace(), "loopback shares the filesystem by construction"); } -/// The file an older `aur-build init` wrote, verbatim. It carries the retired -/// keys, but they say `loopback` and three empty strings — which is what the -/// default already means — so it must still load rather than strand a working -/// local deployment on a syntax change. +/// The file an older `aur-build init` wrote, verbatim. It carries the retired keys, +/// but they say what the default already means, so it must still load. #[test] fn a_config_init_wrote_before_the_enum_still_loads() { let cfg = load_raw( @@ -290,9 +269,8 @@ fn a_config_init_wrote_before_the_enum_still_loads() { assert_eq!(cfg.lease_secs, 90); } -/// …but retired keys that *would* have changed behaviour are refused, not -/// quietly reinterpreted. A retired `"remote"` becoming loopback is the exact -/// silent substitution the enum was introduced to make impossible. +/// …but retired keys that *would* have changed behaviour are refused, not quietly +/// reinterpreted. #[test] fn retired_sandbox_keys_that_mean_something_are_refused() { let err = load_raw(r#"{ "sandbox_backend": "remote", "agent_listen": "0.0.0.0:1", "agent_token": "t" }"#) @@ -323,11 +301,9 @@ fn the_rendezvous_secrets_never_reach_debug() { assert!(shown.contains("builds"), "the non-secret fields are still visible: {shown}"); } -// --------------------------------------------------------------------------- -// The startup guard. The enum makes the impossible unrepresentable; this -// refuses what a type cannot see — a field present but empty, and a remote -// backend that was never told the workspace is shared. -// --------------------------------------------------------------------------- +// The startup guard: the enum makes the impossible unrepresentable, this refuses +// what a type cannot see — a field present but empty, and a remote backend that +// was never told the workspace is shared. /// A config that parses but cannot work must be refused by `validate`, not /// discovered at the step that needed the thing it is missing. @@ -362,10 +338,8 @@ fn a_field_that_is_present_but_empty_is_refused() { } } -/// The workspace gap, made impossible to hit by accident. The build workspace -/// is not shipped to a remote sandbox, so "remote" without this assertion would -/// silently build on the hub — the exact substitution this whole enum exists to -/// prevent, one layer down. +/// The workspace gap: the build workspace is not shipped to a remote sandbox, so +/// "remote" without this assertion would silently build on the hub. #[test] fn a_remote_backend_must_assert_the_shared_workspace() { let cfg = load_sandbox(r#"{"kind":"remote","listen":"127.0.0.1:1","token":"t"}"#).unwrap(); -- cgit v1.2.3