sendResults
Send the results of a branch's tests the remote doesn't have, under the keys they were kept under: a test's hash covers what it runs, so its result holds wherever that runs the same. How many were sent (none from a remote that doesn't keep results: an older tcm).
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { chunks, testsIn } from "#codebase/tcmts/cli/sync"; import type { Remote, SharedResult } from "#codebase/tcmts/cli/sync"; import type { NameRow } from "#codebase/tcmts/store"; export async function sendResults(cb: Codebase, remote: Remote, names: NameRow[]): Promise<number> { const tests = testsIn(names); try { const theirs = new Set<string>(); for (const c of chunks(tests)) for (const [h, k] of (await remote.resultKeys(c)) ?? []) theirs.add(`${h} ${k}`); const missing: SharedResult[] = []; for (const h of tests) for (const key of cb.store.resultKeysOf(h)) if (!theirs.has(`${h} ${key}`)) missing.push({ ...cb.store.testResult(h, key)!, key }); // with the test framework's version they ran on, so a codebase pulling them runs tests on it too if (missing.some((r) => r.key.includes(" vitest@"))) await remote.putPackages(cb.store.lockedPackages().filter((e) => e.name === "vitest")); for (const c of chunks(missing, 200)) await remote.putResults(c); return missing.length; } catch { return 0; } }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.sync.Remote
- tcmts.cli.sync.SharedResult
- tcmts.cli.sync.chunks
- tcmts.cli.sync.testsIn
- tcmts.store.NameRow