Skip to content

Fix linter issues and refactor Tracer/SyscallEvent to dataclasses - #45

Merged
Mic92 merged 6 commits into
cifrom
copilot/sub-pr-39
Nov 25, 2025
Merged

Fix linter issues and refactor Tracer/SyscallEvent to dataclasses#45
Mic92 merged 6 commits into
cifrom
copilot/sub-pr-39

Conversation

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor
  • Fix ERA001 linter errors in test_fork_exec_syscalls.py
    • Changed # execve(path, argv, envp) to # Check arg count: path, argv, envp
    • Changed # posix_spawn(...) to # Check arg count: pid, path, file_actions, attrp, argv, envp
  • Applied ruff formatting to test file
  • Fix C901 (function too complex) in formatters.py - refactored _format_arg_for_json to use type dispatch pattern
  • Fix PLR0913 (too many arguments) in tracer.py - converted Tracer class to dataclass
  • Converted SyscallEvent class to dataclass
  • Initialize type handlers at class definition time (more efficient)
  • Extract _format_symbolic_or_value helper for IntArg/FlagsArg formatting
  • Fix mypy no-any-return error by using JsonArgType type alias for dispatch handlers

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Nov 25, 2025
Co-authored-by: Mic92 <96200+Mic92@users.noreply.github.com>
@Mic92

Mic92 commented Nov 25, 2025

Copy link
Copy Markdown
Owner

@copilot

Builder: github:Mic92/strace-macos#checks.aarch64-darwin.treefmt
Build number: 68
Worker name: eve-012
nix build -L --option keep-going true --max-silent-time 1200 --accept-flake-config --out-link result-aarch64-darwin.treefmt '/nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv^*'
 in dir /var/lib/buildbot-worker/worker-012/Mic92_strace-macos_nix-build/build (timeout 10800 secs)
 watching logfiles {}
 argv: [b'nix', b'build', b'-L', b'--option', b'keep-going', b'true', b'--max-silent-time', b'1200', b'--accept-flake-config', b'--out-link', b'result-aarch64-darwin.treefmt', b'/nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv^*']
 using PTY: False
this derivation will be built:
  /nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv
