ContextReference
Testing
Scripted models, fake skills and tools, deterministic counters, and assertions on loads, budgets and cache behaviour.
Fakes are public API, in viewportai.context.testing and @viewportai/context/testing.
skills = fake_skills(
{
"refunds": {"description": "Refund orders.", "tools": ["issue_refund"], "body": "Refund only looked-up orders."},
"docs": {"description": "Search help.", "tools": ["search_docs"], "body": "Cite the article."},
},
tools=[fake_tool("issue_refund"), fake_tool("search_docs")],
counter=word_counter(),
budget=200,
)
run = await script(load("refunds"), call("issue_refund", order_id="A-1001"), say("Done.")).run(
skills.session(), "Refund A-1001"
)
assert run.session.loaded_names == ["refunds"] # the model loaded exactly one skill
assert run.results[1].ok is True # and its tool ran
assert (await run.session.call("search_docs", query="x")).refused is True # docs was never loaded
assert run.session.prompt().budget.ok is True # every request fit
assert run.cache_invalidations_for("anthropic") == 0 # loading never broke the cached prefix
assert run.session.prompt("hi").shares_prefix_with(run.session.prompt("bye")) # the input is not in the prefixconst skills = fakeSkills(
{
refunds: { description: "Refund orders.", tools: ["issue_refund"], body: "Refund only looked-up orders." },
docs: { description: "Search help.", tools: ["search_docs"], body: "Cite the article." },
},
{ tools: [fakeTool("issue_refund"), fakeTool("search_docs")], counter: wordCounter(), budget: 200 },
);
const run = await script(load("refunds"), call("issue_refund", { order_id: "A-1001" }), say("Done.")).run(
skills.session(),
"Refund A-1001",
);
assert.deepEqual(run.session.loadedNames, ["refunds"]); // the model loaded exactly one skill
assert.equal(run.results[1]?.ok, true); // and its tool ran
assert.equal((await run.session.call("search_docs", { query: "x" })).refused, true); // docs was never loaded
assert.equal(run.session.prompt().budget.ok, true); // every request fit
assert.equal(run.cacheInvalidationsFor("anthropic"), 0); // loading never broke the cached prefix
assert.ok(run.session.prompt("hi").sharesPrefixWith(run.session.prompt("bye"))); // the input is not in the prefix| Helper | What it gives you |
|---|---|
script(load(...), call(...), say(...)) | A scripted model: replays steps through session.call, building a prompt before each, and returns a Run (session, prompts, results, messages, cache_invalidations) |
| Per-stack scripted models | scriptedModel in each TypeScript adapter subpath (AI SDK, LangGraph, OpenAI Agents) and the matching Python fakes, so adapter tests run the real framework with no key |
fake_skills / fakeSkills, fake_tool / fakeTool | An inline registry and tools that echo their arguments |
tmp_skills (pytest fixture) / skillsDir | Real SKILL.md folders in a temp dir, so tests exercise the real parser |
word_counter() / wordCounter(), fixed_counter(n) / fixedCounter(n) | Predictable token counts |
vitest contextMatchers | toHaveLoaded, toBeWithinBudget, toSharePrefixWith, toInvalidateCacheAtMost; promptSerializer for readable snapshots |
| pytest fixtures | skills (your project's skills/ with config), tmp_skills, skill_events (captured skill_load events) |
In Python, values compare naturally (session.loaded == ["refunds"], "refunds" in session, result.refused) and
prompt.explain() is the repr, so pytest failure output is readable.