Skip to content

Commit d7d2f7c

Browse files
authored
test(web): complete externally consumable plugin contract kit (#8370)
* test(web): add legacy plugin contract fixture Add a test-scope fixture that drives the real ShenyuWebHandler instead of copying its chain cursor, with role-aware recording plugins and assertions for completion, failure, cancellation, skip and repeated subscriptions. The focused test-jar is the basis for the external consumer in the follow-up change. Refs #8202 * test(web): complete external plugin contract kit * fix(ci): validate Maven wrapper before independent jobs. --------- Co-authored-by: klT45 <klT45@users.noreply.github.com>
1 parent c9e5fe8 commit d7d2f7c

23 files changed

Lines changed: 3041 additions & 62 deletions
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one or more
4+
# contributor license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright ownership.
6+
# The ASF licenses this file to You under the Apache License, Version 2.0
7+
# (the "License"); you may not use this file except in compliance with
8+
# the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
set -euo pipefail
19+
20+
wrapper_jar=.mvn/wrapper/maven-wrapper.jar
21+
wrapper_main=org/apache/maven/wrapper/MavenWrapperMain.class
22+
if [[ -r "$wrapper_jar" ]] && jar tf "$wrapper_jar" | grep -Fx "$wrapper_main" > /dev/null; then
23+
exit 0
24+
fi
25+
26+
wrapper_url="$(awk -F= '$1 == "wrapperUrl" { print substr($0, index($0, "=") + 1); exit }' .mvn/wrapper/maven-wrapper.properties)"
27+
if [[ -z "$wrapper_url" ]]; then
28+
echo "Could not find wrapperUrl in .mvn/wrapper/maven-wrapper.properties."
29+
exit 1
30+
fi
31+
32+
wrapper_tmp="$(mktemp .mvn/wrapper/maven-wrapper.jar.XXXXXX)"
33+
trap 'rm -f "$wrapper_tmp"' EXIT
34+
curl --fail --location --retry 5 --retry-all-errors --retry-delay 2 \
35+
--output "$wrapper_tmp" "$wrapper_url"
36+
if ! jar tf "$wrapper_tmp" | grep -Fx "$wrapper_main" > /dev/null; then
37+
echo "Downloaded Maven wrapper JAR does not contain $wrapper_main."
38+
exit 1
39+
fi
40+
mv "$wrapper_tmp" "$wrapper_jar"

‎.github/scripts/test-ci-workflows.mjs‎

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ test('the stable build gate includes every independent correctness check', () =>
8989
});
9090

9191

92+
test('the plugin contract consumer resolves packaged artifacts in a separate Maven invocation', () => {
93+
const jobs = workflows.get('ci.yml').jobs;
94+
const job = jobs.plugin_contract;
95+
assert.ok(job, 'The external consumer must run in CI');
96+
assert.deepEqual(Array.from(job.needs), ['changes']);
97+
assert.ok(job.if.includes("needs.changes.outputs.code == 'true'"));
98+
const commands = job.steps.filter(step => step.run).map(step => step.run);
99+
const producer = commands.findIndex(command => command.includes('-pl shenyu-web -am install'));
100+
const consumer = commands.findIndex(command => command.includes('-f shenyu-examples/shenyu-examples-plugin-contract/pom.xml'));
101+
assert.ok(producer >= 0 && consumer > producer, 'Install the producer before testing the separate consumer');
102+
assert.ok(commands[producer].includes('-DskipTests'));
103+
assert.ok(!commands[producer].includes('-Dmaven.test.skip'));
104+
assert.ok(commands[consumer].includes('test org.apache.rat:apache-rat-plugin:0.15:check'));
105+
assert.ok(commands[consumer].includes('-DfailIfNoTests=true'));
106+
assert.ok(!commands[consumer].includes('-am'));
107+
assert.ok(!/-D(?:skipTests|maven\.test\.skip|checkstyle\.skip|rat\.skip)(?:[=\s]|$)/.test(commands[consumer]));
108+
assert.ok(jobs.requirement.needs.includes('plugin_contract'));
109+
assert.ok(jobs.requirement.steps.some(step => step.run?.includes('needs.plugin_contract.result')));
110+
});
111+
92112
test('a slow starter subtree runs once in its own shard', () => {
93113
const groups = workflows.get('ci.yml').jobs.test_group.strategy.matrix.include;
94114
const agent = groups.find(group => group.name === 'starters-agent');
@@ -283,18 +303,28 @@ test('aggregate jobs still report failures but do not keep cancelled PR runs ali
283303
}
284304
});
285305

