implements PLN-0010 builder pipeline entrypoints

This commit is contained in:
2026-03-30 19:01:07 +01:00
parent df8a98488a
commit c467a2642f
10 changed files with 217 additions and 32 deletions
@@ -2,6 +2,7 @@ package p.studio.compiler.integration;
import org.junit.jupiter.api.Test;
import p.studio.compiler.messages.BuilderPipelineConfig;
import p.studio.compiler.models.BuilderPipelineContext;
import p.studio.compiler.workspaces.BuilderPipelineService;
import p.studio.utilities.logs.LogAggregator;
@@ -14,26 +15,76 @@ import static org.junit.jupiter.api.Assertions.*;
class MainProjectPipelineIntegrationTest {
@Test
void shouldCompileMainProjectAndWriteProgramBytecode() throws IOException {
void analyzeShouldNotWriteProgramBytecode() throws IOException {
final var projectRoot = projectRoot();
final var outputPath = resetOutput(projectRoot);
final var logs = bufferedLogs();
final var context = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, projectRoot.toString()));
final var snapshot = assertDoesNotThrow(
() -> BuilderPipelineService.INSTANCE.analyze(context, logs),
() -> "analyze unexpectedly failed for " + projectRoot);
assertNotNull(snapshot.resolvedWorkspace(), "analyze must expose resolved workspace");
assertNotNull(snapshot.fileTable(), "analyze must expose file table");
assertNotNull(snapshot.irBackend(), "analyze must expose frontend semantic result");
assertFalse(Files.exists(outputPath), "analyze must not write output: " + outputPath);
}
@Test
void compileShouldProduceInMemoryBytecodeWithoutWritingProgramBytecode() throws IOException {
final var projectRoot = projectRoot();
final var outputPath = resetOutput(projectRoot);
final var logs = bufferedLogs();
final var context = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, projectRoot.toString()));
final var result = assertDoesNotThrow(
() -> BuilderPipelineService.INSTANCE.compile(context, logs),
() -> "compile unexpectedly failed for " + projectRoot);
assertNotNull(result.analysisSnapshot(), "compile must retain analysis snapshot");
assertNotNull(result.bytecodeModule(), "compile must expose bytecode module");
assertNotNull(result.bytecodeBytes(), "compile must expose bytecode bytes");
assertTrue(result.bytecodeBytes().length > 0, "compile must expose non-empty bytecode bytes");
assertFalse(Files.exists(outputPath), "compile must not write output: " + outputPath);
}
@Test
void buildShouldWriteProgramBytecode() throws IOException {
final var repoRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize());
final var projectRoot = repoRoot.resolve("test-projects").resolve("main");
final var outputPath = resetOutput(projectRoot);
final var logs = bufferedLogs();
final var context = BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, projectRoot.toString()));
final var result = assertDoesNotThrow(
() -> BuilderPipelineService.INSTANCE.build(context, logs),
() -> "build unexpectedly failed for " + projectRoot);
assertEquals(outputPath, result.bytecodeArtifactPath(), "build must expose written artifact path");
assertTrue(Files.exists(outputPath), "build did not write output: " + outputPath);
assertTrue(Files.size(outputPath) > 0, "build wrote empty bytecode file: " + outputPath);
}
private Path projectRoot() {
final var repoRoot = findRepoRoot(Path.of("").toAbsolutePath().normalize());
return repoRoot.resolve("test-projects").resolve("main");
}
private Path resetOutput(final Path projectRoot) throws IOException {
final var outputPath = projectRoot.resolve("build").resolve("program.pbx");
Files.createDirectories(outputPath.getParent());
Files.deleteIfExists(outputPath);
return outputPath;
}
private LogAggregator bufferedLogs() {
final var logsOut = new StringBuilder();
final var logs = LogAggregator.with(line -> {
return LogAggregator.with(line -> {
logsOut.append(line);
if (!line.endsWith("\n")) {
logsOut.append('\n');
}
});
assertDoesNotThrow(
() -> BuilderPipelineService.INSTANCE.run(new BuilderPipelineConfig(false, projectRoot.toString()), logs),
logsOut::toString);
assertTrue(Files.exists(outputPath), "pipeline did not write output: " + outputPath + "\n" + logsOut);
assertTrue(Files.size(outputPath) > 0, "pipeline wrote empty bytecode file: " + outputPath + "\n" + logsOut);
}
private Path findRepoRoot(final Path start) {