CodeSampleX

Beispiel

basic-ftp 5.3.1: FileType

Verifiziertes Beispiel für npm basic-ftp 5.3.1: FileType. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:adf11c8bdb651480a47130e90c3ec0c3c123445db823d7b8dcc20ef3a870d00a

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-26
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

Fall

HOW
Ziel
verify basic-ftp.FileType in pkg:npm/basic-ftp@5.3.1
Pakete
Symbole
  • basic-ftp.FileType
Erstellt
2026-08-26T12:28:39Z

Contract

  1. FileType enumeration defines integer constants for Unknown (0), File (1), Directory (2), and SymbolicLink (3)
  2. FileType provides reverse mapping from numeric values to type name strings
  3. FileInfo instances use FileType values to determine isFile, isDirectory, and isSymbolicLink boolean states
  4. parseList parses directory listings and populates FileInfo objects with the corresponding FileType enum values

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 basic-ftp.FileType in pkg:npm/basic-ftp@5.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/basic-ftp@5.3.1
Demonstrate these symbols/APIs:
  - basic-ftp.FileType

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:8f0ed1c8f160292da49feeac3d5027a9a7898037c4665aa81240432d0d24462f","contract":["FileType enumeration defines integer constants for Unknown (0), File (1), Directory (2), and SymbolicLink (3)","FileType provides reverse mapping from numeric values to type name strings","FileInfo instances use FileType values to determine isFile, isDirectory, and isSymbolicLink boolean states","parseList parses directory listings and populates FileInfo objects with the corresponding FileType enum values"],"goal":"verify basic-ftp.FileType in pkg:npm/basic-ftp@5.3.1","kind":"HOW","packages":["pkg:npm/basic-ftp@5.3.1"],"schemaVersion":1,"symbols":["basic-ftp.FileType"]},"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/basic-ftp@5.3.1"],"schemaVersion":1,"subject":"pkg:npm/basic-ftp@5.3.1","symbols":["basic-ftp.FileType"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-basic-ftp-filetype",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-basic-ftp-filetype",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "basic-ftp": "5.3.1"
      }
    },
    "node_modules/basic-ftp": {
      "version": "5.3.1",
      "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.3.1.tgz",
      "integrity": "sha512-bopVNp6ugyA150DDuZfPFdt1KZ5a94ZDiwX4hMgZDzF+GttD80lEy8kj98kbyhLXnPvhtIo93mdnLIjpCAeeOw==",
      "license": "MIT",
      "engines": {
        "node": ">=10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-basic-ftp-filetype",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "basic-ftp": "5.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify basic-ftp.FileType in pkg:npm/basic-ftp@5.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/basic-ftp@5.3.1"
  ],
  "symbols": [
    "basic-ftp.FileType"
  ]
}
src/index.mjs
import ftp from 'basic-ftp';

const { FileType, FileInfo, parseList } = ftp;

/**
 * Resolves the string name for a given FileType enum value.
 * @param {number} fileType - The numeric FileType value.
 * @returns {string} The name of the file type.
 */
export function getFileTypeName(fileType) {
  return FileType[fileType] || 'Unknown';
}

/**
 * Creates a FileInfo instance with a specified name and FileType.
 * @param {string} name - File or directory name.
 * @param {number} type - FileType enum value.
 * @returns {ftp.FileInfo} Configured FileInfo object.
 */
export function createFileInfo(name, type) {
  const info = new FileInfo(name);
  info.type = type;
  return info;
}

/**
 * Parses raw FTP list output into FileInfo objects with FileType information.
 * @param {string} rawEntries - Raw directory listing string.
 * @returns {ftp.FileInfo[]} Array of parsed FileInfo objects.
 */
export function parseDirectoryList(rawEntries) {
  return parseList(rawEntries);
}

export { FileType, FileInfo, parseList };
export default FileType;
test/contract.mjs
import assert from 'node:assert/strict';
import ftp from 'basic-ftp';
import {
  FileType,
  FileInfo,
  parseList,
  getFileTypeName,
  createFileInfo,
  parseDirectoryList
} from '../src/index.mjs';

// 1. FileType enumeration defines integer constants for Unknown (0), File (1), Directory (2), and SymbolicLink (3)
{
  assert.equal(FileType.Unknown, 0);
  assert.equal(FileType.File, 1);
  assert.equal(FileType.Directory, 2);
  assert.equal(FileType.SymbolicLink, 3);
}

// 2. FileType provides reverse mapping from numeric values to type name strings
{
  assert.equal(FileType[0], 'Unknown');
  assert.equal(FileType[1], 'File');
  assert.equal(FileType[2], 'Directory');
  assert.equal(FileType[3], 'SymbolicLink');

  assert.equal(getFileTypeName(FileType.Unknown), 'Unknown');
  assert.equal(getFileTypeName(FileType.File), 'File');
  assert.equal(getFileTypeName(FileType.Directory), 'Directory');
  assert.equal(getFileTypeName(FileType.SymbolicLink), 'SymbolicLink');
}

// 3. FileInfo instances use FileType values to determine isFile, isDirectory, and isSymbolicLink boolean states
{
  const file = createFileInfo('example.txt', FileType.File);
  assert.equal(file.name, 'example.txt');
  assert.equal(file.type, FileType.File);
  assert.equal(file.isFile, true);
  assert.equal(file.isDirectory, false);
  assert.equal(file.isSymbolicLink, false);

  const dir = createFileInfo('docs', FileType.Directory);
  assert.equal(dir.name, 'docs');
  assert.equal(dir.type, FileType.Directory);
  assert.equal(dir.isFile, false);
  assert.equal(dir.isDirectory, true);
  assert.equal(dir.isSymbolicLink, false);

  const link = createFileInfo('link-to-doc', FileType.SymbolicLink);
  assert.equal(link.name, 'link-to-doc');
  assert.equal(link.type, FileType.SymbolicLink);
  assert.equal(link.isFile, false);
  assert.equal(link.isDirectory, false);
  assert.equal(link.isSymbolicLink, true);

  const unknown = createFileInfo('unknown-entry', FileType.Unknown);
  assert.equal(unknown.type, FileType.Unknown);
  assert.equal(unknown.isFile, false);
  assert.equal(unknown.isDirectory, false);
  assert.equal(unknown.isSymbolicLink, false);
}

// 4. parseList parses directory listings and populates FileInfo objects with the corresponding FileType enum values
{
  const rawList = [
    '-rw-r--r-- 1 owner group 1024 Jan 01 00:00 notes.txt',
    'drwxr-xr-x 2 owner group 4096 Jan 01 00:00 projects',
    'lrwxrwxrwx 1 owner group    9 Jan 01 00:00 shortcut -> notes.txt'
  ].join('\n');

  const parsed = parseDirectoryList(rawList);
  assert.equal(parsed.length, 3);

  assert.equal(parsed[0].name, 'notes.txt');
  assert.equal(parsed[0].type, FileType.File);
  assert.equal(parsed[0].isFile, true);

  assert.equal(parsed[1].name, 'projects');
  assert.equal(parsed[1].type, FileType.Directory);
  assert.equal(parsed[1].isDirectory, true);

  assert.equal(parsed[2].name, 'shortcut');
  assert.equal(parsed[2].type, FileType.SymbolicLink);
  assert.equal(parsed[2].isSymbolicLink, true);
}

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

Ursprungs-Seeder

anonym