[pr-fix][startup] config: an empty path in darner.toml means unset, not the working directory #383

Open
qnjk wants to merge 2 commits from qnjk/Darner:config-empty-path into main
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: the environment values are filtered so that an empty value means unset (let env_path = |k: &str| env(k).filter(|v| !v.is_empty()).map(PathBuf::from);, crates/darner-core/src/config.rs:100) and so is physical_pages_dir from the file (with a test pinning it, config.rs:352), but the other file fields are not:

    let cache_dir = env_path("DARNER_CACHE_DIR")
        .or(file.cache_dir)
        .map_or_else(|| default_dir("cache"), Ok)?;
    

    (config.rs:107-109, the same at :110-112 for data_dir and :128 for game_dir). So [paths] cache_dir = '' yields PathBuf::from(""). The empty path is not "the default": subdir/checked_dir join the sub-name onto it, and Path::new("").join("shaders") is the relative path shaders, so every cache write happens in whatever directory darner was started from. On the binary built from f3840d7, in a folder whose whole darner.toml is

    [paths]
    cache_dir = ''
    data_dir = ''
    

    darner config exits with Error: data_dir () must not be the cache_dir () or inside it: the cache may be deleted at any time — both are the empty path, so the guard sees one inside itself and darner refuses to start at all. With only cache_dir = '' the same binary prints cache_dir : (empty) where a run without darner.toml prints C:\Users\<user>\AppData\Local\darner\cache, and darner translate --warm creates shaders\ beside the config file. The same held for data_dir, game_dir and an empty entry in test_titles.

  • This change filters every file path the way the environment and physical_pages_dir already were, through one file_path helper, and drops empty test_titles entries. A path that is not empty behaves exactly as before.

