## Implementation Plan: Jack Up Comment Length (Default 1000 → 5000, Live-Changeable) ### Summary Increase the default comment maximum length from 1000 to 5000 characters and make the limit dynamically adjustable via the existing site_settings mechanism (60s TTL cache) with environment variable fallback (`DEVPLACE_COMMENT_MAX_LENGTH`). This requires introducing a single resolver function `get_comment_max_length()` and applying it across nine consumption points, plus documentation and test updates. --- ### Step-by-Step Changes #### 1. Core Resolver Create a new function in `devplacepy/database/settings.py` (or a new module, but reuse existing pattern). This function will be the single source of truth for all runtime lookups. ```python def get_comment_max_length() -> int: from devplacepy.config import COMMENT_MAX_LENGTH # avoid circular import return get_int_setting("comment_max_length", COMMENT_MAX_LENGTH) ``` #### 2. Models (`devplacepy/models.py`) - Lines 160, 175: Replace `Field(max_length=COMMENT_MAX_LENGTH)` with `Field(max_length=10000)` (generous hard cap). - Add a Pydantic `@field_validator('content')` that calls `get_comment_max_length()` and raises `ValueError` if length exceeds the current live value. #### 3. Templating Globals (`devplacepy/templating.py`) - Lines 9, 70: Replace the direct value reference with a callable: `lambda: get_comment_max_length()`. The Jinja `{{ comment_max_length }}` in templates will invoke this callable transparently. #### 4. Documentation Strings (API docs, Devii tool descriptions) These must evaluate `get_comment_max_length()` at render time, not import time. For each file: - `devplacepy/docs_api/groups/content.py` (lines 3, 233, 294): Replace `COMMENT_MAX_LENGTH` with `get_comment_max_length()`. - `devplacepy/docs_devrant.py` (lines 3, 242): Same. - `devplacepy/services/devii/actions/catalog/comments.py` (lines 5, 32): Same. All of these use f-strings inside callables (e.g., endpoint descriptions or tool parameter descriptions) that are evaluated lazily, so the function call will return the current value. #### 5. Route-level Validation Replace direct constant imports with runtime calls: - `devplacepy/routers/devrant/rants.py` lines 230-232: Replace `COMMENT_MAX_LENGTH` with `get_comment_max_length()`. - `devplacepy/routers/devrant/comments.py` lines 72-74: Same. #### 6. Bot Process (`devplacepy/services/containers/files/bot.py` line 75) This process runs separately and reads `os.environ.get("DEVPLACE_COMMENT_MAX_LENGTH", ...)`. No code change needed; update the environment variable default in `.env.example` and README. #### 7. Documentation - **`README.md` line 172**: Change “default 1000” to “default 5000”. Add a new section (or subsection after “Configuration”) explaining that the value can be changed at runtime via the settings API or admin UI, and that the environment variable acts as a fallback when the DB setting is absent. - **`.env.example` lines 42-44**: Update `DEVPLACE_COMMENT_MAX_LENGTH=5000`. #### 8. Tests - **Unit tests**: Ensure existing API tests (`tests/api/comments/create.py` lines 350-366, `tests/api/comments/edit.py` lines 134-147) still pass (they post content > 1000 but ≤ 5000). Update the test constants if needed to reflect the new default. - **E2E test**: Add a new test in `tests/e2e/post.py` that navigates to the comment form, fills in text exceeding `get_comment_max_length()`, submits, and checks for a client-side or server-side rejection. This validates that the Jinja and API layers agree. --- ### Definition of Done - [ ] All nine consumption points listed in the investigation have been updated to use `get_comment_max_length()`. - [ ] `.env.example` shows `DEVPLACE_COMMENT_MAX_LENGTH=5000`. - [ ] `README.md` documents both the environment variable and runtime setting mechanism; default value updated. - [ ] New Pydantic validator in `models.py` enforces live max length; `Field(max_length=10000)` acts as hard cap. - [ ] Existing API tests for too-long comments pass (update test data to use a length > 5000 if they were testing 1001). - [ ] One new e2e test (in `tests/e2e/post.py`) creates a comment exceeding the live limit and expects a rejection. - [ ] All project verification commands pass: ``` pip install -e '.[dev]' -q && make test-unit pip install -q ruff && ruff check . ``` - [ ] Manual smoke test: start dev server with default `DEVPLACE_COMMENT_MAX_LENGTH=5000`, verify comment form shows `maxlength=5000`, submit a 5001-character comment, get rejected. Then change the setting via admin UI to 2000, verify the same flow rejects at 2001. - [ ] No regressions detected in related functionality (comment editing, rant posting, Devii tool usage).