Files
Supra4E8C df252e39ea test: merge overlapping suites and drop brittle assertions
Fold single-purpose files into their topic suites, parameterize the
per-provider copies, and remove source-grep, constant and duplicated
assertions plus locale presence checks now covered by localeParity.
2026-11-23 18:46:10 +08:00

64 lines
2.0 KiB
TypeScript

import { describe, expect, spyOn, test } from 'bun:test';
import { apiClient } from '../src/services/api/client';
import { runSavePlan } from '../src/features/authFiles/modelRules/useModelRulesData';
describe('model rules save connection isolation', () => {
for (const firstOperation of ['save', 'delete'] as const) {
for (const fails of [false, true]) {
test(`aborts after a stale ${firstOperation} ${fails ? 'failure' : 'success'}`, async () => {
let revision = 1;
const revisionSpy = spyOn(apiClient, 'getConnectionRevision').mockImplementation(
() => revision
);
const calls: string[] = [];
let finish!: () => void;
const pending = new Promise<void>((resolve, reject) => {
finish = () => (fails ? reject(new Error('stale request')) : resolve());
});
const operation = async (provider: string) => {
calls.push(provider);
await pending;
};
try {
const saving = runSavePlan(
[
{ provider: 'claude', value: firstOperation === 'delete' ? null : ['a'] },
{ provider: 'codex', value: ['b'] },
{ provider: 'gemini', value: null },
],
operation,
operation
);
expect(calls).toEqual(['claude']);
revision++;
finish();
expect(await saving).toBeNull();
expect(calls).toEqual(['claude']);
} finally {
revisionSpy.mockRestore();
}
});
}
}
test('also discards the outcome when the last operation becomes stale', async () => {
let revision = 1;
const revisionSpy = spyOn(apiClient, 'getConnectionRevision').mockImplementation(
() => revision
);
try {
expect(
await runSavePlan(
[{ provider: 'codex', value: ['a'] }],
async () => {
revision++;
},
async () => {}
)
).toBeNull();
} finally {
revisionSpy.mockRestore();
}
});
});