How it was tested

  • Tested revision: 357250a (two commits on f3840d7: the fix, and the new test bringing its own user directories so that it still holds once #315 lands — see "Checked for overlap").
  • Commands and results:
    • cargo test --locked -p darner-core — 32 passed, 0 failed.
    • With #315 (121ae5c) merged in, the Config::resolve hunk resolved the way its author wrote it in the thread, cargo test --locked -p darner-core --lib gives 35 passed, 0 failed (32 from this branch plus the 3 #315 adds) and cargo clippy -p darner-core --all-targets -- -D warnings is clean. The merge commit is not on this branch.
    • The new test config::tests::an_empty_path_in_the_file_means_unset was also run with only the three .or_else(|| file_path(..)) changed back to .or(..): it fails there and passes with the change, so it pins the defect rather than the new code.
    • On the binary built from this branch, the same scratch folder with the same darner.toml prints the default cache_dir/data_dir under %LOCALAPPDATA%\darner and no error, instead of the empty paths and Error: data_dir () must not be the cache_dir (). Both runs are darner config, which needs no title and no GPU.
    • cargo clippy --locked -p darner-core --all-targets -- -D warnings passes.
  • Changes a default: no. A config file with real paths resolves as before; only an empty value changes, and it now means "unset" as an empty environment variable and an empty physical_pages_dir already did.
  • A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim.
  • 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 --workspace --locked: not green on this machine, and not because of this change. Three pre-existing failures, each covered by an open pull request: darner-gpu stands still in parallel on the test deadlock #224 describes, and serially it finishes 1772 passed and 1 failed (pipeline::make::tests::a_capped_draw_waits_once_then_drops, which passes on its own) beside the order-dependent watch::tests::ask_once_by_res_splits_reservations_without_refusals and texture::ahead::tests::drain_waits_until_then_callbacks_have_run flakes that #150 is about; darner-shader fails emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes. Every other crate passes. darner-core's suite is green.
  • Gameplay, when relevant: no gameplay run. This is configuration resolution; the check was done with darner config on the built binary, which resolves the same paths a run would.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: only the three path fields and test_titles were exercised; no run was started from a folder with a real darner.toml and an empty data_dir to see where saves go.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay. The change is in config resolution; it was verified on the built binary's darner config (empty paths become the defaults) and by a unit test that fails on main.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 555 files ok.)
  • 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: #315 changes the same three lines of crates/darner-core/src/config.rs (default_dir(sub) becomes default_dir(sub, &env)); the resolution keeps both sides, and this branchs test now injects the user directories it needs, so nothing has to change on either side when they meet — verified by merging 121ae5chere (35 passed). #326 touches the same file in its unused-helper cleanup. No open or closed issue mentions an empty path indarner.toml`.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: the environment values are filtered so that an empty value means unset (`let env_path = |k: &str| env(k).filter(|v| !v.is_empty()).map(PathBuf::from);`, `crates/darner-core/src/config.rs:100`) and so is `physical_pages_dir` from the file (with a test pinning it, `config.rs:352`), but the other file fields are not: ```rust let cache_dir = env_path("DARNER_CACHE_DIR") .or(file.cache_dir) .map_or_else(|| default_dir("cache"), Ok)?; ``` (`config.rs:107-109`, the same at `:110-112` for `data_dir` and `:128` for `game_dir`). So `[paths] cache_dir = ''` yields `PathBuf::from("")`. The empty path is not "the default": `subdir`/`checked_dir` join the sub-name onto it, and `Path::new("").join("shaders")` is the relative path `shaders`, so every cache write happens in whatever directory darner was started from. On the binary built from `f3840d7`, in a folder whose whole `darner.toml` is ```toml [paths] cache_dir = '' data_dir = '' ``` `darner config` exits with `Error: data_dir () must not be the cache_dir () or inside it: the cache may be deleted at any time` — both are the empty path, so the guard sees one inside itself and darner refuses to start at all. With only `cache_dir = ''` the same binary prints `cache_dir : ` (empty) where a run without `darner.toml` prints `C:\Users\<user>\AppData\Local\darner\cache`, and `darner translate --warm` creates `shaders\` beside the config file. The same held for `data_dir`, `game_dir` and an empty entry in `test_titles`. - This change filters every file path the way the environment and `physical_pages_dir` already were, through one `file_path` helper, and drops empty `test_titles` entries. A path that is not empty behaves exactly as before. ## How it was tested - Tested revision: `357250a` (two commits on `f3840d7`: the fix, and the new test bringing its own user directories so that it still holds once #315 lands — see "Checked for overlap"). - Commands and results: - cargo test --locked -p darner-core — 32 passed, 0 failed. - With #315 (121ae5c) merged in, the Config::resolve hunk resolved the way its author wrote it in the thread, cargo test --locked -p darner-core --lib gives 35 passed, 0 failed (32 from this branch plus the 3 #315 adds) and cargo clippy -p darner-core --all-targets -- -D warnings is clean. The merge commit is not on this branch. - The new test `config::tests::an_empty_path_in_the_file_means_unset` was also run with only the three `.or_else(|| file_path(..))` changed back to `.or(..)`: it fails there and passes with the change, so it pins the defect rather than the new code. - On the binary built from this branch, the same scratch folder with the same `darner.toml` prints the default `cache_dir`/`data_dir` under `%LOCALAPPDATA%\darner` and no error, instead of the empty paths and `Error: data_dir () must not be the cache_dir ()`. Both runs are `darner config`, which needs no title and no GPU. - `cargo clippy --locked -p darner-core --all-targets -- -D warnings` passes. - Changes a default: no. A config file with real paths resolves as before; only an empty value changes, and it now means "unset" as an empty environment variable and an empty `physical_pages_dir` already did. - A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim. - 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 --workspace --locked`: **not green on this machine, and not because of this change.** Three pre-existing failures, each covered by an open pull request: `darner-gpu` stands still in parallel on the test deadlock #224 describes, and serially it finishes 1772 passed and 1 failed (`pipeline::make::tests::a_capped_draw_waits_once_then_drops`, which passes on its own) beside the order-dependent `watch::tests::ask_once_by_res_splits_reservations_without_refusals` and `texture::ahead::tests::drain_waits_until_then_callbacks_have_run` flakes that #150 is about; `darner-shader` fails `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, whose fixture #227 fixes. Every other crate passes. `darner-core`'s suite is green. - Gameplay, when relevant: no gameplay run. This is configuration resolution; the check was done with `darner config` on the built binary, which resolves the same paths a run would. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: only the three path fields and `test_titles` were exercised; no run was started from a folder with a real `darner.toml` and an empty `data_dir` to see where saves go. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay. The change is in config resolution; it was verified on the built binary's `darner config` (empty paths become the defaults) and by a unit test that fails on `main`. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 555 files ok.) - [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: #315 changes the same three lines of `crates/darner-core/src/config.rs` (`default_dir(sub)` becomes `default_dir(sub, &env)`); the resolution keeps both sides, and this branch`s test now injects the user directories it needs, so nothing has to change on either side when they meet — verified by merging `121ae5c` here (35 passed). #326 touches the same file in its unused-helper cleanup. No open or closed issue mentions an empty path in `darner.toml`. - Replaces or overlaps: none found
The environment values are filtered so that empty means unset, and so is
`physical_pages_dir` from the file, but the other file fields are not:
`[paths] cache_dir = ''` became `PathBuf::from("")`. That is not "the
default": `subdir`/`checked_dir` join onto it, and `Path::new("").join("shaders")`
is the relative path `shaders`, so every cache write landed in whatever
folder darner was started from instead of under `%LOCALAPPDATA%\darner`
(it was reproduced with `darner config` and `darner translate --warm` in
a scratch folder). The same held for `data_dir`, `game_dir` and an empty
entry of `test_titles`.

All the file paths are now filtered the way the environment and
`physical_pages_dir` already were. A path that is not empty behaves as
before.
First-time contributor

Heads-up on the overlap with #315 (mine), checked on Windows (Rust 1.98.1, x86_64-pc-windows-msvc): the two pull requests are each green on their own, but they don't combine cleanly, in two ways.

  1. Text conflict in Config::resolve (crates/darner-core/src/config.rs, the cache_dir/data_dir/physical_pages_dir lines): #315 changes default_dir("cache") to default_dir("cache", &env) on the same lines where this one changes .or(file.cache_dir) to .or_else(|| file_path(file.cache_dir)). git merge-tree of 121ae5c and 7081f4e stops there. The resolution keeps both:

    let cache_dir = env_path("DARNER_CACHE_DIR")
        .or_else(|| file_path(file.cache_dir))
        .map_or_else(|| default_dir("cache", &env), Ok)?;
    
  2. A test that fails once both are in. #315 makes default_dir read LOCALAPPDATA/XDG_CACHE_HOME/HOME through the injected env instead of the process environment. So an_empty_path_in_the_file_means_unset, which resolves with |_| None, finds no user directory. With the conflict resolved as above, cargo test --locked -p darner-core --lib config gives 21 passed, 1 failed:

    called `Result::unwrap()` on an `Err` value: cannot determine a user directory; set DARNER_CACHE_DIR and DARNER_DATA_DIR
    

    Giving the test a LOCALAPPDATA, as the #315 tests do, makes it 22 passed, 0 failed, and it still checks the same thing:

    Config::resolve(file.paths, None, |k| (k == "LOCALAPPDATA").then(|| OsString::from("appdata"))).unwrap()
    

Whichever of the two lands second needs both changes. If this one lands first, I'll rebase #315 and fix the test there.

Heads-up on the overlap with #315 (mine), checked on Windows (Rust 1.98.1, `x86_64-pc-windows-msvc`): the two pull requests are each green on their own, but they don't combine cleanly, in two ways. 1. **Text conflict** in `Config::resolve` (`crates/darner-core/src/config.rs`, the `cache_dir`/`data_dir`/`physical_pages_dir` lines): #315 changes `default_dir("cache")` to `default_dir("cache", &env)` on the same lines where this one changes `.or(file.cache_dir)` to `.or_else(|| file_path(file.cache_dir))`. `git merge-tree` of `121ae5c` and `7081f4e` stops there. The resolution keeps both: ```rust let cache_dir = env_path("DARNER_CACHE_DIR") .or_else(|| file_path(file.cache_dir)) .map_or_else(|| default_dir("cache", &env), Ok)?; ``` 2. **A test that fails once both are in.** #315 makes `default_dir` read `LOCALAPPDATA`/`XDG_CACHE_HOME`/`HOME` through the injected `env` instead of the process environment. So `an_empty_path_in_the_file_means_unset`, which resolves with `|_| None`, finds no user directory. With the conflict resolved as above, `cargo test --locked -p darner-core --lib config` gives 21 passed, 1 failed: ``` called `Result::unwrap()` on an `Err` value: cannot determine a user directory; set DARNER_CACHE_DIR and DARNER_DATA_DIR ``` Giving the test a `LOCALAPPDATA`, as the #315 tests do, makes it 22 passed, 0 failed, and it still checks the same thing: ```rust Config::resolve(file.paths, None, |k| (k == "LOCALAPPDATA").then(|| OsString::from("appdata"))).unwrap() ``` Whichever of the two lands second needs both changes. If this one lands first, I'll rebase #315 and fix the test there.
#315 makes `default_dir` read the environment through the injected closure
instead of the process's environment, so a test that resolves with
`|_| None` cannot find a user directory once both changes are in: together
they failed `an_empty_path_in_the_file_means_unset` with "cannot determine
a user directory; set DARNER_CACHE_DIR and DARNER_DATA_DIR".

The test now answers LOCALAPPDATA, XDG_CACHE_HOME and HOME through the
closure. That changes nothing while `default_dir` reads the process's
environment (it ignores the closure), and keeps the test about the empty
path once it does not, so whichever of the two lands second needs only the
three-line `default_dir("cache", &env)` conflict resolution.
Author
First-time contributor

Thanks — both points check out, and I have taken the second one off the table.

an_empty_path_in_the_file_means_unset now answers LOCALAPPDATA/XDG_CACHE_HOME/HOME through the injected closure (357250a on this branch). That is a no-op while default_dir reads the process's environment — it ignores the closure, as it still does on main — and it is exactly what the test needs once #315's default_dir(sub, &env) is in, so no test edit is left for whichever side lands second.

I also ran the combination here rather than trusting the numbers. 121ae5c merged into 357250a, the Config::resolve hunk resolved exactly as you wrote it, on Windows 11, Rust 1.98.1, x86_64-pc-windows-msvc:

cargo test --locked -p darner-core --lib                          ->  test result: ok. 35 passed; 0 failed
cargo clippy --locked -p darner-core --all-targets -- -D warnings ->  clean

35 is this branch's 32 plus the 3 tests #315 adds; the merge commit itself is not pushed onto this PR. So the whole of the combination is the three-line resolution you gave — no dependency in either direction.

If you would rather land #315 first, ping me and I will rebase this branch on it and re-run the same two commands; the diff of this PR would then be only the file_path filtering.

Thanks — both points check out, and I have taken the second one off the table. `an_empty_path_in_the_file_means_unset` now answers `LOCALAPPDATA`/`XDG_CACHE_HOME`/`HOME` through the injected closure (`357250a` on this branch). That is a no-op while `default_dir` reads the process's environment — it ignores the closure, as it still does on `main` — and it is exactly what the test needs once #315's `default_dir(sub, &env)` is in, so no test edit is left for whichever side lands second. I also ran the combination here rather than trusting the numbers. `121ae5c` merged into `357250a`, the `Config::resolve` hunk resolved exactly as you wrote it, on Windows 11, Rust 1.98.1, `x86_64-pc-windows-msvc`: ``` cargo test --locked -p darner-core --lib -> test result: ok. 35 passed; 0 failed cargo clippy --locked -p darner-core --all-targets -- -D warnings -> clean ``` 35 is this branch's 32 plus the 3 tests #315 adds; the merge commit itself is not pushed onto this PR. So the whole of the combination is the three-line resolution you gave — no dependency in either direction. If you would rather land #315 first, ping me and I will rebase this branch on it and re-run the same two commands; the diff of this PR would then be only the `file_path` filtering.
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-empty-path:qnjk-config-empty-path'
git switch 'qnjk-config-empty-path'

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-empty-path'
git switch 'qnjk-config-empty-path'
git rebase 'main'
git switch 'main'
git merge --ff-only 'qnjk-config-empty-path'
git switch 'qnjk-config-empty-path'
git rebase 'main'
git switch 'main'
git merge --no-ff 'qnjk-config-empty-path'
git switch 'main'
git merge --squash 'qnjk-config-empty-path'
git switch 'main'
git merge --ff-only 'qnjk-config-empty-path'
git switch 'main'
git merge 'qnjk-config-empty-path'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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!383
No description provided.