An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:white_check_mark: Cover structured title upgrades and recovery https://github.com/siyuan-note/siyuan/issues/19938
Danield969dcbc11b7
diff --git a/app/src/plugin/loader.test.ts b/app/src/plugin/loader.test.tsindex 039c2186f9..ef23e4b09e 100644--- a/app/src/plugin/loader.test.ts+++ b/app/src/plugin/loader.test.ts@@ -236,6 +236,7 @@ test("removing a dock preserves its open state for re-enabling while explicitlyconst dependencies = {resizeTabs: (): void => undefined,adjustDockPadding: (): void => undefined,+ syncDockBarVisibility: (): boolean => false,updatePluginDockShowStates,setStorageVal: (): void => undefined,Constants: {LOCAL_PLUGIN_DOCKS: "local-plugin-docks"},diff --git a/kernel/documentaddressing/migration_test.go b/kernel/documentaddressing/migration_test.goindex 3ea137eeaf..2a66287062 100644--- a/kernel/documentaddressing/migration_test.go+++ b/kernel/documentaddressing/migration_test.go@@ -2,12 +2,16 @@ package documentaddressingimport ("bytes"+ "context""encoding/json""errors""fmt""os"+ "os/exec""path/filepath"+ "strconv""testing"+ "time""github.com/siyuan-note/filelock")@@ -188,3 +192,117 @@ func TestStructuredTitlesMissingConfigurationRetainsFloor(t *testing.T) {t.Fatal("mode inspection recreated a deleted notebook", err)}}++func TestStructuredTitlesMigrationProcessRestart(t *testing.T) {+ const rootVariable = "SIYUAN_TEST_TITLE_MIGRATION_ROOT"+ const phaseVariable = "SIYUAN_TEST_TITLE_MIGRATION_PHASE"+ const interruptedExit = 73+ if root := os.Getenv(rootVariable); root != "" {+ dataDir, confDir := filepath.Join(root, "data"), filepath.Join(root, "conf")+ phase := os.Getenv(phaseVariable)+ switch phase {+ case "guard":+ defaultMode = 1+ if err := CheckBox(dataDir, confDir, testBox); !errors.Is(err, ErrUnsupported) {+ t.Fatal("protective reader admitted an interrupted or upgraded notebook", err)+ }+ case "recover":+ if err := CheckBox(dataDir, confDir, testBox); err != nil {+ t.Fatal(err)+ }+ snapshot, err := InspectBox(dataDir, confDir, testBox)+ if err != nil || snapshot.Mode != 2 || !snapshot.RecordsConsistent || snapshot.State != "structured" {+ t.Fatal("fresh process did not finish migration", snapshot, err)+ }+ default:+ stage, err := strconv.Atoi(phase)+ if err != nil || stage < 0 || stage > 4 {+ t.Fatal("invalid interruption stage", phase)+ }+ store, err := loadStore(dataDir, confDir)+ if err != nil {+ t.Fatal(err)+ }+ writes := 0+ err = migrateBoxRecords(dataDir, testBox, store, func(name string, data []byte) error {+ if err := filelock.WriteFile(name, data); err != nil {+ return err+ }+ writes+++ if writes == stage {+ // 已完成的持久写入保留;直接结束进程,禁止清理函数代为完成迁移。+ os.Exit(interruptedExit)+ }+ return nil+ })+ if err != nil {+ t.Fatal(err)+ }+ }+ return+ }++ for stage := 0; stage <= 4; stage++ {+ t.Run(strconv.Itoa(stage), func(t *testing.T) {+ root := t.TempDir()+ boxDir := filepath.Join(root, "data", testBox)+ original := `{"name":"legacy","closed":false,"custom":{"keep":[1,2,3]}}`+ writeTestFile(t, boxDir, ConfigPath, original)+ const document = "20261023000001-abcdefg.sy"+ const source = `{"ID":"20261023000001-abcdefg","Spec":"2","Type":"NodeDocument","Properties":{"id":"20261023000001-abcdefg","title":"Legacy %2F"}}`+ writeTestFile(t, boxDir, document, source)+ writeTestFile(t, boxDir, "assets/retained.bin", "existing attachment")+ run := func(phase string, exitCode int) {+ t.Helper()+ ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)+ defer cancel()+ command := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestStructuredTitlesMigrationProcessRestart$", "-test.v")+ command.Env = append(os.Environ(), rootVariable+"="+root, phaseVariable+"="+phase)+ output, err := command.CombinedOutput()+ if exitCode == 0 && err == nil {+ return+ }+ var exited *exec.ExitError+ if errors.As(err, &exited) && exited.ExitCode() == exitCode {+ return+ }+ t.Fatalf("phase %s: expected exit %d, got %v\n%s", phase, exitCode, err, output)+ }+ expectedExit := 0+ if stage > 0 {+ expectedExit = interruptedExit+ }+ run(strconv.Itoa(stage), expectedExit)+ run("guard", 0)+ run("recover", 0)+ config, err := os.ReadFile(filepath.Join(boxDir, ConfigPath))+ if err != nil {+ t.Fatal(err)+ }+ var fields map[string]json.RawMessage+ if err = json.Unmarshal(config, &fields); err != nil || string(fields["documentAddressingVersion"]) != "2" {+ t.Fatal("configuration projection was not recovered", err)+ }+ delete(fields, "documentAddressingVersion")+ var wanted map[string]json.RawMessage+ _ = json.Unmarshal([]byte(original), &wanted)+ for key, value := range wanted {+ var compact bytes.Buffer+ if err = json.Compact(&compact, fields[key]); err != nil || !bytes.Equal(value, compact.Bytes()) {+ t.Fatalf("migration changed configuration field %s", key)+ }+ }+ run("recover", 0)+ for name, want := range map[string]string{ConfigPath: string(config), document: source, "assets/retained.bin": "existing attachment"} {+ data, err := os.ReadFile(filepath.Join(boxDir, name))+ if err != nil || string(data) != want {+ t.Fatalf("restart changed %s: %v", name, err)+ }+ }+ journal := filepath.Join(root, "conf", "document-addressing-recovery", testBox+".json")+ if _, err = os.Stat(journal); !errors.Is(err, os.ErrNotExist) {+ t.Fatal("recovered process retained a migration journal", err)+ }+ })+ }+}diff --git a/kernel/model/structured_titles_upgrade_test.go b/kernel/model/structured_titles_upgrade_test.gonew file mode 100644index 0000000000..088915ab8f--- /dev/null+++ b/kernel/model/structured_titles_upgrade_test.go@@ -0,0 +1,297 @@+//go:build fts5 && (sqlcipher || libsqlcipher)++package model++import (+ "bytes"+ "context"+ "crypto/sha256"+ "encoding/hex"+ "encoding/json"+ "os"+ "os/exec"+ "path/filepath"+ "reflect"+ "testing"+ "time"++ "github.com/siyuan-note/dejavu"+ "github.com/siyuan-note/dejavu/cloud"+ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/documentaddressing"+ "github.com/siyuan-note/siyuan/kernel/filesys"+ "github.com/siyuan-note/siyuan/kernel/sql"+ "github.com/siyuan-note/siyuan/kernel/treenode"+ "github.com/siyuan-note/siyuan/kernel/util"+)++type structuredTitlesLegacyFixture struct {+ Password string `json:"password"`+ Documents []struct {+ Notebook string `json:"notebook"`+ ID string `json:"id"`+ ParentID string `json:"parentID"`+ Path string `json:"path"`+ Title string `json:"title"`+ Encrypted bool `json:"encrypted"`+ } `json:"documents"`+ SHA256 map[string]string `json:"sha256"`+}++func loadStructuredTitlesLegacyFixture(t *testing.T) (string, structuredTitlesLegacyFixture) {+ t.Helper()+ directory := filepath.Join("testdata", "structured_titles_legacy")+ data, err := os.ReadFile(filepath.Join(directory, "manifest.json"))+ if err != nil {+ t.Fatal(err)+ }+ var fixture structuredTitlesLegacyFixture+ if err = json.Unmarshal(data, &fixture); err != nil {+ t.Fatal(err)+ }+ if len(fixture.Documents) != 4 || len(fixture.SHA256) == 0 {+ t.Fatal("legacy fixture is incomplete")+ }+ for name, expected := range fixture.SHA256 {+ data, err := os.ReadFile(filepath.Join(directory, name))+ if err != nil {+ t.Fatal(err)+ }+ sum := sha256.Sum256(data)+ if hex.EncodeToString(sum[:]) != expected {+ t.Fatalf("released fixture changed: %s", name)+ }+ }+ return directory, fixture+}++func TestStructuredTitlesReleasedDataUpgradeAndRestart(t *testing.T) {+ directory, fixture := loadStructuredTitlesLegacyFixture(t)+ const rootVariable = "SIYUAN_TEST_RELEASED_TITLES_ROOT"+ root := os.Getenv(rootVariable)+ if root == "" {+ root = t.TempDir()+ if err := os.CopyFS(filepath.Join(root, "data"), os.DirFS(filepath.Join(directory, "data"))); err != nil {+ t.Fatal(err)+ }+ for _, phase := range []string{"upgrade", "restart"} {+ ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)+ command := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestStructuredTitlesReleasedDataUpgradeAndRestart$", "-test.v")+ command.Env = append(os.Environ(), rootVariable+"="+root)+ output, err := command.CombinedOutput()+ cancel()+ if err != nil {+ t.Fatalf("%s: %v\n%s", phase, err, output)+ }+ }+ return+ }++ // 每个进程使用全新索引,只有旧文档及迁移后的持久记录跨进程保存。+ prepareHPathRefreshTest(t)+ t.Cleanup(backgroundRefreshWaitGroup.Wait)+ util.WorkspaceDir, util.DataDir, util.ConfDir = root, filepath.Join(root, "data"), filepath.Join(root, "conf")+ Conf.Flashcard.Store(conf.NewFlashcard())+ keyData, err := os.ReadFile(filepath.Join(directory, "notebook-crypto.json"))+ if err != nil {+ t.Fatal(err)+ }+ if err = json.Unmarshal(keyData, &Conf.NotebookCrypto); err != nil {+ t.Fatal(err)+ }+ keys, _ := json.Marshal(currentNotebookCrypto())+ boxes := map[string]bool{}+ for _, document := range fixture.Documents {+ boxes[document.Notebook] = document.Encrypted+ }+ for box, encrypted := range boxes {+ configPath := filepath.Join(util.DataDir, box, documentaddressing.ConfigPath)+ before, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatal(err)+ }+ if err = documentaddressing.CheckBox(util.DataDir, util.ConfDir, box); err != nil {+ t.Fatal(err)+ }+ after, err := os.ReadFile(configPath)+ if err != nil {+ t.Fatal(err)+ }+ var original, migrated map[string]any+ if json.Unmarshal(before, &original) != nil || json.Unmarshal(after, &migrated) != nil {+ t.Fatal("invalid notebook configuration")+ }+ delete(original, "documentAddressingVersion")+ delete(migrated, "documentAddressingVersion")+ if !reflect.DeepEqual(original, migrated) {+ t.Fatal("mode migration changed old configuration or key material")+ }+ if encrypted {+ crypt, err := GetBoxEncryption(box)+ if err != nil {+ t.Fatal(err)+ }+ if _, err = UnlockAndMountBox(box, "incorrect-fixture-password", crypt); err == nil || IsBoxUnlocked(box) {+ t.Fatal("legacy encrypted notebook bypassed password authentication")+ }+ if _, err = UnlockAndMountBox(box, fixture.Password, crypt); err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { LockBox(box) })+ } else if _, err = Mount(box); err != nil {+ t.Fatal(err)+ }+ indexBox(box)+ sql.FlushQueue()+ if treenode.DocumentMetadataState(box) != "ready" {+ t.Fatal("legacy source index was not rebuilt")+ }+ }+ for _, document := range fixture.Documents {+ tree, err := filesys.LoadTree(document.Notebook, document.Path, util.NewLute())+ if err != nil || tree.Root.Spec != "2" || tree.ID != document.ID || tree.Root.IALAttr("id") != document.ID ||+ treenode.ReadDocumentTitle(tree.Root).Text != document.Title {+ t.Fatalf("legacy document changed identity, title or specification: %s, %v", document.ID, err)+ }+ paths, missing, err := GetDocPaths(document.Notebook, []string{document.ID})+ if err != nil || len(missing) != 0 || len(paths) != 1 {+ t.Fatal("legacy document missing from rebuilt metadata", err)+ }+ parent := ""+ if paths[0].ParentID != nil {+ parent = *paths[0].ParentID+ }+ if paths[0].Title.Text != document.Title || parent != document.ParentID {+ t.Fatalf("legacy hierarchy or literal title changed: %+v", paths[0])+ }+ original, err := os.ReadFile(filepath.Join(directory, "data", document.Notebook, document.Path))+ if err != nil {+ t.Fatal(err)+ }+ current, err := os.ReadFile(filepath.Join(util.DataDir, document.Notebook, document.Path))+ if err != nil || !bytes.Equal(original, current) || util.IsCiphertext(current) != document.Encrypted {+ t.Fatal("upgrade or authenticated reindex rewrote a legacy source", err)+ }+ }+ afterKeys, _ := json.Marshal(currentNotebookCrypto())+ if !bytes.Equal(keys, afterKeys) {+ t.Fatal("upgrade changed the master salt, verifier or recovery keys")+ }+}++func TestStructuredTitlesSyncAndSnapshotRetainUpgradedMode(t *testing.T) {+ const helper = "SIYUAN_TEST_RELEASED_TITLES_SYNC"+ if os.Getenv(helper) != "1" {+ // 同步事件及笔记本生命周期是进程级状态,不能继承其他模型用例的后台任务。+ ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)+ defer cancel()+ command := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestStructuredTitlesSyncAndSnapshotRetainUpgradedMode$", "-test.v")+ command.Env = append(os.Environ(), helper+"=1")+ if output, err := command.CombinedOutput(); err != nil {+ t.Fatalf("released-data sync: %v\n%s", err, output)+ }+ return+ }+ directory, fixture := loadStructuredTitlesLegacyFixture(t)+ full, receiver, fullData := prepareAssetDownloadRepoTest(t)+ backend := cloud.NewLocal(&cloud.BaseCloud{Conf: &cloud.Conf{Dir: "main", RepoPath: full.Path,+ AvailableSize: 1 << 30, Local: &cloud.ConfLocal{Endpoint: Conf.LoadSync().Local.Endpoint}}})+ sender, err := dejavu.NewRepoWithOptions(dejavu.Options{+ DataPath: full.DataPath, RepoPath: full.Path, HistoryPath: full.HistoryPath, TempPath: full.TempPath,+ DeviceID: full.DeviceID, DeviceName: full.DeviceName, DeviceOS: full.DeviceOS,+ AESKey: Conf.LoadRepo().Key, Cloud: backend, HiddenDirectoryNames: []string{".siyuan"},+ })+ if err != nil {+ t.Fatal(err)+ }+ boxes := map[string]bool{}+ for _, document := range fixture.Documents {+ boxes[document.Notebook] = true+ }+ for box := range boxes {+ if err = os.CopyFS(filepath.Join(fullData, box), os.DirFS(filepath.Join(directory, "data", box))); err != nil {+ t.Fatal(err)+ }+ // 旧样本与升级记录使用不同的秒级时间,避免测试准备阶段复用快照文件身份。+ if err = filepath.WalkDir(filepath.Join(fullData, box), func(name string, entry os.DirEntry, walkErr error) error {+ if walkErr != nil || entry.IsDir() {+ return walkErr+ }+ stamp := time.Unix(1700000000, 0)+ return os.Chtimes(name, stamp, stamp)+ }); err != nil {+ t.Fatal(err)+ }+ }+ synchronize := func(source *dejavu.Repo, memo string, target *dejavu.Repo) {+ t.Helper()+ if _, err := source.Index(memo, false, nil); err != nil {+ t.Fatalf("%s: index sender: %v", memo, err)+ }+ if _, _, err := source.Sync(nil); err != nil {+ t.Fatalf("%s: upload sender: %v", memo, err)+ }+ if _, _, err := target.Sync(nil); err != nil {+ t.Fatalf("%s: sync receiver: %v", memo, err)+ }+ }+ synchronize(sender, "released notebook data", receiver)+ legacy, err := receiver.Index("before automatic migration", false, nil)+ if err != nil {+ t.Fatal(err)+ }+ assertUpgraded := func() {+ t.Helper()+ for box := range boxes {+ if err := documentaddressing.CheckBox(receiver.DataPath, util.ConfDir, box); err != nil {+ t.Fatal(err)+ }+ snapshot, err := documentaddressing.InspectBox(receiver.DataPath, util.ConfDir, box)+ if err != nil || snapshot.Mode != 2 || !snapshot.RecordsConsistent {+ t.Fatal("sync or snapshot lowered a confirmed capability", snapshot, err)+ }+ }+ for _, document := range fixture.Documents {+ name := filepath.Join(document.Notebook, document.Path)+ original, err := os.ReadFile(filepath.Join(directory, "data", name))+ if err != nil {+ t.Fatal(err)+ }+ current, err := os.ReadFile(filepath.Join(receiver.DataPath, name))+ if err != nil || !bytes.Equal(original, current) {+ t.Fatal("sync or restoration changed a released source", name, err)+ }+ }+ }+ assertUpgraded()+ synchronize(receiver, "automatically upgraded records", sender)+ for box := range boxes {+ // 模拟对端传回未升级配置并删除笔记本下界,接收端须保留已确认的本机要求。+ original, err := os.ReadFile(filepath.Join(directory, "data", box, documentaddressing.ConfigPath))+ if err != nil {+ t.Fatal(err)+ }+ name := filepath.Join(sender.DataPath, box, documentaddressing.ConfigPath)+ if err = os.WriteFile(name, original, 0600); err != nil {+ t.Fatal(err)+ }+ stamp := time.Now().Add(5 * time.Second)+ if err = os.Chtimes(name, stamp, stamp); err != nil {+ t.Fatal(err)+ }+ if err = os.Remove(filepath.Join(sender.DataPath, box, documentaddressing.FloorPath)); err != nil {+ t.Fatal(err)+ }+ }+ synchronize(sender, "stale notebook configuration", receiver)+ for box := range boxes {+ if _, err = os.Stat(filepath.Join(receiver.DataPath, box, documentaddressing.FloorPath)); !os.IsNotExist(err) {+ t.Fatal("the stale remote deletion was not exercised", err)+ }+ }+ assertUpgraded()+ if _, _, err = receiver.Checkout(legacy.ID, nil); err != nil {+ t.Fatal(err)+ }+ assertUpgraded()+}diff --git a/kernel/model/testdata/structured_titles_legacy/.gitattributes b/kernel/model/testdata/structured_titles_legacy/.gitattributesnew file mode 100644index 0000000000..ee4bba5bb1--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/.gitattributes@@ -0,0 +1,3 @@+# 保留历史写入器生成的原始字节,与清单中的 SHA-256 保持一致。+data/** -text+notebook-crypto.json -textdiff --git a/kernel/model/testdata/structured_titles_legacy/README.md b/kernel/model/testdata/structured_titles_legacy/README.mdnew file mode 100644index 0000000000..5422de54f6--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/README.md@@ -0,0 +1,9 @@+# 结构化标题升级样本++本目录由已发布的 `v3.8.9-alpha.4` 源码(提交 `335d16ddc182606864d1b5b89c07f411c8a78636`)实际写入生成,包含普通及加密笔记本各两篇父子文档、旧版笔记本配置、密钥包络及恢复材料。文档采用 Spec 2,配置尚无结构化寻址标记。全部内容和密码均为专门生成的公开测试数据。++`manifest.json` 记录原身份、层级、标题、生成版本和文件 SHA-256;`notebook-crypto.json` 保留旧版本生成的主密码配置。测试必须先校验样本哈希,再复制到临时目录,不能直接修改样本或用当前写入器重新生成旧格式密文。++重新生成时,将 `generate_test.go.txt` 复制到该历史提交的独立源码副本 `kernel/model/structured_titles_legacy_generate_test.go`,设置 `SIYUAN_LEGACY_FIXTURE_DESTINATION` 为新建空目录、`SIYUAN_LEGACY_FIXTURE_COMMIT` 为上述完整提交号,从该副本的 `kernel/` 执行 `go test -tags=fts5,sqlcipher ./model -run=^TestGenerateStructuredTitlesLegacyFixture$ -count=1`。将输出文件复制至样本目录,并在清单的 `sha256` 对象中登记除清单自身外所有生成数据文件的摘要。生成过程使用 Go 1.26.10,随机 ID、盐和密文随机数每次会不同。++这些样本证明旧版本写出的数据能够认证读取和升级;它们不代表旧客户端已经具备对新模式的保护能力,也不替代真实客户端混用验收。diff --git a/kernel/model/testdata/structured_titles_legacy/data/.siyuan/data-crypto-backup.json b/kernel/model/testdata/structured_titles_legacy/data/.siyuan/data-crypto-backup.jsonnew file mode 100644index 0000000000..0078c70d8e--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/data/.siyuan/data-crypto-backup.json@@ -0,0 +1 @@+{"enabled":true,"masterSalt":"uXX9rraT7D5YFPfmf0/VwQ==","kdfParams":{"memory":65536,"iterations":3,"parallelism":4,"keyLength":32},"kekVerifier":"U0VOQwEBDEvO0X/4ITWkdwZauPA1vbXbcC8AX+9fmZ+RY5s99/LdBbZlraCB/OsR42mK+bgeVIeJtbuP","verifierNonce":"S87Rf/ghNaR3Blq4","autoLockMinutes":5,"spec":1,"backupID":"t0w9gz3mx4mtdez3","createdAt":1792749637,"checksum":"1e687935c05340c1d05de35e6ea7aa2cf6fb0825cd8287675c33d7c0cd86cc7c","kekMAC":"urnke0rvW789UYgy1DUTjagCw29SVuGupuuEfQJbjaQ="}\ No newline at end of filediff --git a/kernel/model/testdata/structured_titles_legacy/data/.siyuan/indexignore b/kernel/model/testdata/structured_titles_legacy/data/.siyuan/indexignorenew file mode 100644index 0000000000..e69de29bb2diff --git a/kernel/model/testdata/structured_titles_legacy/data/.siyuan/syncignore b/kernel/model/testdata/structured_titles_legacy/data/.siyuan/syncignorenew file mode 100644index 0000000000..e69de29bb2diff --git a/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/.siyuan/conf.json b/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/.siyuan/conf.jsonnew file mode 100644index 0000000000..ff5536041a--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/.siyuan/conf.json@@ -0,0 +1,16 @@+{+ "name": "Legacy title fixture",+ "sort": 1,+ "icon": "",+ "closed": false,+ "refCreateSaveBox": "",+ "refCreateSavePath": "",+ "docCreateSaveBox": "",+ "docCreateSavePath": "",+ "docCreateTemplatePath": "",+ "dailyNoteSavePath": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}",+ "dailyNoteTemplatePath": "",+ "sortMode": 15,+ "encrypted": false,+ "boxCrypt": null+}\ No newline at end of filediff --git a/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/20261023180037-3dh65i9.sy b/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/20261023180037-3dh65i9.synew file mode 100644index 0000000000..70cd9aa98d--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/20261023180037-3dh65i9.sy@@ -0,0 +1 @@+{"ID":"20261023180037-3dh65i9","Spec":"2","Type":"NodeDocument","Properties":{"id":"20261023180037-3dh65i9","title":"Legacy ordinary","type":"doc","updated":"20261023180037"},"Children":[{"ID":"20261023180037-u25u0yj","Type":"NodeParagraph","Properties":{"id":"20261023180037-u25u0yj","updated":"20261023180037"}},{"ID":"hpath refresh regression","Type":"NodeParagraph","Properties":{"id":"hpath refresh regression","updated":"hpath refresh "}}]}\ No newline at end of filediff --git a/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/20261023180037-3dh65i9/20261023180037-h6el7k4.sy b/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/20261023180037-3dh65i9/20261023180037-h6el7k4.synew file mode 100644index 0000000000..08cf68f392--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/data/20261022000000-normal1/20261023180037-3dh65i9/20261023180037-h6el7k4.sy@@ -0,0 +1 @@+{"ID":"20261023180037-h6el7k4","Spec":"2","Type":"NodeDocument","Properties":{"id":"20261023180037-h6el7k4","title":"Literal / %2F **text** 😀","type":"doc","updated":"20261023180037"},"Children":[{"ID":"20261023180037-q0p1bkd","Type":"NodeParagraph","Properties":{"id":"20261023180037-q0p1bkd","updated":"20261023180037"}},{"ID":"hpath refresh regression","Type":"NodeParagraph","Properties":{"id":"hpath refresh regression","updated":"hpath refresh "}}]}\ No newline at end of filediff --git a/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/.siyuan/conf.json b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/.siyuan/conf.jsonnew file mode 100644index 0000000000..6e88c3e5df--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/.siyuan/conf.json@@ -0,0 +1,22 @@+{+ "name": "Legacy encrypted fixture",+ "sort": 0,+ "icon": "",+ "closed": false,+ "refCreateSaveBox": "",+ "refCreateSavePath": "",+ "docCreateSaveBox": "",+ "docCreateSavePath": "",+ "docCreateTemplatePath": "",+ "dailyNoteSavePath": "/daily note/{{now | date \"2006/01\"}}/{{now | date \"2006-01-02\"}}",+ "dailyNoteTemplatePath": "",+ "sortMode": 15,+ "encrypted": true,+ "boxCrypt": {+ "spec": 1,+ "wrappedDEK": "U0VOQwEBDJYQleFyYO70BrWzREehU31wYFIVytdK6HkTjrowz19thtAzcn62AHxIP3UpHG5b7Y2W/qpmT3bYKi3rDg==",+ "wrapNonce": "lhCV4XJg7vQGtbNE",+ "metadata": "U0VOQwEBDF+Kukhk1s1j6ftstq5EjQY3Ac7GgE/eOtndoQ2XVvwRivrOGQcTQlrYaU2RyKeCpCLEgDizcziODd75h6iY",+ "createdAt": 1792749638016+ }+}\ No newline at end of filediff --git a/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/.siyuan/notebook-crypto-backup.json b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/.siyuan/notebook-crypto-backup.jsonnew file mode 100644index 0000000000..841bb46be3--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/.siyuan/notebook-crypto-backup.json@@ -0,0 +1,7 @@+{+ "spec": 1,+ "wrappedDEK": "U0VOQwEBDJYQleFyYO70BrWzREehU31wYFIVytdK6HkTjrowz19thtAzcn62AHxIP3UpHG5b7Y2W/qpmT3bYKi3rDg==",+ "wrapNonce": "lhCV4XJg7vQGtbNE",+ "metadata": "U0VOQwEBDF+Kukhk1s1j6ftstq5EjQY3Ac7GgE/eOtndoQ2XVvwRivrOGQcTQlrYaU2RyKeCpCLEgDizcziODd75h6iY",+ "createdAt": 1792749638016+}\ No newline at end of filediff --git a/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/20261023180038-pwkjtsl.sy b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/20261023180038-pwkjtsl.synew file mode 100644index 0000000000..fbd1d6c966Binary files /dev/null and b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/20261023180038-pwkjtsl.sy differdiff --git a/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/20261023180038-pwkjtsl/20261023180038-h60kzb9.sy b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/20261023180038-pwkjtsl/20261023180038-h60kzb9.synew file mode 100644index 0000000000..4b7b4c19dd--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/data/20261023180038-mbrj58v/20261023180038-pwkjtsl/20261023180038-h60kzb9.sy@@ -0,0 +1,2 @@+SENC�^�Uw�m4:&��N�t�-m��U��*z���4}�K(%)�@��?Xep9Z�Ƙ;����&��i�世�,�h�ݶRf��(�;����PDv ADM�ۈ��/�eM�b��h�Ǫj^��>R����̌Flh�Ǿ�b�Bt�i�cb����)f<��׳����+7��e�ꩋO�Q�JT�06{��0p~H�8k�)����Y0�k�TY�������&�9�g� Ky�'�`(�C#Cc��^��?L�wன�n��2S�h���:���4��S�'Ñ�Ȩ�C�[l]Q�9�B+����Jap;K/��f��ߖb���ĺJۭ�[�j��m�{�j�F�]�3s8� �i7v�l&����(�Z�tP�;2 .6��9��YJ+7��"U�d'>σ��PhHs&Ë�"���]�yF��s,U�T`B��a ���k1i�z l�� ������yMM��g��{�i�:�������Z�k2F��\ No newline at end of filediff --git a/kernel/model/testdata/structured_titles_legacy/generate_test.go.txt b/kernel/model/testdata/structured_titles_legacy/generate_test.go.txtnew file mode 100644index 0000000000..52d99e7b9a--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/generate_test.go.txt@@ -0,0 +1,90 @@+//go:build fts5 && (sqlcipher || libsqlcipher)++package model++import (+ "encoding/json"+ "os"+ "path/filepath"+ "strings"+ "testing"++ "github.com/88250/lute/parse"+ "github.com/siyuan-note/siyuan/kernel/conf"+ "github.com/siyuan-note/siyuan/kernel/sql"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestGenerateStructuredTitlesLegacyFixture(t *testing.T) {+ destination := os.Getenv("SIYUAN_LEGACY_FIXTURE_DESTINATION")+ if destination == "" {+ t.Fatal("fixture destination is required")+ }+ prepareHPathRefreshTest(t)+ t.Cleanup(backgroundRefreshWaitGroup.Wait)+ Conf.Flashcard.Store(conf.NewFlashcard())+ const password = "legacy-title-fixture-password"+ if err := EnableEncryptedNotebook(password); err != nil {+ t.Fatal(err)+ }+ normal := &Box{ID: "20261022000000-normal1"}+ boxConf := conf.NewBoxConf()+ boxConf.Name, boxConf.Closed = "Legacy title fixture", false+ if err := normal.SaveConf(boxConf); err != nil {+ t.Fatal(err)+ }+ plain := newHPathTestDoc(t, normal.ID, "/", "Legacy ordinary", 2)+ plainChild := newHPathTestDoc(t, normal.ID, plain.Path, "Literal / %2F **text** 😀", 2)+ encrypted, err := CreateEncryptedBox("Legacy encrypted fixture", password)+ if err != nil {+ t.Fatal(err)+ }+ if _, err = Mount(encrypted); err != nil {+ t.Fatal(err)+ }+ private := newHPathTestDoc(t, encrypted, "/", "Private legacy", 2)+ privateChild := newHPathTestDoc(t, encrypted, private.Path, "Private literal / %2F 😀", 2)+ sql.FlushQueue()+ drainHPathRefreshTest(t)+ type document struct {+ Notebook string `json:"notebook"`+ ID string `json:"id"`+ ParentID string `json:"parentID"`+ Path string `json:"path"`+ Title string `json:"title"`+ Encrypted bool `json:"encrypted"`+ }+ documents := []document{}+ for _, tree := range []*parse.Tree{plain, plainChild, private, privateChild} {+ parent := ""+ directory := filepath.ToSlash(filepath.Dir(tree.Path))+ if directory != "/" && directory != "." {+ parent = filepath.Base(directory)+ }+ documents = append(documents, document{tree.Box, tree.ID, parent, tree.Path,+ tree.Root.IALAttr("title"), tree.Box == encrypted})+ if strings.Contains(tree.Root.IALAttr("title"), "/") {+ t.Fatal("legacy title contains a slash")+ }+ if tree.Root.Spec != "2" {+ t.Fatalf("unexpected legacy specification: %s", tree.Root.Spec)+ }+ }+ LockBox(encrypted)+ if err = os.CopyFS(filepath.Join(destination, "data"), os.DirFS(util.DataDir)); err != nil {+ t.Fatal(err)+ }+ write := func(name string, value any) {+ t.Helper()+ data, err := json.MarshalIndent(value, "", " ")+ if err != nil {+ t.Fatal(err)+ }+ if err = os.WriteFile(filepath.Join(destination, name), data, 0600); err != nil {+ t.Fatal(err)+ }+ }+ write("notebook-crypto.json", currentNotebookCrypto())+ write("manifest.json", map[string]any{"tag": "v3.8.9-alpha.4", "commit": os.Getenv("SIYUAN_LEGACY_FIXTURE_COMMIT"),+ "password": password, "documents": documents})+}diff --git a/kernel/model/testdata/structured_titles_legacy/manifest.json b/kernel/model/testdata/structured_titles_legacy/manifest.jsonnew file mode 100644index 0000000000..9d90d98b3a--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/manifest.json@@ -0,0 +1,52 @@+{+ "commit": "335d16ddc182606864d1b5b89c07f411c8a78636",+ "documents": [+ {+ "notebook": "20261022000000-normal1",+ "id": "20261023180037-3dh65i9",+ "parentID": "",+ "path": "/20261023180037-3dh65i9.sy",+ "title": "Legacy ordinary",+ "encrypted": false+ },+ {+ "notebook": "20261022000000-normal1",+ "id": "20261023180037-h6el7k4",+ "parentID": "20261023180037-3dh65i9",+ "path": "/20261023180037-3dh65i9/20261023180037-h6el7k4.sy",+ "title": "Literal / %2F **text** 😀",+ "encrypted": false+ },+ {+ "notebook": "20261023180038-mbrj58v",+ "id": "20261023180038-pwkjtsl",+ "parentID": "",+ "path": "/20261023180038-pwkjtsl.sy",+ "title": "Private legacy",+ "encrypted": true+ },+ {+ "notebook": "20261023180038-mbrj58v",+ "id": "20261023180038-h60kzb9",+ "parentID": "20261023180038-pwkjtsl",+ "path": "/20261023180038-pwkjtsl/20261023180038-h60kzb9.sy",+ "title": "Private literal / %2F 😀",+ "encrypted": true+ }+ ],+ "password": "legacy-title-fixture-password",+ "tag": "v3.8.9-alpha.4",+ "sha256": {+ "data/.siyuan/data-crypto-backup.json": "bc432727370cb113c5fde04a8d9430db53ea563f621d0adac15fa07b0854b0e1",+ "data/.siyuan/indexignore": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",+ "data/.siyuan/syncignore": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",+ "data/20261022000000-normal1/.siyuan/conf.json": "560e724c45888a421b0f6bba0b792a1dbcf1d5ec99c26434499e23d7c161d602",+ "data/20261022000000-normal1/20261023180037-3dh65i9/20261023180037-h6el7k4.sy": "b76cc8888ab7d8587e71b9b74541a8f2ee5cd73ffc4d18cbc850bc1c8b6ce278",+ "data/20261022000000-normal1/20261023180037-3dh65i9.sy": "c163b651b5cbb8752c80b6bfb90764f58129bcd1012f21229f2b1d4e7368a32a",+ "data/20261023180038-mbrj58v/.siyuan/conf.json": "b4f8aafbc343ecb0a89d2667cfdc967b6abfeb77cba4472501a3b586765ad789",+ "data/20261023180038-mbrj58v/.siyuan/notebook-crypto-backup.json": "834bb8fe59b278855be053d565c015b078acbd023299336a7953bace48b72372",+ "data/20261023180038-mbrj58v/20261023180038-pwkjtsl/20261023180038-h60kzb9.sy": "c3af4ee3c72daf10b3805e01d8c02ed4c2ff6a69d6d7f6f691423f3fff75575e",+ "data/20261023180038-mbrj58v/20261023180038-pwkjtsl.sy": "4a12a2adfab616fdb6b96a02a2a443adea4d3a4dfc300dfe159c427020e9bab6",+ "notebook-crypto.json": "af6fa2299127fb35f56a766b73d26e4535279ac3add6ca6253c17364a5f0e24a"+ }+}diff --git a/kernel/model/testdata/structured_titles_legacy/notebook-crypto.json b/kernel/model/testdata/structured_titles_legacy/notebook-crypto.jsonnew file mode 100644index 0000000000..f5d6f0e838--- /dev/null+++ b/kernel/model/testdata/structured_titles_legacy/notebook-crypto.json@@ -0,0 +1,18 @@+{+ "enabled": true,+ "masterSalt": "uXX9rraT7D5YFPfmf0/VwQ==",+ "kdfParams": {+ "memory": 65536,+ "iterations": 3,+ "parallelism": 4,+ "keyLength": 32+ },+ "kekVerifier": "U0VOQwEBDEvO0X/4ITWkdwZauPA1vbXbcC8AX+9fmZ+RY5s99/LdBbZlraCB/OsR42mK+bgeVIeJtbuP",+ "verifierNonce": "S87Rf/ghNaR3Blq4",+ "autoLockMinutes": 5,+ "spec": 1,+ "backupID": "t0w9gz3mx4mtdez3",+ "createdAt": 1792749637,+ "checksum": "1e687935c05340c1d05de35e6ea7aa2cf6fb0825cd8287675c33d7c0cd86cc7c",+ "kekMAC": "urnke0rvW789UYgy1DUTjagCw29SVuGupuuEfQJbjaQ="+}\ No newline at end of file