Files
LocalAI/pkg/addons/contract/changeproposal_test.go
T
Ettore Di Giacinto f7c8dd15d6 feat(contract): add the change proposal record
A model can ask to change the person's own state (a memory note, a
profile, a skill). Add the versioned wire record, its kinds, scopes,
statuses, source and limits, so every surface that runs a model, and
any add-on, shares one type without platform code.

Assisted-by: Claude Code:claude-sonnet-5-5
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-11-03 09:23:59 +00:00

51 lines
1.8 KiB
Go

// SPDX-License-Identifier: MIT
package contract
import (
"encoding/json"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("change proposals", func() {
It("names every kind and status once", func() {
Expect(ChangeKinds()).To(ConsistOf(ChangeMemory, ChangeProfile, ChangeSkill, ChangePage, ChangeDashboard))
for _, k := range ChangeKinds() {
Expect(ValidChangeKind(string(k))).To(BeTrue(), "kind %s", k)
}
Expect(ValidChangeKind("Memory")).To(BeFalse())
Expect(ValidChangeKind("")).To(BeFalse())
Expect(ValidChangeScope("user")).To(BeTrue())
Expect(ValidChangeScope("agent")).To(BeTrue())
Expect(ValidChangeScope("channel")).To(BeTrue())
Expect(ValidChangeScope("team")).To(BeFalse())
})
It("tells a settled status from a pending one", func() {
Expect(ProposalPending.Settled()).To(BeFalse())
for _, s := range []ProposalStatus{ProposalApplied, ProposalDismissed, ProposalExpired, ProposalReverted, ProposalStale} {
Expect(s.Settled()).To(BeTrue(), "status %s", s)
}
})
It("keeps the wire version and omits empty fields", func() {
p := ChangeProposal{V: ChangeProposalVersion, ID: "c1", Kind: ChangeMemory, Scope: ScopeUser, Target: "index.md",
Status: ProposalPending, Created: time.Date(2026, 11, 3, 9, 0, 0, 0, time.UTC)}
raw, err := json.Marshal(p)
Expect(err).NotTo(HaveOccurred())
Expect(string(raw)).To(ContainSubstring(`"v":1`))
Expect(string(raw)).NotTo(ContainSubstring(`"source"`))
Expect(string(raw)).NotTo(ContainSubstring(`"rev"`))
})
It("has the limits the owner decided", func() {
Expect(ChangeExpiry).To(Equal(24 * time.Hour))
Expect(MaxPendingChanges).To(Equal(10))
Expect(MaxChangesPerHour).To(Equal(5))
Expect(MaxProfileBytes).To(Equal(4 << 10))
Expect(MaxChangeBytes).To(Equal(16 << 10))
})
})