ScriptCollection 4.4.54__py3-none-any.whl → 4.4.56__py3-none-any.whl

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.
@@ -40,7 +40,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
40
40
  from .ProgramRunnerPopen import ProgramRunnerPopen
41
41
  from .SCLog import SCLog, LogLevel
42
42
 
43
- version = "4.4.54"
43
+ version = "4.4.56"
44
44
  __version__ = version
45
45
 
46
46
  class VSCodeWorkspaceShellTask:
@@ -513,9 +513,10 @@ class TFCPS_CodeUnit_BuildCodeUnits:
513
513
 
514
514
  #install the host-declared trusted root-CA-certificates into the container (needed when the build pulls packages from a privately
515
515
  #hosted registry whose certificate-chain is not publicly rooted - for example an internally hosted gitlab-nuget-source). The
516
- #three env-var forms are detected automatically; see __collect_trusted_root_ca_arguments. _Path-variables add file-mounts, the
517
- #inline forms (_Content/_ContentBase64) are returned as a name->value dict that gets merged into required_environment_variables
518
- #below so their values flow through the docker-client's own environment (not through argv) just like a required secret does.
516
+ #two env-var forms are detected automatically from both the machine-wide environment-variables-configuration-file and the
517
+ #environment of the current process; see __collect_trusted_root_ca_arguments. _Path-variables add file-mounts, the inline
518
+ #_ContentBase64-form is returned as a name->value dict that gets merged into required_environment_variables below so its
519
+ #value flows through the docker-client's own environment (not through argv) just like a required secret does.
519
520
  trusted_root_ca_mount_arguments, trusted_root_ca_inline_env_vars = self.__collect_trusted_root_ca_arguments()
520
521
  mount_arguments += trusted_root_ca_mount_arguments
521
522
 
@@ -551,24 +552,46 @@ class TFCPS_CodeUnit_BuildCodeUnits:
551
552
 
552
553
  @GeneralUtilities.check_arguments
553
554
  def __collect_trusted_root_ca_arguments(self) -> tuple[list[str], dict[str, str]]:
554
- """Resolves the TrustedRootCA_<name>_Path, TrustedRootCA_<name>_Content and TrustedRootCA_<name>_ContentBase64 environment-variables
555
- of the current host into docker-arguments which install those certificates into the trust-store of the build-container. Returns
556
- (mount_arguments, inline_env_vars):
555
+ """Resolves the TrustedRootCA_<name>_Path and TrustedRootCA_<name>_ContentBase64 environment-variables of the current host into
556
+ docker-arguments which install those certificates into the trust-store of the build-container. Returns (mount_arguments, inline_env_vars):
557
557
  - mount_arguments: '-v <host-path>:/Workspace/RootCAs/<name>.crt:ro' entries for each _Path-variable.
558
- - inline_env_vars: a name->value dict for each _Content/_ContentBase64-variable; the caller merges it into
559
- required_environment_variables so the values flow through the docker-client's own environment, not through argv.
560
- The actual trust-store update happens in SCBuilder's EntryPoint.sh, which scans /Workspace/RootCAs and the TrustedRootCA_*
561
- environment-variables and runs update-ca-certificates once before any build-step. The <name>-part becomes the filename inside
562
- /usr/local/share/ca-certificates/ and must therefore be unique across the three env-var-forms; a duplicate is rejected here with
563
- a clear error, before the container is started."""
558
+ - inline_env_vars: a name->value dict for each _ContentBase64-variable; the caller merges it into required_environment_variables
559
+ so the values flow through the docker-client's own environment, not through argv.
560
+ Candidate-names are collected from two sources (identical to the OCI-registry-credentials, see
561
+ ScriptCollectionCore.__get_defined_oci_registry_names): the machine-wide environment-variables-configuration-file and the
562
+ environment of the current process. The value is then resolved through ScriptCollectionCore.resolve_environment_variable, so a
563
+ CSV-entry takes precedence over an environment-variable of the same name - consistent with every other environment-variable
564
+ this script-collection resolves. If a name is declared in the file but its value can not be determined there (for example a
565
+ 'file'-entry pointing to a missing file), the resolver falls back to the environment and fails only if neither source yields a
566
+ value. The actual trust-store update happens in SCBuilder's EntryPoint.sh, which scans /Workspace/RootCAs and the
567
+ TrustedRootCA_*-environment-variables and runs update-ca-certificates once before any build-step. The <name>-part becomes the
568
+ filename inside /usr/local/share/ca-certificates/ and must therefore be unique across the two env-var-forms; a duplicate is
569
+ rejected here with a clear error, before the container is started."""
564
570
  path_pattern = re.compile(r"^TrustedRootCA_(.+)_Path$", re.IGNORECASE)
