Skip to content

fix(rest): make /ok health-check shortcut reachable - #85

Closed
bsuttor wants to merge 1 commit into
mainfrom
fix-forwarder-ok-accept-any
Closed

bsuttor wants to merge 1 commit into
mainfrom
fix-forwarder-ok-accept-any

Conversation

@bsuttor

@bsuttor bsuttor commented Jun 9, 2026

Copy link
Copy Markdown
Member

ref: KEYC-77

Summary by CodeRabbit

  • Bug Fixes

    • Fixed health-check endpoints (/ok) for directory, events, and news services to be reachable with any Accept header format, improving compatibility with external monitoring tools.
  • Tests

    • Added functional tests verifying health-check endpoints respond correctly with various Accept header configurations.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adjusts HTTP content-type routing for three REST request-forwarder services to enable their /ok health-check shortcuts to work with Accept: */* headers. Configuration changes three GET routes from application/json to */*, a changelog entry documents the fix, and a new test verifies the endpoints respond correctly without a JSON Accept header.

Changes

REST Accept media type fix

Layer / File(s) Summary
Configure GET routes to accept */*
src/imio/smartweb/core/rest/configure.zcml, CHANGES.rst
Directory, events, and news forwarder GET routes updated from accept="application/json" to accept="*/*"; changelog entry documents the fix for passerelle check_status compatibility.
Verify forwarder /ok without JSON Accept
src/imio/smartweb/core/tests/test_rest.py
New functional test confirms directory, events, and news /ok endpoints respond with 200 and correct JSON payload when Accept header is set to */* instead of application/json.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • IMIO/imio.smartweb.core#84: This PR directly builds on the /ok request-forwarder shortcut implementation by adjusting media-type routing to ensure the /ok endpoints remain reachable for clients sending Accept: */*.

Poem

🐰 Accept all types, reject none,
The /ok shortcut now runs and runs!
From application/json we set it free,
To */* and all can see—
Passerelle health checks, working with glee! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: making the /ok health-check shortcut reachable by adjusting REST accept headers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-forwarder-ok-accept-any

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/imio/smartweb/core/tests/test_rest.py`:
- Around line 751-764: The failing line in
test_request_forwarder_ok_without_json_accept is too long: break the long
assertion into two shorter statements to keep under 88 chars; for example assign
the expected dict to a local variable (e.g. expected = {"status": "ok",
"service": service_name}) and then call self.assertEqual(resp.json(), expected).
Locate the code in the test_request_forwarder_ok_without_json_accept function
and replace the single long self.assertEqual(...) line with the two shorter
lines so line length rules are satisfied.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e73cef73-2444-4236-b487-88c93447d5cc

📥 Commits

Reviewing files that changed from the base of the PR and between 0dcf0c0 and ad546ab.

📒 Files selected for processing (3)
  • CHANGES.rst
  • src/imio/smartweb/core/rest/configure.zcml
  • src/imio/smartweb/core/tests/test_rest.py

Comment on lines +751 to +764
def test_request_forwarder_ok_without_json_accept(self):
# passerelle's check_status sends `Accept: */*` (no application/json),
# so the endpoint must be registered for that media type too.
for endpoint, service_name in (
("@directory_request_forwarder", "directory"),
("@events_request_forwarder", "events"),
("@news_request_forwarder", "news"),
):
session = RelativeSession(self.portal_url)
session.headers.pop("Accept", None)
resp = session.get(f"/{endpoint}/ok")
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.json(), {"status": "ok", "service": service_name})
session.close()

@coderabbitai coderabbitai Bot Jun 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix line length violation on line 763.

Line 763 exceeds the 88-character limit (89 characters). As per coding guidelines, Python line length must be 88 characters (black-compatible).

🔧 Suggested fix
             session = RelativeSession(self.portal_url)
             session.headers.pop("Accept", None)
             resp = session.get(f"/{endpoint}/ok")
             self.assertEqual(resp.status_code, 200)
-            self.assertEqual(resp.json(), {"status": "ok", "service": service_name})
+            expected = {"status": "ok", "service": service_name}
+            self.assertEqual(resp.json(), expected)
             session.close()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_request_forwarder_ok_without_json_accept(self):
# passerelle's check_status sends `Accept: */*` (no application/json),
# so the endpoint must be registered for that media type too.
for endpoint, service_name in (
("@directory_request_forwarder", "directory"),
("@events_request_forwarder", "events"),
("@news_request_forwarder", "news"),
):
session = RelativeSession(self.portal_url)
session.headers.pop("Accept", None)
resp = session.get(f"/{endpoint}/ok")
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.json(), {"status": "ok", "service": service_name})
session.close()
def test_request_forwarder_ok_without_json_accept(self):
# passerelle's check_status sends `Accept: */*` (no application/json),
# so the endpoint must be registered for that media type too.
for endpoint, service_name in (
("`@directory_request_forwarder`", "directory"),
("`@events_request_forwarder`", "events"),
("`@news_request_forwarder`", "news"),
):
session = RelativeSession(self.portal_url)
session.headers.pop("Accept", None)
resp = session.get(f"/{endpoint}/ok")
self.assertEqual(resp.status_code, 200)
expected = {"status": "ok", "service": service_name}
self.assertEqual(resp.json(), expected)
session.close()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/imio/smartweb/core/tests/test_rest.py` around lines 751 - 764, The
failing line in test_request_forwarder_ok_without_json_accept is too long: break
the long assertion into two shorter statements to keep under 88 chars; for
example assign the expected dict to a local variable (e.g. expected = {"status":
"ok", "service": service_name}) and then call self.assertEqual(resp.json(),
expected). Locate the code in the test_request_forwarder_ok_without_json_accept
function and replace the single long self.assertEqual(...) line with the two
shorter lines so line length rules are satisfied.

Source: Coding guidelines

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we use ruff instead of black now

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@bsuttor, thanks for the clarification! I've noted that this project uses ruff instead of black for Python formatting.


✏️ Learnings added
Learnt from: bsuttor
Repo: IMIO/imio.smartweb.core PR: 85
File: src/imio/smartweb/core/tests/test_rest.py:751-764
Timestamp: 2026-06-09T13:51:59.137Z
Learning: In the imio.smartweb.core repository, ruff is used as the Python formatter/linter instead of black. When reviewing Python code style and line length compliance, reference ruff configuration rather than black.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@bsuttor bsuttor closed this Jun 15, 2026
@bsuttor
bsuttor deleted the fix-forwarder-ok-accept-any branch June 15, 2026 09:34
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.

1 participant