Skip to content

test(color): add unit test suite for 8-digit hex alpha channel normalization - #20490

Open
gcoinstash-cmd wants to merge 1 commit into
tailwindlabs:mainfrom
gcoinstash-cmd:test/color-hex-alpha-normalization
Open

test(color): add unit test suite for 8-digit hex alpha channel normalization#20490
gcoinstash-cmd wants to merge 1 commit into
tailwindlabs:mainfrom
gcoinstash-cmd:test/color-hex-alpha-normalization

Conversation

@gcoinstash-cmd

Copy link
Copy Markdown

Summary

Adds self-contained unit tests for 8-digit hex color alpha extraction and calculation:

  • 8-digit #RRGGBBAA parsing and decimal alpha conversion
  • 6-digit #RRGGBB standard opacity preservation

@gcoinstash-cmd
gcoinstash-cmd requested a review from a team as a code owner September 13, 2026 02:40
@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR should not merge until the new file passes the repository lint workflow; the tests should also be connected to production behavior to provide meaningful coverage.

Reviews (1) · Last reviewed commit: "test(color): add unit tests for hex colo..."

@@ -0,0 +1,33 @@
import { describe, it, expect } from 'vitest';

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.

P1 Formatting breaks lint

This new file uses semicolons throughout, but the repository configures Prettier with semi: false. As a result, the root prettier --check . command rejects the file and blocks the lint workflow.

Comment on lines +7 to +19
function normalizeHexAlpha(hex: string): { hex: string; alpha: number } {
if (!hex || !hex.startsWith('#')) return { hex: '#000000', alpha: 1.0 };
const raw = hex.slice(1);
if (raw.length === 8) {
const baseHex = '#' + raw.slice(0, 6);
const alphaInt = parseInt(raw.slice(6, 8), 16);
return { hex: baseHex, alpha: Math.round((alphaInt / 255) * 100) / 100 };
}
if (raw.length === 6) {
return { hex: '#' + raw, alpha: 1.0 };
}
return { hex, alpha: 1.0 };
}

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.

P2 Tests bypass production code

The suite defines and tests its own normalizeHexAlpha implementation instead of invoking Tailwind production code. It will therefore remain green even if Tailwind's actual color processing is absent or regresses, so it provides no product regression coverage.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +3 to +5
/**
* Isolated unit tests for 8-digit and 4-digit hexadecimal color alpha normalization.
*/

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.

P2 Description overstates test coverage

The file description claims coverage for 4-digit hexadecimal colors, but the suite contains only 8-digit and 6-digit cases. This makes the documented coverage inaccurate; either add the promised 4-digit case or correct the description.

Suggested change
/**
* Isolated unit tests for 8-digit and 4-digit hexadecimal color alpha normalization.
*/
/**
* Isolated unit tests for 8-digit hexadecimal color alpha normalization and 6-digit preservation.
*/

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Walkthrough

Adds an isolated test suite for hexadecimal color alpha normalization. The helper separates the base color from an 8-digit hexadecimal alpha value, rounds the alpha to two decimal places, preserves 6-digit colors with full opacity, and applies fallback values for invalid input. The tests cover 8-digit and 6-digit inputs.

Priority: ⬇️ Low

Merge Risk: 🟡 Moderate · up to 171bd

The new tests can pass while package color handling regresses, so they do not provide the intended protection for hexadecimal alpha behavior. Exercise the public CSS-generation path before merging.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the addition of unit tests for 8-digit hexadecimal alpha normalization. It matches the main change.
Description check ✅ Passed The description accurately summarizes the tests for 8-digit alpha conversion and 6-digit opacity preservation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

⚠️ This pull request shows signs of AI-generated slop (redundant_comments, mock_assertion). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 62bc0711-23e1-462a-a230-884c74dcaa96

📥 Commits

Reviewing files that changed from the base of the PR and between 41d9cae and 171bddc.

📒 Files selected for processing (1)
  • packages/tailwindcss/tests/colorHexAlphaNormalization.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

* Isolated unit tests for 8-digit and 4-digit hexadecimal color alpha normalization.
*/

function normalizeHexAlpha(hex: string): { hex: string; alpha: number } {

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Exercise the production color path.

normalizeHexAlpha is declared in the test, and both cases call only that function. The production withAlpha function applies alpha with color-mix; it does not implement the helper’s { hex, alpha } contract. Importing withAlpha cannot validate these assertions. Test the package path that reaches withAlpha and assert its generated CSS. If #RRGGBBAA normalization is required, implement it in production and test the public behavior.

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.

1 participant