fix(camera): keep activated cameras offline until agent confirmation
Heimdall Gitea / Detect CI scope (pull_request) Successful in 24s
Heimdall Gitea / Build and tests (pull_request) Successful in 28m37s
Heimdall Gitea / Build and scan agent image (pull_request) Failing after 6m41s
Heimdall Gitea / Build and scan server image (pull_request) Failing after 9m20s
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Failing after 19m39s
Heimdall Gitea / Publish versioned installer release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 3s

This commit is contained in:
arnaud.dartois committed 2026-11-11 21:10:40 +01:00
1 parent fcc719d627
commit ff64e61617
8 files changed
+76 -11

No files matched your search

@@ -67,11 +67,54 @@ public class CamerasControllerTests : PostgresTestBase
var cameraId = cameraContent.GetProperty("id").GetGuid();
cameraContent.GetProperty("status").GetString().ShouldBe("Disabled");
// Toggle → Online
// Activation is enabled but has no connectivity evidence yet.
var toggleResponse = await client.PostAsync($"api/cameras/{cameraId}/toggle-status", null);
toggleResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var toggled = await toggleResponse.Content.ReadFromJsonAsync<JsonElement>();
toggled.GetProperty("status").GetString().ShouldBe("Online");
toggled.GetProperty("status").GetString().ShouldBe("Offline");
var cameraResponse = await client.GetAsync($"api/cameras/{cameraId}");
var camera = await cameraResponse.Content.ReadFromJsonAsync<JsonElement>();
camera.GetProperty("status").GetString().ShouldBe("Offline");
var tokenResponse = await client.PostAsync($"api/sites/{siteId}/tokens", null);
var siteToken = (await tokenResponse.Content.ReadFromJsonAsync<JsonElement>())
.GetProperty("token").GetString()!;
var registerResponse = await client.PostAsJsonAsync("api/agents/register", new
{
token = siteToken,
hostname = "camera-connectivity-agent",
version = "1.0.0-test"
});
var registration = await registerResponse.Content.ReadFromJsonAsync<JsonElement>();
var agentId = registration.GetProperty("agentId").GetGuid();
var apiKey = registration.GetProperty("apiKey").GetString()!;
var agentClient = Factory.CreateClient();
agentClient.DefaultRequestHeaders.Add("X-API-Key", apiKey);
var heartbeatResponse = await agentClient.PostAsJsonAsync(
$"api/agents/{agentId}/heartbeat", new { publicIp = "127.0.0.1" });
heartbeatResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var assignmentResponse = await client.PostAsJsonAsync("api/assignments", new
{
cameraId,
agentId,
reason = "integration test"
});
assignmentResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var reportResponse = await agentClient.PutAsJsonAsync(
$"api/agents/{agentId}/cameras/{cameraId}/status", new { status = "Online" });
reportResponse.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
var wrongAgentReport = await agentClient.PutAsJsonAsync(
$"api/agents/{Guid.NewGuid()}/cameras/{cameraId}/status", new { status = "Offline" });
wrongAgentReport.StatusCode.ShouldBe(System.Net.HttpStatusCode.Forbidden);
cameraResponse = await client.GetAsync($"api/cameras/{cameraId}");
camera = await cameraResponse.Content.ReadFromJsonAsync<JsonElement>();
camera.GetProperty("status").GetString().ShouldBe("Online");
// Toggle back → Disabled
var toggleBack = await client.PostAsync($"api/cameras/{cameraId}/toggle-status", null);