Files
inkwell/tests/test_settings.py
T
bvandeusenandClaude Opus 5.5 a51a563fe7
CI & Build / Python lint (push) Successful in 2s
CI & Build / Build now, or wait for Android? (push) Successful in 2s
Android / Build, or is the channel already serving this? (push) Successful in 3s
Android / Core and FFI clippy and tests (push) Skipped
Android / Kotlin + Rust (APK) (push) Skipped
Desktop (Tauri) / Build, or is the channel already serving this? (push) Successful in 2s
CI & Build / Web typecheck and unit tests (push) Successful in 9s
CI & Build / Python tests (push) Successful in 13s
Android / Build the server image (push) Skipped
Desktop (Tauri) / Web tests, clippy, Rust tests and rustfmt (push) Skipped
Desktop (Tauri) / Tauri desktop (Linux) (push) Skipped
Desktop (Tauri) / Windows installer (cross-compiled) (push) Skipped
Desktop (Tauri) / Update manifest (push) Skipped
CI & Build / integration (push) Successful in 1m30s
CI & Build / Build & push image (push) Successful in 32s
Server comments describe the code to a stranger (#6221)
Rule 32 "Comments describe the product to a stranger" sweep over
src/, alembic/ and tests/. Comments and docstrings now say what the code
does and the reason as a present-tense constraint, briefly.

Removed:
- issue, task, note, rule, milestone and family-idea references
- "used to" / before-and-after narration
- quotes of decisions and incident stories from the deploying instance
- paragraph-length arguments, where a line or two carries the fact

Kept every hazard as a present-tense fact, e.g. timing oracles, the
proxy hop direction, and migrations that must stay frozen.

Also:
- Three test names lose "still"/"used to"/"pre_m304" phrasing.
- pyproject's description drops "FabledSword family".

The history these comments carried stays in Scribe and in git log.
A comment-stripping diff (Scribe snippet #6226 "codeonly.py — prove a
diff changed only comments") shows no code changed apart from the
renamed tests and the description string.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 20:07:47 -04:00

79 lines
2.9 KiB
Python

from inkwell.settings import MAX_BODY_MB, REGISTRY, validate_updates
def test_registry_has_expected_keys():
keys = {d.key for d in REGISTRY}
assert {"site_name", "allow_registration", "session_ttl_days"} <= keys
def test_validate_rejects_unknown_key():
clean, error = validate_updates({"nope": 1})
assert error is not None
assert clean == {}
def test_validate_coerces_bool_and_int():
clean, error = validate_updates({"allow_registration": "true", "session_ttl_days": "45"})
assert error is None
assert clean["allow_registration"] is True
assert clean["session_ttl_days"] == 45
def test_each_integer_with_a_dangerous_range_is_bounded():
"""Session length 0 expired every session at once; an attachment limit above the
body ceiling allowed files no request could carry; a negative one refused all."""
for key, bad, good in (
("session_ttl_days", 0, 1),
("trash_retention_days", -1, 0),
("max_attachment_mb", 0, 1),
("max_attachment_mb", MAX_BODY_MB, MAX_BODY_MB - 1),
):
clean, error = validate_updates({key: str(bad)})
assert error is not None and clean == {}, f"{key}={bad} refused"
clean, error = validate_updates({key: str(good)})
assert error is None and clean == {key: good}, f"{key}={good} kept"
def test_a_stored_value_from_before_the_bounds_reads_as_the_nearest_bound():
from inkwell.settings import _BY_KEY, _coerce
assert _coerce(_BY_KEY["session_ttl_days"], 0) == 1
assert _coerce(_BY_KEY["max_attachment_mb"], 500) == MAX_BODY_MB - 1
assert _coerce(_BY_KEY["trash_retention_days"], 30) == 30
def test_validate_rejects_bad_int():
clean, error = validate_updates({"session_ttl_days": "not-a-number"})
assert error is not None
assert clean == {}
def test_an_empty_secret_keeps_what_is_saved():
clean, error = validate_updates({"smtp_password": "", "smtp_host": "smtp.example.test"})
assert error is None
assert clean == {"smtp_host": "smtp.example.test"}
def test_a_choice_must_be_one_of_its_values():
assert validate_updates({"smtp_security": "tls"}) == ({"smtp_security": "tls"}, None)
clean, error = validate_updates({"smtp_security": "ssl"})
assert clean == {} and error
def test_the_public_address_is_an_http_url_without_a_trailing_slash():
assert validate_updates({"public_url": "https://notes.example.test/"}) == (
{"public_url": "https://notes.example.test"},
None,
)
assert validate_updates({"public_url": ""}) == ({"public_url": ""}, None)
clean, error = validate_updates({"public_url": "javascript:alert(1)"})
assert clean == {} and error
def test_choice_labels_name_every_choice():
"""The UI pairs labels with choices by position, so a label list of another length
would put one choice's name on another."""
for d in REGISTRY:
if d.choice_labels is not None:
assert d.choices is not None and len(d.choice_labels) == len(d.choices), d.key