Skip to content

fix(tests): send platform-absolute event paths in the preemptive-context tests (#692, class 5) - #920

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/692-preemptive-context-windows-paths
Nov 6, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/692-preemptive-context-windows-paths

Conversation

@cdeust

@cdeust cdeust commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Refs #692 (classe 5, première partie : test_preemptive_context, 9 tests)

Cause racine

Le run Windows 38008915302 (job 114084097957) échoue sur 9 tests de tests_py/hooks/test_preemptive_context.py avec « _prime_file_memories called 0 times ». Les événements portent file_path: "/a.py", qui n'a pas de lecteur sous Windows (PureWindowsPath("/a.py").is_absolute() vaut False) : _event_paths le rejette, à juste titre, comme chemin relatif sans cwd. Le hook est correct, la fixture supposait POSIX. Les chemins sont maintenant construits depuis la racine résolue du système de fichiers (C:\ sous Windows, / ailleurs).

test_expired_cooldown_primes_again semait la clé "/a.py" alors que le cooldown est indexé par json.dumps([project, path]) : il passait même avec un cooldown frais. Il sème maintenant hook._cooldown_key(A_PY, None).

Tests lancés

  • pytest tests_py/hooks/test_preemptive_context.py (Linux) : 25 passés.
  • Mutation : avec stale = time.time(), l'ancien test d'expiration passe (vacuité), le nouveau échoue.
  • ruff check, ruff format --check, scripts/check_craftsmanship.py : OK.

Non vérifié

Rien n'a tourné sous Windows ; la correction s'appuie sur le log du run 38008915302 et sur la sémantique de PureWindowsPath. Le reste de la classe 5 (test_validate_memory 4, test_capture_dispatch 1, test_session_queue[~/state] 1) n'est pas dans cette PR.


Generated by Claude Code

…ext tests (#692, class 5)

The Windows full-suite run 38008915302 (job 114084097957) failed 9 tests
of tests_py/hooks/test_preemptive_context.py with "_prime_file_memories
called 0 times": the events carried file_path "/a.py", which has no
drive on Windows (PureWindowsPath("/a.py").is_absolute() is False), so
_event_paths rejected it as a relative path with no cwd. The hook is
right; the fixture assumed POSIX. The paths are now built from the
resolved filesystem root (C:\ on Windows, / elsewhere).

test_expired_cooldown_primes_again seeded the key "/a.py", but the
cooldown is keyed by json.dumps([project, path]); it passed even with a
fresh cooldown. It now seeds hook._cooldown_key(A_PY, None) and fails
when the cooldown is not expired (checked by mutation).

Refs #692

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018kyZYrLmY9FajFeAEPo9rw
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T23:27:50.506874Z cd919d7 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-06T23:29:02.189153Z cd919d7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Claude finished @cdeust's task in 1m 42s —— View job


Review of PR #920 (review 1 of 3)

No Blockers. On Windows, C:\a.py passes is_absolute(), and .resolve() returns the same string, so assert_called_once_with(A_PY, None) still matches. project is None in these tests, so the seeded _cooldown_key(A_PY, None) is the key the hook actually looks up. The "/a.py" strings that are left are only used as plain cooldown keys or passed to a mock, so they don't fail on Windows.

I posted two Notes, neither needed before merge:

  • A sibling test seeding a fresh cooldown would catch the case where the seed is silently ignored again.
  • The fix hasn't been run on Windows yet.

Verdict: approve

@claude

claude Bot commented Nov 6, 2026

Copy link
Copy Markdown

Review 1/3: PR #920

Five reviewers ran (code quality, performance, test coverage, docs accuracy, security). I traced their claims against mcp_server/hooks/preemptive_context.py and mcp_server/shared/project_scope.py. None of them found a Blocker.

What I checked:

  • The assertion holds on Windows. A_PY = str(Path("/").resolve() / "a.py") gives something like C:\a.py. That passes is_absolute() at preemptive_context.py:134. Line 136 computes Path("/") / "C:\a.py"; the joined path has a drive, so it replaces the left side and .resolve() returns the same string. So assert_called_once_with(A_PY, None) still matches.
  • project is really None in these tests. resolve_project_root only reads CLAUDE_PROJECT_ROOT, which the autouse fixture removes, and event["cwd"], which no test event sets.
  • The expired-cooldown test now tests expiry. The seeded key now equals json.dumps([None, A_PY]), the key _check_cooldown actually looks up. The old "/a.py" seed was never read.
  • The remaining "/a.py" strings are safe. The ones in the _check_cooldown, _update_cooldown and store tests are opaque keys or are passed to a mock. None of them goes through _event_paths, so they do not fail on Windows.
  • The CHANGELOG entry and the new comment are accurate. No security or performance concerns: the only file the tests write goes to tmp_path.

Notes, no action before merge

  • test_expired_cooldown_primes_again would still pass if the seed were silently ignored again, for example after another key-format change. A sibling test that seeds a fresh _cooldown_key(A_PY, None) and asserts prime.assert_not_called() would pin that down.
  • Nothing has run on Windows yet; the PR body says so. The next Windows full-suite run will confirm the fix.

Verdict: approve

cdeust commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner Author

Sur la note non bloquante de la revue 1/3 (test frère avec une clé fraîche) : je ne la pousse pas dans cette PR. La graine est maintenant construite par hook._cooldown_key, la fonction même que process_event utilise pour la lecture : un changement de format de clé change les deux côtés à la fois et ne peut plus rendre la graine silencieusement ignorée. Le seul écart restant serait que process_event cesse d'appeler _cooldown_key, et test_second_event_within_the_window_is_skipped couvre déjà le comportement « cooldown frais, pas de second priming ». Le test proposé reste une amélioration possible, pas un défaut de cette PR.


Generated by Claude Code

@github-actions
github-actions Bot merged commit 0f98b53 into main Nov 6, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants