fix(workbench): accept a JSON-number decimal and deliver the source's exact string
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / integration (push) Skipped
masterplan-lock / check (push) Successful in 4s
masterplan-lock / check (pull_request) Successful in 8s
CI (SIAX Cloud) / security (push) Successful in 17s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 24s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / integration (pull_request) Successful in 33s
Security Scan (SIAX Cloud) / security (push) Successful in 33s
CI (SIAX Cloud) / quality (push) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 58s
CI (SIAX Cloud) / sonar (pull_request) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
CI (SIAX Cloud) / integration (push) Skipped
masterplan-lock / check (push) Successful in 4s
masterplan-lock / check (pull_request) Successful in 8s
CI (SIAX Cloud) / security (push) Successful in 17s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 24s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / integration (pull_request) Successful in 33s
Security Scan (SIAX Cloud) / security (push) Successful in 33s
CI (SIAX Cloud) / quality (push) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 58s
The local model returns 12500.00 as a JSON number, which the contract rejects as a non-string decimal. A numeric value now matches a source span numerically and the delivered value is rewritten to that span's decimal string (12500.00), so precision is preserved instead of rounded. Exact string equality is still required for string decimals, and ambiguous formats still go to review.
This commit is contained in:
@@ -13,7 +13,7 @@ function isCalendarDate(year: number, month: number, day: number): boolean {
|
||||
return day <= days[month - 1]!;
|
||||
}
|
||||
|
||||
const pad = (n: number): string => String(n).padStart(2, "0");
|
||||
const pad = (n: number): string => String(n).padStart(2, '0');
|
||||
|
||||
/** Returns every unambiguous ISO rendering of the span (empty when ambiguous). */
|
||||
export function dateCandidates(text: string): string[] {
|
||||
@@ -43,31 +43,44 @@ export function dateCandidates(text: string): string[] {
|
||||
|
||||
/** Returns every unambiguous decimal rendering of the span. */
|
||||
export function decimalCandidates(text: string): string[] {
|
||||
const t = text.trim().replace(/[\s\u00a0\u202f]/g, "");
|
||||
const t = text.trim().replace(/[\s\u00a0\u202f]/g, '');
|
||||
if (!/^[+-]?[\d.,]+$/.test(t) || !/\d/.test(t)) return [];
|
||||
const sign = t.startsWith("-") ? "-" : "";
|
||||
const body = t.replace(/^[+-]/, "");
|
||||
const hasComma = body.includes(",");
|
||||
const hasDot = body.includes(".");
|
||||
const sign = t.startsWith('-') ? '-' : '';
|
||||
const body = t.replace(/^[+-]/, '');
|
||||
const hasComma = body.includes(',');
|
||||
const hasDot = body.includes('.');
|
||||
const out = new Set<string>();
|
||||
const add = (value: string) => {
|
||||
if (/^(0|[1-9]\d*)(\.\d+)?$/.test(value)) out.add(`${sign}${value}`);
|
||||
};
|
||||
if (hasComma && hasDot) {
|
||||
const lastComma = body.lastIndexOf(",");
|
||||
const lastDot = body.lastIndexOf(".");
|
||||
if (lastComma > lastDot) add(body.replace(/\./g, "").replace(",", "."));
|
||||
else add(body.replace(/,/g, ""));
|
||||
const lastComma = body.lastIndexOf(',');
|
||||
const lastDot = body.lastIndexOf('.');
|
||||
if (lastComma > lastDot) add(body.replace(/\./g, '').replace(',', '.'));
|
||||
else add(body.replace(/,/g, ''));
|
||||
} else if (hasComma) {
|
||||
const parts = body.split(",");
|
||||
const parts = body.split(',');
|
||||
if (parts.length === 2 && parts[1]!.length <= 2) add(`${parts[0]}.${parts[1]}`);
|
||||
add(body.replace(/,/g, ""));
|
||||
add(body.replace(/,/g, ''));
|
||||
} else if (hasDot) {
|
||||
const parts = body.split(".");
|
||||
const parts = body.split('.');
|
||||
if (parts.length === 2 && parts[1]!.length <= 2) add(body);
|
||||
add(body.replace(/\./g, ""));
|
||||
add(body.replace(/\./g, ''));
|
||||
} else {
|
||||
add(body);
|
||||
}
|
||||
return [...out];
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonical decimal string: no exponent, no leading '+', no trailing zeros in
|
||||
* the fraction. Used only for equality checks; the delivered value keeps its
|
||||
* original precision.
|
||||
*/
|
||||
export function canonicalDecimal(value: string): string | undefined {
|
||||
const match = /^([+-]?)(0|[1-9]\d*)(?:\.(\d+))?$/.exec(value.trim());
|
||||
if (!match) return undefined;
|
||||
const sign = match[1] === '-' ? '-' : '';
|
||||
const fraction = (match[3] ?? '').replace(/0+$/, '');
|
||||
return `${sign}${match[2]}${fraction ? `.${fraction}` : ''}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user