Skip to content

@codesoul-co/hypha-testing / mock-execution-provider

Using this module

Use the Mock execution provider module for binding external or local providers to Hypha ports. It exports 2 classes, 2 interfaces.

Import from the package entrypoint

ts
import {
  MockExecutionProvider,
  MockExecutionProviderError,
} from '@codesoul-co/hypha-testing';

import type {
  MockExecutionBehavior,
  MockExecutionProviderOptions,
} from '@codesoul-co/hypha-testing';

Usage patterns

  • Use the 2 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 2 classes as constructable runtime implementations. Each symbol entry lists its constructor and public methods.

Public exports

SymbolKindSignatureDescription
MockExecutionProviderclassnew MockExecutionProvider(options?: MockExecutionProviderOptions): MockExecutionProviderDeterministic, in-memory SandboxProvider for contract tests, replay fixtures, and failure injection. It never starts a process or mutates a real Workspace.
MockExecutionProviderErrorclassnew MockExecutionProviderError(normalizedError: NormalizedExecutionError): MockExecutionProviderErrorMock Execution Provider Error class with 9 public constructor or member entries; its exact declarations are listed below.
MockExecutionBehaviorinterfaceinterface MockExecutionBehaviorMock Execution Behavior interface with 17 public fields or methods.
MockExecutionProviderOptionsinterfaceinterface MockExecutionProviderOptionsMock Execution Provider Options interface with 8 public fields or methods.

MockExecutionProvider

Deterministic, in-memory SandboxProvider for contract tests, replay fixtures, and failure injection. It never starts a process or mutates a real Workspace.

  • Kind: class
  • Import: import { MockExecutionProvider } from '@codesoul-co/hypha-testing';
  • Source module: mock-execution-provider

Declaration

text
export declare class MockExecutionProvider implements SandboxProvider {
    readonly id: string;
    constructor(options?: MockExecutionProviderOptions);
    enqueue(behavior: MockExecutionBehavior): void;
    setHealth(health: ProviderHealth): void;
    capabilities(): Promise<SandboxProviderCapabilities>;
    create(input: SandboxCreateRequest): Promise<SandboxRecord>;
    start(input: SandboxStartRequest): Promise<SandboxRecord>;
    execute(input: CommandExecutionRequest): Promise<CommandExecutionResult>;
    cancel(input: ExecutionCancelRequest): Promise<void>;
    terminate(input: SandboxTerminateRequest): Promise<void>;
    status(input: SandboxStatusRequest): Promise<SandboxRecord | null>;
    cleanup(input: SandboxCleanupRequest): Promise<void>;
    health(): Promise<ProviderHealth>;
    close(): Promise<void>;
}

Public members

MemberKindSignatureDescription
cancelmethodcancel(input: ExecutionCancelRequest): Promise<void>Public method; parameters and return type are shown in the signature.
capabilitiesmethodcapabilities(): Promise<SandboxProviderCapabilities>Public method; parameters and return type are shown in the signature.
cleanupmethodcleanup(input: SandboxCleanupRequest): Promise<void>Public method; parameters and return type are shown in the signature.
closemethodclose(): Promise<void>Public method; parameters and return type are shown in the signature.
constructorconstructor(options?: MockExecutionProviderOptions): MockExecutionProviderCreates an instance of this class.
createmethodcreate(input: SandboxCreateRequest): Promise<SandboxRecord>Public method; parameters and return type are shown in the signature.
enqueuemethodenqueue(behavior: MockExecutionBehavior): voidPublic method; parameters and return type are shown in the signature.
executemethodexecute(input: CommandExecutionRequest): Promise<CommandExecutionResult>Public method; parameters and return type are shown in the signature.
healthmethodhealth(): Promise<ProviderHealth>Public method; parameters and return type are shown in the signature.
idpropertyreadonly id: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
setHealthmethodsetHealth(health: ProviderHealth): voidPublic method; parameters and return type are shown in the signature.
startmethodstart(input: SandboxStartRequest): Promise<SandboxRecord>Public method; parameters and return type are shown in the signature.
statusmethodstatus(input: SandboxStatusRequest): Promise<SandboxRecord | null>Public method; parameters and return type are shown in the signature.
terminatemethodterminate(input: SandboxTerminateRequest): Promise<void>Public method; parameters and return type are shown in the signature.

MockExecutionProviderError

Mock Execution Provider Error class with 9 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { MockExecutionProviderError } from '@codesoul-co/hypha-testing';
  • Source module: mock-execution-provider

Declaration

text
export declare class MockExecutionProviderError extends Error {
    readonly normalizedError: NormalizedExecutionError;
    constructor(normalizedError: NormalizedExecutionError);
}

Public members

