feat(api): absorb the Hub control plane into the local instance model

Add central notification channels, rules, queue and delivery logs, fleet
organization groups and tags, device discovery, the device action catalog,
instance module reads, the log centre, connection settings and system
maintenance as native /api/v1 routes backed by the existing secret store,
audit trail and pinned upstream transport.
This commit is contained in:
chick
2026-09-05 18:53:04 +08:00
parent f11877f13e
commit f9186bd851
97 changed files with 18646 additions and 104 deletions
@@ -1,6 +1,12 @@
import { describe, expect, it } from 'vitest';
import { nextOccurrence, previewCron, reconcileOccurrence } from './schedule-time.js';
import {
nextOccurrence,
nextOccurrenceFor,
previewCron,
previewTrigger,
reconcileOccurrence,
} from './schedule-time.js';
describe('schedule time', () => {
it('calculates future occurrences in Beijing time across the UTC day boundary', () => {
@@ -44,4 +50,69 @@ describe('schedule time', () => {
nextDueAt: '2026-07-30T01:30:00.000Z',
});
});
it('expands Hub fixed schedules over the Beijing weekday and time grid', () => {
const weekdays = { kind: 'fixed' as const, weekdays: [4, 5], times: ['09:00', '21:30'] };
// 2026-07-30 is a Thursday; 01:25Z is 09:25 in Beijing, so the same-day 21:30 slot is next.
expect(previewTrigger(weekdays, 2, new Date('2026-07-30T01:25:00.000Z'))).toEqual([
'2026-07-30T13:30:00.000Z',
'2026-07-31T01:00:00.000Z',
]);
expect(
nextOccurrenceFor(
{ kind: 'fixed', weekdays: [6], times: ['00:30'] },
new Date('2026-07-30T01:25:00.000Z'),
),
).toBe('2026-07-31T16:30:00.000Z');
});
it('keeps interval schedules anchored on the previous occurrence', () => {
const interval = { kind: 'interval' as const, value: 90, unit: 'mins' as const };
expect(nextOccurrenceFor(interval, new Date('2026-07-30T01:00:00.000Z'))).toBe(
'2026-07-30T02:30:00.000Z',
);
expect(
nextOccurrenceFor(
interval,
new Date('2026-07-30T05:00:00.000Z'),
new Date('2026-07-30T01:00:00.000Z'),
),
).toBe('2026-07-30T05:30:00.000Z');
expect(previewTrigger(interval, 3, new Date('2026-07-30T01:00:00.000Z'))).toEqual([
'2026-07-30T02:30:00.000Z',
'2026-07-30T04:00:00.000Z',
'2026-07-30T05:30:00.000Z',
]);
});
it('reconciles fixed and interval misfires against the stored due time', () => {
expect(
reconcileOccurrence(
{
trigger: { kind: 'interval', value: 90, unit: 'mins' },
nextDueAt: '2026-07-30T04:00:00.000Z',
misfirePolicy: 'catch-up-once',
},
new Date('2026-07-30T05:00:00.000Z'),
),
).toEqual({
action: 'run',
dueAt: '2026-07-30T04:00:00.000Z',
nextDueAt: '2026-07-30T05:30:00.000Z',
});
expect(
reconcileOccurrence(
{
trigger: { kind: 'fixed', weekdays: [4, 5], times: ['09:00', '21:30'] },
nextDueAt: '2026-07-30T01:00:00.000Z',
misfirePolicy: 'skip',
},
new Date('2026-07-30T01:25:00.000Z'),
),
).toEqual({
action: 'skip',
dueAt: '2026-07-30T01:00:00.000Z',
nextDueAt: '2026-07-30T13:30:00.000Z',
});
});
});