main 4509ec7

xai_test.go RawHistoryFolder

1package auth
2
3import (
4	"context"
5	"encoding/json"
6	"net/http"
7	"net/http/httptest"
8	"net/url"
9	"testing"
10)
11
12func TestRequestXAIDeviceAuthorizationBuildsPrefilledURL(t *testing.T) {
13	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
14		if err := r.ParseForm(); err != nil {
15			t.Fatal(err)
16		}
17		if r.Form.Get("client_id") != xaiClientID || r.Form.Get("scope") != xaiScope {
18			t.Fatalf("unexpected form: %v", r.Form)
19		}
20		_ = json.NewEncoder(w).Encode(map[string]any{
21			"device_code": "device", "user_code": "AB CD",
22			"verification_uri": "https://accounts.example/activate",
23			"expires_in":       600,
24		})
25	}))
26	defer server.Close()
27
28	old := xaiDeviceCodeURL
29	xaiDeviceCodeURL = server.URL
30	t.Cleanup(func() { xaiDeviceCodeURL = old })
31
32	device, err := RequestXAIDeviceAuthorization(context.Background())
33	if err != nil {
34		t.Fatal(err)
35	}
36	u, err := url.Parse(device.VerificationURIComplete)
37	if err != nil {
38		t.Fatal(err)
39	}
40	if got := u.Query().Get("user_code"); got != "AB CD" {
41		t.Fatalf("user_code = %q", got)
42	}
43}
44
45func TestRefreshXAITokenPreservesRefreshToken(t *testing.T) {
46	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
47		if err := r.ParseForm(); err != nil {
48			t.Fatal(err)
49		}
50		if r.Form.Get("grant_type") != "refresh_token" || r.Form.Get("refresh_token") != "old-refresh" {
51			t.Fatalf("unexpected form: %v", r.Form)
52		}
53		_ = json.NewEncoder(w).Encode(map[string]any{
54			"access_token": "new-access", "expires_in": 3600,
55		})
56	}))
57	defer server.Close()
58
59	old := xaiTokenURL
60	xaiTokenURL = server.URL
61	t.Cleanup(func() { xaiTokenURL = old })
62
63	token, err := RefreshXAIToken(context.Background(), "old-refresh")
64	if err != nil {
65		t.Fatal(err)
66	}
67	if token.AccessToken != "new-access" || token.RefreshToken != "old-refresh" {
68		t.Fatalf("token = %+v", token)
69	}
70}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close