Skip to content

Read the backend contract from its TypeScript server - #28

Merged
Mathis (echobt) merged 1 commit into
mainfrom
backend-typescript-contract
Sep 30, 2026
Merged

Mathis (echobt) merged 1 commit into
mainfrom
backend-typescript-contract

Conversation

@echobt

@echobt Mathis (echobt) commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

The backend replaces its Rust crates with server/ in CortexLM/backend#441, so this validator's crates/… reads fail there.

  • Error codes and PROBLEM_TYPE_BASE now come from server/src/core/error.ts (ERROR_CODES keys).
  • Registered paths come from the route literals under server/src/api: /v1 prefix except health probes and /internal/…; admin-listener literals (/v1/admin/…) stay out of the public set.

Test plan:

  • node scripts/check-docs-site.mjs <backend at #441>: ok (24 problem pages; 317 router paths). The 317 match the public rows of the backend's route-parity fixture exactly.
  • bash scripts/tests/check-docs-site.test.sh: ok. New cases: a code removed from ERROR_CODES fails; documenting an admin path fails.
  • check-docs-content, docs-ui, docs-images tests: ok. mint validate not run locally (network).

Merge order: this must land with or before backend#441; the backend CI pins this commit.

Summary by CodeRabbit

  • Documentation
    • Clarified which server error codes and API routes support documented problem pages.
  • Bug Fixes
    • Documentation checks now validate problem codes and documented API paths against the TypeScript server, helping catch references to unregistered routes or unknown codes.
    • Checks now report a missing documentation checkout as a failure.

The backend replaced its Rust crates with server/ (CortexLM/backend#441).
Error codes and PROBLEM_TYPE_BASE now come from server/src/core/error.ts and
registered paths from the route literals under server/src/api; admin-listener
paths stay out of the public set.
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4454640d-8a4d-4038-95d1-0fac73b881e2

📥 Commits

Reviewing files that changed from the base of the PR and between 9e0daaf and c18d111.

📒 Files selected for processing (3)
  • README.md
  • scripts/check-docs-site.mjs
  • scripts/tests/check-docs-site.test.sh

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The documentation checker now validates problem pages against the TypeScript server’s ERROR_CODES and documented API paths against route modules under server/src/api. The README and test fixtures now refer to these TypeScript sources.

Changes

Documentation validation

Layer / File(s) Summary
Discover TypeScript contracts and routes
scripts/check-docs-site.mjs
The checker parses server error codes and API route registrations, and loads TypeScript files under server/src/api.
Validate documentation against server sources
scripts/check-docs-site.mjs, scripts/tests/check-docs-site.test.sh, README.md
Problem-page and route checks use the TypeScript server sources. The README and tests describe and exercise these checks, including missing docs checkouts, undocumented server error codes, and admin-listener routes.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to c18d1

The validator now reads TypeScript backend contracts, with no demonstrated merge-blocking issue. Compatibility with the actual backend route conventions remains unverified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to c18d1

The change remains a file-based documentation check and does not expose or execute backend routes. Residual uncertainty concerns whether the new route-discovery rules accurately distinguish public and private routes in the external backend.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed contract can affect documentation-validation results and CI compatibility. It does not itself grant backend privileges or make a discovered route reachable over the network.

Trust Boundaries and Controls

  • observed — External backend source enters the changed checker through filesystem reads and string parsing, not backend imports or evaluation. The fixture expects documentation of a /v1/admin route to fail, but establishes only the synthetic convention, not production listener separation.

Resilience and Maintainability Implications

  • observed — The routed fixture mutations occur in separately seeded case directories under a unique temporary root with EXIT cleanup. They do not introduce a shared production-state transition.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: the documentation validator now reads the backend contract from the TypeScript server.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

@echobt
Mathis (echobt) merged commit ed7e41f into main Sep 30, 2026
6 checks passed

@cortex-security-agent cortex-security-agent 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.

Cortex Security

Nothing to change. Cortex Security reviewed every changed file and found no issues.

●●●●● 5/5 — Nothing to change

What happens, in order
flowchart
  errorSrc["server/src/core/error.ts"] --> baseCheck{PROBLEM_TYPE_BASE == "https://docs.cortex.foundation/problems"?}
  errorSrc --> codes["parse ERROR_CODES codes"]
  baseCheck -- no --> fail1["FAIL: PROBLEM_TYPE_BASE mismatch"]
  baseCheck -- yes --> tsBaseCheck["check packages/api-types/src/errors.ts PROBLEM_TYPE_BASE"]
  tsBaseCheck -- mismatch --> fail2["FAIL: PROBLEM_TYPE_BASE mismatch"]
  tsBaseCheck -- ok --> codes
  codes --> missingPageCheck{for each code: problems/{code}.mdx exists?}
  missingPageCheck -- no --> fail3["FAIL: missing problem page"]
  missingPageCheck -- yes --> extraPageCheck{for each .mdx: code in ERROR_CODES?}
  extraPageCheck -- no --> fail4["FAIL: undocumented error code"]
  extraPageCheck -- yes --> routerCheck["walk server/src/api/*.ts → extract registered routes"]
  routerCheck --> docPathCheck{for documented /v1/… paths: registered in router?}
  docPathCheck -- no --> fail5["FAIL: undocumented API path"]
Loading

3 further observations did not survive verification and were not posted.

Open in Cortex Security


Review 1 · read c18d111 · comment @cortex-security-agent review to look again

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