← All languages

Servirtium for

Janet

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
built-in FFI (ffi/native). Pure Janet over Janet's built-in FFI (Janet 1.23+), so there is no C extension and no compiler or janet.h on your machine; the library is loaded lazily on the first call that needs it.
Toolchain
Janet 1.23 or newer (built with the FFI), jpm and git. No C compiler.
Distribution
jpm install from git at the tag, plus the native library from the release; not in a Janet registry
Finding the library
First hit wins: (servirtium/set-library! path) or the :native-lib option; SERVIRTIUM_VCR_LIB (an absolute path to the file); native/ inside the installed servirtium/ directory (empty in a git install); the bare file name through the OS loader. Loading is lazy, so (import servirtium) works without the library.
On GitHub
janet/ · README

Getting it

There is no published package for Janet. 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 copy it to the plain name (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. Install the package from the repository at the release tag into ./jpm_tree (the tag is pinned in the bundle string; the repo root carries a project.janet, so there is no subdirectory).
    jpm --tree=jpm_tree install "git::https://github.com/servirtium/servirtium-vcr.git::v2.0.0-alpha.20"
    
  3. Point Janet at the tree and the library, here and wherever your tests run, then check it by replaying a tape.
    export JANET_PATH="$PWD/jpm_tree/lib"
    export SERVIRTIUM_VCR_LIB="$LIBDIR/libservirtium_vcr.so"     # .dylib on macOS
    mkdir -p tapes
    curl -fsSL -o tapes/single_get.md https://raw.githubusercontent.com/servirtium/servirtium-vcr/v2.0.0-alpha.20/janet/example/tapes/single_get.md
    janet -e '
    (import servirtium)
    (servirtium/with-playback [vcr "tapes/single_get.md"]
      (os/execute ["curl" "-fsS" (string (servirtium/base-url vcr) "/ok")] :p)
      (print " " (servirtium/last-kind vcr)))'                  # -> ok-body :ok
    
  4. In a project of your own the dependency is a line in project.janet; jpm deps then installs it.
    :dependencies [{:url "https://github.com/servirtium/servirtium-vcr.git" :tag "v2.0.0-alpha.20"}]
    

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.

(import servirtium)

(servirtium/with-record [rec "tapes/climate_api.md" "https://example.org"]
  # drive your SUT at (servirtium/base-url rec) ...
  (servirtium/flush-tape rec))    # commit: writes the tape (and stops the server)
# a body that raises discards the recording; one that ends with neither
# flush-tape nor discard raises

Playback

The same tape, replayed with no network.

(import servirtium)

(servirtium/with-playback [vcr "tapes/single_get.md"]
  # drive your SUT at (servirtium/base-url vcr) ...
  (assert (= :ok (servirtium/last-kind vcr))))   # optional: assert a clean match
                                                 # the server is stopped on every path

Idiomatic extras

A failed test discards the recording

If the with-record body raises, the recording is discarded and the error propagates; (servirtium/discard rec) drops it explicitly.

(servirtium/with-record [rec tape upstream]
  (run-test (servirtium/base-url rec))   # raises -> nothing written
  (servirtium/flush-tape rec))

Options struct: redaction and credentials

Options are applied between open and start, unknown keys raise, and every option has a function form.

(servirtium/with-record [rec tape upstream
                         {:redact-credentials true
                          :redact-credential-headers ["X-Tenant-Token"]
                          :redact-headers ["X-Request-Signature"]
                          :redact-json-fields ["secretKey"]}]
  # ... drive the SUT ...
  (servirtium/flush-tape rec))

Volatile values and drift detection

:flush-mode :fail-if-changed raises if the fresh recording differs from the tape on disk (the new tape is still written, for the git diff).

(servirtium/with-record [rec tape upstream
                         {:flush-mode :fail-if-changed
                          :volatile-rules [["request body" "<a:MessageID>urn:uuid:{{messageId}}</a:MessageID>"]]}]
  # ... drive the SUT ...
  (servirtium/flush-tape rec))

Gotchas

  • Needs Janet 1.23+ built with the FFI; otherwise: unknown symbol ffi/native.
  • jpm installs into JANET_MODPATH (often a system directory) unless you pass --tree=DIR or --local; set JANET_PATH to the tree's lib directory afterwards, or you get 'could not find module servirtium'.
  • Janet names are kebab-case (last-kind, flush-tape); there is no servirtium/flush because Janet has its own flush.
  • Errors are structs: (string e) prints <struct 0x...>; use (string/format "%q" e) or (e :message).
  • The library must be the same tag as the package, or a call fails naming the missing aether_vcr_embed_... symbol.
  • Windows: use the .dll asset and its full path (untested by the project).

Prompt for your coding agent

Paste this into Claude, Codex, Gemini or any coding agent, in your Janet 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 Janet 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 Janet. Follow https://servirtium.dev/languages/janet/ 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: jpm install from git at the tag, plus the native library from the release; not in a Janet registry.
   Toolchain and minimum version: Janet 1.23 or newer (built with the FFI), jpm and git. No C compiler..
   How the binding finds the native library: First hit wins: (servirtium/set-library! path) or the :native-lib option; SERVIRTIUM_VCR_LIB (an absolute path to the file); native/ inside the installed servirtium/ directory (empty in a git install); the bare file name through the OS loader. Loading is lazy, so (import servirtium) works without the library.

3. Route that test's HTTP client to the Servirtium VCR's base URL instead of the real service, using the idiomatic Janet 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 Janet 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.
- Needs Janet 1.23+ built with the FFI; otherwise: unknown symbol ffi/native.
- jpm installs into JANET_MODPATH (often a system directory) unless you pass --tree=DIR or --local; set JANET_PATH to the tree's lib directory afterwards, or you get 'could not find module servirtium'.
- Janet names are kebab-case (last-kind, flush-tape); there is no servirtium/flush because Janet has its own flush.
- Errors are structs: (string e) prints <struct 0x...>; use (string/format "%q" e) or (e :message).
- The library must be the same tag as the package, or a call fails naming the missing aether_vcr_embed_... symbol.
- Windows: use the .dll asset and its full path (untested by the project).

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

macOS arm64 with Janet 1.43.0 and jpm: downloaded the macos-arm64 dylib from v2.0.0-alpha.20 (sha256 OK); ran the README's jpm --tree install of git::...::v2.0.0-alpha.20 (installed cleanly); then ran a record-then-replay script (with-playback of single_get.md as the stand-in upstream, with-record with {:redact-credentials true :notes ...} and flush-tape, then with-playback of the new tape: live ok-body, replay ok-body :ok); with-record with an empty body raised {:error :servirtium ... 'without commit or discard'} and wrote nothing; a raising body discarded; the extras options (redact-headers, redact-credential-headers, rewrite-upstream-base, volatile-rules) were accepted by with-record. :flush-mode example mirrors janet/docs/usage.md and was not run.

They mirror these files in the repository:

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