# activitypub-testing + FEP-0f2a

&horbar;[bengo][]

## Contents

* [Context](#context)
* [Running the FEP-0f2a Test on an Actor input as a JSON string](#running-the-fep-0f2a-test-on-an-actor-input-as-a-json-string)
* [Running the FEP-0f2a Test on an Actor fetched via curl](#running-the-fep-0f2a-test-on-an-actor-fetched-via-curl)
    * [testing actor `https://socialweb.coop`](#testing-actor-httpssocialwebcoop)
* [testing fedify.dev with activitypub-testing-fedify](#testing-fedifydev-with-activitypub-testing-fedify)

## Context

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

[FEP-0f2a: Announce Activity for Migrations and Tombstone Events](https://codeberg.org/fediverse/fep/pulls/351) is a **FEP Specification** by bumblefudge.com specifying how ActivityPub Actors can indicate that they have become a Tombstone and/or movedTo/copiedTo another location. @bumblefudge.com also included a **FEP Test Specification** for [a FEP-0f2a Test](https://codeberg.org/bumblefudge/fep/src/branch/feat/fep-0f2a-announce-activity-for-migrations-and-tombstone-events/fep/0f2a/fep-0f2a-test-case.md). This is a human-readable specification of a test procedure that verifies that a test subject implements the normative requirements specified by FEP-0f2a.

@bengo.is later created a **FEP Test Implementation** for the FEP-0f2a Test in JavaScript and published [activitypub-testing-fep-0f2a](https://codeberg.org/socialweb.coop/activitypub-testing-fep-0f2a/). The repo also makes the test's JavaScript file [available over HTTP](https://codeberg.org/socialweb.coop/activitypub-testing-fep-0f2a/raw/branch/main/fep-0f2a-actor-object-tombstone-syntax.js), and this URL is used later to instruct `activitypub-testing run test` to run a test from a remote URL.

`activitypub-testing` performs **Test Run**s for the FEP-0f2a Test Implementation.

## Running the FEP-0f2a Test on an Actor input as a JSON string

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.

```shell
activitypub-testing run test \
--url=https://codeberg.org/socialweb.coop/activitypub-testing-fep-0f2a/raw/branch/main/fep-0f2a-actor-object-tombstone-syntax.js \
--input.actor="$(cat <<EOF
{
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://w3id.org/fep/7628"
  ],
  "type": ["Person","Tombstone"],
  "inbox": "https://example.com/inbox",
  "outbox": "https://example.com/outbox"
}
EOF
)"
```

<details>
  <summary>show output</summary>
  <pre>
  {
    "type": [
      "Assertion"
    ],
    "result": {
      "outcome": "passed"
    },
    "test": {
      "slug": "fep-0f2a-actor-object-tombstone-syntax",
      "description": "This rule checks whether a given Actor Object has used valid `movedTo` or `copiedTo` values and exclusively.",
      "name": "Actor Object Tombstone Syntax",
      "id": "urn:uuid:73257c1a-70da-42df-9698-579940c7065a",
      "requirementReference": []
    },
    "input": {
      "actor": "{\n  \"@context\": [\n    \"https://www.w3.org/ns/activitystreams\",\n    \"https://w3id.org/fep/7628\"\n  ],\n  \"type\": [\"Person\",\"Tombstone\"],\n  \"inbox\": \"https://example.com/inbox\",\n  \"outbox\": \"https://example.com/outbox\"\n}"
    },
    "@context": [
      "https://socialweb.coop/ns/testing/context.json",
      "https://www.w3.org/ns/activitystreams"
    ]
  }
  </pre>
</details>

## Running the FEP-0f2a 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.actor` JSON string. 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 an ActivityPub JSON object and substitute that value as `--input.actor`.

### testing actor `https://socialweb.coop`

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

testFep0f2aActorUrl() {
    activitypub-testing run test \
      --url=https://codeberg.org/socialweb.coop/activitypub-testing-fep-0f2a/raw/branch/main/fep-0f2a-actor-object-tombstone-syntax.js \
      --input.actor="$(fetchActivityPubActor "$1")"
}

testFep0f2aActorUrl https://socialweb.coop
```

<details>
  <summary>show output</summary>
  <pre>
  {
    "type": [
      "Assertion"
    ],
    "result": {
      "outcome": "passed"
    },
    "test": {
      "slug": "fep-0f2a-actor-object-tombstone-syntax",
      "description": "This rule checks whether a given Actor Object has used valid `movedTo` or `copiedTo` values and exclusively.",
      "name": "Actor Object Tombstone Syntax",
      "id": "urn:uuid:73257c1a-70da-42df-9698-579940c7065a",
      "requirementReference": []
    },
    "input": {
      "actor": "{\n  \"type\": [\n    \"Organization\"\n  ],\n  \"inbox\": \"https://socialweb.coop/inbox\",\n  \"outbox\": \"https://socialweb.coop/outbox\",\n  \"followers\": {\n    \"type\": \"OrderedCollection\",\n    \"orderedItems\": []\n  },\n  \"following\": {\n    \"type\": \"OrderedCollection\",\n    \"orderedItems\": []\n  },\n  \"liked\": {\n    \"type\": \"OrderedCollection\",\n    \"orderedItems\": []\n  },\n  \"likes\": {\n    \"type\": \"OrderedCollection\",\n    \"orderedItems\": []\n  },\n  \"shares\": {\n    \"type\": \"OrderedCollection\",\n    \"orderedItems\": []\n  },\n  \"assertionMethod\": [\n    {\n      \"@context\": \"https://w3id.org/security/multikey/v1\",\n      \"id\": \"did:key:zUC7GbgfshTTmWM1V8uy26VKHT52z59519SDxkcg1hdNVSD8NvKPZFnM6R8tG38n2ySQ6zk5JBBQGjfRqy2oi7NgYcoF2LRaE2fHpLWnDvccE1dgfoTkUWAq1AzHZ7jowWC39Ya\",\n      \"type\": \"Multikey\",\n      \"controller\": \"https://socialweb.coop/\",\n      \"publicKeyMultibase\": \"zUC7GbgfshTTmWM1V8uy26VKHT52z59519SDxkcg1hdNVSD8NvKPZFnM6R8tG38n2ySQ6zk5JBBQGjfRqy2oi7NgYcoF2LRaE2fHpLWnDvccE1dgfoTkUWAq1AzHZ7jowWC39Ya\"\n    }\n  ],\n  \"id\": \"https://socialweb.coop/\",\n  \"@context\": [\n    \"https://www.w3.org/ns/activitystreams\",\n    \"https://w3id.org/fep/7628\"\n  ]\n}"
    },
    "@context": [
      "https://socialweb.coop/ns/testing/context.json",
      "https://www.w3.org/ns/activitystreams"
    ]
  }
  </pre>
</details>

## testing fedify.dev with activitypub-testing-fedify

[activitypub-testing-fedify](https://github.com/gobengo/activitypub-testing-fedify/) is a repository that tests an ActivityPub server powered by [fedify.dev](https://fedify.dev/) using activitypub-testing and activitypub-testing-fep-0f2a.

The CI job runs `bin/activitypub-testing`, [which invokes](https://github.com/gobengo/activitypub-testing-fedify/commit/96f2c54db6b2497160587d7eb78acc9a9ebd9bbe#diff-ef1a58bc763ca4be059e7680bc2b0d3da8afcd32f05368a0042125ee7a09ef4dR47) `activitypub-testing run test --url=<url-to-fep-0f2a-test>`.

GitHub Actions job logs [show that the test ran and the result outcome is `passed`](https://github.com/gobengo/activitypub-testing-fedify/actions/runs/9814092289/job/27101226733#step:5:168).

<!-- links for markdown above -->

[bengo]: https://bengo.is
