Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- name: Typecheck
run: npm run -s typecheck

- name: Run frontend tests
run: npm run -s test:run

- name: Build frontend
env:
NODE_OPTIONS: --max-old-space-size=4096
Expand Down
7 changes: 4 additions & 3 deletions src/components/data/SpreadsheetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4063,12 +4063,14 @@ export function SpreadsheetView({
return true
}
for (const modelRow of targetModelRows) {
if (!hasMaterializedRowData(modelRow)) {
// Activation only needs confirmation that preload resolved this row.
// Empty-row sentinels stay non-materialized for copy/cut/delete.
if (!rowDataRef.current.has(modelRow)) {
return false
}
}
return true
}, [hasMaterializedRowData])
}, [])

const resolveActivationBundleTargetRows = useCallback(
async (
Expand Down Expand Up @@ -16543,4 +16545,3 @@ export function SpreadsheetView({

export default SpreadsheetView


Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,26 @@ vi.mock('@/services/cacheService', () => ({
default: {
getDatasetStorageInfo: vi.fn().mockResolvedValue(null),
getRowsHybrid: vi.fn().mockResolvedValue([]),
flushOverlay: vi.fn().mockResolvedValue(undefined),
getAllColumnStats: vi.fn().mockResolvedValue([]),
getPersistedColumnIds: vi.fn().mockResolvedValue([]),
getGridMutationQueueState: vi.fn().mockReturnValue({
status: 'idle',
failedQueueId: null,
error: null,
}),
subscribeGridMutationQueue: vi.fn((_datasetId: string, listener: (state: any) => void) => {
listener({ status: 'idle', failedQueueId: null, error: null })
return () => undefined
}),
},
}))

vi.mock('@/lib/grid/editExecutor', () => ({
createEditExecutor: vi.fn(() => ({
execute: harness.executeEdits,
executeSingle: harness.executeSingleEdit,
applyDataStoreUpdate: vi.fn(),
})),
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ describe('SpreadsheetView Sort/Outline dialog column filtering', () => {

await act(async () => { await openSort() })

fireEvent.keyDown(screen.getByRole('combobox', { name: 'Sort by column' }), {
key: 'ArrowDown',
})

// col-0 and col-2 options should appear; col-1 should not
expect(screen.getByRole('option', { name: /Column 1/ })).toBeInTheDocument()
expect(screen.queryByRole('option', { name: /Column 2/ })).not.toBeInTheDocument()
Expand Down Expand Up @@ -284,6 +288,10 @@ describe('SpreadsheetView Sort/Outline dialog column filtering', () => {
// Open sort dialog — col-1 must appear even though nonNullCount = 0
await act(async () => { await openSort() })

fireEvent.keyDown(screen.getByRole('combobox', { name: 'Sort by column' }), {
key: 'ArrowDown',
})

expect(screen.getByRole('option', { name: /Column 2/ })).toBeInTheDocument()
})

Expand Down Expand Up @@ -343,6 +351,9 @@ describe('SpreadsheetView Sort/Outline dialog column filtering', () => {

// Dialog renders exactly once
expect(screen.getAllByRole('heading', { name: /Sort Data/ })).toHaveLength(1)
fireEvent.keyDown(screen.getByRole('combobox', { name: 'Sort by column' }), {
key: 'ArrowDown',
})
// Only data-bearing columns appear (col-0 and col-2)
expect(screen.getByRole('option', { name: /Column 1/ })).toBeInTheDocument()
expect(screen.queryByRole('option', { name: /Column 2/ })).not.toBeInTheDocument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const cacheHarness = vi.hoisted(() => ({
queueCellUpdate: vi.fn(),
updateCellsBatch: vi.fn().mockResolvedValue(0),
enqueueGridMutationBatch: vi.fn().mockResolvedValue({ accepted: true, queueId: 'q-1' }),
flushGridMutationQueue: vi.fn().mockResolvedValue(undefined),
scheduleOverlayFlush: vi.fn(),
insertRowAt: vi.fn().mockResolvedValue(0),
insertRowsAt: vi.fn().mockResolvedValue(0),
Expand All @@ -58,6 +59,7 @@ const undoHarness = vi.hoisted(() => ({
pushBatchCellEdit: vi.fn().mockResolvedValue({ can_undo: true, can_redo: false, undo_count: 1, redo_count: 0 }),
enqueueBatchCellEdit: vi.fn().mockResolvedValue({ can_undo: true, can_redo: false, undo_count: 1, redo_count: 0 }),
trackPendingBatchRegistration: vi.fn(),
recordGridTransaction: vi.fn().mockResolvedValue(undefined),
undo: vi.fn().mockResolvedValue(null),
redo: vi.fn().mockResolvedValue(null),
}))
Expand Down Expand Up @@ -249,6 +251,7 @@ describe('SpreadsheetView formula display commit', () => {
clipboardHarness.read.mockReset()
clipboardHarness.write.mockClear()
cacheHarness.queueCellUpdate.mockClear()
cacheHarness.flushOverlay.mockReset().mockResolvedValue(undefined)
})

it('renders computed formula result instead of raw formula text after commit', async () => {
Expand Down Expand Up @@ -368,9 +371,10 @@ describe('SpreadsheetView formula display commit', () => {
expect(tauriHarness.evaluateFormulaRange).not.toHaveBeenCalled()
})

it('keeps cut and paste cells visible across a stale range reload', async () => {
it('keeps cut and paste cells visible while persistence is pending', async () => {
let capturedCut: (() => void | Promise<void>) | null = null
let capturedPaste: (() => void | Promise<void>) | null = null
cacheHarness.flushOverlay.mockImplementation(() => new Promise<void>(() => {}))
render(
<SpreadsheetView
onCutRequest={fn => { capturedCut = fn }}
Expand Down Expand Up @@ -410,19 +414,6 @@ describe('SpreadsheetView formula display commit', () => {
await Promise.resolve()
})

await waitFor(() => {
expect(gridHarness.getCellContent?.([1, 1])?.displayData).toBe('10')
})

// Simulate a stale backend range read returning the pre-cut/pre-paste rows.
const getRowsCallCountBeforeStaleReload = cacheHarness.getRowsHybrid.mock.calls.length
cacheHarness.getRowsHybrid.mockResolvedValueOnce(sourceRows)
fireEvent.click(screen.getByTestId('show-rows'))

await waitFor(() => {
expect(cacheHarness.getRowsHybrid.mock.calls.length).toBeGreaterThan(getRowsCallCountBeforeStaleReload)
})

await waitFor(() => {
expect(gridHarness.getCellContent?.([0, 0])?.displayData).toBe('')
expect(gridHarness.getCellContent?.([1, 1])?.displayData).toBe('10')
Expand All @@ -433,7 +424,8 @@ describe('SpreadsheetView formula display commit', () => {
let capturedCopy: (() => void | Promise<void>) | null = null
let capturedCut: (() => void | Promise<void>) | null = null
let capturedPaste: (() => void | Promise<void>) | null = null
render(
cacheHarness.flushOverlay.mockImplementation(() => new Promise<void>(() => {}))
const { unmount } = render(
<SpreadsheetView
onCopyRequest={fn => { capturedCopy = fn }}
onCutRequest={fn => { capturedCut = fn }}
Expand Down Expand Up @@ -465,6 +457,14 @@ describe('SpreadsheetView formula display commit', () => {
// Stale range read keeps the visible cell overlay-authoritative while base data is blank.
const getRowsCallCountBeforeStaleReload = cacheHarness.getRowsHybrid.mock.calls.length
cacheHarness.getRowsHybrid.mockResolvedValueOnce(sourceRows)
unmount()
render(
<SpreadsheetView
onCopyRequest={fn => { capturedCopy = fn }}
onCutRequest={fn => { capturedCut = fn }}
onPasteRequest={fn => { capturedPaste = fn }}
/>
)
fireEvent.click(screen.getByTestId('show-rows'))

await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const tauriHarness = vi.hoisted(() => ({
const undoHarness = vi.hoisted(() => ({
undo: vi.fn().mockResolvedValue(null),
redo: vi.fn().mockResolvedValue(null),
recordGridTransaction: vi.fn().mockResolvedValue(undefined),
}))
const storeHarness = vi.hoisted(() => {
const dataset = {
Expand Down
13 changes: 13 additions & 0 deletions src/components/data/__tests__/SpreadsheetView.theme.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,26 @@ vi.mock('@/services/cacheService', () => ({
default: {
getDatasetStorageInfo: vi.fn().mockResolvedValue(null),
getRowsHybrid: vi.fn().mockResolvedValue([]),
flushOverlay: vi.fn().mockResolvedValue(undefined),
getAllColumnStats: vi.fn().mockResolvedValue([]),
getPersistedColumnIds: vi.fn().mockResolvedValue([]),
getGridMutationQueueState: vi.fn().mockReturnValue({
status: 'idle',
failedQueueId: null,
error: null,
}),
subscribeGridMutationQueue: vi.fn((_datasetId: string, listener: (state: any) => void) => {
listener({ status: 'idle', failedQueueId: null, error: null })
return () => undefined
}),
},
}))

vi.mock('@/lib/grid/editExecutor', () => ({
createEditExecutor: vi.fn(() => ({
execute: vi.fn().mockResolvedValue(undefined),
executeSingle: vi.fn(),
applyDataStoreUpdate: vi.fn(),
})),
}))

Expand Down
4 changes: 2 additions & 2 deletions src/lib/grid/__tests__/formulaLargeDataset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('FormulaService large dataset guards', () => {
formulaService.setAsyncAggregateContext(asyncContext)
formulaService.setBackendEvalContext(backendContext)

const result = formulaService.evaluate('=A1', { row: 1, col: 1, sheet: 'Sheet1' })
const result = formulaService.evaluate('=A1', { row: 2, col: 1, sheet: 'Sheet1' })
expect(result.error?.type).toBe('#VALUE!')
expect(result.error?.message).toContain('row order')
})
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('FormulaService large dataset guards', () => {
enqueueBackendEval: vi.fn(),
})

const result = formulaService.evaluate('=A1', { row: 1, col: 1, sheet: 'Sheet1' })
const result = formulaService.evaluate('=A1', { row: 2, col: 1, sheet: 'Sheet1' })
expect(result.error).toBeUndefined()
expect(result.value).toBe(42)
})
Expand Down
9 changes: 8 additions & 1 deletion src/store/__tests__/app-store.familyBinding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
* - null familyId captured = no binding (explicit "no family" signal)
* - non-existent dataset = no orphan family binding
*/
import { beforeEach, describe, expect, it } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useAppStore } from '@/store/app-store'
import { useDataStore } from '@/store/data-store'
import type { Dataset } from '@/store/data-store'

vi.mock('@/services/cacheService', () => ({
default: {
createEmptyDuckDB: vi.fn().mockResolvedValue(undefined),
setActiveProjectId: vi.fn().mockResolvedValue('project-1'),
},
}))

// Minimal Dataset stub
function makeDataset(overrides: Partial<Dataset> = {}): Dataset {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/store/remote-session-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('useRemoteSessionStore', () => {

await useRemoteSessionStore.getState().revoke()

expect(revokeRemoteControl).toHaveBeenCalledWith('session-1')
expect(revokeRemoteControl).toHaveBeenCalledWith('session-1', undefined)
expect(stopRemoteSession).toHaveBeenCalled()
expect(useRemoteSessionStore.getState().status?.current_session).toBeNull()
expect(useRemoteSessionStore.getState().invite).toBeNull()
Expand All @@ -265,7 +265,7 @@ describe('useRemoteSessionStore', () => {

await useRemoteSessionStore.getState().revoke()

expect(revokeRemoteControl).toHaveBeenCalledWith('session-1')
expect(revokeRemoteControl).toHaveBeenCalledWith('session-1', undefined)
expect(stopRemoteSession).toHaveBeenCalled()
expect(useRemoteSessionStore.getState().status?.current_session).toBeNull()
expect(useRemoteSessionStore.getState().invite).toBeNull()
Expand Down
15 changes: 15 additions & 0 deletions src/test-utils/__tests__/vitestConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'

import { resolveVitestMaxWorkers } from '../../../vitest.workerPolicy'

describe('Vitest worker policy', () => {
it('caps hosted CI runs at two workers', () => {
expect(resolveVitestMaxWorkers({ ci: true, parallelism: 16 })).toBe(2)
})

it('keeps local runs adaptive up to four workers', () => {
expect(resolveVitestMaxWorkers({ ci: false, parallelism: 16 })).toBe(4)
expect(resolveVitestMaxWorkers({ ci: false, parallelism: 3 })).toBe(2)
expect(resolveVitestMaxWorkers({ ci: false, parallelism: 1 })).toBe(1)
})
})
53 changes: 53 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,74 @@
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import { existsSync } from 'node:fs'
import path from 'path'

import { resolveVitestMaxWorkers } from './vitest.workerPolicy'

const privateE2eUtilsPath = path.resolve(__dirname, 'e2e/utils')
const hasPrivateE2eDependencyClosure = (...helperFiles: string[]) =>
helperFiles.every((helperFile) =>
existsSync(path.resolve(privateE2eUtilsPath, helperFile)),
)

const hasDeviceApprovalDependencies = hasPrivateE2eDependencyClosure(
'device-approval-helper.mjs',
)
const hasRValidationDependencies = hasPrivateE2eDependencyClosure(
'r-validation.mjs',
'categorical-stat-map.mjs',
'group5-stat-map.mjs',
)
const hasValidationPathAliasDependencies = hasPrivateE2eDependencyClosure(
'r-validation.mjs',
'categorical-stat-map.mjs',
'group5-stat-map.mjs',
'fixtures.mjs',
'manifest.mjs',
)

const privateE2eContractTests = [
...(hasDeviceApprovalDependencies
? []
: ['src/services/__tests__/deviceApprovalHelper.test.ts']),
...(hasRValidationDependencies
? []
: [
'src/utils/__tests__/rValidation.compareToRBaseline.test.ts',
'src/utils/__tests__/rValidation.extractStatsFromUI.test.ts',
'src/utils/__tests__/rValidation.lmmInferentialReport.test.ts',
]),
...(hasValidationPathAliasDependencies
? []
: ['src/utils/__tests__/validationPathAliases.test.ts']),
]

const maxWorkers = resolveVitestMaxWorkers({
ci: process.env.CI === 'true',
})

export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/test-utils/setup.ts'],
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
// AppShell contract suites reset modules and import the full shell. Bounding
// concurrent transforms prevents hook starvation while retaining parallelism.
// Hosted CI has less predictable shared resources, so keep it at the verified
// two-worker ceiling; local runs reserve one CPU and may use up to four.
maxWorkers,
exclude: [
'node_modules',
'dist',
'src-tauri',
'.git',
'.cache',
'build',
// Private checkouts provide these ignored helpers and keep this coverage.
// Public checkouts remain self-contained without publishing private E2E code.
...privateE2eContractTests,
],
coverage: {
provider: 'v8',
Expand Down
12 changes: 12 additions & 0 deletions vitest.workerPolicy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { availableParallelism } from 'node:os'

interface VitestWorkerPolicyOptions {
ci: boolean
parallelism?: number
}

export const resolveVitestMaxWorkers = ({
ci,
parallelism = availableParallelism(),
}: VitestWorkerPolicyOptions) =>
Math.max(1, Math.min(ci ? 2 : 4, parallelism - 1))
Loading