test: complete configuration layer matrix

This commit is contained in:
Dandaedre 2026-09-29 13:33:20 +02:00
parent 7bb9781064
commit 43ede9c717
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
11 changed files with 190 additions and 12 deletions

View File

@ -1,8 +1,8 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 114
coverage = 72.32
lines_parsed = 130
coverage = 73.13
[last_run_clean.run_duration]
secs = 10
nanos = 643158348
secs = 12
nanos = 427354221

View File

@ -252,3 +252,8 @@ never include unrelated or pre-existing user changes. Use a concise conventional
commit message that describes the completed behavior. If a task cannot be
verified or committed, leave it unchecked and report the blocker instead of
combining it with later work.
After every milestone's acceptance criteria and quality gates pass, create an
annotated Git tag named `milestone-N` on its completion commit. Never move an
existing milestone tag; add a corrective commit and a documented successor tag
if a published milestone needs amendment.

View File

@ -32,6 +32,7 @@ signals, not the probability that AI wrote the content.
- [Documentation index](docs/README.md)
- [Command-line usage and current capabilities](docs/usage.md)
- [Architecture and public library API](docs/architecture.md)
- [Layered configuration](docs/configuration.md)
- [Development, tests, features, and coverage](docs/development.md)
- [Design decision records](docs/decisions/)
- [Background reading](docs/background.md)

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 72%"><title>test-coverage: 72%</title><linearGradient id="bms-fd246ae864179eba" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-fd246ae864179eba"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-fd246ae864179eba)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-fd246ae864179eba)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">72%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">72%</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 73%"><title>test-coverage: 73%</title><linearGradient id="bms-8d6cd37f67f8e99e" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-8d6cd37f67f8e99e"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-8d6cd37f67f8e99e)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-8d6cd37f67f8e99e)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">73%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">73%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -7,6 +7,8 @@ the details needed to use, embed, and develop John Slop:
and the current formatter/LSP status.
- [Architecture](architecture.md) describes module boundaries, shared domain
values, input safety, and the reusable library facade.
- [Configuration](configuration.md) documents schema version 1, source
precedence, stable-ID merges, validation, and inspection commands.
- [Development](development.md) covers the supported Rust version, feature
matrix, snapshots, coverage, badges, and CI quality gates.
- [Background](background.md) collects external context on observable signs of

View File

@ -35,9 +35,10 @@ The crate root exposes four entry points:
- `analyze_source` returns findings and evidence confidence for UTF-8 text;
- `plan_replacements` returns safe edits against the same source snapshot.
Configuration files and precedence layers are a later milestone. Keeping these
operations behind the facade lets those layers evolve without duplicating logic
across the three binaries.
`ConfigLoader` applies embedded, user base, named user, explicit file, and CLI
layers in order. Stable-ID merging and semantic validation happen before a
configuration reaches analysis. Keeping these operations behind the facade
avoids duplicating policy across the three binaries.
See [ADR 0001](decisions/0001-core-analysis-contracts.md) for the foundational
contracts and [ADR 0002](decisions/0002-input-policy-and-limits.md) for traversal

65
docs/configuration.md Normal file
View File

@ -0,0 +1,65 @@
# Configuration
John Slop embeds schema-versioned replacement and heuristic catalogs in every
binary. Installed binaries therefore work without a source checkout or external
default files.
## Precedence
Configuration layers are applied from lowest to highest priority:
1. embedded `assets/config.toml` and `assets/heuristics.toml`;
2. the platform user file `config.toml`;
3. a selected user `<config_name>.toml`;
4. an explicit `--config <FILE>`;
5. configuration flags for the current invocation.
On Linux, the user directory conventionally resolves to
`~/.config/john_slop`. John Slop uses operating-system APIs rather than reading
`HOME` directly, so Windows and macOS receive their native application config
directories. Run this to inspect the exact paths on the current machine:
```sh
john-slop config paths
```
Named configurations accept only ASCII letters, digits, `_`, and `-`. Do not
include a directory, dot component, or `.toml` extension. Missing user and named
files are optional; a selected explicit file must exist.
## Schema
The current `schema_version` is `1`. The complete defaults and documented record
examples live in [`assets/config.toml`](../assets/config.toml) and
[`assets/heuristics.toml`](../assets/heuristics.toml).
Replacement and heuristic arrays merge by stable `id`. A partial record changes
only the supplied fields:
```toml
[[replacements]]
id = "em-dash"
enabled = false
[[rules]]
id = "templated-conclusion"
weight = 2.5
```
A new ID must provide every field. Scope extension arrays replace the prior
array as a whole. Unknown keys, malformed TOML, duplicate IDs within one layer,
invalid regular expressions, unsafe matchers, non-ASCII replacement targets,
and invalid thresholds are fatal configuration diagnostics.
## Inspection
Print the fully layered and validated model as deterministic TOML:
```sh
john-slop config show
john-slop config show --config project.toml
john-slop config show --config-name strict
```
The output contains no secrets in schema version 1. If secret-bearing fields are
introduced later, inspection output must redact them by default.

View File

