@variance-authority/vantage
What a run has reported, while it is still running.
Kept in a process that outlives the test, so a suite in flight is something to look at rather than something to wait for.
Part of Variance Authority.
Point your coding agent at llms.txt.
What this is for
A test that hangs reports only the condition it was waiting for. Thirty seconds
later, in a process that has already torn down the page, the runner prints the
assertion that did not settle. That message is all the failure prints, and you
already knew it.
This package gives you the other side, while the test is still stuck there. You
start a small watching process; your suite reads its address from one
environment variable and reports to it as it goes; you GET that same address
from any other shell and read a JSON snapshot of what every test has done so
far. Nothing is written to disk, and stopping the watcher loses the run.
You can also stop a test on purpose — await variance.observe() in a spec holds
the page exactly where it is until you say go on — and look at the live browser
before releasing it.
Requirements
Node 22 or newer, and 22.15 for the CLI and the Playwright fixtures below. ESM
only ("type": "module"); there is no CommonJS build.
This package has no peer dependencies and imports nothing from any test runner —
it is two ends of an HTTP conversation, and Playwright is only the runner the
ready-made reporting fixtures happen to be written for.
You normally do not install this package. It arrives as a dependency of
@variance-authority/playwright-test,
@variance-authority/cli and
@variance-authority/mcp. For the workflow
below, install those:
npm install --save-dev @variance-authority/cli @variance-authority/playwright-test @playwright/test
| Package |
Why it is here |
@variance-authority/cli |
variance watch starts a watcher; variance ask reads one |
@variance-authority/playwright-test |
varianceFixtures, which report your run to the watcher |
@playwright/test |
the runner those fixtures extend (>=1.55 <2) |
@variance-authority/event |
only if your application code announces — see Announcements, below |
Install @variance-authority/vantage directly when you are writing your own
watcher, or reporting from a runner that is not Playwright:
npm install --save-dev @variance-authority/vantage
Watch a run, start to finish
Three steps, in two shells. No port is agreed in advance: the watcher takes an
ephemeral one and prints the address, and that printed string is the only thing
you copy.
1. Start the watcher and leave it up.
variance watch
variance-authority is watching. Start the suite with this in its environment:
VARIANCE_AUTHORITY_VANTAGE=http://127.0.0.1:53393
Ask it, from any other shell, with the same address:
variance ask self --at http://127.0.0.1:53393
It holds the run in memory and writes nothing down. Stop it and the run is gone.
2. Start the suite with the line it printed, in a second shell, using that
address rather than the one above:
VARIANCE_AUTHORITY_VANTAGE=http://127.0.0.1:53393 npx playwright test
The suite needs varianceFixtures, and nothing else:
// tests/fixtures.ts
import { test as base, expect } from '@playwright/test';
import { varianceFixtures } from '@variance-authority/playwright-test';
export const test = base.extend(varianceFixtures);
export { expect };
Every test in the run appears, including tests that destructure nothing, so the
listing has no holes. With VARIANCE_AUTHORITY_VANTAGE unset, varianceFixtures
costs one environment read per worker and reports nothing.
3. Ask, from a third shell or the second one, with that same address:
variance ask run-signals --at http://127.0.0.1:53393
A question only the watcher answers reads no variance.config.json, so it can
be asked from any directory. diff also reads a finished run, so ask it from
your project root.
What you get
variance ask run-signals --at <address>, against a run in flight:
2 test(s) at http://127.0.0.1:53393 — 1 running, 1 passed.
▸ waiting checkout › pays with a saved card — tests/checkout.spec.ts — project chromium — worker 2 — heard 3, pending 1
stopped at tests/checkout.spec.ts:41:11
passed cart › adds an item — tests/cart.spec.ts — project chromium — worker 0 — heard 0
variance ask test-signals --test f8a1c2d3e4b5 --at <address>, for the one
that is stuck:
checkout › pays with a saved card — tests/checkout.spec.ts — project chromium — worker 2 — running
Heard, in order:
0 page checkout / card-form / shown
1 page checkout / payment / authorising (start)
2 payments-service payments / charge / received
Started and never ended:
page checkout / payment / authorising
The listener also knows:
payments-service has announced 1 time(s) in this execution
The test itself sent:
tests/checkout.spec.ts:41:11 after 3 announcement(s) before the card form appears
Stopped at tests/checkout.spec.ts:41:11, waiting to be told to continue. Release it with `variance_continue`.
Both are printed from the same JSON a plain GET returns, so a reader that is
not the CLI gets the whole thing:
curl "$VARIANCE_AUTHORITY_VANTAGE/"
{
"state": {
"address": "http://127.0.0.1:53393",
"tests": [
{
"id": "f8a1c2d3e4b5",
"title": "checkout › pays with a saved card",
"file": "tests/checkout.spec.ts",
"project": "chromium",
"worker": 2,
"ordinal": 0,
"state": "running",
"heard": [
{ "phase": "once", "location": "checkout", "subject": "card-form", "action": "shown", "ordinal": 0, "realm": "page" },
{ "phase": "start", "location": "checkout", "subject": "payment", "action": "authorising", "ordinal": 1, "realm": "page" },
{ "phase": "once", "location": "payments", "subject": "charge", "action": "received", "ordinal": 2, "realm": "payments-service" }
],
"forgotten": 0,
"pending": [
{ "phase": "start", "location": "checkout", "subject": "payment", "action": "authorising", "ordinal": 1, "realm": "page" }
],
"remarks": ["payments-service has announced 1 time(s) in this execution"],
"notes": [
{ "at": "tests/checkout.spec.ts:41:11", "note": "before the card form appears", "ordinal": 0, "after": 3 }
],
"forgottenNotes": 0,
"waitingAt": "tests/checkout.spec.ts:41:11"
},
{
"id": "a1b2",
"title": "cart › adds an item",
"file": "tests/cart.spec.ts",
"project": "chromium",
"worker": 0,
"ordinal": 1,
"state": "passed",
"heard": [],
"forgotten": 0,
"pending": [],
"remarks": [],
"notes": [],
"forgottenNotes": 0
}
],
"forgotten": 0
},
"previous": { "address": "http://127.0.0.1:53393", "tests": [], "forgotten": 0 }
}
previous is the snapshot handed to whoever read last, so a one-shot command can
answer what has happened since somebody looked without remembering anything
between invocations. It is one value shared by every reader of that watcher, not
one per reader.
The fields
| Field |
What it is |
id |
the runner's test id — a retry arrives as a different id |
state |
running, or the runner's own word for how it ended: passed, failed, timedOut, skipped, interrupted |
heard |
every announcement in this execution, oldest first |
pending |
work that started and never ended, exact whatever was dropped |
remarks |
what the listener worked out and a wait could not see, keyed and last-write-wins |
notes |
what the spec itself sent, from variance.snapshot() and variance.observe() calls its author placed |
waitingAt |
file:line:column where this test has stopped, present only while it is stopped |
error |
the first four lines of the failure, when there was one |
forgotten, forgottenNotes |
how many entries were dropped from the front to stay bounded |
Inside heard and pending:
| Field |
What it is |
realm |
who announced it: page, or the name a service reports under |
location, subject, action |
the three coordinates the announcing call used, in the code's own words. Not a Variance Authority subject — one named UI state you asked for and can ask for again; this package never sees one |
phase |
once, or start/end for work with a duration |
ordinal |
arrival order in this execution, from 0 |
waitingAt is not a sixth state. A test standing still is running.
Announcements
heard, pending and realm are empty until your application code announces.
Announcing is @variance-authority/event: vae(location, subject, action) for a
thing that happened, and vaStart / vaEnd on the same three coordinates for
work with a duration — anything vaStart opened and vaEnd never closed is what
lands in pending.
import { vae, vaStart, vaEnd } from '@variance-authority/event';
vaStart('checkout', 'payment', 'authorising');
await authorise();
vaEnd('checkout', 'payment', 'authorising');
vae('checkout', 'card-form', 'shown');
A test hears those only if it destructures the events fixture, which is what
installs the listener:
import { expect, test } from './fixtures';
test('pays with a saved card', async ({ page, events }) => {
await page.goto('/checkout');
await events.happened('checkout', 'card-form', 'shown');
await expect(page.getByRole('dialog')).toBeHidden({ timeout: 0 });
});
A test that takes no events fixture still appears in the listing, with heard
empty. That distinction is the diagnosis: nothing at all is a wiring fact — no
listener, or code that does not announce — while a page that spoke while a
service did not is a request that never arrived or never came back.
Stop a test where you want to look at it
import { expect, test } from './fixtures';
test('the cart settles', async ({ page, variance }) => {
await page.getByRole('button', { name: 'Add' }).click();
variance.snapshot('one item in');
await page.getByRole('button', { name: 'Checkout' }).click();
await variance.observe('before the card form appears');
await expect(page.getByTestId('cart')).toBeVisible();
});
snapshot(note?) sends what is here now and keeps going. observe(note?, options?)
sends it and then holds the test — the page still up, the network still whatever
it was — until somebody releases it. Neither takes a line number; both read their
own from the stack. While a test stands still the runner's clock is stopped, and
when it goes on it has exactly the time it had before.
Find and release stopped tests:
variance ask waiting --at http://127.0.0.1:53393
1 test(s) are waiting to be told to continue.
checkout › pays with a saved card — tests/checkout.spec.ts — project chromium — worker 2 [f8a1c2d3e4b5]
stopped at tests/checkout.spec.ts:41:11
sent:
tests/checkout.spec.ts:41:11 after 3 announcement(s) before the card form appears
Releasing is the one thing a one-shot shell command cannot do, because the run
lives in the watcher's memory and a CLI process has no run. Release from the
process that is watching: over MCP with variance_continue, or in your own
watcher with release (below).
Leave both calls in the spec. With VARIANCE_AUTHORITY_VANTAGE unset, observe
returns 'unwatched' immediately and snapshot sends nothing, so a spec that
has them runs straight through in CI — which is what separates them from the
debugger; and .only they stand in for. If you do run a watcher in CI and
nobody ever releases, observe returns 'expired' after ten minutes by default
and the test goes on.
Write your own watcher
attachVantage(), from @variance-authority/vantage/attach, is the watching
end and the only half that opens a socket. It returns the address to start a run
with, so you never type a port:
// watch.ts — run with `node watch.ts`
import { spawn } from 'node:child_process';
import { attachVantage } from '@variance-authority/vantage/attach';
const watching = await attachVantage();
const suite = spawn('npx', ['playwright', 'test'], {
env: { ...process.env, VARIANCE_AUTHORITY_VANTAGE: watching.address },
stdio: 'inherit',
});
const every = setInterval(() => {
const now = watching.observatory.snapshot();
for (const test of now.tests) {
if (test.waitingAt === undefined) continue;
console.log(`${test.title} stopped at ${test.waitingAt}; letting it go`);
watching.observatory.release(test.id);
}
}, 500);
suite.on('exit', async () => {
clearInterval(every);
await watching.close();
});
On attachVantage()'s result |
|
address: string |
the origin a run is started with, and the origin a reader GETs |
observatory.snapshot(): VantageState |
plain values that will not change again — the shape printed above |
observatory.release(test: string): boolean |
let one stopped test go on; false if it was not stopped, or was already released |
observatory.releaseAll(): readonly string[] |
let everything stopped go on, and answer which tests those were |
close(): Promise<void> |
stop listening; the run in its memory is gone |
A release is spent exactly once, by the run's next poll. Two readers cannot
release one test twice, and a second release cannot land on whatever that test
stops at next.