@solidxai/core 0.1.20 → 0.1.21-beta.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/CHANGELOG.md +51 -0
- package/agenthub-ui-json-seed-audit.md +151 -0
- package/dist/commands/run-tests.command.d.ts +2 -0
- package/dist/commands/run-tests.command.d.ts.map +1 -1
- package/dist/commands/run-tests.command.js +16 -0
- package/dist/commands/run-tests.command.js.map +1 -1
- package/dist/constants/error-messages.js +1 -1
- package/dist/constants/error-messages.js.map +1 -1
- package/dist/controllers/agent-config-version.controller.d.ts +93 -0
- package/dist/controllers/agent-config-version.controller.d.ts.map +1 -0
- package/dist/controllers/agent-config-version.controller.js +211 -0
- package/dist/controllers/agent-config-version.controller.js.map +1 -0
- package/dist/controllers/agent-registry.controller.d.ts +2 -0
- package/dist/controllers/agent-registry.controller.d.ts.map +1 -1
- package/dist/controllers/agent-registry.controller.js +14 -0
- package/dist/controllers/agent-registry.controller.js.map +1 -1
- package/dist/controllers/agent-session.controller.d.ts +18 -0
- package/dist/controllers/agent-session.controller.d.ts.map +1 -1
- package/dist/controllers/agent-session.controller.js +18 -0
- package/dist/controllers/agent-session.controller.js.map +1 -1
- package/dist/controllers/agent-user-memory.controller.d.ts +16 -0
- package/dist/controllers/agent-user-memory.controller.d.ts.map +1 -0
- package/dist/controllers/agent-user-memory.controller.js +135 -0
- package/dist/controllers/agent-user-memory.controller.js.map +1 -0
- package/dist/dtos/activate-agent-registry.dto.d.ts +5 -0
- package/dist/dtos/activate-agent-registry.dto.d.ts.map +1 -0
- package/dist/dtos/activate-agent-registry.dto.js +34 -0
- package/dist/dtos/activate-agent-registry.dto.js.map +1 -0
- package/dist/dtos/create-agent-config-version.dto.d.ts +8 -0
- package/dist/dtos/create-agent-config-version.dto.d.ts.map +1 -0
- package/dist/dtos/create-agent-config-version.dto.js +50 -0
- package/dist/dtos/create-agent-config-version.dto.js.map +1 -0
- package/dist/dtos/create-agent-hub-tag.dto.d.ts +2 -0
- package/dist/dtos/create-agent-hub-tag.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-hub-tag.dto.js +13 -1
- package/dist/dtos/create-agent-hub-tag.dto.js.map +1 -1
- package/dist/dtos/create-agent-registry.dto.d.ts +2 -0
- package/dist/dtos/create-agent-registry.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-registry.dto.js +13 -1
- package/dist/dtos/create-agent-registry.dto.js.map +1 -1
- package/dist/dtos/create-agent-skill-registry.dto.d.ts +2 -0
- package/dist/dtos/create-agent-skill-registry.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-skill-registry.dto.js +13 -1
- package/dist/dtos/create-agent-skill-registry.dto.js.map +1 -1
- package/dist/dtos/create-agent-tool-registry.dto.d.ts +2 -0
- package/dist/dtos/create-agent-tool-registry.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-tool-registry.dto.js +13 -1
- package/dist/dtos/create-agent-tool-registry.dto.js.map +1 -1
- package/dist/dtos/create-agent-user-memory.dto.d.ts +8 -0
- package/dist/dtos/create-agent-user-memory.dto.d.ts.map +1 -0
- package/dist/dtos/create-agent-user-memory.dto.js +52 -0
- package/dist/dtos/create-agent-user-memory.dto.js.map +1 -0
- package/dist/dtos/create-secret.dto.d.ts +2 -0
- package/dist/dtos/create-secret.dto.d.ts.map +1 -1
- package/dist/dtos/create-secret.dto.js +13 -1
- package/dist/dtos/create-secret.dto.js.map +1 -1
- package/dist/dtos/test-run-request.dto.d.ts +1 -0
- package/dist/dtos/test-run-request.dto.d.ts.map +1 -1
- package/dist/dtos/test-run-request.dto.js +6 -1
- package/dist/dtos/test-run-request.dto.js.map +1 -1
- package/dist/dtos/update-agent-config-version.dto.d.ts +9 -0
- package/dist/dtos/update-agent-config-version.dto.d.ts.map +1 -0
- package/dist/dtos/update-agent-config-version.dto.js +58 -0
- package/dist/dtos/update-agent-config-version.dto.js.map +1 -0
- package/dist/dtos/update-agent-hub-tag.dto.d.ts +2 -0
- package/dist/dtos/update-agent-hub-tag.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-hub-tag.dto.js +13 -1
- package/dist/dtos/update-agent-hub-tag.dto.js.map +1 -1
- package/dist/dtos/update-agent-registry.dto.d.ts +2 -0
- package/dist/dtos/update-agent-registry.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-registry.dto.js +13 -1
- package/dist/dtos/update-agent-registry.dto.js.map +1 -1
- package/dist/dtos/update-agent-skill-registry.dto.d.ts +2 -0
- package/dist/dtos/update-agent-skill-registry.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-skill-registry.dto.js +13 -1
- package/dist/dtos/update-agent-skill-registry.dto.js.map +1 -1
- package/dist/dtos/update-agent-tool-registry.dto.d.ts +2 -0
- package/dist/dtos/update-agent-tool-registry.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-tool-registry.dto.js +13 -1
- package/dist/dtos/update-agent-tool-registry.dto.js.map +1 -1
- package/dist/dtos/update-agent-user-memory.dto.d.ts +9 -0
- package/dist/dtos/update-agent-user-memory.dto.d.ts.map +1 -0
- package/dist/dtos/update-agent-user-memory.dto.js +58 -0
- package/dist/dtos/update-agent-user-memory.dto.js.map +1 -0
- package/dist/dtos/update-secret.dto.d.ts +2 -0
- package/dist/dtos/update-secret.dto.d.ts.map +1 -1
- package/dist/dtos/update-secret.dto.js +13 -1
- package/dist/dtos/update-secret.dto.js.map +1 -1
- package/dist/entities/agent-config-version.entity.d.ts +9 -0
- package/dist/entities/agent-config-version.entity.d.ts.map +1 -0
- package/dist/entities/agent-config-version.entity.js +44 -0
- package/dist/entities/agent-config-version.entity.js.map +1 -0
- package/dist/entities/agent-hub-tag.entity.d.ts +2 -0
- package/dist/entities/agent-hub-tag.entity.d.ts.map +1 -1
- package/dist/entities/agent-hub-tag.entity.js +8 -1
- package/dist/entities/agent-hub-tag.entity.js.map +1 -1
- package/dist/entities/agent-registry.entity.d.ts +4 -0
- package/dist/entities/agent-registry.entity.d.ts.map +1 -1
- package/dist/entities/agent-registry.entity.js +13 -1
- package/dist/entities/agent-registry.entity.js.map +1 -1
- package/dist/entities/agent-session.entity.d.ts.map +1 -1
- package/dist/entities/agent-session.entity.js.map +1 -1
- package/dist/entities/agent-skill-registry.entity.d.ts +2 -0
- package/dist/entities/agent-skill-registry.entity.d.ts.map +1 -1
- package/dist/entities/agent-skill-registry.entity.js +8 -1
- package/dist/entities/agent-skill-registry.entity.js.map +1 -1
- package/dist/entities/agent-skill.entity.d.ts +1 -0
- package/dist/entities/agent-skill.entity.d.ts.map +1 -1
- package/dist/entities/agent-skill.entity.js +5 -1
- package/dist/entities/agent-skill.entity.js.map +1 -1
- package/dist/entities/agent-tool-registry.entity.d.ts +2 -0
- package/dist/entities/agent-tool-registry.entity.d.ts.map +1 -1
- package/dist/entities/agent-tool-registry.entity.js +8 -1
- package/dist/entities/agent-tool-registry.entity.js.map +1 -1
- package/dist/entities/agent-tool.entity.d.ts +1 -0
- package/dist/entities/agent-tool.entity.d.ts.map +1 -1
- package/dist/entities/agent-tool.entity.js +5 -1
- package/dist/entities/agent-tool.entity.js.map +1 -1
- package/dist/entities/agent-user-memory.entity.d.ts +12 -0
- package/dist/entities/agent-user-memory.entity.d.ts.map +1 -0
- package/dist/entities/agent-user-memory.entity.js +51 -0
- package/dist/entities/agent-user-memory.entity.js.map +1 -0
- package/dist/entities/secret.entity.d.ts +2 -0
- package/dist/entities/secret.entity.d.ts.map +1 -1
- package/dist/entities/secret.entity.js +7 -1
- package/dist/entities/secret.entity.js.map +1 -1
- package/dist/helpers/bootstrap.helper.d.ts.map +1 -1
- package/dist/helpers/bootstrap.helper.js +28 -0
- package/dist/helpers/bootstrap.helper.js.map +1 -1
- package/dist/helpers/module-metadata-helper.service.js +3 -3
- package/dist/helpers/module-metadata-helper.service.js.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs/database/test-run-queue-subscriber-database.service.d.ts.map +1 -1
- package/dist/jobs/database/test-run-queue-subscriber-database.service.js +1 -0
- package/dist/jobs/database/test-run-queue-subscriber-database.service.js.map +1 -1
- package/dist/repository/agent-config-version.repository.d.ts +12 -0
- package/dist/repository/agent-config-version.repository.d.ts.map +1 -0
- package/dist/repository/agent-config-version.repository.js +39 -0
- package/dist/repository/agent-config-version.repository.js.map +1 -0
- package/dist/repository/agent-user-memory.repository.d.ts +12 -0
- package/dist/repository/agent-user-memory.repository.d.ts.map +1 -0
- package/dist/repository/agent-user-memory.repository.js +39 -0
- package/dist/repository/agent-user-memory.repository.js.map +1 -0
- package/dist/resources/agent-embed/solid-agent-embed.js +289 -75
- package/dist/seeders/module-metadata-agenthub.spec.d.ts +2 -0
- package/dist/seeders/module-metadata-agenthub.spec.d.ts.map +1 -0
- package/dist/seeders/module-metadata-agenthub.spec.js +111 -0
- package/dist/seeders/module-metadata-agenthub.spec.js.map +1 -0
- package/dist/seeders/module-metadata-seeder.service.d.ts +8 -0
- package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js +218 -0
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +1129 -135
- package/dist/services/agent-config-version-record.service.d.ts +81 -0
- package/dist/services/agent-config-version-record.service.d.ts.map +1 -0
- package/dist/services/agent-config-version-record.service.js +308 -0
- package/dist/services/agent-config-version-record.service.js.map +1 -0
- package/dist/services/agent-config-version.service.d.ts +10 -1
- package/dist/services/agent-config-version.service.d.ts.map +1 -1
- package/dist/services/agent-config-version.service.js +27 -15
- package/dist/services/agent-config-version.service.js.map +1 -1
- package/dist/services/agent-hub-tag.service.d.ts +4 -0
- package/dist/services/agent-hub-tag.service.d.ts.map +1 -1
- package/dist/services/agent-hub-tag.service.js +65 -2
- package/dist/services/agent-hub-tag.service.js.map +1 -1
- package/dist/services/agent-registry.service.d.ts +3 -0
- package/dist/services/agent-registry.service.d.ts.map +1 -1
- package/dist/services/agent-registry.service.js +39 -3
- package/dist/services/agent-registry.service.js.map +1 -1
- package/dist/services/agent-session.service.d.ts +21 -1
- package/dist/services/agent-session.service.d.ts.map +1 -1
- package/dist/services/agent-session.service.js +78 -2
- package/dist/services/agent-session.service.js.map +1 -1
- package/dist/services/agent-user-memory.service.d.ts +12 -0
- package/dist/services/agent-user-memory.service.d.ts.map +1 -0
- package/dist/services/agent-user-memory.service.js +38 -0
- package/dist/services/agent-user-memory.service.js.map +1 -0
- package/dist/services/file/disk-file.service.d.ts.map +1 -1
- package/dist/services/file/disk-file.service.js +6 -1
- package/dist/services/file/disk-file.service.js.map +1 -1
- package/dist/services/file/index.d.ts +1 -0
- package/dist/services/file/index.d.ts.map +1 -1
- package/dist/services/file/index.js +1 -0
- package/dist/services/file/index.js.map +1 -1
- package/dist/services/file/media-storage-paths.d.ts +8 -0
- package/dist/services/file/media-storage-paths.d.ts.map +1 -0
- package/dist/services/file/media-storage-paths.js +78 -0
- package/dist/services/file/media-storage-paths.js.map +1 -0
- package/dist/services/file/storage-path-builder.d.ts +0 -2
- package/dist/services/file/storage-path-builder.d.ts.map +1 -1
- package/dist/services/file/storage-path-builder.js +3 -44
- package/dist/services/file/storage-path-builder.js.map +1 -1
- package/dist/services/media-storage.utils.d.ts +1 -1
- package/dist/services/media-storage.utils.d.ts.map +1 -1
- package/dist/services/media-storage.utils.js +3 -43
- package/dist/services/media-storage.utils.js.map +1 -1
- package/dist/services/module-metadata.service.d.ts +0 -1
- package/dist/services/module-metadata.service.d.ts.map +1 -1
- package/dist/services/module-metadata.service.js +7 -15
- package/dist/services/module-metadata.service.js.map +1 -1
- package/dist/services/secret.service.js +3 -3
- package/dist/services/secret.service.js.map +1 -1
- package/dist/services/settings/default-settings-provider.service.d.ts +24 -4
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +13 -2
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/services/view-metadata.service.d.ts.map +1 -1
- package/dist/services/view-metadata.service.js +14 -5
- package/dist/services/view-metadata.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +40 -5
- package/dist/solid-core.module.js.map +1 -1
- package/dist/subscribers/agent-hub-tag.subscriber.d.ts +23 -0
- package/dist/subscribers/agent-hub-tag.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-hub-tag.subscriber.js +209 -0
- package/dist/subscribers/agent-hub-tag.subscriber.js.map +1 -0
- package/dist/subscribers/agent-registry-subscribers.spec.d.ts +2 -0
- package/dist/subscribers/agent-registry-subscribers.spec.d.ts.map +1 -0
- package/dist/subscribers/agent-registry-subscribers.spec.js +256 -0
- package/dist/subscribers/agent-registry-subscribers.spec.js.map +1 -0
- package/dist/subscribers/agent-registry.subscriber.d.ts +34 -0
- package/dist/subscribers/agent-registry.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-registry.subscriber.js +360 -0
- package/dist/subscribers/agent-registry.subscriber.js.map +1 -0
- package/dist/subscribers/agent-role.subscriber.d.ts +19 -0
- package/dist/subscribers/agent-role.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-role.subscriber.js +112 -0
- package/dist/subscribers/agent-role.subscriber.js.map +1 -0
- package/dist/subscribers/agent-secret.subscriber.d.ts +19 -0
- package/dist/subscribers/agent-secret.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-secret.subscriber.js +112 -0
- package/dist/subscribers/agent-secret.subscriber.js.map +1 -0
- package/dist/subscribers/agent-skill-registry.subscriber.d.ts +27 -0
- package/dist/subscribers/agent-skill-registry.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-skill-registry.subscriber.js +257 -0
- package/dist/subscribers/agent-skill-registry.subscriber.js.map +1 -0
- package/dist/subscribers/agent-skill.subscriber.d.ts +19 -0
- package/dist/subscribers/agent-skill.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-skill.subscriber.js +112 -0
- package/dist/subscribers/agent-skill.subscriber.js.map +1 -0
- package/dist/subscribers/agent-tool-registry.subscriber.d.ts +27 -0
- package/dist/subscribers/agent-tool-registry.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-tool-registry.subscriber.js +259 -0
- package/dist/subscribers/agent-tool-registry.subscriber.js.map +1 -0
- package/dist/subscribers/agent-tool.subscriber.d.ts +19 -0
- package/dist/subscribers/agent-tool.subscriber.d.ts.map +1 -0
- package/dist/subscribers/agent-tool.subscriber.js +112 -0
- package/dist/subscribers/agent-tool.subscriber.js.map +1 -0
- package/dist/subscribers/agenthub-metadata-sync.util.d.ts +7 -0
- package/dist/subscribers/agenthub-metadata-sync.util.d.ts.map +1 -0
- package/dist/subscribers/agenthub-metadata-sync.util.js +84 -0
- package/dist/subscribers/agenthub-metadata-sync.util.js.map +1 -0
- package/dist/subscribers/secret.subscriber.d.ts +26 -0
- package/dist/subscribers/secret.subscriber.d.ts.map +1 -0
- package/dist/subscribers/secret.subscriber.js +236 -0
- package/dist/subscribers/secret.subscriber.js.map +1 -0
- package/dist/testing/contracts/runtime-context.types.d.ts +2 -0
- package/dist/testing/contracts/runtime-context.types.d.ts.map +1 -1
- package/dist/testing/contracts/runtime-context.types.js.map +1 -1
- package/dist/testing/core/call-args.d.ts +18 -0
- package/dist/testing/core/call-args.d.ts.map +1 -0
- package/dist/testing/core/call-args.js +133 -0
- package/dist/testing/core/call-args.js.map +1 -0
- package/dist/testing/core/dates.d.ts +27 -0
- package/dist/testing/core/dates.d.ts.map +1 -0
- package/dist/testing/core/dates.js +151 -0
- package/dist/testing/core/dates.js.map +1 -0
- package/dist/testing/core/dates.spec.d.ts +2 -0
- package/dist/testing/core/dates.spec.d.ts.map +1 -0
- package/dist/testing/core/dates.spec.js +246 -0
- package/dist/testing/core/dates.spec.js.map +1 -0
- package/dist/testing/core/interpolation.d.ts +4 -1
- package/dist/testing/core/interpolation.d.ts.map +1 -1
- package/dist/testing/core/interpolation.js +56 -27
- package/dist/testing/core/interpolation.js.map +1 -1
- package/dist/testing/core/random-data.d.ts +12 -0
- package/dist/testing/core/random-data.d.ts.map +1 -0
- package/dist/testing/core/random-data.js +270 -0
- package/dist/testing/core/random-data.js.map +1 -0
- package/dist/testing/core/random-data.spec.d.ts +2 -0
- package/dist/testing/core/random-data.spec.d.ts.map +1 -0
- package/dist/testing/core/random-data.spec.js +198 -0
- package/dist/testing/core/random-data.spec.js.map +1 -0
- package/dist/testing/core/random-names.d.ts +4 -0
- package/dist/testing/core/random-names.d.ts.map +1 -0
- package/dist/testing/core/random-names.js +50 -0
- package/dist/testing/core/random-names.js.map +1 -0
- package/dist/testing/core/step-registry.d.ts +6 -1
- package/dist/testing/core/step-registry.d.ts.map +1 -1
- package/dist/testing/core/step-registry.js +8 -1
- package/dist/testing/core/step-registry.js.map +1 -1
- package/dist/testing/core/testing-engine.d.ts +1 -0
- package/dist/testing/core/testing-engine.d.ts.map +1 -1
- package/dist/testing/core/testing-engine.js +15 -1
- package/dist/testing/core/testing-engine.js.map +1 -1
- package/dist/testing/core/token-scan.d.ts +8 -0
- package/dist/testing/core/token-scan.d.ts.map +1 -0
- package/dist/testing/core/token-scan.js +70 -0
- package/dist/testing/core/token-scan.js.map +1 -0
- package/dist/testing/runner/run-from-metadata.d.ts +1 -0
- package/dist/testing/runner/run-from-metadata.d.ts.map +1 -1
- package/dist/testing/runner/run-from-metadata.js +10 -3
- package/dist/testing/runner/run-from-metadata.js.map +1 -1
- package/dist/testing/runner/run-from-metadata.spec.d.ts +2 -0
- package/dist/testing/runner/run-from-metadata.spec.d.ts.map +1 -0
- package/dist/testing/runner/run-from-metadata.spec.js +62 -0
- package/dist/testing/runner/run-from-metadata.spec.js.map +1 -0
- package/dist/testing/steps/util/index.d.ts.map +1 -1
- package/dist/testing/steps/util/index.js +6 -0
- package/dist/testing/steps/util/index.js.map +1 -1
- package/dist/testing/steps/util/now.step.d.ts +3 -0
- package/dist/testing/steps/util/now.step.d.ts.map +1 -0
- package/dist/testing/steps/util/now.step.js +15 -0
- package/dist/testing/steps/util/now.step.js.map +1 -0
- package/dist/testing/steps/util/random.step.d.ts +3 -0
- package/dist/testing/steps/util/random.step.d.ts.map +1 -0
- package/dist/testing/steps/util/random.step.js +18 -0
- package/dist/testing/steps/util/random.step.js.map +1 -0
- package/dist/testing/steps/util/script.step.d.ts +3 -0
- package/dist/testing/steps/util/script.step.d.ts.map +1 -0
- package/dist/testing/steps/util/script.step.js +221 -0
- package/dist/testing/steps/util/script.step.js.map +1 -0
- package/dist/testing/steps/util/script.step.spec.d.ts +2 -0
- package/dist/testing/steps/util/script.step.spec.d.ts.map +1 -0
- package/dist/testing/steps/util/script.step.spec.js +205 -0
- package/dist/testing/steps/util/script.step.spec.js.map +1 -0
- package/package.json +1 -1
- package/resources/agent-embed/solid-agent-embed.js +289 -75
- package/src/commands/run-tests.command.ts +12 -0
- package/src/constants/error-messages.ts +1 -1
- package/src/controllers/agent-config-version.controller.ts +114 -0
- package/src/controllers/agent-registry.controller.ts +7 -0
- package/src/controllers/agent-session.controller.ts +16 -1
- package/src/controllers/agent-user-memory.controller.ts +32 -0
- package/src/dtos/activate-agent-registry.dto.ts +14 -0
- package/src/dtos/create-agent-config-version.dto.ts +27 -0
- package/src/dtos/create-agent-hub-tag.dto.ts +10 -0
- package/src/dtos/create-agent-registry.dto.ts +10 -0
- package/src/dtos/create-agent-skill-registry.dto.ts +10 -0
- package/src/dtos/create-agent-tool-registry.dto.ts +10 -0
- package/src/dtos/create-agent-user-memory.dto.ts +10 -0
- package/src/dtos/create-secret.dto.ts +11 -1
- package/src/dtos/test-run-request.dto.ts +4 -0
- package/src/dtos/update-agent-config-version.dto.ts +34 -0
- package/src/dtos/update-agent-hub-tag.dto.ts +10 -0
- package/src/dtos/update-agent-registry.dto.ts +10 -0
- package/src/dtos/update-agent-skill-registry.dto.ts +10 -0
- package/src/dtos/update-agent-tool-registry.dto.ts +10 -0
- package/src/dtos/update-agent-user-memory.dto.ts +11 -0
- package/src/dtos/update-secret.dto.ts +10 -0
- package/src/entities/agent-config-version.entity.ts +20 -0
- package/src/entities/agent-hub-tag.entity.ts +7 -1
- package/src/entities/agent-registry.entity.ts +11 -1
- package/src/entities/agent-session.entity.ts +1 -0
- package/src/entities/agent-skill-registry.entity.ts +7 -1
- package/src/entities/agent-skill.entity.ts +4 -1
- package/src/entities/agent-tool-registry.entity.ts +7 -1
- package/src/entities/agent-tool.entity.ts +4 -1
- package/src/entities/agent-user-memory.entity.ts +26 -0
- package/src/entities/secret.entity.ts +6 -1
- package/src/helpers/bootstrap.helper.ts +36 -3
- package/src/helpers/module-metadata-helper.service.ts +3 -3
- package/src/index.ts +13 -0
- package/src/jobs/database/test-run-queue-subscriber-database.service.ts +1 -0
- package/src/repository/agent-config-version.repository.ts +19 -0
- package/src/repository/agent-user-memory.repository.ts +18 -0
- package/src/seeders/module-metadata-agenthub.spec.ts +120 -0
- package/src/seeders/module-metadata-seeder.service.ts +221 -0
- package/src/seeders/seed-data/solid-core-metadata.json +1129 -135
- package/src/services/agent-config-version-record.service.ts +317 -0
- package/src/services/agent-config-version.service.ts +52 -13
- package/src/services/agent-hub-tag.service.ts +81 -2
- package/src/services/agent-registry.service.ts +48 -3
- package/src/services/agent-session.service.ts +75 -2
- package/src/services/agent-user-memory.service.ts +18 -0
- package/src/services/file/disk-file.service.ts +6 -1
- package/src/services/file/index.ts +1 -0
- package/src/services/file/media-storage-paths.ts +50 -0
- package/src/services/file/storage-path-builder.ts +2 -12
- package/src/services/media-storage.utils.ts +10 -16
- package/src/services/module-metadata.service.ts +7 -17
- package/src/services/secret.service.ts +4 -4
- package/src/services/settings/default-settings-provider.service.ts +13 -2
- package/src/services/view-metadata.service.ts +17 -5
- package/src/solid-core.module.ts +41 -6
- package/src/subscribers/agent-hub-tag.subscriber.ts +210 -0
- package/src/subscribers/agent-registry-subscribers.spec.ts +228 -0
- package/src/subscribers/agent-registry.subscriber.ts +326 -0
- package/src/subscribers/agent-role.subscriber.ts +105 -0
- package/src/subscribers/agent-secret.subscriber.ts +105 -0
- package/src/subscribers/agent-skill-registry.subscriber.ts +213 -0
- package/src/subscribers/agent-skill.subscriber.ts +105 -0
- package/src/subscribers/agent-tool-registry.subscriber.ts +215 -0
- package/src/subscribers/agent-tool.subscriber.ts +105 -0
- package/src/subscribers/agenthub-metadata-sync.util.ts +57 -0
- package/src/subscribers/secret.subscriber.ts +192 -0
- package/src/testing/README.md +199 -0
- package/src/testing/contracts/runtime-context.types.ts +3 -0
- package/src/testing/core/call-args.ts +154 -0
- package/src/testing/core/dates.spec.ts +311 -0
- package/src/testing/core/dates.ts +198 -0
- package/src/testing/core/interpolation.ts +67 -28
- package/src/testing/core/random-data.spec.ts +253 -0
- package/src/testing/core/random-data.ts +326 -0
- package/src/testing/core/random-names.ts +54 -0
- package/src/testing/core/step-registry.ts +18 -1
- package/src/testing/core/testing-engine.ts +16 -1
- package/src/testing/core/token-scan.ts +72 -0
- package/src/testing/runner/run-from-metadata.spec.ts +82 -0
- package/src/testing/runner/run-from-metadata.ts +15 -3
- package/src/testing/steps/util/index.ts +6 -0
- package/src/testing/steps/util/now.step.ts +19 -0
- package/src/testing/steps/util/random.step.ts +23 -0
- package/src/testing/steps/util/script.step.spec.ts +269 -0
- package/src/testing/steps/util/script.step.ts +242 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-scan.js","sourceRoot":"","sources":["../../../src/testing/core/token-scan.ts"],"names":[],"mappings":";;AA8BA,gCAkBC;AAGD,gDAoBC;AAxDD,SAAS,kBAAkB,CAAC,IAAY,EAAE,MAAc,EAAE,IAAY;IACpE,IAAI,KAAK,GAAkB,IAAI,CAAC;IAChC,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3C,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,IAAI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AAY,EAAE,SAAiB;IAChE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,GAAkB,IAAI,CAAC;IAChC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,IAAI;gBAAE,CAAC,IAAI,CAAC,CAAC;iBAClB,IAAI,CAAC,KAAK,KAAK;gBAAE,KAAK,GAAG,IAAI,CAAC;YACnC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG;YAAE,KAAK,GAAG,CAAC,CAAC;aACjC,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;IACH,CAAC;IACD,IAAI,KAAK;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACxC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Finds `${...}` tokens and splits them on `|`, skipping quoted text, so a quoted argument value\n// can hold `}` or `|`: `${now:date(format='DD | MM')}`. A backslash inside quotes escapes the next\n// character. When a token's quotes never close, the first `}` ends it, as the plain regex this\n// replaces did, so malformed input resolves exactly as before.\n\nexport interface FoundToken {\n /** Index of the `$`. */\n start: number;\n /** Index just past the closing `}`. */\n end: number;\n /** What is between `${` and `}`. */\n inner: string;\n}\n\n/** The index of `target` in `text` from `from`, outside quotes; -1 if absent or the quotes never close. */\nfunction indexOutsideQuotes(text: string, target: string, from: number): number {\n let quote: string | null = null;\n for (let i = from; i < text.length; i += 1) {\n const c = text[i];\n if (quote) {\n if (c === \"\\\\\") i += 1;\n else if (c === quote) quote = null;\n continue;\n }\n if (c === \"'\" || c === '\"') quote = c;\n else if (c === target) return i;\n }\n return -1;\n}\n\nexport function findTokens(text: string): FoundToken[] {\n const tokens: FoundToken[] = [];\n let from = 0;\n for (;;) {\n const start = text.indexOf(\"${\", from);\n if (start === -1) break;\n let close = indexOutsideQuotes(text, \"}\", start + 2);\n if (close === -1) close = text.indexOf(\"}\", start + 2);\n if (close === -1) break;\n const inner = text.slice(start + 2, close);\n if (!inner) {\n from = start + 2;\n continue;\n }\n tokens.push({ start, end: close + 1, inner });\n from = close + 1;\n }\n return tokens;\n}\n\n/** Splits on `separator` outside quotes. With unbalanced quotes it splits everywhere, as before. */\nexport function splitOutsideQuotes(text: string, separator: string): string[] {\n const parts: string[] = [];\n let quote: string | null = null;\n let last = 0;\n for (let i = 0; i < text.length; i += 1) {\n const c = text[i];\n if (quote) {\n if (c === \"\\\\\") i += 1;\n else if (c === quote) quote = null;\n continue;\n }\n if (c === \"'\" || c === '\"') quote = c;\n else if (c === separator) {\n parts.push(text.slice(last, i));\n last = i + 1;\n }\n }\n if (quote) return text.split(separator);\n parts.push(text.slice(last));\n return parts;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-from-metadata.d.ts","sourceRoot":"","sources":["../../../src/testing/runner/run-from-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAC5G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAA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AC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACnE,CAAC;AA+CF,wBAAsB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAsGxE"}
|
|
@@ -41,6 +41,7 @@ const assert_1 = require("../steps/assert");
|
|
|
41
41
|
const util_1 = require("../steps/util");
|
|
42
42
|
const test_1 = require("../steps/test");
|
|
43
43
|
const resource_store_1 = require("../core/resource-store");
|
|
44
|
+
const random_data_1 = require("../core/random-data");
|
|
44
45
|
const step_registry_1 = require("../core/step-registry");
|
|
45
46
|
const spec_registry_1 = require("../core/spec-registry");
|
|
46
47
|
const testing_engine_1 = require("../core/testing-engine");
|
|
@@ -116,7 +117,8 @@ async function runFromMetadata(opts) {
|
|
|
116
117
|
const api = new api_adapter_1.ApiAdapter(opts.api);
|
|
117
118
|
const { PlaywrightAdapter } = await Promise.resolve().then(() => __importStar(require("../adapters/ui/playwright-adapter")));
|
|
118
119
|
const ui = new PlaywrightAdapter(opts.ui);
|
|
119
|
-
const
|
|
120
|
+
const randomData = new random_data_1.RandomDataRegistry();
|
|
121
|
+
const ctxBase = { resources, randomData, reporter, api, ui, specRegistry, testData, env: opts.env, options: opts.options };
|
|
120
122
|
const uiStarted = { value: false };
|
|
121
123
|
let passed = 0;
|
|
122
124
|
let failed = 0;
|
|
@@ -142,10 +144,15 @@ async function runFromMetadata(opts) {
|
|
|
142
144
|
}
|
|
143
145
|
catch (error) {
|
|
144
146
|
failed += 1;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
if (opts.failFast !== false) {
|
|
148
|
+
runError = error;
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
runError ??= error;
|
|
147
152
|
}
|
|
148
153
|
}
|
|
154
|
+
if (runError)
|
|
155
|
+
throw runError;
|
|
149
156
|
}
|
|
150
157
|
catch (error) {
|
|
151
158
|
runError = error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-from-metadata.js","sourceRoot":"","sources":["../../../src/testing/runner/run-from-metadata.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,0CAgGC;AAlMD,6DAAyD;AACzD,sCAAgD;AAChD,oCAA8C;AAC9C,4CAAsD;AACtD,wCAAkD;AAClD,wCAAkD;AAClD,2DAA6D;AAC7D,yDAAqD;AACrD,yDAAqD;AACrD,2DAAuD;AACvD,uDAAoD;AACpD,yDAA0D;AAC1D,2CAA+D;AAC/D,4EAA6E;AAC7E,mEAA+D;AAG/D,SAAS,kBAAkB,CAAC,IAA0B;IACpD,MAAM,KAAK,GAAwC,EAAE,CAAC;IACtD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,KAAK,MAAM,MAAM,IAAI,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,MAAM,EAAE,YAAY,IAAI,CAAC,MAAM,EAAE,eAAe;YAAE,SAAS;QAChE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QAClC,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;IACzE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAgCD,KAAK,UAAU,wBAAwB,CACrC,SAAyB,EACzB,cAAgD;IAEhD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAoB,CAAC;IACnD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,IAAA,iCAAiB,EAAC,QAAQ,C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AQ,CAAC,EAAE,CAAC;iBAC5C,CAAC,CAAC;gBACH,MAAM,IAAI,CAAC,CAAC;YACd,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC,CAAC;gBACZ,QAAQ,GAAG,KAAK,CAAC;gBACjB,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAGf,QAAQ,GAAG,KAAK,CAAC;QACjB,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAClB,EAAE,EAAE,CAAC,QAAQ;YACb,KAAK,EAAE,SAAS,CAAC,MAAM;YACvB,MAAM;YACN,MAAM;YACN,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;SACnC,CAAC,CAAC;QACH,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;YAEpB,MAAM,SAAS,GAAG,CAAC,CAAC,QAAQ,CAAC;YAC7B,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;YAG7B,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC;gBACjC,IAAI,KAAK,IAAI,QAAQ,CAAC,iBAAiB,EAAE,CAAC;oBACxC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;gBACrG,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { Reporter } from \"../reporter/reporter.types\";\nimport type { TestingMetadata, TestingDataRecord, ScenarioSpec } from \"../contracts/testing-metadata.types\";\nimport type { ApiAdapterOptions } from \"../adapters/api/api.types\";\nimport type { PlaywrightAdapterOptions } from \"../adapters/ui/ui.types\";\nimport { ApiAdapter } from \"../adapters/api/api-adapter\";\nimport { registerApiSteps } from \"../steps/api\";\nimport { registerUiSteps } from \"../steps/ui\";\nimport { registerAssertSteps } from \"../steps/assert\";\nimport { registerUtilSteps } from \"../steps/util\";\nimport { registerTestSteps } from \"../steps/test\";\nimport { SimpleResourceStore } from \"../core/resource-store\";\nimport { StepRegistry } from \"../core/step-registry\";\nimport { SpecRegistry } from \"../core/spec-registry\";\nimport { TestingEngine } from \"../core/testing-engine\";\nimport { filterScenarios } from \"./scenario-filter\";\nimport { collectSecretKeys } from \"../core/interpolation\";\nimport { ensureUiStarted, scenarioNeedsUi } from \"./lifecycle\";\nimport { ensureChromiumInstalled } from \"../adapters/ui/browser-provisioner\";\nimport { ConsoleReporter } from \"../reporter/console-reporter\";\n\n\nfunction buildTestDataIndex(data?: TestingDataRecord[]): Record<string, Record<string, any>> {\n const index: Record<string, Record<string, any>> = {};\n if (!Array.isArray(data)) return index;\n for (const record of data) {\n if (!record?.modelUserKey || !record?.recUserKeyValue) continue;\n if (!index[record.modelUserKey]) {\n index[record.modelUserKey] = {};\n }\n index[record.modelUserKey][record.recUserKeyValue] = record.data ?? {};\n }\n return index;\n}\n\nexport type RunnerOptions = {\n metadata?: TestingMetadata;\n scenarios?: ScenarioSpec[];\n data?: TestingDataRecord[];\n externalRunId?: string;\n env?: Record<string, string>;\n scenarioIds?: string[];\n includeTags?: string[];\n skipScenarioIds?: string[];\n reporter?: Reporter;\n api?: ApiAdapterOptions;\n ui?: PlaywrightAdapterOptions;\n defaults?: { timeoutMs?: number; retries?: number };\n options?: { printApiLogs?: boolean };\n specs?: (registry: SpecRegistry) => void;\n /**\n * Resolves `${secret:...}` references against the secret store. Injected by the\n * caller so this runner stays free of database and DI coupling. Required only if a\n * scenario actually references a secret.\n */\n resolveSecrets?: (keys: string[]) => Promise<Record<string, any>>;\n};\n\n/**\n * Resolves every secret referenced by the scenarios about to run, in one call, and\n * returns a per-scenario view of the result.\n *\n * Partitioned deliberately: ctxBase is shared across scenarios, so handing every\n * scenario the whole map would let each read secrets belonging to the others.\n */\nasync function resolveSecretsByScenario(\n scenarios: ScenarioSpec[],\n resolveSecrets?: RunnerOptions[\"resolveSecrets\"],\n): Promise<Map<string, Record<string, any>>> {\n const keysByScenario = new Map<string, string[]>();\n const allKeys = new Set<string>();\n\n for (const scenario of scenarios) {\n const keys = collectSecretKeys(scenario);\n if (keys.length === 0) continue;\n keysByScenario.set(scenario.id, keys);\n keys.forEach((key) => allKeys.add(key));\n }\n\n if (allKeys.size === 0) return new Map();\n\n if (!resolveSecrets) {\n throw new Error(\n `Scenarios reference secrets (${[...allKeys].join(\", \")}) but no secret resolver was provided to the runner.`,\n );\n }\n\n // Resolved up front so a missing secret fails the run before any scenario executes.\n const resolved = await resolveSecrets([...allKeys]);\n\n const byScenario = new Map<string, Record<string, any>>();\n for (const [scenarioId, keys] of keysByScenario) {\n byScenario.set(\n scenarioId,\n keys.reduce((acc, key) => {\n acc[key] = resolved[key];\n return acc;\n }, {} as Record<string, any>),\n );\n }\n return byScenario;\n}\n\nexport async function runFromMetadata(opts: RunnerOptions): Promise<void> {\n const startedAt = Date.now();\n const registry = new StepRegistry();\n registerApiSteps(registry);\n registerUiSteps(registry);\n registerAssertSteps(registry);\n registerUtilSteps(registry);\n registerTestSteps(registry);\n\n const engine = new TestingEngine(registry, opts.defaults);\n const allScenarios = opts.scenarios ?? opts.metadata?.testing?.scenarios ?? [];\n const scenarios = filterScenarios(allScenarios, {\n scenarioIds: opts.scenarioIds,\n includeTags: opts.includeTags,\n skipScenarioIds: opts.skipScenarioIds,\n });\n\n const specRegistry = new SpecRegistry();\n const testData = buildTestDataIndex(opts.data ?? opts.metadata?.testing?.data);\n if (opts.specs) {\n opts.specs(specRegistry);\n }\n\n // Fetch the browser before the reporter starts drawing its footer, so the download\n // gets a clean terminal and a missing browser fails before any scenario runs.\n if (scenarios.some(scenarioNeedsUi)) {\n await ensureChromiumInstalled();\n }\n\n const resources = new SimpleResourceStore();\n const reporter: Reporter = opts.reporter ?? new ConsoleReporter();\n const api = new ApiAdapter(opts.api);\n const { PlaywrightAdapter } = await import(\"../adapters/ui/playwright-adapter\");\n const ui = new PlaywrightAdapter(opts.ui);\n const ctxBase = { resources, reporter, api, ui, specRegistry, testData, env: opts.env, options: opts.options };\n const uiStarted = { value: false };\n let passed = 0;\n let failed = 0;\n let runError: unknown;\n\n reporter.onRunStart?.({\n total: scenarios.length,\n startedAt: new Date(startedAt).toISOString(),\n scenarioIds: scenarios.map((s) => s.id),\n scenarios: scenarios.map((s) => ({ id: s.id, name: s.name, type: s.type })),\n });\n\n try {\n // One query for the whole run, after onRunStart so a failure here still reports\n // run.end. Keys that do not resolve are not fatal — they surface at the step that\n // references them, where the reporter can name the token and locate the failure.\n const secretsByScenario = await resolveSecretsByScenario(scenarios, opts.resolveSecrets);\n\n for (const scenario of scenarios) {\n if (scenarioNeedsUi(scenario)) {\n await ensureUiStarted(ctxBase, uiStarted);\n }\n try {\n await engine.runScenario(scenario, {\n ...ctxBase,\n secrets: secretsByScenario.get(scenario.id),\n });\n passed += 1;\n } catch (error) {\n failed += 1;\n runError = error;\n throw error;\n }\n }\n } catch (error) {\n // Also catches a setup failure before the loop (unreachable database, absent\n // encryption key), which would otherwise leave runError unset and report ok: true.\n runError = error;\n throw error;\n } finally {\n reporter.onRunEnd?.({\n ok: !runError,\n total: scenarios.length,\n passed,\n failed,\n durationMs: Date.now() - startedAt,\n });\n if (uiStarted.value) {\n // Only KEEP the whole-run video when the run FAILED — passing runs discard it unread.\n const keepVideo = !!runError;\n await ui.stop({ keepVideo });\n // Video bytes are only finalized after ui.stop(); attach it as a run-level artifact so\n // the reporter uploads it and references it on run.end (queued before flushPending runs).\n if (keepVideo) {\n const video = ui.getRunVideo?.();\n if (video && reporter.attachRunArtifact) {\n reporter.attachRunArtifact({ name: video.name, contentType: video.contentType, data: video.data });\n }\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"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H,CAAC","sourcesContent":["import type { Reporter } from \"../reporter/reporter.types\";\nimport type { TestingMetadata, TestingDataRecord, ScenarioSpec } from \"../contracts/testing-metadata.types\";\nimport type { ApiAdapterOptions } from \"../adapters/api/api.types\";\nimport type { PlaywrightAdapterOptions } from \"../adapters/ui/ui.types\";\nimport { ApiAdapter } from \"../adapters/api/api-adapter\";\nimport { registerApiSteps } from \"../steps/api\";\nimport { registerUiSteps } from \"../steps/ui\";\nimport { registerAssertSteps } from \"../steps/assert\";\nimport { registerUtilSteps } from \"../steps/util\";\nimport { registerTestSteps } from \"../steps/test\";\nimport { SimpleResourceStore } from \"../core/resource-store\";\nimport { RandomDataRegistry } from \"../core/random-data\";\nimport { StepRegistry } from \"../core/step-registry\";\nimport { SpecRegistry } from \"../core/spec-registry\";\nimport { TestingEngine } from \"../core/testing-engine\";\nimport { filterScenarios } from \"./scenario-filter\";\nimport { collectSecretKeys } from \"../core/interpolation\";\nimport { ensureUiStarted, scenarioNeedsUi } from \"./lifecycle\";\nimport { ensureChromiumInstalled } from \"../adapters/ui/browser-provisioner\";\nimport { ConsoleReporter } from \"../reporter/console-reporter\";\n\n\nfunction buildTestDataIndex(data?: TestingDataRecord[]): Record<string, Record<string, any>> {\n const index: Record<string, Record<string, any>> = {};\n if (!Array.isArray(data)) return index;\n for (const record of data) {\n if (!record?.modelUserKey || !record?.recUserKeyValue) continue;\n if (!index[record.modelUserKey]) {\n index[record.modelUserKey] = {};\n }\n index[record.modelUserKey][record.recUserKeyValue] = record.data ?? {};\n }\n return index;\n}\n\nexport type RunnerOptions = {\n metadata?: TestingMetadata;\n scenarios?: ScenarioSpec[];\n data?: TestingDataRecord[];\n externalRunId?: string;\n env?: Record<string, string>;\n scenarioIds?: string[];\n includeTags?: string[];\n skipScenarioIds?: string[];\n reporter?: Reporter;\n api?: ApiAdapterOptions;\n ui?: PlaywrightAdapterOptions;\n defaults?: { timeoutMs?: number; retries?: number };\n options?: { printApiLogs?: boolean };\n /**\n * Stop the run at the first failed scenario (default `true`). When `false`, every\n * scenario runs; the run still throws after the last one if any failed.\n */\n failFast?: boolean;\n specs?: (registry: SpecRegistry) => void;\n /**\n * Resolves `${secret:...}` references against the secret store. Injected by the\n * caller so this runner stays free of database and DI coupling. Required only if a\n * scenario actually references a secret.\n */\n resolveSecrets?: (keys: string[]) => Promise<Record<string, any>>;\n};\n\n/**\n * Resolves every secret referenced by the scenarios about to run, in one call, and\n * returns a per-scenario view of the result.\n *\n * Partitioned deliberately: ctxBase is shared across scenarios, so handing every\n * scenario the whole map would let each read secrets belonging to the others.\n */\nasync function resolveSecretsByScenario(\n scenarios: ScenarioSpec[],\n resolveSecrets?: RunnerOptions[\"resolveSecrets\"],\n): Promise<Map<string, Record<string, any>>> {\n const keysByScenario = new Map<string, string[]>();\n const allKeys = new Set<string>();\n\n for (const scenario of scenarios) {\n const keys = collectSecretKeys(scenario);\n if (keys.length === 0) continue;\n keysByScenario.set(scenario.id, keys);\n keys.forEach((key) => allKeys.add(key));\n }\n\n if (allKeys.size === 0) return new Map();\n\n if (!resolveSecrets) {\n throw new Error(\n `Scenarios reference secrets (${[...allKeys].join(\", \")}) but no secret resolver was provided to the runner.`,\n );\n }\n\n // Resolved up front so a missing secret fails the run before any scenario executes.\n const resolved = await resolveSecrets([...allKeys]);\n\n const byScenario = new Map<string, Record<string, any>>();\n for (const [scenarioId, keys] of keysByScenario) {\n byScenario.set(\n scenarioId,\n keys.reduce((acc, key) => {\n acc[key] = resolved[key];\n return acc;\n }, {} as Record<string, any>),\n );\n }\n return byScenario;\n}\n\nexport async function runFromMetadata(opts: RunnerOptions): Promise<void> {\n const startedAt = Date.now();\n const registry = new StepRegistry();\n registerApiSteps(registry);\n registerUiSteps(registry);\n registerAssertSteps(registry);\n registerUtilSteps(registry);\n registerTestSteps(registry);\n\n const engine = new TestingEngine(registry, opts.defaults);\n const allScenarios = opts.scenarios ?? opts.metadata?.testing?.scenarios ?? [];\n const scenarios = filterScenarios(allScenarios, {\n scenarioIds: opts.scenarioIds,\n includeTags: opts.includeTags,\n skipScenarioIds: opts.skipScenarioIds,\n });\n\n const specRegistry = new SpecRegistry();\n const testData = buildTestDataIndex(opts.data ?? opts.metadata?.testing?.data);\n if (opts.specs) {\n opts.specs(specRegistry);\n }\n\n // Fetch the browser before the reporter starts drawing its footer, so the download\n // gets a clean terminal and a missing browser fails before any scenario runs.\n if (scenarios.some(scenarioNeedsUi)) {\n await ensureChromiumInstalled();\n }\n\n const resources = new SimpleResourceStore();\n const reporter: Reporter = opts.reporter ?? new ConsoleReporter();\n const api = new ApiAdapter(opts.api);\n const { PlaywrightAdapter } = await import(\"../adapters/ui/playwright-adapter\");\n const ui = new PlaywrightAdapter(opts.ui);\n const randomData = new RandomDataRegistry();\n const ctxBase = { resources, randomData, reporter, api, ui, specRegistry, testData, env: opts.env, options: opts.options };\n const uiStarted = { value: false };\n let passed = 0;\n let failed = 0;\n let runError: unknown;\n\n reporter.onRunStart?.({\n total: scenarios.length,\n startedAt: new Date(startedAt).toISOString(),\n scenarioIds: scenarios.map((s) => s.id),\n scenarios: scenarios.map((s) => ({ id: s.id, name: s.name, type: s.type })),\n });\n\n try {\n // One query for the whole run, after onRunStart so a failure here still reports\n // run.end. Keys that do not resolve are not fatal — they surface at the step that\n // references them, where the reporter can name the token and locate the failure.\n const secretsByScenario = await resolveSecretsByScenario(scenarios, opts.resolveSecrets);\n\n for (const scenario of scenarios) {\n if (scenarioNeedsUi(scenario)) {\n await ensureUiStarted(ctxBase, uiStarted);\n }\n try {\n await engine.runScenario(scenario, {\n ...ctxBase,\n secrets: secretsByScenario.get(scenario.id),\n });\n passed += 1;\n } catch (error) {\n failed += 1;\n if (opts.failFast !== false) {\n runError = error;\n throw error;\n }\n // Keep going; the first failure is rethrown once every scenario has run.\n runError ??= error;\n }\n }\n if (runError) throw runError;\n } catch (error) {\n // Also catches a setup failure before the loop (unreachable database, absent\n // encryption key), which would otherwise leave runError unset and report ok: true.\n runError = error;\n throw error;\n } finally {\n reporter.onRunEnd?.({\n ok: !runError,\n total: scenarios.length,\n passed,\n failed,\n durationMs: Date.now() - startedAt,\n });\n if (uiStarted.value) {\n // Only KEEP the whole-run video when the run FAILED — passing runs discard it unread.\n const keepVideo = !!runError;\n await ui.stop({ keepVideo });\n // Video bytes are only finalized after ui.stop(); attach it as a run-level artifact so\n // the reporter uploads it and references it on run.end (queued before flushPending runs).\n if (keepVideo) {\n const video = ui.getRunVideo?.();\n if (video && reporter.attachRunArtifact) {\n reporter.attachRunArtifact({ name: video.name, contentType: video.contentType, data: video.data });\n }\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-from-metadata.spec.d.ts","sourceRoot":"","sources":["../../../src/testing/runner/run-from-metadata.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const run_from_metadata_1 = require("./run-from-metadata");
|
|
4
|
+
function scenario(id, passes) {
|
|
5
|
+
return {
|
|
6
|
+
id,
|
|
7
|
+
type: "api",
|
|
8
|
+
steps: [{ op: "assert.equals", with: { actual: 1, expected: passes ? 1 : 2 } }],
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function recorder() {
|
|
12
|
+
const ended = [];
|
|
13
|
+
let runEnd;
|
|
14
|
+
const reporter = {
|
|
15
|
+
onScenarioStart: () => undefined,
|
|
16
|
+
onScenarioEnd: (s, r) => {
|
|
17
|
+
ended.push({ id: s.id, ok: r.ok });
|
|
18
|
+
},
|
|
19
|
+
onStepStart: () => undefined,
|
|
20
|
+
onStepEnd: () => undefined,
|
|
21
|
+
onRunEnd: (r) => {
|
|
22
|
+
runEnd = r;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return { reporter, ended, getRunEnd: () => runEnd };
|
|
26
|
+
}
|
|
27
|
+
describe("runFromMetadata: failFast", () => {
|
|
28
|
+
const scenarios = [scenario("a", true), scenario("b", false), scenario("c", true)];
|
|
29
|
+
it("stops at the first failed scenario by default", async () => {
|
|
30
|
+
const { reporter, ended, getRunEnd } = recorder();
|
|
31
|
+
await expect((0, run_from_metadata_1.runFromMetadata)({ scenarios, reporter })).rejects.toThrow();
|
|
32
|
+
expect(ended.map((e) => e.id)).toEqual(["a", "b"]);
|
|
33
|
+
expect(getRunEnd()).toMatchObject({ ok: false, total: 3, passed: 1, failed: 1 });
|
|
34
|
+
});
|
|
35
|
+
it("stops at the first failed scenario when failFast is true", async () => {
|
|
36
|
+
const { reporter, ended } = recorder();
|
|
37
|
+
await expect((0, run_from_metadata_1.runFromMetadata)({ scenarios, reporter, failFast: true })).rejects.toThrow();
|
|
38
|
+
expect(ended.map((e) => e.id)).toEqual(["a", "b"]);
|
|
39
|
+
});
|
|
40
|
+
it("runs every scenario when failFast is false, then still fails the run", async () => {
|
|
41
|
+
const { reporter, ended, getRunEnd } = recorder();
|
|
42
|
+
await expect((0, run_from_metadata_1.runFromMetadata)({ scenarios, reporter, failFast: false })).rejects.toThrow();
|
|
43
|
+
expect(ended).toEqual([
|
|
44
|
+
{ id: "a", ok: true },
|
|
45
|
+
{ id: "b", ok: false },
|
|
46
|
+
{ id: "c", ok: true },
|
|
47
|
+
]);
|
|
48
|
+
expect(getRunEnd()).toMatchObject({ ok: false, total: 3, passed: 2, failed: 1 });
|
|
49
|
+
});
|
|
50
|
+
it("rethrows the first failure when several scenarios fail", async () => {
|
|
51
|
+
const { reporter, getRunEnd } = recorder();
|
|
52
|
+
const many = [scenario("a", false), scenario("b", true), scenario("c", false)];
|
|
53
|
+
await expect((0, run_from_metadata_1.runFromMetadata)({ scenarios: many, reporter, failFast: false })).rejects.toThrow();
|
|
54
|
+
expect(getRunEnd()).toMatchObject({ ok: false, total: 3, passed: 1, failed: 2 });
|
|
55
|
+
});
|
|
56
|
+
it("does not throw when failFast is false and everything passes", async () => {
|
|
57
|
+
const { reporter, getRunEnd } = recorder();
|
|
58
|
+
await (0, run_from_metadata_1.runFromMetadata)({ scenarios: [scenario("a", true), scenario("b", true)], reporter, failFast: false });
|
|
59
|
+
expect(getRunEnd()).toMatchObject({ ok: true, total: 2, passed: 2, failed: 0 });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=run-from-metadata.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-from-metadata.spec.js","sourceRoot":"","sources":["../../../src/testing/runner/run-from-metadata.spec.ts"],"names":[],"mappings":";;AAKA,2DAAsD;AAEtD,SAAS,QAAQ,CAAC,EAAU,EAAE,MAAe;IAC3C,OAAO;QACL,EAAE;QACF,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;KAChF,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ;IACf,MAAM,KAAK,GAAuC,EAAE,CAAC;IACrD,IAAI,MAAoE,CAAC;IACzE,MAAM,QAAQ,GAAa;QACzB,eAAe,EAAE,GAAG,EAAE,CAAC,SAAS;QAChC,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACtB,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrC,CAAC;QACD,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS;QAC5B,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS;QAC1B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;YACd,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;KACF,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,M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AE,CAAC;QAEhG,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,QAAQ,EAAE,CAAC;QAE3C,MAAM,IAAA,mCAAe,EAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QAE5G,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Purpose: a run stops at the first failed scenario by default; failFast: false runs every\n// scenario and still reports the run as failed.\n\nimport type { Reporter } from \"../reporter/reporter.types\";\nimport type { ScenarioSpec } from \"../contracts/testing-metadata.types\";\nimport { runFromMetadata } from \"./run-from-metadata\";\n\nfunction scenario(id: string, passes: boolean): ScenarioSpec {\n return {\n id,\n type: \"api\",\n steps: [{ op: \"assert.equals\", with: { actual: 1, expected: passes ? 1 : 2 } }],\n };\n}\n\nfunction recorder() {\n const ended: Array<{ id: string; ok: boolean }> = [];\n let runEnd: Parameters<NonNullable<Reporter[\"onRunEnd\"]>>[0] | undefined;\n const reporter: Reporter = {\n onScenarioStart: () => undefined,\n onScenarioEnd: (s, r) => {\n ended.push({ id: s.id, ok: r.ok });\n },\n onStepStart: () => undefined,\n onStepEnd: () => undefined,\n onRunEnd: (r) => {\n runEnd = r;\n },\n };\n return { reporter, ended, getRunEnd: () => runEnd };\n}\n\ndescribe(\"runFromMetadata: failFast\", () => {\n const scenarios = [scenario(\"a\", true), scenario(\"b\", false), scenario(\"c\", true)];\n\n it(\"stops at the first failed scenario by default\", async () => {\n const { reporter, ended, getRunEnd } = recorder();\n\n await expect(runFromMetadata({ scenarios, reporter })).rejects.toThrow();\n\n expect(ended.map((e) => e.id)).toEqual([\"a\", \"b\"]);\n expect(getRunEnd()).toMatchObject({ ok: false, total: 3, passed: 1, failed: 1 });\n });\n\n it(\"stops at the first failed scenario when failFast is true\", async () => {\n const { reporter, ended } = recorder();\n\n await expect(runFromMetadata({ scenarios, reporter, failFast: true })).rejects.toThrow();\n\n expect(ended.map((e) => e.id)).toEqual([\"a\", \"b\"]);\n });\n\n it(\"runs every scenario when failFast is false, then still fails the run\", async () => {\n const { reporter, ended, getRunEnd } = recorder();\n\n await expect(runFromMetadata({ scenarios, reporter, failFast: false })).rejects.toThrow();\n\n expect(ended).toEqual([\n { id: \"a\", ok: true },\n { id: \"b\", ok: false },\n { id: \"c\", ok: true },\n ]);\n expect(getRunEnd()).toMatchObject({ ok: false, total: 3, passed: 2, failed: 1 });\n });\n\n it(\"rethrows the first failure when several scenarios fail\", async () => {\n const { reporter, getRunEnd } = recorder();\n const many = [scenario(\"a\", false), scenario(\"b\", true), scenario(\"c\", false)];\n\n await expect(runFromMetadata({ scenarios: many, reporter, failFast: false })).rejects.toThrow();\n\n expect(getRunEnd()).toMatchObject({ ok: false, total: 3, passed: 1, failed: 2 });\n });\n\n it(\"does not throw when failFast is false and everything passes\", async () => {\n const { reporter, getRunEnd } = recorder();\n\n await runFromMetadata({ scenarios: [scenario(\"a\", true), scenario(\"b\", true)], reporter, failFast: false });\n\n expect(getRunEnd()).toMatchObject({ ok: true, total: 2, passed: 2, failed: 0 });\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/steps/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/steps/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAQxD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAO9D"}
|
|
@@ -4,9 +4,15 @@ exports.registerUtilSteps = registerUtilSteps;
|
|
|
4
4
|
const log_step_1 = require("./log.step");
|
|
5
5
|
const sleep_step_1 = require("./sleep.step");
|
|
6
6
|
const require_step_1 = require("./require.step");
|
|
7
|
+
const random_step_1 = require("./random.step");
|
|
8
|
+
const now_step_1 = require("./now.step");
|
|
9
|
+
const script_step_1 = require("./script.step");
|
|
7
10
|
function registerUtilSteps(registry) {
|
|
8
11
|
(0, log_step_1.registerLogStep)(registry);
|
|
9
12
|
(0, sleep_step_1.registerSleepStep)(registry);
|
|
10
13
|
(0, require_step_1.registerRequireStep)(registry);
|
|
14
|
+
(0, random_step_1.registerRandomStep)(registry);
|
|
15
|
+
(0, now_step_1.registerNowStep)(registry);
|
|
16
|
+
(0, script_step_1.registerScriptStep)(registry);
|
|
11
17
|
}
|
|
12
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/steps/util/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/steps/util/index.ts"],"names":[],"mappings":";;AAQA,8CAOC;AAdD,yCAA6C;AAC7C,6CAAiD;AACjD,iDAAqD;AACrD,+CAAmD;AACnD,yCAA6C;AAC7C,+CAAmD;AAEnD,SAAgB,iBAAiB,CAAC,QAAsB;IACtD,IAAA,0BAAe,EAAC,QAAQ,CAAC,CAAC;IAC1B,IAAA,8BAAiB,EAAC,QAAQ,CAAC,CAAC;IAC5B,IAAA,kCAAmB,EAAC,QAAQ,CAAC,CAAC;IAC9B,IAAA,gCAAkB,EAAC,QAAQ,CAAC,CAAC;IAC7B,IAAA,0BAAe,EAAC,QAAQ,CAAC,CAAC;IAC1B,IAAA,gCAAkB,EAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { StepRegistry } from \"../../core/step-registry\";\nimport { registerLogStep } from \"./log.step\";\nimport { registerSleepStep } from \"./sleep.step\";\nimport { registerRequireStep } from \"./require.step\";\nimport { registerRandomStep } from \"./random.step\";\nimport { registerNowStep } from \"./now.step\";\nimport { registerScriptStep } from \"./script.step\";\n\nexport function registerUtilSteps(registry: StepRegistry): void {\n registerLogStep(registry);\n registerSleepStep(registry);\n registerRequireStep(registry);\n registerRandomStep(registry);\n registerNowStep(registry);\n registerScriptStep(registry);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"now.step.d.ts","sourceRoot":"","sources":["../../../../src/testing/steps/util/now.step.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAMxD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAS5D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerNowStep = registerNowStep;
|
|
4
|
+
const dates_1 = require("../../core/dates");
|
|
5
|
+
function registerNowStep(registry) {
|
|
6
|
+
registry.register("util.now", async (_ctx, step) => {
|
|
7
|
+
const input = (step.with ?? {});
|
|
8
|
+
const args = input.args ?? {};
|
|
9
|
+
if (typeof args !== "object" || Array.isArray(args)) {
|
|
10
|
+
throw new Error('"args" must be an object for op "util.now", e.g. { "offset": "+7d" }');
|
|
11
|
+
}
|
|
12
|
+
return (0, dates_1.resolveNow)(String(input.kind ?? "date"), args);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=now.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"now.step.js","sourceRoot":"","sources":["../../../../src/testing/steps/util/now.step.ts"],"names":[],"mappings":";;AASA,0CASC;AAhBD,4CAA8C;AAO9C,SAAgB,eAAe,CAAC,QAAsB;IACpD,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,IAAiB,EAAE,IAAY,EAAE,EAAE;QACtE,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAa,CAAC;QAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC1F,CAAC;QACD,OAAO,IAAA,kBAAU,EAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { TestContext } from \"../../contracts/runtime-context.types\";\nimport type { OpStep } from \"../../contracts/testing-metadata.types\";\nimport { resolveNow } from \"../../core/dates\";\nimport { StepRegistry } from \"../../core/step-registry\";\n\ntype NowInput = { kind?: string; args?: Record<string, unknown> };\n\n// Returns the current date or time so `saveAs` can keep it: two inline ${now:...} tokens can differ\n// by a second, so a timestamp that is typed and then asserted should be taken once.\nexport function registerNowStep(registry: StepRegistry): void {\n registry.register(\"util.now\", async (_ctx: TestContext, step: OpStep) => {\n const input = (step.with ?? {}) as NowInput;\n const args = input.args ?? {};\n if (typeof args !== \"object\" || Array.isArray(args)) {\n throw new Error('\"args\" must be an object for op \"util.now\", e.g. { \"offset\": \"+7d\" }');\n }\n return resolveNow(String(input.kind ?? \"date\"), args);\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.step.d.ts","sourceRoot":"","sources":["../../../../src/testing/steps/util/random.step.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAOxD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAY/D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerRandomStep = registerRandomStep;
|
|
4
|
+
const random_data_1 = require("../../core/random-data");
|
|
5
|
+
function registerRandomStep(registry) {
|
|
6
|
+
registry.register("util.random", async (ctx, step) => {
|
|
7
|
+
const input = (step.with ?? {});
|
|
8
|
+
if (!input.generator) {
|
|
9
|
+
throw new Error('Missing "generator" in step.with for op "util.random"');
|
|
10
|
+
}
|
|
11
|
+
const args = input.args ?? {};
|
|
12
|
+
if (typeof args !== "object" || Array.isArray(args)) {
|
|
13
|
+
throw new Error('"args" must be an object for op "util.random", e.g. { "domain": "acme.test" }');
|
|
14
|
+
}
|
|
15
|
+
return (0, random_data_1.randomDataFor)(ctx).generate(String(input.generator), args);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=random.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.step.js","sourceRoot":"","sources":["../../../../src/testing/steps/util/random.step.ts"],"names":[],"mappings":";;AAUA,gDAYC;AApBD,wDAAuD;AAQvD,SAAgB,kBAAkB,CAAC,QAAsB;IACvD,QAAQ,CAAC,QAAQ,CAAC,aAAa,EAAE,KAAK,EAAE,GAAgB,EAAE,IAAY,EAAE,EAAE;QACxE,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAgB,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;QACD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC,CAAC;QACnG,CAAC;QACD,OAAO,IAAA,2BAAa,EAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { TestContext } from \"../../contracts/runtime-context.types\";\nimport type { OpStep } from \"../../contracts/testing-metadata.types\";\nimport { randomDataFor } from \"../../core/random-data\";\nimport { StepRegistry } from \"../../core/step-registry\";\n\ntype RandomInput = { generator: string; args?: Record<string, unknown> };\n\n// Generates one value and returns it, so `saveAs` can keep it: the same email can then be typed\n// in one step and asserted in another through ${res:<saveAs>}. An inline ${random:...} token\n// gives a new value each time it is resolved.\nexport function registerRandomStep(registry: StepRegistry): void {\n registry.register(\"util.random\", async (ctx: TestContext, step: OpStep) => {\n const input = (step.with ?? {}) as RandomInput;\n if (!input.generator) {\n throw new Error('Missing \"generator\" in step.with for op \"util.random\"');\n }\n const args = input.args ?? {};\n if (typeof args !== \"object\" || Array.isArray(args)) {\n throw new Error('\"args\" must be an object for op \"util.random\", e.g. { \"domain\": \"acme.test\" }');\n }\n return randomDataFor(ctx).generate(String(input.generator), args);\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.step.d.ts","sourceRoot":"","sources":["../../../../src/testing/steps/util/script.step.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAwMxD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAgC/D"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.registerScriptStep = registerScriptStep;
|
|
37
|
+
const vm = __importStar(require("vm"));
|
|
38
|
+
const interpolation_1 = require("../../core/interpolation");
|
|
39
|
+
const token_scan_1 = require("../../core/token-scan");
|
|
40
|
+
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
41
|
+
const MAX_TIMEOUT_MS = 30_000;
|
|
42
|
+
const WRAP_START = "(function () {\n";
|
|
43
|
+
const WRAP_END = "\n})()";
|
|
44
|
+
const TOKEN_PREFIXES = ["res:", "env:", "params.", "data:", "data.", "secret:", "random:", "now:"];
|
|
45
|
+
const OUT_OF_SCOPE = /^(res|params|data|env|secrets?|lastResponse) is not defined$/;
|
|
46
|
+
const PRELUDE = `var input = JSON.parse(__input);
|
|
47
|
+
var __logs = [];
|
|
48
|
+
var console = (function () {
|
|
49
|
+
function text(value) {
|
|
50
|
+
if (typeof value === "string") return value;
|
|
51
|
+
try { var json = JSON.stringify(value); return json === undefined ? String(value) : json; } catch (e) { return String(value); }
|
|
52
|
+
}
|
|
53
|
+
function write(level) {
|
|
54
|
+
return function () { __logs.push(level + ": " + Array.prototype.map.call(arguments, text).join(" ")); };
|
|
55
|
+
}
|
|
56
|
+
return { log: write("log"), info: write("info"), warn: write("warn"), error: write("error"), debug: write("debug") };
|
|
57
|
+
})();
|
|
58
|
+
var __result, __thrown, __failed = false;
|
|
59
|
+
try { __result = `;
|
|
60
|
+
const EPILOGUE = `; } catch (e) { __failed = true; __thrown = e; }
|
|
61
|
+
(function () {
|
|
62
|
+
var out = { logs: __logs };
|
|
63
|
+
if (__failed) {
|
|
64
|
+
out.kind = "error";
|
|
65
|
+
try {
|
|
66
|
+
out.name = __thrown && __thrown.name ? String(__thrown.name) : "";
|
|
67
|
+
out.message = __thrown && __thrown.message !== undefined ? String(__thrown.message) : String(__thrown);
|
|
68
|
+
} catch (e) { out.message = "the script threw a value that cannot be read"; }
|
|
69
|
+
} else if (__result !== null && (typeof __result === "object" || typeof __result === "function") && typeof __result.then === "function") {
|
|
70
|
+
out.kind = "promise";
|
|
71
|
+
} else if (typeof __result === "function") {
|
|
72
|
+
out.kind = "function";
|
|
73
|
+
} else if (__result === undefined) {
|
|
74
|
+
out.kind = "undefined";
|
|
75
|
+
} else {
|
|
76
|
+
try {
|
|
77
|
+
out.json = JSON.stringify(__result);
|
|
78
|
+
out.kind = out.json === undefined ? "unsaveable" : "value";
|
|
79
|
+
} catch (e) { out.kind = "unsaveable"; out.message = String(e && e.message); }
|
|
80
|
+
}
|
|
81
|
+
return JSON.stringify(out);
|
|
82
|
+
})()`;
|
|
83
|
+
let typescript;
|
|
84
|
+
function loadTypeScript() {
|
|
85
|
+
if (typescript === undefined) {
|
|
86
|
+
try {
|
|
87
|
+
typescript = require("typescript");
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
typescript = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return typescript;
|
|
94
|
+
}
|
|
95
|
+
function scriptSource(script) {
|
|
96
|
+
if (typeof script === "string")
|
|
97
|
+
return script;
|
|
98
|
+
if (Array.isArray(script) && script.every((line) => typeof line === "string"))
|
|
99
|
+
return script.join("\n");
|
|
100
|
+
throw new Error('"script" must be text or a list of lines for op "util.script"');
|
|
101
|
+
}
|
|
102
|
+
function refuseTokens(source) {
|
|
103
|
+
for (const { inner } of (0, token_scan_1.findTokens)(source)) {
|
|
104
|
+
const token = inner.trim();
|
|
105
|
+
if (TOKEN_PREFIXES.some((prefix) => token.startsWith(prefix))) {
|
|
106
|
+
throw new Error(`util.script does not resolve \${${token}} inside the script; put tokens in "input" and read them as input.<name>`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function compile(source) {
|
|
111
|
+
const wrapped = WRAP_START + source + WRAP_END;
|
|
112
|
+
const ts = loadTypeScript();
|
|
113
|
+
let call = wrapped;
|
|
114
|
+
if (ts) {
|
|
115
|
+
const out = ts.transpileModule(wrapped, {
|
|
116
|
+
reportDiagnostics: true,
|
|
117
|
+
compilerOptions: { target: ts.ScriptTarget.ES2022 },
|
|
118
|
+
});
|
|
119
|
+
const first = out.diagnostics?.[0];
|
|
120
|
+
if (first) {
|
|
121
|
+
const lines = source.split("\n").length;
|
|
122
|
+
const where = first.file && first.start !== undefined
|
|
123
|
+
? ` (line ${Math.min(first.file.getLineAndCharacterOfPosition(first.start).line, lines)})`
|
|
124
|
+
: "";
|
|
125
|
+
throw new Error(`util.script does not compile${where}: ${ts.flattenDiagnosticMessageText(first.messageText, "\n")}`);
|
|
126
|
+
}
|
|
127
|
+
call = out.outputText.trim().replace(/;$/, "");
|
|
128
|
+
}
|
|
129
|
+
return PRELUDE + call + EPILOGUE;
|
|
130
|
+
}
|
|
131
|
+
function hintFor(name, message) {
|
|
132
|
+
if (OUT_OF_SCOPE.test(message)) {
|
|
133
|
+
return '; the script sees only input, so pass the value in, e.g. "input": { "books": "${res:books}" }';
|
|
134
|
+
}
|
|
135
|
+
if (name === "SyntaxError" && /await/.test(message)) {
|
|
136
|
+
return "; util.script runs synchronously, so await is not available";
|
|
137
|
+
}
|
|
138
|
+
if (name === "SyntaxError" && !loadTypeScript()) {
|
|
139
|
+
return "; TypeScript syntax needs the typescript package where the tests run";
|
|
140
|
+
}
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
143
|
+
function timeoutFor(step) {
|
|
144
|
+
const requested = step.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
145
|
+
return Math.min(Math.max(1, Math.floor(requested)), MAX_TIMEOUT_MS);
|
|
146
|
+
}
|
|
147
|
+
function run(code, input, timeoutMs) {
|
|
148
|
+
const sandbox = Object.assign(Object.create(null), { __input: JSON.stringify(input) });
|
|
149
|
+
let text;
|
|
150
|
+
try {
|
|
151
|
+
text = vm.runInNewContext(code, sandbox, { filename: "util.script", timeout: timeoutMs });
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
if (err?.code === "ERR_SCRIPT_EXECUTION_TIMEOUT") {
|
|
155
|
+
const most = timeoutMs === MAX_TIMEOUT_MS ? `, the most a script may run` : " (raise timeoutMs on the step if it needs longer)";
|
|
156
|
+
throw new Error(`util.script ran past ${timeoutMs}ms${most}`);
|
|
157
|
+
}
|
|
158
|
+
const message = String(err?.message ?? err);
|
|
159
|
+
throw new Error(`util.script failed: ${message}${hintFor(err?.name, message)}`);
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
return JSON.parse(String(text));
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
throw new Error("util.script did not finish normally; do not reassign JSON or the runner's names (__input, __logs)");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function attachLogs(ctx, step, logs) {
|
|
169
|
+
if (!logs?.length || !ctx.reporter?.attach)
|
|
170
|
+
return;
|
|
171
|
+
ctx.reporter.attach({
|
|
172
|
+
scenarioId: ctx.scenarioId,
|
|
173
|
+
name: step.name ? `util.script console: ${step.name}` : "util.script console",
|
|
174
|
+
contentType: "text/plain",
|
|
175
|
+
data: logs.join("\n"),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function toSaved(outcome) {
|
|
179
|
+
switch (outcome.kind) {
|
|
180
|
+
case "value":
|
|
181
|
+
return JSON.parse(outcome.json);
|
|
182
|
+
case "undefined":
|
|
183
|
+
return undefined;
|
|
184
|
+
case "error": {
|
|
185
|
+
const message = outcome.message ?? "";
|
|
186
|
+
throw new Error(`util.script failed: ${message}${hintFor(outcome.name, message)}`);
|
|
187
|
+
}
|
|
188
|
+
case "promise":
|
|
189
|
+
throw new Error("util.script returned a Promise; scripts run synchronously, so compute the value and return it");
|
|
190
|
+
case "function":
|
|
191
|
+
throw new Error("util.script must return data (text, numbers, true/false, lists or objects), not a function");
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(`util.script must return data (text, numbers, true/false, lists or objects)${outcome.message ? `: ${outcome.message}` : ""}`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function registerScriptStep(registry) {
|
|
197
|
+
registry.register("util.script", async (ctx, step) => {
|
|
198
|
+
const w = (step.with ?? {});
|
|
199
|
+
if (w.script === undefined) {
|
|
200
|
+
throw new Error('Missing "script" in step.with for op "util.script"');
|
|
201
|
+
}
|
|
202
|
+
const source = scriptSource(w.script);
|
|
203
|
+
if (!source.trim()) {
|
|
204
|
+
throw new Error('Missing "script" in step.with for op "util.script"');
|
|
205
|
+
}
|
|
206
|
+
if (w.input !== undefined && (w.input === null || typeof w.input !== "object" || Array.isArray(w.input))) {
|
|
207
|
+
throw new Error('"input" must be an object for op "util.script", e.g. { "books": "${res:books}" }');
|
|
208
|
+
}
|
|
209
|
+
refuseTokens(source);
|
|
210
|
+
const code = compile(source);
|
|
211
|
+
const input = (0, interpolation_1.interpolateDeep)((w.input ?? {}), ctx, { keepTypes: true });
|
|
212
|
+
const outcome = run(code, input, timeoutFor(step));
|
|
213
|
+
attachLogs(ctx, step, outcome.logs);
|
|
214
|
+
const result = toSaved(outcome);
|
|
215
|
+
if (result === undefined && step.saveAs) {
|
|
216
|
+
throw new Error(`util.script returned nothing to save as "${step.saveAs}"; end the script with return, e.g. return input.records[0].id`);
|
|
217
|
+
}
|
|
218
|
+
return result;
|
|
219
|
+
}, { rawWith: ["script", "input"] });
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=script.step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.step.js","sourceRoot":"","sources":["../../../../src/testing/steps/util/script.step.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiNA,gDAgCC;AA5OD,uCAAyB;AAGzB,4DAA2D;AAE3D,sDAAmD;AAanD,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAGjC,MAAM,cAAc,GAAG,MAAM,CAAC;AAE9B,MAAM,UAAU,GAAG,kBAAkB,CAAC;AACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAE1B,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OA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CAAC,CAAC,KAAK,IAAI,EAAE,CAA4B,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QACnD,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,4CAA4C,IAAI,CAAC,MAAM,gEAAgE,CACxH,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CACjC,CAAC;AACJ,CAAC","sourcesContent":["// Purpose: util.script runs a short TypeScript function over the values passed in `input` and returns\n// its result, so `saveAs` can keep a value no token can reach: an id found by a condition, two responses\n// combined, a field reshaped for the next request. Tokens go in `input`; code goes in `script`.\n// Anything with I/O, async work or reuse across scenarios belongs in a test.spec.\n\nimport * as vm from \"vm\";\nimport type { TestContext } from \"../../contracts/runtime-context.types\";\nimport type { OpStep } from \"../../contracts/testing-metadata.types\";\nimport { interpolateDeep } from \"../../core/interpolation\";\nimport { StepRegistry } from \"../../core/step-registry\";\nimport { findTokens } from \"../../core/token-scan\";\n\ntype ScriptInput = { script?: unknown; input?: unknown };\n\n/** What the sandbox hands back, always as JSON text, so no object made in it reaches the runner. */\ntype SandboxOutcome = {\n kind: \"value\" | \"undefined\" | \"error\" | \"promise\" | \"function\" | \"unsaveable\";\n json?: string;\n name?: string;\n message?: string;\n logs: string[];\n};\n\nconst DEFAULT_TIMEOUT_MS = 5_000;\n// A script runs synchronously in the runner's process, so while it runs nothing else does: in test-hub,\n// that is the whole API. A step may lower the limit but not raise it past this.\nconst MAX_TIMEOUT_MS = 30_000;\n// One line before the script, so a diagnostic's 0-based line number is the script's own 1-based line.\nconst WRAP_START = \"(function () {\\n\";\nconst WRAP_END = \"\\n})()\";\n// Vocabulary tokens are refused inside a script: there `${...}` is a JavaScript template literal.\nconst TOKEN_PREFIXES = [\"res:\", \"env:\", \"params.\", \"data:\", \"data.\", \"secret:\", \"random:\", \"now:\"];\nconst OUT_OF_SCOPE = /^(res|params|data|env|secrets?|lastResponse) is not defined$/;\n\n// The sandbox is given only text. An object made outside it would carry the runner's own Function\n// constructor (`input.constructor.constructor(\"return process\")()`), and with it everything the\n// process can do. So `input` arrives as JSON and is parsed in here, `console` is written in here, and\n// the result is checked and turned into JSON in here, inside the timeout: a getter in the result\n// cannot then run unbounded once the script has returned.\nconst PRELUDE = `var input = JSON.parse(__input);\nvar __logs = [];\nvar console = (function () {\n function text(value) {\n if (typeof value === \"string\") return value;\n try { var json = JSON.stringify(value); return json === undefined ? String(value) : json; } catch (e) { return String(value); }\n }\n function write(level) {\n return function () { __logs.push(level + \": \" + Array.prototype.map.call(arguments, text).join(\" \")); };\n }\n return { log: write(\"log\"), info: write(\"info\"), warn: write(\"warn\"), error: write(\"error\"), debug: write(\"debug\") };\n})();\nvar __result, __thrown, __failed = false;\ntry { __result = `;\n\nconst EPILOGUE = `; } catch (e) { __failed = true; __thrown = e; }\n(function () {\n var out = { logs: __logs };\n if (__failed) {\n out.kind = \"error\";\n try {\n out.name = __thrown && __thrown.name ? String(__thrown.name) : \"\";\n out.message = __thrown && __thrown.message !== undefined ? String(__thrown.message) : String(__thrown);\n } catch (e) { out.message = \"the script threw a value that cannot be read\"; }\n } else if (__result !== null && (typeof __result === \"object\" || typeof __result === \"function\") && typeof __result.then === \"function\") {\n out.kind = \"promise\";\n } else if (typeof __result === \"function\") {\n out.kind = \"function\";\n } else if (__result === undefined) {\n out.kind = \"undefined\";\n } else {\n try {\n out.json = JSON.stringify(__result);\n out.kind = out.json === undefined ? \"unsaveable\" : \"value\";\n } catch (e) { out.kind = \"unsaveable\"; out.message = String(e && e.message); }\n }\n return JSON.stringify(out);\n})()`;\n\ntype TypeScriptModule = typeof import(\"typescript\");\nlet typescript: TypeScriptModule | null | undefined;\n\n// typescript is a devDependency, so a production install may lack it. Plain JavaScript still runs then.\nfunction loadTypeScript(): TypeScriptModule | null {\n if (typescript === undefined) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n typescript = require(\"typescript\") as TypeScriptModule;\n } catch {\n typescript = null;\n }\n }\n return typescript;\n}\n\n// A script is text, or a list of lines: multi-line code in one JSON string is hard to read.\nfunction scriptSource(script: unknown): string {\n if (typeof script === \"string\") return script;\n if (Array.isArray(script) && script.every((line) => typeof line === \"string\")) return script.join(\"\\n\");\n throw new Error('\"script\" must be text or a list of lines for op \"util.script\"');\n}\n\nfunction refuseTokens(source: string): void {\n for (const { inner } of findTokens(source)) {\n const token = inner.trim();\n if (TOKEN_PREFIXES.some((prefix) => token.startsWith(prefix))) {\n throw new Error(\n `util.script does not resolve \\${${token}} inside the script; put tokens in \"input\" and read them as input.<name>`,\n );\n }\n }\n}\n\n// Compiles the script as one function call, then sets it between the sandbox's prelude and epilogue.\nfunction compile(source: string): string {\n const wrapped = WRAP_START + source + WRAP_END;\n const ts = loadTypeScript();\n let call = wrapped;\n if (ts) {\n const out = ts.transpileModule(wrapped, {\n reportDiagnostics: true,\n compilerOptions: { target: ts.ScriptTarget.ES2022 },\n });\n const first = out.diagnostics?.[0];\n if (first) {\n // A mistake such as an unclosed `{` is found on the wrapper's closing line; report the script's last line.\n const lines = source.split(\"\\n\").length;\n const where =\n first.file && first.start !== undefined\n ? ` (line ${Math.min(first.file.getLineAndCharacterOfPosition(first.start).line, lines)})`\n : \"\";\n throw new Error(`util.script does not compile${where}: ${ts.flattenDiagnosticMessageText(first.messageText, \"\\n\")}`);\n }\n call = out.outputText.trim().replace(/;$/, \"\");\n }\n return PRELUDE + call + EPILOGUE;\n}\n\nfunction hintFor(name: string | undefined, message: string): string {\n if (OUT_OF_SCOPE.test(message)) {\n return '; the script sees only input, so pass the value in, e.g. \"input\": { \"books\": \"${res:books}\" }';\n }\n if (name === \"SyntaxError\" && /await/.test(message)) {\n return \"; util.script runs synchronously, so await is not available\";\n }\n if (name === \"SyntaxError\" && !loadTypeScript()) {\n return \"; TypeScript syntax needs the typescript package where the tests run\";\n }\n return \"\";\n}\n\nfunction timeoutFor(step: OpStep): number {\n const requested = step.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n return Math.min(Math.max(1, Math.floor(requested)), MAX_TIMEOUT_MS);\n}\n\nfunction run(code: string, input: unknown, timeoutMs: number): SandboxOutcome {\n // No prototype: a plain object would give the script `this.constructor`, the runner's own Object.\n const sandbox = Object.assign(Object.create(null), { __input: JSON.stringify(input) });\n let text: unknown;\n try {\n text = vm.runInNewContext(code, sandbox, { filename: \"util.script\", timeout: timeoutMs });\n } catch (err: any) {\n if (err?.code === \"ERR_SCRIPT_EXECUTION_TIMEOUT\") {\n const most = timeoutMs === MAX_TIMEOUT_MS ? `, the most a script may run` : \" (raise timeoutMs on the step if it needs longer)\";\n throw new Error(`util.script ran past ${timeoutMs}ms${most}`);\n }\n // What reaches here failed to compile, so no script code ran: a syntax error such as `await`.\n const message = String(err?.message ?? err);\n throw new Error(`util.script failed: ${message}${hintFor(err?.name, message)}`);\n }\n try {\n return JSON.parse(String(text)) as SandboxOutcome;\n } catch {\n throw new Error(\"util.script did not finish normally; do not reassign JSON or the runner's names (__input, __logs)\");\n }\n}\n\n// The script's console output goes to the step's report, where the author looks, not to the server log.\nfunction attachLogs(ctx: TestContext, step: OpStep, logs: string[]): void {\n if (!logs?.length || !ctx.reporter?.attach) return;\n ctx.reporter.attach({\n scenarioId: ctx.scenarioId,\n name: step.name ? `util.script console: ${step.name}` : \"util.script console\",\n contentType: \"text/plain\",\n data: logs.join(\"\\n\"),\n });\n}\n\nfunction toSaved(outcome: SandboxOutcome): unknown {\n switch (outcome.kind) {\n case \"value\":\n return JSON.parse(outcome.json as string);\n case \"undefined\":\n return undefined;\n case \"error\": {\n const message = outcome.message ?? \"\";\n throw new Error(`util.script failed: ${message}${hintFor(outcome.name, message)}`);\n }\n case \"promise\":\n throw new Error(\"util.script returned a Promise; scripts run synchronously, so compute the value and return it\");\n case \"function\":\n throw new Error(\"util.script must return data (text, numbers, true/false, lists or objects), not a function\");\n default:\n throw new Error(\n `util.script must return data (text, numbers, true/false, lists or objects)${outcome.message ? `: ${outcome.message}` : \"\"}`,\n );\n }\n}\n\nexport function registerScriptStep(registry: StepRegistry): void {\n registry.register(\n \"util.script\",\n async (ctx: TestContext, step: OpStep) => {\n const w = (step.with ?? {}) as ScriptInput;\n if (w.script === undefined) {\n throw new Error('Missing \"script\" in step.with for op \"util.script\"');\n }\n const source = scriptSource(w.script);\n if (!source.trim()) {\n throw new Error('Missing \"script\" in step.with for op \"util.script\"');\n }\n if (w.input !== undefined && (w.input === null || typeof w.input !== \"object\" || Array.isArray(w.input))) {\n throw new Error('\"input\" must be an object for op \"util.script\", e.g. { \"books\": \"${res:books}\" }');\n }\n refuseTokens(source);\n const code = compile(source);\n // The engine leaves `input` raw for this op; resolve it here with whole-value tokens keeping their type.\n // It crosses into the sandbox as JSON, which also makes it a copy: a script cannot change a saved result.\n const input = interpolateDeep((w.input ?? {}) as Record<string, unknown>, ctx, { keepTypes: true });\n const outcome = run(code, input, timeoutFor(step));\n attachLogs(ctx, step, outcome.logs);\n const result = toSaved(outcome);\n if (result === undefined && step.saveAs) {\n throw new Error(\n `util.script returned nothing to save as \"${step.saveAs}\"; end the script with return, e.g. return input.records[0].id`,\n );\n }\n return result;\n },\n { rawWith: [\"script\", \"input\"] },\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.step.spec.d.ts","sourceRoot":"","sources":["../../../../src/testing/steps/util/script.step.spec.ts"],"names":[],"mappings":""}
|