From 676ce45993109f4bf4a6e57f19e325c08f59da9a Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 29 Sep 2020 22:03:21 -0700 Subject: [PATCH] Fix condition and adjust tests --- .../agents/checkin/state_new_actions.test.ts | 14 +++++++++++--- .../services/agents/checkin/state_new_actions.ts | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.test.ts b/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.test.ts index dd00ba87fded5..f4a2147131570 100644 --- a/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.test.ts +++ b/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.test.ts @@ -80,7 +80,15 @@ describe('test agent checkin new action services', () => { expect( await createAgentActionFromPolicyAction( mockSavedObjectsClient, - { ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.1-SNAPSHOT' } } } }, + { ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.0-SNAPSHOT' } } } }, + mockPolicyAction + ) + ).toEqual(expectedResult); + + expect( + await createAgentActionFromPolicyAction( + mockSavedObjectsClient, + { ...mockAgent, local_metadata: { elastic: { agent: { version: '7.10.2' } } } }, mockPolicyAction ) ).toEqual(expectedResult); @@ -131,7 +139,7 @@ describe('test agent checkin new action services', () => { expect( await createAgentActionFromPolicyAction( mockSavedObjectsClient, - { ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.1-SNAPSHOT' } } } }, + { ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.3' } } } }, mockPolicyAction ) ).toEqual(expectedResult); @@ -139,7 +147,7 @@ describe('test agent checkin new action services', () => { expect( await createAgentActionFromPolicyAction( mockSavedObjectsClient, - { ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.3' } } } }, + { ...mockAgent, local_metadata: { elastic: { agent: { version: '7.9.1-SNAPSHOT' } } } }, mockPolicyAction ) ).toEqual(expectedResult); diff --git a/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts b/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts index 89b045c5c0516..51ccdc8eb1c7c 100644 --- a/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts +++ b/x-pack/plugins/ingest_manager/server/services/agents/checkin/state_new_actions.ts @@ -116,10 +116,21 @@ export async function createAgentActionFromPolicyAction( agent: Agent, policyAction: AgentPolicyAction ) { - // Transform the policy action for agent version <= 7.9 for BWC + // Transform the policy action for agent version <= 7.9.x for BWC const agentVersion = semver.parse((agent.local_metadata?.elastic as any)?.agent?.version); const agentPolicyAction: AgentPolicyAction | AgentPolicyActionV7_9 = - agentVersion && semver.lt(agentVersion, '7.10.0') + agentVersion && + semver.lt( + agentVersion, + // A prerelease tag is added here so that agent versions with prerelease tags can be compared + // correctly using `semvar` + '7.10.0-SNAPSHOT', + // `@types/semvar` is out of date with the version of `semvar` we use and doesn't have a + // corresponding release version we can update the typing to :( so, the typing error is + // suppressed here even though it is supported by `semvar` + // @ts-expect-error + { includePrerelease: true } + ) ? { ...policyAction, type: 'CONFIG_CHANGE',