Skip to content

fix(naughty): ensure default timeout applies without ruled.notification#4081

Open
JimmyCozza wants to merge 4 commits intoawesomeWM:masterfrom
JimmyCozza:fix/naughty-default-timeout
Open

fix(naughty): ensure default timeout applies without ruled.notification#4081
JimmyCozza wants to merge 4 commits intoawesomeWM:masterfrom
JimmyCozza:fix/naughty-default-timeout

Conversation

@JimmyCozza
Copy link
Copy Markdown
Contributor

@JimmyCozza JimmyCozza commented Mar 12, 2026

Fixes #3239 — notifications created without an explicit timeout and without ruled.notification never expire.

Three bugs in set_timeout() / create():

  1. The constructor guard if n._private.timeout then skipped set_timeout() entirely when no timeout was provided, so no timer was ever created and the notification lived forever.

  2. The fallback used cst.config.timeout which resolves to nil — the correct path is cst.config.defaults.timeout.

  3. The timer-stop logic was inside the if timeout > 0 branch, so switching to timeout=0 left the old timer referenced by self.timer. reset_timeout() could then accidentally restart it.

Includes a regression test (tests/test-naughty-timeout-init.lua) covering default timeout creation, timer cleanup on timeout=0, and reset_timeout() after clearing.

@JimmyCozza JimmyCozza closed this Mar 12, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.47%. Comparing base (94d38e6) to head (b8e919a).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4081      +/-   ##
==========================================
+ Coverage   90.45%   90.47%   +0.02%     
==========================================
  Files         941      941              
  Lines       60385    60422      +37     
  Branches     1145     1145              
==========================================
+ Hits        54621    54669      +48     
+ Misses       5254     5246       -8     
+ Partials      510      507       -3     
Files with missing lines Coverage Δ
lib/naughty/notification.lua 94.90% <100.00%> (+0.34%) ⬆️
tests/test-naughty-timeout-init.lua 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JimmyCozza JimmyCozza reopened this Mar 12, 2026
Elv13
Elv13 previously approved these changes Mar 14, 2026
Aire-One
Aire-One previously approved these changes Mar 15, 2026
Copy link
Copy Markdown
Member

@Aire-One Aire-One left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @JimmyCozza

…on (awesomeWM#3239)

- Remove constructor guard that skipped set_timeout() when no explicit
  timeout was provided
- Fix fallback config path: cst.config.timeout → cst.config.defaults.timeout
- Stop and nil old timer when setting timeout=0 (prevents stale timer leak)
- Add test covering both default-timeout and timeout=0 timer cleanup
Avoids deprecation warnings in test output. The constructor maps
`text` → `message`, so both work, but new tests should use the
current API.
@JimmyCozza JimmyCozza dismissed stale reviews from Aire-One and Elv13 via ae04548 March 16, 2026 15:56
@JimmyCozza JimmyCozza force-pushed the fix/naughty-default-timeout branch from 524bc22 to ae04548 Compare March 16, 2026 15:56
@JimmyCozza
Copy link
Copy Markdown
Contributor Author

merge conflict fixed

actionless
actionless previously approved these changes Mar 17, 2026
Comment thread tests/test-naughty-timeout-init.lua Outdated
Comment thread tests/test-naughty-timeout-init.lua Outdated
-- set_timeout(0) must stop the old timer and nil out self.timer so that
-- reset_timeout() doesn't accidentally restart a stale reference.
assert(n_timeout_zero.timer == nil,
"timer should be nil after setting timeout=0")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm yeah ok. I guess that's an alternative way to prevent the 5s wait from #3626 (comment) but makes the test aware of the internals.

That's not the best, but I guess I'm ok with it 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me think about this one and see if I can find an alternative approach.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aire-One

What do you think about a more "black-box" approach? No .timer or ._private checks at all.

For timeout=0: create with timeout=1, set to 0, wait ~1.5s, confirm the notification survives via the destroyed signal. Same pattern for reset_timeout().

For default timeout: call ruled.notification._clear() first so implicit_timeout doesn't mask the bug, then create without explicit timeout and wait for it to actually expire. (I found the previous version passed on master because ruled.notification was setting the timeout via implicit_timeout anyway.)

Tradeoff is a few extra seconds of runtime for real timer waits, and wait_per_step bumped to 8.

Comment thread tests/test-naughty-timeout-init.lua Outdated
- use public n.timeout getter instead of n._private.timeout
- use %d format for numeric fields
- shorten assert messages to regression labels
- drop redundant destroy guards and no-op kill_clients option
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.

Notifications with default timeout don't disappear (with naughty.list.notifications)

4 participants