8c1eea53a9
Exchange a build/protocol identity so an older CLI can no longer talk to a newer native server silently: - protocol carries ProtocolVersion and every server frame (including the unsolicited welcome) is stamped with the server build and protocol, so a client that never pings still learns the server identity. - buildinfo.Compare classifies the relationship as InSync/Warn/Refuse and names both builds; the client Watch reports one warning per connection and returns a hard error when the server speaks a newer, uninterpretable protocol so the caller never acts on the frame. - client.ReceiveNotice decodes the raw frame so an unmodeled top-level field produces a one-time "unrecognized field(s)" notice instead of being dropped silently (the case that hid the artifacts field). - CLI routes warnings to stderr, keeps machine JSON stdout clean and fails non-zero on a refused mismatch; ping/connection print the client/server relationship. The TUI surfaces the same notices through the shared log. - scripts/setup-native.py now warns when an older `pipelines` earlier on PATH shadows prefix/bin/pipelines, naming both paths and versions, without installing or modifying anything else. - Docs, the packaged debugging skill reference and README no longer imply the installed CLI always matches the server. Tests cover the comparison table, unknown-field detection and caching, the server identity stamping on pong and welcome, the CLI/TUI reporting paths and the installer PATH shadowing warning.
144 lines
4.0 KiB
Go
144 lines
4.0 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"git.a-wan.net/alan/pipelines/internal/client"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type editorPublicationMsg struct {
|
|
edit editedMsg
|
|
generation uint64
|
|
pipelines []protocol.PipelineSummary
|
|
detail *protocol.PipelineDetail
|
|
published bool
|
|
notices []string
|
|
err error
|
|
}
|
|
|
|
func checkEditorPublication(ctx context.Context, endpoint string, edit editedMsg, generation uint64) tea.Cmd {
|
|
return func() tea.Msg {
|
|
return publicationCheck(ctx, endpoint, edit, generation)
|
|
}
|
|
}
|
|
|
|
// publicationCheck runs the publication comparison for one editor submission.
|
|
// The named result lets the deferred hook attach any build/protocol notices
|
|
// from the short-lived client to every return path.
|
|
func publicationCheck(ctx context.Context, endpoint string, edit editedMsg, generation uint64) (result editorPublicationMsg) {
|
|
result = editorPublicationMsg{edit: edit, generation: generation}
|
|
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
|
defer cancel()
|
|
c, err := client.Open(ctx, endpoint)
|
|
if err != nil {
|
|
result.err = err
|
|
return result
|
|
}
|
|
defer c.Close()
|
|
sink := ¬iceSink{}
|
|
c.Report(sink.report)
|
|
// Surface any build/protocol notice through the shared TUI notice path
|
|
// rather than dropping it for this short-lived client.
|
|
defer func() { result.notices = sink.drain() }()
|
|
list, err := c.Call(ctx, protocol.Message{Type: protocol.List})
|
|
if err != nil {
|
|
result.err = err
|
|
return result
|
|
}
|
|
result.pipelines = list.Pipelines
|
|
for _, p := range list.Pipelines {
|
|
if p.Name != strings.TrimSpace(edit.name) {
|
|
continue
|
|
}
|
|
response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID})
|
|
if err != nil {
|
|
result.err = err
|
|
return result
|
|
}
|
|
result.detail = response.Detail
|
|
if result.detail == nil {
|
|
result.err = fmt.Errorf("server returned no pipeline detail")
|
|
return result
|
|
}
|
|
if result.detail.Source == edit.source {
|
|
result.published = true
|
|
return result
|
|
}
|
|
// If another version was published afterward, the editor's submitted
|
|
// source still must not be offered for duplicate submission. Only
|
|
// inspect versions newer than this draft's immutable starting point.
|
|
for _, v := range result.detail.Versions {
|
|
if v.Version <= edit.baseVersion || v.Version == result.detail.Version {
|
|
continue
|
|
}
|
|
response, err := c.Call(ctx, protocol.Message{Type: protocol.GetPipeline, PipelineID: p.ID, Version: v.Version})
|
|
if err != nil {
|
|
result.err = err
|
|
return result
|
|
}
|
|
if response.Detail != nil && response.Detail.Source == edit.source {
|
|
result.published = true
|
|
return result
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (m Model) finishEditorPublication(msg editorPublicationMsg) (tea.Model, tea.Cmd) {
|
|
if msg.generation != m.editorCheckGeneration {
|
|
return m, nil
|
|
}
|
|
m.appendNotices(msg.notices)
|
|
m.editorChecking = false
|
|
if msg.err == nil {
|
|
m.pipelines = msg.pipelines
|
|
m.loaded = true
|
|
if msg.detail != nil {
|
|
m.detail = msg.detail
|
|
m.keys.detail = true
|
|
m.detailLoading = false
|
|
m.detailError = ""
|
|
m.detailRequest = ""
|
|
m.requestedPipelineID = msg.detail.ID
|
|
m.requestedVersion = msg.detail.Version
|
|
m.resetPipelineView()
|
|
}
|
|
}
|
|
if msg.published {
|
|
m.pendingDraft = nil
|
|
m.confirmOpen = false
|
|
m.keys.confirm = false
|
|
m.draftOpen = false
|
|
m.keys.drafts = false
|
|
m.templateOpen = false
|
|
m.keys.templates = false
|
|
m.submitNotice = "Already published; reloaded latest version."
|
|
m.appendLine(m.submitNotice)
|
|
return m, nil
|
|
}
|
|
if msg.edit.unchanged {
|
|
m.confirmOpen = false
|
|
m.keys.confirm = false
|
|
m.submitNotice = "No local changes; page refreshed."
|
|
if msg.err != nil {
|
|
m.submitNotice = "No local changes; refresh failed: " + msg.err.Error()
|
|
}
|
|
m.appendLine(m.submitNotice)
|
|
return m, nil
|
|
}
|
|
m.pendingDraft = &msg.edit
|
|
m.confirmOpen = true
|
|
m.keys.confirm = true
|
|
m.submitNotice = ""
|
|
if msg.err != nil {
|
|
m.submitNotice = "Could not check publication; draft retained: " + msg.err.Error()
|
|
}
|
|
return m, nil
|
|
}
|