Skip to content

feat(config): resolve relative paths based on config file parent directory#166

Merged
fohte merged 4 commits intomainfrom
fohte/impl-runok-path-resolution-all
Mar 8, 2026
Merged

feat(config): resolve relative paths based on config file parent directory#166
fohte merged 4 commits intomainfrom
fohte/impl-runok-path-resolution-all

Conversation

@fohte
Copy link
Owner

@fohte fohte commented Mar 7, 2026

Why

  • Relative paths in config files (definitions.paths, definitions.sandbox fs.writable/fs.deny) are resolved based on cwd, causing different paths to be referenced depending on where the command is executed
    • Similar to ESLint and TypeScript, resolve paths relative to the config file's parent directory to guarantee consistent results regardless of cwd

What

  • Resolve relative paths in config files based on the config file's parent directory
    • Paths are classified into three types: absolute paths (/) are used as-is, home directory paths (~/) are expanded with $HOME, and relative paths are joined with the config file's parent directory
    • Path resolution happens before merging, so global and project configs each use their own base directory
    • Paths in presets loaded via extends are also resolved relative to the preset file's parent directory
  • Consolidate expand_tilde() from command_executor.rs into the path_resolver module

Open with Devin

fohte and others added 2 commits March 7, 2026 16:03
…cation

Relative paths in `definitions.paths` and `definitions.sandbox`
(fs.writable, fs.deny) were used as-is, causing different results
depending on the working directory when running `runok exec`.

Following the convention of ESLint, TypeScript, and other tools,
relative paths are now resolved against the parent directory of
the configuration file that defines them. Each config file's paths
are resolved before merging, so global and local configs use their
respective base directories. Preset files loaded via `extends` also
resolve paths relative to the preset file's location.

- Add `path_resolver` module with `resolve_path()` and
  `resolve_config_paths()` for path classification and resolution
- Integrate path resolution into `ConfigLoader` (before merge) and
  `load_local_preset` / `load_preset_with` (for extends)
- Move `expand_tilde()` from `command_executor` to `path_resolver`
  to consolidate path handling logic
- Add integration tests verifying consistent results across different
  cwd values

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Clippy denies `unwrap_used`, `expect_used`, and `panic` in this
project. The path_resolution integration tests used `unwrap_or_else`
with `panic!` in the fixture, which triggered `clippy::panic`.

Replace the `#[fixture]` with a `make_env()` helper returning `Result`,
and convert all test functions to return `Result<(), Box<dyn Error>>`
with `?` operator. This eliminates all `unwrap()`, `expect()`, and
`panic!()` calls from the test module.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 90.72165% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.55%. Comparing base (a49f916) to head (072c5b7).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/config/path_resolver.rs 91.81% 14 Missing ⚠️
src/config/preset.rs 42.85% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #166      +/-   ##
==========================================
+ Coverage   89.44%   89.55%   +0.11%     
==========================================
  Files          37       38       +1     
  Lines        6981     7154     +173     
==========================================
+ Hits         6244     6407     +163     
- Misses        737      747      +10     
Flag Coverage Δ
Linux 89.42% <90.72%> (+0.11%) ⬆️
macOS 91.28% <90.72%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the reliability and predictability of path handling within configuration files. By shifting the base for relative path resolution from the current working directory to the configuration file's parent directory, it eliminates a source of inconsistent behavior. This change, along with the introduction of a dedicated path resolution module, ensures that all configured paths, including those in sandbox policies and extended presets, are interpreted consistently across different execution environments.

Highlights

  • Consistent Path Resolution: Relative paths in configuration files (e.g., definitions.paths, definitions.sandbox.fs.writable, definitions.sandbox.fs.deny) are now resolved relative to the parent directory of the config file itself, ensuring consistent behavior regardless of the current working directory.
  • Path Classification: Paths are classified into three types: absolute paths (used as-is), home directory paths (~/ expanded with $HOME), and relative paths (joined with the config file's parent directory).
  • Pre-Merge Resolution: Path resolution occurs before configuration merging, allowing global and project-specific configurations to use their respective base directories for path resolution.
  • Preset Path Handling: Paths within presets loaded via extends are also resolved relative to the preset file's parent directory.
  • Code Consolidation: The expand_tilde() utility function has been moved and consolidated into a new path_resolver module within the config crate.
Changelog
  • docs/src/content/docs/configuration/file-discovery.md
    • Added a new section detailing the new path resolution rules for configuration files, including path types and resolution examples.
  • src/config/loader.rs
    • Renamed find_and_parse to find_parse_and_resolve and integrated path resolution for config files based on their parent directory before merging.
    • Updated the load function to use the new find_parse_and_resolve for global and local configurations.
  • src/config/mod.rs
    • Introduced and exposed the new path_resolver module, making its functions like expand_tilde, resolve_config_paths, and resolve_path publicly available.
  • src/config/path_resolver.rs
    • Added a new module containing the core logic for resolving paths based on their type (absolute, tilde-expanded, relative) against a given base directory.
    • Implemented normalize_logical for logical path normalization without filesystem access, preserving glob patterns.
    • Provided resolve_config_paths to apply path resolution to definitions.paths and definitions.sandbox entries within a Config struct.
  • src/config/preset.rs
    • Modified load_local_preset to resolve paths within the loaded preset relative to the preset file's parent directory.
    • Updated load_preset_with to apply path resolution to remote presets using their cache directory as the base.
  • src/exec/command_executor.rs
    • Updated calls to expand_tilde to reference the consolidated function in crate::config::path_resolver.
    • Removed the now-redundant local expand_tilde function.
  • tests/integration/main.rs
    • Registered the new path_resolution integration test module.
  • tests/integration/path_resolution.rs
    • Added comprehensive integration tests to verify that relative paths in config files, sandbox policies, and presets are correctly resolved relative to their respective config file's parent directory, independent of the current working directory.
Activity
  • A new path_resolver module was introduced to centralize path resolution logic.
  • Configuration loading mechanisms were updated to utilize the new path resolution, ensuring paths are resolved against the config file's parent directory before merging.
  • Documentation was updated to clearly explain the new path resolution behavior.
  • Existing expand_tilde functionality was refactored and moved to the new path_resolver module.
  • New integration tests were added to validate the consistency and correctness of the path resolution across various scenarios, including global, local, and preset configurations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

devin-ai-integration[bot]

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

This project's code comments should be in English per the repository
conventions. The path resolution feature was initially implemented
with Japanese comments across all new and modified files.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
`resolve_config_paths` treated `<path:name>` references (e.g.
`<path:sensitive>`) as relative paths and joined them with base_dir,
producing `/project/<path:sensitive>`. This broke the later
`expand_sandbox_path_refs()` step which uses `strip_prefix("<path:")`
to match these references.

Skip `<path:name>` references in the resolve loop. Also extract the
repeated resolve-and-replace logic into a `resolve_vec` closure, and
revert an unnecessary comment change in command_executor.rs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 5 additional findings in Devin Review.

Open in Devin Review

@fohte fohte merged commit ee1a7c3 into main Mar 8, 2026
9 checks passed
@fohte fohte deleted the fohte/impl-runok-path-resolution-all branch March 8, 2026 04:57
@fohte-bot fohte-bot bot mentioned this pull request Mar 8, 2026
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.

1 participant