weiqingy commented on code in PR #709: URL: https://github.com/apache/flink-agents/pull/709#discussion_r3315347859
########## api/src/test/java/org/apache/flink/agents/api/CrossLanguageEventSnapshotTest.java: ########## @@ -0,0 +1,483 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.agents.api; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.flink.agents.api.agents.OutputSchema; +import org.apache.flink.agents.api.chat.messages.ChatMessage; +import org.apache.flink.agents.api.chat.messages.MessageRole; +import org.apache.flink.agents.api.event.ChatRequestEvent; +import org.apache.flink.agents.api.event.ChatResponseEvent; +import org.apache.flink.agents.api.event.ContextRetrievalRequestEvent; +import org.apache.flink.agents.api.event.ContextRetrievalResponseEvent; +import org.apache.flink.agents.api.event.ToolRequestEvent; +import org.apache.flink.agents.api.event.ToolResponseEvent; +import org.apache.flink.agents.api.tools.ToolResponse; +import org.apache.flink.agents.api.vectorstores.Document; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +/** Cross-language event SerDe snapshot tests. */ +class CrossLanguageEventSnapshotTest { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + private static final UUID FIXED_EVENT_ID = + UUID.fromString("00000000-0000-0000-0000-000000000001"); + private static final UUID FIXED_REQUEST_ID = + UUID.fromString("00000000-0000-0000-0000-000000000002"); + private static final String FIXED_TOOL_CALL_ID = "call_aaaa"; + private static final long FIXED_TIMESTAMP = 1_700_000_000_000L; + + private static Path snapshotDir; + + @BeforeAll + static void resolveSnapshotDir() { + Path repoRoot = Paths.get(System.getProperty("user.dir")).getParent(); + snapshotDir = repoRoot.resolve("e2e-test/cross-language-event-snapshots"); + } + + // ── Helpers ──────────────────────────────────────────────────────────── + + private static boolean regenerateRequested() { + return Boolean.parseBoolean(System.getProperty("regenerate.snapshots", "false")); + } + + private static void writeJavaSnapshot(String fileName, Event event) throws Exception { + String json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(event); + Path target = snapshotDir.resolve("java/" + fileName); + Files.createDirectories(target.getParent()); + Files.writeString(target, json + "\n"); + } + + private static void assertJavaSnapshotStable(String fileName, Event event) throws Exception { + String actualJson = MAPPER.writeValueAsString(event); + JsonNode actual = MAPPER.readTree(actualJson); + + Path committed = snapshotDir.resolve("java/" + fileName); + assumeTrue( Review Comment: `assumeTrue` here means the test reports as "skipped, not failed" if `chat_request_event.json` (or any other committed snapshot) gets renamed or deleted. The whole point of the snapshot suite is to catch silent wire-format drift, so silently-skipped "stable" tests undercut that guarantee. The `regenerate*` tests genuinely need conditional skipping (the system property is the gate). For `*JavaSnapshotIsStable` and `javaCanDeserialize*FromPythonSnapshot`, was there a reason for the symmetric `assumeTrue` — any case where a missing snapshot should soft-pass? If not, would a hard `assertTrue(Files.exists(...))` be better? Same question for `readPythonSnapshot:111`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
