@solidxai/core 0.1.22-beta.3 → 0.1.22-beta.4

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.
Files changed (203) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/constants/error-messages.d.ts +1 -1
  3. package/dist/constants/error-messages.d.ts.map +1 -1
  4. package/dist/constants/error-messages.js +1 -1
  5. package/dist/constants/error-messages.js.map +1 -1
  6. package/dist/controllers/agent-registry.controller.d.ts +8 -0
  7. package/dist/controllers/agent-registry.controller.d.ts.map +1 -1
  8. package/dist/controllers/agent-registry.controller.js +14 -0
  9. package/dist/controllers/agent-registry.controller.js.map +1 -1
  10. package/dist/controllers/agent-session.controller.d.ts +8 -1
  11. package/dist/controllers/agent-session.controller.d.ts.map +1 -1
  12. package/dist/controllers/agent-session.controller.js +66 -2
  13. package/dist/controllers/agent-session.controller.js.map +1 -1
  14. package/dist/controllers/test-data.controller.d.ts +12 -0
  15. package/dist/controllers/test-data.controller.d.ts.map +1 -0
  16. package/dist/controllers/test-data.controller.js +66 -0
  17. package/dist/controllers/test-data.controller.js.map +1 -0
  18. package/dist/controllers/test-data.controller.spec.d.ts +2 -0
  19. package/dist/controllers/test-data.controller.spec.d.ts.map +1 -0
  20. package/dist/controllers/test-data.controller.spec.js +78 -0
  21. package/dist/controllers/test-data.controller.spec.js.map +1 -0
  22. package/dist/dtos/create-agent-job.dto.d.ts +1 -0
  23. package/dist/dtos/create-agent-job.dto.d.ts.map +1 -1
  24. package/dist/dtos/create-agent-job.dto.js +8 -1
  25. package/dist/dtos/create-agent-job.dto.js.map +1 -1
  26. package/dist/dtos/create-agent-process.dto.d.ts +5 -0
  27. package/dist/dtos/create-agent-process.dto.d.ts.map +1 -1
  28. package/dist/dtos/create-agent-process.dto.js +37 -1
  29. package/dist/dtos/create-agent-process.dto.js.map +1 -1
  30. package/dist/dtos/create-agent-registry.dto.d.ts +5 -0
  31. package/dist/dtos/create-agent-registry.dto.d.ts.map +1 -1
  32. package/dist/dtos/create-agent-registry.dto.js +39 -1
  33. package/dist/dtos/create-agent-registry.dto.js.map +1 -1
  34. package/dist/dtos/create-agent-session.dto.js +1 -1
  35. package/dist/dtos/create-agent-session.dto.js.map +1 -1
  36. package/dist/dtos/test-run-request.dto.d.ts +1 -0
  37. package/dist/dtos/test-run-request.dto.d.ts.map +1 -1
  38. package/dist/dtos/test-run-request.dto.js +7 -1
  39. package/dist/dtos/test-run-request.dto.js.map +1 -1
  40. package/dist/dtos/update-agent-deployment.dto.d.ts +8 -0
  41. package/dist/dtos/update-agent-deployment.dto.d.ts.map +1 -0
  42. package/dist/dtos/update-agent-deployment.dto.js +60 -0
  43. package/dist/dtos/update-agent-deployment.dto.js.map +1 -0
  44. package/dist/dtos/update-agent-job.dto.d.ts +1 -0
  45. package/dist/dtos/update-agent-job.dto.d.ts.map +1 -1
  46. package/dist/dtos/update-agent-job.dto.js +8 -1
  47. package/dist/dtos/update-agent-job.dto.js.map +1 -1
  48. package/dist/dtos/update-agent-process.dto.d.ts +5 -0
  49. package/dist/dtos/update-agent-process.dto.d.ts.map +1 -1
  50. package/dist/dtos/update-agent-process.dto.js +37 -1
  51. package/dist/dtos/update-agent-process.dto.js.map +1 -1
  52. package/dist/dtos/update-agent-registry.dto.d.ts +5 -0
  53. package/dist/dtos/update-agent-registry.dto.d.ts.map +1 -1
  54. package/dist/dtos/update-agent-registry.dto.js +39 -1
  55. package/dist/dtos/update-agent-registry.dto.js.map +1 -1
  56. package/dist/dtos/update-agent-session.dto.js +1 -1
  57. package/dist/dtos/update-agent-session.dto.js.map +1 -1
  58. package/dist/entities/agent-job.entity.d.ts +1 -0
  59. package/dist/entities/agent-job.entity.d.ts.map +1 -1
  60. package/dist/entities/agent-job.entity.js +7 -2
  61. package/dist/entities/agent-job.entity.js.map +1 -1
  62. package/dist/entities/agent-process.entity.d.ts +8 -0
  63. package/dist/entities/agent-process.entity.d.ts.map +1 -1
  64. package/dist/entities/agent-process.entity.js +38 -1
  65. package/dist/entities/agent-process.entity.js.map +1 -1
  66. package/dist/entities/agent-registry.entity.d.ts +5 -0
  67. package/dist/entities/agent-registry.entity.d.ts.map +1 -1
  68. package/dist/entities/agent-registry.entity.js +22 -1
  69. package/dist/entities/agent-registry.entity.js.map +1 -1
  70. package/dist/entities/agent-session.entity.d.ts.map +1 -1
  71. package/dist/entities/agent-session.entity.js +3 -1
  72. package/dist/entities/agent-session.entity.js.map +1 -1
  73. package/dist/helpers/agent-config-version-name.d.ts +2 -0
  74. package/dist/helpers/agent-config-version-name.d.ts.map +1 -0
  75. package/dist/helpers/agent-config-version-name.js +17 -0
  76. package/dist/helpers/agent-config-version-name.js.map +1 -0
  77. package/dist/helpers/agent-config-version-name.spec.d.ts +2 -0
  78. package/dist/helpers/agent-config-version-name.spec.d.ts.map +1 -0
  79. package/dist/helpers/agent-config-version-name.spec.js +31 -0
  80. package/dist/helpers/agent-config-version-name.spec.js.map +1 -0
  81. package/dist/index.d.ts +3 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +2 -0
  84. package/dist/index.js.map +1 -1
  85. package/dist/jobs/database/test-run-queue-subscriber-database.service.d.ts.map +1 -1
  86. package/dist/jobs/database/test-run-queue-subscriber-database.service.js +8 -4
  87. package/dist/jobs/database/test-run-queue-subscriber-database.service.js.map +1 -1
  88. package/dist/resources/agent-embed/solid-agent-embed.js +243 -4
  89. package/dist/seeders/module-test-data.service.d.ts +19 -0
  90. package/dist/seeders/module-test-data.service.d.ts.map +1 -1
  91. package/dist/seeders/module-test-data.service.js +95 -15
  92. package/dist/seeders/module-test-data.service.js.map +1 -1
  93. package/dist/seeders/module-test-data.service.spec.d.ts +2 -0
  94. package/dist/seeders/module-test-data.service.spec.d.ts.map +1 -0
  95. package/dist/seeders/module-test-data.service.spec.js +158 -0
  96. package/dist/seeders/module-test-data.service.spec.js.map +1 -0
  97. package/dist/seeders/seed-data/solid-core-metadata.json +278 -11
  98. package/dist/services/agent-hub-process-manager.service.d.ts +4 -0
  99. package/dist/services/agent-hub-process-manager.service.d.ts.map +1 -1
  100. package/dist/services/agent-hub-process-manager.service.js +19 -3
  101. package/dist/services/agent-hub-process-manager.service.js.map +1 -1
  102. package/dist/services/agent-registry.service.d.ts +8 -0
  103. package/dist/services/agent-registry.service.d.ts.map +1 -1
  104. package/dist/services/agent-registry.service.js +32 -1
  105. package/dist/services/agent-registry.service.js.map +1 -1
  106. package/dist/services/crud.service.d.ts +1 -0
  107. package/dist/services/crud.service.d.ts.map +1 -1
  108. package/dist/services/crud.service.js +26 -2
  109. package/dist/services/crud.service.js.map +1 -1
  110. package/dist/services/settings/default-settings-provider.service.d.ts +12 -2
  111. package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
  112. package/dist/services/settings/default-settings-provider.service.js +7 -1
  113. package/dist/services/settings/default-settings-provider.service.js.map +1 -1
  114. package/dist/solid-core.module.d.ts.map +1 -1
  115. package/dist/solid-core.module.js +3 -0
  116. package/dist/solid-core.module.js.map +1 -1
  117. package/dist/testing/adapters/ui/browser-provisioner.d.ts +11 -0
  118. package/dist/testing/adapters/ui/browser-provisioner.d.ts.map +1 -1
  119. package/dist/testing/adapters/ui/browser-provisioner.js +51 -1
  120. package/dist/testing/adapters/ui/browser-provisioner.js.map +1 -1
  121. package/dist/testing/adapters/ui/browser-provisioner.spec.d.ts +2 -0
  122. package/dist/testing/adapters/ui/browser-provisioner.spec.d.ts.map +1 -0
  123. package/dist/testing/adapters/ui/browser-provisioner.spec.js +137 -0
  124. package/dist/testing/adapters/ui/browser-provisioner.spec.js.map +1 -0
  125. package/dist/testing/adapters/ui/playwright-adapter.d.ts +7 -0
  126. package/dist/testing/adapters/ui/playwright-adapter.d.ts.map +1 -1
  127. package/dist/testing/adapters/ui/playwright-adapter.js +37 -8
  128. package/dist/testing/adapters/ui/playwright-adapter.js.map +1 -1
  129. package/dist/testing/adapters/ui/run-video.d.ts +40 -0
  130. package/dist/testing/adapters/ui/run-video.d.ts.map +1 -0
  131. package/dist/testing/adapters/ui/run-video.js +113 -0
  132. package/dist/testing/adapters/ui/run-video.js.map +1 -0
  133. package/dist/testing/adapters/ui/run-video.spec.d.ts +2 -0
  134. package/dist/testing/adapters/ui/run-video.spec.d.ts.map +1 -0
  135. package/dist/testing/adapters/ui/run-video.spec.js +62 -0
  136. package/dist/testing/adapters/ui/run-video.spec.js.map +1 -0
  137. package/dist/testing/contracts/testing-metadata.types.d.ts +1 -0
  138. package/dist/testing/contracts/testing-metadata.types.d.ts.map +1 -1
  139. package/dist/testing/contracts/testing-metadata.types.js.map +1 -1
  140. package/dist/testing/core/testing-engine.d.ts +1 -1
  141. package/dist/testing/core/testing-engine.d.ts.map +1 -1
  142. package/dist/testing/core/testing-engine.js +22 -4
  143. package/dist/testing/core/testing-engine.js.map +1 -1
  144. package/dist/testing/reporter/lifecycle-events.types.d.ts +1 -1
  145. package/dist/testing/reporter/lifecycle-events.types.d.ts.map +1 -1
  146. package/dist/testing/reporter/lifecycle-events.types.js.map +1 -1
  147. package/dist/testing/reporter/lifecycle-webhook-reporter.d.ts.map +1 -1
  148. package/dist/testing/reporter/lifecycle-webhook-reporter.js +2 -0
  149. package/dist/testing/reporter/lifecycle-webhook-reporter.js.map +1 -1
  150. package/dist/testing/runner/read-scenarios-file.d.ts +1 -0
  151. package/dist/testing/runner/read-scenarios-file.d.ts.map +1 -1
  152. package/dist/testing/runner/read-scenarios-file.js +20 -0
  153. package/dist/testing/runner/read-scenarios-file.js.map +1 -1
  154. package/dist/testing/runner/run-from-metadata.d.ts.map +1 -1
  155. package/dist/testing/runner/run-from-metadata.js +9 -1
  156. package/dist/testing/runner/run-from-metadata.js.map +1 -1
  157. package/dist/testing/runner/run-from-metadata.spec.js +12 -1
  158. package/dist/testing/runner/run-from-metadata.spec.js.map +1 -1
  159. package/package.json +1 -1
  160. package/resources/agent-embed/solid-agent-embed.js +243 -4
  161. package/src/constants/error-messages.ts +2 -1
  162. package/src/controllers/agent-registry.controller.ts +8 -1
  163. package/src/controllers/agent-session.controller.ts +37 -2
  164. package/src/controllers/test-data.controller.spec.ts +94 -0
  165. package/src/controllers/test-data.controller.ts +58 -0
  166. package/src/dtos/create-agent-job.dto.ts +6 -0
  167. package/src/dtos/create-agent-process.dto.ts +32 -1
  168. package/src/dtos/create-agent-registry.dto.ts +34 -1
  169. package/src/dtos/create-agent-session.dto.ts +1 -1
  170. package/src/dtos/test-run-request.dto.ts +6 -0
  171. package/src/dtos/update-agent-deployment.dto.ts +37 -0
  172. package/src/dtos/update-agent-job.dto.ts +6 -0
  173. package/src/dtos/update-agent-process.dto.ts +32 -1
  174. package/src/dtos/update-agent-registry.dto.ts +34 -1
  175. package/src/dtos/update-agent-session.dto.ts +1 -1
  176. package/src/entities/agent-job.entity.ts +5 -1
  177. package/src/entities/agent-process.entity.ts +28 -0
  178. package/src/entities/agent-registry.entity.ts +15 -0
  179. package/src/entities/agent-session.entity.ts +3 -0
  180. package/src/helpers/agent-config-version-name.spec.ts +35 -0
  181. package/src/helpers/agent-config-version-name.ts +16 -0
  182. package/src/index.ts +5 -0
  183. package/src/jobs/database/test-run-queue-subscriber-database.service.ts +10 -6
  184. package/src/seeders/module-test-data.service.spec.ts +184 -0
  185. package/src/seeders/module-test-data.service.ts +136 -20
  186. package/src/seeders/seed-data/solid-core-metadata.json +278 -11
  187. package/src/services/agent-hub-process-manager.service.ts +25 -4
  188. package/src/services/agent-registry.service.ts +35 -2
  189. package/src/services/crud.service.ts +30 -2
  190. package/src/services/settings/default-settings-provider.service.ts +11 -1
  191. package/src/solid-core.module.ts +3 -0
  192. package/src/testing/adapters/ui/browser-provisioner.spec.ts +131 -0
  193. package/src/testing/adapters/ui/browser-provisioner.ts +85 -2
  194. package/src/testing/adapters/ui/playwright-adapter.ts +48 -10
  195. package/src/testing/adapters/ui/run-video.spec.ts +72 -0
  196. package/src/testing/adapters/ui/run-video.ts +122 -0
  197. package/src/testing/contracts/testing-metadata.types.ts +5 -0
  198. package/src/testing/core/testing-engine.ts +28 -5
  199. package/src/testing/reporter/lifecycle-events.types.ts +2 -1
  200. package/src/testing/reporter/lifecycle-webhook-reporter.ts +1 -0
  201. package/src/testing/runner/read-scenarios-file.ts +24 -0
  202. package/src/testing/runner/run-from-metadata.spec.ts +15 -1
  203. package/src/testing/runner/run-from-metadata.ts +13 -5
