Brings the chat surface to the Web UI: /api/chat with its own handlers and tests, a self-contained ui/src/chat feature folder, and the shared plumbing to reach the same router Telegram uses. Includes a dangerous-command approval path (internal/gateway/dangerous.go, internal/webui/dangerous.go, and the Telegram counterpart) so /rollback and /stop are gated the same way on both surfaces, persona handling for web sessions, and release-update formatting split out of the Telegram service so both can render it. web_parity_test.go pins that the two surfaces expose the same commands. Authored in a parallel session; committed here so it lands with the rest rather than sitting uncommitted while other work builds on top of it. task check passes with it in place. Screenshots used while building are gitignored (*.png) rather than committed, matching the call made on the earlier design reference.
99 lines
3.1 KiB
Go
99 lines
3.1 KiB
Go
package releaseupdate
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestServiceDefersOnlyTheVersionsShownToThatRecipient(t *testing.T) {
|
|
catalog := &catalogStub{snapshot: Snapshot{Components: []Component{
|
|
{ID: "gateway", Label: "THE GATEWAY", Installed: "v0.1.0", Available: "v0.1.1", Changelog: "- Clearer help"},
|
|
{ID: "runtime", Label: "THE RUNTIME", Installed: "v0.1.0"},
|
|
}}}
|
|
service := Service{Catalog: catalog, StatePath: filepath.Join(t.TempDir(), "deferrals.json")}
|
|
|
|
first, err := service.Check(context.Background(), 42)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(first.Available()); got != 1 {
|
|
t.Fatalf("available before defer = %d, want 1", got)
|
|
}
|
|
if err := service.Defer(context.Background(), 42, first); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
deferred, err := service.Check(context.Background(), 42)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(deferred.Available()); got != 0 {
|
|
t.Fatalf("available after defer = %d, want 0", got)
|
|
}
|
|
if !deferred.Deferred {
|
|
t.Error("Deferred = false, want true")
|
|
}
|
|
|
|
catalog.snapshot.Components[0].Available = "v0.1.2"
|
|
newer, err := service.Check(context.Background(), 42)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(newer.Available()); got != 1 {
|
|
t.Fatalf("available for newer version = %d, want 1", got)
|
|
}
|
|
}
|
|
|
|
func TestServiceInstallForwardsProgressAndFailure(t *testing.T) {
|
|
installer := &installerStub{}
|
|
service := Service{Installer: installer}
|
|
var progress []string
|
|
if err := service.Install(context.Background(), func(message string) { progress = append(progress, message) }); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !installer.called {
|
|
t.Error("installer was not called")
|
|
}
|
|
if len(progress) != 1 || progress[0] != "Pulling release..." {
|
|
t.Errorf("progress = %#v", progress)
|
|
}
|
|
}
|
|
|
|
func TestFormatSnapshotReportsAvailableAndUnchangedComponents(t *testing.T) {
|
|
got := FormatSnapshot(Snapshot{Components: []Component{
|
|
{Label: "THE GATEWAY", Installed: "v1", Available: "v2", Changelog: "- safer updates"},
|
|
{Label: "THE RUNTIME", Installed: "v1"},
|
|
}})
|
|
for _, want := range []string{"Archie has an update available", "v2 available", "safer updates", "No runtime changes"} {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("formatted snapshot missing %q: %s", want, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSameAvailableIgnoresMetadataAndDetectsVersionChanges(t *testing.T) {
|
|
left := Snapshot{Components: []Component{{ID: "gateway", Installed: "v1", Available: "v2", Changelog: "old"}}}
|
|
right := Snapshot{Components: []Component{{ID: "gateway", Installed: "v1", Available: "v2", Changelog: "new"}}}
|
|
if !SameAvailable(left, right) {
|
|
t.Fatal("matching available versions should be equal")
|
|
}
|
|
right.Components[0].Available = "v3"
|
|
if SameAvailable(left, right) {
|
|
t.Fatal("changed available versions should not be equal")
|
|
}
|
|
}
|
|
|
|
type catalogStub struct{ snapshot Snapshot }
|
|
|
|
func (s *catalogStub) Check(context.Context) (Snapshot, error) { return s.snapshot, nil }
|
|
|
|
type installerStub struct{ called bool }
|
|
|
|
func (s *installerStub) Install(_ context.Context, progress func(string)) error {
|
|
s.called = true
|
|
progress("Pulling release...")
|
|
return nil
|
|
}
|