MemberKindSignatureDescription
causepropertycause?: unknownPublic property; its type, readonly modifier and optionality are shown in the signature.
constructorconstructor(normalizedError: NormalizedExecutionError): MockExecutionProviderErrorCreates an instance of this class.
messagepropertymessage: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
namepropertyname: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
normalizedErrorpropertyreadonly normalizedError: NormalizedExecutionErrorPublic property; its type, readonly modifier and optionality are shown in the signature.
stackpropertystack?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
static captureStackTracemethodstatic captureStackTrace(targetObject: object, constructorOpt?: Function): voidCreates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called. js const myObject = {}; Error.captureStackTrace(myObject); myObject.stack; // Similar to `new Error().stack` The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}. The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace. The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance: js function a() { b(); } function b() { c(); } function c() { // Create an error without stack trace to avoid calculating the stack trace twice. const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; const error = new Error(); Error.stackTraceLimit = stackTraceLimit; // Capture the stack trace above function b Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace throw error; } a();
static prepareStackTracemethodstatic prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): anyPublic method; parameters and return type are shown in the signature.
static stackTraceLimitpropertystatic stackTraceLimit: numberThe Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

MockExecutionBehavior

Mock Execution Behavior interface with 17 public fields or methods.

  • Kind: interface
  • Import: import type { MockExecutionBehavior } from '@codesoul-co/hypha-testing';
  • Source module: mock-execution-provider

Declaration

text
export interface MockExecutionBehavior {
    delayMs?: number;
    status?: Extract<CommandExecutionStatus, 'completed' | 'failed' | 'timed_out' | 'oom_killed' | 'resource_exceeded' | 'quarantined'>;
    exitCode?: number | null;
    signal?: string;
    stdout?: string;
    stderr?: string;
    stdoutTruncated?: boolean;
    stderrTruncated?: boolean;
    stdoutArtifactRef?: string;
    stderrArtifactRef?: string;
    changedFiles?: FileMutation[];
    generatedArtifactRefs?: string[];
    snapshotBeforeRef?: string;
    snapshotAfterRef?: string;
    resourceUsage?: ExecutionResourceUsage;
    error?: NormalizedExecutionError;
    metadata?: Record<string, unknown>;
}

Contract members

MemberKindSignatureDescription
changedFilespropertychangedFiles?: FileMutation[]Public property; its type, readonly modifier and optionality are shown in the signature.
delayMspropertydelayMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
errorpropertyerror?: NormalizedExecutionErrorPublic property; its type, readonly modifier and optionality are shown in the signature.
exitCodepropertyexitCode?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
generatedArtifactRefspropertygeneratedArtifactRefs?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
resourceUsagepropertyresourceUsage?: ExecutionResourceUsagePublic property; its type, readonly modifier and optionality are shown in the signature.
signalpropertysignal?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
snapshotAfterRefpropertysnapshotAfterRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
snapshotBeforeRefpropertysnapshotBeforeRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
statuspropertystatus?: "completed" | "failed" | "timed_out" | "oom_killed" | "resource_exceeded" | "quarantined"Public property; its type, readonly modifier and optionality are shown in the signature.
stderrpropertystderr?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stderrArtifactRefpropertystderrArtifactRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stderrTruncatedpropertystderrTruncated?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
stdoutpropertystdout?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stdoutArtifactRefpropertystdoutArtifactRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stdoutTruncatedpropertystdoutTruncated?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.

MockExecutionProviderOptions

Mock Execution Provider Options interface with 8 public fields or methods.

  • Kind: interface
  • Import: import type { MockExecutionProviderOptions } from '@codesoul-co/hypha-testing';
  • Source module: mock-execution-provider

Declaration

text
export interface MockExecutionProviderOptions {
    id?: string;
    now?: () => string;
    sandboxId?: (request: SandboxCreateRequest) => string;
    executionId?: (request: CommandExecutionRequest) => string;
    capabilities?: Partial<SandboxProviderCapabilities>;
    health?: ProviderHealth;
    behaviors?: MockExecutionBehavior[];
    defaultBehavior?: MockExecutionBehavior;
}

Contract members

MemberKindSignatureDescription
behaviorspropertybehaviors?: MockExecutionBehavior[]Public property; its type, readonly modifier and optionality are shown in the signature.
capabilitiespropertycapabilities?: Partial<SandboxProviderCapabilities>Public property; its type, readonly modifier and optionality are shown in the signature.
defaultBehaviorpropertydefaultBehavior?: MockExecutionBehaviorPublic property; its type, readonly modifier and optionality are shown in the signature.
executionIdmethodexecutionId?(request: CommandExecutionRequest): stringPublic method; parameters and return type are shown in the signature.
healthpropertyhealth?: ProviderHealthPublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
nowmethodnow?(): stringPublic method; parameters and return type are shown in the signature.
sandboxIdmethodsandboxId?(request: SandboxCreateRequest): stringPublic method; parameters and return type are shown in the signature.