@caleuche/core 0.5.1 → 0.6.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/README.md +51 -0
- package/dist/index.cjs.js +26 -1
- package/package.json +1 -1
- package/project-templates/requirements.txt.template +2 -2
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ The library acts as the core engine for tools like the Caleuche CLI, providing a
|
|
|
18
18
|
- Primitives: `string`, `number`, `boolean`
|
|
19
19
|
- Complex types: `object`, `array` (with typed items)
|
|
20
20
|
- Required/optional fields with default values
|
|
21
|
+
- **Test Sample Generation**: Automatically generate test variants with overridden input values in a `test/` subfolder
|
|
21
22
|
- **Template Helper Functions**: Built-in language-specific helpers for common code generation tasks:
|
|
22
23
|
- Import/using statement generation
|
|
23
24
|
- Environment variable handling with runtime validation
|
|
@@ -151,6 +152,45 @@ const output = compileSample(sample, { name: "World" }, { project: false });
|
|
|
151
152
|
// Output includes tags.yaml file with metadata
|
|
152
153
|
```
|
|
153
154
|
|
|
155
|
+
### Generating Test Samples with Test Overrides
|
|
156
|
+
|
|
157
|
+
Use `testOverrides` to automatically generate a test variant of your sample in a `test/` subfolder. The test sample inherits all parent input values, with specified values overridden:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
const sample: Sample = {
|
|
161
|
+
template: `
|
|
162
|
+
const client = new OpenAI({ endpoint: "<%= endpoint %>" });
|
|
163
|
+
const response = await client.chat.completions.create({
|
|
164
|
+
model: "<%= model %>",
|
|
165
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
166
|
+
});
|
|
167
|
+
`,
|
|
168
|
+
type: "javascript",
|
|
169
|
+
dependencies: [{ name: "openai", version: "^4.0.0" }],
|
|
170
|
+
input: [
|
|
171
|
+
{ name: "endpoint", type: "string", required: true },
|
|
172
|
+
{ name: "model", type: "string", required: true },
|
|
173
|
+
],
|
|
174
|
+
testOverrides: {
|
|
175
|
+
input: {
|
|
176
|
+
endpoint: "https://test-endpoint.openai.azure.com",
|
|
177
|
+
model: "gpt-4-test",
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const output = compileSample(
|
|
183
|
+
sample,
|
|
184
|
+
{ endpoint: "https://display-endpoint.openai.com", model: "gpt-4" },
|
|
185
|
+
{ project: true },
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// Output includes:
|
|
189
|
+
// - sample.js: Uses production endpoint and model
|
|
190
|
+
// - package.json: Project dependencies
|
|
191
|
+
// - test/sample.js: Uses test endpoint and model (overridden values)
|
|
192
|
+
```
|
|
193
|
+
|
|
154
194
|
### Template Built-ins
|
|
155
195
|
|
|
156
196
|
Template helper functions are available within templates to generate language-specific boilerplate code. These functions are accessed via the language namespace (e.g., `go.includes()`, `csharp.usings()`).
|
|
@@ -296,6 +336,17 @@ interface Sample {
|
|
|
296
336
|
dependencies: Dependency[]; // Package dependencies
|
|
297
337
|
input: TemplateInput[]; // Template input definitions
|
|
298
338
|
tags?: Record<string, any>; // Optional metadata tags
|
|
339
|
+
testOverrides?: TestOverrides; // Optional test sample overrides
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**`TestOverrides`**
|
|
344
|
+
|
|
345
|
+
Defines input value overrides for generating a test sample in a `test/` subfolder:
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
interface TestOverrides {
|
|
349
|
+
input: Record<string, any>; // Input values to override in test sample
|
|
299
350
|
}
|
|
300
351
|
```
|
|
301
352
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -7607,8 +7607,9 @@ var packageJson = "{\n \"name\": \"sample\",\n \"version\": \"1.0.0\",\n \"ty
|
|
|
7607
7607
|
|
|
7608
7608
|
var pomXml = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n <groupId>sample</groupId>\n <artifactId>sample</artifactId>\n <version>1.0-SNAPSHOT</version>\n <dependencies>\n <% _.forEach(dependencies, function(dependency) { %>\n <dependency>\n <groupId><%= dependency.name.split(\":\")[0] %></groupId>\n <artifactId><%= dependency.name.split(\":\")[1] %></artifactId>\n <version><%= dependency.version %></version>\n </dependency>\n <% }); %>\n </dependencies>\n <build>\n <plugins>\n <plugin>\n <groupId>org.codehaus.mojo</groupId>\n <artifactId>build-helper-maven-plugin</artifactId>\n <version>3.6.0</version>\n <executions>\n <execution>\n <id>add-source</id>\n <phase>generate-sources</phase>\n <goals>\n <goal>add-source</goal>\n </goals>\n <configuration>\n <sources>\n <source>.</source>\n </sources>\n </configuration>\n </execution>\n </executions>\n </plugin>\n </plugins>\n </build>\n</project>\n";
|
|
7609
7609
|
|
|
7610
|
-
var requirementsTxt = "<% _.forEach(dependencies, function(dependency) { %>\n<%= dependency.name %><% if (dependency.version) { %>==<%= dependency.version
|
|
7610
|
+
var requirementsTxt = "<% _.forEach(dependencies, function(dependency) { %>\n<%= dependency.name %><% if (dependency.version) { %>==<%= dependency.version %><% } %>\n\n<% }) %>";
|
|
7611
7611
|
|
|
7612
|
+
const TEST_SUBFOLDER = "test";
|
|
7612
7613
|
function fillInputObject(sample, inputData) {
|
|
7613
7614
|
const inputObject = {};
|
|
7614
7615
|
for (const { name, required, default: defaultValue } of sample.input) {
|
|
@@ -7707,6 +7708,12 @@ function compileSample(sample, input, options) {
|
|
|
7707
7708
|
if (options.project) {
|
|
7708
7709
|
const projectFile = generateProjectFile(sample);
|
|
7709
7710
|
output.items.push(projectFile);
|
|
7711
|
+
if (sample.testOverrides) {
|
|
7712
|
+
output.items.push({
|
|
7713
|
+
fileName: `${TEST_SUBFOLDER}/${projectFile.fileName}`,
|
|
7714
|
+
content: projectFile.content,
|
|
7715
|
+
});
|
|
7716
|
+
}
|
|
7710
7717
|
}
|
|
7711
7718
|
if (sample.tags) {
|
|
7712
7719
|
const tagsFile = generateTagsFile(sample);
|
|
@@ -7729,8 +7736,26 @@ function compileSample(sample, input, options) {
|
|
|
7729
7736
|
fileName: targetFileName,
|
|
7730
7737
|
content: outputFileContent,
|
|
7731
7738
|
});
|
|
7739
|
+
if (sample.testOverrides) {
|
|
7740
|
+
const testOutput = generateTestSample(sample, input, sample.testOverrides, compiledTemplate, targetFileName);
|
|
7741
|
+
output.items.push(...testOutput);
|
|
7742
|
+
}
|
|
7732
7743
|
return output;
|
|
7733
7744
|
}
|
|
7745
|
+
function generateTestSample(sample, parentInput, testOverrides, compiledTemplate, targetFileName) {
|
|
7746
|
+
const testItems = [];
|
|
7747
|
+
// Merge parent input with test overrides
|
|
7748
|
+
const testInputObject = fillInputObject(sample, {
|
|
7749
|
+
...parentInput,
|
|
7750
|
+
...testOverrides.input,
|
|
7751
|
+
});
|
|
7752
|
+
const testOutputContent = compiledTemplate(testInputObject);
|
|
7753
|
+
testItems.push({
|
|
7754
|
+
fileName: `${TEST_SUBFOLDER}/${targetFileName}`,
|
|
7755
|
+
content: testOutputContent,
|
|
7756
|
+
});
|
|
7757
|
+
return testItems;
|
|
7758
|
+
}
|
|
7734
7759
|
|
|
7735
7760
|
exports.compileSample = compileSample;
|
|
7736
7761
|
//# sourceMappingURL=index.cjs.js.map
|
package/package.json
CHANGED