Files
deepseek-harness/scripts/baseline-inventory.fixture.ts
T
turtle1999 05883ff6b5 feat(infra): reject silent empty catch clauses
AGENTS.md requires an empty `catch` to name the discarded error, state why it
needs no handling, and keep its `try` to one statement, but nothing enforced
it: 119 clauses break a condition today.

The new `verify-empty-catch` gate scans tracked and non-ignored untracked
first-party source with the TypeScript syntax tree. It records those 119 legacy
clauses by path, syntax fingerprint, and count in
`scripts/empty-catch.baseline.json`, so enforcement starts without a
repository-wide edit. A new or changed clause fails the gate, and fixing a
recorded clause requires `--prune` to retire its allowance; no command adds
one.

The recorded-inventory bookkeeping shared with `verify-no-unknown-casts` moves
to `scripts/baseline-inventory.ts`, which keeps one copy of baseline
validation, counting, pruning, and the command itself.
2026-11-11 12:47:00 +08:00

54 lines
1.9 KiB
TypeScript

/** Temporary-repository fixture shared by recorded-inventory gate specs. */
import { execFileSync } from 'node:child_process'
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
/** Repository roots created by {@link createInventoryRepo}, removed by {@link removeInventoryRepos}. */
const roots: string[] = []
/**
* Write one fixture file, creating its parent directories.
* @param root - fixture repository root.
* @param file - repository-relative path.
* @param contents - file text.
*/
export function writeFixture(root: string, file: string, contents: string): void {
const path = join(root, file)
mkdirSync(dirname(path), { recursive: true })
writeFileSync(path, contents)
}
/**
* Run one Git command in a fixture repository.
* @param root - fixture repository root.
* @param args - Git arguments.
*/
export function gitFixture(root: string, ...args: string[]): void {
execFileSync('git', args, { cwd: root, stdio: 'pipe' })
}
/**
* Create a temporary repository with one seed source file per scanned area and an empty inventory.
* @param baselinePath - repository-relative inventory path the gate reads.
* @param seed - contents of each area's seed source file.
* @returns the repository root, tracked for {@link removeInventoryRepos}.
*/
export function createInventoryRepo(baselinePath: string, seed: string): string {
const root = mkdtempSync(join(tmpdir(), 'dsh-inventory-'))
roots.push(root)
gitFixture(root, 'init', '--quiet')
for (const area of ['packages', 'apps', 'scripts', 'website']) {
writeFixture(root, `${area}/seed.ts`, seed)
}
writeFixture(root, baselinePath, '{}\n')
gitFixture(root, 'add', '.')
return root
}
/** Remove every repository created by {@link createInventoryRepo}. */
export function removeInventoryRepos(): void {
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
}