Repository navigation
Conversation
|
| if providers.is_connected(active_provider): | ||
| return True |
There was a problem hiding this comment.
Keyless commands reject
.env settings
If LLM_PROVIDER=ollama is set in .env, with no saved provider or OLLAMA_API_KEY, _require_auth() rejects a valid keyless setup. Settings reads .env, but is_connected() checks only saved config and os.environ. All four headless commands stop and ask for a key that Ollama does not need. This also breaks runs that previously passed with an OpenHack key.
Use the resolved provider selection for the keyless check and add a .env regression test.
Prompt To Fix With AI
This is a comment left during a code review.
Path: openhack/__main__.py
Line: 30-31
Comment:
**Keyless commands reject `.env` settings**
If `LLM_PROVIDER=ollama` is set in `.env`, with no saved provider or `OLLAMA_API_KEY`, `_require_auth()` rejects a valid keyless setup. `Settings` reads `.env`, but `is_connected()` checks only saved config and `os.environ`. All four headless commands stop and ask for a key that Ollama does not need. This also breaks runs that previously passed with an OpenHack key.
Use the resolved provider selection for the keyless check and add a `.env` regression test.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| monkeypatch.setattr(settings, "llm_provider", "openai") | ||
| monkeypatch.setattr(settings, "openhack_api_key", None) | ||
| monkeypatch.delenv("OPENAI_API_KEY", raising=False) | ||
| monkeypatch.setattr("openhack.provider_auth.all_credentials", lambda: {}) |
There was a problem hiding this comment.
Saved credentials break the test
This test patches all_credentials(), but is_connected() calls get_credential(), which reads saved credentials directly. If a developer has a saved OpenAI API key or ChatGPT login, _require_auth() returns True and the test fails despite working code.
Patch openhack.providers.get_credential to return None, or give the test an isolated credential store.
| monkeypatch.setattr("openhack.provider_auth.all_credentials", lambda: {}) | |
| monkeypatch.setattr("openhack.providers.get_credential", lambda name: None) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/test_cli_dispatch.py
Line: 123
Comment:
**Saved credentials break the test**
This test patches `all_credentials()`, but `is_connected()` calls `get_credential()`, which reads saved credentials directly. If a developer has a saved OpenAI API key or ChatGPT login, `_require_auth()` returns `True` and the test fails despite working code.
Patch `openhack.providers.get_credential` to return `None`, or give the test an isolated credential store.
```suggestion
monkeypatch.setattr("openhack.providers.get_credential", lambda name: None)
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
Fixes #22.
Headless entry points (
--scan,--hack,--plan,--agent) previously gated execution strictly onsettings.openhack_api_key. When using a BYOK provider (such as OpenAI, Anthropic, Ollama, etc.), model calls only use the provider's resolved credentials and never touchopenhack_api_key. Gating onopenhack_api_keyalone prevented using BYOK providers in CI or headless environments without an OpenHack account key.Changes
openhack_api_keygate across_cmd_scan,_cmd_hack,_cmd_plan, and_cmd_agentwith a unified_require_auth()helper inopenhack/__main__.py.settings.llm_provider != "openhack"), verify connection viaproviders.is_connected(settings.llm_provider). If credentials or required environment variables are missing, display an informative error pointing to the specific environment variable required.openhack/config.py, mapped user-savedproviderconfig toLLM_PROVIDERin_build_settingsso persisted provider choices apply to headless scans.openhack/providers.py, allowed keyless local providers whenLLM_PROVIDERis set in environment.tests/test_cli_dispatch.pyverifying auth handling for both connected/disconnected BYOK providers and logged in/out OpenHack accounts.