Skip to content

Commit 4be2f96

Browse files
authored
Merge pull request #13 from kernel/hypeship/keep-human-commits-on-coverage-branches
Keep human commits on the MCP coverage branch when publishing
2 parents 88c9a81 + a10b237 commit 4be2f96

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

‎.github/tests/update-coverage-security.test.mjs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ test('changes are restricted to the allowlist before validation', () => {
6161
assert.ok(jobs.generate.indexOf(snapshot) < jobs.generate.indexOf(verify));
6262
assert.match(snapshot, /mcp-update-disallowed-paths\.sh/);
6363
assert.match(snapshot, /git reset -q --hard\n\s+git clean -fdq/);
64-
assert.match(snapshot, /MAIN_SHA: \$\{\{ steps\.prepare\.outputs\.main_sha \}\}/);
65-
assert.match(snapshot, /git reset -q --soft "\$MAIN_SHA"\n\s+git add -A/);
64+
assert.match(snapshot, /AGENT_BASE: \$\{\{ steps\.prepare\.outputs\.agent_base \}\}/);
65+
assert.match(snapshot, /git reset -q --soft "\$AGENT_BASE"\n\s+git add -A/);
6666
const prepare = step('generate', 'Prepare update branch and SDK diff');
6767
assert.match(prepare, /main_sha=\$\(git rev-parse origin\/main\)/);
68+
assert.match(prepare, /git rebase origin\/main; then[\s\S]*else\n\s+echo "rebased=true"/);
69+
assert.match(prepare, /agent_base=\$\(git rev-parse HEAD\)[\s\S]*agent_base_tree=/);
6870
// Only a branch without human commits may be regenerated from main.
6971
assert.match(
7072
prepare,
@@ -107,6 +109,14 @@ test('publishing runs in a separate job that never executes repository code', ()
107109
assert.match(apply, /git apply --index "\$RUNNER_TEMP\/mcp-coverage-update\/changes\.patch"/);
108110
assert.match(apply, /mcp-update-disallowed-paths\.sh/);
109111
assert.match(apply, /100644\|100755\|000000/);
112+
// Publishing rebuilds the exact head the changes were validated on, so human
113+
// commits on the update branch are never squashed or dropped.
114+
assert.match(
115+
apply,
116+
/if \[\[ "\$REBASED" == true \]\]; then\n\s+git switch -c \S+ "\$UPDATE_SHA"\n\s+git rebase -q "\$MAIN_SHA"/,
117+
);
118+
assert.match(apply, /"\$\(git rev-parse 'HEAD\^\{tree\}'\)" != "\$AGENT_BASE_TREE"[\s\S]*exit 1/);
119+
assert.ok(apply.indexOf('AGENT_BASE_TREE') < apply.indexOf('git apply --index'));
110120
const mint = jobs.publish.indexOf(step('publish', 'Generate MCP repository token'));
111121
assert.ok(jobs.publish.indexOf(apply) < mint);
112122
assert.doesNotMatch(jobs.publish.slice(0, mint).join(''), /GH_TOKEN:/);

‎.github/workflows/update-mcp-coverage.yml‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
changed: ${{ steps.snapshot.outputs.changed }}
6262
main_sha: ${{ steps.prepare.outputs.main_sha }}
6363
update_sha: ${{ steps.prepare.outputs.update_sha }}
64+
rebased: ${{ steps.prepare.outputs.rebased }}
65+
agent_base_tree: ${{ steps.prepare.outputs.agent_base_tree }}
6466
env:
6567
SDK_VERSION: ${{ needs.sdk-version.outputs.version }}
6668
SDK_SHA: ${{ needs.sdk-version.outputs.sha }}
@@ -126,10 +128,16 @@ jobs:
126128
fi
127129
echo "::warning::$UPDATE_BRANCH conflicts with main; regenerating it from main."
128130
git switch -C "$UPDATE_BRANCH" origin/main
131+
else
132+
echo "rebased=true" >> "$GITHUB_OUTPUT"
129133
fi
130134
else
131135
git switch -c "$UPDATE_BRANCH" origin/main
132136
fi
137+
# The agent's changes are published on top of this head, so human
138+
# commits on the update branch keep their content and authorship.
139+
echo "agent_base=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
140+
echo "agent_base_tree=$(git rev-parse 'HEAD^{tree}')" >> "$GITHUB_OUTPUT"
133141
134142
old_version=$(jq -er '.dependencies["@onkernel/sdk"]' package.json)
135143
if [[ "$old_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] &&
@@ -221,9 +229,9 @@ jobs:
221229
id: snapshot
222230
working-directory: mcp
223231
env:
224-
MAIN_SHA: ${{ steps.prepare.outputs.main_sha }}
232+
AGENT_BASE: ${{ steps.prepare.outputs.agent_base }}
225233
run: |
226-
git reset -q --soft "$MAIN_SHA"
234+
git reset -q --soft "$AGENT_BASE"
227235
git add -A
228236
git diff --cached --name-only --no-renames -z \
229237
| bash ../.github/scripts/mcp-update-disallowed-paths.sh > "$RUNNER_TEMP/excluded-paths"
@@ -276,6 +284,8 @@ jobs:
276284
SDK_VERSION: ${{ needs.sdk-version.outputs.version }}
277285
MAIN_SHA: ${{ needs.generate.outputs.main_sha }}
278286
UPDATE_SHA: ${{ needs.generate.outputs.update_sha }}
287+
REBASED: ${{ needs.generate.outputs.rebased }}
288+
AGENT_BASE_TREE: ${{ needs.generate.outputs.agent_base_tree }}
279289
UPDATE_BRANCH: mcp-coverage-update
280290
steps:
281291
- name: Checkout updater scripts
@@ -302,7 +312,16 @@ jobs:
302312
run: |
303313
git config user.name 'kernel-internal[bot]'
304314
git config user.email '260533166+kernel-internal[bot]@users.noreply.github.com'
305-
git switch -c "$UPDATE_BRANCH" "$MAIN_SHA"
315+
if [[ "$REBASED" == true ]]; then
316+
git switch -c "$UPDATE_BRANCH" "$UPDATE_SHA"
317+
git rebase -q "$MAIN_SHA"
318+
else
319+
git switch -c "$UPDATE_BRANCH" "$MAIN_SHA"
320+
fi
321+
if [[ "$(git rev-parse 'HEAD^{tree}')" != "$AGENT_BASE_TREE" ]]; then
322+
echo "::error::The rebuilt update branch differs from the one the changes were validated on."
323+
exit 1
324+
fi
306325
git apply --index "$RUNNER_TEMP/mcp-coverage-update/changes.patch"
307326
git diff --cached --name-only --no-renames -z \
308327
| bash ../.github/scripts/mcp-update-disallowed-paths.sh > "$RUNNER_TEMP/disallowed-paths"

0 commit comments

Comments
 (0)