From 1c075d138392d444ac55c0c1ceb7155d4c9d128e Mon Sep 17 00:00:00 2001 From: twoimo Date: Sun, 25 Oct 2026 04:18:18 +0900 Subject: [PATCH] Preserve exact retained text boundaries in numeric reading folds --- .../node-details-reading-integrity.test.ts | 13 ++++++ .../evaluation/exact-reading-tail-20261025.md | 39 +++++++++++++++++ scripts/alden_source_text.py | 15 +++---- tests/test_alden_source_text.py | 42 +++++++++++++++++++ 4 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 docs/evaluation/exact-reading-tail-20261025.md diff --git a/desktop/src/__tests__/node-details-reading-integrity.test.ts b/desktop/src/__tests__/node-details-reading-integrity.test.ts index 32816df7..83d62e48 100644 --- a/desktop/src/__tests__/node-details-reading-integrity.test.ts +++ b/desktop/src/__tests__/node-details-reading-integrity.test.ts @@ -12,6 +12,19 @@ function render(body:string, extras:Record={}) { renderNodeDetails(selected,selected.nodes[0],{details:{node_id:'record',basis:'source_record',version:'v1',target_id:'target-a',body,raw_sha256:'a'.repeat(64),...extras}}); } describe('source-backed reading and numeric facts',()=>{ + for (const newline of ['\n', '\r\n', '\r']) it(`accepts exact legacy Threads parts with outer whitespace and ${JSON.stringify(newline)}`,()=>{ + const reading='\t 원문과 숫자 후보를 별도로 보존합니다.'+newline+'본문 앞의 공백도 유지합니다.'; + const tail=newline+'11'+newline+'2 \t'+newline; + const projection={policy:'legacy-threads-reading-tail-v1',status:'unverified_presentation_candidate', + basis:'verified_retained_legacy_threads_record',original_preserved:true,semantic_validity:'unverified', + reading,tail,body_sha256:'b'.repeat(64),reading_sha256:'c'.repeat(64),tail_sha256:'d'.repeat(64)}; + render(reading+tail,{body_format:'retained_original_text',reading_projection:projection}); + expect(document.getElementById('knowledge-node-body')!.textContent).toBe(reading); + const fold=document.querySelector('.knowledge-reading-tail')!; + expect(fold.open).toBe(false); + expect(fold.querySelector('pre')!.textContent).toBe(tail); + expect(document.getElementById('knowledge-node-body')!.textContent!+fold.querySelector('pre')!.textContent!).toBe(reading+tail); + }); for (const newline of ['\n', '\r\n', '\r']) it(`keeps exact source boundaries when folding ${JSON.stringify(newline)} with outer whitespace`, () => { const reading = '\t 원문의 들여쓰기와 줄바꿈을 보존합니다.' + newline + '준비 과정과 확인 가능한 근거입니다. '; const tail = newline + ['1', '2', '6', '1', '3'].join(newline) + newline; diff --git a/docs/evaluation/exact-reading-tail-20261025.md b/docs/evaluation/exact-reading-tail-20261025.md new file mode 100644 index 00000000..e7bf1ed5 --- /dev/null +++ b/docs/evaluation/exact-reading-tail-20261025.md @@ -0,0 +1,39 @@ +# Exact retained-text reading folds + +Legacy Threads reading folds used a stripped body while the reader requires +`reading + tail == retained body`. Leading or trailing whitespace therefore +made an otherwise eligible receipt unusable, leaving the numeric suffix in +the main reader. CR-only line endings also failed the optional fold. + +Match against the retained body, preserve its exact reading/tail boundary, +and bind the body hash to those same bytes. LF, CRLF and CR remain unchanged. +The minimum substantive length still ignores outer whitespace, and the +128-character tail limit remains. This repairs the existing presentation +contract; it changes no source text, index extraction/version, stored labels, +source identity, semantic merge decision or numeric value. The numeric suffix +remains an expandable, semantically unverified presentation candidate. + +Verification: the old source fails seven new subcases across the boundary +and detail/storage regressions. The repaired source passes23 source tests, +56 graph-quality tests,53 retrieval tests, and all1,159 UI tests. The UI has +three new boundary tests; its production code is unchanged. Integration +checks preserve the private source archive, collection DB and indexed rows. + +The installed baseline audit covers five permitted projects,26,661 current +memberships and48,355 relations, with26,661 canonical JSON sources verified. +No structural/hash findings were reported; this does not establish semantic +correctness. Seven stored-body match groups contain36 document memberships; +they remain review candidates, not merged entities. Declared time fields +include1,045 notation conversions and459 explicit missing values; no quantity +declarations are present. Body-number interpretation and independent human +gold remain separate. + +The retained-source comparison and actual detail payload fixtures are private +task evidence under `outputs/source-normalization-live-20261025/`. Raw reading +shape candidates must be distinguished from structural extraction: already +separated tails do not require a second reading fold. An initial fixture +chooser conflated these paths; the corrected comparison follows the product's +projection order. Current inspected data did not reproduce the whitespace +bug. New inputs reproduce it; broader future/semantic/physical performance +claims are not established. External current-source Pro/Gemini/reverse review +and the full goal's remaining delivery gates remain incomplete. diff --git a/scripts/alden_source_text.py b/scripts/alden_source_text.py index 62e0089d..7a0431ad 100644 --- a/scripts/alden_source_text.py +++ b/scripts/alden_source_text.py @@ -121,16 +121,17 @@ def reading_tail_presentation(body, source): or not _legacy_threads_source(body, source) or '```' in body or '~~~' in body): return None - display = body.strip() - match = re.search(r'(?:\r?\n[ \t\u00a0]*(?:[0-9]{1,4}|/)[ \t\u00a0]*)+[ \t\r\n\u00a0]*\Z', display) + # Bind the UI parts to the exact retained body, including outer whitespace. + # A stripped copy cannot satisfy the reader's reading + tail == body fence. + match = re.search(r'(?:(?:\r\n|[\r\n])[ \t\u00a0]*(?:[0-9]{1,4}|/)[ \t\u00a0]*)+[ \t\r\n\u00a0]*\Z', body) if match is None: - match = re.search(r'\s+[0-9]{1,4}\s+/\s+[0-9]{1,4}(?:\s+[0-9]{1,4})+\s*\Z', display) + match = re.search(r'\s+[0-9]{1,4}\s+/\s+[0-9]{1,4}(?:\s+[0-9]{1,4})+\s*\Z', body) if match is None: return None - reading = display[:match.start()].rstrip() - tail = display[len(reading):] + reading = body[:match.start()].rstrip() + tail = body[len(reading):] tokens = tail.split() - if (len(reading) < 80 or not re.search(r'[A-Za-z가-힣]', reading) + if (len(reading.strip()) < 80 or not re.search(r'[A-Za-z가-힣]', reading) or len(tail) > 128 or not 2 <= len(tokens) <= 8 or sum(token != '/' for token in tokens) < 2 or '/' in tokens and sum(token != '/' for token in tokens) < 3): @@ -141,5 +142,5 @@ def reading_tail_presentation(body, source): 'basis': 'verified_retained_legacy_threads_record', 'original_preserved': True, 'semantic_validity': 'unverified', 'reading': reading, 'tail': tail, - 'body_sha256': sha(display), 'reading_sha256': sha(reading), + 'body_sha256': sha(body), 'reading_sha256': sha(reading), 'tail_sha256': sha(tail)} diff --git a/tests/test_alden_source_text.py b/tests/test_alden_source_text.py index 652861f7..92499191 100644 --- a/tests/test_alden_source_text.py +++ b/tests/test_alden_source_text.py @@ -73,6 +73,27 @@ def test_reading_candidate_preserves_exact_body_and_unverified_status(self): self.assertEqual(result['semantic_validity'], 'unverified') self.assertIsNone(project_source_text(body, source(body))['projection']) + def test_threads_reading_fold_preserves_outer_whitespace_and_line_endings(self): + for newline in ('\n', '\r\n', '\r'): + for leading, trailing in (('', ' \t' + newline), ('\t ' + newline, '')): + with self.subTest(newline=repr(newline), leading=repr(leading), trailing=repr(trailing)): + reading = leading + BODY.replace('\n', newline) + tail = newline + '11' + newline + '2' + trailing + body = reading + tail + record = source(body) + result = reading_tail_presentation(body, record) + self.assertIsNotNone(result) + self.assertEqual(result['reading'], reading) + self.assertEqual(result['tail'], tail) + self.assertEqual(result['reading'] + result['tail'], body) + self.assertEqual(result['body_sha256'], hashlib.sha256(body.encode()).hexdigest()) + self.assertEqual(record['localOriginalText'], body) + self.assertIsNone(project_source_text(body, record)['projection']) + + def test_outer_whitespace_cannot_make_short_text_eligible_for_folding(self): + body = ' ' * 80 + '짧은 메모\n11\n2' + self.assertIsNone(reading_tail_presentation(body, source(body))) + def test_incremental_json_threads_capture_uses_the_same_reading_fold(self): body = BODY + '\n11\n2' @@ -186,6 +207,27 @@ def test_graph_detail_folds_crlf_without_changing_retained_or_indexed_text(self) with sqlite3.connect(self.store.root/'retrieval.sqlite3') as db: self.assertEqual(db.execute('SELECT * FROM texts').fetchall(), indexed) + def test_threads_detail_fold_preserves_whitespace_body_source_and_search(self): + reading = '\t ' + BODY + tail = '\n11\n2\n \t\n' + body = reading + tail + self.store.ingest(self.target, [{**self.record, 'text': body, 'raw': source(body)}]) + index_text(self.root, ['one']) + with sqlite3.connect(self.store.root / 'retrieval.sqlite3') as db: + indexed = db.execute('SELECT * FROM texts').fetchall() + before = self.store.path.read_bytes() + originals = {p.name: p.read_bytes() for p in self.store.blobs.iterdir()} + detail = self.store.graph_page(projects=['one'], focus=self.doc, details=True)['details'] + self.assertEqual(detail['body'], body) + self.assertEqual(detail['reading_projection']['reading'], reading) + self.assertEqual(detail['reading_projection']['tail'], tail) + self.assertEqual(detail['reading_projection']['body_sha256'], hashlib.sha256(body.encode()).hexdigest()) + self.assertIsNone(detail['text_projection']) + self.assertEqual(self.store.path.read_bytes(), before) + self.assertEqual({p.name: p.read_bytes() for p in self.store.blobs.iterdir()}, originals) + with sqlite3.connect(self.store.root / 'retrieval.sqlite3') as db: + self.assertEqual(db.execute('SELECT * FROM texts').fetchall(), indexed) + def test_detail_and_search_share_projection_without_source_or_version_mutation(self): before = self.store.path.read_bytes() raw_path = next(self.store.blobs.iterdir()); original = raw_path.read_bytes()