Skip to content

[scanner] 🌱 refactor: extract remaining magic numbers to named constants#19253

Merged
clubanderson merged 2 commits into
mainfrom
scanner/fix-19245-v3
Jun 20, 2026
Merged

[scanner] 🌱 refactor: extract remaining magic numbers to named constants#19253
clubanderson merged 2 commits into
mainfrom
scanner/fix-19245-v3

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Fixes #19245

Extracts hardcoded magic numbers to descriptive named constants across 6 files:

  • AlertsContext.tsx — timing constants for MCP, loading, and evaluation
  • alertRunbooks.ts — length limits for prompts and evidence
  • notifications.ts — HTTP status codes for auth errors
  • alertStorage.ts — DOMException error code constant
  • formatters.ts — now imports BYTES_PER_KIB from units.ts
  • units.ts — added new BYTES_PER_KIB constant

All constants use SCREAMING_SNAKE_CASE naming convention matching existing codebase patterns.

Signed-off-by: Scanner Agent <scanner@kubestellar.io>
Copilot AI review requested due to automatic review settings June 20, 2026 05:04
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 20, 2026
@netlify

netlify Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit dc3772f
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a36248d132c68000882ac57
😎 Deploy Preview https://deploy-preview-19253.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mikespreitzer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

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

This PR addresses issue #19245 by continuing the “no magic numbers” refactor in the scanner-related alerting/notification code, extracting several remaining numeric literals into named constants to improve readability and maintainability.

Changes:

  • Replaced hardcoded byte-scaling literal in formatBytes by importing a shared unit constant from constants/units.
  • Introduced named constants for HTTP auth error status codes, DOMException quota error code, and several timing / truncation thresholds.
  • Added BYTES_PER_KIB to the shared units constants module.

Build/lint are expected to be validated by CI on the PR (per repo workflow).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
web/src/lib/formatters.ts Uses shared unit constant for byte formatting calculations.
web/src/lib/constants/units.ts Adds BYTES_PER_KIB to centralize binary byte unit scaling.
web/src/contexts/notifications.ts Extracts HTTP 401/403 checks into named constants for clarity.
web/src/contexts/alertStorage.ts Extracts legacy DOMException quota error code into a named constant.
web/src/contexts/AlertsContext.tsx Adds named timing constants for MCP batching and alert evaluation.
web/src/contexts/alertRunbooks.ts Adds named max-length constants for prompt/evidence truncation.
Comments suppressed due to low confidence (1)

web/src/lib/constants/units.ts:8

  • Now that BYTES_PER_KIB exists, the other binary unit constants can be derived from it to avoid repeating 1024 (which is exactly what this PR is trying to eliminate). This also makes future refactors safer because the base only lives in one place.
/** Bytes per mebibyte (MiB) */
export const BYTES_PER_MIB = 1024 * 1024
/** Bytes per kibibyte (KiB) */
export const BYTES_PER_KIB = 1024
/** Bytes per gibibyte (GiB) */
export const BYTES_PER_GIB = 1024 * 1024 * 1024
/** Bytes per tebibyte (TiB) */
export const BYTES_PER_TIB = 1024 * BYTES_PER_GIB

Comment thread web/src/lib/formatters.ts
Comment on lines 108 to +110
const units = binary ? IEC_UNITS : SI_UNITS
const i = Math.floor(Math.log(bytes) / Math.log(BYTES_PER_KIBIBYTE))
const value = bytes / Math.pow(BYTES_PER_KIBIBYTE, i)
const i = Math.floor(Math.log(bytes) / Math.log(BYTES_PER_KIB))
const value = bytes / Math.pow(BYTES_PER_KIB, i)
@clubanderson clubanderson merged commit a278f3a into main Jun 20, 2026
31 of 39 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the scanner/fix-19245-v3 branch June 20, 2026 05:56
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions

Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit a278f3a85243fe034d770193f7cff02f137eba77.

clubanderson added a commit that referenced this pull request Jun 20, 2026
Add export * from './time' to the constants barrel file, fixing
tests that failed to load due to missing time constant imports
after PR #19253 refactored magic numbers into separate modules.

Signed-off-by: clubanderson <club.anderson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tier/2-standard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Auto-QA] Hardcoded thresholds and magic numbers

2 participants