CodeSampleX

Ejemplo

@vitest/mocker 3.2.7: RedirectedModule

Muestra verificada para npm @vitest/mocker 3.2.7: RedirectedModule. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:f3bd66dec3b1bb300fa5c56b459527e8a4a1fca0af3c91e5794b255a2f82ef25

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-23

Caso

HOW
Objetivo
verify @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7
Paquetes
Símbolos
  • @vitest/mocker.RedirectedModule
Creado
2026-08-23T14:53:30Z

Contrato

  1. RedirectedModule creates instance with raw, id, url, and redirect properties and type 'redirect'
  2. RedirectedModule toJSON serializes module metadata including raw, id, url, redirect, and type
  3. RedirectedModule fromJSON reconstructs a RedirectedModule instance from serialized data
  4. MockerRegistry registers and resolves RedirectedModule instances by url and id

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40vitest/mocker@3.2.7
Demonstrate these symbols/APIs:
  - @vitest/mocker.RedirectedModule

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:175d879f1656ded2dd5233447ba14bbe44f0892925d54b2a63c6545ee96243c4","contract":["RedirectedModule creates instance with raw, id, url, and redirect properties and type 'redirect'","RedirectedModule toJSON serializes module metadata including raw, id, url, redirect, and type","RedirectedModule fromJSON reconstructs a RedirectedModule instance from serialized data","MockerRegistry registers and resolves RedirectedModule instances by url and id"],"goal":"verify @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7","kind":"HOW","packages":["pkg:npm/%40vitest/mocker@3.2.7"],"schemaVersion":1,"symbols":["@vitest/mocker.RedirectedModule"]},"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/%40vitest/mocker@3.2.7"],"schemaVersion":1,"subject":"pkg:npm/%40vitest/mocker@3.2.7","symbols":["@vitest/mocker.RedirectedModule"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-vitest-mocker-redirected-module",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-vitest-mocker-redirected-module",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@vitest/mocker": "3.2.7"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    },
    "node_modules/@types/estree": {
      "version": "1.0.9",
      "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz",
      "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==",
      "license": "MIT"
    },
    "node_modules/@vitest/mocker": {
      "version": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.2.7.tgz",
      "integrity": "sha512-Trr0hYO9CM3Wj6ksWHRhK9IZpIY6wTMO5u/MqXurMxT57sWBaOPEtP3Oq60ihZuh5JsiagKfz95OcxdEP6dBrA==",
      "license": "MIT",
      "dependencies": {
        "@vitest/spy": "3.2.7",
        "estree-walker": "^3.0.3",
        "magic-string": "^0.30.17"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      },
      "peerDependencies": {
        "msw": "^2.4.9",
        "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
      },
      "peerDependenciesMeta": {
        "msw": {
          "optional": true
        },
        "vite": {
          "optional": true
        }
      }
    },
    "node_modules/@vitest/spy": {
      "version": "3.2.7",
      "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.2.7.tgz",
      "integrity": "sha512-Q2eQGI6d2L/hBtZ0qNuKcAGid68XK6cv1xsoaIma6PaJhHPoqcEJhYpXZ/5myCMqkNgtP6UKuBhbc0nHKnrkuQ==",
      "license": "MIT",
      "dependencies": {
        "tinyspy": "^4.0.3"
      },
      "funding": {
        "url": "https://opencollective.com/vitest"
      }
    },
    "node_modules/estree-walker": {
      "version": "3.0.3",
      "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
      "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
      "license": "MIT",
      "dependencies": {
        "@types/estree": "^1.0.0"
      }
    },
    "node_modules/magic-string": {
      "version": "0.30.21",
      "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
      "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.5"
      }
    },
    "node_modules/tinyspy": {
      "version": "4.0.4",
      "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-4.0.4.tgz",
      "integrity": "sha512-azl+t0z7pw/z958Gy9svOTuzqIk6xq+NSheJzn5MMWtWTFywIacg2wUlzKFGtt3cthx0r2SxMK0yzJOR0IES7Q==",
      "license": "MIT",
      "engines": {
        "node": ">=14.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-vitest-mocker-redirected-module",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@vitest/mocker": "3.2.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @vitest/mocker.RedirectedModule in pkg:npm/%40vitest/mocker@3.2.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40vitest/mocker@3.2.7"
  ],
  "symbols": [
    "@vitest/mocker.RedirectedModule"
  ]
}
src/index.mjs
import { RedirectedModule, MockerRegistry } from "@vitest/mocker";

