Skip to content

Commit 9c9b47a

Browse files
committed
FEATURE-ci-v3-runtime-green: make the file-source test asset rewrite checked and verified
The truncated mid-send suites failed three FreeBSD acceptance runs because temp_file::rewrite never checked its ofstream: a silently failed open left the asset intact and the send legally succeeded on the original content (full-stream timings in all three runs). Rewrite now truncates and writes through checked direct syscalls (rig shims, Windows _O_NOINHERIT branch) and verifies the visible post-write size, failing with evidence instead of losing the scenario. Stage-16 ledger in the task card; ChangeLog entries for this and the raw-archive Winsock linkage.
1 parent 0151bdb commit 9c9b47a

3 files changed

Lines changed: 89 additions & 34 deletions

File tree

‎ChangeLog‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
Version 3.0.0 - 2026-10-10
2+
Rewrite the file-source test asset with checked direct syscalls
3+
and a visible-size verification: a silently failed ofstream
4+
open left the asset intact, so the truncated mid-send suites
5+
legally succeeded on the original content (FreeBSD, three
6+
runs) instead of proving the short-body protocol error.
7+
Link the Windows network libraries into the raw static v3core
8+
archive consumers: the QUIC interop programs bypass libtool
9+
dependency propagation, so -lws2_32 -lmswsock -lbcrypt must
10+
ride the LDADD after the archive on Windows.
211
Link the QUIC interop provider test programs with a per-host
312
dynamic-loader flag: empty on Windows, -ldl elsewhere.
413
Bound the pre-filled pipe rig payload to the kernel pipe capacity

