Files
workdsh/scripts/verify-layout.mjs

98 lines
4.4 KiB
JavaScript

import { execFileSync } from 'node:child_process'
import { existsSync, lstatSync, readFileSync, readlinkSync } from 'node:fs'
import { resolve } from 'node:path'
const root = resolve(import.meta.dirname, '..')
const readJson = path => JSON.parse(readFileSync(resolve(root, path), 'utf8'))
const run = (command, args, cwd = root) => execFileSync(command, args, {
cwd,
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
}).trim()
const fail = message => { throw new Error(`verify-layout: ${message}`) }
const workspace = readJson('package.json')
const upstream = readJson('upstream.json')
const stablePlugin = readJson('dsh-plugin-desktop/package.json')
const upstreamPackage = readJson('deepseek-harness/package.json')
if (stablePlugin.name !== 'dsh-plugin-desktop') fail('the stable Desktop workspace must retain dsh-plugin-desktop')
if (typeof upstream.commit !== 'string' || typeof upstream.version !== 'string') {
fail('the pinned upstream commit and version must be recorded')
}
if (workspace.packageManager !== '[email protected]') {
fail('the product workspace must pin [email protected]')
}
if (JSON.stringify(workspace.workspaces) !== JSON.stringify(['dsh-plugin-desktop'])) {
fail('the root Yarn workspace must contain only the Desktop carrier')
}
for (const [name, manifest] of [['dsh-plugin-desktop', stablePlugin]]) {
if (manifest.packageManager !== undefined) fail(`${name} must inherit the root Yarn release`)
}
const claudePath = resolve(root, 'CLAUDE.md')
const claudeStat = lstatSync(claudePath)
// Windows checkouts materialize the symlink as a regular file holding the
// target name; accept both forms so the pointer stays verified on every host.
const claudeTarget = claudeStat.isSymbolicLink()
? readlinkSync(claudePath)
: readFileSync(claudePath, 'utf8').trim()
if (claudeTarget !== 'AGENTS.md') {
fail('CLAUDE.md must link to the outer repository AGENTS.md')
}
for (const legacyFile of [
'pnpm-lock.yaml',
'pnpm-workspace.yaml',
'dsh-plugin-desktop/pnpm-lock.yaml',
'dsh-plugin-desktop/pnpm-workspace.yaml',
]) {
if (existsSync(resolve(root, legacyFile))) fail(`${legacyFile} must not exist`)
}
if (run('git', ['config', '-f', '.gitmodules', '--get', 'submodule.deepseek-harness.path']) !== 'deepseek-harness') {
fail('the upstream submodule path must be deepseek-harness')
}
if (run('git', ['config', '-f', '.gitmodules', '--get', 'submodule.deepseek-harness.url']) !== upstream.repository) {
fail('the upstream submodule URL differs from upstream.json')
}
if (typeof upstreamPackage.packageManager !== 'string' || !upstreamPackage.packageManager.startsWith('pnpm@')) {
fail('the upstream checkout must retain its pnpm package manager')
}
for (const [owner, manifest] of [
['root', workspace],
['stable desktop', stablePlugin],
]) {
for (const field of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies', 'resolutions']) {
for (const [name, range] of Object.entries(manifest[field] ?? {})) {
if (typeof range !== 'string') continue
if (/^(?:workspace|portal|link):/u.test(range)
|| (range.startsWith('file:') && range.includes('deepseek-harness'))) {
fail(`${owner} ${field}.${name} bypasses the published DSH package boundary`)
}
}
}
}
const [mode, object] = run('git', ['ls-files', '--stage', '--', 'deepseek-harness']).split(/\s+/u)
if (mode !== '160000') fail('deepseek-harness must be tracked as a Git submodule')
if (object !== upstream.commit) fail(`submodule index is ${object}, expected ${upstream.commit}`)
const upstreamDir = resolve(root, 'deepseek-harness')
if (run('git', ['rev-parse', 'HEAD'], upstreamDir) !== upstream.commit) {
fail('checked-out upstream commit differs from upstream.json')
}
if (run('git', ['status', '--porcelain'], upstreamDir) !== '') {
fail('deepseek-harness contains local changes')
}
if (run('git', ['remote', 'get-url', 'origin'], upstreamDir) !== upstream.repository) {
fail('deepseek-harness origin differs from upstream.json')
}
if (upstreamPackage.version !== upstream.version) {
fail('deepseek-harness package version differs from upstream.json')
}
if (Object.keys(stablePlugin.dependencies ?? {}).some(name => name === '@deepseek-ai/dsh' || name.startsWith('@deepseek-ai/dsh-'))) {
fail('the Electron carrier must not directly depend on a second DSH runtime')
}
process.stdout.write(`verify-layout: one Electron carrier and upstream ${upstream.commit.slice(0, 10)} are consistent\n`)