CodeSampleX

샘플

postcss 8.5.26: root

검증된 샘플 — npm postcss 8.5.26: root. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert postcss.root initializes an empty Root node or…

sha256:3f52996a1a3f628054593d28c0365cfbe15361cb8cf8d8c0d5fa9c7d4ea7c460

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

케이스

HOW
목표
verify postcss.root in pkg:npm/postcss@8.5.26
패키지
심벌
  • postcss.root
생성일
2026-08-27T02:14:05Z

컨트랙트

  1. assert postcss.root initializes an empty Root node or configures child nodes and raw formatting from defaults
  2. assert root.append, root.prepend, root.insertBefore, and root.insertAfter construct and order the AST node hierarchy
  3. assert root.walk, root.walkRules, root.walkDecls, root.walkAtRules, and root.walkComments traverse descendants with type and name filtering and early termination
  4. assert root.toResult processes root AST directly into LazyResult and root.toString serializes CSS with default or custom stringifiers
  5. assert root.clone performs deep AST duplication without mutating the original root and root.cleanRaws resets formatting raws

파일

  • 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 postcss.root in pkg:npm/postcss@8.5.26
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/postcss@8.5.26
Demonstrate these symbols/APIs:
  - postcss.root

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:a402d7038fcfadd24503029f15469ad79075f9d6811ddad6a7bcf31cac6dffd9","contract":["assert postcss.root initializes an empty Root node or configures child nodes and raw formatting from defaults","assert root.append, root.prepend, root.insertBefore, and root.insertAfter construct and order the AST node hierarchy","assert root.walk, root.walkRules, root.walkDecls, root.walkAtRules, and root.walkComments traverse descendants with type and name filtering and early termination","assert root.toResult processes root AST directly into LazyResult and root.toString serializes CSS with default or custom stringifiers","assert root.clone performs deep AST duplication without mutating the original root and root.cleanRaws resets formatting raws"],"goal":"verify postcss.root in pkg:npm/postcss@8.5.26","kind":"HOW","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"symbols":["postcss.root"]},"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/postcss@8.5.26"],"schemaVersion":1,"subject":"pkg:npm/postcss@8.5.26","symbols":["postcss.root"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-postcss-root",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss-root",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "postcss": "8.5.26"
      }
    },
    "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.26",
      "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz",
      "integrity": "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==",
      "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.17",
        "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-root",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "postcss": "8.5.26"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify postcss.root in pkg:npm/postcss@8.5.26",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss@8.5.26"
  ],
  "symbols": [
    "postcss.root"
  ]
}
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.root initializes an empty Root node or configures child nodes and raw formatting from defaults
{
  const emptyRoot = postcss.root();
  assert.equal(emptyRoot.type, 'root');
  assert.deepEqual(emptyRoot.nodes, []);
  assert.equal(emptyRoot.name, undefined);
  assert.equal(emptyRoot.selector, undefined);
  assert.equal(emptyRoot.first, undefined);
  assert.equal(emptyRoot.last, undefined);

  const initialRule = postcss.rule({ selector: '.box' });
  const rootWithDefaults = postcss.root({
    nodes: [initialRule],
    raws: { after: '\n', indent: '  ' }
  });
  assert.equal(rootWithDefaults.type, 'root');
  assert.equal(rootWithDefaults.nodes.length, 1);
  assert.equal(rootWithDefaults.first, initialRule);
  assert.equal(rootWithDefaults.last, initialRule);
  assert.equal(rootWithDefaults.raws.indent, '  ');
}

// 2. assert root.append, root.prepend, root.insertBefore, and root.insertAfter construct and order the AST node hierarchy
{
  const root = postcss.root();
  const mainRule = postcss.rule({ selector: 'main' });
  mainRule.append(postcss.decl({ prop: 'display', value: 'grid' }));
  root.append(mainRule);

  const headerRule = postcss.rule({ selector: 'header' });
  headerRule.append(postcss.decl({ prop: 'color', value: '#333' }));
  root.prepend(headerRule);

  assert.equal(root.first.selector, 'header');
  assert.equal(root.last.selector, 'main');
  assert.equal(root.nodes.length, 2);

  const comment = postcss.comment({ text: 'navigation' });
  root.insertBefore(mainRule, comment);
  assert.equal(root.nodes[1], comment);
  assert.equal(root.index(comment), 1);

  const footerRule = postcss.rule({ selector: 'footer' });
  root.insertAfter(comment, footerRule);
  assert.equal(root.index(footerRule), 2);
  assert.equal(root.nodes.length, 4);
}

