Skip to content

fix: url inspector channel filtering check for semrush dashboards - #2940

Open
vivesing wants to merge 5 commits into
mainfrom
feat/channel-filter-sr
Open

fix: url inspector channel filtering check for semrush dashboards#2940
vivesing wants to merge 5 commits into
mainfrom
feat/channel-filter-sr

Conversation

@vivesing

@vivesing vivesing commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes — feat/channel-filter-sr

Problem

The URL Inspector channel (content-type) query parameter was inconsistently handled across three Serenity brand-presence endpoints:

  • owned-urls never read/forwarded channel at all.
  • cited-domains and domain-urls did filter by channel, but only via .trim().toLowerCase() — so a value like benchmark_competitors never matched the Semrush Elements API's "Benchmark Competitors" (space-separated, Title Case), silently dropping results.

Changes

src/support/elements/constants.js

  • Added a shared normalizeChannel(value) helper: trims, lowercases, and collapses _/- to spaces, so benchmark_competitors and Benchmark Competitors both canonicalize to benchmark competitors.

src/support/elements/definitions/cited-domains.js

  • paginateDomains now uses normalizeChannel for the channel vs contentType comparison instead of plain lowercase, fixing the benchmark_competitors mismatch.

src/support/elements/definitions/domain-urls.js

  • transformDomainUrlsResponse now uses normalizeChannel for the same channel vs contentType comparison. Same fix as above.

src/support/elements/definitions/owned-urls.js

  • transformOwnedUrlsResponse now compares domain_type via normalizeChannel(row.domain_type) !== 'owned' (format-insensitive) but
    always filters to owned — this endpoint intentionallel` filter, by design (unlike its two siblings).

src/controllers/elements.js

  • listOwnedUrls explicitly does not read channel/selectedChannel from the query, with an inline comment clarifying this is deliberate,
    so a caller-supplied channel on this endpoint has no eff

Net effect

Endpoint Channel behavior
owned-urls Always returns domain_type = Owned rows
cited-domains Filters by channel, now correctly matching all 5 values including benchmark_competitors
domain-urls Filters by channel, same fix as `cited

