core: pin that a darner.toml that does not parse is refused #636

Open
qnjk wants to merge 1 commit from qnjk/Darner:config-parse-failure-test into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: nothing. This is a tests-only change (no production line is edited).

  • What it pins: the parse branch of Config::load_from is the only branch with no test:

    let parsed: FileConfig = toml::from_str(&text)
        .with_context(|| format!("parsing {}", path.display()))?;   // config.rs:87-88
    

    That ? is the entire guarantee that a broken darner.toml cannot silently become the document defaults — a misspelt key, a wrong type or a bad string would otherwise change where every run looks and say nothing. Every other branch had a test (a missing default file, a missing explicit file, a directory at either path, both symlink paths, and the successful parse of darner.example.toml), but nothing ever fed load_from a file that fails to parse, so a unwrap_or_default() or a dropped #[serde(deny_unknown_fields)] would keep the whole module green.

  • This change adds one test that writes a temp darner.toml and loads it through Config::load_from.

How it was tested

  • Tested revision: 59b1686 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-core --lib — 51 passed, 0 failed.
    • New test config::tests::a_config_file_that_does_not_parse_is_refused: a file that is not TOML and a file with a wrongly typed field are both Err, and the message names the file it was reading; the existing "a missing default file is optional" behaviour is asserted beside it so the two halves are pinned together.
    • Fail-before, by mutating the loader to unwrap_or_default(): the new test fails, and every other test in the module stays green — which is the gap itself.
    • cargo clippy --locked -p darner-core --all-targets -- -D warnings passes.
  • Changes a default: no. Tests only.
  • A/B result: not applicable — tests-only change.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3: cargo test --locked -p darner-core --lib is green (51 passed); the whole-workspace run is not green on this machine for the pre-existing darner-gpu reasons (#224, #150), which this does not touch.
  • Gameplay, when relevant: not applicable — tests-only change.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: the test covers two parse failures (not TOML, wrong type); an unknown key is only covered if deny_unknown_fields is on, which this test does not assert specifically.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: tests-only change, stated at the top.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: passes).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #326 changes crates/darner-core/src/config.rs (unused-helper cleanup); this change only adds to the test module. No open or closed issue mentions a malformed darner.toml.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: nothing. This is a **tests-only** change (no production line is edited). - What it pins: the parse branch of `Config::load_from` is the only branch with no test: ```rust let parsed: FileConfig = toml::from_str(&text) .with_context(|| format!("parsing {}", path.display()))?; // config.rs:87-88 ``` That `?` is the entire guarantee that a broken `darner.toml` cannot silently become the document defaults — a misspelt key, a wrong type or a bad string would otherwise change where every run looks and say nothing. Every other branch had a test (a missing default file, a missing explicit file, a directory at either path, both symlink paths, and the successful parse of `darner.example.toml`), but nothing ever fed `load_from` a file that fails to parse, so a `unwrap_or_default()` or a dropped `#[serde(deny_unknown_fields)]` would keep the whole module green. - This change adds one test that writes a temp `darner.toml` and loads it through `Config::load_from`. ## How it was tested - Tested revision: `59b1686` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-core --lib` — 51 passed, 0 failed. - New test `config::tests::a_config_file_that_does_not_parse_is_refused`: a file that is not TOML and a file with a wrongly typed field are both `Err`, and the message names the file it was reading; the existing "a missing default file is optional" behaviour is asserted beside it so the two halves are pinned together. - Fail-before, by mutating the loader to `unwrap_or_default()`: the new test fails, and every other test in the module stays green — which is the gap itself. - `cargo clippy --locked -p darner-core --all-targets -- -D warnings` passes. - Changes a default: no. Tests only. - A/B result: not applicable — tests-only change. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3: `cargo test --locked -p darner-core --lib` is green (51 passed); the whole-workspace run is not green on this machine for the pre-existing `darner-gpu` reasons (#224, #150), which this does not touch. - Gameplay, when relevant: not applicable — tests-only change. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: the test covers two parse failures (not TOML, wrong type); an unknown key is only covered if `deny_unknown_fields` is on, which this test does not assert specifically. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: tests-only change, stated at the top. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: passes). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #326 changes `crates/darner-core/src/config.rs` (unused-helper cleanup); this change only adds to the test module. No open or closed issue mentions a malformed `darner.toml`. - Replaces or overlaps: none found
`Config::load_from` parses the file with `toml::from_str(...)?` and that `?`
is the whole guarantee that a broken `darner.toml` cannot silently become
the defaults: a misspelt key or a wrong type would otherwise change where
every run looks and say nothing. No test fed that branch a file that fails
to parse, so a future `unwrap_or_default()` or a dropped
`deny_unknown_fields` would keep the suite green while a user's `game_dir`
quietly stopped being read.

The test writes two broken files — an unclosed table header and
`cache_dir = 5` — and requires each load to be an error that names the
file; then it removes the file and checks the documented optional
behaviour of the default path. Swallowing the parse error, or dropping the
path from the context, makes it fail.
TrustNo1 changed title from [pr-tests] core: pin that a darner.toml that does not parse is refused to core: pin that a darner.toml that does not parse is refused 2026-12-06 03:25:46 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'config-parse-failure-test:qnjk-config-parse-failure-test'
git switch 'qnjk-config-parse-failure-test'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'qnjk-config-parse-failure-test'
git switch 'qnjk-config-parse-failure-test'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-config-parse-failure-test'
git switch 'qnjk-config-parse-failure-test'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-config-parse-failure-test'
git switch 'Main'
git merge --squash 'qnjk-config-parse-failure-test'
git switch 'Main'
git merge --ff-only 'qnjk-config-parse-failure-test'
git switch 'Main'
git merge 'qnjk-config-parse-failure-test'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!636
No description provided.