// The workbench pages, server-rendered (no script): the catalogue with the run form, and one run: its verdict, steps, // the protocol waterfall, every exchange's metadata, the cleanup counts, its spans and the export links. import type { Scenario } from 'ply/probes'; import { renderRay } from '../rays.ts'; import type { CatalogueEntry } from './catalogue.ts'; import type { Counts } from './entry.ts'; import { replaySlug } from './export.ts'; import { html, type Html } from './html.ts'; import type { Exchange, Wire } from './recorder.ts'; import type { RunSummary, SpanRow, StoredRun } from './store.ts'; import type { Failure, RunVerdict } from './verdict.ts'; import { answerText, kb, phaseName, shortKind, waterfall } from './waterfall.ts'; export const BENCH_CSS_PATH = '/bench.css'; const iso = (ms: number): string => new Date(ms).toISOString().replace('T', ' ').replace(/\.\d+Z$/, ' UTC'); const short = (oid: string): string => (/^[0-9a-f]{40}$/.test(oid) ? oid.slice(0, 12) : oid); function layout(title: string, body: Html): Html { return html`${title}
ply probe workbenchply: the client · this Worker: the probe runner · Artifacts: the server under test
${body}
`; } const supportText = (e: CatalogueEntry): Html => { const s = e.support; switch (s.tag) { case 'runnable': return html`runs${s.notes.map(n => html`
${n}
`)}`; case 'git-only': return html`stock git only
${s.why}
`; case 'too-large': return html`seed too large (${kb(s.bytes)})`; } }; const stepsText = (s: Scenario): string => s.steps.map(st => (st.tag === 'push' || st.tag === 'fetch' ? `${st.tag}${st.fault.tag === 'none' ? '' : ` + ${st.fault.tag}`}` : st.tag)).join(', '); export function indexPage(catalogue: readonly CatalogueEntry[], runs: readonly RunSummary[], counts: Counts, ply: string, notice: string | null): Html { const runnable = catalogue.filter(e => e.support.tag === 'runnable'); const areas = [...new Set(runnable.map(e => e.scenario.id.split('.')[0] || ''))]; const options = areas.map(a => html`${runnable.filter(e => e.scenario.id.startsWith(`${a}.`)).map(e => html``)}`); const recent = runs.map(r => html`${r.id}${r.scenario}${r.seed}${iso(r.startedAt)}${Math.round((r.finishedAt - r.startedAt) / 100) / 10} s${r.verdict}${r.failures > 0 ? ` ${r.failures}` : ''}${r.exchanges}${r.cleaned ? 'yes' : html`no`}`); const rows = catalogue.map(e => html`${e.scenario.id}${e.scenario.description}
${stepsText(e.scenario)}
${supportText(e)}`); return layout('ply probe workbench', html`

Probe workbench

Run one of ply's probe scenarios (ply ${short(ply)}, ply/probes) against Artifacts from this Worker. The plan fixes every object id; the seed names the run's repository. ply is the client under test; the Worker records every exchange (timings, bytes, status, headers, cf-ray, the pkt-lines) and reads the repository back. The repository is in the probe namespace and is deleted, with every token revoked, when the run ends.

${notice === null ? null : html`

${notice}

`}
One run at a time, ${counts.lastHour} of 20 this hour. The page answers when the run is over (a stall scenario takes about 30 s).

Repositories created ${counts.created}, cleaned ${counts.cleaned}.

Recent runs

${runs.length === 0 ? html`

No runs yet.

` : html`${recent}
runscenarioseedstartedtookverdictexchangescleaned
`}

Catalogue (${catalogue.length} scenarios, ${runnable.length} run here)

