Skip to content

Add CI lint for hardcoded user_id and gate demo-sensitive routers via ALWRITY_DEMO_RELEASE#456

Open
AJaySi wants to merge 1 commit intomainfrom
codex/add-ci-lint-check-for-user_id-patterns
Open

Add CI lint for hardcoded user_id and gate demo-sensitive routers via ALWRITY_DEMO_RELEASE#456
AJaySi wants to merge 1 commit intomainfrom
codex/add-ci-lint-check-for-user_id-patterns

Conversation

@AJaySi
Copy link
Copy Markdown
Owner

@AJaySi AJaySi commented Mar 30, 2026

Motivation

  • Prevent accidental shipping of forced/hardcoded user IDs (e.g. user_id = 1, force user_id) outside of test fixtures by failing CI checks.
  • Ensure demo-only functionality (Facebook/LinkedIn/persona routers) can be safely disabled for demo releases and that disabled routers are absent from the /api/routers/status listing.

Description

  • Add a new GitHub Actions workflow .github/workflows/lint-forced-user-id.yml that runs a repository check on PRs and pushes to main to detect forced/hardcoded user_id patterns.
  • Add backend/scripts/check_forced_user_id_patterns.py, a script that scans python sources (while excluding tests/fixtures and the script itself) and fails on patterns like \buser_id\s*=\s*1\b and force user_id.
  • Implement demo-release gating in RouterManager (backend/alwrity_utils/router_manager.py) via a _demo_release_mode_enabled() helper that reads ALWRITY_DEMO_RELEASE and skips inclusion of facebook_writer, linkedin, linkedin_image, and persona routers when enabled so they do not appear in included_routers.
  • Remove hardcoded user-id usage in affected flows by switching persona endpoints to use the authenticated current_user and by replacing other forced user_id occurrences with either request-derived IDs or an environment-configurable fallback (ALWRITY_FALLBACK_USER_ID), and update monitoring/strategy services to resolve user IDs from DB records where appropriate.
  • Add a release-readiness assertion in backend/sif_release_readiness_checks.py to check the presence of the demo-release guard strings in the router manager source.

Testing

  • Ran the new lint script python backend/scripts/check_forced_user_id_patterns.py which reported no violations after the code updates (passed).
  • Ran python -m py_compile against the modified modules to validate syntax (passed).
  • Ran the release-readiness unit suite with PYTHONPATH=backend python -m unittest backend/sif_release_readiness_checks.py, which exercises the added source check, but the run reported a pre-existing unrelated test error (ContentGuardianAgent missing verify_originality) that caused the suite to fail and is not caused by these changes.
  • The CI workflow is configured to execute the lint check on pull_request and push to main so the repository will block merges that reintroduce forbidden patterns.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant