From 56845ab79feaf73c4f93abe983004944376e7dba Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Mon, 18 May 2026 16:34:35 +0800 Subject: [PATCH] test: cover actual OpenClaw run artifact adoption --- README.md | 3 +++ src/exportArtifacts.test.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/README.md b/README.md index 7816c4b..ad3bdca 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,9 @@ local users can open or download them directly from that workspace path. Gateway clients can use: - `xworkmate.artifacts.prepare` before `chat.send` to allocate a task artifact directory. +- Pass the prepared `artifactScope`/`artifactDirectory` to `chat.send` and, if + `chat.send` returns a different OpenClaw `runId`, prepare/export with that + actual `runId` instead of the bridge request id. - `xworkmate.artifacts.list` for a metadata-only manifest and Markdown table. - `xworkmate.artifacts.read` with `artifactScope` and `relativePath` for one task file. - `xworkmate.artifacts.read` with `artifactRef` for a plugin-returned task file. diff --git a/src/exportArtifacts.test.ts b/src/exportArtifacts.test.ts index d03c818..fd5b615 100644 --- a/src/exportArtifacts.test.ts +++ b/src/exportArtifacts.test.ts @@ -254,6 +254,36 @@ describe("exportXWorkmateArtifacts", () => { ); }); + it("adopts root Word documents into only the current task scope", async () => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), "tmp-openclaw-multi-session-plugins-")); + const sinceUnixMs = Date.now() - 1_000; + await fs.writeFile(path.join(root, "article.docx"), "docx-content"); + + const result = await exportXWorkmateArtifacts({ + params: { + sessionKey: "draft-article", + runId: "openclaw-run-1", + sinceUnixMs, + maxInlineBytes: 0, + }, + pluginConfig: { workspaceDir: root }, + }); + + expect(result.artifactScope).toBe("tasks/draft-article/openclaw-run-1"); + expect(result.artifacts).toHaveLength(1); + expect(result.artifacts[0]).toMatchObject({ + relativePath: "article.docx", + artifactScope: "tasks/draft-article/openclaw-run-1", + scopeKind: "task", + contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + }); + expect(result.artifacts[0]?.encoding).toBeUndefined(); + expect(await fs.readFile(path.join(root, "tasks", "draft-article", "openclaw-run-1", "article.docx"), "utf8")).toBe( + "docx-content", + ); + await expect(fs.stat(path.join(root, "tasks", "draft-article", "turn-1", "article.docx"))).rejects.toThrow(); + }); + it("does not adopt old workspace root files into a later task scope", async () => { const root = await fs.mkdtemp(path.join(os.tmpdir(), "tmp-openclaw-multi-session-plugins-")); await prepareXWorkmateArtifacts({