Skip to content

Commit f6345f3

Browse files
simonfaltumIsaac
andcommitted
Restore the preview-off memo test and document the goroutine rule
The memo test with the preview unset proves the feature gate still wins over a memoised context. Restore it, and note in WithHintsMemo that HintsEnabled must run on the command goroutine since the memo has no lock. Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 94e2805 commit f6345f3

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎libs/skills/guard.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func Enabled(ctx context.Context) bool {
3939
// Every HintsEnabled call on the returned context, and on contexts derived from
4040
// it, gives the answer of the first call. A cache refresh later in the run,
4141
// such as the auto-install before the deferred hint prints, cannot then change
42-
// that hint's text, its throttle or the skills command exemption.
42+
// that hint's text, its throttle or the skills command exemption. The memo is
43+
// not locked, so HintsEnabled must run on the command goroutine.
4344
func WithHintsMemo(ctx context.Context) context.Context {
4445
return context.WithValue(ctx, hintsMemoKey{}, &hintsMemo{})
4546
}

‎libs/skills/guard_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ func TestHintsEnabledOncePerRun(t *testing.T) {
6666
assert.False(t, HintsEnabled(nextRun), "a new run reads the refreshed cache")
6767
}
6868

69+
// The memo does not reach past the feature gate: with the preview off, hints
70+
// stay off whatever the cache says, memo or not.
71+
func TestHintsEnabledOncePerRunPreviewOff(t *testing.T) {
72+
testutil.CleanupEnvironment(t)
73+
ctx := t.Context()
74+
writeCachedManifest(t, ctx, entryOn, time.Now())
75+
76+
assert.False(t, HintsEnabled(WithHintsMemo(ctx)))
77+
}
78+
6979
func TestHintsEnabled(t *testing.T) {
7080
cases := []struct {
7181
name string

0 commit comments

Comments
 (0)