Files
Cli-Proxy-API-Management-Ce…/tests/visualConfigDevinSensitiveWords.test.ts
Supra4E8C ebb5b7d0c0 Refactor provider credential weight normalization tests and update API key structure
- Updated test cases in `providerWeightTransformers.test.ts` to reflect changes in API key structure from 'api-key-entries' to 'keys'.
- Introduced new tests in `providerWorkbenchUi.test.ts` to verify the editing surface of provider workbench.
- Modified `sponsorCustomEndpoint.test.ts` to adapt to the new API key structure.
- Adjusted `visualConfigAntigravitySensitiveWords.test.ts` and `visualConfigConcurrency.test.ts` to accommodate new YAML structure for sensitive words and concurrency settings.
- Enhanced `visualConfigDefaults.test.ts` to ensure proper handling of boolean defaults and YAML structure.
- Updated `visualConfigDevinSensitiveWords.test.ts` to reflect changes in the YAML structure for sensitive words.
- Refined `visualConfigDisableImageGeneration.test.ts` to align with new multimedia settings.
- Added comprehensive tests in `visualConfigV8.test.ts` to validate the v8 visual config contract and ensure scalar read/write path parity.
- Improved validation tests in `visualConfigValidation.test.ts` to handle new routing and requests structure.
- Cleaned up `xaiApiKeyProvider.test.ts` by removing unnecessary API client mocks and focusing on normalization of the xAI API key contract.
2026-09-28 12:55:16 +08:00

148 lines
4.6 KiB
TypeScript

import { describe, expect, test } from 'bun:test';
import { createElement, useState } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { parse as parseYaml } from 'yaml';
import { useVisualConfig } from '../src/hooks/useVisualConfig';
function unwrapPre(markup: string): string {
return markup.slice('<pre>'.length, -'</pre>'.length);
}
describe('visual config Devin sensitive words', () => {
test('loads devin.sensitive-words independently from Antigravity', () => {
function Harness() {
const visualConfig = useVisualConfig();
const [loaded, setLoaded] = useState(false);
if (!loaded) {
visualConfig.loadVisualValuesFromYaml(
'oauth:\n providers:\n devin:\n sensitive-words:\n - Claude Code\n - security testing\n' +
' antigravity:\n sensitive-words:\n - proxy\n'
);
setLoaded(true);
return null;
}
return createElement(
'pre',
null,
`${visualConfig.visualValues.devinSensitiveWords.join('|')}::${visualConfig.visualValues.antigravitySensitiveWords.join('|')}`
);
}
expect(unwrapPre(renderToStaticMarkup(createElement(Harness)))).toBe(
'Claude Code|security testing::proxy'
);
});
test('writes trimmed values while preserving unknown keys, comments, and Antigravity', () => {
const yaml = `# root comment
oauth:
providers:
devin:
# list comment
sensitive-words:
# retained item comment
- old-word
# unknown comment
future-option: true
antigravity:
sensitive-words:
- proxy
`;
function Harness() {
const visualConfig = useVisualConfig();
const [phase, setPhase] = useState(0);
if (phase === 0) {
visualConfig.loadVisualValuesFromYaml(yaml);
setPhase(1);
} else if (phase === 1) {
visualConfig.setVisualValues({ devinSensitiveWords: [' old-word ', '', 'new phrase'] });
setPhase(2);
} else {
return createElement('pre', null, visualConfig.applyVisualChangesToYaml(yaml));
}
return null;
}
const output = unwrapPre(renderToStaticMarkup(createElement(Harness)));
expect(parseYaml(output)).toEqual({
oauth: {
providers: {
devin: {
'sensitive-words': ['old-word', 'new phrase'],
'future-option': true,
},
antigravity: { 'sensitive-words': ['proxy'] },
},
},
});
expect(output).toContain('# root comment');
expect(output).toContain('# list comment');
expect(output).toContain('# retained item comment');
expect(output).toContain('# unknown comment');
});
test('clears the sensitive-words key and removes an otherwise empty Devin block', () => {
const yaml =
'oauth:\n providers:\n devin:\n sensitive-words:\n - remove-me\nobservability:\n logs:\n debug: true\n';
function Harness() {
const visualConfig = useVisualConfig();
const [phase, setPhase] = useState(0);
if (phase === 0) {
visualConfig.loadVisualValuesFromYaml(yaml);
setPhase(1);
} else if (phase === 1) {
visualConfig.setVisualValues({ devinSensitiveWords: [] });
setPhase(2);
} else {
return createElement('pre', null, visualConfig.applyVisualChangesToYaml(yaml));
}
return null;
}
expect(parseYaml(unwrapPre(renderToStaticMarkup(createElement(Harness))))).toEqual({
observability: { logs: { debug: true } },
});
});
test('cancels dirty state when restored and never marks Antigravity dirty', () => {
const yaml =
'oauth:\n providers:\n devin:\n sensitive-words:\n - original\n' +
' antigravity:\n sensitive-words:\n - untouched\n';
function Harness() {
const visualConfig = useVisualConfig();
const [phase, setPhase] = useState(0);
if (phase === 0) {
visualConfig.loadVisualValuesFromYaml(yaml);
setPhase(1);
} else if (phase === 1) {
visualConfig.setVisualValues({ devinSensitiveWords: ['changed'] });
setPhase(2);
} else if (phase === 2) {
visualConfig.setVisualValues({ devinSensitiveWords: ['original'] });
setPhase(3);
} else {
const output = visualConfig.applyVisualChangesToYaml(yaml);
return createElement(
'pre',
null,
`${visualConfig.visualDirty}|${[...visualConfig.visualDirtyFields].join(',')}|${output === yaml}`
);
}
return null;
}
expect(unwrapPre(renderToStaticMarkup(createElement(Harness)))).toBe('false||true');
});
});