SOURCE / PINNED RELEASE
Made of little things.
Drone Zone — deep field
- Release
- 578f277a8be1…
- Author-recorded commit
- a96742b428de…
- License
- LICENSE
- Author’s source reference
- nostr://npub1n8ga89w8h6tvwamxusfyzexw8gjy84yxu9rxgnmk955cxtml4ujswzxydd/wss%3A%2F%2Fgit.napplet.soy%2F/n-9753e6cf3ec
Archive hash verified: f7f3bf8ff3482551…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import assert from 'node:assert/strict';
import { readdir, readFile } from 'node:fs/promises';
import { dirname, extname, join, relative } from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';
import { runInNewContext } from 'node:vm';
import ts from 'typescript';
const root = dirname(dirname(fileURLToPath(import.meta.url)));
const textExtensions = new Set(['.css', '.html', '.json', '.md', '.mjs', '.ts']);
const skippedDirectories = new Set(['.git', 'dist', 'node_modules', '.agents', '.claude', '.napplet-space']);
async function collectTextFiles(directory = root) {
const files = [];
for (const entry of await readdir(directory, { withFileTypes: true })) {
if (entry.isDirectory() && skippedDirectories.has(entry.name)) continue;
const path = join(directory, entry.name);
if (entry.isDirectory()) files.push(...await collectTextFiles(path));
else if (entry.isFile() && textExtensions.has(extname(entry.name))) files.push(path);
}
return files;
}
const files = await collectTextFiles();
const sources = new Map(
await Promise.all(files.map(async (path) => [relative(root, path), await readFile(path, 'utf8')])),
);
test('rejects retired app-owned bootstrap and probing APIs', () => {
const joined = (...parts) => parts.join('');
const shimSpecifier = ['@napplet', 'shim'].join('/');
const patterns = [
new RegExp(`import\\s+(?:[^'\"]+\\s+from\\s+)?['\"]${shimSpecifier}['\"]`),
new RegExp(`shell(?:\\.|\\?\\.)${joined('rea', 'dy')}\\s*\\(`),
new RegExp(`shell(?:\\.|\\?\\.)${joined('in', 'it')}\\s*\\(`),
new RegExp(`shell(?:\\.|\\?\\.)${joined('supp', 'orts')}\\s*\\(`),
new RegExp(`window(?:\\.|\\?\\.)napplet(?:\\.|\\?\\.)${joined('sh', 'ell')}`),
new RegExp(`window\\s*\\[\\s*['\"]napplet['\"]\\s*\\]\\s*(?:\\.|\\?\\.)${joined('sh', 'ell')}`),
new RegExp(`window\\s*\\[\\s*['\"]napplet['\"]\\s*\\]\\s*\\[\\s*['\"]${joined('sh', 'ell')}['\"]\\s*\\]`),
new RegExp(`${joined('discover', 'Services')}\\s*\\(`),
new RegExp(`${joined('has', 'Service')}(?:Version)?\\s*\\(`),
];
const retiredExamples = [
`import { install } from '${shimSpecifier}';`,
`shell?.${joined('rea', 'dy')}()`,
`shell.${joined('in', 'it')}()`,
`shell.${joined('supp', 'orts')}('storage')`,
`window?.napplet?.${joined('sh', 'ell')}`,
`window['napplet']?.${joined('sh', 'ell')}`,
`window['napplet']['${joined('sh', 'ell')}']`,
`${joined('discover', 'Services')}()`,
`${joined('has', 'Service', 'Version')}('relay', '1')`,
];
for (const [index, example] of retiredExamples.entries()) {
assert.match(example, patterns[index]);
}
for (const [path, source] of sources) {
for (const pattern of patterns) assert.doesNotMatch(source, pattern, path);
}
});
test('keeps normal Nostr examples OUTBOX-first', () => {
const main = sources.get('src/main.ts');
const patterns = ['query', 'subscribe', 'publish'].map(
(operation) => new RegExp(['relay', operation].join('\\.') + '\\s*\\('),
);
for (const pattern of patterns) assert.doesNotMatch(main, pattern);
const joined = (...parts) => parts.join('');
const directCallPatterns = [
new RegExp(`window(?:\\.|\\?\\.)napplet(?:\\.|\\?\\.)[A-Za-z_$][\\w$]*(?:\\.|\\?\\.)[A-Za-z_$][\\w$]*\\s*\\(`),
new RegExp(`window\\s*\\[\\s*['\"]napplet['\"]\\s*\\]\\s*\\[\\s*['\"][^'\"]+['\"]\\s*\\]\\s*(?:\\.|\\?\\.)[A-Za-z_$][\\w$]*\\s*\\(`),
];
const directCallExamples = [
`window?.napplet?.storage.${joined('get', 'Item')}('key')`,
`window['napplet']['outbox'].${joined('qu', 'ery')}([])`,
];
for (const [index, example] of directCallExamples.entries()) {
assert.match(example, directCallPatterns[index]);
}
for (const [path, source] of sources) {
if (!path.startsWith('src/')) continue;
for (const pattern of directCallPatterns) assert.doesNotMatch(source, pattern, path);
}
const designPatterns = sources.get('docs/design-patterns.md');
assert.match(designPatterns, /OUTBOX-first/i);
assert.match(designPatterns, /relay-local escape hatch/i);
});
test('ships no forked skill body, points agents at skills.sh, and keeps manifest config on documented surface', () => {
const skillBodies = [...sources.keys()].filter((path) => /(?:^|\/)SKILL\.md$/.test(path));
assert.deepEqual(skillBodies, []);
for (const path of ['AGENTS.md', 'README.md']) {
assert.match(sources.get(path), /npx skills add napplet\/napplet/, path);
}
const retiredInstallers = new RegExp(
[['@napplet', 'skills'].join('/'), ['napplet skills', 'install'].join(' '), ['.codex', 'skills'].join('/')]
.map((text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
.join('|'),
);
for (const [path, source] of sources) {
assert.doesNotMatch(source, retiredInstallers, path);
}
const viteConfig = sources.get('vite.config.ts');
assert.match(viteConfig, /artifactMode:\s*'single-file'/);
// `requires` is allowed once a product has a core task that cannot run
// without a domain, but it must stay a list of bare domain names.
const requires = viteConfig.match(/\brequires\s*:\s*\[([^\]]*)\]/);
if (requires) {
const entries = requires[1].split(',').map((entry) => entry.trim()).filter(Boolean);
assert.ok(entries.length > 0, 'requires must not be an empty list; omit it instead');
for (const entry of entries) {
assert.match(entry, /^['"][a-z][a-z0-9-]*['"]$/, `requires entry ${entry} must be a bare domain name`);
}
}
assert.doesNotMatch(viteConfig, /\bconfigSchema\b/);
assert.equal(JSON.parse(sources.get('config.schema.json')).type, 'object');
const retiredSingleFilePlugin = new RegExp(['vite-plugin', 'singlefile'].join('-'));
for (const source of sources.values()) assert.doesNotMatch(source, retiredSingleFilePlugin);
});
test('keeps deferred domains out of active package surfaces', () => {
const joined = (...parts) => parts.join('');
const domains = [joined('con', 'nect'), joined('cl', 'ass')];
for (const domain of domains) {
const patterns = [
new RegExp(`@napplet/nap/${domain}\\b`),
new RegExp(`window(?:\\.|\\?\\.)napplet(?:\\.|\\?\\.)${domain}\\b`),
new RegExp(`window\\s*\\[\\s*['\"]napplet['\"]\\s*\\]\\s*\\[\\s*['\"]${domain}['\"]\\s*\\]`),
new RegExp(`import\\s*\\{[^}]*\\b${domain}\\b[^}]*\\}\\s*from\\s*['\"]@napplet/sdk['\"]`),
new RegExp(`\\b${domain.toUpperCase()}_DOMAIN\\b`),
new RegExp(`\\b${domain}\\s*(?:\\.|\\?\\.)[A-Za-z]\\w*\\s*\\(`),
new RegExp(`\\brequires\\s*:\\s*\\[[^\\]]*['\"]${domain}['\"]`),
];
const examples = [
`@napplet/nap/${domain}`,
`window?.napplet?.${domain}`,
`window['napplet']['${domain}']`,
`import { ${domain} } from '@napplet/sdk'`,
`${domain.toUpperCase()}_DOMAIN`,
`${domain}.request()`,
`requires: ['${domain}']`,
];
for (const [index, example] of examples.entries()) {
assert.match(example, patterns[index]);
}
for (const [path, source] of sources) {
for (const pattern of patterns) assert.doesNotMatch(source, pattern, path);
}
}
for (const label of [joined('NAP-', 'CON', 'NECT'), joined('NAP-', 'CLASS')]) {
for (const [path, source] of sources) {
if (source.includes(label)) assert.match(source, /deferred|retired/i, path);
}
}
});
test('treats injected optional-domain absence as a normal state', async () => {
const helperSource = await readFile(join(root, 'src/domain-availability.ts'), 'utf8');
const compiled = ts.transpileModule(helperSource, {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
}).outputText;
const module = { exports: {} };
runInNewContext(compiled, { module, exports: module.exports });
const { hasDomain } = module.exports;
assert.equal(hasDomain(undefined, 'outbox'), false);
assert.equal(hasDomain({}, 'outbox'), false);
assert.equal(hasDomain({ outbox: null }, 'outbox'), false);
assert.equal(hasDomain({ outbox: {} }, 'outbox'), true);
assert.equal(hasDomain(Object.create({ outbox: {} }), 'outbox'), true);
// Product code may replace every demo control; it must keep gating optional
// domains through the injected-namespace check instead of a probe API.
const main = sources.get('src/main.ts');
assert.match(main, /from '\.\/domain-availability\.js'/);
assert.match(main, /runtimeHasDomain\(/);
});
test('keeps the applet layout contract: no title header, frame-filling root', () => {
const html = sources.get('index.html');
const title = html.match(/<title>([^<]*)<\/title>/)?.[1]?.trim();
assert.ok(title, 'index.html keeps a <title> for metadata');
const escaped = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
// The runtime shows the napplet's name; do not repeat it as a heading.
assert.doesNotMatch(html, new RegExp(`<h[1-6][^>]*>\\s*${escaped}\\s*<`));
assert.doesNotMatch(html, /class="[^"]*\b(?:masthead|eyebrow|hero)\b/);
const css = sources.get('src/styles.css');
assert.doesNotMatch(css, /\bbody\s*\{[^}]*min-width/);
assert.match(css, /html,\s*body,\s*#app\s*\{[^}]*height:\s*100%/);
});
const stationModule = { exports: {} };
runInNewContext(ts.transpileModule(sources.get('src/station.ts'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
}).outputText, { module: stationModule, exports: stationModule.exports, URL });
const { parseStation, STATION_ADDRESS } = stationModule.exports;
const stationEvent = (streams) => ({
id: 'a'.repeat(64), pubkey: STATION_ADDRESS.pubkey, kind: STATION_ADDRESS.kind,
created_at: 1, tags: [['d', STATION_ADDRESS.identifier], ['name', 'Drone Zone']],
content: JSON.stringify({ streams }), sig: '0'.repeat(128),
});
test('station streams prefer HTTPS and the primary source with real bitrate metadata', () => {
const parsed = parseStation(stationEvent([
{url:'http://example.org/radio',primary:true},
{url:'https://example.org/secondary',format:'audio/aac'},
{url:'https://example.org/primary',primary:true,format:'audio/mpeg',quality:{bitrate:256000}},
]));
assert.equal(parsed.url, 'https://example.org/primary');
assert.equal(parsed.bitrate, 256000);
assert.equal(parsed.mimeType, 'audio/mpeg');
});
test('station parsing rejects foreign coordinates, malformed JSON, and executable stream URLs', () => {
const event = stationEvent([{url:'https://example.org/radio'}]);
assert.throws(() => parseStation({...event, pubkey:'f'.repeat(64)}), /address/);
assert.throws(() => parseStation({...event, kind:1}), /address/);
assert.throws(() => parseStation({...event, tags:[['d','different']]}), /address/);
assert.throws(() => parseStation({...event, content:'broken'}), /metadata/);
assert.throws(() => parseStation(stationEvent([{url:'javascript:alert(1)'},{url:'https://user:pass@example.org/audio'}])), /usable/);
});
const geometryModule = { exports: {} };
runInNewContext(ts.transpileModule(sources.get('src/field-data.ts'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
}).outputText, { module: geometryModule, exports: geometryModule.exports });
const {createRoutes, createCamera, projectPoint, navigation, createSystems, orbitPoint,
createTransit, advanceTransit, principalHighway, sampleRoute, tourRange, createDetours, updateDetour, routeAtX} = geometryModule.exports;
const routes = createRoutes();
test('all highway ends remain outside every permitted view, with monotonic projection for clipping', () => {
for(const [width,height] of [[200,160],[320,560],[900,600],[2400,1200],[3840,2160]])
for(const x of [-navigation.panX,0,navigation.panX])
for(const y of [-navigation.panY,0,navigation.panY])
for(const look of [{x:-1,y:-1},{x:1,y:1},{x:-1,y:1},{x:1,y:-1}]) {
const camera=createCamera(width,height,{x,y},look,navigation.minZoom,1);
for(const route of routes) {
const first=projectPoint(route.samples[0],camera),last=projectPoint(route.samples.at(-1),camera);
assert.ok(first.x<-100&&last.x>width+100, `${route.label}: endpoints visible`);
let previous=-Infinity;
for(let i=0;i<route.samples.length;i+=32) {
const p=projectPoint(route.samples[i],camera);
assert.ok(p.x>previous, 'screen x must be monotonic for range clipping');previous=p.x;
}
}
}
for(let t=tourRange.center-tourRange.radius;t<=tourRange.center+tourRange.radius;t+=.001) {
const p=sampleRoute(principalHighway,t);
assert.ok(Math.abs(p.x)<navigation.panX&&Math.abs(p.y)<navigation.panY,'tour respects navigation bounds');
}
});
test('highways have one broad inflection and fine enough samples for close inspection', () => {
assert.ok(routes.length<80,'keep the field calm');
assert.equal(routes.filter(r=>r.gaps.length).length,3,'breaks stay rare');
for(const {samples,label} of routes) {
let lastSign=0,inflections=0;
for(let i=1;i<samples.length-1;i++) {
const a=samples[i-1],b=samples[i],c=samples[i+1];
const turn=Math.atan2(c.y-b.y,c.x-b.x)-Math.atan2(b.y-a.y,b.x-a.x);
assert.ok(Math.abs(turn)<.006, `${label} has a visible corner`);
if(Math.abs(turn)>1e-7) {const sign=Math.sign(turn);if(lastSign&&sign!==lastSign)inflections++;lastSign=sign;}
}
assert.ok(inflections<=1,`${label} changes curvature too often`);
}
});
test('planetary orbits close with a continuous tangent and have real depth', () => {
for(const system of createSystems()) for(const orbit of system.orbits) {
const first=orbitPoint(orbit,0),last=orbitPoint(orbit,Math.PI*2);
assert.ok(Math.hypot(first.x-last.x,first.y-last.y,first.z-last.z)<1e-9);
const before=orbitPoint(orbit,-.0001),after=orbitPoint(orbit,.0001);
const a=[first.x-before.x,first.y-before.y,first.z-before.z];
const b=[after.x-first.x,after.y-first.y,after.z-first.z];
assert.ok(a.reduce((sum,v,i)=>sum+v*b[i],0)/(Math.hypot(...a)*Math.hypot(...b))>.999999);
const front=orbitPoint(orbit,Math.PI*.5),back=orbitPoint(orbit,Math.PI*1.5);
assert.ok(front.z-back.z>40);
}
});
test('hypertravel flashes once at entry, crosses at 22x speed, then resumes cruise without a jump', () => {
const route=routes[0],[entry,exit]=route.gaps[0];
const state=createTransit(route);state.t=entry-route.speed*.2;
advanceTransit(state,route,.3);
assert.ok(state.warping);
assert.ok(Math.abs(state.t-(entry+route.speed*22*.1))<1e-9);
assert.ok(Math.abs(state.flash-.24)<1e-9);
advanceTransit(state,route,.05);
assert.ok(Math.abs(state.flash-.19)<1e-9,'no repeated entry flash while inside');
const untilExit=(exit-state.t)/(route.speed*22);
advanceTransit(state,route,untilExit+.1);
assert.equal(state.warping,false);
assert.ok(Math.abs(state.t-(exit+route.speed*.1))<1e-9);
const frozen=state.t;advanceTransit(state,route,0);assert.equal(state.t,frozen);
// Integration gives the same position across different animation frame sizes.
const coarse=createTransit(route),fine=createTransit(route);
advanceTransit(coarse,route,25);
for(let i=0;i<2500;i++)advanceTransit(fine,route,.01);
assert.ok(Math.abs(coarse.t-fine.t)<1e-9);
});
test('one lane per system follows its moving planet smoothly and rejoins the highway', () => {
const dynamicRoutes=createRoutes(),originalTour=JSON.stringify(dynamicRoutes[0]);
const detours=createDetours(dynamicRoutes,createSystems());
assert.equal(dynamicRoutes.length,65,'detours reuse existing lanes');
assert.equal(new Set(detours.map(d=>d.route)).size,6,'one distinct lane per system');
assert.equal(JSON.stringify(dynamicRoutes[0]),originalTour,'the principal tour path stays intact');
assert.equal(detours.filter(d=>d.route.gaps.length).length,3);
for(const detour of detours) {
const {route,source,orbit,first,last}=detour;
const start=JSON.stringify(source[0]),end=JSON.stringify(source.at(-1));
const body0=orbitPoint(orbit,orbit.phase),t0=routeAtX(route.samples,body0.x);
const initial=sampleRoute(route.samples,t0);
for(let step=0;step<=12;step++) {
const time=step/12*Math.PI*2/orbit.speed;
updateDetour(detour,time);
const body=orbitPoint(orbit,orbit.phase+time*orbit.speed);
const contact=sampleRoute(route.samples,routeAtX(route.samples,body.x));
assert.ok(Math.hypot(contact.x-body.x,contact.y-body.y,contact.z-body.z)<.06,'route must meet the actual moving body in 3D');
assert.equal(JSON.stringify(route.samples[0]),start);
assert.equal(JSON.stringify(route.samples.at(-1)),end);
for(const i of [first,first+1,last-1,last])assert.equal(JSON.stringify(route.samples[i]),JSON.stringify(source[i]),'join shoulders stay on the original highway');
// Project the complete detour at the extreme camera angles used for clipping.
for(const sign of [-1,1]) {
const camera=createCamera(3840,2160,{x:sign*2400,y:sign*1550},{x:sign,y:-sign},3.6,1);
let x=-Infinity;
for(let i=first;i<=last;i++) {const p=projectPoint(route.samples[i],camera);assert.ok(p.x>x,'moving detour remains monotonic for clipping');x=p.x;}
}
}
updateDetour(detour,Math.PI/orbit.speed);
const moved=sampleRoute(route.samples,t0);
assert.ok(Math.hypot(moved.y-initial.y,moved.z-initial.z)>5,'the transfer deforms as the planet moves');
}
});
test('extended hyper gaps have stable, varied lengths between three and four times the originals', () => {
const first=createRoutes(),second=createRoutes();
const gaps=first.filter(route=>route.gaps.length).map(route=>route.gaps[0]);
assert.equal(JSON.stringify(gaps),JSON.stringify(second.filter(route=>route.gaps.length).map(route=>route.gaps[0])));
const multipliers=gaps.slice(1).map(([a,b],i)=>(b-a)/(i===0?.009:.008));
assert.ok(multipliers.every(m=>m>=3&&m<4));assert.notEqual(multipliers[0],multipliers[1]);
for(const route of first.filter(r=>r.gaps.length)) {
const [a,b]=route.gaps[0],state=createTransit(route);state.t=a;
advanceTransit(state,route,(b-a)/(route.speed*22)+.12);
assert.equal(state.warping,false);assert.ok(Math.abs(state.t-b-route.speed*.12)<1e-9);
}
});