@@ -1,4 +1,4 @@
1
- import { Injectable, Logger, NotFoundException } from '@nestjs/common';
1
+ import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';
2
2
  import { InjectEntityManager } from '@nestjs/typeorm';
3
3
  import { ModuleRef } from "@nestjs/core";
4
4
  import { EntityManager } from 'typeorm';
@@ -7,7 +7,9 @@ import { AgentRegistry } from '../entities/agent-registry.entity';
7
7
  import { AgentRegistryRepository } from '../repository/agent-registry.repository';
8
8
  import { AgentConfigVersion } from '../entities/agent-config-version.entity';
9
9
  import { ActivateAgentRegistryDto } from '../dtos/activate-agent-registry.dto';
10
+ import { UpdateAgentDeploymentDto } from '../dtos/update-agent-deployment.dto';
10
11
  import { markActiveAgentsDraft } from './agent-config-version.service';
12
+ import { buildAgentConfigVersionName } from '../helpers/agent-config-version-name';
11
13
  import { normalizeAgentRequiredInputs } from '../helpers/agent-required-inputs';
12
14
  import { ModuleMetadataHelperService } from '../helpers/module-metadata-helper.service';
13
15
  import { syncEntityTagsToModuleMetadataJson } from '../subscribers/agenthub-metadata-sync.util';
