TestHamrpassSetsKeyAndActivates: a valid key is trimmed, saved on the hamrpass profile, persisted, and active flips to hamrpass. The llm client is rebuilt so future requests carry the new token.
(t *testing.T)
| 2954 | func TestHamrpassNoArgsShowsExplainerWhenUnset(t *testing.T) { |
| 2955 | m := newTestModel(t, func(http.ResponseWriter, *http.Request) {}) |
| 2956 | before := m.cfg.Active |
| 2957 | // Bootstrap seeds hamrpass with an empty key; assert the precondition |
| 2958 | // so the test fails loud if Default() ever changes. |
| 2959 | if hp, ok := m.cfg.Models["hamrpass"]; !ok || hp.Key != "" { |
| 2960 | t.Fatalf("precondition: hamrpass profile with empty key, got %+v", hp) |
| 2961 | } |
| 2962 | m2, _ := m.runSlash("/hamrpass") |
| 2963 | final := m2.(Model) |
| 2964 | out := stripANSI(final.scroll.String()) |
| 2965 | for _, want := range []string{ |
| 2966 | "hamrpass", |
| 2967 | "status : unset", |
| 2968 | "endpoint : https://codehamr.com", |
| 2969 | "llm : hamrpass", |
| 2970 | "https://codehamr.com", |
| 2971 | "/hamrpass <your key>", |
| 2972 | } { |
| 2973 | if !strings.Contains(out, want) { |
| 2974 | t.Fatalf("explainer missing %q in:\n%s", want, out) |
| 2975 | } |
| 2976 | } |
| 2977 | if final.cfg.Active != before { |
| 2978 | t.Fatalf("/hamrpass without args must not change active profile, got %q", final.cfg.Active) |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | // TestHamrpassNoArgsShowsSetWhenKeyPresent: status line flips to `set` |
| 2983 | // when the hamrpass profile already has a key. |
| 2984 | func TestHamrpassNoArgsShowsSetWhenKeyPresent(t *testing.T) { |
| 2985 | m := newTestModel(t, func(http.ResponseWriter, *http.Request) {}) |
| 2986 | m.cfg.Models["hamrpass"].Key = "hp-already-1234567890abcdef" |
| 2987 | if err := m.cfg.Save(); err != nil { |
| 2988 | t.Fatal(err) |
| 2989 | } |
nothing calls this directly
no test coverage detected