diff --git a/cloud/chv/memory_files.py b/cloud/chv/memory_files.py index 1e474e9..9b0bc45 100644 --- a/cloud/chv/memory_files.py +++ b/cloud/chv/memory_files.py @@ -258,10 +258,16 @@ class MemorySystemClient: def build_pull_command(ssh_cmd: list[str], remote_home: str) -> list[str]: - """构造拉取命令:ssh … tar -czf - -C <父目录> <家目录名>。""" - parent = os.path.dirname(remote_home.rstrip("/")) - base = os.path.basename(remote_home.rstrip("/")) - return list(ssh_cmd) + ["tar -czf - -C %s %s" % (parent, base)] + """构造拉取命令:ssh … tar -czf - -C <家目录> .(只打包内容)。 + + 绝不用旧形状 ``-C <父目录> <家目录名>``:它会把顶层目录名 + 打进包,解到镜像后文件落在 ``/memory/MEMORY.md``, + 而 ``MemoryFiles(mirror)`` 读的是 ``/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, diff --git a/cloud/tests/test_chv_muse_p7.py b/cloud/tests/test_chv_muse_p7.py index b799937..714d834 100644 --- a/cloud/tests/test_chv_muse_p7.py +++ b/cloud/tests/test_chv_muse_p7.py @@ -401,7 +401,7 @@ class PullMemoryHomeTest(unittest.TestCase): cmd = build_pull_command( ["ssh", "-p", "2222", "chv@127.0.0.1"], "/home/chv/memory") 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): with tempfile.TemporaryDirectory() as tmp: @@ -415,14 +415,18 @@ class PullMemoryHomeTest(unittest.TestCase): fake_ssh = os.path.join(tmp, "fake-ssh") Path(fake_ssh).write_text( "#!/bin/sh\n" - "tar -czf - -C %s memory\n" % remote_parent) + "tar -czf - -C %s .\n" % remote_home) os.chmod(fake_ssh, 0o755) local = os.path.join(tmp, "local") result = pull_memory_home([fake_ssh], GUEST_MEMORY_HOME, local) 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( - local, "memory", "memory", "2026-11-07.md")).read_text()) + local, "memory", "2026-11-07.md")).read_text()) def test_pull_ssh_failure_raises(self): with tempfile.TemporaryDirectory() as tmp: