deer-flow/frontend/tests/unit/core/messages/artifact-archive.test.ts
Ryker_Feng 8d8ca506ba
feat(artifacts): download run files as zip (#5117)
* feat(artifacts): download run files as zip

* fix(artifacts): address archive review feedback

* fix(artifacts): gate unavailable archive downloads

* fix(artifacts): verify archive availability

* fix(artifacts): harden archive consistency

* fix(artifacts): reject archive path aliases
2026-09-01 22:01:21 +08:00

66 lines
1.9 KiB
TypeScript

import type { Message } from "@langchain/langgraph-sdk";
import { describe, expect, test } from "@rstest/core";
import { getArtifactArchiveCandidatesByGroupIndex } from "@/core/messages/artifact-archive";
import { getMessageGroups } from "@/core/messages/utils";
function presentFiles(id: string, runId: string, filepaths: string[]): Message {
return {
id,
type: "ai",
content: "",
run_id: runId,
tool_calls: [
{
id: `call-${id}`,
name: "present_files",
args: { filepaths },
},
],
} as Message;
}
describe("artifact archive display placement", () => {
test("anchors one archive action after a run's final file presentation", () => {
const groups = getMessageGroups([
presentFiles("first", "run-1", ["/mnt/user-data/outputs/a.txt"]),
presentFiles("second", "run-1", [
"/mnt/user-data/outputs/a.txt",
"/mnt/user-data/outputs/b.txt",
]),
]);
expect(getArtifactArchiveCandidatesByGroupIndex(groups)).toEqual([
undefined,
{ runId: "run-1" },
]);
});
test("verifies even a single attempted path against the terminal receipt", () => {
const groups = getMessageGroups([
presentFiles("only", "run-1", ["/mnt/user-data/outputs/a.txt"]),
]);
expect(getArtifactArchiveCandidatesByGroupIndex(groups)).toEqual([
{ runId: "run-1" },
]);
});
test("keeps archive actions independent across runs", () => {
const groups = getMessageGroups([
presentFiles("run-1-first", "run-1", ["/mnt/user-data/outputs/a.txt"]),
presentFiles("run-2", "run-2", [
"/mnt/user-data/outputs/c.txt",
"/mnt/user-data/outputs/d.txt",
]),
presentFiles("run-1-last", "run-1", ["/mnt/user-data/outputs/b.txt"]),
]);
expect(getArtifactArchiveCandidatesByGroupIndex(groups)).toEqual([
undefined,
{ runId: "run-2" },
{ runId: "run-1" },
]);
});
});