Offline Testing with Fixtures
Run the full login→init→generate loop offline using --fixture or OPTIXLOG_FIXTURE, suitable for tests and CI without a live server.
Every CLI command and SDK operation can run against a local JSON fixture instead of a live server. This is how you develop and test locally, and how CI generates bindings without network access.
How fixtures work
Pass --fixture PATH to a CLI command (or set OPTIXLOG_FIXTURE=PATH) to replace all server calls with responses read from the fixture file. The fixture format is the schema contract JSON (schema.sample.json).
The SDK also reads OPTIXLOG_FIXTURE from the environment, so your application code runs offline too — no code changes needed.
The canonical offline loop
Run these three commands in order once per development environment setup:
Login with the fixture
optixlog login \
--fixture tests/fixtures/schema.sample.json \
--api-key sk-opt-test \
--base-url http://localhostThis writes a credential to ~/.optixlog/credentials.toml using the fixture identity (org_leidos_01, founder@optixlog.com). The api_key and base_url values are placeholders — they are not validated against a server when --fixture is set.
Init with the fixture
optixlog init \
--fixture tests/fixtures/schema.sample.json \
--all \
--output optixlog_gen.pyThis reads the project list from the fixture and writes optixlog.toml.
Generate with the fixture
optixlog generate \
--fixture tests/fixtures/schema.sample.jsonThis reads the node types and project↔node associations from the fixture and writes optixlog_gen.py. The output is byte-deterministic — commit it to your repo.
Using OPTIXLOG_FIXTURE in tests
Set the environment variable before running your test suite so SDK calls also use the fixture:
OPTIXLOG_FIXTURE=tests/fixtures/schema.sample.json python -m pytestOr in a .env file used by your test runner:
OPTIXLOG_FIXTURE=tests/fixtures/schema.sample.json
OPTIXLOG_API_KEY=sk-opt-test
OPTIXLOG_BASE_URL=http://localhostUsing the fixture in Python
You can also point the environment variable before importing the SDK:
import os
import pytest
os.environ["OPTIXLOG_FIXTURE"] = "tests/fixtures/schema.sample.json"
os.environ["OPTIXLOG_API_KEY"] = "sk-opt-test"
os.environ["OPTIXLOG_BASE_URL"] = "http://localhost"
from optixlog_gen import OptixClient, Projects, SimulationNode
def test_ingest_creates_node():
client = OptixClient()
result = client.project(Projects.GRATING_COUPLER_LAB).ingest(
data=SimulationNode(config={}, solver="fdtd"),
prompt="Test run.",
)
assert result.node_id
assert isinstance(result.created, bool)
client.close()Fixture path resolution
Relative fixture paths are resolved from the working directory of the process, not from the file containing the path. Use absolute paths or pathlib.Path(__file__).parent / "..." for reliability in test files.
Providing a custom fixture
The fixture file is a JSON schema contract. To customize it for your tests, copy tests/fixtures/schema.sample.json and modify the projects, node_types, and project_node_types sections:
{
"schema_version": 1,
"identity": {
"key_type": "service",
"organization_id": "org_test_01",
"user_email": "test@example.com",
"scoped_project_ids": ["proj_alpha"]
},
"projects": [
{ "id": "proj_alpha", "name": "Alpha Project" }
],
"node_types": [
{
"name": "RunNode",
"fields": [
{ "name": "run_id", "type": "string", "required": true },
{ "name": "status", "type": "enum", "enum": ["pending", "done"], "required": true }
]
}
],
"project_node_types": {
"proj_alpha": ["RunNode"]
}
}Then run:
optixlog login --fixture tests/fixtures/my_fixture.json --api-key sk-opt-test --base-url http://x
optixlog init --fixture tests/fixtures/my_fixture.json --all --output optixlog_gen.py
optixlog generate --fixture tests/fixtures/my_fixture.jsonTabs: offline vs. live
optixlog login --fixture tests/fixtures/schema.sample.json --api-key sk-opt-test --base-url http://x
optixlog init --fixture tests/fixtures/schema.sample.json --all --output optixlog_gen.py
optixlog generate --fixture tests/fixtures/schema.sample.jsonoptixlog login
optixlog init --all --output optixlog_gen.py
optixlog generate