Commit 8ec9a2a
authored
* fix(git): preserve relative paths in git_submodule_add (closes #168)
git_submodule_add was writing ABSOLUTE filesystem paths into .gitmodules
and .git/config because the lean interface's generic "all *path*
parameters must be absolute" validation forced callers to pass absolute
paths, which then propagated verbatim to `git submodule add`. The
result was non-portable repos with entries like:
[submodule "/home/user/repo/sub-packages/remote-iface"]
path = /home/user/repo/sub-packages/remote-iface
Submodule paths are repo-relative by git's own convention (see
gitmodules(5)), so this commit introduces a per-tool exemption:
git_submodule_add's `path` parameter now bypasses the absolute-path
requirement while still rejecting `..` and path-traversal attempts.
After the fix:
- Callers pass `path="sub-packages/remote-iface"` (relative)
- The relative path is passed verbatim to `repo.git.submodule(add, ...)`
- .gitmodules entries are portable, matching native git behavior
Tests added:
- Submodule add accepts relative path (regression test for #168)
- Submodule add still rejects `..` traversal
- Validator exemption mechanism unit test
* test(lean): update dotdot rejection assertion for new validation order
PR #170 reordered _validate_path_parameters so the traversal check
('..' component rejection) runs before the absolute-path check.
As a result, repo_path='..' now raises the traversal error
("Invalid path '..': empty paths and '..' traversal components are
not allowed.") instead of the older "Relative path '..' not supported"
message.
Update test_relative_dotdot_rejected to assert against the new
behavior. The test now confirms both that '..' appears in the message
and that it is rejected for traversal reasons — which is the more
precise, security-aligned diagnosis.
Resolves CI failures in:
- ci / Test Python 3.12 on ubuntu-latest
- ci / Code Quality
Co-Authored-By: MementoRC (https://github.com/MementoRC)
* docs(lean): document relative_path_params and non-normalization note
Addresses minor reviewer feedback on PR #170:
- ToolDefinition class docstring now includes a full Args: section
documenting relative_path_params with the gitmodules(5) rationale
and a concrete example (``{"path"}`` for git_submodule_add).
- _validate_path_parameters docstring adds a Note: that paths such as
``./lib/submod`` or ``lib//submod`` are NOT normalised here — git
canonicalises them downstream; we only enforce no-``..`` components
and non-empty values.
* fix(lean): restrict path validation to string params with 'path' in name
_validate_path_parameters had a dead second-pass block that iterated
through every parameter (not just path ones) and rejected any value not
starting with '/'. This caused four CI failures on PR #170:
- test_multiple_params_with_one_invalid_path: the outer block caught
``other_param='value'`` before the path-aware branch reached
``another_path='relative/bad'``, so the assertion on 'relative/bad'
failed.
- test_non_path_params_ignored: ``branch_name='main'`` and similar
non-path strings were rejected with 'Relative path' errors.
- test_path_param_with_non_string_value_ignored: the fallback called
``.startswith('/')`` on an int, raising AttributeError.
- test_submodule_add_rejects_path_traversal: the URL value (not a path
param) was rejected first, masking the expected traversal error on
``path='../escape'``.
Fix: collapse to a single guarded branch. Skip any parameter that is
not a string or whose name does not contain 'path'. For string path
params, always reject empty / '..' traversal, then require absolute
unless the param is in the per-tool exempt set (e.g. submodule_add's
'path').
This preserves the exemption mechanism introduced for issue #168 and
restores correct behavior for non-path params and non-string values.
Co-Authored-By: MementoRC (https://github.com/MementoRC)
1 parent d541586 commit 8ec9a2a
2 files changed
Lines changed: 58 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
31 | 46 | | |
32 | 47 | | |
33 | 48 | | |
| |||
64 | 79 | | |
65 | 80 | | |
66 | 81 | | |
67 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
68 | 85 | | |
69 | 86 | | |
70 | 87 | | |
| |||
166 | 183 | | |
167 | 184 | | |
168 | 185 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
173 | 194 | | |
174 | 195 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 196 | + | |
| 197 | + | |
179 | 198 | | |
180 | 199 | | |
181 | | - | |
182 | | - | |
| 200 | + | |
183 | 201 | | |
184 | | - | |
| 202 | + | |
185 | 203 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
190 | 208 | | |
191 | 209 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
206 | 217 | | |
207 | | - | |
208 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
209 | 221 | | |
210 | 222 | | |
211 | | - | |
212 | | - | |
| 223 | + | |
| 224 | + | |
213 | 225 | | |
214 | 226 | | |
215 | 227 | | |
| |||
309 | 321 | | |
310 | 322 | | |
311 | 323 | | |
312 | | - | |
313 | | - | |
| 324 | + | |
314 | 325 | | |
315 | | - | |
| 326 | + | |
316 | 327 | | |
317 | 328 | | |
318 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
434 | 439 | | |
435 | 440 | | |
436 | 441 | | |
437 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
438 | 445 | | |
439 | 446 | | |
440 | 447 | | |
| |||
0 commit comments