Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(storage): Test on a mirrored phone storage row probes the backends on the form

Mauricedf7bb9a5e118
diff --git a/client/src/components/Admin/storage/AdminStoragePanel.tsx b/client/src/components/Admin/storage/AdminStoragePanel.tsx
index b567e1cc8..3223dedee 100644
--- a/client/src/components/Admin/storage/AdminStoragePanel.tsx
+++ b/client/src/components/Admin/storage/AdminStoragePanel.tsx
@@ -38,7 +38,7 @@ import {
StatusPill,
} from '../../Settings/settingsKit'
import BackendForm from './BackendForm'
-import { CACHE_CATEGORIES, mirrorProbeTargets, primaryNameOf } from './storageModel'
+import { CACHE_CATEGORIES, primaryNameOf } from './storageModel'
import { categoryNames, migrationPromptLine, useStoragePanel } from './useStoragePanel'
/** The compact buttons of a backend row: white on a hairline, a size under the card's own. */
@@ -123,7 +123,7 @@ export default function AdminStoragePanel(): React.ReactElement {
)
}
const {
- state, draft, migrationCandidates, backendNames, rows, degenerate, effective, usageSums, startAdd, startEdit,
+ state, draft, migrationCandidates, backendNames, rows, degenerate, effective, usageSums, startAdd, startEdit, testRow,
commitBackend, removeMessage, confirmRemoval, setCategory, save, moveAndSave, routeOnlySave,
} = loaded
@@ -202,11 +202,6 @@ export default function AdminStoragePanel(): React.ReactElement {
{rows.map((row) => {
const resultKey = row.mirrorName ?? row.name
const result = testResultFor(resultKey)
- // row.mirrorName only exists when foldBackends adopted a draft mirror
- // for this row, so the draft lookup below cannot miss.
- const testCandidate = row.mirrorName
- ? draft.backends.find((b) => b.name === row.mirrorName)!
- : row.backend
const rowUsage = usageSums?.[row.name]
const backfill = row.mirrorName ? state.backfills.find((b) => b.backend === row.mirrorName) : undefined
const TypeIcon = TYPE_ICON[row.type] ?? HardDrive
@@ -234,11 +229,7 @@ export default function AdminStoragePanel(): React.ReactElement {
<button type="button"
className={ROW_BUTTON}
style={fs(12, 'body')}
- onClick={() =>
- row.mirrorName
- ? admin.testMirror(resultKey, mirrorProbeTargets(draft, state, testCandidate))
- : admin.test(testCandidate)
- }
+ onClick={() => void testRow(row)}
>
<PlugZap size={13} strokeWidth={2.2} />
{t('storage.actions.test')}
diff --git a/client/src/components/Admin/storage/useStoragePanel.test.ts b/client/src/components/Admin/storage/useStoragePanel.test.ts
index e1216908d..f75447f0c 100644
--- a/client/src/components/Admin/storage/useStoragePanel.test.ts
+++ b/client/src/components/Admin/storage/useStoragePanel.test.ts
@@ -1,4 +1,4 @@
-// FE-ADMIN-STOR-PANEL-001 to -012: the storage panel logic behind both admin shells.
+// FE-ADMIN-STOR-PANEL-001 to -017: the storage panel logic behind both admin shells.
import { act, renderHook, waitFor } from '@testing-library/react';
import { STORAGE_CATEGORIES, type StorageAdminState, type StorageBackend, type StorageConfig } from '@trek/shared';
@@ -218,6 +218,27 @@ describe('useStoragePanel', () => {
expect(fake.admin.startMigration).toHaveBeenCalledTimes(1);
});
+ it('FE-ADMIN-STOR-PANEL-017: testRow probes a plain row as it is and a mirrored row per draft target', () => {
+ const state = baseState();
+ const draft: StorageConfig = {
+ ...settingsDocumentOf(state),
+ backends: [
+ ...settingsDocumentOf(state).backends,
+ { name: 'off-box-mirror', type: 'mirror', options: { primary: 'off-box', replicas: ['uploads-local'] } },
+ ],
+ };
+ fake.admin = makeAdmin(state, draft);
+ const { result } = renderHook(() => useStoragePanel());
+ const rows = result.current.loaded!.rows;
+ void result.current.loaded!.testRow(rows.find((r) => r.name === 'uploads-local')!);
+ expect(fake.admin.test).toHaveBeenCalledWith(expect.objectContaining({ name: 'uploads-local' }));
+ void result.current.loaded!.testRow(rows.find((r) => r.name === 'off-box')!);
+ expect(fake.admin.testMirror).toHaveBeenCalledWith('off-box-mirror', [
+ expect.objectContaining({ name: 'off-box', type: 'local' }),
+ expect.objectContaining({ name: 'uploads-local', type: 'local' }),
+ ]);
+ });
+
it('FE-ADMIN-STOR-PANEL-013: backfill and stats actions toast the server error', async () => {
fake.admin = makeAdmin(baseState());
vi.mocked(fake.admin.refreshStats).mockResolvedValueOnce('scan failed');
diff --git a/client/src/components/Admin/storage/useStoragePanel.ts b/client/src/components/Admin/storage/useStoragePanel.ts
index 460d0badd..6a5155889 100644
--- a/client/src/components/Admin/storage/useStoragePanel.ts
+++ b/client/src/components/Admin/storage/useStoragePanel.ts
@@ -17,6 +17,7 @@ import {
computeMigrationCandidates,
effectiveCategoryMap,
foldBackends,
+ mirrorProbeTargets,
removeBackend,
removeBackendAndMirrors,
renameBackendRefs,
@@ -225,6 +226,17 @@ export function useStoragePanel() {
setEditing(null);
};
+ // A mirrored row probes its primary and each replica one by one, with the draft
+ // options of each: the server would resolve a mirror stub against its SAVED
+ // backends by name, so unsaved edits (or a replica not saved yet) would be missed.
+ // row.mirrorName only exists when foldBackends adopted a draft mirror for this
+ // row, so the draft lookup cannot miss.
+ const testRow = (row: FoldedBackendRow) => {
+ if (!row.mirrorName) return admin.test(row.backend);
+ const mirror = draft.backends.find((b) => b.name === row.mirrorName)!;
+ return admin.testMirror(row.mirrorName, mirrorProbeTargets(draft, state, mirror));
+ };
+
const removeMessage = (name: string, isDegenerate: boolean): string => {
const row = rows.find((r) => r.name === name);
const assigned = isDegenerate
@@ -333,6 +345,7 @@ export function useStoragePanel() {
usageSums,
startAdd,
startEdit,
+ testRow,
commitBackend,
removeMessage,
confirmRemoval,
diff --git a/client/src/mobile/screens/admin/MAdminStoragePanel.tsx b/client/src/mobile/screens/admin/MAdminStoragePanel.tsx
index d392997c9..6e0dfa252 100644
--- a/client/src/mobile/screens/admin/MAdminStoragePanel.tsx
+++ b/client/src/mobile/screens/admin/MAdminStoragePanel.tsx
@@ -190,7 +190,7 @@ export default function MAdminStoragePanel(): React.ReactElement {
)
}
const {
- state, draft, backendNames, rows, degenerate, effective, usageSums, startAdd, startEdit, commitBackend,
+ state, draft, backendNames, rows, degenerate, effective, usageSums, startAdd, startEdit, testRow, commitBackend,
removeMessage, confirmRemoval, setCategory, save, moveAndSave, routeOnlySave,
} = loaded
@@ -236,11 +236,6 @@ export default function MAdminStoragePanel(): React.ReactElement {
{rows.map((row) => {
const resultKey = row.mirrorName ?? row.name
const result = admin.testResults[resultKey]
- // row.mirrorName only exists when foldBackends adopted a draft mirror
- // for this row, so the draft lookup below cannot miss.
- const testCandidate = row.mirrorName
- ? draft.backends.find((b) => b.name === row.mirrorName)!
- : row.backend
const rowUsage = usageSums?.[row.name]
const backfill = row.mirrorName ? state.backfills.find((b) => b.backend === row.mirrorName) : undefined
return (
@@ -285,7 +280,7 @@ export default function MAdminStoragePanel(): React.ReactElement {
<p className="mt-1 font-geist text-[0.625rem] text-m-muted">{t('storage.backends.envReadOnly')}</p>
)}
<div className="mt-2 flex gap-2">
- <MAdminButton variant="ghost" onClick={() => admin.test(testCandidate)}>
+ <MAdminButton variant="ghost" onClick={() => void testRow(row)}>
{t('storage.actions.test')}
</MAdminButton>
{row.source !== 'env' && (
diff --git a/client/tests/unit/mobile/admin/MAdminStoragePanel.test.tsx b/client/tests/unit/mobile/admin/MAdminStoragePanel.test.tsx
index 3b5b8fa63..736d155cb 100644
--- a/client/tests/unit/mobile/admin/MAdminStoragePanel.test.tsx
+++ b/client/tests/unit/mobile/admin/MAdminStoragePanel.test.tsx
@@ -441,4 +441,26 @@ describe('MAdminStoragePanel', () => {
await new Promise((r) => setTimeout(r, 100));
expect(screen.queryByText(/Existing objects are not replicated yet/)).not.toBeInTheDocument();
});
+
+ it('FE-MOB-MSTOR-018: Test on a mirrored primary probes the draft primary and each replica, never the mirror stub', async () => {
+ const posted: Array<{ name: string; type: string; options: Record<string, unknown> }> = [];
+ await renderPanel(mirroredState());
+ server.use(
+ http.post('/api/admin/storage/test', async ({ request }) => {
+ const body = (await request.json()) as { backend: { name: string; type: string; options: Record<string, unknown> } };
+ posted.push(body.backend);
+ return HttpResponse.json({ ok: true, targets: [{ name: body.backend.name, ok: true }] });
+ }),
+ );
+ // An unsaved endpoint change on the replica must be what the probe sees.
+ fireEvent.click(within(screen.getByTestId('m-storage-backend-off-box')).getByRole('button', { name: 'Edit' }));
+ fireEvent.change(screen.getByDisplayValue('http://127.0.0.1:9000'), { target: { value: 'http://edited.example:9000' } });
+ fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
+ fireEvent.click(within(screen.getByTestId('m-storage-backend-backups-local')).getByRole('button', { name: 'Test' }));
+ await waitFor(() => expect(posted.length).toBeGreaterThan(0));
+ await new Promise((r) => setTimeout(r, 50));
+ expect(posted.map((b) => b.name).sort()).toEqual(['backups-local', 'off-box']);
+ expect(posted.every((b) => b.type !== 'mirror')).toBe(true);
+ expect(posted.find((b) => b.name === 'off-box')?.options.endpoint).toBe('http://edited.example:9000');
+ });
});