feat: bhl release — артефакты версии спецификации (BHL-027)
- детерминированный tarball (ustar, сортировка путей, mtime/uid/gid=0) - manifest: SHA-256 фактических байтов каждого файла (D-012) + сумма tarball - тесты: повторная сборка идентична; tar-извлечение сверяется с manifest - реальная публикация Git Release не выполнена (D-034); пакет 44/44
This commit is contained in:
+106
-29
@@ -5,13 +5,14 @@ import { runAudit, writeAuditReport } from './audit.ts';
|
||||
import { emit, ExitCode, failEnvelope, okEnvelope } from './envelope.ts';
|
||||
import { fetchSpec, verifyCache } from './fetch.ts';
|
||||
import { renderReport, renderSpec } from './render.ts';
|
||||
import { buildRelease } from './release.ts';
|
||||
import { resolveProfiles } from './resolve.ts';
|
||||
import { specList, specShow, validateManifest } from './spec.ts';
|
||||
import { validateReport } from './report.ts';
|
||||
import { validateSpec } from './validate.ts';
|
||||
|
||||
const USAGE_MESSAGE =
|
||||
'Usage: bhl <version|validate|spec|profile|report|manifest|fetch|verify|audit> [args]; ' +
|
||||
'Usage: bhl <version|validate|spec|profile|report|manifest|fetch|verify|audit|release> [args]; ' +
|
||||
'spec list [--spec-root <path>] [--domain <id>] [--capability <id>]; ' +
|
||||
'spec show <req-id> [--spec-root <path>]; ' +
|
||||
'spec render --spec-root <path> --out <dir>; ' +
|
||||
@@ -23,6 +24,7 @@ const USAGE_MESSAGE =
|
||||
'verify --version <semver> --cache <dir>; ' +
|
||||
'audit <project-dir> --out <report.json> [--spec-root <path>] [--profile <id>] ' +
|
||||
'[--preset <id>] [--generated-at <iso>]; ' +
|
||||
'release <spec-root> --version <semver> --out <dir>; ' +
|
||||
'JSON envelope on stdout; exit codes: 0 ok, 1 validation failed, 2 usage, ' +
|
||||
'3 not implemented, 4 internal.';
|
||||
|
||||
@@ -531,6 +533,89 @@ function parseAuditArgs(args: readonly string[]): AuditFlags | { error: string }
|
||||
return target;
|
||||
}
|
||||
|
||||
const RELEASE_FLAGS: Readonly<Record<string, 'version' | 'out'>> = {
|
||||
'--version': 'version',
|
||||
'--out': 'out',
|
||||
};
|
||||
|
||||
interface ReleaseFlags {
|
||||
version?: string;
|
||||
out?: string;
|
||||
positional: string[];
|
||||
}
|
||||
|
||||
function takeReleaseFlag(
|
||||
args: readonly string[],
|
||||
cursor: number,
|
||||
target: ReleaseFlags,
|
||||
arg: string,
|
||||
): { next: number } | { error: string } {
|
||||
const flag = RELEASE_FLAGS[arg];
|
||||
const value = args[cursor + 1];
|
||||
if (flag === undefined || value === undefined) {
|
||||
return { error: `missing value for ${arg}` };
|
||||
}
|
||||
target[flag] = value;
|
||||
return { next: cursor + 2 };
|
||||
}
|
||||
|
||||
function parseReleaseArgs(args: readonly string[]): ReleaseFlags | { error: string } {
|
||||
const target: ReleaseFlags = { positional: [] };
|
||||
let cursor = 0;
|
||||
while (cursor < args.length) {
|
||||
const arg = args[cursor] ?? '';
|
||||
if (RELEASE_FLAGS[arg] !== undefined) {
|
||||
const taken = takeReleaseFlag(args, cursor, target, arg);
|
||||
if ('error' in taken) {
|
||||
return taken;
|
||||
}
|
||||
cursor = taken.next;
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith('--')) {
|
||||
return { error: `unknown flag ${arg}` };
|
||||
}
|
||||
target.positional.push(arg);
|
||||
cursor += 1;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
function runRelease(command: string, rest: readonly string[]): number {
|
||||
const parsed = parseReleaseArgs(rest);
|
||||
if ('error' in parsed) {
|
||||
emit(failEnvelope(command, 'USAGE', parsed.error));
|
||||
return ExitCode.Usage;
|
||||
}
|
||||
const specRoot = parsed.positional[0];
|
||||
const version = parsed.version;
|
||||
const out = parsed.out;
|
||||
if (
|
||||
specRoot === undefined ||
|
||||
parsed.positional.length !== 1 ||
|
||||
version === undefined ||
|
||||
out === undefined
|
||||
) {
|
||||
emit(
|
||||
failEnvelope(command, 'USAGE', 'release requires <spec-root> --version <semver> --out <dir>'),
|
||||
);
|
||||
return ExitCode.Usage;
|
||||
}
|
||||
const result = buildRelease(specRoot, version, out);
|
||||
const data = {
|
||||
spec_root: specRoot,
|
||||
version,
|
||||
out,
|
||||
files: result.files,
|
||||
errors: result.diagnostics,
|
||||
};
|
||||
if (!result.ok) {
|
||||
return emitValidationFailure(command, data, result.diagnostics.length);
|
||||
}
|
||||
emit(okEnvelope(command, data));
|
||||
return ExitCode.Ok;
|
||||
}
|
||||
|
||||
function runAuditCommand(command: string, rest: readonly string[]): number {
|
||||
const parsed = parseAuditArgs(rest);
|
||||
if ('error' in parsed) {
|
||||
@@ -683,40 +768,32 @@ function runValidate(command: string, rest: readonly string[]): number {
|
||||
return ExitCode.ValidationFailed;
|
||||
}
|
||||
|
||||
const COMMAND_HANDLERS: Readonly<Record<string, (rest: readonly string[]) => number>> = {
|
||||
version: () => {
|
||||
const info = readPackageInfo();
|
||||
emit(okEnvelope('version', { name: info.name, version: info.version }));
|
||||
return ExitCode.Ok;
|
||||
},
|
||||
profile: (rest) => runProfile('profile', rest),
|
||||
validate: (rest) => runValidate('validate', rest),
|
||||
spec: (rest) => runSpec('spec', rest),
|
||||
manifest: (rest) => runManifest('manifest', rest),
|
||||
report: (rest) => runReport('report', rest),
|
||||
fetch: (rest) => runFetch('fetch', rest),
|
||||
verify: (rest) => runVerify('verify', rest),
|
||||
audit: (rest) => runAuditCommand('audit', rest),
|
||||
release: (rest) => runRelease('release', rest),
|
||||
};
|
||||
|
||||
export function run(argv: readonly string[]): number {
|
||||
const [command, ...rest] = argv;
|
||||
if (command === undefined) {
|
||||
emit(failEnvelope('none', 'USAGE', USAGE_MESSAGE));
|
||||
return ExitCode.Usage;
|
||||
}
|
||||
if (command === 'version') {
|
||||
const info = readPackageInfo();
|
||||
emit(okEnvelope('version', { name: info.name, version: info.version }));
|
||||
return ExitCode.Ok;
|
||||
}
|
||||
if (command === 'profile') {
|
||||
return runProfile(command, rest);
|
||||
}
|
||||
if (command === 'validate') {
|
||||
return runValidate(command, rest);
|
||||
}
|
||||
if (command === 'spec') {
|
||||
return runSpec(command, rest);
|
||||
}
|
||||
if (command === 'manifest') {
|
||||
return runManifest(command, rest);
|
||||
}
|
||||
if (command === 'report') {
|
||||
return runReport(command, rest);
|
||||
}
|
||||
if (command === 'fetch') {
|
||||
return runFetch(command, rest);
|
||||
}
|
||||
if (command === 'verify') {
|
||||
return runVerify(command, rest);
|
||||
}
|
||||
if (command === 'audit') {
|
||||
return runAuditCommand(command, rest);
|
||||
const handler = COMMAND_HANDLERS[command];
|
||||
if (handler !== undefined) {
|
||||
return handler(rest);
|
||||
}
|
||||
emit(failEnvelope(command, 'USAGE', USAGE_MESSAGE));
|
||||
return ExitCode.Usage;
|
||||
|
||||
Reference in New Issue
Block a user