286-
test('ingress validates the Maven wrapper before its first Maven invocation', () => {
287-
const steps = workflows.get('integrated-test-k8s-ingress.yml').jobs.build.steps;
288-
const preflight = steps.findIndex(step => step.name === 'Ensure Maven wrapper JAR');
289-
const firstMaven = steps.findIndex(step => /\.\/mvnw\b/.test(step.run ?? ''));
290-
assert.ok(preflight >= 0 && firstMaven > preflight);
291-
assert.equal(steps[preflight].shell, 'bash');
306+
test('CI validates the Maven wrapper before every independent Maven job', () => {
307+
for (const [name, job] of Object.entries(workflows.get('ci.yml').jobs)) {
308+
const steps = job.steps ?? [];
309+
const firstMaven = steps.findIndex(step => /\.\/mvnw\b/.test(step.run ?? ''));
310+
if (firstMaven < 0) continue;
311+
const preflight = steps.findIndex(step => step.run === 'bash .github/scripts/ensure-maven-wrapper.sh');
312+
assert.ok(preflight >= 0 && preflight < firstMaven, name);
313+
}
314+
});
315+
316+
test('integration builds validate the Maven wrapper before their first Maven invocation', () => {
317+
for (const name of ['integrated-test-k8s-ingress.yml', 'integrated-test.yml']) {
318+
const steps = workflows.get(name).jobs.build.steps;
319+
const preflight = steps.findIndex(step => step.run === 'bash .github/scripts/ensure-maven-wrapper.sh');
320+
const firstMaven = steps.findIndex(step => /\.\/mvnw\b/.test(step.run ?? ''));
321+
assert.ok(preflight >= 0 && firstMaven > preflight, name);
322+
assert.equal(steps[preflight].shell, 'bash');
323+
}
292324
});
293325

294-
test('ingress Maven wrapper preflight handles cached, downloaded and failed artifacts', { timeout: 45000 }, async t => {
295-
const preflight = workflows.get('integrated-test-k8s-ingress.yml').jobs.build.steps
296-
.find(step => step.name === 'Ensure Maven wrapper JAR');
297-
assert.ok(preflight, 'The ingress job must validate the wrapper before running Maven');
326+
test('Maven wrapper preflight handles cached, downloaded and failed artifacts', { timeout: 45000 }, async t => {
327+
const preflight = readFileSync(resolve(root, '.github/scripts/ensure-maven-wrapper.sh'), 'utf8');
298328
const temporary = mkdtempSync(resolve(root, '.github/scripts/.wrapper-test-'));
299329
t.after(() => rmSync(temporary, { recursive: true, force: true }));
300330

@@ -342,7 +372,7 @@ test('ingress Maven wrapper preflight handles cached, downloaded and failed arti
342372
writeFileSync(resolve(wrapper, 'maven-wrapper.properties'), fixture.missingUrl
343373
? 'distributionUrl=unused\n'
344374
: `wrapperUrl=http://127.0.0.1:${server.address().port}/wrapper.jar\n`);
345-
const execution = run('bash', ['--noprofile', '--norc', '-e', '-o', 'pipefail', '-c', preflight.run], {
375+
const execution = run('bash', ['--noprofile', '--norc', '-e', '-o', 'pipefail', '-c', preflight], {
346376
cwd: working,
347377
env: { ...process.env, NO_PROXY: '127.0.0.1', no_proxy: '127.0.0.1' },
348378
timeout: 20000,

‎.github/workflows/ci.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ jobs:
125125
distribution: "temurin"
126126
cache: maven
127127

128+
- name: Ensure Maven wrapper JAR
129+
run: bash .github/scripts/ensure-maven-wrapper.sh
128130
- name: Replay registration contract and check resolved client boundaries
129131
run: |
130132
python3 .github/scripts/test-client-boundary.py
@@ -153,9 +155,35 @@ jobs:
153155
with:
154156
java-version: "17"
155157
distribution: "temurin"
158+
- name: Ensure Maven wrapper JAR
159+
run: bash .github/scripts/ensure-maven-wrapper.sh
156160
- name: Run Apache RAT check
157161
run: ./mvnw -B -ntp apache-rat:check
158162

163+
plugin_contract:
164+
needs: [changes]
165+
runs-on: ubuntu-latest
166+
timeout-minutes: 20
167+
if: github.repository == 'apache/shenyu' && needs.changes.outputs.code == 'true'
168+
steps:
169+
- uses: actions/checkout@v4
170+
- uses: ./actions/setup-java-with-retry
171+
with:
172+
java-version: "17"
173+
distribution: "temurin"
174+
cache: maven
175+
- name: Ensure Maven wrapper JAR
176+
run: bash .github/scripts/ensure-maven-wrapper.sh
177+
- name: Install the packaged plugin contract kit
178+
run: |
179+
bash .github/scripts/maven-with-retry.sh ./mvnw -B -ntp -pl shenyu-web -am install \
180+
-DskipTests -DskipRemoteResources=true -Djacoco.skip=true -Dmaven.javadoc.skip=true
181+
- name: Test the external plugin contract consumer
182+
run: |
183+
bash .github/scripts/maven-with-retry.sh ./mvnw -B -ntp \
184+
-f shenyu-examples/shenyu-examples-plugin-contract/pom.xml \
185+
test org.apache.rat:apache-rat-plugin:0.15:check -DfailIfNoTests=true -Djacoco.skip=true
186+
159187
pr_build:
160188
needs: changes
161189
runs-on: ubuntu-latest
@@ -170,6 +198,8 @@ jobs:
170198
distribution: "temurin"
171199
cache: maven
172200

201+
- name: Ensure Maven wrapper JAR
202+
run: bash .github/scripts/ensure-maven-wrapper.sh
173203
- name: Build with Maven
174204
shell: bash
175205
env:
@@ -196,6 +226,8 @@ jobs:
196226
distribution: "temurin"
197227
cache: maven
198228

229+
- name: Ensure Maven wrapper JAR
230+
run: bash .github/scripts/ensure-maven-wrapper.sh
199231
- name: Build ShenYu local Maven repository
200232
shell: bash
201233
run: |
@@ -261,6 +293,8 @@ jobs:
261293
with:
262294
name: shenyu-local-maven-repository
263295
path: /tmp/shenyu-m2
296+
- name: Ensure Maven wrapper JAR
297+
run: bash .github/scripts/ensure-maven-wrapper.sh
264298
- name: Restore ShenYu local Maven repository
265299
run: bash .github/scripts/restore-shenyu-local-repo.sh /tmp/shenyu-m2
266300
# The producer already checks main and test source style for the complete reactor.
@@ -323,6 +357,8 @@ jobs:
323357
with:
324358
name: shenyu-local-maven-repository
325359
path: /tmp/shenyu-m2
360+
- name: Ensure Maven wrapper JAR
361+
run: bash .github/scripts/ensure-maven-wrapper.sh
326362
- name: Restore ShenYu local Maven repository
327363
run: bash .github/scripts/restore-shenyu-local-repo.sh /tmp/shenyu-m2
328364
# Reuse the producer's Checkstyle result; preserve all Java 21 test execution.
@@ -355,6 +391,7 @@ jobs:
355391
- rat_check
356392
- agent_gateway_migrations
357393
- registry_dependencies
394+
- plugin_contract
358395
- check-license-header
359396
- pr_build
360397
- build_local_repo
@@ -367,6 +404,7 @@ jobs:
367404
[[ "${{ needs.changes.result }}" == "success" ]] || exit 1
368405
if [[ "${{ needs.changes.outputs.code }}" == "true" ]]; then
369406
[[ "${{ needs.registry_dependencies.result }}" == "success" ]] || exit 1
407+
[[ "${{ needs.plugin_contract.result }}" == "success" ]] || exit 1
370408
[[ "${{ needs.agent_gateway_migrations.result }}" == "success" ]] || exit 1
371409
fi
372410
if [[ "${{ needs.changes.outputs.rat_required }}" == "true" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then

‎.github/workflows/integrated-test-k8s-ingress.yml‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,7 @@ jobs:
108108
109109
- name: Ensure Maven wrapper JAR
110110
shell: bash
111-
run: |
112-
wrapper_jar=.mvn/wrapper/maven-wrapper.jar
113-
wrapper_main=org/apache/maven/wrapper/MavenWrapperMain.class
114-
if [[ -r "$wrapper_jar" ]] && jar tf "$wrapper_jar" | grep -Fx "$wrapper_main" > /dev/null; then
115-
exit 0
116-
fi
117-
118-
wrapper_url="$(awk -F= '$1 == "wrapperUrl" { print substr($0, index($0, "=") + 1); exit }' .mvn/wrapper/maven-wrapper.properties)"
119-
if [[ -z "$wrapper_url" ]]; then
120-
echo "Could not find wrapperUrl in .mvn/wrapper/maven-wrapper.properties."
121-
exit 1
122-
fi
123-
124-
wrapper_tmp="$(mktemp .mvn/wrapper/maven-wrapper.jar.XXXXXX)"
125-
trap 'rm -f "$wrapper_tmp"' EXIT
126-
curl --fail --location --retry 5 --retry-all-errors --retry-delay 2 \
127-
--output "$wrapper_tmp" "$wrapper_url"
128-
if ! jar tf "$wrapper_tmp" | grep -Fx "$wrapper_main" > /dev/null; then
129-
echo "Downloaded Maven wrapper JAR does not contain $wrapper_main."
130-
exit 1
131-
fi
132-
mv "$wrapper_tmp" "$wrapper_jar"
111+
run: bash .github/scripts/ensure-maven-wrapper.sh
133112

134113
- name: Build with Maven
135114
shell: bash

‎.github/workflows/integrated-test.yml‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,7 @@ jobs:
106106
**/pom.xml
107107
- name: Ensure Maven wrapper JAR
108108
shell: bash
109-
run: |
110-
wrapper_jar=.mvn/wrapper/maven-wrapper.jar
111-
wrapper_main=org/apache/maven/wrapper/MavenWrapperMain.class
112-
if [[ -r "$wrapper_jar" ]] && jar tf "$wrapper_jar" | grep -Fx "$wrapper_main" > /dev/null; then
113-
exit 0
114-
fi
115-
116-
wrapper_url="$(awk -F= '$1 == "wrapperUrl" { print substr($0, index($0, "=") + 1); exit }' .mvn/wrapper/maven-wrapper.properties)"
117-
if [[ -z "$wrapper_url" ]]; then
118-
echo "Could not find wrapperUrl in .mvn/wrapper/maven-wrapper.properties."
119-
exit 1
120-
fi
121-
122-
wrapper_tmp="$(mktemp .mvn/wrapper/maven-wrapper.jar.XXXXXX)"
123-
trap 'rm -f "$wrapper_tmp"' EXIT
124-
curl --fail --location --retry 5 --retry-all-errors --retry-delay 2 \
125-
--output "$wrapper_tmp" "$wrapper_url"
126-
if ! jar tf "$wrapper_tmp" | grep -Fx "$wrapper_main" > /dev/null; then
127-
echo "Downloaded Maven wrapper JAR does not contain $wrapper_main."
128-
exit 1
129-
fi
130-
mv "$wrapper_tmp" "$wrapper_jar"
109+
run: bash .github/scripts/ensure-maven-wrapper.sh
131110
- name: Build with Maven
132111
shell: bash
133112
run: |

0 commit comments

Comments
 (0)