feat(device-manager): align functional UI with Mission Core interaction patterns
Device Core qualification / qualify (push) Successful in 8m53s

This commit is contained in:
DCCONSTRUCTIONS
2026-09-30 20:53:19 +03:00
parent 7072b86fb8
commit b8d240a0a0
12 changed files with 309 additions and 337 deletions
@@ -24,7 +24,7 @@ function repository({ role = 'owner', links = [], otherOwner = ownerId } = {}) {
const db = { release() {}, async query(sql, values) {
if (['begin', 'commit', 'rollback'].includes(sql)) return { rows: [] };
if (sql.includes('from device_projects')) return { rows: [{ id: values[0], owner_scope_id: values[0] === projectId ? ownerId : otherOwner,
lifecycle_state: 'active', owner_lifecycle_state: 'active', scope_kind: 'company', owner_ref: 'company:example' }] };
name: 'Test project', lifecycle_state: 'active', owner_lifecycle_state: 'active', scope_kind: 'company', owner_ref: 'company:example' }] };
if (sql.includes('from device_project_grants')) return { rows: [{ id: 'grant', principal_kind: 'user', principal_ref: actor.userRef,
project_role: role, capability_allow: [], capability_deny: [], lifecycle_state: 'active' }] };
if (sql.includes('from device_infrastructure_hosts')) return { rows: [{ id: hostId }] };
@@ -195,3 +195,42 @@ test('unreachable or mismatched host is reported as unavailable, not an empty he
assert.deepEqual(result.items, []); assert.equal(JSON.stringify(result).includes('private-details'), false);
}
});
test('project connection generates stable contour identity and links it without user codes', async () => {
const repo = repository(); const calls = []; const contour = 'c'.repeat(32);
const service = new B2Infrastructure({ pool: repo.pool, secrets: { read: async () => pkg }, clientFactory: () => ({ async call(path, body) {
calls.push({ path, body });
return path === '/v2/management/contours' ? { id: contour } : { items: [{ id: contour }] };
} }) });
const result = await service.execute(actor, { action: 'project-connect', projectRef: `project:${projectId}`, hostRef: `host:${hostId}`, targetProjectRef: `project:${projectId}` }, 'a'.repeat(32));
assert.equal(result.linked, true);
assert.equal(calls[0].body.key, 'dc-' + projectId);
assert.equal(calls[0].body.name, 'Test project');
assert.equal(repo.writes.filter((x) => x.sql.includes('device_b2_contour_links')).length, 1);
});
test('connecting an already linked project does not create another contour', async () => {
const contour = 'c'.repeat(32); const repo = repository({ links: [{ contour_id: contour, project_id: projectId }] });
const service = new B2Infrastructure({ pool: repo.pool, secrets: { read: async () => pkg }, clientFactory: () => ({ async call(path) {
assert.equal(path, '/v2/contours'); return { items: [{ id: contour }] };
} }) });
const result = await service.execute(actor, { action: 'project-connect', projectRef: `project:${projectId}`, hostRef: `host:${hostId}` }, 'a'.repeat(32));
assert.equal(result.contourId, contour);
});
test('application creation and issuance use one server-generated request identity', async () => {
const contour = 'c'.repeat(32); const repo = repository({ links: [{ contour_id: contour, project_id: projectId }] });
const calls = []; const requestId = 'd'.repeat(32); const app = 'e'.repeat(32);
const service = new B2Infrastructure({ pool: repo.pool, secrets: { read: async () => pkg }, clientFactory: () => ({ async call(path, body) {
calls.push({ path, body }); return path.endsWith('applications') ? { id: app } : { synthetic: true };
} }) });
const result = await service.execute(actor, { action: 'application-connect', projectRef: `project:${projectId}`, hostRef: `host:${hostId}`, name: 'Partner', contourId: contour }, requestId);
assert.equal(calls[0].body.key, 'app-' + requestId);
assert.equal(calls[1].body.request_id, requestId);
assert.equal(result.id, app);
assert.ok(result.connection);
assert.equal(JSON.stringify(repo.writes).includes('synthetic'), false);
await assert.rejects(service.execute(actor, { action: 'application-connect', projectRef: `project:${projectId}`, hostRef: `host:${hostId}`, name: 'Other', contourId: 'f'.repeat(32) }, requestId), /b2_access_denied/);
assert.equal(calls.length, 2);
});