| 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.
|
|---|
| 4 | import { test } from 'node:test';
|
|---|
| 5 | import assert from 'node:assert/strict';
|
|---|
| 6 |
|
|---|
| 7 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 8 | process.env.PUBLIC_BASE_URL = 'https://test.example';
|
|---|
| 9 |
|
|---|
| 10 | const dbMod = await import('../src/config/database.js');
|
|---|
| 11 | dbMod.initializeDatabase();
|
|---|
| 12 | const AP = (await import('../src/services/ActivityPubService.js')).default;
|
|---|
| 13 |
|
|---|
| 14 | const PUB = 'https://www.w3.org/ns/activitystreams#Public';
|
|---|
| 15 | const F = 'https://test.example/ap/users/me/followers';
|
|---|
| 16 |
|
|---|
| 17 | test('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 |
|
|---|
| 26 | test('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 |
|
|---|
| 34 | test('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 | });
|
|---|