mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-17 21:40:39 -07:00
feat(optimization): consolidate extraction pipeline and metrics
- Flatten directory structure by moving masking and evals to scripts root. - Merge evaluation metrics into scripts/optimization/evals. - Restore and verify extraction tests for the new structure.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { maskVariables, unmaskVariables } from './masking.js';
|
||||
|
||||
describe('optimization masking utility', () => {
|
||||
it('should mask unique template variables with indexed tokens', () => {
|
||||
const input = 'Use ${TOOL_A} to read ${FILE_PATH}. ${TOOL_A} is efficient.';
|
||||
const { maskedText, maskMap } = maskVariables(input);
|
||||
|
||||
expect(maskedText).toContain('[[GCLI_VAR_0]]');
|
||||
expect(maskedText).toContain('[[GCLI_VAR_1]]');
|
||||
// Ensure all occurrences of the same variable are replaced with the same token
|
||||
const toolAToken = Object.keys(maskMap).find(
|
||||
(key) => maskMap[key] === '${TOOL_A}',
|
||||
)!;
|
||||
const count = maskedText.split(toolAToken).length - 1;
|
||||
expect(count).toBe(2);
|
||||
expect(maskedText).not.toContain('${TOOL_A}');
|
||||
});
|
||||
|
||||
it('should perfectly restore original text during unmasking', () => {
|
||||
const original = 'Update ${OLD_STR} with ${NEW_STR} in ${FILE_PATH}.';
|
||||
const { maskedText, maskMap } = maskVariables(original);
|
||||
const restored = unmaskVariables(maskedText, maskMap);
|
||||
|
||||
expect(restored).toBe(original);
|
||||
});
|
||||
|
||||
it('should handle text with no variables', () => {
|
||||
const input = 'Static text with no placeholders.';
|
||||
const { maskedText, maskMap } = maskVariables(input);
|
||||
|
||||
expect(maskedText).toBe(input);
|
||||
expect(Object.keys(maskMap).length).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user