Cotton code
31 lines · 1.8 KB · TypeScriptRaw
import { spawnSync } from "node:child_process";import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join, resolve } from "node:path";import { expect, it } from "vitest";const helper = resolve(__dirname, "../ci/cargo-test-paired-shards.py");// RULE: Sharing a compile between sibling partitions never drops the second// partition after a failure, retries a real failure, or hides an empty suite.it("runs both original partitions once and retains every real failure", () => {  const root = mkdtempSync(join(tmpdir(), "cotton-paired-shards-"));  try {    const calls = join(root, "calls");    writeFileSync(join(root, "cargo"), '#!/bin/sh\nprintf "%s\\n" "$*" >> "$COTTON_TEST_CALLS"\ncase "$*" in *hash:3/8*) exit "$COTTON_TEST_FIRST";; *) exit "$COTTON_TEST_SECOND";; esac\n', { mode: 0o755 });    const args = ["nextest", "run", "--profile", "fast", "--no-fail-fast", "--partition", "hash:2/4", "--workspace", "--exclude", "probe"];    for (const [first, second, status] of [[0, 0, 0], [100, 0, 100], [0, 101, 101], [4, 0, 0], [0, 4, 0], [4, 4, 4], [4, 100, 100]]) {      writeFileSync(calls, "");      const out = spawnSync("python3", [helper, ...args], { encoding: "utf8", env: {        ...process.env, PATH: root + ":" + process.env.PATH,        COTTON_PARTITION_BUILD_TARGETS: "0", COTTON_TEST_CALLS: calls,        COTTON_TEST_FIRST: String(first), COTTON_TEST_SECOND: String(second),      } });      expect(out.status, out.stdout + out.stderr).toBe(status);      expect(readFileSync(calls, "utf8").trim().split("\n")).toEqual([        args.join(" ").replace("hash:2/4", "hash:3/8"),        args.join(" ").replace("hash:2/4", "hash:4/8"),      ]);    }  } finally { rmSync(root, { recursive: true, force: true }); }});