-
-
Notifications
You must be signed in to change notification settings - Fork 25
feat(tui): add first-run error reporting opt-in prompt #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3775b82
feat(tui): add first-run error reporting opt-in prompt
wizzomafizzo 99bf44e
Merge branch 'main' into feat/error-reporting-prompt
wizzomafizzo fe5e7ef
Merge branch 'main' into feat/error-reporting-prompt
wizzomafizzo 56fa8b3
test(config): add TUI config tests for applyTUIDefaults and Load/Save…
wizzomafizzo 2730b28
fix(tui): set root before showing error reporting prompt to preserve …
wizzomafizzo ec8873b
fix(tui): check error reporting state from service API instead of loc…
wizzomafizzo 5b1c3b8
perf: build slug search cache in background during startup
wizzomafizzo bb5b233
perf: defer slug search cache build until after API is listening
wizzomafizzo 744d4b5
fix: resolve shadowed err variable in slug cache goroutine
wizzomafizzo fda4c97
fix: track slug cache rebuild as background operation for clean shutdown
wizzomafizzo 131ebb0
fix(test): replace sleeps with condition polling in pn532uart tests
wizzomafizzo 7815645
ci: ignore readers testutils in codecov coverage
wizzomafizzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| ignore: | ||
| - "pkg/testing/**/*" | ||
| - "pkg/readers/testutils/**/*" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| // Zaparoo Core | ||
| // Copyright (c) 2026 The Zaparoo Project Contributors. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // | ||
| // This file is part of Zaparoo Core. | ||
| // | ||
| // Zaparoo Core is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // Zaparoo Core is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with Zaparoo Core. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package config | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| platformids "github.com/ZaparooProject/zaparoo-core/v2/pkg/platforms/ids" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestApplyTUIDefaults_AllNil(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cfg := applyTUIDefaults(tuiConfigRaw{}, "generic") | ||
|
|
||
| assert.Equal(t, defaultTUITheme, cfg.Theme) | ||
| assert.Equal(t, defaultTUIWriteFormat, cfg.WriteFormat) | ||
| assert.True(t, cfg.Mouse) | ||
| assert.False(t, cfg.CRTMode) | ||
| assert.False(t, cfg.OnScreenKeyboard) | ||
| assert.False(t, cfg.ErrorReportingPrompted) | ||
| } | ||
|
|
||
| func TestApplyTUIDefaults_AllSet(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| theme := "dark" | ||
| writeFormat := "uid" | ||
| mouse := false | ||
| crt := true | ||
| osk := true | ||
| prompted := true | ||
|
|
||
| raw := tuiConfigRaw{ | ||
| Theme: &theme, | ||
| WriteFormat: &writeFormat, | ||
| Mouse: &mouse, | ||
| CRTMode: &crt, | ||
| OnScreenKeyboard: &osk, | ||
| ErrorReportingPrompted: &prompted, | ||
| } | ||
|
|
||
| cfg := applyTUIDefaults(raw, "generic") | ||
|
|
||
| assert.Equal(t, "dark", cfg.Theme) | ||
| assert.Equal(t, "uid", cfg.WriteFormat) | ||
| assert.False(t, cfg.Mouse) | ||
| assert.True(t, cfg.CRTMode) | ||
| assert.True(t, cfg.OnScreenKeyboard) | ||
| assert.True(t, cfg.ErrorReportingPrompted) | ||
| } | ||
|
|
||
| func TestApplyTUIDefaults_MisterPlatformDefaults(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cfg := applyTUIDefaults(tuiConfigRaw{}, platformids.Mister) | ||
|
|
||
| assert.True(t, cfg.CRTMode, "MiSTer should default CRT mode to true") | ||
| assert.True(t, cfg.OnScreenKeyboard, "MiSTer should default OSK to true") | ||
| } | ||
|
|
||
| func TestApplyTUIDefaults_MistexPlatformDefaults(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cfg := applyTUIDefaults(tuiConfigRaw{}, platformids.Mistex) | ||
|
|
||
| assert.True(t, cfg.CRTMode, "MiSTex should default CRT mode to true") | ||
| assert.True(t, cfg.OnScreenKeyboard, "MiSTex should default OSK to true") | ||
| } | ||
|
|
||
| func TestApplyTUIDefaults_PlatformDefaultsOverriddenByUser(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| crt := false | ||
| osk := false | ||
| raw := tuiConfigRaw{ | ||
| CRTMode: &crt, | ||
| OnScreenKeyboard: &osk, | ||
| } | ||
|
|
||
| cfg := applyTUIDefaults(raw, platformids.Mister) | ||
|
|
||
| assert.False(t, cfg.CRTMode, "User override should take precedence over platform default") | ||
| assert.False(t, cfg.OnScreenKeyboard, "User override should take precedence over platform default") | ||
| } | ||
|
|
||
| func TestApplyTUIDefaults_ErrorReportingPromptedExplicitFalse(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| prompted := false | ||
| raw := tuiConfigRaw{ | ||
| ErrorReportingPrompted: &prompted, | ||
| } | ||
|
|
||
| cfg := applyTUIDefaults(raw, "generic") | ||
|
|
||
| assert.False(t, cfg.ErrorReportingPrompted, "Explicit false should be preserved") | ||
| } | ||
|
|
||
| // TestTUIConfigGlobalState tests functions that mutate the global tuiCfg atomic. | ||
| // These cannot run in parallel with each other. | ||
| func TestTUIConfigGlobalState(t *testing.T) { | ||
| t.Run("GetSetTUIConfig", func(t *testing.T) { | ||
| cfg := TUIConfig{ | ||
| Theme: "custom", | ||
| WriteFormat: "uid", | ||
| Mouse: false, | ||
| CRTMode: true, | ||
| OnScreenKeyboard: true, | ||
| ErrorReportingPrompted: true, | ||
| } | ||
|
|
||
| SetTUIConfig(cfg) | ||
| got := GetTUIConfig() | ||
|
|
||
| assert.Equal(t, cfg, got) | ||
| }) | ||
|
|
||
| t.Run("LoadTUIConfig_CreatesDefaultWhenMissing", func(t *testing.T) { | ||
| dir := t.TempDir() | ||
|
|
||
| err := LoadTUIConfig(dir, "generic") | ||
| require.NoError(t, err) | ||
|
|
||
| tuiPath := filepath.Join(dir, TUIFile) | ||
| _, err = os.Stat(tuiPath) | ||
| require.NoError(t, err, "TUI config file should be created") | ||
|
|
||
| cfg := GetTUIConfig() | ||
| assert.Equal(t, defaultTUITheme, cfg.Theme) | ||
| assert.Equal(t, defaultTUIWriteFormat, cfg.WriteFormat) | ||
| assert.True(t, cfg.Mouse) | ||
| assert.False(t, cfg.ErrorReportingPrompted) | ||
| }) | ||
|
|
||
| t.Run("LoadTUIConfig_ReadsExistingFile", func(t *testing.T) { | ||
| dir := t.TempDir() | ||
| tuiPath := filepath.Join(dir, TUIFile) | ||
|
|
||
| content := `theme = "retro" | ||
| write_format = "uid" | ||
| mouse = false | ||
| crt_mode = true | ||
| on_screen_keyboard = false | ||
| error_reporting_prompted = true | ||
| ` | ||
| err := os.WriteFile(tuiPath, []byte(content), 0o600) | ||
| require.NoError(t, err) | ||
|
|
||
| err = LoadTUIConfig(dir, "generic") | ||
| require.NoError(t, err) | ||
|
|
||
| cfg := GetTUIConfig() | ||
| assert.Equal(t, "retro", cfg.Theme) | ||
| assert.Equal(t, "uid", cfg.WriteFormat) | ||
| assert.False(t, cfg.Mouse) | ||
| assert.True(t, cfg.CRTMode) | ||
| assert.False(t, cfg.OnScreenKeyboard) | ||
| assert.True(t, cfg.ErrorReportingPrompted) | ||
| }) | ||
|
|
||
| t.Run("LoadTUIConfig_FillsMissingWithDefaults", func(t *testing.T) { | ||
| dir := t.TempDir() | ||
| tuiPath := filepath.Join(dir, TUIFile) | ||
|
|
||
| content := `theme = "minimal" | ||
| ` | ||
| err := os.WriteFile(tuiPath, []byte(content), 0o600) | ||
| require.NoError(t, err) | ||
|
|
||
| err = LoadTUIConfig(dir, "generic") | ||
| require.NoError(t, err) | ||
|
|
||
| cfg := GetTUIConfig() | ||
| assert.Equal(t, "minimal", cfg.Theme) | ||
| assert.Equal(t, defaultTUIWriteFormat, cfg.WriteFormat) | ||
| assert.True(t, cfg.Mouse) | ||
| assert.False(t, cfg.CRTMode) | ||
| assert.False(t, cfg.ErrorReportingPrompted) | ||
| }) | ||
|
|
||
| t.Run("SaveTUIConfig_RoundTrip", func(t *testing.T) { | ||
| dir := t.TempDir() | ||
|
|
||
| original := TUIConfig{ | ||
| Theme: "saved", | ||
| WriteFormat: "uid", | ||
| Mouse: true, | ||
| CRTMode: false, | ||
| OnScreenKeyboard: true, | ||
| ErrorReportingPrompted: true, | ||
| } | ||
| SetTUIConfig(original) | ||
|
|
||
| err := SaveTUIConfig(dir) | ||
| require.NoError(t, err) | ||
|
|
||
| err = LoadTUIConfig(dir, "generic") | ||
| require.NoError(t, err) | ||
|
|
||
| loaded := GetTUIConfig() | ||
| assert.Equal(t, original, loaded) | ||
| }) | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.