Developer series, part 6
Test the code that has a check in it
Once a refund goes through govern(), your code has branches that only run when a rule or a manager says so. You still want to see every one of them work before you ship, and you don't want a test that needs an account or a network to do it.
Give your code the client, then swap it
The TypeScript SDK ships a separate entry point, @veriproof/sdk-core/testing. Its VeriproofTestHarness builds a real Veriproof client whose requests never leave the process. The harness answers them the way the service would, so your code runs the SDK's actual client and response parsing, and the decisions come from your test.
That only helps if your code accepts the client instead of creating it. In part 1, the refund lived inside a switch on result.status. Wrap that in a function, handleRefund(veriproof, order, billing), and pass it Veriproof.fromEnv() in the app and harness.veriproof in tests. Nothing else changes.
Make each result happen on purpose
Here's the setup for the refund tests. Each test gets its own harness and a fake billing system that remembers what it refunded:
import test, { type TestContext } from 'node:test';
import assert from 'node:assert/strict';
import {
TestPolicyDecision,
VeriproofTestHarness,
} from '@veriproof/sdk-core/testing';
import { handleRefund, type Billing } from '../src/refunds.js';
import { refundReviewProfile } from './fixtures.js';
const daniel = { id: 'A-2187', total: 900, deliveredDaysAgo: 41 };
function setup(t: TestContext) {
const harness = new VeriproofTestHarness()
.withReviewProfile(refundReviewProfile);
t.after(() => harness.veriproof.shutdown());
const refunds: number[] = [];
const billing: Billing = {
refund: async ({ amount }) => {
refunds.push(amount);
return { refundId: 'RF-1', amount };
},
};
const run = () => handleRefund(harness.veriproof, daniel, billing);
return { harness, refunds, run };
}withReviewProfile is there because the refund names a review form, support_refund_approval, and the SDK looks that form up before the check. The harness needs a copy to hand back, and without one every call fails with human_review_configuration_invalid before the check runs. Give it the same profile definition your app uses.
Then each test queues the decision it wants and checks what your code did:
test('an allowed refund runs once and sends its facts', async (t) => {
const { harness, refunds, run } = setup(t);
assert.match(await run(), /refunded \$900/);
assert.deepEqual(refunds, [900]);
const [request] = harness.policyRequests;
assert.equal(request?.snapshot.facts?.refund_amount, 900);
});
test('a denied refund never reaches billing', async (t) => {
const { harness, refunds, run } = setup(t);
harness.respondWith(TestPolicyDecision.deny('Past the return window.'));
assert.match(await run(), /Past the return window/);
assert.deepEqual(refunds, []);
});
test('an outage fails closed', async (t) => {
const { harness, refunds, run } = setup(t);
harness.failNext('/v1/sdk/governed-actions/start', 'unavailable');
assert.match(await run(), /haven't issued it/);
assert.deepEqual(refunds, []);
});With nothing queued, the harness allows. respondWith queues exact decisions, and TestPolicyDecision has ready-made ones: allow, warn, deny, transform (with a replacement value), failClosed and reviewContextRequired. For a review, call harness.reviewRequired(), which also creates the review case behind it, and assert that refunds is still empty. failNext takes 'unavailable' or 'timeout'. Pass timeoutMs to the harness for timeout tests so they finish in a fraction of a second.
The facts assertion in the first test earns its place. harness.policyRequests holds exactly what your code sent, and the $500 rule reads input.snapshot.facts.refund_amount. If a refactor drops that fact, this test fails today instead of a rule missing refunds later.
One thing the harness won't guess for you: real VeriProof answers review_context_required when a rule wants a person and the call has no review options. The harness doesn't check your options, so queue TestPolicyDecision.reviewContextRequired() to test that branch.
Rehearse the manager's decision offline
The harness can play the reviewer too. It carries its own signing key, harness.webhookSigningKey, and signHumanReviewTestDelivery from the same testing entry point signs a review outcome with it. Pass the result to reviews.receive and your resume path runs against a real signature check, the one a production callback goes through. Keep checkpoints in the testing entry point's InMemoryHumanReviewContinuationStore, which is fine for tests and never for production.
That's how we test the refund demo. Its rehearsal suite walks Daniel's whole refund, with a small helper, signDecision, that builds the decision the Teams card would send and signs it:
const daniel = await agent.handle('daniel');
assert.equal(daniel.status, 'review_required');
const delivery = runtime.signDecision(daniel.review, {
decision: 'respond',
amount: 600,
});
const received = await runtime.reviews.receive(
delivery.rawBody,
delivery.headers,
);
assert.equal(received.status, 202);
const continuationId =
daniel.review.continuation.outcomeBinding.continuationId;
const resumed = await agent.resume(continuationId);
assert.equal(resumed.status, 'completed');
assert.equal(resumed.value.amount, 600);The other review paths are short variations. With decision: 'reject', the resumed result is blocked and billing stays empty. A manager who types $1,500 gets refused by the demo's own revalidation check, because it's more than Daniel asked for, so nothing is refunded. Approving the full $900 is the same call with amount: 900.
Shadow shows what a rule would have done
Tests prove your code handles every result. They can't tell you whether a rule is aimed right, because you picked the decisions. That's what Shadow is for, once real refunds are flowing.
Your governance engineer tests a rule version with example inputs first: 750 should come back Send for review, 250 should Continue. Then they activate it in Shadow. From then on, VeriProof records what the rule would have decided for every real refund, with the evidence, but it can't change the work, open a review, notify anyone or flag the session. Your code keeps getting the same results it got before the rule existed.
That has a practical side for you. A refund rule in Shadow won't open a single review, so Daniel's Teams card never shows up. The review path's proof stays with your harness tests, and that's fine.
This is where you and the governance engineer work the same problem from both ends. They compare Shadow results with what they expected, looking for refunds the rule would stop or escalate that it shouldn't, and ones it misses. A miss is often a data problem: if refund_amount didn't arrive, the rule had nothing to compare. When a rule needs a field you don't send yet, they send you a request with Request application data, and you confirm the field under Application data in the application's Policy tab. Once the results look right, they select Enforce, with whatever approvals your organization requires for Production. Editing an active rule puts the new version back in Shadow, so a change to the $500 limit gets the same treatment.
Keep the check in CI
The harness tests need no account and make no network requests, so they run anywhere your other unit tests run. Treat them like any other test file in your suite. In most Node projects, that's:
npm testTwo habits keep them useful. Give every status your code branches on a test that makes it happen, and add one whenever you add a branch; for each status that shouldn't release a value, assert that billing never got called. And keep the facts assertion, since it's the cheapest guard you have on what rules can see.
The other SDKs have their own account-free harness too: the feature matrix lists it for all six languages. The TypeScript one is in the TypeScript SDK docs, and Rules covers Shadow and Enforce from the governance engineer's side.
Back to the start
That's the series. Part 5, When you can't change the code, covered agents you reach through Copilot Studio, computer use, MCP and the Agent Gateway. If you're new here, start with part 1, Check your agent's first real action, which builds the refund loop these tests run against.
Try it with a rule of your own
Write the tests against the harness today, then try a rule in Shadow with Developer, free for 60 days.