tidaldb/tests/e2e/features/07-tidalctl.spec.ts
jordan 15f6b11187 test(e2e): Playwright evidence harness for the deploy-verification runbook
Turns docs/runbooks/deploy-verification.md from prose into 32 executable checks
against the live orchard9-k3sf cluster, and it found real defects on its first
run — including in the runbook it verifies.

WHY PLAYWRIGHT, HONESTLY
tidalDB serves zero HTML (no text/html, no Html(), 10 JSON routes), so this uses
Playwright in three distinct roles rather than pretending there is a UI:
  * request fixture as a real HTTP client for DNS/TLS/auth/quorum/404;
  * a browser for the only genuine screens in the chain, Grafana;
  * a test harness for cluster-plane checks with no HTTP surface, shelling out
    to kubectl and attaching the real transcript as evidence.

WHAT IT CAUGHT
  * The runbook asserted the operator/data credential split was "not active yet
    - requires an image roll". globalSetup read the live image and the live
    secret; a probe returned data->403, admin->200. It had been enforcing the
    whole time. Section 9 rewritten. (BUG-001)
  * docs/ops/grafana-tidaldb.json shipped datasource uid ${DS_PROMETHEUS} - a
    Grafana export-for-sharing placeholder with no __inputs block to resolve it.
    Under ConfigMap provisioning every panel queried a datasource that did not
    exist, so the whole board was blank. The API said "loaded" and I had only
    ever checked the API. 41 refs fixed here, 58 across the fleet ConfigMap,
    which was also blanking the postgres and redis dashboards. (BUG-007)
  * Stat panels used calcs "lastNonNull". Grafana's reducer is "lastNotNull", so
    no value was ever computed and Cluster health / Reseed pending / Indexed
    vectors rendered as empty boxes. I chased panel width and then panel height
    before comparing against a working stat panel elsewhere in the same Grafana.
    A spelling error wearing a layout bug's clothes. (BUG-009)
  * The namespace variable defaulted to All, so cluster panels silently included
    tidaldb-586b544c8-vpkmw from the superseded standalone deployment. Latency
    legends read "p50 p50 p50" with no way to tell the nodes apart. Both fixed.
  * "5xx ratio" rendered "No data" as large green text - at a glance a healthy
    value. And Fleet state gave three fields one shared green threshold, so
    reseed_required=1 would have shown GREEN during the exact incident the panel
    exists to surface. Split into three panels with per-field mappings.
  * tidalctl cluster-status exits 2 on a FULLY CONVERGED cluster, because the
    aggregated endpoint reports healthy peers as region=null applied=0
    reachable=false. The runbook claimed `cluster-status && deploy` was a safe
    gate; that claim came from an exit code masked by a shell pipeline. The gate
    can never pass here. Documented, test pins it, engine defect recorded.
    (BUG-005)
  * The deployed image writes ANSI colour into container logs, which the
    collector stores verbatim. Already fixed in logging.rs, not yet rolled;
    pinned as a tripwire. (BUG-006)
  * The runbook's own backup command sorted ALL backups by timestamp and
    selected a restore-canary run: 20 items, one volume, a meaningless pass.
    Now filters on the schedule label the freshness alert actually watches.

DEFECTS FOUND BY LOOKING AT THE SCREENS
Six of the first eight captures were slop and were fixed, not promoted:
230-350px of dead space; a verdict that rendered "exit code 2" in green; the
1600x1800 dashboard scaled into 16:9 until illegible (now clipped to the
evidence band using real element bounds); the dream beat whose caption described
a contradiction the image did not show (now a purpose-built capture holding the
committed doc text, the running image, and the live 403/200 side by side); and a
one-frame blink to bare background at every scene boundary, because Remotion
Sequences do not overlap and both scenes sat at opacity 0 on the boundary frame.

TRIPWIRES IN THE HONEST DIRECTION
Three tests assert what is ABSENT - zero tidaldb_http_* families, JSON_LOGS
unset, plain-text logs - and each carries the message "good news, roll the
runbook section from pending to live". The metric-absence test also asserts the
baseline family count, so "absent" cannot pass for "the scrape failed". That is
the drift that made section 9 stale in the first place.

Regression config uses workers:1 and retries:0 deliberately: a live-cluster
check that only passes on the second attempt has told you something true.

Verified: 32 passed (46.8s); 9 demo captures each asserting before photographing;
tsc clean; render 82.05s 1920x1080 h264, 0 empty frames across 10 boundaries;
every promoted image inspected individually and judged perfect; walk-the-render
ledger complete with no fails.
2026-08-23 14:03:29 -06:00

169 lines
6.7 KiB
TypeScript

