Skip to content

Chore/remove old const behavior and refactor mocking#287

Merged
jlouvel merged 8 commits intomainfrom
chore/clean-up-remove-old-const-behavior
Apr 9, 2026
Merged

Chore/remove old const behavior and refactor mocking#287
jlouvel merged 8 commits intomainfrom
chore/clean-up-remove-old-const-behavior

Conversation

@jlouvel
Copy link
Copy Markdown
Contributor

@jlouvel jlouvel commented Apr 9, 2026

Related Issue

Closes #189


What does this PR do?

Adds mock mode to MCP tools (and strengthens the existing REST mock mode) via a new value field on MappedOutputParameter.

Design choice vs the issue proposal: The issue proposed a mock.output block. This PR uses value directly on output parameters instead — consistent with how ConsumedOutputParameter already uses value for JSONPath, and usable on both MCP and REST adapters without a separate mock-only key. The const field is preserved for JSON Schema validation and linting (Spectral) but no longer has any runtime effect.

Changes:

  • OutputParameterSpec — new value field; serializer/deserializer updated
  • Resolver.resolveOutputMappingsvalue takes precedence over mapping; Mustache templates in value resolved against input parameters
  • Resolver.buildMockData / buildMockValue — shared mock builder extracted into Resolver so REST and MCP use identical logic
  • ToolHandler — mock mode: when a tool has no call and no steps, output parameters with value fields are served directly (no consumes block needed)
  • ResourceRestlet — mock path delegates to shared Resolver.buildMockData; input parameters threaded through for Mustache resolution
  • HttpClientAdapter — headers use getValue() instead of getConstant()
  • naftiko-schema.jsonvalue added to MappedOutputParameterBase; const description updated to schema-only; oneOf constraints updated to mapping | value
  • Wiki (FAQ, Use Cases, Schema spec) — updated to document value and dynamic mock examples
  • Skill (naftiko-capability) — new mock-capability.md reference story; decision table and hard constraints updated

Tests

  • ResolverTest — 2 new tests: resolveOutputMappingsShouldResolveMustacheTemplatesInValue, resolveOutputMappingsShouldReturnRawValueWhenNoParameters
  • ResourceRestletTestbuildMockValueShouldHandleObjectArrayAndPrimitiveFallback, buildMockValueShouldResolveMustacheTemplatesInValue; existing mock tests updated to new signatures
  • ToolHandlerTest — 2 tests updated: no-call/no-steps tools now return mock response instead of throwing
  • AuthenticationIntegrationTest — inline YAML updated from const: "ok" to value: "ok"
  • OutputMappingExtensionTestsetConstantsetValue
  • All 415 tests pass, 0 failures

Checklist

  • CI is green (build, tests, schema validation, security scans)
  • Rebased on latest main
  • Small and focused — one concern per PR
  • Commit messages follow Conventional Commits

Agent Context (optional)

agent_name: GitHub Copilot
llm: Claude Sonnet 4.6
tool: VS Code Copilot Chat
confidence: high
source_event: user_request
discovery_method: user_report
review_focus: "Resolver.java:buildMockData/buildMockValue, ToolHandler.java:buildMockToolResult, naftiko-schema.json:MappedOutputParameterBase"

@jlouvel jlouvel requested a review from eskenazit April 9, 2026 01:14
@jlouvel jlouvel self-assigned this Apr 9, 2026
@jlouvel jlouvel mentioned this pull request Apr 9, 2026
4 tasks
@jlouvel jlouvel changed the title Chore/clean up remove old const behavior Chore/remove old const behavior and refactor mocking Apr 9, 2026
@jlouvel jlouvel mentioned this pull request Apr 9, 2026
4 tasks
@eskenazit eskenazit force-pushed the chore/clean-up-remove-old-const-behavior branch from 46a7f71 to 21a7bbf Compare April 9, 2026 10:05
@jlouvel jlouvel requested a review from eskenazit April 9, 2026 14:41
@jlouvel
Copy link
Copy Markdown
Contributor Author

jlouvel commented Apr 9, 2026

@eskenazit Should be good now :)

Copy link
Copy Markdown
Contributor

@eskenazit eskenazit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eskenazit
Copy link
Copy Markdown
Contributor

I cannot rebase the branch "due to conflicts" =/

jlouvel added 8 commits April 9, 2026 11:16
Replace runtime const injection with a dedicated value field on
MappedOutputParameter. The const field is now schema-only (validation
and linting); value handles static and Mustache-templated output at
runtime.

- Add value field to OutputParameterSpec with serializer/deserializer
- Resolver.resolveOutputMappings resolves Mustache templates in value
- ResourceRestlet mock responses use value with template resolution
- ToolHandler supports mock mode (no call/steps) via value fields
- HttpClientAdapter headers use getValue instead of getConstant
- Update naftiko-schema.json: add value, update oneOf constraints
- Update wiki: FAQ, Use Cases, Schema specification
…consistency

Extract buildMockData and buildMockValue from ResourceRestlet into
Resolver as shared static methods. Both REST (sendMockResponse) and
MCP (buildMockToolResult) now delegate to the same mock builder,
ensuring consistent Mustache resolution and structure handling.
Add mock-capability.md reference story covering static and dynamic
(Mustache) mock output parameters for both MCP and REST adapters.
Update SKILL.md decision table, add Mock workflow section, and add
hard constraints 17-18 for const vs value and Mustache scope rules.
Replace runtime const injection with a dedicated value field on
MappedOutputParameter. The const field is now schema-only (validation
and linting); value handles static and Mustache-templated output at
runtime.

- Add value field to OutputParameterSpec with serializer/deserializer
- Resolver.resolveOutputMappings resolves Mustache templates in value
- ResourceRestlet mock responses use value with template resolution
- ToolHandler supports mock mode (no call/steps) via value fields
- HttpClientAdapter headers use getValue instead of getConstant
- Update naftiko-schema.json: add value, update oneOf constraints
- Update wiki: FAQ, Use Cases, Schema specification
…consistency

Extract buildMockData and buildMockValue from ResourceRestlet into
Resolver as shared static methods. Both REST (sendMockResponse) and
MCP (buildMockToolResult) now delegate to the same mock builder,
ensuring consistent Mustache resolution and structure handling.
Nested object properties with 'value' (mock mode) were misrouted to
setMapping() because the property key was injected as 'name' into the
JSON node before the recursive dispatch, triggering the (value && name)
branch. Fix: set name on the spec after deserialization so the dispatch
logic sees the original node content.

Also fixes duplicate properties caused by processing the 'properties'
block twice.

Adds 3 regression tests covering nested value, nested mapping, and
consumed output parameter backward compatibility.
@jlouvel jlouvel force-pushed the chore/clean-up-remove-old-const-behavior branch from 100ca02 to 6145eca Compare April 9, 2026 18:57
@jlouvel jlouvel merged commit c94bb3d into main Apr 9, 2026
6 checks passed
@jlouvel jlouvel deleted the chore/clean-up-remove-old-const-behavior branch April 9, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Framework : Add mocking feature to MCP server adapter similar to REST server adapter

2 participants