Skip to content

Commit 5bfcf1e

Browse files
committed
rename OperationContext field to user_agent_context
1 parent 0a7499d commit 5bfcf1e

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

src/PowerPlatform/Dataverse/core/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ class OperationContext:
3232
(e.g. ``"app=myapp/1.0;agent=claude-code"``). Free-form text, email
3333
addresses, and other potentially sensitive strings are rejected.
3434
35-
:param operation_context: Attribution string in ``key=value;key=value`` format.
36-
:type operation_context: :class:`str`
35+
:param user_agent_context: Attribution string in ``key=value;key=value`` format.
36+
:type user_agent_context: :class:`str`
3737
3838
:raises ValueError: If the string is empty, contains control characters, or
3939
does not match the required ``key=value`` format.
4040
"""
4141

42-
operation_context: str
42+
user_agent_context: str
4343

4444
def __post_init__(self) -> None:
45-
val = self.operation_context
45+
val = self.user_agent_context
4646
if not val:
4747
raise ValueError("operation_context must not be empty.")
4848
if any(c in val for c in "\r\n\x00"):

src/PowerPlatform/Dataverse/data/_odata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def __init__(
207207
logger=self._http_logger,
208208
)
209209
ctx_obj = self.config.operation_context
210-
self._operation_context = ctx_obj.operation_context if ctx_obj else None
210+
self._operation_context = ctx_obj.user_agent_context if ctx_obj else None
211211
self._logical_to_entityset_cache: dict[str, str] = {}
212212
# Cache: normalized table_schema_name (lowercase) -> primary id attribute (e.g. accountid)
213213
self._logical_primaryid_cache: dict[str, str] = {}

tests/unit/test_operation_context.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,41 @@ class TestOperationContextValidation(unittest.TestCase):
1717
"""Tests for OperationContext format validation and PII rejection."""
1818

1919
def test_valid_single_pair(self):
20-
ctx = OperationContext(operation_context="app=test/1.0")
21-
self.assertEqual(ctx.operation_context, "app=test/1.0")
20+
ctx = OperationContext(user_agent_context="app=test/1.0")
21+
self.assertEqual(ctx.user_agent_context, "app=test/1.0")
2222

2323
def test_valid_multiple_pairs(self):
24-
ctx = OperationContext(operation_context="app=test/1.0;skill=dv-data;agent=claude-code")
25-
self.assertEqual(ctx.operation_context, "app=test/1.0;skill=dv-data;agent=claude-code")
24+
ctx = OperationContext(user_agent_context="app=test/1.0;skill=dv-data;agent=claude-code")
25+
self.assertEqual(ctx.user_agent_context, "app=test/1.0;skill=dv-data;agent=claude-code")
2626

2727
def test_valid_with_dots_slashes_hyphens(self):
28-
ctx = OperationContext(operation_context="app=dataverse-skills/1.2.1")
29-
self.assertEqual(ctx.operation_context, "app=dataverse-skills/1.2.1")
28+
ctx = OperationContext(user_agent_context="app=dataverse-skills/1.2.1")
29+
self.assertEqual(ctx.user_agent_context, "app=dataverse-skills/1.2.1")
3030

3131
def test_reject_empty(self):
3232
with self.assertRaises(ValueError):
33-
OperationContext(operation_context="")
33+
OperationContext(user_agent_context="")
3434

3535
def test_reject_email(self):
3636
with self.assertRaises(ValueError):
37-
OperationContext(operation_context="myname@email.com")
37+
OperationContext(user_agent_context="myname@email.com")
3838

3939
def test_reject_freeform_text(self):
4040
with self.assertRaises(ValueError):
41-
OperationContext(operation_context="my bank password is 1234")
41+
OperationContext(user_agent_context="my bank password is 1234")
4242

4343
def test_reject_control_chars(self):
4444
for bad in ["has\rnewline", "has\nnewline", "has\x00null"]:
4545
with self.assertRaises(ValueError):
46-
OperationContext(operation_context=bad)
46+
OperationContext(user_agent_context=bad)
4747

4848
def test_reject_spaces(self):
4949
with self.assertRaises(ValueError):
50-
OperationContext(operation_context="app=my app")
50+
OperationContext(user_agent_context="app=my app")
5151

5252
def test_reject_no_equals(self):
5353
with self.assertRaises(ValueError):
54-
OperationContext(operation_context="justaplainstring")
54+
OperationContext(user_agent_context="justaplainstring")
5555

5656

5757
class TestOperationContextConfig(unittest.TestCase):
@@ -62,9 +62,9 @@ def test_default_is_none(self):
6262
self.assertIsNone(config.operation_context)
6363

6464
def test_explicit_value(self):
65-
ctx = OperationContext(operation_context="app=test/1.0;agent=claude-code")
65+
ctx = OperationContext(user_agent_context="app=test/1.0;agent=claude-code")
6666
config = DataverseConfig(operation_context=ctx)
67-
self.assertEqual(config.operation_context.operation_context, "app=test/1.0;agent=claude-code")
67+
self.assertEqual(config.operation_context.user_agent_context, "app=test/1.0;agent=claude-code")
6868

6969
def test_default_constructor_is_none(self):
7070
config = DataverseConfig()
@@ -79,14 +79,14 @@ def setUp(self):
7979
self.base_url = "https://example.crm.dynamics.com"
8080

8181
def test_kwarg_sets_config(self):
82-
ctx = OperationContext(operation_context="app=test/1.0;skill=dv-data;agent=claude-code")
82+
ctx = OperationContext(user_agent_context="app=test/1.0;skill=dv-data;agent=claude-code")
8383
client = DataverseClient(
8484
self.base_url,
8585
self.mock_credential,
8686
context=ctx,
8787
)
8888
self.assertEqual(
89-
client._config.operation_context.operation_context,
89+
client._config.operation_context.user_agent_context,
9090
"app=test/1.0;skill=dv-data;agent=claude-code",
9191
)
9292

@@ -95,22 +95,22 @@ def test_no_kwarg_leaves_config_default(self):
9595
self.assertIsNone(client._config.operation_context)
9696

9797
def test_config_and_context_raises(self):
98-
ctx = OperationContext(operation_context="app=test/1.0")
98+
ctx = OperationContext(user_agent_context="app=test/1.0")
9999
config = DataverseConfig(operation_context=ctx)
100100
with self.assertRaises(ValueError):
101101
DataverseClient(
102102
self.base_url,
103103
self.mock_credential,
104104
config=config,
105-
context=OperationContext(operation_context="app=other/2.0"),
105+
context=OperationContext(user_agent_context="app=other/2.0"),
106106
)
107107

108108
def test_config_alone_works(self):
109-
ctx = OperationContext(operation_context="app=test/1.0;agent=copilot")
109+
ctx = OperationContext(user_agent_context="app=test/1.0;agent=copilot")
110110
config = DataverseConfig(operation_context=ctx)
111111
client = DataverseClient(self.base_url, self.mock_credential, config=config)
112112
self.assertEqual(
113-
client._config.operation_context.operation_context,
113+
client._config.operation_context.user_agent_context,
114114
"app=test/1.0;agent=copilot",
115115
)
116116

@@ -132,7 +132,7 @@ def test_default_user_agent_unchanged(self):
132132

133133
def test_operation_context_appended(self):
134134
ctx_str = "app=dataverse-skills/1.2.1;skill=dv-data;agent=claude-code"
135-
ctx = OperationContext(operation_context=ctx_str)
135+
ctx = OperationContext(user_agent_context=ctx_str)
136136
config = DataverseConfig(operation_context=ctx)
137137
odata = _ODataClient(self.dummy_auth, self.base_url, config=config)
138138
headers = odata._headers()
@@ -146,4 +146,4 @@ def test_none_context_no_parentheses(self):
146146

147147
def test_empty_string_rejected_at_creation(self):
148148
with self.assertRaises(ValueError):
149-
OperationContext(operation_context="")
149+
OperationContext(user_agent_context="")

0 commit comments

Comments
 (0)