mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-12 20:15:40 +00:00
test(glmt): align thinking signature coverage
This commit is contained in:
1 parent
cbcdb6ba62
commit
045fc93285
2 files changed
+10
-9
No files matched your search
@@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
const GlmtTransformer = require('../../../dist/glmt/glmt-transformer').default;
|
const GlmtTransformer = require('../../../dist/glmt/glmt-transformer').default;
|
||||||
const { DeltaAccumulator } = require('../../../dist/glmt/delta-accumulator');
|
const { DeltaAccumulator } = require('../../../dist/glmt/delta-accumulator');
|
||||||
|
const { ResponseBuilder } = require('../../../dist/glmt/pipeline');
|
||||||
|
|
||||||
|
const responseBuilder = new ResponseBuilder(false);
|
||||||
|
|
||||||
// Test runner
|
// Test runner
|
||||||
class TestRunner {
|
class TestRunner {
|
||||||
@@ -59,7 +62,6 @@ function assert(condition, message) {
|
|||||||
|
|
||||||
// Test 1: Signature not generated for empty thinking block
|
// Test 1: Signature not generated for empty thinking block
|
||||||
runner.test('Signature not generated for empty thinking block', () => {
|
runner.test('Signature not generated for empty thinking block', () => {
|
||||||
const transformer = new GlmtTransformer({ verbose: false });
|
|
||||||
const accumulator = new DeltaAccumulator({ thinking: true });
|
const accumulator = new DeltaAccumulator({ thinking: true });
|
||||||
|
|
||||||
// Start thinking block but add no content
|
// Start thinking block but add no content
|
||||||
@@ -67,7 +69,7 @@ runner.test('Signature not generated for empty thinking block', () => {
|
|||||||
const block = accumulator.startBlock('thinking');
|
const block = accumulator.startBlock('thinking');
|
||||||
|
|
||||||
// Try to generate signature for empty block
|
// Try to generate signature for empty block
|
||||||
const signatureEvent = transformer._createSignatureDeltaEvent(block);
|
const signatureEvent = responseBuilder.createSignatureDeltaEvent(block);
|
||||||
|
|
||||||
// Should return null for empty block (fix for race condition)
|
// Should return null for empty block (fix for race condition)
|
||||||
assert(signatureEvent === null, 'Expected null for empty thinking block');
|
assert(signatureEvent === null, 'Expected null for empty thinking block');
|
||||||
@@ -75,7 +77,6 @@ runner.test('Signature not generated for empty thinking block', () => {
|
|||||||
|
|
||||||
// Test 2: Signature generated correctly after content accumulated
|
// Test 2: Signature generated correctly after content accumulated
|
||||||
runner.test('Signature generated correctly after content accumulated', () => {
|
runner.test('Signature generated correctly after content accumulated', () => {
|
||||||
const transformer = new GlmtTransformer({ verbose: false });
|
|
||||||
const accumulator = new DeltaAccumulator({ thinking: true });
|
const accumulator = new DeltaAccumulator({ thinking: true });
|
||||||
|
|
||||||
// Start thinking block and add content
|
// Start thinking block and add content
|
||||||
@@ -85,15 +86,14 @@ runner.test('Signature generated correctly after content accumulated', () => {
|
|||||||
accumulator.addDelta('Second thinking delta.');
|
accumulator.addDelta('Second thinking delta.');
|
||||||
|
|
||||||
// Generate signature
|
// Generate signature
|
||||||
const signatureEvent = transformer._createSignatureDeltaEvent(block);
|
const signatureEvent = responseBuilder.createSignatureDeltaEvent(block);
|
||||||
|
|
||||||
// Should return valid signature event
|
// Should return valid signature event
|
||||||
assert(signatureEvent !== null, 'Expected signature event for non-empty block');
|
assert(signatureEvent !== null, 'Expected signature event for non-empty block');
|
||||||
assert(signatureEvent.event === 'content_block_delta', 'Expected content_block_delta event');
|
assert(signatureEvent.event === 'content_block_delta', 'Expected content_block_delta event');
|
||||||
assert(signatureEvent.data.delta.type === 'thinking_signature_delta', 'Expected thinking_signature_delta type');
|
assert(signatureEvent.data.delta.type === 'thinking_signature_delta', 'Expected thinking_signature_delta type');
|
||||||
|
assert(typeof signatureEvent.data.delta.signature === 'string', 'Expected signature string');
|
||||||
assert(signatureEvent.data.delta.signature.length > 0, 'Expected signature length > 0');
|
assert(signatureEvent.data.delta.signature.length > 0, 'Expected signature length > 0');
|
||||||
assert(signatureEvent.data.delta.signature.hash, 'Expected signature hash');
|
|
||||||
assert(signatureEvent.data.delta.signature.hash.length === 16, 'Expected 16-char hash');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test 3: transformDelta skips signature for empty thinking blocks
|
// Test 3: transformDelta skips signature for empty thinking blocks
|
||||||
@@ -179,8 +179,8 @@ runner.test('transformDelta generates signature for non-empty thinking blocks',
|
|||||||
|
|
||||||
// Verify signature structure
|
// Verify signature structure
|
||||||
const sig = signatureEvents[0].data.delta.signature;
|
const sig = signatureEvents[0].data.delta.signature;
|
||||||
assert(sig.hash && sig.hash.length === 16, 'Expected valid 16-char hash');
|
assert(typeof sig === 'string', 'Expected signature string');
|
||||||
assert(sig.length > 0, 'Expected content length > 0');
|
assert(sig.length > 0, 'Expected signature length > 0');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test 5: Loop detection handles empty thinking blocks
|
// Test 5: Loop detection handles empty thinking blocks
|
||||||
@@ -217,7 +217,7 @@ runner.test('Loop detection handles empty thinking blocks without signature', ()
|
|||||||
|
|
||||||
const currentBlock = accumulator.getCurrentBlock();
|
const currentBlock = accumulator.getCurrentBlock();
|
||||||
if (currentBlock && currentBlock.type === 'thinking') {
|
if (currentBlock && currentBlock.type === 'thinking') {
|
||||||
const signatureEvent = transformer._createSignatureDeltaEvent(currentBlock);
|
const signatureEvent = responseBuilder.createSignatureDeltaEvent(currentBlock);
|
||||||
// Should return null for empty block
|
// Should return null for empty block
|
||||||
assert(signatureEvent === null, 'Expected null signature for empty thinking block during loop detection');
|
assert(signatureEvent === null, 'Expected null signature for empty thinking block during loop detection');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,5 +170,6 @@ describe('proxy SSE stream transformer', () => {
|
|||||||
typeof signature,
|
typeof signature,
|
||||||
`expected non-empty string signature, received ${JSON.stringify(signature)}`
|
`expected non-empty string signature, received ${JSON.stringify(signature)}`
|
||||||
).toBe('string');
|
).toBe('string');
|
||||||
|
expect((signature as string).length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user