/**
* Runbook section 7 — the live debugging tool.
*
* CAP-012 tidalctl interrogates a live cluster and its exit codes gate
*
* The exit-code contract is the part that matters operationally: an operator is
* expected to write `tidalctl cluster-status && deploy`, which is only safe if a
* non-converged cluster really exits non-zero and a bad credential does not
* silently exit 0.
*/
import { expect, test } from '@playwright/test';
import { tidalctl, withPortForward } from '../support/cluster';
import { observed, recordJson } from '../support/evidence';
import { NAMESPACE, PORT_CLIENT, apiKey } from '../support/env';
test.describe('section 7 — tidalctl live interrogation', () => {
test('cluster-status reports leadership, regions, and shards from a live node', async ({}, testInfo) => {
await withPortForward(NAMESPACE, 'svc/tidaldb', PORT_CLIENT, async (forward) => {
const result = await observed(testInfo, 'tidalctl cluster-status', () =>
tidalctl(
[
'cluster-status',
'--url',
`https://127.0.0.1:${forward.localPort}`,
'--key',
apiKey(),
// Required: the client port serves the INTERNAL cluster CA, whose
// leaf is issued for in-cluster DNS names, so a localhost tunnel
// cannot validate it.
'--insecure',
],
{ timeoutMs: 45_000 },
),
);
// Exit 2, not 0, on a FULLY CONVERGED cluster. This is not a tidalctl
// bug in isolation — the aggregated /cluster/status endpoint reports two
// of three healthy peers as `region: null, applied_events: 0,
// lag_events: 13322235, reachable: false`, while each of those peers'
// own /cluster/status/local reports lag=0 and all three agree on the
// leader (proven in 01-cluster-convergence.spec.ts). tidalctl correctly
// labels the gap `NO REPORT` but still folds it into its degraded
// verdict, so the exit code is 2.
//
// Consequence: `tidalctl cluster-status && deploy` can NEVER pass on this
// deployment. The runbook claimed it was a safe gate; that claim was
// written from an exit code masked by a shell pipeline. See BUG-005.
expect(
result.code,
'expected exit 2 — the aggregated-status gap makes a converged cluster report ' +
'degraded. If this is now 0, the engine-side peer reporting was fixed: ' +
'update runbook section 7 and mark BUG-005 verified.',
).toBe(2);
// The output must still be correct and complete even though the verdict
// is degraded — an operator reads these tables to locate the problem.
expect(result.stdout, 'must name the leader').toMatch(/leader:/);
expect(result.stdout, 'must list regions').toContain('regions:');
expect(result.stdout, 'must list shards').toContain('shards:');
});
});
test('the aggregated-status gap is reported as NO REPORT, never as fabricated lag', async ({}, testInfo) => {
await withPortForward(NAMESPACE, 'svc/tidaldb', PORT_CLIENT, async (forward) => {
const result = await observed(testInfo, 'tidalctl cluster-status regions', () =>
tidalctl(
[
'cluster-status',
'--url',
`https://127.0.0.1:${forward.localPort}`,
'--key',
apiKey(),
'--insecure',
],
{ timeoutMs: 45_000 },
),
);
// Degraded verdict for the reason pinned in the previous test (BUG-005);
// what matters here is HOW the gap is reported, not the exit code.
expect(result.code, result.stderr).toBe(2);
// The aggregated endpoint reports a peer it holds no frontier report for
// as applied=0 and derives lag against that zero, so a converged peer can
// read as the leader's entire history behind. tidalctl must name that
// condition rather than repeat it as lag.
const regionLines = result.stdout
.split('\n')
.filter((line) => /applied=/.test(line));
await recordJson(testInfo, 'region-lines', regionLines);
expect(regionLines.length, 'expected a line per region').toBeGreaterThan(0);
for (const line of regionLines) {
if (/applied=0\b/.test(line)) {
expect(
line,
'a peer with no frontier report must be labelled NO REPORT, not shown as real lag',
).toContain('NO REPORT');
}
}
});
});
test('watch emits one line per tick and terminates on the requested count', async ({}, testInfo) => {
await withPortForward(NAMESPACE, 'svc/tidaldb', PORT_CLIENT, async (forward) => {
const result = await observed(testInfo, 'tidalctl watch', () =>
tidalctl(
[
'watch',
'--url',
`https://127.0.0.1:${forward.localPort}`,
'--key',
apiKey(),
'--insecure',
'--interval',
'2',
'--count',
'3',
],
{ timeoutMs: 60_000 },
),
);
const ticks = result.stdout.split('\n').filter((line) => line.includes('leader='));
await recordJson(testInfo, 'watch-ticks', ticks);
// A bounded --count must terminate on its own. An unbounded watch here
// would hang the suite, which is why the flag exists.
expect(ticks.length, 'watch must emit exactly the requested number of ticks').toBe(3);
for (const tick of ticks) {
expect(tick, 'each tick must carry a verdict').toMatch(/\[(ok|DEGRADED)\]/);
}
});
});
test('exit codes gate correctly for a bad credential and a malformed url', async ({}, testInfo) => {
await withPortForward(NAMESPACE, 'svc/tidaldb', PORT_CLIENT, async (forward) => {
const badCredential = await observed(testInfo, 'tidalctl with wrong key', () =>
tidalctl(
[
'cluster-status',
'--url',
`https://127.0.0.1:${forward.localPort}`,
'--key',
'definitely-not-the-key',
'--insecure',
],
{ timeoutMs: 45_000 },
),
);
// Exit 2, not 0. A tool that exits 0 on a rejected credential would make
// `tidalctl cluster-status && deploy` deploy against an unverified cluster.
expect(
badCredential.code,
'a rejected credential must exit 2, never 0',
).toBe(2);
});
const malformedUrl = await observed(testInfo, 'tidalctl with schemeless url', () =>
tidalctl(
['cluster-status', '--url', '127.0.0.1:9500', '--key', apiKey(), '--insecure'],
{ timeoutMs: 20_000 },
),
);
// Exit 1 = usage error, distinct from exit 2 = reachable but unhealthy.
expect(malformedUrl.code, 'a malformed --url must exit 1 (usage)').toBe(1);
});
});