Skip to content

Commit eb20346

Browse files
authored
test: Add minimal Java 27 UI test coverage (#1767)
* Add minimal Java 27 UI test coverage * test: capture Java27 terminal Gradle diagnostics * test: select a single CI executable for Gradle diagnostics * test: bind Java27 CI builds to provisioned Gradle * ci: authenticate GitHub release metadata requests * test: retain AutoTest logs for PR1767 failure diagnosis * test: synchronize Java 27 diagnostic file reloads * ci: centralize per-case AutoTest logs and diagnostics * ci: delegate artifacts to published AutoTest collector * ci: organize AutoTest config and remove local regression tests
1 parent 7c60d51 commit eb20346

21 files changed

Lines changed: 1194 additions & 8 deletions

‎.github/workflows/e2e-autotest.yml‎

Lines changed: 133 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ jobs:
119119
- name: Checkout
120120
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
121121

122+
- name: Prepare case artifact directory
123+
shell: pwsh
124+
env:
125+
AUTOTEST_PLAN: ${{ matrix.plan }}
126+
run: |
127+
$plan = $env:AUTOTEST_PLAN
128+
if ($plan -notmatch '^[a-z0-9]+(?:-[a-z0-9]+)*$') { throw "Invalid AutoTest plan name: $plan" }
129+
$outputDirectory = Join-Path (Join-Path $env:GITHUB_WORKSPACE "test-results") $plan
130+
# AutoTest clears --output at startup; keep pre-run logs outside it.
131+
$stagingDirectory = Join-Path $env:RUNNER_TEMP "autotest-$plan"
132+
New-Item -ItemType Directory -Path $outputDirectory, (Join-Path $outputDirectory "logs") -Force | Out-Null
133+
New-Item -ItemType Directory -Path $stagingDirectory -Force | Out-Null
134+
"AUTOTEST_OUTPUT_DIR=$outputDirectory" >> $env:GITHUB_ENV
135+
"AUTOTEST_STAGING_DIR=$stagingDirectory" >> $env:GITHUB_ENV
136+
if ($plan.Contains("java27")) {
137+
$terminalDirectory = Join-Path $stagingDirectory "terminal"
138+
"JAVA27_DIAGNOSTICS_DIR=$terminalDirectory" >> $env:GITHUB_ENV
139+
}
140+
122141
- name: Clone vscode-java (test projects)
123142
run: git clone --depth 1 https://github.com/redhat-developer/vscode-java.git ../vscode-java
124143

@@ -130,6 +149,42 @@ jobs:
130149
with:
131150
node-version: 22
132151

152+
- name: Install resolved AutoTest CLI
153+
if: always()
154+
run: |
155+
npm install -g "@vscjava/vscode-autotest@${{ needs.discover.outputs.autotest_version }}"
156+
npm list -g @vscjava/vscode-autotest --depth=0
157+
158+
- name: Setup Java 27 (for java27 test plans)
159+
if: contains(matrix.plan, 'java27')
160+
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
161+
with:
162+
distribution: temurin
163+
java-version: 27
164+
165+
- name: Configure JDK 27 path for runner OS
166+
if: contains(matrix.plan, 'java27')
167+
shell: pwsh
168+
run: |
169+
$planFile = "test-plans/${{ matrix.plan }}.yaml"
170+
if ($IsWindows) {
171+
$target = "C:\Program Files\Java\jdk-27"
172+
New-Item -ItemType Junction -Path $target -Target $env:JAVA_HOME -Force | Out-Null
173+
} else {
174+
$target = "/opt/jdk-27"
175+
sudo mkdir -p /opt
176+
sudo ln -sfn $env:JAVA_HOME $target
177+
(Get-Content $planFile -Raw) -replace 'C:\\\\Program Files\\\\Java\\\\jdk-27', $target | Set-Content $planFile
178+
}
179+
"JAVA27_HOME=$target" >> $env:GITHUB_ENV
180+
Write-Host "Java 27 project toolchain: $target"
181+
182+
- name: Setup Gradle for Java 27
183+
if: contains(matrix.plan, 'java27') && contains(matrix.plan, 'gradle')
184+
uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
185+
with:
186+
gradle-version: '9.8.1'
187+
133188
- name: Setup Java 25 (for java25 test plans)
134189
if: contains(matrix.plan, 'java25')
135190
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
@@ -164,10 +219,22 @@ jobs:
164219
distribution: temurin
165220
java-version: 21
166221

167-
- name: Install resolved AutoTest CLI
222+
- name: Bind Gradle Java 27 toolchain
223+
if: matrix.plan == 'java-gradle-java27'
224+
shell: pwsh
168225
run: |
169-
npm install -g "@vscjava/vscode-autotest@${{ needs.discover.outputs.autotest_version }}"
170-
npm list -g @vscjava/vscode-autotest --depth=0
226+
$ciGradle = (Get-Command gradle -CommandType Application -ErrorAction Stop | Select-Object -First 1).Source
227+
$versionLog = Join-Path $env:AUTOTEST_STAGING_DIR "gradle-version.log"
228+
$PSNativeCommandUseErrorActionPreference = $false
229+
$gradleVersion = & $ciGradle --version 2>&1 | Out-String
230+
$versionExit = $LASTEXITCODE
231+
"Command: $ciGradle --version`n$gradleVersion" | Set-Content -LiteralPath $versionLog
232+
if ($versionExit -ne 0) { throw "CI Gradle version probe exited with $versionExit; see diagnostics/ci/gradle-version.log in this case's results artifact." }
233+
if ($gradleVersion -notmatch '(?m)^Gradle 9\.8\.1\s*$') {
234+
throw "CI did not select the provisioned Gradle 9.8.1: $ciGradle; see $versionLog"
235+
}
236+
"JAVA27_CI_GRADLE=$ciGradle" >> $env:GITHUB_ENV
237+
Write-Host "Bound Gradle 9.8.1: $ciGradle"
171238
172239
- name: Setup virtual display (Linux)
173240
if: runner.os == 'Linux'
@@ -228,6 +295,7 @@ jobs:
228295
229296
$githubHeaders = @{
230297
Accept = "application/vnd.github+json"
298+
Authorization = "Bearer $env:GITHUB_TOKEN"
231299
"X-GitHub-Api-Version" = "2022-11-28"
232300
"User-Agent" = "vscode-java-pack-autotest"
233301
}
@@ -355,6 +423,39 @@ jobs:
355423
Set-Content $planFile $content
356424
Write-Host "Patched $planFile to install vscode-java through vscode-java-pack before applying VSIX overrides."
357425
426+
- name: Record case toolchain diagnostics
427+
if: always()
428+
shell: pwsh
429+
run: |
430+
$identity = [ordered]@{
431+
javaHome = $env:JAVA_HOME
432+
projectJavaHome = $env:JAVA27_HOME
433+
gradle = $env:JAVA27_CI_GRADLE
434+
runnerOs = $env:RUNNER_OS
435+
runnerArch = $env:RUNNER_ARCH
436+
path = $env:PATH
437+
}
438+
$PSNativeCommandUseErrorActionPreference = $false
439+
foreach ($probe in @(
440+
@{ Name = "node"; Arguments = @("--version") },
441+
@{ Name = "java"; Arguments = @("-XshowSettings:properties", "-version") }
442+
)) {
443+
$command = Get-Command $probe.Name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
444+
if (-not $command) {
445+
Write-Warning "$($probe.Name) unavailable; its CI setup may have failed."
446+
$identity[$probe.Name] = $null
447+
continue
448+
}
449+
$identity[$probe.Name] = $command.Source
450+
$arguments = $probe.Arguments
451+
$version = & $command.Source @arguments 2>&1 | Out-String
452+
$versionExit = $LASTEXITCODE
453+
$identity["$($probe.Name)VersionExitCode"] = $versionExit
454+
$version | Set-Content -LiteralPath (Join-Path $env:AUTOTEST_STAGING_DIR "$($probe.Name)-version.log")
455+
if ($versionExit -ne 0) { Write-Warning "$($probe.Name) version probe failed; see its diagnostic log." }
456+
}
457+
$identity | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $env:AUTOTEST_STAGING_DIR "ci-toolchain.json")
458+
358459
- name: Run ${{ matrix.plan }}
359460
shell: pwsh
360461
env:
@@ -365,6 +466,13 @@ jobs:
365466
$autotestArgs = @(
366467
"run",
367468
"test-plans/${{ matrix.plan }}.yaml",
469+
"--output",
470+
$env:AUTOTEST_OUTPUT_DIR,
471+
"--logs",
472+
"--log-output",
473+
(Join-Path $env:AUTOTEST_OUTPUT_DIR "logs"),
474+
"--artifacts-config",
475+
(Join-Path "test-plans" "config" "artifacts.yaml"),
368476
"--analysis-mode",
369477
"case"
370478
)
@@ -388,14 +496,29 @@ jobs:
388496
}
389497
390498
Write-Host "Running: autotest $($autotestArgs -join ' ')"
391-
& autotest @autotestArgs
499+
$consoleLog = Join-Path $env:AUTOTEST_STAGING_DIR "console.log"
500+
$PSNativeCommandUseErrorActionPreference = $false
501+
& autotest @autotestArgs *> $consoleLog
502+
$testExit = $LASTEXITCODE
503+
Write-Host "AutoTest exit code: $testExit. Logs and diagnostics are in this case's results artifact."
504+
if ($testExit -ne 0) {
505+
Write-Host "::error::AutoTest exited with code $testExit. See this case's results artifact for logs and diagnostics."
506+
}
507+
exit $testExit
508+
509+
- name: Collect case logs and diagnostics
510+
if: always()
511+
shell: pwsh
512+
run: |
513+
& autotest collect --output $env:AUTOTEST_OUTPUT_DIR --artifacts-config (Join-Path "test-plans" "config" "artifacts.yaml") --plan "test-plans/${{ matrix.plan }}.yaml"
514+
exit $LASTEXITCODE
392515
393516
- name: Upload results
394517
if: always()
395518
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
396519
with:
397520
name: results-${{ matrix.plan }}-${{ matrix.os }}
398-
path: test-results/
521+
path: test-results/${{ matrix.plan }}/
399522
retention-days: 30
400523

