diff --git a/desktop/internal/atomicfile/atomicfile.go b/desktop/internal/atomicfile/atomicfile.go new file mode 100644 index 0000000000..37d55ee2ab --- /dev/null +++ b/desktop/internal/atomicfile/atomicfile.go @@ -0,0 +1,136 @@ +// Package atomicfile installs immutable resources and writes owned files with +// one synced, same-directory atomic replacement policy. +package atomicfile + +import ( + "bytes" + "errors" + "fmt" + "io" + "os" + "path/filepath" +) + +// Install reuses unchanged regular files, including executables currently in use. +func Install(path string, data []byte, perm os.FileMode) error { + return InstallWithRename(path, data, perm, os.Rename) +} + +// InstallWithRename permits the caller to inject a competing installation in +// tests. A failed rename succeeds only if the destination has identical bytes. +func InstallWithRename(path string, data []byte, perm os.FileMode, rename func(string, string) error) error { + if err := validateTargetPath(path); err != nil { + return err + } + if rename == nil { + rename = os.Rename + } + if holds(path, data) { + return nil + } + return writeWithRename(path, perm, func(w io.Writer) error { + _, err := w.Write(data) + return err + }, rename, nil, func() bool { + return holds(path, data) + }) +} + +// Write atomically replaces a file with a complete byte buffer. +func Write(path string, data []byte, perm os.FileMode) error { + return WriteWith(path, perm, func(w io.Writer) error { + _, err := w.Write(data) + return err + }) +} + +// WriteWith streams to a private sibling and syncs it before publishing. It +// does not make a second complete copy of the buffer being written. +func WriteWith(path string, perm os.FileMode, write func(io.Writer) error) error { + return WriteWithCheck(path, perm, write, nil) +} + +// WriteWithCheck provides a last check immediately before rename, after the +// temporary file has been synced and closed. Runtime downloads use ctx.Err so +// cancellation after a slow fsync cannot publish an unwanted archive. +func WriteWithCheck(path string, perm os.FileMode, write func(io.Writer) error, beforeRename func() error) error { + return writeWithRename(path, perm, write, os.Rename, beforeRename, nil) +} + +func validateTargetPath(path string) error { + if path == "" { + return errors.New("atomicfile: empty path") + } + base := filepath.Base(path) + if base == "." || base == ".." || base == string(filepath.Separator) { + return fmt.Errorf("atomicfile: invalid target path %q", path) + } + return nil +} + +func writeWithRename(path string, perm os.FileMode, write func(io.Writer) error, rename func(string, string) error, beforeRename func() error, acceptOnRenameError func() bool) (err error) { + if err := validateTargetPath(path); err != nil { + return err + } + if write == nil { + return errors.New("atomicfile: nil writer callback") + } + if rename == nil { + rename = os.Rename + } + dir := filepath.Dir(path) + if err := os.MkdirAll(dir, 0o700); err != nil { + return fmt.Errorf("create directory: %w", err) + } + f, err := os.CreateTemp(dir, "."+filepath.Base(path)+".*") + if err != nil { + return fmt.Errorf("create temporary file: %w", err) + } + temp := f.Name() + closed := false + defer func() { + if !closed { + if closeErr := f.Close(); closeErr != nil { + err = errors.Join(err, fmt.Errorf("close temporary file: %w", closeErr)) + } + } + // log-exempt: 预期的缺失:成功改名已移走本次独占临时文件。 + if cleanup := os.Remove(temp); cleanup != nil && !errors.Is(cleanup, os.ErrNotExist) { + err = errors.Join(err, fmt.Errorf("remove temporary file: %w", cleanup)) + } + }() + if err := write(f); err != nil { + return fmt.Errorf("write temporary file: %w", err) + } + if err := f.Chmod(perm); err != nil { + return fmt.Errorf("set temporary file permissions: %w", err) + } + if err := f.Sync(); err != nil { + return fmt.Errorf("sync temporary file: %w", err) + } + closed = true + if err := f.Close(); err != nil { + return fmt.Errorf("close temporary file: %w", err) + } + if beforeRename != nil { + if err := beforeRename(); err != nil { + return fmt.Errorf("check before replace: %w", err) + } + } + if err := rename(temp, path); err != nil { + if acceptOnRenameError != nil && acceptOnRenameError() { + return nil + } + return fmt.Errorf("replace file: %w", err) + } + return nil +} + +func holds(path string, data []byte) bool { + info, err := os.Lstat(path) + if err != nil || !info.Mode().IsRegular() || info.Size() != int64(len(data)) { + return false + } + existing, err := os.ReadFile(path) + return err == nil && bytes.Equal(existing, data) +} diff --git a/desktop/internal/atomicfile/atomicfile_test.go b/desktop/internal/atomicfile/atomicfile_test.go new file mode 100644 index 0000000000..545a8f8746 --- /dev/null +++ b/desktop/internal/atomicfile/atomicfile_test.go @@ -0,0 +1,224 @@ +package atomicfile + +import ( + "errors" + "fmt" + "io" + "os" + "path/filepath" + "runtime" + "testing" +) + +func TestInstallKeepsSameBytesAndAtomicallyReplacesStaleOnes(t *testing.T) { + path := filepath.Join(t.TempDir(), "nested", "binary") + if err := Install(path, []byte("first"), 0o700); err != nil { + t.Fatal(err) + } + initial, err := os.Stat(path) + if err != nil { + t.Fatal(err) + } + if runtime.GOOS != "windows" && initial.Mode().Perm() != 0o700 { + t.Fatalf("mode = %v", initial.Mode()) + } + if err := Install(path, []byte("first"), 0o700); err != nil { + t.Fatal(err) + } + same, err := os.Stat(path) + if err != nil || !os.SameFile(initial, same) { + t.Fatalf("same bytes rewritten: %v", err) + } + if err := Install(path, []byte("second"), 0o600); err != nil { + t.Fatal(err) + } + changed, err := os.ReadFile(path) + if err != nil || string(changed) != "second" { + t.Fatalf("%q, %v", changed, err) + } + if runtime.GOOS != "windows" { + info, err := os.Stat(path) + if err != nil || info.Mode().Perm() != 0o600 { + t.Fatalf("mode = %v, %v", info.Mode(), err) + } + } + entries, err := os.ReadDir(filepath.Dir(path)) + if err != nil || len(entries) != 1 { + t.Fatalf("leftover temporary files: %v %v", entries, err) + } +} + +func TestInstallReplacesSymlinkRatherThanAcceptMatchingTarget(t *testing.T) { + dir := t.TempDir() + outside := filepath.Join(dir, "outside") + if err := os.WriteFile(outside, []byte("expected"), 0o600); err != nil { + t.Fatal(err) + } + link := filepath.Join(dir, "inside") + if err := os.Symlink(outside, link); err != nil { + t.Skipf("symlink unavailable: %v", err) + } + if err := Install(link, []byte("expected"), 0o600); err != nil { + t.Fatal(err) + } + info, err := os.Lstat(link) + if err != nil || !info.Mode().IsRegular() { + t.Fatalf("did not replace symlink: %v %v", info, err) + } +} + +func TestWriteFailureLeavesNoTemporaryFile(t *testing.T) { + dir := t.TempDir() + blocker := filepath.Join(dir, "blocker") + if err := os.WriteFile(blocker, nil, 0o600); err != nil { + t.Fatal(err) + } + if err := Write(filepath.Join(blocker, "child"), []byte("x"), 0o600); err == nil { + t.Fatal("write inside regular file succeeded") + } + entries, err := os.ReadDir(dir) + if err != nil || len(entries) != 1 { + t.Fatalf("unexpected files: %v %v", entries, err) + } +} + +func TestWriteWithFailureKeepsPreviousBytes(t *testing.T) { + path := filepath.Join(t.TempDir(), "settings.json") + if err := os.WriteFile(path, []byte("old"), 0o600); err != nil { + t.Fatal(err) + } + cause := errors.New("write interrupted") + err := WriteWith(path, 0o600, func(w io.Writer) error { + if _, err := w.Write([]byte("partial")); err != nil { + return err + } + return cause + }) + if !errors.Is(err, cause) { + t.Fatalf("write failed with %v, want %v", err, cause) + } + data, err := os.ReadFile(path) + if err != nil || string(data) != "old" { + t.Fatalf("previous content lost: %q, %v", data, err) + } + entries, err := os.ReadDir(filepath.Dir(path)) + if err != nil || len(entries) != 1 { + t.Fatalf("temporary files left behind: %v, %v", entries, err) + } +} + +func TestInstallOnlyAcceptsIdenticalConcurrentWriter(t *testing.T) { + for _, same := range []bool{true, false} { + t.Run(fmt.Sprint(same), func(t *testing.T) { + path := filepath.Join(t.TempDir(), "binary") + err := InstallWithRename(path, []byte("right"), 0o600, func(_, target string) error { + value := []byte("wrong") + if same { + value = []byte("right") + } + if err := os.WriteFile(target, value, 0o600); err != nil { + return err + } + return errors.New("rename denied by another client") + }) + if same && err != nil { + t.Fatalf("matching installation rejected: %v", err) + } + if !same && err == nil { + t.Fatal("mismatched installation accepted") + } + entries, err := os.ReadDir(filepath.Dir(path)) + if err != nil || len(entries) != 1 { + t.Fatalf("temporary file remains: %v, %v", entries, err) + } + }) + } +} + +func TestWriteWithCheckCancellationBeforeRenameKeepsOriginal(t *testing.T) { + path := filepath.Join(t.TempDir(), "archive") + if err := os.WriteFile(path, []byte("old archive"), 0o600); err != nil { + t.Fatal(err) + } + canceled := errors.New("canceled before commit") + err := WriteWithCheck(path, 0o600, func(w io.Writer) error { + _, err := w.Write([]byte("new archive")) + return err + }, func() error { return canceled }) + if !errors.Is(err, canceled) { + t.Fatalf("cancellation = %v, want %v", err, canceled) + } + data, err := os.ReadFile(path) + if err != nil || string(data) != "old archive" { + t.Fatalf("canceled write replaced original: %q, %v", data, err) + } + entries, err := os.ReadDir(filepath.Dir(path)) + if err != nil || len(entries) != 1 { + t.Fatalf("temporary file remained: %v, %v", entries, err) + } +} + +func TestInstallDoesNotSwallowNonRenameErrorsEvenWhenTargetMatches(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "binary") + wantErr := errors.New("disk write error") + err := writeWithRename(path, 0o600, func(w io.Writer) error { + if err := os.WriteFile(path, []byte("right"), 0o600); err != nil { + return err + } + return wantErr + }, os.Rename, nil, func() bool { + return holds(path, []byte("right")) + }) + if !errors.Is(err, wantErr) { + t.Fatalf("non-rename error swallowed or replaced: %v, want %v", err, wantErr) + } + entries, err := os.ReadDir(dir) + if err != nil || len(entries) != 1 { + t.Fatalf("temporary file remained: %v, %v", entries, err) + } +} + +func TestWriteAndInstallRejectInvalidPaths(t *testing.T) { + for _, invalid := range []string{"", ".", ".."} { + if err := Write(invalid, []byte("x"), 0o600); err == nil { + t.Fatalf("Write(%q) succeeded", invalid) + } + if err := Install(invalid, []byte("x"), 0o600); err == nil { + t.Fatalf("Install(%q) succeeded", invalid) + } + } + if err := WriteWith(filepath.Join(t.TempDir(), "file"), 0o600, nil); err == nil { + t.Fatal("WriteWith(nil) succeeded") + } +} + +func TestWriteWithStreamsToFileDirectly(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "streamed.bin") + err := WriteWith(path, 0o600, func(w io.Writer) error { + f, ok := w.(*os.File) + if !ok { + return fmt.Errorf("writer is %T, want *os.File", w) + } + if _, err := w.Write([]byte("chunk-1-")); err != nil { + return err + } + info, err := f.Stat() + if err != nil { + return err + } + if info.Size() != int64(len("chunk-1-")) { + return fmt.Errorf("size after first write = %d, want incremental write without buffering", info.Size()) + } + _, err = w.Write([]byte("chunk-2")) + return err + }) + if err != nil { + t.Fatal(err) + } + got, err := os.ReadFile(path) + if err != nil || string(got) != "chunk-1-chunk-2" { + t.Fatalf("streamed file = %q, %v", got, err) + } +} diff --git a/desktop/internal/draftstore/store.go b/desktop/internal/draftstore/store.go index eae9143b54..41c5918cbd 100644 --- a/desktop/internal/draftstore/store.go +++ b/desktop/internal/draftstore/store.go @@ -15,6 +15,7 @@ import ( "sync" "unicode/utf8" + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" "github.com/1lck/Lithe-IDEA/desktop/internal/core" ) @@ -179,31 +180,14 @@ func (s *Store) SaveSource(entry Entry, size int64, write func(io.Writer) error) if count >= s.limits.MaxDocuments || total+int64(len(header))+size > s.limits.MaxStorageBytes { return errors.New("recovery storage is full") } - temp, err := os.CreateTemp(s.dir, ".checkpoint-*") - if err != nil { - return err - } - temporary := temp.Name() - defer func() { - if cleanup := os.Remove(temporary); cleanup != nil && !errors.Is(cleanup, os.ErrNotExist) { - err = errors.Join(err, cleanup) + return atomicfile.WriteWith(filename, 0o600, func(w io.Writer) error { + if _, err := w.Write(header); err != nil { + return err } - }() - if _, err = temp.Write(header); err == nil { - err = write(temp) - } - if err == nil { - err = temp.Sync() - } - closeErr := temp.Close() - if err != nil { - return err - } - if closeErr != nil { - return closeErr - } - return os.Rename(temporary, filename) + return write(w) + }) } + func (s *Store) Remove(root, path string) error { recoveryIO.Lock() defer recoveryIO.Unlock() diff --git a/desktop/internal/draftstore/store_test.go b/desktop/internal/draftstore/store_test.go index 12c80dc9f9..028f919a90 100644 --- a/desktop/internal/draftstore/store_test.go +++ b/desktop/internal/draftstore/store_test.go @@ -1,8 +1,12 @@ package draftstore import ( - "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "errors" + "io" + "os" "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" ) func TestRecoveryStoreAtomicOverwriteAndQuotaPreservePriorContents(t *testing.T) { @@ -40,3 +44,30 @@ func TestRecoveryStoreAtomicOverwriteAndQuotaPreservePriorContents(t *testing.T) t.Fatal(err) } } + +func TestSaveSourceStreamingFailurePreservesPriorCheckpointAndLeavesNoTemp(t *testing.T) { + dir := t.TempDir() + limits := core.EditorRecoveryDecision{MaxDocumentBytes: 64, MaxStorageBytes: 4096, MaxDocuments: 2} + s := New(dir, limits) + if err := s.Save(Entry{Root: "workspace", Path: "a.txt", Text: "committed"}); err != nil { + t.Fatal(err) + } + streamErr := errors.New("stream aborted") + err := s.SaveSource(Entry{Root: "workspace", Path: "a.txt"}, 7, func(w io.Writer) error { + if _, err := w.Write([]byte("partial")); err != nil { + return err + } + return streamErr + }) + if !errors.Is(err, streamErr) { + t.Fatalf("SaveSource error = %v, want %v", err, streamErr) + } + got, found, err := s.Load("workspace", "a.txt") + if err != nil || !found || got.Text != "committed" { + t.Fatalf("checkpoint after failed SaveSource = %+v, %v, %v", got, found, err) + } + entries, err := os.ReadDir(s.dir) + if err != nil || len(entries) != 1 { + t.Fatalf("unexpected files in recovery dir: %v, %v", entries, err) + } +} diff --git a/desktop/internal/idehelp/idehelp.go b/desktop/internal/idehelp/idehelp.go index 856909d9b7..d0d479f748 100644 --- a/desktop/internal/idehelp/idehelp.go +++ b/desktop/internal/idehelp/idehelp.go @@ -9,11 +9,11 @@ package idehelp import ( - "crypto/sha256" "errors" "fmt" - "os" "path/filepath" + + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" ) // ErrNotBundled means this build has no embedded helper: development builds without the @@ -39,36 +39,7 @@ func Install(dir, name string) (string, error) { } bin := filepath.Join(dir, "bin") target := filepath.Join(bin, name) - want := sha256.Sum256(data) - if info, err := os.Stat(target); err == nil && info.Mode().IsRegular() { - if existing, err := os.ReadFile(target); err == nil && sha256.Sum256(existing) == want { - return target, nil - } - } - if err := os.MkdirAll(bin, 0o700); err != nil { - return "", fmt.Errorf("create the helper directory: %w", err) - } - temporary, err := os.CreateTemp(bin, "."+name+".*") - if err != nil { - return "", fmt.Errorf("create the helper file: %w", err) - } - temporaryPath := temporary.Name() - defer os.Remove(temporaryPath) // no-op once the rename succeeded - if _, err := temporary.Write(data); err != nil { - temporary.Close() - return "", fmt.Errorf("write the helper: %w", err) - } - if err := temporary.Sync(); err != nil { - temporary.Close() - return "", fmt.Errorf("sync the helper: %w", err) - } - if err := temporary.Close(); err != nil { - return "", fmt.Errorf("close the helper: %w", err) - } - if err := os.Chmod(temporaryPath, 0o700); err != nil { - return "", fmt.Errorf("make the helper executable: %w", err) - } - if err := os.Rename(temporaryPath, target); err != nil { + if err := atomicfile.Install(target, data, 0o700); err != nil { return "", fmt.Errorf("install the helper: %w", err) } return target, nil diff --git a/desktop/internal/idehelp/idehelp_test.go b/desktop/internal/idehelp/idehelp_test.go index 44460aba42..10c36df966 100644 --- a/desktop/internal/idehelp/idehelp_test.go +++ b/desktop/internal/idehelp/idehelp_test.go @@ -54,6 +54,10 @@ func TestInstallWritesTheHelperOnceAndReplacesAnotherVersion(t *testing.T) { if err != nil || string(data) != "second helper" { t.Fatalf("helper = %q, %v", data, err) } + entries, err := os.ReadDir(filepath.Dir(path)) + if err != nil || len(entries) != 1 { + t.Fatalf("temporary helper files left behind: %v, %v", entries, err) + } } func TestInstallRefusesABuildWithoutTheHelper(t *testing.T) { diff --git a/desktop/internal/localshell/conpty/conpty.go b/desktop/internal/localshell/conpty/conpty.go index 2586c39024..ebec45a87d 100644 --- a/desktop/internal/localshell/conpty/conpty.go +++ b/desktop/internal/localshell/conpty/conpty.go @@ -22,13 +22,14 @@ package conpty import ( - "bytes" "crypto/sha256" "encoding/hex" "errors" "fmt" "os" "path/filepath" + + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" ) // ErrUnavailable means this build carries no ConPTY: only the Windows builds for amd64 and @@ -89,53 +90,11 @@ func digest(files []file) string { return hex.EncodeToString(sum.Sum(nil)[:16]) } -// place makes path hold data, writing it through a temporary file in the same folder. +// place installs an immutable resource with the same atomic policy as other +// bundled helpers. Windows already-loaded DLLs can be reused when bytes match. func place(path string, data []byte) error { - if holds(path, data) { - return nil - } - dir := filepath.Dir(path) - if err := os.MkdirAll(dir, 0o700); err != nil { - return fmt.Errorf("conpty: create the folder: %w", err) - } - temporary, err := os.CreateTemp(dir, ".install-*") - if err != nil { - return fmt.Errorf("conpty: create %s: %w", filepath.Base(path), err) - } - temporaryPath := temporary.Name() - defer os.Remove(temporaryPath) // no-op once the rename succeeded - if _, err := temporary.Write(data); err != nil { - temporary.Close() - return fmt.Errorf("conpty: write %s: %w", filepath.Base(path), err) - } - if err := temporary.Sync(); err != nil { - temporary.Close() - return fmt.Errorf("conpty: sync %s: %w", filepath.Base(path), err) - } - if err := temporary.Close(); err != nil { - return fmt.Errorf("conpty: close %s: %w", filepath.Base(path), err) - } - if err := os.Chmod(temporaryPath, 0o700); err != nil { - return fmt.Errorf("conpty: make %s executable: %w", filepath.Base(path), err) - } - if err := os.Rename(temporaryPath, path); err != nil { - // Another client may have installed the same set meanwhile and loaded it; Windows - // refuses to replace a loaded DLL or a running console host, and the file then - // already holds these bytes. - if holds(path, data) { - return nil - } + if err := atomicfile.Install(path, data, 0o700); err != nil { return fmt.Errorf("conpty: install %s: %w", filepath.Base(path), err) } return nil } - -// holds reports whether path is a regular file with exactly data in it. -func holds(path string, data []byte) bool { - info, err := os.Stat(path) - if err != nil || !info.Mode().IsRegular() || info.Size() != int64(len(data)) { - return false - } - existing, err := os.ReadFile(path) - return err == nil && bytes.Equal(existing, data) -} diff --git a/desktop/internal/localshell/conpty/conpty_test.go b/desktop/internal/localshell/conpty/conpty_test.go index 043d0d135d..976776126f 100644 --- a/desktop/internal/localshell/conpty/conpty_test.go +++ b/desktop/internal/localshell/conpty/conpty_test.go @@ -159,7 +159,7 @@ func TestInstallPlacesTheSetInAFolderNamedByItsDigest(t *testing.T) { t.Fatal(err) } for _, entry := range entries { - if strings.HasPrefix(entry.Name(), ".install-") { + if strings.HasPrefix(entry.Name(), ".") { t.Errorf("a temporary file was left behind: %s", entry.Name()) } } diff --git a/desktop/internal/logwindow/export.go b/desktop/internal/logwindow/export.go index a24a1f49e2..5de8249641 100644 --- a/desktop/internal/logwindow/export.go +++ b/desktop/internal/logwindow/export.go @@ -29,6 +29,7 @@ import ( "strconv" "time" + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/logstore" "github.com/1lck/Lithe-IDEA/desktop/internal/store" @@ -587,21 +588,7 @@ func bundlePath(content, relative string) (string, error) { // writeAtomic replaces path with data: a reader sees the old file or the whole new one. func writeAtomic(path string, data []byte) error { - dir, name := filepath.Split(path) - file, err := os.CreateTemp(dir, "."+name+".*.tmp") - if err != nil { - return err - } - temp := file.Name() - defer os.Remove(temp) - if _, err := file.Write(data); err != nil { - file.Close() - return err - } - if err := file.Close(); err != nil { - return err - } - return os.Rename(temp, path) + return atomicfile.Write(path, data, 0o600) } // zipFolder packs folder into a zip archive at destination, with the folder itself at the diff --git a/desktop/internal/logwindow/export_test.go b/desktop/internal/logwindow/export_test.go index 2528a4c896..b0be5b596e 100644 --- a/desktop/internal/logwindow/export_test.go +++ b/desktop/internal/logwindow/export_test.go @@ -293,6 +293,15 @@ func TestExportStagesTheEvidenceAndPacksIt(t *testing.T) { if q := fx.source.queries; len(q) != 1 || q[0].Session != sessionCurrent { t.Fatalf("collected %+v, want the current session once", q) } + if stagedEntries, err := os.ReadDir(filepath.Join(e.root, exportFolder)); err != nil { + t.Fatalf("read staged folder: %v", err) + } else { + for _, entry := range stagedEntries { + if strings.HasPrefix(entry.Name(), ".") { + t.Fatalf("temporary staging file left behind: %s", entry.Name()) + } + } + } root := e.root destination := filepath.Join(fx.saves, "bundle.zip") diff --git a/desktop/internal/pluginhost/commands.go b/desktop/internal/pluginhost/commands.go index b91a3d4a6d..59ad8f2ead 100644 --- a/desktop/internal/pluginhost/commands.go +++ b/desktop/internal/pluginhost/commands.go @@ -13,6 +13,7 @@ import ( "sync" "time" + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" ) @@ -189,25 +190,7 @@ func (s *CommandStore) Record(pluginID string, installation CommandInstallation) if err := os.MkdirAll(directory, 0o755); err != nil { return err } - temporary, err := os.CreateTemp(directory, "."+commandRecordName+".*.tmp") - if err != nil { - return err - } - name := temporary.Name() - if _, err := temporary.Write(data); err != nil { - temporary.Close() - os.Remove(name) - return err - } - if err := temporary.Close(); err != nil { - os.Remove(name) - return err - } - if err := os.Rename(name, path); err != nil { - os.Remove(name) - return err - } - return nil + return atomicfile.Write(path, data, 0o600) } // Lookup is the command lookup of the plugin's systemCommand launches: base diff --git a/desktop/internal/pluginhost/commands_test.go b/desktop/internal/pluginhost/commands_test.go index 1d952ea88c..600caa7489 100644 --- a/desktop/internal/pluginhost/commands_test.go +++ b/desktop/internal/pluginhost/commands_test.go @@ -92,10 +92,16 @@ func TestCommandStoreRecordsAndReplacesInstallations(t *testing.T) { t.Fatal(err) } for _, entry := range entries { - if strings.HasSuffix(entry.Name(), ".tmp") { + if strings.HasPrefix(entry.Name(), ".") || strings.HasSuffix(entry.Name(), ".tmp") { t.Fatalf("temporary file %s was left behind", entry.Name()) } } + if runtime.GOOS != "windows" { + info, err := os.Stat(filepath.Join(state, commandTestPlugin, commandRecordName)) + if err != nil || info.Mode().Perm() != 0o600 { + t.Fatalf("record permissions = %v, %v", info, err) + } + } } func TestCommandStoreReadsAnUnusableRecordAsEmpty(t *testing.T) { diff --git a/desktop/internal/pluginruntime/runtime.go b/desktop/internal/pluginruntime/runtime.go index 5b36ac56a0..820f948e0e 100644 --- a/desktop/internal/pluginruntime/runtime.go +++ b/desktop/internal/pluginruntime/runtime.go @@ -16,6 +16,7 @@ import ( "path/filepath" "strings" + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" "github.com/1lck/Lithe-IDEA/desktop/internal/configfile" "github.com/1lck/Lithe-IDEA/desktop/internal/filelock" "github.com/1lck/Lithe-IDEA/desktop/internal/marketplace" @@ -351,7 +352,7 @@ func removeAbandoned(ctx context.Context, base string) error { if err := ctx.Err(); err != nil { return err } - if strings.HasPrefix(entry.Name(), ".staging-") || strings.HasPrefix(entry.Name(), ".archive-") { + if strings.HasPrefix(entry.Name(), ".staging-") || strings.HasPrefix(entry.Name(), ".archive.") || strings.HasPrefix(entry.Name(), ".archive-") { if err := os.RemoveAll(filepath.Join(base, entry.Name())); err != nil { return err } @@ -390,33 +391,12 @@ func (m *Manager) archive(ctx context.Context, artifact Artifact, base string, p return nil, err } defer func() { err = errors.Join(err, source.Close()) }() - temporary, err := os.CreateTemp(base, ".archive-") - if err != nil { - return nil, err - } - temporaryName := temporary.Name() - defer func() { - if temporary != nil { - err = errors.Join(err, temporary.Close()) - } - if cleanup := os.Remove(temporaryName); cleanup != nil && !errors.Is(cleanup, os.ErrNotExist) { - err = errors.Join(err, cleanup) + if err := atomicfile.WriteWithCheck(path, 0o600, func(w io.Writer) error { + if _, err := io.Copy(w, contextReader{ctx, source}); err != nil { + return err } - }() - if _, err := io.Copy(temporary, contextReader{ctx, source}); err != nil { - return nil, err - } - if err := temporary.Sync(); err != nil { - return nil, err - } - if err := temporary.Close(); err != nil { - return nil, err - } - temporary = nil - if err := ctx.Err(); err != nil { - return nil, err - } - if err := os.Rename(temporaryName, path); err != nil { + return ctx.Err() + }, ctx.Err); err != nil { return nil, err } return openVerified(ctx, path, artifact.SHA256) diff --git a/desktop/internal/pluginruntime/runtime_test.go b/desktop/internal/pluginruntime/runtime_test.go index ad5455d76c..f6b5a16e24 100644 --- a/desktop/internal/pluginruntime/runtime_test.go +++ b/desktop/internal/pluginruntime/runtime_test.go @@ -478,3 +478,25 @@ func TestCancelledTransferLeavesNoCompleteOrPartialGeneration(t *testing.T) { } } } + +func TestPrepareCleansAbandonedAtomicArchiveTemps(t *testing.T) { + body := tarArchive(t, member{name: "distribution/bin/worker", body: "working", mode: 0o755}) + artifact := selected(body, "tar.gz", "1") + manager, _ := testManager(t, map[string][]byte{artifact.URL: body}) + base := filepath.Join(manager.Root, artifact.CacheKey) + if err := os.MkdirAll(base, 0o700); err != nil { + t.Fatal(err) + } + abandoned := filepath.Join(base, ".archive.crashed-attempt") + if err := os.WriteFile(abandoned, []byte("partial"), 0o600); err != nil { + t.Fatal(err) + } + ctx := testContext(t) + installed, err := manager.Prepare(ctx, artifact, validateBody("working"), nil) + if err != nil || installed.Executable == "" { + t.Fatalf("prepare after crash = %+v, %v", installed, err) + } + if _, err := os.Stat(abandoned); !errors.Is(err, os.ErrNotExist) { + t.Fatalf("abandoned archive temp remained: %v", err) + } +} diff --git a/desktop/internal/pluginservice/pages.go b/desktop/internal/pluginservice/pages.go index be4e10860a..0e5cca43af 100644 --- a/desktop/internal/pluginservice/pages.go +++ b/desktop/internal/pluginservice/pages.go @@ -10,6 +10,7 @@ import ( "path/filepath" "time" + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" ) @@ -75,20 +76,5 @@ func (s *Service) SetPageState(pluginID, windowID, workspacePath string, state [ if len(state) > limit { return ErrPageStateTooLarge } - if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { - return err - } - temporary, err := os.CreateTemp(filepath.Dir(path), ".state-*") - if err != nil { - return err - } - defer os.Remove(temporary.Name()) - if _, err := temporary.Write(state); err != nil { - temporary.Close() - return err - } - if err := temporary.Close(); err != nil { - return err - } - return os.Rename(temporary.Name(), path) + return atomicfile.Write(path, state, 0o600) } diff --git a/desktop/internal/pluginservice/pages_test.go b/desktop/internal/pluginservice/pages_test.go index c543c17b94..0bb29359a4 100644 --- a/desktop/internal/pluginservice/pages_test.go +++ b/desktop/internal/pluginservice/pages_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "os" + "path/filepath" "strings" "testing" "time" @@ -83,6 +84,10 @@ func TestPageStateIsKeptPerWindowAndWorkspace(t *testing.T) { if state, err := service.PageState("a", "a.window", "/work/one", limit); err != nil || string(state) != `{"tab":1}` { t.Fatalf("state = %q %v", state, err) } + entries, err := os.ReadDir(filepath.Dir(service.pageStatePath("a", "a.window", "/work/one"))) + if err != nil || len(entries) != 1 { + t.Fatalf("page state dir entries = %v, %v", entries, err) + } for _, other := range [][2]string{{"a.window", "/work/two"}, {"a.other", "/work/one"}} { if state, _ := service.PageState("a", other[0], other[1], limit); state != nil { t.Fatalf("%v saw another window's state: %q", other, state) diff --git a/desktop/internal/projectgen/files.go b/desktop/internal/projectgen/files.go index 00ddd19b46..4eb6fd0465 100644 --- a/desktop/internal/projectgen/files.go +++ b/desktop/internal/projectgen/files.go @@ -6,6 +6,8 @@ import ( "os" "path/filepath" "strings" + + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" ) // errEscape reports a plan path that is not a plain relative path below the @@ -76,35 +78,11 @@ func writeFile(root, path, contents string, executable bool) error { } else if !errors.Is(err, os.ErrNotExist) { return err } - temporary, err := os.CreateTemp(directory, ".lithe-write-*") - if err != nil { - return err - } - name := temporary.Name() - cleanup := func() { _ = os.Remove(name) } - if _, err := temporary.WriteString(contents); err != nil { - _ = temporary.Close() - cleanup() - return err - } mode := os.FileMode(0o644) if executable { mode = 0o755 } - if err := temporary.Chmod(mode); err != nil { - _ = temporary.Close() - cleanup() - return err - } - if err := temporary.Close(); err != nil { - cleanup() - return err - } - if err := os.Rename(name, target); err != nil { - cleanup() - return err - } - return nil + return atomicfile.Write(target, []byte(contents), mode) } // collectDirectory moves the contents of the subdirectory a scaffolding tool diff --git a/desktop/internal/projectgen/run_test.go b/desktop/internal/projectgen/run_test.go index 6947c9e6bd..59a4fbd0ba 100644 --- a/desktop/internal/projectgen/run_test.go +++ b/desktop/internal/projectgen/run_test.go @@ -152,8 +152,10 @@ func TestRunWritesTemplateFilesAtomicallyAndOpensExistingFiles(t *testing.T) { if names := entries(t, parent); len(names) != 1 || names[0] != "demo" { t.Fatalf("the parent holds %v, want only the project (no staging directory)", names) } - if names := entries(t, result.Path); strings.Contains(strings.Join(names, ","), ".lithe-write") { - t.Fatalf("a temporary write file was left: %v", names) + for _, name := range entries(t, result.Path) { + if strings.HasPrefix(name, ".") { + t.Fatalf("a temporary write file was left: %v", entries(t, result.Path)) + } } if len(steps) != 1 || steps[0].Step != 1 || steps[0].Steps != 1 { t.Fatalf("step events = %+v", steps) diff --git a/desktop/internal/remoteserver/remoteserver.go b/desktop/internal/remoteserver/remoteserver.go index 479c9cbe0a..1fe7c5cd27 100644 --- a/desktop/internal/remoteserver/remoteserver.go +++ b/desktop/internal/remoteserver/remoteserver.go @@ -24,6 +24,8 @@ import ( "os" "path/filepath" "sync" + + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" ) // ManifestFile is the manifest's file name, in the stage of build-remote-server.sh and in this @@ -264,58 +266,10 @@ func validSHA256(value string) bool { return true } -// rename is os.Rename; a test replaces it to lose the race with another client. +// rename is os.Rename; tests replace it to emulate a competing installer. var rename = os.Rename -// holds reports whether target is a regular file, not a link, with exactly data. -func holds(target string, data []byte) bool { - info, err := os.Lstat(target) - if err != nil || !info.Mode().IsRegular() { - return false - } - existing, err := os.ReadFile(target) - return err == nil && bytes.Equal(existing, data) -} - -// installFile leaves data at target. An existing regular file with the same bytes is kept, so a -// connection does not rewrite it; anything else is replaced by renaming a synced private file over -// it. +// installFile reuses an existing immutable resource or replaces it atomically. func installFile(target string, data []byte) error { - if holds(target, data) { - return nil - } - dir := filepath.Dir(target) - if err := os.MkdirAll(dir, 0o700); err != nil { - return err - } - temporary, err := os.CreateTemp(dir, "."+BinaryName+".*") - if err != nil { - return err - } - temporaryPath := temporary.Name() - defer os.Remove(temporaryPath) // no-op once the rename succeeded - if _, err := temporary.Write(data); err != nil { - temporary.Close() - return err - } - if err := temporary.Sync(); err != nil { - temporary.Close() - return err - } - if err := temporary.Close(); err != nil { - return err - } - if err := os.Chmod(temporaryPath, 0o600); err != nil { - return err - } - if err := rename(temporaryPath, target); err != nil { - // Another client may have installed the same build meanwhile, and Windows refuses to - // replace a file that a process has open without sharing its deletion; the file then - // already holds these bytes. - if holds(target, data) { - return nil - } - return err - } - return nil + return atomicfile.InstallWithRename(target, data, 0o600, rename) } diff --git a/desktop/internal/store/store.go b/desktop/internal/store/store.go index 3fed1d833f..a052792c7f 100644 --- a/desktop/internal/store/store.go +++ b/desktop/internal/store/store.go @@ -23,6 +23,8 @@ import ( "sort" "sync" "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/atomicfile" ) // Directory is the name of the client's folder inside the user configuration directory. @@ -263,28 +265,11 @@ func (store *Store) Remove(name string) error { return nil } -// WriteFile replaces the file name with data atomically, as Save does for JSON. It keeps a -// file the client owns that is not JSON, such as the workbench background image. +// WriteFile replaces the file name with data atomically, as Save does for JSON. +// It keeps a file the client owns that is not JSON, such as a background image. func (store *Store) WriteFile(name string, data []byte) error { if err := os.MkdirAll(store.dir, 0o755); err != nil { return err } - file, err := os.CreateTemp(store.dir, "."+name+".*.tmp") - if err != nil { - return err - } - temporary := file.Name() - defer os.Remove(temporary) // no-op once the rename succeeded - if _, err := file.Write(data); err != nil { - file.Close() - return err - } - if err := file.Sync(); err != nil { - file.Close() - return err - } - if err := file.Close(); err != nil { - return err - } - return os.Rename(temporary, filepath.Join(store.dir, name)) + return atomicfile.Write(filepath.Join(store.dir, name), data, 0o600) } diff --git a/shared/platform-feature-matrix/features/diagnostics-export.json b/shared/platform-feature-matrix/features/diagnostics-export.json index d0e7048f06..3c27ad11ce 100644 --- a/shared/platform-feature-matrix/features/diagnostics-export.json +++ b/shared/platform-feature-matrix/features/diagnostics-export.json @@ -17,7 +17,10 @@ "desktop/internal/core/log_sites_test.go", "desktop/internal/pluginbackend/trace.go", "desktop/internal/workbench/operation.go", - "desktop/internal/logwindow/preferences_load_test.go" + "desktop/internal/logwindow/preferences_load_test.go", + "desktop/internal/logwindow/export_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go" ] }, "windows": { @@ -34,11 +37,14 @@ "desktop/internal/core/log_sites_test.go", "desktop/internal/pluginbackend/trace.go", "desktop/internal/workbench/operation.go", - "desktop/internal/logwindow/preferences_load_test.go" + "desktop/internal/logwindow/preferences_load_test.go", + "desktop/internal/logwindow/export_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go" ] }, "owner": "Diagnostics", - "verification": "双端记录 language/git/run/performance 事件,按模块、当前/上次会话、级别、UTC 时间与文本筛选;确认诊断 15 分钟到期、过载不阻塞调用线程、日志受限额控制、目录切换后收集实际位置、嵌套与转义凭据不落盘;确认预览后修改源文件不改变导出快照,取消/失败清理暂存,并检查 macOS v1 日志不进入时间线和导出、仅按 30 天过期清理与收集缺失计数。 验证自定义目录中无关的 lithe.*.log 不被收集或删除、刷新期间修改条件后按钮恢复、UTC 小数精度及等价时区边界正确、200 文件上限在模块/会话筛选后应用且遗漏明确标记。 macOS 从齿轮菜单或快捷键进入独立日志窗口,Windows 仍从设置→工具→日志与诊断进入,核对中英文名称、顺序、实际诊断范围、清理全模块会话范围、目录/清理后刷新、预览条件冻结,以及取消/失败后按钮和快照恢复;原生 macOS 明暗页面与实际 ZIP 链路、Windows 前端界面交互分别验证。 macOS v2 按 sessions 会话目录查询并冻结导出,检查 Core 目录字段校验、100 ms/256 条批量、保留容量、log.dropped/log.repeated、32 个句柄 LRU、三段轮转、超时控制与跟随广播;Windows 仍使用 v1。 PR2b 回归覆盖合法 c++ 插件编辑器资源不受日志身份约束、点号活动通道与 ~N 轮转文件互不覆盖、控制取消不丢已接纳批次与丢弃汇总、退出无条件关闭订阅和句柄、多行错误经 Core 规范化后严格校验,以及 LSP/Git/下载/freeze 失败分类和数值证据。 验证 Windows 保留设备名被拒绝、溢出通道可写头并轮转、client_secret/auth_token 等前缀凭据在编码和查询时均被脱敏,以及按 ts/level 字段筛选。 检查多通道总量超过 10 MiB 时所有活动段优先,删除或原子替换已打开的日志后新事件仍落盘;Update 事件保留 Application 分类,浏览器 c++ 与超长语言 ID 语法失败始终保留插件证据。 PR4 B2:macOS 导出使用 Core 范围规划和精确级别过滤,确认前冻结脱敏内容,附带可选环境与有界崩溃报告;macOS 设置已移除日志与诊断页,所有导出入口先打开独立日志窗口并在窗口中确认导出,通知保留原动作并提供目录事件引用跳转。运行 DiagnosticsExportV2Tests、DiagnosticsWorkflowTests、WorkbenchNotificationTests 和 probe-macos-logging-ui.sh,核对中英文 × 深浅色窗口及导出对话框。真实应用保存面板、访达、通知定位及崩溃后验收仍 pending;Windows 仍是 v1,未迁移。 PR4 视觉收尾:日志窗口按 HTML 原型使用独立明暗调色板、可换行工具栏、原生会话路径标题和当前快捷键徽标、212pt 分组通道栏、22pt 虚拟行、自绘选中状态、Core JSON 着色详情及调用链、24pt 状态栏和 560pt 导出对话框。logWindowMatchesMockup 使用真实 MacLogStore 与目录事件渲染 1340×786,中英文×明暗、调用链和单独导出截图由本地 probe 生成;截图实机比对与原生标题栏验收保持 pending。 PR4 收尾:macOS 独立日志窗口提供未开启时的详细诊断卡片及工具栏目录与清理菜单,确认当前实际目录只读呈现、选择后切换并保存、恢复默认仅在非默认目录可用、清理全会话后刷新占用;应用菜单导出在日志窗口中呈现。 修复验收:框选窗口时间后导出当前过滤结果,验证 Core 同时应用导出范围与窗口时间范围,含带时区和不重叠的空结果;原有范围、通道、级别和表达式保持交集。 日志窗口自适应回归:调整窗口宽度,确认事件/消息/字段使用空余宽度、窄窗口可横向滚动且自动列宽不写偏好;详情和调用链左上对齐、动作说明不盖状态栏。原生发送 ⌘F 后筛选框接收焦点,⌘点击两个通道能同时保留,全部通道清除限制;ⓘ 说明表达式交集、通道选择、时间和调用链偏移。时间分布刻度含秒,日历与时分秒草稿应用后包含结束秒,清除移除范围。实时追加只更新受影响行、跟随平滑滚动,暂停不重建已有单元格;真实应用连续突发的整帧流畅度仍需验收。 官方插件日志接入:三SDK协商litheLogging 1,lithe/log由Core校验后进入统一队列,真实SDK/Core验证INFO成功、ERROR失败、WARN降级恢复、op与耗时、不含请求正文;高频成功可单次抑制。上游明确type对应ERROR/WARN/INFO/DEBUG,未分类stderr为DEBUG,进程实际失败为ERROR。检查日志窗口按插件与级别筛选;macOS整机窗口与Windows v2验收仍pending。 执行轨迹:用户动作、Core 请求与 Git 命令按同一 op 串联;用户来源的成功或取消记 INFO,后台来源只在详细诊断下记 DEBUG,失败记 WARN 并由 Git 失败通知引用,宿主不再重复记 ERROR;Core 在入队前按宿主下发的 DEBUG 门过滤,队列事实由唤醒回调安排排空。运行 core_request_traces、CoreRequestTraceTests 和 UserActionTraceTests,在日志窗口按 op 查看调用链;整机操作验收仍pending。 声明式插件代记:没有插件进程的语言服务器、调试适配器和构建命令来源,由实际执行方按 Core 贡献映射表写同一组 plugins.operation.finished/failed 到 plugins//host。调试与构建由 macOS 宿主记录,语言服务器启动通过 startupOperation 交给 Core 记录。失败只取 host.* 阶段码,取消、停止、过期结果和由插件后端提供的构建计划都不记录。运行 plugin_operations、engine 声明式启动、BuildSystemService、DebugModule、PluginDebugAdapter、PluginLanguageServerLaunchResolver 与 MacBuildProviderSessions 回归。用测试内联的合成插件在真实应用中检查日志窗口插件通道的验收仍为 pending。 日志窗口保存偏好损坏或字段形状升级的场景:`TestLogPreferencesReadFailuresAreReported` 断言仅产生一条 background operation_failed(logs_preferences_load),运行时使用可读字段及默认值,打开窗口不会覆盖磁盘原文件;持久化层原有 SaveWithBackup 行为保留。", + "verification": "双端记录 language/git/run/performance 事件,按模块、当前/上次会话、级别、UTC 时间与文本筛选;确认诊断 15 分钟到期、过载不阻塞调用线程、日志受限额控制、目录切换后收集实际位置、嵌套与转义凭据不落盘;确认预览后修改源文件不改变导出快照,取消/失败清理暂存,并检查 macOS v1 日志不进入时间线和导出、仅按 30 天过期清理与收集缺失计数。 验证自定义目录中无关的 lithe.*.log 不被收集或删除、刷新期间修改条件后按钮恢复、UTC 小数精度及等价时区边界正确、200 文件上限在模块/会话筛选后应用且遗漏明确标记。 macOS 从齿轮菜单或快捷键进入独立日志窗口,Windows 仍从设置→工具→日志与诊断进入,核对中英文名称、顺序、实际诊断范围、清理全模块会话范围、目录/清理后刷新、预览条件冻结,以及取消/失败后按钮和快照恢复;原生 macOS 明暗页面与实际 ZIP 链路、Windows 前端界面交互分别验证。 macOS v2 按 sessions 会话目录查询并冻结导出,检查 Core 目录字段校验、100 ms/256 条批量、保留容量、log.dropped/log.repeated、32 个句柄 LRU、三段轮转、超时控制与跟随广播;Windows 仍使用 v1。 PR2b 回归覆盖合法 c++ 插件编辑器资源不受日志身份约束、点号活动通道与 ~N 轮转文件互不覆盖、控制取消不丢已接纳批次与丢弃汇总、退出无条件关闭订阅和句柄、多行错误经 Core 规范化后严格校验,以及 LSP/Git/下载/freeze 失败分类和数值证据。 验证 Windows 保留设备名被拒绝、溢出通道可写头并轮转、client_secret/auth_token 等前缀凭据在编码和查询时均被脱敏,以及按 ts/level 字段筛选。 检查多通道总量超过 10 MiB 时所有活动段优先,删除或原子替换已打开的日志后新事件仍落盘;Update 事件保留 Application 分类,浏览器 c++ 与超长语言 ID 语法失败始终保留插件证据。 PR4 B2:macOS 导出使用 Core 范围规划和精确级别过滤,确认前冻结脱敏内容,附带可选环境与有界崩溃报告;macOS 设置已移除日志与诊断页,所有导出入口先打开独立日志窗口并在窗口中确认导出,通知保留原动作并提供目录事件引用跳转。运行 DiagnosticsExportV2Tests、DiagnosticsWorkflowTests、WorkbenchNotificationTests 和 probe-macos-logging-ui.sh,核对中英文 × 深浅色窗口及导出对话框。真实应用保存面板、访达、通知定位及崩溃后验收仍 pending;Windows 仍是 v1,未迁移。 PR4 视觉收尾:日志窗口按 HTML 原型使用独立明暗调色板、可换行工具栏、原生会话路径标题和当前快捷键徽标、212pt 分组通道栏、22pt 虚拟行、自绘选中状态、Core JSON 着色详情及调用链、24pt 状态栏和 560pt 导出对话框。logWindowMatchesMockup 使用真实 MacLogStore 与目录事件渲染 1340×786,中英文×明暗、调用链和单独导出截图由本地 probe 生成;截图实机比对与原生标题栏验收保持 pending。 PR4 收尾:macOS 独立日志窗口提供未开启时的详细诊断卡片及工具栏目录与清理菜单,确认当前实际目录只读呈现、选择后切换并保存、恢复默认仅在非默认目录可用、清理全会话后刷新占用;应用菜单导出在日志窗口中呈现。 修复验收:框选窗口时间后导出当前过滤结果,验证 Core 同时应用导出范围与窗口时间范围,含带时区和不重叠的空结果;原有范围、通道、级别和表达式保持交集。 日志窗口自适应回归:调整窗口宽度,确认事件/消息/字段使用空余宽度、窄窗口可横向滚动且自动列宽不写偏好;详情和调用链左上对齐、动作说明不盖状态栏。原生发送 ⌘F 后筛选框接收焦点,⌘点击两个通道能同时保留,全部通道清除限制;ⓘ 说明表达式交集、通道选择、时间和调用链偏移。时间分布刻度含秒,日历与时分秒草稿应用后包含结束秒,清除移除范围。实时追加只更新受影响行、跟随平滑滚动,暂停不重建已有单元格;真实应用连续突发的整帧流畅度仍需验收。 官方插件日志接入:三SDK协商litheLogging 1,lithe/log由Core校验后进入统一队列,真实SDK/Core验证INFO成功、ERROR失败、WARN降级恢复、op与耗时、不含请求正文;高频成功可单次抑制。上游明确type对应ERROR/WARN/INFO/DEBUG,未分类stderr为DEBUG,进程实际失败为ERROR。检查日志窗口按插件与级别筛选;macOS整机窗口与Windows v2验收仍pending。 执行轨迹:用户动作、Core 请求与 Git 命令按同一 op 串联;用户来源的成功或取消记 INFO,后台来源只在详细诊断下记 DEBUG,失败记 WARN 并由 Git 失败通知引用,宿主不再重复记 ERROR;Core 在入队前按宿主下发的 DEBUG 门过滤,队列事实由唤醒回调安排排空。运行 core_request_traces、CoreRequestTraceTests 和 UserActionTraceTests,在日志窗口按 op 查看调用链;整机操作验收仍pending。 声明式插件代记:没有插件进程的语言服务器、调试适配器和构建命令来源,由实际执行方按 Core 贡献映射表写同一组 plugins.operation.finished/failed 到 plugins//host。调试与构建由 macOS 宿主记录,语言服务器启动通过 startupOperation 交给 Core 记录。失败只取 host.* 阶段码,取消、停止、过期结果和由插件后端提供的构建计划都不记录。运行 plugin_operations、engine 声明式启动、BuildSystemService、DebugModule、PluginDebugAdapter、PluginLanguageServerLaunchResolver 与 MacBuildProviderSessions 回归。用测试内联的合成插件在真实应用中检查日志窗口插件通道的验收仍为 pending。 日志窗口保存偏好损坏或字段形状升级的场景:`TestLogPreferencesReadFailuresAreReported` 断言仅产生一条 background operation_failed(logs_preferences_load),运行时使用可读字段及默认值,打开窗口不会覆盖磁盘原文件;持久化层原有 SaveWithBackup 行为保留。 #2257:本机 Go 1.27 + 固定 Core 9ab2336 运行 ./scripts/desktop/desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/logwindow(含 export_test.go 暂存打包与无临时文件残留检查)通过;Apple M4 APFS 基准实测加入 F_FULLFSYNC 后单 10 MiB 文件 1.53ms→9.95ms、10×1 MiB 2.04ms→63.42ms、200×50 KiB 上限 26.77ms→1.13s(在后台 goroutine 执行,每文件前检查取消),Windows 原生验收仍 pending。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -95,5 +101,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:日志窗口导出(logwindow/export.go)使用暂存目录,logstore.ExportQuery 支持按会话、级别、时间与表达式筛选,store.go 负责保留预算。#1927 起:写入器在 Core 记录事实时经唤醒回调(core/log_waker.go)合并排空,不再空闲轮询;详细诊断由一次性定时器 15 分钟到期,同时切换 Core 的 DEBUG 门和语言服务器的 lsp.setDetailedDiagnostics;被 Core 拒绝的事件按事件 ID 和错误码显示在日志窗口状态栏与 collection-status.txt,整批编码失败计入 log.dropped。用户动作分配 op,经 origin 带进 Core 请求(core/origin.go、workbench/operation.go),失败提示的“查看日志”按 op 过滤日志窗口。插件后端的引擎日志事实转发进会话日志(pluginbackend/trace.go);调试适配器启动和构建命令来源由宿主经 diagnostics.recordPluginOperation 代记(core/plugin_operation.go);插件 ${logDir} 改为会话内的插件文件目录。core/log_sites_test.go 把每个生产日志调用交给链接的内核按目录校验。未确认过载不阻塞和凭据脱敏的专门实现;macOS 整机窗口与 Windows 实机验收仍 pending。 #1990:logwindow.NewModel 在 Load 返回完整错误或 Store.Unread 标记了字段形状冲突时记录稳定后台警告,不把静默回退误当作未保存。" + "notes": "Viva:日志窗口导出(logwindow/export.go)使用暂存目录,logstore.ExportQuery 支持按会话、级别、时间与表达式筛选,store.go 负责保留预算。#1927 起:写入器在 Core 记录事实时经唤醒回调(core/log_waker.go)合并排空,不再空闲轮询;详细诊断由一次性定时器 15 分钟到期,同时切换 Core 的 DEBUG 门和语言服务器的 lsp.setDetailedDiagnostics;被 Core 拒绝的事件按事件 ID 和错误码显示在日志窗口状态栏与 collection-status.txt,整批编码失败计入 log.dropped。用户动作分配 op,经 origin 带进 Core 请求(core/origin.go、workbench/operation.go),失败提示的“查看日志”按 op 过滤日志窗口。插件后端的引擎日志事实转发进会话日志(pluginbackend/trace.go);调试适配器启动和构建命令来源由宿主经 diagnostics.recordPluginOperation 代记(core/plugin_operation.go);插件 ${logDir} 改为会话内的插件文件目录。core/log_sites_test.go 把每个生产日志调用交给链接的内核按目录校验。未确认过载不阻塞和凭据脱敏的专门实现;macOS 整机窗口与 Windows 实机验收仍 pending。 #1990:logwindow.NewModel 在 Load 返回完整错误或 Store.Unread 标记了字段形状冲突时记录稳定后台警告,不把静默回退误当作未保存。 #2257:logwindow/export.go 的 writeAtomic 改用共享 atomicfile.Write(0600 权限与 fsync)。" } diff --git a/shared/platform-feature-matrix/features/editor-unsaved-recovery.json b/shared/platform-feature-matrix/features/editor-unsaved-recovery.json index 0110761059..98580b24bc 100644 --- a/shared/platform-feature-matrix/features/editor-unsaved-recovery.json +++ b/shared/platform-feature-matrix/features/editor-unsaved-recovery.json @@ -4,14 +4,17 @@ "group": "文档编辑", "capability": "独立于自动保存的未保存内容恢复;磁盘改变或缺失时保留冲突并等待明确选择", "owner": "Editor / Core", - "notes": "Viva 共享实现;匹配、顺序和恢复决策在外部 Rust Core。macOS 无头流程与截图已覆盖;macOS 原生窗口和 Windows 原生验收未执行。", - "verification": "编辑后持久化检查点,重新打开项目自动恢复;初次文件监听和手动/自动保存均不能绕过恢复冲突;明确保留编辑器后保存并清理副本。 自动化:editor_essentials_test.go 与 editor_essentials_visual_test.go。", + "notes": "Viva 共享实现;匹配、顺序和恢复决策在外部 Rust Core。macOS 无头流程与截图已覆盖;macOS 原生窗口和 Windows 原生验收未执行。 #2257:draftstore.SaveSource 改用共享 atomicfile.WriteWith 流式写入(0600 权限与 fsync,不额外缓存完整副本)。", + "verification": "编辑后持久化检查点,重新打开项目自动恢复;初次文件监听和手动/自动保存均不能绕过恢复冲突;明确保留编辑器后保存并清理副本。 自动化:editor_essentials_test.go、editor_essentials_visual_test.go 与 draftstore/store_test.go(含流式写入失败保留原检查点与无临时文件残留)。", "macos": { "implementationStatus": "implemented", "verificationStatus": "pending", "evidence": [ "desktop/internal/workbench/editor_recovery.go", "desktop/internal/draftstore/store.go", + "desktop/internal/draftstore/store_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/workbench/editor_essentials_test.go", "desktop/internal/workbench/editor_essentials_visual_test.go" ] @@ -22,6 +25,9 @@ "evidence": [ "desktop/internal/workbench/editor_recovery.go", "desktop/internal/draftstore/store.go", + "desktop/internal/draftstore/store_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/workbench/editor_essentials_test.go", "desktop/internal/workbench/editor_essentials_visual_test.go" ] diff --git a/shared/platform-feature-matrix/features/ide-mcp-connection.json b/shared/platform-feature-matrix/features/ide-mcp-connection.json index 99b87216fe..98de10532b 100644 --- a/shared/platform-feature-matrix/features/ide-mcp-connection.json +++ b/shared/platform-feature-matrix/features/ide-mcp-connection.json @@ -18,7 +18,10 @@ "desktop/internal/workbench/ide_api_operation_test.go", "desktop/internal/workbench/ide_api_dispatch_test.go", "scripts/desktop/package-desktop.sh", - "scripts/desktop/package-desktop.test.mjs" + "scripts/desktop/package-desktop.test.mjs", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", + "desktop/internal/idehelp/idehelp.go" ] }, "windows": { @@ -36,12 +39,15 @@ "desktop/internal/workbench/ide_api_operation_test.go", "desktop/internal/workbench/ide_api_dispatch_test.go", "scripts/desktop/package-desktop.sh", - "scripts/desktop/package-desktop.test.mjs" + "scripts/desktop/package-desktop.test.mjs", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", + "desktop/internal/idehelp/idehelp.go" ] }, "owner": "Agent", - "notes": "Viva:设置 › AI › IDE 连接按项目开启/关闭连接,分别授权配置与执行(默认关,连接期间不可改),复制 stdio 客户端配置;授权按项目保存在本地偏好,连接目录在应用数据的 ide-host 下,关闭项目撤销连接。broker 循环实现 open/poll/claim/validate/respond/close,open 时用 toolExposure 只发布已实现的工具,validate 用同一列表;工具分发已接入 11 个工具:project_inspect、build inspect/reload/configure/execute、operations list/output/stop、run list/start/restart;environment 与 maven 专属工具按契约不由本客户端提供、不发布(工具链与构建工具由插件经通用 Build 入口暴露)。失败码只用契约列出的共享码与应用码。lithe-mcp 辅助程序已随包嵌入并在应用数据目录安装;打包时它按 desktop-go.sh 的目标映射构建,与安装包同一目标(Windows 为 x86_64-pc-windows-gnu,arm64 主机上打的 amd64 macOS 包为 x86_64-apple-darwin),不取 rustc 主机默认目标。", - "verification": "Viva 本地验证(2026-11-12):bash scripts/desktop/desktop-go.sh test ./internal/workbench/ -run TestIDE;node --test scripts/desktop/package-desktop.test.mjs 验证 Windows 打包在 rustc 默认 MSVC 时暂存并嵌入 GNU 目标的 Core 与 lithe-mcp、arm64 主机打 amd64 macOS 包嵌入 x86_64 辅助程序、make core 在 Windows 暂存 GNU 目标(修复前三项均失败);变异检查(不判旧 ID 失效、读输出不传游标、停止不结束准备、不用 Core 读回值、启动不预留构建窗口)各让对应测试失败。原生实机待验证。旧客户端基线:检查设置侧栏 MCP 配置入口与搜索跳转;未打开项目时资源库照常列出全局服务器,Lithe IDE 访问段显示打开项目提示;切换项目后展示对应授权。双端打包启动后开启连接,配置真实 Agent,验证工具发现、默认拒绝写入、启用权限、禁用、项目关闭和多窗口隔离。macOS 打开 MCP 配置页确认状态徽标与状态卡文案跟随启用状态变化,header ⓘ 可打开完整安全说明,配置代码块只在存在配置时出现且可选中复制;启用后确认项目级 lithe 条目写入两个 Agent 的配置,禁用后条目清理,外部修改过的条目保留并提示。运行前后对比安装目录文件清单与哈希;当前 Linux 仅执行共享协议及前端验证,原生运行待验证。 Windows 验证开启请求通过真实 Host 解码、客户端不能覆盖窗口所有者、关闭其他窗口保留连接及所属窗口关闭删除连接文件。 验证旧版、新版直接发现与初始化后新版发现三个独立 stdio 会话;Windows 验证原生通知、过期领取拒绝、失败后新请求恢复、最小化与休眠恢复、系统时钟回拨、丢失通知后交付新请求、打开失败和关闭后监听释放、中英文错误提示及无重复执行。 Windows 暴露 lithe_build_configure,经过既有 configure 权限,复用 UI 的同一原生本机偏好保存与读回;false、空数组和 null 重置不混淆,旧版本/并发保存和工作区关闭不覆盖新状态;活动构建返回 BUSY。验证共享工具清单、真实 stdio 发现与授权拒绝,旧 Maven 消费者尚未删除。", + "notes": "Viva:设置 › AI › IDE 连接按项目开启/关闭连接,分别授权配置与执行(默认关,连接期间不可改),复制 stdio 客户端配置;授权按项目保存在本地偏好,连接目录在应用数据的 ide-host 下,关闭项目撤销连接。broker 循环实现 open/poll/claim/validate/respond/close,open 时用 toolExposure 只发布已实现的工具,validate 用同一列表;工具分发已接入 11 个工具:project_inspect、build inspect/reload/configure/execute、operations list/output/stop、run list/start/restart;environment 与 maven 专属工具按契约不由本客户端提供、不发布(工具链与构建工具由插件经通用 Build 入口暴露)。失败码只用契约列出的共享码与应用码。lithe-mcp 辅助程序已随包嵌入并在应用数据目录安装;打包时它按 desktop-go.sh 的目标映射构建,与安装包同一目标(Windows 为 x86_64-pc-windows-gnu,arm64 主机上打的 amd64 macOS 包为 x86_64-apple-darwin),不取 rustc 主机默认目标。 #2257:嵌入式 IDE helper 安装改用共享 atomicfile.Install(Lstat 校验常规文件字节复用、同目录私有临时文件 chmod/fsync、原子改名替换与 Windows 同字节并发改名容错),未变更可见入口。", + "verification": "Viva 本地验证(2026-11-12):bash scripts/desktop/desktop-go.sh test ./internal/workbench/ -run TestIDE;node --test scripts/desktop/package-desktop.test.mjs 验证 Windows 打包在 rustc 默认 MSVC 时暂存并嵌入 GNU 目标的 Core 与 lithe-mcp、arm64 主机打 amd64 macOS 包嵌入 x86_64 辅助程序、make core 在 Windows 暂存 GNU 目标(修复前三项均失败);变异检查(不判旧 ID 失效、读输出不传游标、停止不结束准备、不用 Core 读回值、启动不预留构建窗口)各让对应测试失败。原生实机待验证。旧客户端基线:检查设置侧栏 MCP 配置入口与搜索跳转;未打开项目时资源库照常列出全局服务器,Lithe IDE 访问段显示打开项目提示;切换项目后展示对应授权。双端打包启动后开启连接,配置真实 Agent,验证工具发现、默认拒绝写入、启用权限、禁用、项目关闭和多窗口隔离。macOS 打开 MCP 配置页确认状态徽标与状态卡文案跟随启用状态变化,header ⓘ 可打开完整安全说明,配置代码块只在存在配置时出现且可选中复制;启用后确认项目级 lithe 条目写入两个 Agent 的配置,禁用后条目清理,外部修改过的条目保留并提示。运行前后对比安装目录文件清单与哈希;当前 Linux 仅执行共享协议及前端验证,原生运行待验证。 Windows 验证开启请求通过真实 Host 解码、客户端不能覆盖窗口所有者、关闭其他窗口保留连接及所属窗口关闭删除连接文件。 验证旧版、新版直接发现与初始化后新版发现三个独立 stdio 会话;Windows 验证原生通知、过期领取拒绝、失败后新请求恢复、最小化与休眠恢复、系统时钟回拨、丢失通知后交付新请求、打开失败和关闭后监听释放、中英文错误提示及无重复执行。 Windows 暴露 lithe_build_configure,经过既有 configure 权限,复用 UI 的同一原生本机偏好保存与读回;false、空数组和 null 重置不混淆,旧版本/并发保存和工作区关闭不覆盖新状态;活动构建返回 BUSY。验证共享工具清单、真实 stdio 发现与授权拒绝,旧 Maven 消费者尚未删除。 #2257:本机 Go 1.27 + 固定 Core 9ab2336 运行 ./scripts/desktop/desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/idehelp(含等价字节复用、符号链接替换、失败清理、非 rename 错误不吞没、流式写入及前检取消与 installedpackagetest)通过;Windows 原生安装与占位竞争仍待 CI/Windows 实机验收。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/plugin-command-installers.json b/shared/platform-feature-matrix/features/plugin-command-installers.json index 217e7767e5..9196b21505 100644 --- a/shared/platform-feature-matrix/features/plugin-command-installers.json +++ b/shared/platform-feature-matrix/features/plugin-command-installers.json @@ -11,6 +11,8 @@ "desktop/internal/core/command_installers_test.go", "desktop/internal/pluginhost/commands.go", "desktop/internal/pluginhost/commands_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/pluginhost/launch.go", "desktop/internal/workbench/command_installers.go", "desktop/internal/workbench/command_installers_test.go", @@ -28,6 +30,9 @@ "evidence": [ "desktop/internal/core/command_installers.go", "desktop/internal/pluginhost/commands.go", + "desktop/internal/pluginhost/commands_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/pluginhost/launch.go", "desktop/internal/workbench/command_installers.go", "desktop/internal/workbench/command_installers_test.go", @@ -39,6 +44,6 @@ ] }, "owner": "Plugins", - "verification": "宿主测试只用合成插件 dev.lithe.test.command-installers(安装工具是复制出来的测试二进制,不联网):缺失检测按语言服务器、调试适配器和后端分别报告;安装计划展开两个目标,打开对话框不创建目录;managed 目标装进插件根目录 .state 下的受管目录并记录,之后 Backend.ResolveCommand 找到命令;toolDefault 目标按工具默认位置探测并记录该目录;非零退出、命令没写出来、超过超时各报对应原因;取消会停止工具且不留记录;插件没有声明的目标被拒绝。下载安装器用合成插件 dev.lithe.test.command-downloads 和假的 HTTP 传输(不联网):打开对话框不发请求、不建目录;下载解压后记录并能找到命令,旧缓存键被删除,再次安装不再下载;校验值不符、下载失败、命令不在压缩包里、条目逃出解压根各报对应原因且不留记录;取消不写失败日志;超时停止。设置窗口测试覆盖卡片状态、横幅、对话框内容(含下载地址、镜像、SHA-256 和下载进度)、安装输出、完成后卡片清除和取消。可视化证据:-tags 'vivahead lithevisual' 运行 TestVisualCommandInstall 生成深浅主题的卡片、对话框、下载对话框和下载进度截图。macOS 真机:安装一个声明 commandInstallers 的插件,在缺少命令的机器上打开设置 → 插件 → 已安装 → 功能,确认卡片显示“未找到”与安装按钮;分别选择两个安装位置完成安装,确认之后启动语言服务器或调试不再报命令缺失;安装一个声明下载安装器的测试插件(清单固定一个本机可下载的压缩包),确认对话框显示地址和 SHA-256、下载有进度、装好后启动能找到命令;安装中取消、断网失败都显示原因;启动后 app bundle 文件清单不变(scripts/desktop/verify/verify-runtime-bundle-immutability.sh)。Windows 真机:同样流程,命令文件带 .exe 后缀,PATH 类变量用分号分隔。 #2317:命令安装超时提示(desktop.plugins.commandInstallTimedOut)改为数量中性英文,由 desktop/internal/i18n 与 settingswindow/workbench -race -tags 'dev vivahead' 覆盖,原生端待验收。", - "notes": "对应计划 API-23(工具链与受管进程)。宿主声明 commandInstallers 1(1 增加下载安装器,Lithe-core-rust#133);契约与计划展开在 Core(plugins.commandInstallers.requirements/plan/defaultDirectory)。下载安装器复用受管运行时的下载、校验和解压(pluginruntime.Manager.Prepare),结果在插件状态目录 commands/<安装器>/<缓存键>/。受管目录随插件卸载删除;toolDefault 只记录目录,不删除工具装进默认位置的文件。安装进程不经 shell,参数与环境来自 Core 展开的计划。 #2317:将 desktop.plugins.commandInstallTimedOut 改为“Install timeout reached ({seconds}s). Stopped.”数量中性写法;中文不变。" + "verification": "宿主测试只用合成插件 dev.lithe.test.command-installers(安装工具是复制出来的测试二进制,不联网):缺失检测按语言服务器、调试适配器和后端分别报告;安装计划展开两个目标,打开对话框不创建目录;managed 目标装进插件根目录 .state 下的受管目录并记录,之后 Backend.ResolveCommand 找到命令;toolDefault 目标按工具默认位置探测并记录该目录;非零退出、命令没写出来、超过超时各报对应原因;取消会停止工具且不留记录;插件没有声明的目标被拒绝。下载安装器用合成插件 dev.lithe.test.command-downloads 和假的 HTTP 传输(不联网):打开对话框不发请求、不建目录;下载解压后记录并能找到命令,旧缓存键被删除,再次安装不再下载;校验值不符、下载失败、命令不在压缩包里、条目逃出解压根各报对应原因且不留记录;取消不写失败日志;超时停止。设置窗口测试覆盖卡片状态、横幅、对话框内容(含下载地址、镜像、SHA-256 和下载进度)、安装输出、完成后卡片清除和取消。可视化证据:-tags 'vivahead lithevisual' 运行 TestVisualCommandInstall 生成深浅主题的卡片、对话框、下载对话框和下载进度截图。 #2257:desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/pluginhost 覆盖 CommandStore.Record 的 0600 权限、fsync 与无临时文件残留。 #2317:命令安装超时提示(desktop.plugins.commandInstallTimedOut)改为数量中性英文,由 desktop/internal/i18n 与 settingswindow/workbench -race -tags 'dev vivahead' 覆盖,原生端待验收。macOS 真机:安装一个声明 commandInstallers 的插件,在缺少命令的机器上打开设置 → 插件 → 已安装 → 功能,确认卡片显示“未找到”与安装按钮;分别选择两个安装位置完成安装,确认之后启动语言服务器或调试不再报命令缺失;安装一个声明下载安装器的测试插件(清单固定一个本机可下载的压缩包),确认对话框显示地址和 SHA-256、下载有进度、装好后启动能找到命令;安装中取消、断网失败都显示原因;启动后 app bundle 文件清单不变(scripts/desktop/verify/verify-runtime-bundle-immutability.sh)。Windows 真机:同样流程,命令文件带 .exe 后缀,PATH 类变量用分号分隔。", + "notes": "对应计划 API-23(工具链与受管进程)。宿主声明 commandInstallers 1(1 增加下载安装器,Lithe-core-rust#133);契约与计划展开在 Core(plugins.commandInstallers.requirements/plan/defaultDirectory)。下载安装器复用受管运行时的下载、校验和解压(pluginruntime.Manager.Prepare),结果在插件状态目录 commands/<安装器>/<缓存键>/。受管目录随插件卸载删除;toolDefault 只记录目录,不删除工具装进默认位置的文件。安装进程不经 shell,参数与环境来自 Core 展开的计划。 #2257:CommandStore.Record 改用共享 atomicfile.Write 并补齐 fsync 与 0600 权限。 #2317:将 desktop.plugins.commandInstallTimedOut 改为“Install timeout reached ({seconds}s). Stopped.”数量中性写法;中文不变。" } diff --git a/shared/platform-feature-matrix/features/plugin-functions.json b/shared/platform-feature-matrix/features/plugin-functions.json index ea2f9c3bed..690d281534 100644 --- a/shared/platform-feature-matrix/features/plugin-functions.json +++ b/shared/platform-feature-matrix/features/plugin-functions.json @@ -13,6 +13,9 @@ "desktop/internal/pluginservice/pluginservice.go", "desktop/internal/pluginservice/activation.go", "desktop/internal/pluginservice/pages.go", + "desktop/internal/pluginservice/pages_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/pluginservice/hostview.go" ] }, @@ -26,12 +29,15 @@ "desktop/internal/pluginservice/pluginservice.go", "desktop/internal/pluginservice/activation.go", "desktop/internal/pluginservice/pages.go", + "desktop/internal/pluginservice/pages_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/pluginservice/hostview.go" ] }, "owner": "Extensions", - "verification": "macOS Core 桥接测试覆盖声明校验、启动计划、进程协商、函数结果、插件归属拒绝、取消及迟到结果隔离、停止销毁;需接通可信插件宿主后在 macOS 与 Windows 验收完整工作流和进程清理。", - "notes": "Viva:pluginFunctions 已声明;宿主按插件归属调用后端函数(插件视图事件、编辑器动作、设置页按钮、插件页面),调用带上下文以支持取消与超时,页面调用可接收进度;跨插件调用经 Core 的函数中转(lsp.configureFunctionRelay)。尚未用三个官方 SDK 的真实插件在 Viva 上验收。", + "verification": "macOS Core 桥接测试覆盖声明校验、启动计划、进程协商、函数结果、插件归属拒绝、取消及迟到结果隔离、停止销毁;#2257:desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/pluginservice 覆盖页面状态 0600 原子写入、fsync 与无临时文件残留;需接通可信插件宿主后在 macOS 与 Windows 验收完整工作流和进程清理。", + "notes": "Viva:pluginFunctions 已声明;宿主按插件归属调用后端函数(插件视图事件、编辑器动作、设置页按钮、插件页面),调用带上下文以支持取消与超时,页面调用可接收进度;跨插件调用经 Core 的函数中转(lsp.configureFunctionRelay)。尚未用三个官方 SDK 的真实插件在 Viva 上验收。 #2257:pluginservice.SetPageState 改用共享 atomicfile.Write 并补齐 fsync。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/plugin-managed-runtimes.json b/shared/platform-feature-matrix/features/plugin-managed-runtimes.json index f1322f2d79..d43b484f46 100644 --- a/shared/platform-feature-matrix/features/plugin-managed-runtimes.json +++ b/shared/platform-feature-matrix/features/plugin-managed-runtimes.json @@ -10,6 +10,8 @@ "desktop/internal/core/managed_runtimes.go", "desktop/internal/core/managed_runtimes_test.go", "desktop/internal/pluginruntime/", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/pluginservice/runtimes.go", "desktop/internal/pluginservice/runtimes_test.go", "desktop/internal/pluginservice/runtime_lifecycle.go", @@ -35,6 +37,8 @@ "evidence": [ "desktop/internal/core/managed_runtimes.go", "desktop/internal/pluginruntime/", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/filelock/lock_windows.go", "desktop/internal/pluginservice/runtimes.go", "desktop/internal/pluginservice/runtime_lifecycle.go", @@ -54,7 +58,7 @@ ] }, "owner": "Plugins", - "verification": "合成插件测试通过真实 Core 清单与回复校验,使用本地传输夹具验证外部安装零下载、仅下载缺失项、插件版本变化不重复下载、缓存破损从已校验归档恢复、哈希与解压路径拒绝、并发和取消、失败不改旧目录以及准备后端不参与函数转发;验证无后端探测即可汇总受管工具与未绑定依赖到工具链设置视图,并可在缺失时按需触发准备、就绪后触发校验修复。使用合成可执行文件验证当前与其他已打开项目的 PATH、全局符号链接和检查函数返回路径不会绕过工具信任;绑定工具保持 Core 验证的规范文件与目录身份,工作区关闭后释放根引用。运行 desktop-go.sh test ./internal/toolchain/ ./internal/pluginservice/ ./internal/settingswindow/ ./internal/workbench/ 覆盖绑定/未绑定受管依赖投影与准备按钮。macOS 与 Windows 真机仍保留 pending 状态以完成完整安装与原生流程验收。", - "notes": "通用能力 managedRuntimes 0/1 和权限 runtimes.install;清单、归档选择、缓存键及结果完整性由独立 Core 仓库定义,插件检查版本与目录是否合用。状态在 /.state//runtimes/,与插件版本分开;旧插件不进入新流程。安装与更新不再阻塞下载受管依赖,改为在工具链“插件自用运行时”页按需准备/修复或在语言服务器首次启动前自动准备。平台实现共用 Go/Viva 服务,Windows 使用本机文件锁和可执行文件验证,实机验证状态独立保留为 pending。", + "verification": "合成插件测试通过真实 Core 清单与回复校验,使用本地传输夹具验证外部安装零下载、仅下载缺失项、插件版本变化不重复下载、缓存破损从已校验归档恢复、哈希与解压路径拒绝、并发和取消、失败不改旧目录以及准备后端不参与函数转发;验证无后端探测即可汇总受管工具与未绑定依赖到工具链设置视图,并可在缺失时按需触发准备、就绪后触发校验修复。使用合成可执行文件验证当前与其他已打开项目的 PATH、全局符号链接和检查函数返回路径不会绕过工具信任;绑定工具保持 Core 验证的规范文件与目录身份,工作区关闭后释放根引用。运行 desktop-go.sh test ./internal/toolchain/ ./internal/pluginservice/ ./internal/settingswindow/ ./internal/workbench/ 覆盖绑定/未绑定受管依赖投影与准备按钮。 #2257:desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/pluginruntime 覆盖流式写入归档、sync/close 后及改名前 ctx.Err 取消检查与崩溃残留 .archive.* 清理。macOS 与 Windows 真机仍保留 pending 状态以完成完整安装与原生流程验收。", + "notes": "通用能力 managedRuntimes 0/1 和权限 runtimes.install;清单、归档选择、缓存键及结果完整性由独立 Core 仓库定义,插件检查版本与目录是否合用。状态在 /.state//runtimes/,与插件版本分开;旧插件不进入新流程。安装与更新不再阻塞下载受管依赖,改为在工具链“插件自用运行时”页按需准备/修复或在语言服务器首次启动前自动准备。平台实现共用 Go/Viva 服务,Windows 使用本机文件锁和可执行文件验证,实机验证状态独立保留为 pending。 #2257:pluginruntime.archive 改用 atomicfile.WriteWithCheck 流式写入(不额外缓存整包、保留 rename 前取消校验)并在 removeAbandoned 清理 .archive.* 残留。", "lastReviewed": "2026-11-19" } diff --git a/shared/platform-feature-matrix/features/plugin-project-generators.json b/shared/platform-feature-matrix/features/plugin-project-generators.json index cd0b806c33..64ec491434 100644 --- a/shared/platform-feature-matrix/features/plugin-project-generators.json +++ b/shared/platform-feature-matrix/features/plugin-project-generators.json @@ -14,7 +14,10 @@ "desktop/internal/workbench/new_project_advanced_test.go", "desktop/internal/workbench/visual_capture_test.go", "desktop/internal/projectgen/run.go", + "desktop/internal/projectgen/files.go", "desktop/internal/projectgen/run_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/core/project_generators.go", "desktop/internal/core/project_generators_test.go", "desktop/internal/pluginservice/generators.go" @@ -31,15 +34,18 @@ "desktop/internal/workbench/new_project_advanced_test.go", "desktop/internal/workbench/visual_capture_test.go", "desktop/internal/projectgen/run.go", + "desktop/internal/projectgen/files.go", "desktop/internal/projectgen/run_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/core/project_generators.go", "desktop/internal/core/project_generators_test.go", "desktop/internal/pluginservice/generators.go" ] }, "owner": "Plugin Platform", - "verification": "macOS:安装测试内联的合成生成器插件(声明文件、命令、归档三类步骤),从欢迎页和项目切换器点“新建项目”,确认左栏有“新建项目”(含宿主提供的空项目)和“生成器”两组且可搜索。用文件步骤创建,确认生成声明的文件、项目打开后 openFiles 指定的文件已打开。勾选“创建 Git 仓库”时项目根目录有 .git。归档步骤从本机回环 HTTP 服务下载并解压、可执行位保留;把归档地址改成不可达地址时报错且目标目录下没有残留的 .*.lithe-creating-* 临时目录。命令步骤在 PATH 中找不到可执行文件时提示找不到命令。停用该插件后条目变灰、创建按钮不可用,只出现一条启用提示,点击后条目恢复可用;所需插件未安装时出现“在插件市场中查找”。目标目录已存在时拒绝创建且不改动原目录。生成器字段声明了 description 时,选中该生成器后表单正常显示,每个带说明的字段旁各有一个 ⓘ,悬停只显示该字段自己的说明,标题过长时省略且 ⓘ 仍可见。生成器声明了 advanced 字段时,“高级设置”默认收起、箭头朝右,点击后显示高级字段、箭头朝下,再点收起、箭头朝右;高级字段是空的必填项时,选中该生成器后分组自动展开、显示必填提示、创建按钮不可用,收起后不会再被自动展开。工具字段:用 Lithe-core-rust 的 shared/plugins/contract/v1/fixtures/project-generators/project-generator-tool-field.plugin.json 和一个定义了同名工具的插件做本地开发安装,新建项目里该生成器的工具下拉列出本机已发现的安装(含版本),选低于最低版本的安装时创建按钮不可用并提示,选满足版本的安装创建后新项目的 .lithe/run/local.json 里有该工具的 pin,设置里的工具链页面显示同一个固定值;没有任何插件定义该工具时出现“在插件市场中查找”,插件已安装未启用时出现“启用”。在新建项目窗口保持打开时安装或卸载只含生成器的插件,条目立即出现或消失且无需重启。Windows:宿主不声明 projectGenerators,需要它的插件在市场中隐藏。 新建项目左栏底部插件入口:在 800×682 的无头窗口分别用 English、中文和明暗主题打开新建项目,确认整句插件入口在 240px 左栏内自然换行、全行可点击且跳转插件设置;自动断言 TestNewProjectMarketplaceLinkFitsSidebar,截图由 TestVisualNewProjectFieldDescriptions 生成,macOS/Windows 原生验收仍待执行。", - "notes": "Viva 新建项目窗口用 Page 写法重做并接通 projectGenerators 1 与 2(宿主已声明):左栏分“新建项目”和“生成器”两组并经 Core 搜索,列出空项目和已启用插件的生成器;右栏按声明画文本、选择、复选、多选、运行时/工具安装下拉和“高级设置”,默认值、显示条件、错误码和生成计划全部来自 Core(project.generatorCatalog/generatorForm/generationPlan)。创建时先在目标目录旁的 .<名称>.lithe-creating-* 临时目录依次执行文件、命令、归档步骤:文件用同目录临时文件原子写入并拒绝越出目录和符号链接;命令用 buildprocess 执行,输出逐行显示、可取消、有超时(默认 600 秒);归档下载只允许 HTTPS(回环地址可用 HTTP)并限制 512 MiB,再交给 Core 解压。全部成功才整体移动到位,失败或取消删除临时目录不留残留;移动之后的失败(Git 初始化、工具 pin)保留已建目录并提供“打开已创建的项目”。工具与 runtime 字段通过共享工具链在空临时目录里发现安装,所选安装写入新项目的 .lithe/toolchains/local.json,generator 声明的 openFiles 在项目打开后打开。字段说明画成标题旁(复选框字段为复选框旁)的 ⓘ 提示:纯文本没有身份不能带提示,迁移时把提示挂在标题文字上,选中带说明的生成器会让绘制 panic、窗口转圈卡死;各字段按字段 ID 命名,ⓘ 互不混淆。“高级设置”按钮迁移时固定画朝右的箭头,展开后不变;现在箭头跟随展开状态。高级字段出现新的问题(如空的必填项)时分组自动展开一次,否则创建按钮不可用却看不到原因。空项目行为不变。尚未完成:生成器自带图标未画;缺少所需插件时“在插件市场中查找”只打开插件设置而不预填搜索词;命令步骤只按 PATH 解析可执行文件;插件热更新只在已安装列表变化时重读条目;两端原生窗口、真实归档下载与命令步骤和 Windows 都未验证。legacy 是迁移前基线。 英文插件市场入口原先直接用单行 Button 测量完整句子,会溢出固定 240px 左栏;改成限定宽度的可换行文本与有身份的整行按钮,保留完整无障碍名称、悬停提示和点击目标。", + "verification": "macOS:安装测试内联的合成生成器插件(声明文件、命令、归档三类步骤),从欢迎页和项目切换器点“新建项目”,确认左栏有“新建项目”(含宿主提供的空项目)和“生成器”两组且可搜索。用文件步骤创建,确认生成声明的文件、项目打开后 openFiles 指定的文件已打开。勾选“创建 Git 仓库”时项目根目录有 .git。归档步骤从本机回环 HTTP 服务下载并解压、可执行位保留;把归档地址改成不可达地址时报错且目标目录下没有残留的 .*.lithe-creating-* 临时目录。命令步骤在 PATH 中找不到可执行文件时提示找不到命令。停用该插件后条目变灰、创建按钮不可用,只出现一条启用提示,点击后条目恢复可用;所需插件未安装时出现“在插件市场中查找”。目标目录已存在时拒绝创建且不改动原目录。生成器字段声明了 description 时,选中该生成器后表单正常显示,每个带说明的字段旁各有一个 ⓘ,悬停只显示该字段自己的说明,标题过长时省略且 ⓘ 仍可见。生成器声明了 advanced 字段时,“高级设置”默认收起、箭头朝右,点击后显示高级字段、箭头朝下,再点收起、箭头朝右;高级字段是空的必填项时,选中该生成器后分组自动展开、显示必填提示、创建按钮不可用,收起后不会再被自动展开。工具字段:用 Lithe-core-rust 的 shared/plugins/contract/v1/fixtures/project-generators/project-generator-tool-field.plugin.json 和一个定义了同名工具的插件做本地开发安装,新建项目里该生成器的工具下拉列出本机已发现的安装(含版本),选低于最低版本的安装时创建按钮不可用并提示,选满足版本的安装创建后新项目的 .lithe/run/local.json 里有该工具的 pin,设置里的工具链页面显示同一个固定值;没有任何插件定义该工具时出现“在插件市场中查找”,插件已安装未启用时出现“启用”。在新建项目窗口保持打开时安装或卸载只含生成器的插件,条目立即出现或消失且无需重启。 #2257:desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/projectgen 覆盖 writeFile 的 0644/0755 权限、fsync、符号链接拒绝及无临时文件残留。Windows:宿主不声明 projectGenerators,需要它的插件在市场中隐藏。 新建项目左栏底部插件入口:在 800×682 的无头窗口分别用 English、中文和明暗主题打开新建项目,确认整句插件入口在 240px 左栏内自然换行、全行可点击且跳转插件设置;自动断言 TestNewProjectMarketplaceLinkFitsSidebar,截图由 TestVisualNewProjectFieldDescriptions 生成,macOS/Windows 原生验收仍待执行。", + "notes": "Viva 新建项目窗口用 Page 写法重做并接通 projectGenerators 1 与 2(宿主已声明):左栏分“新建项目”和“生成器”两组并经 Core 搜索,列出空项目和已启用插件的生成器;右栏按声明画文本、选择、复选、多选、运行时/工具安装下拉和“高级设置”,默认值、显示条件、错误码和生成计划全部来自 Core(project.generatorCatalog/generatorForm/generationPlan)。创建时先在目标目录旁的 .<名称>.lithe-creating-* 临时目录依次执行文件、命令、归档步骤:文件用同目录临时文件原子写入并拒绝越出目录和符号链接;命令用 buildprocess 执行,输出逐行显示、可取消、有超时(默认 600 秒);归档下载只允许 HTTPS(回环地址可用 HTTP)并限制 512 MiB,再交给 Core 解压。全部成功才整体移动到位,失败或取消删除临时目录不留残留;移动之后的失败(Git 初始化、工具 pin)保留已建目录并提供“打开已创建的项目”。工具与 runtime 字段通过共享工具链在空临时目录里发现安装,所选安装写入新项目的 .lithe/toolchains/local.json,generator 声明的 openFiles 在项目打开后打开。字段说明画成标题旁(复选框字段为复选框旁)的 ⓘ 提示:纯文本没有身份不能带提示,迁移时把提示挂在标题文字上,选中带说明的生成器会让绘制 panic、窗口转圈卡死;各字段按字段 ID 命名,ⓘ 互不混淆。“高级设置”按钮迁移时固定画朝右的箭头,展开后不变;现在箭头跟随展开状态。高级字段出现新的问题(如空的必填项)时分组自动展开一次,否则创建按钮不可用却看不到原因。空项目行为不变。 #2257:projectgen/files.go 的 writeFile 改用共享 atomicfile.Write,保留符号链接检查与 0644/0755 权限并补齐 fsync。尚未完成:生成器自带图标未画;缺少所需插件时“在插件市场中查找”只打开插件设置而不预填搜索词;命令步骤只按 PATH 解析可执行文件;插件热更新只在已安装列表变化时重读条目;两端原生窗口、真实归档下载与命令步骤和 Windows 都未验证。legacy 是迁移前基线。 英文插件市场入口原先直接用单行 Button 测量完整句子,会溢出固定 240px 左栏;改成限定宽度的可换行文本与有身份的整行按钮,保留完整无障碍名称、悬停提示和点击目标。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { diff --git a/shared/platform-feature-matrix/features/remote-development-workspace.json b/shared/platform-feature-matrix/features/remote-development-workspace.json index 20f5c38755..d797c4ee37 100644 --- a/shared/platform-feature-matrix/features/remote-development-workspace.json +++ b/shared/platform-feature-matrix/features/remote-development-workspace.json @@ -19,6 +19,8 @@ "desktop/internal/core/remote_session.go", "desktop/internal/remoteserver/remoteserver.go", "desktop/internal/remoteserver/remoteserver_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/installedpackagetest/installedpackagetest.go", "desktop/internal/core/remote_acceptance_test.go", ".agents/notes/implemented/feature/2026-11-21-remote-connections-window.md", @@ -42,6 +44,8 @@ "desktop/internal/core/remote_session.go", "desktop/internal/remoteserver/remoteserver.go", "desktop/internal/remoteserver/remoteserver_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "desktop/internal/installedpackagetest/installedpackagetest.go", "desktop/internal/core/remote_acceptance_test.go", ".agents/notes/implemented/feature/2026-11-21-remote-connections-window.md", @@ -49,7 +53,7 @@ ] }, "owner": "Workspace", - "verification": "在 macOS 和 Windows 客户端上,分别按 remote-connections 与 remote-workspace 两项的验证方式完整走一遍(#2231 第 13 节)。目标覆盖 Linux x86_64、Linux arm64、经跳板机访问的主机、本机容器和 SSH 主机上的容器,Windows 另加 WSL 发行版。每个组合依次验证:打开 → 信任 → 编辑保存与外部修改冲突 → 终端 → 搜索与 Git → 运行程序和脚本运行配置 → 端口转发与本机预览 → 断线重连后运行接着输出 → 关闭确认与保留进程 → 清理;最后确认本机和主机上都没有残留的 Lithe 进程。远程 Mac 不在范围内(#2231 D2:远端只支持 Linux),不验证。自动部分运行 desktop/internal/core/remote_acceptance_test.go(LITHE_TEST_REMOTE_SSH_HOST 等环境变量指定真实主机时才运行,CI 跳过),以及两项条目列出的单元测试和无头截图。", + "verification": "在 macOS 和 Windows 客户端上,分别按 remote-connections 与 remote-workspace 两项的验证方式完整走一遍(#2231 第 13 节)。目标覆盖 Linux x86_64、Linux arm64、经跳板机访问的主机、本机容器和 SSH 主机上的容器,Windows 另加 WSL 发行版。每个组合依次验证:打开 → 信任 → 编辑保存与外部修改冲突 → 终端 → 搜索与 Git → 运行程序和脚本运行配置 → 端口转发与本机预览 → 断线重连后运行接着输出 → 关闭确认与保留进程 → 清理;最后确认本机和主机上都没有残留的 Lithe 进程。远程 Mac 不在范围内(#2231 D2:远端只支持 Linux),不验证。自动部分运行 desktop/internal/core/remote_acceptance_test.go(LITHE_TEST_REMOTE_SSH_HOST 等环境变量指定真实主机时才运行,CI 跳过),以及两项条目列出的单元测试和无头截图。 #2257:desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/remoteserver 覆盖 0600 安装、同字节复用、符号链接替换、Windows 并发改名容错与 installedpackagetest。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -99,5 +103,5 @@ "verificationStatus": "not-applicable" } }, - "notes": "Viva:SSH 主机、Windows 上的 WSL 发行版、本机及 SSH/WSL 主机上的 Docker/Podman 容器,以及按本机 devcontainer.json 构建的容器,都经 Core 的 remote.* 打开为远程工作区(#2231 R0–R2 已合入)。连接管理见 remote-connections;工作区里的文件、终端、搜索、Git、运行、端口、关闭确认和断线重连见 remote-workspace。记为部分实现,原因有两个:远程 Mac 按 #2231 D2 不支持;远程工作区里的插件任务、构建工具、插件运行和调试属于 #2231 R3/R4,尚未实现。验证状态仍为待验证:自动验收已在 macOS(经 OpenSSH 连 Linux 容器)和 Windows(WSL)上通过,但按上面验证方式完成整机交互验收的结果还没有记录到本项。" + "notes": "Viva:SSH 主机、Windows 上的 WSL 发行版、本机及 SSH/WSL 主机上的 Docker/Podman 容器,以及按本机 devcontainer.json 构建的容器,都经 Core 的 remote.* 打开为远程工作区(#2231 R0–R2 已合入)。连接管理见 remote-connections;工作区里的文件、终端、搜索、Git、运行、端口、关闭确认和断线重连见 remote-workspace。记为部分实现,原因有两个:远程 Mac 按 #2231 D2 不支持;远程工作区里的插件任务、构建工具、插件运行和调试属于 #2231 R3/R4,尚未实现。验证状态仍为待验证:自动验收已在 macOS(经 OpenSSH 连 Linux 容器)和 Windows(WSL)上通过,但按上面验证方式完成整机交互验收的结果还没有记录到本项。 #2257:remoteserver.installFile 改用共享 atomicfile.InstallWithRename(保留 0600 权限与并发改名测试钩子)。" } diff --git a/shared/platform-feature-matrix/features/runtime-package-integrity.json b/shared/platform-feature-matrix/features/runtime-package-integrity.json index b3cc286601..927bc6779f 100644 --- a/shared/platform-feature-matrix/features/runtime-package-integrity.json +++ b/shared/platform-feature-matrix/features/runtime-package-integrity.json @@ -9,6 +9,9 @@ "evidence": [ "desktop/internal/workbench/bundle_immutability_test.go", "desktop/internal/store/store.go", + "desktop/internal/store/store_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "scripts/desktop/verify/verify-runtime-bundle-immutability.sh" ] }, @@ -18,10 +21,13 @@ "evidence": [ "desktop/internal/workbench/bundle_immutability_test.go", "desktop/internal/store/store.go", + "desktop/internal/store/store_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", "scripts/desktop/verify/verify-runtime-bundle-immutability.sh" ] }, "owner": "Desktop", - "notes": "macOS 已在隔离的程序包夹具中运行打开、编辑、保存和搜索,核对文件清单和 SHA-256 不变;静态门禁覆盖统一客户端源码。该夹具不是正式签名发行包;Windows 完整工作台及最终发行包的运行时哈希验证尚未完成,插件和语言服务器资源也尚未覆盖。", - "verification": "在 macOS 与 Windows 上分别构建正式发行包,记录程序及全部打包资源的相对路径、大小和 SHA-256;启动应用,完成项目打开、编辑保存、搜索及可用的插件/语言服务器流程,退出并检查子进程清理;重新记录清单并逐项比较,任何新增、删除或哈希变化均失败。macOS 另用前一发行包验证 Sparkle 差分更新。" + "notes": "macOS 已在隔离的程序包夹具中运行打开、编辑、保存和搜索,核对文件清单和 SHA-256 不变;静态门禁覆盖统一客户端源码。该夹具不是正式签名发行包;Windows 完整工作台及最终发行包的运行时哈希验证尚未完成,插件和语言服务器资源也尚未覆盖。 #2257:store.WriteFile 改用共享 atomicfile.Write(0600 权限与 fsync)。", + "verification": "在 macOS 与 Windows 上分别构建正式发行包,记录程序及全部打包资源的相对路径、大小和 SHA-256;启动应用,完成项目打开、编辑保存、搜索及可用的插件/语言服务器流程,退出并检查子进程清理;重新记录清单并逐项比较,任何新增、删除或哈希变化均失败。macOS 另用前一发行包验证 Sparkle 差分更新。 #2257:desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/store 与 ./scripts/desktop/verify/verify-runtime-bundle-immutability.sh 在 macOS 通过,Windows 原生仍待验收。" } diff --git a/shared/platform-feature-matrix/features/terminal-shell.json b/shared/platform-feature-matrix/features/terminal-shell.json index be7327d038..86723ff2fd 100644 --- a/shared/platform-feature-matrix/features/terminal-shell.json +++ b/shared/platform-feature-matrix/features/terminal-shell.json @@ -14,7 +14,10 @@ "desktop/internal/workbench/terminal_env.go", "desktop/internal/workbench/terminals.go", "desktop/internal/settingswindow/terminal_reset_test.go", - "desktop/internal/settingswindow/terminal_reset_visual_test.go" + "desktop/internal/settingswindow/terminal_reset_visual_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", + "desktop/internal/localshell/conpty/conpty.go" ] }, "windows": { @@ -33,11 +36,14 @@ "desktop/internal/localshell/backend_windows.go", "desktop/internal/localshell/integration_windows.go", "desktop/internal/settingswindow/terminal_reset_test.go", - "desktop/internal/settingswindow/terminal_reset_visual_test.go" + "desktop/internal/settingswindow/terminal_reset_visual_test.go", + "desktop/internal/atomicfile/atomicfile.go", + "desktop/internal/atomicfile/atomicfile_test.go", + "desktop/internal/localshell/conpty/conpty.go" ] }, "owner": "Terminal", - "verification": "验证设置页默认 Shell 选项与终端「新建终端」菜单检测到的 Shell 一致、可选 Git Bash 并生效;macOS 新建终端下拉框复用 Project 下拉框的共享菜单样式,菜单操作与原有 Shell 选择、重新检测功能一致;验证环境变量、工作目录和不可用 Shell 的提示。 设置页终端分组新增回滚行数配置(默认 2000,范围 100–50000,步进 500),读取、写入、恢复默认均做上下限夹取,对新建会话生效(TerminalScrollbackSettingsTests);设置搜索按界面名称 Terminal scrollback/终端回滚行数/行数 均可命中终端页(SettingsSearchVocabularyTests)。 macOS 终端环境随 TERM_PROGRAM=Lithe 一并导出 TERM_PROGRAM_VERSION(取应用打包版本,无法取得时不写入),与 Windows 端一致,供工具按版本门控终端能力(TerminalModuleTests);按当前外观导出 COLORFGBG(浅色 0;15、深色 15;0,宿主无法判定时不写入),TUI 无需 OSC 查询即可选择配色(TerminalModuleTests)。终端会话在启动前剥离从宿主进程继承的 NO_COLOR、FORCE_COLOR、CLICOLOR_FORCE、CI、GITHUB_ACTIONS 和 CONTINUOUS_INTEGRATION,并设置 CLICOLOR=1;显式 environmentChanges 仍可覆盖,避免 Codex 和 Claude Code 因父进程环境退化为黑白。 Windows 运行 TestWindowsShellsMarkTheirPromptsUnderTheToken:cmd.exe、powershell.exe、pwsh.exe 各自启动后带本次令牌标记提示符,进入含中文、空格、分号和百分号的目录后再次标记;等第一个提示符的期限是 45 秒(Windows PowerShell 5.1 在 CI 上冷启动约 9 秒,偶尔超过 12 秒),进入目录后的提示符仍是 12 秒。 Windows 从 Microsoft Store 安装的 PowerShell 7 不加 PATH 项,只在 %LOCALAPPDATA%\\Microsoft\\WindowsApps 根目录和 Microsoft.PowerShell_8wekyb3d8bbwe 子目录注册应用执行别名;Shell 发现把它列为 PowerShell 7,PATH 中没有 pwsh.exe 时默认 Shell 优先选它而不是 Windows PowerShell 5.1(TestWindowsShellDiscoveryFindsTheStorePowerShellAlias、TestWindowsDefaultShellPrefersTheStorePowerShell)。PowerShell 提示符集成不再传 -NoLogo,保留版本横幅(TestPowerShellIntegrationKeepsTheBanner)。Windows 实机验收 pending。 #2019:回滚行数改为非默认值或保存了无法识别的值后,点击全局「恢复默认设置」,设置所有方收到 2000 行,输入框里未提交的草稿也被丢弃并回显 2000;打开页面或选回相同的值不写设置(TestTerminalRestoreDefaultsReachesOwnerAndPage、TestTerminalRestoreDoesNotReviveScrollbackDraft、TestTerminalUnchangedChoicesDoNotWrite)。原生窗口验收 pending。", + "verification": "验证设置页默认 Shell 选项与终端「新建终端」菜单检测到的 Shell 一致、可选 Git Bash 并生效;macOS 新建终端下拉框复用 Project 下拉框的共享菜单样式,菜单操作与原有 Shell 选择、重新检测功能一致;验证环境变量、工作目录和不可用 Shell 的提示。 设置页终端分组新增回滚行数配置(默认 2000,范围 100–50000,步进 500),读取、写入、恢复默认均做上下限夹取,对新建会话生效(TerminalScrollbackSettingsTests);设置搜索按界面名称 Terminal scrollback/终端回滚行数/行数 均可命中终端页(SettingsSearchVocabularyTests)。 macOS 终端环境随 TERM_PROGRAM=Lithe 一并导出 TERM_PROGRAM_VERSION(取应用打包版本,无法取得时不写入),与 Windows 端一致,供工具按版本门控终端能力(TerminalModuleTests);按当前外观导出 COLORFGBG(浅色 0;15、深色 15;0,宿主无法判定时不写入),TUI 无需 OSC 查询即可选择配色(TerminalModuleTests)。终端会话在启动前剥离从宿主进程继承的 NO_COLOR、FORCE_COLOR、CLICOLOR_FORCE、CI、GITHUB_ACTIONS 和 CONTINUOUS_INTEGRATION,并设置 CLICOLOR=1;显式 environmentChanges 仍可覆盖,避免 Codex 和 Claude Code 因父进程环境退化为黑白。 Windows 运行 TestWindowsShellsMarkTheirPromptsUnderTheToken:cmd.exe、powershell.exe、pwsh.exe 各自启动后带本次令牌标记提示符,进入含中文、空格、分号和百分号的目录后再次标记;等第一个提示符的期限是 45 秒(Windows PowerShell 5.1 在 CI 上冷启动约 9 秒,偶尔超过 12 秒),进入目录后的提示符仍是 12 秒。 Windows 从 Microsoft Store 安装的 PowerShell 7 不加 PATH 项,只在 %LOCALAPPDATA%\\Microsoft\\WindowsApps 根目录和 Microsoft.PowerShell_8wekyb3d8bbwe 子目录注册应用执行别名;Shell 发现把它列为 PowerShell 7,PATH 中没有 pwsh.exe 时默认 Shell 优先选它而不是 Windows PowerShell 5.1(TestWindowsShellDiscoveryFindsTheStorePowerShellAlias、TestWindowsDefaultShellPrefersTheStorePowerShell)。PowerShell 提示符集成不再传 -NoLogo,保留版本横幅(TestPowerShellIntegrationKeepsTheBanner)。Windows 实机验收 pending。 #2019:回滚行数改为非默认值或保存了无法识别的值后,点击全局「恢复默认设置」,设置所有方收到 2000 行,输入框里未提交的草稿也被丢弃并回显 2000;打开页面或选回相同的值不写设置(TestTerminalRestoreDefaultsReachesOwnerAndPage、TestTerminalRestoreDoesNotReviveScrollbackDraft、TestTerminalUnchangedChoicesDoNotWrite)。原生窗口验收 pending。 #2257:本机 Go 1.27 + 固定 Core 9ab2336 运行 ./scripts/desktop/desktop-go.sh test -race -tags 'dev vivahead' -count=1 ./internal/atomicfile ./internal/localshell/conpty(含字节复用、符号链接替换、同字节并发容错、非 rename 错误不吞没、失败无残留与 installedpackagetest)通过;Windows 原生 ConPTY DLL 安装与占用竞争仍待 CI/Windows 实机验收。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -67,5 +73,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:默认 Shell 发现和选择(localshell/discovery.go 含 Git Bash,设置页有 automatic 选项,新建菜单列出可用 Shell);设置 › 终端可调回滚行数(默认 2000,新终端生效);terminal_env.go 导出 TERM_PROGRAM、TERM_PROGRAM_VERSION、CLICOLOR 与按主题的 COLORFGBG,并继承 NO_COLOR、FORCE_COLOR、CLICOLOR_FORCE、CI 等变量。 2026-11-16:同步 Motty 2f73c352(Store PowerShell 7 别名)、02916ed5(保留 PowerShell 横幅),见 termview/NOTICE。" + "notes": "Viva:默认 Shell 发现和选择(localshell/discovery.go 含 Git Bash,设置页有 automatic 选项,新建菜单列出可用 Shell);设置 › 终端可调回滚行数(默认 2000,新终端生效);terminal_env.go 导出 TERM_PROGRAM、TERM_PROGRAM_VERSION、CLICOLOR 与按主题的 COLORFGBG,并继承 NO_COLOR、FORCE_COLOR、CLICOLOR_FORCE、CI 等变量。 2026-11-16:同步 Motty 2f73c352(Store PowerShell 7 别名)、02916ed5(保留 PowerShell 横幅),见 termview/NOTICE。 #2257:ConPTY 嵌入文件安装(conpty.place)已统一为共享 atomicfile.Install,严格按常规文件字节复用、同目录临时文件 chmod/fsync、原子改名替换和 Windows 已有同字节并发安装容错,未变更可见入口。" }