; Follow-up — feed/home capstone pipeline. (feed-test name got expected)

; alice follows star and bob (edges: follower followee)
(define
  G
  (feed/follow-graph (list (list "alice" "star") (list "alice" "bob"))))

; star posts s1 then s2; bob posts b1; star re-posts s1 (cross-post dup);
; zoe posts z1 (alice does NOT follow zoe)
(define
  S
  (feed/stream
    (list
      (feed/activity "star" "post" "s1" 10 (list))
      (feed/activity "star" "post" "s2" 20 (list))
      (feed/activity "bob" "post" "b1" 15 (list))
      (feed/activity "star" "post" "s1" 5 (list))
      (feed/activity "zoe" "post" "z1" 30 (list)))))

(define rec (feed/recency 100 10))

(feed-test
  "home count (deduped, followed only)"
  (feed/count (feed/home S G "alice" feed/permit-public? rec 10))
  3)

(feed-test
  "home order by recency"
  (map
    (fn (a) (get a :object))
    (feed/items (feed/home S G "alice" feed/permit-public? rec 10)))
  (list "s2" "b1" "s1"))

(feed-test
  "home excludes unfollowed zoe"
  (feed/-elem?
    "z1"
    (map
      (fn (a) (get a :object))
      (feed/items (feed/home S G "alice" feed/permit-public? rec 10))))
  false)

(feed-test
  "home top-2"
  (map
    (fn (a) (get a :object))
    (feed/items (feed/home S G "alice" feed/permit-public? rec 2)))
  (list "s2" "b1"))

(feed-test
  "home dedupes cross-post (one s1)"
  (len
    (filter
      (fn (o) (equal? o "s1"))
      (map
        (fn (a) (get a :object))
        (feed/items
          (feed/home S G "alice" feed/permit-public? rec 10)))))
  1)

; ACL applied per-viewer in the home pipeline
(define
  Sacl
  (feed/stream
    (list (feed/normalize {:actor "star" :object "pub" :at 20}) (feed/normalize {:actor "star" :object "sec" :visible-to (list "carol") :at 25}))))
(define Gacl (feed/follow-graph (list (list "alice" "star"))))

(feed-test
  "home hides activity alice not permitted"
  (map
    (fn (a) (get a :object))
    (feed/items (feed/home Sacl Gacl "alice" feed/permit-acl? rec 10)))
  (list "pub"))
