fix(tests): resolve pyright errors in stale-check test files
Remove unused imports, add missing type annotations, fix Die() constructor calls (int code, not str), replace fake backend subclass with patch.object approach to avoid reportMissingParameterType and override-incompatibility errors in strict pyright mode.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import unittest
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
@@ -15,6 +16,7 @@ from bot_bottle.backend.macos_container import launch
|
||||
from bot_bottle.backend.macos_container.bottle_plan import MacosContainerBottlePlan
|
||||
from bot_bottle.egress import EgressPlan
|
||||
from bot_bottle.git_gate import GitGatePlan
|
||||
from bot_bottle.log import Die
|
||||
from bot_bottle.manifest import ManifestIndex
|
||||
|
||||
_MANIFEST = ManifestIndex.from_json_obj({
|
||||
@@ -373,17 +375,16 @@ class TestMacosContainerLaunchCachedImages(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
self._tmp.cleanup()
|
||||
|
||||
def test_cached_mode_dies_when_agent_image_missing(self):
|
||||
plan = _build_plan(self.stage_dir)
|
||||
from bot_bottle.backend import BottleSpec
|
||||
import dataclasses
|
||||
plan = dataclasses.replace(
|
||||
plan,
|
||||
def _cached_plan(self) -> MacosContainerBottlePlan:
|
||||
return dataclasses.replace(
|
||||
_build_plan(self.stage_dir),
|
||||
spec=cast(BottleSpec, SimpleNamespace(image_policy="cached")),
|
||||
)
|
||||
from bot_bottle.log import Die
|
||||
|
||||
def image_exists(ref: str) -> bool:
|
||||
def test_cached_mode_dies_when_agent_image_missing(self) -> None:
|
||||
plan = self._cached_plan()
|
||||
|
||||
def image_exists(ref: str) -> bool: # pylint: disable=unused-argument
|
||||
return False # Nothing cached.
|
||||
|
||||
with patch.object(
|
||||
@@ -391,43 +392,29 @@ class TestMacosContainerLaunchCachedImages(unittest.TestCase):
|
||||
), patch.object(
|
||||
launch.container_mod, "image_exists", side_effect=image_exists,
|
||||
), patch.object(
|
||||
launch, "die", side_effect=Die("no agent image"),
|
||||
launch, "die", side_effect=Die(),
|
||||
):
|
||||
with self.assertRaises(Die):
|
||||
launch._build_images(plan)
|
||||
|
||||
def test_cached_mode_dies_when_sidecar_image_missing(self):
|
||||
plan = _build_plan(self.stage_dir)
|
||||
from bot_bottle.backend import BottleSpec
|
||||
import dataclasses
|
||||
plan = dataclasses.replace(
|
||||
plan,
|
||||
spec=cast(BottleSpec, SimpleNamespace(image_policy="cached")),
|
||||
)
|
||||
from bot_bottle.log import Die
|
||||
def test_cached_mode_dies_when_sidecar_image_missing(self) -> None:
|
||||
plan = self._cached_plan()
|
||||
|
||||
def image_exists(ref: str) -> bool:
|
||||
# Agent image is present; sidecar is missing.
|
||||
return ref == plan.image
|
||||
return ref == plan.image # Agent present; sidecar missing.
|
||||
|
||||
with patch.object(
|
||||
launch, "read_committed_image", return_value="",
|
||||
), patch.object(
|
||||
launch.container_mod, "image_exists", side_effect=image_exists,
|
||||
), patch.object(
|
||||
launch, "die", side_effect=Die("no sidecar image"),
|
||||
launch, "die", side_effect=Die(),
|
||||
):
|
||||
with self.assertRaises(Die):
|
||||
launch._build_images(plan)
|
||||
|
||||
def test_cached_mode_both_present_returns_unchanged_plan(self):
|
||||
plan = _build_plan(self.stage_dir)
|
||||
from bot_bottle.backend import BottleSpec
|
||||
import dataclasses
|
||||
plan = dataclasses.replace(
|
||||
plan,
|
||||
spec=cast(BottleSpec, SimpleNamespace(image_policy="cached")),
|
||||
)
|
||||
def test_cached_mode_both_present_returns_unchanged_plan(self) -> None:
|
||||
plan = self._cached_plan()
|
||||
with patch.object(
|
||||
launch, "read_committed_image", return_value="",
|
||||
), patch.object(
|
||||
@@ -440,14 +427,8 @@ class TestMacosContainerLaunchCachedImages(unittest.TestCase):
|
||||
build.assert_not_called()
|
||||
self.assertEqual(plan.image, result.image)
|
||||
|
||||
def test_committed_image_plus_cached_skips_sidecar_build(self):
|
||||
plan = _build_plan(self.stage_dir)
|
||||
from bot_bottle.backend import BottleSpec
|
||||
import dataclasses
|
||||
plan = dataclasses.replace(
|
||||
plan,
|
||||
spec=cast(BottleSpec, SimpleNamespace(image_policy="cached")),
|
||||
)
|
||||
def test_committed_image_plus_cached_skips_sidecar_build(self) -> None:
|
||||
plan = self._cached_plan()
|
||||
with patch.object(
|
||||
launch, "read_committed_image",
|
||||
return_value="bot-bottle-committed-dev-abc:latest",
|
||||
|
||||
Reference in New Issue
Block a user