Skip to content

Commit 0aa90cf

Browse files
committed
Add command tests and /commit quality check command
1 parent 7559136 commit 0aa90cf

9 files changed

Lines changed: 1070 additions & 0 deletions

File tree

.gg/commands/commit.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: commit
3+
description: Run checks, commit with AI message, and push
4+
---
5+
6+
1. Run quality checks — fix ALL errors before continuing:
7+
- `gofmt -w .`
8+
- `go vet ./...`
9+
- `go test ./... -count=1`
10+
11+
2. Review changes: run `git status`, `git diff --staged`, and `git diff`
12+
13+
3. Stage relevant files with `git add` (specific files, not -A)
14+
15+
4. Generate a commit message:
16+
- Start with verb (Add/Update/Fix/Remove/Refactor)
17+
- Be specific and concise, one line preferred
18+
19+
5. Commit and push:
20+
- `git commit -m "your generated message"`
21+
- `git push`

internal/cli/commands/auth_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,82 @@ func TestAuthStatus_CustomAPIURL(t *testing.T) {
572572
t.Errorf("expected custom_api_url=true, got %v", result["custom_api_url"])
573573
}
574574
}
575+
576+
func TestAuthLoginWithSigningKeyFallback(t *testing.T) {
577+
tmp := t.TempDir()
578+
cfgPath := filepath.Join(tmp, "cli.json")
579+
config.ResetForTest()
580+
t.Setenv("INNGEST_CLI_CONFIG", cfgPath)
581+
t.Setenv("INNGEST_SIGNING_KEY_FALLBACK", "")
582+
583+
state.Config = &config.Config{}
584+
state.Output = "json"
585+
586+
cmd := NewAuthCmd()
587+
cmd.SetArgs([]string{"login", "--signing-key", "signkey-test-primary", "--signing-key-fallback", "signkey-test-fallback"})
588+
var buf bytes.Buffer
589+
cmd.SetOut(&buf)
590+
cmd.SetErr(&buf)
591+
592+
got := captureStdout(t, func() {
593+
if err := cmd.Execute(); err != nil {
594+
t.Fatalf("unexpected error: %v", err)
595+
}
596+
})
597+
598+
if state.Config.SigningKey != "signkey-test-primary" {
599+
t.Errorf("expected signing key %q, got %q", "signkey-test-primary", state.Config.SigningKey)
600+
}
601+
if state.Config.SigningKeyFallback != "signkey-test-fallback" {
602+
t.Errorf("expected signing key fallback %q, got %q", "signkey-test-fallback", state.Config.SigningKeyFallback)
603+
}
604+
// Output should contain redacted fallback
605+
if !strings.Contains(got, "signing_key_fallback") {
606+
t.Errorf("expected output to contain signing_key_fallback, got: %s", got)
607+
}
608+
}
609+
610+
func TestAuthLoginFallbackFromEnv(t *testing.T) {
611+
tmp := t.TempDir()
612+
cfgPath := filepath.Join(tmp, "cli.json")
613+
config.ResetForTest()
614+
t.Setenv("INNGEST_CLI_CONFIG", cfgPath)
615+
t.Setenv("INNGEST_SIGNING_KEY_FALLBACK", "signkey-test-envfallback")
616+
617+
state.Config = &config.Config{}
618+
state.Output = "json"
619+
620+
cmd := NewAuthCmd()
621+
cmd.SetArgs([]string{"login", "--signing-key", "signkey-test-primary"})
622+
var buf bytes.Buffer
623+
cmd.SetOut(&buf)
624+
cmd.SetErr(&buf)
625+
626+
if err := cmd.Execute(); err != nil {
627+
t.Fatalf("unexpected error: %v", err)
628+
}
629+
630+
if state.Config.SigningKeyFallback != "signkey-test-envfallback" {
631+
t.Errorf("expected signing key fallback %q, got %q", "signkey-test-envfallback", state.Config.SigningKeyFallback)
632+
}
633+
}
634+
635+
func TestAuthLoginInvalidFallbackKey(t *testing.T) {
636+
state.Config = &config.Config{}
637+
state.Output = "json"
638+
t.Setenv("INNGEST_SIGNING_KEY_FALLBACK", "")
639+
640+
cmd := NewAuthCmd()
641+
cmd.SetArgs([]string{"login", "--signing-key", "signkey-test-primary", "--signing-key-fallback", "bad-fallback"})
642+
var buf bytes.Buffer
643+
cmd.SetOut(&buf)
644+
cmd.SetErr(&buf)
645+
646+
err := cmd.Execute()
647+
if err == nil {
648+
t.Fatal("expected error for invalid signing key fallback")
649+
}
650+
if !strings.Contains(err.Error(), "invalid signing key fallback") {
651+
t.Errorf("expected error about invalid signing key fallback, got: %v", err)
652+
}
653+
}

