fix: v0.17.0 — sim-control POST retries + permission-aware notifications e2e
CI / build + unit + e2e (pull_request) Successful in 6m52s
CI / build + unit + e2e (pull_request) Successful in 6m52s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { pendingScaleConfirmed } from './LeftPane';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { pendingScaleConfirmed, retrySimPost, SIM_POST_MAX_ATTEMPTS, SIM_POST_RETRY_DELAY_MS } from './LeftPane';
|
||||
|
||||
// ISS-001 — the optimistic slider value is cleared exactly when a rendered snapshot confirms
|
||||
// it (server scale === pending), never earlier. Clearing at commit time would snap the pointer
|
||||
@@ -22,3 +22,70 @@ describe('pendingScaleConfirmed', () => {
|
||||
expect(pendingScaleConfirmed(1, 1)).toBe(true); // committing the current value confirms immediately
|
||||
});
|
||||
});
|
||||
|
||||
// ISS-008 fix (CI runs #44/#47): a dropped POST /api/sim must be retried before surfacing the
|
||||
// error — up to SIM_POST_MAX_ATTEMPTS tries with SIM_POST_RETRY_DELAY_MS between them, and a newer
|
||||
// intent supersedes the in-flight body instead of waiting out its retries.
|
||||
|
||||
describe('retrySimPost', () => {
|
||||
it('pins the retry budget: 3 attempts total, ~500 ms backoff', () => {
|
||||
expect(SIM_POST_MAX_ATTEMPTS).toBe(3);
|
||||
expect(SIM_POST_RETRY_DELAY_MS).toBe(500);
|
||||
});
|
||||
|
||||
it('succeeds on the first attempt without sleeping or retrying', async () => {
|
||||
const post = vi.fn(async () => {});
|
||||
const sleep = vi.fn(async () => {});
|
||||
await expect(retrySimPost(post, () => false, sleep)).resolves.toEqual({ ok: true });
|
||||
expect(post).toHaveBeenCalledTimes(1);
|
||||
expect(sleep).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('retries with the backoff delay and succeeds on a later attempt', async () => {
|
||||
let calls = 0;
|
||||
const post = vi.fn(async () => {
|
||||
if (++calls < 3) throw new Error('dropped');
|
||||
});
|
||||
const sleep = vi.fn(async () => {});
|
||||
await expect(retrySimPost(post, () => false, sleep)).resolves.toEqual({ ok: true });
|
||||
expect(post).toHaveBeenCalledTimes(3);
|
||||
expect(sleep).toHaveBeenCalledTimes(2); // one backoff between each pair of attempts
|
||||
expect(sleep).toHaveBeenCalledWith(SIM_POST_RETRY_DELAY_MS);
|
||||
});
|
||||
|
||||
it('gives up after the final attempt with the last error (no trailing sleep)', async () => {
|
||||
const err = new Error('down');
|
||||
const post = vi.fn(async () => {
|
||||
throw err;
|
||||
});
|
||||
const sleep = vi.fn(async () => {});
|
||||
const result = await retrySimPost(post, () => false, sleep);
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) {
|
||||
expect(result.reason).toBe('exhausted');
|
||||
if (result.reason === 'exhausted') expect(result.error).toBe(err); // the LAST attempt's error
|
||||
}
|
||||
expect(post).toHaveBeenCalledTimes(SIM_POST_MAX_ATTEMPTS);
|
||||
expect(sleep).toHaveBeenCalledTimes(SIM_POST_MAX_ATTEMPTS - 1);
|
||||
});
|
||||
|
||||
it('stops retrying once a newer intent supersedes the in-flight body (no further attempts or sleeps)', async () => {
|
||||
let calls = 0;
|
||||
const post = vi.fn(async () => {
|
||||
calls++; // flip "superseded" right after the first failure, like a queued commitNow would
|
||||
throw new Error('dropped');
|
||||
});
|
||||
const sleep = vi.fn(async () => {});
|
||||
await expect(retrySimPost(post, () => calls >= 1, sleep)).resolves.toEqual({ ok: false, reason: 'superseded' });
|
||||
expect(post).toHaveBeenCalledTimes(1); // the caller's loop sends the newer body instead
|
||||
expect(sleep).not.toHaveBeenCalled(); // supersede is checked before the backoff sleep
|
||||
});
|
||||
|
||||
it('never even sends a body that is already superseded', async () => {
|
||||
const post = vi.fn(async () => {});
|
||||
const sleep = vi.fn(async () => {});
|
||||
await expect(retrySimPost(post, () => true, sleep)).resolves.toEqual({ ok: false, reason: 'superseded' });
|
||||
expect(post).not.toHaveBeenCalled();
|
||||
expect(sleep).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user