feat(api): add fleet snapshots and durable event stream

This commit is contained in:
chick
2026-07-17 14:16:46 +08:00
parent 1cc4a995ee
commit b4ae28c8f0
12 changed files with 1777 additions and 1 deletions
+57
View File
@@ -23,6 +23,63 @@ class Store implements SecretStore {
}
}
describe('buildControlPlaneApp', () => {
it('registers the durable event route fail-closed when no authentication dependency is supplied', async () => {
const db = new Database(':memory:');
db.pragma('foreign_keys=ON');
migrateDatabase(db);
dbs.push(db);
const app = buildControlPlaneApp({
db,
store: new Store(),
upstream: {
get: async () => ({ status: 200, headers: {}, body: '' }),
request: async () => ({ status: 200, headers: {}, body: '' }),
postNetworkRegisterAuto: async () => ({ status: 200 }),
},
});
const response = await app.inject({ method: 'GET', url: '/api/v1/events' });
expect(response.statusCode).toBe(401);
expect(response.headers['content-type']).toContain('application/problem+json');
expect(response.json()).toMatchObject({ status: 401, code: 'UNAUTHORIZED' });
await app.close();
});
it('passes an explicit event-stream authenticator to durable cursor replay', async () => {
const db = new Database(':memory:');
db.pragma('foreign_keys=ON');
migrateDatabase(db);
dbs.push(db);
const app = buildControlPlaneApp({
db,
store: new Store(),
upstream: {
get: async () => ({ status: 200, headers: {}, body: '' }),
request: async () => ({ status: 200, headers: {}, body: '' }),
postNetworkRegisterAuto: async () => ({ status: 200 }),
},
authenticateEventStream: (request) => request.headers.authorization === 'Bearer allowed',
});
const response = await app.inject({
method: 'GET',
url: '/api/v1/events',
headers: {
authorization: 'Bearer allowed',
'last-event-id': 'unknown-cursor',
},
});
expect(response.statusCode).toBe(409);
expect(response.headers['content-type']).toContain('application/problem+json');
expect(response.json()).toMatchObject({
status: 409,
code: 'EVENT_POSITION_UNAVAILABLE',
});
await app.close();
});
it('assembles instance CRUD, connection checks, login and logout without listening or reading external config', async () => {
const db = new Database(':memory:');
db.pragma('foreign_keys=ON');