···6363 end
64646565 describe "GET /xrpc/dev.atvouch.graph.getCurrentUserVouches" do
6666- test "returns vouches created by the authenticated user" do
6666+ test "returns vouches created by the authenticated user, newest first" do
6767 conn =
6868 conn(:get, "/xrpc/dev.atvouch.graph.getCurrentUserVouches")
6969 |> put_req_header("authorization", "Bearer valid-token:did:plc:alice")
···7474 assert is_list(body["vouches"])
7575 assert length(body["vouches"]) == 2
76767777+ # Should be ordered by original_created_at DESC (newest first)
7878+ # Carol vouch is 2026-03-02, Bob vouch is 2026-03-01
7779 uris = Enum.map(body["vouches"], & &1["uri"])
7878- assert "at://did:plc:alice/dev.atvouch.graph.vouch/did:plc:bob" in uris
7979- assert "at://did:plc:alice/dev.atvouch.graph.vouch/did:plc:carol" in uris
8080+ assert uris == [
8181+ "at://did:plc:alice/dev.atvouch.graph.vouch/did:plc:carol",
8282+ "at://did:plc:alice/dev.atvouch.graph.vouch/did:plc:bob"
8383+ ]
80848185 vouch = Enum.find(body["vouches"], &(&1["uri"] =~ "did:plc:bob"))
8286 assert vouch["creatorDid"] == "did:plc:alice"
···340344 })
341345342346 # Alice now has 3 remote vouches, fetch with limit=2
347347+ # Ordered by original_created_at DESC: eve (03-06), carol (03-05), bob (03-03)
343348 conn1 =
344349 conn(:get, "/xrpc/dev.atvouch.graph.getRemoteVouches?limit=2")
345350 |> put_req_header("authorization", "Bearer valid-token:did:plc:alice")
···350355 cursor = body1["cursor"]
351356 assert cursor
352357358358+ # First page should have the two newest
359359+ uris1 = Enum.map(body1["vouches"], & &1["uri"])
360360+ assert uris1 == [
361361+ "at://did:plc:eve/dev.atvouch.graph.vouch/did:plc:alice",
362362+ "at://did:plc:carol/dev.atvouch.graph.vouch/did:plc:alice"
363363+ ]
364364+353365 conn2 =
354366 conn(:get, "/xrpc/dev.atvouch.graph.getRemoteVouches?limit=2&cursor=#{cursor}")
355367 |> put_req_header("authorization", "Bearer valid-token:did:plc:alice")
···359371 assert length(body2["vouches"]) == 1
360372 refute body2["cursor"]
361373362362- uris1 = Enum.map(body1["vouches"], & &1["uri"])
374374+ # Last page should have the oldest
363375 uris2 = Enum.map(body2["vouches"], & &1["uri"])
364364- assert MapSet.disjoint?(MapSet.new(uris1), MapSet.new(uris2))
376376+ assert uris2 == ["at://did:plc:bob/dev.atvouch.graph.vouch/did:plc:alice"]
365377 end
366378367379 test "no cursor when all results fit in one page" do
···404416 end
405417406418 describe "GET /xrpc/dev.atvouch.graph.getEntireGraph" do
407407- test "returns all vouches with default limit" do
419419+ test "returns all vouches with default limit, newest first" do
408420 conn =
409421 conn(:get, "/xrpc/dev.atvouch.graph.getEntireGraph")
410422 |> Atvouch.Router.call(@opts)
···413425 body = Jason.decode!(conn.resp_body)
414426 assert length(body["vouches"]) == 3
415427 refute body["cursor"]
428428+429429+ # Should be ordered by original_created_at DESC (newest first)
430430+ # Bob→Alice is 2026-03-03, Alice→Carol is 2026-03-02, Alice→Bob is 2026-03-01
431431+ uris = Enum.map(body["vouches"], & &1["uri"])
432432+ assert uris == [
433433+ "at://did:plc:bob/dev.atvouch.graph.vouch/did:plc:alice",
434434+ "at://did:plc:alice/dev.atvouch.graph.vouch/did:plc:carol",
435435+ "at://did:plc:alice/dev.atvouch.graph.vouch/did:plc:bob"
436436+ ]
416437 end
417438418439 test "returns total count of vouches" do