Skip to content

test: coverage for build_args_str() and load_env_file() inline comment stripping#3

Open
thor-guardrail wants to merge 2 commits into
digitalforgeca:mainfrom
thor-guardrail:test/shell-utils-secrets-coverage
Open

test: coverage for build_args_str() and load_env_file() inline comment stripping#3
thor-guardrail wants to merge 2 commits into
digitalforgeca:mainfrom
thor-guardrail:test/shell-utils-secrets-coverage

Conversation

@thor-guardrail
Copy link
Copy Markdown

Summary

Adds test coverage for the two new behaviours introduced in PR #2.

Depends on PR #2 (fix/build-args-dedup-env-file-comments) — merge that first.

1. tests/test_shell_utils.py (new file) — build_args_str() and run_cmd()

Tests cover:

  • None / empty dict → empty string
  • Single and multiple simple args
  • Values with spaces → shell-quoted (prevents silent corruption with shell=True)
  • Values with dollar signs → quoted (prevents shell variable expansion)
  • Values with = (connection strings, base64) → survive round-trip
  • Simple alphanumeric values → not over-quoted by shlex
  • Integer values coerced to string

Also adds smoke tests for run_cmd() which had zero coverage: stdout capture, non-zero exit, cwd, and env merging.

2. tests/test_secrets.pyload_env_file() inline comment stripping (4 new cases)

  • Unquoted value with # comment → comment stripped
  • Unquoted value with \t# comment → comment stripped
  • Quoted value with # inside → hash preserved (PASSWORD="hunter#2")
  • Quoted value with trailing comment → value extracted cleanly

Thor (Guardrail) and others added 2 commits April 22, 2026 14:02
…line comment parsing

Two improvements:

1. _build_args_str() was duplicated identically in both
   dds/providers/azure/container.py and dds/builders/docker.py.
   Moved the canonical implementation to dds/utils/shell.build_args_str()
   (with shell-quoting via shlex.quote — see PR digitalforgeca#1 for the safety fix).
   Both original sites now import and delegate to the shared version.
   Module-level _build_args_str aliases kept for backward compatibility.

2. load_env_file() in dds/secrets.py did not strip inline comments from
   unquoted values, so a line like:
     DATABASE_URL=postgres://localhost/mydb  # local dev only
   would produce 'postgres://localhost/mydb  # local dev only' as the value.
   This is incorrect — standard .env file parsers (dotenv et al.) strip
   inline comments from unquoted values. Quoted values are left untouched
   (the comment is considered part of the value when quoted).

   Added stripping for ' #' and '\t#' comment separators on unquoted values.
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