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

@@ -15,6 +15,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -43,15 +44,24 @@ static const char *PROG =
static int
run_stage(const char *name, const char *driver)
{
char tmpdir[64], src[128], outbin[128], rmcmd[160], cmd[2048];
snprintf(tmpdir, sizeof tmpdir, "/tmp/dtl_%d_d", getpid());
mkdir(tmpdir, 0755);
char tmpdir[64] = "/tmp/dtl_XXXXXX";
if (mkdtemp(tmpdir) == NULL) {
perror("dirs_toolong: mkdtemp");
return 1;
}
char src[128], outbin[128], sepwork[160], rmcmd[192], cmd[2048];
char shorthome[128], shortcfg[160], shortprog[192];
snprintf(src, sizeof src, "%s/dtl_%d.ww", tmpdir, getpid());
snprintf(outbin, sizeof outbin, "%s/dtl_%d", tmpdir, getpid());
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
snprintf(sepwork, sizeof sepwork, "%s.sepwork", outbin);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", sepwork);
snprintf(shorthome, sizeof shorthome, "%s/home", tmpdir);
snprintf(shortcfg, sizeof shortcfg, "%s/.config", shorthome);
snprintf(shortprog, sizeof shortprog, "%s/prog", shortcfg);
int fail = 0;
FILE *f = fopen(src, "wb");
if (!f) { runwait(rmcmd); return 1; }
if (!f) { fail = 1; goto cleanup; }
fputs(PROG, f);
fclose(f);
@@ -59,16 +69,14 @@ run_stage(const char *name, const char *driver)
driver, outbin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "dirs_toolong[%s]: build failed\n", name);
runwait(rmcmd);
return 1;
fail = 1;
goto cleanup;
}
int fail = 0;
/* short HOME — the normal path, must still exit 0. */
snprintf(cmd, sizeof cmd,
"env -u XDG_CONFIG_HOME HOME=/tmp/dtl_%d_home %s >/dev/null 2>&1",
getpid(), outbin);
"env -u XDG_CONFIG_HOME HOME=%s %s >/dev/null 2>&1",
shorthome, outbin);
if (runwait(cmd) != 0) {
fprintf(stderr, "dirs_toolong[%s]: short HOME did not exit 0\n",
name);
@@ -77,7 +85,7 @@ run_stage(const char *name, const char *driver)
/* ~260-byte HOME — must abort loudly (non-zero) and create no dir. */
char longhome[512];
int p = snprintf(longhome, sizeof longhome, "/tmp/dtl_%d_long_", getpid());
int p = snprintf(longhome, sizeof longhome, "%s/long_", tmpdir);
for (int i = 0; i < 260 && p < (int)sizeof longhome - 1; i++)
longhome[p++] = 'a';
longhome[p] = '\0';
@@ -96,13 +104,23 @@ run_stage(const char *name, const char *driver)
fprintf(stderr, "dirs_toolong[%s]: stray directory created\n",
name);
fail = 1;
snprintf(cmd, sizeof cmd, "rm -rf %s", longhome);
(void)system(cmd);
}
runwait(rmcmd);
snprintf(cmd, sizeof cmd, "rm -rf /tmp/dtl_%d_home", getpid());
(void)system(cmd);
cleanup: {
int cleanbad = 0;
if (unlink(src) != 0 && errno != ENOENT) cleanbad = 1;
if (unlink(outbin) != 0 && errno != ENOENT) cleanbad = 1;
if (runwait(rmcmd) != 0) cleanbad = 1;
if (rmdir(shortprog) != 0 && errno != ENOENT) cleanbad = 1;
if (rmdir(shortcfg) != 0 && errno != ENOENT) cleanbad = 1;
if (rmdir(shorthome) != 0 && errno != ENOENT) cleanbad = 1;
if (rmdir(tmpdir) != 0) cleanbad = 1;
if (cleanbad) {
fprintf(stderr, "dirs_toolong[%s]: temporary cleanup failed\n",
name);
fail = 1;
}
}
return fail;
}