@signalwire/sdk 2.0.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/.github/workflows/publish.yml +27 -0
- package/.github/workflows/test.yml +17 -0
- package/CLAUDE.md +112 -0
- package/README.md +254 -0
- package/docs/MIGRATION-2.0.md +81 -0
- package/docs/agent-guide.md +869 -0
- package/docs/agent_guide.md +1026 -0
- package/docs/api-reference.md +2420 -0
- package/docs/api_reference.md +1301 -0
- package/docs/architecture.md +843 -0
- package/docs/cli-guide.md +579 -0
- package/docs/cli_guide.md +448 -0
- package/docs/cloud_functions_guide.md +474 -0
- package/docs/configuration.md +422 -0
- package/docs/contexts-guide.md +787 -0
- package/docs/contexts_guide.md +511 -0
- package/docs/datamap-guide.md +1141 -0
- package/docs/datamap_guide.md +595 -0
- package/docs/llm_parameters.md +239 -0
- package/docs/mcp_gateway_reference.md +648 -0
- package/docs/mcp_integration.md +108 -0
- package/docs/prefabs-guide.md +800 -0
- package/docs/sdk_features.md +477 -0
- package/docs/security.md +436 -0
- package/docs/serverless-guide.md +513 -0
- package/docs/skills-guide.md +857 -0
- package/docs/skills-system.md +301 -0
- package/docs/skills_parameter_schema.md +392 -0
- package/docs/skills_system.md +467 -0
- package/docs/swaig-reference.md +1627 -0
- package/docs/swaig_reference.md +910 -0
- package/docs/swml_service_guide.md +600 -0
- package/docs/third_party_skills.md +533 -0
- package/docs/web_service.md +677 -0
- package/examples/README.md +131 -0
- package/examples/advanced-datamap.ts +100 -0
- package/examples/advanced-dynamic-config.ts +70 -0
- package/examples/auto-vivified.ts +94 -0
- package/examples/call-flow.ts +63 -0
- package/examples/comprehensive-dynamic.ts +125 -0
- package/examples/contexts-steps.ts +65 -0
- package/examples/custom-path.ts +45 -0
- package/examples/datamap-tools.ts +55 -0
- package/examples/datasphere-multi-instance.ts +63 -0
- package/examples/datasphere-serverless-env.ts +68 -0
- package/examples/datasphere-webhook-env.ts +66 -0
- package/examples/datasphere.ts +37 -0
- package/examples/declarative.ts +100 -0
- package/examples/dynamic-config.ts +54 -0
- package/examples/dynamic-info-gatherer.ts +69 -0
- package/examples/dynamic-swml-service.ts +67 -0
- package/examples/gather-info.ts +71 -0
- package/examples/gather-per-question-functions-demo.ts +140 -0
- package/examples/joke-agent.ts +34 -0
- package/examples/kubernetes-agent.ts +45 -0
- package/examples/llm-params.ts +69 -0
- package/examples/mcp-agent.ts +84 -0
- package/examples/mcp-gateway.ts +35 -0
- package/examples/multi-agent.ts +73 -0
- package/examples/multi-endpoint.ts +79 -0
- package/examples/pom-prompt.ts +71 -0
- package/examples/prefab-concierge.ts +47 -0
- package/examples/prefab-faq.ts +54 -0
- package/examples/prefab-info-gatherer.ts +33 -0
- package/examples/prefab-receptionist.ts +36 -0
- package/examples/prefab-survey.ts +68 -0
- package/examples/record-call.ts +67 -0
- package/examples/relay-demo.ts +33 -0
- package/examples/room-and-sip.ts +94 -0
- package/examples/serverless-lambda.ts +35 -0
- package/examples/session-state.ts +83 -0
- package/examples/simple-agent.ts +36 -0
- package/examples/simple-static.ts +29 -0
- package/examples/skills-demo.ts +38 -0
- package/examples/step-function-inheritance-demo.ts +124 -0
- package/examples/swaig-features.ts +187 -0
- package/examples/swml-service-routing.ts +66 -0
- package/examples/swml-service.ts +38 -0
- package/examples/tap.ts +68 -0
- package/examples/verb-methods.ts +45 -0
- package/examples/web-search-multi-instance.ts +72 -0
- package/examples/web-search.ts +38 -0
- package/examples/wikipedia.ts +36 -0
- package/livewire/README.md +140 -0
- package/livewire/docs/migration-guide.md +228 -0
- package/livewire/examples/livewire-basic-agent.ts +74 -0
- package/livewire/examples/livewire-handoff.ts +197 -0
- package/livewire/examples/livewire-multi-tool.ts +117 -0
- package/package.json +38 -0
- package/relay/README.md +70 -0
- package/relay/RELAY_IMPLEMENTATION_GUIDE.md +1257 -0
- package/relay/docs/call-methods.md +474 -0
- package/relay/docs/client-reference.md +142 -0
- package/relay/docs/events.md +134 -0
- package/relay/docs/getting-started.md +134 -0
- package/relay/docs/guide.md +306 -0
- package/relay/docs/messaging.md +182 -0
- package/relay/examples/relay-inbound.ts +66 -0
- package/relay/examples/relay-messaging.ts +71 -0
- package/relay/examples/relay-outbound.ts +76 -0
- package/rest/README.md +95 -0
- package/rest/docs/calling.md +273 -0
- package/rest/docs/client-reference.md +107 -0
- package/rest/docs/compat.md +204 -0
- package/rest/docs/fabric.md +183 -0
- package/rest/docs/getting-started.md +110 -0
- package/rest/docs/guide.md +351 -0
- package/rest/docs/namespaces.md +285 -0
- package/rest/examples/rest-10dlc-registration.ts +161 -0
- package/rest/examples/rest-calling-ivr-and-ai.ts +102 -0
- package/rest/examples/rest-calling-play-and-record.ts +91 -0
- package/rest/examples/rest-client.ts +65 -0
- package/rest/examples/rest-compat-laml.ts +210 -0
- package/rest/examples/rest-datasphere-search.ts +82 -0
- package/rest/examples/rest-fabric-conferences-and-routing.ts +144 -0
- package/rest/examples/rest-fabric-subscribers-and-sip.ts +108 -0
- package/rest/examples/rest-fabric-swml-and-callflows.ts +99 -0
- package/rest/examples/rest-manage-resources.ts +65 -0
- package/rest/examples/rest-phone-number-management.ts +197 -0
- package/rest/examples/rest-queues-mfa-and-recordings.ts +143 -0
- package/rest/examples/rest-video-rooms.ts +186 -0
- package/src/AgentBase.ts +2489 -0
- package/src/AgentServer.ts +415 -0
- package/src/AuthHandler.ts +256 -0
- package/src/ConfigLoader.ts +447 -0
- package/src/ContextBuilder.ts +1150 -0
- package/src/DataMap.ts +449 -0
- package/src/FunctionResult.ts +866 -0
- package/src/Logger.ts +337 -0
- package/src/PomBuilder.ts +439 -0
- package/src/PromptManager.ts +133 -0
- package/src/SWMLHandler.ts +298 -0
- package/src/SWMLService.ts +717 -0
- package/src/SchemaUtils.ts +361 -0
- package/src/SecurityUtils.ts +153 -0
- package/src/ServerlessAdapter.ts +221 -0
- package/src/SessionManager.ts +311 -0
- package/src/SslConfig.ts +118 -0
- package/src/SwaigFunction.ts +276 -0
- package/src/SwmlBuilder.ts +258 -0
- package/src/SwmlVerbMethods.generated.ts +234 -0
- package/src/TypeInference.ts +181 -0
- package/src/WebService.ts +619 -0
- package/src/cli/agent-loader.ts +166 -0
- package/src/cli/mock-data.ts +111 -0
- package/src/cli/swaig-test.ts +452 -0
- package/src/generateVerbTypes.ts +322 -0
- package/src/index.ts +167 -0
- package/src/livewire/index.ts +950 -0
- package/src/prefabs/ConciergeAgent.ts +287 -0
- package/src/prefabs/FAQBotAgent.ts +384 -0
- package/src/prefabs/InfoGathererAgent.ts +339 -0
- package/src/prefabs/ReceptionistAgent.ts +366 -0
- package/src/prefabs/SurveyAgent.ts +646 -0
- package/src/prefabs/index.ts +27 -0
- package/src/relay/Action.ts +314 -0
- package/src/relay/Call.ts +854 -0
- package/src/relay/Deferred.ts +71 -0
- package/src/relay/Message.ts +148 -0
- package/src/relay/RelayClient.ts +1036 -0
- package/src/relay/RelayError.ts +14 -0
- package/src/relay/RelayEvent.ts +892 -0
- package/src/relay/constants.ts +132 -0
- package/src/relay/index.ts +123 -0
- package/src/relay/types.ts +149 -0
- package/src/rest/HttpClient.ts +103 -0
- package/src/rest/RestError.ts +31 -0
- package/src/rest/base/BaseResource.ts +19 -0
- package/src/rest/base/CrudResource.ts +51 -0
- package/src/rest/base/CrudWithAddresses.ts +26 -0
- package/src/rest/index.ts +200 -0
- package/src/rest/namespaces/addresses.ts +32 -0
- package/src/rest/namespaces/calling.ts +187 -0
- package/src/rest/namespaces/chat.ts +20 -0
- package/src/rest/namespaces/compat.ts +352 -0
- package/src/rest/namespaces/datasphere.ts +45 -0
- package/src/rest/namespaces/fabric.ts +222 -0
- package/src/rest/namespaces/imported-numbers.ts +20 -0
- package/src/rest/namespaces/logs.ts +84 -0
- package/src/rest/namespaces/lookup.ts +21 -0
- package/src/rest/namespaces/mfa.ts +30 -0
- package/src/rest/namespaces/number-groups.ts +38 -0
- package/src/rest/namespaces/phone-numbers.ts +44 -0
- package/src/rest/namespaces/project.ts +36 -0
- package/src/rest/namespaces/pubsub.ts +20 -0
- package/src/rest/namespaces/queues.ts +33 -0
- package/src/rest/namespaces/recordings.ts +28 -0
- package/src/rest/namespaces/registry.ts +101 -0
- package/src/rest/namespaces/short-codes.ts +28 -0
- package/src/rest/namespaces/sip-profile.ts +25 -0
- package/src/rest/namespaces/verified-callers.ts +27 -0
- package/src/rest/namespaces/video.ts +165 -0
- package/src/rest/pagination.ts +84 -0
- package/src/rest/types.ts +61 -0
- package/src/schema.json +12250 -0
- package/src/skills/SkillBase.ts +547 -0
- package/src/skills/SkillManager.ts +415 -0
- package/src/skills/SkillRegistry.ts +367 -0
- package/src/skills/builtin/api_ninjas_trivia.ts +280 -0
- package/src/skills/builtin/ask_claude.ts +241 -0
- package/src/skills/builtin/claude_skills.ts +978 -0
- package/src/skills/builtin/custom_skills.ts +312 -0
- package/src/skills/builtin/datasphere.ts +438 -0
- package/src/skills/builtin/datasphere_serverless.ts +339 -0
- package/src/skills/builtin/datetime.ts +130 -0
- package/src/skills/builtin/google_maps.ts +651 -0
- package/src/skills/builtin/index.ts +88 -0
- package/src/skills/builtin/info_gatherer.ts +405 -0
- package/src/skills/builtin/joke.ts +191 -0
- package/src/skills/builtin/math.ts +142 -0
- package/src/skills/builtin/mcp_gateway.ts +677 -0
- package/src/skills/builtin/native_vector_search.ts +901 -0
- package/src/skills/builtin/play_background_file.ts +358 -0
- package/src/skills/builtin/spider.ts +869 -0
- package/src/skills/builtin/swml_transfer.ts +635 -0
- package/src/skills/builtin/weather_api.ts +248 -0
- package/src/skills/builtin/web_search.ts +1074 -0
- package/src/skills/builtin/wikipedia_search.ts +299 -0
- package/src/skills/index.ts +12 -0
- package/src/types.ts +132 -0
- package/tests/AgentBase.test.ts +1093 -0
- package/tests/AgentServer.test.ts +126 -0
- package/tests/AuthHandler.test.ts +133 -0
- package/tests/ConfigLoader.test.ts +151 -0
- package/tests/ContextBuilder.test.ts +108 -0
- package/tests/DataMap.test.ts +367 -0
- package/tests/EphemeralSkillCopy.test.ts +107 -0
- package/tests/FunctionResult.test.ts +298 -0
- package/tests/GracefulShutdown.test.ts +46 -0
- package/tests/Logger.test.ts +420 -0
- package/tests/PomBuilder.test.ts +228 -0
- package/tests/ProxyDetection.test.ts +228 -0
- package/tests/SWMLService.test.ts +320 -0
- package/tests/SWMLVerbHandler.test.ts +523 -0
- package/tests/SchemaUtils.test.ts +106 -0
- package/tests/SchemaUtils.verb.test.ts +206 -0
- package/tests/SecurityUtils.test.ts +192 -0
- package/tests/ServerlessAdapter.test.ts +222 -0
- package/tests/SessionManager.test.ts +257 -0
- package/tests/SkillBaseFeatures.test.ts +130 -0
- package/tests/SkillMultiInstance.test.ts +102 -0
- package/tests/SkillParameterSchemas.test.ts +134 -0
- package/tests/SkillRegistrySchema.test.ts +84 -0
- package/tests/SslConfig.test.ts +97 -0
- package/tests/SwmlBuilder.test.ts +400 -0
- package/tests/TypeInference.test.ts +165 -0
- package/tests/VerbHandlerRegistry.test.ts +128 -0
- package/tests/cli/mock-data.test.ts +113 -0
- package/tests/cli/swaig-test.test.ts +108 -0
- package/tests/examples.test.ts +194 -0
- package/tests/fixtures/scrape-parity/README.md +53 -0
- package/tests/fixtures/scrape-parity/expected/01_simple_article.json +5 -0
- package/tests/fixtures/scrape-parity/expected/02_class_based_noise.json +5 -0
- package/tests/fixtures/scrape-parity/expected/03_nested_containers.json +5 -0
- package/tests/fixtures/scrape-parity/expected/04_bare_body.json +5 -0
- package/tests/fixtures/scrape-parity/expected/05_malformed.json +5 -0
- package/tests/fixtures/scrape-parity/expected/06_multi_class.json +5 -0
- package/tests/fixtures/scrape-parity/expected/07_anchor_pattern.json +5 -0
- package/tests/fixtures/scrape-parity/expected/08_inline_script.json +5 -0
- package/tests/fixtures/scrape-parity/expected/09_whitespace_nbsp.json +5 -0
- package/tests/fixtures/scrape-parity/expected/10_entity_unicode.json +5 -0
- package/tests/fixtures/scrape-parity/expected/11_cdata_comments.json +5 -0
- package/tests/fixtures/scrape-parity/expected/12_deep_nested_removals.json +5 -0
- package/tests/fixtures/scrape-parity/html/01_simple_article.html +18 -0
- package/tests/fixtures/scrape-parity/html/02_class_based_noise.html +18 -0
- package/tests/fixtures/scrape-parity/html/03_nested_containers.html +13 -0
- package/tests/fixtures/scrape-parity/html/04_bare_body.html +9 -0
- package/tests/fixtures/scrape-parity/html/05_malformed.html +11 -0
- package/tests/fixtures/scrape-parity/html/06_multi_class.html +18 -0
- package/tests/fixtures/scrape-parity/html/07_anchor_pattern.html +12 -0
- package/tests/fixtures/scrape-parity/html/08_inline_script.html +17 -0
- package/tests/fixtures/scrape-parity/html/09_whitespace_nbsp.html +21 -0
- package/tests/fixtures/scrape-parity/html/10_entity_unicode.html +10 -0
- package/tests/fixtures/scrape-parity/html/11_cdata_comments.html +13 -0
- package/tests/fixtures/scrape-parity/html/12_deep_nested_removals.html +24 -0
- package/tests/fixtures/scrape-parity/python_extract.py +109 -0
- package/tests/livewire/livewire.test.ts +780 -0
- package/tests/mcp.test.ts +221 -0
- package/tests/prefabs/prefabs.test.ts +1093 -0
- package/tests/relay/Action.test.ts +392 -0
- package/tests/relay/Call.test.ts +535 -0
- package/tests/relay/Deferred.test.ts +71 -0
- package/tests/relay/Message.test.ts +164 -0
- package/tests/relay/RelayClient.test.ts +779 -0
- package/tests/relay/RelayEvent.test.ts +463 -0
- package/tests/relay/helpers.ts +79 -0
- package/tests/rest/HttpClient.test.ts +274 -0
- package/tests/rest/RestError.test.ts +53 -0
- package/tests/rest/calling.test.ts +156 -0
- package/tests/rest/client.test.ts +197 -0
- package/tests/rest/compat.test.ts +335 -0
- package/tests/rest/datasphere.test.ts +71 -0
- package/tests/rest/fabric.test.ts +186 -0
- package/tests/rest/helpers.ts +95 -0
- package/tests/rest/logs.test.ts +68 -0
- package/tests/rest/pagination.test.ts +133 -0
- package/tests/rest/registry.test.ts +94 -0
- package/tests/rest/relay-rest.test.ts +290 -0
- package/tests/rest/video.test.ts +173 -0
- package/tests/setup.ts +6 -0
- package/tests/skills/SkillBase.test.ts +108 -0
- package/tests/skills/SkillManager.test.ts +268 -0
- package/tests/skills/SkillRegistry.test.ts +176 -0
- package/tests/skills/builtin.test.ts +1472 -0
- package/tests/skills/claude-skills.test.ts +54 -0
- package/tests/skills/custom-skills.test.ts +53 -0
- package/tests/skills/datasphere-serverless.test.ts +70 -0
- package/tests/skills/datasphere.test.ts +107 -0
- package/tests/skills/datetime.test.ts +101 -0
- package/tests/skills/google-maps.test.ts +78 -0
- package/tests/skills/info-gatherer.test.ts +411 -0
- package/tests/skills/joke.test.ts +81 -0
- package/tests/skills/math.test.ts +68 -0
- package/tests/skills/mcp-gateway.test.ts +101 -0
- package/tests/skills/play-background.test.ts +54 -0
- package/tests/skills/spider.test.ts +108 -0
- package/tests/skills/swml-transfer.test.ts +178 -0
- package/tests/skills/trivia.test.ts +54 -0
- package/tests/skills/vector-search.test.ts +135 -0
- package/tests/skills/weather-api.test.ts +77 -0
- package/tests/skills/web-search-parity.test.ts +59 -0
- package/tests/skills/web-search.test.ts +103 -0
- package/tests/skills/wikipedia.test.ts +63 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { SkillRegistry } from '../src/skills/SkillRegistry.js';
|
|
3
|
+
import { registerBuiltinSkills } from '../src/skills/builtin/index.js';
|
|
4
|
+
|
|
5
|
+
describe('SkillRegistry Schema', () => {
|
|
6
|
+
let registry: SkillRegistry;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
SkillRegistry.resetInstance();
|
|
10
|
+
registry = SkillRegistry.getInstance();
|
|
11
|
+
registerBuiltinSkills();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('getSkillSchema returns full schema for a registered skill', () => {
|
|
15
|
+
const schema = registry.getSkillSchema('datetime');
|
|
16
|
+
expect(schema).toBeDefined();
|
|
17
|
+
expect(schema!.name).toBe('datetime');
|
|
18
|
+
expect(schema!.description).toBeTruthy();
|
|
19
|
+
expect(schema!.version).toBeTruthy();
|
|
20
|
+
expect(schema!.supportsMultipleInstances).toBe(false);
|
|
21
|
+
expect(schema!.parameters).toHaveProperty('swaig_fields');
|
|
22
|
+
expect(schema!.parameters).toHaveProperty('skip_prompt');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('getSkillSchema returns undefined for unregistered skill', () => {
|
|
26
|
+
const schema = registry.getSkillSchema('nonexistent');
|
|
27
|
+
expect(schema).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('getAllSkillsSchema returns schemas for all 19 built-in skills', () => {
|
|
31
|
+
const allSchemas = registry.getAllSkillsSchema();
|
|
32
|
+
const names = Object.keys(allSchemas);
|
|
33
|
+
expect(names.length).toBe(19);
|
|
34
|
+
expect(names).toContain('datetime');
|
|
35
|
+
expect(names).toContain('math');
|
|
36
|
+
expect(names).toContain('joke');
|
|
37
|
+
expect(names).toContain('weather_api');
|
|
38
|
+
expect(names).toContain('datasphere');
|
|
39
|
+
expect(names).toContain('native_vector_search');
|
|
40
|
+
expect(names).toContain('claude_skills');
|
|
41
|
+
expect(names).toContain('ask_claude');
|
|
42
|
+
expect(names).toContain('mcp_gateway');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('every schema entry has type and description', () => {
|
|
46
|
+
const allSchemas = registry.getAllSkillsSchema();
|
|
47
|
+
for (const [skillName, schema] of Object.entries(allSchemas)) {
|
|
48
|
+
for (const [paramName, entry] of Object.entries(schema.parameters)) {
|
|
49
|
+
expect(entry.type, `${skillName}.${paramName} missing type`).toBeTruthy();
|
|
50
|
+
expect(entry.description, `${skillName}.${paramName} missing description`).toBeTruthy();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('multi-instance skills report supportsMultipleInstances = true', () => {
|
|
56
|
+
const allSchemas = registry.getAllSkillsSchema();
|
|
57
|
+
expect(allSchemas['datasphere'].supportsMultipleInstances).toBe(true);
|
|
58
|
+
expect(allSchemas['datasphere_serverless'].supportsMultipleInstances).toBe(true);
|
|
59
|
+
expect(allSchemas['native_vector_search'].supportsMultipleInstances).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('single-instance skills report supportsMultipleInstances = false', () => {
|
|
63
|
+
const allSchemas = registry.getAllSkillsSchema();
|
|
64
|
+
expect(allSchemas['datetime'].supportsMultipleInstances).toBe(false);
|
|
65
|
+
expect(allSchemas['math'].supportsMultipleInstances).toBe(false);
|
|
66
|
+
expect(allSchemas['weather_api'].supportsMultipleInstances).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('listAllSkillSources groups skills by source', () => {
|
|
70
|
+
const sources = registry.listAllSkillSources();
|
|
71
|
+
expect(sources).toBeDefined();
|
|
72
|
+
// All 19 should appear in some category
|
|
73
|
+
const total = Object.values(sources).flat().length;
|
|
74
|
+
expect(total).toBe(19);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('weather_api schema includes api_key with hidden + env_var', () => {
|
|
78
|
+
const schema = registry.getSkillSchema('weather_api');
|
|
79
|
+
expect(schema).toBeDefined();
|
|
80
|
+
expect(schema!.parameters).toHaveProperty('api_key');
|
|
81
|
+
expect(schema!.parameters['api_key'].hidden).toBe(true);
|
|
82
|
+
expect(schema!.parameters['api_key'].env_var).toBe('WEATHER_API_KEY');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
|
2
|
+
import { SslConfig } from '../src/SslConfig.js';
|
|
3
|
+
import { writeFileSync, mkdirSync, rmSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const TEST_DIR = join(process.cwd(), '__ssl_test_tmp__');
|
|
7
|
+
|
|
8
|
+
describe('SslConfig', () => {
|
|
9
|
+
beforeAll(() => {
|
|
10
|
+
mkdirSync(TEST_DIR, { recursive: true });
|
|
11
|
+
writeFileSync(join(TEST_DIR, 'cert.pem'), '-----BEGIN CERTIFICATE-----\ntest\n-----END CERTIFICATE-----');
|
|
12
|
+
writeFileSync(join(TEST_DIR, 'key.pem'), '-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
rmSync(TEST_DIR, { recursive: true, force: true });
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('defaults to disabled', () => {
|
|
20
|
+
const ssl = new SslConfig();
|
|
21
|
+
expect(ssl.enabled).toBe(false);
|
|
22
|
+
expect(ssl.isConfigured()).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('can be enabled via options', () => {
|
|
26
|
+
const ssl = new SslConfig({
|
|
27
|
+
enabled: true,
|
|
28
|
+
certPath: join(TEST_DIR, 'cert.pem'),
|
|
29
|
+
keyPath: join(TEST_DIR, 'key.pem'),
|
|
30
|
+
});
|
|
31
|
+
expect(ssl.enabled).toBe(true);
|
|
32
|
+
expect(ssl.isConfigured()).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('isConfigured returns false when files missing', () => {
|
|
36
|
+
const ssl = new SslConfig({
|
|
37
|
+
enabled: true,
|
|
38
|
+
certPath: '/nonexistent/cert.pem',
|
|
39
|
+
keyPath: '/nonexistent/key.pem',
|
|
40
|
+
});
|
|
41
|
+
expect(ssl.isConfigured()).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('getCert reads certificate file', () => {
|
|
45
|
+
const ssl = new SslConfig({
|
|
46
|
+
enabled: true,
|
|
47
|
+
certPath: join(TEST_DIR, 'cert.pem'),
|
|
48
|
+
keyPath: join(TEST_DIR, 'key.pem'),
|
|
49
|
+
});
|
|
50
|
+
const cert = ssl.getCert();
|
|
51
|
+
expect(cert).toContain('BEGIN CERTIFICATE');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('getKey reads key file', () => {
|
|
55
|
+
const ssl = new SslConfig({
|
|
56
|
+
enabled: true,
|
|
57
|
+
certPath: join(TEST_DIR, 'cert.pem'),
|
|
58
|
+
keyPath: join(TEST_DIR, 'key.pem'),
|
|
59
|
+
});
|
|
60
|
+
const key = ssl.getKey();
|
|
61
|
+
expect(key).toContain('BEGIN PRIVATE KEY');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('getCert returns null for missing file', () => {
|
|
65
|
+
const ssl = new SslConfig({ enabled: true, certPath: '/missing' });
|
|
66
|
+
expect(ssl.getCert()).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('getHstsHeader returns HSTS value when enabled', () => {
|
|
70
|
+
const ssl = new SslConfig({ enabled: true, hsts: true });
|
|
71
|
+
const header = ssl.getHstsHeader();
|
|
72
|
+
expect(header).toContain('max-age=31536000');
|
|
73
|
+
expect(header).toContain('includeSubDomains');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('getHstsHeader returns null when disabled', () => {
|
|
77
|
+
const ssl = new SslConfig({ enabled: false });
|
|
78
|
+
expect(ssl.getHstsHeader()).toBeNull();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('getServerOptions returns cert and key', () => {
|
|
82
|
+
const ssl = new SslConfig({
|
|
83
|
+
enabled: true,
|
|
84
|
+
certPath: join(TEST_DIR, 'cert.pem'),
|
|
85
|
+
keyPath: join(TEST_DIR, 'key.pem'),
|
|
86
|
+
});
|
|
87
|
+
const opts = ssl.getServerOptions();
|
|
88
|
+
expect(opts).not.toBeNull();
|
|
89
|
+
expect(opts!.cert).toContain('CERTIFICATE');
|
|
90
|
+
expect(opts!.key).toContain('PRIVATE KEY');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('getServerOptions returns null when files missing', () => {
|
|
94
|
+
const ssl = new SslConfig({ enabled: true });
|
|
95
|
+
expect(ssl.getServerOptions()).toBeNull();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { SwmlBuilder } from '../src/SwmlBuilder.js';
|
|
3
|
+
|
|
4
|
+
describe('SwmlBuilder — verb auto-vivification', () => {
|
|
5
|
+
let builder: SwmlBuilder;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
builder = new SwmlBuilder();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('verb method existence', () => {
|
|
12
|
+
it('has all ~38 verb methods', () => {
|
|
13
|
+
const schemaUtils = SwmlBuilder.getSchemaUtils();
|
|
14
|
+
const verbNames = schemaUtils.getVerbNames();
|
|
15
|
+
expect(verbNames.length).toBe(38);
|
|
16
|
+
for (const name of verbNames) {
|
|
17
|
+
expect(typeof (builder as Record<string, unknown>)[name]).toBe('function');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('has answer method', () => {
|
|
22
|
+
expect(typeof builder.answer).toBe('function');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('has hangup method', () => {
|
|
26
|
+
expect(typeof builder.hangup).toBe('function');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('has play method', () => {
|
|
30
|
+
expect(typeof builder.play).toBe('function');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('has sleep method', () => {
|
|
34
|
+
expect(typeof builder.sleep).toBe('function');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('verb method invocation', () => {
|
|
39
|
+
it('answer() adds answer verb to document', () => {
|
|
40
|
+
builder.answer();
|
|
41
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
42
|
+
expect(doc.sections.main).toHaveLength(1);
|
|
43
|
+
expect(doc.sections.main[0]).toEqual({ answer: {} });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('answer() with config adds config', () => {
|
|
47
|
+
builder.answer({ max_duration: 3600 });
|
|
48
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
49
|
+
expect(doc.sections.main[0]).toEqual({ answer: { max_duration: 3600 } });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('hangup() with reason', () => {
|
|
53
|
+
builder.hangup({ reason: 'busy' });
|
|
54
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
55
|
+
expect(doc.sections.main[0]).toEqual({ hangup: { reason: 'busy' } });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('hangup() without args adds empty config', () => {
|
|
59
|
+
builder.hangup();
|
|
60
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
61
|
+
expect(doc.sections.main[0]).toEqual({ hangup: {} });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('play() with config', () => {
|
|
65
|
+
builder.play({ url: 'https://example.com/audio.mp3' });
|
|
66
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
67
|
+
expect(doc.sections.main[0]).toEqual({ play: { url: 'https://example.com/audio.mp3' } });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('tap() with required uri', () => {
|
|
71
|
+
builder.tap({ uri: 'wss://example.com/tap' });
|
|
72
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
73
|
+
expect(doc.sections.main[0]).toEqual({ tap: { uri: 'wss://example.com/tap' } });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('goto() with required label', () => {
|
|
77
|
+
builder.goto({ label: 'start' });
|
|
78
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
79
|
+
expect(doc.sections.main[0]).toEqual({ goto: { label: 'start' } });
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('label() with string', () => {
|
|
83
|
+
(builder as Record<string, Function>)['label']('greeting');
|
|
84
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
85
|
+
expect(doc.sections.main[0]).toEqual({ label: 'greeting' });
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('sleep special handling', () => {
|
|
90
|
+
it('sleep() with number adds integer directly', () => {
|
|
91
|
+
builder.sleep(5000);
|
|
92
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
93
|
+
expect(doc.sections.main[0]).toEqual({ sleep: 5000 });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('sleep() with config object', () => {
|
|
97
|
+
builder.sleep({ duration: 3000 });
|
|
98
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
99
|
+
expect(doc.sections.main[0]).toEqual({ sleep: { duration: 3000 } });
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('fluent chaining', () => {
|
|
104
|
+
it('returns this for chaining', () => {
|
|
105
|
+
const result = builder.answer();
|
|
106
|
+
expect(result).toBe(builder);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('chains multiple verb calls', () => {
|
|
110
|
+
builder.answer().hangup();
|
|
111
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
112
|
+
expect(doc.sections.main).toHaveLength(2);
|
|
113
|
+
expect(doc.sections.main[0]).toEqual({ answer: {} });
|
|
114
|
+
expect(doc.sections.main[1]).toEqual({ hangup: {} });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('full call flow: answer → play → hangup', () => {
|
|
118
|
+
builder
|
|
119
|
+
.answer({ max_duration: 3600 })
|
|
120
|
+
.play({ url: 'https://example.com/greeting.mp3' })
|
|
121
|
+
.hangup({ reason: 'hangup' });
|
|
122
|
+
|
|
123
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
124
|
+
expect(doc.sections.main).toHaveLength(3);
|
|
125
|
+
expect(doc.sections.main[0]).toEqual({ answer: { max_duration: 3600 } });
|
|
126
|
+
expect(doc.sections.main[1]).toEqual({ play: { url: 'https://example.com/greeting.mp3' } });
|
|
127
|
+
expect(doc.sections.main[2]).toEqual({ hangup: { reason: 'hangup' } });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('sleep chains correctly', () => {
|
|
131
|
+
const result = builder.sleep(1000);
|
|
132
|
+
expect(result).toBe(builder);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('mixing verb methods with addVerb()', () => {
|
|
137
|
+
it('verb methods and addVerb produce same output', () => {
|
|
138
|
+
builder.answer();
|
|
139
|
+
builder.addVerb('denoise', {});
|
|
140
|
+
builder.hangup();
|
|
141
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
142
|
+
expect(doc.sections.main).toHaveLength(3);
|
|
143
|
+
expect(doc.sections.main[0]).toEqual({ answer: {} });
|
|
144
|
+
expect(doc.sections.main[1]).toEqual({ denoise: {} });
|
|
145
|
+
expect(doc.sections.main[2]).toEqual({ hangup: {} });
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('reset()', () => {
|
|
150
|
+
it('clears verb-method-added content', () => {
|
|
151
|
+
builder.answer().hangup();
|
|
152
|
+
builder.reset();
|
|
153
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
154
|
+
expect(doc.sections.main).toHaveLength(0);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('returns this for fluent chaining', () => {
|
|
158
|
+
const result = builder.answer().reset();
|
|
159
|
+
expect(result).toBe(builder);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('chains reset with further verbs', () => {
|
|
163
|
+
builder.answer().hangup().reset().answer();
|
|
164
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
165
|
+
expect(doc.sections.main).toHaveLength(1);
|
|
166
|
+
expect(doc.sections.main[0]).toEqual({ answer: {} });
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('validation', () => {
|
|
171
|
+
it('rejects missing required properties', () => {
|
|
172
|
+
expect(() => {
|
|
173
|
+
builder.tap({} as any);
|
|
174
|
+
}).toThrow('SWML verb validation failed');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('rejects missing required properties with detail', () => {
|
|
178
|
+
expect(() => {
|
|
179
|
+
builder.tap({} as any);
|
|
180
|
+
}).toThrow("'uri'");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('passes valid configs', () => {
|
|
184
|
+
expect(() => {
|
|
185
|
+
builder.tap({ uri: 'wss://example.com' });
|
|
186
|
+
}).not.toThrow();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('SWML_SKIP_SCHEMA_VALIDATION disables validation', () => {
|
|
190
|
+
const origEnv = process.env['SWML_SKIP_SCHEMA_VALIDATION'];
|
|
191
|
+
try {
|
|
192
|
+
process.env['SWML_SKIP_SCHEMA_VALIDATION'] = 'true';
|
|
193
|
+
const skipBuilder = new SwmlBuilder();
|
|
194
|
+
// Should not throw even though required uri is missing
|
|
195
|
+
expect(() => {
|
|
196
|
+
skipBuilder.tap({} as any);
|
|
197
|
+
}).not.toThrow();
|
|
198
|
+
} finally {
|
|
199
|
+
if (origEnv === undefined) {
|
|
200
|
+
delete process.env['SWML_SKIP_SCHEMA_VALIDATION'];
|
|
201
|
+
} else {
|
|
202
|
+
process.env['SWML_SKIP_SCHEMA_VALIDATION'] = origEnv;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('addVerbToSection()', () => {
|
|
209
|
+
it('still works with custom sections', () => {
|
|
210
|
+
builder.addVerbToSection('greet', 'play', { url: 'https://example.com/hi.mp3' });
|
|
211
|
+
const doc = builder.getDocument() as { sections: Record<string, unknown[]> };
|
|
212
|
+
expect(doc.sections['greet']).toHaveLength(1);
|
|
213
|
+
expect(doc.sections['greet'][0]).toEqual({ play: { url: 'https://example.com/hi.mp3' } });
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('say() — text-to-speech convenience', () => {
|
|
218
|
+
it('adds a play verb with say: prefix', () => {
|
|
219
|
+
builder.say('Hello world');
|
|
220
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
221
|
+
expect(doc.sections.main).toHaveLength(1);
|
|
222
|
+
expect(doc.sections.main[0]).toEqual({ play: { url: 'say:Hello world' } });
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('passes voice option as say_voice', () => {
|
|
226
|
+
builder.say('Hello', { voice: 'en-US-Neural2-F' });
|
|
227
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
228
|
+
expect(doc.sections.main[0]).toEqual({
|
|
229
|
+
play: { url: 'say:Hello', say_voice: 'en-US-Neural2-F' },
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('passes all TTS options', () => {
|
|
234
|
+
builder.say('Test', { voice: 'v', language: 'en', gender: 'female', volume: 10 });
|
|
235
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
236
|
+
expect(doc.sections.main[0]).toEqual({
|
|
237
|
+
play: {
|
|
238
|
+
url: 'say:Test',
|
|
239
|
+
say_voice: 'v',
|
|
240
|
+
say_language: 'en',
|
|
241
|
+
say_gender: 'female',
|
|
242
|
+
volume: 10,
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('returns this for fluent chaining', () => {
|
|
248
|
+
const result = builder.say('Hi');
|
|
249
|
+
expect(result).toBe(builder);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('chains say with other verbs', () => {
|
|
253
|
+
builder.answer().say('Welcome').hangup();
|
|
254
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
255
|
+
expect(doc.sections.main).toHaveLength(3);
|
|
256
|
+
expect(doc.sections.main[1]).toEqual({ play: { url: 'say:Welcome' } });
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe('addSection() — create empty section', () => {
|
|
261
|
+
it('creates an empty named section', () => {
|
|
262
|
+
builder.addSection('greetings');
|
|
263
|
+
const doc = builder.getDocument() as { sections: Record<string, unknown[]> };
|
|
264
|
+
expect(doc.sections['greetings']).toEqual([]);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('is a no-op if section already exists', () => {
|
|
268
|
+
builder.addVerbToSection('greetings', 'play', { url: 'https://example.com/hi.mp3' });
|
|
269
|
+
builder.addSection('greetings');
|
|
270
|
+
const doc = builder.getDocument() as { sections: Record<string, unknown[]> };
|
|
271
|
+
expect(doc.sections['greetings']).toHaveLength(1);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('returns this for fluent chaining', () => {
|
|
275
|
+
const result = builder.addSection('test');
|
|
276
|
+
expect(result).toBe(builder);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('chains with addVerbToSection', () => {
|
|
280
|
+
builder.addSection('custom').addVerbToSection('custom', 'play', { url: 'say:hi' });
|
|
281
|
+
const doc = builder.getDocument() as { sections: Record<string, unknown[]> };
|
|
282
|
+
expect(doc.sections['custom']).toHaveLength(1);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
describe('build() — alias for getDocument()', () => {
|
|
287
|
+
it('returns the same result as getDocument', () => {
|
|
288
|
+
builder.answer();
|
|
289
|
+
expect(builder.build()).toBe(builder.getDocument());
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('returns document with version and sections', () => {
|
|
293
|
+
builder.answer();
|
|
294
|
+
const doc = builder.build();
|
|
295
|
+
expect(doc).toHaveProperty('version', '1.0.0');
|
|
296
|
+
expect(doc).toHaveProperty('sections');
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe('render() — alias for renderDocument()', () => {
|
|
301
|
+
it('returns the same result as renderDocument', () => {
|
|
302
|
+
builder.answer();
|
|
303
|
+
expect(builder.render()).toBe(builder.renderDocument());
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('produces valid JSON', () => {
|
|
307
|
+
builder.answer().hangup();
|
|
308
|
+
const json = builder.render();
|
|
309
|
+
const parsed = JSON.parse(json);
|
|
310
|
+
expect(parsed.version).toBe('1.0.0');
|
|
311
|
+
expect(parsed.sections.main).toHaveLength(2);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe('constructor with initialDocument', () => {
|
|
316
|
+
it('accepts an initial document', () => {
|
|
317
|
+
const initial = {
|
|
318
|
+
version: '1.0.0',
|
|
319
|
+
sections: { main: [{ answer: {} }] },
|
|
320
|
+
};
|
|
321
|
+
const b = new SwmlBuilder({ initialDocument: initial });
|
|
322
|
+
const doc = b.getDocument() as { sections: { main: unknown[] } };
|
|
323
|
+
expect(doc.sections.main).toHaveLength(1);
|
|
324
|
+
expect(doc.sections.main[0]).toEqual({ answer: {} });
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('defaults version to 1.0.0 when omitted', () => {
|
|
328
|
+
const b = new SwmlBuilder({ initialDocument: { sections: { main: [] } } });
|
|
329
|
+
expect(b.getDocument()).toHaveProperty('version', '1.0.0');
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('defaults sections when omitted', () => {
|
|
333
|
+
const b = new SwmlBuilder({ initialDocument: {} });
|
|
334
|
+
const doc = b.getDocument() as { sections: Record<string, unknown[]> };
|
|
335
|
+
expect(doc.sections).toHaveProperty('main');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('still works with no options', () => {
|
|
339
|
+
const b = new SwmlBuilder();
|
|
340
|
+
const doc = b.getDocument() as { sections: { main: unknown[] } };
|
|
341
|
+
expect(doc).toHaveProperty('version', '1.0.0');
|
|
342
|
+
expect(doc.sections.main).toHaveLength(0);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe('document public accessor', () => {
|
|
347
|
+
it('exposes the internal document via getter', () => {
|
|
348
|
+
builder.answer();
|
|
349
|
+
const doc = builder.document;
|
|
350
|
+
expect(doc.version).toBe('1.0.0');
|
|
351
|
+
expect(doc.sections.main).toHaveLength(1);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('returns the same reference as getDocument', () => {
|
|
355
|
+
expect(builder.document).toBe(builder.getDocument());
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
describe('hangup reason type widened to string', () => {
|
|
360
|
+
it('accepts arbitrary string reasons', () => {
|
|
361
|
+
builder.hangup({ reason: 'custom_reason' });
|
|
362
|
+
const doc = builder.getDocument() as { sections: { main: unknown[] } };
|
|
363
|
+
expect(doc.sections.main[0]).toEqual({ hangup: { reason: 'custom_reason' } });
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe('getDocument() and renderDocument()', () => {
|
|
368
|
+
it('getDocument returns correct structure', () => {
|
|
369
|
+
builder.answer();
|
|
370
|
+
const doc = builder.getDocument();
|
|
371
|
+
expect(doc).toHaveProperty('version', '1.0.0');
|
|
372
|
+
expect(doc).toHaveProperty('sections');
|
|
373
|
+
const sections = doc['sections'] as Record<string, unknown[]>;
|
|
374
|
+
expect(sections).toHaveProperty('main');
|
|
375
|
+
expect(sections['main']).toHaveLength(1);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('renderDocument produces valid JSON', () => {
|
|
379
|
+
builder.answer().sleep(1000).hangup();
|
|
380
|
+
const json = builder.renderDocument();
|
|
381
|
+
const parsed = JSON.parse(json);
|
|
382
|
+
expect(parsed.version).toBe('1.0.0');
|
|
383
|
+
expect(parsed.sections.main).toHaveLength(3);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe('getSchemaUtils()', () => {
|
|
388
|
+
it('returns a SchemaUtils instance', () => {
|
|
389
|
+
const utils = SwmlBuilder.getSchemaUtils();
|
|
390
|
+
expect(utils).toBeDefined();
|
|
391
|
+
expect(typeof utils.getVerbNames).toBe('function');
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('returns the same singleton', () => {
|
|
395
|
+
const a = SwmlBuilder.getSchemaUtils();
|
|
396
|
+
const b = SwmlBuilder.getSchemaUtils();
|
|
397
|
+
expect(a).toBe(b);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
});
|