From 0ee8d99d9c7d5ce0e1a4638e26c05a716032b3c5 Mon Sep 17 00:00:00 2001 From: "Shannon Roberts (Beagin)" Date: Wed, 2 Jul 2025 16:31:02 -0700 Subject: [PATCH] UI: Fix flaky secrets-sync test with optional chaining (#31176) * UI: Fix flaky secrets-sync test with optional chaining * resolve timing issues by moving cleanup directly to test and stubbing endpoint instead of relying on req.passthrough() * Revert "UI: Fix flaky secrets-sync test with optional chaining" This reverts commit 3e170db4a3136655d3a46e193879fa726fd44567. * add data wrappers & reset hvd flag before deleting the admin namespace --------- Co-authored-by: claire bontempo --- .../acceptance/sync/secrets/overview-test.js | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/ui/tests/acceptance/sync/secrets/overview-test.js b/ui/tests/acceptance/sync/secrets/overview-test.js index c634ec5f5e..1919880260 100644 --- a/ui/tests/acceptance/sync/secrets/overview-test.js +++ b/ui/tests/acceptance/sync/secrets/overview-test.js @@ -168,11 +168,6 @@ module('Acceptance | sync | overview', function (hooks) { await loginNs('admin/foo'); }); - hooks.afterEach(async function () { - await visit('vault/dashboard'); - await runCmd([`delete admin/sys/namespaces/foo -f`, deleteNS('admin')]); - }); - test('it should make activation-flag requests to correct namespace', async function (assert) { assert.expect(3); @@ -201,14 +196,25 @@ module('Acceptance | sync | overview', function (hooks) { await click(ts.overview.activationModal.checkbox); await click(ts.overview.activationModal.confirm); - // During the afterEach hook cleanup endpoint is hit again which increases the assertion count (above) - // Re-stub here without the assertion to prep for namespace cleanup. - this.server.get('/sys/activation-flags', (_, req) => req.passthrough()); + // During the namespace cleanup in the afterEach hook this endpoint is hit again which increases the assertion count (above) + // Re-stub here without the assertion to reduce unnecessary assertions. + this.server.get('/sys/activation-flags', () => { + return { + data: { + activated: ['secrets-sync'], + unactivated: [], + }, + }; + }); + await visit('vault/dashboard'); + await runCmd([`delete admin/sys/namespaces/foo -f`, deleteNS('admin')]); }); test('it should make activation-flag requests to correct namespace when managed', async function (assert) { assert.expect(3); - this.owner.lookup('service:flags').featureFlags = ['VAULT_CLOUD_ADMIN_NAMESPACE']; + + const flagService = this.owner.lookup('service:flags'); + flagService.featureFlags = ['VAULT_CLOUD_ADMIN_NAMESPACE']; this.server.get('/sys/activation-flags', (_, req) => { assert.deepEqual(req.requestHeaders, {}, 'Request is unauthenticated and in root namespace'); @@ -236,9 +242,25 @@ module('Acceptance | sync | overview', function (hooks) { await click(ts.overview.activationModal.checkbox); await click(ts.overview.activationModal.confirm); - // During the afterEach hook this endpoint is hit again which increases the assertion count (above) - // Re-stub here without the assertion to prep for namespace cleanup. - this.server.get('/sys/activation-flags', (_, req) => req.passthrough()); + // During the namespace cleanup in the afterEach hook this endpoint is hit again which increases the assertion count (above) + // Re-stub here without the assertion to reduce unnecessary assertions. + this.server.get('/sys/activation-flags', () => { + return { + data: { + activated: ['secrets-sync'], + unactivated: [], + }, + }; + }); + + // Delete the admin/foo namespace + await visit('vault/dashboard'); + await runCmd([deleteNS('foo')]); + + // Reset the HVD feature flag so that we can delete the admin namespace + flagService.featureFlags = []; + await login(); + await runCmd([deleteNS('admin')]); }); }); });