Files
PersonalBlog/tests/workspace-config.test.mjs
implementer bcea489391 feat: add TypeBox/Ajv config schema package to the workspace (E00-S04-T01)
Adds packages/config (@personal-blog/config) — the EPPP configuration
service foundation. The package defines the configuration schema with
TypeBox (configSchema: host, port, databaseUrl, sessionSecret — the
validated config fields, golden-tuple pins @sinclair/typebox@0.34.52 and
ajv@8.20.0) and compiles it with Ajv (validateConfig). The environment
adapter (T04), field-specific startup errors (T02) and secret redaction
(T03) build on this boundary in later tasks; nothing reads process.env yet.

Wiring for the new workspace package: lockfile importer + resolved
typebox/ajv tree, apps/server/Dockerfile manifest copy (frozen in-image
install must match the lockfile importers), config-schema CI job, package
set fixtures (workspace-layout, workspace-config, strict-tsconfig,
typescript-pin), probe-file gitignore entry.
2026-08-30 02:29:52 +00:00

87 lines
3.5 KiB
JavaScript

/**
* Workspace configuration test — locks in the committed pnpm 11.23.0
* workspace for [E00-S01-T07] pnpm 11.23.0 workspace committed.
*
* Acceptance criteria covered (each test fails without the committed config):
* - "pnpm 11.23.0 workspace is committed" → root `package.json` pins
* `packageManager` to `pnpm@11.23.0`; `pnpm-workspace.yaml` declares the
* three package groups; `pnpm-lock.yaml` is committed with lockfile
* version 9.0 and an importer for every workspace package.
* - "install uses the committed pnpm version" → corepack resolves the
* pinned version (`corepack pnpm --version` == 11.23.0), and the
* committed CI workflow enables corepack and installs with
* `--frozen-lockfile` so the lockfile is the single source of truth.
*
* Run: `node --test tests/workspace-config.test.mjs`
* (node:test — built into Node >= 18; no dependencies, lockfile untouched.)
*/
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const read = (relPath) => readFileSync(path.join(REPO_ROOT, relPath), 'utf8');
const WORKSPACE_GROUPS = ['apps/*', 'packages/*', 'extensions/*'];
const WORKSPACE_PACKAGES = ['.', 'apps/server', 'packages/core', 'packages/config', 'packages/database-postgres', 'extensions/example'];
const PINNED_PNPM = '11.23.0';
// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------
test('root package.json pins packageManager to pnpm@11.23.0', () => {
const manifest = JSON.parse(read('package.json'));
assert.equal(manifest.packageManager, `pnpm@${PINNED_PNPM}`);
});
test('pnpm-workspace.yaml is committed and declares the three workspace groups', () => {
const workspace = read('pnpm-workspace.yaml');
for (const group of WORKSPACE_GROUPS) {
assert.ok(workspace.includes(group), `pnpm-workspace.yaml must declare group "${group}"`);
}
});
test('pnpm-lock.yaml is committed with lockfile version 9.0', () => {
const lockfile = read('pnpm-lock.yaml');
assert.ok(
lockfile.startsWith("lockfileVersion: '9.0'"),
'pnpm-lock.yaml must be the pnpm 9.x lockfile format written by pnpm 11.23.0',
);
});
test('pnpm-lock.yaml has an importer for every workspace package', () => {
const lockfile = read('pnpm-lock.yaml');
for (const pkg of WORKSPACE_PACKAGES) {
const entry = pkg === '.' ? ' .:' : ` ${pkg}:`;
assert.ok(
lockfile.includes(entry),
`pnpm-lock.yaml must contain an importer for "${pkg}"`,
);
}
});
test('corepack resolves the committed pnpm version (11.23.0)', () => {
const result = spawnSync('corepack', ['pnpm', '--version'], {
cwd: REPO_ROOT,
encoding: 'utf8',
timeout: 60_000,
});
assert.equal(result.status, 0, `corepack pnpm --version failed: ${result.stderr?.trim()}`);
assert.equal(result.stdout.trim(), PINNED_PNPM);
});
test('committed CI workflow enables corepack and installs with the frozen lockfile', () => {
const workflow = read('.gitea/workflows/ci.yml');
assert.ok(workflow.includes('corepack enable'), 'CI must enable corepack (pinned pnpm)');
assert.ok(
workflow.includes('pnpm install --frozen-lockfile'),
'CI must install with the committed lockfile (--frozen-lockfile)',
);
});