Skip to content

Expand ~ and $VAR in config paths#461

Closed
onurogut wants to merge 1 commit intoosa1:masterfrom
onurogut:expand-config-paths
Closed

Expand ~ and $VAR in config paths#461
onurogut wants to merge 1 commit intoosa1:masterfrom
onurogut:expand-config-paths

Conversation

@onurogut
Copy link
Contributor

Summary

  • Add tilde (~) and environment variable ($VAR) expansion for log_dir and SASL external pem paths in config
  • Use shellexpand crate to resolve paths like ~/tiny_logs or $HOME/logs during config parsing
  • Expansion happens in parse_config after deserialization, before the config is used by the rest of the application
  • On expansion failure (e.g. undefined variable), prints a warning and falls back to the original path
  • Add shellexpand as a new dependency for path expansion
  • Add 5 tests: 3 unit tests for expand_path function, 2 integration tests verifying parse_config expands log_dir
    and sasl pem paths end-to-end

Fixes #192, fixes #429

Test plan

  • cargo test -p tiny — 15 tests pass (10 existing + 5 new)
  • cargo build — builds successfully

Use shellexpand to resolve tilde and environment variables in
log_dir and SASL external PEM paths during config parsing.

Add shellexpand as a new dependency for tilde (~) and
environment variable ($VAR) expansion in file paths.

Add tests for path expansion, log_dir and sasl pem integration.

Fixes osa1#192, fixes osa1#429
Copy link
Owner

@osa1 osa1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right that this is vibe-coded?

I know we don't have a policy in this repo for vibe-coded patches yet, but for now you should (1) review every line yourself and make sure you understand every line and design decision (2) declare that the PR is vibe-coded so that I know how detailed I should give feedback. (I'm not keen on talking to an LLM in a GitHub comments section and micro-managing it in GitHub comments)

Ok(expanded) => PathBuf::from(expanded.as_ref()),
Err(err) => {
println!("Failed to expand path {path:?}: {err}");
path.to_owned()
Copy link
Owner

@osa1 osa1 Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When expand_path fails to expand a variable we can't continue, we should show the error to the user and stop.

parse_config should return all errors, including IO errors (which we don't return currently, but we should) + path expansion errors. The call site (main) already deals with errors (prints them and exits).

PathBuf::from(format!("{home}/test_logs"))
);

let _ = fs::remove_dir_all(&dir);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to create a file to test config file parsing and shell expansion. Refactor the code to separate the IO parts (the let contents = { ... } part in parse_config) from parsing parts, then test the parsing function.

@onurogut
Copy link
Contributor Author

Sorry for the additional review round.

Yes, I used Claude Code to speed up the implementation, but I reviewed the code myself before submitting it. That said, I didn’t examine the AI-generated output carefully enough, particularly in terms of error handling and test design. The silent fallback on expansion failure and the unnecessary file I/O in the tests are issues I should have caught earlier.

I will fix both:

Make expand_path return an error instead of silently falling back, and ensure parse_config propagates all relevant errors, including I/O and path expansion errors.

Separate I/O from parsing so tests can call the parsing function directly.

Going forward, I will clearly declare AI assistance upfront and apply a more thorough review before submitting changes.

@osa1
Copy link
Owner

osa1 commented Feb 23, 2026

Feel free to reopen when you have an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow SASL_EXTERNAL to be a multiline string or a path Implement tilde extension for log_dir config field

2 participants