feat(web): auth-gate code search submit on Ask GH

Merged
MS
2mo ago
+67-6

Fixes SOU-2307

Summary

  • Adds a client-side login gate to non-empty code search submissions only when EXPERIMENT_ASK_GH_ENABLED=true and the user is anonymous.
  • Reuses Ask Sourcebot's server-derived isAuthenticated / isLoginWallEnabled contract, shared LoginDialog, and empty-submission behavior, while tracking code-search prompts separately with wa_publicsaas_cs_login_wall_prompted.
  • Preserves anonymous access to existing search results, code previews, files, repository trees, and file history.
  • Carries the requested search URL through authentication so the pending search runs automatically after login.
  • Leaves Ask GH-off behavior unchanged.

E2E matrix

Tested the final behavior at e372c864. The analytics-only follow-up at 4e6cd962 passed the full lint and test suite. For regression comparisons, tested the exact pre-change baseline at a28b1812 with the same indexed repository, database, and action sequence.

Ask GH on + anonymous access enabled

  • Main /search: anonymous SearchBar submission opened Sign in to continue; after credentials login, the browser automatically reached /search?query=SearchBar and rendered results without query re-entry.
  • Anonymous browsing: directly opened existing SearchBar results, opened code preview and full file browser, navigated from layoutClient.tsx to layout.tsx, and viewed commit history without a login wall.
  • Existing result page: anonymous user changed SearchBar to LoginDialog; login wall appeared over the old results; after login, the browser automatically reached /search?query=LoginDialog and rendered the new results.
  • Empty submission: pressing Enter with an empty search did not open the login wall or navigate.




Ask GH off + anonymous access enabled

Ran the same script on changed and baseline deployments: anonymous SearchBar search, result preview, full file browser, file-tree navigation to layout.tsx, history view, and LoginDialog search from the result page. Both remained ungated and produced matching behavior.

Changed deployment:

Pre-change baseline:

Ask GH off + anonymous access disabled

Ran the same script on changed and baseline deployments. Both redirected logged-out /search requests to /login with no guest option. After authentication, both completed the same search, preview, file-tree, history, and second-search flow with matching behavior.

Changed deployment:

Pre-change baseline:

Automated validation

  • yarn workspace @sourcebot/web lint
  • yarn workspace @sourcebot/web test --run (147 files, 1,503 tests)
  • GitHub build, lint, test, OpenAPI generation, CodeQL, and vulnerability checks pass.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

Summary by cubic

Gates code search submissions behind a client-side login for anonymous users when EXPERIMENT_ASK_GH_ENABLED=true, while preserving anonymous access to results and repository browsing.

  • Unauthenticated users see a login dialog instead of being sent to search results, with their pending search automatically resuming at the result URL after sign-in.
  • Empty searches don't trigger the login wall, and the prompt is captured as wa_publicsaas_cs_login_wall_prompted.
  • Rolls the shared LoginDialog out of Ask chat so code search and chat use one component.
  • Deployments without the flag keep existing behavior; the changelog documents the change.

Summary by CodeRabbit

  • New Features
    • When the Ask GitHub experiment is enabled, search prompts from signed-out visitors open a login dialog instead of navigating to results.
    • After signing in, visitors can continue to the search they requested. Search behavior remains unchanged when the experiment is disabled.