Skip to content

Commit db3dd87

Browse files
committed
test: Type create-conflict error types as a closed literal
1 parent 4a2a997 commit db3dd87

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

tests/_utils.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import time
88
from collections.abc import AsyncIterator, Iterator
99
from dataclasses import dataclass
10-
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, cast, overload
10+
from typing import TYPE_CHECKING, Any, Literal, Protocol, TypeVar, cast, overload
1111

1212
import pytest
1313

@@ -229,11 +229,26 @@ async def drain() -> list[_HasIdT]:
229229
return collected
230230

231231

232+
ConflictErrorType = Literal[
233+
'actor-name-not-unique',
234+
'actor-task-name-not-unique',
235+
'schedule-name-not-unique',
236+
'version-already-exists',
237+
'env-var-already-exists',
238+
]
239+
"""API error types signalling that a create request lost the resource's unique name or version number.
240+
241+
Kept a closed set rather than a plain `str` so a typo in a call below fails the type check instead of silently
242+
disabling the recovery it was meant to enable. The values and their status codes come from the API itself - the
243+
`*-not-unique` ones are 409, `version-already-exists` and `env-var-already-exists` are 403.
244+
"""
245+
246+
232247
async def _create_with_conflict_recovery(
233248
create: Callable[[], Awaitable[T] | T],
234249
recover: Callable[[], Awaitable[T | None] | T | None],
235250
*,
236-
error_type: str,
251+
error_type: ConflictErrorType,
237252
description: str,
238253
) -> T:
239254
"""Run `create`, recovering the resource if an already-committed retry made its name unavailable.

0 commit comments

Comments
 (0)