From aceee502ef271231c5bf53fb6f57c63c9b6b7112 Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Tue, 30 Jun 2026 15:45:45 +0900 Subject: [PATCH 01/10] Add webfinger query handling with default config --- Cargo.lock | 1 + crates/feder-runtime-server/Cargo.toml | 1 + crates/feder-runtime-server/src/app.rs | 10 ++- crates/feder-runtime-server/src/config.rs | 4 ++ crates/feder-runtime-server/src/lib.rs | 1 + crates/feder-runtime-server/src/webfinger.rs | 68 ++++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 crates/feder-runtime-server/src/webfinger.rs diff --git a/Cargo.lock b/Cargo.lock index ccab5e7..05553c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -95,6 +95,7 @@ dependencies = [ "axum", "feder-core", "feder-vocab", + "serde", "thiserror", "tokio", "tracing", diff --git a/crates/feder-runtime-server/Cargo.toml b/crates/feder-runtime-server/Cargo.toml index e9621d3..6014044 100644 --- a/crates/feder-runtime-server/Cargo.toml +++ b/crates/feder-runtime-server/Cargo.toml @@ -12,6 +12,7 @@ thiserror = "2" tokio = { version = "1", features = ["macros", "net", "rt-multi-thread"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } +serde.workspace = true [lints] workspace = true diff --git a/crates/feder-runtime-server/src/app.rs b/crates/feder-runtime-server/src/app.rs index bff8682..50df99e 100644 --- a/crates/feder-runtime-server/src/app.rs +++ b/crates/feder-runtime-server/src/app.rs @@ -16,13 +16,17 @@ use std::sync::{Arc, Mutex}; use crate::config::RuntimeConfig; +use crate::webfinger::webfinger; use axum::{Router, http::StatusCode, routing::get}; use feder_core::{FederConfig, FederCore}; -use feder_vocab::Actor; +use feder_vocab::{Actor, Iri}; #[derive(Clone)] pub struct AppState { pub core: Arc>, + pub actor_id: Iri, + pub username: String, + pub handle_host: String, } impl AppState { @@ -37,6 +41,9 @@ impl AppState { Self { core: Arc::new(Mutex::new(core)), + actor_id: config.actor_id.clone(), + username: config.username.clone(), + handle_host: config.handle_host.clone(), } } } @@ -46,6 +53,7 @@ pub fn build_router(config: &RuntimeConfig) -> Router { Router::new() .route("/healthz", get(healthz)) + .route("/.well-known/webfinger", get(webfinger)) .with_state(state) } diff --git a/crates/feder-runtime-server/src/config.rs b/crates/feder-runtime-server/src/config.rs index d0bd2bd..80edbc2 100644 --- a/crates/feder-runtime-server/src/config.rs +++ b/crates/feder-runtime-server/src/config.rs @@ -22,6 +22,8 @@ pub struct RuntimeConfig { pub actor_id: Iri, pub inbox: Iri, pub outbox: Iri, + pub username: String, + pub handle_host: String, } impl RuntimeConfig { @@ -39,6 +41,8 @@ impl RuntimeConfig { bind: "127.0.0.1:3000" .parse() .expect("valid default bind address"), + username: "alice".to_string(), + handle_host: "127.0.0.1:3000".to_string(), } } } diff --git a/crates/feder-runtime-server/src/lib.rs b/crates/feder-runtime-server/src/lib.rs index dcf01c5..ffcf6c1 100644 --- a/crates/feder-runtime-server/src/lib.rs +++ b/crates/feder-runtime-server/src/lib.rs @@ -16,3 +16,4 @@ pub mod app; pub mod config; pub mod error; +pub mod webfinger; diff --git a/crates/feder-runtime-server/src/webfinger.rs b/crates/feder-runtime-server/src/webfinger.rs new file mode 100644 index 0000000..7ee6eaa --- /dev/null +++ b/crates/feder-runtime-server/src/webfinger.rs @@ -0,0 +1,68 @@ +// Feder: A portable ActivityPub core for many runtimes. +// Copyright (C) 2026 Feder contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use axum::{ + Json, + extract::{Query, State}, + http::StatusCode, +}; +use serde::{Deserialize, Serialize}; + +use crate::app::AppState; + +#[derive(Deserialize)] +pub struct WebFingerQuery { + resource: Option, +} + +#[derive(Serialize)] +pub struct WebFingerResponse { + subject: String, + aliases: Vec, + links: Vec, +} + +#[derive(Serialize)] +pub struct WebFingerLink { + rel: &'static str, + #[serde(rename = "type")] + media_type: &'static str, + href: String, +} +pub async fn webfinger( + State(state): State, + Query(query): Query, +) -> Result, StatusCode> { + let Some(resource) = query.resource else { + return Err(StatusCode::BAD_REQUEST); + }; + + let expected = format!("acct:{}@{}", state.username, state.handle_host); + if resource != expected { + return Err(StatusCode::NOT_FOUND); + } + + let actor_id = state.actor_id.to_string(); + + Ok(Json(WebFingerResponse { + subject: resource, + aliases: vec![actor_id.clone()], + links: vec![WebFingerLink { + rel: "self", + media_type: "application/activity+json", + href: actor_id, + }], + })) +} From c09097d0b28a5735f09b41b539ada916e15fa3dc Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Tue, 30 Jun 2026 16:24:27 +0900 Subject: [PATCH 02/10] Add response header and return response --- crates/feder-runtime-server/src/webfinger.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/feder-runtime-server/src/webfinger.rs b/crates/feder-runtime-server/src/webfinger.rs index 7ee6eaa..fcfc5ab 100644 --- a/crates/feder-runtime-server/src/webfinger.rs +++ b/crates/feder-runtime-server/src/webfinger.rs @@ -14,9 +14,7 @@ // along with this program. If not, see . use axum::{ - Json, - extract::{Query, State}, - http::StatusCode, + Json, extract::{Query, State}, http::{StatusCode, header}, response::{IntoResponse, Response}, }; use serde::{Deserialize, Serialize}; @@ -44,7 +42,7 @@ pub struct WebFingerLink { pub async fn webfinger( State(state): State, Query(query): Query, -) -> Result, StatusCode> { +) -> Result { let Some(resource) = query.resource else { return Err(StatusCode::BAD_REQUEST); }; @@ -56,7 +54,9 @@ pub async fn webfinger( let actor_id = state.actor_id.to_string(); - Ok(Json(WebFingerResponse { + Ok(( + [(header::CONTENT_TYPE, "application/jrd+json")], + Json(WebFingerResponse { subject: resource, aliases: vec![actor_id.clone()], links: vec![WebFingerLink { @@ -64,5 +64,6 @@ pub async fn webfinger( media_type: "application/activity+json", href: actor_id, }], - })) + }), + ).into_response()) } From 82da624c67db22e9ac05695208b4465b2850a7ab Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Tue, 30 Jun 2026 16:32:52 +0900 Subject: [PATCH 03/10] Add mise run test command --- mise.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mise.toml b/mise.toml index 8da167b..966f131 100644 --- a/mise.toml +++ b/mise.toml @@ -23,3 +23,7 @@ run = [ [tasks.fmt] description = "Format code and docs" run = ["cargo fmt", "hongdown --write", "mise fmt"] + +[tasks.test] +description = "Run the Rust tests" +run = "cargo test" From 0121411095bf1f8ce067a23b7821e68510c7ea79 Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Tue, 30 Jun 2026 16:36:06 +0900 Subject: [PATCH 04/10] Test WebFinger discovery responses Assisted-by: Codex:gpt-5.5 --- Cargo.lock | 2 + crates/feder-runtime-server/Cargo.toml | 4 + crates/feder-runtime-server/src/webfinger.rs | 108 +++++++++++++++++-- 3 files changed, 104 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05553c5..e730504 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,8 +96,10 @@ dependencies = [ "feder-core", "feder-vocab", "serde", + "serde_json", "thiserror", "tokio", + "tower", "tracing", "tracing-subscriber", ] diff --git a/crates/feder-runtime-server/Cargo.toml b/crates/feder-runtime-server/Cargo.toml index 6014044..cd1cc4f 100644 --- a/crates/feder-runtime-server/Cargo.toml +++ b/crates/feder-runtime-server/Cargo.toml @@ -14,5 +14,9 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } serde.workspace = true +[dev-dependencies] +serde_json.workspace = true +tower = "0.5" + [lints] workspace = true diff --git a/crates/feder-runtime-server/src/webfinger.rs b/crates/feder-runtime-server/src/webfinger.rs index fcfc5ab..c190e12 100644 --- a/crates/feder-runtime-server/src/webfinger.rs +++ b/crates/feder-runtime-server/src/webfinger.rs @@ -14,7 +14,10 @@ // along with this program. If not, see . use axum::{ - Json, extract::{Query, State}, http::{StatusCode, header}, response::{IntoResponse, Response}, + Json, + extract::{Query, State}, + http::{StatusCode, header}, + response::{IntoResponse, Response}, }; use serde::{Deserialize, Serialize}; @@ -39,6 +42,7 @@ pub struct WebFingerLink { media_type: &'static str, href: String, } + pub async fn webfinger( State(state): State, Query(query): Query, @@ -57,13 +61,97 @@ pub async fn webfinger( Ok(( [(header::CONTENT_TYPE, "application/jrd+json")], Json(WebFingerResponse { - subject: resource, - aliases: vec![actor_id.clone()], - links: vec![WebFingerLink { - rel: "self", - media_type: "application/activity+json", - href: actor_id, - }], - }), - ).into_response()) + subject: resource, + aliases: vec![actor_id.clone()], + links: vec![WebFingerLink { + rel: "self", + media_type: "application/activity+json", + href: actor_id, + }], + }), + ) + .into_response()) +} + +#[cfg(test)] +mod tests { + use axum::{ + body::{Body, to_bytes}, + http::{Request, StatusCode, header}, + }; + use serde_json::Value; + use tower::ServiceExt; + + use crate::{app::build_router, config::RuntimeConfig}; + + const WEBFINGER_PATH: &str = "/.well-known/webfinger?resource=acct:alice@127.0.0.1:3000"; + + #[tokio::test] + async fn returns_webfinger_descriptor_for_local_actor() { + let app = build_router(&RuntimeConfig::default_local()); + + let response = app + .oneshot( + Request::builder() + .uri(WEBFINGER_PATH) + .body(Body::empty()) + .expect("valid request"), + ) + .await + .expect("response"); + + assert_eq!(response.status(), StatusCode::OK); + assert_eq!( + response.headers().get(header::CONTENT_TYPE).unwrap(), + "application/jrd+json" + ); + + let body = to_bytes(response.into_body(), 1024) + .await + .expect("read response body"); + let json: Value = serde_json::from_slice(&body).expect("valid json"); + + assert_eq!(json["subject"], "acct:alice@127.0.0.1:3000"); + assert_eq!(json["aliases"][0], "http://127.0.0.1:3000/users/alice"); + assert_eq!(json["links"][0]["rel"], "self"); + assert_eq!(json["links"][0]["type"], "application/activity+json"); + assert_eq!( + json["links"][0]["href"], + "http://127.0.0.1:3000/users/alice" + ); + } + + #[tokio::test] + async fn rejects_missing_resource() { + let app = build_router(&RuntimeConfig::default_local()); + + let response = app + .oneshot( + Request::builder() + .uri("/.well-known/webfinger") + .body(Body::empty()) + .expect("valid request"), + ) + .await + .expect("response"); + + assert_eq!(response.status(), StatusCode::BAD_REQUEST); + } + + #[tokio::test] + async fn rejects_non_local_actor_resource() { + let app = build_router(&RuntimeConfig::default_local()); + + let response = app + .oneshot( + Request::builder() + .uri("/.well-known/webfinger?resource=acct:bob@127.0.0.1:3000") + .body(Body::empty()) + .expect("valid request"), + ) + .await + .expect("response"); + + assert_eq!(response.status(), StatusCode::NOT_FOUND); + } } From 6278df4348a9bd816398ef9ce43c0a5145bc59a6 Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Wed, 1 Jul 2026 13:28:18 +0900 Subject: [PATCH 05/10] Implement actor endpoint Expose GET /users/{username} from the server runtime and return the configured local actor as application/activity+json. Keep the local actor in AppState and pass a clone into FederCore so HTTP serving does not need to lock the core state. --- crates/feder-runtime-server/src/actor.rs | 40 ++++++++++++++++++++ crates/feder-runtime-server/src/app.rs | 14 ++++--- crates/feder-runtime-server/src/config.rs | 2 + crates/feder-runtime-server/src/lib.rs | 1 + crates/feder-runtime-server/src/webfinger.rs | 2 +- 5 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 crates/feder-runtime-server/src/actor.rs diff --git a/crates/feder-runtime-server/src/actor.rs b/crates/feder-runtime-server/src/actor.rs new file mode 100644 index 0000000..3e5e2cc --- /dev/null +++ b/crates/feder-runtime-server/src/actor.rs @@ -0,0 +1,40 @@ +// Feder: A portable ActivityPub core for many runtimes. +// Copyright (C) 2026 Feder contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use axum::{ + Json, + extract::{Path, State}, + http::{StatusCode, header}, + response::{IntoResponse, Response}, +}; + +use crate::app::AppState; + +pub async fn actor( + State(app_state): State, + Path(username): Path, +) -> Result { + if username != app_state.username { + return Err(StatusCode::NOT_FOUND); + } + // FederCore + let actor = app_state.local_actor.clone(); + + Ok(( + [(header::CONTENT_TYPE, "application/activity+json")], + Json(actor), + ) + .into_response()) +} diff --git a/crates/feder-runtime-server/src/app.rs b/crates/feder-runtime-server/src/app.rs index 50df99e..8cca69a 100644 --- a/crates/feder-runtime-server/src/app.rs +++ b/crates/feder-runtime-server/src/app.rs @@ -15,33 +15,36 @@ use std::sync::{Arc, Mutex}; +use crate::actor::actor; use crate::config::RuntimeConfig; use crate::webfinger::webfinger; use axum::{Router, http::StatusCode, routing::get}; use feder_core::{FederConfig, FederCore}; -use feder_vocab::{Actor, Iri}; +use feder_vocab::Actor; #[derive(Clone)] pub struct AppState { pub core: Arc>, - pub actor_id: Iri, + pub local_actor: Actor, pub username: String, pub handle_host: String, } impl AppState { pub fn from_config(config: &RuntimeConfig) -> Self { - let actor = Actor::person( + let mut actor = Actor::person( config.actor_id.clone(), config.inbox.clone(), config.outbox.clone(), ); + actor.preferred_username = Some(config.preferred_username.clone()); + actor.name = Some(config.username.clone()); - let core = FederCore::new(FederConfig::new(actor)); + let core = FederCore::new(FederConfig::new(actor.clone())); Self { core: Arc::new(Mutex::new(core)), - actor_id: config.actor_id.clone(), + local_actor: actor, username: config.username.clone(), handle_host: config.handle_host.clone(), } @@ -54,6 +57,7 @@ pub fn build_router(config: &RuntimeConfig) -> Router { Router::new() .route("/healthz", get(healthz)) .route("/.well-known/webfinger", get(webfinger)) + .route("/users/{username}", get(actor)) .with_state(state) } diff --git a/crates/feder-runtime-server/src/config.rs b/crates/feder-runtime-server/src/config.rs index 80edbc2..f3cd866 100644 --- a/crates/feder-runtime-server/src/config.rs +++ b/crates/feder-runtime-server/src/config.rs @@ -23,6 +23,7 @@ pub struct RuntimeConfig { pub inbox: Iri, pub outbox: Iri, pub username: String, + pub preferred_username: String, pub handle_host: String, } @@ -42,6 +43,7 @@ impl RuntimeConfig { .parse() .expect("valid default bind address"), username: "alice".to_string(), + preferred_username: "alice".to_string(), handle_host: "127.0.0.1:3000".to_string(), } } diff --git a/crates/feder-runtime-server/src/lib.rs b/crates/feder-runtime-server/src/lib.rs index ffcf6c1..2071764 100644 --- a/crates/feder-runtime-server/src/lib.rs +++ b/crates/feder-runtime-server/src/lib.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +pub mod actor; pub mod app; pub mod config; pub mod error; diff --git a/crates/feder-runtime-server/src/webfinger.rs b/crates/feder-runtime-server/src/webfinger.rs index c190e12..5eeee15 100644 --- a/crates/feder-runtime-server/src/webfinger.rs +++ b/crates/feder-runtime-server/src/webfinger.rs @@ -56,7 +56,7 @@ pub async fn webfinger( return Err(StatusCode::NOT_FOUND); } - let actor_id = state.actor_id.to_string(); + let actor_id = state.local_actor.id.to_string(); Ok(( [(header::CONTENT_TYPE, "application/jrd+json")], From 11e7af09edfcceda3aaa77304eed3d447bfb90c9 Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Wed, 1 Jul 2026 13:30:46 +0900 Subject: [PATCH 06/10] Test local ActivityPub actor endpoint Cover the configured local actor route, unknown usernames, response content type, and serialized ActivityPub actor fields. Assisted-by: Codex:gpt-5.5 --- crates/feder-runtime-server/src/actor.rs | 68 ++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/crates/feder-runtime-server/src/actor.rs b/crates/feder-runtime-server/src/actor.rs index 3e5e2cc..daf6028 100644 --- a/crates/feder-runtime-server/src/actor.rs +++ b/crates/feder-runtime-server/src/actor.rs @@ -29,12 +29,74 @@ pub async fn actor( if username != app_state.username { return Err(StatusCode::NOT_FOUND); } - // FederCore - let actor = app_state.local_actor.clone(); + let local_actor = app_state.local_actor.clone(); Ok(( [(header::CONTENT_TYPE, "application/activity+json")], - Json(actor), + Json(local_actor), ) .into_response()) } + +#[cfg(test)] +mod tests { + use axum::{ + body::{Body, to_bytes}, + http::{Request, StatusCode, header}, + }; + use serde_json::Value; + use tower::ServiceExt; + + use crate::{app::build_router, config::RuntimeConfig}; + + #[tokio::test] + async fn returns_local_actor() { + let app = build_router(&RuntimeConfig::default_local()); + + let response = app + .oneshot( + Request::builder() + .uri("/users/alice") + .body(Body::empty()) + .expect("valid request"), + ) + .await + .expect("response"); + + assert_eq!(response.status(), StatusCode::OK); + assert_eq!( + response.headers().get(header::CONTENT_TYPE).unwrap(), + "application/activity+json" + ); + + let body = to_bytes(response.into_body(), 2048) + .await + .expect("read response body"); + let json: Value = serde_json::from_slice(&body).expect("valid json"); + + assert_eq!(json["@context"], "https://www.w3.org/ns/activitystreams"); + assert_eq!(json["type"], "Person"); + assert_eq!(json["id"], "http://127.0.0.1:3000/users/alice"); + assert_eq!(json["inbox"], "http://127.0.0.1:3000/users/alice/inbox"); + assert_eq!(json["outbox"], "http://127.0.0.1:3000/users/alice/outbox"); + assert_eq!(json["preferredUsername"], "alice"); + assert_eq!(json["name"], "alice"); + } + + #[tokio::test] + async fn rejects_unknown_actor() { + let app = build_router(&RuntimeConfig::default_local()); + + let response = app + .oneshot( + Request::builder() + .uri("/users/bob") + .body(Body::empty()) + .expect("valid request"), + ) + .await + .expect("response"); + + assert_eq!(response.status(), StatusCode::NOT_FOUND); + } +} From 7d67af1002c3f2283d0290129847cb3c67107f0e Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Thu, 2 Jul 2026 16:39:34 +0900 Subject: [PATCH 07/10] Implement note endpoint --- crates/feder-runtime-server/src/app.rs | 15 ++++++-- crates/feder-runtime-server/src/config.rs | 6 ++++ crates/feder-runtime-server/src/lib.rs | 1 + crates/feder-runtime-server/src/note.rs | 42 +++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 crates/feder-runtime-server/src/note.rs diff --git a/crates/feder-runtime-server/src/app.rs b/crates/feder-runtime-server/src/app.rs index 8cca69a..fa591b9 100644 --- a/crates/feder-runtime-server/src/app.rs +++ b/crates/feder-runtime-server/src/app.rs @@ -15,12 +15,12 @@ use std::sync::{Arc, Mutex}; -use crate::actor::actor; use crate::config::RuntimeConfig; use crate::webfinger::webfinger; +use crate::{actor::actor, note::note}; use axum::{Router, http::StatusCode, routing::get}; use feder_core::{FederConfig, FederCore}; -use feder_vocab::Actor; +use feder_vocab::{Actor, Note, Reference}; #[derive(Clone)] pub struct AppState { @@ -28,6 +28,8 @@ pub struct AppState { pub local_actor: Actor, pub username: String, pub handle_host: String, + // TODO(#25): Replace this seeded preview note with durable runtime storage. + pub notes: Vec, } impl AppState { @@ -40,6 +42,13 @@ impl AppState { actor.preferred_username = Some(config.preferred_username.clone()); actor.name = Some(config.username.clone()); + // TODO(#25): Replace this seeded preview note with durable runtime storage. + let mut note = Note::new(config.note_id.clone()); + note.attributed_to = Some(Reference::id(config.actor_id.clone())); + note.content = + Some("Hello, World! This is Feder, a portable AP core for many runtimes.".to_string()); + let notes = vec![note]; + let core = FederCore::new(FederConfig::new(actor.clone())); Self { @@ -47,6 +56,7 @@ impl AppState { local_actor: actor, username: config.username.clone(), handle_host: config.handle_host.clone(), + notes, } } } @@ -58,6 +68,7 @@ pub fn build_router(config: &RuntimeConfig) -> Router { .route("/healthz", get(healthz)) .route("/.well-known/webfinger", get(webfinger)) .route("/users/{username}", get(actor)) + .route("/notes/{id}", get(note)) .with_state(state) } diff --git a/crates/feder-runtime-server/src/config.rs b/crates/feder-runtime-server/src/config.rs index f3cd866..9039c9d 100644 --- a/crates/feder-runtime-server/src/config.rs +++ b/crates/feder-runtime-server/src/config.rs @@ -25,6 +25,8 @@ pub struct RuntimeConfig { pub username: String, pub preferred_username: String, pub handle_host: String, + // TODO(#25): Replace this seeded preview note with durable runtime storage. + pub note_id: Iri, } impl RuntimeConfig { @@ -45,6 +47,10 @@ impl RuntimeConfig { username: "alice".to_string(), preferred_username: "alice".to_string(), handle_host: "127.0.0.1:3000".to_string(), + // TODO(#25): Replace this seeded preview note with durable runtime storage. + note_id: "http://127.0.0.1:3000/notes/1" + .parse() + .expect("valid default note IRI"), } } } diff --git a/crates/feder-runtime-server/src/lib.rs b/crates/feder-runtime-server/src/lib.rs index 2071764..58c1a85 100644 --- a/crates/feder-runtime-server/src/lib.rs +++ b/crates/feder-runtime-server/src/lib.rs @@ -17,4 +17,5 @@ pub mod actor; pub mod app; pub mod config; pub mod error; +pub mod note; pub mod webfinger; diff --git a/crates/feder-runtime-server/src/note.rs b/crates/feder-runtime-server/src/note.rs new file mode 100644 index 0000000..70667ac --- /dev/null +++ b/crates/feder-runtime-server/src/note.rs @@ -0,0 +1,42 @@ +// Feder: A portable ActivityPub core for many runtimes. +// Copyright (C) 2026 Feder contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use axum::{ + Json, + extract::{Path, State}, + http::{StatusCode, header}, + response::{IntoResponse, Response}, +}; + +use crate::app::AppState; + +pub async fn note( + State(app_state): State, + Path(id): Path, +) -> Result { + // TODO(#25): Replace this seeded preview note with durable runtime storage. + let note = app_state + .notes + .iter() + .find(|note| note.id.as_str() == format!("http://{}/notes/{id}", app_state.handle_host)) + .cloned() + .ok_or(StatusCode::NOT_FOUND)?; + + Ok(( + [(header::CONTENT_TYPE, "application/activity+json")], + Json(note), + ) + .into_response()) +} From 6cc594f51010f7fd00a1403c6d625c6de1314b1b Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Thu, 2 Jul 2026 16:46:51 +0900 Subject: [PATCH 08/10] Test public Note endpoint Cover the seeded public Note route, unknown Note IDs, response content type, and serialized ActivityPub Note fields. Assisted-by: Codex:gpt-5.5 --- crates/feder-runtime-server/src/note.rs | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/crates/feder-runtime-server/src/note.rs b/crates/feder-runtime-server/src/note.rs index 70667ac..94dca70 100644 --- a/crates/feder-runtime-server/src/note.rs +++ b/crates/feder-runtime-server/src/note.rs @@ -40,3 +40,67 @@ pub async fn note( ) .into_response()) } + +#[cfg(test)] +mod tests { + use axum::{ + body::{Body, to_bytes}, + http::{Request, StatusCode, header}, + }; + use serde_json::Value; + use tower::ServiceExt; + + use crate::{app::build_router, config::RuntimeConfig}; + + #[tokio::test] + async fn returns_public_note() { + let app = build_router(&RuntimeConfig::default_local()); + + let response = app + .oneshot( + Request::builder() + .uri("/notes/1") + .body(Body::empty()) + .expect("valid request"), + ) + .await + .expect("response"); + + assert_eq!(response.status(), StatusCode::OK); + assert_eq!( + response.headers().get(header::CONTENT_TYPE).unwrap(), + "application/activity+json" + ); + + let body = to_bytes(response.into_body(), 2048) + .await + .expect("read response body"); + let json: Value = serde_json::from_slice(&body).expect("valid json"); + + assert_eq!(json["@context"], "https://www.w3.org/ns/activitystreams"); + assert_eq!(json["type"], "Note"); + assert_eq!(json["id"], "http://127.0.0.1:3000/notes/1"); + assert_eq!(json["attributedTo"], "http://127.0.0.1:3000/users/alice"); + assert_eq!( + json["content"], + "Hello, World! This is Feder, a portable AP core for many runtimes." + ); + } + + #[tokio::test] + async fn rejects_unknown_note() { + let app = build_router(&RuntimeConfig::default_local()); + + let response = app + .oneshot( + Request::builder() + .uri("/notes/missing") + .body(Body::empty()) + .expect("valid request"), + ) + .await + .expect("response"); + + assert_eq!(response.status(), StatusCode::NOT_FOUND); + } +} From 07be8f96b8391bff1ab67fff8cfa30d4d20da8dc Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Fri, 3 Jul 2026 14:51:26 +0900 Subject: [PATCH 09/10] Fix hardcoded URL to suffix --- crates/feder-runtime-server/src/note.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/feder-runtime-server/src/note.rs b/crates/feder-runtime-server/src/note.rs index 94dca70..7fa92ef 100644 --- a/crates/feder-runtime-server/src/note.rs +++ b/crates/feder-runtime-server/src/note.rs @@ -27,10 +27,11 @@ pub async fn note( Path(id): Path, ) -> Result { // TODO(#25): Replace this seeded preview note with durable runtime storage. + let expected_suffix = format!("/notes/{id}"); let note = app_state .notes .iter() - .find(|note| note.id.as_str() == format!("http://{}/notes/{id}", app_state.handle_host)) + .find(|note| note.id.as_str().ends_with(&expected_suffix)) .cloned() .ok_or(StatusCode::NOT_FOUND)?; From 0cc162c0bb920ca1967c346513d85f43f6de0364 Mon Sep 17 00:00:00 2001 From: Jiwon Kwon Date: Fri, 3 Jul 2026 14:54:41 +0900 Subject: [PATCH 10/10] Enable tower's util --- Cargo.toml | 1 + crates/feder-runtime-server/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b7439be..f889890 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ license = "AGPL-3.0-only" iri-string = { version = "0.7.12", default-features = false, features = ["alloc", "serde"] } serde = { version = "1.0.219", default-features = false, features = ["alloc", "derive"] } serde_json = "1.0.140" +tower = { version = "0.5", features = ["util"]} [workspace.lints.rust] warnings = "deny" diff --git a/crates/feder-runtime-server/Cargo.toml b/crates/feder-runtime-server/Cargo.toml index cd1cc4f..d32af2b 100644 --- a/crates/feder-runtime-server/Cargo.toml +++ b/crates/feder-runtime-server/Cargo.toml @@ -16,7 +16,7 @@ serde.workspace = true [dev-dependencies] serde_json.workspace = true -tower = "0.5" +tower.workspace = true [lints] workspace = true