Unified · Split
| @@ -66,10 +66,11 @@ type App struct { · 65 unmodified lines | |||
| 66 | Stdout io.Writer | 66 | Stdout io.Writer |
| 67 | Stderr io.Writer | 67 | Stderr io.Writer |
| 68 | 68 | ||
| 69 | configPath string | 69 | configPath string |
| 70 | format OutputFormat | 70 | format OutputFormat |
| 71 | getWorkingDirectory func() (string, error) | 71 | getWorkingDirectory func() (string, error) |
| 72 | dbTargetNoticeOnce sync.Once | 72 | githubAuthTokenLookup func(context.Context) (string, error) |
| 73 | dbTargetNoticeOnce sync.Once | ||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | type initResult struct { | 76 | type initResult struct { |
| @@ -2140,7 +2140,12 @@ func TestCloudPublishStageOnlyThenResumesDefaultCutover(t *testing.T) { · 2139 unmodified lines | |||
| 2140 | stagedDatasetGeneratedAt = result.DatasetGeneratedAt | 2140 | stagedDatasetGeneratedAt = result.DatasetGeneratedAt |
| 2141 | if stagedDatasetGeneratedAt != concurrentDatasetGeneratedAt || | 2141 | if stagedDatasetGeneratedAt != concurrentDatasetGeneratedAt || |
| 2142 | result.MutationToken != "" { | 2142 | result.MutationToken != "" { |
| 2143 | t.Fatalf("stage-only did not bind its generation: %#v", result) | 2143 | t.Fatalf( |
| 2144 | "stage-only generation mismatch: generation_matches=%t mutation_token_present=%t mutation_token_length=%d", | ||
| 2145 | stagedDatasetGeneratedAt == concurrentDatasetGeneratedAt, | ||
| 2146 | result.MutationToken != "", | ||
| 2147 | len(result.MutationToken), | ||
| 2148 | ) | ||
| 2144 | } | 2149 | } |
| 2145 | time.Sleep(2 * time.Millisecond) | 2150 | time.Sleep(2 * time.Millisecond) |
| 2146 | } | 2151 | } |
| @@ -2161,7 +2166,7 @@ func TestCloudPublishStageOnlyThenResumesDefaultCutover(t *testing.T) { · 14 unmodified lines | |||
| 2161 | ) | 2166 | ) |
| 2162 | } | 2167 | } |
| 2163 | if result.MutationToken != "" { | 2168 | if result.MutationToken != "" { |
| 2164 | t.Fatalf("resumed publish minted mutation token %q", result.MutationToken) | 2169 | t.Fatalf("resumed publish minted mutation token: length=%d", len(result.MutationToken)) |
| 2165 | } | 2170 | } |
| 2166 | } | 2171 | } |
| 2167 | } | 2172 | } |
| @@ -2389,7 +2394,13 @@ func TestRemoteLoginStoresKeyringToken(t *testing.T) { · 221 unmodified lines | |||
| 2389 | t.Fatalf("remote login: %v", err) | 2394 | t.Fatalf("remote login: %v", err) |
| 2390 | } | 2395 | } |
| 2391 | if pollSecretHash == "" || pollSecret == "" || crawlremote.LoginPollSecretHash(pollSecret) != pollSecretHash { | 2396 | if pollSecretHash == "" || pollSecret == "" || crawlremote.LoginPollSecretHash(pollSecret) != pollSecretHash { |
| 2392 | t.Fatalf("poll secret/hash not linked: secret=%q hash=%q", pollSecret, pollSecretHash) | 2397 | t.Fatalf( |
| 2398 | "poll secret/hash not linked: secret_present=%t secret_length=%d hash_present=%t hash_length=%d", | ||
| 2399 | pollSecret != "", | ||
| 2400 | len(pollSecret), | ||
| 2401 | pollSecretHash != "", | ||
| 2402 | len(pollSecretHash), | ||
| 2403 | ) | ||
| 2393 | } | 2404 | } |
| 2394 | cfg, err := config.Load(configPath) | 2405 | cfg, err := config.Load(configPath) |
| 2395 | if err != nil { | 2406 | if err != nil { |
| @@ -2403,7 +2414,7 @@ func TestRemoteLoginStoresKeyringToken(t *testing.T) { · 7 unmodified lines | |||
| 2403 | t.Fatalf("keyring get: %v", err) | 2414 | t.Fatalf("keyring get: %v", err) |
| 2404 | } | 2415 | } |
| 2405 | if stored != "session-token" { | 2416 | if stored != "session-token" { |
| 2406 | t.Fatalf("stored token = %q", stored) | 2417 | t.Fatalf("stored token mismatch: present=%t length=%d", stored != "", len(stored)) |
| 2407 | } | 2418 | } |
| 2408 | 2419 | ||
| 2409 | whoami := New() | 2420 | whoami := New() |
| @@ -2461,7 +2472,7 @@ func TestRemoteLoginWithGitHubTokenEnvStoresKeyringToken(t *testing.T) { · 51 unmodified lines | |||
| 2461 | t.Fatalf("remote login: %v", err) | 2472 | t.Fatalf("remote login: %v", err) |
| 2462 | } | 2473 | } |
| 2463 | if sawToken != "github-token" { | 2474 | if sawToken != "github-token" { |
| 2464 | t.Fatalf("github token = %q", sawToken) | 2475 | t.Fatalf("github token mismatch: present=%t length=%d", sawToken != "", len(sawToken)) |
| 2465 | } | 2476 | } |
| 2466 | if !strings.Contains(out.String(), `"login_method": "github-token"`) { | 2477 | if !strings.Contains(out.String(), `"login_method": "github-token"`) { |
| 2467 | t.Fatalf("login output = %s", out.String()) | 2478 | t.Fatalf("login output = %s", out.String()) |
| @@ -2475,7 +2486,7 @@ func TestRemoteLoginWithGitHubTokenEnvStoresKeyringToken(t *testing.T) { · 7 unmodified lines | |||
| 2475 | t.Fatalf("keyring get: %v", err) | 2486 | t.Fatalf("keyring get: %v", err) |
| 2476 | } | 2487 | } |
| 2477 | if stored != "session-token" { | 2488 | if stored != "session-token" { |
| 2478 | t.Fatalf("stored token = %q", stored) | 2489 | t.Fatalf("stored token mismatch: present=%t length=%d", stored != "", len(stored)) |
| 2479 | } | 2490 | } |
| 2480 | 2491 | ||
| 2481 | whoami := New() | 2492 | whoami := New() |
| @@ -2995,7 +3006,7 @@ func TestSameGitRemoteIgnoresHTTPSCredentials(t *testing.T) { · 513 unmodified lines | |||
| 2995 | func TestGitRemoteForMessageRedactsURLCredentials(t *testing.T) { | 3006 | func TestGitRemoteForMessageRedactsURLCredentials(t *testing.T) { |
| 2996 | got := gitRemoteForMessage("https://user:secret@example.com/org/store.git") | 3007 | got := gitRemoteForMessage("https://user:secret@example.com/org/store.git") |
| 2997 | if strings.Contains(got, "user") || strings.Contains(got, "secret") { | 3008 | if strings.Contains(got, "user") || strings.Contains(got, "secret") { |
| 2998 | t.Fatalf("remote message leaked credentials: %q", got) | 3009 | t.Fatal("remote message leaked credentials") |
| 2999 | } | 3010 | } |
| 3000 | if got != "https://example.com/org/store.git" { | 3011 | if got != "https://example.com/org/store.git" { |
| 3001 | t.Fatalf("remote message = %q, want sanitized URL", got) | 3012 | t.Fatalf("remote message = %q, want sanitized URL", got) |
| @@ -5840,7 +5851,7 @@ func TestCommandFlowCoversSearchEmbedNeighborsClusterDetailRunsAndRefresh(t *tes · 2838 unmodified lines | |||
| 5840 | t.Fatalf("unexpected OpenAI path: %s", r.URL.Path) | 5851 | t.Fatalf("unexpected OpenAI path: %s", r.URL.Path) |
| 5841 | } | 5852 | } |
| 5842 | if got := r.Header.Get("Authorization"); got != "Bearer test-openai-key" { | 5853 | if got := r.Header.Get("Authorization"); got != "Bearer test-openai-key" { |
| 5843 | t.Fatalf("authorization = %q", got) | 5854 | t.Fatalf("authorization mismatch: present=%t length=%d", got != "", len(got)) |
| 5844 | } | 5855 | } |
| 5845 | var payload struct { | 5856 | var payload struct { |
| 5846 | Input []string `json:"input"` | 5857 | Input []string `json:"input"` |
| @@ -6289,7 +6300,7 @@ func TestSyncCommandUsesConfiguredGitHubBaseURLAndHydratesComments(t *testing.T) · 442 unmodified lines | |||
| 6289 | 6300 | ||
| 6290 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 6301 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 6291 | if got := r.Header.Get("Authorization"); got != "Bearer test-gh-token" { | 6302 | if got := r.Header.Get("Authorization"); got != "Bearer test-gh-token" { |
| 6292 | t.Fatalf("authorization = %q", got) | 6303 | t.Fatalf("authorization mismatch: present=%t length=%d", got != "", len(got)) |
| 6293 | } | 6304 | } |
| 6294 | switch r.URL.Path { | 6305 | switch r.URL.Path { |
| 6295 | case "/repos/openclaw/openclaw": | 6306 | case "/repos/openclaw/openclaw": |
| @@ -6459,7 +6470,7 @@ func TestFillPRDetailsHydratesMissingPullRequestDetails(t *testing.T) { · 163 unmodified lines | |||
| 6459 | 6470 | ||
| 6460 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 6471 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 6461 | if got := r.Header.Get("Authorization"); got != "Bearer test-gh-token" { | 6472 | if got := r.Header.Get("Authorization"); got != "Bearer test-gh-token" { |
| 6462 | t.Fatalf("authorization = %q", got) | 6473 | t.Fatalf("authorization mismatch: present=%t length=%d", got != "", len(got)) |
| 6463 | } | 6474 | } |
| 6464 | w.Header().Set("X-RateLimit-Limit", "5000") | 6475 | w.Header().Set("X-RateLimit-Limit", "5000") |
| 6465 | w.Header().Set("X-RateLimit-Remaining", "4990") | 6476 | w.Header().Set("X-RateLimit-Remaining", "4990") |
| @@ -6710,7 +6721,7 @@ func TestFillPRDetailsReserveRateLimitStopsBeforeCrossingDuringBatch(t *testing. · 244 unmodified lines | |||
| 6710 | var coreCalls atomic.Int32 | 6721 | var coreCalls atomic.Int32 |
| 6711 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 6722 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 6712 | if got := r.Header.Get("Authorization"); got != "Bearer test-gh-token" { | 6723 | if got := r.Header.Get("Authorization"); got != "Bearer test-gh-token" { |
| 6713 | t.Fatalf("authorization = %q", got) | 6724 | t.Fatalf("authorization mismatch: present=%t length=%d", got != "", len(got)) |
| 6714 | } | 6725 | } |
| 6715 | if r.URL.Path == "/rate_limit" { | 6726 | if r.URL.Path == "/rate_limit" { |
| 6716 | remaining := 12 - int(rateStatusCalls.Add(1)) | 6727 | remaining := 12 - int(rateStatusCalls.Add(1)) |
| @@ -162,7 +162,7 @@ func TestSendSnapshotIngestDatasetStreamsBoundedBatches(t *testing.T) { · 161 unmodified lines | |||
| 162 | t.Fatalf("stream dataset: %v", err) | 162 | t.Fatalf("stream dataset: %v", err) |
| 163 | } | 163 | } |
| 164 | if progress.RowsAccepted != 501 || progress.MutationToken != "mutation-3" { | 164 | if progress.RowsAccepted != 501 || progress.MutationToken != "mutation-3" { |
| 165 | t.Fatalf("progress = %#v", progress) | 165 | t.Fatalf("progress mismatch: rows_accepted=%d mutation_token_present=%t mutation_token_length=%d", progress.RowsAccepted, progress.MutationToken != "", len(progress.MutationToken)) |
| 166 | } | 166 | } |
| 167 | if len(requests) != 3 { | 167 | if len(requests) != 3 { |
| 168 | t.Fatalf("requests = %d, want 3", len(requests)) | 168 | t.Fatalf("requests = %d, want 3", len(requests)) |
| @@ -253,7 +253,7 @@ func TestSendSnapshotIngestDatasetFlushesBeforeEncodedByteLimit(t *testing.T) { · 84 unmodified lines | |||
| 253 | t.Fatalf("stream byte-bounded dataset: %v", err) | 253 | t.Fatalf("stream byte-bounded dataset: %v", err) |
| 254 | } | 254 | } |
| 255 | if progress.RowsAccepted != 3 || progress.MutationToken != "mutation-3" { | 255 | if progress.RowsAccepted != 3 || progress.MutationToken != "mutation-3" { |
| 256 | t.Fatalf("progress = %#v", progress) | 256 | t.Fatalf("progress mismatch: rows_accepted=%d mutation_token_present=%t mutation_token_length=%d", progress.RowsAccepted, progress.MutationToken != "", len(progress.MutationToken)) |
| 257 | } | 257 | } |
| 258 | if len(requests) != 3 { | 258 | if len(requests) != 3 { |
| 259 | t.Fatalf("requests = %d, want one per large row", len(requests)) | 259 | t.Fatalf("requests = %d, want one per large row", len(requests)) |
| @@ -331,7 +331,7 @@ func TestSendSnapshotIngestRowsFlushesBeforeEncodedByteLimit(t *testing.T) { · 71 unmodified lines | |||
| 331 | t.Fatalf("send byte-bounded rows: %v", err) | 331 | t.Fatalf("send byte-bounded rows: %v", err) |
| 332 | } | 332 | } |
| 333 | if progress.RowsAccepted != 3 || progress.MutationToken != "mutation-3" { | 333 | if progress.RowsAccepted != 3 || progress.MutationToken != "mutation-3" { |
| 334 | t.Fatalf("progress = %#v", progress) | 334 | t.Fatalf("progress mismatch: rows_accepted=%d mutation_token_present=%t mutation_token_length=%d", progress.RowsAccepted, progress.MutationToken != "", len(progress.MutationToken)) |
| 335 | } | 335 | } |
| 336 | if len(requests) != 3 { | 336 | if len(requests) != 3 { |
| 337 | t.Fatalf("requests = %d, want one per large row", len(requests)) | 337 | t.Fatalf("requests = %d, want one per large row", len(requests)) |
| @@ -16,7 +16,11 @@ func (a *App) resolveGitHubToken(ctx context.Context, cfg config.Config) config. · 15 unmodified lines | |||
| 16 | if token.Value != "" { | 16 | if token.Value != "" { |
| 17 | return token | 17 | return token |
| 18 | } | 18 | } |
| 19 | if value, err := a.githubAuthToken(ctx); err == nil && value != "" { | 19 | lookup := a.githubAuthToken |
| 20 | if a.githubAuthTokenLookup != nil { | ||
| 21 | lookup = a.githubAuthTokenLookup | ||
| 22 | } | ||
| 23 | if value, err := lookup(ctx); err == nil && value != "" { | ||
| 20 | return config.TokenResolution{Value: value, Source: "gh auth token"} | 24 | return config.TokenResolution{Value: value, Source: "gh auth token"} |
| 21 | } | 25 | } |
| 22 | return token | 26 | return token |
| @@ -13,35 +13,31 @@ import ( · 12 unmodified lines | |||
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | func TestResolveGitHubTokenFallsBackToGHAuthToken(t *testing.T) { | 15 | func TestResolveGitHubTokenFallsBackToGHAuthToken(t *testing.T) { |
| 16 | dir := t.TempDir() | ||
| 17 | ghPath := filepath.Join(dir, "gh") | ||
| 18 | if err := os.WriteFile(ghPath, []byte("#!/bin/sh\nif [ \"$1\" = auth ] && [ \"$2\" = token ]; then echo gh-fallback-token; exit 0; fi\nexit 1\n"), 0o755); err != nil { | ||
| 19 | t.Fatalf("write fake gh: %v", err) | ||
| 20 | } | ||
| 21 | t.Setenv("GITHUB_TOKEN", "") | 16 | t.Setenv("GITHUB_TOKEN", "") |
| 22 | t.Setenv("GITCRAWL_GH_PATH", ghPath) | ||
| 23 | 17 | ||
| 24 | token := New().resolveGitHubToken(context.Background(), config.Default()) | 18 | app := New() |
| 19 | app.githubAuthTokenLookup = func(context.Context) (string, error) { | ||
| 20 | return "gh-fallback-token", nil | ||
| 21 | } | ||
| 22 | token := app.resolveGitHubToken(context.Background(), config.Default()) | ||
| 25 | if token.Value != "gh-fallback-token" || token.Source != "gh auth token" { | 23 | if token.Value != "gh-fallback-token" || token.Source != "gh auth token" { |
| 26 | t.Fatalf("token = %#v", token) | 24 | t.Fatalf("token mismatch: source=%q value_present=%t value_length=%d", token.Source, token.Value != "", len(token.Value)) |
| 27 | } | 25 | } |
| 28 | } | 26 | } |
| 29 | 27 | ||
| 30 | func TestDoctorReportsGHAuthTokenFallback(t *testing.T) { | 28 | func TestDoctorReportsGHAuthTokenFallback(t *testing.T) { |
| 31 | dir := t.TempDir() | 29 | dir := t.TempDir() |
| 32 | ghPath := filepath.Join(dir, "gh") | ||
| 33 | if err := os.WriteFile(ghPath, []byte("#!/bin/sh\nif [ \"$1\" = auth ] && [ \"$2\" = token ]; then echo gh-fallback-token; exit 0; fi\nexit 1\n"), 0o755); err != nil { | ||
| 34 | t.Fatalf("write fake gh: %v", err) | ||
| 35 | } | ||
| 36 | configPath := filepath.Join(dir, "config.toml") | 30 | configPath := filepath.Join(dir, "config.toml") |
| 37 | dbPath := filepath.Join(dir, "gitcrawl.db") | 31 | dbPath := filepath.Join(dir, "gitcrawl.db") |
| 38 | if err := os.WriteFile(configPath, []byte("version = 1\ndb_path = "+strconv.Quote(dbPath)+"\n[github]\ntoken_env = 'GITHUB_TOKEN'\n"), 0o600); err != nil { | 32 | if err := os.WriteFile(configPath, []byte("version = 1\ndb_path = "+strconv.Quote(dbPath)+"\n[github]\ntoken_env = 'GITHUB_TOKEN'\n"), 0o600); err != nil { |
| 39 | t.Fatalf("write config: %v", err) | 33 | t.Fatalf("write config: %v", err) |
| 40 | } | 34 | } |
| 41 | t.Setenv("GITHUB_TOKEN", "") | 35 | t.Setenv("GITHUB_TOKEN", "") |
| 42 | t.Setenv("GITCRAWL_GH_PATH", ghPath) | ||
| 43 | 36 | ||
| 44 | doctor := New() | 37 | doctor := New() |
| 38 | doctor.githubAuthTokenLookup = func(context.Context) (string, error) { | ||
| 39 | return "gh-fallback-token", nil | ||
| 40 | } | ||
| 45 | var stdout bytes.Buffer | 41 | var stdout bytes.Buffer |
| 46 | doctor.Stdout = &stdout | 42 | doctor.Stdout = &stdout |
| 47 | if err := doctor.Run(context.Background(), []string{"--config", configPath, "doctor", "--json"}); err != nil { | 43 | if err := doctor.Run(context.Background(), []string{"--config", configPath, "doctor", "--json"}); err != nil { |
| @@ -49,12 +45,12 @@ func TestDoctorReportsGHAuthTokenFallback(t *testing.T) { · 1 unmodified line | |||
| 49 | } | 45 | } |
| 50 | var payload map[string]any | 46 | var payload map[string]any |
| 51 | if err := json.Unmarshal(stdout.Bytes(), &payload); err != nil { | 47 | if err := json.Unmarshal(stdout.Bytes(), &payload); err != nil { |
| 52 | t.Fatalf("parse doctor json: %v\n%s", err, stdout.String()) | 48 | t.Fatalf("parse doctor json: %v (output_bytes=%d)", err, stdout.Len()) |
| 53 | } | 49 | } |
| 54 | if got := payload["github_token_present"]; got != true { | 50 | if got := payload["github_token_present"]; got != true { |
| 55 | t.Fatalf("github_token_present = %#v, payload=%s", got, stdout.String()) | 51 | t.Fatalf("github_token_present = %#v", got) |
| 56 | } | 52 | } |
| 57 | if got := payload["github_token_source"]; got != "gh auth token" { | 53 | if got := payload["github_token_source"]; got != "gh auth token" { |
| 58 | t.Fatalf("github_token_source = %#v, payload=%s", got, stdout.String()) | 54 | t.Fatalf("github_token_source = %#v", got) |
| 59 | } | 55 | } |
| 60 | } | 56 | } |
| @@ -81,7 +81,13 @@ func TestPollRemoteLoginStates(t *testing.T) { · 80 unmodified lines | |||
| 81 | t.Fatalf("poll login: %v", err) | 81 | t.Fatalf("poll login: %v", err) |
| 82 | } | 82 | } |
| 83 | if result.Token != "session-token" || polls != 2 { | 83 | if result.Token != "session-token" || polls != 2 { |
| 84 | t.Fatalf("result=%#v polls=%d", result, polls) | 84 | t.Fatalf( |
| 85 | "poll result mismatch: status=%q token_present=%t token_length=%d polls=%d", | ||
| 86 | result.Status, | ||
| 87 | result.Token != "", | ||
| 88 | len(result.Token), | ||
| 89 | polls, | ||
| 90 | ) | ||
| 85 | } | 91 | } |
| 86 | }) | 92 | }) |
| 87 | 93 | ||
| @@ -154,10 +160,10 @@ func TestSendIngestRowsBatchesAndFinalizes(t *testing.T) { · 66 unmodified lines | |||
| 154 | t.Fatalf("requests len = %d", len(requests)) | 160 | t.Fatalf("requests len = %d", len(requests)) |
| 155 | } | 161 | } |
| 156 | if requests[0].Cursor != "" || requests[0].Final || len(requests[0].Rows) != gitcrawlCloudBatchSize { | 162 | if requests[0].Cursor != "" || requests[0].Final || len(requests[0].Rows) != gitcrawlCloudBatchSize { |
| 157 | t.Fatalf("first request = %#v", requests[0]) | 163 | t.Fatalf("first request mismatch: cursor=%q final=%t rows=%d", requests[0].Cursor, requests[0].Final, len(requests[0].Rows)) |
| 158 | } | 164 | } |
| 159 | if requests[1].Cursor != "250" || !requests[1].Final || len(requests[1].Rows) != 1 { | 165 | if requests[1].Cursor != "250" || !requests[1].Final || len(requests[1].Rows) != 1 { |
| 160 | t.Fatalf("second request = %#v", requests[1]) | 166 | t.Fatalf("second request mismatch: cursor=%q final=%t rows=%d", requests[1].Cursor, requests[1].Final, len(requests[1].Rows)) |
| 161 | } | 167 | } |
| 162 | } | 168 | } |
| 163 | 169 | ||
| @@ -207,16 +213,16 @@ func TestSendSnapshotIngestRowsRotatesMutationTokens(t *testing.T) { · 43 unmodified lines | |||
| 207 | t.Fatalf("send snapshot ingest: %v", err) | 213 | t.Fatalf("send snapshot ingest: %v", err) |
| 208 | } | 214 | } |
| 209 | if progress.RowsAccepted != int64(len(rows)) || progress.MutationToken != "generation-2" { | 215 | if progress.RowsAccepted != int64(len(rows)) || progress.MutationToken != "generation-2" { |
| 210 | t.Fatalf("progress = %#v", progress) | 216 | t.Fatalf("progress mismatch: rows_accepted=%d mutation_token_present=%t mutation_token_length=%d", progress.RowsAccepted, progress.MutationToken != "", len(progress.MutationToken)) |
| 211 | } | 217 | } |
| 212 | if len(requests) != 2 { | 218 | if len(requests) != 2 { |
| 213 | t.Fatalf("requests = %#v", requests) | 219 | t.Fatalf("requests length = %d, want 2", len(requests)) |
| 214 | } | 220 | } |
| 215 | if requests[0].Cursor != "" || requests[0].MutationToken != "previous-dataset" { | 221 | if requests[0].Cursor != "" || requests[0].MutationToken != "previous-dataset" { |
| 216 | t.Fatalf("first request = %#v", requests[0]) | 222 | t.Fatalf("first request mismatch: cursor=%q mutation_token_present=%t mutation_token_length=%d", requests[0].Cursor, requests[0].MutationToken != "", len(requests[0].MutationToken)) |
| 217 | } | 223 | } |
| 218 | if requests[1].Cursor != "250" || requests[1].MutationToken != "generation-1" || !requests[1].Final { | 224 | if requests[1].Cursor != "250" || requests[1].MutationToken != "generation-1" || !requests[1].Final { |
| 219 | t.Fatalf("second request = %#v", requests[1]) | 225 | t.Fatalf("second request mismatch: cursor=%q final=%t mutation_token_present=%t mutation_token_length=%d", requests[1].Cursor, requests[1].Final, requests[1].MutationToken != "", len(requests[1].MutationToken)) |
| 220 | } | 226 | } |
| 221 | } | 227 | } |
| 222 | 228 | ||
| @@ -287,17 +293,20 @@ func TestSendIngestRowsDrainsRemoteResetBeforeRetry(t *testing.T) { · 64 unmodified lines | |||
| 287 | t.Fatalf("send ingest: %v", err) | 293 | t.Fatalf("send ingest: %v", err) |
| 288 | } | 294 | } |
| 289 | if progress.RowsAccepted != 1 || progress.MutationToken != "generation-current" { | 295 | if progress.RowsAccepted != 1 || progress.MutationToken != "generation-current" { |
| 290 | t.Fatalf("progress = %#v", progress) | 296 | t.Fatalf("progress mismatch: rows_accepted=%d mutation_token_present=%t mutation_token_length=%d", progress.RowsAccepted, progress.MutationToken != "", len(progress.MutationToken)) |
| 291 | } | 297 | } |
| 292 | if resetCalls != 2 { | 298 | if resetCalls != 2 { |
| 293 | t.Fatalf("resetCalls = %d", resetCalls) | 299 | t.Fatalf("resetCalls = %d", resetCalls) |
| 294 | } | 300 | } |
| 295 | if len(requests) != 1 || requests[0].Cursor != "" || !requests[0].Final { | 301 | if len(requests) != 1 { |
| 296 | t.Fatalf("data requests = %#v", requests) | 302 | t.Fatalf("data requests length = %d, want 1", len(requests)) |
| 303 | } | ||
| 304 | if requests[0].Cursor != "" || !requests[0].Final { | ||
| 305 | t.Fatalf("data request mismatch: cursor=%q final=%t", requests[0].Cursor, requests[0].Final) | ||
| 297 | } | 306 | } |
| 298 | for index, request := range drainRequests { | 307 | for index, request := range drainRequests { |
| 299 | if request.MutationToken != "generation-current" { | 308 | if request.MutationToken != "generation-current" { |
| 300 | t.Fatalf("drain request %d mutation token = %q", index, request.MutationToken) | 309 | t.Fatalf("drain request %d mutation token mismatch: present=%t length=%d", index, request.MutationToken != "", len(request.MutationToken)) |
| 301 | } | 310 | } |
| 302 | } | 311 | } |
| 303 | } | 312 | } |
| @@ -319,10 +319,10 @@ func TestResolveTokens(t *testing.T) { · 318 unmodified lines | |||
| 319 | 319 | ||
| 320 | cfg := Default() | 320 | cfg := Default() |
| 321 | if got := ResolveGitHubToken(cfg); got.Value != "ghp_test" || got.Source != "GITHUB_TOKEN" { | 321 | if got := ResolveGitHubToken(cfg); got.Value != "ghp_test" || got.Source != "GITHUB_TOKEN" { |
| 322 | t.Fatalf("github token resolution mismatch: %#v", got) | 322 | t.Fatalf("github token resolution mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 323 | } | 323 | } |
| 324 | if got := ResolveOpenAIKey(cfg); got.Value != "sk_test" || got.Source != "OPENAI_API_KEY" { | 324 | if got := ResolveOpenAIKey(cfg); got.Value != "sk_test" || got.Source != "OPENAI_API_KEY" { |
| 325 | t.Fatalf("openai key resolution mismatch: %#v", got) | 325 | t.Fatalf("openai key resolution mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | t.Setenv("GITHUB_TOKEN", "") | 328 | t.Setenv("GITHUB_TOKEN", "") |
| @@ -332,19 +332,19 @@ func TestResolveTokens(t *testing.T) { · 3 unmodified lines | |||
| 332 | t.Setenv("CUSTOM_GITHUB_TOKEN", "custom-gh") | 332 | t.Setenv("CUSTOM_GITHUB_TOKEN", "custom-gh") |
| 333 | t.Setenv("CUSTOM_OPENAI_KEY", "custom-openai") | 333 | t.Setenv("CUSTOM_OPENAI_KEY", "custom-openai") |
| 334 | if got := ResolveGitHubToken(cfg); got.Value != "custom-gh" || got.Source != "CUSTOM_GITHUB_TOKEN" { | 334 | if got := ResolveGitHubToken(cfg); got.Value != "custom-gh" || got.Source != "CUSTOM_GITHUB_TOKEN" { |
| 335 | t.Fatalf("custom github token mismatch: %#v", got) | 335 | t.Fatalf("custom github token mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 336 | } | 336 | } |
| 337 | if got := ResolveOpenAIKey(cfg); got.Value != "custom-openai" || got.Source != "CUSTOM_OPENAI_KEY" { | 337 | if got := ResolveOpenAIKey(cfg); got.Value != "custom-openai" || got.Source != "CUSTOM_OPENAI_KEY" { |
| 338 | t.Fatalf("custom openai key mismatch: %#v", got) | 338 | t.Fatalf("custom openai key mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 339 | } | 339 | } |
| 340 | 340 | ||
| 341 | t.Setenv("CUSTOM_GITHUB_TOKEN", "") | 341 | t.Setenv("CUSTOM_GITHUB_TOKEN", "") |
| 342 | t.Setenv("CUSTOM_OPENAI_KEY", "") | 342 | t.Setenv("CUSTOM_OPENAI_KEY", "") |
| 343 | if got := ResolveGitHubToken(cfg); got.Value != "" || got.Source != "" { | 343 | if got := ResolveGitHubToken(cfg); got.Value != "" || got.Source != "" { |
| 344 | t.Fatalf("empty github token mismatch: %#v", got) | 344 | t.Fatalf("empty github token mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 345 | } | 345 | } |
| 346 | if got := ResolveOpenAIKey(cfg); got.Value != "" || got.Source != "" { | 346 | if got := ResolveOpenAIKey(cfg); got.Value != "" || got.Source != "" { |
| 347 | t.Fatalf("empty openai key mismatch: %#v", got) | 347 | t.Fatalf("empty openai key mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 348 | } | 348 | } |
| 349 | } | 349 | } |
| 350 | 350 | ||
| @@ -358,15 +358,15 @@ func TestResolveTokensFromConfigEnv(t *testing.T) { · 7 unmodified lines | |||
| 358 | "OPENAI_API_KEY": "config-openai", | 358 | "OPENAI_API_KEY": "config-openai", |
| 359 | } | 359 | } |
| 360 | if got := ResolveGitHubToken(cfg); got.Value != "config-gh" || got.Source != "config.toml [env].GITHUB_TOKEN" { | 360 | if got := ResolveGitHubToken(cfg); got.Value != "config-gh" || got.Source != "config.toml [env].GITHUB_TOKEN" { |
| 361 | t.Fatalf("github token config env mismatch: %#v", got) | 361 | t.Fatalf("github token config env mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 362 | } | 362 | } |
| 363 | if got := ResolveOpenAIKey(cfg); got.Value != "config-openai" || got.Source != "config.toml [env].OPENAI_API_KEY" { | 363 | if got := ResolveOpenAIKey(cfg); got.Value != "config-openai" || got.Source != "config.toml [env].OPENAI_API_KEY" { |
| 364 | t.Fatalf("openai key config env mismatch: %#v", got) | 364 | t.Fatalf("openai key config env mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 365 | } | 365 | } |
| 366 | 366 | ||
| 367 | t.Setenv("GITHUB_TOKEN", "process-gh") | 367 | t.Setenv("GITHUB_TOKEN", "process-gh") |
| 368 | if got := ResolveGitHubToken(cfg); got.Value != "process-gh" || got.Source != "GITHUB_TOKEN" { | 368 | if got := ResolveGitHubToken(cfg); got.Value != "process-gh" || got.Source != "GITHUB_TOKEN" { |
| 369 | t.Fatalf("process env should win: %#v", got) | 369 | t.Fatalf("process env should win: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 370 | } | 370 | } |
| 371 | } | 371 | } |
| 372 | 372 | ||
| @@ -384,15 +384,15 @@ func TestResolveTokensFromCustomConfigEnv(t *testing.T) { · 11 unmodified lines | |||
| 384 | "OPENAI_API_KEY": "ignored-default-openai", | 384 | "OPENAI_API_KEY": "ignored-default-openai", |
| 385 | } | 385 | } |
| 386 | if got := ResolveGitHubToken(cfg); got.Value != "config-custom-gh" || got.Source != "config.toml [env].CUSTOM_GITHUB_TOKEN" { | 386 | if got := ResolveGitHubToken(cfg); got.Value != "config-custom-gh" || got.Source != "config.toml [env].CUSTOM_GITHUB_TOKEN" { |
| 387 | t.Fatalf("custom github token config env mismatch: %#v", got) | 387 | t.Fatalf("custom github token config env mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 388 | } | 388 | } |
| 389 | if got := ResolveOpenAIKey(cfg); got.Value != "config-custom-openai" || got.Source != "config.toml [env].CUSTOM_OPENAI_KEY" { | 389 | if got := ResolveOpenAIKey(cfg); got.Value != "config-custom-openai" || got.Source != "config.toml [env].CUSTOM_OPENAI_KEY" { |
| 390 | t.Fatalf("custom openai key config env mismatch: %#v", got) | 390 | t.Fatalf("custom openai key config env mismatch: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | cfg.Env["CUSTOM_GITHUB_TOKEN"] = " " | 393 | cfg.Env["CUSTOM_GITHUB_TOKEN"] = " " |
| 394 | if got := ResolveGitHubToken(cfg); got.Value != "" || got.Source != "" { | 394 | if got := ResolveGitHubToken(cfg); got.Value != "" || got.Source != "" { |
| 395 | t.Fatalf("empty config env should be ignored: %#v", got) | 395 | t.Fatalf("empty config env should be ignored: source=%q value_present=%t value_length=%d", got.Source, got.Value != "", len(got.Value)) |
| 396 | } | 396 | } |
| 397 | } | 397 | } |
| 398 | 398 | ||
| @@ -40,7 +40,7 @@ func TestRemoteTokenResolutionWithKeyring(t *testing.T) { · 39 unmodified lines | |||
| 40 | t.Fatalf("resolve env token: %v", err) | 40 | t.Fatalf("resolve env token: %v", err) |
| 41 | } | 41 | } |
| 42 | if resolved.Value != "env-session" || resolved.Source != "GITCRAWL_TEST_REMOTE_TOKEN" { | 42 | if resolved.Value != "env-session" || resolved.Source != "GITCRAWL_TEST_REMOTE_TOKEN" { |
| 43 | t.Fatalf("env token = %#v", resolved) | 43 | t.Fatalf("env token mismatch: source=%q value_present=%t value_length=%d", resolved.Source, resolved.Value != "", len(resolved.Value)) |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | t.Setenv("GITCRAWL_TEST_REMOTE_TOKEN", "") | 46 | t.Setenv("GITCRAWL_TEST_REMOTE_TOKEN", "") |
| @@ -57,7 +57,7 @@ func TestRemoteTokenResolutionWithKeyring(t *testing.T) { · 10 unmodified lines | |||
| 57 | t.Fatalf("resolve keyring token: %v", err) | 57 | t.Fatalf("resolve keyring token: %v", err) |
| 58 | } | 58 | } |
| 59 | if resolved.Value != "keyring-session" || resolved.Source != "keyring" { | 59 | if resolved.Value != "keyring-session" || resolved.Source != "keyring" { |
| 60 | t.Fatalf("keyring token = %#v", resolved) | 60 | t.Fatalf("keyring token mismatch: source=%q value_present=%t value_length=%d", resolved.Source, resolved.Value != "", len(resolved.Value)) |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | cfg.Remote.Auth.TokenSource = "none" | 63 | cfg.Remote.Auth.TokenSource = "none" |
| @@ -27,8 +27,8 @@ func writeRateLimits(t *testing.T, w http.ResponseWriter, resetAt time.Time, cor · 26 unmodified lines | |||
| 27 | 27 | ||
| 28 | func TestListRepositoryIssuesPaginatesAndLimits(t *testing.T) { | 28 | func TestListRepositoryIssuesPaginatesAndLimits(t *testing.T) { |
| 29 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 29 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 30 | if r.Header.Get("Authorization") != "Bearer token" { | 30 | if got := r.Header.Get("Authorization"); got != "Bearer token" { |
| 31 | t.Fatalf("missing auth header: %q", r.Header.Get("Authorization")) | 31 | t.Fatalf("auth header mismatch: present=%t length=%d", got != "", len(got)) |
| 32 | } | 32 | } |
| 33 | switch r.URL.Query().Get("page") { | 33 | switch r.URL.Query().Get("page") { |
| 34 | case "": | 34 | case "": |
| @@ -18,7 +18,7 @@ func TestSummarizeUsesResponsesOutputText(t *testing.T) { · 17 unmodified lines | |||
| 18 | t.Fatalf("path = %q", r.URL.Path) | 18 | t.Fatalf("path = %q", r.URL.Path) |
| 19 | } | 19 | } |
| 20 | if got := r.Header.Get("Authorization"); got != "Bearer test-key" { | 20 | if got := r.Header.Get("Authorization"); got != "Bearer test-key" { |
| 21 | t.Fatalf("authorization = %q", got) | 21 | t.Fatalf("authorization mismatch: present=%t length=%d", got != "", len(got)) |
| 22 | } | 22 | } |
| 23 | var request summaryRequest | 23 | var request summaryRequest |
| 24 | if err := json.NewDecoder(r.Body).Decode(&request); err != nil { | 24 | if err := json.NewDecoder(r.Body).Decode(&request); err != nil { |
| @@ -402,6 +402,6 @@ func assertPortableFileDoesNotContain(t *testing.T, path, value string) { · 401 unmodified lines | |||
| 402 | t.Fatalf("read portable database bytes: %v", err) | 402 | t.Fatalf("read portable database bytes: %v", err) |
| 403 | } | 403 | } |
| 404 | if bytes.Contains(data, []byte(value)) { | 404 | if bytes.Contains(data, []byte(value)) { |
| 405 | t.Fatalf("portable database retains scrubbed value %q", value) | 405 | t.Fatal("portable database retains a scrubbed credential value") |
| 406 | } | 406 | } |
| 407 | } | 407 | } |