CodeSampleX

Exemple

galactus 1.0.0: DestroyerOfModules

Échantillon vérifié pour npm galactus 1.0.0: DestroyerOfModules. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a réussi.

sha256:536e92910e5764bbdaf5b201a31cdab84ae2b091f346470aca78b08d75418368

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
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-19

Cas

HOW
Objectif
verify galactus.DestroyerOfModules in pkg:npm/galactus@1.0.0
Paquets
Symboles
  • galactus.DestroyerOfModules
Créé
2026-09-17T16:20:12Z

Contrat

  1. DestroyerOfModules is an exported class constructor
  2. DestroyerOfModules constructor throws an Error if neither rootDirectory nor walker is provided
  3. DestroyerOfModules instantiates with a rootDirectory option
  4. DestroyerOfModules instantiates with a custom walker option
  5. collectKeptModules returns module map with absolute paths by default
  6. collectKeptModules returns relative paths when relativePaths option is true
  7. collectKeptModules respects custom shouldKeepModuleTest override
  8. destroy removes devDependencies from disk while retaining production dependencies

Fichiers

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • test/contract.mjs

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 galactus.DestroyerOfModules in pkg:npm/galactus@1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/galactus@1.0.0
Demonstrate these symbols/APIs:
  - galactus.DestroyerOfModules

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
{"case":{"caseId":"case:sha256:e1f2dc937ba281e09a871ebb9a8cf56a2ba00e93d1cd24bdc02ccb79f762c204","contract":["DestroyerOfModules is an exported class constructor","DestroyerOfModules constructor throws an Error if neither rootDirectory nor walker is provided","DestroyerOfModules instantiates with a rootDirectory option","DestroyerOfModules instantiates with a custom walker option","collectKeptModules returns module map with absolute paths by default","collectKeptModules returns relative paths when relativePaths option is true","collectKeptModules respects custom shouldKeepModuleTest override","destroy removes devDependencies from disk while retaining production dependencies"],"goal":"verify galactus.DestroyerOfModules in pkg:npm/galactus@1.0.0","kind":"HOW","packages":["pkg:npm/galactus@1.0.0"],"schemaVersion":1,"symbols":["galactus.DestroyerOfModules"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/galactus@1.0.0"],"schemaVersion":1,"subject":"pkg:npm/galactus@1.0.0","symbols":["galactus.DestroyerOfModules"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-galactus",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-galactus",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "galactus": "1.0.0"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/flora-colossus": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/flora-colossus/-/flora-colossus-2.0.0.tgz",
      "integrity": "sha512-dz4HxH6pOvbUzZpZ/yXhafjbR2I8cenK5xL0KtBFb7U2ADsR+OwXifnxZjij/pZWF775uSCMzWVd+jDik2H2IA==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4",
        "fs-extra": "^10.1.0"
      },
      "engines": {
        "node": ">= 12"
      }
    },
    "node_modules/fs-extra": {
      "version": "10.1.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
      "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=12"
      }
    },
    "node_modules/galactus": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/galactus/-/galactus-1.0.0.tgz",
      "integrity": "sha512-R1fam6D4CyKQGNlvJne4dkNF+PvUUl7TAJInvTGa9fti9qAv95quQz29GXapA4d8Ec266mJJxFVh82M4GIIGDQ==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4",
        "flora-colossus": "^2.0.0",
        "fs-extra": "^10.1.0"
      },
      "engines": {
        "node": ">= 12"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/jsonfile": {
      "version": "6.2.1",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
      "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-galactus",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "galactus": "1.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify galactus.DestroyerOfModules in pkg:npm/galactus@1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/galactus@1.0.0"
  ],
  "symbols": [
    "galactus.DestroyerOfModules"
  ]
}
src/index.mjs
import { DestroyerOfModules, Walker, DepType } from 'galactus';

/**
 * Creates a DestroyerOfModules instance configured for the given root directory.
 * @param {string} rootDirectory
 * @param {Function} [shouldKeepModuleTest]
 * @returns {DestroyerOfModules}
 */
export function createDestroyer(rootDirectory, shouldKeepModuleTest) {
  return new DestroyerOfModules({
    rootDirectory,
    shouldKeepModuleTest
  });
}

/**
 * Collects module paths that would be retained during pruning.
 * @param {string} rootDirectory
 * @param {boolean} [relativePaths=false]
 * @returns {Promise<Map<string, any>>}
 */
export async function getKeptModules(rootDirectory, relativePaths = false) {
  const destroyer = new DestroyerOfModules({ rootDirectory });
  return destroyer.collectKeptModules({ relativePaths });
}

/**
 * Prunes non-production dependencies from the given root directory.
 * @param {string} rootDirectory
 * @param {Function} [shouldKeepModuleTest]
 * @returns {Promise<void>}
 */
