source: Klonkt/test/c2s-visibility.test.js

main
Last change on this file was 81b2e1e, checked in by Robin <roboburr@…>, 7 weeks ago

Feature: C2S posts honor to/cc visibility (shaer-60b wire)

A note POSTed over C2S now federates the way it is addressed instead
of always going loud-public. Public in to = public; Public in cc =
quiet public (unlisted: followers in to, Public in cc on the built
note); followers-only = friends, riding the existing fan_only pipeline
(followers-only delivery + web gating); mention-only addressing =
direct, stored followers-gated and kept local until mention addressing
lands in the client. No addressing at all keeps the legacy public
behavior. Visibility is stored in the new additive posts.ap_visibility
column.

Changed files:
src/services/ActivityPubService.js

  • c2sVisibility(object): addressing -> bucket
  • c2sCreatePost stores ap_visibility + fan_only mapping, skips federation for direct
  • buildNote: quiet -> to followers, Public in cc

src/config/database.js

  • additive column posts.ap_visibility

New file:
test/c2s-visibility.test.js

  • bucket mapping, quiet addressing, friends never Public

-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>

  • Property mode set to 100644
File size: 2.0 KB
Line 
1// C2S visibility (shaer-60b): the note's to/cc addressing decides how a post
2// federates. friends/direct ride the fan_only pipeline; quiet puts Public in
3// cc (unlisted); no addressing keeps the legacy public behavior.
4import { test } from 'node:test';
5import assert from 'node:assert/strict';
6
7process.env.DATABASE_PATH = ':memory:';
8process.env.PUBLIC_BASE_URL = 'https://test.example';
9
10const dbMod = await import('../src/config/database.js');
11dbMod.initializeDatabase();
12const AP = (await import('../src/services/ActivityPubService.js')).default;
13
14const PUB = 'https://www.w3.org/ns/activitystreams#Public';
15const F = 'https://test.example/ap/users/me/followers';
16
17test('addressing maps to the right visibility bucket', () => {
18 assert.equal(AP.c2sVisibility({ to: [PUB] }), 'public');
19 assert.equal(AP.c2sVisibility({ to: [F], cc: [PUB] }), 'quiet');
20 assert.equal(AP.c2sVisibility({ to: [F] }), 'friends');
21 assert.equal(AP.c2sVisibility({ to: ['https://a.test/u/x'] }), 'direct');
22 assert.equal(AP.c2sVisibility({}), 'public'); // legacy client
23 assert.equal(AP.c2sVisibility({ to: PUB }), 'public'); // bare string form
24});
25
26test('a quiet post addresses followers in to and Public in cc', () => {
27 const site = { slug: 'me', primary_slug: 'me' };
28 const post = { id: 'p1', slug: 'x', title: '', content: '<p>hi</p>', tags: '[]', created_at: '2026-01-01T00:00:00Z', ap_visibility: 'quiet' };
29 const note = AP.buildNote('https://test.example', site, post);
30 assert.deepEqual(note.to, [F]);
31 assert.ok(note.cc.includes(PUB), 'Public rides in cc');
32});
33
34test('a friends (fan_only) post never addresses Public', () => {
35 const site = { slug: 'me', primary_slug: 'me' };
36 const post = { id: 'p2', slug: 'y', title: '', content: '<p>hi</p>', tags: '[]', created_at: '2026-01-01T00:00:00Z', fan_only: 1, ap_visibility: 'friends' };
37 const note = AP.buildNote('https://test.example', site, post);
38 assert.deepEqual(note.to, [F]);
39 assert.ok(!note.cc.includes(PUB));
40});
Note: See TracBrowser for help on using the repository browser.