Compare commits

...
Author SHA1 Message Date
poli0981andClaude Opus 5 a717bf0d04 test(native): the log test reads this child's log, not a stale one under a reused pid
FindOverlayLog took the first overlay-<pid>-*.log by name in the real %LOCALAPPDATA%\FrameLedger\logs,
which keeps every run's log (2130 on the dev box). A harness that drew a reused pid read a finished
log from an earlier process and failed on the STOP line; a re-run drew a fresh pid and passed, so it
was filed as a flake four times while the failure output printed the stale path.

The lookup now takes the newest log created at or after the child started, and the test plants a
1999-dated log under the child's pid first, so the old behaviour is red on every run (9 of 18
assertions with the lookup reverted) and the fix is green (18 of 18). Test-only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 23:58:04 +07:00
3 changed files with 96 additions and 4 deletions

No files matched your search

+9
View File
@@ -147,6 +147,15 @@ under a `## [x.y.z] - date` heading in the same commit that bumps `VERSION`, the
### Fixed
- **The native log test read another process's log, and was filed as a flake four times (2026-09-14).**
`guard_test.cpp`'s `FindOverlayLog` took the first `overlay-<pid>-*.log` by name in the real
`%LOCALAPPDATA%\FrameLedger\logs`, which keeps every run's log — 2130 on the dev box. A harness that drew a
reused pid (6840) read a finished log from 2026-09-06 and failed on its STOP line; a re-run drew a fresh pid and
passed. The failure output had printed the stale path every time. It now takes the newest log created at or after
the child process started (`GetProcessTimes`), and the test now plants a 1999-dated log under the child's pid
before injecting, so the old lookup is red on every run instead of on pid reuse — measured: with the lookup
reverted, 9 of 18 assertions failed reading the planted file; with the fix, 18 of 18 pass and the file is removed
either way. Test-only: no shipped binary changes.
- **A DXGI present counter that went backwards read as four billion unseen presents (2026-09-14).** The Present
hook reads `IDXGISwapChain::GetLastPresentCount` before forwarding and took `now − previous` on the chain's slot
as unsigned arithmetic. A chain released and re-created at the same address inherits the slot and its old count
+5
View File
@@ -1669,6 +1669,11 @@ diagnosis*.
`SafetyNoticesTests` was green throughout: it asserted the model, and nothing instantiated the template.
When a control's affordance matters, render it (`PagesLoadTests` has the STA harness) and walk the visual
tree for the element — `16_WPFUI_SYNTAX` §Gotchas carries the fix and the test that retires it.
- **A test that finds a file by pid finds the wrong one on a machine that has run the tests before.** The native
log test looked up `overlay-<pid>-*.log` in the real `%LOCALAPPDATA%\FrameLedger\logs`, which keeps every run's
log (2130 on the dev box by 2026-09-14). A reused pid read a stale log and failed on the STOP line; the re-run
drew a new pid and passed, so it was called a flake four times while the failure output printed the September 6
path. **Read the path in a failure before calling it a flake**, and select by creation time, not by name.
---
+82 -4
View File
@@ -2238,7 +2238,20 @@ TEST_CASE("launch mode against the real harness through the real module seam: in
namespace {
// The newest logs\overlay-<pid>-*.log under %LOCALAPPDATA%\FrameLedger, if any.
bool FindOverlayLog(DWORD pid, std::wstring& out) {
// The log of THIS child, not the first file carrying its pid. Pids are reused and the logs directory outlives
// every run: measured 2026-09-14, the dev box held 2130 overlay logs and pid 6840 twice, and FindFirstFileW
// enumerated the 2026-09-06 file first -- so the test read a finished log from an unrelated earlier process and
// failed on the STOP line, then "passed on a re-run" with a fresh pid. Four gate runs were lost to that before the
// log path in the failure output gave it away. Only a file created at or after the child started can be its log,
// and of those the newest is taken.
bool FindOverlayLog(DWORD pid, HANDLE process, std::wstring& out) {
FILETIME started{};
FILETIME exited{};
FILETIME kernel{};
FILETIME user{};
if (!GetProcessTimes(process, &started, &exited, &kernel, &user)) {
return false;
}
wchar_t base[fl::guard::kMaxRulesPathLen]{};
if (!fl::guard::LocalAppDataDir(base, fl::guard::kMaxRulesPathLen)) {
return false;
@@ -2250,13 +2263,72 @@ bool FindOverlayLog(DWORD pid, std::wstring& out) {
if (h == INVALID_HANDLE_VALUE) {
return false;
}
bool found = false;
FILETIME newest{};
std::wstring name;
do {
if (CompareFileTime(&fd.ftCreationTime, &started) >= 0 &&
(!found || CompareFileTime(&fd.ftCreationTime, &newest) > 0)) {
newest = fd.ftCreationTime;
name = fd.cFileName;
found = true;
}
} while (FindNextFileW(h, &fd));
FindClose(h);
if (!found) {
return false;
}
std::wstring dir = pattern;
dir = dir.substr(0, dir.find_last_of(L'\\'));
out = dir + L"\\" + fd.cFileName;
FindClose(h);
out = dir + L"\\" + name;
return true;
}
// A finished log under a pid, dated long before the process that holds the pid now: what a reused pid meets on a
// machine that has run these tests before. The file is removed when the guard leaves scope, pass or fail.
struct StaleOverlayLog {
std::wstring path;
StaleOverlayLog() = default;
StaleOverlayLog(const StaleOverlayLog&) = delete;
StaleOverlayLog& operator=(const StaleOverlayLog&) = delete;
~StaleOverlayLog() {
if (!path.empty()) {
static_cast<void>(DeleteFileW(path.c_str()));
}
}
};
bool PlantStaleOverlayLog(DWORD pid, StaleOverlayLog& out) {
wchar_t base[fl::guard::kMaxRulesPathLen]{};
if (!fl::guard::LocalAppDataDir(base, fl::guard::kMaxRulesPathLen)) {
return false;
}
wchar_t dir[fl::guard::kMaxRulesPathLen]{};
_snwprintf_s(dir, _TRUNCATE, L"%s\\FrameLedger", base);
static_cast<void>(CreateDirectoryW(dir, nullptr));
_snwprintf_s(dir, _TRUNCATE, L"%s\\FrameLedger\\logs", base);
static_cast<void>(CreateDirectoryW(dir, nullptr));
// 19990101 sorts before every real log's date, so a lookup that takes the first match by name reads this file.
wchar_t path[fl::guard::kMaxRulesPathLen]{};
_snwprintf_s(path, _TRUNCATE, L"%s\\overlay-%lu-19990101-000000.log", dir, pid);
HANDLE h = CreateFileW(path, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (h == INVALID_HANDLE_VALUE) {
return false;
}
out.path = path;
static const char kText[] = "# a stale log planted by guard_test: an earlier process that had this pid\r\n";
SYSTEMTIME then{};
then.wYear = 1999;
then.wMonth = 1;
then.wDay = 1;
FILETIME old{};
DWORD written = 0;
const bool ok = WriteFile(h, kText, static_cast<DWORD>(sizeof(kText) - 1), &written, nullptr) != FALSE &&
SystemTimeToFileTime(&then, &old) != FALSE && SetFileTime(h, &old, &old, &old) != FALSE;
CloseHandle(h);
return ok;
}
std::string ReadWholeFile(const std::wstring& path) {
HANDLE h = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, nullptr);
@@ -2330,6 +2402,12 @@ TEST_CASE("the native log: written at init, on the Agent's request, and on the s
Child child;
REQUIRE(StartHarness(child, L"--real --hold-presenting 14"));
// A finished log already under this child's pid, dated 1999. The lookup must skip it -- it predates the child --
// or everything below reads an unrelated process's log: the defect that was filed as a flake four times, made
// deterministic here instead of left to pid reuse.
StaleOverlayLog stale;
REQUIRE(PlantStaleOverlayLog(child.pi.dwProcessId, stale));
ResetFake();
g.modules = {"kernel32.dll"};
g.scanSet = {child.pi.dwProcessId};
@@ -2342,7 +2420,7 @@ TEST_CASE("the native log: written at init, on the Agent's request, and on the s
std::wstring log;
bool found = false;
for (int i = 0; i < 40 && !found; ++i) {
found = FindOverlayLog(child.pi.dwProcessId, log);
found = FindOverlayLog(child.pi.dwProcessId, child.pi.hProcess, log);
if (!found) {
Sleep(50);
}