Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# SMITH_HTTP_RETRY_BACKOFF_SECONDS=0.4

# Optional: Output truncation limit (characters)
# THANOS_LOCAL_MAX_OUTPUT_CHARS=10240
# SMITH_LOCAL_MAX_OUTPUT_CHARS=10240

# Optional: GitHub grep parallelism
# GITHUB_GREP_ENABLE_PARALLEL=true
Expand Down
9 changes: 7 additions & 2 deletions src/smith/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,13 @@ def parse_runtime_config(
api_version=resolved_api_version,
timeout_seconds=timeout,
max_output_chars=parse_int_env(
"THANOS_LOCAL_MAX_OUTPUT_CHARS",
default=max_output_chars or 10240,
"SMITH_LOCAL_MAX_OUTPUT_CHARS",
default=parse_int_env(
"THANOS_LOCAL_MAX_OUTPUT_CHARS",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Because the CLI is on alpha I think is ok to bring breaking changes, otherwise we should log a warning message that THANOS_LOCAL_MAX_OUTPUT_CHARS is deprecated.

default=max_output_chars or 10240,
min_value=256,
max_value=1_000_000,
),
min_value=256,
max_value=1_000_000,
),
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_parse_runtime_config_uses_defaults_when_env_not_set(monkeypatch: Any) -
"AZURE_DEVOPS_ORG",
"AZURE_DEVOPS_API_VERSION",
"AZURE_DEVOPS_TIMEOUT_SECONDS",
"SMITH_LOCAL_MAX_OUTPUT_CHARS",
"THANOS_LOCAL_MAX_OUTPUT_CHARS",
"SMITH_GREP_MAX_FILES",
"GITHUB_ORG",
Expand Down Expand Up @@ -126,6 +127,57 @@ def test_parse_runtime_config_uses_defaults_when_env_not_set(monkeypatch: Any) -
assert runtime.http_retry_backoff_seconds == pytest.approx(0.4)


def test_parse_runtime_config_prefers_smith_max_output_chars_env(monkeypatch: Any) -> None:
monkeypatch.setenv("SMITH_LOCAL_MAX_OUTPUT_CHARS", "12345")
monkeypatch.setenv("THANOS_LOCAL_MAX_OUTPUT_CHARS", "99999")

runtime = parse_runtime_config(
azdo_org="example",
api_version=None,
timeout_seconds=None,
max_output_chars=None,
github_api_url_default="https://api.github.com/",
github_api_version_default="2022-11-28",
gitlab_api_url_default="https://gitlab.com/api/v4/",
)

assert runtime.max_output_chars == 12345


def test_parse_runtime_config_supports_legacy_thanos_max_output_chars_env(monkeypatch: Any) -> None:
monkeypatch.delenv("SMITH_LOCAL_MAX_OUTPUT_CHARS", raising=False)
monkeypatch.setenv("THANOS_LOCAL_MAX_OUTPUT_CHARS", "54321")

runtime = parse_runtime_config(
azdo_org="example",
api_version=None,
timeout_seconds=None,
max_output_chars=None,
github_api_url_default="https://api.github.com/",
github_api_version_default="2022-11-28",
gitlab_api_url_default="https://gitlab.com/api/v4/",
)

assert runtime.max_output_chars == 54321


def test_parse_runtime_config_falls_back_to_legacy_var_when_new_var_is_invalid(monkeypatch: Any) -> None:
monkeypatch.setenv("SMITH_LOCAL_MAX_OUTPUT_CHARS", "invalid")
monkeypatch.setenv("THANOS_LOCAL_MAX_OUTPUT_CHARS", "54321")

runtime = parse_runtime_config(
azdo_org="example",
api_version=None,
timeout_seconds=None,
max_output_chars=None,
github_api_url_default="https://api.github.com/",
github_api_version_default="2022-11-28",
gitlab_api_url_default="https://gitlab.com/api/v4/",
)

assert runtime.max_output_chars == 54321


def test_parse_runtime_config_applies_timeout_and_backoff_overrides(monkeypatch: Any) -> None:
monkeypatch.setenv("AZURE_DEVOPS_TIMEOUT_SECONDS", "45")
monkeypatch.setenv("SMITH_GREP_MAX_FILES", "9000")
Expand Down
Loading