diff --git a/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md b/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md index 9baf4dd1..853c511c 100644 --- a/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md +++ b/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md @@ -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 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 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 diff --git a/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeProbe.java b/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeProbe.java index 894234c2..a224c2c1 100644 --- a/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeProbe.java +++ b/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeProbe.java @@ -74,6 +74,15 @@ public final class InstalledKnowledgeProbe { var catalog = new ProjectCatalogService(root, mapper, new ProjectLocalStudioSetupStore(mapper)); var knowledge = new CompilerProjectKnowledge(access, catalog, mapper); 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, ProjectKnowledge.ReferenceKind.SEMANTICS, ProjectKnowledge.ReferenceKind.EXAMPLE, ProjectKnowledge.ReferenceKind.SDK)) 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"; var location = loader.getResource(resource); 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(); Path root = Files.createDirectory(Path.of("beacon-workshop")).toRealPath(); + var paths = new java.util.HashSet(); try (var input = location.openStream()) { 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(); check(target.startsWith(root), "Packaged game path must stay inside project"); 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 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 -> {})) { @@ -324,6 +348,7 @@ public final class InstalledKnowledgeProbe { .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 transient exclusion verified"); } private static int[] position(String text, String needle, int offset) { diff --git a/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeTest.java b/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeTest.java index ea7fa8fd..8f5fd7fb 100644 --- a/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeTest.java +++ b/prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeTest.java @@ -30,6 +30,7 @@ class InstalledKnowledgeTest { 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 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 { diff --git a/prometeu-compiler/frontends/prometeu-frontend-pbs/build.gradle.kts b/prometeu-compiler/frontends/prometeu-frontend-pbs/build.gradle.kts index 54b9f848..723bb353 100644 --- a/prometeu-compiler/frontends/prometeu-frontend-pbs/build.gradle.kts +++ b/prometeu-compiler/frontends/prometeu-frontend-pbs/build.gradle.kts @@ -17,7 +17,10 @@ val pbsResources = layout.projectDirectory.dir("src/main/resources") val beaconWorkshop = rootProject.layout.projectDirectory.dir("test-projects/beacon-workshop") val beaconFiles = fileTree(beaconWorkshop) { 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) { from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") } diff --git a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/documentation/PbsDocumentationTest.java b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/documentation/PbsDocumentationTest.java index a4c42a89..246633d6 100644 --- a/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/documentation/PbsDocumentationTest.java +++ b/prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/documentation/PbsDocumentationTest.java @@ -9,6 +9,35 @@ import java.util.*; import static org.junit.jupiter.api.Assertions.*; class PbsDocumentationTest { + @Test void beaconDistributionPreservesCanonicalAssetsAndExcludesTransientState() throws Exception { + String prefix = "pbs-knowledge/examples/game/1/beacon-workshop/"; + var loader = getClass().getClassLoader(); + var paths = new HashSet(); + 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 { // These IDs were published before the chapters were numbered. var legacyIds = List.of("typed-arrays-and-optional-execution.md", diff --git a/test-projects/beacon-workshop/.gitignore b/test-projects/beacon-workshop/.gitignore index 74a3fd4d..6e63fee3 100644 --- a/test-projects/beacon-workshop/.gitignore +++ b/test-projects/beacon-workshop/.gitignore @@ -1,3 +1,4 @@ /build/ /.studio/ __pycache__/ +/assets/.prometeu/cache.json