-
-
Notifications
You must be signed in to change notification settings - Fork 96
Closed
Closed
Copy link
Labels
component/actorActor dispatcher relatedActor dispatcher relatedcomponent/federationFederation object relatedFederation object relatedcomponent/testingTesting utilities (@fedify/testing)Testing utilities (@fedify/testing)type/bugSomething isn't workingSomething isn't working
Description
Summary
TestContext, created by TestFederation.createContext() from @fedify/testing, cannot get Actor or other objects such as Note using getActor() or getObject() method.
Here is the example code describing the issue:
import { Note, Person, PUBLIC_COLLECTION } from "@fedify/fedify";
import type { ActorDispatcher, ObjectDispatcher } from "@fedify/fedify";
import { Temporal } from "@js-temporal/polyfill";
import * as testing from "@fedify/testing";
const myActorDispatcher: ActorDispatcher<unknown> = async (
ctx,
identifier,
) => {
// Sample Person object
return new Person({
id: ctx.getActorUri(identifier),
preferredUsername: identifier,
name: "alice",
summary: "alice's account",
});
};
const myNoteDispatcher: ObjectDispatcher<unknown, Note, string> = async (
ctx,
values,
) => {
// Sample Note object
return new Note({
id: ctx.getObjectUri(Note, values),
attribution: ctx.getActorUri(values.identifier),
to: PUBLIC_COLLECTION,
content: "test content",
mediaType: "text/html",
published: Temporal.Instant.from("2026-01-01T00:00:00Z"),
});
};
// Create testing federation object
const federation = testing.createFederation();
// Register dispatcher functions
federation.setActorDispatcher(
"/users/{identifier}",
myActorDispatcher);
federation.setObjectDispatcher(
Note,
"/users/{identifier}/posts/{postId}",
myNoteDispatcher,
);
// Try to get objects
const context = federation.createContext(new Request("https://example.com/"), undefined);
const actor = await context.getActor("alice");
console.log("actor:", actor);
const note = await context.getObject(Note, { identifier: "alice", postId: "1000" });
console.log("note:", note);Expected Behavior
The following would be output:
actor: Person {
id: URL 'https://example.com/users/alice',
name: 'alice',
summary: "alice's account",
preferredUsername: 'alice'
}
note: Note {
id: URL 'https://example.com/users/alice/posts/1000',
attribution: URL 'https://example.com/users/alice',
content: 'test content',
published: Instant [Temporal.Instant] {},
to: URL 'https://www.w3.org/ns/activitystreams#Public',
mediaType: 'text/html'
}
Actual Behavior
Both context.getActor() and context.getObject return null:
actor: null
note: null
If I use createFederation of @fedify/fedify instead, i.e.:
-const federation = testing.createFederation();
+import { createFederation, InProcessMessageQueue, MemoryKvStore } from "@fedify/fedify";
+const federation = createFederation({
+ kv: new MemoryKvStore(),
+ queue: new InProcessMessageQueue(),
+});the sample code above works as expected.
Environment
Using Docker image node:22.22.0-bookworm-slim on WSL2 (Windows 11 Home 25H2)
- OS: Debian (bookworm)
- Runtime: Node.js
- Runtime version: v22.22.0
@fedify/fedifyversion: v1.10.0@fedify/testingversion: v1.10.0
Logs / Screenshots
No response
Steps to Reproduce
npm install "@fedify/fedify@1.10.0"; npm install "@fedify/testing@1.10.0" "tsx@4.21.0" -D- Save the sample code above as
sample.ts npx tsx sample.ts
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
component/actorActor dispatcher relatedActor dispatcher relatedcomponent/federationFederation object relatedFederation object relatedcomponent/testingTesting utilities (@fedify/testing)Testing utilities (@fedify/testing)type/bugSomething isn't workingSomething isn't working