← All languages

Servirtium for

Julia

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
ccall. Julia's built-in ccall invokes libservirtium_vcr's flat C ABI directly; the package is pure Julia with nothing to build. The library path is read once from SERVIRTIUM_VCR_LIB at module load.
Toolchain
Julia 1.6+ (Project.toml compat julia = "1.6"). No C compiler.
Distribution
Pkg.add by git URL at the tag (subdir julia) plus the native library from the release; not in the General registry
Finding the library
SERVIRTIUM_VCR_LIB (absolute path to the library file), read once into a const at module load and baked into Julia's precompile cache; so export it BEFORE Pkg.add. Fallbacks: a bundled native/libservirtium_vcr.so (absent in a git checkout), then the bare name via the OS loader (on macOS only the variable works).
On GitHub
julia/ · README

Getting it

There is no published package for Julia. 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 from the release, verify it, and keep it outside your git tree (README step 1, collapsed; Linux x86_64 shown).
    TAG=v2.0.0-alpha.20
    REL=https://github.com/servirtium/servirtium-vcr/releases/download/$TAG
    LIBDIR="$HOME/.servirtium-vcr/$TAG"; mkdir -p "$LIBDIR"
    LIB=libservirtium_vcr-$TAG-linux-x86_64.so      # macos-arm64.dylib, linux-arm64-musl.so, freebsd-x86_64.so, ...
    curl -fsSL -o "$LIBDIR/$LIB" "$REL/$LIB"
    curl -fsSL -o "$LIBDIR/$LIB.sha256" "$REL/$LIB.sha256"
    ( cd "$LIBDIR" && sha256sum -c "$LIB.sha256" )   # macOS: shasum -a 256 -c
    cp "$LIBDIR/$LIB" "$LIBDIR/libservirtium_vcr.so"
    
  2. Export SERVIRTIUM_VCR_LIB first, then add the package by URL at the release tag (subdir, because the package lives in julia/). Julia precompiles at this step and bakes the library path in; exported later, it is ignored.
    export SERVIRTIUM_VCR_LIB="$LIBDIR/libservirtium_vcr.so"     # .dylib on macOS; set it wherever your tests run
    TAG=v2.0.0-alpha.20 julia --project=. -e 'using Pkg; Pkg.add(url="https://github.com/servirtium/servirtium-vcr", rev=ENV["TAG"], subdir="julia")'
    
  3. Check it: replay a tape (fetch the canonical tape from the release first).
    mkdir -p tapes
    curl -fsSL -o tapes/single_get.md https://raw.githubusercontent.com/servirtium/servirtium-vcr/v2.0.0-alpha.20/julia/example/tapes/single_get.md
    julia --project=. -e '
    using Servirtium
    playback("tapes/single_get.md") do vcr
        println(chomp(read(`curl -s -S $(base_url(vcr))/ok`, String)), " ", last_kind(vcr))   # -> ok-body Ok
    end'
    

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.

using Servirtium

record("tapes/climate_api.md", "https://example.org") do rec
    body = chomp(read(`curl -s $(base_url(rec))/countries`, String))   # or your HTTP client
    flush!(rec)    # commit: writes the tape
end   # a block that throws discards; one that ends with neither flush! nor discard! throws

Playback

The same tape, replayed with no network.

using Servirtium
using Test

playback("tapes/single_get.md") do vcr
    body = chomp(read(`curl -s "$(base_url(vcr))/ok"`, String))
    @test body == "ok-body"
    @test last_kind(vcr) == Ok
end   # <- the do-block closes the server on every path

Idiomatic extras

A failed test discards the recording

In the record do-block an exception discards the recording (nothing is written) and rethrows; discard! drops it explicitly.

record("tapes/api.md", upstream) do rec
    run_test(base_url(rec))        # throws -> recording discarded, tape untouched
    flush!(rec)
end

Redact secrets before the tape is written

