implements PLN-0120

This commit is contained in:
2026-07-15 12:57:36 +01:00
parent 38790c0b45
commit 1f1a92d43f
3 changed files with 72 additions and 2 deletions
@@ -15,11 +15,26 @@ import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.*;
class IRBackendExecutableContractTest {
private static final String FORBIDDEN_PBS_PACKAGE = "p.studio.compiler.pbs";
private static final Set<Class<?>> AUDITED_SUPPORT_TYPES = Set.of(
FileId.class,
ModuleId.class,
CallableId.class,
IntrinsicId.class,
Span.class,
ModuleReference.class,
CallableSignatureRef.class,
IntrinsicReference.class,
ReadOnlyList.class,
String.class,
Integer.class,
Long.class,
Boolean.class);
private static final List<Class<?>> PUBLIC_CONTRACT_TYPES = List.of(
IRBackend.class,
IRBackend.IRBackendAggregator.class,
@@ -45,6 +60,61 @@ class IRBackendExecutableContractTest {
IRReservedMetadata.IntrinsicSurface.class,
IRReservedMetadata.BuiltinConstSurface.class);
@Test
void publicIRBackendContractAuditMustCoverAllModelTypes() {
final var expectedTopLevelModelTypes = Set.of(
IRBackend.class,
IRBackendReader.class,
IRBackendFile.class,
IRBackendExecutableFunction.class,
IRFunction.class,
IRGlobal.class,
IRGlobalOrigin.class,
IRGlobalVisibility.class,
IRHiddenGlobalKind.class,
IRReservedMetadata.class,
IRSyntheticCallableKind.class,
IRSyntheticFunction.class,
IRSyntheticOrigin.class);
assertTrue(
PUBLIC_CONTRACT_TYPES.containsAll(expectedTopLevelModelTypes),
"public IRBackend contract audit must cover every top-level handoff model type");
assertTrue(
PUBLIC_CONTRACT_TYPES.contains(IRBackendExecutableFunction.Instruction.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRBackendExecutableFunction.HostCallMetadata.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRBackendExecutableFunction.IntrinsicCallMetadata.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.HostMethodBinding.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.BuiltinTypeSurface.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.BuiltinFieldSurface.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.IntrinsicSurface.class)
&& PUBLIC_CONTRACT_TYPES.contains(IRReservedMetadata.BuiltinConstSurface.class),
"public IRBackend contract audit must cover nested handoff value types");
}
@Test
void publicIRBackendContractAuditMustClassifyAllowedSupportTypes() {
assertTrue(
AUDITED_SUPPORT_TYPES.containsAll(Set.of(
FileId.class,
ModuleId.class,
CallableId.class,
IntrinsicId.class)),
"table-scoped ids are audited as explicit handoff identifiers");
assertTrue(
AUDITED_SUPPORT_TYPES.contains(Span.class),
"Span is audited as source attribution data");
assertTrue(
AUDITED_SUPPORT_TYPES.containsAll(Set.of(
ModuleReference.class,
CallableSignatureRef.class,
IntrinsicReference.class)),
"source table references are audited as ordered table values");
assertTrue(
AUDITED_SUPPORT_TYPES.contains(ReadOnlyList.class),
"ReadOnlyList is audited as the ordered collection contract");
}
@Test
void publicIRBackendContractMustNotExposePbsTypes() {
final var violations = new ArrayList<String>();