feat: add configurable parallel video uploads
Allow up to four video upload connections while keeping one connection as the default. Preserve existing messaging interfaces and add configuration controls, reliable failure handling, and upload diagnostics. Closes #569
This commit is contained in:
18 files changed
+1182
-217
No files matched your search
@@ -29,8 +29,13 @@ describe('global-config (config/snowluma.json)', () => {
|
||||
expect(defaultGlobalSettings()).toEqual({
|
||||
rkey: { fallbackServers: [] },
|
||||
musicSignUrl: '',
|
||||
videoUploadConcurrency: 1,
|
||||
});
|
||||
expect(loadGlobalSettings()).toEqual({
|
||||
rkey: { fallbackServers: [] },
|
||||
musicSignUrl: '',
|
||||
videoUploadConcurrency: 1,
|
||||
});
|
||||
expect(loadGlobalSettings()).toEqual({ rkey: { fallbackServers: [] }, musicSignUrl: '' });
|
||||
});
|
||||
|
||||
it('keeps only well-formed http(s) URLs, trims, and dedupes', () => {
|
||||
@@ -55,10 +60,12 @@ describe('global-config (config/snowluma.json)', () => {
|
||||
expect(normalizeGlobalSettings({ rkey: 'nope' })).toEqual({
|
||||
rkey: { fallbackServers: [] },
|
||||
musicSignUrl: '',
|
||||
videoUploadConcurrency: 1,
|
||||
});
|
||||
expect(normalizeGlobalSettings(null)).toEqual({
|
||||
rkey: { fallbackServers: [] },
|
||||
musicSignUrl: '',
|
||||
videoUploadConcurrency: 1,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -74,6 +81,7 @@ describe('global-config (config/snowluma.json)', () => {
|
||||
expect(onDisk).toEqual({
|
||||
rkey: { fallbackServers: ['https://r.example/rkey'] },
|
||||
musicSignUrl: '',
|
||||
videoUploadConcurrency: 1,
|
||||
});
|
||||
|
||||
expect(loadGlobalSettings().rkey.fallbackServers).toEqual(['https://r.example/rkey']);
|
||||
@@ -100,6 +108,37 @@ describe('global-config (config/snowluma.json)', () => {
|
||||
expect(loadGlobalSettings().musicSignUrl).toBe('https://s.example/c');
|
||||
});
|
||||
|
||||
it.each([1, 2, 3, 4])('persists %i video connections and preserves partial saves', (value) => {
|
||||
expect(saveGlobalSettings({ videoUploadConcurrency: value }).videoUploadConcurrency).toBe(
|
||||
value,
|
||||
);
|
||||
saveGlobalSettings({ musicSignUrl: 'https://sign.example/card' });
|
||||
expect(loadGlobalSettings().videoUploadConcurrency).toBe(value);
|
||||
});
|
||||
|
||||
it.each([0, 5, -1, 1.5, '2', null, false])(
|
||||
'rejects invalid video concurrency %j without writing',
|
||||
(value) => {
|
||||
saveGlobalSettings({ videoUploadConcurrency: 3 });
|
||||
const file = path.join(tempDir, 'config', 'snowluma.json');
|
||||
const before = fs.readFileSync(file, 'utf8');
|
||||
expect(() => saveGlobalSettings({ videoUploadConcurrency: value })).toThrow(
|
||||
/integer from 1 to 4/,
|
||||
);
|
||||
expect(fs.readFileSync(file, 'utf8')).toBe(before);
|
||||
expect(() => normalizeGlobalSettings({ videoUploadConcurrency: value })).toThrow();
|
||||
},
|
||||
);
|
||||
|
||||
it('reports an invalid persisted concurrency instead of silently ignoring it', () => {
|
||||
fs.mkdirSync(path.join(tempDir, 'config'), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(tempDir, 'config', 'snowluma.json'),
|
||||
JSON.stringify({ videoUploadConcurrency: 99 }),
|
||||
);
|
||||
expect(() => loadGlobalSettings()).toThrow(/videoUploadConcurrency/);
|
||||
});
|
||||
|
||||
describe('migrateGlobalSettings (musicSignUrl copy-up)', () => {
|
||||
function writeOnebot(file: string, body: unknown) {
|
||||
const dir = path.join(tempDir, 'config');
|
||||
@@ -167,6 +206,10 @@ describe('global-config (config/snowluma.json)', () => {
|
||||
it('falls back to defaults when the file is corrupt', () => {
|
||||
fs.mkdirSync(path.join(tempDir, 'config'), { recursive: true });
|
||||
fs.writeFileSync(path.join(tempDir, 'config', 'snowluma.json'), '{ not json', 'utf8');
|
||||
expect(loadGlobalSettings()).toEqual({ rkey: { fallbackServers: [] }, musicSignUrl: '' });
|
||||
expect(loadGlobalSettings()).toEqual({
|
||||
rkey: { fallbackServers: [] },
|
||||
musicSignUrl: '',
|
||||
videoUploadConcurrency: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,8 @@
|
||||
import * as globalConfig from '../src/global-config';
|
||||
import {
|
||||
getVideoUploadConcurrency,
|
||||
setVideoUploadConcurrency,
|
||||
} from '@snowluma/protocol/highway/upload-settings';
|
||||
import { currentRequestId, runWithRequestId } from '@snowluma/common/logger';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { OneBotManager } from '../src/manager';
|
||||
@@ -13,6 +18,27 @@ function config(trigger: string): OneBotConfig {
|
||||
}
|
||||
|
||||
describe('OneBotManager config apply value ownership', () => {
|
||||
it('applies video concurrency at startup and reloads it even with no active accounts', () => {
|
||||
const load = vi.spyOn(globalConfig, 'loadGlobalSettings').mockReturnValue({
|
||||
...globalConfig.defaultGlobalSettings(),
|
||||
videoUploadConcurrency: 3,
|
||||
});
|
||||
|
||||
try {
|
||||
const manager = new OneBotManager();
|
||||
expect(getVideoUploadConcurrency()).toBe(3);
|
||||
load.mockReturnValue({
|
||||
...globalConfig.defaultGlobalSettings(),
|
||||
videoUploadConcurrency: 2,
|
||||
});
|
||||
manager.reloadGlobalSettings();
|
||||
expect(getVideoUploadConcurrency()).toBe(2);
|
||||
} finally {
|
||||
load.mockRestore();
|
||||
setVideoUploadConcurrency(1);
|
||||
}
|
||||
});
|
||||
|
||||
it('passes each concurrent caller exact config value to the instance', async () => {
|
||||
const manager = new OneBotManager();
|
||||
const seen: OneBotConfig[] = [];
|
||||
|
||||
Reference in new issue
Block a user