From 9c9e4b034d1b1fe599ec257ad3287e537edaead8 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 23 Sep 2026 13:29:25 +0100 Subject: [PATCH 1/2] Fix `getCommitOid` stubs --- src/git-utils.test.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/git-utils.test.ts b/src/git-utils.test.ts index b77d40a7ec..f6a25778a8 100644 --- a/src/git-utils.test.ts +++ b/src/git-utils.test.ts @@ -29,10 +29,12 @@ test.serial( process.env["GITHUB_SHA"] = currentSha; const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs("HEAD").resolves(currentSha); + callback.withArgs(sinon.match.string, "HEAD").resolves(currentSha); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, expectedRef); + + t.true(callback.calledOnceWith(tmpDir, "HEAD")); }); }, ); @@ -48,11 +50,15 @@ test.serial( const sha = "a".repeat(40); const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs("refs/remotes/pull/1/merge").resolves(sha); - callback.withArgs("HEAD").resolves(sha); + callback + .withArgs(sinon.match.string, "refs/remotes/pull/1/merge") + .resolves(sha); + callback.withArgs(sinon.match.any, "HEAD").resolves(sha); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, expectedRef); + + t.true(callback.calledWith(tmpDir, "refs/remotes/pull/1/merge")); }); }, ); @@ -71,6 +77,9 @@ test.serial( const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, "refs/pull/1/head"); + + t.true(callback.calledOnceWith(tmpDir, "refs/pull/1/merge")); + t.true(callback.calledOnceWith(tmpDir, "HEAD")); }); }, ); @@ -92,11 +101,14 @@ test.serial( process.env["GITHUB_SHA"] = "a".repeat(40); const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs("refs/pull/1/merge").resolves("b".repeat(40)); - callback.withArgs("HEAD").resolves("b".repeat(40)); + callback.withArgs(tmpDir, "refs/pull/1/merge").resolves("b".repeat(40)); + callback.withArgs(sinon.match.any, "HEAD").resolves("b".repeat(40)); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, "refs/pull/2/merge"); + + t.true(callback.calledOnceWith(tmpDir, "refs/pull/1/merge")); + t.true(callback.calledOnceWith(tmpDir, "HEAD")); }); }, ); From 42277414c74077324e1a1eb1f3cfd58f64fbabc5 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 23 Sep 2026 13:38:53 +0100 Subject: [PATCH 2/2] Stub `getCommitOid` correctly and check calls --- src/git-utils.test.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/git-utils.test.ts b/src/git-utils.test.ts index f6a25778a8..64b76590ae 100644 --- a/src/git-utils.test.ts +++ b/src/git-utils.test.ts @@ -34,6 +34,7 @@ test.serial( const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, expectedRef); + t.is(callback.callCount, 1); t.true(callback.calledOnceWith(tmpDir, "HEAD")); }); }, @@ -58,6 +59,8 @@ test.serial( const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, expectedRef); + t.is(callback.callCount, 2); + t.true(callback.calledWith(tmpDir, "HEAD")); t.true(callback.calledWith(tmpDir, "refs/remotes/pull/1/merge")); }); }, @@ -72,14 +75,18 @@ test.serial( process.env["GITHUB_SHA"] = "a".repeat(40); const callback = sinon.stub(gitUtils, "getCommitOid"); - callback.withArgs(tmpDir, "refs/pull/1/merge").resolves("a".repeat(40)); + callback + .withArgs(tmpDir, "refs/remotes/pull/1/merge") + .resolves("a".repeat(40)); callback.withArgs(tmpDir, "HEAD").resolves("b".repeat(40)); + callback.throws(new Error("Unexpected getCommitOid call in test.")); const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, "refs/pull/1/head"); - t.true(callback.calledOnceWith(tmpDir, "refs/pull/1/merge")); - t.true(callback.calledOnceWith(tmpDir, "HEAD")); + t.is(callback.callCount, 2); + t.true(callback.calledWith(tmpDir, "refs/remotes/pull/1/merge")); + t.true(callback.calledWith(tmpDir, "HEAD")); }); }, ); @@ -107,8 +114,8 @@ test.serial( const actualRef = await gitUtils.getRef(); t.deepEqual(actualRef, "refs/pull/2/merge"); - t.true(callback.calledOnceWith(tmpDir, "refs/pull/1/merge")); - t.true(callback.calledOnceWith(tmpDir, "HEAD")); + // getCommitOid shouldn't be called, because the ref should be taken from the input + t.is(callback.callCount, 0); }); }, );