Skip to content

docs: document the 16 env vars code reads but .env.example never mentioned - #42

Merged
OkiriGabriel merged 1 commit into
open-devops-agent:mainfrom
Nitjsefnie-OSC:docs/document-env-vars-15
Aug 4, 2026
Merged

OkiriGabriel merged 1 commit into
open-devops-agent:mainfrom
Nitjsefnie-OSC:docs/document-env-vars-15

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

Description

Documents the 16 environment variables that code reads but .env.example never mentioned, and adds a test that fails when a new one appears — so the file cannot drift again.

Fixes #15

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • New platform/collector support

Platform/Component

  • Core Agent
  • Kubernetes
  • CI/CD (specify: ____________)
  • Cloud Provider (specify: ____________)
  • ArgoCD
  • Docker
  • API Server
  • Tools/Executor
  • Documentation
  • Tests

I derived the variable list rather than taking the issue's, and the issue is wrong on two counts and short on a third:

  • SLACK_BOT_TOKEN is already documented at .env.example:112-115 with a four-line comment — added since the issue was filed. No change made.
  • TESTING is not read by any Python code. grep -rn "TESTING" --include=*.py . finds only an allow-list entry in tests/test_ci_env_alignment.py; it is only set, by ci.yml. Documenting it in .env.example would advertise a test-harness flag as a production setting, so it is on the new test's allow-list with that reason recorded instead.
  • Six variables the issue missed are documented here: ARGOCD_INSECURE_SKIP_VERIFY, AZURE_STORAGE_ACCOUNT (distinct from the _URL the issue lists), SSH_CONNECT_TIMEOUT, and all four JIRA_PRIORITY_*.

Everything else the issue listed is correct and was followed. Defaults are read from the code, not guessed, and the two MINIO_* credentials are marked as secrets.

Also corrected docs/GETTING_STARTED.md, which documented JENKINS_USER and JENKINS_TOKEN — the code reads JENKINS_USERNAME and JENKINS_API_TOKEN (collectors/jenkins.py:17-18, tools/cicd_tools.py:21-22). Anyone following that guide got a silently unauthenticated Jenkins collector.

Testing

  • Unit tests added/updated
  • Integration tests pass
  • Manual testing performed
  • Tested with dummy data
  • Tested in production-like environment

tests/test_env_example_coverage.py walks the AST of every *.py for os.getenv / os.environ.get|setdefault|pop / os.environ[...] and compares against what .env.example declares. AST rather than grep, so the three obvious false positives are structurally impossible — and I proved each rather than asserting it: a commented-out os.getenv("X") never reaches the AST, a string that merely spells one out parses as a Constant, and self.environ.get("X") fails the exact-base match. All three were added to a file at once and the test stayed green.

Mutation-proven: adding os.getenv("ZZ_PROBE_VAR") to tools/safety.py produces

AssertionError: these environment variables are read by the code but have no `NAME=` line in .env.example …
    ZZ_PROBE_VAR  (read at tools/safety.py:87)

and removing it returns to green. It also failed against the real bug before the fix, naming all 16 variables.

The allow-list is a dict of name → reason, not a bare set, so an entry cannot be added without recording why. A second test fails if an allow-listed name ever does get documented, forcing the entry's removal. Three anti-vacuity guards: an empty scrape is an error, a known variable must be found, and every discovered name must be accounted for.

Test Configuration

OS: Debian 13
Python Version: 3.13.14
Kubernetes Version: n/a
Cloud Provider: n/a

pytest tests/ -v goes 162 → 164 passed, 2 skipped. flake8 clean. black --check . fails identically before and after — 67 files on a clean main, pre-existing and untouched; my new file is Black-clean, so the unchanged-count rose 14 → 15. The test-collectors, test-tools and docs job commands all pass.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Breaking Changes

None. Documentation and one new test file; no runtime code changed.

Additional Notes

Two behaviour bugs surfaced while doing this. Both are filed separately rather than fixed here, since each changes how the server starts:

Both are demonstrated in their issues by driving the real CLI, not inferred from reading the code. They change what this PR could honestly write in .env.example: FASTMCP_HOST/FASTMCP_PORT ship commented out with the hazard noted, because a .env.example people copy verbatim would otherwise manufacture #40 for every user; and HOST/PORT/UVICORN_WORKERS carry a caveat that they must be exported rather than set in .env.

One more thing worth knowing, not acted on: LOG_LEVEL, PAGERDUTY_TOKEN, PAGERDUTY_SERVICE_ID and the three AZURE_* credentials are in .env.example but read by no Python code — presumably by SDKs or unimplemented features. The new test deliberately does not assert that direction, since it would demand deleting live documentation.

Generated by Claude Opus 5 (brief, implementation, review)

Sixteen variables were read via os.getenv/os.environ with no entry in
.env.example, so their defaults silently won in production. Each is now
listed with its default (taken from the code), what it controls, and a
secret marker where it is a credential:

  HOST, UVICORN_WORKERS            devops_agent/cli.py
  FASTMCP_HOST, FASTMCP_PORT       devops_mcp/server.py
  STORAGE_CONTAINER                storage/factory.py
  MINIO_ENDPOINT/_ACCESS_KEY/_SECRET_KEY  storage/factory.py
  AZURE_STORAGE_ACCOUNT_URL        storage/factory.py
  AZURE_STORAGE_ACCOUNT            storage/azure_storage.py
  ARGOCD_INSECURE_SKIP_VERIFY      collectors/argocd.py
  SSH_CONNECT_TIMEOUT              tools/ssh_utils.py
  JIRA_PRIORITY_CRITICAL/_HIGH/_MEDIUM/_LOW  tools/jira_tools.py

FASTMCP_HOST/FASTMCP_PORT ship commented out: the server seeds them with
os.environ.setdefault, so a value in .env would silently override the
CLI's --host/--port.

tests/test_env_example_coverage.py keeps the file honest. It walks the
tree with ast, collects every string-literal name passed to os.getenv,
os.environ.get/setdefault/pop or os.environ[...], and fails naming any
that has no `NAME=` line in .env.example. Parsing the AST rather than
grepping means a commented-out or stringified lookup cannot trigger a
false failure. TESTING is on an allow-list with the reason it stays out
(a CI-only harness flag), and a second test fails if an allow-list entry
ever becomes documented, so the list cannot rot.

Also corrects JENKINS_USER/JENKINS_TOKEN to the names the code actually
reads (JENKINS_USERNAME/JENKINS_API_TOKEN) in docs/GETTING_STARTED.md.

Refs open-devops-agent#15

Co-Authored-By: Claude Opus 5 <[email protected]>
@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Reviewed — CI is green across all checks. Env var documentation and drift-prevention test are solid. Merging to dev, then main.

@OkiriGabriel
OkiriGabriel merged commit 6886566 into open-devops-agent:main Aug 4, 2026
10 checks passed
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.

Document undocumented environment variables referenced in code

2 participants