test/wcc: carrier ownership repair and driver-contract adaptation

Every surviving carrier now owns its artifacts: checked mkdir/mkdtemp/
fopen acquisition, one all-exit cleanup funnel per carrier, ENOENT-
tolerant checked unlinks, exact-path deletion (rm -rf only for an
owned pid-keyed dir or a .sepwork beneath one), and cleanup failure
fails a passing carrier without overwriting its diagnostic. In the
same pass the carriers adapt to the driver contract this branch lands:
--sep and WW_PKGCACHE are gone, -S and the /tmp/ww_run_<pid> scratch
contract are asserted, and rows whose runtime or reject coverage moved
to test/wcc/data fixtures or test/lang @test owners are trimmed to the
byte/artifact/diagnostic observations only they can make.

Repair and adaptation ride together because most files interleave both
in the same hunks; splitting would manufacture intermediate carrier
states that never existed and cannot run against either driver.
This commit is contained in:
2026-08-07 23:02:47 +09:00
parent b2899dd8d3
commit a95a7a316b
132 changed files with 7573 additions and 6172 deletions

View File

@@ -1,8 +1,6 @@
/*
* The white-box half must be the -T root: dependency packages lose @test
* declarations before code generation. Keep it separate from the external
* regex_test binary because each -T unit owns main and __wwtests.
*/
/* The canonical package route builds separate regex and regex_test -T roots
* under one `ww test <dir>` result. This legacy oracle pins the real 15/33
* split without recreating package discovery itself. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -108,25 +106,39 @@ okcount(const char *out)
}
static int
checkresult(const char *label, const char *out, int expected,
const char *const *names, size_t nnames)
checkresult(const char *out)
{
char summary[64], row[256];
char row[256];
const char *white_account, *external_account;
int bad;
bad = 0;
snprintf(summary, sizeof summary, "%d passed, 0 failed", expected);
if (linecount(out, summary) != 1 || okcount(out) != expected
|| strstr(out, "FAIL") != NULL || strstr(out, "No tests run") != NULL) {
fprintf(stderr, "regex_run FAIL: %s result was incomplete\n%s",
label, out);
white_account = strstr(out,
"15 discovered, 15 selected, 15 started, 15 completed\n");
external_account = strstr(out,
"33 discovered, 33 selected, 33 started, 33 completed\n");
if (linecount(out,
"15 passed, 0 failed, 0 skipped, 0 harness errors") != 1
|| linecount(out,
"15 discovered, 15 selected, 15 started, 15 completed") != 1
|| linecount(out,
"33 passed, 0 failed, 0 skipped, 0 harness errors") != 1
|| linecount(out,
"33 discovered, 33 selected, 33 started, 33 completed") != 1
|| okcount(out) != 48 || white_account == NULL
|| external_account == NULL || white_account >= external_account
|| strstr(out, "FAIL") != NULL || strstr(out, "HARNESS") != NULL
|| strstr(out, "[no tests]") != NULL
|| strstr(out, "[no matches]") != NULL) {
fprintf(stderr, "regex_run FAIL: package result was incomplete\n%s",
out);
bad = 1;
}
for (size_t i = 0; i < nnames; i++) {
snprintf(row, sizeof row, "%s ... ok", names[i]);
for (size_t i = 0; i < sizeof whitebox / sizeof whitebox[0]; i++) {
snprintf(row, sizeof row, "regex.%s ... ok", whitebox[i]);
if (linecount(out, row) != 1) {
fprintf(stderr, "regex_run FAIL: %s did not execute exactly once\n",
names[i]);
fprintf(stderr, "regex_run FAIL: regex.%s did not execute "
"exactly once\n", whitebox[i]);
bad = 1;
}
}
@@ -138,7 +150,7 @@ main(void)
{
const char *bin;
char absbin[1024], cwd[1024], tmp[] = "/tmp/wwregex.XXXXXX";
char cmd[4096], output[32768], cleanup[1200];
char cmd[4096], output[32768];
int rc, failed;
bin = getenv("BIN");
@@ -158,42 +170,25 @@ main(void)
return 1;
failed = 0;
/* A unique cwd prevents an unrelated local `regex` path from winning
* the module lookup; the private cache keeps the source tree untouched. */
/* A unique cwd prevents an unrelated local `regex` path from winning;
* the package coordinator owns both compatible groups in lexical order. */
if (snprintf(cmd, sizeof cmd,
"cd '%s' && WW_PKGCACHE='%s/cache-black' timeout 180 '%s/ww' "
"test -I '%s/lib' '%s/lib/regex/regex_test.ww'",
tmp, tmp, bin, cwd, cwd) >= (int)sizeof cmd) {
"cd '%s' && timeout 180 '%s/ww' "
"test -I '%s/lib' '%s/lib/regex'",
tmp, bin, cwd, cwd) >= (int)sizeof cmd) {
failed = 1;
} else {
rc = runcapture(cmd, output, sizeof output);
if (rc != 0 || checkresult("black-box", output, 33, NULL, 0) != 0) {
fprintf(stderr, "regex_run FAIL: black-box exited %d\n", rc);
if (rc != 0 || checkresult(output) != 0) {
fprintf(stderr, "regex_run FAIL: package exited %d\n", rc);
failed = 1;
} else {
printf("regex_run: black-box 33 discovered, 33 passed, 0 failed\n");
printf("regex_run: package 15 white-box + 33 external, "
"48 passed, 0 failed\n");
}
}
/* Resolving the package directory as the root keeps -T off imported
* dependencies while making every in-package probe visible to the synth. */
if (snprintf(cmd, sizeof cmd,
"cd '%s' && WW_PKGCACHE='%s/cache-white' timeout 180 '%s/ww' "
"test -I '%s/lib' regex", tmp, tmp, bin, cwd) >= (int)sizeof cmd) {
failed = 1;
} else {
rc = runcapture(cmd, output, sizeof output);
if (rc != 0 || checkresult("white-box", output, 15, whitebox,
sizeof whitebox / sizeof whitebox[0]) != 0) {
fprintf(stderr, "regex_run FAIL: white-box exited %d\n", rc);
failed = 1;
} else {
printf("regex_run: white-box 15 discovered, 15 passed, 0 failed\n");
}
}
snprintf(cleanup, sizeof cleanup, "rm -rf -- '%s'", tmp);
if (runwait(cleanup) != 0) {
if (rmdir(tmp) != 0) {
fprintf(stderr, "regex_run FAIL: cannot clean temporary directory\n");
failed = 1;
}