SOURCE / PINNED RELEASE
Made of little things.
Black Site Map Editor
- Release
- 32a57733b7e9…
- Author-recorded commit
- 3f54890f542f…
- License
- LICENSE
- Author’s source reference
- nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.shakespeare.diy%2F/black-site-map-editor
Archive hash verified: 7a4b1abbac7db5b0…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import ts from 'typescript';
const source = await readFile(new URL('../src/map-intent.ts', import.meta.url), 'utf8');
let available = true,
receiver,
closed = false;
const author = 'a'.repeat(64),
address = `35858:${author}:outpost`;
const delivery = (action = 'edit', payload = { address }) => ({
sender: 'catalog:source',
archetype: 'black-site',
action: `map-${action}`,
convention: `napplet:black-site/map-${action}`,
payload,
});
globalThis.__intentFixture = {
intent: {
onDelivery(callback) {
receiver = callback;
callback(delivery());
return {
close() {
closed = true;
},
};
},
},
hasDomain: () => available,
};
const js = ts
.transpileModule(source, {
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext },
})
.outputText.replace(
"import { intent } from '@napplet/sdk';",
'const {intent}=globalThis.__intentFixture;',
)
.replace(
"import { runtimeHasDomain } from './domain-availability.js';",
'const runtimeHasDomain=globalThis.__intentFixture.hasDomain;',
)
.replace(
"from './model'",
`from '${new URL('../src/vendor/validate-map.mjs', import.meta.url).href}'`,
);
const { parseMapIntent, subscribeMapIntents } = await import(
'data:text/javascript;base64,' + Buffer.from(js).toString('base64')
);
const map = JSON.parse(
await readFile(new URL('../src/vendor/outpost.json', import.meta.url), 'utf8'),
);
test('exact routing accepts edit/remix/open address targets and source grants no authority', () => {
for (const action of ['edit', 'remix', 'open']) {
const parsed = parseMapIntent(
delivery(action, {
address,
relays: ['wss://relay.example.com', 'wss://relay.example.com/'],
}),
);
assert.equal(parsed.action, action);
assert.equal(parsed.target.author, author);
assert.deepEqual(parsed.target.relays, ['wss://relay.example.com/']);
assert.equal(parsed.sender, 'catalog:source');
assert.equal(parsed.owner, undefined);
}
});
test('queried conventions, mismatched routing and malformed targets are rejected', () => {
assert.throws(
() =>
parseMapIntent({ ...delivery(), convention: 'napplet:black-site/map-edit?address=x' }),
/convention/,
);
assert.throws(() => parseMapIntent({ ...delivery(), action: 'remix' }), /routing/);
assert.throws(() => parseMapIntent({ ...delivery(), archetype: 'map' }), /routing/);
assert.throws(
() =>
parseMapIntent({
...delivery(),
convention: 'napplet:map/edit',
archetype: 'map',
action: 'edit',
}),
/convention/,
);
for (const bad of [
'30078:' + author + ':outpost',
'35858:' + author.toUpperCase() + ':outpost',
'35858:' + author + ':../map',
])
assert.throws(() => parseMapIntent(delivery('edit', { address: bad })), /address/);
assert.throws(() => parseMapIntent(delivery('edit', { address, event: {} })), /unsupported/);
for (const relay of [
'https://relay.example.com',
'wss://localhost',
'wss://192.168.1.1',
'wss://relay.example.com:444',
'wss://user:pw@relay.example.com',
])
assert.throws(
() => parseMapIntent(delivery('edit', { address, relays: [relay] })),
/relay/,
);
});
test('new handoffs validate schema, reject malformed layers and excessive payload size', () => {
assert.equal(parseMapIntent(delivery('new', {})).map, undefined);
const parsed = parseMapIntent(delivery('new', { map }));
assert.deepEqual(parsed.map, map);
assert.notEqual(parsed.map, map);
assert.throws(
() => parseMapIntent(delivery('new', { map: { ...map, walls: [[-1, 0, 3, 3]] } })),
/invalid/,
);
assert.throws(
() => parseMapIntent(delivery('new', { map: { ...map, desc: 'x'.repeat(270000) } })),
/size/,
);
});
test('official subscription receives retained deliveries, reports malformed requests and closes', async () => {
const received = [],
errors = [];
const sub = subscribeMapIntents(
(request) => received.push(request),
(error) => errors.push(error),
);
assert.equal(received.length, 1);
receiver(delivery('remix'));
assert.equal(received.length, 2);
receiver({ ...delivery(), convention: 'napplet:black-site/map-edit?x=1' });
assert.equal(errors.length, 1);
sub.close();
assert.equal(closed, true);
receiver(delivery());
assert.equal(received.length, 2);
});
test('absent optional intent and missing implemented receiver leave local authoring usable', () => {
available = false;
let called = false;
subscribeMapIntents(
() => {
called = true;
},
() => {
called = true;
},
).close();
assert.equal(called, false);
available = true;
const original = globalThis.__intentFixture.intent.onDelivery;
delete globalThis.__intentFixture.intent.onDelivery;
let error;
subscribeMapIntents(
() => {},
(value) => {
error = value;
},
).close();
assert.ok(error instanceof Error);
globalThis.__intentFixture.intent.onDelivery = original;
});
