Tuning: the CI waits may be zero
The live review test sets ci_grace_s: 0, which the shared tuning parser
refused (every number had to be positive). A field now opts in to zero
with metadata {"zero": True}; ci_wait_s and ci_grace_s do.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J5Utyfzw7gF7UhjRDEtjTk
This commit is contained in:
1 parent
096eeea56b
commit
59fba3bb76
5 files changed
+42
-9
No files matched your search
@@ -81,13 +81,14 @@ def read_file(path: Path, errors: list[str]) -> dict[str, Any]:
|
||||
return loaded
|
||||
|
||||
|
||||
def positive(value: Any, kind: type) -> int | float | None:
|
||||
def positive(value: Any, kind: type, *, zero: bool = False) -> int | float | None:
|
||||
"""``value`` as ``kind`` if above 0 (or 0 itself, given ``zero``)."""
|
||||
# bool is an int in Python; `true` for a turn limit is a mistake.
|
||||
if isinstance(value, bool) or not isinstance(value, int | float):
|
||||
return None
|
||||
if kind is int and not float(value).is_integer():
|
||||
return None
|
||||
if value <= 0:
|
||||
if value < 0 or (value == 0 and not zero):
|
||||
return None
|
||||
return kind(value)
|
||||
|
||||
@@ -132,9 +133,13 @@ def parse_tuning(
|
||||
if spec is None:
|
||||
errors.append(f"tuning.{name}.{key}: unknown setting")
|
||||
continue
|
||||
number = positive(value, float if spec.type in (float, "float") else int)
|
||||
# A field with metadata {"zero": True} may also be 0 ("don't wait").
|
||||
zero = bool(spec.metadata.get("zero"))
|
||||
kind = float if spec.type in (float, "float") else int
|
||||
number = positive(value, kind, zero=zero)
|
||||
if number is None:
|
||||
errors.append(f"tuning.{name}.{key}: must be a positive number")
|
||||
need = "zero or more" if zero else "a positive number"
|
||||
errors.append(f"tuning.{name}.{key}: must be {need}")
|
||||
continue
|
||||
values[key] = number
|
||||
sections[name] = cls(**values)
|
||||
|
||||
@@ -19,6 +19,7 @@ from nisse_core.config import (
|
||||
class Review:
|
||||
max_rounds: int = 3
|
||||
wait_s: float = 60.0
|
||||
grace_s: float = field(default=5.0, metadata={"zero": True})
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -45,6 +46,17 @@ def test_an_agents_own_tuning_sections() -> None:
|
||||
]
|
||||
|
||||
|
||||
def test_a_field_may_opt_in_to_zero() -> None:
|
||||
errors: list[str] = []
|
||||
tuning = parse_tuning({"review": {"grace_s": 0}}, Tuning, errors)
|
||||
assert tuning.review.grace_s == 0 and errors == []
|
||||
parse_tuning({"review": {"grace_s": -1, "wait_s": 0}}, Tuning, errors)
|
||||
assert errors == [
|
||||
"tuning.review.grace_s: must be zero or more",
|
||||
"tuning.review.wait_s: must be a positive number",
|
||||
]
|
||||
|
||||
|
||||
def test_references_and_people() -> None:
|
||||
errors: list[str] = []
|
||||
env = {"TOKEN": "s3cret"}
|
||||
|
||||
Reference in new issue
Block a user