caskroom: filter out casks without valid installation metadata by koddsson · Pull Request #21630 · Homebrew/brew

@koddsson @claude

`Caskroom.casks` enumerates all directories in the Caskroom path but
doesn't verify each cask is actually installed. When a cask directory
exists but its `.metadata` directory is missing or corrupt,
`installed_version` returns `nil`, causing `brew info --installed
--json=v2` to include casks with `installed: null`.

Add `.select(&:installed?)` to filter out these ghost entries so the
method only returns genuinely installed casks, matching its documented
behaviour of "Get all installed casks".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>