Files
SnowLuma/packages/onebot/tests/manager-config-apply.test.ts
T
DrSmoothl 852004291b feat(onebot): reconcile and drain network adapters
Serialize desired network plans, isolate per-adapter apply failures, restore prior bindings when possible, and report saved versus applied state. Quiesce Action and event ingress, await in-flight dispatches and transport closes, retain failed generations for retry, and propagate shutdown failures.
2026-07-10 13:49:17 +08:00

37 lines
1.2 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { OneBotManager } from '../src/manager';
import type { OneBotConfig } from '../src/types';
function config(trigger: string): OneBotConfig {
return {
networks: { httpServers: [], httpClients: [], wsServers: [], wsClients: [] },
statusCommand: { enabled: true, swallow: false, cooldownSeconds: 5, trigger },
notifications: { channelIds: [] },
};
}
describe('OneBotManager config apply value ownership', () => {
it('passes each concurrent caller exact config value to the instance', async () => {
const manager = new OneBotManager();
const seen: OneBotConfig[] = [];
const instance = {
reloadConfig: vi.fn(async (value: OneBotConfig) => {
seen.push(value);
return { applied: true, errors: [], statuses: [] };
}),
};
(manager as unknown as { instances: Map<string, unknown> }).instances.set('10001', instance);
const a = config('#a');
const b = config('#b');
await Promise.all([
manager.reloadConfig('10001', a),
manager.reloadConfig('10001', b),
]);
expect(seen).toEqual([a, b]);
expect(instance.reloadConfig).toHaveBeenNthCalledWith(1, a);
expect(instance.reloadConfig).toHaveBeenNthCalledWith(2, b);
});
});