@speedkit/cli 4.44.0-beta.3 → 4.44.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.
Files changed (189) hide show
  1. package/CHANGELOG.md +38 -8
  2. package/README.md +68 -42
  3. package/dist/base/sk-command.d.ts +7 -0
  4. package/dist/base/sk-command.js +19 -0
  5. package/dist/commands/deploy.d.ts +1 -0
  6. package/dist/commands/deploy.js +5 -1
  7. package/dist/commands/diff.d.ts +47 -0
  8. package/dist/commands/diff.js +67 -0
  9. package/dist/commands/generate-pop-config.js +3 -7
  10. package/dist/helpers/race.js +4 -2
  11. package/dist/helpers/spec/race.spec.js +31 -0
  12. package/dist/models/files.d.ts +0 -1
  13. package/dist/models/files.js +0 -1
  14. package/dist/services/browser-fetch/browser-origin-fetch.js +1 -1
  15. package/dist/services/browser-fetch/browser-origin-fetcher.d.ts +1 -7
  16. package/dist/services/browser-fetch/browser-origin-fetcher.js +3 -26
  17. package/dist/services/bundler/bundle-service-factory.d.ts +0 -3
  18. package/dist/services/bundler/bundle-service-factory.js +1 -5
  19. package/dist/services/bundler/bundle-service.d.ts +1 -10
  20. package/dist/services/bundler/bundle-service.js +1 -16
  21. package/dist/services/bundler/index.d.ts +0 -1
  22. package/dist/services/bundler/index.js +0 -1
  23. package/dist/services/cli/cli-environment.d.ts +11 -0
  24. package/dist/services/cli/cli-environment.js +37 -0
  25. package/dist/services/cli/cli-service-model.d.ts +3 -1
  26. package/dist/services/cli/cli-service.d.ts +1 -1
  27. package/dist/services/cli/cli-service.js +4 -1
  28. package/dist/services/cli/spec/cli-environment.spec.js +30 -1
  29. package/dist/services/deploy/checks/activation/customer-approval-check.js +1 -1
  30. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.d.ts +2 -2
  31. package/dist/services/deploy/checks/post-deploy/refresh-deployment-job-check.js +8 -7
  32. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.d.ts +2 -2
  33. package/dist/services/deploy/checks/post-deploy/revalidated-module-check.js +11 -7
  34. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +2 -2
  35. package/dist/services/deploy/checks/post-deploy/save-files-check.js +3 -2
  36. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +3 -2
  37. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +3 -2
  38. package/dist/services/deploy/deploy-service-build-context.d.ts +2 -0
  39. package/dist/services/deploy/deploy-service-build-context.js +13 -2
  40. package/dist/services/deploy/deploy-service-factory.js +2 -9
  41. package/dist/services/deploy/deploy-service-model.d.ts +11 -1
  42. package/dist/services/deploy/deploy-service.d.ts +2 -0
  43. package/dist/services/deploy/deploy-service.js +26 -1
  44. package/dist/services/deploy/handler/customer-config-handler.d.ts +2 -2
  45. package/dist/services/deploy/handler/install-resource-handler.d.ts +2 -2
  46. package/dist/services/deploy/handler/install-resource-handler.js +6 -3
  47. package/dist/services/deploy/handler/module-handler.d.ts +2 -2
  48. package/dist/services/deploy/handler/module-handler.js +2 -2
  49. package/dist/services/deploy/handler/server-config-handler.d.ts +2 -2
  50. package/dist/services/deploy/handler/server-config-handler.js +2 -2
  51. package/dist/services/deploy/mr/live-state-check.d.ts +2 -2
  52. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +2 -7
  53. package/dist/services/deploy/policy/deploy-policy-model.d.ts +1 -5
  54. package/dist/services/deploy/policy/deploy-policy-model.js +0 -4
  55. package/dist/services/deploy/policy/index.d.ts +1 -0
  56. package/dist/services/deploy/policy/index.js +1 -0
  57. package/dist/services/deploy/policy/testing-deploy-policy.d.ts +16 -0
  58. package/dist/services/deploy/policy/testing-deploy-policy.js +42 -0
  59. package/dist/services/deploy/spec/checks/post-deploy/refresh-deployment-job-check.spec.js +5 -12
  60. package/dist/services/deploy/spec/deploy-service.spec.js +64 -0
  61. package/dist/services/deploy/spec/handler/install-resource-handler.spec.js +58 -0
  62. package/dist/services/deploy/spec/mr/live-state-check.spec.js +2 -2
  63. package/dist/services/deploy/spec/policy/auto-deploy-policy.spec.js +0 -2
  64. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.d.ts +1 -0
  65. package/dist/services/deploy/spec/policy/testing-deploy-policy.spec.js +46 -0
  66. package/dist/services/diff/create-diff-engine.d.ts +14 -0
  67. package/dist/services/diff/create-diff-engine.js +42 -0
  68. package/dist/services/diff/customer-origin.d.ts +9 -0
  69. package/dist/services/diff/customer-origin.js +19 -0
  70. package/dist/services/diff/diff-engine.d.ts +30 -0
  71. package/dist/services/diff/diff-engine.js +49 -0
  72. package/dist/services/diff/diff-log.d.ts +9 -0
  73. package/dist/services/diff/diff-log.js +18 -0
  74. package/dist/services/diff/diff-model.d.ts +68 -0
  75. package/dist/services/diff/diff-model.js +1 -0
  76. package/dist/services/diff/diff-service-build-context.d.ts +99 -9
  77. package/dist/services/diff/diff-service-build-context.js +299 -1
  78. package/dist/services/diff/diff-service-factory.d.ts +24 -2
  79. package/dist/services/diff/diff-service-factory.js +165 -3
  80. package/dist/services/diff/diff-service.d.ts +93 -33
  81. package/dist/services/diff/diff-service.js +274 -140
  82. package/dist/services/diff/index.d.ts +12 -1
  83. package/dist/services/diff/index.js +12 -1
  84. package/dist/services/diff/noise-baseline.d.ts +28 -0
  85. package/dist/services/diff/noise-baseline.js +105 -0
  86. package/dist/services/diff/page-source.d.ts +42 -0
  87. package/dist/services/diff/page-source.js +93 -0
  88. package/dist/services/diff/side-failure.d.ts +28 -0
  89. package/dist/services/diff/side-failure.js +100 -0
  90. package/dist/services/diff/sinks/json-diff-sink.d.ts +32 -0
  91. package/dist/services/diff/sinks/json-diff-sink.js +44 -0
  92. package/dist/services/diff/sinks/no-diff-sink.d.ts +5 -0
  93. package/dist/services/diff/sinks/no-diff-sink.js +6 -0
  94. package/dist/services/diff/sinks/patch-diff-sink.d.ts +19 -0
  95. package/dist/services/diff/sinks/patch-diff-sink.js +29 -0
  96. package/dist/services/diff/sinks/tool-diff-sink.d.ts +26 -0
  97. package/dist/services/diff/sinks/tool-diff-sink.js +88 -0
  98. package/dist/services/diff/sinks/unified-patch.d.ts +7 -0
  99. package/dist/services/diff/sinks/unified-patch.js +12 -0
  100. package/dist/services/diff/spec/customer-origin.spec.d.ts +1 -0
  101. package/dist/services/diff/spec/customer-origin.spec.js +27 -0
  102. package/dist/services/diff/spec/diff-engine.spec.d.ts +1 -0
  103. package/dist/services/diff/spec/diff-engine.spec.js +47 -0
  104. package/dist/services/diff/spec/diff-service-build-context.spec.d.ts +1 -0
  105. package/dist/services/diff/spec/diff-service-build-context.spec.js +185 -0
  106. package/dist/services/diff/spec/diff-service.spec.d.ts +1 -0
  107. package/dist/services/diff/spec/diff-service.spec.js +393 -0
  108. package/dist/services/diff/spec/noise-baseline.spec.d.ts +1 -0
  109. package/dist/services/diff/spec/noise-baseline.spec.js +95 -0
  110. package/dist/services/diff/spec/page-source.spec.d.ts +1 -0
  111. package/dist/services/diff/spec/page-source.spec.js +140 -0
  112. package/dist/services/diff/spec/sinks/json-diff-sink.spec.d.ts +1 -0
  113. package/dist/services/diff/spec/sinks/json-diff-sink.spec.js +72 -0
  114. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.d.ts +1 -0
  115. package/dist/services/diff/spec/sinks/patch-diff-sink.spec.js +47 -0
  116. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.d.ts +1 -0
  117. package/dist/services/diff/spec/sinks/tool-diff-sink.spec.js +61 -0
  118. package/dist/services/document-handler-runtime/document-handler-abort.d.ts +2 -0
  119. package/dist/services/document-handler-runtime/document-handler-abort.js +2 -0
  120. package/dist/services/document-handler-runtime/document-handler-server.d.ts +0 -17
  121. package/dist/services/document-handler-runtime/document-handler-server.js +19 -81
  122. package/dist/services/document-handler-runtime/runtime-files.d.ts +9 -0
  123. package/dist/services/document-handler-runtime/runtime-files.js +17 -0
  124. package/dist/services/integration-api/integration-api-model.d.ts +1 -2
  125. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +8 -68
  126. package/dist/services/integration-api/struct/customer-config.d.ts +1 -32
  127. package/dist/services/integration-api/struct/customer-config.js +3 -33
  128. package/dist/services/integration-api/struct/speed-kit-config-file.d.ts +4 -9
  129. package/dist/services/integration-api/struct/speed-kit-config-file.js +10 -27
  130. package/dist/services/onboarding/config-renderer/speed-kit-install-context.js +8 -20
  131. package/dist/services/onboarding/dashboard/diff-against-current-page.d.ts +29 -7
  132. package/dist/services/onboarding/dashboard/diff-against-current-page.js +24 -37
  133. package/dist/services/onboarding/dashboard/index.js +13 -6
  134. package/dist/services/onboarding/dashboard/request-diff-service.d.ts +21 -8
  135. package/dist/services/onboarding/dashboard/request-diff-service.js +21 -49
  136. package/dist/services/onboarding/onboarding-model.d.ts +0 -1
  137. package/dist/services/onboarding/onboarding-model.js +0 -1
  138. package/dist/services/onboarding/onboarding-service-factory.d.ts +0 -1
  139. package/dist/services/onboarding/onboarding-service-factory.js +24 -30
  140. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.d.ts +1 -0
  141. package/dist/services/onboarding/spec/dashboard/request-diff-service.spec.js +57 -0
  142. package/dist/services/onboarding/templates/install-speed-kit-js-template.js +0 -5
  143. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +3 -3
  144. package/dist/services/onboarding/virtual-orestes-app/index.js +5 -5
  145. package/dist/services/origin-request/index.d.ts +3 -0
  146. package/dist/services/origin-request/index.js +3 -0
  147. package/dist/services/origin-request/origin-fetcher.d.ts +52 -0
  148. package/dist/services/origin-request/origin-fetcher.js +93 -0
  149. package/dist/services/origin-request/origin-request-service-factory.js +19 -1
  150. package/dist/services/origin-request/origin-request-service.d.ts +6 -10
  151. package/dist/services/origin-request/origin-request-service.js +28 -70
  152. package/dist/services/origin-request/runtime-config-source.d.ts +36 -0
  153. package/dist/services/origin-request/runtime-config-source.js +59 -0
  154. package/dist/services/origin-request/spec/origin-error-cause.spec.d.ts +1 -0
  155. package/dist/services/{onboarding/spec/virtual-orestes-app → origin-request/spec}/origin-error-cause.spec.js +1 -1
  156. package/dist/services/origin-request/spec/origin-fetcher.spec.d.ts +1 -0
  157. package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.js → origin-request/spec/origin-fetcher.spec.js} +46 -15
  158. package/dist/services/prewarm/assets/asset-api-client.d.ts +6 -0
  159. package/dist/services/prewarm/assets/asset-api-client.js +6 -1
  160. package/dist/services/prewarm/pre-warm-service.d.ts +10 -0
  161. package/dist/services/prewarm/pre-warm-service.js +17 -0
  162. package/dist/services/prewarm/spec/pre-warm-service.spec.d.ts +1 -0
  163. package/dist/services/prewarm/spec/pre-warm-service.spec.js +72 -0
  164. package/dist/services/query-builder/query-builder-factory.js +3 -3
  165. package/dist/services/setup/os/tool-registry.d.ts +1 -1
  166. package/oclif.manifest.json +294 -162
  167. package/package.json +1 -2
  168. package/dist/commands/diff-url-parameters.d.ts +0 -19
  169. package/dist/commands/diff-url-parameters.js +0 -121
  170. package/dist/services/bundler/error/packjockel-error.d.ts +0 -3
  171. package/dist/services/bundler/error/packjockel-error.js +0 -3
  172. package/dist/services/bundler/packjockel-service.d.ts +0 -72
  173. package/dist/services/bundler/packjockel-service.js +0 -156
  174. package/dist/services/bundler/spec/packjockel-service.spec.js +0 -143
  175. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +0 -15
  176. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +0 -70
  177. package/dist/services/deploy/error/check-module-file-error.d.ts +0 -4
  178. package/dist/services/deploy/error/check-module-file-error.js +0 -4
  179. package/dist/services/deploy/error/post-deploy-deployment-detection-error.d.ts +0 -4
  180. package/dist/services/deploy/error/post-deploy-deployment-detection-error.js +0 -4
  181. package/dist/services/onboarding/server-config/index.d.ts +0 -10
  182. package/dist/services/onboarding/server-config/index.js +0 -27
  183. package/dist/services/onboarding/virtual-orestes-app/crawler.d.ts +0 -31
  184. package/dist/services/onboarding/virtual-orestes-app/crawler.js +0 -98
  185. /package/dist/{services/bundler/spec/packjockel-service.spec.d.ts → helpers/spec/race.spec.d.ts} +0 -0
  186. /package/dist/services/{onboarding/spec/virtual-orestes-app/crawler.spec.d.ts → deploy/spec/deploy-service.spec.d.ts} +0 -0
  187. /package/dist/services/{onboarding/spec/virtual-orestes-app/origin-error-cause.spec.d.ts → deploy/spec/handler/install-resource-handler.spec.d.ts} +0 -0
  188. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.d.ts +0 -0
  189. /package/dist/services/{onboarding/virtual-orestes-app → origin-request}/origin-error-cause.js +0 -0
