docs(daemon): fix misleading comments in bar script env handling
- Record why collectBarScriptContext can capture sess.env without copying it, unlike every other reader in the package. - Correct the TestRefreshBarScriptsAllSessionsForcesRun comment: the 60s interval is not actually exercised since lastRefresh is zero on a fresh session, so the interval check is skipped regardless of force.
- commit
- 87551626c75d9920b729fa1a68f624d1d3c6300a
- author
- brice · · 2026-07-20 08:45 UTC
- parent
- 56f6958
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +8 -2
M internal/usecase/daemon/bar_refresh.go +3 -0
| @@ -107,6 +107,9 @@ func (d *Daemon) collectBarScriptContext(sess *session, anchor string) (barScrip | |||
| 107 | 107 | } | |
| 108 | 108 | sess.mu.Lock() | |
| 109 | 109 | ctx.Session = sess.name | |
| 110 | + | // No copy needed: writers always replace sess.env with a whole fresh | |
| 111 | + | // slice under sess.mu (daemon.go, resume.go), and nothing mutates the | |
| 112 | + | // backing array in place, so capturing the header here is safe. | |
| 110 | 113 | env := sess.env | |
| 111 | 114 | active := sess.active | |
| 112 | 115 | var tb *tab | |
| @@ -107,6 +107,9 @@ func (d *Daemon) collectBarScriptContext(sess *session, anchor string) (barScrip | |||||
| 107 | } | 107 | } | ||
| 108 | sess.mu.Lock() | 108 | sess.mu.Lock() | ||
| 109 | ctx.Session = sess.name | 109 | ctx.Session = sess.name | ||
| 110 | + | // No copy needed: writers always replace sess.env with a whole fresh | |||
| 111 | + | // slice under sess.mu (daemon.go, resume.go), and nothing mutates the | |||
| 112 | + | // backing array in place, so capturing the header here is safe. | |||
| 110 | env := sess.env | 113 | env := sess.env | ||
| 111 | active := sess.active | 114 | active := sess.active | ||
| 112 | var tb *tab | 115 | var tb *tab | ||
M internal/usecase/daemon/bar_refresh_test.go +5 -2
| @@ -222,8 +222,11 @@ func TestRefreshBarScriptsAllSessionsForcesRun(t *testing.T) { | |||
| 222 | 222 | sess.client = &attachedClient{size: domain.Size{Cols: 80, Rows: 24}} | |
| 223 | 223 | d.sessions = map[domain.SessionID]*session{sess.id: sess} | |
| 224 | 224 | ||
| 225 | - | // Nothing has run yet, and the 60s interval means a non-forced tick would | |
| 226 | - | // not be due for a long time. | |
| 225 | + | // Verifies refreshBarScriptsAllSessions iterates every live session and | |
| 226 | + | // dispatches a run for each. This does not exercise force specifically: | |
| 227 | + | // lastRefresh is zero on a fresh session, so refreshBarScriptsIfDue skips | |
| 228 | + | // the interval check regardless of force, and a non-forcing call would | |
| 229 | + | // pass this test too. | |
| 227 | 230 | d.refreshBarScriptsAllSessions() | |
| 228 | 231 | waitBarRefreshIdle(t, d) | |
| 229 | 232 | ||
| @@ -222,8 +222,11 @@ func TestRefreshBarScriptsAllSessionsForcesRun(t *testing.T) { | |||||
| 222 | sess.client = &attachedClient{size: domain.Size{Cols: 80, Rows: 24}} | 222 | sess.client = &attachedClient{size: domain.Size{Cols: 80, Rows: 24}} | ||
| 223 | d.sessions = map[domain.SessionID]*session{sess.id: sess} | 223 | d.sessions = map[domain.SessionID]*session{sess.id: sess} | ||
| 224 | 224 | ||||
| 225 | - | // Nothing has run yet, and the 60s interval means a non-forced tick would | 225 | + | // Verifies refreshBarScriptsAllSessions iterates every live session and |
| 226 | - | // not be due for a long time. | 226 | + | // dispatches a run for each. This does not exercise force specifically: |
| 227 | + | // lastRefresh is zero on a fresh session, so refreshBarScriptsIfDue skips | |||
| 228 | + | // the interval check regardless of force, and a non-forcing call would | |||
| 229 | + | // pass this test too. | |||
| 227 | d.refreshBarScriptsAllSessions() | 230 | d.refreshBarScriptsAllSessions() | ||
| 228 | waitBarRefreshIdle(t, d) | 231 | waitBarRefreshIdle(t, d) | ||
| 229 | 232 | ||||