‎specs/tasks/FEATURE-ci-v3-runtime-green.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,12 @@ Full local `make check -j1` (TLS=no, g++ 15.2, WSL2): 232/235 pass, 2 platform s
207207
- [x] Windows `-ldl`: `configure.ac` derives `V3_TLS_DL_LIBS` from the existing `is_windows` host classification (empty on mingw/msys/cygwin, `-ldl` elsewhere) and `quic_interop_tls_LDADD` (inherited by `quic_interop_endpoint`) uses the substitution. POSIX branch verified in a fresh scratch worktree (`V3_TLS_DL_LIBS = -ldl` in the generated test/Makefile); the mingw64 empty branch was not compiled locally (no mingw toolchain), recorded honestly, CI compiles it.
208208
- [x] Local gates (macOS arm64 scratch worktree at f821d40a): bootstrap, configure (no doxygen flag), `response_sources` 30/304 checks green ×3, `response_definition` 32/311 checks green ×3, `native_http1_parity` green; cpplint clean on all three touched files; `git diff --check` clean; `test-v3-http3-full-gates.py` 1/1; ChangeLog entries added. Script tests on this host: `test-v3-ci-workflows.py` 30/31 and `test-v3-platform-ci.py` 11/20 — the failures are environmental (Apple BSD make lacks `--eval`, system python lacks `hashlib.file_digest`, a fixture git invocation) and the same single workflows failure reproduces at c3b235a8 in a throwaway worktree, so pre-existing; the Linux CI lane runs these green.
209209
- [ ] Full exact-source CI on the working branch (mingw64 tls-yes build, Windows acceptance, FreeBSD make check past both repairs).
210+
211+
## Stage 16: Windows raw-archive Winsock linkage and the FreeBSD truncation fixture (2026-12-02)
212+
213+
- [x] Evidence (runs 46731744600 package + 46731744909 acceptance, both at the b3ae3e95 merge preview 7819ff62): mingw64 tls-yes `make -j2` and the Windows acceptance in-tree build both fail linking `quic_interop_endpoint.exe` — undefined `__imp_inet_ntop/getsockopt/WSAIoctl/WSASocketW/WSARecvFrom/WSASendTo/WSARecv/WSASend/setsockopt/getpeername` from `io_iocp_backend.o` and `net/address.cpp` inside the raw `src/.libs/libhttpserver_v3core.a`. darwin acceptance and macos package never ran: GitHub-hosted runner-acquisition failures ("not acquired by Runner of type hosted", macOS arm64 capacity) — infrastructure, not code. FreeBSD tls-no `make check` failed 1/235 (`response_definition`, `file_send_truncated_mid_send_fails`, checks at lines 858/860, done==1 but outcome not protocol_error and `end_calls()==1`).
214+
- [x] Windows root cause: `quic_interop_tls_LDADD` is the only link line that takes the raw static v3core archive, bypassing libtool dependency propagation; automake places the global `LDFLAGS` (carrying `-lws2_32 -lmswsock -lbcrypt` on Windows) before the objects, too early to satisfy the archive's imports. Repair mirrors the stage-15 `V3_TLS_DL_LIBS` pattern: `configure.ac` substitutes `V3_NETWORK_LIBS` (`$NETWORK_LIBS` on Windows hosts, empty elsewhere) and the LDADD appends `$(V3_NETWORK_LIBS)` after the archive; `quic_interop_endpoint` inherits it. POSIX empty branch verified in the fresh scratch worktree (`V3_NETWORK_LIBS = ` in the generated `test/Makefile`, bootstrap exit 0 proves automake resolves it); the mingw64 branch is CI-verified. `check-v3-installed-consumer.py` already adds the three system libraries to its own Windows consumer links (line 118), so the installed lanes are covered.
215+
- [x] FreeBSD root cause (full `test-suite.log` and per-test logs extracted from artifact 15546253396, 5.1GB, into external evidence storage): across all three occurrences (2026-10-30 run 41120424110, 2026-11-30 run 46508507388, 2026-12-01 run 46731744909) test 24 ran at full-streaming time (2.6–3.8ms, matching whole-body test 20's 3.7ms; the fast-fail prepare-time short test 23 runs 0.32ms) — the post-rewrite reads always returned original bytes, so the send legally completed as success. The stage-15 "stall" was the old single-round assertion observing that legitimate in-flight success; the stage-15 drive loop then surfaced its true signature (done==1, wrong outcome, `end_calls()==1`). Mechanism: `temp_file::rewrite` used `std::ofstream(path, trunc)` and never checked the stream — a silently failed ofstream open leaves the 40960-byte asset intact (test 24's rewrite is invisible-by-construction; test 23's identical call is self-verifying because a failed rewrite fails its own protocol_error assertion, and it passed). Production `pull_file` behaved correctly for what it observed on every platform.
216+
- [x] Repair: `temp_file::rewrite` now truncates and writes through checked direct syscalls (POSIX `::open(O_WRONLY|O_TRUNC)`/`::write`/`::close`, Windows `_open(_O_WRONLY|_O_TRUNC|_O_BINARY|_O_NOINHERIT)`/`_write`/`_close`, the rig's `rig_write`/`rig_close` shims hoisted above the class) and verifies the visible post-write size via `std::filesystem::file_size`, failing with the sizes in the message. A platform that cannot truncate now fails the suite immediately with evidence instead of corrupting the scenario. The test assertions and the stage-15 drive loop are unchanged.
217+
- [x] Local gates (macOS arm64 scratch worktree at 0151bdbb + the rig edit): `response_sources` 30/304 green ×3, `response_definition` 32/311 green ×3, `native_http1_parity` green; a guard probe makes the truncating open impossible (chmod 0444) — the new rig throws with the errno evidence (EACCES) while the pre-fix rig silently succeeds, proving both sides of the failure mode; cpplint clean; `git diff --check` clean; the same workflow/platform script-test environmental baseline as stage 15. The Windows `_open` branch was not compiled locally (no mingw toolchain), recorded honestly, CI compiles it.
218+
- [ ] Full exact-source CI on the working branch (mingw64 tls-yes build past the endpoint link, Windows acceptance, FreeBSD make check past the fixture repair, darwin/macos lanes past the runner-capacity failures).

‎test/unit/response_source_rig.hpp‎

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@
3131
// after the payload).
3232

3333
#include <unistd.h>
34+
#include <fcntl.h> // ::open(O_WRONLY|O_TRUNC); the _O_* CRT names on Windows.
3435
#if defined(_WIN32)
35-
#include <fcntl.h> // _O_BINARY for the _pipe(3) restoration branch.
36-
#include <io.h> // _pipe/_write/_close/_fdopen (no POSIX ::pipe in MSYS2).
36+
#include <io.h> // _pipe/_open/_write/_close/_fdopen (no POSIX ::pipe in MSYS2).
3737
#endif
3838

3939
#include <atomic>
4040
#include <cerrno>
41+
#include <cstdint>
4142
#include <cstdio>
4243
#include <filesystem> // NOLINT(build/c++17): native v3 requires C++20.
43-
#include <fstream>
4444
#include <memory>
4545
#include <span>
4646
#include <stdexcept>
@@ -52,6 +52,35 @@
5252

5353
namespace httpserver_test {
5454

55+
// reason: MSYS2/mingw does not expose POSIX ::pipe(); the Windows CRT
56+
// equivalents from <io.h>/<fcntl.h> keep the same fd-pair shape in
57+
// binary mode (the restoration plan recorded in
58+
// test/PORTABILITY.md), so the parity /pipe route keeps its coverage
59+
// on every platform. The same shims serve the checked rewrite of the
60+
// scratch asset.
61+
#if defined(_WIN32)
62+
inline int rig_pipe(int* fds, std::size_t payload) noexcept {
63+
// The buffer must cover the whole payload: the constructor writes it
64+
// all before any reader exists, and a _pipe(3) write beyond the
65+
// buffer would block forever.
66+
const unsigned int bytes = payload < 4096u
67+
? 4096u : static_cast<unsigned int>(payload) + 1u;
68+
return ::_pipe(fds, bytes, _O_BINARY);
69+
}
70+
inline ssize_t rig_write(int fd, const char* buffer, std::size_t size) noexcept {
71+
return ::_write(fd, buffer, static_cast<unsigned>(size));
72+
}
73+
inline int rig_close(int fd) noexcept { return ::_close(fd); }
74+
inline std::FILE* rig_fdopen(int fd) noexcept { return ::_fdopen(fd, "rb"); }
75+
#else
76+
inline int rig_pipe(int* fds, std::size_t) noexcept { return ::pipe(fds); }
77+
inline ssize_t rig_write(int fd, const char* buffer, std::size_t size) noexcept {
78+
return ::write(fd, buffer, size);
79+
}
80+
inline int rig_close(int fd) noexcept { return ::close(fd); }
81+
inline std::FILE* rig_fdopen(int fd) noexcept { return ::fdopen(fd, "rb"); }
82+
#endif
83+
5584
// RAII scratch file: created from `content`, rewritable, removed on
5685
// destruction.
5786
class temp_file {
@@ -76,10 +105,46 @@ class temp_file {
76105

77106
const std::string& path() const noexcept { return path_; }
78107

108+
// Checked direct syscalls, verified by the visible size: an ofstream
109+
// whose open fails stays silently bad, leaving the asset untouched --
110+
// the truncated mid-send suites would then legally succeed on the
111+
// original content and the scenario would be lost (FreeBSD
112+
// 2026-10-30/2026-11-30/2026-12-01, full-stream timings). A platform
113+
// that cannot truncate fails here, with evidence, instead.
79114
void rewrite(const std::string& content) {
80-
std::ofstream out(path_, std::ios::binary | std::ios::trunc);
81-
out.write(content.data(),
82-
static_cast<std::streamsize>(content.size()));
115+
#if defined(_WIN32)
116+
const int fd = ::_open(path_.c_str(),
117+
_O_WRONLY | _O_TRUNC | _O_BINARY | _O_NOINHERIT);
118+
#else
119+
const int fd = ::open(path_.c_str(), O_WRONLY | O_TRUNC);
120+
#endif
121+
if (fd < 0) {
122+
throw std::system_error(errno, std::generic_category(),
123+
"task113: rewrite open " + path_);
124+
}
125+
std::size_t written = 0;
126+
while (written < content.size()) {
127+
const auto n = rig_write(fd, content.data() + written,
128+
content.size() - written);
129+
if (n <= 0) {
130+
const int saved = errno;
131+
rig_close(fd);
132+
throw std::system_error(saved, std::generic_category(),
133+
"task113: rewrite write " + path_);
134+
}
135+
written += static_cast<std::size_t>(n);
136+
}
137+
if (rig_close(fd) != 0) {
138+
throw std::system_error(errno, std::generic_category(),
139+
"task113: rewrite close " + path_);
140+
}
141+
const std::uint64_t visible =
142+
static_cast<std::uint64_t>(std::filesystem::file_size(path_));
143+
if (visible != content.size()) {
144+
throw std::runtime_error("task113: rewrite left " + path_ + " at " +
145+
std::to_string(visible) + " bytes instead of " +
146+
std::to_string(content.size()));
147+
}
83148
}
84149

85150
private:
@@ -134,34 +199,6 @@ inline httpserver::owned_close_fn counting_close(
134199
};
135200
}
136201

137-
// reason: MSYS2/mingw does not expose POSIX ::pipe(); the Windows CRT
138-
// equivalents from <io.h>/<fcntl.h> keep the same fd-pair shape in
139-
// binary mode (the restoration plan recorded in
140-
// test/PORTABILITY.md), so the parity /pipe route keeps its coverage
141-
// on every platform.
142-
#if defined(_WIN32)
143-
// The buffer must cover the whole payload: the constructor writes it
144-
// all before any reader exists, and a _pipe(3) write beyond the
145-
// buffer would block forever.
146-
inline int rig_pipe(int* fds, std::size_t payload) noexcept {
147-
const unsigned int bytes = payload < 4096u
148-
? 4096u : static_cast<unsigned int>(payload) + 1u;
149-
return ::_pipe(fds, bytes, _O_BINARY);
150-
}
151-
inline int rig_write(int fd, const char* buffer, std::size_t size) noexcept {
152-
return ::_write(fd, buffer, static_cast<unsigned>(size));
153-
}
154-
inline int rig_close(int fd) noexcept { return ::_close(fd); }
155-
inline std::FILE* rig_fdopen(int fd) noexcept { return ::_fdopen(fd, "rb"); }
156-
#else
157-
inline int rig_pipe(int* fds, std::size_t) noexcept { return ::pipe(fds); }
158-
inline ssize_t rig_write(int fd, const char* buffer, std::size_t size) noexcept {
159-
return ::write(fd, buffer, size);
160-
}
161-
inline int rig_close(int fd) noexcept { return ::close(fd); }
162-
inline std::FILE* rig_fdopen(int fd) noexcept { return ::fdopen(fd, "rb"); }
163-
#endif
164-
165202
// A pre-filled pipe read end as a std::FILE* (pipe(2) + fdopen; the
166203
// write end closes immediately so the read end sees EOF right after
167204
// the payload). One-shot by construction: no seek position, no second

0 commit comments

Comments
 (0)