|
6 | 6 | import git_repo |
7 | 7 | import pydantic_yaml |
8 | 8 | import pytest_mock.plugin |
| 9 | +import reconciler_state |
9 | 10 | from dre_cli import ElectionProposal |
10 | 11 | from public_dashboard import DashboardAPI |
11 | 12 | from reconciler import Reconciler |
@@ -140,6 +141,165 @@ def _cdf(r: git_repo.GitRepo) -> commit_annotation.ChangeDeterminatorProtocol: |
140 | 141 | return commit_annotation.LocalCommitChangeDeterminator(r) |
141 | 142 |
|
142 | 143 |
|
| 144 | +def _ignore_filter_retriever_fixture() -> typing.Callable[ |
| 145 | + [], |
| 146 | + tuple[dict[str, ElectionProposal], dict[str, ElectionProposal]], |
| 147 | +]: |
| 148 | + """ |
| 149 | + Build a self-contained retriever returning one GuestOS and one HostOS |
| 150 | + election proposal with distinct IDs. This bypasses ``MockDashboard`` |
| 151 | + (whose ``_fake_proposal`` always emits ``hostos_version_to_elect``) |
| 152 | + so the test exercises both branches of the ignore filter. |
| 153 | + """ |
| 154 | + guestos_commit = "11" * 20 |
| 155 | + hostos_commit = "22" * 20 |
| 156 | + |
| 157 | + def retriever() -> tuple[ |
| 158 | + dict[str, ElectionProposal], dict[str, ElectionProposal] |
| 159 | + ]: |
| 160 | + guestos: dict[str, ElectionProposal] = { |
| 161 | + guestos_commit: { |
| 162 | + "id": 200001, |
| 163 | + "payload": { |
| 164 | + "replica_version_to_elect": guestos_commit, |
| 165 | + "release_package_sha256_hex": "aa" * 32, |
| 166 | + }, |
| 167 | + "proposal_timestamp_seconds": 1743789296, |
| 168 | + "proposer": 61, |
| 169 | + "status": "REJECTED", |
| 170 | + "summary": "...stubbed out...", |
| 171 | + "title": "Elect new IC/GuestOS revision (test fixture)", |
| 172 | + } |
| 173 | + } |
| 174 | + hostos: dict[str, ElectionProposal] = { |
| 175 | + hostos_commit: { |
| 176 | + "id": 200002, |
| 177 | + "payload": { |
| 178 | + "hostos_version_to_elect": hostos_commit, |
| 179 | + "release_package_sha256_hex": "bb" * 32, |
| 180 | + }, |
| 181 | + "proposal_timestamp_seconds": 1743789296, |
| 182 | + "proposer": 61, |
| 183 | + "status": "REJECTED", |
| 184 | + "summary": "...stubbed out...", |
| 185 | + "title": "Elect new IC/HostOS revision (test fixture)", |
| 186 | + } |
| 187 | + } |
| 188 | + return guestos, hostos |
| 189 | + |
| 190 | + return retriever |
| 191 | + |
| 192 | + |
| 193 | +def test_reconciler_filtered_proposals_retriever_drops_ignored_ids() -> None: |
| 194 | + """ |
| 195 | + With ``ignored_proposals`` set, the wrapper around the proposal |
| 196 | + retriever must omit any matching proposal so the corresponding |
| 197 | + version is treated by ``ReconcilerState`` as not yet proposed. |
| 198 | + """ |
| 199 | + retriever = _ignore_filter_retriever_fixture() |
| 200 | + guestos_commit, hostos_commit = "11" * 20, "22" * 20 |
| 201 | + ignored_guestos_id = 200001 |
| 202 | + rs = ReconcilerState() |
| 203 | + |
| 204 | + wrapped = Reconciler._filtered_proposals_retriever( |
| 205 | + retriever, |
| 206 | + source="dashboard", |
| 207 | + ignore_proposal_ids=[ignored_guestos_id], |
| 208 | + ) |
| 209 | + guestos, hostos = wrapped() |
| 210 | + |
| 211 | + assert guestos == {}, guestos |
| 212 | + assert list(hostos.keys()) == [hostos_commit], hostos |
| 213 | + assert hostos[hostos_commit]["id"] == 200002 |
| 214 | + |
| 215 | + rs.update_state(wrapped) |
| 216 | + assert isinstance( |
| 217 | + rs.version_proposal(guestos_commit, const.GUESTOS), |
| 218 | + reconciler_state.NoProposal, |
| 219 | + ) |
| 220 | + assert isinstance( |
| 221 | + rs.version_proposal(hostos_commit, const.HOSTOS), |
| 222 | + reconciler_state.SubmittedProposal, |
| 223 | + ) |
| 224 | + |
| 225 | + |
| 226 | +def test_reconciler_filtered_proposals_retriever_is_noop_without_ids() -> None: |
| 227 | + """Without ``ignored_proposals``, the wrapper returns the data unchanged.""" |
| 228 | + retriever = _ignore_filter_retriever_fixture() |
| 229 | + |
| 230 | + direct_guestos, direct_hostos = retriever() |
| 231 | + wrapped_guestos, wrapped_hostos = Reconciler._filtered_proposals_retriever( |
| 232 | + retriever, |
| 233 | + source="dashboard", |
| 234 | + ignore_proposal_ids=[], |
| 235 | + )() |
| 236 | + |
| 237 | + assert wrapped_guestos == direct_guestos |
| 238 | + assert wrapped_hostos == direct_hostos |
| 239 | + |
| 240 | + |
| 241 | +def test_reconciler_picks_up_ignored_proposals_from_release_index( |
| 242 | + ic_repo: git_repo.GitRepo, |
| 243 | + mocker: pytest_mock.plugin.MockerFixture, |
| 244 | +) -> None: |
| 245 | + """ |
| 246 | + ``ignored_proposals`` declared at the top of ``release-index.yaml`` must |
| 247 | + propagate through the loader into the per-cycle ignore set, so a |
| 248 | + previously-rejected proposal stops blocking resubmission. |
| 249 | + """ |
| 250 | + with mocker.patch.object(ic_repo, "push_release_tags"): |
| 251 | + d, f, n, rs, a, dre, s, rl, p, db = _defaults_for_test() |
| 252 | + already_blocked_hostos_id = 138817 |
| 253 | + rl = StaticReleaseLoader( |
| 254 | + pydantic_yaml.to_yaml_str( |
| 255 | + ReleaseIndexModel.model_validate( |
| 256 | + { |
| 257 | + "ignored_proposals": [already_blocked_hostos_id], |
| 258 | + "releases": [ |
| 259 | + _release( |
| 260 | + "rc--2025-10-02_03-13", |
| 261 | + {"base": "45657852c1eca6728ff313808db29b47c862ad13"}, |
| 262 | + ), |
| 263 | + _release( |
| 264 | + "rc--2025-09-25_09-52", |
| 265 | + {"base": "206b61a8616bc93d36d6a014e5cc8edf1ba256ae"}, |
| 266 | + ), |
| 267 | + _release( |
| 268 | + "rc--2025-09-19_10-17", |
| 269 | + {"base": "bf0d4d1b8cb6c0c19a5afa1454ada014847aa5c6"}, |
| 270 | + ), |
| 271 | + ], |
| 272 | + } |
| 273 | + ) |
| 274 | + ) |
| 275 | + ) |
| 276 | + reconciler = Reconciler( |
| 277 | + f, rl, n, p, "", rs, ic_repo, lambda: _cdf(ic_repo), a, dre, db, s |
| 278 | + ) |
| 279 | + |
| 280 | + def fake_approved_release_notes(*args): # type: ignore |
| 281 | + return f"Fake changelog for {args}" |
| 282 | + |
| 283 | + rl.proposal_summary = fake_approved_release_notes # type: ignore |
| 284 | + reconciler.reconcile() |
| 285 | + |
| 286 | + # The HostOS dashboard fixture pins id 138817 to both top releases. |
| 287 | + # After reconcile, those versions must have been seen as "not yet |
| 288 | + # proposed" — i.e. the reconciler issued a fresh proposal for them |
| 289 | + # (dryrun.DRECli returns a synthetic, version-derived ID), so the |
| 290 | + # state for them no longer points at the ignored id. |
| 291 | + for commit in ( |
| 292 | + "45657852c1eca6728ff313808db29b47c862ad13", |
| 293 | + "206b61a8616bc93d36d6a014e5cc8edf1ba256ae", |
| 294 | + ): |
| 295 | + prop = rs.version_proposal(commit, const.HOSTOS) |
| 296 | + assert isinstance(prop, reconciler_state.SubmittedProposal), prop |
| 297 | + assert prop.proposal_id != already_blocked_hostos_id, ( |
| 298 | + f"Expected a fresh proposal id for HostOS commit {commit}, " |
| 299 | + f"got the previously-blocked id {already_blocked_hostos_id}." |
| 300 | + ) |
| 301 | + |
| 302 | + |
143 | 303 | def test_reconciler_reconciles_without_error_already_submitted_proposals( |
144 | 304 | ic_repo: git_repo.GitRepo, |
145 | 305 | mocker: pytest_mock.plugin.MockerFixture, |
|
0 commit comments