${rows}
scenariowhat it probeshere
`); } function failureView(f: Failure): Html { const d = f.difference; const step = f.step === null ? null : html`
step ${f.step.index}: ply concluded ${f.step.outcome} (${String(f.step.error)})${f.step.expected === null ? null : html`, the scenario states ${f.step.expected.outcome} (${String(f.step.expected.error)})`}
`; const text = f.tag === 'expected_incompatibility' ? f.reason : f.why; const evidence = f.evidence.map(e => html`
  • exchange #${e.exchange} ${e.cfRay}: ${e.says}
  • `); return html`
    ${f.tag}
    ${d.pair} · ${d.field}
    observed ${d.left}
    stated ${d.right}
    ${step}

    ${text}

    ${f.evidence.length === 0 ? null : html``}
    `; } function verdictView(v: RunVerdict): Html { switch (v.tag) { case 'pass': return html`
    pass: every one of ${v.compared} steps, the end refs and every landed claim meet the stated expectation
    `; case 'fail': return html`
    ${v.failures.length} difference${v.failures.length === 1 ? '' : 's'} from the stated expectation
    ${v.failures.map(f => failureView(f))}`; case 'harness': return html`
    not observed (${v.stage}): ${v.message}
    `; } } const kv = (rows: ReadonlyArray): Html => html`
    ${rows.map(([k, v]) => html`
    ${k}
    ${v}
    `)}
    `; const headerList = (hs: ReadonlyArray): Html => (hs.length === 0 ? html`none` : html``); function wireView(w: Wire): Html { switch (w.tag) { case 'advertisement': { const a = w.advertisement; return kv([['protocol', `${a.version}${a.service === null ? '' : ` (${a.service})`}`], ['advertised refs', a.refs.length === 0 ? 'none' : html``], ['capabilities', html`${a.capabilities.join(' ')}`]]); } case 'receive-pack': { const r = w.report; const report = r.tag === 'none' ? html`no report-status: ${r.why}` : html``; const band = r.sideband === null ? 'not banded' : `band 1 ${r.sideband.bands.data} B, band 2 ${r.sideband.bands.progress} B, band 3 ${r.sideband.bands.error} B${r.sideband.error.length > 0 ? `: ${r.sideband.error}` : ''}`; return kv([['commands', html``], ['capabilities', html`${w.request.capabilities.join(' ')}`], ['pack', kb(w.request.packBytes)], ['report-status', report], ['side-band', band]]); } case 'ls-refs': return kv([['arguments', html`${w.request.args.join(' ')}`], ['refs', w.refs.length === 0 ? 'none' : html``]]); case 'fetch': { const sb = w.answer.sideband; return kv([['arguments', html``], ['sections', w.answer.sections.join(', ')], ['side-band', sb === null ? 'none' : `band 1 ${kb(sb.bands.data)}, band 2 ${sb.bands.progress} B, band 3 ${sb.bands.error} B${sb.error.length > 0 ? `: ${sb.error}` : ''}`]]); } case 'opaque': return html`no git payload read`; } } function exchangeView(run: StoredRun, x: Exchange): Html { const timing = `start ${x.startMs} ms · headers ${x.headersMs === null ? '—' : `${x.headersMs} ms (+${x.headersMs - x.startMs})`} · end ${x.endMs} ms (${x.endMs - x.startMs} ms)`; const bodies = html`${x.requestBytes > 0 ? html`request body ` : null}${x.responseBytes > 0 ? html`response body` : null}`; return html`
    #${x.i} ${phaseName(x.phase)} · ${x.channel} · ${shortKind(x)} · ${answerText(x)} · ↑${kb(x.requestBytes)} ↓${kb(x.responseBytes)} · ${x.endMs - x.startMs} ms · ${renderRay(x.cfRay)}${x.applied === null ? null : html` · fault ${x.applied.tag}`} ${kv([['request', html`${x.method} ${x.path}`], ['answer', x.answer.tag === 'http' ? String(x.answer.status) : html`no answer: ${x.answer.error}`], ['cf-ray', html`${renderRay(x.cfRay)}`], ['timing', timing], ['fault', x.applied === null ? 'none' : html`${JSON.stringify(x.applied)}`], ['request headers', headerList(x.requestHeaders)], ['response headers', headerList(x.responseHeaders)], ['bodies', bodies]])} ${wireView(x.wire)}
    `; } function spansView(spans: readonly SpanRow[]): Html { const ordered = [...spans].sort((a, b) => a.startMs - b.startMs); const fill = (s: SpanRow): number => { let d = 0; let p = s.parent; while (p !== null && d < 12) { const up = spans.find(x => x.id === p); if (typeof up !== 'object') break; d++; p = up.parent; } return d; }; return html`${ordered.map(s => html``)}
    spanstartdurationstatusattributes
    ${s.name}${s.startMs} ms${Math.round(s.durationMs)} ms${s.ok ? 'ok' : html`error`}${Object.entries(s.attrs).filter(([k]) => k.startsWith('bench.') || k.startsWith('probe.') || k === 'cf.ray' || k === 'http.response.status_code' || k.startsWith('git.push') || k === 'error.type').map(([k, v]) => `${k}=${String(v)}`).join(' ')}
    `; } export function runPage(run: StoredRun, scenario: Scenario | null): Html { const r = run.result; const c = r.cleanup; const slug = replaySlug({ scenario: scenario === null ? ({ id: run.scenario } as Scenario) : scenario, run: run.id }); const steps = r.steps.map((o, i) => { const st = scenario === null ? null : scenario.steps[i]; const e = scenario === null ? null : scenario.expect[i]; const stated = typeof e === 'object' && e !== null ? (e.tag === 'one' ? `${e.ply.outcome} (${String(e.ply.error)})` : e.tag === 'either' ? e.ply.map(x => `${x.outcome} (${String(x.error)})`).join(' or ') : e.ply.join(', ')) : ''; const kind = typeof st === 'object' && st !== null ? (st.tag === 'push' || st.tag === 'fetch' ? `${st.tag}${st.fault.tag === 'none' ? '' : ` + ${st.fault.tag}`}` : st.tag) : ''; return html`${i}${kind}${o.outcomes.map(x => html`
    ${x.outcome} (${String(x.error)}) ${x.detail}
    `)}${stated}`; }); const end = r.end === null ? html`

    not read

    ` : kv([['HEAD', r.end.head === null ? '(none)' : r.end.head], ['refs', Object.keys(r.end.refs).length === 0 ? 'none' : html``], ['objects', String(r.end.objects.length)], ['not compared', 'fsck and merge bases (no git in a Worker)']]); return layout(`${run.scenario} · run ${run.id}`, html`

    ${run.scenario}

    ${scenario === null ? html`

    This scenario is not in the catalogue of the running ply.

    ` : html`

    ${scenario.description}

    `} ${kv([['run', html`${run.id}`], ['seed', run.seed], ['repository', html`${run.repo} (probe namespace; deleted)`], ['ply', html`${run.ply}`], ['started', iso(run.startedAt)], ['took', `${run.finishedAt - run.startedAt} ms, ${r.exchanges.length} exchanges`]])}

    Verdict

    ${verdictView(r.verdict)}

    Steps

    ${steps}
    #stepply concludedstated

    End state, read back by ply

    ${end}

    Protocol waterfall

    One row per exchange from the start of the run: light is the wait for the server's headers, dark the answer's body. Blue is ply under test (main), amber the other writer and the seed (side), grey the read-back and cleanup (judge). Each row links to its exchange below.

    ${waterfall(r.exchanges)}

    Exchanges

    ${r.exchanges.map(x => exchangeView(run, x))}

    Cleanup

    ${kv([['tokens listed', String(c.tokensListed)], ['tokens revoked', String(c.tokensRevoked)], ['revoked token tried', html`${c.revokedStatus === null ? 'no answer' : String(c.revokedStatus)} ${c.revokedRay} ${c.refused ? html`refused` : html`not refused`}`], ['repository deleted', c.deleted ? 'yes' : html`no`], ['repository gone', c.gone ? 'yes' : html`no`], ['errors', c.errors.length === 0 ? 'none' : c.errors.join('; ')]])}

    Export

    A replay for ply's probe suite: ${slug}.json and ${slug}.test.js. Put both in test/probes/replay/ of a ply checkout; the test runs the plan against git http-backend (the reference) and checks the recorded run against the expectation with that commit's evaluator.

    Spans

    ${spansView(run.spans)}`); } export function messagePage(title: string, text: string): Html { return layout(title, html`

    ${title}

    ${text}

    Back to the workbench

    `); } export const BENCH_CSS = ` :root{color-scheme:light dark;--fg:#1d1d1f;--bg:#fff;--muted:#6b7280;--line:#e5e7eb;--main:#2563eb;--side:#d97706;--judge:#6b7280;--bad:#b91c1c;--ok:#047857} @media (prefers-color-scheme:dark){:root{--fg:#e5e7eb;--bg:#111318;--muted:#9ca3af;--line:#2b2f36}} body{margin:0;font:14px/1.45 system-ui,sans-serif;color:var(--fg);background:var(--bg)} main{max-width:1180px;margin:0 auto;padding:12px 20px 60px} .top{display:flex;gap:16px;align-items:baseline;padding:10px 20px;border-bottom:1px solid var(--line)} .top a{font-weight:600;color:inherit;text-decoration:none}.roles{color:var(--muted);font-size:12px} h1{font-size:20px;margin:18px 0 6px}h2{font-size:16px;margin:26px 0 8px;border-bottom:1px solid var(--line);padding-bottom:4px} .mono,code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px} .muted,.note{color:var(--muted)}.note{font-size:12px}.bad{color:var(--bad)}.ok{color:var(--ok)} table{border-collapse:collapse;width:100%}th,td{text-align:left;vertical-align:top;padding:4px 8px;border-bottom:1px solid var(--line)} dl{display:grid;grid-template-columns:160px 1fr;gap:2px 12px;margin:6px 0}dt{color:var(--muted)}dd{margin:0} dd ul{margin:0;padding-left:16px} form.run{display:flex;gap:12px;align-items:center;flex-wrap:wrap;padding:10px;border:1px solid var(--line);border-radius:6px} select{max-width:420px} .notice{padding:8px;border-left:3px solid var(--side)} .verdict{padding:8px 10px;border-radius:6px;font-weight:600}.v-pass{background:#ecfdf5;color:#065f46}.v-fail{background:#fef2f2;color:#991b1b}.v-harness{background:#fffbeb;color:#92400e} .failure{border:1px solid var(--line);border-left-width:4px;border-radius:6px;padding:8px 10px;margin:8px 0} .failure .tag{font-weight:700;font-family:ui-monospace,monospace} .f-client_bug{border-left-color:var(--main)}.f-server_bug{border-left-color:var(--bad)}.f-expected_incompatibility{border-left-color:var(--ok)}.f-unresolved{border-left-color:var(--side)} .diff{margin:4px 0} .exchange{border:1px solid var(--line);border-left-width:4px;border-radius:4px;margin:4px 0;padding:2px 8px} .exchange summary{cursor:pointer;font-size:13px}.ch-main{border-left-color:var(--main)}.ch-side{border-left-color:var(--side)}.ch-judge{border-left-color:var(--judge)} .fault{color:var(--bad);font-weight:600} .headers{margin:0;padding-left:16px} .wf-wrap{overflow-x:auto;border:1px solid var(--line);border-radius:6px} .waterfall text{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;fill:var(--fg)} .waterfall .wf-tick{stroke:var(--line)}.waterfall .wf-tick-label{fill:var(--muted)} .waterfall .wf-phase{stroke:var(--muted);stroke-dasharray:3 3}.waterfall .wf-phase-label{fill:var(--muted);font-style:italic} .waterfall .wf-wait{opacity:.35}.waterfall .wf-main{fill:var(--main)}.waterfall .wf-side{fill:var(--side)}.waterfall .wf-judge{fill:var(--judge)} .waterfall .wf-failed rect{fill:var(--bad)}.waterfall .wf-fault{fill:var(--bad);font-weight:700}.waterfall .wf-ms{fill:var(--muted)} .waterfall a:hover text.wf-label{text-decoration:underline} .spans td{padding:2px 8px}.attrs{color:var(--muted);word-break:break-all} ${Array.from({ length: 9 }, (_, i) => `.d${i}{padding-left:${8 + i * 14}px}`).join('')} `;