test: cover actual OpenClaw run artifact adoption

This commit is contained in:
Haitao Pan 2026-05-18 16:34:35 +08:00
parent b68fc811c9
commit 56845ab79f
2 changed files with 33 additions and 0 deletions

View File

@ -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.

View File

@ -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({