Files
PersonalBlog/tests/workspace-config.test.mjs
T
implementer 97c5306768
CI / Frozen lockfile install (pull_request) Successful in 43s
CI / Secrets not embedded (E00-S02-T08) (pull_request) Successful in 30s
CI / Database-postgres import isolation (E00-S03-T02) (pull_request) Successful in 31s
CI / Compose config (E00-S03-T01) (pull_request) Successful in 24s
test: lock in pg/Kysely import isolation to database-postgres (E00-S03-T02)
- database-postgres-imports.test.mjs: static scan of every workspace package
  source proves pg/kysely import specifiers resolve only to
  packages/database-postgres; owner manifest pins the driver and no other
  package declares it; mutation probes prove the scan catches a driver import
  injected into apps/server/src/index.ts; comment-stripping and specifier
  matcher unit probes; CI-enforcement assertion
- workspace-layout / workspace-config / strict-tsconfig / typescript-pin:
  package-set fixtures updated to include packages/database-postgres
- docs/development/non-container.md: workspace package table and build
  expectations updated for the new package
2026-08-29 11:14:15 +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/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)',
);
});