task-h.5.3
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { buildAuditPayload, createSqlClient, summarizeIssues } from './pdf-audit-utils.ts';
|
||||
import {
|
||||
PDFME_STATIC_LABEL_FIELD_KEYS,
|
||||
buildAuditPayload,
|
||||
createSqlClient,
|
||||
summarizeIssues,
|
||||
writeAuditArtifact
|
||||
} from './pdf-audit-utils.ts';
|
||||
|
||||
type PayloadFinding = {
|
||||
field: string;
|
||||
@@ -126,22 +132,77 @@ async function main() {
|
||||
walkValue(findings, 'templateInput', 'templateInput', payload.templateInput);
|
||||
walkValue(findings, 'topicInputs', 'topicInputs', payload.topicInputs);
|
||||
|
||||
const status = summarizeIssues(findings.map((finding) => finding.status));
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
audit: 'runtime-payload',
|
||||
overallStatus: status,
|
||||
quotationCode: payload.quotationCode,
|
||||
templateName: payload.templateName,
|
||||
templateVersion: payload.templateVersion,
|
||||
findingCount: findings.length,
|
||||
findings
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
const priceTable = payload.templateInput.quotation_price_data;
|
||||
const priceTableRows = Array.isArray(priceTable) ? priceTable : [];
|
||||
const firstPriceRow = Array.isArray(priceTableRows[0]) ? (priceTableRows[0] as unknown[]) : [];
|
||||
|
||||
pushFinding(findings, {
|
||||
field: 'templateInput.quotation_price_data',
|
||||
source: 'templateInput',
|
||||
status: Array.isArray(priceTable) ? 'PASS' : 'FAIL',
|
||||
value: Array.isArray(priceTable) ? `rows:${priceTable.length}` : priceTable,
|
||||
message: Array.isArray(priceTable)
|
||||
? 'Price table input is present'
|
||||
: 'Price table input is missing or not a table'
|
||||
});
|
||||
pushFinding(findings, {
|
||||
field: 'templateInput.quotation_price_data[0][0]',
|
||||
source: 'templateInput',
|
||||
status: firstPriceRow[0] === 'Price (Exclude VAT)' ? 'PASS' : 'FAIL',
|
||||
value: firstPriceRow[0] ?? null,
|
||||
message: 'Price table label matches canonical text'
|
||||
});
|
||||
pushFinding(findings, {
|
||||
field: 'templateInput.quotation_price_data[0][1]',
|
||||
source: 'templateInput',
|
||||
status:
|
||||
typeof firstPriceRow[1] === 'string' && firstPriceRow[1].trim() && firstPriceRow[1] !== '-'
|
||||
? 'PASS'
|
||||
: 'FAIL',
|
||||
value: firstPriceRow[1] ?? null,
|
||||
message: 'Price table amount cell is formatted'
|
||||
});
|
||||
pushFinding(findings, {
|
||||
field: 'templateInput.quotation_price_data[0][3]',
|
||||
source: 'templateInput',
|
||||
status:
|
||||
typeof firstPriceRow[3] === 'string' && firstPriceRow[3].trim()
|
||||
? 'PASS'
|
||||
: 'FAIL',
|
||||
value: firstPriceRow[3] ?? null,
|
||||
message: 'Price table currency code cell is populated'
|
||||
});
|
||||
|
||||
const staticLabelFindings = [...PDFME_STATIC_LABEL_FIELD_KEYS].map((fieldName) => {
|
||||
const value = payload.templateInput[fieldName];
|
||||
const valid = typeof value === 'string' && value.trim().length > 0 && value !== '-';
|
||||
const finding: PayloadFinding = {
|
||||
field: `templateInput.${fieldName}`,
|
||||
source: 'templateInput',
|
||||
status: valid ? 'PASS' : 'FAIL',
|
||||
value: value ?? null,
|
||||
message: valid ? 'Static label is populated' : 'Static label is empty'
|
||||
};
|
||||
pushFinding(findings, finding);
|
||||
return finding;
|
||||
});
|
||||
|
||||
const status = findings.some((finding) => finding.status === 'FAIL') ? 'FAIL' : 'PASS';
|
||||
const report = {
|
||||
audit: 'runtime-payload',
|
||||
overallStatus: status,
|
||||
staticLabelsStatus: summarizeIssues(
|
||||
staticLabelFindings.map((finding) => finding.status)
|
||||
),
|
||||
quotationCode: payload.quotationCode,
|
||||
templateName: payload.templateName,
|
||||
templateVersion: payload.templateVersion,
|
||||
findingCount: findings.length,
|
||||
findings
|
||||
};
|
||||
const artifactPath = await writeAuditArtifact('runtime-payload-report.json', report);
|
||||
|
||||
console.log(JSON.stringify({ ...report, artifactPath }, null, 2));
|
||||
} finally {
|
||||
await sql.end({ timeout: 5 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user