Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: add subscriptions:sync and garden:seeds:report handle_in tests

Test subscriptions:sync creating new subscriptions and removing ones
not in the sync list (with DB verification). Test garden:seeds:report
recording seed generations and handling empty profiles.

SOW-73

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+84
+84
apps/sower/test/sower_web/channels/garden_channel_handle_in_test.exs
··· 354 354 assert_reply ref, :error, :deployment_not_found 355 355 end 356 356 end 357 + 358 + describe "subscriptions:sync" do 359 + test "creates new subscriptions and returns them" do 360 + %{socket: socket} = connect_and_join_garden() 361 + 362 + ref = 363 + push(socket, "subscriptions:sync", %{ 364 + "subscriptions" => [ 365 + %{"seed_name" => "sync-host-1", "seed_type" => "nixos"}, 366 + %{"seed_name" => "sync-host-2", "seed_type" => "nixos"} 367 + ] 368 + }) 369 + 370 + assert_reply ref, :ok, %{subscriptions: subscriptions} 371 + assert length(subscriptions) == 2 372 + 373 + names = Enum.map(subscriptions, & &1.seed_name) |> Enum.sort() 374 + assert names == ["sync-host-1", "sync-host-2"] 375 + end 376 + 377 + test "removes subscriptions not in the sync list" do 378 + %{socket: socket, garden: garden} = connect_and_join_garden() 379 + 380 + subscription_fixture(%{ 381 + garden_id: garden.id, 382 + seed_name: "to-remove", 383 + seed_type: "nixos" 384 + }) 385 + 386 + ref = 387 + push(socket, "subscriptions:sync", %{ 388 + "subscriptions" => [ 389 + %{"seed_name" => "to-keep", "seed_type" => "nixos"} 390 + ] 391 + }) 392 + 393 + assert_reply ref, :ok, %{subscriptions: subscriptions} 394 + assert length(subscriptions) == 1 395 + assert hd(subscriptions).seed_name == "to-keep" 396 + 397 + remaining = Sower.Orchestration.list_subscriptions_for_garden(garden) 398 + assert length(remaining) == 1 399 + assert hd(remaining).seed_name == "to-keep" 400 + end 401 + end 402 + 403 + describe "garden:seeds:report" do 404 + test "records garden seed generations" do 405 + %{socket: socket} = connect_and_join_garden() 406 + 407 + seed = seed_fixture(%{name: "report-seed", seed_type: "nixos"}) 408 + 409 + ref = 410 + push(socket, "garden:seeds:report", %{ 411 + "profiles" => [ 412 + %{ 413 + "profile_path" => "/nix/var/nix/profiles/system", 414 + "generations" => [ 415 + %{ 416 + "path" => seed.artifact, 417 + "link" => "/nix/var/nix/profiles/system-1-link", 418 + "created" => DateTime.utc_now() |> DateTime.to_iso8601(), 419 + "generation_number" => 1, 420 + "is_current" => true 421 + } 422 + ] 423 + } 424 + ] 425 + }) 426 + 427 + assert_reply ref, :ok, :ok 428 + end 429 + 430 + test "handles empty profiles list" do 431 + %{socket: socket} = connect_and_join_garden() 432 + 433 + ref = 434 + push(socket, "garden:seeds:report", %{ 435 + "profiles" => [] 436 + }) 437 + 438 + assert_reply ref, :ok, :ok 439 + end 440 + end 357 441 end