diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 53933f362..98f2b8254 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -1,3 +1,9 @@ +unreleased: + fixed bugs: + - >- + Fixed a bug where item's parent reference was missing from request and + response callback + 7.43.0: date: 2024-10-30 new features: diff --git a/lib/runner/create-item-context.js b/lib/runner/create-item-context.js index 325d696e1..07902cc2a 100644 --- a/lib/runner/create-item-context.js +++ b/lib/runner/create-item-context.js @@ -36,6 +36,7 @@ module.exports = function (payload, defaults) { // we clone item from the payload, so that we can make any changes we need there, without mutating the // collection context.item = new sdk.Item(payload.item.toJSON()); + context.item.setParent(payload.item.parent()); // get a reference to the Auth instance from the item, so changes are synced back context.auth = context.originalItem.getAuth(); diff --git a/lib/runner/request-helpers-presend.js b/lib/runner/request-helpers-presend.js index 2e8a2723a..85b388980 100644 --- a/lib/runner/request-helpers-presend.js +++ b/lib/runner/request-helpers-presend.js @@ -317,6 +317,8 @@ module.exports = [ item = new sdk.Item({ request }), originalItem = context.originalItem; + item.setParent(originalItem.parent()); + // auth handler gave a no go, and an intermediate request. // make the intermediate request the response is passed to `init` hook // we are overriding the originalItem because in pre we have a entire new request diff --git a/lib/runner/util.js b/lib/runner/util.js index 9ee4573bb..3d65fcd8e 100644 --- a/lib/runner/util.js +++ b/lib/runner/util.js @@ -270,6 +270,7 @@ module.exports = { hasVaultSecrets = vaultValues ? vaultValues.count() > 0 : false, + itemParent = context.item.parent(), urlObj = context.item.request.url, // @note URL string is used to resolve nested variables as URL parser doesn't support them well. urlString = urlObj.toString(), @@ -310,6 +311,9 @@ module.exports = { item = context.item = new sdk.Item(context.item.toObjectResolved(null, variableDefinitions, { ignoreOwnVariables: true })); + // restore the parent reference + item.setParent(itemParent); + // re-parse and update the URL from the resolved string urlString && (item.request.url = new sdk.Url(urlString)); diff --git a/test/integration/sanity/response-callback.test.js b/test/integration/sanity/response-callback.test.js index f8d0c41df..25ae34d23 100644 --- a/test/integration/sanity/response-callback.test.js +++ b/test/integration/sanity/response-callback.test.js @@ -145,5 +145,13 @@ describe('response callback', function () { // cursor expect(testrun).to.have.nested.property('response.firstCall.args[1]').that.has.property('ref'); }); + + it('should have item\'s parent reference intact', function () { + const parent = testrun.beforeItem.firstCall.args[2].parent(); + + expect(testrun.request.firstCall.args[4].parent()).to.equal(parent); + expect(testrun.request.secondCall.args[4].parent()).to.equal(parent); + expect(testrun.response.firstCall.args[4].parent()).to.equal(parent); + }); }); });