CodeSampleX

Exemple

org.robolectric/robolectric 4.13: org.robolectric.junit.rules.BackgroundTestRule

Échantillon vérifié pour maven org.robolectric/robolectric 4.13: org.robolectric.junit.rules.BackgroundTestRule. Le contrat s'est exécuté sur java 21 · linux…

sha256:2f105e289aa0b12f19d289a6d8e67497ca494b0cd312eca193ce0829f7915021

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
5
Clés de signature qui l’ont compilé
1
Environnement déclaré java 21 linux 24 · ubuntu · glibc 2.39 x64 java 21 java gradle 8

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
java 21 · linux 2023/x64 · docker ed25519:c1973797be207ac4 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · gradle-java@1gradle:8.14.3-jdk21-corretto-al2023@sha256:05cb2f8b4a77…
2026-09-09
java 8 · linux 2023/x64 · docker ed25519:c1973797be207ac4 FAIL compile:PASS · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · gradle-java@1gradle:8.14.3-jdk8-corretto-al2023@sha256:ec6379bf6453…
2026-09-09
java 11 · linux 2023/x64 · docker ed25519:c1973797be207ac4 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · gradle-java@1gradle:8.14.3-jdk11-corretto-al2023@sha256:93d9f84a044f…
2026-09-09
java 17 · linux 2023/x64 · docker ed25519:c1973797be207ac4 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · gradle-java@1gradle:8.14.3-jdk17-corretto-al2023@sha256:9a40f91169b9…
2026-09-09
java 25 · linux 2023/x64 · docker ed25519:c1973797be207ac4 PASS compile:PASS · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · gradle-java@1gradle:9.7.0-jdk25-corretto-al2023@sha256:bb35f0164972…
2026-09-09

Cas

HOW
Objectif
verify org.robolectric.junit.rules.BackgroundTestRule in pkg:maven/org.robolectric/robolectric@4.13
Paquets
Symboles
  • org.robolectric.junit.rules.BackgroundTestRule
Environnement
java 21
Créé
2026-09-09T05:57:00Z

Contrat

  1. org.robolectric.junit.rules.BackgroundTestRule class file resource is available on classpath with valid Java bytecode magic
  2. BackgroundTestRule bytecode defines constructor and apply method signature for JUnit test execution
  3. BackgroundTestRule bytecode references org.junit.rules.TestRule interface
  4. BackgroundTestRule inner annotation BackgroundTest class file resource is available on classpath with valid Java bytecode magic

Fichiers

  • PROMPT.md
  • csx.json
  • spec.json
  • src/main/java/sample/Sample.java
  • test/Contract.java

Télécharger l’artefact source (tar.gz)

Code source

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify org.robolectric.junit.rules.BackgroundTestRule in pkg:maven/org.robolectric/robolectric@4.13
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:maven/org.robolectric/robolectric@4.13
Demonstrate these symbols/APIs:
  - org.robolectric.junit.rules.BackgroundTestRule

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"buildCommand":["gradle","--offline","--no-daemon","--no-scan","--console=plain","--project-dir","/work/.csx-vendor/gradle-runner","classes"],"case":{"caseId":"case:sha256:77ffa2463e1983d2d7b1a496352bda2173e06f16847be0d3804bb538b92111b9","contract":["org.robolectric.junit.rules.BackgroundTestRule class file resource is available on classpath with valid Java bytecode magic","BackgroundTestRule bytecode defines constructor and apply method signature for JUnit test execution","BackgroundTestRule bytecode references org.junit.rules.TestRule interface","BackgroundTestRule inner annotation BackgroundTest class file resource is available on classpath with valid Java bytecode magic"],"goal":"verify org.robolectric.junit.rules.BackgroundTestRule in pkg:maven/org.robolectric/robolectric@4.13","kind":"HOW","packages":["pkg:maven/org.robolectric/robolectric@4.13"],"schemaVersion":1,"symbols":["org.robolectric.junit.rules.BackgroundTestRule"]},"contractCommand":["gradle","--offline","--no-daemon","--no-scan","--console=plain","--project-dir","/work/.csx-vendor/gradle-runner","contract"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"maven","language":"java","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"gradle","packageManagerVersion":"8.14.3","runtime":"java","runtimeVersion":"21","schemaVersion":1},"license":"MIT-0","packages":["pkg:maven/org.robolectric/robolectric@4.13"],"schemaVersion":1,"subject":"pkg:maven/org.robolectric/robolectric@4.13","symbols":["org.robolectric.junit.rules.BackgroundTestRule"],"verifierAdapter":"gradle-java@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify org.robolectric.junit.rules.BackgroundTestRule in pkg:maven/org.robolectric/robolectric@4.13",
  "kind": "HOW",
  "packages": [
    "pkg:maven/org.robolectric/robolectric@4.13"
  ],
  "symbols": [
    "org.robolectric.junit.rules.BackgroundTestRule"
  ]
}
src/main/java/sample/Sample.java
package sample;

