Skip to content

Conversation

@adamoutler
Copy link
Collaborator

@adamoutler adamoutler commented Jan 31, 2026

📌 Description

Implemented a friendly redirect from the root path (/) to the API documentation (/docs) to improve user experience for browser-based access. Additionally, added unit tests for both the redirect logic and the documentation serving endpoint.


🔍 Related Issues


📋 Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Code refactor
  • 📚 Documentation update
  • 🧪 Test addition or change
  • 🔧 Build/config update
  • 🚀 Performance improvement
  • 🔨 CI/CD or automation
  • 🧹 Cleanup / chore

📷 Screenshots or Logs (if applicable)

image
test/api_endpoints/test_docs.py ..                                       [100%]

============================== 2 passed in 0.86s ===============================

✅ Checklist

  • I have read the Contribution Guidelines
  • I have tested my changes locally
  • I have updated relevant documentation (if applicable)
  • I have verified my changes do not break existing behavior
  • I am willing to respond to requested changes and feedback

Summary by CodeRabbit

  • New Features

    • Added a root endpoint that redirects visitors from the site root to the API documentation.
  • Tests

    • Added tests verifying the root redirect behavior (HTTP redirect to docs).
    • Added tests ensuring the API documentation endpoint returns HTML content.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2026

📝 Walkthrough

Walkthrough

Adds a root Flask route (/) that redirects to the API documentation and new unit tests validating the redirect and the /docs endpoint; notes a potential risk of duplicate index_redirect route definitions.

Changes

Cohort / File(s) Summary
Root Redirect Implementation
server/api_server/api_server_start.py
Added Flask imports (redirect, url_for) and a new index_redirect() function with @app.route('/') that redirects root requests to the API docs (url_for('api_docs')). Potential duplicate route definition introduced.
Docs Endpoint Tests
test/api_endpoints/test_docs.py
Added tests: test_index_redirect_logic() asserts a 302 redirect from / to /docs; test_api_docs_logic() asserts /docs returns 200, text/html mimetype, and contains HTML content.

Poem

🐰 I hopped to the root and gave a peep,
A gentle nudge, a redirect leap,
Off to the docs where wisdom blooms,
My code-tip feet beat quiet tunes,
Hop, click, and learn — hooray for rooms!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Redirect from / to /docs' is a concise, clear summary of the main change—adding a root path redirect to the API documentation endpoint.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@test/api_endpoints/test_docs.py`:
- Line 1: The top-of-file comment contains an outdated path string "#
tests/test_root_redirect.py"; update or remove that comment so it correctly
reflects this file's purpose (e.g., replace with a relevant comment like "#
tests for docs API endpoints" or just delete the line). Locate the line with the
exact string "# tests/test_root_redirect.py" in the test file and change it
accordingly to avoid confusion.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@test/api_endpoints/test_docs.py`:
- Around line 7-13: The test_index_redirect_logic currently calls the view
function index_redirect() directly which bypasses Flask routing; change it to
use the Flask test client via api_server_start.app.test_client() and issue a GET
request to "/" so the full request cycle and routing are exercised; assert the
response status_code is 302 (or the expected redirect code) and that
response.headers['Location'] == '/docs' to verify the route wiring rather than
calling index_redirect() directly.
🧹 Nitpick comments (1)
test/api_endpoints/test_docs.py (1)

16-24: Improve consistency by using test_client() to exercise the actual /docs route.

The current test uses test_request_context() and calls api_docs() directly. However, all other tests in the codebase use test_client() with HTTP method calls (e.g., client.get()), which properly validates the route and integrates routing logic. Additionally, get_data() is the recommended way to read file responses from send_from_directory() in Flask tests, avoiding manual response iteration.

Proposed refactor
 def test_api_docs_logic():
-    """Test that api_docs attempts to serve the correct file."""
-    with api_server_start.app.test_request_context():
-        response = api_server_start.api_docs()
-        assert response.status_code == 200
-        assert response.mimetype == 'text/html'
-        # Manually join the chunks from the generator
-        data = b"".join(response.response)
-        assert b'<!DOCTYPE html>' in data or b'<html>' in data
+    """Test that /docs serves HTML."""
+    with api_server_start.app.test_client() as client:
+        response = client.get("/docs")
+        assert response.status_code == 200
+        assert response.mimetype == "text/html"
+        response.direct_passthrough = False
+        data = response.get_data()
+        assert b"<!DOCTYPE html>" in data or b"<html>" in data

@jokob-sk jokob-sk merged commit 87b15fb into netalertx:main Jan 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants