Repository navigation
fix(test): record the DACL lockdown spy only on the test's own thread - #39055
Open
aniruddhaadak80 wants to merge 1 commit into
Open
aniruddhaadak80 wants to merge 1 commit into
aniruddhaadak80 wants to merge 1 commit into
Conversation
kirodotdev#37631: the `seen` fixture swaps the process-global platform_compat.restrict_to_owner for a spy that records every thread's calls, and three of its tests assert the exact list, its length or that it is empty. The SEL writer daemon re-locks its audit log through that same symbol on every append (src/kiro_crew/sel_append.py:255), so a flush of events an earlier test queued lands in `seen` and fails a test whose code is fine. Scope the spy to the fixture's own thread: record a call only when it is made on the thread that installed the fixture. Every writer these tests drive locks down on the calling thread, so none of their calls is dropped; a writer that ever moves to a worker thread fails here loudly (the expected call is missing) instead of passing on a stale count.
aniruddhaadak80
requested review from
a team and
KiroCrewCaptain
as code owners
November 18, 2026 09:00
aniruddhaadak80
requested review from
iamwhatever
and
a balanced review from Copilot
November 18, 2026 09:00
This branch has not been deployed
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.
Problem / Motivation
Goal: Scope
test_secret_file_owner_dacl.py'srestrict_to_ownerspy to the test's own thread, so the SEL writer thread can no longer fail an exact-list assertion in a test that has nothing to do with it.The file's
seenfixture swaps the process-globalplatform_compat.restrict_to_ownerfor a spy that records every call from every thread. Three of its tests then assert the exact list, its length, or that it is empty (test_telemetry_salt_is_restricted,test_log_append_is_restricted_on_windows,test_log_append_leaves_posix_to_the_creation_mode). The SEL writer is a daemon thread (sel-writer) that re-locks its non-empty audit log through that same symbol on every append (src/kiro_crew/sel_append.py:255). When it flushes events an earlier test on the same worker queued, its call lands inseenand the test fails on a change that has nothing to do with it. #33300 was this failure on macOS CI. The file landed (via #31288) after #33379's sites were swept, so itsseenfixture never got the thread scope the other spies got.Why it matters
Any backend PR can hit one of these reds, pay a rerun, and sit blocked on PR Readiness for a defect that is not in its diff — the same cost #35491 is removing for the nineteen remaining spies in fourteen other files. This file is the one site that issue's sweep did not cover, and it asserts on the exact list three times.
Not a goal
sel_append.py: the issue asks for thetmp_pathfilter only for a writer that locks down on a worker thread; none of these writers does._denyspies the issue marks unaffected.What changed (motivation -> approach -> change)
test_secret_file_owner_dacl.py's exact-list assertions on CI, caused by a lockdown from a thread the test never touched.seenfixture recorded calls from every thread, while the process-global symbol it replaced is also the one thesel-writerdaemon calls on each audit-log append (src/kiro_crew/sel_append.py:255).threading.get_ident()when it installs and its recorder appends only when the calling thread is that thread. The docstring records why the scope exists (Flaky risk: test_secret_file_owner_dacl's restrict_to_owner spy also records the SEL writer thread's calls #37631, the Flaky risk: restrict_to_owner spies in tests also record the SEL writer thread's calls #33379 exposure) and the writer sweep behind it:open_log_for_append_owner_only/restrict_file_to_owner_soft,_get_telemetry_salt,write_queue_atomic,_save_lockedand_save_coloursall run on the calling thread, so every lockdown these tests expect is made on the test's own thread. A writer that ever moves to a worker thread then fails here loudly (the expected call is missing) instead of silently passing on a stale count.restrict_to_ownerfrom a thread namedsel-writerright after the spy installs and after eachtempfile.mkstemp— turns the three remaining named tests red with the fixture reverted and leaves all twelve green with it in place. (The issue's fourth site,test_redaction_allow_list_is_restricted, no longer exists on main; the file changed since the issue was filed.)Backwards compatibility
Compatible: test-only change — no product code, no public surface, nothing main accepts today stops working.
Tests
test/test_secret_file_owner_dacl.py— 12/12 pass with the change in place;black --check,isort --check-onlyandflake8are clean on the file.test_telemetry_salt_is_restricted,test_log_append_is_restricted_on_windowsandtest_log_append_leaves_posix_to_the_creation_modefail on the foreign thread's call inseen; with the change in place, all twelve pass under the same plugin.Manual verification
N/A — unit coverage sufficient: the change is confined to one test fixture, the proof drives it through the same spy the CI flake hits, and no product or frontend surface changes.
Related Issues
Fixes #37631
Sibling sweep
Swept:
rg -n "restrict_to_owner" test --glob "*.py"— every test that monkeypatches the symbol the SEL writer calls, each checked for an exact-list, length or emptiness assertion.restrict_dir_to_owner, a symbol the SEL writer never callsrestrict_dir_to_owner, not the writer'srestrict_to_ownerPattern harvest
Rule candidate: review-prompt
Pattern: a test fixture replaces a process-global function with a recording spy and asserts the exact list, its length or emptiness, while a background daemon thread calls the same symbol — scope the spy to the test's own thread at install time.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.