agentic-lang 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMMUNITY.md +220 -0
- package/CONTRIBUTING.md +194 -0
- package/FINAL_REPORT.md +398 -0
- package/FOR_OTHER_LLMS.md +286 -0
- package/IMPROVEMENTS.md +319 -0
- package/LAUNCH_GUIDE.md +388 -0
- package/LICENSE +21 -0
- package/NPM_PUBLISH.md +257 -0
- package/PROJECT_COMPLETE.md +414 -0
- package/PROJECT_OVERVIEW.md +265 -0
- package/PROJECT_TREE.txt +228 -0
- package/PUBLISHING_GUIDE.md +426 -0
- package/PUBLISH_NOW.md +337 -0
- package/QUICKSTART.md +207 -0
- package/README.md +195 -0
- package/README_ENHANCED.md +329 -0
- package/READY_TO_LAUNCH.txt +56 -0
- package/REFACTOR_PLAN.md +179 -0
- package/ROADMAP.md +201 -0
- package/SUMMARY.md +315 -0
- package/bin/agentic.js +3 -0
- package/blog/001-introducing-agentic.md +382 -0
- package/blog/002-confidence-driven-development.md +490 -0
- package/blog/003-formal-verification.md +427 -0
- package/blog/004-multi-agent-production.md +436 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +151 -0
- package/dist/cli.js.map +1 -0
- package/dist/diagnostics/diagnostic.d.ts +115 -0
- package/dist/diagnostics/diagnostic.d.ts.map +1 -0
- package/dist/diagnostics/diagnostic.js +101 -0
- package/dist/diagnostics/diagnostic.js.map +1 -0
- package/dist/diagnostics/formatter.d.ts +36 -0
- package/dist/diagnostics/formatter.d.ts.map +1 -0
- package/dist/diagnostics/formatter.js +263 -0
- package/dist/diagnostics/formatter.js.map +1 -0
- package/dist/effects/effect-system.d.ts +64 -0
- package/dist/effects/effect-system.d.ts.map +1 -0
- package/dist/effects/effect-system.js +197 -0
- package/dist/effects/effect-system.js.map +1 -0
- package/dist/generator/typescript-generator.d.ts +31 -0
- package/dist/generator/typescript-generator.d.ts.map +1 -0
- package/dist/generator/typescript-generator.js +308 -0
- package/dist/generator/typescript-generator.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/lean4/exporter.d.ts +24 -0
- package/dist/lean4/exporter.d.ts.map +1 -0
- package/dist/lean4/exporter.js +142 -0
- package/dist/lean4/exporter.js.map +1 -0
- package/dist/lsp/server.d.ts +6 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +131 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/parser/lexer.d.ts +79 -0
- package/dist/parser/lexer.d.ts.map +1 -0
- package/dist/parser/lexer.js +296 -0
- package/dist/parser/lexer.js.map +1 -0
- package/dist/parser/parser-enhanced.d.ts +12 -0
- package/dist/parser/parser-enhanced.d.ts.map +1 -0
- package/dist/parser/parser-enhanced.js +206 -0
- package/dist/parser/parser-enhanced.js.map +1 -0
- package/dist/parser/parser.d.ts +34 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +507 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/property-tests/generator-enhanced.d.ts +27 -0
- package/dist/property-tests/generator-enhanced.d.ts.map +1 -0
- package/dist/property-tests/generator-enhanced.js +209 -0
- package/dist/property-tests/generator-enhanced.js.map +1 -0
- package/dist/property-tests/generator-fixed.d.ts +2 -0
- package/dist/property-tests/generator-fixed.d.ts.map +1 -0
- package/dist/property-tests/generator-fixed.js +7 -0
- package/dist/property-tests/generator-fixed.js.map +1 -0
- package/dist/property-tests/generator.d.ts +28 -0
- package/dist/property-tests/generator.d.ts.map +1 -0
- package/dist/property-tests/generator.js +284 -0
- package/dist/property-tests/generator.js.map +1 -0
- package/dist/refinements/refinement-types.d.ts +96 -0
- package/dist/refinements/refinement-types.d.ts.map +1 -0
- package/dist/refinements/refinement-types.js +234 -0
- package/dist/refinements/refinement-types.js.map +1 -0
- package/dist/repl.d.ts +21 -0
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +317 -0
- package/dist/repl.js.map +1 -0
- package/dist/runtime/agents.d.ts +97 -0
- package/dist/runtime/agents.d.ts.map +1 -0
- package/dist/runtime/agents.js +258 -0
- package/dist/runtime/agents.js.map +1 -0
- package/dist/runtime/index.d.ts +98 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +253 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/types-extended.d.ts +197 -0
- package/dist/types-extended.d.ts.map +1 -0
- package/dist/types-extended.js +7 -0
- package/dist/types-extended.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/verification/z3-engine.d.ts +75 -0
- package/dist/verification/z3-engine.d.ts.map +1 -0
- package/dist/verification/z3-engine.js +234 -0
- package/dist/verification/z3-engine.js.map +1 -0
- package/examples/advanced-features.agentic +98 -0
- package/examples/annotations.agentic +37 -0
- package/examples/auth.agentic +53 -0
- package/examples/enterprise-example.agentic +360 -0
- package/examples/minimal.agentic +3 -0
- package/examples/minimal.ts +7 -0
- package/examples/ml-pipeline.agentic +350 -0
- package/examples/multi-agent-example.agentic +212 -0
- package/examples/onboarding-tutorial.agentic +263 -0
- package/examples/production-api.agentic +304 -0
- package/examples/real-world-chatbot.agentic +351 -0
- package/examples/result-handling.agentic +34 -0
- package/examples/runtime.ts +24 -0
- package/examples/showcase.agentic +22 -0
- package/examples/showcase.ts +28 -0
- package/examples/simple-test.agentic +4 -0
- package/examples/simple-test.ts +7 -0
- package/examples/simple.agentic +20 -0
- package/examples/test2.agentic +4 -0
- package/examples/test2.ts +9 -0
- package/examples/test3.agentic +4 -0
- package/examples/test3.ts +9 -0
- package/package.json +70 -0
- package/playground/index.html +221 -0
- package/playground/playground.js +291 -0
- package/registry/package-registry.ts +319 -0
- package/scripts/build.js +50 -0
- package/scripts/validate-confidence-mutation.ts +112 -0
- package/stdlib/async/promise.agentic +216 -0
- package/stdlib/database/pool.agentic +235 -0
- package/stdlib/file/io.agentic +194 -0
- package/stdlib/http/client.agentic +168 -0
- package/video-scripts/001-agentic-in-100-seconds.md +175 -0
- package/vscode-extension/README.md +67 -0
- package/vscode-extension/language-configuration.json +31 -0
- package/vscode-extension/package.json +46 -0
- package/vscode-extension/syntaxes/agentic.tmLanguage.json +134 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced Property-based test generator
|
|
4
|
+
* Automatically generates fast-check tests with 10+ inference rules
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.EnhancedPropertyTestGenerator = void 0;
|
|
8
|
+
class EnhancedPropertyTestGenerator {
|
|
9
|
+
generate(ast) {
|
|
10
|
+
const tests = [];
|
|
11
|
+
for (const node of ast) {
|
|
12
|
+
if (node.type === 'FunctionDeclaration') {
|
|
13
|
+
const func = node;
|
|
14
|
+
const funcTests = this.generateForFunction(func);
|
|
15
|
+
if (funcTests) {
|
|
16
|
+
tests.push(funcTests);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return tests;
|
|
21
|
+
}
|
|
22
|
+
generateForFunction(func) {
|
|
23
|
+
const properties = this.inferProperties(func);
|
|
24
|
+
if (properties.length === 0) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const testCode = this.generateTestCode(func, properties);
|
|
28
|
+
return {
|
|
29
|
+
functionName: func.name,
|
|
30
|
+
properties,
|
|
31
|
+
testCode,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
inferProperties(func) {
|
|
35
|
+
const properties = [];
|
|
36
|
+
// Extract explicit @property annotations
|
|
37
|
+
for (const annotation of func.annotations) {
|
|
38
|
+
if (annotation.name === 'property') {
|
|
39
|
+
properties.push({
|
|
40
|
+
name: annotation.args.name || annotation.args.arg0 || 'custom_property',
|
|
41
|
+
description: annotation.args.description || annotation.args.arg1 || '',
|
|
42
|
+
testFunction: 'typeof result !== "undefined"',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Infer from return type
|
|
47
|
+
if (func.returnType) {
|
|
48
|
+
properties.push(...this.inferFromReturnType(func.returnType));
|
|
49
|
+
}
|
|
50
|
+
// Infer from parameters (10+ rules)
|
|
51
|
+
properties.push(...this.inferFromParameters(func));
|
|
52
|
+
// Infer from function name
|
|
53
|
+
properties.push(...this.inferFromFunctionName(func));
|
|
54
|
+
// Infer from confidence level
|
|
55
|
+
properties.push(...this.inferFromConfidence(func));
|
|
56
|
+
return properties;
|
|
57
|
+
}
|
|
58
|
+
inferFromReturnType(returnType) {
|
|
59
|
+
const properties = [];
|
|
60
|
+
// Result<T, E> should handle both cases
|
|
61
|
+
if (returnType.kind === 'result') {
|
|
62
|
+
properties.push({
|
|
63
|
+
name: 'handles_success_case',
|
|
64
|
+
description: 'Function can return successful result',
|
|
65
|
+
testFunction: 'result.ok === true || result.ok === false',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Never returns null/undefined
|
|
69
|
+
properties.push({
|
|
70
|
+
name: 'never_returns_null',
|
|
71
|
+
description: 'Function never returns null or undefined',
|
|
72
|
+
testFunction: 'result !== null && result !== undefined',
|
|
73
|
+
});
|
|
74
|
+
return properties;
|
|
75
|
+
}
|
|
76
|
+
inferFromParameters(func) {
|
|
77
|
+
const properties = [];
|
|
78
|
+
const params = func.params;
|
|
79
|
+
// Check for string parameters
|
|
80
|
+
const hasStringParam = params.some(p => p.typeAnnotation && p.typeAnnotation.value === 'string');
|
|
81
|
+
if (hasStringParam) {
|
|
82
|
+
properties.push({
|
|
83
|
+
name: 'handles_empty_string',
|
|
84
|
+
description: 'Function handles empty string input',
|
|
85
|
+
testFunction: 'typeof result !== "undefined"',
|
|
86
|
+
});
|
|
87
|
+
properties.push({
|
|
88
|
+
name: 'handles_whitespace',
|
|
89
|
+
description: 'Function handles whitespace-only strings',
|
|
90
|
+
testFunction: 'typeof result !== "undefined"',
|
|
91
|
+
});
|
|
92
|
+
properties.push({
|
|
93
|
+
name: 'handles_unicode',
|
|
94
|
+
description: 'Function handles Unicode/emoji characters',
|
|
95
|
+
testFunction: 'typeof result !== "undefined"',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
// Check for number parameters
|
|
99
|
+
const hasNumberParam = params.some(p => p.typeAnnotation && p.typeAnnotation.value === 'number');
|
|
100
|
+
if (hasNumberParam) {
|
|
101
|
+
properties.push({
|
|
102
|
+
name: 'handles_zero',
|
|
103
|
+
description: 'Function handles zero input',
|
|
104
|
+
testFunction: 'typeof result !== "undefined"',
|
|
105
|
+
});
|
|
106
|
+
properties.push({
|
|
107
|
+
name: 'handles_negative',
|
|
108
|
+
description: 'Function handles negative numbers',
|
|
109
|
+
testFunction: 'typeof result !== "undefined"',
|
|
110
|
+
});
|
|
111
|
+
properties.push({
|
|
112
|
+
name: 'handles_decimals',
|
|
113
|
+
description: 'Function handles floating-point numbers',
|
|
114
|
+
testFunction: 'typeof result !== "undefined"',
|
|
115
|
+
});
|
|
116
|
+
properties.push({
|
|
117
|
+
name: 'handles_large_numbers',
|
|
118
|
+
description: 'Function handles very large numbers',
|
|
119
|
+
testFunction: 'typeof result !== "undefined"',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return properties;
|
|
123
|
+
}
|
|
124
|
+
inferFromFunctionName(func) {
|
|
125
|
+
const properties = [];
|
|
126
|
+
const funcName = func.name;
|
|
127
|
+
// Predicate functions (is*, has*)
|
|
128
|
+
if (/^(is|has)[A-Z]/.test(funcName)) {
|
|
129
|
+
properties.push({
|
|
130
|
+
name: 'returns_boolean',
|
|
131
|
+
description: 'Predicate function returns boolean',
|
|
132
|
+
testFunction: 'typeof result === "boolean"',
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// Parse functions
|
|
136
|
+
if (funcName.toLowerCase().includes('parse')) {
|
|
137
|
+
properties.push({
|
|
138
|
+
name: 'rejects_invalid_input',
|
|
139
|
+
description: 'Parse function handles invalid input',
|
|
140
|
+
testFunction: '!result.ok || result.ok === true',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// Validate functions
|
|
144
|
+
if (funcName.toLowerCase().includes('validate')) {
|
|
145
|
+
properties.push({
|
|
146
|
+
name: 'deterministic',
|
|
147
|
+
description: 'Validation is deterministic',
|
|
148
|
+
testFunction: 'consistent results',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return properties;
|
|
152
|
+
}
|
|
153
|
+
inferFromConfidence(func) {
|
|
154
|
+
const properties = [];
|
|
155
|
+
const confAnnotation = func.annotations.find(a => a.name === 'confidence');
|
|
156
|
+
if (confAnnotation && confAnnotation.args.arg0) {
|
|
157
|
+
const confidence = parseFloat(confAnnotation.args.arg0);
|
|
158
|
+
if (confidence >= 0.95) {
|
|
159
|
+
properties.push({
|
|
160
|
+
name: 'high_confidence_verified',
|
|
161
|
+
description: 'High-confidence function passes all tests',
|
|
162
|
+
testFunction: 'result !== null && result !== undefined',
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return properties;
|
|
167
|
+
}
|
|
168
|
+
generateTestCode(func, properties) {
|
|
169
|
+
const imports = `import { test } from '@fast-check/vitest';
|
|
170
|
+
import * as fc from 'fast-check';
|
|
171
|
+
|
|
172
|
+
`;
|
|
173
|
+
const arbitraries = func.params.map(p => this.generateArbitrary(p));
|
|
174
|
+
let testCode = imports;
|
|
175
|
+
testCode += `describe('${func.name} property tests', () => {\n`;
|
|
176
|
+
for (const property of properties) {
|
|
177
|
+
testCode += ` test.prop([${arbitraries.join(', ')}])('${property.description}', (${func.params.map(p => p.name).join(', ')}) => {
|
|
178
|
+
const result = ${func.name}(${func.params.map(p => p.name).join(', ')});
|
|
179
|
+
// Property: ${property.testFunction}
|
|
180
|
+
expect(result).toBeDefined();
|
|
181
|
+
}, { numRuns: 1000 });
|
|
182
|
+
|
|
183
|
+
`;
|
|
184
|
+
}
|
|
185
|
+
testCode += '});\n';
|
|
186
|
+
return testCode;
|
|
187
|
+
}
|
|
188
|
+
generateArbitrary(param) {
|
|
189
|
+
if (!param.typeAnnotation) {
|
|
190
|
+
return 'fc.anything()';
|
|
191
|
+
}
|
|
192
|
+
const type = param.typeAnnotation.value;
|
|
193
|
+
if (typeof type === 'string') {
|
|
194
|
+
switch (type) {
|
|
195
|
+
case 'string':
|
|
196
|
+
return 'fc.string()';
|
|
197
|
+
case 'number':
|
|
198
|
+
return 'fc.integer()';
|
|
199
|
+
case 'boolean':
|
|
200
|
+
return 'fc.boolean()';
|
|
201
|
+
default:
|
|
202
|
+
return 'fc.anything()';
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return 'fc.anything()';
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.EnhancedPropertyTestGenerator = EnhancedPropertyTestGenerator;
|
|
209
|
+
//# sourceMappingURL=generator-enhanced.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-enhanced.js","sourceRoot":"","sources":["../../src/property-tests/generator-enhanced.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAgBH,MAAa,6BAA6B;IACxC,QAAQ,CAAC,GAAkB;QACzB,MAAM,KAAK,GAAmB,EAAE,CAAC;QAEjC,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;YACvB,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;gBACxC,MAAM,IAAI,GAAG,IAA+B,CAAC;gBAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;gBACjD,IAAI,SAAS,EAAE,CAAC;oBACd,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,mBAAmB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AA6B,IAAI,qBAAqB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PropertyTestGenerator = void 0;
|
|
4
|
+
// Temporary fix - use the enhanced generator instead
|
|
5
|
+
var generator_enhanced_1 = require("./generator-enhanced");
|
|
6
|
+
Object.defineProperty(exports, "PropertyTestGenerator", { enumerable: true, get: function () { return generator_enhanced_1.EnhancedPropertyTestGenerator; } });
|
|
7
|
+
//# sourceMappingURL=generator-fixed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator-fixed.js","sourceRoot":"","sources":["../../src/property-tests/generator-fixed.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AACrD,2DAA8F;AAArF,2HAAA,6BAA6B,OAAyB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Property-based test generator
|
|
3
|
+
* Automatically generates fast-check tests from function signatures
|
|
4
|
+
*/
|
|
5
|
+
import * as AST from '../types';
|
|
6
|
+
export interface PropertyTest {
|
|
7
|
+
functionName: string;
|
|
8
|
+
properties: Property[];
|
|
9
|
+
testCode: string;
|
|
10
|
+
}
|
|
11
|
+
export interface Property {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
testFunction: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class PropertyTestGenerator {
|
|
17
|
+
generate(ast: AST.ASTNode[]): PropertyTest[];
|
|
18
|
+
private generateForFunction;
|
|
19
|
+
private inferProperties;
|
|
20
|
+
private inferFromReturnType;
|
|
21
|
+
private inferFromParameters;
|
|
22
|
+
private inferFromFunctionName;
|
|
23
|
+
private inferFromConfidence;
|
|
24
|
+
private inferErrorHandlingProperties;
|
|
25
|
+
private generateTestCode;
|
|
26
|
+
private generateArbitrary;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/property-tests/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,qBAAqB;IAChC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,YAAY,EAAE;IAe5C,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,eAAe;IAyBvB,OAAO,CAAC,mBAAmB;IA8B3B,OAAO,CAAC,mBAAmB;IAwH3B,OAAO,CAAC,qBAAqB;IAkC7B,OAAO,CAAC,mBAAmB;IA4B3B,OAAO,CAAC,4BAA4B;IAoBpC,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,iBAAiB;CAkB1B"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Property-based test generator
|
|
4
|
+
* Automatically generates fast-check tests from function signatures
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PropertyTestGenerator = void 0;
|
|
8
|
+
class PropertyTestGenerator {
|
|
9
|
+
generate(ast) {
|
|
10
|
+
const tests = [];
|
|
11
|
+
for (const node of ast) {
|
|
12
|
+
if (node.type === 'FunctionDeclaration') {
|
|
13
|
+
const funcTests = this.generateForFunction(node);
|
|
14
|
+
if (funcTests) {
|
|
15
|
+
tests.push(funcTests);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return tests;
|
|
20
|
+
}
|
|
21
|
+
generateForFunction(func) {
|
|
22
|
+
const properties = this.inferProperties(func);
|
|
23
|
+
if (properties.length === 0) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const testCode = this.generateTestCode(func, properties);
|
|
27
|
+
return {
|
|
28
|
+
functionName: func.name,
|
|
29
|
+
properties,
|
|
30
|
+
testCode,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
inferProperties(func) {
|
|
34
|
+
const properties = [];
|
|
35
|
+
// Extract properties from annotations
|
|
36
|
+
for (const annotation of func.annotations) {
|
|
37
|
+
if (annotation.name === 'property') {
|
|
38
|
+
properties.push({
|
|
39
|
+
name: annotation.args.name || 'custom_property',
|
|
40
|
+
description: annotation.args.description || '',
|
|
41
|
+
testFunction: '',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Infer properties from return type
|
|
46
|
+
if (func.returnType) {
|
|
47
|
+
properties.push(...this.inferFromReturnType(func.returnType));
|
|
48
|
+
}
|
|
49
|
+
// Infer properties from parameters
|
|
50
|
+
properties.push(...this.inferFromParameters(func.params));
|
|
51
|
+
return properties;
|
|
52
|
+
}
|
|
53
|
+
inferFromReturnType(returnType) {
|
|
54
|
+
const properties = [];
|
|
55
|
+
// Result<T, E> should handle both success and failure
|
|
56
|
+
if (returnType.kind === 'result') {
|
|
57
|
+
properties.push({
|
|
58
|
+
name: 'handles_success_case',
|
|
59
|
+
description: 'Function handles successful result',
|
|
60
|
+
testFunction: 'result.ok === true',
|
|
61
|
+
});
|
|
62
|
+
properties.push({
|
|
63
|
+
name: 'handles_error_case',
|
|
64
|
+
description: 'Function handles error result',
|
|
65
|
+
testFunction: 'result.ok === false || result.ok === true',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Never returns null/undefined
|
|
69
|
+
if (returnType.kind === 'primitive' || returnType.kind === 'custom') {
|
|
70
|
+
properties.push({
|
|
71
|
+
name: 'never_returns_null',
|
|
72
|
+
description: 'Function never returns null or undefined',
|
|
73
|
+
testFunction: 'result !== null && result !== undefined',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return properties;
|
|
77
|
+
}
|
|
78
|
+
inferFromParameters(params) {
|
|
79
|
+
const properties = [];
|
|
80
|
+
// RULE 1: String parameters - test empty, whitespace, special chars
|
|
81
|
+
if (params.some(p => p.typeAnnotation?.value === 'string')) {
|
|
82
|
+
properties.push({
|
|
83
|
+
name: 'handles_empty_string',
|
|
84
|
+
description: 'Function handles empty string input',
|
|
85
|
+
testFunction: 'typeof result !== "undefined"',
|
|
86
|
+
});
|
|
87
|
+
properties.push({
|
|
88
|
+
name: 'handles_whitespace_only',
|
|
89
|
+
description: 'Function handles whitespace-only strings',
|
|
90
|
+
testFunction: 'typeof result !== "undefined"',
|
|
91
|
+
});
|
|
92
|
+
properties.push({
|
|
93
|
+
name: 'handles_special_characters',
|
|
94
|
+
description: 'Function handles strings with special characters',
|
|
95
|
+
testFunction: 'typeof result !== "undefined"',
|
|
96
|
+
});
|
|
97
|
+
properties.push({
|
|
98
|
+
name: 'handles_unicode',
|
|
99
|
+
description: 'Function handles Unicode characters (emoji, etc.)',
|
|
100
|
+
testFunction: 'typeof result !== "undefined"',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// RULE 2: Number parameters - test zero, negative, infinity, NaN
|
|
104
|
+
if (params.some(p => p.typeAnnotation?.value === 'number')) {
|
|
105
|
+
properties.push({
|
|
106
|
+
name: 'handles_zero',
|
|
107
|
+
description: 'Function handles zero input',
|
|
108
|
+
testFunction: 'typeof result !== "undefined"',
|
|
109
|
+
});
|
|
110
|
+
properties.push({
|
|
111
|
+
name: 'handles_negative',
|
|
112
|
+
description: 'Function handles negative numbers',
|
|
113
|
+
testFunction: 'typeof result !== "undefined"',
|
|
114
|
+
});
|
|
115
|
+
properties.push({
|
|
116
|
+
name: 'handles_large_numbers',
|
|
117
|
+
description: 'Function handles very large numbers',
|
|
118
|
+
testFunction: 'typeof result !== "undefined"',
|
|
119
|
+
});
|
|
120
|
+
properties.push({
|
|
121
|
+
name: 'handles_decimals',
|
|
122
|
+
description: 'Function handles decimal/floating-point numbers',
|
|
123
|
+
testFunction: 'typeof result !== "undefined"',
|
|
124
|
+
});
|
|
125
|
+
properties.push({
|
|
126
|
+
name: 'handles_infinity',
|
|
127
|
+
description: 'Function handles Infinity and -Infinity',
|
|
128
|
+
testFunction: 'typeof result !== "undefined"',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// RULE 3: Array parameters - test empty, single, duplicates
|
|
132
|
+
// Note: TypeAnnotation doesn't have 'kind' property yet, using value for now
|
|
133
|
+
if (params.some(p => p.typeAnnotation?.value?.includes('[]'))) {
|
|
134
|
+
properties.push({
|
|
135
|
+
name: 'handles_empty_array',
|
|
136
|
+
description: 'Function handles empty array input',
|
|
137
|
+
testFunction: 'typeof result !== "undefined"',
|
|
138
|
+
});
|
|
139
|
+
properties.push({
|
|
140
|
+
name: 'handles_single_element',
|
|
141
|
+
description: 'Function handles single-element array',
|
|
142
|
+
testFunction: 'typeof result !== "undefined"',
|
|
143
|
+
});
|
|
144
|
+
properties.push({
|
|
145
|
+
name: 'handles_duplicate_elements',
|
|
146
|
+
description: 'Function handles arrays with duplicate values',
|
|
147
|
+
testFunction: 'typeof result !== "undefined"',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// RULE 4: Object parameters - test missing fields, extra fields
|
|
151
|
+
// Note: TypeAnnotation doesn't have 'kind' property yet, using heuristic
|
|
152
|
+
if (params.some(p => p.typeAnnotation && !['string', 'number', 'boolean', 'void'].includes(p.typeAnnotation.value))) {
|
|
153
|
+
properties.push({
|
|
154
|
+
name: 'handles_missing_optional_fields',
|
|
155
|
+
description: 'Function handles objects with missing optional fields',
|
|
156
|
+
testFunction: 'typeof result !== "undefined"',
|
|
157
|
+
});
|
|
158
|
+
properties.push({
|
|
159
|
+
name: 'handles_extra_fields',
|
|
160
|
+
description: 'Function handles objects with unexpected extra fields',
|
|
161
|
+
testFunction: 'typeof result !== "undefined"',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
// RULE 5: Async functions - test concurrent execution
|
|
165
|
+
if (func.annotations.some(a => a.name === 'async')) {
|
|
166
|
+
properties.push({
|
|
167
|
+
name: 'concurrent_execution_safe',
|
|
168
|
+
description: 'Function can be called concurrently without issues',
|
|
169
|
+
testFunction: 'typeof result !== "undefined"',
|
|
170
|
+
});
|
|
171
|
+
properties.push({
|
|
172
|
+
name: 'handles_cancellation',
|
|
173
|
+
description: 'Function handles cancellation gracefully',
|
|
174
|
+
testFunction: 'typeof result !== "undefined"',
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return properties;
|
|
178
|
+
}
|
|
179
|
+
// NEW: Infer properties from function name patterns
|
|
180
|
+
inferFromFunctionName(funcName) {
|
|
181
|
+
const properties = [];
|
|
182
|
+
// Functions starting with 'is' or 'has' should return boolean
|
|
183
|
+
if (/^(is|has)[A-Z]/.test(funcName)) {
|
|
184
|
+
properties.push({
|
|
185
|
+
name: 'returns_boolean',
|
|
186
|
+
description: 'Predicate function returns boolean',
|
|
187
|
+
testFunction: 'typeof result === "boolean"',
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
// Functions with 'parse' should handle invalid input
|
|
191
|
+
if (funcName.includes('parse') || funcName.includes('Parse')) {
|
|
192
|
+
properties.push({
|
|
193
|
+
name: 'rejects_invalid_input',
|
|
194
|
+
description: 'Parse function returns error for invalid input',
|
|
195
|
+
testFunction: 'result.ok === false when input is invalid',
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// Functions with 'validate' should be deterministic
|
|
199
|
+
if (funcName.includes('validate') || funcName.includes('Validate')) {
|
|
200
|
+
properties.push({
|
|
201
|
+
name: 'deterministic_validation',
|
|
202
|
+
description: 'Validation gives same result for same input',
|
|
203
|
+
testFunction: 'validate(x) === validate(x)',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return properties;
|
|
207
|
+
}
|
|
208
|
+
// NEW: Infer properties from confidence levels
|
|
209
|
+
inferFromConfidence(func) {
|
|
210
|
+
const properties = [];
|
|
211
|
+
const confAnnotation = func.annotations.find(a => a.name === 'confidence');
|
|
212
|
+
if (confAnnotation && confAnnotation.args.level) {
|
|
213
|
+
const confidence = parseFloat(confAnnotation.args.level);
|
|
214
|
+
if (confidence >= 0.95) {
|
|
215
|
+
properties.push({
|
|
216
|
+
name: 'high_confidence_verified',
|
|
217
|
+
description: 'High-confidence functions should pass all property tests',
|
|
218
|
+
testFunction: 'result satisfies all properties',
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (confidence < 0.70) {
|
|
222
|
+
properties.push({
|
|
223
|
+
name: 'low_confidence_documented',
|
|
224
|
+
description: 'Low-confidence functions should document limitations',
|
|
225
|
+
testFunction: 'has @uncertain annotation or documentation',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return properties;
|
|
230
|
+
}
|
|
231
|
+
// NEW: Infer error handling properties
|
|
232
|
+
inferErrorHandlingProperties(func) {
|
|
233
|
+
const properties = [];
|
|
234
|
+
if (func.returnType?.kind === 'result') {
|
|
235
|
+
properties.push({
|
|
236
|
+
name: 'error_messages_are_descriptive',
|
|
237
|
+
description: 'Error results contain meaningful messages',
|
|
238
|
+
testFunction: 'result.ok === false implies result.error.length > 0',
|
|
239
|
+
});
|
|
240
|
+
properties.push({
|
|
241
|
+
name: 'errors_have_recovery_context',
|
|
242
|
+
description: 'Errors include recovery suggestions when available',
|
|
243
|
+
testFunction: 'result.ok === false implies has error context',
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return properties;
|
|
247
|
+
}
|
|
248
|
+
generateTestCode(func, properties) {
|
|
249
|
+
const imports = `import { test } from '@fast-check/vitest';
|
|
250
|
+
import * as fc from 'fast-check';
|
|
251
|
+
import { ${func.name} } from './${func.name}';
|
|
252
|
+
|
|
253
|
+
`;
|
|
254
|
+
let testCode = imports;
|
|
255
|
+
// Generate arbitraries for parameters
|
|
256
|
+
const arbitraries = func.params.map(p => this.generateArbitrary(p));
|
|
257
|
+
// Generate test cases
|
|
258
|
+
for (const property of properties) {
|
|
259
|
+
testCode += `test.prop([${arbitraries.join(', ')}], (${func.params.map(p => p.name).join(', ')}) => {
|
|
260
|
+
const result = ${func.name}(${func.params.map(p => p.name).join(', ')});
|
|
261
|
+
expect(${property.testFunction}).toBe(true);
|
|
262
|
+
}, { numRuns: 1000 });\n\n`;
|
|
263
|
+
}
|
|
264
|
+
return testCode;
|
|
265
|
+
}
|
|
266
|
+
generateArbitrary(param) {
|
|
267
|
+
if (!param.typeAnnotation) {
|
|
268
|
+
return 'fc.anything()';
|
|
269
|
+
}
|
|
270
|
+
const type = param.typeAnnotation.value;
|
|
271
|
+
switch (type) {
|
|
272
|
+
case 'string':
|
|
273
|
+
return 'fc.string()';
|
|
274
|
+
case 'number':
|
|
275
|
+
return 'fc.integer()';
|
|
276
|
+
case 'boolean':
|
|
277
|
+
return 'fc.boolean()';
|
|
278
|
+
default:
|
|
279
|
+
return 'fc.anything()';
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
exports.PropertyTestGenerator = PropertyTestGenerator;
|
|
284
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/property-tests/generator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAgBH,MAAa,qBAAqB;IAChC,QAAQ,CAAC,GAAkB;QACzB,MAAM,KAAK,GAAmB,EAAE,CAAC;QAEjC,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;YACvB,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;gBACxC,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAA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AAC,CAAC,CAAC,CAAC,CAAC;QAEpE,sBAAsB;QACtB,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;YAClC,QAAQ,IAAI,cAAc,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;mBACjF,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;WAC5D,QAAQ,CAAC,YAAY;2BACL,CAAC;QACxB,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,iBAAiB,CAAC,KAAoB;QAC5C,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;YAC1B,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,MAAM,IAAI,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC;QAExC,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,QAAQ;gBACX,OAAO,aAAa,CAAC;YACvB,KAAK,QAAQ;gBACX,OAAO,cAAc,CAAC;YACxB,KAAK,SAAS;gBACZ,OAAO,cAAc,CAAC;YACxB;gBACE,OAAO,eAAe,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AA1UD,sDA0UC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refinement Types for Agentic
|
|
3
|
+
* Enables dependent types and logical predicates in type annotations
|
|
4
|
+
* Inspired by Liquid Haskell and F*
|
|
5
|
+
*/
|
|
6
|
+
export interface RefinementType {
|
|
7
|
+
baseType: string;
|
|
8
|
+
predicate: string;
|
|
9
|
+
variable: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const CommonRefinements: {
|
|
12
|
+
Positive: {
|
|
13
|
+
baseType: string;
|
|
14
|
+
predicate: string;
|
|
15
|
+
variable: string;
|
|
16
|
+
};
|
|
17
|
+
NonNegative: {
|
|
18
|
+
baseType: string;
|
|
19
|
+
predicate: string;
|
|
20
|
+
variable: string;
|
|
21
|
+
};
|
|
22
|
+
NonZero: {
|
|
23
|
+
baseType: string;
|
|
24
|
+
predicate: string;
|
|
25
|
+
variable: string;
|
|
26
|
+
};
|
|
27
|
+
Range: (min: number, max: number) => {
|
|
28
|
+
baseType: string;
|
|
29
|
+
predicate: string;
|
|
30
|
+
variable: string;
|
|
31
|
+
};
|
|
32
|
+
NonEmptyString: {
|
|
33
|
+
baseType: string;
|
|
34
|
+
predicate: string;
|
|
35
|
+
variable: string;
|
|
36
|
+
};
|
|
37
|
+
MaxLength: (max: number) => {
|
|
38
|
+
baseType: string;
|
|
39
|
+
predicate: string;
|
|
40
|
+
variable: string;
|
|
41
|
+
};
|
|
42
|
+
MinLength: (min: number) => {
|
|
43
|
+
baseType: string;
|
|
44
|
+
predicate: string;
|
|
45
|
+
variable: string;
|
|
46
|
+
};
|
|
47
|
+
ConfidenceScore: {
|
|
48
|
+
baseType: string;
|
|
49
|
+
predicate: string;
|
|
50
|
+
variable: string;
|
|
51
|
+
};
|
|
52
|
+
HighConfidence: {
|
|
53
|
+
baseType: string;
|
|
54
|
+
predicate: string;
|
|
55
|
+
variable: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare class RefinementTypeChecker {
|
|
59
|
+
private z3Context;
|
|
60
|
+
private initialized;
|
|
61
|
+
initialize(): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Check if a value satisfies a refinement type
|
|
64
|
+
* Can be used at compile-time (static) or runtime (dynamic)
|
|
65
|
+
*/
|
|
66
|
+
check(value: any, refinement: RefinementType, mode?: 'static' | 'runtime'): Promise<{
|
|
67
|
+
valid: boolean;
|
|
68
|
+
counterexample?: any;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Runtime checking (evaluate predicate with actual value)
|
|
72
|
+
*/
|
|
73
|
+
private checkRuntime;
|
|
74
|
+
/**
|
|
75
|
+
* Static checking (verify predicate holds for all values using Z3)
|
|
76
|
+
*/
|
|
77
|
+
private checkStatic;
|
|
78
|
+
private createSymbolicVariable;
|
|
79
|
+
private parsePredicateToZ3;
|
|
80
|
+
private parseOperand;
|
|
81
|
+
private evaluatePredicate;
|
|
82
|
+
private extractCounterexample;
|
|
83
|
+
}
|
|
84
|
+
export declare class RefinementValidator {
|
|
85
|
+
private checker;
|
|
86
|
+
validate<T>(value: T, refinement: RefinementType, location: string): Promise<T>;
|
|
87
|
+
}
|
|
88
|
+
export declare class RefinementViolation extends Error {
|
|
89
|
+
location: string;
|
|
90
|
+
refinement: RefinementType;
|
|
91
|
+
value: any;
|
|
92
|
+
constructor(message: string, location: string, refinement: RefinementType, value: any);
|
|
93
|
+
}
|
|
94
|
+
export declare const refinementChecker: RefinementTypeChecker;
|
|
95
|
+
export declare const refinementValidator: RefinementValidator;
|
|
96
|
+
//# sourceMappingURL=refinement-types.d.ts.map
|