Skip to content

feat(redirect-links): stage util to append ?u= on openhm.xyz URLs (#1164)#1184

Open
oxoxDev wants to merge 5 commits intotinyhumansai:mainfrom
oxoxDev:feat/redirect-links-user-id-5865693557718907555
Open

feat(redirect-links): stage util to append ?u= on openhm.xyz URLs (#1164)#1184
oxoxDev wants to merge 5 commits intotinyhumansai:mainfrom
oxoxDev:feat/redirect-links-user-id-5865693557718907555

Conversation

@oxoxDev
Copy link
Copy Markdown
Contributor

@oxoxDev oxoxDev commented May 4, 2026

Summary

Stage a rust util that appends ?u=<user_id> to every openhm.xyz/<id> URL in a string. Util-only — no call sites yet; the wire-up belongs in a follow-up once openhm.xyz URL emission lands client-side (today the repo only emits internal openhuman://link/<id>).

Problem

Per #1164, every public openhm.xyz/<id> short URL surfaced to the user must carry ?u=<user_id> so the redirect service can attribute clicks and resolve user-scoped state. Today grep -rn "openhm.xyz" src/ returns no hits — the public form is produced backend-side. This PR puts the rewrite logic in place so wiring it from a future caller is one line.

Solution

  • append_user_id_to_public_links(text, Option<user_id>) -> String in src/openhuman/redirect_links/ops.rs — regex-based, idempotent, URL-encodes user_id, preserves existing query strings, anchored on https?:// so lookalike domains (evil-openhm.xyz, openhm.xyz.evil.com) do not match.
  • rewrite_outbound_for_user(config, text, Option<user_id>) — convenience wrapper running the existing rewrite_outbound then injecting ?u=.
  • Re-exported from redirect_links::mod.
  • 10 inline #[cfg(test)] cases cover bare URL, existing query, idempotent, None user, no-URL, multi-URL, special-char encoding, lookalike rejection, surrounding text/punctuation, and the wrapper roundtrip.

Submission Checklist

  • Tests added — 10 inline cases in ops.rs
  • cargo check, cargo fmt --check, cargo clippy clean for redirect_links
  • cargo test --lib redirect_links green (27 pass)
  • Diff coverage ≥ 80%
  • [N/A: util-only PR — no call sites today] — no behavior change for existing callers
  • [N/A: rust-core only, no frontend touch] — no pnpm gates apply

Impact

Zero runtime impact today (no caller). Stages the substitution layer so a future backend or follow-up PR can wrap outbound text in one call.

Related

Closes #1164. Wire-up deferred to follow-up — confirm with @senamakel whether ?u= injection should land render-time (here) or resolve-time (server-side at openhm.xyz).

Summary by CodeRabbit

  • New Features
    • Automatically appends a URL-encoded user identifier to public openhm.xyz links where applicable, preserving surrounding punctuation, handling fragments and existing query parameters, and leaving links unchanged when no identifier is provided or already present.
  • Tests
    • Expanded tests covering expansion and outbound rewriting, encoding, multiple matches, idempotency, query/fragment edge cases, lookalike avoidance, and punctuation preservation.

google-labs-jules Bot and others added 3 commits May 4, 2026 16:47
…inyhumansai#1164)

Adds append_user_id_to_public_links + rewrite_outbound_for_user wrapper.
Util-only — no call sites yet; wire-up follows once openhm.xyz emission
lands client-side. Regex anchored on https?:// (rejects evil-openhm.xyz /
openhm.xyz.evil.com), idempotent (skips URLs already containing u=),
preserves existing query strings, urlencoding::encode for special chars in
user_id. 9 inline test cases.

Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
…yhumansai#1164)

Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
…mansai#1164)

Asserts the wrapper expands openhuman:// placeholders AND tags public
openhm.xyz URLs with ?u= when user_id is Some, and leaves URLs untagged
when user_id is None.

Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
@oxoxDev oxoxDev requested a review from a team May 4, 2026 12:17
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4eba300a-c2af-4231-8ac5-cf25b8235e76

📥 Commits

Reviewing files that changed from the base of the PR and between 83e46cd and 6e7d5e6.

📒 Files selected for processing (1)
  • src/openhuman/redirect_links/ops.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openhuman/redirect_links/ops.rs

📝 Walkthrough

Walkthrough

Adds two exported functions that expand internal link placeholders then append a URL-encoded ?u=<user_id> (or &u=) to domain-anchored https://openhm.xyz/... public links. Handles None user IDs, preserves trailing punctuation and fragments, avoids lookalike domains, is idempotent, and includes unit tests.

Changes

User ID Tagging for Public Links

Layer / File(s) Summary
Data / Pattern
src/openhuman/redirect_links/ops.rs
Introduces public_url_regex() that matches only https://openhm.xyz/... (optional query and fragment) to avoid lookalikes and mid-token matches.
Core Implementation
src/openhuman/redirect_links/ops.rs
Adds append_user_id_to_public_links(text, user_id) which URL-encodes user_id, preserves trailing sentence punctuation, splits #fragment to insert ?u=/&u= into the query, is idempotent (skips when ?u=/&u= present), no-ops when user_id is None, and supports multiple replacements.
Integration / Flow
src/openhuman/redirect_links/ops.rs
Adds rewrite_outbound_for_user(config, text, user_id) that first runs existing rewrite_outbound() to expand openhuman://link/<id> placeholders, then calls append_user_id_to_public_links() on the expanded text.
Public API
src/openhuman/redirect_links/mod.rs
Re-exports append_user_id_to_public_links and rewrite_outbound_for_user alongside existing ops, expanding the module's public API surface.
Tests
src/openhuman/redirect_links/ops.rs (tests)
Adds unit tests covering bare vs query URLs, idempotency, None user_id, non-matching domains, multiple matches, URL-encoding, lookalike avoidance, punctuation preservation, fragment handling, and an integration-style roundtrip for rewrite_outbound_for_user.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hop through text where short links hide,
I tuck a tiny "u=" at the public side.
I mind the commas, dots, and crafty fakes,
I URL-encode each hop the rabbit makes.
Clicks now carry who came by — a happy little stride.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a utility function to append user ID query parameters to openhm.xyz URLs.
Linked Issues check ✅ Passed The PR implements the core utility functions required by #1164, but defers integration with actual call sites to follow-up work.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the utility functions and re-exports specified in the linked issue; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Review rate limit: 3/5 reviews remaining, refill in 14 minutes and 1 second.

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

Copy link
Copy Markdown
Contributor

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openhuman/redirect_links/ops.rs`:
- Around line 34-35: The regex used to match URLs (Regex::new(...) in ops.rs)
currently includes '#' in the query character class, causing appended "u=" to
become part of the fragment for URLs like https://openhm.xyz/abc?foo=bar#frag;
update the regex to exclude '#' from the query charclass (remove '#' from the
class string) and change the tail-appending logic (the code that concatenates
the new param in the block around lines 165–170) to split the matched tail on
'#' into query and fragment parts, insert the "u=..." into the query portion
(adding '?' or '&' as appropriate) and then rejoin with the fragment prefixed by
'#' so the u param is always a query parameter, not part of the fragment.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 394c4d2b-b469-4d8a-8a09-3d1e5de50156

📥 Commits

Reviewing files that changed from the base of the PR and between 995e5cc and 2196f97.

📒 Files selected for processing (2)
  • src/openhuman/redirect_links/mod.rs
  • src/openhuman/redirect_links/ops.rs

Comment thread src/openhuman/redirect_links/ops.rs Outdated
@oxoxDev oxoxDev force-pushed the feat/redirect-links-user-id-5865693557718907555 branch from 594d1bf to 2196f97 Compare May 4, 2026 13:12
google-labs-jules Bot and others added 2 commits May 4, 2026 18:46
…i#1164)

CI cargo fmt --check flagged the single-line assert! at ops.rs:417 — wrap
in multi-line form per rustfmt rules.

Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
…ansai#1164)

CodeRabbit feedback: regex put '#' in the query class, so URLs like
https://openhm.xyz/abc?foo=bar#frag had ?u= appended after the fragment,
making u= fragment data instead of a query parameter. Split the matched
URL on '#' so the user-id always lands in the query, then re-attach the
fragment after. Two new tests cover bare+fragment and query+fragment.

Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
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.

[Feature] Pass user id as ?u= query param when opening openhm.xyz redirect links

1 participant