Skip to content

Enable skipped tests and fix dash dash parse bug#471

Open
ben-grande wants to merge 1 commit into
QubesOS:mainfrom
ben-grande:fix-old-run-dash
Open

Enable skipped tests and fix dash dash parse bug#471
ben-grande wants to merge 1 commit into
QubesOS:mainfrom
ben-grande:fix-old-run-dash

Conversation

@ben-grande
Copy link
Copy Markdown
Contributor

Argparse interprets "--" as end of options separator, even if it already is inside nargs. Fix it by another less ugly hack that correctly distinguishes the dash dash when it's part of the command.

Fixes: QubesOS/qubes-issues#2916


Didn't test on my system. Relying on unit tests.

with subprocess.Popen(
["echo", "some-data"], stdout=subprocess.PIPE
) as echo:
with unittest.mock.patch("sys.stdin", echo.stdout):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why remove this? Cause later its already testing is stdin, stdout and stderr are None.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted this, not sure if I should touch that in this PR or commit. Maybe call a subprocess for shell and pass stdin that way, and capture stdout and stderr also that way?

Argparse interprets "--" as end of options separator, even if it already
is inside nargs. Fix it by another less ugly hack that correctly
distinguishes the dash dash when it's part of the command.

Fixes: QubesOS/qubes-issues#2916
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.84%. Comparing base (64cd714) to head (5748465).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #471   +/-   ##
=======================================
  Coverage   76.83%   76.84%           
=======================================
  Files          53       53           
  Lines        9365     9363    -2     
=======================================
- Hits         7196     7195    -1     
+ Misses       2169     2168    -1     

☔ 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.

(
"@dispvm:test-vm",
"qubes.VMExec+----",
"qubes.VMExec+----+----",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is correct. -- (the first one) means end of options, it shouldn't be considered part of the command itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case, yes. Old one was correct.

(
"@dispvm:test-vm",
"qubes.VMExec+command+----",
"qubes.VMExec+command+----+----",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here too, the old behavior was correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Command: ["--no-gui", "--dispvm=test-vm", "command", "--", "--"].

So when the command command is already the first positional argument, everything else should be passed to the VMExec and not be trimmed by qvm-run.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

-- is "end of options" marker, not "start of positional arguments" marker. It only means options shouldn't be interpreted after it, nothing more. See POSIX spec (Guideline 10).
See for example behavior of ls:

  • ls - l foo -- bar
  • ls foo -l -- -- bar
  • ls foo -- bar -l

That said, qvm-run already enforces all options to be passed before the command (for example qvm-run VM ls -p is not the same as qvm-run -p VM ls). So, maybe indeed in this case your approach is more consistent.

self.app.expected_calls[
('test-vm', 'admin.vm.feature.CheckWithTemplate', 'os', None)
] = b"2\x00QubesFeatureNotFoundError\x00\x00Feature 'os' not set\x00"
stdout = io.StringIO()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is unused after your change (the assert at the end is pointless with the mock.patch removed).

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.

Fix tests for qvm-run

2 participants