by adom
The hero-image lab with a human gate: `hero-studio pose <owner/slug>` opens the studio in front of the human, posed for their package, and blocks until they click Generate, producing the provenance-stamped 2000x1250 PNG the registry's hero gate requires. The image carries the title and artwork; the exported image also bakes the type pill (top right) and full wiki slug (bottom right); the page shows the hero bare, and only the homepage marquee overlays its own dynamic info. Every hero wears its P
master
Colby Knox
Full test suite in the page repo: npm test runs here (the published package carries only test/brand.mjs)
625499c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
#!/usr/bin/env node
// Posing from a plain terminal (hero-studio#72): node test/pose-surface.mjs
//
// A terminal on a cloud container has no VS Code proxy, the desktop bridge
// lists other bridges' verbs before pup's, and a surface can fail to open
// while the gate itself works. These checks pin each fix:
// - the bridge adapter picks pup_* (or browser_*) verbs, never altium_status,
// fusion_status or the native-browser extension's nbrowser_open_window;
// - an ambiguous desktop reads as "pass --target", not as "did not answer";
// - --url / HERO_STUDIO_URL outrank the VS Code proxy;
// - with no URL at all, pose refuses before anything is posed;
// - when no surface opens, pose keeps waiting with the URL, and with
// --no-fallback it closes the gate it opened and exits 3.
import { spawn } from 'child_process';
import fs from 'fs';
import os from 'os';
import net from 'net';
import path from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const require = createRequire(import.meta.url);
const { resolveVerbs, bridgeTrouble } = await import(path.join(ROOT, 'bridge.mjs'));
const PLAT = require(path.join(ROOT, 'platform.cjs'));
let pass = 0; const fails = [];
const ok = (name, cond, detail) => { if (cond) { pass++; console.log(' ok ' + name); } else { fails.push(name); console.log(' FAIL ' + name + (detail ? ': ' + detail : '')); } };
// --- verb resolution, in the order a real bridge_list prints them ---
const listed = 'altium_status altium_eval hd_status hd_open_url kicad_status fusion_status nbrowser_status nbrowser_open_window nbrowser_navigate nbrowser_screenshot nbrowser_eval pup_alert_window pup_status pup_open_window pup_navigate pup_eval pup_screenshot';
const v = resolveVerbs(listed);
ok('status resolves to pup_status, not altium_status or fusion_status', v.status === 'pup_status', v.status);
ok('open_window resolves to pup_open_window, not the extension', v.open_window === 'pup_open_window', v.open_window);
ok('navigate resolves to pup_navigate', v.navigate === 'pup_navigate', v.navigate);
const older = resolveVerbs('fusion_status nbrowser_open_window browser_open_window browser_status');
ok('an older box answers browser_*', older.open_window === 'browser_open_window' && older.status === 'browser_status', JSON.stringify(older));
ok('nothing listed falls back to pup_*', resolveVerbs('').open_window === 'pup_open_window');
// --- reading a bridge answer ---
const amb = { ok: false, out: '{"error":"ambiguous_target","connected":["A","B"]}', errOut: '', fail: 'exit 1' };
ok('ambiguous_target says to pass --target', /--target/.test(bridgeTrouble(amb)), bridgeTrouble(amb));
ok('a clean answer is no trouble', bridgeTrouble({ ok: true, out: '{"ok":true}', errOut: '' }) === '');
ok('an error answer names the error', bridgeTrouble({ ok: true, out: '{"error":"not_running"}', errOut: '' }) === 'not_running');
// --- the studio URL ---
const saved = { h: process.env.HERO_STUDIO_URL, v: process.env.VSCODE_PROXY_URI };
delete process.env.HERO_STUDIO_URL; delete process.env.VSCODE_PROXY_URI;
ok('no URL anywhere is null', PLAT.studioUrl(8846) === null);
process.env.VSCODE_PROXY_URI = 'https://x.example/proxy/{{port}}';
ok('the VS Code proxy template fills the port', PLAT.studioUrl(8846) === 'https://x.example/proxy/8846/', PLAT.studioUrl(8846));
process.env.HERO_STUDIO_URL = 'https://studio-abc.adom.cloud';
ok('HERO_STUDIO_URL outranks the proxy and gains a slash', PLAT.studioUrl(8846) === 'https://studio-abc.adom.cloud/', PLAT.studioUrl(8846));
if (saved.h === undefined) delete process.env.HERO_STUDIO_URL; else process.env.HERO_STUDIO_URL = saved.h;
if (saved.v === undefined) delete process.env.VSCODE_PROXY_URI; else process.env.VSCODE_PROXY_URI = saved.v;
// --- pose itself ---
const freePort = () => new Promise((res) => { const s = net.createServer().listen(0, () => { const p = s.address().port; s.close(() => res(p)); }); });
// A fake adom-cli with no Hydrogen panes, so no real webview tab is touched.
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hs-pose-'));
const fakeBin = path.join(tmp, 'bin'); fs.mkdirSync(fakeBin);
fs.writeFileSync(path.join(fakeBin, 'adom-cli'), '#!/bin/sh\necho \'{"tabs":[]}\'\n', { mode: 0o755 });
const baseEnv = { ...process.env, PATH: fakeBin + ':' + (process.env.PATH || ''), ADOM_AI_THREAD: 'pose-surface test' };
delete baseEnv.VSCODE_PROXY_URI; delete baseEnv.HERO_STUDIO_URL; delete baseEnv.HERO_STUDIO_PORT;
const pose = (args, env, ms = 120000) => new Promise((res) => {
const p = spawn(process.execPath, [path.join(ROOT, 'pose.mjs'), ...args], { env, stdio: ['ignore', 'pipe', 'pipe'] });
let err = '';
p.stderr.on('data', (d) => { err += d; });
const t = setTimeout(() => p.kill(), ms);
p.on('close', (code) => { clearTimeout(t); res({ code, err }); });
});
const servers = [];
try {
let r = await pose(['adom/hero-studio', '--surface', 'pup', '--no-local'], baseEnv, 20000);
ok('no URL: pose refuses with NO_CONTAINER_PROXY and exit 1', r.code === 1 && /NO_CONTAINER_PROXY/.test(r.err), r.code + ' ' + r.err.slice(0, 200));
ok(' and says nothing was posed, with the port-mapping recipe', /Nothing was posed/.test(r.err) && /port-add/.test(r.err) && /--url/.test(r.err));
const port = await freePort(); servers.push(port);
r = await pose(['adom/hero-studio', '--surface', 'webview', '--no-local', '--port', String(port), '--url', 'http://127.0.0.1:' + port + '/', '--timeout', '4'], baseEnv);
ok('no surface opens: pose keeps waiting at the URL and times out (exit 2), not exit 1', r.code === 2, r.code + ' ' + r.err.slice(-300));
ok(' and prints the URL to open', r.err.includes('NOT OPENED [NO_WEBVIEW_PANE]') && r.err.includes('http://127.0.0.1:' + port + '/'), r.err.slice(-400));
let st = await (await fetch('http://127.0.0.1:' + port + '/state')).json();
ok(' the gate stays open for whoever opens the URL', st.verify === true && st.page === 'adom/hero-studio', JSON.stringify({ verify: st.verify, page: st.page }));
r = await pose(['adom/hero-studio', '--surface', 'webview', '--no-local', '--port', String(port), '--url', 'http://127.0.0.1:' + port + '/', '--steal', '--no-fallback'], baseEnv);
ok('--no-fallback: exit 3 when no surface opens', r.code === 3, r.code + ' ' + r.err.slice(-300));
st = await (await fetch('http://127.0.0.1:' + port + '/state')).json();
ok(' and the gate it opened is closed again', st.verify === false, JSON.stringify({ verify: st.verify }));
r = await pose(['adom/hero-studio', '--surface', 'webview', '--no-local', '--port', String(port), '--url', 'http://127.0.0.1:' + port + '/', '--timeout', '3'], baseEnv);
ok(' so the next pose is not POSE_BUSY', r.code !== 4 && !/POSE_BUSY/.test(r.err), r.code + ' ' + r.err.slice(-200));
} finally {
// stop the studios these poses started, by their instance files' exact pids
const dir = path.join(os.homedir(), '.adom', 'instances', 'hero-studio');
try {
for (const f of fs.readdirSync(dir)) {
if (!f.endsWith('.json')) continue;
try {
const e = JSON.parse(fs.readFileSync(path.join(dir, f), 'utf8'));
if (servers.includes(Number(e.port)) && e.thread === 'pose-surface test') process.kill(e.pid);
} catch {}
}
} catch {}
fs.rmSync(tmp, { recursive: true, force: true });
}
console.log('\n' + pass + ' passed, ' + fails.length + ' failed');
process.exit(fails.length ? 1 : 0);