feat(coding-runtime): add managed Pi extension host
This commit is contained in:
1 parent
47159b3cbd
commit
3861c3286a
22 files changed
+1673
-16
No files matched your search
@@ -0,0 +1,42 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { PiProjectWriteLeaseCoordinator } from '../../electron/coding-runtime/pi/write-lease';
|
||||
|
||||
describe('Pi project write lease', () => {
|
||||
it('serializes mutations in one project while allowing other projects to proceed', async () => {
|
||||
const coordinator = new PiProjectWriteLeaseCoordinator();
|
||||
const first = await coordinator.acquire('project-a', 'write-a1');
|
||||
let secondSettled = false;
|
||||
const secondFlight = coordinator.acquire('project-a', 'write-a2').then((lease) => {
|
||||
secondSettled = true;
|
||||
return lease;
|
||||
});
|
||||
const otherProject = await coordinator.acquire('project-b', 'write-b1');
|
||||
|
||||
await Promise.resolve();
|
||||
expect(secondSettled).toBe(false);
|
||||
expect(coordinator.activeCount).toBe(2);
|
||||
expect(coordinator.waitingCount('project-a')).toBe(1);
|
||||
|
||||
first.release();
|
||||
const second = await secondFlight;
|
||||
expect(second.holderId).toBe('write-a2');
|
||||
second.release();
|
||||
otherProject.release();
|
||||
expect(coordinator.activeCount).toBe(0);
|
||||
});
|
||||
|
||||
it('removes a cancelled waiter without disturbing the active lease', async () => {
|
||||
const coordinator = new PiProjectWriteLeaseCoordinator();
|
||||
const active = await coordinator.acquire('project-a', 'active');
|
||||
const controller = new AbortController();
|
||||
const waiting = coordinator.acquire('project-a', 'waiting', controller.signal);
|
||||
controller.abort();
|
||||
|
||||
await expect(waiting).rejects.toThrow('cancelled');
|
||||
expect(coordinator.activeCount).toBe(1);
|
||||
expect(coordinator.waitingCount()).toBe(0);
|
||||
active.release();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user