kind of like tap but different and in rust
0
fork

Configure Feed

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

at main 112 lines 3.7 kB view raw
1#!/usr/bin/env nu 2use common.nu * 3 4def main [] { 5 let env_vars = load-env-file 6 let did = ($env_vars | get --optional TEST_REPO) 7 let password = ($env_vars | get --optional TEST_PASSWORD) 8 9 if ($did | is-empty) or ($password | is-empty) { 10 print "error: TEST_REPO and TEST_PASSWORD must be set in .env" 11 exit 1 12 } 13 14 let port = 3007 15 let url = $"http://localhost:($port)" 16 let db_path = (mktemp -d -t hydrant_signal_test.XXXXXX) 17 let collection = "app.bsky.feed.post" 18 19 print $"database path: ($db_path)" 20 21 let pds_url = resolve-pds $did 22 print $"resolved pds: ($pds_url)" 23 24 let session = authenticate $pds_url $did $password 25 let jwt = $session.accessJwt 26 print "authenticated" 27 28 let binary = build-hydrant 29 let instance = start-hydrant $binary $db_path $port 30 31 mut test_passed = false 32 33 if (wait-for-api $url) { 34 # configure signal mode: index app.bsky.feed.post from anyone on the network 35 print "configuring signal mode..." 36 http patch -t application/json $"($url)/filter" { 37 mode: "signal", 38 signals: [$collection] 39 } 40 41 # verify filter state 42 let filter = (http get $"($url)/filter") 43 print $"filter state: ($filter | to json)" 44 45 if $filter.mode != "signal" { 46 print "FAILED: mode was not set to signal" 47 } else if not ($filter.signals | any { |s| $s == $collection }) { 48 print $"FAILED: ($collection) not in signals" 49 } else { 50 print "filter configured correctly" 51 52 # wait a moment for the firehose to connect and the filter to take effect 53 sleep 3sec 54 55 let timestamp = (date now | format date "%Y-%m-%dT%H:%M:%SZ") 56 let record_data = { 57 "$type": $collection, 58 text: $"hydrant signal filter test ($timestamp)", 59 createdAt: $timestamp 60 } 61 62 print "creating post..." 63 let create_res = (http post -t application/json -H ["Authorization" $"Bearer ($jwt)"] $"($pds_url)/xrpc/com.atproto.repo.createRecord" { 64 repo: $did, 65 collection: $collection, 66 record: $record_data 67 }) 68 let rkey = ($create_res.uri | split row "/" | last) 69 print $"created: ($create_res.uri)" 70 71 # give hydrant time to receive and process the firehose event 72 sleep 5sec 73 74 # verify the record was indexed 75 print "checking indexed record..." 76 let result = (try { 77 http get $"($url)/xrpc/com.atproto.repo.getRecord?repo=($did)&collection=($collection)&rkey=($rkey)" 78 } catch { 79 null 80 }) 81 82 if ($result | is-empty) { 83 print "FAILED: record not found in hydrant index" 84 } else { 85 print $"indexed record cid: ($result.cid)" 86 print "test PASSED: signal filter correctly indexed the post" 87 $test_passed = true 88 } 89 90 # cleanup: delete the test post 91 print "cleaning up test post..." 92 try { 93 http post -t application/json -H ["Authorization" $"Bearer ($jwt)"] $"($pds_url)/xrpc/com.atproto.repo.deleteRecord" { 94 repo: $did, 95 collection: $collection, 96 rkey: $rkey 97 } 98 } 99 } 100 } else { 101 print "hydrant failed to start" 102 } 103 104 print "stopping hydrant..." 105 try { kill -9 $instance.pid } 106 107 if $test_passed { 108 exit 0 109 } else { 110 exit 1 111 } 112}