fix(pbs): exclude transient state from packaged example knowledge
Keep canonical asset identities and verify cache-independent packaging and installed references. Work: WRK-0027. Validation: make -C tooling verify, run 20261127T004152Z-e028bb55, PASSED.
This commit is contained in:
@@ -568,6 +568,17 @@ example references identify their SDK major and target; unsupported selections
|
|||||||
MUST NOT silently reuse another SDK/target. Numbered spec/draft revisions and the
|
MUST NOT silently reuse another SDK/target. Numbered spec/draft revisions and the
|
||||||
reference-index schema revision MUST NOT be reported as language/compiler versions.
|
reference-index schema revision MUST NOT be reported as language/compiler versions.
|
||||||
|
|
||||||
|
The packaged Beacon Workshop example MUST preserve canonical sources, asset
|
||||||
|
metadata, animation sidecars, PNG resources and `assets/.prometeu/index.json`
|
||||||
|
with their content hashes. Its resource bundle, `distribution.json` inventory
|
||||||
|
and reference index MUST use the same source selection and exclude local
|
||||||
|
`assets/.prometeu/cache.json`, Python `__pycache__` directories and temporary
|
||||||
|
publications (`.asset-publish-*.tmp`, `.record-*.tmp`, `.animation-*.tmp`). These
|
||||||
|
transient files MUST NOT affect the generated resources, inventory, reference
|
||||||
|
IDs or hashes when created, modified or removed. Regeneration MUST remove
|
||||||
|
previously copied transient resources. The installed example MUST remain
|
||||||
|
compilable and packable outside the source checkout without a preexisting cache.
|
||||||
|
|
||||||
`studio_reference_read` is authenticated but does not require an acquired task; the transport still requires a grant-published project credential. It resolves the explicit open root and its current saved manifest selection
|
`studio_reference_read` is authenticated but does not require an acquired task; the transport still requires a grant-published project credential. It resolves the explicit open root and its current saved manifest selection
|
||||||
on every read. Changing SDK/target can invalidate previously advertised IDs.
|
on every read. Changing SDK/target can invalidate previously advertised IDs.
|
||||||
Only IDs in that project's installed index can be read, including when other
|
Only IDs in that project's installed index can be read, including when other
|
||||||
|
|||||||
@@ -74,6 +74,15 @@ public final class InstalledKnowledgeProbe {
|
|||||||
var catalog = new ProjectCatalogService(root, mapper, new ProjectLocalStudioSetupStore(mapper));
|
var catalog = new ProjectCatalogService(root, mapper, new ProjectLocalStudioSetupStore(mapper));
|
||||||
var knowledge = new CompilerProjectKnowledge(access, catalog, mapper);
|
var knowledge = new CompilerProjectKnowledge(access, catalog, mapper);
|
||||||
var context = knowledge.context(root);
|
var context = knowledge.context(root);
|
||||||
|
String cacheReference = "pbs:example:game:1:beacon-workshop/assets/.prometeu/cache.json";
|
||||||
|
check(context.references().stream().noneMatch(ref -> ref.id().equals(cacheReference)), "Cache must not be advertised");
|
||||||
|
try {
|
||||||
|
knowledge.readReference(root, cacheReference, 0, 100);
|
||||||
|
throw new AssertionError("Installed cache reference must not be readable");
|
||||||
|
} catch (p.studio.api.automation.AutomationException failure) {
|
||||||
|
check(failure.failure().code() == p.studio.api.automation.AutomationFailure.Code.REFERENCE_NOT_FOUND,
|
||||||
|
"Cache must fail with REFERENCE_NOT_FOUND");
|
||||||
|
}
|
||||||
for (var kind : java.util.List.of(ProjectKnowledge.ReferenceKind.QUICKSTART, ProjectKnowledge.ReferenceKind.SYNTAX,
|
for (var kind : java.util.List.of(ProjectKnowledge.ReferenceKind.QUICKSTART, ProjectKnowledge.ReferenceKind.SYNTAX,
|
||||||
ProjectKnowledge.ReferenceKind.SEMANTICS, ProjectKnowledge.ReferenceKind.EXAMPLE, ProjectKnowledge.ReferenceKind.SDK))
|
ProjectKnowledge.ReferenceKind.SEMANTICS, ProjectKnowledge.ReferenceKind.EXAMPLE, ProjectKnowledge.ReferenceKind.SDK))
|
||||||
check(context.references().stream().anyMatch(ref -> ref.kind() == kind), "Missing " + kind);
|
check(context.references().stream().anyMatch(ref -> ref.kind() == kind), "Missing " + kind);
|
||||||
@@ -288,10 +297,20 @@ public final class InstalledKnowledgeProbe {
|
|||||||
String resource = "pbs-knowledge/examples/game/1/beacon-workshop/distribution.json";
|
String resource = "pbs-knowledge/examples/game/1/beacon-workshop/distribution.json";
|
||||||
var location = loader.getResource(resource);
|
var location = loader.getResource(resource);
|
||||||
check(location != null && location.getProtocol().equals("jar"), "Beacon Workshop must come from installed JAR");
|
check(location != null && location.getProtocol().equals("jar"), "Beacon Workshop must come from installed JAR");
|
||||||
|
String prefix = "pbs-knowledge/examples/game/1/beacon-workshop/";
|
||||||
|
var connection = (java.net.JarURLConnection) location.openConnection();
|
||||||
|
try (var jar = new java.util.jar.JarFile(Path.of(connection.getJarFileURL().toURI()).toFile())) {
|
||||||
|
check(jar.stream().map(java.util.jar.JarEntry::getName).filter(name -> name.startsWith(prefix))
|
||||||
|
.noneMatch(name -> name.equals(prefix + "assets/.prometeu/cache.json") || name.contains("__pycache__/")
|
||||||
|
|| name.matches("(?:.*/)?\\.(?:asset-publish|record|animation)-.*\\.tmp")),
|
||||||
|
"Installed JAR must not carry transient example resources");
|
||||||
|
}
|
||||||
var mapper = new ObjectMapper();
|
var mapper = new ObjectMapper();
|
||||||
Path root = Files.createDirectory(Path.of("beacon-workshop")).toRealPath();
|
Path root = Files.createDirectory(Path.of("beacon-workshop")).toRealPath();
|
||||||
|
var paths = new java.util.HashSet<String>();
|
||||||
try (var input = location.openStream()) {
|
try (var input = location.openStream()) {
|
||||||
for (var file : mapper.readTree(input).path("files")) {
|
for (var file : mapper.readTree(input).path("files")) {
|
||||||
|
check(paths.add(file.path("path").asText()), "Game inventory paths must be unique");
|
||||||
Path target = root.resolve(file.path("path").asText()).normalize();
|
Path target = root.resolve(file.path("path").asText()).normalize();
|
||||||
check(target.startsWith(root), "Packaged game path must stay inside project");
|
check(target.startsWith(root), "Packaged game path must stay inside project");
|
||||||
var url = loader.getResource(file.path("resource").asText());
|
var url = loader.getResource(file.path("resource").asText());
|
||||||
@@ -304,6 +323,11 @@ public final class InstalledKnowledgeProbe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
check(paths.containsAll(java.util.List.of("assets/.prometeu/index.json", "assets/workshop/asset.json",
|
||||||
|
"assets/workshop/animations.studio.json", "assets/workshop/beacon_on.png",
|
||||||
|
"assets/room/scene-bank.pack-request.json")), "Canonical asset resources must remain installed");
|
||||||
|
check(!paths.contains("assets/.prometeu/cache.json"), "Inventory must exclude local cache");
|
||||||
|
check(!Files.exists(root.resolve("assets/.prometeu/cache.json")), "Installed game must start without cache");
|
||||||
var setup = new ProjectLocalStudioSetupStore(mapper);
|
var setup = new ProjectLocalStudioSetupStore(mapper);
|
||||||
var project = new ProjectCatalogService(root.getParent(), mapper, setup).openProject(root);
|
var project = new ProjectCatalogService(root.getParent(), mapper, setup).openProject(root);
|
||||||
try (var workers = java.util.concurrent.Executors.newSingleThreadExecutor(); var packer = p.packer.Packer.bootstrap(mapper, ignored -> {})) {
|
try (var workers = java.util.concurrent.Executors.newSingleThreadExecutor(); var packer = p.packer.Packer.bootstrap(mapper, ignored -> {})) {
|
||||||
@@ -324,6 +348,7 @@ public final class InstalledKnowledgeProbe {
|
|||||||
.digest(Files.readAllBytes(output.resolve("program.pbx"))))));
|
.digest(Files.readAllBytes(output.resolve("program.pbx"))))));
|
||||||
}
|
}
|
||||||
System.out.println("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack");
|
System.out.println("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack");
|
||||||
|
System.out.println("Installed Beacon Workshop transient exclusion verified");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] position(String text, String needle, int offset) {
|
private static int[] position(String text, String needle, int offset) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class InstalledKnowledgeTest {
|
|||||||
assertTrue(log.contains("Installed production contracts verified: 21 compile classifications"), log);
|
assertTrue(log.contains("Installed production contracts verified: 21 compile classifications"), log);
|
||||||
assertTrue(log.contains("Installed generated animation project: zelda-1"), log);
|
assertTrue(log.contains("Installed generated animation project: zelda-1"), log);
|
||||||
assertTrue(log.contains("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack"), log);
|
assertTrue(log.contains("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack"), log);
|
||||||
|
assertTrue(log.contains("Installed Beacon Workshop transient exclusion verified"), log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test void installedCompilerAndSdkCarryTheSameVerifiedCatalog() throws Exception {
|
@Test void installedCompilerAndSdkCarryTheSameVerifiedCatalog() throws Exception {
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ val pbsResources = layout.projectDirectory.dir("src/main/resources")
|
|||||||
val beaconWorkshop = rootProject.layout.projectDirectory.dir("test-projects/beacon-workshop")
|
val beaconWorkshop = rootProject.layout.projectDirectory.dir("test-projects/beacon-workshop")
|
||||||
val beaconFiles = fileTree(beaconWorkshop) {
|
val beaconFiles = fileTree(beaconWorkshop) {
|
||||||
include("src/**", "assets/**", "tools/*.py", "*.md", "prometeu.json", ".gitignore")
|
include("src/**", "assets/**", "tools/*.py", "*.md", "prometeu.json", ".gitignore")
|
||||||
exclude("**/__pycache__/**")
|
// Local packer state and in-flight publications are not example source material.
|
||||||
|
// Keep assets/.prometeu/index.json: it owns the canonical asset identities.
|
||||||
|
exclude("assets/.prometeu/cache.json", "**/__pycache__/**",
|
||||||
|
"**/.asset-publish-*.tmp", "**/.record-*.tmp", "**/.animation-*.tmp")
|
||||||
}
|
}
|
||||||
val generatePbsKnowledge by tasks.registering(Sync::class) {
|
val generatePbsKnowledge by tasks.registering(Sync::class) {
|
||||||
from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") }
|
from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") }
|
||||||
|
|||||||
+29
@@ -9,6 +9,35 @@ import java.util.*;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class PbsDocumentationTest {
|
class PbsDocumentationTest {
|
||||||
|
@Test void beaconDistributionPreservesCanonicalAssetsAndExcludesTransientState() throws Exception {
|
||||||
|
String prefix = "pbs-knowledge/examples/game/1/beacon-workshop/";
|
||||||
|
var loader = getClass().getClassLoader();
|
||||||
|
var paths = new HashSet<String>();
|
||||||
|
var references = new PbsDocumentation().references(1, AppMode.Game).stream()
|
||||||
|
.map(FrontendReferenceProvider.Reference::id).collect(java.util.stream.Collectors.toSet());
|
||||||
|
try (var stream = loader.getResourceAsStream(prefix + "distribution.json")) {
|
||||||
|
assertNotNull(stream);
|
||||||
|
for (var file : new com.fasterxml.jackson.databind.ObjectMapper().readTree(stream).path("files")) {
|
||||||
|
String path = file.path("path").asText();
|
||||||
|
assertTrue(paths.add(path), path);
|
||||||
|
assertFalse(path.equals("assets/.prometeu/cache.json") || path.contains("__pycache__/")
|
||||||
|
|| path.matches("(?:.*/)?\\.(?:asset-publish|record|animation)-.*\\.tmp"), path);
|
||||||
|
assertEquals(prefix + path, file.path("resource").asText());
|
||||||
|
try (var content = loader.getResourceAsStream(prefix + path)) {
|
||||||
|
assertNotNull(content, path);
|
||||||
|
assertEquals(file.path("sha256").asText(), HexFormat.of().formatHex(
|
||||||
|
java.security.MessageDigest.getInstance("SHA-256").digest(content.readAllBytes())), path);
|
||||||
|
}
|
||||||
|
assertEquals(!path.endsWith(".png"), references.contains("pbs:example:game:1:beacon-workshop/" + path), path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertTrue(paths.containsAll(List.of("prometeu.json", "src/main.pbs", "assets/.prometeu/index.json",
|
||||||
|
"assets/workshop/asset.json", "assets/workshop/animations.studio.json",
|
||||||
|
"assets/workshop/beacon_on.png", "assets/room/scene-bank.pack-request.json")));
|
||||||
|
assertNull(loader.getResource(prefix + "assets/.prometeu/cache.json"));
|
||||||
|
assertFalse(references.contains("pbs:example:game:1:beacon-workshop/assets/.prometeu/cache.json"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test void publishedFeatureIdsResolveToTheSameCanonicalChapterResourceAndHash() throws Exception {
|
@Test void publishedFeatureIdsResolveToTheSameCanonicalChapterResourceAndHash() throws Exception {
|
||||||
// These IDs were published before the chapters were numbered.
|
// These IDs were published before the chapters were numbered.
|
||||||
var legacyIds = List.of("typed-arrays-and-optional-execution.md",
|
var legacyIds = List.of("typed-arrays-and-optional-execution.md",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
/build/
|
/build/
|
||||||
/.studio/
|
/.studio/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
/assets/.prometeu/cache.json
|
||||||
|
|||||||
Reference in New Issue
Block a user