Files
ComfyUI_frontend/scripts/prepare-workflow-validation.ts
Glary-Bot 5adeb0c9fe test(validation): tighten test patterns per pythongosssss review
- prepare-workflow-validation.ts: parse pnpm-workspace.yaml with the
  `yaml` package instead of a regex; safer for any future formatting
  drift in the catalog block.
- useWorkflowValidation: use the global `structuredClone` directly
  instead of the in-tree `clone` helper. The helper falls back to
  JSON parse/stringify in legacy environments, which is irrelevant
  here (vitest happy-dom + production targets all support
  `structuredClone`), and removing the import drops a transitive
  dep on `@/scripts/utils` which made the composable harder to
  unit-test.
- linkRepair.test.ts: drop the synthetic 'patched view diverges'
  fixture (it didn't actually trigger the throw, exactly the
  false-positive pythongosssss called out) and the duplicate
  describeTopologyError-via-abort block (already covered in
  linkTopology.test.ts). The abort path is now exercised structurally
  in useWorkflowValidation.test.ts where a mocked
  `LinkRepairAbortedError` flows through the catch.
- linkRepair.test.ts: keep the live-graph cast — the live-graph
  branch in `repairLinks` genuinely accesses `graph.links` as a
  record at runtime even though the published type is an array, so
  the test fixture needs to mirror that mismatch.
- useWorkflowValidation.test.ts: use `createTestingPinia({
  stubActions: false })`; replace the per-mock clears with
  `vi.clearAllMocks()`; trim the vue-i18n mock down to identity
  `t()` (matches what real i18n with empty messages would do); add
  a JSON-snapshot test that proves the original graph is byte-equal
  before and after an aborted repair (the prior `!== wf` assertion
  only proved a different reference, not preservation).
2026-05-07 15:50:02 +00:00

98 lines
2.5 KiB
TypeScript

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { parse as parseYaml } from 'yaml'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const repoRoot = path.resolve(__dirname, '..')
const packageDir = path.join(repoRoot, 'packages', 'workflow-validation')
const distDir = path.join(packageDir, 'dist')
interface SourcePackage {
name: string
version: string
description?: string
license?: string
repository?: string
homepage?: string
dependencies?: Record<string, string>
publishConfig?: Record<string, unknown>
}
interface PnpmWorkspace {
catalog?: Record<string, string>
}
const sourcePackage = JSON.parse(
fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')
) as SourcePackage
const workspace = parseYaml(
fs.readFileSync(path.join(repoRoot, 'pnpm-workspace.yaml'), 'utf8')
) as PnpmWorkspace
const catalog = workspace.catalog ?? {}
function resolveCatalog(name: string): string {
const sourceVersion = sourcePackage.dependencies?.[name]
if (sourceVersion && sourceVersion !== 'catalog:') return sourceVersion
const version = catalog[name]
if (!version) {
throw new Error(
`Could not resolve catalog version for ${name}. ` +
`Expected entry under \`catalog:\` in pnpm-workspace.yaml.`
)
}
return version
}
const distPackage = {
name: sourcePackage.name,
version: sourcePackage.version,
description: sourcePackage.description,
license: sourcePackage.license,
repository: sourcePackage.repository,
homepage: sourcePackage.homepage,
type: 'module',
main: './index.js',
module: './index.js',
types: './index.d.ts',
exports: {
'.': {
types: './index.d.ts',
import: './index.js'
},
'./linkRepair': {
types: './linkRepair.d.ts',
import: './index.js'
},
'./linkTopology': {
types: './linkTopology.d.ts',
import: './index.js'
},
'./workflowSchema': {
types: './workflowSchema.d.ts',
import: './index.js'
},
'./serialised': {
types: './serialised.d.ts',
import: './index.js'
}
},
files: ['*.js', '*.d.ts'],
publishConfig: sourcePackage.publishConfig ?? { access: 'public' },
dependencies: {
zod: resolveCatalog('zod'),
'zod-validation-error': resolveCatalog('zod-validation-error')
}
}
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true })
}
fs.writeFileSync(
path.join(distDir, 'package.json'),
JSON.stringify(distPackage, null, 2) + '\n'
)
console.warn(`Prepared ${distPackage.name}@${distPackage.version} in dist/`)