Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ node_modules/

# AI
.claude/worktrees

# Tests
coverage/
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Default vocabulary: `needs-triage`, `needs-info`, `ready-for-agent`, `ready-for-

Single-context: `GLOSSARY.md` and `docs/adr/` at the repo root. See `docs/agents/domain.md`.

## Tests and coverage

`pnpm test` fails when coverage of `src/` drops below the thresholds in `vitest.config.ts`. Vitest raises them when a run beats them: commit that change. The aim is 100%.

Entry points (`scripts/*.ts`, `src/index.ts`) only parse arguments and call code in `src/`. They run as their own process, which coverage can't see, so they are left out of it; logic put there is unmeasured.

## Database migrations

A migration that creates or changes arocapi's models (`prisma/arocapi`, symlinked from the arocapi package) is named after the arocapi version: after an arocapi upgrade that changes the models, run `pnpm db:migrate --name arocapi-<version>`. Name migrations for our own models (`prisma/models`) after what they change.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"scripts": {
"postinstall": "prisma generate",
"test": "vitest run",
"test": "vitest run --coverage",
"test:watch": "vitest",
"build": "tailwindcss -i src/admin/admin.css -o src/admin/public/admin.css --minify",
"dev": "pnpm run --parallel \"/^dev:/\"",
Expand Down Expand Up @@ -76,6 +76,7 @@
"@tailwindcss/cli": "^4.3.3",
"@types/node": "^26.6.6",
"@types/oidc-provider": "^9.12.1",
"@vitest/coverage-v8": "^5.0.5",
"knip": "^6.42.1",
"lefthook": "^2.2.2",
"pino-pretty": "^13.2.0",
Expand Down
128 changes: 114 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 4 additions & 38 deletions scripts/crates-import.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
import { readdir, readFile } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { OcflError, type StorageRoot, type VersionDetails } from '@ocfl/ocfl-fs';
import { ROCrate } from 'ro-crate';
import { resolve } from 'node:path';
import { config } from '../src/configuration.ts';
import { importCrates } from '../src/crates-import.ts';
import { logger } from '../src/logger.ts';
import { openOrCreateRepository } from '../src/ocfl-repository.ts';

const source = resolve(process.argv[2] ?? 'test-data');

/** Merges the crate at `path` into its OCFL object, creating the object on first import */
async function importCrate(repository: StorageRoot, crateId: string, path: string) {
const details: VersionDetails = {
message: `Imported from ${path}`,
user: { name: 'ldacapi crates:import', address: 'https://github.com/Language-Research-Technology/ldacapi' },
};
try {
return await repository.create(crateId, details, (draft) => draft.import(path));
} catch (error) {
if (!(error instanceof OcflError && error.code === 'OBJECT_EXISTS')) {
throw error;
}
}
const object = await repository.open(crateId);
return object.update(details, (draft) => draft.import(path));
}

const repository = await openOrCreateRepository();

const directories = await readdir(source, { withFileTypes: true });
for (const directory of directories.filter((entry) => entry.isDirectory())) {
const path = join(source, directory.name);
const crate = await ROCrate.create(JSON.parse(await readFile(join(path, 'ro-crate-metadata.json'), 'utf-8')));
try {
const object = await importCrate(repository, crate.rootId, path);
logger.info({ crateId: crate.rootId, path, version: object.head.number }, 'Imported crate');
} catch (error) {
// A crate another writer holds, or one that needs recovery, is left for a person; the rest still import
const lockedAt = error instanceof OcflError ? error.lockedAt : undefined;
logger.error({ err: error, crateId: crate.rootId, path, lockedAt }, 'Cannot import crate');
process.exitCode = 1;
}
if (!(await importCrates(await openOrCreateRepository(), resolve(process.argv[2] ?? 'test-data')))) {
process.exitCode = 1;
}
logger.info({ root: config.ocfl.root }, 'Imported crates into the OCFL repository');
Loading
Loading