implements PLN-0065

This commit is contained in:
2026-05-05 15:50:55 +01:00
parent e5342e34f7
commit b0073cd7bd
32 changed files with 1445 additions and 277 deletions
@@ -0,0 +1,63 @@
package p.studio.lsp.v1.bootstrap;
import org.junit.jupiter.api.Test;
import p.studio.lsp.api.LspProjectContext;
import p.studio.lsp.api.LspServerBootRequest;
import p.studio.lsp.api.LspServerEndpoint;
import p.studio.lsp.v1.compiler.CompilerLanguageServiceBridge;
import p.studio.lsp.v1.host.ProjectScopedLspServerHost;
import p.studio.lsp.v1.host.ProjectScopedLspServerHostFactory;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class LspV1ServerLifecycleTest {
@Test
void lifecycleBootsAndShutsDownProjectScopedHost() {
final FakeHost host = new FakeHost();
final ProjectScopedLspServerHostFactory factory = (request, compilerBridge) -> host;
final var lifecycle = new LspV1ServerLifecycle(factory, new CompilerLanguageServiceBridge());
final var project = new LspProjectContext("demo", "pbs", Path.of("."));
final var handle = lifecycle.bootServer(LspServerBootRequest.defaults(project));
assertEquals(project, handle.project());
assertEquals("127.0.0.1", handle.endpoint().host());
assertEquals(7777, handle.endpoint().port());
assertTrue(host.started);
lifecycle.shutdownServer(project);
assertTrue(host.closed);
}
@Test
void lifecycleRejectsDoubleBootForSameProject() {
final ProjectScopedLspServerHostFactory factory = (request, compilerBridge) -> new FakeHost();
final var lifecycle = new LspV1ServerLifecycle(factory, new CompilerLanguageServiceBridge());
final var request = LspServerBootRequest.defaults(new LspProjectContext("demo", "pbs", Path.of(".")));
lifecycle.bootServer(request);
assertThrows(IllegalStateException.class, () -> lifecycle.bootServer(request));
}
private static final class FakeHost implements ProjectScopedLspServerHost {
private boolean started;
private boolean closed;
@Override
public LspServerEndpoint start() {
started = true;
return new LspServerEndpoint("127.0.0.1", 7777);
}
@Override
public void close() {
closed = true;
}
}
}
@@ -0,0 +1,46 @@
package p.studio.lsp.v1.boundary;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertTrue;
class LspV1BoundaryTest {
@Test
void lsp4jMustRemainContainedInsideLspV1Sources() throws IOException {
final List<Path> forbiddenRoots = List.of(
Path.of("../prometeu-lsp-api/src/main/java"),
Path.of("../../../prometeu-studio/src/main/java"),
Path.of("../../../prometeu-app/src/main/java"),
Path.of("../../../prometeu-compiler"),
Path.of("../../../prometeu-packer"),
Path.of("../../../prometeu-infra"));
for (final Path root : forbiddenRoots) {
assertNoLsp4jImports(root.normalize());
}
}
private static void assertNoLsp4jImports(final Path root) throws IOException {
if (!Files.exists(root)) {
return;
}
final List<Path> javaFiles;
try (var stream = Files.walk(root)) {
javaFiles = stream
.filter(path -> path.toString().endsWith(".java"))
.toList();
}
for (final Path javaFile : javaFiles) {
final String source = Files.readString(javaFile);
assertTrue(!source.contains("org.eclipse.lsp4j"),
() -> "LSP4J leaked outside lsp-v1: " + javaFile);
}
}
}