Skip to content

Test fixes for MST metadata expectations and User-Agent env leak#788

Open
vikrantpuppala wants to merge 2 commits into
mainfrom
fix/useragent-test-env-leak
Open

Test fixes for MST metadata expectations and User-Agent env leak#788
vikrantpuppala wants to merge 2 commits into
mainfrom
fix/useragent-test-env-leak

Conversation

@vikrantpuppala
Copy link
Copy Markdown
Contributor

@vikrantpuppala vikrantpuppala commented May 15, 2026

Summary

Two independent test-only fixes bundled together because both were uncovered while investigating CI red on test-with-coverage.

1. Flip TestMstMetadata to assert blocked behavior

The four tests/e2e/test_transactions.py::TestMstMetadata::test_cursor_*_in_mst tests, added in #775, were written speculatively expecting Thrift Get{Catalogs,Schemas,Tables,Columns} RPCs to succeed inside an active multi-statement transaction. The server's MST guard is intentionally designed to reject these ("... is not supported within a multi-statement transaction."), matching the small allowlist pattern documented in TestMstBlockedSql.

  • Renamed the four *_in_mst tests to *_blocked and rewrote them to assert the expected DatabaseError via a shared _assert_metadata_rpc_blocked helper.
  • Deleted the two *_non_transactional_after_concurrent_* freshness tests outright — their premise ("Thrift RPCs bypass MST and see concurrent DDL") is no longer valid, so there's nothing meaningful left to assert.
  • Updated the TestMstMetadata and TestMstBlockedSql docstrings to reflect actual server behavior.

One subtle difference vs TestMstBlockedSql's SQL-form blocks: the Get* rejection happens at the MST guard before reaching the transaction, so the active txn remains usable after a blocked Get* (whereas SQL-form blocks abort the txn). The shared helper documents this.

2. Fix test_useragent_header environment-sensitivity

tests/unit/test_session.py::test_useragent_header strictly asserts ("User-Agent", "<name>/<version>") in http_headers. When run inside any AI-agent shell that databricks.sql.common.agent.KNOWN_AGENTS knows about (e.g. Claude Code sets CLAUDECODE=1), session.py:68-70 appends agent/<product> to the header and the in check fails. CI runners don't set agent env vars, so this passed there — it's an environment-sensitivity bug rather than a code regression.

The fix mirrors the pattern in tests/unit/test_agent_detection.py:42-49: monkeypatch.delenv every known agent env var before the assertion. Iterating KNOWN_AGENTS keeps the cleared list automatically in sync if new agents are added to src/databricks/sql/common/agent.py.

Test plan

  • pytest tests/e2e/test_transactions.py::TestMstMetadata against dogfood: 4 passed in 33.67s
  • pytest tests/unit/test_session.py::TestSession::test_useragent_header passes inside a Claude Code shell (was failing before the fix)
  • Full local unit suite: 601 passed, 4 skipped
  • CI test-with-coverage (e2e + coverage) — verifying via this PR

This pull request and its description were written by Isaac.

Clear all KNOWN_AGENTS env vars in test_useragent_header before
connecting, mirroring the pattern in test_agent_detection.py. Without
this, running the test inside an AI-agent shell (e.g. Claude Code, which
sets CLAUDECODE=1) causes session.py to append " agent/<product>" to
the User-Agent and the strict `in` assertion fails. CI runners don't
set agent env vars so this passes there, but the test is environment-
sensitive locally.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
… MST

The TestMstMetadata tests were written speculatively expecting the
Thrift Get{Catalogs,Schemas,Tables,Columns} RPCs to succeed inside an
active multi-statement transaction. The server's MST guard now rejects
these RPCs with TRANSACTION_NOT_SUPPORTED ("... is not supported within
a multi-statement transaction."), matching the intentional design where
MST exposes a small allowlist of SQL forms.

Flip the four `*_in_mst` tests into `*_blocked` tests asserting the
expected DatabaseError. The two `*_non_transactional_after_concurrent_*`
freshness tests are deleted outright — their entire premise ("Thrift
RPCs bypass MST and see concurrent DDL") is no longer valid, so there
is nothing meaningful left to assert.

Note: the rejection happens at the MST guard before reaching the txn,
so the active transaction remains usable after a blocked Get* (unlike
SQL forms in TestMstBlockedSql, where the failure aborts the txn).
The shared helper documents this distinction.

Verified against dogfood: 4 passed in 33.67s.

Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala vikrantpuppala changed the title Fix test_useragent_header environment-sensitivity Test fixes for MST metadata expectations and User-Agent env leak May 15, 2026
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