Skip to content

Commit 3ccfffc

Browse files
committed
Share the bundle section mutation helper between Node tests
1 parent bf7586d commit 3ccfffc

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎task-sdk/tests/task_sdk/coordinators/node/_bundle_test_utils.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,8 @@ def mutate_byte(bundle: pathlib.Path, offset: int) -> None:
142142
contents = bytearray(bundle.read_bytes())
143143
contents[offset] = ord("A") if contents[offset] != ord("A") else ord("B")
144144
bundle.write_bytes(contents)
145+
146+
147+
def mutate_section(bundle: pathlib.Path, section: str) -> None:
148+
"""Change the first byte of a layout section, so its digest no longer matches."""
149+
mutate_byte(bundle, int(read_layout(bundle)[section]["start"], 16)) # type: ignore[index, call-overload]

‎task-sdk/tests/task_sdk/coordinators/node/test_coordinator.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from task_sdk.coordinators.node._bundle_test_utils import (
2828
BUNDLE_NAME,
2929
mutate_byte,
30+
mutate_section,
3031
read_layout,
3132
write_bundle,
3233
)
@@ -153,7 +154,7 @@ def test_returns_node_and_bundle_schema_version(self, tmp_path):
153154

154155
def test_tampered_bundle_raises(self, tmp_path):
155156
bundle = write_bundle(tmp_path, "native_dag")
156-
mutate_byte(bundle, int(read_layout(bundle)["code"]["start"], 16)) # type: ignore[index, call-overload]
157+
mutate_section(bundle, "code")
157158

158159
with pytest.raises(ValueError, match="code SHA-256 mismatch"):
159160
NodeCoordinator()._build_parse_dag_command(path=bundle)

‎task-sdk/tests/task_sdk/coordinators/node/test_dag_importer.py‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
from task_sdk.coordinators.node._bundle_test_utils import (
2525
BUNDLE_NAME,
2626
LAYOUT_PREFIX,
27-
mutate_byte,
28-
read_layout,
27+
mutate_section,
2928
write_bundle,
3029
)
3130

@@ -45,14 +44,10 @@ def importer() -> NodeDagImporter:
4544
return NodeDagImporter(coordinator=NodeCoordinator())
4645

4746

48-
def _mutate_section(bundle: pathlib.Path, section: str) -> None:
49-
mutate_byte(bundle, int(read_layout(bundle)[section]["start"], 16)) # type: ignore[index, call-overload]
50-
51-
5247
def test_lists_only_packed_bundles(importer, tmp_path):
5348
nested = write_bundle(tmp_path / "team", "sales")
5449
tampered = write_bundle(tmp_path, "inventory", name="tampered.min.mjs")
55-
_mutate_section(tampered, "code")
50+
mutate_section(tampered, "code")
5651
write_bundle(tmp_path, "orders", name="plain.mjs")
5752
(tmp_path / "vendor.min.mjs").write_bytes(b"export {};\n")
5853

@@ -105,7 +100,7 @@ def test_returns_the_entry_module(self, importer, tmp_path):
105100
@pytest.mark.parametrize(
106101
("break_bundle", "reason"),
107102
[
108-
(lambda path: _mutate_section(path, "source"), "source SHA-256 mismatch"),
103+
(lambda path: mutate_section(path, "source"), "source SHA-256 mismatch"),
109104
(lambda path: write_bundle(path.parent, "sales", source=b"x" * (1024 * 1024 + 1)), "exceeds"),
110105
(lambda path: path.unlink(), "cannot read bundle.min.mjs"),
111106
],

0 commit comments

Comments
 (0)