Repository navigation
Merged
Conversation
tests/test_stdin_source_top_level_wins_344.py and tests/test_session_start_compact_recap_339.py named their own "today" staging file with time.strftime() at pytest collection time while scripts/session-start-hook.sh computes $TODAY at run time; a real UTC midnight crossing between those two reads (observed once, PR #421, pytest macos-latest/3.9, 57s past midnight) drops the today body from the recap and forks a stray background consolidation. Both files now shim `date` on PATH so both sides read one frozen value, and a new pinning test in the 344 file drives the two dates apart deliberately to confirm a genuine mismatch excludes only the stale file rather than blanking the rest of the recap. Fixes #422 Co-Authored-By: Max <noreply>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #422.
Both
tests/test_stdin_source_top_level_wins_344.pyand its siblingtests/test_session_start_compact_recap_339.pynamed their own "today" staging file with Python'stime.strftime("%Y-%m-%d")at pytest COLLECTION time (module import), whilescripts/session-start-hook.shcomputes its own$TODAYat RUN time -- minutes later on this suite's slower legs, since pytest collects every module before running any test.A run that straddles a real UTC-midnight crossing between those two reads leaves the fixture's "today" file with a different date suffix than the one
session-start-hook.sh:866buildsREMEMBER_TODAY_FILEfrom. That is a direct filename mismatch, not just a race:REMEMBER_TODAY_FILEthen simply names a path that does not exist, so the file's body is never selected byMEMORY_FILES(session-start-hook.sh:1219), which alone explains "body missing" with no timing window required. The stale fixture file is also, correctly, counted bySTAGING_COUNT(session-start-hook.sh:1395) as past-day staging and forks a backgroundrun-consolidation.sh(session-start-hook.sh:1399) -- both effects are visible in the CI artefact this was filed from (pytest (macos-latest, 3.9), PR #421, check-failure timestamped 57 seconds past UTC midnight, output carrying "1 day(s) of memory to compress").Note for the record: the consolidation fork happens strictly after
=== MEMORY ===is already printed to stdout (line 1243 vs. 1383+), and detaches vianohup ... & disownwhile the parent script runs to completion synchronously -- so there is no actual timing race for the test's own stdout capture. The mechanism is real and matches the observed failure, just slightly more direct than "races the test's own read": a plain filename mismatch is sufficient on its own.Fix
Both files now shim
dateon PATH (matching the existing idiom intests/test_ndc_day_boundary.pyandtests/test_doctor_timezone_357.py) so the fixture's "today" filename and the hook subprocess's own runtime clock read one frozen, arbitrary value -- never the real wall clock, closing the exposure regardless of when the suite actually runs, rather than narrowing the window by re-deriving at test time.REMEMBER_NO_PRINTF_T=1is set so the shim actually intercepts on bash >= 4.2, where_remember_dateotherwise prefers the spawn-freeprintf '%(FMT)T'builtin and never touches PATH -- the exact seamtests/test_prompt_hook_spawns.py::test_no_test_fakes_the_clock_on_path_without_disabling_the_builtinguards, which both files satisfy and which was run directly to confirm.Two new tests were added to the 344 file, both against the same shim mechanism:
test_a_stale_today_file_does_not_blank_the_rest_of_the_recap-- the must-fire pin. Drives the fixture's date and the hook's shimmed clock a day apart deliberately (no waiting for a real midnight) and asserts identity/core-memories/now/recent/archive bodies still all arrive, while documenting that the stale file is correctly excluded from the recap and correctly triggers consolidation -- that half is expected, legitimate behaviour once the two clocks genuinely disagree, not the defect.test_agreeing_dates_trigger_no_background_consolidation-- the must-not-fire control: with the two dates agreeing, no=== MEMORY CONSOLIDATION ===section should appear.Sibling module
Grepped
tests/*.pyforstrftime|datetime.now()|date.today()at module scope.tests/test_session_start_compact_recap_339.pywas the only other hit, with the byte-identical pattern and the same exposure -- fixed in this same commit with the same shim mechanism, since it is the same class, same file shape, no separate design decision needed.Scope
This diff touches only the two test files named above plus
changelog.d/422.fixed.md. Nothing underscripts/was touched (that tree is PR #421's lane, still open).Reproduction
A throwaway pytest file (not committed) built
today-2099-03-16.mdas the fixture's "today" file while shimming the hook's owndate +%Y-%m-%dto answer2099-03-17-- reproducing a real midnight crossing deterministically. Asserting the original test's own claim (all bodies present) failed with exactly the CI failure's shape:today-2099-03-16.md body missing, alongside=== MEMORY CONSOLIDATION === / 1 day(s) of memory to compressin the same output.Docs
README.md(the repo's onlydocs_targetsentry) was read against this change and needs none: it documents user-facing timezone/config behaviour and the test-running command, not this internal test-fixture convention.Testing
python3 -m pytest tests/test_stdin_source_top_level_wins_344.py tests/test_session_start_compact_recap_339.py -q-- 22 passed.python3 -m pytest tests/test_prompt_hook_spawns.py::test_no_test_fakes_the_clock_on_path_without_disabling_the_builtin -q-- 1 passed. Full suite not run: change is confined to two independent test modules with no shared fixture/conftest/production-code edits, and no rebase occurred.