Skip to content

test(hamode): add unit tests for Detect - #40

Merged
mar-schmidt merged 1 commit into
Podiom:masterfrom
alexsmolya:test/34-hamode-detect-coverage
Aug 24, 2026
Merged

mar-schmidt merged 1 commit into
Podiom:masterfrom
alexsmolya:test/34-hamode-detect-coverage

Conversation

@alexsmolya

Copy link
Copy Markdown
Contributor

Closes #34

This is a tests-only patch adding unit test coverage for hamode.Detect() in internal/hamode/hamode_test.go.

Covered Cases

Table-driven tests covering the three environment states for SUPERVISOR_TOKEN:

  1. unset: SUPERVISOR_TOKEN is unset in the process environment -> Detect() returns false
  2. set to non-empty: SUPERVISOR_TOKEN is set to "mock-supervisor-token" via t.Setenv -> Detect() returns true
  3. set to empty string: SUPERVISOR_TOKEN is set to "" via t.Setenv -> Detect() returns false

Validation

  • go test ./internal/hamode/... -v (3/3 subtests pass)
  • go test ./internal/autostart/... ./internal/claudeauth/... ./internal/discovery/... -v (pass)
  • gofmt -d ./internal/hamode/hamode_test.go (clean)
  • go vet ./internal/hamode/... (clean)
  • git diff --check (clean)

@mar-schmidt

Copy link
Copy Markdown
Collaborator

Thanks for this @alexsmolya — and welcome, this is your first contribution here.

First, an apology for the delay: your CI never ran. GitHub holds workflow runs from first-time contributors until a maintainer approves them, and nobody did, so this PR has been sitting since yesterday showing no checks through no fault of yours. I've approved it and CI is running now.

In the meantime I verified it locally rather than leaving you waiting on that:

  • go test ./internal/hamode/... -v -count=1 — 3/3 subtests pass
  • gofmt -l internal/hamode/hamode_test.go — clean
  • go vet ./internal/hamode/... — clean
  • Diff is exactly one added file, no production code touched

The thing I want to call out as a genuinely good decision: the unset case. Using os.LookupEnv to capture the previous value and restoring it via t.Cleanup, rather than reaching for t.Setenv, is the right call — t.Setenv can't express "this variable does not exist," which is the exact state Detect() needs to distinguish. It also means the test behaves correctly when the suite happens to run inside a real Home Assistant supervisor environment where SUPERVISOR_TOKEN is genuinely set. That's the failure mode most people miss.

Covering the empty-string case alongside it pins down the != "" semantics rather than just the presence check, which is the part of Detect() that could silently regress.

Leaving the merge to @mar-schmidt as maintainer.

@mar-schmidt
mar-schmidt merged commit da2d1bd into Podiom:master Aug 24, 2026
4 checks passed
@mar-schmidt

Copy link
Copy Markdown
Collaborator

Merged — thanks @alexsmolya.

I verified this rather than just trusting the green check: Detect is at 100% statement coverage, and I mutation-tested it by inverting the != "" condition in hamode.go — your test caught it. The three cases you picked (unset / non-empty / empty-string) are exactly the three real branches, and restoring the pre-existing env var in Cleanup rather than blindly unsetting is a nice touch that keeps the suite order-independent.

@alexsmolya
alexsmolya deleted the test/34-hamode-detect-coverage branch August 24, 2026 19:06
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.

internal/hamode.Detect has zero test coverage

2 participants