Config calls throw VcrError with the core's message if refused. Register the same rules on the playback handle.

record("tapes/api.md", upstream) do rec
    redact_credentials(rec)                      # Authorization, Cookie, X-Api-Key, ...
    redact_credential_header(rec, "X-Tenant-Token")
    redact_header(rec, "X-Request-Signature")
    # ... drive the system under test ...
    flush!(rec)
end

Volatile values as keyword rules

A bad rule fails the open with the core's message; markers apply before any rule.

playback("tapes/create_case.md";
         volatile_rules=[("request body", "<a:MessageID>urn:uuid:{{messageId}}</a:MessageID>")],
         volatile_binds=["caseId" => "42"]) do vcr
    # ... drive the SUT ...
    println(volatile_report(vcr))
end

Gotchas

  • Export SERVIRTIUM_VCR_LIB BEFORE Pkg.add: it is baked into the precompile cache. If you set it later, rm -rf ~/.julia/compiled/v*/Servirtium and Pkg.precompile(). Moving the library afterwards breaks it the same way.
  • Pkg.add("Servirtium") fails: the package is not registered. Use the URL form with subdir="julia"; without the subdir Pkg reports no Project.toml at the repo root.
  • Use volatile_bind(vcr, name, value), not bind (that is Sockets.bind).
  • On macOS only SERVIRTIUM_VCR_LIB works for finding the library; use the .dylib asset and an absolute path.
  • Windows: use the .dll asset and its full path.

Prompt for your coding agent

Paste this into Claude, Codex, Gemini or any coding agent, in your Julia 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 Julia 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 Julia. Follow https://servirtium.dev/languages/julia/ 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: Pkg.add by git URL at the tag (subdir julia) plus the native library from the release; not in the General registry.
   Toolchain and minimum version: Julia 1.6+ (Project.toml compat julia = "1.6"). No C compiler..
   How the binding finds the native library: SERVIRTIUM_VCR_LIB (absolute path to the library file), read once into a const at module load and baked into Julia's precompile cache; so export it BEFORE Pkg.add. Fallbacks: a bundled native/libservirtium_vcr.so (absent in a git checkout), then the bare name via the OS loader (on macOS only the variable works).

3. Route that test's HTTP client to the Servirtium VCR's base URL instead of the real service, using the idiomatic Julia 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 Julia 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.
- Export SERVIRTIUM_VCR_LIB BEFORE Pkg.add: it is baked into the precompile cache. If you set it later, rm -rf ~/.julia/compiled/v*/Servirtium and Pkg.precompile(). Moving the library afterwards breaks it the same way.
- Pkg.add("Servirtium") fails: the package is not registered. Use the URL form with subdir="julia"; without the subdir Pkg reports no Project.toml at the repo root.
- Use volatile_bind(vcr, name, value), not bind (that is Sockets.bind).
- On macOS only SERVIRTIUM_VCR_LIB works for finding the library; use the .dylib asset and an absolute path.
- Windows: use the .dll asset and its full path.

References:
- This language's page: https://servirtium.dev/languages/julia/
- The binding's directory: https://github.com/servirtium/servirtium-vcr/tree/main/julia
- 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

Linux x86_64 on cachyos with Julia 1.13.4: downloaded the linux-x86_64 library from v2.0.0-alpha.20 (sha256 OK), exported SERVIRTIUM_VCR_LIB, ran the README's Pkg.add(url, rev, subdir) which precompiled cleanly; then ran a record-then-replay script (playback single_get.md as the stand-in upstream, record do-block with redact_credentials + note + flush!, then playback of the new tape: live ok-body, replay ok-body Ok); a record block ending with neither flush! nor discard! threw VcrError 'without commit or discard' and wrote nothing; a throwing block discarded; the extras (redact_header, redact_credential_header, set_rewrite_upstream_base, volatile_rules keyword) ran. Not run on macOS (no Julia there).

They mirror these files in the repository:

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