Class: PromptObjects::Universal::VerifyPrimitive
- Inherits:
-
Primitive
- Object
- Capability
- Primitive
- PromptObjects::Universal::VerifyPrimitive
- Defined in:
- lib/prompt_objects/universal/verify_primitive.rb
Overview
Universal capability to test primitives with sample inputs. Helps POs verify their primitives work correctly before relying on them.
Instance Attribute Summary
Attributes inherited from Capability
Instance Method Summary collapse
Methods inherited from Primitive
Methods inherited from Capability
#descriptor, execution_policy, execution_policy_definition, #execution_policy_definition, #execution_policy_signature, #initialize, #resolved_execution_policy
Constructor Details
This class inherits a constructor from PromptObjects::Primitive
Instance Method Details
#description ⇒ Object
12 13 14 |
# File 'lib/prompt_objects/universal/verify_primitive.rb', line 12 def description "Test a primitive with sample inputs to verify it works correctly. Useful after creating or modifying a primitive." end |
#name ⇒ Object
8 9 10 |
# File 'lib/prompt_objects/universal/verify_primitive.rb', line 8 def name "verify_primitive" end |
#parameters ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/prompt_objects/universal/verify_primitive.rb', line 16 def parameters { type: "object", properties: { name: { type: "string", description: "Name of the primitive to test" }, tests: { type: "array", description: "Array of test cases. Each test has 'input' (Hash of parameters), and optionally 'expected' (exact match) or 'expected_error' (true if expecting an error)", items: { type: "object", properties: { input: { type: "object", description: "Input parameters to pass to the primitive" }, expected: { description: "Expected output (for exact match)" }, expected_error: { type: "boolean", description: "Set to true if this test should produce an error" }, expected_contains: { type: "string", description: "String that should be contained in the output" } } } } }, required: ["name", "tests"] } end |
#receive(message, context:) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/prompt_objects/universal/verify_primitive.rb', line 53 def receive(, context:) prim_name = [:name] || ["name"] tests = [:tests] || ["tests"] || [] # Find the primitive primitive = context.env.registry.get(prim_name) unless primitive return "Error: Primitive '#{prim_name}' not found." end unless primitive.is_a?(Primitive) return "Error: '#{prim_name}' is not a primitive." end if tests.empty? return "Error: No test cases provided. Include at least one test with 'input' parameters." end # Run tests results = tests.map.with_index { |test, i| run_test(primitive, test, i, context) } # Summarize passed = results.count { |r| r[:passed] } failed = results.count { |r| !r[:passed] } format_results(prim_name, passed, failed, results) end |