#!/bin/bash # Seeds the empty run workspace with a small home-library CLI (Node, node --test). # Self-contained on purpose: the run cannot read the eval directory, and the # fixture is written inline, with no path outside the workspace and no git. set -eu mkdir -p src bin tests cat > package.json <<'J' { "name": "shelf", "version": "0.2.0", "type": "module", "private": true, "bin": { "shelf": "bin/shelf.mjs" }, "scripts": { "test": "node --test", "lint": "node --check src/books.mjs" } } J cat > src/books.mjs <<'J' // A tiny home-library catalogue kept in a JSON file. import { readFileSync, writeFileSync, existsSync } from 'node:fs'; export function load(path) { return existsSync(path) ? JSON.parse(readFileSync(path, 'utf8')) : []; } export function save(path, books) { writeFileSync(path, JSON.stringify(books, null, 2) + '\n'); } export function add(books, { title, author }) { if (!title) throw new Error('title is required'); return [...books, { title, author: author ?? 'unknown', added: new Date().toISOString().slice(0, 10) }]; } J cat > bin/shelf.mjs <<'J' #!/usr/bin/env node // shelf add "" [--author <name>] | shelf list import { load, save, add } from '../src/books.mjs'; const file = process.env.SHELF_FILE ?? 'shelf.json'; const [cmd, ...rest] = process.argv.slice(2); if (cmd === 'add') { const i = rest.indexOf('--author'); const author = i >= 0 ? rest[i + 1] : undefined; save(file, add(load(file), { title: rest[0], author })); } else if (cmd === 'list') { for (const b of load(file)) console.log(`${b.title} — ${b.author}`); } else { console.error('usage: shelf add "<title>" [--author <name>] | shelf list'); process.exit(2); } J cat > tests/books.test.mjs <<'J' import { test } from 'node:test'; import assert from 'node:assert/strict'; import { add } from '../src/books.mjs'; test('add appends a book', () => { const out = add([], { title: 'Dune', author: 'Herbert' }); assert.equal(out.length, 1); assert.equal(out[0].author, 'Herbert'); }); test('add needs a title', () => assert.throws(() => add([], {}), /title is required/)); J