Files
gemini-cli/scripts/optimization/masking.test.ts
T
Abhijit Balaji 9bdf5d5995 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.
2026-03-04 15:14:45 -08:00

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);
});
});