# activitypub-testing + FEP-9091

&horbar;[bengo][]

## Context

`activitypub-testing` can run tests for Fediverse Enhancement Proposals. Let's use FEP-9091 as an example:

[FEP-9091: Export Actor Service Endpoint](https://codeberg.org/fediverse/fep/pulls/353/files#diff-942d7a7cc9d98c31bc5cd383d2f252c0f05cc1c8) is a **FEP Specification**.

There is a **FEP Test Implementation** FEP-9091 in JavaScript and published [activitypub-testing-fep-9091](https://codeberg.org/bengo/fep/pulls/2). The repo also makes the test's JavaScript file [available over HTTP](https://codeberg.org/socialweb.coop/activitypub-testing-fep-9091/raw/branch/main/fep-9091-actor-must-have-valid-export-service-endpoint.js).

`activitypub-testing run test --url <fep-url>` performs **Test Run**s for the FEP-9091 Test Implementation.

## Running the FEP-9091 Test on an Actor as JSON

To run a custom test module, use `activitypub-testing run test` with the `--url` flag set to the URL of the module.
`activitypub-testing` will fetch the URL, load the test, and then apply the test to the input built from the other CLI flags.

```shell
activitypub-testing run test \
--url=https://codeberg.org/socialweb.coop/activitypub-testing-fep-9091/raw/branch/main/fep-9091-actor-must-have-valid-export-service-endpoint.js \
--input.actor="$(cat <<EOF
{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://www.w3.org/ns/did/v1"
  ],
  "id": "https://alice-personal-site.example/actor",
  "type": "Person",
  "name": "Alice",
  "service": [{
    "id": "https://alice-personal-site.example/actor#export",
    "type": "https://w3id.org/fep/9091#Export",
    "serviceEndpoint": "https://alice-personal-site.example/actor/accountExport"
  }]
}
EOF
)"
```

<details>
  <summary>show output</summary>
  <pre>
{
  "type": [
    "Assertion"
  ],
  "result": {
    "outcome": "passed"
  },
  "test": {
    "slug": "fep-9091-actor-must-have-valid-export-service-endpoint",
    "name": "Actor must have a valid export service endpoint",
    "id": "urn:uuid:94113b63-3de7-4924-8fcb-90b61133d3aa",
    "requirementReference": []
  },
  "input": {
    "actor": "{\n  \"@context\": [\n    \"https://www.w3.org/ns/activitystreams\",\n    \"https://www.w3.org/ns/did/v1\"\n  ],\n  \"id\": \"https://alice-personal-site.example/actor\",\n  \"type\": \"Person\",\n  \"name\": \"Alice\",\n  \"service\": [{\n    \"id\": \"https://alice-personal-site.example/actor#export\",\n    \"type\": \"https://w3id.org/fep/9091#Export\",\n    \"serviceEndpoint\": \"https://alice-personal-site.example/actor/accountExport\"\n  }]\n}"
  },
  "@context": [
    "https://socialweb.coop/ns/testing/context.json",
    "https://www.w3.org/ns/activitystreams"
  ]
}
</pre>
</details>

## Running the FEP-9091 Test on an Actor fetched via curl

Use `activitypub-testing run test` with the `--url` flag set to the URL to the custom test module. `activitypub-testing` will fetch the URL, load the test, and then apply the test to the input built from the other CLI flags. The test accepts an `--input.module` argument that expects an ECMAScript Module. We can use `curl` in a [shell command substitution](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_03) to get the URL as JavaScript and substitute that value as `--input.module`.

### testinging known implementations

```shell
fetchAsObject() {
  curl --silent -H 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"' "$1"
}

testFep9091ActorUrl() {
    activitypub-testing run test \
      --url=https://codeberg.org/socialweb.coop/activitypub-testing-fep-9091/raw/branch/main/fep-9091-actor-must-have-valid-export-service-endpoint.js \
      --input.actor="$(fetchAsObject "$1")"
}

testFep9091ActorUrl https://socialweb.coop
```

<!-- links for markdown above -->

[bengo]: https://bengo.is
