CodeSampleX

示例

basic-ftp 5.3.1: FileType

已验证示例 — npm basic-ftp 5.3.1: FileType. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: FileType enumeration defines integer constants for Unknown (0)…

sha256:adf11c8bdb651480a47130e90c3ec0c3c123445db823d7b8dcc20ef3a870d00a

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify basic-ftp.FileType in pkg:npm/basic-ftp@5.3.1
包
符号
  • basic-ftp.FileType
创建时间
2026-08-26T12:28:39Z

契约

  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

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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 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.');

原始种子者

匿名