Skip to content

Commit 119d970

Browse files
committed
make git default metadata stricter
1 parent 386831e commit 119d970

5 files changed

Lines changed: 50 additions & 27 deletions

File tree

py/src/braintrust/framework.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,9 @@ class Evaluator(Generic[Input, Output, Expected]):
397397

398398
git_metadata_settings: GitMetadataSettings | None = None
399399
"""
400-
Optional settings for collecting git metadata. By default, will collect all
401-
git metadata fields allowed in org-level settings.
400+
Optional settings for collecting git metadata. By default, defers entirely
401+
to org-level settings returned by the control plane; no git metadata is
402+
collected if the org has not configured any.
402403
"""
403404

404405
repo_info: RepoInfo | None = None
@@ -863,7 +864,7 @@ async def EvalAsync(
863864
summarized and compared to this experiment.
864865
:param base_experiment_id: An optional experiment id to use as a base. If specified, the new experiment will be
865866
summarized and compared to this experiment. This takes precedence over `base_experiment_name` if specified.
866-
:param git_metadata_settings: Optional settings for collecting git metadata. By default, will collect git metadata fields allowed in org-level settings, excluding diff content unless the org opts in.
867+
:param git_metadata_settings: Optional settings for collecting git metadata. By default, defers to org-level settings returned by the control plane.
867868
:param repo_info: Optionally explicitly specify the git metadata for this experiment. This takes precedence over `git_metadata_settings` if specified.
868869
:param error_score_handler: Optionally supply a custom function to specifically handle score values when tasks or scoring functions have errored.
869870
:param description: An optional description for the experiment.
@@ -991,7 +992,7 @@ def Eval(
991992
summarized and compared to this experiment.
992993
:param base_experiment_id: An optional experiment id to use as a base. If specified, the new experiment will be
993994
summarized and compared to this experiment. This takes precedence over `base_experiment_name` if specified.
994-
:param git_metadata_settings: Optional settings for collecting git metadata. By default, will collect git metadata fields allowed in org-level settings, excluding diff content unless the org opts in.
995+
:param git_metadata_settings: Optional settings for collecting git metadata. By default, defers to org-level settings returned by the control plane.
995996
:param repo_info: Optionally explicitly specify the git metadata for this experiment. This takes precedence over `git_metadata_settings` if specified.
996997
:param error_score_handler: Optionally supply a custom function to specifically handle score values when tasks or scoring functions have errored.
997998
:param description: An optional description for the experiment.

py/src/braintrust/git_fields.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,3 @@ def merge(cls, s1: "GitMetadataSettings", s2: "GitMetadataSettings") -> "GitMeta
4343
if not ret.fields:
4444
ret.collect = "none"
4545
return ret
46-
47-
48-
DEFAULT_GIT_METADATA_FIELDS = [
49-
"commit",
50-
"branch",
51-
"tag",
52-
"dirty",
53-
"author_name",
54-
"author_email",
55-
"commit_message",
56-
"commit_time",
57-
]
58-
59-
60-
def default_git_metadata_settings() -> GitMetadataSettings:
61-
return GitMetadataSettings(
62-
collect="some",
63-
fields=list(DEFAULT_GIT_METADATA_FIELDS),
64-
)

py/src/braintrust/gitutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import threading
66
from functools import lru_cache as _cache
77

8-
from .git_fields import GitMetadataSettings, RepoInfo, default_git_metadata_settings
8+
from .git_fields import GitMetadataSettings, RepoInfo
99

1010

1111
# https://stackoverflow.com/questions/48399498/git-executable-not-found-in-python
@@ -123,7 +123,7 @@ def truncate_to_byte_limit(input_string, byte_limit=65536):
123123

124124
def get_repo_info(settings: GitMetadataSettings | None = None):
125125
if settings is None:
126-
settings = default_git_metadata_settings()
126+
settings = GitMetadataSettings(collect="none")
127127

128128
if settings.collect == "none":
129129
return None

py/src/braintrust/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
PromptOptions,
6161
SpanAttributes,
6262
)
63-
from .git_fields import GitMetadataSettings, RepoInfo, default_git_metadata_settings
63+
from .git_fields import GitMetadataSettings, RepoInfo
6464
from .gitutil import get_past_n_ancestors, get_repo_info
6565
from .merge_row_batch import batch_items, merge_row_batch
6666
from .object import DEFAULT_IS_LEGACY_DATASET, ensure_dataset_record
@@ -2669,7 +2669,7 @@ def _check_org_info(state, org_info, org_name):
26692669
state.api_url = os.environ.get("BRAINTRUST_API_URL", orgs["api_url"])
26702670
state.proxy_url = os.environ.get("BRAINTRUST_PROXY_URL", orgs["proxy_url"])
26712671
state.git_metadata_settings = GitMetadataSettings(
2672-
**(orgs.get("git_metadata") or default_git_metadata_settings().as_dict())
2672+
**(orgs.get("git_metadata") or GitMetadataSettings(collect="none").as_dict())
26732673
)
26742674
break
26752675

py/src/braintrust/test_logger.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@
2424
)
2525
from braintrust.id_gen import OTELIDGenerator, get_id_generator
2626
from braintrust.logger import (
27+
BraintrustState,
2728
RemoteEvalParameters,
29+
_check_org_info,
2830
_extract_attachments,
2931
parent_context,
3032
render_message,
3133
render_mustache,
3234
stringify_exception,
3335
)
36+
from braintrust.git_fields import GitMetadataSettings
37+
from braintrust.gitutil import get_repo_info
3438
from braintrust.prompt import PromptChatBlock, PromptData, PromptMessage, PromptSchema
3539
from braintrust.test_helpers import (
3640
assert_dict_matches,
@@ -3699,3 +3703,40 @@ def failing_function():
36993703
logs = with_memory_logger.pop()
37003704
assert len(logs) == 1
37013705
_assert_test_exception_group_contents(logs[0].get("error", ""))
3706+
3707+
3708+
def test_check_org_info_no_git_metadata_defaults_to_none():
3709+
"""When org has no git_metadata, state.git_metadata_settings should be collect='none'."""
3710+
state = BraintrustState()
3711+
org_info = [
3712+
{
3713+
"id": "org-1",
3714+
"name": "org1",
3715+
"api_url": "https://api.example.com",
3716+
"proxy_url": "https://proxy.example.com",
3717+
}
3718+
]
3719+
_check_org_info(state, org_info, None)
3720+
assert state.git_metadata_settings.collect == "none"
3721+
3722+
3723+
def test_check_org_info_with_git_metadata_uses_server_settings():
3724+
"""When org provides git_metadata, it is used as-is."""
3725+
state = BraintrustState()
3726+
org_info = [
3727+
{
3728+
"id": "org-1",
3729+
"name": "org1",
3730+
"api_url": "https://api.example.com",
3731+
"proxy_url": "https://proxy.example.com",
3732+
"git_metadata": {"collect": "some", "fields": ["commit", "branch"]},
3733+
}
3734+
]
3735+
_check_org_info(state, org_info, None)
3736+
assert state.git_metadata_settings.collect == "some"
3737+
assert set(state.git_metadata_settings.fields) == {"commit", "branch"}
3738+
3739+
3740+
def test_get_repo_info_without_settings_returns_none():
3741+
"""Direct call to get_repo_info with settings=None should return None."""
3742+
assert get_repo_info(None) is None

0 commit comments

Comments
 (0)