Skip to content

fix(agent): portable api.env path, declared rich dep, optional SSH HOST field#66

Merged
Hongjiseung-ROK merged 1 commit into
mainfrom
fix/agent-portability-hpc-audit
May 10, 2026
Merged

fix(agent): portable api.env path, declared rich dep, optional SSH HOST field#66
Hongjiseung-ROK merged 1 commit into
mainfrom
fix/agent-portability-hpc-audit

Conversation

@Hongjiseung-ROK

Copy link
Copy Markdown
Owner

Summary

  • replace the hard-coded api.env path with portable resolution logic in chemsmart.agent.providers
  • declare rich>=13,<15 as a direct runtime dependency because chemsmart.agent.cli imports it at module load
  • let SSH submission honor an optional HOST field while preserving the existing filename-stem fallback

Why

PR #65's HPC OS compatibility audit identified three portability defects on fork/main:

  1. provider credentials were tied to a maintainer-only absolute path
  2. rich only arrived transitively via textual
  3. remote submit assumed the server YAML filename stem was always the SSH host

User / developer impact

  • users can now provide credentials via --env-path, $CHEMSMART_API_ENV, ~/.chemsmart/api.env, or ./api.env
  • environments that install only base dependencies now declare rich explicitly
  • HPC users can set SERVER.HOST in server YAML when the SSH alias differs from the filename

Root cause

The agent code path baked in maintainer-local filesystem assumptions and relied on an undeclared transitive dependency.

Validation

  • AI_PROVIDER=openai python -m pytest -v tests/agent/test_providers_api_env_resolution.py tests/agent/test_transport_ssh_host_resolution.py
  • AI_PROVIDER=openai python -m pytest tests/agent/
  • black -l 79 .
  • isort --gitignore .
  • ruff check . --fix

Notes

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements dynamic resolution for the API environment file and adds support for explicit SSH hosts in server configurations. It also introduces the rich dependency and updates the test suite to reflect these changes. Review feedback recommends prioritizing local configuration files over global ones in the resolution logic to follow standard CLI conventions, along with a corresponding update to the test assertions.

Comment on lines +146 to +149
candidates = (
Path.home() / ".chemsmart" / "api.env",
Path.cwd() / "api.env",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current resolution logic prioritizes the global configuration file (~/.chemsmart/api.env) over the local one (./api.env). In standard CLI tool design, local (project-specific) configuration is expected to override global configuration. Swapping the order allows users to define project-specific API keys more easily. Additionally, Path.home() can raise a RuntimeError if the home directory is not resolvable; while rare, placing it second or handling it defensively would improve portability.

Suggested change
candidates = (
Path.home() / ".chemsmart" / "api.env",
Path.cwd() / "api.env",
)
candidates = (
Path.cwd() / "api.env",
Path.home() / ".chemsmart" / "api.env",
)

Comment on lines +66 to +80
def test_get_provider_prefers_home_api_env_over_cwd(monkeypatch, tmp_path):
dummy_provider = _configure_openai(monkeypatch)
home_dir = tmp_path / "home"
cwd_dir = tmp_path / "cwd"
cwd_dir.mkdir()
monkeypatch.setenv("HOME", str(home_dir))
monkeypatch.chdir(cwd_dir)

_write_api_env(home_dir / ".chemsmart" / "api.env", "home-key")
_write_api_env(cwd_dir / "api.env", "cwd-key")

provider = providers.get_provider()

assert isinstance(provider, dummy_provider)
assert provider.api_key == "home-key"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test asserts that the global configuration takes precedence over the local one. If the priority is reversed in chemsmart/agent/providers.py (as suggested), this test should be updated to verify that the local configuration (cwd-key) is preferred over the global one (home-key).

Suggested change
def test_get_provider_prefers_home_api_env_over_cwd(monkeypatch, tmp_path):
dummy_provider = _configure_openai(monkeypatch)
home_dir = tmp_path / "home"
cwd_dir = tmp_path / "cwd"
cwd_dir.mkdir()
monkeypatch.setenv("HOME", str(home_dir))
monkeypatch.chdir(cwd_dir)
_write_api_env(home_dir / ".chemsmart" / "api.env", "home-key")
_write_api_env(cwd_dir / "api.env", "cwd-key")
provider = providers.get_provider()
assert isinstance(provider, dummy_provider)
assert provider.api_key == "home-key"
def test_get_provider_prefers_cwd_api_env_over_home(monkeypatch, tmp_path):
dummy_provider = _configure_openai(monkeypatch)
home_dir = tmp_path / "home"
cwd_dir = tmp_path / "cwd"
cwd_dir.mkdir()
monkeypatch.setenv("HOME", str(home_dir))
monkeypatch.chdir(cwd_dir)
_write_api_env(home_dir / ".chemsmart" / "api.env", "home-key")
_write_api_env(cwd_dir / "api.env", "cwd-key")
provider = providers.get_provider()
assert isinstance(provider, dummy_provider)
assert provider.api_key == "cwd-key"

@Hongjiseung-ROK Hongjiseung-ROK marked this pull request as ready for review May 10, 2026 06:09
@Hongjiseung-ROK Hongjiseung-ROK merged commit f37038e into main May 10, 2026
@Hongjiseung-ROK Hongjiseung-ROK deleted the fix/agent-portability-hpc-audit branch May 10, 2026 06:09
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