@ -36,8 +36,8 @@ Run line coverage with Cargo Tarpaulin:
cargo tarpaulin --config tarpaulin.toml
```
The configuration enforces a 30% floor. The current suite measured 72.32%
(196/271 lines) on 2026-09-29. The low floor is intentional while CLI
The configuration enforces a 30% floor. The current suite measured 73.13%
(430/588 lines) on 2026-09-29. The low floor is intentional while CLI
subprocesses and future protocol adapters are not attributed consistently by
every backend; the tracked badge still reports the measured result.
@ -58,3 +58,6 @@ change crosses a binary boundary. Important edge cases include malformed input,
invalid UTF-8, empty text, Unicode byte spans, deterministic ordering, archive
limits, and near misses for detection rules. The detailed expectations and
task-level commit discipline are in [AGENTS.md](../AGENTS.md).
Each completed milestone receives an immutable annotated `milestone-N` Git tag
after its acceptance criteria and quality gates pass.

View File

@ -27,6 +27,12 @@ Exit statuses are stable:
Confidence is a summary of observable configured evidence. It is not an
AI-authorship probability.
Configuration layers can be selected with `--config-name NAME` and `--config
FILE`; `--max-document-bytes BYTES` is the current highest-precedence input
override. Use `john-slop config show` to print the resolved TOML and `john-slop
config paths` to inspect source precedence. See [Configuration](configuration.md)
for the schema and merge rules.
## Supported input policy
Input reads use strict UTF-8 and reject NUL-containing text. They do not follow

View File

@ -1163,6 +1163,13 @@ mod tests {
id = "em-dash"
enabled = false
[[replacements]]
id = "right-arrow"
source = "→"
replacement = "->"
rationale = "Use an ASCII arrow in plain text."
enabled = true
[[rules]]
id = "templated-conclusion"
weight = 9.5
@ -1173,7 +1180,7 @@ weight = 9.5
let config = ConfigLoader::from_paths(paths).load().unwrap();
assert_eq!(config.replacements.len(), 10);
assert_eq!(config.replacements.len(), 11);
let replacement = config
.replacements
.iter()
@ -1182,6 +1189,7 @@ weight = 9.5
assert!(!replacement.enabled);
assert_eq!(replacement.source, '—');
assert_eq!(replacement.replacement, "-");
assert_eq!(config.replacements.last().unwrap().id, "right-arrow");
assert_eq!(config.rules.len(), 6);
let heuristic = config
.rules
@ -1258,4 +1266,91 @@ weight = 9.5
"john_slop::config::invalid_value"
);
}
#[test]
fn each_file_layer_can_override_embedded_defaults_independently() {
let base_dir = tempfile::tempdir().unwrap();
std::fs::write(
base_dir.path().join("config.toml"),
"[thresholds]\nlow = 21\n",
)
.unwrap();
let base = ConfigLoader::from_paths(ConfigPaths::in_directory(
base_dir.path().to_owned(),
None,
None,
))
.load()
.unwrap();
assert_eq!(base.thresholds.low, 21);
let named_dir = tempfile::tempdir().unwrap();
std::fs::write(
named_dir.path().join("strict.toml"),
"[thresholds]\nlow = 22\n",
)
.unwrap();
let name = "strict".parse::<ConfigName>().unwrap();
let named = ConfigLoader::from_paths(ConfigPaths::in_directory(
named_dir.path().to_owned(),
Some(&name),
None,
))
.load()
.unwrap();
assert_eq!(named.thresholds.low, 22);
let explicit_dir = tempfile::tempdir().unwrap();
let explicit_path = explicit_dir.path().join("project.toml");
std::fs::write(&explicit_path, "[thresholds]\nlow = 23\n").unwrap();
let explicit = ConfigLoader::from_paths(ConfigPaths::in_directory(
explicit_dir.path().to_owned(),
None,
Some(explicit_path),
))
.load()
.unwrap();
assert_eq!(explicit.thresholds.low, 23);
}
#[test]
fn named_layers_apply_only_when_selected() {
let directory = tempfile::tempdir().unwrap();
std::fs::write(
directory.path().join("strict.toml"),
"[thresholds]\nlow = 25\n",
)
.unwrap();
let unselected = ConfigLoader::from_paths(ConfigPaths::in_directory(
directory.path().to_owned(),
None,
None,
))
.load()
.unwrap();
let name = "strict".parse::<ConfigName>().unwrap();
let selected = ConfigLoader::from_paths(ConfigPaths::in_directory(
directory.path().to_owned(),
Some(&name),
None,
))
.load()
.unwrap();
assert_eq!(unselected.thresholds.low, 20);
assert_eq!(selected.thresholds.low, 25);
}
#[test]
fn malformed_toml_is_a_fatal_layer_error() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("config.toml");
std::fs::write(&path, "[input\nmax_document_bytes = 12\n").unwrap();
let paths = ConfigPaths::in_directory(directory.path().to_owned(), None, None);
let error = ConfigLoader::from_paths(paths).load().unwrap_err();
assert!(matches!(error, ConfigError::Layer(layer) if layer.path == path));
}
}

View File

@ -99,7 +99,7 @@ entry do not discard successful documents.
a `miette` configuration diagnostic.
- [x] Add `john-slop config show` and `john-slop config paths` so precedence is
inspectable; output deterministic TOML or JSON.
- [ ] Test every layer alone and in combination, including missing optional files,
- [x] Test every layer alone and in combination, including missing optional files,
malformed TOML, unknown fields, named configs, array semantics, and CLI wins.
Acceptance: installed binaries work without source-tree assets, the resolved