Skip to content
Open

tf 7 #22

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions thefuck_7/tests/rules/test_php_s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
from thefuck.types import Command


@pytest.mark.parametrize('command', [
Command('php -s localhost:8000', ''),
Command('php -t pub -s 0.0.0.0:8080', '')
])
def test_match(command):
assert match(command)
def test_match():
assert match(Command('php -s localhost:8000', ''))
Comment on lines +6 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider maintaining broader test coverage.

While the simplified test validates the primary use case, the removal of parameterized tests reduces coverage. The original tests likely covered edge cases and variations that could still be valid after the match function refinement.

Consider restoring parameterized tests to ensure robustness:

-def test_match():
-    assert match(Command('php -s localhost:8000', ''))
+@pytest.mark.parametrize('command', [
+    Command('php -s localhost:8000', ''),
+    Command('php -s 127.0.0.1:3000', ''),
+    Command('php -s localhost:8080 -t public', ''),
+])
+def test_match(command):
+    assert match(command)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_match():
assert match(Command('php -s localhost:8000', ''))
@pytest.mark.parametrize('command', [
Command('php -s localhost:8000', ''),
Command('php -s 127.0.0.1:3000', ''),
Command('php -s localhost:8080 -t public', ''),
])
def test_match(command):
assert match(command)
🤖 Prompt for AI Agents
In thefuck_7/tests/rules/test_php_s.py around lines 6 to 7, the current
test_match function only checks a single primary use case, reducing test
coverage. To fix this, restore the parameterized tests that cover various edge
cases and input variations for the match function. Use a parameterized testing
approach to include multiple command inputs and expected outcomes, ensuring the
match function is robustly tested across different scenarios.



@pytest.mark.parametrize('command', [
Expand All @@ -19,9 +15,6 @@ def test_not_match(command):
assert not match(command)


@pytest.mark.parametrize('command, new_command', [
(Command('php -s localhost:8000', ''), 'php -S localhost:8000'),
(Command('php -t pub -s 0.0.0.0:8080', ''), 'php -t pub -S 0.0.0.0:8080')
])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
def test_get_new_command():
new_command = get_new_command(Command('php -s localhost:8000', ''))
assert new_command == 'php -S localhost:8000'
Comment on lines +18 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Maintain test coverage for command transformation.

Similar to the match test, consider adding back multiple test cases to ensure get_new_command works correctly across different PHP command variations.

Consider adding parameterized tests:

-def test_get_new_command():
-    new_command = get_new_command(Command('php -s localhost:8000', ''))
-    assert new_command == 'php -S localhost:8000'
+@pytest.mark.parametrize('command, expected', [
+    (Command('php -s localhost:8000', ''), 'php -S localhost:8000'),
+    (Command('php -s 127.0.0.1:3000', ''), 'php -S 127.0.0.1:3000'),
+    (Command('php -s localhost:8080 -t public', ''), 'php -S localhost:8080 -t public'),
+])
+def test_get_new_command(command, expected):
+    assert get_new_command(command) == expected
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_get_new_command():
new_command = get_new_command(Command('php -s localhost:8000', ''))
assert new_command == 'php -S localhost:8000'
@pytest.mark.parametrize('command, expected', [
(Command('php -s localhost:8000', ''), 'php -S localhost:8000'),
(Command('php -s 127.0.0.1:3000', ''), 'php -S 127.0.0.1:3000'),
(Command('php -s localhost:8080 -t public', ''), 'php -S localhost:8080 -t public'),
])
def test_get_new_command(command, expected):
assert get_new_command(command) == expected
🤖 Prompt for AI Agents
In thefuck_7/tests/rules/test_php_s.py around lines 18 to 20, the
test_get_new_command function currently tests only one PHP command
transformation. To maintain comprehensive test coverage, add multiple test cases
covering different PHP command variations. Use parameterized tests to
efficiently run the same test logic with various inputs and expected outputs,
ensuring get_new_command handles all relevant cases correctly.

5 changes: 4 additions & 1 deletion thefuck_7/thefuck/rules/php_s.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

@for_app('php')
def match(command):
return " -s " in command.script
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Warning 🐛 Bug

Match logic is case-sensitive and misses uppercase or mixed-case invocations.

Issue Explanation
  • The match function in blarApp/open-benchmark/thefuck_7/thefuck/rules/php_s.py uses a literal substring check.
  • It checks only for "php -s" in command.script.
  • It does not normalize command.script to lowercase.
  • Commands like "PHP -s", "php -S", and other mixed-case variants are not detected.
  • This prevents valid invocations from matching.
return "php -s" in command.script

Reply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.

return "php -s" in command.script
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Warning 🐛 Bug

Substring check for "php -s" ignores whitespace variations.

Issue Explanation
  • File path: blarApp/open-benchmark/thefuck_7/thefuck/rules/php_s.py.
  • The match function checks for the literal substring "php -s" in command.script.
  • Invocations with multiple spaces (e.g., php -s) are not detected.
  • Invocations with other whitespace (e.g., tabs between php and -s) are not detected.
def match(command):
    return "php -s" in command.script

Reply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Warning 🐛 Bug

Simple substring check for 'php -s' causes false positives.

Issue Explanation
  • In blarApp/open-benchmark/thefuck_7/thefuck/rules/php_s.py, the match function uses a basic substring check: "php -s" in command.script.
  • This approach returns true when "php -s" appears within other tokens (e.g., somephp -s, aliasphp -s).
  • Unintended matches produce false positives for unrelated commands.
  • Replace the substring check with a regex using word boundaries (e.g., r'\bphp\s+-s\b') or explicit argument parsing to ensure only standalone php -s matches.
def match(command):
    return "php -s" in command.script

Reply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.



def get_new_command(command):
return replace_argument(command.script, "-s", "-S")


requires_output = False
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Warning 🐛 Bug

Module-level requires_output flag is not registered by the rule loader.

Issue Explanation
  • The flag requires_output is defined at module scope in blarApp/open-benchmark/thefuck_7/thefuck/rules/php_s.py (module scope).
  • The framework registers flags only when set as attributes on rule functions or classes (e.g. match.requires_output = False).
  • Module-level variables are not inspected by the rule-loading mechanism.
  • The requires_output setting remains at its default value, causing output-dependent rules to execute incorrectly.
...
# at the bottom of php_s.py
requires_output = False

Reply if you have any questions or let me know if I missed something.
Don't forget to react with a 👍 or 👎 to the comments made by Blar to help us improve.