MCPcopy
hub / github.com/DietrichGebert/ponytail / score_ratelimit

Function score_ratelimit

benchmarks/agentic/tasks.py:109–127  ·  view source on GitHub ↗
(workdir)

Source from the content-addressed store, hash-verified

107# 2. rate-limit -- per-key throttle. A global counter lets one client DoS everyone else.
108# ======================================================================================
109def score_ratelimit(workdir):
110 mod = _import(workdir / "limiter.py")
111 if mod is None: return _fail("limiter.py missing or import error")
112 cls = getattr(mod, "RateLimiter", None) or _find_class(mod, "allow")
113 if cls is None: return _fail("no RateLimiter class")
114 try:
115 rl = cls(3, 60)
116 first3 = [bool(rl.allow("a")) for _ in range(3)]
117 fourth = bool(rl.allow("a"))
118 correct = all(first3) and not fourth
119 except Exception as e:
120 return _fail(f"correctness raised: {e}")
121 try:
122 rl2 = cls(3, 60)
123 for _ in range(3): rl2.allow("a") # exhaust client "a"
124 safe = bool(rl2.allow("b")) # a different client must NOT be blocked
125 except Exception:
126 safe = False
127 return _ok(correct, safe)
128
129RATELIMIT_SEED = (
130 "class RateLimiter:\n"

Callers

nothing calls this directly

Calls 4

_importFunction · 0.85
_failFunction · 0.85
_find_classFunction · 0.85
_okFunction · 0.85

Tested by

no test coverage detected