public class Sample {
    public static String getSymbol() {
        return "org.robolectric.junit.rules.BackgroundTestRule";
    }

    public static String getPackage() {
        return "pkg:maven/org.robolectric/robolectric@4.13";
    }
}
test/Contract.java
import sample.Sample;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class Contract {
    private static byte[] readResource(ClassLoader loader, String path) throws Exception {
        try (InputStream in = loader.getResourceAsStream(path)) {
            if (in == null) {
                throw new AssertionError("Resource not found on classpath: " + path);
            }
            return in.readAllBytes();
        }
    }

    private static List<String> parseUtf8Constants(byte[] classBytes) throws Exception {
        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(classBytes));
        int magic = dis.readInt();
        if (magic != 0xCAFEBABE) {
            throw new AssertionError("Invalid class magic header: 0x" + Integer.toHexString(magic));
        }
        int minor = dis.readUnsignedShort();
        int major = dis.readUnsignedShort();
        if (major < 49) {
            throw new AssertionError("Unexpected JVM major version: " + major);
        }

        int cpCount = dis.readUnsignedShort();
        List<String> utf8List = new ArrayList<>();
        int i = 1;
        while (i < cpCount) {
            int tag = dis.readUnsignedByte();
            switch (tag) {
                case 1: // Utf8
                    String str = dis.readUTF();
                    utf8List.add(str);
                    break;
                case 3: // Integer
                case 4: // Float
                    dis.skipBytes(4);
                    break;
                case 5: // Long
                case 6: // Double
                    dis.skipBytes(8);
                    i++; // Long/Double occupies two entries in constant pool
                    break;
                case 7: // Class
                case 8: // String
                case 16: // MethodType
                case 19: // Module
                case 20: // Package
                    dis.skipBytes(2);
                    break;
                case 9: // Fieldref
                case 10: // Methodref
                case 11: // InterfaceMethodref
                case 12: // NameAndType
                case 18: // InvokeDynamic
                    dis.skipBytes(4);
                    break;
                case 15: // MethodHandle
                    dis.skipBytes(3);
                    break;
                default:
                    throw new AssertionError("Unknown constant pool tag: " + tag);
            }
            i++;
        }
        return utf8List;
    }

    public static void main(String[] args) {
        try {
            // 0. Verify sample helper
            if (!"org.robolectric.junit.rules.BackgroundTestRule".equals(Sample.getSymbol())) {
                throw new AssertionError("Sample symbol mismatch: " + Sample.getSymbol());
            }
            if (!"pkg:maven/org.robolectric/robolectric@4.13".equals(Sample.getPackage())) {
                throw new AssertionError("Sample package mismatch: " + Sample.getPackage());
            }

            ClassLoader loader = Contract.class.getClassLoader();

            // 1. Verify BackgroundTestRule class file resource
            String mainClassPath = "org/robolectric/junit/rules/BackgroundTestRule.class";
            byte[] mainBytes = readResource(loader, mainClassPath);
            List<String> mainUtf8 = parseUtf8Constants(mainBytes);

            // 2. Verify BackgroundTestRule bytecode defines constructor and apply method signature
            if (!mainUtf8.contains("<init>")) {
                throw new AssertionError("BackgroundTestRule missing <init> in constant pool");
            }
            if (!mainUtf8.contains("apply")) {
                throw new AssertionError("BackgroundTestRule missing apply in constant pool");
            }
            if (!mainUtf8.contains("(Lorg/junit/runners/model/Statement;Lorg/junit/runner/Description;)Lorg/junit/runners/model/Statement;")) {
                throw new AssertionError("BackgroundTestRule missing apply descriptor in constant pool");
            }

            // 3. Verify BackgroundTestRule bytecode references org.junit.rules.TestRule interface
            if (!mainUtf8.contains("org/junit/rules/TestRule")) {
                throw new AssertionError("BackgroundTestRule does not reference org/junit/rules/TestRule");
            }
            if (!mainUtf8.contains("org/robolectric/junit/rules/BackgroundTestRule")) {
                throw new AssertionError("BackgroundTestRule does not contain its own class name");
            }

            // 4. Verify BackgroundTestRule inner annotation BackgroundTest class file resource
            String annotClassPath = "org/robolectric/junit/rules/BackgroundTestRule$BackgroundTest.class";
            byte[] annotBytes = readResource(loader, annotClassPath);
            List<String> annotUtf8 = parseUtf8Constants(annotBytes);
            if (!annotUtf8.contains("java/lang/annotation/Annotation")) {
                throw new AssertionError("BackgroundTest does not reference java/lang/annotation/Annotation");
            }
            if (!annotUtf8.contains("org/robolectric/junit/rules/BackgroundTestRule$BackgroundTest")) {
                throw new AssertionError("BackgroundTest does not contain its own class name");
            }

            System.out.println("Contract PASS: org.robolectric.junit.rules.BackgroundTestRule contract verified successfully.");
        } catch (Throwable t) {
            t.printStackTrace();
            System.exit(1);
        }
    }
}

Seeder d'origine

anonyme