package testing
This commit is contained in:
+22
-2
@@ -136,8 +136,28 @@ npm --prefix tools/vscode-extension run compile
|
||||
PROMETEU_VSCODE_DEV_TEST=1 ./gradlew :prometeu-lsp:prometeu-lsp-v1:test --tests '*ExternalSourceDevelopmentHostTest' --console=plain
|
||||
```
|
||||
|
||||
Packaged Studio, installed distributions and installed JAR behavior were explicitly
|
||||
excluded by the user and were not validated. Development resource loading was tested.
|
||||
Packaged Studio was excluded from the initial acceptance above. On 2026-10-07,
|
||||
the user explicitly requested this additional validation. The existing
|
||||
`InstalledKnowledgeTest` now launches its isolated probe with the Java runtime
|
||||
from `installDist`, using distribution JARs plus test probe classes, with its working
|
||||
directory and projects outside the checkout. It asserts that the frontend and LSP
|
||||
bridge load from JARs and that SDK/core resources have `jar:` URLs.
|
||||
|
||||
The packaged gate passed:
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-app:installedKnowledgeTest --console=plain
|
||||
```
|
||||
|
||||
Besides reading the installed documentation and compiling its example, it verifies
|
||||
project-to-SDK, SDK-to-host and SDK-to-core definitions, matching declaration lines,
|
||||
exact SDK/core text against JAR bytes, read-only bundled descriptors, SDK hover and
|
||||
semantic tokens, and source revalidation after reconnect. The project contains only
|
||||
its original manifest and sources after navigation: no bundled source extraction.
|
||||
The first run caught an incorrect cursor position in the test fixture; calculating
|
||||
the position from the source fragment fixed the fixture. No production fix was needed.
|
||||
This is a packaged resource/backend gate; it does not launch the Studio desktop or
|
||||
repeat the VS Code UI checks against the installed process.
|
||||
|
||||
## Pitfalls
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ public final class InstalledKnowledgeProbe {
|
||||
BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, root.toString())), LogAggregator.empty());
|
||||
check(result.diagnostics().stream().noneMatch(issue -> issue.isError()), "Example must compile without errors");
|
||||
check(result.bytecodeBytes().length > 0, "Example must produce bytecode");
|
||||
verifyExternalSources(provider.getClass().getClassLoader());
|
||||
registration.unsubscribe();
|
||||
System.out.println("Installed knowledge verified: " + docs.size() + " references; example compiled");
|
||||
}
|
||||
@@ -59,4 +60,64 @@ public final class InstalledKnowledgeProbe {
|
||||
private static void check(boolean condition, String message) {
|
||||
if (!condition) throw new AssertionError(message);
|
||||
}
|
||||
|
||||
private static void verifyExternalSources(ClassLoader loader) throws Exception {
|
||||
var resource = loader.getResource("game/stdlib/1/sdk/gfx/main.pbs");
|
||||
check(resource != null && resource.getProtocol().equals("jar"), "SDK must be read from a JAR URL");
|
||||
check(p.studio.lsp.services.compiler.CompilerLanguageServiceBridge.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation().getPath().endsWith(".jar"), "LSP bridge must come from installed JAR");
|
||||
Path root = Files.createDirectory(Path.of("external-sources")).toRealPath();
|
||||
Files.createDirectories(root.resolve("src"));
|
||||
Files.writeString(root.resolve("prometeu.json"), """
|
||||
{"name":"app","version":"1.0.0","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
|
||||
""");
|
||||
String source = "import { Gfx } from @sdk:gfx;\nfn main() -> void { Gfx.clear(0); }\n";
|
||||
Path file = Files.writeString(root.resolve("src/main.pbs"), source);
|
||||
Files.writeString(root.resolve("src/mod.barrel"), "pub fn main() -> void;\n");
|
||||
var context = new p.studio.lsp.messages.LspProjectContext("installed", "pbs", root);
|
||||
var bridge = new p.studio.lsp.services.compiler.CompilerLanguageServiceBridge();
|
||||
try (var registry = new p.studio.lsp.services.compiler.ExternalSourceRegistry()) {
|
||||
String consumer = registry.connect(null, false);
|
||||
int[] sdkUse = position(source, "Gfx.clear", "Gfx.".length());
|
||||
var targets = bridge.navigation(context, file.toUri().toString(), source, sdkUse[0], sdkUse[1], registry, consumer).locations();
|
||||
check(targets.size() == 1, "Packaged SDK definition must resolve");
|
||||
String uri = targets.getFirst().uri();
|
||||
check(uri.startsWith("prometeu-source:"), "SDK must use a virtual URI");
|
||||
var content = registry.read(consumer, uri);
|
||||
check(content.descriptor().readOnly() && content.descriptor().origin().equals("bundled"), "Bundled SDK must be read-only");
|
||||
try (var stream = resource.openStream()) {
|
||||
check(content.text().equals(new String(stream.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8)), "SDK text must exactly match JAR bytes");
|
||||
}
|
||||
int[] hostUse = position(content.text(), "LowGfx.clear", "LowGfx.".length());
|
||||
check(bridge.externalHover(context, uri, hostUse[0], hostUse[1], registry, consumer).markdown().contains("clear"), "SDK hover must work");
|
||||
var host = bridge.navigation(context, uri, null, hostUse[0], hostUse[1], registry, consumer).locations().getFirst();
|
||||
check(registry.read(consumer, host.uri()).text().split("\n")[host.startLine()].contains("clear"), "SDK to host definition range must match");
|
||||
check(!bridge.externalSemanticTokens(context, uri, registry, consumer).tokens().isEmpty(), "SDK semantic highlighting must work");
|
||||
int[] colorUse = position(content.text(), "color: Color", 7);
|
||||
var core = bridge.navigation(context, uri, null, colorUse[0], colorUse[1], registry, consumer).locations().getFirst();
|
||||
var coreContent = registry.read(consumer, core.uri());
|
||||
check(coreContent.descriptor().readOnly() && coreContent.descriptor().name().replace('\\', '/').contains("core/color"), "SDK to core definition must resolve");
|
||||
var coreResource = loader.getResource("game/stdlib/1/core/color/main.pbs");
|
||||
check(coreResource != null && coreResource.getProtocol().equals("jar"), "Core must be read from a JAR URL");
|
||||
try (var stream = coreResource.openStream()) {
|
||||
check(coreContent.text().equals(new String(stream.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8)), "Core text must exactly match JAR bytes");
|
||||
}
|
||||
check(coreContent.text().split("\n")[core.startLine()].contains("Color"), "Core definition range must match");
|
||||
registry.disconnect(consumer);
|
||||
registry.connect(consumer, false);
|
||||
check(registry.revalidate(consumer, uri, path -> bridge.currentSource(context, path)).text().equals(content.text()), "Bundled source must revalidate after reconnect");
|
||||
}
|
||||
try (var files = Files.walk(root)) {
|
||||
check(files.filter(Files::isRegularFile).map(root::relativize).map(Path::toString).collect(java.util.stream.Collectors.toSet())
|
||||
.equals(java.util.Set.of("prometeu.json", "src/main.pbs", "src/mod.barrel")), "Navigation must not extract bundled sources into the project");
|
||||
}
|
||||
System.out.println("Packaged external sources verified: JAR bytes, SDK/host/core navigation, hover, tokens, read-only, reconnect, no extraction");
|
||||
}
|
||||
|
||||
private static int[] position(String text, String needle, int offset) {
|
||||
int index = text.indexOf(needle);
|
||||
check(index >= 0, "Missing source fragment: " + needle);
|
||||
String prefix = text.substring(0, index + offset);
|
||||
return new int[] {(int) prefix.chars().filter(c -> c == '\n').count(), prefix.length() - prefix.lastIndexOf('\n') - 1};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class InstalledKnowledgeTest {
|
||||
}
|
||||
String probeClasses = Path.of(InstalledKnowledgeProbe.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
|
||||
Path output = outsideRepository.resolve("probe.log");
|
||||
var process = new ProcessBuilder(Path.of(System.getProperty("java.home"), "bin", "java").toString(),
|
||||
var process = new ProcessBuilder(distribution.resolve("runtime/bin/java").toString(),
|
||||
"-cp", jars + java.io.File.pathSeparator + probeClasses, InstalledKnowledgeProbe.class.getName())
|
||||
.directory(outsideRepository.toFile()).redirectErrorStream(true).redirectOutput(output.toFile()).start();
|
||||
try {
|
||||
@@ -28,6 +28,7 @@ class InstalledKnowledgeTest {
|
||||
String log = Files.readString(output);
|
||||
assertEquals(0, process.exitValue(), log);
|
||||
assertTrue(log.contains("references; example compiled"), log);
|
||||
assertTrue(log.contains("Packaged external sources verified"), log);
|
||||
} finally { if (process.isAlive()) process.destroyForcibly().waitFor(); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user