cody
cody copied to clipboard
fix(rules): avoid duplicate .sourcegraph paths in rule search
This commit prevents the addition of duplicate .sourcegraph paths when generating rule search paths. This avoids scenarios where the same .sourcegraph directory is added multiple times to the search path which would result in a console error since you are not supposed to have .sourcegraph.sourcegraph paths.
The fix involves checking if the current path already ends with .sourcegraph before adding it to the search paths. A new test case is added to ensure that duplicate paths are not generated.
Additionally, a check is added to ensure that the directory exists before attempting to read it. If the directory does not exist, an empty array is returned without error.
Test plan
- create a .sourcegraph/test.rule.md within a folder that is the the workspace root
- check that the rule is properly loaded and you don't get any console errors regarding
"Error: ENOENT: no such file or directory, scandir