This commit is contained in:
DrSmoothl committed 2026-10-12 15:43:34 +08:00
1 parent effeb66554
commit 7c0519f75f
977 files changed
+198426 -158324

No files matched your search

@@ -4,54 +4,57 @@ 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 },
historySync: { enabled: false },
notifications: { channelIds: [] },
};
return {
networks: { httpServers: [], httpClients: [], wsServers: [], wsClients: [] },
statusCommand: { enabled: true, swallow: false, cooldownSeconds: 5, trigger },
historySync: { enabled: false },
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');
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),
]);
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);
});
expect(seen).toEqual([a, b]);
expect(instance.reloadConfig).toHaveBeenNthCalledWith(1, a);
expect(instance.reloadConfig).toHaveBeenNthCalledWith(2, b);
});
it('does not attach a caller operation to reconfigured network resources', async () => {
const manager = new OneBotManager();
const observedRequestIds: Array<number | undefined> = [];
let observeDeferred!: () => void;
const instance = {
reloadConfig: vi.fn(async () => {
observedRequestIds.push(currentRequestId());
observeDeferred = () => observedRequestIds.push(currentRequestId());
return { applied: true, errors: [], statuses: [] };
}),
};
(manager as unknown as { instances: Map<string, unknown> }).instances.set('10001', instance);
it('does not attach a caller operation to reconfigured network resources', async () => {
const manager = new OneBotManager();
const observedRequestIds: Array<number | undefined> = [];
let observeDeferred!: () => void;
const instance = {
reloadConfig: vi.fn(async () => {
observedRequestIds.push(currentRequestId());
observeDeferred = () => observedRequestIds.push(currentRequestId());
return { applied: true, errors: [], statuses: [] };
}),
};
(manager as unknown as { instances: Map<string, unknown> }).instances.set(
'10001',
instance,
);
await runWithRequestId(5101, () => manager.reloadConfig('10001', config('#reload')));
observeDeferred();
await runWithRequestId(5101, () => manager.reloadConfig('10001', config('#reload')));
observeDeferred();
expect(observedRequestIds).toEqual([undefined, undefined]);
});
expect(observedRequestIds).toEqual([undefined, undefined]);
});
});