Skip to content

feat(mapper): add Django route mapping#54

Merged
steipete merged 5 commits into
openclaw:mainfrom
rohitjavvadi:feat/django-route-mapper
May 18, 2026
Merged

feat(mapper): add Django route mapping#54
steipete merged 5 commits into
openclaw:mainfrom
rohitjavvadi:feat/django-route-mapper

Conversation

@rohitjavvadi
Copy link
Copy Markdown
Contributor

Closes #53

Summary

  • add conservative Django urls.py route mapping for path, re_path, and legacy url
  • normalize simple Django path converters and named regex groups into route features
  • treat include("app.urls") as a URL group without recursively expanding imported configs
  • avoid mapping route-like calls from comments, strings, docstrings, helper lists, and local-only urlpatterns

Testing

  • ./node_modules/.bin/vitest run src/mapper.test.ts
  • ./node_modules/.bin/tsc -p tsconfig.json --noEmit
  • ./node_modules/.bin/oxlint . --config oxlint.json
  • ./node_modules/.bin/vitest run

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f5e591f66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mappers/python.ts
Comment on lines +651 to +652
if (previous !== undefined && /[A-Za-z0-9_.]/u.test(previous)) {
return null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject route-helper matches inside underscored names

The identifier-boundary check in djangoRouteHelperAt misses _ as a valid preceding identifier character, so calls like custom_path('x/', view) inside urlpatterns are parsed from the path( substring and incorrectly emitted as Django routes. This creates false-positive route features (wrong ownership/tests/trust boundaries) in Django projects that use helper functions with names ending in _path, and the issue is introduced by the new Django mapper logic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for calling this out. I checked this path and the matcher already treats _ as part of the preceding identifier, so custom_path(...) is skipped instead of being parsed from the inner path substring.

I added an explicit regression test for this case in src/mapper.test.ts to make that behavior clear and keep it covered going forward. Focused mapper tests, typecheck, and lint are passing.

@steipete steipete merged commit 8b4154b into openclaw:main May 18, 2026
6 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d8bbc0597

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mappers/python.ts

function djangoRouteHelperAt(source: string, index: number): string | null {
const previous = source[index - 1];
if (previous !== undefined && /[A-Za-z0-9_.]/u.test(previous)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat underscore as an identifier char before route helpers

The boundary check in djangoRouteHelperAt still allows matching path( inside larger identifiers because _ is not included in the preceding-character class, so custom_path('x/', view) is parsed as a Django path(...) call and produces a false route feature. This creates incorrect ownership/tests/trust-boundary mapping in projects that use helper names ending in _path. Fresh evidence in this commit is that the guard regex is /[A-Za-z0-9_.]/, which omits _.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I rechecked this against the merged code and the current test coverage. The guard is /[A-Za-z0-9_.]/u, so _ is already part of the preceding-character class. For custom_path(...), the scanner reaches the p in path, sees _ as the previous character, and returns null rather than treating it as a Django path(...) helper.

This is also covered by the mapper fixture now: it includes custom_path('custom/', views.custom) and asserts /custom/ is not emitted as a Django route. I do not think there is a code change needed for this one.

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.

Add Django urls.py route mapping

2 participants