package tech.easyflow.core.runtime;

import org.junit.Assert;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
 * Assistant 历史 payload 的 Artifact 安全投影测试。
 */
public class ChatAssistantAccumulatorArtifactTest {

    /**
     * 验证只持久化安全字段，并按 artifactId 原位去重。
     */
    @Test
    public void buildPayloadShouldPersistOnlySafeArtifactFields() {
        ChatAssistantAccumulator accumulator = new ChatAssistantAccumulator();
        accumulator.appendArtifact(Map.of(
                "schemaVersion", 1,
                "artifactId", "a1",
                "fileName", "report.csv",
                "mimeType", "text/csv",
                "size", 12L,
                "sha256", "abc",
                "downloadUrl", "/api/v1/agent/artifacts/a1/content",
                "status", "AVAILABLE",
                "objectKey", "private/object/key"));

        Map<String, Object> payload = accumulator.buildPayload("done");
        @SuppressWarnings("unchecked")
        List<Map<String, Object>> artifacts = (List<Map<String, Object>>) payload.get("artifacts");

        Assert.assertEquals(1, artifacts.size());
        Assert.assertEquals("a1", artifacts.get(0).get("artifactId"));
        Assert.assertFalse(artifacts.get(0).containsKey("objectKey"));
    }
}