Verification

  • `npx eslint src/support/elements/ src/controllers/elemen
  • npx mocha test/support/elements/definitions/cited-domains.test.js test/controllers/elements.test.js — 175 passing

@vivesing
vivesing requested a review from MysticatBot July 29, 2026 11:48
@github-actions

Copy link
Copy Markdown

This PR will trigger a patch release when merged.

@MysticatBot MysticatBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @vivesing,

⚠ Degraded review - no spec document was found for this change (searched the PR links, the touched repos' docs, the architecture/guidelines docs, and linked Jira). This review covers code-level quality but could not validate the change against an agreed design, so confidence is reduced. Add a spec link (PR template section 4) and re-request review for a full-confidence pass.

Verdict: Request changes - missing unit test for the new shared utility.
Complexity: MEDIUM - small diff; API surface signal.
Changes: Extracts channel normalization into a shared normalizeChannel utility to fix case/format-insensitive filtering between UI snake_case params and Semrush Title Case responses (5 files).

Must fix before merge

  1. [Important] No unit test for normalizeChannel - src/support/elements/constants.js:76 (details inline)
Non-blocking (2): minor issues and suggestions
  • nit: Comment changed to "Channel filter" but this block is specifically the "Owned" filter (hardcoded !== 'owned' check) - the old wording was more accurate - src/support/elements/definitions/owned-urls.js:134
  • suggestion: Align the normalized-channel variable name across cited-domains.js (wanted) and domain-urls.js (channel) since they are described as mirroring each other - src/support/elements/definitions/domain-urls.js:131

Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 1m 21s | Cost: $2.90 | Commit: 5aa7efae2631802019af76191590777651a1bc1f
If this code review was useful, please react with 👍. Otherwise, react with 👎.

Comment thread src/support/elements/constants.js
@MysticatBot MysticatBot added ai-reviewed Reviewed by AI complexity:medium AI-assessed PR complexity: MEDIUM labels Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@calvarezg

Copy link
Copy Markdown
Contributor

Multi-persona review — PR #2940

Recommendation: Approve. No critical, major, security, or DB issues. CI is green, including codecov/patchnormalizeChannel is exercised transitively through cited-domains.test.js, so the coverage gate is satisfied.

⚠️ Required follow-up before this is considered done

  • Add a focused unit test for normalizeChannel (src/support/elements/constants.js:63-80). This is being waived for urgency, not dropped. Repo CLAUDE.md requires unit tests for behavior changes, and coverage passing only means the lines are hit via cited-domains — not that the _/-→space transform (the actual fix) is asserted. A regression in benchmark_competitorsBenchmark Competitors matching could ship green. File a fast-follow. Cover: null/undefined/non-string → '', whitespace-only, benchmark_competitors, Benchmark Competitors, ai-generated, repeated __/--.

Minor (author's discretion)

  • Comment vs code mismatchowned-urls.js:137-138 comment changed to "Channel filter" but the block still hardcodes !== 'owned'. It filters domain_type, not a channel param. Revert to "Owned filter is client-side".
  • Inconsistent variable namecited-domains.js:189 uses wanted, domain-urls.js:131 uses channel for the same normalized value. Pick one (channel).

Question

  • normalizeChannel collapses _/- runs but not repeated whitespace (constants.js:38, regex /[_-]+/g). "Benchmark Competitors" (two spaces) would not match benchmark_competitors. Intentional given known inputs? If inputs can vary, append .replace(/\s+/g, ' ').

Working well

Correct root-cause fix; non-string input degrades safely to no-filter (no bypass); regex is linear (no ReDoS); the elements.js comment guards the intentional owned-only behavior.

@calvarezg calvarezg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving — multi-persona review found no blocking issues. One required follow-up: add a focused unit test for normalizeChannel (waived for urgency, not dropped). See review comment.

@vivesing
vivesing requested a review from MysticatBot July 29, 2026 12:17

@MysticatBot MysticatBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @vivesing,

⚠ Degraded review - no spec document was found for this change (searched the PR links, the touched repos' docs, the architecture/guidelines docs, and linked Jira). This review covers code-level quality but could not validate the change against an agreed design, so confidence is reduced. Add a spec link (PR template section 4) and re-request review for a full-confidence pass.

Verdict: Request changes - whitespace-run gap in normalizeChannel creates a latent correctness risk.
Complexity: MEDIUM - small diff; API surface signal.
Changes: Extracts channel normalization into a shared normalizeChannel utility to fix case/format-insensitive filtering between UI snake_case params and Semrush Title Case responses (6 files).
Note: CI checks are currently pending - confirm green before merge.

Must fix before merge

  1. [Important] normalizeChannel does not collapse whitespace runs - src/support/elements/constants.js:78 (details inline)
Non-blocking (2): minor issues and suggestions
  • nit: Comment changed to "Channel filter" but this block filters domain_type, not a channel param - revert to "Owned filter" or similar - src/support/elements/definitions/owned-urls.js:135
  • suggestion: Align normalized-channel variable name across cited-domains.js (wanted) and domain-urls.js (channel) for grep-ability - src/support/elements/definitions/domain-urls.js:131

Previously flagged, now resolved

  • Unit test for normalizeChannel added (test/support/elements/constants.test.js with 9 cases covering null, undefined, empty, whitespace, snake_case, Title Case, hyphenated, repeated separators, single-word)

Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 4m 3s | Cost: $5.22 | Commit: 2ae53f63ef44ea958ebb0fe876a04a92d1051cb1
If this code review was useful, please react with 👍. Otherwise, react with 👎.

Comment thread src/support/elements/constants.js Outdated
@vivesing
vivesing requested a review from MysticatBot July 29, 2026 13:31

@MysticatBot MysticatBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @vivesing,

⚠ Degraded review - no spec document was found for this change (searched the PR links, the touched repos' docs, the architecture/guidelines docs, and linked Jira). This review covers code-level quality but could not validate the change against an agreed design, so confidence is reduced. Add a spec link (PR template section 4) and re-request review for a full-confidence pass.

Verdict: Approve - prior blocking findings resolved, no new issues.
Complexity: HIGH - medium diff; API surface risk signal.
Changes: Extracts channel normalization into a shared normalizeChannel utility to fix format-insensitive filtering between UI snake_case params and Semrush Title Case responses (6 files).
Note: CI checks are currently pending - confirm green before merge.

Non-blocking (4): minor issues and suggestions
  • nit: Comment says "Channel filter" but this block filters domain_type to 'owned', not a channel param - revert to "Owned filter" or "domain_type filter" - src/support/elements/definitions/owned-urls.js:134
  • suggestion: Align the normalized-channel variable name across cited-domains.js (wanted) and domain-urls.js (channel) for grep-ability - src/support/elements/definitions/domain-urls.js:131
  • nit: Consider adding a non-string numeric input test (e.g., normalizeChannel(42)) to document the type-guard contract - test/support/elements/constants.test.js
  • nit: Consider adding a mixed-separator test (e.g., 'foo_- bar') to document the regex collapsing across separator classes - test/support/elements/constants.test.js

Previously flagged, now resolved

  • Unit tests for normalizeChannel added (10 cases covering null, undefined, empty, whitespace, snake_case, Title Case, hyphenated, repeated separators, single-word, double-space)
  • Whitespace-run gap fixed (regex now /[\s_-]+/g instead of /[_-]+/g, with test for double-space input)

Skill: pr-review | Model: us.anthropic.claude-opus-4-6-v1[1m] | Duration: 1m 49s | Cost: $2.94 | Commit: 5a7598ceef6196951d5c234689b93e7a620c8428
If this code review was useful, please react with 👍. Otherwise, react with 👎.

@MysticatBot MysticatBot added complexity:high AI-assessed PR complexity: HIGH and removed complexity:medium AI-assessed PR complexity: MEDIUM labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-reviewed Reviewed by AI complexity:high AI-assessed PR complexity: HIGH

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants