@llmist/testing 16.1.0 → 16.2.1

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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Readable, PassThrough, Writable } from 'node:stream';
2
- import { LLMMessage, AbstractGadget, AudioMimeType, LLMGenerationOptions, ImageMimeType, ProviderAdapter, ModelDescriptor, LLMStream, ImageGenerationOptions, ImageGenerationResult, SpeechGenerationOptions, SpeechGenerationResult, LLMist, IConversationManager, LLMStreamChunk } from 'llmist';
2
+ import { LLMMessage, AbstractGadget, AudioMimeType, LLMGenerationOptions, ImageMimeType, ProviderAdapter, ModelDescriptor, LLMStream, ImageGenerationOptions, ImageGenerationResult, SpeechGenerationOptions, SpeechGenerationResult, LLMist, IConversationManager, Skill, SkillActivation, SkillMetadata, SkillActivationOptions, ParsedSkill, LLMStreamChunk } from 'llmist';
3
3
  import { ZodType } from 'zod';
4
4
 
5
5
  /**
@@ -1353,6 +1353,105 @@ declare function createTextMockStream(text: string, options?: {
1353
1353
  usage?: MockResponse["usage"];
1354
1354
  }): LLMStream;
1355
1355
 
1356
+ /**
1357
+ * Testing utilities for skills.
1358
+ *
1359
+ * Provides helpers for parsing, activating, and asserting on skills
1360
+ * without requiring filesystem setup.
1361
+ *
1362
+ * @module testing/skill-testing
1363
+ */
1364
+
1365
+ /**
1366
+ * Parse and validate a SKILL.md content string.
1367
+ *
1368
+ * @param content - Full SKILL.md content (frontmatter + body)
1369
+ * @param sourcePath - Optional source path (defaults to /test/SKILL.md)
1370
+ * @returns Parsed skill with instructions loaded
1371
+ *
1372
+ * @example
1373
+ * ```typescript
1374
+ * import { testSkillParse } from '@llmist/testing';
1375
+ *
1376
+ * const parsed = testSkillParse(`---
1377
+ * name: my-skill
1378
+ * description: A test skill
1379
+ * ---
1380
+ * Do the thing.`);
1381
+ *
1382
+ * expect(parsed.metadata.name).toBe('my-skill');
1383
+ * ```
1384
+ */
1385
+ declare function testSkillParse(content: string, sourcePath?: string): ParsedSkill;
1386
+ /**
1387
+ * Test a skill's activation with given arguments.
1388
+ *
1389
+ * @param skill - Skill instance to activate
1390
+ * @param options - Activation options (arguments, cwd, etc.)
1391
+ * @returns Activation result with resolved instructions
1392
+ *
1393
+ * @example
1394
+ * ```typescript
1395
+ * import { testSkillActivation, mockSkill } from '@llmist/testing';
1396
+ *
1397
+ * const skill = mockSkill({ name: 'search' });
1398
+ * const activation = await testSkillActivation(skill, { arguments: '*.ts' });
1399
+ * expect(activation.resolvedInstructions).toContain('*.ts');
1400
+ * ```
1401
+ */
1402
+ declare function testSkillActivation(skill: Skill, options?: SkillActivationOptions): Promise<SkillActivation>;
1403
+ /**
1404
+ * Assert that a skill's resolved instructions contain expected content.
1405
+ *
1406
+ * @param activation - The activation result to check
1407
+ * @param expected - Array of strings that must be present in the instructions
1408
+ * @throws AssertionError if any expected string is missing
1409
+ */
1410
+ declare function assertSkillContains(activation: SkillActivation, expected: string[]): void;
1411
+ /**
1412
+ * Validate a SKILL.md content string and return any issues.
1413
+ *
1414
+ * @param content - Full SKILL.md content
1415
+ * @returns Array of validation issues (empty if valid)
1416
+ */
1417
+ declare function validateSkill(content: string): string[];
1418
+ /**
1419
+ * Create a mock Skill instance for testing.
1420
+ *
1421
+ * @param overrides - Override any metadata fields
1422
+ * @param instructions - Custom instructions body
1423
+ */
1424
+ declare function mockSkill(overrides?: Partial<SkillMetadata>, instructions?: string): Skill;
1425
+ /**
1426
+ * Fluent builder for creating test skills.
1427
+ *
1428
+ * @example
1429
+ * ```typescript
1430
+ * import { MockSkillBuilder } from '@llmist/testing';
1431
+ *
1432
+ * const skill = new MockSkillBuilder()
1433
+ * .withName('gmail-read')
1434
+ * .withDescription('Read Gmail messages')
1435
+ * .withInstructions('Use gws to read emails.')
1436
+ * .build();
1437
+ * ```
1438
+ */
1439
+ declare class MockSkillBuilder {
1440
+ private _name;
1441
+ private _description;
1442
+ private _instructions;
1443
+ private _overrides;
1444
+ withName(name: string): this;
1445
+ withDescription(description: string): this;
1446
+ withInstructions(instructions: string): this;
1447
+ withModel(model: string): this;
1448
+ withContext(context: "fork" | "inline"): this;
1449
+ withPaths(paths: string[]): this;
1450
+ withAllowedTools(tools: string[]): this;
1451
+ withGadgets(gadgets: string[]): this;
1452
+ build(): Skill;
1453
+ }
1454
+
1356
1455
  /**
1357
1456
  * Stream testing utilities for llmist.
1358
1457
  * Provides helpers for creating and consuming test streams.
@@ -1492,4 +1591,4 @@ interface MockTUIApp {
1492
1591
  */
1493
1592
  declare const createMockTUIApp: () => MockTUIApp;
1494
1593
 
1495
- export { type MockAudioData, MockBuilder, MockConversationManager, type MockGadget, MockGadgetBuilder, type MockGadgetConfig, type MockImageData, MockManager, type MockMatcher, type MockMatcherContext, type MockOptions, MockPromptRecorder, MockProviderAdapter, type MockRegistration, type MockResponse, type MockStats, type MockTUIApp, type RecordedCall, type TestEnvironment, type TestEnvironmentOptions, type TestGadgetOptions, type TestGadgetResult, collectOutput, collectStream, collectStreamText, createAssistantMessage, createConversation, createConversationWithGadgets, createEmptyStream, createErrorStream, createLargeConversation, createMinimalConversation, createMockAdapter, createMockClient, createMockConversationManager, createMockGadget, createMockPrompt, createMockReadable, createMockStream, createMockTUIApp, createMockWritable, createSystemMessage, createTestEnvironment, createTestStream, createTextMockStream, createTextStream, createUserMessage, estimateTokens, getBufferedOutput, getMockManager, getStreamFinalChunk, mockGadget, mockLLM, resetMocks, testGadget, testGadgetBatch, waitFor };
1594
+ export { type MockAudioData, MockBuilder, MockConversationManager, type MockGadget, MockGadgetBuilder, type MockGadgetConfig, type MockImageData, MockManager, type MockMatcher, type MockMatcherContext, type MockOptions, MockPromptRecorder, MockProviderAdapter, type MockRegistration, type MockResponse, MockSkillBuilder, type MockStats, type MockTUIApp, type RecordedCall, type TestEnvironment, type TestEnvironmentOptions, type TestGadgetOptions, type TestGadgetResult, assertSkillContains, collectOutput, collectStream, collectStreamText, createAssistantMessage, createConversation, createConversationWithGadgets, createEmptyStream, createErrorStream, createLargeConversation, createMinimalConversation, createMockAdapter, createMockClient, createMockConversationManager, createMockGadget, createMockPrompt, createMockReadable, createMockStream, createMockTUIApp, createMockWritable, createSystemMessage, createTestEnvironment, createTestStream, createTextMockStream, createTextStream, createUserMessage, estimateTokens, getBufferedOutput, getMockManager, getStreamFinalChunk, mockGadget, mockLLM, mockSkill, resetMocks, testGadget, testGadgetBatch, testSkillActivation, testSkillParse, validateSkill, waitFor };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Readable, PassThrough, Writable } from 'node:stream';
2
- import { LLMMessage, AbstractGadget, AudioMimeType, LLMGenerationOptions, ImageMimeType, ProviderAdapter, ModelDescriptor, LLMStream, ImageGenerationOptions, ImageGenerationResult, SpeechGenerationOptions, SpeechGenerationResult, LLMist, IConversationManager, LLMStreamChunk } from 'llmist';
2
+ import { LLMMessage, AbstractGadget, AudioMimeType, LLMGenerationOptions, ImageMimeType, ProviderAdapter, ModelDescriptor, LLMStream, ImageGenerationOptions, ImageGenerationResult, SpeechGenerationOptions, SpeechGenerationResult, LLMist, IConversationManager, Skill, SkillActivation, SkillMetadata, SkillActivationOptions, ParsedSkill, LLMStreamChunk } from 'llmist';
3
3
  import { ZodType } from 'zod';
4
4
 
5
5
  /**
@@ -1353,6 +1353,105 @@ declare function createTextMockStream(text: string, options?: {
1353
1353
  usage?: MockResponse["usage"];
1354
1354
  }): LLMStream;
1355
1355
 
1356
+ /**
1357
+ * Testing utilities for skills.
1358
+ *
1359
+ * Provides helpers for parsing, activating, and asserting on skills
1360
+ * without requiring filesystem setup.
1361
+ *
1362
+ * @module testing/skill-testing
1363
+ */
1364
+
1365
+ /**
1366
+ * Parse and validate a SKILL.md content string.
1367
+ *
1368
+ * @param content - Full SKILL.md content (frontmatter + body)
1369
+ * @param sourcePath - Optional source path (defaults to /test/SKILL.md)
1370
+ * @returns Parsed skill with instructions loaded
1371
+ *
1372
+ * @example
1373
+ * ```typescript
1374
+ * import { testSkillParse } from '@llmist/testing';
1375
+ *
1376
+ * const parsed = testSkillParse(`---
1377
+ * name: my-skill
1378
+ * description: A test skill
1379
+ * ---
1380
+ * Do the thing.`);
1381
+ *
1382
+ * expect(parsed.metadata.name).toBe('my-skill');
1383
+ * ```
1384
+ */
1385
+ declare function testSkillParse(content: string, sourcePath?: string): ParsedSkill;
1386
+ /**
1387
+ * Test a skill's activation with given arguments.
1388
+ *
1389
+ * @param skill - Skill instance to activate
1390
+ * @param options - Activation options (arguments, cwd, etc.)
1391
+ * @returns Activation result with resolved instructions
1392
+ *
1393
+ * @example
1394
+ * ```typescript
1395
+ * import { testSkillActivation, mockSkill } from '@llmist/testing';
1396
+ *
1397
+ * const skill = mockSkill({ name: 'search' });
1398
+ * const activation = await testSkillActivation(skill, { arguments: '*.ts' });
1399
+ * expect(activation.resolvedInstructions).toContain('*.ts');
1400
+ * ```
1401
+ */
1402
+ declare function testSkillActivation(skill: Skill, options?: SkillActivationOptions): Promise<SkillActivation>;
1403
+ /**
1404
+ * Assert that a skill's resolved instructions contain expected content.
1405
+ *
1406
+ * @param activation - The activation result to check
1407
+ * @param expected - Array of strings that must be present in the instructions
1408
+ * @throws AssertionError if any expected string is missing
1409
+ */
1410
+ declare function assertSkillContains(activation: SkillActivation, expected: string[]): void;
1411
+ /**
1412
+ * Validate a SKILL.md content string and return any issues.
1413
+ *
1414
+ * @param content - Full SKILL.md content
1415
+ * @returns Array of validation issues (empty if valid)
1416
+ */
1417
+ declare function validateSkill(content: string): string[];
1418
+ /**
1419
+ * Create a mock Skill instance for testing.
1420
+ *
1421
+ * @param overrides - Override any metadata fields
1422
+ * @param instructions - Custom instructions body
1423
+ */
1424
+ declare function mockSkill(overrides?: Partial<SkillMetadata>, instructions?: string): Skill;
1425
+ /**
1426
+ * Fluent builder for creating test skills.
1427
+ *
1428
+ * @example
1429
+ * ```typescript
1430
+ * import { MockSkillBuilder } from '@llmist/testing';
1431
+ *
1432
+ * const skill = new MockSkillBuilder()
1433
+ * .withName('gmail-read')
1434
+ * .withDescription('Read Gmail messages')
1435
+ * .withInstructions('Use gws to read emails.')
1436
+ * .build();
1437
+ * ```
1438
+ */
1439
+ declare class MockSkillBuilder {
1440
+ private _name;
1441
+ private _description;
1442
+ private _instructions;
1443
+ private _overrides;
1444
+ withName(name: string): this;
1445
+ withDescription(description: string): this;
1446
+ withInstructions(instructions: string): this;
1447
+ withModel(model: string): this;
1448
+ withContext(context: "fork" | "inline"): this;
1449
+ withPaths(paths: string[]): this;
1450
+ withAllowedTools(tools: string[]): this;
1451
+ withGadgets(gadgets: string[]): this;
1452
+ build(): Skill;
1453
+ }
1454
+
1356
1455
  /**
1357
1456
  * Stream testing utilities for llmist.
1358
1457
  * Provides helpers for creating and consuming test streams.
@@ -1492,4 +1591,4 @@ interface MockTUIApp {
1492
1591
  */
1493
1592
  declare const createMockTUIApp: () => MockTUIApp;
1494
1593
 
1495
- export { type MockAudioData, MockBuilder, MockConversationManager, type MockGadget, MockGadgetBuilder, type MockGadgetConfig, type MockImageData, MockManager, type MockMatcher, type MockMatcherContext, type MockOptions, MockPromptRecorder, MockProviderAdapter, type MockRegistration, type MockResponse, type MockStats, type MockTUIApp, type RecordedCall, type TestEnvironment, type TestEnvironmentOptions, type TestGadgetOptions, type TestGadgetResult, collectOutput, collectStream, collectStreamText, createAssistantMessage, createConversation, createConversationWithGadgets, createEmptyStream, createErrorStream, createLargeConversation, createMinimalConversation, createMockAdapter, createMockClient, createMockConversationManager, createMockGadget, createMockPrompt, createMockReadable, createMockStream, createMockTUIApp, createMockWritable, createSystemMessage, createTestEnvironment, createTestStream, createTextMockStream, createTextStream, createUserMessage, estimateTokens, getBufferedOutput, getMockManager, getStreamFinalChunk, mockGadget, mockLLM, resetMocks, testGadget, testGadgetBatch, waitFor };
1594
+ export { type MockAudioData, MockBuilder, MockConversationManager, type MockGadget, MockGadgetBuilder, type MockGadgetConfig, type MockImageData, MockManager, type MockMatcher, type MockMatcherContext, type MockOptions, MockPromptRecorder, MockProviderAdapter, type MockRegistration, type MockResponse, MockSkillBuilder, type MockStats, type MockTUIApp, type RecordedCall, type TestEnvironment, type TestEnvironmentOptions, type TestGadgetOptions, type TestGadgetResult, assertSkillContains, collectOutput, collectStream, collectStreamText, createAssistantMessage, createConversation, createConversationWithGadgets, createEmptyStream, createErrorStream, createLargeConversation, createMinimalConversation, createMockAdapter, createMockClient, createMockConversationManager, createMockGadget, createMockPrompt, createMockReadable, createMockStream, createMockTUIApp, createMockWritable, createSystemMessage, createTestEnvironment, createTestStream, createTextMockStream, createTextStream, createUserMessage, estimateTokens, getBufferedOutput, getMockManager, getStreamFinalChunk, mockGadget, mockLLM, mockSkill, resetMocks, testGadget, testGadgetBatch, testSkillActivation, testSkillParse, validateSkill, waitFor };
package/dist/index.js CHANGED
@@ -2141,6 +2141,102 @@ function mockGadget() {
2141
2141
  return new MockGadgetBuilder();
2142
2142
  }
2143
2143
 
2144
+ // src/skill-testing.ts
2145
+ import {
2146
+ parseSkillContent,
2147
+ Skill,
2148
+ validateMetadata
2149
+ } from "llmist";
2150
+ function testSkillParse(content, sourcePath = "/test/skill/SKILL.md") {
2151
+ return parseSkillContent(content, sourcePath, { type: "directory", path: "/test/skill" }, true);
2152
+ }
2153
+ async function testSkillActivation(skill, options) {
2154
+ return skill.activate({
2155
+ ...options,
2156
+ // Disable shell preprocessing in tests by default for safety
2157
+ cwd: options?.cwd ?? "/test"
2158
+ });
2159
+ }
2160
+ function assertSkillContains(activation, expected) {
2161
+ for (const text of expected) {
2162
+ if (!activation.resolvedInstructions.includes(text)) {
2163
+ throw new Error(
2164
+ `Expected skill instructions to contain "${text}" but it was not found.
2165
+ Instructions: ${activation.resolvedInstructions.slice(0, 500)}...`
2166
+ );
2167
+ }
2168
+ }
2169
+ }
2170
+ function validateSkill(content) {
2171
+ const parsed = testSkillParse(content);
2172
+ return validateMetadata(parsed.metadata);
2173
+ }
2174
+ function mockSkill(overrides, instructions = "Mock skill instructions for testing.") {
2175
+ const name = overrides?.name ?? "mock-skill";
2176
+ const description = overrides?.description ?? "A mock skill for testing";
2177
+ const metadataLines = Object.entries({ name, description, ...overrides }).filter(([_, v2]) => v2 !== void 0).map(([k2, v2]) => {
2178
+ if (Array.isArray(v2)) return `${k2}:
2179
+ ${v2.map((i) => ` - "${i}"`).join("\n")}`;
2180
+ return `${k2}: ${v2}`;
2181
+ }).join("\n");
2182
+ return Skill.fromContent(
2183
+ `---
2184
+ ${metadataLines}
2185
+ ---
2186
+ ${instructions}`,
2187
+ `/mock/${name}/SKILL.md`,
2188
+ { type: "directory", path: `/mock/${name}` }
2189
+ );
2190
+ }
2191
+ var MockSkillBuilder = class {
2192
+ _name = "mock-skill";
2193
+ _description = "A mock skill";
2194
+ _instructions = "Mock instructions.";
2195
+ _overrides = {};
2196
+ withName(name) {
2197
+ this._name = name;
2198
+ return this;
2199
+ }
2200
+ withDescription(description) {
2201
+ this._description = description;
2202
+ return this;
2203
+ }
2204
+ withInstructions(instructions) {
2205
+ this._instructions = instructions;
2206
+ return this;
2207
+ }
2208
+ withModel(model) {
2209
+ this._overrides.model = model;
2210
+ return this;
2211
+ }
2212
+ withContext(context) {
2213
+ this._overrides.context = context;
2214
+ return this;
2215
+ }
2216
+ withPaths(paths) {
2217
+ this._overrides.paths = paths;
2218
+ return this;
2219
+ }
2220
+ withAllowedTools(tools) {
2221
+ this._overrides["allowed-tools"] = tools;
2222
+ return this;
2223
+ }
2224
+ withGadgets(gadgets) {
2225
+ this._overrides.gadgets = gadgets;
2226
+ return this;
2227
+ }
2228
+ build() {
2229
+ return mockSkill(
2230
+ {
2231
+ name: this._name,
2232
+ description: this._description,
2233
+ ...this._overrides
2234
+ },
2235
+ this._instructions
2236
+ );
2237
+ }
2238
+ };
2239
+
2144
2240
  // src/stream-helpers.ts
2145
2241
  function createTestStream(chunks) {
2146
2242
  return (async function* () {
@@ -18954,6 +19050,8 @@ export {
18954
19050
  MockManager,
18955
19051
  MockPromptRecorder,
18956
19052
  MockProviderAdapter,
19053
+ MockSkillBuilder,
19054
+ assertSkillContains,
18957
19055
  collectOutput,
18958
19056
  collectStream,
18959
19057
  collectStreamText,
@@ -18985,9 +19083,13 @@ export {
18985
19083
  getStreamFinalChunk,
18986
19084
  mockGadget,
18987
19085
  mockLLM,
19086
+ mockSkill,
18988
19087
  resetMocks,
18989
19088
  testGadget,
18990
19089
  testGadgetBatch,
19090
+ testSkillActivation,
19091
+ testSkillParse,
19092
+ validateSkill,
18991
19093
  waitFor
18992
19094
  };
18993
19095
  /*! Bundled license information: