Skip to content

refactor: centralize slugify in utils (#30)#32

Merged
wpak-ai merged 4 commits intomasterfrom
feat/30-unify-slugify-utils
May 7, 2026
Merged

refactor: centralize slugify in utils (#30)#32
wpak-ai merged 4 commits intomasterfrom
feat/30-unify-slugify-utils

Conversation

@clean6378-max-it
Copy link
Copy Markdown
Collaborator

@clean6378-max-it clean6378-max-it commented May 6, 2026

Summary

Consolidates _slugify into a single implementation under utils.slugify.slugify, completing the residual CCC8 work after PR #24 (session-text exclusion plumbing). api/export_api.py and scripts/export.py now both import the shared helper; duplicate local definitions are removed.

Changes

  • Add utils/slugify.py with slugify(text: str) -> str: lowercase, replace runs of non-[a-z0-9] with -, strip hyphens (matches former export_api behavior).
  • api/export_api.py: drop local _slugify, use from utils.slugify import slugify.
  • scripts/export.py: drop character-loop _slugify (isalnum / Unicode-preserving), use shared slugify.
  • Add tests/test_slugify.py for ASCII, punctuation collapse, Unicode titles, empty-ish input, and digits.

Behavior note

Canonical slugging is ASCII-only (same as the previous HTTP export path). CLI export filenames for titles with non-ASCII letters may change vs the old script (e.g. accented characters are folded into hyphens like the web bulk export). Zip and download filenames stay predictable across platforms.

Testing

  • pytest186 passed locally.

References

Summary by CodeRabbit

  • New Features
    • Export API responses now include last_export_time and export_count for improved export visibility.
  • Improvements
    • Exported filenames and archive paths now use a consistent ASCII-safe slug format with a fallback default for empty titles, ensuring portable, predictable naming and parity between CLI and API exports.
  • Tests
    • Added regression tests covering slug behavior: hyphenation, punctuation collapsing, Unicode handling, empty-input fallback, and digit preservation.

Add utils.slugify.slugify (ASCII-safe, matches former export_api).
Remove duplicate implementations from api/export_api.py and
scripts/export.py; add regression tests.
Closes #30
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d529dfaa-48ac-43b2-982e-82e65d46f654

📥 Commits

Reviewing files that changed from the base of the PR and between f94bde7 and fd88ba4.

📒 Files selected for processing (1)
  • utils/slugify.py
✅ Files skipped from review due to trivial changes (1)
  • utils/slugify.py

📝 Walkthrough

Walkthrough

Consolidates two local slugify implementations into a single utils/slugify.py, updates api/export_api.py and scripts/export.py to import and use slugify (with a default fallback), renames API response keys from lastExportTime/exportedCount to last_export_time/export_count, and adds regression tests including export path parity checks.

Changes

Slug Consolidation and API Response Update

Layer / File(s) Summary
Core Utility
utils/slugify.py
Adds slugify(text: str, *, default: str = "") -> str: lowercases input, replaces runs of non-[a-z0-9] with a single hyphen, trims hyphens, returns default when result is empty; includes module docstring.
API Integration
api/export_api.py
Removes local _slugify, imports slugify from utils.slugify, replaces session/project slug generation in bulk_export and export_session with slugify(..., default=...), and maps persisted lastExportTime/exportedCount to last_export_time/export_count in /api/export/state.
Script Integration
scripts/export.py
Imports slugify from utils.slugify, uses slugify(..., default=...) for bulk and single-session export filenames/paths, and removes the module-local _slugify.
Tests
tests/test_slugify.py
Adds and extends regression tests covering ASCII hyphenation, punctuation collapsing, Unicode handling, digit preservation, default fallback when slug is empty, and a parity test verifying API zip inner paths match CLI-relative path formatting.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit trims paths with gentle hops,
One slug to rule the filename crops,
Tests planted neat where edges fray,
Exports march tidy, all the way—
Hooray for shared steps and fewer stops! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.46% which is insufficient. The required threshold is 80.00%. 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 summarizes the main change: consolidating duplicate slugify implementations into a shared utility module.
Linked Issues check ✅ Passed The PR successfully addresses all coding-related requirements from issue #30: consolidates duplicate _slugify implementations into utils/slugify.py, removes local copies from api/export_api.py and scripts/export.py, adds comprehensive regression tests in tests/test_slugify.py, and provides clear documentation of the unified behavior.
Out of Scope Changes check ✅ Passed All changes directly align with issue #30 objectives: no unrelated modifications to exclusion-rule logic, frontend code, or other tangential areas are present in the changeset.

✏️ 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 feat/30-unify-slugify-utils

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

Copy link
Copy Markdown

@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: 2

🤖 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 `@api/export_api.py`:
- Around line 96-99: When slugify(project["name"]) can return an empty string
causing rel_path to start with a slash, ensure proj_slug is replaced with a safe
fallback before building rel_path: set proj_slug = slugify(project["name"]) or a
default (e.g., "project" or short_id) and use that sanitized value when
composing rel_path (alongside ts_file, title_slug, short_id) so the zip entry is
never absolute-like.

In `@scripts/export.py`:
- Around line 370-373: slugify(session["title"]) and slugify(project["name"])
can return an empty string; update the assignments for title_slug and
project_slug to fall back to a stable value when empty (e.g., use short_id,
"untitled", or a combination like f"untitled-{short_id}"). Specifically, after
computing title_slug = slugify(session["title"]) and project_slug =
slugify(project["name"]), replace them with logic that checks for a falsy string
and assigns a fallback (reference the variables title_slug, project_slug,
short_id and sid) so exported filenames/paths never contain empty slugs.
🪄 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: c67d3b87-cc50-4ce8-a577-dc7c99c29490

📥 Commits

Reviewing files that changed from the base of the PR and between 09de881 and d13b071.

📒 Files selected for processing (4)
  • api/export_api.py
  • scripts/export.py
  • tests/test_slugify.py
  • utils/slugify.py

Comment thread api/export_api.py Outdated
Comment thread scripts/export.py Outdated
@clean6378-max-it clean6378-max-it requested a review from timon0305 May 6, 2026 21:58
Comment thread utils/slugify.py
Comment thread utils/slugify.py Outdated
Comment thread scripts/export.py Outdated
Comment thread scripts/export.py Outdated
Comment thread scripts/export.py Outdated
Comment thread tests/test_slugify.py
@clean6378-max-it clean6378-max-it requested a review from wpak-ai May 7, 2026 21:32
@wpak-ai wpak-ai merged commit e0e0a76 into master May 7, 2026
2 checks passed
@wpak-ai wpak-ai deleted the feat/30-unify-slugify-utils branch May 7, 2026 21:59
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.

Issue — claude-code-chat-browser — Exclusion rule consolidation: residual _slugify divergence (**CCC8**) (3 pt)

3 participants