{"version":3,"file":"testing.mjs","names":["platform.handshake"],"sources":["../src/testing/run.ts","../src/testing/plugin-client.ts"],"sourcesContent":["/**\n * `run`: one payload answered in-process, as exec answers the agent's\n * delivery, and what came of it: the answer, what the worker would print,\n * what reached the platform, what was logged and how each step ended.\n * Nothing leaves the process: the platform is a recording one, answering as\n * `respond` says, and tracing is off unless a port is given. The run's\n * settings are the ones given, else the defaults: nothing reads the\n * environment.\n *\n * A route's name answers the route's sample, the payload tooling offers for\n * it; a payload answers as it is. `with` is laid over either, field by field\n * however deep, on a copy: neither the sample nor the payload given changes.\n */\n\nimport { recordingPlatform, type RecordedRequest, type RecordingOptions } from \"../core/api\";\nimport type { Failure } from \"../core/errors\";\nimport { recordingLog, type Logger, type RunLog } from \"../core/logger\";\nimport { merged } from \"../core/merge\";\nimport { deliveryOf, type Payload } from \"../core/payload\";\nimport type { AnswerPorts } from \"../core/run/context\";\nimport type { Plugin } from \"../core/run/plugin\";\nimport { settingsOf, type Settings } from \"../core/settings\";\nimport { noopTracing } from \"../core/tracing/port\";\nimport type { StepObserver } from \"../core/tracing/step\";\nimport { tracerOf, type TracingPort } from \"../core/tracing/sdk\";\nimport { answerDocument, printed, type PrintableAnswer } from \"../core/transport/exec\";\nimport type { OwnPortsArgument } from \"../core/transport/ports\";\n\n/** How a payload is run. */\nexport interface RunOptions<Own extends object = {}> {\n  /** Laid over the payload, field by field however deep: the route's sample, or the payload given. */\n  with?: Record<string, unknown>;\n  /** What answers each platform call; `200 {}` unless given. */\n  respond?: RecordingOptions[\"respond\"];\n  /** The run's settings (contract/settings.json), each the one given or its default: the handler gets their platform credentials, `context.credentials`. */\n  settings?: Partial<Settings>;\n  /** The project's own ports: `context.ports`. */\n  ports?: Own;\n  /** Aborted to cancel the run; never unless given. */\n  signal?: AbortSignal;\n  /** Where the run is traced: `noopTracing` unless given, whatever the settings say. */\n  tracing?: TracingPort;\n}\n\n/** How a step ended, and how long it took. */\nexport interface RunStep {\n  /** The step's name, its key on the trace. */\n  key: string;\n  status: \"completed\" | \"failed\";\n  durationMs: number;\n}\n\n/** What came of a run. */\nexport interface RunResult {\n  /** Whether it succeeded: the worker's exit, 0 when it did. */\n  success: boolean;\n  /** What the handler returned, when it succeeded and returned anything. */\n  data?: unknown;\n  /** How it failed, when it did. */\n  failure?: Failure;\n  /** What the worker prints for the answer, as exec prints it. */\n  stdout: string;\n  /** What reached the platform, in order. */\n  requests: RecordedRequest[];\n  /** What was logged, every level, in order. */\n  logs: RunLog[];\n  /** How each step ended, in the order they ended. */\n  steps: RunStep[];\n}\n\n/** The sample of the route `name` names; a name of no route with one is refused, naming the routes that have one. */\nfunction sampleOf<Own extends object>(plugin: Plugin<Own>, name: string): Payload {\n  const sampled = plugin.routes.filter((route) => route.sample !== undefined);\n  const sample = sampled.find((route) => route.name === name)?.sample;\n  if (sample === undefined) {\n    const named = sampled.length === 0 ? \"none has one\" : `these have one: ${sampled.map((route) => route.name).join(\", \")}`;\n    throw new Error(`run: \"${name}\" names no route of ${plugin.package.name} with a sample (${named})`);\n  }\n  return sample;\n}\n\n/** The ports a run of `settings` answers with: the platform's calls through `fetch`, its log, its own ports, its signal and tracer, each step told to `observeStep`. */\nfunction portsOf<Own extends object>(options: RunOptions<Own>, settings: Settings, fetch: AnswerPorts[\"fetch\"], log: Logger, observeStep: StepObserver): AnswerPorts<Own> {\n  return {\n    settings,\n    fetch,\n    log,\n    signal: options.signal ?? new AbortController().signal,\n    ports: options.ports ?? ({} as Own),\n    tracer: tracerOf(options.tracing ?? noopTracing, { log, settings }),\n    observeStep,\n  };\n}\n\n/** What came of `answer`, with what the run recorded. */\nfunction resultOf(answer: PrintableAnswer, recorded: Pick<RunResult, \"requests\" | \"logs\" | \"steps\">): RunResult {\n  const { output, success } = printed(answer);\n  const { data, failure } = answer;\n  return { success, ...(data !== undefined && { data }), ...(failure !== undefined && { failure }), stdout: output, ...recorded };\n}\n\n/**\n * Answers `request`, a route's name or a payload, with `with` laid over it, as\n * exec answers the document the agent delivers it in, and says what came of\n * it; the plugin's own ports required when it needs them. A name of no route\n * with a sample is refused.\n */\nexport async function run<Own extends object = {}>(plugin: Plugin<Own>, request: string | Payload, ...[given]: OwnPortsArgument<Own, RunOptions<Own>, RunOptions<Own> & { ports: Own }>): Promise<RunResult> {\n  const options: RunOptions<Own> = given ?? {};\n  const payload = merged(typeof request === \"string\" ? sampleOf(plugin, request) : request, options.with ?? {});\n  const settings = settingsOf(options.settings);\n  const platform = recordingPlatform({ respond: options.respond, apiUrl: settings.apiUrl });\n  const { log, logs } = recordingLog();\n  const steps: RunStep[] = [];\n  const observeStep: StepObserver = (key, outcome) => {\n    steps.push({ key, ...outcome });\n  };\n  const answer = await answerDocument(plugin, deliveryOf(payload), portsOf(options, settings, platform.fetch, log, observeStep));\n  return resultOf(answer, { requests: platform.requests, logs, steps });\n}\n","/**\n * The agent's side of a plugin process, for tests and tooling (the dev UI).\n * `startPluginProcess` starts a plugin's entry point as the agent starts a\n * worker, the agent's cookie in its environment and no listen address, reads\n * the handshake that names its unix socket (the first line of its stdout that\n * is not blank, as platform.json has it, within the agent's bound) and dials\n * it. The client asks what the plugin declares (`Capabilities`) and sends\n * each payload as the agent's Execute, with the command type the plugin\n * declares first unless told another: the plugin answers by the document it\n * is handed, the command type is the agent's label for it.\n *\n * The plugin's own output after the handshake is teed to this process's\n * stdout and stderr, and forwarded as output events to every execute that\n * streams while it comes: each keeps its own forwarding until it ends, since\n * the plugin's own output names no call.\n */\n\nimport * as grpc from \"@grpc/grpc-js\";\nimport { dirname, resolve } from \"path\";\nimport platform from \"../../../contract/platform.json\" with { type: \"json\" };\nimport { written } from \"../core/logger\";\nimport { agentVariableOf } from \"../core/settings\";\nimport { jsonOr } from \"../core/text\";\nimport { AGENT_PROTOCOL } from \"../core/transport/agent\";\nimport { loadPluginProto, type LoadedProto } from \"../core/transport/proto\";\nimport { within } from \"../core/within\";\n\n/** An event of an Execute, as the agent reads it; an output event the test client forwards from the plugin's own output carries no data. */\nexport interface PluginTestEvent {\n  started?: {};\n  output?: {\n    stdout: string;\n    stderr: string;\n    /** What the plugin streamed beside its text, as bytes (JSON when it is a document); none for its own output. */\n    data: Buffer | null;\n  };\n  result?: {\n    success: boolean;\n    data: Buffer;\n    error: string;\n    error_code: string;\n    exit_code: number;\n  };\n}\n\n/** Every event of an Execute, and its result, its data parsed as JSON; no result when none came. */\nexport interface ExecuteResponse {\n  events: PluginTestEvent[];\n  result: {\n    success: boolean;\n    data: unknown;\n    error: string;\n    errorCode: string;\n    exitCode: number;\n  } | null;\n}\n\n/** Told each event of an Execute as it comes. */\nexport type EventCallback = (event: PluginTestEvent) => void;\n\n/** How an Execute is sent: the command type (the plugin's first declared unless given) and the action type, the agent's labels. */\nexport interface ExecuteOptions {\n  commandType?: string;\n  actionType?: string;\n}\n\n/** A client of a plugin process, as the agent drives one. */\nexport interface PluginTestClient {\n  /** The command types the plugin declares to the agent. */\n  readonly commandTypes: string[];\n  /** Sends `payload` as the agent's Execute, and answers its events and its result once the call ends. */\n  execute(payload: unknown, options?: ExecuteOptions): Promise<ExecuteResponse>;\n  /** As `execute`, each event told to `onEvent` as it comes, the plugin's own output among them. */\n  executeStreaming(payload: unknown, onEvent: EventCallback, options?: ExecuteOptions): Promise<ExecuteResponse>;\n  /** Closes the connection and stops the plugin. */\n  stop(): void;\n}\n\n/** What a client drives beside its gRPC calls: the plugin's own output, forwarded while an execute streams, and how the plugin stops. */\nexport interface PluginProcess {\n  /** Forwards the plugin's own output to `callback`, beside any other, until what it answers is called. */\n  forward(callback: EventCallback): () => void;\n  stop(): void;\n}\n\n/** A plugin process, as a client drives it: its output and how it stops. */\nexport interface SpawnedPlugin {\n  stdout: ReadableStream<Uint8Array>;\n  stderr: ReadableStream<Uint8Array>;\n  kill(): void;\n}\n\n/** How a plugin process is started: Bun's spawn, unless a test gives another. */\nexport type Spawn = (command: string[], options: { cwd: string; env: Record<string, string | undefined> }) => SpawnedPlugin;\n\n/** A client of the agent's ExecutorPlugin service, as the contract loads it. */\nexport type ExecutorPluginClient = InstanceType<LoadedProto[\"npagent\"][\"plugin\"][\"v1\"][\"ExecutorPlugin\"]>;\n\n/** How long a client waits for the plugin's server to be ready. */\nconst READY_MS = 5_000;\n\n/** How long a plugin process has to print its handshake: the agent's own bound. */\nexport const HANDSHAKE_TIMEOUT_MS = 15_000;\n\n/** How a plugin process is started. */\nexport interface StartOptions {\n  /** Where it runs; its entry point's folder unless given. */\n  cwd?: string;\n  /** Laid over this process's environment. */\n  env?: Record<string, string>;\n  /** How long it has to print its handshake; HANDSHAKE_TIMEOUT_MS unless given. */\n  handshakeTimeoutMs?: number;\n}\n\n/** A plugin process started by Bun, its output piped to this one: the one adapter to a real process. */\nconst bunSpawn: Spawn = (command, options) => Bun.spawn(command, { ...options, stdout: \"pipe\", stderr: \"pipe\" });\n\n/** The agent's Execute request for `payload`: the command type the plugin declares first unless `options` names one. */\nexport function executeRequestOf(payload: unknown, declared: string[], options: ExecuteOptions = {}) {\n  return {\n    message_id: `test-${Date.now()}`,\n    command_type: options.commandType ?? declared[0] ?? \"\",\n    payload: Buffer.from(JSON.stringify(payload)),\n    supports_partial: true,\n    can_cancel: false,\n    reply_to: \"\",\n    action_type: options.actionType ?? \"\",\n  };\n}\n\n/** What `bytes` say as JSON; null when there are none or they are not JSON. */\nfunction jsonIn(bytes: Buffer): unknown {\n  return jsonOr(bytes.toString(\"utf-8\"), null);\n}\n\n/** The result `event` carries, its data parsed as JSON; none when it is not a result. */\nexport function executeResultOf(event: PluginTestEvent): ExecuteResponse[\"result\"] {\n  const sent = event.result;\n  if (sent === undefined) {\n    return null;\n  }\n  return { success: sent.success, data: jsonIn(sent.data), error: sent.error, errorCode: sent.error_code, exitCode: sent.exit_code };\n}\n\n/** Once `client` is ready to call, within READY_MS. */\nfunction ready(client: ExecutorPluginClient): Promise<void> {\n  return new Promise((resolve, reject) => {\n    client.waitForReady(Date.now() + READY_MS, (error?: Error) => (error ? reject(error) : resolve()));\n  });\n}\n\n/** What the plugin declares to the agent, its command types, within READY_MS: a plugin that never answers is refused when it passes. */\nfunction commandTypesOf(client: ExecutorPluginClient): Promise<string[]> {\n  return new Promise((resolve, reject) => {\n    const deadline = { deadline: Date.now() + READY_MS };\n    client.Capabilities({}, deadline, (error: Error | null, reply?: { command_types?: string[] }) => (error ? reject(error) : resolve(reply?.command_types ?? [])));\n  });\n}\n\n/**\n * Sends `request` as an Execute on `client`: every event until the call ends,\n * each told to `onEvent` as it comes, and the result. A callback that throws,\n * or whose promise rejects, loses its event, never the execute.\n */\nfunction executed(client: ExecutorPluginClient, request: ReturnType<typeof executeRequestOf>, onEvent?: EventCallback): Promise<ExecuteResponse> {\n  return new Promise((resolve, reject) => {\n    const call = client.Execute(request);\n    const events: PluginTestEvent[] = [];\n    let result: ExecuteResponse[\"result\"] = null;\n    call.on(\"data\", (event: PluginTestEvent) => {\n      events.push(event);\n      written(() => onEvent?.(event));\n      result = executeResultOf(event) ?? result;\n    });\n    call.on(\"end\", () => resolve({ events, result }));\n    call.on(\"error\", reject);\n  });\n}\n\n/** What the plugin on `client` declares, once it is ready; one it cannot reach is refused, the client closed and the plugin stopped. */\nasync function declaredBy(client: ExecutorPluginClient, plugin: PluginProcess): Promise<string[]> {\n  try {\n    await ready(client);\n    return await commandTypesOf(client);\n  } catch (error) {\n    client.close();\n    plugin.stop();\n    throw error;\n  }\n}\n\n/**\n * A client of the plugin served on `client`'s channel, once it is ready: it\n * asks what the plugin declares, then executes. A plugin it cannot reach is\n * refused, the client closed and the plugin stopped.\n */\nexport async function connectPlugin(client: ExecutorPluginClient, plugin: PluginProcess): Promise<PluginTestClient> {\n  const commandTypes = await declaredBy(client, plugin);\n  return {\n    commandTypes,\n    execute: (payload, options) => executed(client, executeRequestOf(payload, commandTypes, options)),\n    executeStreaming: async (payload, onEvent, options) => {\n      const stopForwarding = plugin.forward(onEvent);\n      try {\n        return await executed(client, executeRequestOf(payload, commandTypes, options), onEvent);\n      } finally {\n        stopForwarding();\n      }\n    },\n    stop: () => {\n      client.close();\n      plugin.stop();\n    },\n  };\n}\n\n/** A client of the plugin's ExecutorPlugin service on the unix socket `socketPath`: it connects on its first call. */\nexport function executorPluginClient(socketPath: string): ExecutorPluginClient {\n  const { ExecutorPlugin } = loadPluginProto().npagent.plugin.v1;\n  return new ExecutorPlugin(`unix://${socketPath}`, grpc.credentials.createInsecure());\n}\n\n/**\n * Each piece of text `stream` gives, decoded as UTF-8 across its chunks, until\n * it ends or fails: the plugin's output ends with it. A sequence it cuts short\n * is said as the replacement character, never dropped.\n */\nasync function* textsOf(stream: ReadableStream<Uint8Array>): AsyncGenerator<string> {\n  const decoder = new TextDecoder();\n  try {\n    for await (const chunk of stream) {\n      yield decoder.decode(chunk, { stream: true });\n    }\n  } catch {\n    // A stream that fails has ended.\n  }\n  const rest = decoder.decode();\n  if (rest !== \"\") {\n    yield rest;\n  }\n}\n\n/** The first whole line of `text` that is not blank, trimmed, and the text after it; none while `text` holds no such line. */\nfunction firstLineIn(text: string): { line: string; rest: string } | undefined {\n  const lines = text.split(\"\\n\");\n  const index = lines.slice(0, -1).findIndex((line) => line.trim() !== \"\");\n  if (index === -1) {\n    return undefined;\n  }\n  return { line: lines[index].trim(), rest: lines.slice(index + 1).join(\"\\n\") };\n}\n\n/** What `texts` gave before they ended, trimmed, when they end before a whole line that is not blank. */\ninterface CutShort {\n  cutShort: string;\n}\n\n/** The first whole line `texts` give that is not blank, trimmed, as the agent reads a handshake, and the text after it; what they gave, trimmed, when they end first: the agent refuses a line cut short. */\nasync function firstLineOf(texts: AsyncGenerator<string>): Promise<{ line: string; rest: string } | CutShort> {\n  let text = \"\";\n  let found = firstLineIn(text);\n  while (found === undefined) {\n    const next = await texts.next();\n    if (next.done) {\n      return { cutShort: text.trim() };\n    }\n    text += next.value;\n    found = firstLineIn(text);\n  }\n  return found;\n}\n\n/** The unix socket a handshake line names, read by platform.json's handshake; none when the line is not one, or names no socket. */\nfunction socketOf(line: string): string | undefined {\n  const [before, after] = platform.handshake.split(\"${socket}\");\n  if (!line.startsWith(before) || !line.endsWith(after)) {\n    return undefined;\n  }\n  const socket = line.slice(before.length, line.length - after.length);\n  return socket === \"\" ? undefined : socket;\n}\n\n/**\n * Where the plugin's own output goes: teed to this process's stream `name`,\n * and forwarded to each callback of `forwarded`, unless it is blank. Neither a\n * tee nor a callback that throws or rejects stops the pipe being drained, as\n * the agent always drains it: a plugin whose pipe fills blocks.\n */\nfunction outputSink(name: \"stdout\" | \"stderr\", forwarded: ReadonlySet<EventCallback>): (text: string) => void {\n  return (text) => {\n    written(() => process[name].write(text));\n    if (text.trim() === \"\") {\n      return;\n    }\n    for (const callback of forwarded) {\n      written(() => callback({ output: { stdout: \"\", stderr: \"\", [name]: text, data: null } }));\n    }\n  };\n}\n\n/** Hands `first`, when there is any, then each piece of text `texts` give to `sink`, until they end. */\nasync function piped(texts: AsyncGenerator<string>, sink: (text: string) => void, first = \"\"): Promise<void> {\n  if (first !== \"\") {\n    sink(first);\n  }\n  for await (const text of texts) {\n    sink(text);\n  }\n}\n\n/**\n * The environment a plugin process starts with: this process's, then `given`,\n * then the agent's cookie, and never a listen address: the agent's child\n * serves on a unix socket and prints the handshake naming it, where a listen\n * address would have it listen on TCP and print none.\n */\nfunction environmentOf(given: Record<string, string> = {}): Record<string, string | undefined> {\n  const listen = agentVariableOf(\"grpcListen\");\n  const kept = Object.entries({ ...process.env, ...given }).filter(([name]) => name !== listen);\n  return { ...Object.fromEntries(kept), [agentVariableOf(\"agentPlugin\")]: AGENT_PROTOCOL };\n}\n\n/** The socket the first whole line of `stdout` that is not blank names, and the text after it; refused, naming `entrypoint` and what it printed, when it is not the agent's handshake or its stdout ends first. */\nasync function socketLineOf(stdout: AsyncGenerator<string>, entrypoint: string, timeoutMs: number): Promise<{ socket: string; rest: string }> {\n  const late = () => new Error(`${entrypoint}: printed no handshake on stdout within ${timeoutMs}ms (${platform.handshake})`);\n  const first = await within(firstLineOf(stdout), timeoutMs, late);\n  if (\"cutShort\" in first) {\n    throw new Error(`${entrypoint}: its stdout ended before a whole line that is not blank, the agent's handshake (${platform.handshake}, a newline after it): ${JSON.stringify(first.cutShort)}`);\n  }\n  const socket = socketOf(first.line);\n  if (socket === undefined) {\n    throw new Error(`${entrypoint}: its first line of stdout that is not blank is not the agent's handshake (${platform.handshake}): ${JSON.stringify(first.line)}`);\n  }\n  return { socket, rest: first.rest };\n}\n\n/**\n * The socket the handshake names, the first whole line of `stdout` that is\n * not blank, and the text after it. A plugin that prints none within\n * `timeoutMs`, prints another line first, or ends its stdout first, is killed\n * and refused, naming its entry point.\n */\nasync function handshakeOf(spawned: SpawnedPlugin, stdout: AsyncGenerator<string>, entrypoint: string, timeoutMs: number): Promise<{ socket: string; rest: string }> {\n  try {\n    return await socketLineOf(stdout, entrypoint, timeoutMs);\n  } catch (error) {\n    spawned.kill();\n    throw error;\n  }\n}\n\n/**\n * Starts a plugin's entry point as the agent starts a worker (`environmentOf`)\n * and answers a client of it once it is ready. The plugin runs with the ports\n * its entry point passes: a test that wants it local starts the entry point\n * that passes in-memory ones (`local.ts`). A plugin that prints no handshake\n * within the agent's bound, or another line first, is killed and refused.\n */\nexport async function startPluginProcess(entrypoint: string, options: StartOptions = {}, spawn: Spawn = bunSpawn): Promise<PluginTestClient> {\n  const spawned = spawn([\"bun\", \"run\", entrypoint], { cwd: options.cwd ?? dirname(resolve(entrypoint)), env: environmentOf(options.env) });\n  const forwarded = new Set<EventCallback>();\n  void piped(textsOf(spawned.stderr), outputSink(\"stderr\", forwarded));\n  const stdout = textsOf(spawned.stdout);\n  const { socket, rest } = await handshakeOf(spawned, stdout, entrypoint, options.handshakeTimeoutMs ?? HANDSHAKE_TIMEOUT_MS);\n  void piped(stdout, outputSink(\"stdout\", forwarded), rest);\n  const plugin: PluginProcess = {\n    forward: (callback) => {\n      // Each call's own entry, so two calls handed the same callback each stop only their own.\n      const entry: EventCallback = (event) => callback(event);\n      forwarded.add(entry);\n      return () => forwarded.delete(entry);\n    },\n    stop: () => spawned.kill(),\n  };\n  return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