@@ -1,5 +1,5 @@
1
1
  import DeployHandlerInterface from "../interface/deploy-handler-interface.js";
2
- import { DiffService } from "../../diff/index.js";
2
+ import { DiffEngine } from "../../diff/index.js";
3
3
  import { CliServiceInterface } from "../../cli/index.js";
4
4
  import { FILE_TYPE, ServerConfigFile } from "../../integration-api/index.js";
5
5
  import { ConfigApiService } from "../../config-api/index.js";
@@ -9,7 +9,7 @@ export default class ServerConfigHandler implements DeployHandlerInterface {
9
9
  private diffService;
10
10
  private cli;
11
11
  private policy;
12
- constructor(configApi: ConfigApiService, diffService: DiffService, cli: CliServiceInterface, policy: DeployPolicyInterface);
12
+ constructor(configApi: ConfigApiService, diffService: DiffEngine, cli: CliServiceInterface, policy: DeployPolicyInterface);
13
13
  canHandle(type: FILE_TYPE): boolean;
14
14
  handle(files: ServerConfigFile[]): Promise<void>;
15
15
  upload(files: ServerConfigFile[]): Promise<void>;
@@ -27,9 +27,9 @@ export default class ServerConfigHandler {
27
27
  const remoteConfig = JSON.parse(remote);
28
28
  // @ts-expect-error revision is unknown
29
29
  file.config.revision.version = remoteConfig.revision.version;
30
- const { updatedFile, diff } = await this.diffService.diffContent(file.name, remote, file.getContent());
30
+ const { updatedFile, equal } = await this.diffService.diffContent(file.name, remote, file.getContent());
31
31
  file.setContent(updatedFile);
32
- if (diff) {
32
+ if (equal) {
33
33
  this.cli.writeWarning(`skipped ${file.name} (identical with remote)`);
34
34
  file.skipFile();
35
35
  return;
@@ -1,4 +1,4 @@
1
- import { DiffService } from "../../diff/index.js";
1
+ import { DiffEngine } from "../../diff/index.js";
2
2
  import { FileListInterface } from "../../integration-api/index.js";
3
3
  import Install from "../interface/install.js";
4
4
  /** How the live installation relates to the merge request. */
@@ -27,7 +27,7 @@ export interface LiveStateResult {
27
27
  */
28
28
  export declare class LiveStateCheck {
29
29
  private readonly diff;
30
- constructor(diff: DiffService);
30
+ constructor(diff: DiffEngine);
31
31
  compare(base: FileListInterface, local: FileListInterface, install: Install | null): LiveStateResult;
32
32
  /** Whether the merge request changes anything this deploy would upload. */
33
33
  isUnchanged(base: FileListInterface, local: FileListInterface): boolean;
@@ -1,5 +1,5 @@
1
1
  import { BundleServiceFactory } from "../../bundler/index.js";
2
- import { DiffServiceBuildContext, DiffServiceFactory, } from "../../diff/index.js";
2
+ import { createDiffEngine } from "../../diff/index.js";
3
3
  import { GitRepository } from "../../git/index.js";
4
4
  import { IntegrationApiServiceBuildContext, IntegrationApiFactory, } from "../../integration-api/index.js";
5
5
  import { CustomerApprovalCheck } from "../checks/activation/customer-approval-check.js";
@@ -50,12 +50,7 @@ export class MergeRequestDeployServiceFactory {
50
50
  const deployService = await deployFactory.buildService();
51
51
  // A deploy that runs without a person never opens a diff tool, so the
52
52
  // comparison only tells whether two contents are equal.
53
- const diffService = new DiffServiceFactory(new DiffServiceBuildContext({
54
- environment: this.context.environment,
55
- executablePath: null,
56
- executableTemplate: null,
57
- opensDiffTool: false,
58
- })).getService();
53
+ const diffService = createDiffEngine(this.context.environment, "none");
59
54
  this.service = new MergeRequestDeployService(this.context, request, repository, new BaseConfigReader(repository, (directory, configName) => new IntegrationApiFactory(new IntegrationApiServiceBuildContext({
60
55
  environment: this.context.environment,
61
56
  basePath: directory,
@@ -32,11 +32,7 @@ export declare enum DeployQuestion {
32
32
  /** Deploy although the device detection changes. */
33
33
  DeviceDetectionChange = "deviceDetectionChange",
34
34
  /** Write the content taken over from the installation to the local files. */
35
- SaveLocalFiles = "saveLocalFiles",
36
- /** Delete the job of the deprecated deployment detection. */
37
- DeleteDeprecatedJob = "deleteDeprecatedJob",
38
- /** Delete the module of the deprecated deployment detection. */
39
- DeleteDeprecatedModule = "deleteDeprecatedModule"
35
+ SaveLocalFiles = "saveLocalFiles"
40
36
  }
41
37
  export interface DeployPolicyInterface {
42
38
  /**
@@ -34,8 +34,4 @@ export var DeployQuestion;
34
34
  DeployQuestion["DeviceDetectionChange"] = "deviceDetectionChange";
35
35
  /** Write the content taken over from the installation to the local files. */
36
36
  DeployQuestion["SaveLocalFiles"] = "saveLocalFiles";
37
- /** Delete the job of the deprecated deployment detection. */
38
- DeployQuestion["DeleteDeprecatedJob"] = "deleteDeprecatedJob";
39
- /** Delete the module of the deprecated deployment detection. */
40
- DeployQuestion["DeleteDeprecatedModule"] = "deleteDeprecatedModule";
41
37
  })(DeployQuestion || (DeployQuestion = {}));
@@ -1,2 +1,3 @@
1
1
  export * from "./deploy-policy-model.js";
2
2
  export * from "./interactive-deploy-policy.js";
3
+ export * from "./testing-deploy-policy.js";
@@ -1,2 +1,3 @@
1
1
  export * from "./deploy-policy-model.js";
2
2
  export * from "./interactive-deploy-policy.js";
3
+ export * from "./testing-deploy-policy.js";
@@ -0,0 +1,16 @@
1
+ import { DeployPolicyInterface, DeployQuestion } from "./deploy-policy-model.js";
2
+ /**
3
+ * The policy of `sk deploy --testing`: the local config becomes a testing
4
+ * installation, and nothing else.
5
+ *
6
+ * It answers yes to everything that shapes the new installation, because that
7
+ * installation reaches no visitor without the debug parameter. It answers no
8
+ * to both ways into a regular activation, so the live installation stays as it
9
+ * is. This is what makes the deploy safe to run from a branch.
10
+ */
11
+ export declare class TestingDeployPolicy implements DeployPolicyInterface {
12
+ private readonly description;
13
+ constructor(description: string);
14
+ confirm(question: DeployQuestion): Promise<boolean>;
15
+ text(question: DeployQuestion): Promise<string>;
16
+ }
@@ -0,0 +1,42 @@
1
+ import { DeployQuestion, } from "./deploy-policy-model.js";
2
+ /**
3
+ * The policy of `sk deploy --testing`: the local config becomes a testing
4
+ * installation, and nothing else.
5
+ *
6
+ * It answers yes to everything that shapes the new installation, because that
7
+ * installation reaches no visitor without the debug parameter. It answers no
8
+ * to both ways into a regular activation, so the live installation stays as it
9
+ * is. This is what makes the deploy safe to run from a branch.
10
+ */
11
+ export class TestingDeployPolicy {
12
+ description;
13
+ constructor(description) {
14
+ this.description = description;
15
+ }
16
+ async confirm(question) {
17
+ switch (question) {
18
+ // The content of the new installation.
19
+ case DeployQuestion.UpdateFile:
20
+ case DeployQuestion.UpdateOrigins:
21
+ case DeployQuestion.CreateConfig:
22
+ case DeployQuestion.DeleteInstallResourceKey:
23
+ case DeployQuestion.UploadInstallResource:
24
+ case DeployQuestion.ActivateAsTesting: {
25
+ return true;
26
+ }
27
+ // These guard a change to live traffic, which this deploy never makes.
28
+ case DeployQuestion.SplitChange:
29
+ case DeployQuestion.DeviceDetectionChange: {
30
+ return true;
31
+ }
32
+ // Activate and CustomerApproval lead to live traffic. The modules, the
33
+ // server config and the local files are no part of an installation.
34
+ default: {
35
+ return false;
36
+ }
37
+ }
38
+ }
39
+ async text(question) {
40
+ return question === DeployQuestion.Description ? this.description : "";
41
+ }
42
+ }
@@ -1,7 +1,6 @@
1
1
  import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
3
  import { RefreshDeploymentJobCheck } from "../../../checks/post-deploy/refresh-deployment-job-check.js";
4
- import ApplicationError from "../../../../error-handling/error/application-error.js";
5
4
  function entityManagerWithJobs(names) {
6
5
  const jobs = names.map((name) => ({ data: { name }, type: "Refreshjob" }));
7
6
  return {
@@ -12,22 +11,16 @@ function entityManagerWithJobs(names) {
12
11
  }
13
12
  const cli = { writeWarning: () => undefined };
14
13
  async function runCheck(names) {
15
- try {
16
- await new RefreshDeploymentJobCheck(entityManagerWithJobs(names), cli).check();
17
- }
18
- catch (error) {
19
- return error;
20
- }
21
- return undefined;
14
+ return new RefreshDeploymentJobCheck(entityManagerWithJobs(names), cli).check();
22
15
  }
23
16
  describe("RefreshDeploymentJobCheck", () => {
24
17
  it("accepts jobs whose names carry a suffix", async () => {
25
18
  // As used by zeg and tectake.
26
- expect(await runCheck(["HTML", "Landing Page (RegExp)", "CSS, JS, Font"])).to.equal(undefined);
19
+ expect(await runCheck(["HTML", "Landing Page (RegExp)", "CSS, JS, Font"])).to.deep.equal({ success: true });
27
20
  });
28
21
  it("reports jobs that are missing entirely", async () => {
29
- const error = await runCheck(["HTML", "Images"]);
30
- expect(error).to.be.instanceOf(ApplicationError);
31
- expect(error.suggestions[0]).to.equal("Missing required jobs: Landing Page, CSS, JS, Font");
22
+ const result = await runCheck(["HTML", "Images"]);
23
+ expect(result.success).to.equal(false);
24
+ expect(result.error).to.equal("Missing required jobs: Landing Page, CSS, JS, Font");
32
25
  });
33
26
  });
@@ -0,0 +1,64 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import DeployService from "../deploy-service.js";
4
+ const fileList = {
5
+ filter: () => undefined,
6
+ getTypes: () => [],
7
+ getCustomerConfig: () => ({ config: { app: "app", name: "production" } }),
8
+ };
9
+ function recordingCli(warnings) {
10
+ return {
11
+ spacer: () => undefined,
12
+ write: () => undefined,
13
+ comment: () => undefined,
14
+ writeWarning: (message) => warnings.push(message),
15
+ };
16
+ }
17
+ function check(run) {
18
+ return { check: run };
19
+ }
20
+ function deploy(warnings, postDeployChecks) {
21
+ return new DeployService(fileList, [], recordingCli(warnings), [], postDeployChecks).run();
22
+ }
23
+ describe("DeployService", () => {
24
+ it("runs every post-deploy check and reports the failed ones after", async () => {
25
+ const warnings = [];
26
+ let laterCheckRan = false;
27
+ await deploy(warnings, [
28
+ check(async () => ({
29
+ success: false,
30
+ error: "Missing required jobs: HTML",
31
+ suggestions: ["create them", "or not"],
32
+ })),
33
+ check(async () => {
34
+ laterCheckRan = true;
35
+ return { success: true };
36
+ }),
37
+ ]);
38
+ expect(laterCheckRan).to.equal(true);
39
+ expect(warnings).to.deep.equal([
40
+ "1 post-deploy check(s) failed:",
41
+ "› Missing required jobs: HTML\n Try this:\n * create them\n * or not",
42
+ ]);
43
+ });
44
+ it("stays quiet when every post-deploy check passes", async () => {
45
+ const warnings = [];
46
+ await deploy(warnings, [check(async () => ({ success: true }))]);
47
+ expect(warnings).to.deep.equal([]);
48
+ });
49
+ it("lets an error thrown by a post-deploy check fail the deploy", async () => {
50
+ const failure = new Error("could not reach the app");
51
+ let laterCheckRan = false;
52
+ const error = await deploy([], [
53
+ check(async () => {
54
+ throw failure;
55
+ }),
56
+ check(async () => {
57
+ laterCheckRan = true;
58
+ return { success: true };
59
+ }),
60
+ ]).catch((e) => e);
61
+ expect(error).to.equal(failure);
62
+ expect(laterCheckRan).to.equal(false);
63
+ });
64
+ });
@@ -0,0 +1,58 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import InstallResourceBuilder from "../../builder/install-resource-builder.js";
4
+ import InstallResourceHandler from "../../handler/install-resource-handler.js";
5
+ import DeletedFileCheck from "../../handler/install-resource-modifier/deleted-file-check.js";
6
+ import { TestingDeployPolicy } from "../../policy/testing-deploy-policy.js";
7
+ const ACTIVE = { id: "/db/speedKit.Install/live", version: 3 };
8
+ const CLONE = { id: "/db/speedKit.Install/abc-123", version: 1 };
9
+ /** The app, recording every call that changes it. */
10
+ function app() {
11
+ const calls = [];
12
+ const record = (name) => async (install) => {
13
+ calls.push(name);
14
+ return install;
15
+ };
16
+ const configApi = {
17
+ getActiveInstall: async () => ACTIVE,
18
+ cloneInstall: async () => ({ ...CLONE }),
19
+ setInstall: record("setInstall"),
20
+ activateInstall: record("activateInstall"),
21
+ activateInstallTesting: record("activateInstallTesting"),
22
+ };
23
+ return { calls, configApi };
24
+ }
25
+ async function handlerFor(configApi, customer, lines) {
26
+ const cli = new Proxy({}, {
27
+ get: (_target, property) => property === "write"
28
+ ? (line) => lines.push(line)
29
+ : () => undefined,
30
+ });
31
+ const policy = new TestingDeployPolicy("branch feature/x");
32
+ const config = { origins: ["https://www.example.com"], ...customer };
33
+ // The handler of config_customer.json starts the builder from the live installation.
34
+ const builder = new InstallResourceBuilder(configApi);
35
+ await builder.init("production");
36
+ return new InstallResourceHandler(config, configApi, "production", {}, cli, builder, new DeletedFileCheck(cli, policy, true), {
37
+ // The answer of a customer who approves nothing and of one who needs no approval.
38
+ isActivationApproved: async () => !config.needsCustomerApproval,
39
+ }, policy);
40
+ }
41
+ const FILE = {
42
+ remoteKey: "config",
43
+ shouldSkipFile: () => false,
44
+ getContent: () => "speedKit = {};",
45
+ };
46
+ describe("InstallResourceHandler under the TestingDeployPolicy", () => {
47
+ for (const needsCustomerApproval of [false, true]) {
48
+ it(`activates as a testing installation only (needsCustomerApproval: ${needsCustomerApproval})`, async () => {
49
+ const { calls, configApi } = app();
50
+ const lines = [];
51
+ const handler = await handlerFor(configApi, { needsCustomerApproval }, lines);
52
+ await handler.upload([FILE]);
53
+ expect(calls).to.deep.equal(["setInstall", "activateInstallTesting"]);
54
+ expect(lines).to.include("Testing installation id: abc-123");
55
+ expect(lines).to.include(" https://www.example.com/?debugSpeedKit=abc-123");
56
+ });
57
+ }
58
+ });
@@ -1,7 +1,7 @@
1
1
  import { expect } from "chai";
2
2
  import { describe, it } from "mocha";
3
3
  import { LiveState, LiveStateCheck } from "../../mr/live-state-check.js";
4
- import { DiffService } from "../../../diff/index.js";
4
+ import { DiffEngine, NoDiffSink } from "../../../diff/index.js";
5
5
  const ORIGINS = ["https://www.example.com"];
6
6
  /** A configuration of the install resource files it holds. */
7
7
  function configuration(files, origins = ORIGINS) {
@@ -19,7 +19,7 @@ function configuration(files, origins = ORIGINS) {
19
19
  function installOf(files, origins = ORIGINS) {
20
20
  return { domain: "production", origins, ...files };
21
21
  }
22
- const check = new LiveStateCheck(new DiffService({}));
22
+ const check = new LiveStateCheck(new DiffEngine({ sink: new NoDiffSink() }));
23
23
  describe("LiveStateCheck", () => {
24
24
  it("calls the deploy reviewed while live is the state before the merge request", () => {
25
25
  const base = configuration({ config: "before" });
@@ -26,8 +26,6 @@ const NOT_IN_A_MERGE_REQUEST = [
26
26
  DeployQuestion.SplitChange,
27
27
  DeployQuestion.DeviceDetectionChange,
28
28
  DeployQuestion.SaveLocalFiles,
29
- DeployQuestion.DeleteDeprecatedJob,
30
- DeployQuestion.DeleteDeprecatedModule,
31
29
  ];
32
30
  function policy(approval) {
33
31
  return new AutoDeployPolicy("!42 a reviewed change", approval);
@@ -0,0 +1,46 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { DeployQuestion } from "../../policy/deploy-policy-model.js";
4
+ import { TestingDeployPolicy } from "../../policy/testing-deploy-policy.js";
5
+ const policy = new TestingDeployPolicy("branch feature/x");
6
+ describe("TestingDeployPolicy", () => {
7
+ for (const question of [
8
+ DeployQuestion.Activate,
9
+ DeployQuestion.CustomerApproval,
10
+ ]) {
11
+ it(`never answers yes to ${question}, the way to live traffic`, async () => {
12
+ expect(await policy.confirm(question)).to.equal(false);
13
+ });
14
+ }
15
+ for (const question of [
16
+ DeployQuestion.UpdateFile,
17
+ DeployQuestion.UpdateOrigins,
18
+ DeployQuestion.CreateConfig,
19
+ DeployQuestion.DeleteInstallResourceKey,
20
+ DeployQuestion.UploadInstallResource,
21
+ DeployQuestion.SplitChange,
22
+ DeployQuestion.DeviceDetectionChange,
23
+ DeployQuestion.ActivateAsTesting,
24
+ ]) {
25
+ it(`answers yes to ${question}`, async () => {
26
+ expect(await policy.confirm(question)).to.equal(true);
27
+ });
28
+ }
29
+ for (const question of [
30
+ DeployQuestion.UploadModules,
31
+ DeployQuestion.UploadServerConfig,
32
+ DeployQuestion.SaveLocalFiles,
33
+ ]) {
34
+ it(`answers no to ${question}, which is no part of an installation`, async () => {
35
+ expect(await policy.confirm(question)).to.equal(false);
36
+ });
37
+ }
38
+ it("answers every question of the deploy, so a new one needs a decision here", () => {
39
+ // Fails when DeployQuestion grows: decide then whether a testing deploy may answer yes.
40
+ expect(Object.values(DeployQuestion)).to.have.length(14);
41
+ });
42
+ it("gives the description, and nothing for another open question", async () => {
43
+ expect(await policy.text(DeployQuestion.Description)).to.equal("branch feature/x");
44
+ expect(await policy.text(DeployQuestion.UpdateFile)).to.equal("");
45
+ });
46
+ });
@@ -0,0 +1,14 @@
1
+ import { CliEnvironment } from "../cli/index.js";
2
+ import { DiffEngine } from "./diff-engine.js";
3
+ import { DiffOutput } from "./diff-model.js";
4
+ /**
5
+ * A diff engine that shows its results through `output`. A factory that
6
+ * wires a diff into its service calls this; the engine is no service of its
7
+ * own, because it is built from the environment alone.
8
+ */
9
+ export declare function createDiffEngine(environment: CliEnvironment, output: DiffOutput): DiffEngine;
10
+ /**
11
+ * The output when the user names none: the diff tool for a person at a
12
+ * terminal, a patch on stdout for an agent, a pipe or CI.
13
+ */
14
+ export declare function defaultDiffOutput(environment: CliEnvironment): DiffOutput;
@@ -0,0 +1,42 @@
1
+ import { DiffEngine } from "./diff-engine.js";
2
+ import { JsonDiffSink } from "./sinks/json-diff-sink.js";
3
+ import { NoDiffSink } from "./sinks/no-diff-sink.js";
4
+ import { PatchDiffSink } from "./sinks/patch-diff-sink.js";
5
+ import { ToolDiffSink } from "./sinks/tool-diff-sink.js";
6
+ /** Where the diff tool's files go, under the CLI's cache directory. */
7
+ const DIFF_FOLDER = "diff";
8
+ function createSink(environment, output) {
9
+ switch (output) {
10
+ case "tool": {
11
+ return new ToolDiffSink({
12
+ cli: environment.cli,
13
+ settings: environment.settings,
14
+ createDirectory: () => environment.createTempDirectory(DIFF_FOLDER),
15
+ });
16
+ }
17
+ case "patch": {
18
+ return new PatchDiffSink({ cli: environment.cli });
19
+ }
20
+ case "json": {
21
+ return new JsonDiffSink(environment.cli);
22
+ }
23
+ case "none": {
24
+ return new NoDiffSink();
25
+ }
26
+ }
27
+ }
28
+ /**
29
+ * A diff engine that shows its results through `output`. A factory that
30
+ * wires a diff into its service calls this; the engine is no service of its
31
+ * own, because it is built from the environment alone.
32
+ */
33
+ export function createDiffEngine(environment, output) {
34
+ return new DiffEngine({ sink: createSink(environment, output) });
35
+ }
36
+ /**
37
+ * The output when the user names none: the diff tool for a person at a
38
+ * terminal, a patch on stdout for an agent, a pipe or CI.
39
+ */
40
+ export function defaultDiffOutput(environment) {
41
+ return environment.nonInteractive ? "patch" : "tool";
42
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Refuses a page that is not on one of the customer's origins. Its
3
+ * documentHandler and runtime config are made for those origins, so another
4
+ * site rendered with them would compare nonsense.
5
+ *
6
+ * `origins` are `config_customer`'s, plain `https://host` entries; they are
7
+ * compared as `URL.origin`, so case and a default port do not matter.
8
+ */
9
+ export declare function assertCustomerOrigin(pageUrl: string, origins: readonly string[], customerPath: string): void;
@@ -0,0 +1,19 @@
1
+ import ApplicationError from "../error-handling/error/application-error.js";
2
+ /**
3
+ * Refuses a page that is not on one of the customer's origins. Its
4
+ * documentHandler and runtime config are made for those origins, so another
5
+ * site rendered with them would compare nonsense.
6
+ *
7
+ * `origins` are `config_customer`'s, plain `https://host` entries; they are
8
+ * compared as `URL.origin`, so case and a default port do not matter.
9
+ */
10
+ export function assertCustomerOrigin(pageUrl, origins, customerPath) {
11
+ const origin = new URL(pageUrl).origin;
12
+ if (origins.some((candidate) => new URL(candidate).origin === origin)) {
13
+ return;
14
+ }
15
+ throw new ApplicationError(`${origin} is not an origin of ${customerPath}.`, [
16
+ `config_customer lists: ${origins.join(", ")}`,
17
+ "Diff a page of the customer, or use --raw without the customer path.",
18
+ ]);
19
+ }
@@ -0,0 +1,30 @@
1
+ import { DiffResult, DiffSide, DiffSink, FailedComparison } from "./diff-model.js";
2
+ export interface DiffEngineDeps {
3
+ readonly sink: DiffSink;
4
+ }
5
+ /**
6
+ * Compares two contents and hands the result to a sink.
7
+ *
8
+ * Equality ignores whitespace, so reformatting alone never counts as a
9
+ * change. The sink decides what a person or an agent gets to see.
10
+ */
11
+ export declare class DiffEngine {
12
+ private readonly deps;
13
+ constructor(deps: DiffEngineDeps);
14
+ /** Whether the two contents are equal once all whitespace is removed. */
15
+ isContentEqual(left?: string, right?: string): boolean;
16
+ compare(left: DiffSide, right: DiffSide): Promise<DiffResult>;
17
+ /**
18
+ * Compares a remote content with its local counterpart, as a deploy does.
19
+ * `updatedFile` is the local content after the diff tool, which a person
20
+ * may have used to take changes over from remote.
21
+ */
22
+ diffContent(fileName: string, remoteContent: string, localContent: string): Promise<{
23
+ updatedFile: string;
24
+ equal: boolean;
25
+ }>;
26
+ /** Hands a comparison that could not be made to the sink. */
27
+ fail(comparison: FailedComparison): void;
28
+ /** Lets a sink that collects its results write them. */
29
+ finish(): void;
30
+ }
@@ -0,0 +1,49 @@
1
+ /** One line ending, so a CRLF file does not differ from its LF copy. */
2
+ function normalizeLineEndings(side) {
3
+ return { ...side, content: (side.content ?? "").replaceAll(/\r?\n/g, "\n") };
4
+ }
5
+ /**
6
+ * Compares two contents and hands the result to a sink.
7
+ *
8
+ * Equality ignores whitespace, so reformatting alone never counts as a
9
+ * change. The sink decides what a person or an agent gets to see.
10
+ */
11
+ export class DiffEngine {
12
+ deps;
13
+ constructor(deps) {
14
+ this.deps = deps;
15
+ }
16
+ /** Whether the two contents are equal once all whitespace is removed. */
17
+ isContentEqual(left = "", right = "") {
18
+ return left.replaceAll(/\s/g, "") === right.replaceAll(/\s/g, "");
19
+ }
20
+ async compare(left, right) {
21
+ const result = {
22
+ left: normalizeLineEndings(left),
23
+ right: normalizeLineEndings(right),
24
+ equal: this.isContentEqual(left.content, right.content),
25
+ };
26
+ const edited = await this.deps.sink.show(result);
27
+ if (edited === undefined) {
28
+ return result;
29
+ }
30
+ return { ...result, right: { ...result.right, content: edited } };
31
+ }
32
+ /**
33
+ * Compares a remote content with its local counterpart, as a deploy does.
34
+ * `updatedFile` is the local content after the diff tool, which a person
35
+ * may have used to take changes over from remote.
36
+ */
37
+ async diffContent(fileName, remoteContent, localContent) {
38
+ const { equal, right } = await this.compare({ label: `${fileName}-remote`, content: remoteContent }, { label: `${fileName}-local`, content: localContent });
39
+ return { updatedFile: right.content, equal };
40
+ }
41
+ /** Hands a comparison that could not be made to the sink. */
42
+ fail(comparison) {
43
+ this.deps.sink.fail?.(comparison);
44
+ }
45
+ /** Lets a sink that collects its results write them. */
46
+ finish() {
47
+ this.deps.sink.finish?.();
48
+ }
49
+ }
@@ -0,0 +1,9 @@
1
+ import { CliServiceInterface } from "../cli/index.js";
2
+ import { OriginFetchLog, RuntimeConfigLog } from "../origin-request/index.js";
3
+ /** What a page diff reports its progress through. */
4
+ export type DiffLog = RuntimeConfigLog & OriginFetchLog & Pick<CliServiceInterface, "write" | "writeWarning" | "comment" | "spacer">;
5
+ /**
6
+ * A log that writes every line to stderr and leaves stdout to the JSON
7
+ * payload, so `sk diff --output json` can be piped into a parser.
8
+ */
9
+ export declare function stderrLog(cli: CliServiceInterface): DiffLog;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A log that writes every line to stderr and leaves stdout to the JSON
3
+ * payload, so `sk diff --output json` can be piped into a parser.
4
+ */
5
+ export function stderrLog(cli) {
6
+ const note = (message) => cli.note(message);
7
+ return {
8
+ write: note,
9
+ writeError: note,
10
+ writeSuccess: note,
11
+ writeWarning: note,
12
+ comment: note,
13
+ spacer: () => cli.note(""),
14
+ startAction: () => undefined,
15
+ successAction: () => undefined,
16
+ failAction: () => undefined,
17
+ };
18
+ }