Skip to content

Commit 0e242ef

Browse files
authored
Merge branch 'main' into port/vscode-lm-reliability
2 parents d40e3a9 + 10b45ab commit 0e242ef

2 files changed

Lines changed: 48 additions & 9 deletions

File tree

‎.github/workflows/mutation-testing.yml‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ jobs:
3636
fetch-depth: 0
3737
persist-credentials: false
3838

39-
- name: Fetch pull request base
40-
if: github.event_name == 'pull_request'
41-
env:
42-
BASE_REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}.git
43-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
44-
run: git fetch --no-tags "$BASE_REPOSITORY_URL" "$BASE_SHA"
45-
4639
- name: Setup Node.js and pnpm
4740
if: github.event_name == 'pull_request'
4841
uses: ./.github/actions/setup-node-pnpm
@@ -56,9 +49,10 @@ jobs:
5649
- name: Enforce executable-line scope and run advisory mutation testing
5750
if: github.event_name == 'pull_request'
5851
env:
59-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
6052
HEAD_SHA: ${{ github.sha }}
61-
run: node scripts/stryker-diff.mjs ci --base "$BASE_SHA" --head "$HEAD_SHA"
53+
run: |
54+
BASE_SHA="$(git rev-parse "$HEAD_SHA^1")"
55+
node scripts/stryker-diff.mjs ci --base "$BASE_SHA" --head "$HEAD_SHA"
6256
6357
- name: Upload mutation reports
6458
id: mutation_report

‎scripts/stryker-diff.test.mjs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ describe("mutation testing workflow", () => {
5757
assert.ok(!workflow.includes("ref: ${{ github.event.pull_request.head.sha }}"))
5858
assert.ok(workflow.includes("HEAD_SHA: ${{ github.sha }}"))
5959
assert.ok(!workflow.includes("HEAD_SHA: ${{ github.event.pull_request.head.sha }}"))
60+
assert.ok(workflow.includes('BASE_SHA="$(git rev-parse "$HEAD_SHA^1")"'))
61+
assert.ok(!workflow.includes("github.event.pull_request.base.sha"))
6062
assert.ok(workflow.includes("steps.mutation_report.outputs.artifact-url"))
6163
assert.ok(workflow.includes("open the package's mutation.html file"))
6264
assert.ok(workflow.includes("Enforce executable-line scope and run advisory mutation testing"))
@@ -524,6 +526,49 @@ describe("selectFromGit", () => {
524526
fs.rmSync(repo, { recursive: true, force: true })
525527
}
526528
})
529+
530+
it("does not charge intervening base-branch changes to the pull request", () => {
531+
const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-stale-base-"))
532+
const runGit = (...args) => execFileSync("git", args, { cwd: repo, encoding: "utf8" }).trim()
533+
534+
try {
535+
runGit("init", "--initial-branch=main")
536+
runGit("config", "user.name", "Mutation Test")
537+
runGit("config", "user.email", "[email protected]")
538+
fs.mkdirSync(path.join(repo, "packages/core/src"), { recursive: true })
539+
fs.writeFileSync(path.join(repo, "packages/core/src/pr.ts"), "export const pr = false\n")
540+
fs.writeFileSync(path.join(repo, "packages/core/src/base.ts"), "export const base = false\n")
541+
runGit("add", ".")
542+
runGit("commit", "-m", "initial")
543+
const staleBaseSha = runGit("rev-parse", "HEAD")
544+
545+
runGit("checkout", "-b", "feature")
546+
fs.writeFileSync(path.join(repo, "packages/core/src/pr.ts"), "export const pr = true\n")
547+
runGit("commit", "-am", "change pull request")
548+
549+
runGit("checkout", "main")
550+
fs.writeFileSync(path.join(repo, "packages/core/src/base.ts"), "export const base = true\n")
551+
runGit("commit", "-am", "advance base branch")
552+
const currentBaseSha = runGit("rev-parse", "HEAD")
553+
runGit("merge", "--no-ff", "feature", "-m", "synthetic pull request merge")
554+
const mergeSha = runGit("rev-parse", "HEAD")
555+
const mergeResultBaseSha = runGit("rev-parse", `${mergeSha}^1`)
556+
assert.equal(mergeResultBaseSha, currentBaseSha)
557+
558+
assert.deepEqual(
559+
selectFromGit(repo, staleBaseSha, mergeSha).packages[0].files.map(({ path: filePath }) => filePath),
560+
["packages/core/src/base.ts", "packages/core/src/pr.ts"],
561+
)
562+
assert.deepEqual(
563+
selectFromGit(repo, mergeResultBaseSha, mergeSha).packages[0].files.map(
564+
({ path: filePath }) => filePath,
565+
),
566+
["packages/core/src/pr.ts"],
567+
)
568+
} finally {
569+
fs.rmSync(repo, { recursive: true, force: true })
570+
}
571+
})
527572
})
528573

529574
describe("mutation exclusions", () => {

0 commit comments

Comments
 (0)