chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.1 Latest 5 packages
0
0
// `npm run unit` in web/ (`just check` runs it).
import { strict as assert } from 'node:assert';
import { test } from 'node:test';
import { callOf, Names, pathOf, plain, recordAt, routeOf, type Route } from './routes.ts';
const FOR_YOU = { name: 'query', args: { method: 'social.grain.feed.getFeed', params: { feed: 'at://did:web:grain.social/social.grain.feed.generator/foryou' } } };
const ROUTES: Route[] = [
{ path: '/feeds/for-you', call: FOR_YOU },
{ path: '/profile/{actor}/gallery/{rkey}', call: { name: 'query', args: { method: 'social.grain.gallery.getGallery', params: { gallery: 'at://{actor}/social.grain.gallery/{rkey}' } } } },
{ path: '/profile/{actor}/story/{rkey}', call: { name: 'query', args: { method: 'social.grain.story.getArchive', params: { actor: '{actor:did}' }, at: 'at://{actor:did}/social.grain.story/{rkey}' } } },
{ path: '/profile/{actor}', call: { name: 'describe_app', args: { domain: 'grain.social', actor: '{actor}' } } }
];
test("a call less its compose is the screen it opens, at the screen's URL", () => {
const opening = { ...FOR_YOU, args: { ...FOR_YOU.args, compose: 'New gallery' } };
assert.deepEqual(plain(opening), FOR_YOU);
assert.equal(pathOf(opening, ROUTES, new Names()), '/feeds/for-you');
assert.equal(plain(FOR_YOU), FOR_YOU, 'a call with none is itself');
});
test("a record's screen is its route's, by the record its call names", () => {
const names = new Names([['did:plc:me', 'me.test']]);
const gallery = recordAt('at://did:plc:me/social.grain.gallery/3k2a', ROUTES);
assert.deepEqual(gallery, { call: { name: 'query', args: { method: 'social.grain.gallery.getGallery', params: { gallery: 'at://did:plc:me/social.grain.gallery/3k2a' } } }, tab: undefined });
assert.equal(pathOf(gallery!.call, ROUTES, names), '/profile/me.test/gallery/3k2a');
const story = recordAt('at://did:plc:me/social.grain.story/3k2b', ROUTES);
assert.deepEqual(story?.call.args, { method: 'social.grain.story.getArchive', params: { actor: 'did:plc:me' }, at: 'at://did:plc:me/social.grain.story/3k2b' });
});
test('a record no route names has no screen: an account alone is no record, nor a fixed one another', () => {
assert.equal(recordAt('at://did:plc:me/social.grain.photo/3k2c', ROUTES), null);
assert.equal(recordAt('at://did:web:grain.social/social.grain.feed.generator/recent', ROUTES), null);
});
test("a story's route opens it in the story viewer, its URL loaded over the screen its under names", async () => {
const story = { ...ROUTES[2], pager: true, under: '/profile/{actor}' };
const routes = [ROUTES[0], ROUTES[1], story, ROUTES[3]];
const shown = { name: 'query', args: { method: 'social.grain.story.getArchive', params: { actor: 'did:plc:me' }, at: 'at://did:plc:me/social.grain.story/3k2b' } };
assert.equal(routeOf(shown, routes)?.pager, true);
assert.equal(routeOf(FOR_YOU, routes)?.pager, undefined);
assert.equal(routeOf({ name: 'query', args: { method: 'social.grain.story.getStories', params: { actor: 'did:plc:me' } } }, routes), null);
const resolve = async (actor: string) => (actor === 'me.test' ? 'did:plc:me' : actor);
const found = await callOf('/profile/me.test/story/3k2b', '', routes, resolve);
assert.deepEqual(found, { call: shown, tab: undefined, pager: true, under: '/profile/me.test' });
assert.equal(pathOf(shown, routes, new Names([['did:plc:me', 'me.test']])), '/profile/me.test/story/3k2b');
// A route that is no story's has neither, nor one with no under.
assert.deepEqual(await callOf('/profile/me.test', '', routes, resolve), { call: { name: 'describe_app', args: { domain: 'grain.social', actor: 'me.test' } }, tab: undefined });
const bare = await callOf('/profile/me.test/story/3k2b', '', [{ ...ROUTES[2], pager: true }], resolve);
assert.equal(bare?.pager, true);
assert.equal(bare?.under, undefined);
});