Skip to content

fix(test): make no-provider tests robust against real ~/.caseforge.yaml#71

Merged
yuchou87 merged 2 commits into
mainfrom
fix/ask-test-no-provider
May 7, 2026
Merged

fix(test): make no-provider tests robust against real ~/.caseforge.yaml#71
yuchou87 merged 2 commits into
mainfrom
fix/ask-test-no-provider

Conversation

@yuchou87

@yuchou87 yuchou87 commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • TestAskCommand_FailsWhenNoProvider and TestAskCommand_Integration_NoProvider were flaky on machines with a real API key in ~/.caseforge.yaml. Clearing env vars didn't help because viper loads the config file first, and api_key in the file takes precedence over empty env vars.
  • AT-235 (conformance no LLM fails gracefully) had the same problem — the acceptance binary reads ~/.caseforge.yaml.

Fixes

  • TestAskCommand_FailsWhenNoProvider: call viper.Reset() + viper.Set("ai.provider", "noop") instead of relying on env var clearing
  • TestAskCommand_Integration_NoProvider: pass --config <tmp-noop.yaml> so initConfig() reads a controlled file instead of ~/.caseforge.yaml
  • AT-235: write a temp noop config yaml and pass it via --config flag

Test Plan

  • go test ./cmd/... -run TestAskCommand -count=1 — all 5 pass
  • ./scripts/acceptance.sh — AT-235 passes, zero other failures

yuchou87 added 2 commits May 7, 2026 21:18
TestAskCommand_FailsWhenNoProvider and TestAskCommand_Integration_NoProvider
were relying on env-var clearing, which doesn't work when ~/.caseforge.yaml
has a real api_key (config file takes precedence over empty env vars in viper).

- FailsWhenNoProvider: reset viper and set ai.provider=noop directly
- Integration_NoProvider: pass --config pointing to a temp noop-provider yaml
  so initConfig() reads that instead of ~/.caseforge.yaml

AT-235: same root cause — conformance --config <noop.yaml> forces the
"LLM provider not available" path regardless of the local config file.
Reviewer feedback on #71:
- TestAskCommand_Integration_NoProvider was leaving cfgFile set to a deleted
  temp path; subsequent rootCmd.Execute() calls in the same test binary
  printed "error reading config: no such file or directory" to stderr.
  Added cfgFile = "" to the cleanup closure.
- AT-235 noprov config was written to /tmp and leaked across runs. Moved to
  $WORKDIR so the existing trap rm cleans it up automatically.
- Switched '$NOPROV_CFG' (single-quotes inside double-quotes) to \"$NOPROV_CFG\"
  for idiomatic quoting consistency.
@yuchou87 yuchou87 merged commit 39cf4d4 into main May 7, 2026
1 check passed
@yuchou87 yuchou87 deleted the fix/ask-test-no-provider branch May 7, 2026 13:33
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