Skip to content

"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/

Python

fix: harden WaveTone packaging and launch guards

Shuhan Zhang15f1a0b50ceb
diff --git a/README.md b/README.md
index a99ab3e80..f2b780932 100644
--- a/README.md
+++ b/README.md
@@ -1228,7 +1228,7 @@ gimp 107 passed ✅ (64 unit + 43 e2e)
blender 208 passed ✅ (150 unit + 58 e2e)
inkscape 202 passed ✅ (148 unit + 54 e2e)
audacity 161 passed ✅ (107 unit + 54 e2e)
-wavetone 18 passed ✅ (13 unit + 5 e2e)
+wavetone 20 passed ✅ (15 unit + 5 e2e)
libreoffice 158 passed ✅ (89 unit + 69 e2e)
mubu 96 passed ✅ (85 unit + 11 e2e)
obs-studio 153 passed ✅ (116 unit + 37 e2e)
@@ -1308,7 +1308,7 @@ cli-anything/
├── 🧊 blender/agent-harness/ # Blender CLI (208 tests)
├── ✏️ inkscape/agent-harness/ # Inkscape CLI (202 tests)
├── 🎵 audacity/agent-harness/ # Audacity CLI (161 tests)
-├── wavetone/agent-harness/ # WaveTone CLI (18 tests: 13 unit + 5 e2e)
+├── wavetone/agent-harness/ # WaveTone CLI (20 tests: 15 unit + 5 e2e)
├── 🌐 browser/agent-harness/ # Browser CLI (DOMShell MCP, new)
├── 📄 libreoffice/agent-harness/ # LibreOffice CLI (158 tests)
├── 📧 mailchimp/agent-harness/ # Mailchimp Marketing API CLI (303 commands, 36 unit tests)
diff --git a/README_CN.md b/README_CN.md
index 91e1825ec..71dfeb301 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -679,7 +679,7 @@ gimp 107 passed ✅ (64 unit + 43 e2e)
blender 208 passed ✅ (150 unit + 58 e2e)
inkscape 202 passed ✅ (148 unit + 54 e2e)
audacity 161 passed ✅ (107 unit + 54 e2e)
-wavetone 18 passed ✅ (13 unit + 5 e2e)
+wavetone 20 passed ✅ (15 unit + 5 e2e)
libreoffice 158 passed ✅ (89 unit + 69 e2e)
obs-studio 153 passed ✅ (116 unit + 37 e2e)
kdenlive 155 passed ✅ (111 unit + 44 e2e)
@@ -753,7 +753,7 @@ cli-anything/
├── 🧊 blender/agent-harness/ # Blender CLI(208 项测试)
├── ✏️ inkscape/agent-harness/ # Inkscape CLI(202 项测试)
├── 🎵 audacity/agent-harness/ # Audacity CLI(161 项测试)
-├── wavetone/agent-harness/ # WaveTone CLI(18 项测试:13 unit + 5 e2e)
+├── wavetone/agent-harness/ # WaveTone CLI(20 项测试:15 unit + 5 e2e)
├── 📄 libreoffice/agent-harness/ # LibreOffice CLI(158 项测试)
├── 📚 zotero/agent-harness/ # Zotero CLI(新增,支持文献导入)
├── 📓 joplin/agent-harness/ # Joplin CLI(134 测试:107 单元 + 27 e2e)
diff --git a/wavetone/agent-harness/cli_anything/wavetone/core/audio.py b/wavetone/agent-harness/cli_anything/wavetone/core/audio.py
index b8f8d3d91..4f419f0e9 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/core/audio.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/core/audio.py
@@ -12,6 +12,24 @@ from typing import Any
from .project import normalize_audio_path
+def _safe_float(value: Any) -> float | None:
+ if value in (None, "", "N/A"):
+ return None
+ try:
+ return float(value)
+ except (TypeError, ValueError):
+ return None
+
+
+def _safe_int(value: Any) -> int | None:
+ if value in (None, "", "N/A"):
+ return None
+ try:
+ return int(value)
+ except (TypeError, ValueError):
+ return None
+
+
def _probe_wav_stdlib(path: Path) -> dict[str, Any]:
with wave.open(str(path), "rb") as handle:
frames = handle.getnframes()
@@ -57,16 +75,16 @@ def _probe_ffprobe(path: Path) -> dict[str, Any]:
{},
)
fmt = data.get("format", {})
- duration = float(fmt.get("duration") or 0.0)
+ duration = _safe_float(fmt.get("duration"))
return {
"path": str(path),
"format": fmt.get("format_name"),
"codec": audio_stream.get("codec_name"),
- "duration_seconds": round(duration, 6),
- "sample_rate": int(audio_stream["sample_rate"]) if audio_stream.get("sample_rate") else None,
+ "duration_seconds": round(duration, 6) if duration is not None else None,
+ "sample_rate": _safe_int(audio_stream.get("sample_rate")),
"channels": audio_stream.get("channels"),
- "bit_rate": int(fmt["bit_rate"]) if fmt.get("bit_rate") else None,
- "size_bytes": int(fmt.get("size") or path.stat().st_size),
+ "bit_rate": _safe_int(fmt.get("bit_rate")),
+ "size_bytes": _safe_int(fmt.get("size")) or path.stat().st_size,
"probe_method": "ffprobe",
}
diff --git a/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md b/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md
index d3f3e4086..dff7369ba 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md
+++ b/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md
@@ -2,7 +2,7 @@
## Test Inventory Plan
-- `test_core.py`: 13 unit tests for project manifests, audio probing, session logs,
+- `test_core.py`: 15 unit tests for project manifests, audio probing, session logs,
and backend discovery.
- `test_full_e2e.py`: 5 E2E tests covering CLI subprocess workflows and real
WaveTone launch smoke coverage.
@@ -17,6 +17,7 @@
- Probe a generated WAV file with the Python stdlib.
- Fall back to stat metadata for malformed WAV files.
- Probe non-WAV audio with a single stable `ffprobe -show_entries` argument.
+- Safely parse non-numeric ffprobe metadata.
- Append and reload session events.
- Reject invalid session JSON schemas with clear `ValueError`s.
- Resolve `WAVETONE_EXE` from the environment.
@@ -24,6 +25,7 @@
invocations.
- Return a failing exit status for launch smoke checks when the backend exits
early with a nonzero code.
+- Reject GUI launch attempts on non-Windows hosts with a clear error.
## E2E Test Plan
@@ -75,7 +77,7 @@ python -m pytest cli_anything\wavetone\tests\ -v -s
Result:
```text
-collected 18 items
+collected 20 items
cli_anything/wavetone/tests/test_core.py::test_create_project_manifest PASSED
cli_anything/wavetone/tests/test_core.py::test_rejects_unsupported_audio PASSED
@@ -85,18 +87,20 @@ cli_anything/wavetone/tests/test_core.py::test_update_analysis_settings PASSED
cli_anything/wavetone/tests/test_core.py::test_probe_wav_metadata PASSED
cli_anything/wavetone/tests/test_core.py::test_probe_malformed_wav_falls_back_to_stat PASSED
cli_anything/wavetone/tests/test_core.py::test_ffprobe_uses_single_show_entries_argument PASSED
+cli_anything/wavetone/tests/test_core.py::test_ffprobe_handles_non_numeric_metadata PASSED
cli_anything/wavetone/tests/test_core.py::test_session_event_log PASSED
cli_anything/wavetone/tests/test_core.py::test_session_rejects_invalid_schema PASSED
cli_anything/wavetone/tests/test_core.py::test_find_wavetone_from_env PASSED
cli_anything/wavetone/tests/test_core.py::test_cli_preserves_inherited_project_and_json_context PASSED
cli_anything/wavetone/tests/test_core.py::test_wavetone_launch_fails_on_early_nonzero_exit PASSED
+cli_anything/wavetone/tests/test_core.py::test_launch_requires_windows PASSED
cli_anything/wavetone/tests/test_full_e2e.py::TestCLISubprocess::test_help PASSED
cli_anything/wavetone/tests/test_full_e2e.py::TestCLISubprocess::test_project_audio_workflow_json PASSED
cli_anything/wavetone/tests/test_full_e2e.py::TestCLISubprocess::test_formats_json PASSED
cli_anything/wavetone/tests/test_full_e2e.py::TestRealWaveToneBackend::test_doctor_real_backend PASSED
cli_anything/wavetone/tests/test_full_e2e.py::TestRealWaveToneBackend::test_launch_real_backend_with_wav PASSED
-18 passed in 3.19s
+20 passed in 3.09s
```
## Coverage Notes
@@ -104,7 +108,8 @@ cli_anything/wavetone/tests/test_full_e2e.py::TestRealWaveToneBackend::test_laun
- Unit tests cover manifest creation, validation, persistence, labels, tempo,
analysis settings, audio probing, malformed WAV fallback, session logs,
session schema validation, backend discovery, ffprobe argument construction,
- inherited CLI project and JSON context, and failed launch smoke reporting.
+ ffprobe metadata parsing, inherited CLI project and JSON context, failed
+ launch smoke reporting, and Windows launch gating.
- CLI subprocess tests resolve and use the installed `cli-anything-wavetone`
entry point.
- Real backend coverage launches `C:\Users\Hp\Desktop\wavetone2.6.1\wavetone.exe`
diff --git a/wavetone/agent-harness/cli_anything/wavetone/tests/helpers.py b/wavetone/agent-harness/cli_anything/wavetone/tests/helpers.py
new file mode 100644
index 000000000..a64fbee83
--- /dev/null
+++ b/wavetone/agent-harness/cli_anything/wavetone/tests/helpers.py
@@ -0,0 +1,18 @@
+from __future__ import annotations
+
+import math
+import struct
+import wave
+from pathlib import Path
+
+
+def make_wav(path: Path, freq: float = 440.0, duration: float = 0.5, sample_rate: int = 8000) -> Path:
+ frames = int(duration * sample_rate)
+ with wave.open(str(path), "wb") as handle:
+ handle.setnchannels(1)
+ handle.setsampwidth(2)
+ handle.setframerate(sample_rate)
+ for idx in range(frames):
+ sample = int(16000 * math.sin(2 * math.pi * freq * idx / sample_rate))
+ handle.writeframes(struct.pack("<h", sample))
+ return path
diff --git a/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py b/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py
index cae1da697..ea82b63f5 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py
@@ -1,10 +1,7 @@
from __future__ import annotations
import json
-import math
import subprocess
-import struct
-import wave
from pathlib import Path
import pytest
@@ -22,22 +19,11 @@ from cli_anything.wavetone.core.project import (
update_analysis,
)
from cli_anything.wavetone.core.session import append_event, load_events
+from cli_anything.wavetone.tests.helpers import make_wav
from cli_anything.wavetone.utils import wavetone_backend
from cli_anything.wavetone.wavetone_cli import cli
-def make_wav(path: Path, freq: float = 440.0, duration: float = 0.25, sample_rate: int = 8000) -> Path:
- frames = int(duration * sample_rate)
- with wave.open(str(path), "wb") as handle:
- handle.setnchannels(1)
- handle.setsampwidth(2)
- handle.setframerate(sample_rate)
- for idx in range(frames):
- sample = int(16000 * math.sin(2 * math.pi * freq * idx / sample_rate))
- handle.writeframes(struct.pack("<h", sample))
- return path
-
-
def test_create_project_manifest(tmp_path: Path) -> None:
wav = make_wav(tmp_path / "tone.wav")
project = create_project(wav, name="Tone Test")
@@ -152,6 +138,36 @@ def test_ffprobe_uses_single_show_entries_argument(tmp_path: Path, monkeypatch:
assert info["sample_rate"] == 44100
+def test_ffprobe_handles_non_numeric_metadata(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ audio = tmp_path / "tone.mp3"
+ audio.write_bytes(b"mp3")
+
+ monkeypatch.setattr(audio_core.shutil, "which", lambda name: "ffprobe")
+
+ def fake_run(args: list[str], **kwargs: object) -> subprocess.CompletedProcess[str]:
+ stdout = json.dumps(
+ {
+ "streams": [{"codec_type": "audio", "sample_rate": "N/A"}],
+ "format": {
+ "duration": "N/A",
+ "format_name": "mp3",
+ "bit_rate": "N/A",
+ "size": "N/A",
+ },
+ }
+ )
+ return subprocess.CompletedProcess(args, 0, stdout=stdout)
+
+ monkeypatch.setattr(audio_core.subprocess, "run", fake_run)
+
+ info = audio_core._probe_ffprobe(audio)
+
+ assert info["duration_seconds"] is None
+ assert info["sample_rate"] is None
+ assert info["bit_rate"] is None
+ assert info["size_bytes"] == audio.stat().st_size
+
+
def test_session_event_log(tmp_path: Path) -> None:
session_path = tmp_path / "session.json"
append_event(session_path, "created", {"project": "demo"})
@@ -215,3 +231,10 @@ def test_wavetone_launch_fails_on_early_nonzero_exit(monkeypatch: pytest.MonkeyP
data = json.loads(result.output)
assert data["ok"] is False
assert data["launch"]["exit_code"] == 42
+
+
+def test_launch_requires_windows(monkeypatch: pytest.MonkeyPatch) -> None:
+ monkeypatch.setattr(wavetone_backend.platform, "system", lambda: "Linux")
+
+ with pytest.raises(RuntimeError, match="requires Windows"):
+ wavetone_backend.launch_wavetone()
diff --git a/wavetone/agent-harness/cli_anything/wavetone/tests/test_full_e2e.py b/wavetone/agent-harness/cli_anything/wavetone/tests/test_full_e2e.py
index c3040df3f..695840fcf 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/tests/test_full_e2e.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/tests/test_full_e2e.py
@@ -1,32 +1,18 @@
from __future__ import annotations
import json
-import math
import os
import shutil
-import struct
import subprocess
import sys
-import wave
from pathlib import Path
import pytest
+from cli_anything.wavetone.tests.helpers import make_wav
from cli_anything.wavetone.utils import wavetone_backend
-def make_wav(path: Path, freq: float = 440.0, duration: float = 0.5, sample_rate: int = 8000) -> Path:
- frames = int(duration * sample_rate)
- with wave.open(str(path), "wb") as handle:
- handle.setnchannels(1)
- handle.setsampwidth(2)
- handle.setframerate(sample_rate)
- for idx in range(frames):
- sample = int(16000 * math.sin(2 * math.pi * freq * idx / sample_rate))
- handle.writeframes(struct.pack("<h", sample))
- return path
-
-
def _resolve_cli(name: str) -> list[str]:
"""Resolve installed CLI command; fall back to python -m for development."""
force = os.environ.get("CLI_ANYTHING_FORCE_INSTALLED", "").strip() == "1"
diff --git a/wavetone/agent-harness/cli_anything/wavetone/utils/wavetone_backend.py b/wavetone/agent-harness/cli_anything/wavetone/utils/wavetone_backend.py
index 076fbe4d2..33af7de43 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/utils/wavetone_backend.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/utils/wavetone_backend.py
@@ -103,6 +103,9 @@ def launch_wavetone(
wait_seconds: float = 0.0,
terminate: bool = False,
) -> dict[str, Any]:
+ if platform.system().lower() != "windows":
+ raise RuntimeError("WaveTone launch requires Windows")
+
exe = find_wavetone(executable)
args = [str(exe)]
audio: Path | None = None
diff --git a/wavetone/agent-harness/cli_anything/wavetone/wavetone_cli.py b/wavetone/agent-harness/cli_anything/wavetone/wavetone_cli.py
index 1d7a267f9..da08c128c 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/wavetone_cli.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/wavetone_cli.py
@@ -124,7 +124,7 @@ def project_new(ctx: click.Context, audio_path: str, output_path: str, name: str
try:
project = create_project(audio_path, name=name)
path = save_project(project, output_path)
- except (OSError, ValueError) as exc:
+ except (OSError, RuntimeError, ValueError) as exc:
raise click.ClickException(str(exc)) from exc
emit({"ok": True, "project_path": str(path), "project": project_summary(project)}, ctx_json(ctx))
diff --git a/wavetone/agent-harness/setup.py b/wavetone/agent-harness/setup.py
index c1a58e96d..82c9ecd60 100644
--- a/wavetone/agent-harness/setup.py
+++ b/wavetone/agent-harness/setup.py
@@ -43,7 +43,7 @@ setup(
"cli-anything-wavetone=cli_anything.wavetone.wavetone_cli:main",
],
},
- package_data={"cli_anything.wavetone": ["skills/*.md"]},
+ package_data={"cli_anything.wavetone": ["skills/SKILL.md", "skills/*.md"]},
include_package_data=True,
zip_safe=False,
)