Repository navigation
Commit 0e303ee
refactor: give the Python walk classifier the shape Go already has
Go decides how to treat each entry of a recursive grep in a named function
with three named outcomes -- classifyWalkEntry returning walkEntryGrep,
walkEntrySkip or walkEntryUnreadable. Python made the same decision inline,
held together by comments that referenced the Go symbols by name:
# matching the split Go makes in classifyWalkEntry:
# ... as Go's walkEntryUnreadable does.
# ... as Go's walkEntrySkip does.
That is a cross-runtime contract enforced by English. Renaming the Go
function would silently falsify it -- no test fails, nothing rebuilds. It
matters here specifically because runtime drift is this feature's recurring
defect: six of the ten findings in the last review were the two
implementations having quietly diverged.
Extract _classify_walk_entry with the same three outcomes, the same argument
order and the same return shape, so the two can be diffed by reading them
side by side rather than by trusting prose. The entry loop drops from 38
lines (25 of them comment, 65%) to 14 (3 comment, 21%), and the reasoning
moves onto the function it actually describes.
The docstring is explicit that the two are not branch-for-branch identical
and should not be forced to be -- Go tests IsDir, EvalSymlinks, Stat and
IsRegular separately because WalkDir hands it directories and unresolvable
links, while os.walk yields only filenames and Path.is_file() collapses
those cases into one call. It also records the one divergence we know of and
could not construct: Go counts a failed Stat on a non-symlink as UNREADABLE,
where Path.is_file() swallows the OSError and reaches SKIP.
Behavior is unchanged. Each outcome is independently pinned, verified by
inverting it and confirming the suite catches it:
UNREADABLE -> SKIP (broken links uncounted) caught
SKIP -> GREP (escaping symlinks searched) caught
GREP -> SKIP (regular files never read) caught
SKIP -> UNREADABLE (FIFOs counted) caught
Adds a direct table test for the classifier, which the inline form could
not have: the three-way split is now assertable without going through
grep_content, including the symlink-loop case.
Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: brandonkeung <[email protected]>1 parent 97a23d8 commit 0e303ee
2 files changed
Lines changed: 120 additions & 30 deletions
File tree
- python/packages/kagent-skills/src/kagent
- skills
- tests/unittests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
30 | 93 | | |
31 | 94 | | |
32 | 95 | | |
| |||
236 | 299 | | |
237 | 300 | | |
238 | 301 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 302 | + | |
| 303 | + | |
252 | 304 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
| 305 | + | |
| 306 | + | |
267 | 307 | | |
268 | 308 | | |
269 | 309 | | |
270 | 310 | | |
271 | 311 | | |
272 | 312 | | |
273 | | - | |
| 313 | + | |
274 | 314 | | |
275 | | - | |
276 | 315 | | |
277 | 316 | | |
278 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
466 | 517 | | |
467 | 518 | | |
468 | 519 | | |
| |||
0 commit comments