Skip to content

test(common-auth): add HeaderFieldSpec for header-name constants#5790

Open
lalalastella wants to merge 1 commit into
apache:mainfrom
lalalastella:test/header-field-spec
Open

test(common-auth): add HeaderFieldSpec for header-name constants#5790
lalalastella wants to merge 1 commit into
apache:mainfrom
lalalastella:test/header-field-spec

Conversation

@lalalastella

Copy link
Copy Markdown

What changes were proposed in this PR?

Add HeaderFieldSpec.scala — a dedicated unit spec for HeaderField in common/auth/src/main/scala/org/apache/texera/auth/util/.

HeaderField holds the canonical HTTP header names the auth layer reads from every request. Without a spec, accidental renames silently break header-based authentication. This PR pins three contracts:

Contract Tests
Exact value Each constant equals its expected string literal
RFC-7230 format Every constant matches x-user-* lowercase-hyphen namespace
Distinctness No two constants share the same value (no accidental aliasing)

No production-code changes.

Any related issues, documentation, discussions?

Closes #5662

How was this PR tested?

New spec file: HeaderFieldSpec.scala (~50 lines, no build changes needed — ScalaTest is already a % Test dependency in common/auth).

sbt "Auth/testOnly org.apache.texera.auth.util.HeaderFieldSpec"

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Sonnet 4.6

Pins the exact value, RFC-7230-compatible format, and distinctness of
every constant in HeaderField so accidental renames are caught by CI.

Closes apache#5662
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for your first contribution to Texera, @lalalastella!

If you're looking for a good place to start, browse issues labeled starter-task; they're scoped to be approachable for newcomers.

You can drive common housekeeping yourself by commenting one of these commands on its own line:

  • Issues. Comment /take to assign an open issue to yourself, or /untake to release it. You can find unclaimed work with the search filter is:issue is:open no:assignee.
  • Sub-issues. To link issues into a parent/child hierarchy, comment /sub-issue #5166 #5222 on the parent to attach those children (or /unsub-issue #5166 #5222 to detach them). From a child issue, comment /parent-issue #5166 to set its parent, or /unparent-issue to clear it (the current parent is detected automatically). References may be written as #5166 or as a bare 5166; cross-repository references are not supported.
  • Pull requests (author only). Comment /request-review @user to request a review from someone, or /unrequest-review @user to withdraw that request.

Each command must match exactly: /take this will not work, only /take does. For the full contribution flow, see CONTRIBUTING.md.

Copilot AI 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.

Pull request overview

Adds a ScalaTest spec in common/auth to lock down the canonical HTTP header-name constants used by the auth layer, preventing accidental renames from silently breaking header-based authentication.

Changes:

  • Introduce HeaderFieldSpec to assert exact string values for each HeaderField constant.
  • Add validation that all header constants follow the expected x-user-* lowercase-hyphen naming pattern.
  • Add a distinctness check to prevent accidental aliasing between header constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +43 to +64
"HeaderField constants" should "all match the x-user-* namespace in lowercase-hyphen format" in {
val rfcPattern = "^x-user-[a-z]+(?:-[a-z]+)*$".r
val allConstants = Seq(
HeaderField.UserComputingUnitAccess,
HeaderField.UserId,
HeaderField.UserName,
HeaderField.UserEmail
)
allConstants.foreach { value =>
rfcPattern.matches(value) shouldBe true
}
}

it should "all be distinct (no accidental aliasing)" in {
val allConstants = Seq(
HeaderField.UserComputingUnitAccess,
HeaderField.UserId,
HeaderField.UserName,
HeaderField.UserEmail
)
allConstants.distinct should have size allConstants.size
}
@codecov-commenter

codecov-commenter commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.29%. Comparing base (731d671) to head (0c16a4b).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5790      +/-   ##
============================================
- Coverage     53.30%   53.29%   -0.02%     
+ Complexity     2668     2663       -5     
============================================
  Files          1098     1098              
  Lines         42532    42532              
  Branches       4575     4575              
============================================
- Hits          22673    22666       -7     
- Misses        18530    18535       +5     
- Partials       1329     1331       +2     
Flag Coverage Δ *Carryforward flag
access-control-service 70.44% <ø> (ø)
agent-service 34.36% <ø> (ø) Carriedforward from 731d671
amber 53.77% <ø> (-0.05%) ⬇️
computing-unit-managing-service 1.65% <ø> (ø)
config-service 56.71% <ø> (ø)
file-service 57.06% <ø> (ø)
frontend 48.00% <ø> (ø) Carriedforward from 731d671
pyamber 90.13% <ø> (ø) Carriedforward from 731d671
python 90.80% <ø> (ø) Carriedforward from 731d671
workflow-compiling-service 58.69% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aglinxinyuan aglinxinyuan 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.

Please address the comments.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 0 better · 🔴 7 worse · ⚪ 8 noise (<±5%) · 0 without baseline

Compared against main 731d671 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 424 0.259 23,939/34,546/34,546 us 🔴 +26.9% / ⚪ within ±5%
bs=100 sw=10 sl=64 932 0.569 104,294/147,693/147,693 us ⚪ within ±5% / 🟢 -7.1%
🔴 bs=1000 sw=10 sl=64 1,087 0.664 919,387/1,023,222/1,023,222 us 🔴 +9.2% / 🟢 -5.5%
Baseline details

Latest main 731d671 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 424 tuples/sec 456 tuples/sec 410.82 tuples/sec -7.0% +3.2%
bs=10 sw=10 sl=64 MB/s 0.259 MB/s 0.278 MB/s 0.251 MB/s -6.8% +3.3%
bs=10 sw=10 sl=64 p50 23,939 us 18,864 us 23,785 us +26.9% +0.6%
bs=10 sw=10 sl=64 p95 34,546 us 31,922 us 34,980 us +8.2% -1.2%
bs=10 sw=10 sl=64 p99 34,546 us 31,922 us 34,980 us +8.2% -1.2%
bs=100 sw=10 sl=64 throughput 932 tuples/sec 914 tuples/sec 891.94 tuples/sec +2.0% +4.5%
bs=100 sw=10 sl=64 MB/s 0.569 MB/s 0.558 MB/s 0.544 MB/s +2.0% +4.5%
bs=100 sw=10 sl=64 p50 104,294 us 104,885 us 112,277 us -0.6% -7.1%
bs=100 sw=10 sl=64 p95 147,693 us 142,874 us 139,802 us +3.4% +5.6%
bs=100 sw=10 sl=64 p99 147,693 us 142,874 us 139,802 us +3.4% +5.6%
bs=1000 sw=10 sl=64 throughput 1,087 tuples/sec 1,115 tuples/sec 1,041 tuples/sec -2.5% +4.4%
bs=1000 sw=10 sl=64 MB/s 0.664 MB/s 0.681 MB/s 0.635 MB/s -2.5% +4.5%
bs=1000 sw=10 sl=64 p50 919,387 us 899,773 us 972,714 us +2.2% -5.5%
bs=1000 sw=10 sl=64 p95 1,023,222 us 936,880 us 1,023,057 us +9.2% +0.0%
bs=1000 sw=10 sl=64 p99 1,023,222 us 936,880 us 1,023,057 us +9.2% +0.0%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,471.34,200,128000,424,0.259,23938.92,34546.20,34546.20
1,100,10,64,20,2146.87,2000,1280000,932,0.569,104293.74,147692.57,147692.57
2,1000,10,64,20,18391.39,20000,12800000,1087,0.664,919387.06,1023222.02,1023222.02

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.

add unit test coverage for HeaderField

4 participants