// 3. assert root.walk, root.walkRules, root.walkDecls, root.walkAtRules, and root.walkComments traverse descendants with type and name filtering and early termination
{
  const root = postcss.root();
  const media = postcss.atRule({ name: 'media', params: 'screen and (min-width: 1024px)' });
  const rule = postcss.rule({ selector: '.container' });
  rule.append(postcss.decl({ prop: 'max-width', value: '1200px' }));
  rule.append(postcss.decl({ prop: 'margin', value: '0 auto' }));
  media.append(rule);
  root.append(media);
  root.append(postcss.comment({ text: 'footer note' }));

  const walkedTypes = [];
  root.walk((node) => {
    walkedTypes.push(node.type);
  });
  assert.deepEqual(walkedTypes, ['atrule', 'rule', 'decl', 'decl', 'comment']);

  const declProps = [];
  root.walkDecls((decl) => {
    declProps.push(decl.prop);
  });
  assert.deepEqual(declProps, ['max-width', 'margin']);

  const atRules = [];
  root.walkAtRules('media', (atRule) => {
    atRules.push(atRule.params);
  });
  assert.deepEqual(atRules, ['screen and (min-width: 1024px)']);

  const comments = [];
  root.walkComments((c) => {
    comments.push(c.text);
  });
  assert.deepEqual(comments, ['footer note']);

  let earlyCount = 0;
  root.walkDecls((decl) => {
    earlyCount++;
    return false;
  });
  assert.equal(earlyCount, 1);
}

// 4. assert root.toResult processes root AST directly into LazyResult and root.toString serializes CSS with default or custom stringifiers
{
  const root = postcss.root();
  const rule = postcss.rule({ selector: 'button.btn' });
  rule.append(postcss.decl({ prop: 'background-color', value: 'blue' }));
  rule.append(postcss.decl({ prop: 'border', value: 'none' }));
  root.append(rule);

  const lazyResult = root.toResult({ map: false });
  assert.ok(lazyResult.css);
  assert.equal(lazyResult.root, root);
  assert.equal(lazyResult.css, 'button.btn {\n    background-color: blue;\n    border: none\n}');

  assert.equal(root.toString(), 'button.btn {\n    background-color: blue;\n    border: none\n}');

  const customStringifier = (node, builder) => {
    if (node.type === 'decl') {
      builder(`${node.prop}: ${node.value};`, node);
    } else if (node.type === 'rule') {
      builder(`${node.selector} { `, node, 'start');
      node.nodes.forEach((child) => customStringifier(child, builder));
      builder(' }', node, 'end');
    } else if (node.type === 'root') {
      node.nodes.forEach((child) => customStringifier(child, builder));
    }
  };

  const customCss = root.toString(customStringifier);
  assert.equal(customCss, 'button.btn { background-color: blue;border: none; }');
}

// 5. assert root.clone performs deep AST duplication without mutating the original root and root.cleanRaws resets formatting raws
{
  const root = postcss.root();
  const rule = postcss.rule({ selector: '.card' });
  rule.append(postcss.decl({ prop: 'padding', value: '16px' }));
  root.append(rule);

  const cloned = root.clone({ raws: { after: '\n\n' } });
  assert.notEqual(cloned, root);
  assert.equal(cloned.nodes.length, 1);
  assert.equal(cloned.first.selector, '.card');
  assert.notEqual(cloned.first, root.first);

  cloned.first.append(postcss.decl({ prop: 'color', value: 'red' }));
  assert.equal(root.first.nodes.length, 1);
  assert.equal(cloned.first.nodes.length, 2);

  cloned.cleanRaws();
  assert.equal(cloned.raws.after, undefined);
  assert.equal(cloned.toString(), '.card {\n    padding: 16px;\n    color: red\n}');
}

오리진 시더

익명