-
Notifications
You must be signed in to change notification settings - Fork 216
Add sqitch grep command.
#913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Thanks for the PR. If you don't mind:
Thanks! |
What does this mean? Do you want me to remove the reviews on this page? Happy to squash to a single commit, but I'm unsure of what you're asking above. |
566554b to
d157d95
Compare
|
@theory I've gone through the code with a fine-toothed comb. I've made a few minor changes here and there, but largely stylistic (but added some missing POD). I've squashed it all to a single commit. Is there more you'd like me to take care of? |
|
Also, I listed you as the author on grep.pm. Wasn't sure if there's guidance on that, but happy to have your name there. |
I tried to delete the LLM comments, but got an error; I've reported the bug to GitHub. If you can remove them, great! But I assume this PR is stuck with them. No, what I meant is that all the generated code needs to be exactly like all the other code in the project, and if it's not, should be removed and replaced or refactored, as appropriate. I trust you, not code generators. Er, and it sounds like you've already done that. 🤦🏻 I'll review sometime this week, I hope. Don't worry about the CI failures, BTW; something's broken with the Windows builds and the Snowflake builds don't work for PRs from users without the permissions for the Snowflake credentials. Though I would have thought you'd have them TBH. I'll make sure those tests pass at merged time. |
theory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. I stopped reviewing the test after around 920 lines because I figure I've left enough comments already to drive someone mad, and a lot of the issues are the same. Sorry about that.
Overall I like the feature, and want to add it, but it needs some more TLC IMO:
- Consider greping only files associated with changes and ignore others. You can potentially include other categories of files other than deploy/verify/revert by passing any other subdirectories of the top dir to
Change::script_file; this would fork for test scripts, for example. - If you really want to grep all the files in those directories, not just the files associated with changes, maybe document it a bit more and explain the rationale. I suspect it's fairly rare, TBH, but am aware of some cases of
\include--- though I typically recommend putting such files in a separate directory. - Take advantage of more of the methods in App::Sqitch::Plan::Change if you can. I has all kinds of stuff for normalized names, file paths (and segments), and more.
- A lot of the tests are pretty weak, counting only results rather than inspecting the results, and in some places test nothing or test duplicate code that would not fail if the original code was changed. In other ways it tests more than it needs to! (Honestly just 1-2 tests to show that regular expressions are evaluated at such is enough IMO). I think it needs more massaging to properly evaluate the module.
- Please use the output methods for all output and then use MockOutput to test output.
|
|
||
| # VERSION | ||
|
|
||
| has [qw/type t/] => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I've never seen this syntax before. Too bad it doesn't create just one field and let Getopt::Long map both names to it.
| } | ||
| else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| else { | |
| } else { |
| return -1 if $a =~ /^$deploy_dir/ and $b !~ /^$deploy_dir/; | ||
| return -1 if $a =~ /^$verify_dir/ and $b =~ /^$revert_dir/; | ||
| return 1 if $b =~ /^$deploy_dir/ and $a !~ /^$deploy_dir/; | ||
| return 1 if $b =~ /^$verify_dir/ and $a =~ /^$revert_dir/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably escape those $*_dir names in the regular expressions.
| # figure out the sort order | ||
| my $dir; | ||
| foreach ( $deploy_dir, $verify_dir, $revert_dir ) { | ||
| $dir = $_ if $a =~ /^$_/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $dir = $_ if $a =~ /^$_/; | |
| $dir = $_ if $a =~ /^\Q$_/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will false match on, say deploy/deploy.sql, no?
| A lightweight version of C<grep>, this command allows you to search for files | ||
| in your C<sqitch> directories, but it returns them in the order they were | ||
| defined in your plan (with deploy, verify, and revert directories being sorted | ||
| in that order). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the goal is to search change scripts in plan order, why not use the plan to figure out which files to search, rather than File::Find::Rule?
| dir(qw(t grep-fixtures deploy)), | ||
| 'CREATE TABLE' | ||
| ); | ||
| ok scalar(@files) > 0, 'List mode grep should find files with pattern'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it also find files when not in list mode? How is this different?
| # Verify the order_by hash has the expected changes | ||
| ok exists $order_by{roles}, 'Plan should include roles change'; | ||
| ok exists $order_by{users}, 'Plan should include users change'; | ||
| ok exists $order_by{widgets}, 'Plan should include widgets change'; | ||
| ok exists $order_by{posts}, 'Plan should include posts change'; | ||
|
|
||
| # Verify the plan order is correct | ||
| is $order_by{roles}, 0, 'roles should be first in plan (index 0)'; | ||
| is $order_by{users}, 1, 'users should be second in plan (index 1)'; | ||
| is $order_by{widgets}, 2, 'widgets should be third in plan (index 2)'; | ||
| is $order_by{posts}, 3, 'posts should be fourth in plan (index 3)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These appear to test the result of line 786, not the actual execution done in the module. I understand that the algorithm is the same, but if someone changes it in the module this test will not start failing.
| return 0 if $a eq $b; | ||
|
|
||
| # deploy < verify < revert for different directories | ||
| return -1 if $a =~ /^$deploy_dir/ and $b !~ /^$deploy_dir/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails on Windows because the names are not quoted. Also, like above, this test, unless I misread it, tests the logic of code duplicated from the module, not its execution in the module.
| 'widgets files should appear before posts files (plan order)'; | ||
| } | ||
|
|
||
| # Test that files not in plan are sorted last |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why grep files that don't correspond to plan items?
| if ( open my $fh, '<:utf8_strict', $file ) { | ||
| while ( my $line = <$fh> ) { | ||
| if ( $line =~ /$regex/ ) { | ||
| printf "%s:%d: %s" => $file, $., $line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please $self->emit or one of the other related output methods that App::Sqitch::Command provides (by delegating to App::Sqitch).
Fine with me for you to be listed as author TBH. |
After a nail-biting five years of anticipation, here's the pull request for sqitch grep.
Full tests and documentation included.
sqitch help grepwill give full information.Disclaimer: while the
grep.pmcode is based on the code I wrote several years ago, the tests and the documentation have been written by Amazon's Kiro using Claude Sonnet 4.5.