@spinnaker/core 0.0.0-2026.2-2 → 0.0.0-2026.2-3

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.
@@ -6,5 +6,5 @@ export interface IEvaluatedVariable {
6
6
  key: string;
7
7
  value: string;
8
8
  }
9
- export declare function validateEvaluateVariablesStage(stage: IStage): any;
9
+ export declare function validateEvaluateVariablesStage(stage: IStage, dashedIdentifiersEnabled?: boolean): any;
10
10
  export declare function EvaluateVariablesStageConfig(props: IStageConfigProps): JSX.Element;
@@ -0,0 +1,8 @@
1
+ export interface IExpressionCapabilities {
2
+ functions: unknown[];
3
+ spelEvaluators: unknown[];
4
+ dashedIdentifiersEnabled: boolean;
5
+ }
6
+ export declare class ExpressionCapabilitiesReader {
7
+ static getExpressionCapabilities(): PromiseLike<IExpressionCapabilities>;
8
+ }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "https://github.com/spinnaker/spinnaker.git"
6
6
  },
7
7
  "license": "Apache-2.0",
8
- "version": "0.0.0-2026.2-2",
8
+ "version": "0.0.0-2026.2-3",
9
9
  "module": "dist/index.js",
10
10
  "typings": "dist/index.d.ts",
11
11
  "publishConfig": {
@@ -133,5 +133,5 @@
133
133
  "shx": "0.3.3",
134
134
  "typescript": "5.0.4"
135
135
  },
136
- "gitHead": "a4affe721ec80ca8978291e2accce065ea0d227a"
136
+ "gitHead": "fb7f43aaf1fbaed8f36d9bce0c3c59d8566f6f3e"
137
137
  }
@@ -0,0 +1,70 @@
1
+ import { validateEvaluateVariablesStage } from './EvaluateVariablesStageConfig';
2
+ import type { IStage } from '../../../../domain';
3
+
4
+ function buildStage(variables: Array<{ key: string; value: string }>): IStage {
5
+ return ({ variables } as unknown) as IStage;
6
+ }
7
+
8
+ describe('validateEvaluateVariablesStage', () => {
9
+ describe('when dashed identifier support is disabled (default)', () => {
10
+ it('rejects a variable name containing a hyphen', () => {
11
+ const stage = buildStage([{ key: 'my-container-name', value: '${1}' }]);
12
+
13
+ const result = validateEvaluateVariablesStage(stage);
14
+
15
+ expect(result.variables[0].key).toEqual(
16
+ 'Error: Variable Name should consist only of letters, numbers, or underscore',
17
+ );
18
+ });
19
+
20
+ it('accepts a variable name using only letters, numbers, and underscore', () => {
21
+ const stage = buildStage([{ key: 'my_container_name1', value: '${1}' }]);
22
+
23
+ const result = validateEvaluateVariablesStage(stage);
24
+
25
+ expect(result.variables).toBeUndefined();
26
+ });
27
+ });
28
+
29
+ describe('when dashed identifier support is enabled', () => {
30
+ it('accepts a variable name containing a hyphen', () => {
31
+ const stage = buildStage([{ key: 'my-container-name', value: '${1}' }]);
32
+
33
+ const result = validateEvaluateVariablesStage(stage, true);
34
+
35
+ expect(result.variables).toBeUndefined();
36
+ });
37
+
38
+ it('still rejects a variable name starting with a digit', () => {
39
+ const stage = buildStage([{ key: '1-my-container-name', value: '${1}' }]);
40
+
41
+ const result = validateEvaluateVariablesStage(stage, true);
42
+
43
+ expect(result.variables[0].key).toEqual(
44
+ 'Error: Variable Name should consist only of letters, numbers, underscore, or hyphen',
45
+ );
46
+ });
47
+
48
+ it('still rejects a variable name containing a space or other invalid character', () => {
49
+ const stage = buildStage([{ key: 'my container name', value: '${1}' }]);
50
+
51
+ const result = validateEvaluateVariablesStage(stage, true);
52
+
53
+ expect(result.variables[0].key).toEqual(
54
+ 'Error: Variable Name should consist only of letters, numbers, underscore, or hyphen',
55
+ );
56
+ });
57
+ });
58
+
59
+ it('still enforces the duplicate key validator regardless of dashed identifier support', () => {
60
+ const stage = buildStage([
61
+ { key: 'my-name', value: '${1}' },
62
+ { key: 'my-name', value: '${2}' },
63
+ ]);
64
+
65
+ const result = validateEvaluateVariablesStage(stage, true);
66
+
67
+ expect(result.variables[0].key).toEqual("Duplicate key 'my-name'");
68
+ expect(result.variables[1].key).toEqual("Duplicate key 'my-name'");
69
+ });
70
+ });
@@ -4,6 +4,7 @@ import React from 'react';
4
4
 
