From 814e4f047e33227acf0177449d0d3be30de043f1 Mon Sep 17 00:00:00 2001 From: Maurice Date: Fri, 4 Dec 2026 09:48:37 +0100 Subject: [PATCH] fix(ci): repair mobile tests and lint diagnostics Restore the saved-list filter import and test the actual sheet backdrop. Remove unsafe fixture assertions and apply formatting reported by CI. Reuse the current lint results and compare base files in sequence so warning diagnostics can finish without exhausting the heap. --- client/scripts/eslint-baseline.json | 2 +- client/scripts/lib/eslint-warnings.mjs | 72 ++++++++++--------- .../Planner/IcsSubscribeModal.test.tsx | 3 +- .../screens/collections/MCollSavedFilters.tsx | 1 + .../mobile/screens/collections/MCollTours.tsx | 5 +- .../screens/journey/MJourneyInviteFrame.tsx | 3 +- .../screens/trip/sheets/formOptionClass.ts | 2 +- .../tests/unit/mobile/trip/MCostsTab.test.tsx | 4 +- .../unit/mobile/trip/MPackingListTab.test.tsx | 8 ++- .../tests/unit/sync/tripSyncManager.test.ts | 4 +- 10 files changed, 59 insertions(+), 45 deletions(-) diff --git a/client/scripts/eslint-baseline.json b/client/scripts/eslint-baseline.json index c84f4d998..8dbf83e06 100644 --- a/client/scripts/eslint-baseline.json +++ b/client/scripts/eslint-baseline.json @@ -7,7 +7,7 @@ "@typescript-eslint/no-explicit-any": 113, "trek/no-swallowed-catch": 124, "max-params": 31, - "trek/store-without-selector": 65, + "trek/store-without-selector": 64, "react-hooks/refs": 380, "react-hooks/set-state-in-effect": 188, "@typescript-eslint/no-floating-promises": 156, diff --git a/client/scripts/lib/eslint-warnings.mjs b/client/scripts/lib/eslint-warnings.mjs index 35dc50c3b..e240a39ce 100644 --- a/client/scripts/lib/eslint-warnings.mjs +++ b/client/scripts/lib/eslint-warnings.mjs @@ -172,48 +172,49 @@ function ofRule(results, rule, area) { * this names the file that tipped it. Null when `ref` is not at hand (a clone * without it), and the report then keeps to the files holding the most. */ -export async function newWarningsOf({ root, rule, area, keys, lintText, ref = baseRef(), git = gitIn }) { +export async function newWarningsOf({ root, rule, area, keys, lintText, current = null, ref = baseRef(), git = gitIn }) { const changed = git(root, ['diff', '--name-only', '--relative', ref, '--', '.']); if (changed === null) return null; const differs = new Set(changed.split('\n').filter(Boolean)); - const found = await Promise.all( - keys - .filter((key) => differs.has(key)) - .map(async (key) => { - const path = join(root, key); - // A typed rule can trip over a text that is not the file on disk (the - // base version); then the file's own warnings are told, marked so. - const lint = async (text) => { - try { - return { messages: ofRule(await lintText(text, path), rule, area) }; - } catch { - return null; - } - }; - const now = await lint(readText(path)); - if (!now) return []; - const before = git(root, ['show', `${ref}:./${key}`]); - const was = before === null ? { messages: [] } : await lint(before); - if (was && now.messages.length <= was.messages.length) return []; - const note = was ? '' : ' (the base version could not be linted)'; - return now.messages.map((m) => `${key}:${m.line ?? 0} ${m.message}${note}`); - }) - ); - return found.flat(); + const found = []; + // Run typed linting for base versions in sequence. Linting many alternate + // versions in parallel can exhaust the CI runner's heap. + for (const key of keys.filter((key) => differs.has(key))) { + const path = join(root, key); + const lint = async (text) => { + try { + return ofRule(await lintText(text, path), rule, area); + } catch { + return null; + } + }; + const now = current ? ofRule([current.get(key)], rule, area) : await lint(readText(path)); + if (!now?.length) continue; + const before = git(root, ['show', `${ref}:./${key}`]); + const was = before === null ? [] : await lint(before); + if (was && now.length <= was.length) continue; + const note = was ? '' : ' (the base version could not be linted)'; + for (const message of now) found.push(`${key}:${message.line ?? 0} ${message.message}${note}`); + } + return found; } /** Prints, under the grown counts, the files and lines behind each one (see newWarningsOf). */ -async function reportNew(grown, { root, files, lintText, error }) { +async function reportNew(grown, { root, files, lintText, error, results }) { if (!grown.length || !lintText) return; - const found = await Promise.all( - grown.map(({ area, rule }) => newWarningsOf({ root, rule, area, keys: Object.keys(files[area][rule]), lintText })) - ); - grown.forEach(({ area, rule }, i) => { - const lines = found[i]; - if (!lines?.length) return; + const current = new Map(results.map((result) => [toKey(root, result.filePath), result])); + const previous = new Map(); + const lintOnce = (text, path) => { + if (!previous.has(path)) previous.set(path, lintText(text, path)); + return previous.get(path); + }; + for (const { area, rule } of grown) { + const keys = Object.keys(files[area][rule]); + const lines = await newWarningsOf({ root, rule, area, keys, lintText: lintOnce, current }); + if (!lines?.length) continue; error(`New ${rule} warning(s) in ${area}, against ${baseRef()}:`); for (const line of lines) error(` ${line}`); - }); + } } /** Lints one file's text with the client's own config, for newWarningsOf. */ @@ -238,7 +239,8 @@ export async function check({ error = console.error, }) { let baseline = readBaseline(baselinePath, areaCounts); - const { counts, files, errors } = tally(await lint(root), root); + const results = await lint(root); + const { counts, files, errors } = tally(results, root); if (update) { baseline = Object.fromEntries(AREAS.map((area) => [area, lowerCounts(baseline[area], counts[area])])); @@ -268,7 +270,7 @@ export async function check({ }); stale += fallen.length; } - await reportNew(grown, { root, files, lintText: lintText && lintText(root), error }); + await reportNew(grown, { root, files, lintText: lintText && lintText(root), error, results }); if (grown.length) { error( 'Fix the new warning rather than silencing it: an eslint-disable comment is counted under "suppressed". ' + diff --git a/client/src/components/Planner/IcsSubscribeModal.test.tsx b/client/src/components/Planner/IcsSubscribeModal.test.tsx index 6c09ede1e..8b4a1c36b 100644 --- a/client/src/components/Planner/IcsSubscribeModal.test.tsx +++ b/client/src/components/Planner/IcsSubscribeModal.test.tsx @@ -178,7 +178,8 @@ describe('IcsSubscribeModal on the phone', () => { fireEvent.click(screen.getByRole('button', { name: 'Close' })); expect(onClose).toHaveBeenCalledTimes(1); - const backdrop = document.querySelector('[data-m-scrim]')!.parentElement!; + const backdrop = screen.getByRole('dialog', { name: defaultProps.title }).closest('[role="presentation"]'); + if (!backdrop) throw new Error('Expected the sheet backdrop'); fireEvent.click(backdrop); expect(onClose).toHaveBeenCalledTimes(2); diff --git a/client/src/mobile/screens/collections/MCollSavedFilters.tsx b/client/src/mobile/screens/collections/MCollSavedFilters.tsx index c1feea57a..411fd874d 100644 --- a/client/src/mobile/screens/collections/MCollSavedFilters.tsx +++ b/client/src/mobile/screens/collections/MCollSavedFilters.tsx @@ -5,6 +5,7 @@ import type { useCollections } from '../../../pages/collections/useCollections'; import MListRow from '../../components/MListRow'; import { CollFilterSection, CollFiltersSheet, DropRow } from './MCollFilterKit'; import { categoryMeta, STATUS_SPEC } from './collectionsMobileModel'; +import { savedListFilterCount } from './savedListFilterCount'; type Collections = ReturnType; type Group = 'status' | 'category' | 'tags' | 'rating' | 'sort'; diff --git a/client/src/mobile/screens/collections/MCollTours.tsx b/client/src/mobile/screens/collections/MCollTours.tsx index f828725f8..30e45f52c 100644 --- a/client/src/mobile/screens/collections/MCollTours.tsx +++ b/client/src/mobile/screens/collections/MCollTours.tsx @@ -19,14 +19,15 @@ import { useSettingsStore } from '../../../store/settingsStore'; import MSheet from '../../components/MSheet'; import MSkeleton from '../../components/MSkeleton'; import MConfirmSheet from '../settings/MConfirmSheet'; +import { formOptionClass } from '../trip/sheets/formOptionClass'; import { FIELD_CLS, FORM_LABEL_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader, - FormSheetSection } from '../trip/sheets/PlSheetChrome'; -import { formOptionClass } from '../trip/sheets/formOptionClass'; + FormSheetSection, +} from '../trip/sheets/PlSheetChrome'; /** A kept tour's measures as the small pills of the phone's rows. */ function MeasurePills({ tour }: { tour: CollectionTourItem }) { diff --git a/client/src/mobile/screens/journey/MJourneyInviteFrame.tsx b/client/src/mobile/screens/journey/MJourneyInviteFrame.tsx index 6810dbed0..34b27b18b 100644 --- a/client/src/mobile/screens/journey/MJourneyInviteFrame.tsx +++ b/client/src/mobile/screens/journey/MJourneyInviteFrame.tsx @@ -9,7 +9,8 @@ import { FormSheetBody, FormSheetFooter, FormSheetHeader, - FormSheetSection } from '../trip/sheets/PlSheetChrome'; + FormSheetSection, +} from '../trip/sheets/PlSheetChrome'; import { formOptionClass } from '../trip/sheets/formOptionClass'; export default function MJourneyInviteFrame({ diff --git a/client/src/mobile/screens/trip/sheets/formOptionClass.ts b/client/src/mobile/screens/trip/sheets/formOptionClass.ts index e87610df8..e0601e21d 100644 --- a/client/src/mobile/screens/trip/sheets/formOptionClass.ts +++ b/client/src/mobile/screens/trip/sheets/formOptionClass.ts @@ -1,5 +1,5 @@ export function formOptionClass(active: boolean) { return `flex min-h-10 items-center gap-1.5 rounded-full border px-3 py-1.5 text-start text-caption font-semibold ${ active ? 'border-transparent bg-m-act text-m-actfg' : 'border-m-rowbr bg-m-sheetop text-m-ink' - }` + }`; } diff --git a/client/tests/unit/mobile/trip/MCostsTab.test.tsx b/client/tests/unit/mobile/trip/MCostsTab.test.tsx index dcfd3170d..fa210fda1 100644 --- a/client/tests/unit/mobile/trip/MCostsTab.test.tsx +++ b/client/tests/unit/mobile/trip/MCostsTab.test.tsx @@ -958,7 +958,9 @@ describe('MCostsTab', () => { expect(screen.getByText('costs.byCategory')).not.toBeVisible() fireEvent.click(budgetSummary()) expect(screen.getByText('costs.byCategory')).toBeVisible() - expect(within(budgetSummary().parentElement!).getAllByText('$185.00')).toHaveLength(1) + const summary = budgetSummary().parentElement + if (!summary) throw new Error('Expected the budget summary') + expect(within(summary).getAllByText('$185.00')).toHaveLength(1) }) it('FE-MOB-COSTT-055: in Arabic a signed balance and an amount read as one left-to-right run, and a payment names who paid whom in reading order', async () => { diff --git a/client/tests/unit/mobile/trip/MPackingListTab.test.tsx b/client/tests/unit/mobile/trip/MPackingListTab.test.tsx index 74fc161f4..288a129b5 100644 --- a/client/tests/unit/mobile/trip/MPackingListTab.test.tsx +++ b/client/tests/unit/mobile/trip/MPackingListTab.test.tsx @@ -360,7 +360,9 @@ describe('MPackingListTab', () => { const input = screen.getByPlaceholderText('packing.newCategoryPlaceholder') fireEvent.change(input, { target: { value: 'Documents' } }) - await act(async () => { fireEvent.submit((input as HTMLInputElement).form!) }) + const form = input.closest('form') + if (!form) throw new Error('Expected the new list form') + await act(async () => { fireEvent.submit(form) }) expect(planner.tripActions.addPackingItem).toHaveBeenCalledWith(3, { name: '...', category: `Documents${ZERO_WIDTH}`, visibility: 'common' }) }) @@ -383,7 +385,9 @@ describe('MPackingListTab', () => { fireEvent.click(screen.getByRole('button', { name: 'packing.addCategory' })) const field = screen.getByPlaceholderText('packing.newCategoryPlaceholder') fireEvent.change(field, { target: { value: 'Gear' } }) - await act(async () => { fireEvent.submit((field as HTMLInputElement).form!) }) + const form = field.closest('form') + if (!form) throw new Error('Expected the new list form') + await act(async () => { fireEvent.submit(form) }) expect(planner.toast.error).toHaveBeenCalledWith('packing.toast.addError') fireEvent.keyDown(screen.getByPlaceholderText('packing.newCategoryPlaceholder'), { key: 'Escape' }) diff --git a/client/tests/unit/sync/tripSyncManager.test.ts b/client/tests/unit/sync/tripSyncManager.test.ts index 332787c44..feaf7195b 100644 --- a/client/tests/unit/sync/tripSyncManager.test.ts +++ b/client/tests/unit/sync/tripSyncManager.test.ts @@ -135,7 +135,9 @@ describe('prepareForOffline — selected trip', () => { expect(list).not.toHaveBeenCalled(); expect(await offlineDb.trips.get(other.id)).toBeDefined(); expect(await offlineDb.trips.get(trip.id)).toBeDefined(); - expect(await offlineDb.blobCache.get(bundle.files[0]!.url!)).toBeDefined(); + const fileUrl = bundle.files[0]?.url; + if (!fileUrl) throw new Error('Expected a file URL in the trip bundle'); + expect(await offlineDb.blobCache.get(fileUrl)).toBeDefined(); expect(getOfflinePrefs().pinnedTripIds).toEqual([trip.id]); expect(getOfflinePrefs().disabledTripIds).not.toContain(trip.id); });