Skip to content

refactor/fix: code quality, filter fixes, expand hints, smoke-v3#25

Merged
chenliuyun merged 10 commits intomainfrom
fix/post-review-improvements
Apr 21, 2026
Merged

refactor/fix: code quality, filter fixes, expand hints, smoke-v3#25
chenliuyun merged 10 commits intomainfrom
fix/post-review-improvements

Conversation

@chenliuyun
Copy link
Copy Markdown
Collaborator

Summary

Post-review improvements across three areas: code quality refactoring, two bug fixes, and smoke-v3 test infrastructure.

Refactoring

  • Extract exitWithError() helper in output.ts (string or options overload) — eliminates ~17 repeated isJsonMode() ? emitJsonError() : console.error() + process.exit() blocks across batch.ts, mcp.ts, devices.ts
  • Replace private isJsonRequested() duplicates in index.ts and config.ts with the shared isJsonMode() import

Bug fixes

  • field-aliases.ts: remove 'category' from controlType aliases — prevents collision where --filter category=X could match controlType instead of the physical/IR classification field
  • devices.ts: add controlType to LIST_FILTER_CANONICAL, LIST_FILTER_TO_RUNTIME, and the matchesFilter entry shape so --filter controlType=X actually works (was documented but silently ignored)
  • mcp.ts: remove dead loadConfig import; replace EOF-only stdin handler with unified graceful shutdown (SIGTERM + SIGINT + stdin end, isShuttingDown guard, 30 s force-exit timeout)

Feature

  • devices describe now shows a tip line for device types that support devices expand (Air Conditioner, Curtain, Curtain 3, Blind Tilt, Relay Switch 2PM); --json output includes an optional expandHint: { command, flags, example } field

Tests

  • devices.test.ts: --filter controlType=Bot, --filter roomName=Living, read-only device still rejected with --allow-unknown-device
  • mcp.test.ts: send_command case normalization (turnonturnOn)
  • mcp-stdio.test.ts: MCP stdio graceful shutdown (stdin EOF, SIGTERM)

smoke-v3 fixes

  • analyze.py: remove duplicate if dim == "real.mutate" branch that was double-counting alongside meta.real_mutate
  • runner.py: extract check_real_mutate_success(); add --json flag to allowlist mutate commands; validate ok:true in CLI envelope; add meta={real_mutate:True} so the counter in analyze.py fires

Test plan

  • npx vitest run — all tests pass (1 pre-existing events.test.ts failure unrelated to these changes)
  • npx tsc --noEmit — no type errors
  • switchbot devices describe <acId> — shows expand tip at the end
  • switchbot devices describe <acId> --json | jq .expandHint — returns { command, flags, example }
  • switchbot devices list --filter controlType=Bot — returns matching devices

chenliuyun added 10 commits April 21, 2026 14:16
…xes, MCP shutdown, expand hints

- output.ts: add exitWithError() overload (string | options) to eliminate ~17
  repeated isJsonMode()/emitJsonError()/process.exit() blocks
- index.ts, config.ts: replace private isJsonRequested() duplicates with
  shared isJsonMode() import
- field-aliases.ts: remove 'category' from controlType aliases to prevent
  collision with the standalone category filter key
- devices.ts: add controlType to LIST_FILTER_CANONICAL / LIST_FILTER_TO_RUNTIME
  / matchesFilter entry shape so --filter controlType=X works; replace 3 inline
  error blocks with exitWithError(); add EXPAND_HINTS map and tip line in
  renderCatalogEntry() + expandHint field in --json output for device types
  supported by 'devices expand' (AC, Curtain, Curtain 3, Blind Tilt, Relay
  Switch 2PM)
- batch.ts: replace FilterSyntaxError and no-targets error blocks with
  exitWithError()
- mcp.ts: remove dead loadConfig import; replace 2 inline error blocks with
  exitWithError(); replace EOF-only stdin handler with graceful shutdown
  (SIGTERM/SIGINT + stdin end, isShuttingDown guard, 30s force-exit timeout)
- devices.test.ts: --filter controlType=Bot (verifies the new canonical key),
  --filter roomName=Living (verifies alias works + null roomName excluded),
  read-only device with --allow-unknown-device still rejected with exit 2
- mcp.test.ts: send_command case normalization (turnon → turnOn)
- mcp-stdio.test.ts: MCP stdio graceful shutdown (stdin EOF, SIGTERM) exits
  cleanly without hanging
… suite

- analyze.py: remove redundant 'if dim == "real.mutate"' branch that was
  double-counting alongside meta.real_mutate; meta.real_mutate is now the
  sole counter
- runner.py: extract check_real_mutate_success(); add --json to allowlist
  mutate commands so output is parseable; check ok:true in the CLI envelope
  instead of string-matching statusCode; add meta={real_mutate:True} so
  analyze.py counter fires correctly
- .gitignore: ignore smoke-v3/results/
- smoke-v3/: initial commit of the v3 smoke test suite (runner, analyzer,
  fuzzer, common utilities)
@chenliuyun chenliuyun merged commit c66b66b into main Apr 21, 2026
4 checks passed
@chenliuyun chenliuyun deleted the fix/post-review-improvements branch April 21, 2026 09:50
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.

1 participant