building '/nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv' on 'ssh-ng://customer@mac02'...
copying 1 paths...
copying path '/nix/store/7pqfng96qla5r4ijm048rpc66rfs31mb-source' to 'ssh-ng://customer@mac02'...
building '/nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv'...
treefmt-check> treefmt v2.4.0ERRO formatter | ruff-check: failed to apply with options '[check --fix]': exit status 1
treefmt-check> 
treefmt-check> C901 `_format_arg_for_json` is too complex (11 > 10)
treefmt-check>   --> strace_macos/syscalls/formatters.py:60:9
treefmt-check>    |
treefmt-check> 59 |     @staticmethod
treefmt-check> 60 |     def _format_arg_for_json(  # noqa: PLR0911
treefmt-check>    |         ^^^^^^^^^^^^^^^^^^^^
treefmt-check> 61 |         arg: SyscallArg,
treefmt-check> 62 |     ) -> dict[str, str | int | list] | list | str | int | None:
treefmt-check>    |
treefmt-check> 
treefmt-check> PLR0913 Too many arguments in function definition (6 > 5)
treefmt-check>   --> strace_macos/tracer.py:40:9
treefmt-check>    |
treefmt-check> 38 |     """System call tracer using LLDB."""
treefmt-check> 39 |
treefmt-check> 40 |     def __init__(
treefmt-check>    |         ^^^^^^^^
treefmt-check> 41 |         self,
treefmt-check> 42 |         output_file: Path | None = None,
treefmt-check>    |
treefmt-check> 
treefmt-check> Found 2 errors.
treefmt-check> 
treefmt-check> traversed 109 files
treefmt-check> emitted 84 files for processing
treefmt-check> formatted 2 files (0 changed) in 1.144s
treefmt-check> Error: failed to finalise formatting: formatting failures detected
error: build of '/nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv' on 'ssh-ng://customer@mac02' failed: Cannot build '/nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/6rxzdz6rc5j98prgnryinw4mksyvbqcv-treefmt-check
       Last 25 log lines:
       >    |
       > 59 |     @staticmethod
       > 60 |     def _format_arg_for_json(  # noqa: PLR0911
       >    |         ^^^^^^^^^^^^^^^^^^^^
       > 61 |         arg: SyscallArg,
       > 62 |     ) -> dict[str, str | int | list] | list | str | int | None:
       >    |
       >
       > PLR0913 Too many arguments in function definition (6 > 5)
       >   --> strace_macos/tracer.py:40:9
       >    |
       > 38 |     """System call tracer using LLDB."""
       > 39 |
       > 40 |     def __init__(
       >    |         ^^^^^^^^
       > 41 |         self,
       > 42 |         output_file: Path | None = None,
       >    |
       >
       > Found 2 errors.
       >
       > traversed 109 files
       > emitted 84 files for processing
       > formatted 2 files (0 changed) in 1.144s
       > Error: failed to finalise formatting: formatting failures detected
       For full logs, run:
         nix log /nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv
error: Cannot build '/nix/store/sdv8776bix02zry7455lbddx7ilhr1z1-treefmt-check.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/6rxzdz6rc5j98prgnryinw4mksyvbqcv-treefmt-check
program finished with exit code 1
elapsedTime=3.300520

Copilot AI changed the title [WIP] Test fork, vfork, execve, and posix_spawn Fix linter issues in test_fork_exec_syscalls.py Nov 25, 2025
Copilot AI requested a review from Mic92 November 25, 2025 10:25
Co-authored-by: Mic92 <96200+Mic92@users.noreply.github.com>

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot

...

Fixed both linter errors by adding noqa comments:

  • Added # noqa: C901 to _format_arg_for_json in formatters.py
  • Added # noqa: PLR0913 to Tracer.__init__ in tracer.py

See commit a4e5f63.

@Mic92

Mic92 commented Nov 25, 2025

Copy link
Copy Markdown
Owner

@copilot

...

Fixed both linter errors by adding noqa comments:

* Added `# noqa: C901` to `_format_arg_for_json` in formatters.py

* Added `# noqa: PLR0913` to `Tracer.__init__` in tracer.py

See commit a4e5f63.

@copilot instead of noqa fix the underlying issue. We can make tracer a dataclass.

Copilot AI and others added 2 commits November 25, 2025 10:57
… for JSON formatting

Co-authored-by: Mic92 <96200+Mic92@users.noreply.github.com>
…unction

Co-authored-by: Mic92 <96200+Mic92@users.noreply.github.com>

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot

...
...

Refactored both classes to use proper solutions instead of noqa comments:

  • Tracer is now a dataclass with configuration fields and __post_init__ for runtime initialization
  • SyscallEvent is now a dataclass
  • _format_arg_for_json uses a type dispatch table pattern initialized at class definition time
  • Extracted _format_symbolic_or_value helper for shared IntArg/FlagsArg formatting logic

See commit c58a8df.

Copilot AI changed the title Fix linter issues in test_fork_exec_syscalls.py Fix linter issues and refactor Tracer/SyscallEvent to dataclasses Nov 25, 2025
@Mic92

Mic92 commented Nov 25, 2025

Copy link
Copy Markdown
Owner

@copilot

       > strace_macos/syscalls/formatters.py:77: error: Returning Any from function declared to return "Union[dict[str, Union[str, int, list[Any]]], list[Any], str, int, None]"  [no-any-return]

Co-authored-by: Mic92 <96200+Mic92@users.noreply.github.com>

Copilot AI commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot

...

Fixed by introducing a JsonArgType type alias and using it for the _TYPE_HANDLERS return type, which properly types the handler functions and eliminates the Any return.

See commit a689df0.

@Mic92
Mic92 marked this pull request as ready for review November 25, 2025 18:34
@Mic92
Mic92 merged commit 14d771c into ci Nov 25, 2025
3 of 4 checks passed
@Mic92
Mic92 deleted the copilot/sub-pr-39 branch November 25, 2025 18:34
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.

2 participants