or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Store Integrity Checker

A utility for verifying the integrity of packages in a content-addressable file store.

Overview

Build a tool that can verify package integrity in a content-addressable storage system where files are stored by their cryptographic hash. The system should be able to check that stored files match their expected content hashes and detect any corrupted or missing files.

Capabilities

Hash Calculation

Calculate cryptographic hashes for file content to verify integrity.

  • Given a Buffer containing file data, computes its SHA-512 hash and returns it as a hex string @test
  • Given an empty Buffer, returns the SHA-512 hash of empty content @test

Content-Addressable Path Generation

Generate storage paths based on content hashes following the pattern used in content-addressable file systems.

  • Given a hash string "abc123def456...", generates a path like "ab/abc123def456" where the first 2 characters form a prefix directory @test
  • Given a hash and executable flag true, appends "-exec" suffix to the path @test

File Integrity Verification

Verify that files in storage match their expected content hashes.

  • Given a file path and expected hash, reads the file and returns true if computed hash matches expected hash @test
  • Given a file path and expected hash, returns false if the computed hash does not match @test
  • Given a non-existent file path, throws an error indicating file not found @test

Store Integrity Check

Check integrity of multiple files in a content-addressable store directory.

  • Given a store directory and a map of expected files with their hashes, returns a report listing all valid files @test
  • Given a store with some corrupted files, returns a report identifying which files are corrupted @test

Implementation

@generates

API

/**
 * Computes SHA-512 hash of the given buffer content.
 *
 * @param {Buffer} content - The content to hash
 * @returns {string} The SHA-512 hash as a hexadecimal string
 */
function computeHash(content) {
  // IMPLEMENTATION HERE
}

/**
 * Generates a content-addressable storage path from a hash.
 * Uses first 2 characters as prefix directory.
 *
 * @param {string} hash - The content hash
 * @param {boolean} isExecutable - Whether the file is executable
 * @returns {string} The storage path (e.g., "ab/abc123" or "ab/abc123-exec")
 */
function generateStoragePath(hash, isExecutable = false) {
  // IMPLEMENTATION HERE
}

/**
 * Verifies that a file's content matches its expected hash.
 *
 * @param {string} filePath - Path to the file to verify
 * @param {string} expectedHash - The expected SHA-512 hash
 * @returns {Promise<boolean>} True if hash matches, false otherwise
 * @throws {Error} If file cannot be read
 */
async function verifyFileIntegrity(filePath, expectedHash) {
  // IMPLEMENTATION HERE
}

/**
 * Checks integrity of all files in a content-addressable store.
 *
 * @param {string} storeDir - Root directory of the store
 * @param {Object.<string, string>} expectedFiles - Map of relative paths to expected hashes
 * @returns {Promise<Object>} Report with { valid: string[], corrupted: string[], missing: string[] }
 */
async function checkStoreIntegrity(storeDir, expectedFiles) {
  // IMPLEMENTATION HERE
}

module.exports = {
  computeHash,
  generateStoragePath,
  verifyFileIntegrity,
  checkStoreIntegrity
};

Dependencies { .dependencies }

pnpm { .dependency }

Provides reference implementation of content-addressable storage patterns and integrity verification.