CodeSampleX

Sample

loose-envify 1.4.0

Verified sample for npm loose-envify 1.4.0. The contract ran on node 22 · linux alpine/x64 · docker and passed: loose-envify exports a stream transform…

sha256:0a76f43b3658cacf0454885a0672e440687f861b069ccfd5dc0009d91b0e82cb

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Case

HOW
Goal
verify pkg:npm/loose-envify@1.4.0
Packages
Environment
node 22.23.2
Created
2026-08-27T21:41:36Z

Contract

  1. loose-envify exports a stream transform function
  2. loose-envify/replace exports a replace function
  3. loose-envify/custom exports a custom environment transform factory
  4. replace(src, envs) replaces process.env.VARIABLE with JSON-stringified values
  5. replace(src, envs) preserves unreplaced environment variables by default
  6. replace(src, envs) replaces unreplaced environment variables with undefined when purge flag is set
  7. replace(src, envs) ignores property assignments and object property access on process.env
  8. looseEnvify(file, trOpts) transforms source stream chunks by replacing process.env variables
  9. looseEnvify(file, trOpts) passes through .json files unmodified

Files

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

Download the source artifact (tar.gz)

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 pkg:npm/loose-envify@1.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/loose-envify@1.4.0

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:8665e9548a35ddc5b5c50b786816cdb53bbe73a327bf6798a3fd3ef328416b13","contract":["loose-envify exports a stream transform function","loose-envify/replace exports a replace function","loose-envify/custom exports a custom environment transform factory","replace(src, envs) replaces process.env.VARIABLE with JSON-stringified values","replace(src, envs) preserves unreplaced environment variables by default","replace(src, envs) replaces unreplaced environment variables with undefined when purge flag is set","replace(src, envs) ignores property assignments and object property access on process.env","looseEnvify(file, trOpts) transforms source stream chunks by replacing process.env variables","looseEnvify(file, trOpts) passes through .json files unmodified"],"goal":"verify pkg:npm/loose-envify@1.4.0","kind":"HOW","packages":["pkg:npm/loose-envify@1.4.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/loose-envify@1.4.0"],"schemaVersion":1,"subject":"pkg:npm/loose-envify@1.4.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-loose-envify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-loose-envify",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "loose-envify": "1.4.0"
      }
    },
    "node_modules/js-tokens": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
      "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
      "license": "MIT"
    },
    "node_modules/loose-envify": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
      "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
      "license": "MIT",
      "dependencies": {
        "js-tokens": "^3.0.0 || ^4.0.0"
      },
      "bin": {
        "loose-envify": "cli.js"
      }
    }
  }
}
package.json
{
  "name": "sample-loose-envify",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "loose-envify": "1.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/loose-envify@1.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/loose-envify@1.4.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { Readable } from 'node:stream';

const require = createRequire(import.meta.url);
const looseEnvify = require('loose-envify');
const replace = require('loose-envify/replace');
const customEnvify = require('loose-envify/custom');

// 1. Module export verification
assert.equal(typeof looseEnvify, 'function', 'loose-envify must export a transform function');
assert.equal(typeof replace, 'function', 'loose-envify/replace must export a replace function');
assert.equal(typeof customEnvify, 'function', 'loose-envify/custom must export a factory function');

// 2. replace(src, envs) replaces process.env.KEY with JSON stringified value
const src1 = 'if (process.env.NODE_ENV === "production") { doSomething(); }';
const replaced1 = replace(src1, [{ NODE_ENV: 'production' }]);
assert.equal(replaced1, 'if ("production" === "production") { doSomething(); }');

// 3. replace(src, envs) replaces multiple environment variables
const src2 = 'const api = process.env.API_URL; const port = process.env.PORT;';
const replaced2 = replace(src2, [{ API_URL: 'https://example.com', PORT: 8080 }]);
assert.equal(replaced2, 'const api = "https://example.com"; const port = 8080;');

// 4. replace(src, envs) preserves unreplaced environment variables when purge is not set
const src3 = 'const debug = process.env.DEBUG;';
const replaced3 = replace(src3, [{ NODE_ENV: 'development' }]);
assert.equal(replaced3, 'const debug = process.env.DEBUG;');

// 5. replace(src, envs) replaces unreplaced environment variables with undefined when purge flag is enabled
const src4 = 'const debug = process.env.DEBUG;';
const replaced4 = replace(src4, [{ NODE_ENV: 'development', _: ['purge'] }]);
assert.equal(replaced4, 'const debug = undefined;');

// 6. replace(src, envs) does not replace assignments or property chains on process.env
const src5 = 'process.env.NODE_ENV = "test"; obj.process.env.NODE_ENV;';
const replaced5 = replace(src5, [{ NODE_ENV: 'production' }]);
assert.equal(replaced5, 'process.env.NODE_ENV = "test"; obj.process.env.NODE_ENV;');

// 7. looseEnvify(file, trOpts) creates a transform stream that replaces environment variables in stream chunks
const customTransform = customEnvify({ APP_NAME: 'MyDemoApp' });
const trStream = customTransform('main.js');

let output = '';
trStream.on('data', (chunk) => {
  output += chunk.toString();
});

await new Promise((resolve, reject) => {
  trStream.on('end', resolve);
  trStream.on('error', reject);

  const inStream = Readable.from(['const name = process.env.APP_NAME;']);
  inStream.pipe(trStream);
});

assert.equal(output, 'const name = "MyDemoApp";');

// 8. looseEnvify bypasses .json files with PassThrough stream
const jsonStream = customTransform('data.json');
let jsonOutput = '';
jsonStream.on('data', (chunk) => {
  jsonOutput += chunk.toString();
});

await new Promise((resolve, reject) => {
  jsonStream.on('end', resolve);
  jsonStream.on('error', reject);

  const inStream = Readable.from(['{"name": "process.env.APP_NAME"}']);
  inStream.pipe(jsonStream);
});

assert.equal(jsonOutput, '{"name": "process.env.APP_NAME"}');

console.log('Contract tests passed successfully.');

Origin Seeder

anonymous