Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { currentOperationSource, withOperationSource } from '../../src/lib/server/hosts/operation-context.js';
|
||||
import {
|
||||
currentOperationSource,
|
||||
withOperationSource
|
||||
} from '../../src/lib/server/hosts/operation-context.js';
|
||||
import { trackActivity, workerActivity } from '../../src/lib/server/pipeline/activity.js';
|
||||
|
||||
describe('host operation source context', () => {
|
||||
it('isolates overlapping asynchronous sources and restores the caller', async () => {
|
||||
let release!: () => void;
|
||||
const barrier = new Promise<void>(resolve => { release = resolve; });
|
||||
const barrier = new Promise<void>((resolve) => {
|
||||
release = resolve;
|
||||
});
|
||||
const first = withOperationSource('GET /servers/[name]', async () => {
|
||||
await barrier;
|
||||
return currentOperationSource();
|
||||
@@ -16,7 +21,10 @@ describe('host operation source context', () => {
|
||||
return currentOperationSource();
|
||||
});
|
||||
expect(currentOperationSource()).toBeNull();
|
||||
expect(await Promise.all([first, second])).toEqual(['GET /servers/[name]', 'Status monitor']);
|
||||
expect(await Promise.all([first, second])).toEqual([
|
||||
'GET /servers/[name]',
|
||||
'Status monitor'
|
||||
]);
|
||||
expect(currentOperationSource()).toBeNull();
|
||||
});
|
||||
|
||||
@@ -27,7 +35,11 @@ describe('host operation source context', () => {
|
||||
expect(currentOperationSource()).toBe('Status monitor');
|
||||
});
|
||||
expect(currentOperationSource()).toBe('POST /api/servers/[name]/refresh');
|
||||
expect(() => withOperationSource('Failing task', () => { throw new Error('failed'); })).toThrow('failed');
|
||||
expect(() =>
|
||||
withOperationSource('Failing task', () => {
|
||||
throw new Error('failed');
|
||||
})
|
||||
).toThrow('failed');
|
||||
expect(currentOperationSource()).toBe('POST /api/servers/[name]/refresh');
|
||||
});
|
||||
expect(currentOperationSource()).toBeNull();
|
||||
@@ -44,18 +56,21 @@ describe('host operation source context', () => {
|
||||
await withOperationSource('POST /api/servers/[name]/restart', () =>
|
||||
trackActivity('context-test-request', 'Processing provisioning requests', async () => {
|
||||
expect(currentOperationSource()).toBe('POST /api/servers/[name]/restart');
|
||||
}));
|
||||
})
|
||||
);
|
||||
expect(currentOperationSource()).toBeNull();
|
||||
expect(workerActivity()).toEqual([]);
|
||||
});
|
||||
|
||||
it('restores context and clears activity when asynchronous work rejects', async () => {
|
||||
await withOperationSource('Manual maintenance check', async () => {
|
||||
await expect(trackActivity('context-test-error', 'Waiting for files.read', async () => {
|
||||
await Promise.resolve();
|
||||
expect(currentOperationSource()).toBe('Manual maintenance check');
|
||||
throw new Error('unavailable');
|
||||
})).rejects.toThrow('unavailable');
|
||||
await expect(
|
||||
trackActivity('context-test-error', 'Waiting for files.read', async () => {
|
||||
await Promise.resolve();
|
||||
expect(currentOperationSource()).toBe('Manual maintenance check');
|
||||
throw new Error('unavailable');
|
||||
})
|
||||
).rejects.toThrow('unavailable');
|
||||
expect(currentOperationSource()).toBe('Manual maintenance check');
|
||||
});
|
||||
expect(currentOperationSource()).toBeNull();
|
||||
|
||||
Reference in New Issue
Block a user