CodeSampleX

Пример

postcss 8.5.25

Проверенный пример — npm postcss 8.5.25. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: assert postcss.parse parses CSS into an AST Root…

sha256:1a22e71fbe88e6f1587f7d914680dace98a77d685987da9632aed9aa0bcd13a7

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Кейс

HOW
Цель
verify pkg:npm/postcss@8.5.25
Пакеты
Окружение
node 22.23.2
Создан
2026-08-20T19:23:24Z

Контракт

  1. assert postcss.parse parses CSS into an AST Root node containing AtRule, Rule, Declaration, and Comment child nodes
  2. assert root.walkDecls and root.walkRules traverse descendant nodes with optional property or selector name filtering
  3. assert postcss.root, postcss.rule, and postcss.decl construct AST nodes programmatically and serialize into formatted CSS
  4. assert AST mutation methods including clone, replaceWith, remove, and after modify the node tree and update toString output
  5. assert postcss.parse throws CssSyntaxError with line and column information when parsing malformed or unclosed CSS syntax

Файлы

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

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

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/postcss@8.5.25
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/postcss@8.5.25
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - runtime: node@22.23.2

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:7050818d06e979d5a263bdb8401bf62409812414f7d2aef0cfebfaa3ff43731e","constraints":{"executionContext":"node"},"contract":["assert postcss.parse parses CSS into an AST Root node containing AtRule, Rule, Declaration, and Comment child nodes","assert root.walkDecls and root.walkRules traverse descendant nodes with optional property or selector name filtering","assert postcss.root, postcss.rule, and postcss.decl construct AST nodes programmatically and serialize into formatted CSS","assert AST mutation methods including clone, replaceWith, remove, and after modify the node tree and update toString output","assert postcss.parse throws CssSyntaxError with line and column information when parsing malformed or unclosed CSS syntax"],"goal":"verify pkg:npm/postcss@8.5.25","kind":"HOW","packages":["pkg:npm/postcss@8.5.25"],"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","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/postcss@8.5.25"],"schemaVersion":1,"subject":"pkg:npm/postcss@8.5.25","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-postcss",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "postcss": "8.5.25"
      }
    },
    "node_modules/nanoid": {
      "version": "3.3.18",
      "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz",
      "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "bin": {
        "nanoid": "bin/nanoid.cjs"
      },
      "engines": {
        "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
      }
    },
    "node_modules/picocolors": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
      "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
      "license": "ISC"
    },
    "node_modules/postcss": {
      "version": "8.5.25",
      "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.25.tgz",
      "integrity": "sha512-DTPx3RWSSnWyzLxQnlH0rJP+EW5ekl16ZU4/psbIhA0e53kJfdgaN5vKM+xP7yJtXVu+nfdVFmlgFDEKAe4Pyw==",
      "funding": [
        {
          "type": "opencollective",
          "url": "https://opencollective.com/postcss/"
        },
        {
          "type": "tidelift",
          "url": "https://tidelift.com/funding/github/npm/postcss"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "nanoid": "^3.3.16",
        "picocolors": "^1.1.1",
        "source-map-js": "^1.2.1"
      },
      "engines": {
        "node": "^10 || ^12 || >=14"
      }
    },
    "node_modules/source-map-js": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
      "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-postcss",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "postcss": "8.5.25"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/postcss@8.5.25",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss@8.5.25"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const postcss = require('postcss');

// 1. assert postcss.parse parses CSS into an AST Root node containing AtRule, Rule, Declaration, and Comment child nodes
{
  const css = `
    /* Navigation header */
    @media screen and (min-width: 768px) {
      .header {
        color: #333333;
        font-size: 16px !important;
      }
    }
  `;
  const root = postcss.parse(css);
  assert.equal(root.type, 'root');
  assert.equal(root.nodes.length, 2);

  const comment = root.nodes[0];
  assert.equal(comment.type, 'comment');
  assert.equal(comment.text, 'Navigation header');

  const atRule = root.nodes[1];
  assert.equal(atRule.type, 'atrule');
  assert.equal(atRule.name, 'media');
  assert.equal(atRule.params, 'screen and (min-width: 768px)');
  assert.equal(atRule.nodes.length, 1);

  const rule = atRule.nodes[0];
  assert.equal(rule.type, 'rule');
  assert.equal(rule.selector, '.header');
  assert.equal(rule.nodes.length, 2);

  const [colorDecl, fontDecl] = rule.nodes;
  assert.equal(colorDecl.type, 'decl');
  assert.equal(colorDecl.prop, 'color');
  assert.equal(colorDecl.value, '#333333');
  assert.equal(Boolean(colorDecl.important), false);

  assert.equal(fontDecl.type, 'decl');
  assert.equal(fontDecl.prop, 'font-size');
  assert.equal(fontDecl.value, '16px');
  assert.equal(fontDecl.important, true);
}

// 2. assert root.walkDecls and root.walkRules traverse descendant nodes with optional property or selector name filtering
{
  const css = `
    .card { color: #111; background: #fff; }
    .footer { color: #222; border: 1px solid #ccc; }
  `;
  const root = postcss.parse(css);

  const colorValues = [];
  root.walkDecls('color', (decl) => {
    colorValues.push(decl.value);
  });
  assert.deepEqual(colorValues, ['#111', '#222']);

  const allProps = [];
  root.walkDecls((decl) => {
    allProps.push(decl.prop);
  });
  assert.deepEqual(allProps, ['color', 'background', 'color', 'border']);

  const rules = [];
  root.walkRules('.card', (rule) => {
    rules.push(rule.selector);
  });
  assert.deepEqual(rules, ['.card']);
}

// 3. assert postcss.root, postcss.rule, and postcss.decl construct AST nodes programmatically and serialize into formatted CSS
{
  const customRoot = postcss.root();
  const rule = postcss.rule({ selector: '.btn-primary' });
  rule.append(postcss.decl({ prop: 'display', value: 'inline-flex' }));
  rule.append(postcss.decl({ prop: 'padding', value: '0.5rem 1rem' }));
  customRoot.append(rule);

  const expectedCss = '.btn-primary {\n    display: inline-flex;\n    padding: 0.5rem 1rem\n}';
  assert.equal(customRoot.toString(), expectedCss);
}

// 4. assert AST mutation methods including clone, replaceWith, remove, and after modify the node tree and update toString output
{
  const css = '.box { margin: 10px; opacity: 0.8; }';
  const root = postcss.parse(css);

  root.walkDecls('margin', (decl) => {
    const cloned = decl.clone({ prop: 'padding', value: '5px' });
    decl.after(cloned);
    decl.replaceWith(postcss.decl({ prop: 'margin', value: '15px' }));
  });

  root.walkDecls('opacity', (decl) => {
    decl.remove();
  });

  const output = root.toString();
  assert.equal(output, '.box { margin: 15px; padding: 5px; }');
}

// 5. assert postcss.parse throws CssSyntaxError with line and column information when parsing malformed or unclosed CSS syntax
{
  assert.throws(
    () => postcss.parse('.unclosed { color: red;'),
    (err) => {
      return (
        err.name === 'CssSyntaxError' &&
        err.reason === 'Unclosed block' &&
        typeof err.line === 'number' &&
        typeof err.column === 'number'
      );
    }
  );
}

Исходный сидер

аноним