5
5
  import type { IExecutionAndStagePickerProps } from './ExecutionAndStagePicker';
6
6
  import { ExecutionAndStagePicker } from './ExecutionAndStagePicker';
7
+ import { ExpressionCapabilitiesReader } from './ExpressionCapabilitiesReader';
7
8
  import type { IFormikStageConfigInjectedProps } from '../FormikStageConfig';
8
9
  import { FormikStageConfig } from '../FormikStageConfig';
9
10
  import type { IStageConfigProps } from '../common';
@@ -31,9 +32,14 @@ export interface IEvaluatedVariable {
31
32
  value: string;
32
33
  }
33
34
 
34
- const variableNameValidator: IValidator = (val: string, label: string) =>
35
- !val.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/) &&
36
- errorMessage(`${label} should consist only of letters, numbers, or underscore`);
35
+ const createVariableNameValidator = (dashedIdentifiersEnabled: boolean): IValidator => {
36
+ const pattern = dashedIdentifiersEnabled ? /^[a-zA-Z_][a-zA-Z0-9_-]*$/ : /^[a-zA-Z_][a-zA-Z0-9_]*$/;
37
+ const allowedCharacters = dashedIdentifiersEnabled
38
+ ? 'letters, numbers, underscore, or hyphen'
39
+ : 'letters, numbers, or underscore';
40
+ return (val: string, label: string) =>
41
+ !val.match(pattern) && errorMessage(`${label} should consist only of ${allowedCharacters}`);
42
+ };
37
43
 
38
44
  const duplicateKeyValidatorFactory = (variables: IEvaluatedVariable[] = []) => {
39
45
  const keyCounts = countBy(
@@ -43,9 +49,10 @@ const duplicateKeyValidatorFactory = (variables: IEvaluatedVariable[] = []) => {
43
49
  return (key: string) => keyCounts[key] > 1 && `Duplicate key '${key}'`;
44
50
  };
45
51
 
46
- export function validateEvaluateVariablesStage(stage: IStage) {
52
+ export function validateEvaluateVariablesStage(stage: IStage, dashedIdentifiersEnabled = false) {
47
53
  const formValidator = new FormValidator(stage);
48
54
  const duplicateKeyValidator = duplicateKeyValidatorFactory(stage.variables);
55
+ const variableNameValidator = createVariableNameValidator(dashedIdentifiersEnabled);
49
56
  formValidator.field('variables').withValidators(
50
57
  formValidator.arrayForEach((item) => {
51
58
  item.field('key', 'Variable Name').required().withValidators(variableNameValidator, duplicateKeyValidator);
@@ -75,6 +82,14 @@ function PreviewConfiguration(props: IExecutionAndStagePickerProps) {
75
82
  export function EvaluateVariablesStageConfig(props: IStageConfigProps) {
76
83
  const { application, stage, pipeline, updateStage } = props;
77
84
  const [chosenStage, setChosenStage] = React.useState({} as IStageForSpelPreview);
85
+ const [dashedIdentifiersEnabled, setDashedIdentifiersEnabled] = React.useState(false);
86
+
87
+ React.useEffect(() => {
88
+ ExpressionCapabilitiesReader.getExpressionCapabilities().then(
89
+ (capabilities) => setDashedIdentifiersEnabled(capabilities.dashedIdentifiersEnabled),
90
+ () => setDashedIdentifiersEnabled(false),
91
+ );
92
+ }, []);
78
93
 
79
94
  const helpMessage =
80
95
  'Define one or more variables by assigning a **name** _(string)_ and a **value** ' +
@@ -86,7 +101,9 @@ export function EvaluateVariablesStageConfig(props: IStageConfigProps) {
86
101
  application={application}
87
102
  stage={stage}
88
103
  pipeline={pipeline}
89
- validate={validateEvaluateVariablesStage}
104
+ validate={(stageToValidate) =>
105
+ validateEvaluateVariablesStage(stageToValidate as IStage, dashedIdentifiersEnabled)
106
+ }
90
107
  onChange={updateStage}
91
108
  render={(renderProps) => {
92
109
  return (
@@ -0,0 +1,13 @@
1
+ import { REST } from '../../../../api';
2
+
3
+ export interface IExpressionCapabilities {
4
+ functions: unknown[];
5
+ spelEvaluators: unknown[];
6
+ dashedIdentifiersEnabled: boolean;
7
+ }
8
+
9
+ export class ExpressionCapabilitiesReader {
10
+ public static getExpressionCapabilities(): PromiseLike<IExpressionCapabilities> {
11
+ return REST('/capabilities/expressions').useCache(true).get();
12
+ }
13
+ }