Skip to content

Conversation

@Miauwkeru
Copy link
Contributor

Instead of changing the behaviour of the adapters to accomodate the command type like in #130
I opt instead to simplify the command type itself and make the structure completely flat.
If we ever want to change how it gets formatted for an adapter, it feels like this should happen at the adapter level
instead of the packing level

@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 95.16129% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.25%. Comparing base (cd69cf1) to head (f1cbabf).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
flow/record/fieldtypes/__init__.py 95.08% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
- Coverage   83.26%   83.25%   -0.02%     
==========================================
  Files          35       35              
  Lines        3705     3702       -3     
==========================================
- Hits         3085     3082       -3     
  Misses        620      620              
Flag Coverage Δ
unittests 83.25% <95.16%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yunzheng yunzheng self-requested a review August 20, 2025 08:15
Copy link
Member

@yunzheng yunzheng left a comment

Choose a reason for hiding this comment

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

Before I continue reviewing, it doesn't seem to pass these simple tests:

def test_empty_command() -> None:
    command = fieldtypes.command()
    assert command.executable == None
    assert command.args == None


def test_empty_string_command() -> None:
    command = fieldtypes.command("")
    assert command.executable == ""
    assert command.args == []

Would error with:

flow/record/fieldtypes/__init__.py:766: in __init__
    self.executable, self.args = self._split(self._raw)
                                 ^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = (executable=None, args=None), value = ''

    def _split(self, value: str) -> tuple[path, list[str]]:
>       executable, *args = shlex.split(value, posix=self._posix)
        ^^^^^^^^^^^^^^^^^
E       ValueError: not enough values to unpack (expected at least 1, got 0)

Also i'm not sure if my asserts would match with what one would expect. That is up for debate.

@Miauwkeru
Copy link
Contributor Author

Miauwkeru commented Aug 21, 2025

Before I continue reviewing, it doesn't seem to pass these simple tests:

Seems i forgot to add those simple tests, added them now

Also i'm not sure if my asserts would match with what one would expect. That is up for debate.

I don't think I'd expect everything to be None if i pass an empty string to it. executable and args are now filled up with "" and [] respectively

@Miauwkeru Miauwkeru requested a review from yunzheng August 21, 2025 14:53
Copy link
Member

@yunzheng yunzheng left a comment

Choose a reason for hiding this comment

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

I made some slight changes.

There is one thing though, it's that command.args is mutable.
But when you mutate it and pack/serialize it again, it's not taken into account. So not sure if it should be a tuple or fix it that it works correctly.

@Schamper
Copy link
Member

I made some slight changes.

There is one thing though, it's that command.args is mutable.

But when you mutate it and pack/serialize it again, it's not taken into account. So not sure if it should be a tuple or fix it that it works correctly.

Probably should be a tuple then?

@yunzheng
Copy link
Member

I made some slight changes.
There is one thing though, it's that command.args is mutable.
But when you mutate it and pack/serialize it again, it's not taken into account. So not sure if it should be a tuple or fix it that it works correctly.

Probably should be a tuple then?

I think that would be better indeed. @Miauwkeru can you make it so?

@Miauwkeru
Copy link
Contributor Author

I think that would be better indeed. @Miauwkeru can you make it so?

I changed it to a tuple

@yunzheng
Copy link
Member

I think that would be better indeed. @Miauwkeru can you make it so?

I changed it to a tuple

Thanks, the attributes are still settable though, for instance you can do:

cmd.executable = "cat"
cmd.args = ("hello.txt",)

Which works, but does not serialize/deserialize properly when writing the record. Maybe it's also better to make executable and args read-only. Or make it work with serialization and deserialization.

@respondersGY
Copy link
Contributor

Is this PR still in progress?

@EinatFox EinatFox linked an issue Dec 9, 2025 that may be closed by this pull request
Miauwkeru and others added 9 commits December 10, 2025 18:16
kept the from_windows and from_posix classmethods to enforce the path
type
Co-authored-by: Yun Zheng Hu <hu@fox-it.com>
* Move the `str` type check into __init__
* Make the command value explicity `str` type. So cannot be initialized using None
* mark `path_type` keyword argument only for clarity
_path_type = posix_path
@executable.setter
def executable(self, val: str | path | None) -> None:
self.__executable = self.__path_type(val)
Copy link
Member

Choose a reason for hiding this comment

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

with the latest merged PR #200 we should be able to directly initialize path with the value to determine the correct path type. Then you can als get rid of __path_type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean removing the whole __path_type in general? As in that case, there will be issues with for example hello_world.exe that will be interpreted differently depending on what system it gets run on.

If you just mean this specific case, this could still be an issue because the whole type can change from windows to posix path and vise versa. Tho I already have an idea on how to fix that specific issue.

Copy link
Member

Choose a reason for hiding this comment

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

ah wait I thought __path_type was a function to determine the path type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, no. It is a type[path], so either a windows_path or a posix_path :)

@Miauwkeru Miauwkeru requested a review from yunzheng December 11, 2025 15:23
@yunzheng yunzheng merged commit 6fab237 into main Dec 12, 2025
23 checks passed
@yunzheng yunzheng deleted the fix-command-type branch December 12, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify the command type

5 participants