-
Notifications
You must be signed in to change notification settings - Fork 7
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package errsystem | ||
|
|
||
| import ( | ||
| "errors" | ||
| "os" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestShowErrorAndExitWithQRCode(t *testing.T) { | ||
| // This test demonstrates the QR code functionality | ||
| // It will show the error banner with QR code, but we need to prevent actual exit | ||
| // We'll use a deferred recover to catch the os.Exit call | ||
|
|
||
|
Comment on lines
+10
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recover cannot intercept os.Exit; the comment is incorrect and potentially misleading os.Exit terminates the process immediately; defer/recover won’t run. This test as written will kill the test process when ShowErrorAndExit executes. Remove the misleading comment and avoid calling ShowErrorAndExit directly from a normal unit test. See next comment for a safe pattern. 🤖 Prompt for AI Agents |
||
| // Skip in CI or non-interactive environments | ||
| if os.Getenv("CI") != "" { | ||
| t.Skip("Skipping interactive test in CI environment") | ||
| } | ||
|
|
||
|
Comment on lines
+14
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Skip this “manual” test by default; don’t rely solely on CI detection Relying only on CI env risks accidental local exits during go test. Gate behind an explicit opt-in env var. Apply: - // Skip in CI or non-interactive environments
- if os.Getenv("CI") != "" {
- t.Skip("Skipping interactive test in CI environment")
- }
+ // Manual/interactive test: require explicit opt-in
+ if os.Getenv("ERRSYSTEM_QR_MANUAL") == "" {
+ t.Skip("Skipping manual ShowErrorAndExit test (set ERRSYSTEM_QR_MANUAL=1 to run)")
+ }Optionally, replace this test with a subprocess pattern that asserts exit code without killing the parent test runner. I can provide that snippet if you’d like. 🤖 Prompt for AI Agents |
||
| t.Log("This test will show an error with QR code. You should see the Discord QR code in the output.") | ||
|
|
||
| // Create a test error | ||
| testErr := errors.New("This is a test error to demonstrate the QR code feature") | ||
| errSys := New(ErrInvalidConfiguration, testErr, | ||
| WithContextMessage("Testing QR code display in unit test"), | ||
| WithUserMessage("This test shows the QR code feature working properly")) | ||
|
|
||
| // Note: In a real scenario, this would call os.Exit(1) | ||
| // For testing purposes, you can comment out the next line to see the QR code | ||
| // and manually verify it works, then uncomment it for automated testing | ||
|
|
||
| t.Log("Calling ShowErrorAndExit - this will show the QR code and then exit") | ||
| t.Log("The QR code should point to: https://discord.gg/agentuity") | ||
|
|
||
| // This will actually exit the test, but that's okay for a manual verification test | ||
| errSys.ShowErrorAndExit() | ||
| } | ||
|
|
||
| func TestGenerateQRCode(t *testing.T) { | ||
| // Test that QR code generation works | ||
| qrCode := generateQRCode("https://discord.gg/agentuity") | ||
|
|
||
| // Basic validation that something was generated | ||
| if len(qrCode) == 0 { | ||
| t.Error("QR code generation returned empty string") | ||
| } | ||
|
|
||
| // Check that it contains expected QR code characters | ||
| if !contains(qrCode, "█") { | ||
| t.Error("QR code should contain block characters") | ||
| } | ||
|
|
||
| t.Logf("Generated QR code length: %d characters", len(qrCode)) | ||
| } | ||
|
Comment on lines
+38
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Relax the assertion to support both full- and half-block render modes generateQRCode currently uses HalfBlocks=true, which typically uses ▀/▄, not █. The test will flake/fail depending on config or library changes. Apply: @@
- // Check that it contains expected QR code characters
- if !contains(qrCode, "█") {
- t.Error("QR code should contain block characters")
- }
+ // Check that it contains expected QR code characters (full or half blocks)
+ if !strings.ContainsAny(qrCode, "█▀▄") {
+ t.Error("QR code should contain block-drawing characters")
+ }Also update imports to use the stdlib helper (see next comment).
🤖 Prompt for AI Agents |
||
|
|
||
| func contains(s, substr string) bool { | ||
| return len(s) >= len(substr) && | ||
| (s == substr || | ||
| (len(s) > len(substr) && (s[:len(substr)] == substr || | ||
| s[len(s)-len(substr):] == substr || | ||
| containsInner(s, substr)))) | ||
| } | ||
|
|
||
| func containsInner(s, substr string) bool { | ||
| for i := 0; i <= len(s)-len(substr); i++ { | ||
| if s[i:i+len(substr)] == substr { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
Comment on lines
+55
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove custom contains helpers; they reimplement strings.Contains These helpers add complexity and potential bugs. Use strings.Contains/ContainsAny instead. Apply: -func contains(s, substr string) bool {
- return len(s) >= len(substr) &&
- (s == substr ||
- (len(s) > len(substr) && (s[:len(substr)] == substr ||
- s[len(s)-len(substr):] == substr ||
- containsInner(s, substr))))
-}
-
-func containsInner(s, substr string) bool {
- for i := 0; i <= len(s)-len(substr); i++ {
- if s[i:i+len(substr)] == substr {
- return true
- }
- }
- return false
-}
+// Custom contains helpers removed in favor of strings.Contains/ContainsAny.
🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Gate QR rendering on TTY; avoid dumping block characters into logs/non-interactive output
The comment says “when running in terminal,” but this block runs unconditionally. In non-TTY contexts (CI logs, file redirection), the QR’s block characters reduce readability and bloat logs.
Apply: