Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(loaders): redact a scheme's labelled credential and stop tests reaching the network

cgycoreyd81b0ad9e5f6
diff --git a/agent/backtest/loader_health.py b/agent/backtest/loader_health.py
index 9d2fec148..b6f4f8050 100644
--- a/agent/backtest/loader_health.py
+++ b/agent/backtest/loader_health.py
@@ -67,7 +67,9 @@ _PATH_RE = re.compile(r"/[^\s]+")
_CREDENTIAL_RE = re.compile(
r"[\"']?\b[\w-]*(?:token|secret|password|passwd|api[-_]?key|private[-_]?key)[\w-]*[\"']?"
r"\s*[=:]\s*(?:\"(?:\\.|[^\"])*(?:\"|$)|'(?:\\.|[^'])*(?:'|$)|\S+)"
- r"|\b(?:bearer|basic)\s+\S+"
+ # A scheme owns the rest of the warning: its value may be labelled
+ # (``Bearer token: VALUE``), and stopping at the label left the value behind.
+ r"|\b(?:bearer|basic)\s+\S+(?:\s+\S+)*"
r"|\b(?:gh[pousr]_|github_pat_|sk-|xox[baprs]-)[\w-]{8,}",
re.IGNORECASE,
)
diff --git a/agent/tests/test_loader_health.py b/agent/tests/test_loader_health.py
index 234375eb2..66f59cb5d 100644
--- a/agent/tests/test_loader_health.py
+++ b/agent/tests/test_loader_health.py
@@ -14,6 +14,20 @@ from backtest import loader_health as health
TODAY = date(2026, 9, 28)
[email protected](autouse=True)
+def _registered_loaders():
+ """Register the real loaders before a test stubs one of them.
+
+ Registration fires on first use and assigns into ``LOADER_REGISTRY``
+ unconditionally, so a stub installed for a real source before that first
+ use is silently replaced by the real loader and the test reaches the live
+ network instead of the stub.
+ """
+ from backtest.loaders.registry import _ensure_registered
+
+ _ensure_registered()
+
+
def frame(age=0):
return pd.DataFrame(
{"open": [10.0], "high": [12.0], "low": [9.0], "close": [11.0], "volume": [100.0]},
@@ -292,6 +306,25 @@ def test_sanitizer_redacts_header_and_token_shaped_credentials():
assert health.sanitize_evidence("token sk-abcdefghijklmnop rejected") == "token <redacted> rejected"
+ "message,expected",
+ [
+ # The scheme arm used to stop at the label and leave its value in the
+ # report artifact CI uploads.
+ ("Authorization: Bearer token: S3CR3TVALUE", "Authorization: <redacted>"),
+ ("Bearer password: hunter2", "<redacted>"),
+ ],
+)
+def test_sanitizer_redacts_a_schemes_labelled_value(message, expected):
+ assert health.sanitize_evidence(message) == expected
+
+
+def test_sanitizer_does_not_strand_a_scheme_behind_a_keyword_label():
+ """A keyword chain must not hide the scheme's value from the scheme arm."""
+ cleaned = health.sanitize_evidence("password: token: Bearer S3CR3TVALUE")
+ assert cleaned is not None and "S3CR3TVALUE" not in cleaned
+
+
def test_sanitizer_truncates_and_collapses_whitespace():
assert len(health.sanitize_evidence("x" * 500)) == health.EVIDENCE_TEXT_LIMIT
assert health.sanitize_evidence("two\n\tlines here ") == "two lines here"