Skip to content

Commit bf59730

Browse files
nihalnihalaniclaude
andcommitted
fix(nodes): fix no-overlap assertion and improve IGlobal lifecycle test
Change the no-overlap position assertion to compare start_char against the previous chunk's end_char (not start_char) so it actually verifies non-overlapping spans. Rewrite test_iglobal_creates_strategy to instantiate IGlobal, mock the endpoint and glb with strategy='sentence', call beginGlobal(), and assert the resulting strategy type and parameters. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 16124d1 commit bf59730

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

test/nodes/test_chunker.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_repeated_sentences_no_overlap_in_positions(self):
255255
# Each chunk's start_char should be >= previous chunk's end_char (no overlap mode)
256256
if len(chunks) >= 2:
257257
for i in range(1, len(chunks)):
258-
assert chunks[i]['metadata']['start_char'] >= chunks[i - 1]['metadata']['start_char']
258+
assert chunks[i]['metadata']['start_char'] >= chunks[i - 1]['metadata']['end_char']
259259

260260

261261
# ===========================================================================
@@ -499,13 +499,29 @@ def test_iglobal_creates_strategy(self):
499499
if 'chunker' in mod_name and 'test' not in mod_name:
500500
del sys.modules[mod_name]
501501

502-
# Verify the strategy classes can be instantiated correctly
503-
from nodes.src.nodes.chunker.chunker_strategies import RecursiveCharacterChunker as RC
502+
from nodes.src.nodes.chunker.IGlobal import IGlobal
503+
from nodes.src.nodes.chunker.chunker_strategies import SentenceChunker
504504

505-
strategy = RC(chunk_size=100, chunk_overlap=10)
506-
assert strategy is not None
507-
chunks = strategy.chunk('Hello world. This is a test.')
508-
assert len(chunks) >= 1
505+
iglobal = IGlobal.__new__(IGlobal)
506+
iglobal.strategy = None
507+
508+
# Mock endpoint (run mode) and glb (connConfig with strategy params)
509+
endpoint = MagicMock()
510+
endpoint.openMode = 'run'
511+
iglobal.IEndpoint = MagicMock()
512+
iglobal.IEndpoint.endpoint = endpoint
513+
514+
glb = MagicMock()
515+
glb.logicalType = 'chunker'
516+
glb.connConfig = {'strategy': 'sentence', 'chunk_size': '500', 'chunk_overlap': '50'}
517+
iglobal.glb = glb
518+
519+
iglobal.beginGlobal()
520+
521+
assert iglobal.strategy is not None
522+
assert isinstance(iglobal.strategy, SentenceChunker)
523+
assert iglobal.strategy.chunk_size == 500
524+
assert iglobal.strategy.chunk_overlap == 50
509525
finally:
510526
self._restore_modules(saved, names)
511527

0 commit comments

Comments
 (0)