401524
# ── Job 3: Aggregate analysis ───────────────────────────
@@ -430,9 +553,11 @@ jobs:
430553
for dir in all-results/results-*/; do
431554
artifact=$(basename "$dir") # results-<plan>-<os>
432555
suffix="${artifact#results-}" # <plan>-<os>
433-
find "$dir" -name "results.json" -exec dirname {} \; | while read d; do
434-
cp -r "$d" "test-results/$suffix"
435-
done
556+
if [ -f "$dir/results.json" ]; then
557+
cp -r "$dir" "test-results/$suffix"
558+
else
559+
echo "::warning::No results.json in $artifact; setup/startup logs remain in that artifact."
560+
fi
436561
done
437562
echo "Organized results:"
438563
ls test-results/
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
const assert = require("node:assert/strict");
5+
const { createHash } = require("node:crypto");
6+
const fs = require("node:fs/promises");
7+
const vscode = require("vscode");
8+
9+
const COMMAND = "java27.autotest.insertUnresolvedTypeAfterClose";
10+
const SOURCE_LEVEL = "org.eclipse.jdt.core.compiler.source";
11+
const INSERTION = "MissingJava27Type sentinel;";
12+
const INSERTION_LINE = 3;
13+
const CHANNEL = "Java 27 AutoTest";
14+
const COMPLETED = "REOPEN_INSERTION_CONFIRMED";
15+
16+
const logicalText = text => text.replace(/\r\n/g, "\n");
17+
const hash = text => createHash("sha256").update(logicalText(text)).digest("hex");
18+
19+
async function waitFor(check, description, deadline) {
20+
while (Date.now() < deadline) {
21+
if (check()) {
22+
return;
23+
}
24+
await new Promise(resolve => setTimeout(resolve, 50));
25+
}
26+
throw new Error(`Timed out waiting for ${description}`);
27+
}
28+
29+
async function beforeDeadline(promise, description, deadline) {
30+
let timer;
31+
try {
32+
return await Promise.race([
33+
promise,
34+
new Promise((_, reject) => {
35+
timer = setTimeout(() => reject(new Error(`Timed out waiting for ${description}`)),
36+
Math.max(0, deadline - Date.now()));
37+
}),
38+
]);
39+
} finally {
40+
clearTimeout(timer);
41+
}
42+
}
43+
44+
async function insertAfterClose(output) {
45+
const deadline = Date.now() + 60_000;
46+
const record = (phase, fields = {}) => output.info(JSON.stringify({
47+
time: new Date().toISOString(), phase, ...fields,
48+
}));
49+
const folder = vscode.workspace.workspaceFolders?.[0];
50+
assert(folder, "The Java 27 fixture workspace must be open");
51+
const uri = vscode.Uri.joinPath(folder.uri, "src", "main", "java", "example", "PrimitivePatterns.java");
52+
const isTarget = candidate => candidate.toString() === uri.toString();
53+
const document = vscode.workspace.textDocuments.find(candidate => isTarget(candidate.uri));
54+
assert(document && !document.isClosed, "PrimitivePatterns.java must be an open text document");
55+
assert(!document.isDirty, "Refusing to close a document with unsaved edits");
56+
const original = await fs.readFile(uri.fsPath, "utf8");
57+
assert.equal(logicalText(document.getText()), logicalText(original), "Editor and disk contents differ");
58+
assert(!original.includes(INSERTION), "The unresolved type must not already exist");
59+
60+
const extension = vscode.extensions.getExtension("redhat.java");
61+
assert(extension, "Language Support for Java is not installed");
62+
const java = await beforeDeadline(extension.activate(), "Java extension activation", deadline);
63+
assert(typeof java?.serverReady === "function" && typeof java?.getProjectSettings === "function",
64+
"Language Support for Java must expose serverReady and getProjectSettings");
65+
assert.equal(await beforeDeadline(java.serverReady(), "the standard Java server", deadline), true);
66+
record("initial-document", { uri: uri.toString(), javaVersion: extension.packageJSON.version,
67+
documentVersion: document.version, textHash: hash(original) });
68+
69+
const roundTrip = async phase => {
70+
const settings = await beforeDeadline(java.getProjectSettings(uri.toString(), [SOURCE_LEVEL]), phase, deadline);
71+
assert.equal(settings?.[SOURCE_LEVEL], "27", "The Java server must confirm source compliance 27");
72+
record(phase, { sourceLevel: settings[SOURCE_LEVEL] });
73+
};
74+
let closed = false;
75+
const closeSubscription = vscode.workspace.onDidCloseTextDocument(candidate => {
76+
if (candidate === document) {
77+
closed = true;
78+
record("client-document-closed", { isClosed: candidate.isClosed });
79+
}
80+
});
81+
try {
82+
const tabs = vscode.window.tabGroups.all.flatMap(group => group.tabs).filter(tab =>
83+
tab.input instanceof vscode.TabInputText && isTarget(tab.input.uri));
84+
assert(tabs.length > 0, "PrimitivePatterns.java must have a text editor tab");
85+
assert.equal(await beforeDeadline(vscode.window.tabGroups.close(tabs), "closing the editor tabs", deadline), true,
86+
"VS Code refused to close the target editor tabs");
87+
await waitFor(() => closed && document.isClosed
88+
&& !vscode.workspace.textDocuments.some(candidate => isTarget(candidate.uri)),
89+
"the actual text-document close event", deadline);
90+
} finally {
91+
closeSubscription.dispose();
92+
}
93+
94+
// JDT processes didClose synchronously; a following request on the same connection is the server barrier.
95+
await roundTrip("server-close-round-trip");
96+
assert.equal(await fs.readFile(uri.fsPath, "utf8"), original, "The source changed while closing");
97+
const lines = original.split("\n");
98+
assert(lines.length >= INSERTION_LINE, "The fixture is missing the insertion line");
99+
lines.splice(INSERTION_LINE, 0, INSERTION);
100+
const updated = lines.join("\n");
101+
let diagnosticEvents = 0;
102+
let contentChanges = 0;
103+
const errors = () => vscode.languages.getDiagnostics(uri).filter(diagnostic =>
104+
diagnostic.severity === vscode.DiagnosticSeverity.Error);
105+
const diagnosticsSubscription = vscode.languages.onDidChangeDiagnostics(event => {
106+
if (event.uris.some(isTarget)) {
107+
diagnosticEvents++;
108+
record("target-diagnostics", { errors: errors().map(diagnostic => ({
109+
code: diagnostic.code, message: diagnostic.message, range: diagnostic.range,
110+
})) });
111+
}
112+
});
113+
const changeSubscription = vscode.workspace.onDidChangeTextDocument(event => {
114+
if (isTarget(event.document.uri)) {
115+
contentChanges += event.contentChanges.length;
116+
record("client-content-change", { changes: event.contentChanges });
117+
}
118+
});
119+
try {
120+
await fs.writeFile(uri.fsPath, updated);
121+
record("disk-written", { textHash: hash(updated), insertions: updated.split(INSERTION).length - 1 });
122+
const reopened = await beforeDeadline(vscode.workspace.openTextDocument(uri), "a fresh text document", deadline);
123+
assert.notEqual(reopened, document, "Reopening must create a new text-document lifecycle");
124+
assert(!reopened.isClosed, "The replacement text document is closed");
125+
assert.equal(logicalText(reopened.getText()), logicalText(updated), "The reopened text differs from disk");
126+
await beforeDeadline(vscode.window.showTextDocument(reopened, { preview: false }), "showing the document", deadline);
127+
await roundTrip("server-open-round-trip");
128+
record("full-document-reopened", { documentVersion: reopened.version, textHash: hash(reopened.getText()) });
129+
await waitFor(() => {
130+
const current = errors();
131+
assert(!current.some(diagnostic => diagnostic.message.includes("Duplicate field")),
132+
"The Java server published a duplicate-field diagnostic after full reopen");
133+
if (diagnosticEvents === 0 || current.length !== 1) {
134+
return false;
135+
}
136+
const diagnostic = current[0];
137+
const code = typeof diagnostic.code === "object" ? diagnostic.code.value : diagnostic.code;
138+
return String(code) === "16777218"
139+
&& diagnostic.message === "MissingJava27Type cannot be resolved to a type"
140+
&& diagnostic.range.start.line === INSERTION_LINE;
141+
}, "one fresh target-file unresolved-type diagnostic", deadline);
142+
assert.equal(contentChanges, 0, "The insertion must not also produce incremental text edits");
143+
assert.equal(await fs.readFile(uri.fsPath, "utf8"), updated, "The inserted source changed unexpectedly");
144+
record("insertion-verified", { errors: 1, diagnosticEvents, contentChanges, textHash: hash(updated) });
145+
output.info(COMPLETED);
146+
} finally {
147+
diagnosticsSubscription.dispose();
148+
changeSubscription.dispose();
149+
}
150+
}
151+
152+
function activate(context) {
153+
const output = vscode.window.createOutputChannel(CHANNEL, { log: true });
154+
context.subscriptions.push(output, vscode.commands.registerCommand(COMMAND, async () => {
155+
output.clear();
156+
try {
157+
await insertAfterClose(output);
158+
} catch (error) {
159+
output.error(`REOPEN_FAILED ${error.stack ?? error.message}`);
160+
vscode.window.showErrorMessage(`Java 27 AutoTest document reopen failed: ${error.message}`);
161+
throw error;
162+
}
163+
}));
164+
}
165+
166+
module.exports = { activate };
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "java27-autotest-support",
3+
"displayName": "Java 27 AutoTest Support",
4+
"publisher": "vscjava",
5+
"version": "0.0.1",
6+
"private": true,
7+
"engines": {
8+
"vscode": "^1.74.0"
9+
},
10+
"main": "./extension.cjs",
11+
"activationEvents": [
12+
"onCommand:java27.autotest.insertUnresolvedTypeAfterClose"
13+
],
14+
"extensionDependencies": [
15+
"redhat.java"
16+
],
17+
"contributes": {
18+
"commands": [
19+
{
20+
"command": "java27.autotest.insertUnresolvedTypeAfterClose",
21+
"title": "Java 27 AutoTest: Insert Unresolved Type After Document Close"
22+
}
23+
]
24+
}
25+
}

0 commit comments

Comments
 (0)