Files
gemini-cli/scripts/optimization/lib/masking.test.ts
T
Abhijit Balaji 59d377e5e0 feat(optimization): implement manifest-driven extraction pipeline
- Implement `extract.ts` with robust character-aware parsing for snippets and tools.
- Consolidate research dependencies by moving `@ax-llm/ax` to root `optionalDependencies`.
- Relocate evaluation logic from `packages/core` to `scripts/optimization/lib/evals` to keep the production core lean.
- Add `optimization_targets` to `data/manifest.json` as the single source of truth for the pipeline.
- Implement comprehensive unit tests for extraction and variable masking with 100% pass rate.
- Update global config and linting rules to support the new optimization infrastructure.
2026-03-04 14:25:17 -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);
});
});