export function createRedirectedModule(raw, id, url, redirect) {
  return new RedirectedModule(raw, id, url, redirect);
}

export function serializeRedirectedModule(module) {
  return module.toJSON();
}

export function deserializeRedirectedModule(data) {
  return RedirectedModule.fromJSON(data);
}

export function registerRedirect(registry, raw, id, url, redirect) {
  return registry.register("redirect", raw, id, url, redirect);
}

export { RedirectedModule, MockerRegistry };
test/contract.mjs
import assert from "node:assert/strict";
import { RedirectedModule, MockerRegistry } from "@vitest/mocker";
import {
  createRedirectedModule,
  serializeRedirectedModule,
  deserializeRedirectedModule,
  registerRedirect
} from "../src/index.mjs";

// Test 1: RedirectedModule creates instance with raw, id, url, and redirect properties and type 'redirect'
{
  const raw = "axios";
  const id = "/mock/path/node_modules/axios/index.js";
  const url = "/@mock/axios";
  const redirect = "/mock/path/mocks/axios.js";

  const module = createRedirectedModule(raw, id, url, redirect);
  assert.equal(module instanceof RedirectedModule, true);
  assert.equal(module.type, "redirect");
  assert.equal(module.raw, raw);
  assert.equal(module.id, id);
  assert.equal(module.url, url);
  assert.equal(module.redirect, redirect);
}

// Test 2: RedirectedModule toJSON serializes module metadata including raw, id, url, redirect, and type
{
  const raw = "lodash";
  const id = "/project/node_modules/lodash/index.js";
  const url = "/@mock/lodash";
  const redirect = "/project/mocks/lodash.js";

  const module = new RedirectedModule(raw, id, url, redirect);
  const serialized = serializeRedirectedModule(module);

  assert.deepEqual(serialized, {
    type: "redirect",
    url: "/@mock/lodash",
    raw: "lodash",
    id: "/project/node_modules/lodash/index.js",
    redirect: "/project/mocks/lodash.js"
  });
}

// Test 3: RedirectedModule fromJSON reconstructs a RedirectedModule instance from serialized data
{
  const serialized = {
    type: "redirect",
    url: "/@mock/service",
    raw: "my-service",
    id: "/app/src/service.js",
    redirect: "/app/src/__mocks__/service.js"
  };

  const reconstructed = deserializeRedirectedModule(serialized);
  assert.equal(reconstructed instanceof RedirectedModule, true);
  assert.equal(reconstructed.type, "redirect");
  assert.equal(reconstructed.raw, serialized.raw);
  assert.equal(reconstructed.id, serialized.id);
  assert.equal(reconstructed.url, serialized.url);
  assert.equal(reconstructed.redirect, serialized.redirect);
}

// Test 4: MockerRegistry registers and resolves RedirectedModule instances by url and id
{
  const registry = new MockerRegistry();
  const raw = "database";
  const id = "/app/src/db.js";
  const url = "/@mock/db";
  const redirect = "/app/test/mock-db.js";

  const registered = registerRedirect(registry, raw, id, url, redirect);
  assert.equal(registered instanceof RedirectedModule, true);
  assert.equal(registered.type, "redirect");

  assert.equal(registry.has(url), true);
  assert.equal(registry.get(url), registered);
  assert.equal(registry.getById(id), registered);

  // Deserialized registration
  const serialized = registered.toJSON();
  const registry2 = new MockerRegistry();
  const registeredFromJSON = registry2.register(serialized);
  assert.equal(registeredFromJSON instanceof RedirectedModule, true);
  assert.equal(registry2.has(url), true);
  assert.equal(registry2.get(url)?.redirect, redirect);
  assert.equal(registry2.getById(id)?.redirect, redirect);
}

console.log("All @vitest/mocker.RedirectedModule contract tests passed successfully.");

Seeder de origen

anónimo