Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
70
frontend/tests/quotaSessionIsolation.test.ts
Normal file
70
frontend/tests/quotaSessionIsolation.test.ts
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import { beforeEach, describe, expect, test } from 'vitest';
|
||||
import { invalidateAuthFileDerivedCaches } from '../src/features/authFiles/cacheInvalidation';
|
||||
import {
|
||||
captureQuotaCacheGeneration,
|
||||
commitIfQuotaCacheCurrent,
|
||||
useQuotaStore,
|
||||
} from '../src/stores/useQuotaStore';
|
||||
|
||||
describe('quota cache session isolation', () => {
|
||||
beforeEach(() => {
|
||||
useQuotaStore.getState().clearQuotaCache();
|
||||
});
|
||||
|
||||
test('prevents an earlier connection from committing after the cache is cleared', () => {
|
||||
const previousConnection = captureQuotaCacheGeneration();
|
||||
let committed = false;
|
||||
|
||||
useQuotaStore.getState().clearQuotaCache();
|
||||
|
||||
expect(
|
||||
commitIfQuotaCacheCurrent(previousConnection, () => {
|
||||
committed = true;
|
||||
})
|
||||
).toBe(false);
|
||||
expect(committed).toBe(false);
|
||||
});
|
||||
|
||||
test('allows the current connection generation to commit', () => {
|
||||
const currentConnection = captureQuotaCacheGeneration();
|
||||
let committed = false;
|
||||
|
||||
expect(
|
||||
commitIfQuotaCacheCurrent(currentConnection, () => {
|
||||
committed = true;
|
||||
})
|
||||
).toBe(true);
|
||||
expect(committed).toBe(true);
|
||||
});
|
||||
|
||||
test('clears same-name quota and rejects an in-flight commit after auth mutation', () => {
|
||||
const fileName = 'shared-codex.json';
|
||||
useQuotaStore.getState().setCodexQuota({
|
||||
[fileName]: {
|
||||
status: 'success',
|
||||
windows: [],
|
||||
planType: 'account-a',
|
||||
},
|
||||
});
|
||||
const accountARequest = captureQuotaCacheGeneration();
|
||||
let invalidatedNames: string[] | undefined;
|
||||
|
||||
invalidateAuthFileDerivedCaches(
|
||||
(names) => {
|
||||
invalidatedNames = names;
|
||||
},
|
||||
[fileName]
|
||||
);
|
||||
|
||||
expect(invalidatedNames).toEqual([fileName]);
|
||||
expect(useQuotaStore.getState().codexQuota[fileName]).toBeUndefined();
|
||||
|
||||
let committed = false;
|
||||
expect(
|
||||
commitIfQuotaCacheCurrent(accountARequest, () => {
|
||||
committed = true;
|
||||
})
|
||||
).toBe(false);
|
||||
expect(committed).toBe(false);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue