fix(handoff): 在执行器容器内读取云端归档清单
build / build (push) Successful in 1m23s

This commit is contained in:
姚章浩
2026-10-30 22:45:25 +08:00
parent 52c0186172
commit 323f9ae502
3 changed files with 62 additions and 1 deletions
+6
View File
@@ -1,5 +1,11 @@
# Changelog
## 开发快照(云端归档清单读回)
### Fixed
- 快照清单通过指定执行器容器读取,不再将容器内归档路径当作 SSH 宿主机路径;避免已导入的快照被误报不存在,保留真实缺失与执行错误的区别。
## 开发快照(云端快照搬运默认值与接收目录)
### Fixed
+3 -1
View File
@@ -538,7 +538,9 @@ func (r *sshRemote) ReadVersionManifest(ctx context.Context, id string) ([]byte,
path := filepath.Join(r.config.RemoteArchive, "versions", id+".json")
var out strings.Builder
// 只有 "文件不存在" 才算"还没有这份版本";其它失败必须让调用方停下来。
command := fmt.Sprintf("if [ -f %s ]; then cat %s; else exit 44; fi", shellQuote(path), shellQuote(path))
// RemoteArchive belongs to the executor filesystem, not the SSH host.
read := fmt.Sprintf("if [ -f %s ]; then cat %s; else exit 44; fi", shellQuote(path), shellQuote(path))
command := "docker exec " + shellQuote(r.config.ExecutorContainer) + " sh -c " + shellQuote(read)
if err := r.run(ctx, nil, &out, command); err != nil {
var exit *remoteExitError
if errors.As(err, &exit) && exit.code == 44 {
@@ -0,0 +1,53 @@
package libraryhandoff
import (
"context"
"errors"
"os"
"path/filepath"
"strings"
"testing"
"time"
)
// SSH runs its remote shell locally; Docker is an explicit process-boundary
// fixture. The archive path deliberately does not exist on the SSH host.
func TestSSHManifestReadUsesExecutorFilesystem(t *testing.T) {
bin := t.TempDir()
write := func(name, text string) {
t.Helper()
if err := os.WriteFile(filepath.Join(bin, name), []byte(text), 0700); err != nil {
t.Fatal(err)
}
}
write("ssh", "#!/bin/sh\nfor arg do last=$arg; done\nexec /bin/sh -c \"$last\"\n")
write("docker", `#!/bin/sh
[ "$1" = exec ] && [ "$2" = fixture-executor ] && [ "$3" = sh ] && [ "$4" = -c ] || exit 91
case "$5" in *"/executor-only/archive/versions/"*) ;; *) exit 92;; esac
printf '%s' "$5" > "$MANIFEST_TRACE"
if [ "$MANIFEST_MODE" = missing ]; then exit 44; fi
if [ "$MANIFEST_MODE" = denied ]; then exit 13; fi
printf '%s' '{"container":true}'
`)
t.Setenv("PATH", bin+":"+os.Getenv("PATH"))
trace := filepath.Join(bin, "trace")
t.Setenv("MANIFEST_TRACE", trace)
r := &sshRemote{config: Config{SSHTarget: "fixture", SSHConfig: "/unused", ExecutorContainer: "fixture-executor", RemoteArchive: "/executor-only/archive", OpTimeout: time.Second * 5}}
id := strings.Repeat("a", 64)
got, err := r.ReadVersionManifest(context.Background(), id)
if err != nil || string(got) != `{"container":true}` {
t.Fatalf("must read through executor, got=%s err=%v", got, err)
}
cmd, err := os.ReadFile(trace)
if err != nil || !strings.Contains(string(cmd), id+".json") {
t.Fatalf("missing exact snapshot read: %s %v", cmd, err)
}
t.Setenv("MANIFEST_MODE", "missing")
if _, err := r.ReadVersionManifest(context.Background(), id); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("missing manifest: %v", err)
}
t.Setenv("MANIFEST_MODE", "denied")
if _, err := r.ReadVersionManifest(context.Background(), id); err == nil || errors.Is(err, os.ErrNotExist) {
t.Fatalf("permission failure must not mean absent: %v", err)
}
}