refactor(channels): integrate channel runtime status management and enhance account status handling (#547)

This commit is contained in:
Haze
2026-03-17 11:29:17 +08:00
committed by GitHub
Unverified
parent 43fe7a4d1c
commit d4367d3265
10 changed files with 713 additions and 61 deletions

View File

@@ -0,0 +1,66 @@
import { describe, expect, it } from 'vitest';
import {
computeChannelRuntimeStatus,
pickChannelRuntimeStatus,
} from '@/lib/channel-status';
describe('channel runtime status helpers', () => {
it('treats healthy running channels as connected', () => {
expect(
computeChannelRuntimeStatus({
running: true,
connected: false,
linked: false,
}),
).toBe('connected');
});
it('treats successful probes as connected for forward compatibility', () => {
expect(
computeChannelRuntimeStatus({
probe: { ok: true },
running: false,
}),
).toBe('connected');
});
it('returns error when runtime reports a lastError', () => {
expect(
computeChannelRuntimeStatus({
running: true,
lastError: 'bot token invalid',
}),
).toBe('error');
});
it('returns disconnected for empty runtime state', () => {
expect(computeChannelRuntimeStatus({})).toBe('disconnected');
});
it('keeps connected status when another account has an error', () => {
expect(
pickChannelRuntimeStatus([
{ connected: true },
{ lastError: 'boom' },
]),
).toBe('connected');
});
it('treats multi-account healthy running channels as connected', () => {
expect(
pickChannelRuntimeStatus([
{ running: true, connected: false },
{ running: true, connected: false },
]),
).toBe('connected');
});
it('uses summary-level errors when no account is connected', () => {
expect(
pickChannelRuntimeStatus(
[{ accountId: 'default', connected: false, running: false }],
{ error: 'channel bootstrap failed' },
),
).toBe('error');
});
});