-
-
Notifications
You must be signed in to change notification settings - Fork 252
Fix failing tests #1009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix failing tests #1009
Conversation
WalkthroughThe PR adjusts timezone handling in date utilities and tests, modifies a currency item validator’s TypeScript typing, updates a CI test script to disable file parallelism, broadens a .gitignore pattern for .data directories, and removes trailing whitespace in a Vue component’s style block. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor UI as UI
participant Utils as utils.loadCurrencyDecimals
participant API as Currency API
participant Cache as Local Cache
UI->>Utils: request decimals for currency codes
Utils->>Cache: check cached decimals
alt cache hit
Cache-->>Utils: return decimals
Utils-->>UI: decimals
else cache miss
Utils->>API: fetch currency items
API-->>Utils: items[]
Utils->>Utils: isValidCurrencyItem(item): boolean
Utils->>Cache: store UPPERCASE(code) -> clamped decimals
Utils-->>UI: decimals
end
note over Utils: Validator now returns boolean (no TS type-narrowing)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Security recommendations
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
1297f2c to
04354c0
Compare
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/composables/utils.ts (1)
167-174: Security: restrict bracketed link scheme to http(s) to prevent javascript: URLs.
[text](javascript:...)currently setsisUrl=true. Enforce allowed protocols.- if (match && match.length === 3) { - result.isUrl = true; - result.text = match[1]!; - result.url = match[2]!; - } + if (match && match.length === 3) { + const url = match[2]!; + const allowed = url.startsWith("http://") || url.startsWith("https://"); + if (allowed) { + result.isUrl = true; + result.text = match[1]!; + result.url = url; + } + }
🧹 Nitpick comments (6)
.gitignore (1)
63-63: Broadened.data/ignore may hide unintended directories. Scope it.This now ignores any
.data/anywhere. If the intent was only VitePress cache, restrict the glob.Apply:
- .data/ + docs/.vitepress/cache/.data/frontend/package.json (1)
12-12: Good call to disable file parallelism for CI flake reduction.Watch for longer runtimes; consider gating slow suites instead of global serialization.
Optional:
- "test:ci": "TEST_SHUTDOWN_API_SERVER=true vitest --run --config ./test/vitest.config.ts --no-file-parallelism", + "test:ci": "pnpm run typecheck && TEST_SHUTDOWN_API_SERVER=true vitest --run --config ./test/vitest.config.ts --no-file-parallelism",frontend/lib/datelib/datelib.test.ts (2)
17-17: Test passes, but verify intent (local vs UTC).If you adopt UTC zeroing, assert
getUTCHours()instead; otherwise current local‑midnight assertion is fine.
44-49: Add a parse→format round‑trip test to prevent regressions.Catches the UTC/local mismatch described earlier.
describe("parse", () => { test("should parse a date string", () => { const date = parse("2020-02-01"); expect(date).toBeInstanceOf(Date); }); }); + +describe("roundtrip", () => { + test("parse(format(d)) preserves calendar day", () => { + const s = "2020-02-01"; + const d = parse(s); + expect(format(d)).toBe(s); + }); +});frontend/composables/utils.ts (2)
47-62: Restore type predicate to regain compile‑time narrowing and safer API use.Current boolean return loses narrowing and requires
CurrenciesCurrencyat call sites (which may beunknownfrom the API).-function isValidCurrencyItem(item: CurrenciesCurrency): boolean { +function isValidCurrencyItem(item: unknown): item is CurrenciesCurrency { - if ( - typeof item !== "object" || - item === null || - typeof item.code !== "string" || - item.code.trim() === "" || - typeof item.decimals !== "number" || - !Number.isFinite(item.decimals) - ) { + if (typeof item !== "object" || item === null) return false; + const rec = item as Partial<CurrenciesCurrency> & { decimals?: unknown }; + if (typeof rec.code !== "string" || rec.code.trim() === "") return false; + if (typeof rec.decimals !== "number" || !Number.isFinite(rec.decimals)) return false; return false; - } - // Truncate decimals to integer and check range - const truncatedDecimals = Math.trunc(item.decimals); + // Truncate decimals to integer and check range + const truncatedDecimals = Math.trunc(rec.decimals); return truncatedDecimals >= SAFE_MIN_DECIMALS && truncatedDecimals <= SAFE_MAX_DECIMALS; }
95-109: Security/perf: guard against oversized currency lists from API.Unbounded loops can spike memory/CPU if the endpoint misbehaves.
- for (const currency of data) { + const MAX_ITEMS = 500; + for (const currency of data.slice(0, MAX_ITEMS)) { // Strict validation: only process items that pass all checks if (!isValidCurrencyItem(currency)) { // Skip invalid items without caching - no clamping for out-of-range values continue; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.gitignore(1 hunks)frontend/components/global/DetailsSection/DetailsSection.vue(0 hunks)frontend/composables/utils.ts(2 hunks)frontend/lib/datelib/datelib.test.ts(2 hunks)frontend/lib/datelib/datelib.ts(1 hunks)frontend/package.json(1 hunks)
💤 Files with no reviewable changes (1)
- frontend/components/global/DetailsSection/DetailsSection.vue
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-12T23:36:19.928Z
Learnt from: realchrisolin
PR: sysadminsmedia/homebox#1004
File: frontend/composables/use-formatters.ts:64-73
Timestamp: 2025-09-12T23:36:19.928Z
Learning: In the homebox frontend, UTC dates from the backend are handled correctly by the current date formatting implementation without needing additional local day conversion for display, as confirmed by testing in negative timezones.
Applied to files:
frontend/lib/datelib/datelib.test.ts
📚 Learning: 2025-09-12T23:52:45.823Z
Learnt from: realchrisolin
PR: sysadminsmedia/homebox#1004
File: frontend/lib/datelib/datelib.ts:14-18
Timestamp: 2025-09-12T23:52:45.823Z
Learning: In the homebox frontend datelib, when working with day-level precision and UTC-normalized dates (T00:00:00.000Z), DST drift from addDays is not a practical concern since the system only deals with whole-day offsets and consistently uses UTC midnight as the baseline.
Applied to files:
frontend/lib/datelib/datelib.ts
🧬 Code graph analysis (1)
frontend/composables/utils.ts (1)
frontend/lib/api/types/data-contracts.ts (1)
CurrenciesCurrency(55-61)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
- GitHub Check: build (linux/amd64)
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 1/4
- GitHub Check: End-to-End Playwright Tests / E2E Playwright Testing 3/4
- GitHub Check: build (linux/arm64)
- GitHub Check: build (linux/arm/v7)
- GitHub Check: Frontend Tests / Integration Tests
- GitHub Check: Backend Server Tests / Go
- GitHub Check: Frontend Tests / Integration Tests PGSQL 15
- GitHub Check: build (linux/arm/v7)
- GitHub Check: build (linux/amd64)
- GitHub Check: build (linux/arm64)
- GitHub Check: build (linux/arm/v7)
- GitHub Check: build (linux/amd64)
- GitHub Check: build (linux/arm64)
🔇 Additional comments (2)
frontend/lib/datelib/datelib.test.ts (1)
6-6: LGTM: UTC construction removes TZ fragility.This stabilizes expectations across environments.
frontend/composables/utils.ts (1)
1-1: Type import looks good.Keeps runtime bundle slim.
What type of PR is this?
What this PR does / why we need it:
Fix failing unit tests blocking the CI.
Which issue(s) this PR fixes:
-
Special notes for your reviewer:
-
Testing
Summary by CodeRabbit
Bug Fixes
Tests
Chores