mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-28 12:42:42 -07:00
9bdf5d5995
- 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.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
/**
|
|
* @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);
|
|
});
|
|
});
|