|
4 | 4 | import io.github.timemachinelab.domain.catalog.model.AuthScheme; |
5 | 5 | import io.github.timemachinelab.domain.catalog.model.RequestMethod; |
6 | 6 | import io.github.timemachinelab.adapter.web.config.ImportAgentStreamProperties; |
| 7 | +import io.github.timemachinelab.api.req.AppendImportAgentTurnReq; |
7 | 8 | import io.github.timemachinelab.api.req.CreateImportAgentSessionReq; |
8 | 9 | import io.github.timemachinelab.service.model.ApiImportAgentRunModel; |
9 | 10 | import io.github.timemachinelab.service.model.ApiImportAgentSessionModel; |
10 | 11 | import io.github.timemachinelab.service.model.AsyncTaskConfigModel; |
| 12 | +import io.github.timemachinelab.service.model.AppendImportAgentTurnCommand; |
11 | 13 | import io.github.timemachinelab.service.model.CreateImportAgentSessionCommand; |
12 | 14 | import io.github.timemachinelab.service.model.ImportAgentActorType; |
| 15 | +import io.github.timemachinelab.service.model.ImportAgentClarificationItemModel; |
| 16 | +import io.github.timemachinelab.service.model.ImportAgentClarificationOptionModel; |
13 | 17 | import io.github.timemachinelab.service.model.ImportAgentPlanModel; |
14 | 18 | import io.github.timemachinelab.service.model.ImportAgentRunStatus; |
15 | 19 | import io.github.timemachinelab.service.model.ImportAgentSessionStatus; |
@@ -95,6 +99,39 @@ void shouldMapMalformedAsyncAuthModeAlias() { |
95 | 99 | assertEquals("HEADER_TOKEN", response.getCurrentPlan().getAssetPlans().get(0).getAsyncTaskConfig().getAuthScheme().name()); |
96 | 100 | } |
97 | 101 |
|
| 102 | + @Test |
| 103 | + @DisplayName("append turn should map structured answers and clarification items") |
| 104 | + void shouldMapStructuredClarificationAnswersAndItems() { |
| 105 | + ApiImportAgentUseCase useCase = mock(ApiImportAgentUseCase.class); |
| 106 | + when(useCase.appendTurn(any(AppendImportAgentTurnCommand.class))).thenReturn(sessionModelWithClarificationItem()); |
| 107 | + ApiImportAgentWebDelegate delegate = new ApiImportAgentWebDelegate(useCase, STREAM_PROPERTIES); |
| 108 | + AppendImportAgentTurnReq req = new AppendImportAgentTurnReq(); |
| 109 | + io.github.timemachinelab.api.req.ImportAgentClarificationAnswerReq answer = |
| 110 | + new io.github.timemachinelab.api.req.ImportAgentClarificationAnswerReq(); |
| 111 | + answer.setClarificationId("plan-1:/assetPlans/0/authScheme:authScheme"); |
| 112 | + answer.setTargetPath("/assetPlans/0/authScheme"); |
| 113 | + answer.setFieldKey("authScheme"); |
| 114 | + answer.setValue("HEADER_TOKEN"); |
| 115 | + req.setClarificationAnswers(List.of(answer)); |
| 116 | + |
| 117 | + var response = delegate.appendTurn("user-1", "session-1", req); |
| 118 | + |
| 119 | + ArgumentCaptor<AppendImportAgentTurnCommand> captor = ArgumentCaptor.forClass(AppendImportAgentTurnCommand.class); |
| 120 | + verify(useCase).appendTurn(captor.capture()); |
| 121 | + assertEquals("user-1", captor.getValue().getOwnerUserId()); |
| 122 | + assertEquals("session-1", captor.getValue().getSessionId()); |
| 123 | + assertEquals(null, captor.getValue().getMessage()); |
| 124 | + assertEquals(1, captor.getValue().getClarificationAnswers().size()); |
| 125 | + assertEquals("authScheme", captor.getValue().getClarificationAnswers().get(0).getFieldKey()); |
| 126 | + assertEquals("HEADER_TOKEN", captor.getValue().getClarificationAnswers().get(0).getValue()); |
| 127 | + assertEquals(1, response.getCurrentPlan().getClarificationItems().size()); |
| 128 | + assertEquals("Authentication scheme", response.getCurrentPlan().getClarificationItems().get(0).getLabel()); |
| 129 | + assertEquals("SELECT", response.getCurrentPlan().getClarificationItems().get(0).getInputType()); |
| 130 | + assertEquals("HEADER_TOKEN", response.getCurrentPlan().getClarificationItems().get(0).getOptions().get(0).getValue()); |
| 131 | + assertEquals("HEADER_TOKEN", response.getCurrentPlan().getClarificationItems().get(0).getDefaultValue()); |
| 132 | + assertEquals("DOCUMENT", response.getCurrentPlan().getClarificationItems().get(0).getDefaultSource()); |
| 133 | + } |
| 134 | + |
98 | 135 | private ApiImportAgentSessionModel sessionModel() { |
99 | 136 | return new ApiImportAgentSessionModel( |
100 | 137 | "session-1", |
@@ -158,6 +195,65 @@ private ApiImportAgentRunModel runModel() { |
158 | 195 | ); |
159 | 196 | } |
160 | 197 |
|
| 198 | + private ApiImportAgentSessionModel sessionModelWithClarificationItem() { |
| 199 | + return new ApiImportAgentSessionModel( |
| 200 | + "session-1", |
| 201 | + "user-1", |
| 202 | + ImportAgentSessionStatus.WAITING_FOR_CLARIFICATION, |
| 203 | + "https://docs.example.com/weather", |
| 204 | + "summary", |
| 205 | + "import weather api", |
| 206 | + "Alice", |
| 207 | + 1, |
| 208 | + null, |
| 209 | + null, |
| 210 | + null, |
| 211 | + new ImportAgentPlanModel( |
| 212 | + 1, |
| 213 | + false, |
| 214 | + "need auth scheme", |
| 215 | + List.of("Authentication scheme (authScheme): Choose the upstream authentication scheme."), |
| 216 | + List.of(new ImportAgentClarificationItemModel( |
| 217 | + "plan-1:/assetPlans/0/authScheme:authScheme", |
| 218 | + "/assetPlans/0/authScheme", |
| 219 | + "authScheme", |
| 220 | + "Authentication scheme", |
| 221 | + "Choose the upstream authentication scheme.", |
| 222 | + "SELECT", |
| 223 | + true, |
| 224 | + List.of(new ImportAgentClarificationOptionModel("HEADER_TOKEN", "HEADER_TOKEN")), |
| 225 | + null, |
| 226 | + "HEADER_TOKEN", |
| 227 | + "HEADER_TOKEN", |
| 228 | + "DOCUMENT", |
| 229 | + "HIGH" |
| 230 | + )), |
| 231 | + List.of(new ImportCategoryPlanModel("tools", "Tools", ImportCategoryPlanAction.CREATE_IF_MISSING)), |
| 232 | + List.of(new ImportAssetPlanModel( |
| 233 | + "weather-forecast", |
| 234 | + "Weather Forecast", |
| 235 | + AssetType.STANDARD_API, |
| 236 | + "tools", |
| 237 | + RequestMethod.GET, |
| 238 | + "https://upstream.example.com/weather", |
| 239 | + null, |
| 240 | + null, |
| 241 | + null, |
| 242 | + null, |
| 243 | + null, |
| 244 | + null, |
| 245 | + null, |
| 246 | + true, |
| 247 | + null, |
| 248 | + null |
| 249 | + )) |
| 250 | + ), |
| 251 | + List.of(), |
| 252 | + "2026-05-18T10:00:00Z", |
| 253 | + "2026-05-18T10:05:00Z" |
| 254 | + ); |
| 255 | + } |
| 256 | + |
161 | 257 | private ApiImportAgentSessionModel sessionModelWithMalformedAsyncAuthMode() { |
162 | 258 | return new ApiImportAgentSessionModel( |
163 | 259 | "session-1", |
|
0 commit comments