A repository per test run instead of the shared sandbox
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 5m17s
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 5m17s
Every live test that touches a repository gets one of its own from e2e_support.fresh_repo, made by the test operator as an operator makes a project's (D4, D8): seeded from tests/integration/seed/ (the sandbox's package, without past runs' leftovers), the agent's account a collaborator with write access, main protected (pushes only by the owner, an approval to merge), and a deploy key generated for the run. It is deleted afterwards (NISSE_E2E_KEEP_REPOS keeps it); scripts/e2e-cleanup.sh deletes leftovers. - Both e2e fixtures use it; per-run base branches are gone. The merge helper approves first, as the protection now requires. - test_gitea_live uses it, so CI needs NISSE_OPERATOR_TOKEN and no longer writes the sandbox deploy key (NISSE_PUSH_KEY). - A live test of the helper: seeded, shared with the agent, protected against it, deleted. - nisse-test.yaml's project entry is a placeholder; pytest and ruff skip the seed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPQ14L3LikyefCMFBqEbKE
This commit is contained in:
1 parent
6c962e1ed9
commit
679ace1fd8
18 files changed
+379
-55
No files matched your search
@@ -0,0 +1,4 @@
|
||||
# sandbox
|
||||
|
||||
A small Python package for nisse-dev's end-to-end tests: each run gets a
|
||||
fresh repository seeded with this. Run its tests with `python3 -m pytest`.
|
||||
@@ -0,0 +1,2 @@
|
||||
from .text import truncate
|
||||
from .mathutils import factorial
|
||||
@@ -0,0 +1,16 @@
|
||||
"""Math utilities."""
|
||||
|
||||
|
||||
def factorial(n: int) -> int:
|
||||
"""Return n! for a non-negative integer n.
|
||||
|
||||
Raises TypeError if n is not an int (bool is rejected), ValueError if n < 0.
|
||||
"""
|
||||
if isinstance(n, bool) or not isinstance(n, int):
|
||||
raise TypeError(f"n must be an int, got {type(n).__name__}")
|
||||
if n < 0:
|
||||
raise ValueError(f"n must be >= 0, got {n}")
|
||||
result = 1
|
||||
for i in range(2, n + 1):
|
||||
result *= i
|
||||
return result
|
||||
@@ -0,0 +1,10 @@
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
_NON_ALNUM = re.compile(r"[^a-z0-9]+")
|
||||
|
||||
|
||||
def slugify(text: str) -> str:
|
||||
"""Lowercase; runs of non-alphanumerics -> single '-'; no leading/trailing '-'."""
|
||||
ascii_text = unicodedata.normalize("NFKD", text).encode("ascii", "ignore").decode("ascii")
|
||||
return _NON_ALNUM.sub("-", ascii_text.lower()).strip("-")
|
||||
@@ -0,0 +1,16 @@
|
||||
"""Text utilities."""
|
||||
|
||||
ELLIPSIS = "\u2026"
|
||||
|
||||
|
||||
def truncate(text: str, n: int) -> str:
|
||||
"""Return text unchanged if len(text) <= n, else its first n-1 chars followed by '…'.
|
||||
|
||||
Raises ValueError if n < 1.
|
||||
"""
|
||||
if n < 1:
|
||||
raise ValueError(f"n must be >= 1, got {n}")
|
||||
if len(text) <= n:
|
||||
return text
|
||||
return text[: n - 1] + ELLIPSIS
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import math
|
||||
|
||||
import pytest
|
||||
|
||||
from sandbox import factorial
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"n, expected",
|
||||
[
|
||||
(0, 1),
|
||||
(1, 1),
|
||||
(2, 2),
|
||||
(3, 6),
|
||||
(5, 120),
|
||||
(10, 3628800),
|
||||
(20, 2432902008176640000),
|
||||
],
|
||||
)
|
||||
def test_factorial_known_values(n, expected):
|
||||
assert factorial(n) == expected
|
||||
|
||||
|
||||
def test_factorial_matches_math_factorial():
|
||||
for n in range(0, 101):
|
||||
assert factorial(n) == math.factorial(n)
|
||||
|
||||
|
||||
def test_factorial_large_input_no_recursion_limit():
|
||||
assert factorial(2000) == math.factorial(2000)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("n", [-1, -5, -100])
|
||||
def test_factorial_negative_raises_value_error(n):
|
||||
with pytest.raises(ValueError):
|
||||
factorial(n)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("n", [5.0, 2.5, "5", None, True, False])
|
||||
def test_factorial_non_int_raises_type_error(n):
|
||||
with pytest.raises(TypeError):
|
||||
factorial(n)
|
||||
@@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
from sandbox.slugify import slugify
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text, expected",
|
||||
[
|
||||
("Hello World", "hello-world"),
|
||||
("Hello, World!", "hello-world"),
|
||||
(" leading and trailing ", "leading-and-trailing"),
|
||||
("multiple spaces", "multiple-spaces"),
|
||||
("a--b__c..d", "a-b-c-d"),
|
||||
("!!!", ""),
|
||||
("", ""),
|
||||
("-already-slugged-", "already-slugged"),
|
||||
("MiXeD CaSe 123", "mixed-case-123"),
|
||||
("tab\tand\nnewline", "tab-and-newline"),
|
||||
("Café Déjà Vu", "cafe-deja-vu"),
|
||||
("emoji 🎉 party", "emoji-party"),
|
||||
("Foo Bar", "foo-bar"),
|
||||
],
|
||||
)
|
||||
def test_slugify(text, expected):
|
||||
assert slugify(text) == expected
|
||||
@@ -0,0 +1,37 @@
|
||||
import pytest
|
||||
|
||||
from sandbox import truncate
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text, n, expected",
|
||||
[
|
||||
("", 1, ""),
|
||||
("abc", 3, "abc"),
|
||||
("abc", 10, "abc"),
|
||||
("abcd", 3, "ab\u2026"),
|
||||
("hello world", 5, "hell\u2026"),
|
||||
("ab", 1, "\u2026"),
|
||||
("a", 1, "a"),
|
||||
("h\u00e9llo w\u00f6rld", 4, "h\u00e9l\u2026"),
|
||||
],
|
||||
)
|
||||
def test_truncate_cases(text, n, expected):
|
||||
assert truncate(text, n) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("n", range(1, 16))
|
||||
def test_result_never_exceeds_n(n):
|
||||
assert len(truncate("hello world!!", n)) <= n
|
||||
|
||||
|
||||
def test_uses_single_ellipsis_char():
|
||||
result = truncate("hello world", 5)
|
||||
assert result.endswith("\u2026")
|
||||
assert not result.endswith("...")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("n", [0, -5])
|
||||
def test_invalid_n_raises(n):
|
||||
with pytest.raises(ValueError):
|
||||
truncate("abc", n)
|
||||
Reference in new issue
Block a user