Files
buzz/beehive/test/manager-installed-fixture.ts
Logan Johnson 9aef40a3f6 fix(beehive): derive first-use owner directly from Buzz key
Bypass manual routing for Buzz sign-in, derive and validate identity in the controller, and initialize only public owner routing using the current Host relay after the stale/cancel fence. Retained owners still must match; custody remains session-only.

Regression drives the real Node/Bun UI once with no controller owner configured and an explicit synthetic credential fixture. Focused 12-test checks, typecheck, and first-use PTY walkthrough pass. Earlier broad-suite 400-second failure remains unresolved; no production Keychain access or native rebuild.

Signed-off-by: Logan Johnson <loganj@squareup.com>
2026-09-16 13:22:09 -04:00

43 lines
3.4 KiB
TypeScript

import { readBuzzOwnerKey, buzzOwnerKeyErrors } from '../src/buzz-owner-key.ts';
import { nip19 } from 'nostr-tools';
import { registerAgent, agentNsec, addOpenAI, addProvider } from '../src/settings-credentials.ts';
import type { CredentialReference } from '../src/credential-store.ts';
import { bootstrapHostIdentity } from '../src/host-identity.ts';
import { isolatedFileCredentials } from './isolated-file-credentials.ts';
import { createCredential, credentialReference, readCredential } from '../src/credential-store.ts';
import { publicKey } from '../src/protocol.ts';
import type { managementClient } from '../src/intents.ts';
/** Installed-launcher smoke ONLY: explicit synthetic credential file and zero transport. */
export async function fixtureCredential(input: any, signal: AbortSignal) {
signal.throwIfAborted();
const backend = isolatedFileCredentials(process.env.BEEHIVE_TEST_CREDENTIAL_FILE!);
if (input.action === 'configure') {
bootstrapHostIdentity(input.directory,input.label,input.owner,input.relay,backend);
return { ok: true };
}
if (input.action === 'register-agent') { registerAgent(input.directory,agentNsec(input.secret),backend,input.profile,input.runtimeId,input.expectedRevision); return { ok: true }; }
if (input.action === 'add-openai') { addOpenAI(input.directory,input.name,input.secret,{ read: r => backend.read(r as unknown as CredentialReference), create: (r,s) => backend.create(r as unknown as CredentialReference,s) }); return { ok: true }; }
if (input.action === 'add-provider') { addProvider(input.directory,input.name,input.secret,{read:r=>backend.read(r as unknown as CredentialReference),create:(r,s)=>backend.create(r as unknown as CredentialReference,s)},input.type,input.endpoint,input.wire); return {ok:true}; }
if (input.action === 'models') return { ok: true, models: ['fixture-model'] };
if (input.action === 'signin-buzz') {
// Test-only pacing so a PTY driver can observe the pending state and exercise
// Esc cancellation deterministically; inert unless the driver sets it.
const paced = Number(process.env.BEEHIVE_TEST_SIGNIN_DELAY_MS ?? '0');
if (paced > 0) await new Promise((resolve, reject) => { const timer = setTimeout(resolve, paced); signal.addEventListener('abort', () => { clearTimeout(timer); reject(signal.reason); }, { once: true }); });
const key = backend.read(credentialReference('owner', process.env.BEEHIVE_TEST_BUZZ_OWNER ?? input.owner));
const result = readBuzzOwnerKey(input.owner, () => key === null ? null : JSON.stringify({identity:nip19.nsecEncode(Buffer.from(key,'hex'))}));
if (!result.ok) throw Error(buzzOwnerKeyErrors[result.reason]);
return result;
}
if (input.action !== 'signin') throw Error('Unsupported installed fixture action');
if (input.secret) {
if (publicKey(input.secret) !== input.owner) throw Error('Wrong fixture owner');
createCredential('owner',input.secret,backend);
}
const reference = credentialReference('owner',input.owner);
return { ok: true, secret: backend.read(reference) === null ? null : readCredential(reference,backend) };
}
/** Never opens a socket, even if a supplied fixture URL is accidentally real. */
export const disconnectedTransport = (() => ({ ready: Promise.resolve(), connected: false, status: () => [], close() {}, reconcile() {}, submit() { throw Error('Explicit fixture transport is disconnected'); } })) as unknown as typeof managementClient;