fix(extractor): skip hidden-dir filter for root path when using relative "."#66
fix(extractor): skip hidden-dir filter for root path when using relative "."#66spencercjh merged 4 commits intomainfrom
Conversation
When users run `spec-forge generate .` from a project root, filepath.Walk visits "." first. The existing hidden-directory check matched "." via HasPrefix(info.Name(), "."), causing SkipDir on the entire tree and producing an empty openapi.yaml. Exclude the root walk entry from the hidden-directory filter so that relative paths work the same as absolute paths. Signed-off-by: spencercjh <spencercjh@gmail.com>
Apply the same root-path guard from 92ad9f6 to gin/detector.go, gozero/detector.go, and grpcprotoc/detector.go so that no walk function can accidentally skip the entire tree when called with a relative "." path. Add regression tests for each. Signed-off-by: spencercjh <spencercjh@gmail.com>
Convert grpcprotoc and gozero detector tests from external (_test) to internal package so unexported walk functions are accessible. Fold the separate detector_walk_test.go files into detector_test.go and remove the now-redundant files. Signed-off-by: spencercjh <spencercjh@gmail.com>
Review Summary by QodoFix hidden-dir filter skipping tree with relative "." path
WalkthroughsDescription• Fix hidden-directory filter skipping entire tree with relative "." path - Root entry "." was incorrectly matched by HasPrefix check, causing filepath.SkipDir on all files - Added path comparison guard to exclude root from hidden-directory filter • Apply fix to all detector walk functions (gin, gozero, grpcprotoc) • Add regression tests for relative "." path in all detectors • Convert gozero and grpcprotoc tests from external to internal package Diagramflowchart LR
A["filepath.Walk with relative dot path"] -->|"info.Name() == dot"| B["Hidden-dir filter check"]
B -->|"Before: HasPrefix matches dot"| C["SkipDir entire tree - BUG"]
B -->|"After: path != projectPath guard"| D["Skip only actual hidden dirs"]
D --> E["Files parsed correctly"]
File Changes1. internal/extractor/gin/ast_parser.go
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
Pull request overview
Fixes a regression where using a relative "." project path caused directory walkers to treat the root entry "." as a hidden directory and skip the entire tree, resulting in zero parsed/collected files during extraction.
Changes:
- Prevent hidden-directory skipping from applying to the walk root entry when
projectPathis"."(and similar root cases) in gin/grpcprotoc/gozero walkers. - Add/extend regression tests covering relative
"."path walking for gin, grpcprotoc, and gozero. - Convert grpcprotoc and gozero detector tests from external (
*_test) to internal package tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/extractor/grpcprotoc/detector.go | Adjust hidden-dir filter to avoid skipping the walk root when invoked with ".". |
| internal/extractor/grpcprotoc/detector_test.go | Switch to internal package tests and add a relative "." regression test for proto discovery. |
| internal/extractor/gozero/detector.go | Adjust hidden-dir filter to avoid skipping the walk root when invoked with ".". |
| internal/extractor/gozero/detector_test.go | Switch to internal package tests and add a relative "." regression test for API discovery. |
| internal/extractor/gin/detector.go | Adjust vendor/hidden-dir filter to avoid skipping the walk root when invoked with ".". |
| internal/extractor/gin/detector_test.go | Add a relative "." regression test for main file discovery. |
| internal/extractor/gin/ast_parser.go | Adjust vendor/hidden-dir filter to avoid skipping the walk root when invoked with ".". |
| internal/extractor/gin/ast_parser_test.go | Add regression tests for parsing with relative "." and for hidden-dir skipping behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback on PR #66: check all error return values in the new relative-path regression tests so failures report the real root cause instead of producing misleading results. Signed-off-by: spencercjh <spencercjh@gmail.com>
Summary
spec-forge generate .from a project root,filepath.Walk(".")visits the root directory"."first. The hidden-directory filterstrings.HasPrefix(info.Name(), ".")matched".", causingfilepath.SkipDirto skip the entire directory tree — producing an emptyopenapi.yamlwith 0 parsed filesgin/detector.go,grpcprotoc/detector.go, andgozero/detector.goso no walk function can accidentally skip the tree when called with a relative"."pathgrpcprotocandgozerodetector tests from external (_test) to internal package, merge walk regression tests intodetector_test.goRoot Cause
filepath.Walk(".")→ root entry hasinfo.Name() == "."→HasPrefix(".", ".") == true→SkipDiron entire tree.Test plan
TestASTParser_ParseFiles_RelativeDotPath— reproduces the original bug, verifies files are parsed with"."pathTestASTParser_ParseFiles_HiddenDirsSkipped— confirms.hiddendirs still properly skippedTestDetector_findMainFiles_RelativeDotPath— regression for gin detectorTestDetector_findProtoFiles_RelativeDotPath— regression for grpcprotoc detectorTestDetector_findAPIFiles_RelativeDotPath— regression for gozero detectormake testpasses with zero failures