服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
161 lines
5.7 KiB
Go
161 lines
5.7 KiB
Go
package services
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"pvfine/internal/pvf"
|
|
"pvfine/internal/ruleconfig"
|
|
)
|
|
|
|
func ruleServiceFixture(t *testing.T) (*core, *RuleService) {
|
|
t.Helper()
|
|
dir := t.TempDir()
|
|
files := map[string]string{
|
|
"annotations.json": `{"version":1,"rules":[{"id":"path","match":{"glob":"a.etc"},"target":{"kind":"path"},"annotation":{"type":"text","title":"old"}},{"id":"section","match":{"extensions":[".etc"]},"target":{"kind":"section","section":"name"},"annotation":{"type":"text","title":"old"}}]}`,
|
|
"rendering.json": `{"version":1,"rules":[{"id":"name","match":{},"target":{"kind":"section","section":"name"},"format":{"tokensPerLine":2}}]}`,
|
|
"paths.json": `{"version":1,"rules":[]}`, "sections.json": `{"version":1,"rules":[]}`, "lists.json": `{"version":1,"relations":{}}`,
|
|
}
|
|
for name, data := range files {
|
|
if err := os.WriteFile(filepath.Join(dir, name), []byte(data), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
c := newCore()
|
|
c.ruleStore = ruleconfig.New(true, dir, t.TempDir())
|
|
service := NewRuleService(c)
|
|
for _, category := range []string{"annotations", "rendering"} {
|
|
if err := service.reload(category); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
t.Cleanup(c.closeArchive)
|
|
return c, service
|
|
}
|
|
func TestRuleServiceSaveWithoutArchiveAndRejectStaleRevision(t *testing.T) {
|
|
c, s := ruleServiceFixture(t)
|
|
q, err := s.Query(RuleTarget{Category: "annotations", Path: "a.etc"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(q.Entries) != 1 || !q.Entries[0].Effective {
|
|
t.Fatalf("query = %#v", q)
|
|
}
|
|
m := ruleconfig.Mutation{Category: "annotations", Revision: q.Revision, Kind: "rule", ID: "path", Action: "save", JSON: `{"id":"path","match":{"glob":"a.etc"},"target":{"kind":"path"},"annotation":{"type":"text","title":"new"}}`}
|
|
if err := s.Apply(m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := c.annotationEngine.AnnotatePath("a.etc", false); len(got) != 1 || got[0].Title != "new" {
|
|
t.Fatalf("inactive save: %#v", got)
|
|
}
|
|
if err := s.Apply(m); err == nil {
|
|
t.Fatal("stale write accepted")
|
|
}
|
|
}
|
|
func TestRuleServiceUpdatesArchiveAndPreservesDraft(t *testing.T) {
|
|
c, s := ruleServiceFixture(t)
|
|
a := pvf.New()
|
|
index := mustAddText(t, a, "a.etc", "[name]\n1 2 3 4", pvf.TypeScript)
|
|
if err := c.setArchive(a); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
editor := NewEditorService(c)
|
|
if err := editor.SetText(index, "[name]\n1 2 3 4 5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
q, err := s.Query(RuleTarget{Category: "rendering", Path: "a.etc", Section: "name"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(q.Entries) != 1 || !q.Entries[0].Effective {
|
|
t.Fatalf("query=%#v", q)
|
|
}
|
|
if err := s.Apply(ruleconfig.Mutation{Category: "rendering", Revision: q.Revision, Kind: "rule", ID: "name", Action: "save", JSON: `{"id":"name","match":{},"target":{"kind":"section","section":"name"},"format":{"tokensPerLine":1}}`}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
meta, err := editor.GetFile(index)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if meta.Text != "[name]\n1 2 3 4 5" {
|
|
t.Fatalf("draft replaced: %q", meta.Text)
|
|
}
|
|
if c.renderingEngine.SectionFormat("a.etc", "name").TokensPerLine != 1 {
|
|
t.Fatal("renderer not activated")
|
|
}
|
|
q, err = s.Query(RuleTarget{Category: "annotations", Path: "a.etc", Section: "name"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var raw map[string]any
|
|
json.Unmarshal([]byte(q.Entries[0].JSON), &raw)
|
|
raw["annotation"] = map[string]any{"type": "text", "title": "changed"}
|
|
data, _ := json.Marshal(raw)
|
|
if err := s.Apply(ruleconfig.Mutation{Category: "annotations", Revision: q.Revision, Kind: "rule", ID: "section", Action: "save", JSON: string(data)}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
anns, err := editor.GetAnnotations(index)
|
|
if err != nil || len(anns) == 0 || anns[0].Title != "changed" {
|
|
t.Fatalf("annotations = %#v, %v", anns, err)
|
|
}
|
|
}
|
|
func TestRuleServiceInvalidReloadPreservesEngine(t *testing.T) {
|
|
c, s := ruleServiceFixture(t)
|
|
previous := c.renderingEngine
|
|
if err := os.WriteFile(filepath.Join(c.ruleStore.SourceDir, "rendering.json"), []byte("{"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := NewRenderingService(c).ReloadRules(); err == nil {
|
|
t.Fatal("corruption accepted")
|
|
}
|
|
if c.renderingEngine != previous {
|
|
t.Fatal("reload changed active engine")
|
|
}
|
|
if _, err := s.Query(RuleTarget{Category: "rendering", Path: "a.etc"}); err == nil {
|
|
t.Fatal("damaged file editable")
|
|
}
|
|
}
|
|
|
|
func TestRuleStartupFallsBackForDamagedUserConfiguration(t *testing.T) {
|
|
c := newCore()
|
|
previous := c.renderingEngine
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "rendering.user.json"), []byte("{"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c.loadInitialRules(ruleconfig.New(false, "", dir))
|
|
if c.renderingEngine != previous || c.renderingErr != nil || len(c.ruleWarnings) == 0 {
|
|
t.Fatal("startup did not retain embedded renderer with warning")
|
|
}
|
|
if _, err := NewRenderingService(c).ReloadRules(); err == nil {
|
|
t.Fatal("damaged user configuration accepted on reload")
|
|
}
|
|
data, _ := os.ReadFile(filepath.Join(dir, "rendering.user.json"))
|
|
if string(data) != "{" {
|
|
t.Fatal("damaged configuration overwritten")
|
|
}
|
|
}
|
|
|
|
func TestRuleDraftAnnotationsDoNotCommitText(t *testing.T) {
|
|
c, _ := ruleServiceFixture(t)
|
|
a := pvf.New()
|
|
index := mustAddText(t, a, "a.etc", "[name]\n1", pvf.TypeScript)
|
|
if err := c.setArchive(a); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before, _ := a.Text(index)
|
|
wasModified := a.IsModified(index)
|
|
cached := c.editorText[index]
|
|
draft := "# draft\n[name]\n2"
|
|
anns, err := NewEditorService(c).GetAnnotationsForText(index, draft)
|
|
if err != nil || len(anns) == 0 || anns[0].Start < 8 {
|
|
t.Fatalf("draft annotations=%#v, %v", anns, err)
|
|
}
|
|
after, _ := a.Text(index)
|
|
if before != after || a.IsModified(index) != wasModified || c.editorText[index] != cached {
|
|
t.Fatal("annotation refresh committed frontend draft")
|
|
}
|
|
}
|