internal/cli/commands/config_test.go

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,197 @@ func TestConfigSource(t *testing.T) {
301301
t.Errorf("expected source 'unknown' for bogus key, got %q", got)
302302
}
303303
}
304+
305+
func TestConfigSetEventKey(t *testing.T) {
306+
tmp := t.TempDir()
307+
cfgPath := filepath.Join(tmp, "cli.json")
308+
config.ResetForTest()
309+
t.Setenv("INNGEST_CLI_CONFIG", cfgPath)
310+
311+
state.Config = &config.Config{}
312+
state.Output = "json"
313+
314+
cmd := NewConfigCmd()
315+
cmd.SetArgs([]string{"set", "event_key", "my-event-key-123"})
316+
cmd.SetOut(&bytes.Buffer{})
317+
cmd.SetErr(&bytes.Buffer{})
318+
319+
var out string
320+
var execErr error
321+
out = captureStdout(t, func() {
322+
execErr = cmd.Execute()
323+
})
324+
if execErr != nil {
325+
t.Fatalf("unexpected error: %v", execErr)
326+
}
327+
328+
if state.Config.EventKey != "my-event-key-123" {
329+
t.Errorf("expected EventKey %q, got %q", "my-event-key-123", state.Config.EventKey)
330+
}
331+
// Event key should be redacted in output
332+
if strings.Contains(out, "my-event-key-123") {
333+
t.Error("output contains unredacted event key")
334+
}
335+
}
336+
337+
func TestConfigSetAPIBaseURL(t *testing.T) {
338+
tmp := t.TempDir()
339+
cfgPath := filepath.Join(tmp, "cli.json")
340+
config.ResetForTest()
341+
t.Setenv("INNGEST_CLI_CONFIG", cfgPath)
342+
343+
state.Config = &config.Config{}
344+
state.Output = "json"
345+
346+
cmd := NewConfigCmd()
347+
cmd.SetArgs([]string{"set", "api_base_url", "https://custom.inngest.com"})
348+
cmd.SetOut(&bytes.Buffer{})
349+
cmd.SetErr(&bytes.Buffer{})
350+
351+
var execErr error
352+
captureStdout(t, func() {
353+
execErr = cmd.Execute()
354+
})
355+
if execErr != nil {
356+
t.Fatalf("unexpected error: %v", execErr)
357+
}
358+
359+
if state.Config.APIBaseURL != "https://custom.inngest.com" {
360+
t.Errorf("expected APIBaseURL %q, got %q", "https://custom.inngest.com", state.Config.APIBaseURL)
361+
}
362+
}
363+
364+
func TestConfigSetDevServerURL(t *testing.T) {
365+
tmp := t.TempDir()
366+
cfgPath := filepath.Join(tmp, "cli.json")
367+
config.ResetForTest()
368+
t.Setenv("INNGEST_CLI_CONFIG", cfgPath)
369+
370+
state.Config = &config.Config{}
371+
state.Output = "json"
372+
373+
cmd := NewConfigCmd()
374+
cmd.SetArgs([]string{"set", "dev_server_url", "http://localhost:9999"})
375+
cmd.SetOut(&bytes.Buffer{})
376+
cmd.SetErr(&bytes.Buffer{})
377+
378+
var execErr error
379+
captureStdout(t, func() {
380+
execErr = cmd.Execute()
381+
})
382+
if execErr != nil {
383+
t.Fatalf("unexpected error: %v", execErr)
384+
}
385+
386+
if state.Config.DevServerURL != "http://localhost:9999" {
387+
t.Errorf("expected DevServerURL %q, got %q", "http://localhost:9999", state.Config.DevServerURL)
388+
}
389+
}
390+
391+
func TestConfigSetInvalidKey(t *testing.T) {
392+
state.Config = &config.Config{}
393+
state.Output = "json"
394+
395+
cmd := NewConfigCmd()
396+
cmd.SetArgs([]string{"set", "bogus_key", "value"})
397+
cmd.SetOut(&bytes.Buffer{})
398+
cmd.SetErr(&bytes.Buffer{})
399+
400+
err := cmd.Execute()
401+
if err == nil {
402+
t.Fatal("expected error for invalid config key")
403+
}
404+
if !strings.Contains(err.Error(), "unrecognized config key") {
405+
t.Errorf("expected error about unrecognized key, got: %v", err)
406+
}
407+
}
408+
409+
func TestConfigSetValidSigningKey(t *testing.T) {
410+
tmp := t.TempDir()
411+
cfgPath := filepath.Join(tmp, "cli.json")
412+
config.ResetForTest()
413+
t.Setenv("INNGEST_CLI_CONFIG", cfgPath)
414+
415+
state.Config = &config.Config{}
416+
state.Output = "json"
417+
418+
cmd := NewConfigCmd()
419+
cmd.SetArgs([]string{"set", "signing_key", "signkey-test-valid123"})
420+
cmd.SetOut(&bytes.Buffer{})
421+
cmd.SetErr(&bytes.Buffer{})
422+
423+
var execErr error
424+
captureStdout(t, func() {
425+
execErr = cmd.Execute()
426+
})
427+
if execErr != nil {
428+
t.Fatalf("unexpected error: %v", execErr)
429+
}
430+
431+
if state.Config.SigningKey != "signkey-test-valid123" {
432+
t.Errorf("expected SigningKey %q, got %q", "signkey-test-valid123", state.Config.SigningKey)
433+
}
434+
}
435+
436+
func TestGetConfigValue_AllKeys(t *testing.T) {
437+
cfg := &config.Config{
438+
SigningKey: "signkey-test-123",
439+
EventKey: "evt-key-123",
440+
ActiveEnv: "staging",
441+
APIBaseURL: "https://custom.api.com",
442+
DevServerURL: "http://localhost:9999",
443+
}
444+
445+
tests := []struct {
446+
key string
447+
expected string
448+
}{
449+
{"signing_key", "signkey-test-123"},
450+
{"event_key", "evt-key-123"},
451+
{"active_env", "staging"},
452+
{"api_base_url", "https://custom.api.com"},
453+
{"dev_server_url", "http://localhost:9999"},
454+
{"unknown_key", ""},
455+
}
456+
457+
for _, tt := range tests {
458+
t.Run(tt.key, func(t *testing.T) {
459+
got := getConfigValue(cfg, tt.key)
460+
if got != tt.expected {
461+
t.Errorf("getConfigValue(%q) = %q, want %q", tt.key, got, tt.expected)
462+
}
463+
})
464+
}
465+
}
466+
467+
func TestConfigSource_AllKeys(t *testing.T) {
468+
t.Setenv("INNGEST_SIGNING_KEY", "")
469+
t.Setenv("INNGEST_EVENT_KEY", "")
470+
471+
cfg := &config.Config{
472+
APIBaseURL: "https://custom.api.com",
473+
DevServerURL: "http://localhost:9999",
474+
}
475+
476+
if got := configSource(cfg, "api_base_url"); got != "config" {
477+
t.Errorf("expected source 'config' for api_base_url, got %q", got)
478+
}
479+
if got := configSource(cfg, "dev_server_url"); got != "config" {
480+
t.Errorf("expected source 'config' for dev_server_url, got %q", got)
481+
}
482+
483+
cfg2 := &config.Config{}
484+
if got := configSource(cfg2, "api_base_url"); got != "default" {
485+
t.Errorf("expected source 'default' for empty api_base_url, got %q", got)
486+
}
487+
if got := configSource(cfg2, "dev_server_url"); got != "default" {
488+
t.Errorf("expected source 'default' for empty dev_server_url, got %q", got)
489+
}
490+
491+
// event_key from env
492+
t.Setenv("INNGEST_EVENT_KEY", "evt-from-env")
493+
cfg3 := &config.Config{}
494+
if got := configSource(cfg3, "event_key"); got != "env (INNGEST_EVENT_KEY)" {
495+
t.Errorf("expected source 'env (INNGEST_EVENT_KEY)' for event_key from env, got %q", got)
496+
}
497+
}

0 commit comments

Comments
 (0)