565
- content_pattern = re.compile(r"^TrustedRootCA_(.+)_Content$", re.IGNORECASE)
566
571
  content_b64_pattern = re.compile(r"^TrustedRootCA_(.+)_ContentBase64$", re.IGNORECASE)
567
- seen_names: dict[str, str] = {}#lower-case name -> originating env-var-name, used only to produce an informative error on duplicate <name>.
572
+ #collect every candidate-variable-name from both sources before any value is resolved; this way a secret-value is read only for
573
+ #a name that is actually declared and the discovery is identical to the OCI-registry-credential-discovery. The configuration-
574
+ #file is scanned before the environment and a name found in both is kept with the casing of the file: on Windows, os.environ
575
+ #normalizes a variable-name to uppercase as soon as it is set, so without this preference the same declaration in both places
576
+ #would be treated as two different names and resolution would silently pick the environment-value instead of the file-value.
577
+ candidate_names: dict[str, str] = {}#lower-case variable-name -> canonical variable-name (file-casing preferred)
578
+ configuration_file = self.sc.get_environment_variables_configuration_file()
579
+ if os.path.isfile(configuration_file):
580
+ for entry in GeneralUtilities.read_csv_file(configuration_file, True):
581
+ if 0 == len(entry):
582
+ continue
583
+ env_name = entry[0]
584
+ if path_pattern.match(env_name) is not None or content_b64_pattern.match(env_name) is not None:
585
+ candidate_names.setdefault(env_name.lower(), env_name)
586
+ for env_name in os.environ.keys():
587
+ if path_pattern.match(env_name) is not None or content_b64_pattern.match(env_name) is not None:
588
+ candidate_names.setdefault(env_name.lower(), env_name)
589
+ seen_names: dict[str, str] = {}#lower-case <name>-part -> originating variable-name, used only to produce an informative error on duplicate <name>.
568
590
  mount_arguments: list[str] = []
569
591
  inline_env_vars: dict[str, str] = {}
570
592
  #sorted so the log-output (and therefore the order of "-v"-/"-e"-arguments) stays deterministic across runs.
571
- for env_name, env_value in sorted(os.environ.items()):
593
+ for env_name in sorted(candidate_names.values(), key=str.lower):
594
+ env_value = self.sc.resolve_environment_variable(env_name, f"the TrustedRootCA-mechanism (declared via \"{env_name}\")")
572
595
  if not GeneralUtilities.string_has_content(env_value):
573
596
  continue
574
597
  path_match = path_pattern.match(env_name)
@@ -584,9 +607,9 @@ class TFCPS_CodeUnit_BuildCodeUnits:
584
607
  raise ValueError(f"Environment-variable \"{env_name}\" (\"{host_path}\") does not look like a PEM-encoded certificate (missing \"-----BEGIN CERTIFICATE-----\"-header).")
585
608
  mount_arguments += ["-v", f"{host_path}:/Workspace/RootCAs/{ca_name}.crt:ro"]
586
609
  continue
587
- inline_match = content_pattern.match(env_name) or content_b64_pattern.match(env_name)
588
- if inline_match is not None:
589
- ca_name = inline_match.group(1)
610
+ content_b64_match = content_b64_pattern.match(env_name)
611
+ if content_b64_match is not None:
612
+ ca_name = content_b64_match.group(1)
590
613
  self.__check_trusted_root_ca_name_is_unique(seen_names, ca_name, env_name)
591
614
  inline_env_vars[env_name] = env_value
592
615
  continue
@@ -596,7 +619,7 @@ class TFCPS_CodeUnit_BuildCodeUnits:
596
619
  def __check_trusted_root_ca_name_is_unique(self, seen_names: dict[str, str], ca_name: str, env_name: str) -> None:
597
620
  key = ca_name.lower()
598
621
  if key in seen_names:
599
- raise ValueError(f"Multiple TrustedRootCA-definitions for name \"{ca_name}\" found (\"{seen_names[key]}\" and \"{env_name}\"). The <name>-part becomes the filename in the trust-store and must therefore be unique across _Path, _Content and _ContentBase64.")
622
+ raise ValueError(f"Multiple TrustedRootCA-definitions for name \"{ca_name}\" found (\"{seen_names[key]}\" and \"{env_name}\"). The <name>-part becomes the filename in the trust-store and must therefore be unique across _Path and _ContentBase64.")
600
623
  seen_names[key] = env_name
