← All languages

Servirtium for

Pharo (Smalltalk)

No shipped package: vendor the binding's source at a release tag, with the native library from the release. Release v2.0.0-alpha.20.

FFI mechanism
UnifiedFFI (uFFI). Smalltalk classes call the aether_vcr_embed_* C ABI through uFFI; the library is loaded by name at the first call, from SERVIRTIUM_VCR_LIB or an explicit ServirtiumLibrary libPath:.
Toolchain
Pharo 12 VM and image (Metacello, Zinc/ZnClient for HTTP); no C compiler. Minimum Pharo not stated beyond 'Pharo 12' in the README.
Distribution
Load the Tonel sources at the tag with Metacello + the release native library
Finding the library
SERVIRTIUM_VCR_LIB (absolute path to the file, read from the OS environment when the image starts), or ServirtiumLibrary libPath: '/abs/path/libservirtium_vcr.so' before the first server starts.
On GitHub
pharo/ · README

Getting it

There is no published package for Pharo (Smalltalk). You vendor the binding's source into your project at the release tag v2.0.0-alpha.20 and take the native library from the same release.

  1. Fetch the native library for your OS/arch into ~/.servirtium-vcr/<tag>, checksum-verified, and give it the plain name the loader wants (Windows: take the .dll asset by hand).
    TAG=v2.0.0-alpha.20
    REL=https://github.com/servirtium/servirtium-vcr/releases/download/$TAG
    case "$(uname -s)" in
      Linux)   OS=linux;   EXT=so;    ldd --version 2>&1 | grep -qi musl && LIBC=-musl || LIBC= ;;
      Darwin)  OS=macos;   EXT=dylib; LIBC= ;;
      FreeBSD) OS=freebsd; EXT=so;    LIBC= ;;
    esac
    case "$(uname -m)" in x86_64|amd64) ARCH=x86_64 ;; arm64|aarch64) ARCH=arm64 ;; esac
    LIBDIR="$HOME/.servirtium-vcr/$TAG"; mkdir -p "$LIBDIR"
    LIB=libservirtium_vcr-$TAG-$OS-$ARCH$LIBC.$EXT
    curl -fsSL -o "$LIBDIR/$LIB" "$REL/$LIB"
    curl -fsSL -o "$LIBDIR/$LIB.sha256" "$REL/$LIB.sha256"
    ( cd "$LIBDIR" && { sha256sum -c "$LIB.sha256" || shasum -a 256 -c "$LIB.sha256"; } )
    cp "$LIBDIR/$LIB" "$LIBDIR/libservirtium_vcr.$EXT"
    
  2. Export SERVIRTIUM_VCR_LIB BEFORE the image starts, then load the Tonel sources of the same tag into a copy of your image with Metacello (the repository path is pharo/src, not the repo root). Use load: 'tests' to also load the SUnit suite.
    export SERVIRTIUM_VCR_LIB="$LIBDIR/libservirtium_vcr.$EXT"
    pharo --headless Pharo.image eval --save "
    Metacello new
      baseline: 'Servirtium';
      repository: 'github://servirtium/servirtium-vcr:v2.0.0-alpha.20/pharo/src';
      load."
    
  3. In your own baseline, depend on it the same way. There is no Pharo catalog entry and no registry form.
    spec baseline: 'Servirtium' with: [
      spec repository: 'github://servirtium/servirtium-vcr:v2.0.0-alpha.20/pharo/src' ]
    
  4. Check it: replay the canonical tape (expect 'ok-body' #ok).
    mkdir -p tapes
    curl -fsSL -o tapes/single_get.md \
      https://raw.githubusercontent.com/servirtium/servirtium-vcr/v2.0.0-alpha.20/pharo/src/Servirtium-Tests/tapes/single_get.md
    pharo --headless Pharo.image eval "
    | s | s := (Servirtium playback: 'tapes/single_get.md') port: 0; start.
    [ (ZnClient new get: s baseUrl , '/ok') displayString , ' ' , s lastKind printString ] ensure: [ s stop ]"
    

Record

Point your client at the VCR's base URL; the VCR forwards to the real service and hands back the real response. Nothing is written until you commit.

"A record server writes its tape only on commit. startThenDo: always stops the
 server and discards the recording if the block raises."
(Servirtium record: 'tapes/climate_api.md' upstream: 'https://climatedataapi.worldbank.org')
    port: 0;
    startThenDo: [ :server |
        ZnClient new get: server baseUrl , '/api/v1/countries'.
        server commit ].

Playback

The same tape, replayed with no network.

| server body |
server := (Servirtium playback: 'tapes/climate_api.md') port: 0; start.
body := ZnClient new get: server baseUrl , '/api/v1/countries'.
self assert: server lastKind equals: #ok.    "optional: assert a clean match"
server stop.

"or auto-closing:"
(Servirtium playback: 'tapes/climate_api.md') startThenDo: [ :server |
    ZnClient new get: server baseUrl , '/api/v1/countries'.
    self assert: server lastKind equals: #ok ].

Idiomatic extras

Redact credentials on record

Scrubs the standard credential headers from the tape while the live test still sees real bytes.

(Servirtium record: 'tapes/api.md' upstream: 'https://api.example.com')
    redactCredentials;
    startThenDo: [ :server |
        ZnClient new get: server baseUrl , '/me'.
        server commit ].

Drop the recording on failure, or on purpose

startThenDo: discards when the block raises; call server discard to drop a recording explicitly.

(Servirtium record: tape upstream: upstream) startThenDo: [ :server |
    ZnClient new get: server baseUrl , '/ok'.
    self checkSomething
        ifTrue: [ server commit ]
        ifFalse: [ server discard ] ].

Volatile values for byte-identical re-records

Rules name values that change on every run; the tape holds tokens and playback matches any live value of the right shape.

(Servirtium record: tape upstream: upstream)
    volatileRule: 'response headers' pattern: 'Date: {{serverDate}}';
    volatileRule: 'request path' pattern: '/orders/(?<orderId>[0-9a-f]{16})' kind: 'regex';
    startThenDo: [ :server | "... drive the SUT ..." server commit ].

Gotchas

  • SERVIRTIUM_VCR_LIB is read from the OS environment when the image starts: export it before launching, or call ServirtiumLibrary libPath: first. It must be an absolute path to an existing file.
  • The library and the Smalltalk source must be the same tag; an older library fails at the first call naming an aether_vcr_embed_ symbol.
  • Use the -musl asset on Alpine. Do not put the library in the image directory or a git tree.
  • The README itself marks the Getting-it recipe as written from the loader source and not run.

Prompt for your coding agent

Paste this into Claude, Codex, Gemini or any coding agent, in your Pharo (Smalltalk) project. It wraps one of your existing integration tests with Servirtium. The general prompt has a slot for the language instead.

Hey Gemini or Claude or Codex,

I want a test in this Pharo (Smalltalk) project to run without calling a real web service every time. Use Servirtium (https://servirtium.dev), which records HTTP conversations as readable Markdown "tapes" and replays them. Do these steps in order and tell me what you did at each one.

1. Find an existing integration test in this project that calls a web service as a side effect of what it is testing. Prefer one that is slow, flaky, or needs credentials or network because of that call. Tell me which test you chose and why.

2. Add the Servirtium binding for Pharo (Smalltalk). Follow https://servirtium.dev/languages/pharo/ exactly. Servirtium ships no package for this language. Vendor the binding's source into the project at the release tag v2.0.0-alpha.20 and put the native library from the same release where the page says: Load the Tonel sources at the tag with Metacello + the release native library.
   Toolchain and minimum version: Pharo 12 VM and image (Metacello, Zinc/ZnClient for HTTP); no C compiler. Minimum Pharo not stated beyond 'Pharo 12' in the README..
   How the binding finds the native library: SERVIRTIUM_VCR_LIB (absolute path to the file, read from the OS environment when the image starts), or ServirtiumLibrary libPath: '/abs/path/libservirtium_vcr.so' before the first server starts.

3. Route that test's HTTP client to the Servirtium VCR's base URL instead of the real service, using the idiomatic Pharo (Smalltalk) way of setting a base URL or HTTP client. The VCR starts on its own port (use port 0, so it picks a free one) and gives you its base URL; give that URL to the client and never hard-code a port.

4. Run the test once in record mode against the real service. Commit the recording when the test passes and discard it when the test fails: a record VCR that is closed without a commit or a discard writes no tape and raises an error. Use redact_credentials (the spelling for Pharo (Smalltalk) is on the page) so secrets become numbered tokens, and remove volatile request headers such as User-Agent and Date from the tape so playback does not depend on them.

5. Keep the tape beside the test as readable Markdown, in version control. Open it and check there are no secrets or personal data in it before committing.

6. Make the test play back by default, with an explicit switch (for example an environment variable such as SERVIRTIUM_RECORD=1) that re-records.

7. Prove it works offline: make the real service unreachable (network off, or a wrong host) and show the test still passes in playback.

Traps to avoid:
- A record VCR needs Commit() or Discard(); closing it without either writes nothing and raises.
- The VCR runs in your test process on its own port; the system under test must use the VCR's base URL, not the real one.
- SERVIRTIUM_VCR_LIB is read from the OS environment when the image starts: export it before launching, or call ServirtiumLibrary libPath: first. It must be an absolute path to an existing file.
- The library and the Smalltalk source must be the same tag; an older library fails at the first call naming an aether_vcr_embed_ symbol.
- Use the -musl asset on Alpine. Do not put the library in the image directory or a git tree.
- The README itself marks the Getting-it recipe as written from the loader source and not run.

References:
- This language's page: https://servirtium.dev/languages/pharo/
- The binding's directory: https://github.com/servirtium/servirtium-vcr/tree/main/pharo
- Concepts, features and every language's quick start: https://servirtium.dev/llms-full.txt (index: https://servirtium.dev/llms.txt)

How these snippets were checked

NOT RUN: no Pharo VM on the Mac or cachyos (I did not download one). Snippets mirror pharo/docs/usage.md, the README quick start, pharo/.example.ae and the SUnit tests; the commit/discard/startThenDo: semantics were read from ServirtiumServer.class.st and ServirtiumRecordBuilder.class.st. The native library itself was exercised through the other bindings.

They mirror these files in the repository:

See also the feature reference, llms.txt and the pharo/ directory.