This is an automated email from the ASF dual-hosted git repository. luigidemasi pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-kit.git
commit dd919911bb139101d8eb0bafa9bd97896449e431 Author: Jinal Sarvaiya <[email protected]> AuthorDate: Thu Nov 26 12:41:54 2026 +0000 fix: address critical DataMapper and Ship prompt issue --- docs/modules/ROOT/pages/camel-brainstorm.adoc | 4 +- docs/modules/ROOT/pages/greenfield.adoc | 4 +- .../camel/kit/ship/controller/ShipCoordinator.java | 72 +- .../camel-brainstorm/guides/design-assembly.md | 36 +- .../guides/greenfield-interview.md | 135 ++-- .../camel-design/guides/datamapper-interview.md | 20 +- .../skills/shared/datamapper-canonicalize.md | 4 +- .../skills/shared/interface-contract-briefing.md | 4 +- .../brainstorm/InterfaceContractDiscoveryTest.java | 721 +++++++++++++-------- 9 files changed, 622 insertions(+), 378 deletions(-) diff --git a/docs/modules/ROOT/pages/camel-brainstorm.adoc b/docs/modules/ROOT/pages/camel-brainstorm.adoc index 66a07148..f6831296 100644 --- a/docs/modules/ROOT/pages/camel-brainstorm.adoc +++ b/docs/modules/ROOT/pages/camel-brainstorm.adoc @@ -58,8 +58,8 @@ clarification at all. Open points are asked one at a time, never in batches, in . *Cross-cutting questions*: performance, security and monitoring when relevant, then remaining constraints and the deliberate scope exclusions. A category that does not apply is recorded as not applicable with the reason. -NOTE: Interface contract discovery is available in development snapshots only (0.5.0-SNAPSHOT and later). Released -versions (0.4.x) do not include this feature. +NOTE: Interface contract discovery is available in development snapshots (channel: {camel-kit-snapshot-version}) only. Released +versions ({camel-kit-version}) do not include this feature. .Topics the interview can cover, with example exchanges [%collapsible] diff --git a/docs/modules/ROOT/pages/greenfield.adoc b/docs/modules/ROOT/pages/greenfield.adoc index 582ffe45..d1c68538 100644 --- a/docs/modules/ROOT/pages/greenfield.adoc +++ b/docs/modules/ROOT/pages/greenfield.adoc @@ -49,8 +49,8 @@ should be designed together. Supplied contracts are inspected for compatibility question; pending contracts are recorded as explicit dependencies without placeholder definitions; new contracts for user-controlled endpoints are proposed in the design specification for approval before implementation. -NOTE: Interface contract discovery is available in development snapshots only (0.5.0-SNAPSHOT and later). Released -versions (0.4.x) do not include this feature. +NOTE: Interface contract discovery is available in development snapshots (channel: {camel-kit-snapshot-version}) only. Released +versions ({camel-kit-version}) do not include this feature. .Example exchanges from the interview [%collapsible] diff --git a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/ship/controller/ShipCoordinator.java b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/ship/controller/ShipCoordinator.java index da25d9b6..eeeded04 100644 --- a/kit/camel-kit-core/src/main/java/org/apache/camel/kit/ship/controller/ShipCoordinator.java +++ b/kit/camel-kit-core/src/main/java/org/apache/camel/kit/ship/controller/ShipCoordinator.java @@ -738,30 +738,56 @@ public final class ShipCoordinator { } } - // For DISCOVERY stage, include interface contract discovery rules + // For DISCOVERY stage, include interface contract discovery rules directly in prompt if (attempt.stage().stage() == Stage.DISCOVERY) { - text.append("\n## Interface Contract Discovery\n\n"); - try (InputStream resource = getClass().getResourceAsStream( - "/skills/shared/interface-contract-briefing.md")) { - if (resource != null) { - byte[] briefingContent = resource.readAllBytes(); - text.append(new String(briefingContent, StandardCharsets.UTF_8)) - .append('\n'); - } else { - // Fallback: minimal inline guidance if resource not found - text.append("For each integration boundary (source and destination), ") - .append("establish the interface contract status separately:\n\n") - .append("- Ask one boundary at a time (source, then destination)\n") - .append("- Analyze supplied material first (OpenAPI, AsyncAPI, WSDL, JSON Schema, XSD)\n") - .append("- Four statuses: existing, pending, designed, not-applicable\n") - .append("- Record pending contracts as dependencies (do NOT invent placeholders)\n") - .append("- Propose new contracts only for user-controlled endpoints\n") - .append("- Defer DataMapper if either contract is pending\n\n"); - } - } catch (IOException e) { - // If we can't load the briefing, continue without it - // The shared discovery-completeness.md will still apply - } + text.append("\n## Interface Contract Discovery\n\n") + .append("For each integration boundary (source and destination), establish the ") + .append("interface contract status separately:\n\n") + .append("### Ask One Boundary at a Time\n\n") + .append("1. **For the source** (where data comes from): Do you have an interface ") + .append("definition, will you provide one later, should we design it, or is it not applicable?\n") + .append("2. **For the destination** (where data goes): Do you have an interface ") + .append("definition, will you provide one later, should we design it, or is it not applicable?\n\n") + .append("### Analyze Supplied Material First\n\n") + .append("Before asking about a boundary's contract, check if the user already provided:\n") + .append("- OpenAPI specification\n") + .append("- AsyncAPI specification\n") + .append("- WSDL document\n") + .append("- JSON Schema\n") + .append("- XSD schema\n") + .append("- Documented message contract\n\n") + .append("If found, read it, extract constraints, record status as \"existing\", ") + .append("and skip the question for that boundary.\n\n") + .append("### Four Possible Statuses\n\n") + .append("**Status: existing** - Request artifact details (file path, URL, or inline content), ") + .append("contract type (OpenAPI/AsyncAPI/WSDL/JSON Schema/XSD/other), and compatibility constraints. ") + .append("Read and establish: schema version, required vs. optional fields, data type constraints, ") + .append("breaking vs. non-breaking policies. Record the artifact reference and all constraints.\n\n") + .append("**Status: pending** - Record dependency: \"[source/destination] contract must be provided ") + .append("before execution.\" Note: \"Detailed field-level design decisions remain open.\" ") + .append("Do NOT invent a placeholder contract. Defer DataMapper or field-level transformations ") + .append("that depend on this contract.\n\n") + .append("**Status: designed** - Propose contract definition based on requirements. Include in ") + .append("design specification for user approval before implementation. ONLY for user-controlled ") + .append("endpoints (never redesign external system interfaces). Specify contract type and present ") + .append("proposed schema.\n\n") + .append("**Status: not-applicable** - Record rationale for why no formal contract is needed. ") + .append("No further action required for this boundary.\n\n") + .append("### Record Both Boundaries\n\n") + .append("Capture separately:\n") + .append("- `source`: status, artifact, type, constraints, dependencies\n") + .append("- `destination`: status, artifact, type, constraints, dependencies\n\n") + .append("For conditional routing with multiple destinations, record one contract decision ") + .append("per distinct routing target.\n\n") + .append("### Recording in Ship Result\n\n") + .append("Record all interface contract findings in the `report` field of your result.\n") + .append("For each unresolved contract question, record it in `unansweredQuestions`.\n\n") + .append("Use the grouped `report` structure to capture:\n") + .append("- Analyzed material (what contracts were found in supplied requirements)\n") + .append("- Established contracts (status: existing, with artifact reference and constraints)\n") + .append("- Pending contracts (status: pending, with explicit dependency statement)\n") + .append("- Designed contracts (status: designed, with proposed schema for approval)\n") + .append("- Not applicable contracts (status: not-applicable, with rationale)\n\n"); requireBriefingSize(text); } diff --git a/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/design-assembly.md b/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/design-assembly.md index e1224f25..2c71e772 100644 --- a/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/design-assembly.md +++ b/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/design-assembly.md @@ -218,7 +218,7 @@ it. If the user identified no exclusions, write - Endpoint options: [key options from MCP catalog] - **Interface Contract:** [from flow.contracts.source] - Status: [existing / pending / designed / not-applicable] - - [If existing] Artifact: [file path or URL]; Type: [OpenAPI/AsyncAPI/WSDL/JSON Schema/XSD/other]; Constraints: [compatibility requirements] + - [If existing] Artifact: [file path, URL, or inline excerpt/reference]; Type: [OpenAPI/AsyncAPI/WSDL/JSON Schema/XSD/other]; Constraints: [compatibility requirements] - [If pending] **Dependency:** Source contract must be provided before execution. Field-level design decisions remain open. - [If designed] Proposed [contract-type] definition (see Appendix or inline below for the proposed schema awaiting approval) - [If not-applicable] No formal contract required @@ -246,7 +246,37 @@ it. If the user identified no exclusions, write - Groovy sections include `Transformation Engine: Groovy (inline)` and `Format Pair`; XSLT sections include the selected XSLT pattern/approach and structural mapping columns. -**Sink:** +**Conditional Routing:** (if applicable — use this instead of single Sink when Question 8a identified multiple routing targets) +- **Routing Logic:** [from flow.routing] + - Branch 1: [condition] → [destination-name] + - System: [name] + - Component: `[camel-component]` (MCP-verified) + - Action: [description] + - Endpoint options: [key options] + - **Interface Contract:** [from flow.routing.conditions[0].contract] + - Status: [existing / pending / designed / not-applicable] + - [If existing] Artifact: [file path, URL, or inline excerpt/reference]; Type: [OpenAPI/AsyncAPI/WSDL/JSON Schema/XSD/other]; Constraints: [compatibility requirements] + - [If pending] **Dependency:** Destination contract must be provided before execution. Field-level design decisions remain open. + - [If designed] Proposed [contract-type] definition (see Appendix or inline below for the proposed schema awaiting approval) + - [If not-applicable] No formal contract required + - Branch 2: [condition] → [destination-name] + - System: [name] + - Component: `[camel-component]` (MCP-verified) + - Action: [description] + - Endpoint options: [key options] + - **Interface Contract:** [from flow.routing.conditions[1].contract] + - Status: [existing / pending / designed / not-applicable] + - [If existing] Artifact: [file path, URL, or inline excerpt/reference]; Type: [OpenAPI/AsyncAPI/WSDL/JSON Schema/XSD/other]; Constraints: [compatibility requirements] + - [If pending] **Dependency:** Destination contract must be provided before execution. Field-level design decisions remain open. + - [If designed] Proposed [contract-type] definition (see Appendix or inline below for the proposed schema awaiting approval) + - [If not-applicable] No formal contract required + - [Repeat for each routing branch] + - Default: [destination-name or "none"] + - [Same structure as branches above, if applicable] + +Each branch's contract status is recorded separately. For example, Branch 1 may have an existing OpenAPI reference while Branch 2 has a pending schema dependency. The approved design preserves both statuses. + +**Sink:** (use only for single-destination flows — omit when Conditional Routing is present) - System: [name] - Component: `[camel-component]` (MCP-verified) - **Rationale:** [Why this component was chosen over alternatives] @@ -255,7 +285,7 @@ it. If the user identified no exclusions, write - Endpoint options: [key options from MCP catalog] - **Interface Contract:** [from flow.contracts.destination] - Status: [existing / pending / designed / not-applicable] - - [If existing] Artifact: [file path or URL]; Type: [OpenAPI/AsyncAPI/WSDL/JSON Schema/XSD/other]; Constraints: [compatibility requirements] + - [If existing] Artifact: [file path, URL, or inline excerpt/reference]; Type: [OpenAPI/AsyncAPI/WSDL/JSON Schema/XSD/other]; Constraints: [compatibility requirements] - [If pending] **Dependency:** Destination contract must be provided before execution. Field-level design decisions remain open. - [If designed] Proposed [contract-type] definition (see Appendix or inline below for the proposed schema awaiting approval) - [If not-applicable] No formal contract required diff --git a/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/greenfield-interview.md b/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/greenfield-interview.md index d1cf6a0b..066ac7c4 100644 --- a/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/greenfield-interview.md +++ b/kit/camel-kit-core/src/main/resources/skills/camel-brainstorm/guides/greenfield-interview.md @@ -280,43 +280,51 @@ Understood — no formal contract needed for this destination. Record: `flow.contracts.destination` with status (existing/pending/designed/na), artifact reference, constraints, and dependencies -### Question 7a: Data Transformation Detail (conditional) - -ONLY if field mapping needed AND format pair is XML/JSON combinations AND neither source nor destination contract is pending. +### Question 8: Sink System (per flow) -If either contract status is "pending", defer this question. Note in the design spec that field mapping depends on the pending contract and will be resolved when the artifact arrives. +``` +For flow "[flow-name]": +Where should the processed data go? +- System name (e.g., "PostgreSQL", "Fulfillment queue") +- Technology (e.g., SQL, Kafka, HTTP POST) +- Action (e.g., "INSERT INTO orders", "POST to /api/fulfillment") ``` -For the data transformation in "[flow-name]": -I'll need to understand the field mappings. Can you describe: -- Source fields and their paths -- Target fields and their paths -- Any transformation logic (concatenation, formatting, default values) +After response: note sink for MCP component verification. + +Record: `flow.sink.system`, `flow.sink.technology`, `flow.sink.action` + +### Question 8a: Multi-Path Routing (conditional) + +ONLY if user indicated multiple destinations or conditional routing. -Or if you have example source and target messages, share those. ``` +For the conditional routing in "[flow-name]": -Load `camel-design/guides/datamapper-interview.md` and `shared/datamapper-canonicalize.md` for detailed field mapping. +What are the routing conditions? +- Condition 1: [condition] → [destination] +- Condition 2: [condition] → [destination] +- Default: [destination] +``` -Record: `flow.datamapper.mappings[]` +Record: `flow.routing.conditions[]` + +### Question 8b: Routing Target Contracts (conditional) + +ONLY if Question 8a revealed multiple routing targets. For each distinct routing destination that was NOT already covered by Question 7c: + +Analyze supplied material first. If a contract artifact for this routing destination was already provided, read it, record status as "existing", extract constraints, and skip this question for that destination. -### Question 7b: Interface Contracts (per flow) +Reuse any answers already given in Question 7c. If Question 7c recorded a destination contract, apply it to the matching routing branch and skip asking about that branch. ``` -For flow "[flow-name]": +For the [destination-name] branch: -Do you have an interface definition for the source or destination, or should we design one? +Do you have an interface definition for this destination, or should we design one? Interface definitions include OpenAPI, AsyncAPI, WSDL, JSON Schema, XSD, or documented message contracts. -For the **source** (where data comes from): -a) Existing definition available now — I'll provide it -b) Definition will be supplied later -c) We should design it together -d) Not applicable (no formal contract needed) - -For the **destination** (where data goes): a) Existing definition available now — I'll provide it b) Definition will be supplied later c) We should design it together @@ -331,70 +339,61 @@ Please provide: - Any compatibility constraints or version requirements ``` -Read the supplied contract and establish: -- Schema version and compatibility requirements -- Required vs. optional fields -- Data type constraints -- Any breaking vs. non-breaking change policies +Read and establish: schema version, required vs. optional fields, data type constraints, breaking vs. non-breaking policies. -**For each "definition will be supplied later" answer:** -``` -Noted. The [source/destination] contract is pending. +**For "definition will be supplied later":** +Record dependency: "Destination contract for [branch-name] must be provided before execution. Field-level design decisions remain open." -This means: -- Detailed field-level design decisions will remain open -- The implementation plan will record this dependency -- You'll need to provide the contract before execution begins -``` +**For "we should design it together":** +Only for user-controlled endpoints. Propose contract definition in design spec for approval. -Record the dependency without inventing a placeholder contract. +**For "not applicable":** +Record rationale for why no formal contract is needed. -**For each "we should design it together" answer:** -``` -I'll propose a [contract-type] definition based on your requirements. +Record: `flow.routing.conditions[].contract` for each branch with status (existing/pending/designed/na), artifact references, constraints, and dependencies. -This will be included in the design specification for your approval before implementation. -Since this is a [source/destination] you control, we can design it to fit the integration needs. -``` +The design specification must carry each routing branch's contract status separately so pending schemas on one branch and existing contracts on another are both preserved in the approved design. -Note: Only propose designing contracts for systems under the user's control. External system interfaces cannot be redesigned. +### Question 7a: Data Transformation Detail (conditional) -**For "not applicable" answer:** -``` -Understood — no formal contract needed for this [source/destination]. -``` +ONLY if field mapping needed AND format pair is XML/JSON combinations. -Record: `flow.contracts.source`, `flow.contracts.destination` with status (existing/pending/designed/na), artifact references, constraints, and dependencies +Before proceeding, determine which mappings can be collected now: -### Question 8: Sink System (per flow) +**For single-destination flows:** +- Check source contract (`flow.contracts.source` from Q7b) and destination contract (`flow.contracts.destination` from Q7c) +- If BOTH source and destination have status "existing" or "designed", proceed with mapping +- If EITHER source or destination has status "pending", defer this mapping. Note in design spec: "Field mapping depends on pending [source/destination] contract and will be resolved when the artifact arrives" -``` -For flow "[flow-name]": +**For conditional routing flows:** +- Check source contract (`flow.contracts.source` from Q7b) +- For EACH routing branch, check that branch's destination contract (`flow.routing.conditions[].contract` from Q8b) +- Collect mapping for each branch where BOTH source and that branch's destination have status "existing" or "designed" +- Defer mapping for branches where source or that specific branch's destination has status "pending" +- Record each pending mapping dependency separately: "Field mapping for [branch-name] depends on pending [source/destination] contract" -Where should the processed data go? -- System name (e.g., "PostgreSQL", "Fulfillment queue") -- Technology (e.g., SQL, Kafka, HTTP POST) -- Action (e.g., "INSERT INTO orders", "POST to /api/fulfillment") -``` +If source contract is "pending", defer ALL mappings for this flow. -After response: note sink for MCP component verification. +``` +For the data transformation in "[flow-name]": -Record: `flow.sink.system`, `flow.sink.technology`, `flow.sink.action` +I'll need to understand the field mappings. Can you describe: +- Source fields and their paths +- Target fields and their paths +- Any transformation logic (concatenation, formatting, default values) -### Question 8a: Multi-Path Routing (conditional) +Or if you have example source and target messages, share those. +``` -ONLY if user indicated multiple destinations or conditional routing. +Pass any existing contract artifacts from Questions 7b, 7c, and 8b into DataMapper. The artifacts contain: +- Source schema (from Q7b if status is "existing" or "designed") +- Destination schema (from Q7c for single-destination, or from Q8b for each routing branch if status is "existing" or "designed") -``` -For the conditional routing in "[flow-name]": +Load `camel-design/guides/datamapper-interview.md` and `shared/datamapper-canonicalize.md` for detailed field mapping. When schema artifacts are provided, skip the schema request steps and use the provided schemas directly. Ask only for information not already available in the contract artifacts. -What are the routing conditions? -- Condition 1: [condition] → [destination] -- Condition 2: [condition] → [destination] -- Default: [destination] -``` +Record: `flow.datamapper.mappings[]` -Record: `flow.routing.conditions[]` +After completing DataMapper (or noting deferred mappings), return to Question 9. ### Question 9: Error Handling (per flow) diff --git a/kit/camel-kit-core/src/main/resources/skills/camel-design/guides/datamapper-interview.md b/kit/camel-kit-core/src/main/resources/skills/camel-design/guides/datamapper-interview.md index 38adb637..e9102b62 100644 --- a/kit/camel-kit-core/src/main/resources/skills/camel-design/guides/datamapper-interview.md +++ b/kit/camel-kit-core/src/main/resources/skills/camel-design/guides/datamapper-interview.md @@ -7,7 +7,9 @@ You are now acting as a **Data Mapping Specialist**. This guide is loaded by `camel-brainstorm` when the user mentions data transformation or field mapping and the format pair is XML→XML, JSON→JSON, JSON→XML, or XML→JSON. -Follow the steps below, then return control to `camel-brainstorm` at Question 8. +**Contract artifact references:** `camel-brainstorm` Question 7a passes any existing contract artifacts from Questions 7b, 7c, and 8b. Check for these references before asking for schemas in Steps 2-3. + +Follow the steps below, then return control to `camel-brainstorm` at Question 9. --- @@ -25,6 +27,14 @@ Is this correct? (yes / no — specify the correct pair) ## Step 2: Source Schema +**Check for existing artifact:** If `camel-brainstorm` Question 7b recorded a source contract with status "existing" or "designed", use that artifact reference. The contract includes: +- Artifact location (file path, URL, or inline content) +- Contract type (OpenAPI, AsyncAPI, WSDL, JSON Schema, XSD, other) + +If a source schema artifact is already available, extract the schema from the artifact and skip the request below. For OpenAPI/AsyncAPI, extract the message schema. For WSDL, extract the message XSD. For JSON Schema/XSD, use as-is. + +**If no source schema artifact is available from Q7b, ask:** + ``` Please provide the source schema. @@ -46,6 +56,14 @@ c) No schema — I'll describe the fields manually ## Step 3: Target Schema +**Check for existing artifact:** If `camel-brainstorm` Question 7c (single-destination) or Question 8b (conditional routing branch) recorded a destination contract with status "existing" or "designed", use that artifact reference. The contract includes: +- Artifact location (file path, URL, or inline content) +- Contract type (OpenAPI, AsyncAPI, WSDL, JSON Schema, XSD, other) + +If a target schema artifact is already available, extract the schema from the artifact and skip the request below. For OpenAPI/AsyncAPI, extract the message schema. For WSDL, extract the message XSD. For JSON Schema/XSD, use as-is. + +**If no target schema artifact is available from Q7c/Q8b, ask:** + ``` Please provide the target schema. diff --git a/kit/camel-kit-core/src/main/resources/skills/shared/datamapper-canonicalize.md b/kit/camel-kit-core/src/main/resources/skills/shared/datamapper-canonicalize.md index 785ce9c2..e8a32715 100644 --- a/kit/camel-kit-core/src/main/resources/skills/shared/datamapper-canonicalize.md +++ b/kit/camel-kit-core/src/main/resources/skills/shared/datamapper-canonicalize.md @@ -305,7 +305,7 @@ Omit the Collection Mappings section if there are no collection mappings. **When done:** return control to the calling guide. -- If called from `datamapper-interview.md`: return to `camel-brainstorm` at Question 8 (Sink System). +- If called from `datamapper-interview.md`: return to `camel-brainstorm` at Question 9 (Error Handling). - If called from `datamapper-migrate.md`: return to `camel-migrate-mule` Step 2.3. --- @@ -446,5 +446,5 @@ Omit the Collection Mappings section if there are no collection mappings. **When done:** return control to the calling guide. -- If called from `datamapper-interview.md`: return to `camel-brainstorm` at Question 8 (Sink System). +- If called from `datamapper-interview.md`: return to `camel-brainstorm` at Question 9 (Error Handling). - If called from `datamapper-migrate.md`: return to `camel-migrate-mule` Step 2.3. diff --git a/kit/camel-kit-core/src/main/resources/skills/shared/interface-contract-briefing.md b/kit/camel-kit-core/src/main/resources/skills/shared/interface-contract-briefing.md index 60a322f1..ce851add 100644 --- a/kit/camel-kit-core/src/main/resources/skills/shared/interface-contract-briefing.md +++ b/kit/camel-kit-core/src/main/resources/skills/shared/interface-contract-briefing.md @@ -13,7 +13,7 @@ For each integration boundary (source and destination), establish the interface 1. **For the source** (where data comes from): - Do you have an interface definition, will you provide one later, should we design it, or is it not applicable? - + 2. **For the destination** (where data goes): - Do you have an interface definition, will you provide one later, should we design it, or is it not applicable? @@ -21,7 +21,7 @@ For each integration boundary (source and destination), establish the interface Before asking about a boundary's contract, check if the user already provided: - OpenAPI specification -- AsyncAPI specification +- AsyncAPI specification - WSDL document - JSON Schema - XSD schema diff --git a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/brainstorm/InterfaceContractDiscoveryTest.java b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/brainstorm/InterfaceContractDiscoveryTest.java index 1761d54f..c0c38c58 100644 --- a/kit/camel-kit-core/src/test/java/org/apache/camel/kit/brainstorm/InterfaceContractDiscoveryTest.java +++ b/kit/camel-kit-core/src/test/java/org/apache/camel/kit/brainstorm/InterfaceContractDiscoveryTest.java @@ -10,332 +10,503 @@ import org.junit.jupiter.api.io.TempDir; import static org.junit.jupiter.api.Assertions.*; /** - * Behavioral tests for interface contract discovery (Issues #111 and #160). + * Workflow regression tests for interface contract discovery (Issues #111 and #160). * - * These tests verify that: 1. Supplied contracts are read first without re-asking 2. Missing contracts are asked about - * 3. Pending contracts are recorded as dependencies (not invented) 4. User-controlled contracts are proposed for - * approval 5. DataMapper is deferred when contracts are pending 6. Ship discovery includes contract rules + * These tests verify the actual greenfield interview behavior by checking that: 1. Questions appear in the correct + * order 2. Contract questions are split (source separate from destination) 3. DataMapper is deferred when contracts are + * pending 4. Routing targets trigger per-destination contract discovery 5. Ship DISCOVERY includes contract rules + * inline in the prompt + * + * Tests must FAIL if the interview structure regresses to the old combined Question 7b. */ -@DisplayName("Interface Contract Discovery") +@DisplayName("Interface Contract Discovery Workflow") class InterfaceContractDiscoveryTest { + private static final String GREENFIELD_INTERVIEW_PATH + = "src/main/resources/skills/camel-brainstorm/guides/greenfield-interview.md"; + private static final String SHIP_COORDINATOR_PATH + = "src/main/java/org/apache/camel/kit/ship/controller/ShipCoordinator.java"; + private static final String CONTRACT_BRIEFING_PATH + = "src/main/resources/skills/shared/interface-contract-briefing.md"; + @TempDir Path tempDir; @Test - @DisplayName("Should read supplied OpenAPI contract without re-asking") - void testSuppliedContractNotAskedAgain() throws Exception { - // Given: User provides an OpenAPI file in requirements - Path openapiFile = tempDir.resolve("api-spec.yaml"); - Files.writeString(openapiFile, """ - openapi: 3.0.1 - info: - title: Order API - version: 1.0.0 - paths: - /orders: - post: - summary: Create order - requestBody: - content: - application/json: - schema: - type: object - required: - - orderId - - amount - properties: - orderId: - type: string - amount: - type: number - """); - - // When: Interview analyzes supplied material - // Then: Contract status = "existing" - // Then: Question 7b for source is NOT asked - // Then: Artifact reference and constraints are extracted - - // Expected behavior verification: - // - Contract should be detected during material analysis - // - Status recorded as "existing" - // - No question asked about source contract - // - Compatibility constraints extracted from OpenAPI version - - assertTrue(Files.exists(openapiFile), "OpenAPI file should exist"); - String content = Files.readString(openapiFile); - assertTrue(content.contains("openapi: 3.0.1"), "Should contain OpenAPI version"); - assertTrue(content.contains("required"), "Should contain required fields"); + @DisplayName("Interview must have separate source and destination contract questions") + void testSeparateSourceAndDestinationQuestions() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + assertTrue(Files.exists(interviewPath), + "Greenfield interview file must exist at: " + GREENFIELD_INTERVIEW_PATH); + + String content = Files.readString(interviewPath); + + // Must have Question 7b for source + assertTrue(content.contains("### Question 7b: Source Interface Contract"), + "Question 7b must ask about SOURCE interface contract specifically"); + + // Must have Question 7c for destination + assertTrue(content.contains("### Question 7c: Destination Interface Contract"), + "Question 7c must ask about DESTINATION interface contract specifically"); + + // Must NOT have the old combined question + assertFalse( + content.contains("For the **source** (where data comes from):\na) Existing definition available now") + && content.contains( + "For the **destination** (where data goes):\na) Existing definition available now") + && content.indexOf("For the **source**") > content.indexOf("### Question 7b"), + "Must NOT contain old combined source+destination question after Question 7b"); } @Test - @DisplayName("Should ask about missing source contract") - void testMissingContractAsked() { - // Given: No contract provided in requirements + @DisplayName("Interview must NOT have duplicate Question 7b") + void testNoDuplicateQuestion7b() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); - // When: Interview reaches Question 7b for source - // Then: Question IS asked: "For the source, do you have an interface definition...?" + int firstOccurrence = content.indexOf("### Question 7b:"); + int secondOccurrence = content.indexOf("### Question 7b:", firstOccurrence + 1); - // Expected behavior: - // - Material analysis finds no contract - // - Question 7b for source is asked - // - User can choose: existing / pending / designed / not-applicable + assertEquals(-1, secondOccurrence, + "There must be exactly ONE Question 7b, not multiple instances"); + } + + @Test + @DisplayName("Question order must be: transformations → contracts → sink → routing → DataMapper") + void testQuestionOrder() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); + + int q7Index = content.indexOf("### Question 7: Transformations"); + int q7bIndex = content.indexOf("### Question 7b: Source Interface Contract"); + int q7cIndex = content.indexOf("### Question 7c: Destination Interface Contract"); + int q8Index = content.indexOf("### Question 8: Sink System"); + int q8aIndex = content.indexOf("### Question 8a: Multi-Path Routing"); + int q8bIndex = content.indexOf("### Question 8b: Routing Target Contracts"); + int q7aIndex = content.indexOf("### Question 7a: Data Transformation Detail"); + int q9Index = content.indexOf("### Question 9: Error Handling"); + + assertTrue(q7Index > 0, "Question 7 (Transformations) must exist"); + assertTrue(q7bIndex > 0, "Question 7b (Source Contract) must exist"); + assertTrue(q7cIndex > 0, "Question 7c (Destination Contract) must exist"); + assertTrue(q8Index > 0, "Question 8 (Sink) must exist"); + assertTrue(q8aIndex > 0, "Question 8a (Routing) must exist"); + assertTrue(q8bIndex > 0, "Question 8b (Routing Target Contracts) must exist"); + assertTrue(q7aIndex > 0, "Question 7a (DataMapper) must exist"); + assertTrue(q9Index > 0, "Question 9 (Error Handling) must exist"); + + assertTrue(q7Index < q7bIndex, + "Question 7 (Transformations) must come before 7b (Source Contract)"); + assertTrue(q7bIndex < q7cIndex, + "Question 7b (Source Contract) must come before 7c (Destination Contract)"); + assertTrue(q7cIndex < q8Index, + "Question 7c (Destination Contract) must come before 8 (Sink)"); + assertTrue(q8Index < q8aIndex, + "Question 8 (Sink) must come before 8a (Routing)"); + assertTrue(q8aIndex < q8bIndex, + "Question 8a (Routing) must come before 8b (Routing Target Contracts)"); + assertTrue(q8bIndex < q7aIndex, + "Question 8b (Routing Target Contracts) must come before 7a (DataMapper) - routing targets must be known before field mapping"); + assertTrue(q7aIndex < q9Index, + "Question 7a (DataMapper) must come before 9 (Error Handling)"); + } - // This test verifies the question is asked when no material is supplied - assertTrue(true, "Question 7b should be asked when no contract is supplied"); + @Test + @DisplayName("DataMapper must defer only mappings that depend on pending contracts") + void testDataMapperDefersOnlyAffectedMappings() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); + + int q7aIndex = content.indexOf("### Question 7a: Data Transformation Detail"); + int q9Index = content.indexOf("### Question 9: Error Handling"); + + String q7aSection = content.substring(q7aIndex, q9Index); + + // Must check per-mapping dependencies, not blanket defer + assertTrue( + q7aSection.contains("BOTH source and destination") + || q7aSection.contains("BOTH source and that branch"), + "Question 7a must check if BOTH source and destination are available for each mapping"); + + // Must collect mappings where both schemas are available + assertTrue(q7aSection.contains("Collect mapping for each branch where") + || q7aSection.contains("proceed with mapping"), + "Question 7a must collect mappings where both schemas are available"); + + // Must defer only specific mappings with pending dependencies + assertTrue(q7aSection.contains("Defer mapping for branches where") || q7aSection.contains("defer this mapping"), + "Question 7a must defer only mappings that depend on pending contracts"); + + // Must handle conditional routing per-branch + assertTrue(q7aSection.contains("For EACH routing branch") || q7aSection.contains("each branch"), + "Question 7a must handle conditional routing per-branch"); + + // Must record pending dependencies separately per branch + assertTrue(q7aSection.contains("Record each pending mapping dependency separately") + || q7aSection.contains("separately"), + "Question 7a must record each pending mapping dependency separately"); + + // Must defer all if source is pending + assertTrue(q7aSection.contains("If source contract is \"pending\", defer ALL"), + "Question 7a must defer all mappings if source contract is pending"); } @Test - @DisplayName("Should record pending contract as dependency without placeholder") - void testPendingContractRecordedAsDependency() { - // Given: User answers "definition will be supplied later" - - // When: Response is "b) Definition will be supplied later" - // Then: Status = "pending" - // Then: Dependency recorded: "destination contract must be provided before execution" - // Then: NO placeholder contract is invented - // Then: Field-level design decisions remain open - - // Expected in design spec: - // Interface Contract: - // - Status: pending - // - Dependency: Destination contract must be provided before execution. - // Field-level design decisions remain open. - - // Verify NO placeholder like this appears: - // ❌ WRONG: "schema": { "type": "object", "properties": {} } - - assertTrue(true, "Pending contract should be recorded as dependency"); + @DisplayName("DataMapper must consume artifact references and return to Q9") + void testDataMapperConsumesArtifactsAndReturnsToQ9() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); + + int q7aIndex = content.indexOf("### Question 7a: Data Transformation Detail"); + int q9Index = content.indexOf("### Question 9: Error Handling"); + String q7aSection = content.substring(q7aIndex, q9Index); + + // Must pass artifact references to DataMapper + assertTrue(q7aSection.contains("Pass any existing contract artifacts") + || q7aSection.contains("Pass") && q7aSection.contains("artifact"), + "Question 7a must pass existing contract artifacts to DataMapper"); + + assertTrue(q7aSection.contains("Questions 7b, 7c, and 8b") || (q7aSection.contains("7b") + && q7aSection.contains("7c") && q7aSection.contains("8b")), + "Question 7a must reference artifacts from Questions 7b, 7c, and 8b"); + + // Must skip schema request steps when artifacts are provided + assertTrue(q7aSection.contains("skip the schema request steps") + || q7aSection.contains("use the provided schemas directly"), + "Question 7a must tell DataMapper to skip schema requests when artifacts are provided"); + + // Must ask only for missing information + assertTrue(q7aSection.contains("Ask only for information not already") + || q7aSection.contains("not already available"), + "Question 7a must ask only for information not already in contract artifacts"); + + // Must return to Question 9 + assertTrue(q7aSection.contains("return to Question 9"), + "Question 7a must explicitly return to Question 9 after completion"); } @Test - @DisplayName("Should propose user-controlled contract for approval") - void testUserControlledContractProposed() { - // Given: User answers "we should design it together" - // And: Endpoint is user-controlled (not external) - - // When: Response is "c) We should design it together" - // Then: Status = "designed" - // Then: Proposed contract included in design spec - // Then: Awaits user approval before implementation - - // Expected in design spec: - // Interface Contract: - // - Status: designed - // - Proposed JSON Schema definition (see Appendix or inline below) - // - [User must approve this schema in design approval] - - assertTrue(true, "New contract should be proposed for user approval"); + @DisplayName("DataMapper interview must consume artifact references from Q7a") + void testDataMapperInterviewConsumesReferences() throws Exception { + Path datamapperPath = Path.of("src/main/resources/skills/camel-design/guides/datamapper-interview.md"); + assertTrue(Files.exists(datamapperPath), "DataMapper interview must exist"); + + String content = Files.readString(datamapperPath); + + // Must mention contract artifact references from Q7a + assertTrue(content.contains("Contract artifact references") || content.contains("Question 7a passes"), + "DataMapper interview must acknowledge contract artifact references from Q7a"); + + // Must check for existing artifacts in Step 2 (Source Schema) + int step2Index = content.indexOf("## Step 2: Source Schema"); + int step3Index = content.indexOf("## Step 3: Target Schema"); + String step2Section = content.substring(step2Index, step3Index); + + assertTrue(step2Section.contains("Check for existing artifact") || step2Section.contains("already available"), + "Step 2 must check for existing source artifact from Q7b"); + + assertTrue(step2Section.contains("Question 7b") || step2Section.contains("Q7b"), + "Step 2 must reference Question 7b for source artifact"); + + assertTrue(step2Section.contains("skip the request") || step2Section.contains("skip"), + "Step 2 must skip schema request if artifact is available"); + + // Must check for existing artifacts in Step 3 (Target Schema) + int step3bIndex = content.indexOf("## Step 3b:"); + String step3Section = content.substring(step3Index, step3bIndex); + + assertTrue(step3Section.contains("Check for existing artifact") || step3Section.contains("already available"), + "Step 3 must check for existing target artifact from Q7c/Q8b"); + + assertTrue((step3Section.contains("Question 7c") || step3Section.contains("Q7c")) + && (step3Section.contains("Question 8b") || step3Section.contains("Q8b")), + "Step 3 must reference Question 7c and Question 8b for target artifact"); + + assertTrue(step3Section.contains("skip the request") || step3Section.contains("skip"), + "Step 3 must skip schema request if artifact is available"); + + // Must return to Question 9 + assertTrue(content.contains("return control to `camel-brainstorm` at Question 9"), + "DataMapper interview must return to Question 9"); } @Test - @DisplayName("Should NOT propose to redesign external system interface") - void testExternalInterfaceNotRedesigned() { - // Given: Destination is external system (e.g., third-party API) - // And: User answers "we should design it together" + @DisplayName("DataMapper canonicalize must return to Question 9") + void testDataMapperCanonicalizeReturnsToQ9() throws Exception { + Path canonicalizePath = Path.of("src/main/resources/skills/shared/datamapper-canonicalize.md"); + assertTrue(Files.exists(canonicalizePath), "DataMapper canonicalize must exist"); - // When: System detects endpoint is NOT user-controlled - // Then: Warn or reject: "Cannot redesign external system interface" - // Then: Suggest: existing / pending / not-applicable instead + String content = Files.readString(canonicalizePath); - assertTrue(true, "External interfaces cannot be redesigned"); + // Must return to Question 9, not Question 8 + assertTrue(content.contains("return to `camel-brainstorm` at Question 9"), + "DataMapper canonicalize must return to Question 9"); + + assertFalse(content.contains("return to `camel-brainstorm` at Question 8"), + "DataMapper canonicalize must NOT return to Question 8"); } @Test - @DisplayName("Should defer DataMapper when source contract is pending") - void testDataMapperDeferredWhenSourcePending() { - // Given: Source contract status = "pending" - // And: Transformation includes field mapping - - // When: Interview reaches Question 7a (DataMapper) - // Then: Check source contract status - // Then: Status is "pending" - // Then: Skip Question 7a - // Then: Note in design spec: "Field mapping depends on pending source contract" - - // Expected flow: - // Question 7: Transformations → field mapping selected - // Question 7b: Source contract → pending - // Question 7c: Destination contract → existing - // Question 7a: DataMapper → SKIPPED (source pending) - // Question 8: Sink System - - assertTrue(true, "DataMapper should be deferred when source contract is pending"); + @DisplayName("Question 8b must reuse Q7c answers and analyze supplied material first") + void testRoutingTargetContractsReuseAnswers() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); + + int q8bIndex = content.indexOf("### Question 8b: Routing Target Contracts"); + int q7aIndex = content.indexOf("### Question 7a: Data Transformation Detail"); + String q8bSection = content.substring(q8bIndex, q7aIndex); + + // Must analyze supplied material first + assertTrue(q8bSection.contains("Analyze supplied material first"), + "Question 8b must analyze supplied material first"); + + // Must reuse Q7c answers + assertTrue(q8bSection.contains("Reuse any answers already given in Question 7c") + || q8bSection.contains("Reuse") && q8bSection.contains("7c"), + "Question 8b must reuse answers already given in Question 7c"); + + // Must skip asking if already recorded + assertTrue(q8bSection.contains("skip") || q8bSection.contains("Skip"), + "Question 8b must skip asking about destinations already recorded in Q7c"); + } + + @Test + @DisplayName("Interview must have routing target contract question after Question 8a") + void testRoutingTargetContractQuestion() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); + + int q8aIndex = content.indexOf("### Question 8a: Multi-Path Routing"); + assertTrue(q8aIndex > 0, "Question 8a (Routing) must exist"); + + int q8bIndex = content.indexOf("### Question 8b: Routing Target Contracts"); + assertTrue(q8bIndex > 0, + "Question 8b (Routing Target Contracts) must exist for conditional routing scenarios"); + + assertTrue(q8aIndex < q8bIndex, + "Question 8b (Routing Target Contracts) must come after 8a (Multi-Path Routing)"); + + int q9Index = content.indexOf("### Question 9: Error Handling"); + assertTrue(q8bIndex < q9Index, + "Question 8b must come before Question 9 (Error Handling)"); + + // Verify it handles per-destination contracts + String q8bSection = content.substring(q8bIndex, content.indexOf("### Question 7a")); + assertTrue(q8bSection.contains("distinct routing destination") || q8bSection.contains("each distinct"), + "Question 8b must ask about each distinct routing destination"); + assertTrue(q8bSection.contains("flow.routing.conditions[].contract"), + "Question 8b must record contract per routing branch"); + } + + @Test + @DisplayName("Ship DISCOVERY must include contract rules directly in controller-issued prompt") + void testShipDiscoveryPromptIncludesInlineRules() throws Exception { + Path shipCoordinatorPath = Path.of(SHIP_COORDINATOR_PATH); + assertTrue(Files.exists(shipCoordinatorPath), + "ShipCoordinator.java must exist at: " + SHIP_COORDINATOR_PATH); + + String content = Files.readString(shipCoordinatorPath); + + assertTrue(content.contains("Stage.DISCOVERY"), + "ShipCoordinator must have DISCOVERY stage handling"); + + // Rules must be inline in text.append() calls + assertTrue(content.contains("Interface Contract Discovery"), + "DISCOVERY prompt must contain Interface Contract Discovery heading"); + + assertTrue(content.contains("Ask One Boundary") && content.contains("text.append"), + "DISCOVERY prompt must contain inline 'Ask One Boundary at a Time' rule"); + + assertTrue(content.contains("Analyze Supplied Material") && content.contains("text.append"), + "DISCOVERY prompt must contain inline 'Analyze Supplied Material First' rule"); + + assertTrue(content.contains("Four Possible Statuses") && content.contains("text.append"), + "DISCOVERY prompt must contain inline 'Four Possible Statuses' rule"); + + assertTrue(content.contains("Status: existing") && content.contains("Status: pending"), + "DISCOVERY prompt must define status values inline"); + } + + @Test + @DisplayName("Ship DISCOVERY prompt must tell worker to record in report and unansweredQuestions") + void testShipDiscoveryRecordingInstructions() throws Exception { + Path shipCoordinatorPath = Path.of(SHIP_COORDINATOR_PATH); + String content = Files.readString(shipCoordinatorPath); + + assertTrue(content.contains("Stage.DISCOVERY"), "DISCOVERY stage handling must exist"); + + // Must tell worker to record in report and unansweredQuestions + assertTrue(content.contains("report") && content.contains("unansweredQuestions"), + "DISCOVERY prompt must mention 'report' and 'unansweredQuestions' fields"); + + assertTrue(content.contains("Record all interface contract findings"), + "DISCOVERY prompt must instruct to record contract findings"); + + assertTrue(content.contains("Recording in Ship Result") || content.contains("Recording"), + "DISCOVERY prompt must have recording instructions section"); } @Test - @DisplayName("Should defer DataMapper when destination contract is pending") - void testDataMapperDeferredWhenDestinationPending() { - // Given: Destination contract status = "pending" - // And: Transformation includes field mapping - - // When: Interview reaches Question 7a (DataMapper) - // Then: Check destination contract status - // Then: Status is "pending" - // Then: Skip Question 7a - // Then: Note in design spec: "Field mapping depends on pending destination contract" - - assertTrue(true, "DataMapper should be deferred when destination contract is pending"); + @DisplayName("Contract briefing must define four statuses") + void testContractBriefingDefinesFourStatuses() throws Exception { + Path briefingPath = Path.of(CONTRACT_BRIEFING_PATH); + assertTrue(Files.exists(briefingPath), + "Contract briefing must exist at: " + CONTRACT_BRIEFING_PATH); + + String content = Files.readString(briefingPath); + + assertTrue(content.contains("Status: existing") || content.contains("**Status: existing**"), + "Briefing must define 'existing' status"); + assertTrue(content.contains("Status: pending") || content.contains("**Status: pending**"), + "Briefing must define 'pending' status"); + assertTrue(content.contains("Status: designed") || content.contains("**Status: designed**"), + "Briefing must define 'designed' status"); + assertTrue(content.contains("Status: not-applicable") || content.contains("**Status: not-applicable**"), + "Briefing must define 'not-applicable' status"); } @Test - @DisplayName("Should run DataMapper when both contracts are available") - void testDataMapperRunsWhenContractsAvailable() { - // Given: Source contract status = "existing" - // And: Destination contract status = "existing" - // And: Transformation includes field mapping - - // When: Interview reaches Question 7a (DataMapper) - // Then: Neither source nor destination is pending - // Then: Question 7a IS asked - // Then: DataMapper interview proceeds normally - - assertTrue(true, "DataMapper should run when both contracts are available"); + @DisplayName("Contract briefing must prohibit inventing placeholder contracts") + void testContractBriefingProhibitsPlaceholders() throws Exception { + Path briefingPath = Path.of(CONTRACT_BRIEFING_PATH); + String content = Files.readString(briefingPath); + + assertTrue(content.contains("Do NOT invent") || content.contains("do not invent") + || content.contains("NOT invent a placeholder"), + "Briefing must explicitly prohibit inventing placeholder contracts"); } @Test - @DisplayName("Should handle mixed scenario: existing source + designed destination") - void testMixedExistingAndDesigned() throws Exception { - // Given: Source has existing OpenAPI - Path sourceApi = tempDir.resolve("source-api.yaml"); - Files.writeString(sourceApi, "openapi: 3.0.1\ninfo:\n title: Source API"); - - // And: Destination is user-controlled, to be designed - - // When: Interview processes both - // Then: Source status = "existing", artifact extracted - // Then: Source question skipped (already supplied) - // Then: Destination question asked - // Then: User chooses "design together" - // Then: Destination status = "designed" - // Then: Proposed schema included in design spec - - assertTrue(Files.exists(sourceApi), "Source API should be provided"); - assertTrue(true, "Mixed existing + designed scenario should work"); + @DisplayName("Contract briefing must require asking source and destination separately") + void testContractBriefingRequiresSeparateQuestions() throws Exception { + Path briefingPath = Path.of(CONTRACT_BRIEFING_PATH); + String content = Files.readString(briefingPath); + + assertTrue(content.contains("one boundary at a time") || content.contains("separately"), + "Briefing must require asking about source and destination separately"); + assertTrue(content.contains("source") && content.contains("destination"), + "Briefing must mention both source and destination"); } @Test - @DisplayName("Should handle mixed scenario: existing source + pending destination") - void testMixedExistingAndPending() throws Exception { - // Given: Source has existing OpenAPI - Path sourceApi = tempDir.resolve("source-api.yaml"); - Files.writeString(sourceApi, "openapi: 3.0.1\ninfo:\n title: Source API"); - - // And: Destination contract will be supplied later - - // When: Interview processes both - // Then: Source status = "existing" - // Then: Destination status = "pending" - // Then: Destination dependency recorded - // Then: NO DataMapper (destination pending) - - assertTrue(Files.exists(sourceApi), "Source API should be provided"); - assertTrue(true, "Mixed existing + pending scenario should work"); + @DisplayName("Design template must support inline contract excerpts") + void testDesignTemplateSupportsInlineExcerpts() throws Exception { + Path designTemplatePath = Path.of( + "src/main/resources/skills/camel-brainstorm/guides/design-assembly.md"); + assertTrue(Files.exists(designTemplatePath), + "Design assembly template must exist"); + + String content = Files.readString(designTemplatePath); + + // Check both Source and Sink Interface Contract sections + assertTrue(content.contains("inline excerpt") || content.contains("inline content"), + "Design template must allow inline contract excerpts, not just file paths or URLs"); } @Test - @DisplayName("Should include contract rules in Ship DISCOVERY prompt") - void testShipDiscoveryIncludesContractRules() { - // Given: Ship controller generates DISCOVERY task - - // When: DISCOVERY prompt is created - // Then: Include interface-contract-briefing.md - // Then: Include per-boundary rules (source and destination separately) - // Then: Preserve Ship's grouped question format - // Then: Maintain controller-owned oversight - - // Expected in Ship DISCOVERY prompt: - // - Reference to shared/interface-contract-briefing.md - // - Per-boundary contract discovery instructions - // - Structured result schema for contract status - // - Ship-specific grouped question approach - - assertTrue(true, "Ship DISCOVERY should include contract discovery rules"); + @DisplayName("Design template must preserve per-branch contract statuses for conditional routing") + void testDesignTemplatePreservesPerBranchContracts() throws Exception { + Path designTemplatePath = Path.of( + "src/main/resources/skills/camel-brainstorm/guides/design-assembly.md"); + String content = Files.readString(designTemplatePath); + + // Must have Conditional Routing section + assertTrue(content.contains("**Conditional Routing:**"), + "Design template must have Conditional Routing section for multi-destination flows"); + + // Must show per-branch structure + assertTrue(content.contains("Branch 1:") && content.contains("Branch 2:"), + "Conditional Routing section must show per-branch structure"); + + // Each branch must have its own Interface Contract field + int conditionalRoutingIndex = content.indexOf("**Conditional Routing:**"); + int sinkIndex = content.indexOf("**Sink:**", conditionalRoutingIndex); + String conditionalSection = content.substring(conditionalRoutingIndex, sinkIndex); + + // Count Interface Contract occurrences in conditional routing section + int contractCount = 0; + int index = 0; + while ((index = conditionalSection.indexOf("**Interface Contract:**", index)) != -1) { + contractCount++; + index += "**Interface Contract:**".length(); + } + + assertTrue(contractCount >= 2, + "Conditional Routing section must have Interface Contract for each branch (found " + contractCount + + ", expected >= 2)"); + + // Must reference flow.routing.conditions[].contract + assertTrue(content.contains("flow.routing.conditions[0].contract") + || content.contains("flow.routing.conditions[1].contract"), + "Design template must reference flow.routing.conditions[].contract for per-branch contracts"); + + // Must explain that each branch's contract is recorded separately + assertTrue(content.contains("separately") || content.contains("Branch 1 may have") + || content.contains("preserves both"), + "Design template must explain that per-branch contracts are preserved separately"); } @Test - @DisplayName("Should extract compatibility constraints from existing contract") - void testCompatibilityConstraintsExtracted() throws Exception { - // Given: OpenAPI with specific version and constraints - Path openapiFile = tempDir.resolve("api-with-constraints.yaml"); - Files.writeString(openapiFile, """ - openapi: 3.0.1 - info: - title: Order API - version: 2.1.0 - x-breaking-changes: false - servers: - - url: https://api.example.com/v2 - paths: - /orders: - post: - requestBody: - required: true - """); - - // When: Contract is analyzed - // Then: Extract version: 2.1.0 - // Then: Extract breaking changes policy: false - // Then: Extract required fields - // Then: Record in design spec constraints section - - String content = Files.readString(openapiFile); - assertTrue(content.contains("version: 2.1.0"), "Should extract version"); - assertTrue(content.contains("required: true"), "Should extract required constraints"); - assertTrue(true, "Compatibility constraints should be extracted and recorded"); + @DisplayName("Interview must record contract status for both source and destination") + void testInterviewRecordsBothContracts() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); + + assertTrue(content.contains("flow.contracts.source"), + "Interview must record flow.contracts.source"); + assertTrue(content.contains("flow.contracts.destination"), + "Interview must record flow.contracts.destination"); } @Test - @DisplayName("Should preserve question order: transformations → source contract → dest contract → DataMapper → sink") - void testQuestionOrderPreserved() { - // Expected order for per-flow questions: - // Question 5: Flow Intent and Data - // Question 6: Source System - // Question 7: Transformations - // Question 7b: Source Interface Contract - // Question 7c: Destination Interface Contract - // Question 7a: Data Transformation Detail (DataMapper) - CONDITIONAL - // Question 8: Sink System - // Question 8a: Multi-Path Routing - CONDITIONAL - // Question 9: Error Handling - - // This order ensures: - // 1. Contracts are established BEFORE DataMapper - // 2. DataMapper can check if contracts are pending - // 3. DataMapper return goes to Question 8 (sink) as expected - - assertTrue(true, "Question order should be: transformations → contracts → DataMapper → sink"); + @DisplayName("Contract briefing must require analyzing supplied material first") + void testContractBriefingRequiresAnalysisFirst() throws Exception { + Path briefingPath = Path.of(CONTRACT_BRIEFING_PATH); + String content = Files.readString(briefingPath); + + assertTrue(content.contains("Analyze") || content.contains("analyze"), + "Briefing must require analyzing supplied material"); + assertTrue(content.contains("First") || content.contains("first") || content.contains("Before asking"), + "Briefing must require analysis BEFORE asking questions"); + + // Must list supported contract types + assertTrue(content.contains("OpenAPI") && content.contains("AsyncAPI") + && content.contains("WSDL") && content.contains("JSON Schema") + && content.contains("XSD"), + "Briefing must list all supported contract types"); } @Test - @DisplayName("Should record contract information in design spec flow section") - void testContractInDesignSpec() { - // Given: Flow with contracts discovered - - // When: design-assembly.md generates design spec - // Then: Source section includes Interface Contract - // Then: Sink section includes Interface Contract - // Then: Each shows: status, artifact (if existing), dependency (if pending), proposed def (if designed) - - // Expected format in design spec Section 3 (Flow Designs): - // - // **Source:** - // - System: Shopify - // - Component: `camel-http` - // - Interface Contract: - // - Status: existing - // - Artifact: api/shopify-orders.yaml - // - Type: OpenAPI 3.0.1 - // - Constraints: Breaking changes not allowed, all requests require authentication - // - // **Sink:** - // - System: Internal Event Bus - // - Component: `camel-kafka` - // - Interface Contract: - // - Status: designed - // - Proposed JSON Schema definition (see below) - // - [Awaiting user approval in design review] - - assertTrue(true, "Contract information should appear in design spec flow sections"); + @DisplayName("Interview contract questions must support all four answer options") + void testContractQuestionsSupportAllOptions() throws Exception { + Path interviewPath = Path.of(GREENFIELD_INTERVIEW_PATH); + String content = Files.readString(interviewPath); + + int q7bIndex = content.indexOf("### Question 7b:"); + int q7cIndex = content.indexOf("### Question 7c:"); + + assertTrue(q7bIndex > 0 && q7cIndex > 0, "Both contract questions must exist"); + + // Check Question 7b section + String q7bSection = content.substring(q7bIndex, q7cIndex); + assertTrue(q7bSection.contains("Existing definition available now"), + "Question 7b must have 'existing' option"); + assertTrue(q7bSection.contains("Definition will be supplied later"), + "Question 7b must have 'pending' option"); + assertTrue(q7bSection.contains("We should design it together"), + "Question 7b must have 'designed' option"); + assertTrue(q7bSection.contains("Not applicable"), + "Question 7b must have 'not-applicable' option"); + + // Check Question 7c section + String q7cSection = content.substring(q7cIndex, content.indexOf("### Question 8")); + assertTrue(q7cSection.contains("Existing definition available now"), + "Question 7c must have 'existing' option"); + assertTrue(q7cSection.contains("Definition will be supplied later"), + "Question 7c must have 'pending' option"); + assertTrue(q7cSection.contains("We should design it together"), + "Question 7c must have 'designed' option"); + assertTrue(q7cSection.contains("Not applicable"), + "Question 7c must have 'not-applicable' option"); } }
