feat: fetch, кеш и lock с SHA-256 фактических байтов (BHL-021)
- bhl fetch/verify: lock.json (sha256 байтов, без LF-нормализации), несовпадение суммы прерывает использование артефакта - missing-file/unexpected-file/missing-cache — явные диагностики - офлайн validate зафиксированной версии после загрузки (тест) - validate.ts: Ajv strict-отказ и битый JSON — диагностики вместо crash - пакет: 36/36 тестов
This commit is contained in:
@@ -137,6 +137,33 @@ class Validator {
|
||||
this.diagnostics.push(item);
|
||||
}
|
||||
|
||||
private addSchemaFile(schemasDir: string, name: string): void {
|
||||
const file = `schemas/${name}`;
|
||||
let text: string;
|
||||
try {
|
||||
text = readFileSync(path.join(schemasDir, name), 'utf8');
|
||||
} catch {
|
||||
this.push(file, 'read-error', 'schema file is not readable');
|
||||
return;
|
||||
}
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(text);
|
||||
} catch {
|
||||
this.push(file, 'parse-error', 'schema file is not valid JSON');
|
||||
return;
|
||||
}
|
||||
if (!isSchema(parsed)) {
|
||||
this.push(file, 'parse-error', 'schema must be an object or boolean');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.ajv.addSchema(parsed);
|
||||
} catch {
|
||||
this.push(file, 'schema-error', 'schema is rejected by Ajv strict mode');
|
||||
}
|
||||
}
|
||||
|
||||
private addSchemas(): boolean {
|
||||
const schemasDir = path.join(this.root, 'schemas');
|
||||
if (!existsSync(schemasDir)) {
|
||||
@@ -155,20 +182,7 @@ class Validator {
|
||||
return false;
|
||||
}
|
||||
for (const name of names) {
|
||||
const file = `schemas/${name}`;
|
||||
let text: string;
|
||||
try {
|
||||
text = readFileSync(path.join(schemasDir, name), 'utf8');
|
||||
} catch {
|
||||
this.push(file, 'read-error', 'schema file is not readable');
|
||||
continue;
|
||||
}
|
||||
const parsed: unknown = JSON.parse(text);
|
||||
if (isSchema(parsed)) {
|
||||
this.ajv.addSchema(parsed);
|
||||
} else {
|
||||
this.push(file, 'parse-error', 'schema must be an object or boolean');
|
||||
}
|
||||
this.addSchemaFile(schemasDir, name);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user