export async function pruneDependencies(rootDirectory, shouldKeepModuleTest) {
  const destroyer = new DestroyerOfModules({ rootDirectory, shouldKeepModuleTest });
  await destroyer.destroy();
}

export { DestroyerOfModules, Walker, DepType };
test/contract.mjs
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import { DestroyerOfModules, Walker } from 'galactus';

async function run() {
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'galactus-contract-'));

  try {
    // 1. DestroyerOfModules is an exported class constructor
    assert.strictEqual(typeof DestroyerOfModules, 'function', 'DestroyerOfModules must be a constructor function');

    // 2. DestroyerOfModules constructor throws an Error if neither rootDirectory nor walker is provided
    assert.throws(
      () => new DestroyerOfModules({}),
      /Must either provide rootDirectory or walker argument/,
      'DestroyerOfModules must throw when neither rootDirectory nor walker is provided'
    );

    // Setup mock package directory with production and dev dependencies
    const packageJson = {
      name: 'test-fixture-app',
      version: '1.0.0',
      dependencies: {
        'fixture-prod-lib': '^1.0.0'
      },
      devDependencies: {
        'fixture-dev-tool': '^1.0.0'
      }
    };
    fs.writeFileSync(path.join(tmpDir, 'package.json'), JSON.stringify(packageJson, null, 2));

    const nodeModulesDir = path.join(tmpDir, 'node_modules');
    const prodDepDir = path.join(nodeModulesDir, 'fixture-prod-lib');
    const devDepDir = path.join(nodeModulesDir, 'fixture-dev-tool');

    fs.mkdirSync(prodDepDir, { recursive: true });
    fs.writeFileSync(
      path.join(prodDepDir, 'package.json'),
      JSON.stringify({ name: 'fixture-prod-lib', version: '1.0.0' }, null, 2)
    );

    fs.mkdirSync(devDepDir, { recursive: true });
    fs.writeFileSync(
      path.join(devDepDir, 'package.json'),
      JSON.stringify({ name: 'fixture-dev-tool', version: '1.0.0' }, null, 2)
    );

    // 3. DestroyerOfModules instantiates with a rootDirectory option
    const destroyerWithDir = new DestroyerOfModules({ rootDirectory: tmpDir });
    assert(destroyerWithDir instanceof DestroyerOfModules, 'destroyerWithDir must be instance of DestroyerOfModules');

    // 4. DestroyerOfModules instantiates with a custom walker option
    const customWalker = new Walker(tmpDir);
    const destroyerWithWalker = new DestroyerOfModules({ walker: customWalker });
    assert(destroyerWithWalker instanceof DestroyerOfModules, 'destroyerWithWalker must be instance of DestroyerOfModules');

    // 5. collectKeptModules returns module map with absolute paths by default
    const keptAbsolute = await destroyerWithDir.collectKeptModules({ relativePaths: false });
    assert(keptAbsolute instanceof Map, 'collectKeptModules must return a Map');
    assert(keptAbsolute.has(prodDepDir), 'keptAbsolute must include production dependency path');
    assert(!keptAbsolute.has(devDepDir), 'keptAbsolute must not include dev dependency path');

    // 6. collectKeptModules returns relative paths when relativePaths option is true
    const keptRelative = await destroyerWithDir.collectKeptModules({ relativePaths: true });
    assert(keptRelative instanceof Map, 'collectKeptModules must return a Map');
    assert(keptRelative.has(path.join('node_modules', 'fixture-prod-lib')), 'keptRelative must include relative prod dep path');
    assert(!keptRelative.has(path.join('node_modules', 'fixture-dev-tool')), 'keptRelative must not include relative dev dep path');

    // 7. collectKeptModules respects custom shouldKeepModuleTest override
    const overrideDestroyer = new DestroyerOfModules({
      rootDirectory: tmpDir,
      shouldKeepModuleTest: (_module, _isDevDep) => true
    });
    const keptWithOverride = await overrideDestroyer.collectKeptModules({ relativePaths: true });
    assert(
      keptWithOverride.has(path.join('node_modules', 'fixture-dev-tool')),
      'shouldKeepModuleTest override should allow retaining dev dependencies'
    );

    // 8. destroy removes devDependencies from disk while retaining production dependencies
    assert(fs.existsSync(devDepDir), 'devDepDir must exist before destroy');
    assert(fs.existsSync(prodDepDir), 'prodDepDir must exist before destroy');
    await destroyerWithDir.destroy();
    assert(fs.existsSync(prodDepDir), 'prodDepDir must remain on disk after destroy');
    assert(!fs.existsSync(devDepDir), 'devDepDir must be removed from disk after destroy');

    console.log('Contract tests passed successfully.');
    process.exit(0);
  } finally {
    try {
      if (fs.existsSync(tmpDir)) {
        fs.rmSync(tmpDir, { recursive: true, force: true });
      }
    } catch {
      // Ignore cleanup error
    }
  }
}

run().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Seeder d'origine

anonyme