or run

npx @tessl/cli init
Log in

Version

Files

docs

asset-management.mdautomation.mdconfiguration.mddynamic-resources.mdindex.mdlogging-diagnostics.mdoutput-system.mdprovider-development.mdresource-management.mdruntime-operations.mdstack-references.mdutilities.md
tile.json

task.mdevals/scenario-1/

Mocked Preview Harness

  • Runs a mocked IaC program and returns its outputs @test
  • Honors preview/dry-run flag when executing the program @test
  • Supports custom resource and data-source mock responses @test

@generates

Overview

Implement a helper that executes an infrastructure program entirely in-memory using the dependency's runtime mocking hook. The helper should install mocks, run the user-supplied program, expose outputs, and clean up runtime state so multiple runs do not leak state.

Requirements

  1. Mock installation and teardown
  • runWithMocks installs the runtime mock hook using the provided handlers before running the program and clears runtime state afterward. Repeated calls should not share mocks or config.
  • clearMocks removes any installed mocks so other tests or programs can run normally.
  1. Preview / dry-run control
  • When preview is true, the runtime should behave as if running a dry-run/preview: the program should observe preview mode via the dependency's preview indicator and any unknown output semantics should be preserved.
  • When preview is false or omitted, the program executes as an update run.
  1. Resource and data mocks
  • handlers.resources is invoked for each resource registration with details about the request. Its returned id and state become the resource's result.
  • handlers.calls (if provided) is invoked for each data-source/provider call with the request details. Its return value becomes the call result.
  • Handlers may be synchronous or async; errors bubble to the caller.
  1. Return value
  • runWithMocks returns a promise resolving to { outputs, preview }, where outputs is whatever the program returns (resolved through the dependency's output machinery) and preview echoes the mode used.

Dependencies { .dependencies }

@pulumi/pulumi { .dependency }

Provides IaC runtime, Outputs, and mock-aware execution utilities.

export interface MockResourceRequest {
  type: string;
  name: string;
  inputs: Record<string, any>;
  provider?: string;
  preview: boolean;
}

export interface MockResourceResult {
  id: string;
  state: Record<string, any>;
}

export interface MockCallRequest {
  token: string;
  inputs: Record<string, any>;
  preview: boolean;
}

export interface MockHandlers {
  resources(request: MockResourceRequest): Promise<MockResourceResult> | MockResourceResult;
  calls?(request: MockCallRequest): Promise<Record<string, any>> | Record<string, any>;
}

export interface MockRunOptions<TOutputs> {
  program: () => Promise<TOutputs>;
  handlers: MockHandlers;
  preview?: boolean;
}

export interface MockRunResult<TOutputs> {
  outputs: TOutputs;
  preview: boolean;
}

export function runWithMocks<TOutputs>(options: MockRunOptions<TOutputs>): Promise<MockRunResult<TOutputs>>;
export function clearMocks(): void;