feat(manager): manage ontology assets and infrastructure
This commit is contained in:
@@ -60,6 +60,36 @@ test("Device Core client accepts only canonical commands and entity refs", async
|
||||
);
|
||||
});
|
||||
|
||||
test("Device Core client merges workspace and ontology projections", async () => {
|
||||
const calls = [];
|
||||
const client = createDeviceCoreClient({
|
||||
baseUrl: "http://127.0.0.1:3210",
|
||||
token,
|
||||
fetchImpl: async (url) => {
|
||||
calls.push(String(url));
|
||||
if (String(url).endsWith("/ontology")) {
|
||||
return jsonResponse(200, {
|
||||
ok: true,
|
||||
projection: {
|
||||
ontology: { catalogHash: "229c61c02a790906", packages: [] },
|
||||
assets: [], assetBindings: [], hosts: [], endpoints: [],
|
||||
deployments: [], serviceInstances: [], policies: {},
|
||||
},
|
||||
});
|
||||
}
|
||||
return jsonResponse(200, { ok: true, workspace: { project: { projectRef: "project:test" } } });
|
||||
},
|
||||
});
|
||||
const workspace = await client.getWorkspace(
|
||||
actor,
|
||||
"project:11111111-1111-4111-8111-111111111111",
|
||||
);
|
||||
assert.equal(workspace.ontology.ontology.catalogHash, "229c61c02a790906");
|
||||
assert.equal(calls.length, 2);
|
||||
assert.ok(calls.some((value) => value.endsWith("/workspace")));
|
||||
assert.ok(calls.some((value) => value.endsWith("/ontology")));
|
||||
});
|
||||
|
||||
test("local preview is empty and creates resources only through canonical commands", async () => {
|
||||
const client = createLocalPreviewDeviceCore();
|
||||
assert.deepEqual(await client.listProjects(actor), []);
|
||||
@@ -81,6 +111,47 @@ test("local preview is empty and creates resources only through canonical comman
|
||||
assert.equal(created.result.created, true);
|
||||
const projectRef = created.result.project.projectRef;
|
||||
|
||||
const host = await client.execute("infrastructure-hosts:ensure", actor, {
|
||||
projectRef,
|
||||
hostKey: "preview-vps",
|
||||
displayName: "Preview VPS",
|
||||
providerRef: "provider:preview",
|
||||
externalRef: "provider-resource:preview-vps",
|
||||
managementCredentialRef: "secret-ref:device-core/preview-vps",
|
||||
lifecycleState: "active",
|
||||
});
|
||||
const deployment = await client.execute("infrastructure-deployments:ensure", actor, {
|
||||
projectRef,
|
||||
hostRef: host.result.host.hostRef,
|
||||
deploymentKey: "preview-edge",
|
||||
displayName: "Preview Edge deployment",
|
||||
artifactRef: "artifact:device-edge/1.0.0",
|
||||
artifactDigest: `sha256:${"c".repeat(64)}`,
|
||||
lifecycleState: "active",
|
||||
});
|
||||
await client.execute("infrastructure-service-instances:ensure", actor, {
|
||||
projectRef,
|
||||
hostRef: host.result.host.hostRef,
|
||||
deploymentRef: deployment.result.deployment.deploymentRef,
|
||||
edgeRef: null,
|
||||
serviceKey: "device-edge",
|
||||
displayName: "Device Edge",
|
||||
serviceRole: "device.edge",
|
||||
lifecycleState: "active",
|
||||
});
|
||||
await client.execute("health-observations:record", actor, {
|
||||
projectRef,
|
||||
subjectKind: "host",
|
||||
subjectRef: host.result.host.hostRef,
|
||||
observedState: "reachable",
|
||||
evidenceClass: "manual",
|
||||
sourceRef: "test:preview",
|
||||
schemaRef: "nodedc.health.test.v1",
|
||||
evidence: {},
|
||||
observedAt: new Date().toISOString(),
|
||||
expiresAt: new Date(Date.now() + 60_000).toISOString(),
|
||||
});
|
||||
|
||||
await client.execute("collections:ensure", actor, {
|
||||
projectRef,
|
||||
collectionKey: "field-devices",
|
||||
@@ -217,6 +288,10 @@ test("local preview is empty and creates resources only through canonical comman
|
||||
assert.equal(workspace.grants.length, 2);
|
||||
assert.ok(workspace.auditEvents.some((event) => event.eventType === "device_binding.created"));
|
||||
assert.equal(workspace.policies.commandTransport, "disabled");
|
||||
assert.equal(workspace.ontology.hosts[0].health.state, "reachable");
|
||||
assert.equal(workspace.ontology.serviceInstances[0].serviceRole, "device.edge");
|
||||
assert.equal(workspace.ontology.hosts[0].managementCredentialConfigured, true);
|
||||
assert.equal(JSON.stringify(workspace).includes("secret-ref:device-core/preview-vps"), false);
|
||||
assert.deepEqual(workspace.devices, []);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user