fix(chv-muse-r12fix-3): pull_memory_home 打包不再含顶层目录名(P7)
R12 真机:pull_memory_home 用 tar -czf - -C <父目录> <家目录名> 打包,解到镜像后文件落在 mirror/memory/MEMORY.md,而 MemoryFiles(mirror) 读的是 mirror/MEMORY.md——拉取与读取差 一层,host_pull_files=1 却报 memory file missing: MEMORY.md, state-DB 备份与 host forget 同因失败。改为 -C <家目录> . 只打 包内容,MEMORY.md 直接落在镜像根;两处钉住的测试同步改形状 (旧测试本身钉的就是多一层的错误形状)。
This commit is contained in:
1 parent
33ca6c75ed
commit
1da0d86159
2 files changed
+17
-7
No files matched your search
@@ -258,10 +258,16 @@ class MemorySystemClient:
|
|||||||
|
|
||||||
|
|
||||||
def build_pull_command(ssh_cmd: list[str], remote_home: str) -> list[str]:
|
def build_pull_command(ssh_cmd: list[str], remote_home: str) -> list[str]:
|
||||||
"""构造拉取命令:ssh … tar -czf - -C <父目录> <家目录名>。"""
|
"""构造拉取命令:ssh … tar -czf - -C <家目录> .(只打包内容)。
|
||||||
parent = os.path.dirname(remote_home.rstrip("/"))
|
|
||||||
base = os.path.basename(remote_home.rstrip("/"))
|
绝不用旧形状 ``-C <父目录> <家目录名>``:它会把顶层目录名
|
||||||
return list(ssh_cmd) + ["tar -czf - -C %s %s" % (parent, base)]
|
打进包,解到镜像后文件落在 ``<local>/memory/MEMORY.md``,
|
||||||
|
而 ``MemoryFiles(mirror)`` 读的是 ``<local>/MEMORY.md``——
|
||||||
|
拉取与读取差一层,R12 真机 P7 实测 ``host_pull_files=1``
|
||||||
|
却报 ``memory file missing: MEMORY.md``。
|
||||||
|
"""
|
||||||
|
return list(ssh_cmd) + ["tar -czf - -C %s ."
|
||||||
|
% remote_home.rstrip("/")]
|
||||||
|
|
||||||
|
|
||||||
def pull_memory_home(ssh_cmd: list[str], remote_home: str,
|
def pull_memory_home(ssh_cmd: list[str], remote_home: str,
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ class PullMemoryHomeTest(unittest.TestCase):
|
|||||||
cmd = build_pull_command(
|
cmd = build_pull_command(
|
||||||
["ssh", "-p", "2222", "chv@127.0.0.1"], "/home/chv/memory")
|
["ssh", "-p", "2222", "chv@127.0.0.1"], "/home/chv/memory")
|
||||||
self.assertEqual(cmd, ["ssh", "-p", "2222", "chv@127.0.0.1",
|
self.assertEqual(cmd, ["ssh", "-p", "2222", "chv@127.0.0.1",
|
||||||
"tar -czf - -C /home/chv memory"])
|
"tar -czf - -C /home/chv/memory ."])
|
||||||
|
|
||||||
def test_pull_with_fake_ssh(self):
|
def test_pull_with_fake_ssh(self):
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
@@ -415,14 +415,18 @@ class PullMemoryHomeTest(unittest.TestCase):
|
|||||||
fake_ssh = os.path.join(tmp, "fake-ssh")
|
fake_ssh = os.path.join(tmp, "fake-ssh")
|
||||||
Path(fake_ssh).write_text(
|
Path(fake_ssh).write_text(
|
||||||
"#!/bin/sh\n"
|
"#!/bin/sh\n"
|
||||||
"tar -czf - -C %s memory\n" % remote_parent)
|
"tar -czf - -C %s .\n" % remote_home)
|
||||||
os.chmod(fake_ssh, 0o755)
|
os.chmod(fake_ssh, 0o755)
|
||||||
local = os.path.join(tmp, "local")
|
local = os.path.join(tmp, "local")
|
||||||
result = pull_memory_home([fake_ssh], GUEST_MEMORY_HOME,
|
result = pull_memory_home([fake_ssh], GUEST_MEMORY_HOME,
|
||||||
local)
|
local)
|
||||||
self.assertEqual(result["files"], 2)
|
self.assertEqual(result["files"], 2)
|
||||||
|
# round-12 修复轮(项 3,P7):拉取不再多一层目录——
|
||||||
|
# MEMORY.md 直接落在镜像根,MemoryFiles 读得到。
|
||||||
|
self.assertEqual(Path(os.path.join(
|
||||||
|
local, "MEMORY.md")).read_text(), "# 记忆\n")
|
||||||
self.assertIn("冰美式", Path(os.path.join(
|
self.assertIn("冰美式", Path(os.path.join(
|
||||||
local, "memory", "memory", "2026-11-07.md")).read_text())
|
local, "memory", "2026-11-07.md")).read_text())
|
||||||
|
|
||||||
def test_pull_ssh_failure_raises(self):
|
def test_pull_ssh_failure_raises(self):
|
||||||
with tempfile.TemporaryDirectory() as tmp:
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
|||||||
Reference in new issue
Block a user