@@ -54,6 +56,37 @@ export class AgentRegistryService extends CRUDService<AgentRegistry>{
54
56
  return this.repo.findOne({ where: { id: saved.id } });
55
57
  }
56
58
 
59
+ async updateDeployment(id: number, dto: UpdateAgentDeploymentDto) {
60
+ return this.entityManager.transaction(async (manager) => {
61
+ const repository = manager.getRepository(AgentRegistry);
62
+ const agent = await repository.findOne({ where: { id }, lock: { mode: 'pessimistic_write' } });
63
+ if (!agent) throw new NotFoundException(`Agent ${id} was not found.`);
64
+
65
+ const runner = dto.runner === undefined ? agent.runner : dto.runner;
66
+ const minProcesses = dto.minProcesses ?? agent.minProcesses;
67
+ const maxProcesses = dto.maxProcesses === undefined ? agent.maxProcesses : dto.maxProcesses;
68
+ const processCpu = dto.processCpu === undefined ? agent.processCpu : dto.processCpu;
69
+ const processMemory = dto.processMemory === undefined ? agent.processMemory : dto.processMemory;
70
+ if (maxProcesses !== null && minProcesses > maxProcesses) {
71
+ throw new BadRequestException('Minimum processes cannot exceed maximum processes.');
72
+ }
73
+ if (runner === 'docker' || runner === 'ecs') {
74
+ const links = await repository.createQueryBuilder('agent')
75
+ .innerJoin('agent.agentTools', 'link')
76
+ .innerJoin('link.agentToolRegistry', 'tool')
77
+ .select('tool.name', 'name')
78
+ .where('agent.id = :id', { id })
79
+ .getRawMany<{ name: string }>();
80
+ if (links.some(({ name }) => name.startsWith('browser_'))) {
81
+ throw new BadRequestException('Agents with browser tools require the local runner.');
82
+ }
83
+ }
84
+ const deployment = { runner, minProcesses, maxProcesses, processCpu, processMemory };
85
+ await repository.update(id, deployment);
86
+ return deployment;
87
+ });
88
+ }
89
+
57
90
  async activate(id: number, dto: ActivateAgentRegistryDto = {}): Promise<AgentRegistry> {
58
91
  return this.entityManager.transaction(async (manager) => {
59
92
  const agentRepository = manager.getRepository(AgentRegistry);
@@ -71,7 +104,7 @@ export class AgentRegistryService extends CRUDService<AgentRegistry>{
71
104
  await versionRepository.save(versionRepository.create({
72
105
  agentRegistry: agent,
73
106
  versionNumber,
74
- name: dto.name?.trim() || null,
107
+ name: buildAgentConfigVersionName(dto.name, versionNumber),
75
108
  description: dto.description?.trim() || null,
76
109
  }));
77
110
 
@@ -979,7 +979,7 @@ private async prepareManyToManyAuditSnapshot(entity: T,id: number,modelSingularN
979
979
  return { message: SUCCESS_MESSAGES.RECORD_RECOVERED, data: softDeletedRows };
980
980
  } catch (error: any) {
981
981
  if (error instanceof QueryFailedError && (error as any).code === '23505') {
982
- throw new ConflictException(ERROR_MESSAGES.CONFLICTING_RECORD_ON_UNARCHIVE);
982
+ throw new ConflictException(this.getRecoveryConflictMessage(error));
983
983
  }
984
984
  if (error instanceof HttpException) {
985
985
  throw error;
@@ -988,6 +988,34 @@ private async prepareManyToManyAuditSnapshot(entity: T,id: number,modelSingularN
988
988
  }
989
989
  }
990
990
 
991
+ private getRecoveryConflictMessage(error: any): string {
992
+ const defaultMessage = ERROR_MESSAGES.CONFLICTING_RECORD_ON_UNARCHIVE();
993
+ const databaseDetail = error?.driverError?.detail ?? error?.detail;
994
+ if (typeof databaseDetail !== 'string') return defaultMessage;
995
+
996
+ // PostgreSQL detail example: Key (unique_field, deleted_tracker)=(value, not-deleted) already exists.
997
+ const match = databaseDetail.match(/^Key \((.+)\)=\((.+)\) already exists\.$/);
998
+ if (!match) return defaultMessage;
999
+
1000
+ const fields = match[1].split(/,\s*/);
1001
+ const values = match[2].split(/,\s*/);
1002
+ if (fields.length !== values.length) return defaultMessage;
1003
+
1004
+ const conflictDetails: string[] = [];
1005
+ fields.forEach((field: string, index: number) => {
1006
+ // deletedTracker is an internal soft-delete field and is not useful to the user.
1007
+ const fieldName = field.replace(/^"|"$/g, '');
1008
+ const isInternalField = fieldName === 'deleted_tracker' || fieldName === 'deletedTracker';
1009
+ if (!isInternalField) {
1010
+ conflictDetails.push(`${fieldName.replace(/_/g, ' ')} "${values[index]}"`);
1011
+ }
1012
+ });
1013
+
1014
+ if (conflictDetails.length === 0) return defaultMessage;
1015
+
1016
+ return ERROR_MESSAGES.CONFLICTING_RECORD_ON_UNARCHIVE(conflictDetails.join(' and '));
1017
+ }
1018
+
991
1019
  async recoverMany(ids: number[], solidRequestContext: any = {}) {
992
1020
  try {
993
1021
  const loadedmodel = await this.loadModel();
@@ -1033,7 +1061,7 @@ private async prepareManyToManyAuditSnapshot(entity: T,id: number,modelSingularN
1033
1061
  return { message: SUCCESS_MESSAGES.SELECTED_RECORDS_RECOVERED, recoveredIds: ids };
1034
1062
  } catch (error: any) {
1035
1063
  if (error instanceof QueryFailedError && (error as any).code === "23505") {
1036
- throw new ConflictException(ERROR_MESSAGES.CONFLICTING_RECORD_ON_UNARCHIVE);
1064
+ throw new ConflictException(this.getRecoveryConflictMessage(error));
1037
1065
  }
1038
1066
  if (error instanceof HttpException) {
1039
1067
  throw error;
@@ -438,6 +438,14 @@ const getSolidCoreSettings = (isProd: boolean) =>
438
438
  value: process.env.MCP_API_KEY,
439
439
  level: SettingLevel.SystemEnv,
440
440
  },
441
+ {
442
+ // Lets POST /api/test-data/load write seed data into this app. Off unless the env var is "true". SystemEnv keeps it
443
+ // out of the settings screen and out of reach of the settings API.
444
+ moduleName: "solid-core",
445
+ key: "testDataEndpointEnabled",
446
+ value: process.env.SOLIDX_TEST_DATA_ENDPOINT_ENABLED === "true",
447
+ level: SettingLevel.SystemEnv,
448
+ },
441
449
  {
442
450
  moduleName: "solid-core",
443
451
  key: "solidAgentEnabled",
@@ -1224,7 +1232,9 @@ const getSolidCoreSettings = (isProd: boolean) =>
1224
1232
  {
1225
1233
  moduleName: "solid-core",
1226
1234
  key: "forceChangePasswordOnFirstLogin",
1227
- value: false,
1235
+ // Defaults to true. Set FORCE_CHANGE_PASSWORD_ON_FIRST_LOGIN=false before the first
1236
+ // start on a fresh database to create users without the flag (used by test apps).
1237
+ value: process.env.FORCE_CHANGE_PASSWORD_ON_FIRST_LOGIN !== "false",
1228
1238
  level: SettingLevel.SystemAdminEditable,
1229
1239
  label: "Force Change Password On First Login",
1230
1240
  group: "authentication-settings",
@@ -117,6 +117,7 @@ import { ServiceController } from "./controllers/service.controller";
117
117
  import { SmsTemplateController } from "./controllers/sms-template.controller";
118
118
  import { TestQueueController } from "./controllers/test-queue.controller";
119
119
  import { TestRunController } from "./controllers/test-run.controller";
120
+ import { TestDataController } from "./controllers/test-data.controller";
120
121
  import { EmailAttachment } from "./entities/email-attachment.entity";
121
122
  import { EmailTemplate } from "./entities/email-template.entity";
122
123
  import { MenuItemMetadata } from "./entities/menu-item-metadata.entity";
@@ -756,6 +757,7 @@ import { AgentToolRegistryService } from "./services/agent-tool-registry.service
756
757
  TestController,
757
758
  TestQueueController,
758
759
  TestRunController,
760
+ TestDataController,
759
761
  UserActivityHistoryController,
760
762
  UserController,
761
763
  UserViewMetadataController,
@@ -1213,6 +1215,7 @@ import { AgentToolRegistryService } from "./services/agent-tool-registry.service
1213
1215
  ConfigModule,
1214
1216
  DraftPublishHelperService,
1215
1217
  InternationalisationHelperService,
1218
+ ModuleTestDataService,
1216
1219
  CrudHelperService,
1217
1220
  CRUDService,
1218
1221
  CsvService,
@@ -0,0 +1,131 @@
1
+ import * as fs from "fs";
2
+ import * as os from "os";
3
+ import * as path from "path";
4
+ import {
5
+ headlessShellDirectory,
6
+ isBrowserInstallComplete,
7
+ isChromiumBundleComplete,
8
+ playwrightBrowserDirectory,
9
+ readPlaywrightBrowsersJson,
10
+ } from "./browser-provisioner";
11
+
12
+ describe("browser install check", () => {
13
+ let root: string;
14
+
15
+ /** Creates `<root>/<folder>/<relative>` as an empty file and returns its path. */
16
+ const makeExecutable = (folder: string, relative = "chrome-mac/Chromium.app/Contents/MacOS/Chromium") => {
17
+ const executable = path.join(root, folder, relative);
18
+ fs.mkdirSync(path.dirname(executable), { recursive: true });
19
+ fs.writeFileSync(executable, "");
20
+ return executable;
21
+ };
22
+
23
+ beforeEach(() => {
24
+ root = fs.mkdtempSync(path.join(os.tmpdir(), "solid-browser-"));
25
+ });
26
+
27
+ afterEach(() => {
28
+ fs.rmSync(root, { recursive: true, force: true });
29
+ });
30
+
31
+ it("is not installed when the executable is missing", () => {
32
+ expect(isBrowserInstallComplete(path.join(root, "chromium-1228", "chrome"))).toBe(false);
33
+ });
34
+
35
+ it("is not installed when the executable exists but the completion marker does not", () => {
36
+ // An install interrupted during extraction: the executable is there, the marker never was.
37
+ const executable = makeExecutable("chromium-1228");
38
+ expect(isBrowserInstallComplete(executable)).toBe(false);
39
+ });
40
+
41
+ it("is installed when the executable and the completion marker both exist", () => {
42
+ const executable = makeExecutable("chromium-1228");
43
+ fs.writeFileSync(path.join(root, "chromium-1228", "INSTALLATION_COMPLETE"), "");
44
+ expect(isBrowserInstallComplete(executable)).toBe(true);
45
+ });
46
+
47
+ it("also requires the marker for a headless shell folder", () => {
48
+ const executable = makeExecutable("chromium_headless_shell-1228", "chrome-headless-shell-mac/chrome-headless-shell");
49
+ expect(isBrowserInstallComplete(executable)).toBe(false);
50
+ fs.writeFileSync(path.join(root, "chromium_headless_shell-1228", "INSTALLATION_COMPLETE"), "");
51
+ expect(isBrowserInstallComplete(executable)).toBe(true);
52
+ });
53
+
54
+ it("trusts the executable alone when it is outside a Playwright browser folder", () => {
55
+ const executable = makeExecutable("my-own-chrome");
56
+ expect(isBrowserInstallComplete(executable)).toBe(true);
57
+ });
58
+
59
+ it("finds the browser folder from deep inside it, and returns null elsewhere", () => {
60
+ const executable = makeExecutable("chromium-1228");
61
+ expect(playwrightBrowserDirectory(executable)).toBe(path.join(root, "chromium-1228"));
62
+ expect(playwrightBrowserDirectory(path.join(root, "my-own-chrome", "chrome"))).toBeNull();
63
+ });
64
+ });
65
+
66
+ describe("chromium and its headless shell", () => {
67
+ const browsersJson = {
68
+ browsers: [
69
+ { name: "chromium", revision: "1228" },
70
+ { name: "chromium-headless-shell", revision: "1228" },
71
+ ],
72
+ };
73
+ let root: string;
74
+ let chromium: string;
75
+
76
+ const touch = (file: string) => {
77
+ fs.mkdirSync(path.dirname(file), { recursive: true });
78
+ fs.writeFileSync(file, "");
79
+ };
80
+
81
+ beforeEach(() => {
82
+ root = fs.mkdtempSync(path.join(os.tmpdir(), "solid-browser-"));
83
+ chromium = path.join(root, "chromium-1228", "chrome-mac", "Chromium");
84
+ touch(chromium);
85
+ touch(path.join(root, "chromium-1228", "INSTALLATION_COMPLETE"));
86
+ });
87
+
88
+ afterEach(() => {
89
+ fs.rmSync(root, { recursive: true, force: true });
90
+ });
91
+
92
+ it("finds the headless shell folder next to the Chromium folder, by the revision in browsers.json", () => {
93
+ expect(headlessShellDirectory(chromium, browsersJson)).toBe(path.join(root, "chromium_headless_shell-1228"));
94
+ });
95
+
96
+ it("has no headless shell to check for a Chromium outside a Playwright folder, or without browsers.json", () => {
97
+ expect(headlessShellDirectory(path.join(root, "my-own-chrome", "chrome"), browsersJson)).toBeNull();
98
+ expect(headlessShellDirectory(chromium, null)).toBeNull();
99
+ expect(headlessShellDirectory(chromium, { browsers: [{ name: "chromium", revision: "1228" }] })).toBeNull();
100
+ });
101
+
102
+ it("is not complete while the headless shell is missing", () => {
103
+ expect(isChromiumBundleComplete(chromium, browsersJson)).toBe(false);
104
+ });
105
+
106
+ it("is not complete when the headless shell was interrupted before its marker", () => {
107
+ touch(path.join(root, "chromium_headless_shell-1228", "chrome-headless-shell-mac", "chrome-headless-shell"));
108
+ expect(isChromiumBundleComplete(chromium, browsersJson)).toBe(false);
109
+ });
110
+
111
+ it("is complete when Chromium and the headless shell both have their markers", () => {
112
+ touch(path.join(root, "chromium_headless_shell-1228", "chrome-headless-shell-mac", "chrome-headless-shell"));
113
+ touch(path.join(root, "chromium_headless_shell-1228", "INSTALLATION_COMPLETE"));
114
+ expect(isChromiumBundleComplete(chromium, browsersJson)).toBe(true);
115
+ });
116
+
117
+ it("is not complete when Chromium itself is interrupted, even with a finished headless shell", () => {
118
+ touch(path.join(root, "chromium_headless_shell-1228", "INSTALLATION_COMPLETE"));
119
+ fs.rmSync(path.join(root, "chromium-1228", "INSTALLATION_COMPLETE"));
120
+ expect(isChromiumBundleComplete(chromium, browsersJson)).toBe(false);
121
+ });
122
+
123
+ it("checks only Chromium when browsers.json cannot say where the headless shell is", () => {
124
+ expect(isChromiumBundleComplete(chromium, null)).toBe(true);
125
+ });
126
+
127
+ it("reads browsers.json from the installed Playwright", () => {
128
+ const json = readPlaywrightBrowsersJson();
129
+ expect(json?.browsers?.some((browser) => browser.name === "chromium")).toBe(true);
130
+ });
131
+ });
@@ -27,6 +27,88 @@ export function resolvePlaywrightCli(): string | null {
27
27
  }
28
28
  }
29
29
 
30
+ /** Playwright writes this file into a browser's folder as the very last step of installing it. */
31
+ const INSTALL_COMPLETE_MARKER = "INSTALLATION_COMPLETE";
32
+
33
+ /** Playwright keeps each browser in its own folder, such as `chromium-1228` or `chromium_headless_shell-1228`. */
34
+ const PLAYWRIGHT_BROWSER_DIRECTORY = /^chromium(_headless_shell)?-\d+$/;
35
+
36
+ /**
37
+ * The browser folder that contains `executablePath`, or null when the executable does not sit
38
+ * in a Playwright-style folder (for example a Chrome the operator pointed to).
39
+ */
40
+ export function playwrightBrowserDirectory(executablePath: string): string | null {
41
+ let dir = path.dirname(executablePath);
42
+ while (dir !== path.dirname(dir)) {
43
+ if (PLAYWRIGHT_BROWSER_DIRECTORY.test(path.basename(dir))) return dir;
44
+ dir = path.dirname(dir);
45
+ }
46
+ return null;
47
+ }
48
+
49
+ /**
50
+ * True when the browser at `executablePath` is fully installed.
51
+ *
52
+ * The executable alone is not proof: Playwright extracts the archive file by file and writes
53
+ * the completion marker last, so an interrupted install can leave the executable behind in a
54
+ * broken browser. When the executable is in a Playwright browser folder we also require the
55
+ * marker. Anywhere else there is no marker to expect, so the executable alone is enough.
56
+ */
57
+ export function isBrowserInstallComplete(executablePath: string): boolean {
58
+ if (!fs.existsSync(executablePath)) return false;
59
+ const directory = playwrightBrowserDirectory(executablePath);
60
+ if (!directory) return true;
61
+ return hasInstallMarker(directory);
62
+ }
63
+
64
+ function hasInstallMarker(browserDirectory: string): boolean {
65
+ return fs.existsSync(path.join(browserDirectory, INSTALL_COMPLETE_MARKER));
66
+ }
67
+
68
+ /** The part of Playwright's browsers.json that this file reads. */
69
+ export interface PlaywrightBrowsersJson {
70
+ browsers?: Array<{ name: string; revision: string }>;
71
+ }
72
+
73
+ /**
74
+ * Playwright's list of browser versions (`browsers.json`), read from the same install as the `playwright`
75
+ * package. It is not in the package's exports map, so it is read as a file next to `package.json`, the same
76
+ * way the CLI entry point is found. Null when it cannot be read.
77
+ */
78
+ export function readPlaywrightBrowsersJson(): PlaywrightBrowsersJson | null {
79
+ try {
80
+ const playwrightPackage = require.resolve("playwright/package.json");
81
+ const corePackage = require.resolve("playwright-core/package.json", { paths: [path.dirname(playwrightPackage)] });
82
+ return JSON.parse(fs.readFileSync(path.join(path.dirname(corePackage), "browsers.json"), "utf8"));
83
+ } catch {
84
+ return null;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * The headless shell folder that belongs with the Chromium at `chromiumExecutable`, or null when it cannot be
90
+ * worked out (a Chromium outside a Playwright folder, or a Playwright with no headless shell).
91
+ *
92
+ * UI runs launch Chromium headless by default, and Playwright serves a headless launch from this separate
93
+ * browser, which `playwright install chromium` installs alongside Chromium.
94
+ */
95
+ export function headlessShellDirectory(chromiumExecutable: string, browsersJson: PlaywrightBrowsersJson | null): string | null {
96
+ const chromiumDirectory = playwrightBrowserDirectory(chromiumExecutable);
97
+ const shell = browsersJson?.browsers?.find((browser) => browser.name === "chromium-headless-shell");
98
+ if (!chromiumDirectory || !shell) return null;
99
+ return path.join(path.dirname(chromiumDirectory), `chromium_headless_shell-${shell.revision}`);
100
+ }
101
+
102
+ /**
103
+ * True when everything a UI run launches is fully installed: Chromium, and its headless shell when this
104
+ * Playwright has one. Each is checked for its completion marker (see `isBrowserInstallComplete`).
105
+ */
106
+ export function isChromiumBundleComplete(chromiumExecutable: string, browsersJson: PlaywrightBrowsersJson | null): boolean {
107
+ if (!isBrowserInstallComplete(chromiumExecutable)) return false;
108
+ const shellDirectory = headlessShellDirectory(chromiumExecutable, browsersJson);
109
+ return shellDirectory === null || hasInstallMarker(shellDirectory);
110
+ }
111
+
30
112
  /**
31
113
  * Asking Playwright for the executable path keeps us in step with PLAYWRIGHT_BROWSERS_PATH
32
114
  * and its per-version cache layout instead of second-guessing either.
@@ -34,7 +116,7 @@ export function resolvePlaywrightCli(): string | null {
34
116
  export async function isChromiumInstalled(): Promise<boolean> {
35
117
  try {
36
118
  const { chromium } = await import("playwright");
37
- return fs.existsSync(chromium.executablePath());
119
+ return isChromiumBundleComplete(chromium.executablePath(), readPlaywrightBrowsersJson());
38
120
  } catch {
39
121
  return false;
40
122
  }
@@ -61,7 +143,8 @@ export function ensureChromiumInstalled(): Promise<void> {
61
143
 
62
144
  /**
63
145
  * Stops a download that is still running, so shutting down mid-install does not orphan the
64
- * child process against a half-written browser cache.
146
+ * child process against a half-written browser cache. A half-written browser has no completion
147
+ * marker, so `isChromiumInstalled` reports it as missing and the next call repairs it.
65
148
  */
66
149
  export function cancelChromiumInstall(): void {
67
150
  activeInstall?.kill("SIGTERM");
@@ -3,6 +3,7 @@ import type { Browser, BrowserContext, Page, ConsoleMessage, Response, Request,
3
3
  import type { HealEvent } from "../../contracts/runtime-context.types";
4
4
  import type { HealingPolicy } from "../../contracts/testing-metadata.types";
5
5
  import type { AttachOptions, CaptureOptions, PlaywrightAdapterOptions, ViewportOptions } from "./ui.types";
6
+ import { buildTimeline, clipDurationMs, findFfmpeg, joinClips, type ClipTiming, type RunVideoTimeline, type ScenarioMark } from "./run-video";
6
7
 
7
8
  /** Storage state as returned by `BrowserContext.storageState()`. */
8
9
  export type StorageState = Awaited<ReturnType<BrowserContext["storageState"]>>;
@@ -71,8 +72,11 @@ export class PlaywrightAdapter {
71
72
  * finalized bytes.
72
73
  */
73
74
  private videoDir?: string;
74
- private videoSegments: Video[] = [];
75
+ private videoSegments: Array<{ video: Video; startedAt: number; endedAt: number }> = [];
76
+ private segmentStartedAt = 0;
77
+ private scenarioMarks: ScenarioMark[] = [];
75
78
  private runVideos: FailureArtifact[] = [];
79
+ private runVideoTimeline?: RunVideoTimeline;
76
80
  private readonly requestStartedAt = new Map<Request, number>();
77
81
 
78
82
  constructor(opts?: PlaywrightAdapterOptions) {
@@ -162,12 +166,13 @@ export class PlaywrightAdapter {
162
166
  this.context.setDefaultTimeout(this.defaultTimeoutMs);
163
167
  this.context.setDefaultNavigationTimeout(this.navigationTimeoutMs);
164
168
  this.page = await this.context.newPage();
169
+ this.segmentStartedAt = Date.now();
165
170
  this.attachCaptureListeners(this.page);
166
171
  }
167
172
 
168
173
  private async closeContext(): Promise<void> {
169
174
  const video = this.videoDir ? this.page?.video() : undefined;
170
- if (video) this.videoSegments.push(video);
175
+ if (video) this.videoSegments.push({ video, startedAt: this.segmentStartedAt, endedAt: Date.now() });
171
176
  try {
172
177
  if (this.context) {
173
178
  await this.context.close();
@@ -203,11 +208,21 @@ export class PlaywrightAdapter {
203
208
  return this.runVideos[0];
204
209
  }
205
210
 
206
- /** Every whole-run video segment (one per browser context), after {@link stop}. */
211
+ /** Every whole-run video file, after {@link stop}: one, unless clips could not be joined (no ffmpeg). */
207
212
  getRunVideos(): FailureArtifact[] {
208
213
  return [...this.runVideos];
209
214
  }
210
215
 
216
+ /** Where each scenario is in the run video, after {@link stop} kept it. */
217
+ getRunVideoTimeline(): RunVideoTimeline | undefined {
218
+ return this.runVideoTimeline;
219
+ }
220
+
221
+ /** Note when a scenario attempt ran, so the run video can show where it is. Only while recording. */
222
+ recordScenario(mark: ScenarioMark): void {
223
+ if (this.videoDir) this.scenarioMarks.push(mark);
224
+ }
225
+
211
226
  /**
212
227
  * Wire console/network listeners once per page. Events accumulate in the per-scenario
213
228
  * buffers and are only surfaced (via {@link collectFailureArtifacts}) when a scenario
@@ -349,13 +364,8 @@ export class PlaywrightAdapter {
349
364
  const fs = await import('fs');
350
365
  // Only read the recording into memory when the caller wants to keep it (i.e. the
351
366
  // run FAILED). Passing runs discard the webm unread — no wasted IO/memory.
352
- if (keepVideo) {
353
- const single = this.videoSegments.length === 1;
354
- for (const [i, video] of this.videoSegments.entries()) {
355
- const data = await fs.promises.readFile(await video.path());
356
- const name = single ? 'run.webm' : `run-${i + 1}.webm`;
357
- this.runVideos.push({ name, contentType: 'video/webm', data });
358
- }
367
+ if (keepVideo && this.videoSegments.length) {
368
+ await this.keepRunVideo(this.videoDir);
359
369
  }
360
370
  // Clean up the temp recording directory either way.
361
371
  await fs.promises.rm(this.videoDir, { recursive: true, force: true }).catch(() => {});
@@ -364,6 +374,7 @@ export class PlaywrightAdapter {
364
374
  } finally {
365
375
  this.videoDir = undefined;
366
376
  this.videoSegments = [];
377
+ this.scenarioMarks = [];
367
378
  }
368
379
  }
369
380
 
@@ -376,6 +387,33 @@ export class PlaywrightAdapter {
376
387
  }
377
388
  }
378
389
 
390
+ /**
391
+ * Read the run's recording into {@link runVideos} as one `run.webm` (clips joined with ffmpeg when the run opened
392
+ * several contexts) and work out where each scenario is in it. Without ffmpeg several clips stay `run-<n>.webm`.
393
+ */
394
+ private async keepRunVideo(dir: string): Promise<void> {
395
+ const fs = await import('fs');
396
+ const path = await import('path');
397
+ const files = await Promise.all(this.videoSegments.map((s) => s.video.path()));
398
+ const ffmpeg = await findFfmpeg();
399
+ const clips: ClipTiming[] = [];
400
+ for (const [i, s] of this.videoSegments.entries()) {
401
+ const measured = ffmpeg ? await clipDurationMs(ffmpeg, files[i]) : undefined;
402
+ clips.push({ startedAt: s.startedAt, endedAt: s.endedAt, durationMs: measured ?? s.endedAt - s.startedAt });
403
+ }
404
+
405
+ let joined: string | undefined = files.length === 1 ? files[0] : undefined;
406
+ if (!joined && ffmpeg) {
407
+ const out = path.join(dir, 'run-joined.webm');
408
+ if (await joinClips(ffmpeg, files, path.join(dir, 'clips.txt'), out)) joined = out;
409
+ }
410
+ const names = joined ? ['run.webm'] : files.map((_, i) => `run-${i + 1}.webm`);
411
+ for (const [i, file] of (joined ? [joined] : files).entries()) {
412
+ this.runVideos.push({ name: names[i], contentType: 'video/webm', data: await fs.promises.readFile(file) });
413
+ }
414
+ this.runVideoTimeline = buildTimeline(clips, names, this.scenarioMarks, !!joined);
415
+ }
416
+
379
417
  /**
380
418
  * Multi-tab support. The onboarding flow needs a second site (the BI OTP portal)
381
419
  * open at the same time as the in-progress SPA, without destroying it. Opening a
@@ -0,0 +1,72 @@
1
+ import { buildTimeline, parseDurationMs, videoPosition, type ClipTiming, type ScenarioMark } from "./run-video";
2
+
3
+ // Two contexts as Playwright records them: each clip is a little shorter than its page was open,
4
+ // because recording starts a moment after the page opens.
5
+ const CLIPS: ClipTiming[] = [
6
+ { startedAt: 1_000, endedAt: 3_650, durationMs: 2_440 },
7
+ { startedAt: 3_700, endedAt: 7_870, durationMs: 3_920 },
8
+ ];
9
+
10
+ const mark = (scenarioId: string, startedAt: number, endedAt: number, ok = true, attempt = 1): ScenarioMark => ({
11
+ scenarioId,
12
+ attempt,
13
+ ok,
14
+ startedAt,
15
+ endedAt,
16
+ });
17
+
18
+ describe("run video timeline", () => {
19
+ it("measures a time back from the end of its clip", () => {
20
+ expect(videoPosition(CLIPS, 3_650)).toEqual({ clip: 0, ms: 2_440 });
21
+ expect(videoPosition(CLIPS, 2_650)).toEqual({ clip: 0, ms: 1_440 });
22
+ // The moment the page opened is before the recording started: clamp to 0.
23
+ expect(videoPosition(CLIPS, 1_000)).toEqual({ clip: 0, ms: 0 });
24
+ });
25
+
26
+ it("puts a time between two clips at the start of the next", () => {
27
+ expect(videoPosition(CLIPS, 3_680)).toEqual({ clip: 1, ms: 0 });
28
+ expect(videoPosition(CLIPS, 9_000)).toEqual({ clip: 1, ms: 3_920 });
29
+ });
30
+
31
+ it("gives every scenario its place in the joined file", () => {
32
+ const timeline = buildTimeline(CLIPS, ["run.webm"], [
33
+ mark("login", 1_100, 3_600),
34
+ mark("tasks-list", 4_000, 5_000),
35
+ mark("task-create", 5_000, 7_800, false),
36
+ ], true);
37
+
38
+ expect(timeline.oneFile).toBe(true);
39
+ expect(timeline.clips).toEqual([{ name: "run.webm", durationMs: 6_360 }]);
40
+ expect(timeline.scenarios).toEqual([
41
+ { scenarioId: "login", attempt: 1, ok: true, clip: 0, startMs: 0, endMs: 2_390 },
42
+ // Second clip starts at 2440 in the joined file.
43
+ { scenarioId: "tasks-list", attempt: 1, ok: true, clip: 0, startMs: 2_440 + 50, endMs: 2_440 + 1_050 },
44
+ { scenarioId: "task-create", attempt: 1, ok: false, clip: 0, startMs: 2_440 + 1_050, endMs: 2_440 + 3_850 },
45
+ ]);
46
+ });
47
+
48
+ it("keeps clip-relative times when the clips stay separate", () => {
49
+ const timeline = buildTimeline(CLIPS, ["run-1.webm", "run-2.webm"], [mark("tasks-list", 4_000, 5_000)], false);
50
+ expect(timeline.oneFile).toBe(false);
51
+ expect(timeline.clips).toEqual([
52
+ { name: "run-1.webm", durationMs: 2_440 },
53
+ { name: "run-2.webm", durationMs: 3_920 },
54
+ ]);
55
+ expect(timeline.scenarios).toEqual([{ scenarioId: "tasks-list", attempt: 1, ok: true, clip: 1, startMs: 50, endMs: 1_050 }]);
56
+ });
57
+
58
+ it("leaves out scenarios that ran while nothing was recording, and keeps retries apart", () => {
59
+ const timeline = buildTimeline(CLIPS, ["run.webm"], [
60
+ mark("api-health", 100, 900),
61
+ mark("flaky", 4_000, 4_500, false, 1),
62
+ mark("flaky", 4_500, 5_000, true, 2),
63
+ ], true);
64
+ expect(timeline.scenarios.map((s) => `${s.scenarioId}#${s.attempt}:${s.ok}`)).toEqual(["flaky#1:false", "flaky#2:true"]);
65
+ });
66
+
67
+ it("reads ffmpeg's duration line", () => {
68
+ expect(parseDurationMs(" Duration: 00:00:06.36, start: 0.000000, bitrate: 19 kb/s")).toBe(6_360);
69
+ expect(parseDurationMs(" Duration: 01:02:03.50, start: 0")).toBe(3_723_500);
70
+ expect(parseDurationMs("Duration: N/A")).toBeUndefined();
71
+ });
72
+ });