Files
superwork/vscode/cli/internal/marker/marker_test.go
T
cruldra def5f4e88c ✨ feat(spx): issue marker 支持第三种类型 prototype
- --type 三选一 spec|plan|prototype,marker 行写 <!-- spx:prototype=路径 -->,
  与 spec/plan 共用同一套增量更新逻辑;类型→state 字段的映射收成一张表
- 同步写 state JSON 的 prototypeFile(pattern 要求 dir/.../x.json)
- 顺手补上 b62e58d 漏掉的 prototypeSessionId / prototypeProfilePath:
  schema 与 knownStateFields 都没有它们,带原型会话的工单一 merge
  就会被 additionalProperties 拒掉

Claude-Session: https://claude.ai/code/session_01Kgmb1LvrPmFX3NoUDB4zZC
2026-09-15 00:08:31 +08:00

87 lines
2.7 KiB
Go

package marker
import (
"strings"
"testing"
)
func TestUpsertMarkerAppendsWhenAbsent(t *testing.T) {
got := UpsertMarker("hello body", "spec", "docs/specs/x.md")
want := "hello body\n<!-- spx:spec=docs/specs/x.md -->"
if got != want {
t.Fatalf("got %q want %q", got, want)
}
}
func TestUpsertMarkerReplacesWhenPresent(t *testing.T) {
body := "intro\n<!-- spx:spec=old.md -->\nmore"
got := UpsertMarker(body, "spec", "new.md")
if strings.Contains(got, "old.md") {
t.Fatalf("old value should be gone: %q", got)
}
if !strings.Contains(got, "<!-- spx:spec=new.md -->") {
t.Fatalf("new marker missing: %q", got)
}
// Other content preserved.
if !strings.Contains(got, "intro") || !strings.Contains(got, "more") {
t.Fatalf("surrounding content lost: %q", got)
}
}
func TestUpsertMarkerLeavesOtherTypesAlone(t *testing.T) {
body := "<!-- spx:plan=p.md -->\n<!-- spx:prototype=docs/prototype/x/figma-plugin/manifest.json -->\n<!-- spx:spec=old.md -->"
got := UpsertMarker(body, "spec", "new.md")
if !strings.Contains(got, "<!-- spx:plan=p.md -->") {
t.Fatalf("plan marker should be preserved: %q", got)
}
if !strings.Contains(got, "<!-- spx:prototype=docs/prototype/x/figma-plugin/manifest.json -->") {
t.Fatalf("prototype marker should be preserved: %q", got)
}
if !strings.Contains(got, "<!-- spx:spec=new.md -->") {
t.Fatalf("spec marker should be updated: %q", got)
}
}
func TestUpsertMarkerPrototypeAppendsWhenAbsent(t *testing.T) {
got := UpsertMarker("hello body", "prototype", "docs/prototype/login/figma-plugin/manifest.json")
want := "hello body\n<!-- spx:prototype=docs/prototype/login/figma-plugin/manifest.json -->"
if got != want {
t.Fatalf("got %q want %q", got, want)
}
}
func TestUpsertMarkerPrototypeReplacesWhenPresent(t *testing.T) {
body := "intro\n<!-- spx:prototype=old/manifest.json -->\nmore"
got := UpsertMarker(body, "prototype", "new/manifest.json")
if strings.Contains(got, "old/manifest.json") {
t.Fatalf("old value should be gone: %q", got)
}
if !strings.Contains(got, "<!-- spx:prototype=new/manifest.json -->") {
t.Fatalf("new marker missing: %q", got)
}
}
func TestUpsertMarkerEmptyBody(t *testing.T) {
got := UpsertMarker("", "plan", "p.md")
want := "<!-- spx:plan=p.md -->"
if got != want {
t.Fatalf("got %q want %q", got, want)
}
}
func TestPrependReviewMarkerAdds(t *testing.T) {
got := PrependReviewMarker("body")
want := "<!-- spx:review=1 -->\n\nbody"
if got != want {
t.Fatalf("got %q want %q", got, want)
}
}
func TestPrependReviewMarkerIdempotent(t *testing.T) {
body := "<!-- spx:review=1 -->\n\nbody"
got := PrependReviewMarker(body)
if got != body {
t.Fatalf("expected unchanged, got %q", got)
}
}