Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367/** The function-level scenarios of the incumbent dependent-version unit tests, as differential cases.
Sources, under `package/git-policy/repository/src`: `dependent-version-bump.unit.test.ts`, `manifest-text.unit.test.ts`, `source-imports.unit.test.ts`, and the `readPublishableNames` cases of `dependent-version-bump-policy.unit.test.ts`. Each case keeps its unit test's assertion as `expected`, compared with the incumbent's result by `matches`: a whole result, or the named fields of one. */// The bin scripts sit outside the package tsconfig's include list; this reference loads the Node types./// <reference types="node" />import { graphCases } from './dependent-version-unit-graph.mjs';
/** @typedef {import('./dependent-version-types.mjs').DifferentialCase} DifferentialCase *//** @typedef {DifferentialCase & { expected: Record<string, unknown>, whole: boolean }} UnitCase */
/** Versions `patchBumpVersion` rejects. */const rejectedVersions = [ '1.0.0-alpha.1', '1.0.0+build', '01.0.0', '1.0', '1.0.x', '',];
/** The cases of `dependent-version-bump.unit.test.ts`.
@returns {UnitCase[]} cases */function bumpCases() { return [ { name: 'patchBumpVersion increments 1.2.3', kind: 'patchBumpVersion', input: { name: 'a', version: '1.2.3', }, expected: { kind: 'ok', value: '1.2.4', }, whole: true, }, { name: 'patchBumpVersion increments 0.0.9', kind: 'patchBumpVersion', input: { name: 'a', version: '0.0.9', }, expected: { kind: 'ok', value: '0.0.10', }, whole: true, }, ...rejectedVersions.map(function rejection(version) { return /** @type {UnitCase} */ ({ name: `patchBumpVersion rejects ${JSON.stringify(version)}`, kind: 'patchBumpVersion', input: { name: '@scope/a', version, }, expected: { kind: 'unsupported' }, whole: false, }); }), ];}
const formatted = '{\n "name": "a",\n "description": "version \\"x\\"",\n "publishConfig": { "version": "9.9.9" },\n "version" : "1.0.0",\n "tail": ["version"]\n}\n';
/** The cases of `manifest-text.unit.test.ts`.
@returns {UnitCase[]} cases */function manifestCases() { /** @type {[string, string, Record<string, unknown>, boolean][]} */ const facts = [ [ 'reads name, version, runtime fields in order, and development names', JSON.stringify({ name: '@scope/a', version: '1.0.0', dependencies: { '@scope/b': 'workspace:*' }, peerDependencies: { '@scope/c': '*' }, optionalDependencies: { '@scope/d': '*' }, devDependencies: { '@scope/e': 'workspace:*' } }), { kind: 'facts', name: '@scope/a', version: '1.0.0', runtime: [ '@scope/b', '@scope/c', '@scope/d' ], dev: ['@scope/e'] }, true, ], [ 'omits an absent version and treats non-object dependency fields as empty', '{"name":"a","dependencies":["b"]}', { kind: 'facts', name: 'a', version: null, runtime: [], dev: [] }, true ], [ 'rejects manifest that is not a JSON object', '[]', { error: 'shape' }, false ], [ 'rejects manifest that has no string "name"', '{"version":"1.0.0"}', { error: 'shape' }, false ], [ 'rejects manifest that has a non-string "version"', '{"name":"a","version":1}', { error: 'shape' }, false ], ]; /** @type {[string, string, Record<string, unknown>, boolean][]} */ const rewrites = [ [ 'changes only the top-level version value and keeps formatting', formatted, { kind: 'ok', value: formatted.replace( '"version" : "1.0.0"', '"version" : "1.0.1"' ) }, true ], [ 'rejects manifest that declares a different version', '{"version":"2.0.0"}', { error: 'shape' }, false ], [ 'rejects manifest that has no top-level version', '{"name":"a","nested":{"version":"1.0.0"}}', { error: 'shape' }, false ], [ 'rejects manifest that has a non-string version', '{"version":1}', { error: 'shape' }, false ], [ 'rejects manifest that ends inside a string literal', '{"name":"a', { error: 'shape' }, false ], ]; return [ ...facts.map(function toCase([title, text, expected, whole]) { return /** @type {UnitCase} */ ({ name: `readManifestDependencyFacts ${title}`, kind: 'readManifestDependencyFacts', input: { path: whole ? 'package.json' : 'package/module/a/package.json', text, }, expected, whole, }); }), ...rewrites.map(function toCase([title, text, expected, whole]) { return /** @type {UnitCase} */ ({ name: `replaceManifestVersion ${title}`, kind: 'replaceManifestVersion', input: { path: 'package.json', text, from: '1.0.0', to: '1.0.1', }, expected, whole, }); }), ];}
/** Sources `importsPackage` detects, then ones it ignores. */const detected = [ "import { a } from '@scope/b';", 'import type { A } from "@scope/b/ts";', "import '@scope/b';", "export * from '@scope/b';", "const m = await import('@scope/b');", 'const m = await import ( `@scope/b/sub` );', "const m = require('@scope/b');", "import { a }\nfrom\n'@scope/b';", "const note = '@scope/b';\nimport { a } from '@scope/b';",];
/** Sources `importsPackage` ignores. */const ignored = [ "import { a } from '@scope/bc';", "const name = '@scope/b';", "reimport '@scope/b';", "myrequire('@scope/b');", "import { a } from 'x@scope/b';", '@scope/b', '',];
/** Paths `isNonTestSourcePath` decides for `package/module/a`.
@type {[string, boolean][]} */const sourcePaths = [ [ 'package/module/a/src/index.ts', true ], [ 'package/module/a/src/deep/view.tsx', true ], [ 'package/module/a/src/index.unit.test.ts', false ], [ 'package/module/a/src/README.md', false ], [ 'package/module/a/test/index.ts', false ], [ 'package/module/ab/src/index.ts', false ],];
/** Configurations `readPublishableNames` reads, with their names.
@type {[string, string[]][]} */const configurations = [ [ "a: 1\n packages:\n - '@s/a'\n - '@s/b'\n other: x\n - '@s/c'\n", [ '@s/a', '@s/b' ] ], [ "packages:\n - '@s/a'", ['@s/a'] ], [ 'no list here\n', [] ], [ "packages:\n - ''\n", [] ],];
/** The cases of `source-imports.unit.test.ts`.
@returns {UnitCase[]} cases */function scanCases() { return [ ...[ ...detected, ...ignored ].map(function toCase(sourceText) { const found = detected.includes(sourceText); return /** @type {UnitCase} */ ({ name: `importsPackage ${found ? 'detects' : 'ignores'} ${JSON.stringify(sourceText)}`, kind: 'importsPackage', input: { sourceText, packageName: '@scope/b', }, expected: { kind: 'bool', value: found, }, whole: true, }); }), ...sourcePaths.map(function toCase([path, accepted]) { return /** @type {UnitCase} */ ({ name: `isNonTestSourcePath ${accepted ? 'accepts' : 'rejects'} ${path}`, kind: 'isNonTestSourcePath', input: { directory: 'package/module/a', path, }, expected: { kind: 'bool', value: accepted, }, whole: true, }); }), ];}
/** The `readPublishableNames` cases of `dependent-version-bump-policy.unit.test.ts`.
@returns {UnitCase[]} cases */export function publishableScenarios() { return configurations.map(function toCase([configText, names]) { return /** @type {UnitCase} */ ({ name: `readPublishableNames reads ${JSON.stringify(configText)}`, kind: 'readPublishableNames', input: { configText }, expected: { kind: 'names', value: names, }, whole: true, }); });}
/** Every function-level scenario except the publishable-name ones, with its assertion.
@returns {UnitCase[]} cases */export function functionScenarios() { return [ ...bumpCases(), ...graphCases(), ...manifestCases(), ...scanCases(), ];}