fix(i18n): reject invalid document upload dates

This commit is contained in:
cesnimda
2026-11-03 09:50:59 +01:00
parent d4b938fafb
commit ca519cacbe
8 changed files with 74 additions and 2 deletions
+2
View File
@@ -1,5 +1,7 @@
# Current localisation continuation
3 November 2026 — independent document-date fix: invalid uploaded wall-clock dates/times/trailing junk now show the existing EN/NB unknown-date message instead of JavaScript rollover.40 tests/3 suites, typecheck, scoped lint and build pass; see DOCUMENT_DATE_VALIDATION.md. All four historical direct-catalogue accesses have contextual dispositions in DIRECT_CATALOGUE_REVIEW.md; current full extraction/backend literals/every-string triage remain open. No new locales or release approval. This branch is not yet integrated into A3 dashboard/application work.
Register portability correction: schema 3 explicitly normalises CRLF to LF when hashing reviewed TS/TSX/JSON text and the original inventory; historicalSourceSha256 retains the original inventory's raw-hash meaning. This avoids treating Git checkout line-ending conversion as a source edit. Integration initially detected the raw inventory mismatch; original snapshot contents and historical source hashes were preserved, and both worktrees are revalidated with the declared encoding. This is evidence portability, not renewed runtime execution.
2 November 2026. Historical 188 dynamic-call census finite key-domain review COMPLETE; full I18N-00 / European locale release acceptance remains INCOMPLETE. Original source-bound snapshots are retained under 00/. Machine register schema 2 binds inventory indices, source hashes and selected owner dependencies; 108 original plus 80 supplemental calls cover all 188 indices without overlap. Static review does not establish all translator sensitivity/context, every visible/backend string, grammar/plural quality, runtime coverage or native review.
+14
View File
@@ -0,0 +1,14 @@
# Historical direct catalogue access review
3 November 2026. All four entries in the frozen 00/DIRECT_CATALOGUE_ACCESS.json are in I18nProvider.tsx. Reviewed actual current callers and source, not re-extracted as a claim of complete current coverage.
| Historical expression | Context and disposition |
|---|---|
| translations[l].settingsLanguageSaveFailed | Public static account-preference error copy, no runtime private value. Uses requested language, guarded by save sequence/current language before showing feedback. Deliberate provider-internal access; calling the context hook inside its owner is inappropriate. Retain. |
| translations[l].retry | Static retry action label in the same guarded feedback; no interpolation/private data. Retain. |
| translations[language][key] | Central typed message lookup inside t, passed to interpolation; all callers use this message owner. React callers render text; this review does not certify every sink. Retain. |
| translations.en[key] | Deterministic English fallback for the central lookup. No country/document-language coupling. Retain. |
The provider's TranslationKey/UiLanguage contracts and catalogue completeness tests constrain these accesses; sequence guards prevent obsolete-save feedback/retries. No new catalogue bypass or runtime change was required. Existing provider/catalogue tests pass within the40-case document-date qualification; this is not native linguistic or full security acceptance.
Original inventory/hash/line records are immutable historical evidence. Current source identity is bound in document-date SOURCE_MANIFEST.json. This closes contextual classification of the four historical direct accesses only. Current full re-extraction, non-catalogue/backend literal inventory and every-string sensitivity/caller review remain incomplete. No runtime user content was exported or translated externally.
+11
View File
@@ -0,0 +1,11 @@
# Document upload wall-clock date correction
3 November 2026. Independent ordinary application fix, branch `codex/i18n-document-dates` from published d4b938fa. Not integrated into A3 yet; no wholesale merge of this older integration-derived tree.
Reproduced: the document index accepted an ISO prefix and let JavaScript normalise invalid wall-clock components. `2026-02-30T09:15:00`, hour24, minute61 and trailing junk displayed plausible timestamps. Eight EN/NB regression cases failed before the fix; two valid fractional-second cases passed. These failures are retained in evidence/document-dates-red.json;21 unrelated cases were skipped in that focused red execution.
The existing uploaded-local branch now accepts the complete unzoned .NET-style timestamp (optional1–7 fractional digits) and round-trips all calendar/time fields before formatting. Invalid input uses the existing localised Date not recorded message and emits no fabricated time element. Valid wall-clock components remain unchanged across time zones using the existing UTC formatting carrier. The raw datetime attribute remains unchanged. No API date-kind semantics, server data, UTC-history formatting, document content, download behavior, revisions or navigation changes. No new locale key/dependency/schema.
Final validation: **40 tests /3 suites PASSED**, documents31 + provider6 + catalogue3. Tests include metadata filters/paging/history, source links, all seven resource kinds, download/focus/cancellation, ownership-safe read behavior, both languages, invalid dates and valid .NET fractional seconds. All document tests assert no POST/PUT/PATCH/DELETE. Typecheck, scoped zero-warning lint, production build and diff whitespace check PASSED. An intermediate command used a nonexistent catalogue-test filename:37 cases passed but that execution failed one suite; it is not counted as passing. Corrected final run uses translation-catalogue.test.ts. No fresh browser/backend/native/provider qualification.
Rollback: revert this bounded view/parser and test commit; no data rollback. Broader document UTC date validation, partial-date semantics outside this surface, DST/native reviews and full European locale architecture remain open. No release or production qualification inferred.
@@ -0,0 +1,15 @@
{
"base": "d4b938fafbf10541b62134293cea8299f25c4031",
"recordedAtUtc": "2026-11-03T08:50:34.776817+00:00",
"policy": "LF-normalised SHA256 text",
"files": {
"job-tracker-ui/src/views/DocumentsPage.tsx": "2a3187938d7f61cc1d723bae5b784f09707713606b523db176d6df6d05a91c3d",
"job-tracker-ui/src/documents-page.test.tsx": "abfa8c4bef73499c0546f7e9b8a091793b8c273f829b51159ae115fc54aa4ed3",
"job-tracker-ui/src/i18n/I18nProvider.tsx": "d22b5d033d0e405ffb5d581c752d61a24056d1e496f5f6a2f1baecef500f2113",
"docs/i18n/00/DIRECT_CATALOGUE_ACCESS.json": "c470c52c500d79f51c4cedd073c2a8474ae73b832e531df3c0c38369993cae3f",
"docs/i18n/DOCUMENT_DATE_VALIDATION.md": "602cd31d84eed1e59ed000159bdc8b998b0dbdc5b7c965ad51831d26a16b31d6",
"docs/i18n/DIRECT_CATALOGUE_REVIEW.md": "4eb88d2d1da2ed0cd52d49fc8dc7f11d1943d169c240e56ae3562d298bc6eb6a",
"docs/i18n/evidence/document-dates-tests.json": "227187b5a02473f442c8600b434e5f0922fa63ba13bfb9355254b9a19b7d4e81",
"docs/i18n/evidence/document-dates-red.json": "430ec89f685c2558d443677c596a12b587829a9a45e3f29dc03e042d3685a074"
}
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -38,6 +38,27 @@ function deferred<T>() {
return { promise, resolve, reject };
}
describe.each(['en', 'nb'] as const)('%s uploaded wall-clock dates', locale => {
test.each(['2026-02-30T09:15:00', '2026-02-12T24:15:00', '2026-02-12T09:61:00', '2026-02-12T09:15:00junk'])('does not invent a timestamp from %s', async recordedAt => {
localStorage.setItem('uiLanguage', locale);
mockedApi.get.mockResolvedValue({ data: page([item({ recordedAt, dateKind: 'uploaded-local' })]) } as never);
renderPage();
expect(await screen.findByText(copy('documentsDateUnknown', {}, locale))).toBeVisible();
expect(document.querySelector('time')).not.toBeInTheDocument();
});
test('preserves fractional-second wall-clock metadata without timezone conversion', async () => {
localStorage.setItem('uiLanguage', locale);
const recordedAt = '2026-02-12T09:15:00.1234567';
mockedApi.get.mockResolvedValue({ data: page([item({ recordedAt, dateKind: 'uploaded-local' })]) } as never);
renderPage();
await screen.findByText('Metadata CV ÆØÅ', { exact: true });
const time = document.querySelector('time');
expect(time).toHaveAttribute('datetime', recordedAt);
expect(time).toHaveTextContent(new Intl.DateTimeFormat(locale === 'nb' ? 'nb-NO' : 'en-GB', { dateStyle: 'medium', timeStyle: 'short', timeZone: 'UTC' }).format(new Date('2026-02-12T09:15:00Z')));
});
});
function Probe() {
const location = useLocation();
const navigate = useNavigate();
+9 -2
View File
@@ -214,9 +214,16 @@ export default function DocumentsPage() {
const label: TranslationKey = item.dateKind === "uploaded-local" ? "documentsUploadedLocal" : item.dateKind === "captured-utc" ? "documentsCaptured" : item.dateKind === "history-recorded-utc" ? "documentsHistoryRecorded" : "documentsUpdated";
let value: Date | null = null;
if (item.recordedAt && item.dateKind === "uploaded-local") {
const local = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/.exec(item.recordedAt);
const local = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.\d{1,7})?$/.exec(item.recordedAt);
// UTC is only a formatting carrier for the unzoned wall-clock components.
if (local) value = new Date(Date.UTC(+local[1], +local[2] - 1, +local[3], +local[4], +local[5], +local[6]));
if (local) {
const parts = local.slice(1).map(Number);
const candidate = new Date(0);
candidate.setUTCFullYear(parts[0], parts[1] - 1, parts[2]);
candidate.setUTCHours(parts[3], parts[4], parts[5], 0);
// Date normalises impossible fields; show unknown rather than inventing a date.
if ([candidate.getUTCFullYear(), candidate.getUTCMonth() + 1, candidate.getUTCDate(), candidate.getUTCHours(), candidate.getUTCMinutes(), candidate.getUTCSeconds()].every((part, index) => part === parts[index])) value = candidate;
}
} else if (item.recordedAt && ["updated-utc", "captured-utc", "history-recorded-utc"].includes(item.dateKind)) value = new Date(item.recordedAt);
if (!value || Number.isNaN(value.valueOf())) return <Typography variant="body2" color="text.secondary">{t("documentsDateUnknown")}</Typography>;
return <Box><Typography variant="caption" color="text.secondary">{t(label)}</Typography><Typography variant="body2" component="time" dateTime={item.recordedAt!} sx={{ display: "block" }}>{value.toLocaleString(locale, { dateStyle: "medium", timeStyle: "short", ...(item.dateKind === "uploaded-local" ? { timeZone: "UTC" } : {}) })}</Typography></Box>;