601
624
 
602
625
  @GeneralUtilities.check_arguments
@@ -2,6 +2,7 @@ import json
2
2
  import os
3
3
  import re
4
4
  import socket
5
+ from typing import Callable
5
6
  from PIL import Image, ImageChops
6
7
  from ..GeneralUtilities import GeneralUtilities
7
8
  from ..ScriptCollectionCore import ScriptCollectionCore
@@ -76,7 +77,7 @@ class TFCPS_VisualRegressionTests:
76
77
  self.__sc.log.loglevel = tfcps_codeunit.get_verbosity()
77
78
 
78
79
  @GeneralUtilities.check_arguments
79
- def run(self, update_baselines: bool, playwright_project_folder_relative_path: str = ".", domain_of_externally_started_application: str = None, environment_variables: dict[str, str] = None, playwright_project: str = None) -> None:
80
+ def run(self, update_baselines: bool, playwright_project_folder_relative_path: str = ".", domain_of_externally_started_application: str = None, environment_variables: dict[str, str] = None, playwright_project: str = None, restart_application_under_test: Callable = None) -> None:
80
81
  """Executes the visual-regression-tests of the codeunit.
81
82
  If 'update_baselines' is false the screenshots are compared with the baselines and a difference fails the
82
83
  run. If 'update_baselines' is true the baseline-screenshots are regenerated instead: missing ones are
@@ -96,7 +97,17 @@ class TFCPS_VisualRegressionTests:
96
97
  'playwright_project' restricts the run to one project of the playwright-configuration (which is one
97
98
  browser). It is required by codeunits whose testcases change the state of the application under test:
98
99
  those have to start the application newly for every browser, because otherwise the second browser would
99
- find the state which the first one left behind and would therefore see other pages than the first one."""
100
+ find the state which the first one left behind and would therefore see other pages than the first one.
101
+ 'restart_application_under_test' is only relevant in the update-mode and only for an application which the
102
+ caller started itself (see the documentation of this class). That mode runs the testcases twice (see the
103
+ construction of the command below): once to write the baselines and once to verify that every screenshot
104
+ could really be produced. An application which the playwright-configuration starts itself is restarted by
105
+ every "npx playwright test" and therefore begins the verify-pass with a fresh state, but an application
106
+ which the caller started keeps its state for the lifetime of its process, so a testcase which changes that
107
+ state (by registering a user or by creating an entity for example) would find in the verify-pass the state
108
+ which it created in the update-pass and would fail although its screenshot could be produced. The caller
109
+ therefore passes this callback, which restarts the application between the two passes; when it is not given
110
+ the two passes share one application, which is correct for an application that restarts itself."""
100
111
  codeunit_folder: str = self.__tfcps_codeunit.get_codeunit_folder()
101
112
  repository_folder: str = self.__tfcps_codeunit.get_repository_folder()
102
113
  playwright_project_folder: str = self.__get_folder_in_codeunit(codeunit_folder, playwright_project_folder_relative_path)
@@ -119,6 +130,21 @@ class TFCPS_VisualRegressionTests:
119
130
  # contain packages for another operating-system. "--no-save" is required so that the installation does not
120
131
  # modify "package.json" or "package-lock.json".
121
132
  install_command: str = "npm install --no-audit --no-fund --no-save"
133
+ base_arguments: list[str] = ["run", "--rm"]
134
+ # Playwright recommends this because the default-size of the shared memory of a container is too small for
135
+ # chromium, which makes chromium crash on pages which are not trivial.
136
+ base_arguments = base_arguments+["--ipc=host"]
137
+ base_arguments = base_arguments+self.__get_mount_arguments(codeunit_folder, codeunit_folder_in_container, playwright_project_folder_relative_path)
138
+ if domain_of_externally_started_application is not None:
139
+ base_arguments = base_arguments+self.__get_network_arguments(domain_of_externally_started_application)
140
+ if environment_variables is not None:
141
+ for name, value in environment_variables.items():
142
+ base_arguments = base_arguments+["-e", f"{name}={value}"]
143
+ base_arguments = base_arguments+["-w", working_folder, image]
144
+
145
+ def run_in_container(command_to_run: str) -> tuple:
146
+ return self.__sc.run_program_argsasarray("docker", base_arguments+["/bin/sh", "-c", command_to_run], throw_exception_if_exitcode_is_not_zero=False, print_live_output=True, print_errors_as_information=True)
147
+
122
148
  if update_baselines:
123
149
  # The update-run writes the baseline-screenshots (it creates the missing ones and overwrites the
124
150
  # changed ones). Since playwright 1.50 that run reports every testcase whose screenshot it created or
@@ -129,22 +155,26 @@ class TFCPS_VisualRegressionTests:
129
155
  # captured stabilizes and therefore matches its own new baseline, while a testcase which can not
130
156
  # produce a screenshot keeps failing (a missing baseline is regenerated by the second run and still
131
157
  # fails it). The exit-code of the second run therefore decides about success, so the one of the
132
- # update-run is discarded by separating the two runs with ";" instead of "&&".
133
- command = f"{install_command} && ( {test_command} --update-snapshots ; {test_command} )"
158
+ # update-run is discarded.
159
+ update_command: str = f"{install_command} && {test_command} --update-snapshots"
160
+ verify_command: str = f"{install_command} && {test_command}"
161
+ if restart_application_under_test is None:
162
+ # The application restarts itself between the two passes (for example because the
163
+ # playwright-configuration starts it through its "webServer"-setting), so both passes can share one
164
+ # invocation. They are separated by ";" and not by "&&" so that the discarded exit-code of the
165
+ # update-run does not skip the verify-run.
166
+ result = run_in_container(f"{install_command} && ( {test_command} --update-snapshots ; {test_command} )")
167
+ else:
168
+ # The application was started by the caller and keeps its state for the lifetime of its process, so
169
+ # the two passes must not share one application: the verify-pass would otherwise find the state
170
+ # which a testcase created in the update-pass (a registered user or a created entity for example)
171
+ # and would fail although its screenshot could be produced. The passes are therefore two separate
172
+ # invocations and the caller restarts the application in between through the callback.
173
+ run_in_container(update_command)
174
+ restart_application_under_test()
175
+ result = run_in_container(verify_command)
134
176
  else:
135
- command = f"{install_command} && {test_command}"
136
- arguments: list[str] = ["run", "--rm"]
137
- # Playwright recommends this because the default-size of the shared memory of a container is too small for
138
- # chromium, which makes chromium crash on pages which are not trivial.
139
- arguments = arguments+["--ipc=host"]
140
- arguments = arguments+self.__get_mount_arguments(codeunit_folder, codeunit_folder_in_container, playwright_project_folder_relative_path)
141
- if domain_of_externally_started_application is not None:
142
- arguments = arguments+self.__get_network_arguments(domain_of_externally_started_application)
143
- if environment_variables is not None:
144
- for name, value in environment_variables.items():
145
- arguments = arguments+["-e", f"{name}={value}"]
146
- arguments = arguments+["-w", working_folder, image, "/bin/sh", "-c", command]
147
- result = self.__sc.run_program_argsasarray("docker", arguments, throw_exception_if_exitcode_is_not_zero=False, print_live_output=True, print_errors_as_information=True)
177
+ result = run_in_container(f"{install_command} && {test_command}")
148
178
  if result[0] != 0:
149
179
  if update_baselines:
150
180
  # A non-zero exit-code of the second run means a screenshot could not be produced even against its
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.4.54
3
+ Version: 4.4.56
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Author-email: Marius Göcke <marius.goecke@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -11,7 +11,7 @@ ScriptCollection/ProgramRunnerSudo.py,sha256=vwKq-MOcqsgiKhSf-MBUDBC_UyaU8evP3Ro
11
11
  ScriptCollection/RepositoryDiagramGenerator.py,sha256=K_u2NW_p4ozdWD50irJEkkcDVa70TcUJpZN63TeXSLw,7092
12
12
  ScriptCollection/RepositoryHistoryAnalyzer.py,sha256=u9141B9D-Kef-9uo3yR7BXKUMzIKLVsesnYk7H-cWm4,6157
13
13
  ScriptCollection/SCLog.py,sha256=Fjf8Pdi63cXHGMxL_aI6A0dwGm7QIfrv3czjvpSUlaM,4705
14
- ScriptCollection/ScriptCollectionCore.py,sha256=DSxbIUAAI3nOF7pLspynT8zerBg-Fp1tCeX1d8ny9FE,310633
14
+ ScriptCollection/ScriptCollectionCore.py,sha256=exENc4S6aOMh_TgBDwRuZbd0nxCqjZ_AGqJxRTerKq4,310633
15
15
  ScriptCollection/TestKind.py,sha256=jqLJwNvQeyea7SZf-UFzMC9pM0znv4do7FIC1xq8u9M,1672
16
16
  ScriptCollection/UnassignedVariablesCheck.py,sha256=8xNcp1D5HeOLO1a1NEerq2TsnpFhw7yzYPkaay-oisY,3804
17
17
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -39,7 +39,7 @@ ScriptCollection/TFCPS/TFCPS_BuildCodeUnitsHook.py,sha256=67_DQwoH5bhxxSmwtuAeoW
39
39
  ScriptCollection/TFCPS/TFCPS_CodeSpellCheck.py,sha256=zV62O7UiGjewx1yQUIWmUJ9D-5ipkV_f28uNhp-JWUs,5306
40
40
  ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py,sha256=yosafTfbB0LBMKomZvLnFJpgJpJOMHsGKLirVjG1slk,40501
41
41
  ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=Mj9t1SyRpkYZE74cLsGWYv4xB89gXL2ld-RX3xvvGdw,9835
42
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=kQNvDuU_pPLB8cgjfF2uZVE2W0OlBvKPGiTfBQzTolw,61268
42
+ ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=V76EF-Dd2sqnmZPMeJt_Z9QKsY5o1cLS7dz42g3N4SU,63647
43
43
  ScriptCollection/TFCPS/TFCPS_CreateRelease.py,sha256=BVK3fpEyjcXYVHIb6YYLH7bWe6iKRaCtPrJ3tXAemYw,6582
44
44
  ScriptCollection/TFCPS/TFCPS_Generic.py,sha256=mRBcf7XuNWOSXbZYc3NuJow18AMZ30D6Z-BtyNYfNcM,2072
45
45
  ScriptCollection/TFCPS/TFCPS_MergeToMain.py,sha256=Krt5oyGNcRAN3szsgU7LoTh8yVTOdHW-Kq7R9MDDV-Q,7673
@@ -48,7 +48,7 @@ ScriptCollection/TFCPS/TFCPS_OCIImageSecretScan.py,sha256=Jb7AaMcJDW-gYEYBUVZAG3
48
48
  ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py,sha256=XLVsFTA1jvfDbZ7wYJgIdEByZhF_bYVbA5jkisuvK4k,2322
49
49
  ScriptCollection/TFCPS/TFCPS_RemoteBuild.py,sha256=2Tx5HLk1ZftBWDCTiGZdP2QiiGNyWsEuTCSt33dNQjc,23891
50
50
  ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=eGmKZSoS2EQin-qrHTewJrvm-2VzdZhw6d0LceIonF0,158891
51
- ScriptCollection/TFCPS/TFCPS_VisualRegressionTests.py,sha256=Bf9TAQxwkhQMolvf6ZYsVNfp0jGQ1pmc3gUT3qMIJuw,39568
51
+ ScriptCollection/TFCPS/TFCPS_VisualRegressionTests.py,sha256=F90CF5kLCgV_M3yN696xWzF1cglWLXecau9My2ZyGxw,42230
52
52
  ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  ScriptCollection/TFCPS/CPP/TFCPS_CodeUnitSpecific_CPP.py,sha256=BNZPMjGiWLMBH7QDtP06WEVLMnI38NLX4Dpd13bSbi4,16614
54
54
  ScriptCollection/TFCPS/CPP/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -73,8 +73,8 @@ ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=yyjWPMHQjPLkML
73
73
  ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=ILVhJHvwG5TvPBBqSvyACYb7W9QnWrJpxKgHu8IQu4g,9249
75
75
  ScriptCollection/TFCPS/TypeScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
- scriptcollection-4.4.54.dist-info/METADATA,sha256=6gQo9E5tDJaMQTH6mC0sZBUIBslhE-dsEDCMkwjU6go,8032
77
- scriptcollection-4.4.54.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
78
- scriptcollection-4.4.54.dist-info/entry_points.txt,sha256=--Xk3EcTa14uk1YnUD8CQ2naQjNKJFohScd1ONy4CeY,6135
79
- scriptcollection-4.4.54.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
80
- scriptcollection-4.4.54.dist-info/RECORD,,
76
+ scriptcollection-4.4.56.dist-info/METADATA,sha256=JSlo8zmGqx2KewGX_VytinYT3hoK30xp-MEVKI56U_4,8032
77
+ scriptcollection-4.4.56.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
78
+ scriptcollection-4.4.56.dist-info/entry_points.txt,sha256=--Xk3EcTa14uk1YnUD8CQ2naQjNKJFohScd1ONy4CeY,6135
79
+ scriptcollection-4.4.56.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
80
+ scriptcollection-4.4.56.dist-info/RECORD,,