CodeSampleX

Exemple

basic-ftp 5.3.1: Client

Échantillon vérifié pour npm basic-ftp 5.3.1: Client. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:c5065af3583a041f62e2572b034a65feac0018735b61c1e5b9c1e27aa65e39bb

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify basic-ftp.Client in pkg:npm/basic-ftp@5.3.1
Paquets
Symboles
  • basic-ftp.Client
Créé
2026-08-26T12:22:58Z

Contrat

  1. Client instance starts in closed state and respects configured timeout parameter
  2. trackProgress allows setting and clearing progress handlers on Client
  3. access establishes FTP connection and authenticates with credentials
  4. pwd returns current working directory path
  5. cd and cdup navigate remote working directories
  6. send executes FTP commands and returns response object
  7. server failure responses reject with FTPError instance and status code
  8. close closes connection and resets closed state to true

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 basic-ftp.Client 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.Client

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:0b2c3be89575610bb291e2f10eb228f4fba23d714fe3a4649c5e4606d00948d7","contract":["Client instance starts in closed state and respects configured timeout parameter","trackProgress allows setting and clearing progress handlers on Client","access establishes FTP connection and authenticates with credentials","pwd returns current working directory path","cd and cdup navigate remote working directories","send executes FTP commands and returns response object","server failure responses reject with FTPError instance and status code","close closes connection and resets closed state to true"],"goal":"verify basic-ftp.Client in pkg:npm/basic-ftp@5.3.1","kind":"HOW","packages":["pkg:npm/basic-ftp@5.3.1"],"schemaVersion":1,"symbols":["basic-ftp.Client"]},"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.Client"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-basic-ftp",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-basic-ftp",
      "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",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "basic-ftp": "5.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify basic-ftp.Client in pkg:npm/basic-ftp@5.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/basic-ftp@5.3.1"
  ],
  "symbols": [
    "basic-ftp.Client"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import net from 'node:net';
import { Client, FTPError } from 'basic-ftp';

// 1. Initial Client state and default properties
const client = new Client(15000);
assert.strictEqual(client.closed, true, 'Client starts with closed=true');
assert.strictEqual(client.ftp.timeout, 15000, 'Client constructor sets ftp timeout');

const defaultClient = new Client();
assert.strictEqual(defaultClient.closed, true, 'Default client starts closed');
assert.strictEqual(defaultClient.ftp.timeout, 30000, 'Default timeout is 30000ms');
defaultClient.close();

// 2. Track progress handler registration
assert.strictEqual(typeof client.trackProgress, 'function', 'trackProgress is a method on Client');
client.trackProgress((info) => {});
client.trackProgress(); // clear progress handler

// 3. Setup lightweight offline mock FTP server on localhost
let currentPath = '/ftp_virtual_dir';
const server = net.createServer((socket) => {
  socket.write('220 Service ready\r\n');
  let buffer = '';
  socket.on('data', (chunk) => {
    buffer += chunk.toString();
    const lines = buffer.split('\r\n');
    buffer = lines.pop();
    for (const line of lines) {
      if (!line) continue;
      const [command, ...args] = line.split(' ');
      const arg = args.join(' ');
      switch (command.toUpperCase()) {
        case 'FEAT':
          socket.write('211-Features:\r\n UTF8\r\n211 End\r\n');
          break;
        case 'OPTS':
          socket.write('200 OPTS UTF8 set\r\n');
          break;
        case 'USER':
          socket.write('331 User name okay, need password\r\n');
          break;
        case 'PASS':
          socket.write('230 User logged in, proceed\r\n');
          break;
        case 'TYPE':
          socket.write('200 Type set to I\r\n');
          break;
        case 'PWD':
          socket.write(`257 "${currentPath}" is current directory\r\n`);
          break;
        case 'CWD':
          if (arg === 'error_dir') {
            socket.write('550 Failed to change directory\r\n');
          } else {
            currentPath = arg.startsWith('/') ? arg : `${currentPath}/${arg}`;
            socket.write(`250 Directory successfully changed to "${currentPath}"\r\n`);
          }
          break;
        case 'CDUP':
          currentPath = '/ftp_virtual_dir';
          socket.write('250 Directory successfully changed to "/ftp_virtual_dir"\r\n');
          break;
        case 'NOOP':
          socket.write('200 NOOP command successful\r\n');
          break;
        case 'QUIT':
          socket.write('221 Goodbye\r\n');
          socket.end();
          break;
        default:
          socket.write('500 Unknown command\r\n');
      }
    }
  });
});

await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const port = server.address().port;

try {
  // 4. Access / connect to FTP server
  const accessResponse = await client.access({
    host: '127.0.0.1',
    port: port,
    user: 'testuser',
    password: 'password123',
    secure: false,
  });
  assert.strictEqual(client.closed, false, 'Client is open after access()');
  assert.strictEqual(accessResponse.code, 220, 'access() returns greeting FTPResponse');

  // 5. PWD command
  const dir = await client.pwd();
  assert.strictEqual(dir, '/ftp_virtual_dir', 'pwd() returns current directory path');

  // 6. CD and CDUP commands
  await client.cd('subfolder');
  assert.strictEqual(await client.pwd(), '/ftp_virtual_dir/subfolder', 'cd() changes working directory');

  await client.cdup();
  assert.strictEqual(await client.pwd(), '/ftp_virtual_dir', 'cdup() returns to parent directory');

  // 7. Custom SEND command (NOOP)
  const noopResponse = await client.send('NOOP');
  assert.strictEqual(noopResponse.code, 200, 'send("NOOP") returns 200 response');

  // 8. Error handling on server rejection (550)
  await assert.rejects(
    async () => {
      await client.cd('error_dir');
    },
    (err) => {
      assert(err instanceof FTPError, 'Rejected error is an instance of FTPError');
      assert.strictEqual(err.code, 550, 'FTPError code matches 550 response');
      return true;
    },
    'Server 5xx error rejects with FTPError'
  );

  // 9. Close connection
  client.close();
  assert.strictEqual(client.closed, true, 'Client closed is true after close()');
} finally {
  client.close();
  await new Promise((resolve) => server.close(resolve));
}

Seeder d'origine

anonyme