Skip to content

Commit 676ce45

Browse files
committed
Fix condition and adjust tests
1 parent 4b578eb commit 676ce45

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ describe('test agent checkin new action services', () => {
8080
expect(
8181
await createAgentActionFromPolicyAction(
8282
mockSavedObjectsClient,
83-
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.1-SNAPSHOT' } } } },
83+
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.0-SNAPSHOT' } } } },
84+
mockPolicyAction
85+
)
86+
).toEqual(expectedResult);
87+
88+
expect(
89+
await createAgentActionFromPolicyAction(
90+
mockSavedObjectsClient,
91+
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.2' } } } },
8492
mockPolicyAction
8593
)
8694
).toEqual(expectedResult);
@@ -131,15 +139,15 @@ describe('test agent checkin new action services', () => {
131139
expect(
132140
await createAgentActionFromPolicyAction(
133141
mockSavedObjectsClient,
134-
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.1-SNAPSHOT' } } } },
142+
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.3' } } } },
135143
mockPolicyAction
136144
)
137145
).toEqual(expectedResult);
138146

139147
expect(
140148
await createAgentActionFromPolicyAction(
141149
mockSavedObjectsClient,
142-
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.3' } } } },
150+
{ ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.1-SNAPSHOT' } } } },
143151
mockPolicyAction
144152
)
145153
).toEqual(expectedResult);

x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,21 @@ export async function createAgentActionFromPolicyAction(
116116
agent: Agent,
117117
policyAction: AgentPolicyAction
118118
) {
119-
// Transform the policy action for agent version <= 7.9 for BWC
119+
// Transform the policy action for agent version <= 7.9.x for BWC
120120
const agentVersion = semver.parse((agent.local_metadata?.elastic as any)?.agent?.version);
121121
const agentPolicyAction: AgentPolicyAction | AgentPolicyActionV7_9 =
122-
agentVersion && semver.lt(agentVersion, '7.10.0')
122+
agentVersion &&
123+
semver.lt(
124+
agentVersion,
125+
// A prerelease tag is added here so that agent versions with prerelease tags can be compared
126+
// correctly using `semvar`
127+
'7.10.0-SNAPSHOT',
128+
// `@types/semvar` is out of date with the version of `semvar` we use and doesn't have a
129+
// corresponding release version we can update the typing to :( so, the typing error is
130+
// suppressed here even though it is supported by `semvar`
131+
// @ts-expect-error
132+
{ includePrerelease: true }
133+
)
123134
? {
124135
...policyAction,
125136
type: 'CONFIG_CHANGE',

0 commit comments

Comments
 (0)