fix(stremio_mcp): guard ANDROID_TV_PORT parsing with bounded _env_int - #27
Merged
Conversation
Replace the import-time int(os.getenv(...)) parse with the project's existing _env_int helper so empty, quoted, nonnumeric, and out-of-range values fall back to 5555 instead of crashing server startup. Valid ports 1..65535 are preserved. Warnings name only the variable, never the raw value. Regression coverage exercises import-time parsing in a fresh subprocess for absent, empty, whitespace, quoted, nonnumeric, negative, zero, above-range, valid custom, and boundary ports. Fail-before (AndroidTvPortConfigTests, defective int() parse): Ran 10 tests in 7.091s FAILED (failures=7) empty/quoted/whitespace/nonnumeric: ValueError on import negative/zero/70000: accepted invalid ports instead of defaulting Pass-after (same selectors, _env_int(..., 5555, 1, 65535)): Ran 10 tests in 7.144s OK Full suite after: Ran 132 tests … OK; compileall OK; uv build OK.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Validate and ship the committed ANDROID_TV_PORT startup guard for stremio-mcp before the 0.2.0 release path. The defect was an unguarded import-time int(os.getenv("ANDROID_TV_PORT", "5555")) that crashed the entire MCP server on empty, quoted, nonnumeric, or otherwise invalid values, and accepted out-of-range ports.
Captain-approved scope (already committed on this branch; do not expand):
What Changed
int(os.getenv("ANDROID_TV_PORT", "5555"))parse with_env_int("ANDROID_TV_PORT", 5555, 1, 65535), so empty, quoted, whitespace, non-numeric, or out-of-range values fall back to the default 5555 instead of crashing MCP server startup, while valid custom ports (including boundaries 1 and 65535) are preserved.CHANGELOG.mdwith no version bump or release metadata changes.Risk Assessment
✅ Low: A single, well-bounded one-line fix replacing an unguarded int parse with the existing validated _env_int helper, backed by focused subprocess regression tests and an unreleased-only changelog entry, all matching the authoritative intent.
Testing
Baseline locked setup, the 10 focused subprocess regression tests, and the full 132-test suite all pass. I then demonstrated the actual end-user surface by importing the server module across every ANDROID_TV_PORT value category: the fixed code survives import (exit 0) for all invalid/out-of-range values, falls back to 5555, and warns with the variable name only — confirmed the raw secret value never appears in a warning — while valid custom (37139) and boundary ports (1, 65535) pass through unchanged. A before/after contrast confirms the old unguarded parse crashed with ValueError on empty/whitespace/quoted/nonnumeric input and silently accepted 0/70000, matching the reported defect. Worktree left clean.
Evidence: Fixed server import behavior across all ANDROID_TV_PORT values
absent/empty -> 5555 (exit 0, no warn); whitespace/quoted/abc -> 5555 + 'is not an integer' warn (exit 0); -1/0/70000 -> 5555 + 'is outside 1-65535' warn (exit 0); 37139 -> 37139; 1 -> 1; 65535 -> 65535. Raw value 37139 never appears in any warning line.Evidence: Before-fix defect: old int(os.getenv(...)) parse crashed / accepted out-of-range
empty/' '/'"37139"'/abc -> ValueError: invalid literal for int() (exit 1, import crash); 0 -> 0 and 70000 -> 70000 (exit 0, out-of-range silently accepted).Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
uv sync --locked(locked setup)uv run --locked python -m unittest tests.test_stremio_mcp.AndroidTvPortConfigTests -v— 10 focused subprocess tests OKuv run --locked python -m unittest discover -s tests— full suite 132 tests OKManual end-user import probe: imported stremio_mcp with ANDROID_TV_PORT set to absent/empty/whitespace/quoted/nonnumeric/-1/0/70000/37139/1/65535, recording exit code, resulting port, and warning textBefore/after contrast: ran the old unguardedint(os.getenv('ANDROID_TV_PORT','5555'))parse to reproduce the ValueError crash and out-of-range acceptanceVerified via grep that the raw configured value 37139 never leaks into any fallback warning✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.