Copilot commented on code in PR #13739:
URL: https://github.com/apache/trafficserver/pull/13739#discussion_r4118502615


##########
tools/hrw4u/tests/test_coverage.py:
##########
@@ -101,6 +102,46 @@ def test_is_matched_prefix(self):
         assert not _is_matched("response_header.Host", 
frozenset(["request_header."]))
 
 
+class TestSandboxWarningOnFailure:
+    """A policy warning must not outlive a resolution that fails."""
+
+    @staticmethod
+    def _resolver(**warn: frozenset[str]) -> SymbolResolver:
+        return SymbolResolver(sandbox=SandboxConfig(message="", 
deny=PolicySets(), warn=PolicySets(**warn)))
+
+    def test_statement_function(self):
+        resolver = self._resolver(functions=frozenset(["set-debug"]))
+        with pytest.raises(SymbolResolutionError):
+            resolver.resolve_statement_func("set-debug", ['"extra"'], 
SectionType.REMAP)
+        assert resolver.drain_warnings() == []
+        resolver.resolve_statement_func("set-debug", [], SectionType.REMAP)
+        assert resolver.drain_warnings()
+
+    def test_assignment(self):
+        resolver = self._resolver(operators=frozenset(["inbound.resp."]))
+        with pytest.raises(SymbolResolutionError):
+            resolver.resolve_assignment("inbound.resp.X-A", '"1"', 
SectionType.REMAP)
+        assert resolver.drain_warnings() == []
+        resolver.resolve_assignment("inbound.resp.X-A", '"1"', 
SectionType.SEND_RESPONSE)
+        assert resolver.drain_warnings()
+
+    def test_add_assignment(self):
+        resolver = self._resolver(operators=frozenset(["inbound.resp."]))
+        with pytest.raises(SymbolResolutionError):
+            resolver.resolve_add_assignment("inbound.resp.X-A", '"1"', 
SectionType.REMAP)
+        assert resolver.drain_warnings() == []
+        resolver.resolve_add_assignment("inbound.resp.X-A", '"1"', 
SectionType.SEND_RESPONSE)
+        assert resolver.drain_warnings()
+
+    def test_condition(self):
+        resolver = self._resolver(conditions=frozenset(["inbound.resp."]))
+        with pytest.raises(SymbolResolutionError):
+            resolver.resolve_condition("inbound.resp.X-A", SectionType.REMAP)
+        assert resolver.drain_warnings() == []
+        resolver.resolve_condition("inbound.resp.X-A", 
SectionType.SEND_RESPONSE)
+        assert resolver.drain_warnings()

Review Comment:
   The rollback tests cover statement functions, assignments, `+=`, and 
conditions, but not the `resolve_function` path changed above. Once 
value-function policy checks are present, an invalid call such as `access()` 
can raise after buffering a warning; add a failing-then-successful 
value-function case so this leak cannot regress.



##########
tools/hrw4u/src/symbols.py:
##########
@@ -180,7 +181,7 @@ def resolve_condition(self, name: str, section: SectionType 
| None = None) -> tu
             raise error
 
     def resolve_function(self, func_name: str, args: list[str], strip_quotes: 
bool = False) -> str:
-        with self.debug_context("resolve_function", func_name, args):
+        with self.debug_context("resolve_function", func_name, args), 
self._warnings_on_success():

Review Comment:
   This adds the success-scope around value-function resolution, but 
`resolve_function` still never calls `check_function`, so `warn.functions` and 
`deny.functions` are ignored for calls such as `access(...)` and 
`{txn-count()}`. Collect the function policy before the lookup, as 
`resolve_statement_func` does, so the new warning handling actually covers 
value functions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to