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,24 +1,23 @@
/*
* 975_dirs_run — execute the lib/dirs @test fixture under the C-side
* `ww run` driver and assert exit 0.
* `ww test` driver and assert exit 0.
*
* Workflow:
* 1. mkdtemp /tmp/wwdirs-XXXXXX — fresh per run, no cross-run
* stale state, no parallel-test conflicts.
* 2. setenv the four cohort env states (see lib/dirs/dirstest.ww
* file header for the contract).
* 3. exec `ww run lib/dirs/dirstest.ww`. The fixture reads
* 3. exec `ww test lib/dirs/dirstest.ww`. The fixture reads
* WW_TEST_TMPDIR + the XDG_/HOME envs and asserts.
* 4. system("rm -rf <tmpl>") to reclaim the tmpdir + the
* auto-created child dirs (dirs.* mkdir-recursive on the way
* down, so the directory tree is non-empty by test exit).
* 4. Remove the exact auto-created child dirs bottom-up, then the
* mkdtemp-owned root.
*
* Same wrapper shape as 970-974; cleanup-on-failure is rm-rf'd so a
* test failure never leaves residue in /tmp.
* Same wrapper shape as 970-974; cleanup runs on success and failure.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
@@ -54,7 +53,7 @@ main(void)
return 1;
}
/* Pre-arrange env. The child `ww run` inherits these. */
/* Pre-arrange env. The child `ww test` inherits these. */
char cfg[128];
snprintf(cfg, sizeof cfg, "%s/cfg", tmpl);
setenv("HOME", tmpl, 1);
@@ -70,15 +69,39 @@ main(void)
snprintf(cmd, sizeof cmd, "%s/ww test %s", bin, path);
int rc = runwait(cmd);
/* Cleanup regardless of pass/fail — no residue under /tmp. */
char rmcmd[256];
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpl);
(void)system(rmcmd);
int fail = 0;
if (rc != 0) {
fprintf(stderr, "dirs_run FAIL: %s exited %d\n", src, rc);
return 1;
fail = 1;
}
/* dirs.* recursively creates these exact directory chains. */
char p[256];
int cleanbad = 0;
snprintf(p, sizeof p, "%s/cfg/myapp", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/cfg", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/.cache/myapp", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/.cache", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/.local/share/myapp", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/.local/share", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/.local/state/myapp", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/.local/state", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
snprintf(p, sizeof p, "%s/.local", tmpl);
if (rmdir(p) != 0 && errno != ENOENT) cleanbad = 1;
if (rmdir(tmpl) != 0) cleanbad = 1;
if (cleanbad) {
fprintf(stderr, "dirs_run FAIL: temporary cleanup failed\n");
fail = 1;
}
if (fail) return 1;
printf("dirs_run: %s ok\n", src);
return 0;
}