CodeSampleX

Sample

postcss 8.5.26: Container#insertBefore

Verified sample for npm postcss 8.5.26: Container#insertBefore. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:0765475c602341b029e43d30719b524de3cf38489ec1202ad4d165dad02ef81c

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:d91480838ac982c9 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 Container#insertBefore in pkg:npm/postcss@8.5.26
Packages
Symbols
  • Container#insertBefore
Environment
node 22.23.2
Created
2026-08-27T01:53:31Z

Contract

  1. assert insertBefore inserts a Node before an existing child Node and returns the container instance
  2. assert insertBefore inserts a Node before an existing child at a numeric index
  3. assert insertBefore parses and inserts raw object declarations or rules before a target child
  4. assert insertBefore inserts an array of multiple nodes before an existing child
  5. assert insertBefore moves an existing child node to a new position without duplicating it
  6. assert insertBefore moves a child node from another container and updates its parent reference

Files

  • PROMPT.md
  • csx.json
  • index.js
  • 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 Container#insertBefore 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:
  - Container#insertBefore

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:ecaf91baf6d8a356626b41774255e9cc18e66399cc14efc0c41d0fcc0f1f2290","contract":["assert insertBefore inserts a Node before an existing child Node and returns the container instance","assert insertBefore inserts a Node before an existing child at a numeric index","assert insertBefore parses and inserts raw object declarations or rules before a target child","assert insertBefore inserts an array of multiple nodes before an existing child","assert insertBefore moves an existing child node to a new position without duplicating it","assert insertBefore moves a child node from another container and updates its parent reference"],"goal":"verify Container#insertBefore in pkg:npm/postcss@8.5.26","kind":"HOW","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"symbols":["Container#insertBefore"]},"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/postcss@8.5.26"],"schemaVersion":1,"subject":"pkg:npm/postcss@8.5.26","symbols":["Container#insertBefore"],"verifierAdapter":"node-typescript@1"}
index.js
const postcss = require("postcss");

function insertNodeBefore(container, existChild, newChild) {
  return container.insertBefore(existChild, newChild);
}

function insertBeforeIndex(container, index, newChild) {
  return container.insertBefore(index, newChild);
}

function insertRawBefore(container, existChild, rawSpec) {
  return container.insertBefore(existChild, rawSpec);
}

function insertManyBefore(container, existChild, nodesArray) {
  return container.insertBefore(existChild, nodesArray);
}

module.exports = {
  postcss,
  insertNodeBefore,
  insertBeforeIndex,
  insertRawBefore,
  insertManyBefore,
};
package-lock.json
{
  "name": "sample-postcss-insert-before",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss-insert-before",
      "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-insert-before",
  "version": "1.0.0",
  "description": "Minimal clean-room sample verifying Container#insertBefore in postcss",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "postcss": "8.5.26"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify Container#insertBefore in pkg:npm/postcss@8.5.26",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss@8.5.26"
  ],
  "symbols": [
    "Container#insertBefore"
  ]
}
test/contract.mjs
import assert from "node:assert";
import postcss from "postcss";
import {
  insertNodeBefore,
  insertBeforeIndex,
  insertRawBefore,
  insertManyBefore,
} from "../index.js";

// 1. Insert Node before an existing child Node and return container
{
  const root = postcss.root();
  const ruleA = postcss.rule({ selector: ".a" });
  const ruleB = postcss.rule({ selector: ".b" });
  root.append(ruleB);

  const returned = insertNodeBefore(root, ruleB, ruleA);
  assert.strictEqual(returned, root, "insertBefore must return the container instance");
  assert.strictEqual(root.nodes.length, 2, "Root should have 2 nodes");
  assert.strictEqual(root.nodes[0], ruleA, "ruleA should be at index 0");
  assert.strictEqual(root.nodes[1], ruleB, "ruleB should be at index 1");
  assert.strictEqual(ruleA.parent, root, "ruleA parent should be root");
}

// 2. Insert Node using numeric index
{
  const root = postcss.root();
  const rule1 = postcss.rule({ selector: ".one" });
  const rule2 = postcss.rule({ selector: ".two" });
  const rule3 = postcss.rule({ selector: ".three" });
  root.append(rule1);
  root.append(rule3);

  const returned = insertBeforeIndex(root, 1, rule2);
  assert.strictEqual(returned, root, "insertBefore must return the container instance");
  assert.strictEqual(root.nodes.length, 3, "Root should have 3 nodes");
  assert.strictEqual(root.nodes[0], rule1);
  assert.strictEqual(root.nodes[1], rule2);
  assert.strictEqual(root.nodes[2], rule3);
}

// 3. Insert raw object specification (Declaration / Rule)
{
  const rule = postcss.rule({ selector: ".main" });
  const declColor = postcss.decl({ prop: "color", value: "blue" });
  rule.append(declColor);

  insertRawBefore(rule, declColor, { prop: "margin", value: "0" });
  assert.strictEqual(rule.nodes.length, 2);
  assert.strictEqual(rule.nodes[0].prop, "margin");
  assert.strictEqual(rule.nodes[0].value, "0");
  assert.strictEqual(rule.nodes[1].prop, "color");
  assert.strictEqual(rule.nodes[1].value, "blue");
}

// 4. Insert array of multiple nodes
{
  const root = postcss.root();
  const lastRule = postcss.rule({ selector: ".last" });
  root.append(lastRule);

  const node1 = postcss.decl({ prop: "opacity", value: "1" });
  const node2 = postcss.comment({ text: "important" });
  insertManyBefore(root, lastRule, [node1, node2]);

  assert.strictEqual(root.nodes.length, 3);
  assert.strictEqual(root.nodes[0], node1);
  assert.strictEqual(root.nodes[1], node2);
  assert.strictEqual(root.nodes[2], lastRule);
}

// 5. Move existing node to a new position without duplicating it
{
  const root = postcss.root();
  const first = postcss.rule({ selector: ".first" });
  const middle = postcss.rule({ selector: ".middle" });
  const last = postcss.rule({ selector: ".last" });
  root.append(first);
  root.append(middle);
  root.append(last);

  insertNodeBefore(root, middle, last);
  assert.strictEqual(root.nodes.length, 3, "Moving existing node should not duplicate it");
  assert.strictEqual(root.nodes[0], first);
  assert.strictEqual(root.nodes[1], last);
  assert.strictEqual(root.nodes[2], middle);
}

// 6. Move node from another container and update parent reference
{
  const containerA = postcss.root();
  const containerB = postcss.root();
  const item = postcss.rule({ selector: ".item" });
  const target = postcss.rule({ selector: ".target" });

  containerA.append(item);
  containerB.append(target);

  insertNodeBefore(containerB, target, item);
  assert.strictEqual(containerA.nodes.length, 0, "Item should be removed from original container");
  assert.strictEqual(containerB.nodes.length, 2, "Item should be added to target container");
  assert.strictEqual(containerB.nodes[0], item);
  assert.strictEqual(containerB.nodes[1], target);
  assert.strictEqual(item.parent, containerB);
}

console.log("All Container#insertBefore contract assertions passed.");

Origin Seeder

anonymous