fix(web): gate Plex authorized-no-servers messaging on released lock
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 8s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 8s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 24s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 44s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 4m17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 5m18s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 5m56s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 8s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 8s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 24s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 44s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 4m17s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 5m18s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 5m56s
Adversarial review of the initial fix found that authorizedNoServers = isAuthorized && !hasServers ignored isLocked. Because boot.state updates on every poll observation, the "no eligible servers — sign out and retry" subtitle + summary rendered during the normal `finalizing` window (locked, authorized, no servers yet) alongside the "discovering your Plex servers…" status — and during `budget-exhausted` (large first sync still holding the lock, polling stopped, Sign out enabled) it urged the user to sign out mid-sync. That reintroduced the contradictory-state class the PR fixes. Gate the empty-servers presentation on !isLocked so it only appears at the genuine released-lock terminal. Add regression coverage: the pin-flow test now passes through the finalizing cell asserting the empty-servers messaging is absent while locked, plus a budget-exhausted-while-locked case. Both new guards were confirmed to fail on the ungated code (negative control). Refs #345
This commit is contained in:
@@ -188,6 +188,16 @@ describe('PlexSourceScreen', () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Sign in to Plex' }));
|
||||
await vi.waitFor(() => expect(screen.getByText(/Waiting for you to authorize/i)).toBeTruthy());
|
||||
|
||||
// Authorized but STILL LOCKED = finalizing (discovery in progress). The empty-servers terminal
|
||||
// messaging must NOT appear here — while locked this is the normal "discovering" window, not
|
||||
// "no servers were found" (regression guard for the isLocked gate).
|
||||
stateRef.current = { isAuthorized: true, isLocked: true, servers: [] };
|
||||
await vi.advanceTimersByTimeAsync(2000);
|
||||
await vi.waitFor(() => expect(screen.getByText(/discovering your Plex servers/i)).toBeTruthy());
|
||||
expect(screen.queryByText(/Your Plex account is authorized/i)).toBeNull(); // no "sign out and retry" summary
|
||||
expect(screen.queryByText(/no eligible servers were discovered/i)).toBeNull();
|
||||
expect(screen.queryByRole('button', { name: 'Sign in to Plex' })).toBeNull();
|
||||
|
||||
// Lock releases while authorized but discovery found nothing: the distinct terminal state.
|
||||
stateRef.current = { isAuthorized: true, isLocked: false, servers: [] };
|
||||
await vi.advanceTimersByTimeAsync(2000);
|
||||
@@ -230,4 +240,30 @@ describe('PlexSourceScreen', () => {
|
||||
expect(fetchSpy.mock.calls.some(([input, init]) => String(input).endsWith('/sign-out') && (init?.method ?? '').toUpperCase() === 'POST')).toBe(true)
|
||||
);
|
||||
});
|
||||
|
||||
// #345 (review follow-up): a large first sync legitimately still holds the lock past the poll
|
||||
// budget (budget-exhausted). The empty-servers "sign out and retry" messaging must NOT show — it
|
||||
// would contradict the "Still working…" status and urge aborting an in-progress sync.
|
||||
it('budget-exhausted while locked with no servers does not show the "no servers, sign out" messaging', async () => {
|
||||
const stateRef = { current: { isAuthorized: false, isLocked: false, servers: [] } as PlexState };
|
||||
const counter = { state: 0 };
|
||||
installFetch(stateRef, counter);
|
||||
vi.spyOn(window, 'open').mockReturnValue({} as Window);
|
||||
vi.useFakeTimers();
|
||||
|
||||
render(<PlexSourceScreen />);
|
||||
await vi.waitFor(() => expect(screen.getByRole('button', { name: 'Sign in to Plex' })).toBeTruthy());
|
||||
|
||||
// Authorized but locked forever (large first sync holds the lock).
|
||||
stateRef.current = { isAuthorized: true, isLocked: true, servers: [] };
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Sign in to Plex' }));
|
||||
await vi.waitFor(() => expect(screen.getByText(/discovering your Plex servers|Waiting/i)).toBeTruthy());
|
||||
|
||||
await vi.advanceTimersByTimeAsync(152_000); // consume the whole 150s budget
|
||||
await vi.waitFor(() => expect(screen.getByText(/Still working/i)).toBeTruthy());
|
||||
|
||||
// The lock is still held, so no terminal "no servers were found" messaging.
|
||||
expect(screen.queryByText(/Your Plex account is authorized/i)).toBeNull();
|
||||
expect(screen.queryByText(/no eligible servers were discovered/i)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -220,7 +220,12 @@ export function PlexSourceScreen() {
|
||||
// authorized/unlocked/empty-servers state recoverable: Sign out is offered, Sign in is not.
|
||||
const hasPlexAccount = isAuthorized || hasServers;
|
||||
const needsFix = hasServers && !isAuthorized;
|
||||
const authorizedNoServers = isAuthorized && !hasServers;
|
||||
// Only a RELEASED lock is terminal: while `isLocked`, an authorized+empty observation is the
|
||||
// normal `finalizing` (discovery in progress) or `budget-exhausted` (large first sync still
|
||||
// running) window — NOT "no servers were found". Gating on `!isLocked` keeps the "no eligible
|
||||
// servers, sign out and retry" messaging from contradicting the in-flight discovery status and
|
||||
// from urging a sign-out that would abort a legitimately-running sync.
|
||||
const authorizedNoServers = isAuthorized && !hasServers && !isLocked;
|
||||
const connectionSubtitle = !hasPlexAccount
|
||||
? 'Not signed in.'
|
||||
: needsFix
|
||||
|
||||
Reference in New Issue
Block a user