pranavshuklaa commented on code in PR #1091:
URL: https://github.com/apache/flink-agents/pull/1091#discussion_r4543835299
##########
python/flink_agents/runtime/skill/tests/test_materialize.py:
##########
@@ -309,3 +400,532 @@ def
test_logs_sanitized_effective_url_for_same_protocol_redirect(
assert "redirect-fragment" not in warning
finally:
path.unlink(missing_ok=True)
+
+
+# ---------------------------------------------------------------------------
+# Helpers for size-cap tests
+# ---------------------------------------------------------------------------
+
+
+def _make_streaming_server(
+ declared_content_length: int | None, bytes_to_stream: int
+) -> tuple[str, HTTPServer]:
+ class _StreamingHandler(BaseHTTPRequestHandler):
+ def do_GET(self) -> None:
+ self.send_response(200)
+ if declared_content_length is not None:
+ self.send_header("Content-Length",
str(declared_content_length))
+ self.end_headers()
+ chunk = b"x" * 65536
+ remaining = bytes_to_stream
+ while remaining > 0:
+ to_write = min(len(chunk), remaining)
+ try:
+ self.wfile.write(chunk[:to_write])
+ self.wfile.flush()
+ except OSError:
+ break
+ remaining -= to_write
+
+ def log_message(self, *_args: object) -> None:
+ pass
+
+ server = HTTPServer(("127.0.0.1", 0), _StreamingHandler)
+ port = server.server_address[1]
+ threading.Thread(target=server.serve_forever, daemon=True).start()
+ return f"http://127.0.0.1:{port}", server
+
+
+def _make_zip_with_patched_declared_sizes(
+ zip_path: Path, entries: dict[str, bytes], declared_size: int
+) -> None:
+ r"""Write a ZIP and patch the declared uncompressed size in both the local
file
+ header (LFH, ``PK\x03\x04``) and the central directory header (CDH,
``PK\x01\x02``)
+ for every entry.
+
+ Patching only the CDH is insufficient for the per-entry streaming test:
Python's
+ ``zipfile`` reads the LFH declared size to bound how many bytes it
decompresses, so
+ leaving the LFH intact causes a CRC mismatch before the byte counter is
reached.
+ Patching both headers lets the full real payload flow through the
streaming counter.
Review Comment:
Yes Updated. The docstring now says the forged-size tests expect CRC
validation to reject the archive, and that the byte counters are tested through
`_bounded_copy`.
--
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]