-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
201 lines (173 loc) · 7.92 KB
/
test-without-fix.yml
File metadata and controls
201 lines (173 loc) · 7.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# When a PR contains both test changes and source changes,
# this workflow runs the changed tests WITHOUT the source fix
# to verify that the tests actually reproduce the bug.
# - Tests FAILING without the fix = expected (confirms the test catches the bug)
# - Tests PASSING without the fix = warning (the test might not verify the bugfix)
name: Verify Test Reproduction
on:
pull_request:
permissions:
contents: read
pull-requests: write
jobs:
test-without-fix:
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for changed test and source files
id: check-changes
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
MERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA")
# Get changed test files (only *.test.ts files)
CHANGED_TESTS=$(git diff --name-only "$MERGE_BASE" "$HEAD_SHA" -- 'test/' | grep '\.test\.ts$' || true)
# Get changed source files
CHANGED_SRC=$(git diff --name-only "$MERGE_BASE" "$HEAD_SHA" -- 'src/')
if [ -z "$CHANGED_TESTS" ]; then
echo "No test files changed, skipping"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ -z "$CHANGED_SRC" ]; then
echo "No source files changed (test-only PR), skipping"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "should_run=true" >> "$GITHUB_OUTPUT"
echo "Changed test files:"
echo "$CHANGED_TESTS"
echo ""
echo "Changed source files:"
echo "$CHANGED_SRC"
- name: Set node version
if: steps.check-changes.outputs.should_run == 'true'
uses: actions/setup-node@v6
with:
node-version-file: ".nvmrc"
- name: Reuse npm cache folder
if: steps.check-changes.outputs.should_run == 'true'
uses: actions/cache@v5
env:
cache-name: cache-node-modules
with:
path: |
~/.npm
./node_modules
key: ${{ runner.os }}-npm-test-without-fix-x1-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-npm-test-without-fix-x1-
- name: Apply test changes to base branch code
if: steps.check-changes.outputs.should_run == 'true'
id: apply-patch
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
MERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA")
# Save the test directory changes as a patch
git diff "$MERGE_BASE" "$HEAD_SHA" -- test/ > /tmp/test-changes.patch
if [ ! -s /tmp/test-changes.patch ]; then
echo "Empty patch, nothing to apply"
exit 0
fi
# Checkout the merge base (code state before this PR)
git checkout "$MERGE_BASE"
# Apply only the test changes on top of the unfixed code
git apply /tmp/test-changes.patch
- name: Install dependencies
if: steps.check-changes.outputs.should_run == 'true'
run: npm install || (sleep 15 && npm install) || (sleep 15 && npm install)
- name: Build
if: steps.check-changes.outputs.should_run == 'true'
id: build
continue-on-error: true
run: npm run build 2>&1 | tee /tmp/build-output.txt
- name: Run tests (expect failure)
if: steps.check-changes.outputs.should_run == 'true' && steps.build.outcome == 'success'
id: run-tests
continue-on-error: true
run: npm run test:fast:memory 2>&1 | tee /tmp/test-output.txt
- name: Evaluate results
if: steps.check-changes.outputs.should_run == 'true'
id: evaluate
run: |
echo "== Test-Without-Fix Results =="
echo ""
if [ "${{ steps.build.outcome }}" == "failure" ]; then
echo "✅ Build FAILED without the source changes."
echo "This confirms the test requires the source changes from this PR."
COMMENT_ICON="✅"
COMMENT_TITLE="Build FAILED without the source changes (expected)"
COMMENT_BODY="This confirms the source changes in this PR are required for the build to succeed."
OUTPUT_FILE="/tmp/build-output.txt"
elif [ "${{ steps.run-tests.outcome }}" == "failure" ]; then
echo "✅ Tests FAILED without the fix."
echo "This confirms the test correctly reproduces the bug."
COMMENT_ICON="✅"
COMMENT_TITLE="Tests FAILED without the fix (expected)"
COMMENT_BODY="This confirms the changed tests correctly reproduce the bug that the source changes fix."
OUTPUT_FILE="/tmp/test-output.txt"
else
echo "⚠️ Tests PASSED without the fix."
echo "The changed tests do not fail without the source changes from this PR."
echo "Please inspect whether the test changes actually test the bug that the source changes fix."
COMMENT_ICON="⚠️"
COMMENT_TITLE="Tests PASSED without the fix (unexpected)"
COMMENT_BODY="The changed tests do not fail without the source changes from this PR. Please inspect whether the test changes actually test the bug that the source changes fix."
OUTPUT_FILE="/tmp/test-output.txt"
fi
echo ""
echo "This workflow is informational only. Inspect the output above to verify the test reproduces the bug."
# Write comment header to file
{
printf '## %s Verify Test Reproduction: %s\n\n' "$COMMENT_ICON" "$COMMENT_TITLE"
printf '%s\n\n' "$COMMENT_BODY"
printf '%s\n\n' '_This workflow runs the changed tests **without** the source fix to verify they reproduce the bug._'
} > /tmp/pr-comment.md
# Append truncated output if available
if [ -f "$OUTPUT_FILE" ]; then
TOTAL_LINES=$(wc -l < "$OUTPUT_FILE")
printf '<details>\n<summary>Show output</summary>\n\n```\n' >> /tmp/pr-comment.md
if [ "$TOTAL_LINES" -gt 200 ]; then
printf '...(truncated, showing last 200 of %s lines)\n' "$TOTAL_LINES" >> /tmp/pr-comment.md
tail -200 "$OUTPUT_FILE" >> /tmp/pr-comment.md
else
cat "$OUTPUT_FILE" >> /tmp/pr-comment.md
fi
printf '\n```\n\n</details>\n\n' >> /tmp/pr-comment.md
fi
echo "[View full workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> /tmp/pr-comment.md
exit 0
- name: Post or update PR comment
if: steps.check-changes.outputs.should_run == 'true'
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const commentBody = fs.readFileSync('/tmp/pr-comment.md', 'utf8');
const marker = '<!-- test-without-fix-bot -->';
const body = marker + '\n' + commentBody;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}