Skip to content

Validate edge padding CLI arguments - #9

Merged
Spiffical merged 1 commit into
masterfrom
agent/validate-edge-padding-cli
Jul 15, 2026
Merged

Validate edge padding CLI arguments#9
Spiffical merged 1 commit into
masterfrom
agent/validate-edge-padding-cli

Conversation

@Spiffical

Copy link
Copy Markdown
Owner

What changed

  • validate negative --clip-pad-seconds and --edge-pad-seconds values immediately after argument parsing
  • apply that validation to ordinary clipped processing as well as event mode
  • add regression coverage for both CLI aliases without --event-time

Why

The edge-padding validation was nested inside event-mode validation. Negative padding in other modes reached the broad exception handler and could be reported as an unexpected error with a traceback.

User impact

Invalid edge-padding values now produce concise argparse usage errors with exit code 2 in every CLI mode.

Validation

  • 5 passed in the focused CLI suite
  • 66 passed, 2 deselected in the full offline suite
  • git diff --check

@Spiffical
Spiffical marked this pull request as ready for review July 15, 2026 17:50
Copilot AI review requested due to automatic review settings July 15, 2026 17:50
@Spiffical
Spiffical merged commit eb3b216 into master Jul 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR moves edge-padding validation (--clip-pad-seconds / --edge-pad-seconds) to immediately after CLI argument parsing so negative values consistently fail via argparse (exit code 2) across both normal and event-driven modes, avoiding broad exception handling/tracebacks.

Changes:

  • Add a post-parse_args() validation that rejects negative clip_pad_seconds values with an argparse error.
  • Remove the prior event-mode-only negative padding validation to ensure consistent behavior across modes.
  • Add a regression test ensuring negative edge-padding values fail via argparse without tracebacks when not using --event-time.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
scripts/generate_spectrograms.py Moves negative padding validation to immediately after argument parsing and removes the event-only check.
tests/test_generate_spectrograms_cli.py Adds a regression test for negative padding values (both CLI aliases) in non-event mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +61 to +65
@pytest.mark.parametrize("flag", ["--clip-pad-seconds", "--edge-pad-seconds"])
def test_negative_clip_pad_without_event_uses_argparse_without_traceback(
tmp_path: Path,
flag: str,
):
Comment on lines +61 to +90
@pytest.mark.parametrize("flag", ["--clip-pad-seconds", "--edge-pad-seconds"])
def test_negative_clip_pad_without_event_uses_argparse_without_traceback(
tmp_path: Path,
flag: str,
):
input_path = tmp_path / "audio.wav"
input_path.touch()

completed = subprocess.run(
[
sys.executable,
str(SCRIPT),
"--input-file",
str(input_path),
flag,
"-0.1",
],
cwd=REPO_ROOT,
text=True,
capture_output=True,
check=False,
)

assert completed.returncode == 2
assert (
"error: --clip-pad-seconds/--edge-pad-seconds must be non-negative"
in completed.stderr
)
assert "Traceback" not in completed.stderr
assert "Unexpected error" not in completed.stdout + completed.stderr
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