Files
codex-security/plugins/codex-security/mcp-app/tests/assertions.ts
Michael D'Angelo 22a95220e4 feat(config): apply native profiles across scan workflows (#1018)
Load the selected Codex profile for scan workflows and pass its settings to fresh and resumed workers. Preserve explicit overrides on replay and keep provider credentials isolated by scan.
2026-11-02 15:45:49 -08:00

59 lines
1.5 KiB
TypeScript

import assert from "node:assert/strict";
import { parse as parseToml } from "smol-toml";
interface ToolResponse {
error?: { message?: string };
result?: { isError?: boolean; content?: { text?: string }[] };
}
export function assertNoError(response: ToolResponse) {
assert.equal(response.error, undefined, response.error?.message!);
assert.ok(response.result, "Expected a JSON-RPC result");
assert.notEqual(
response.result.isError,
true,
response.result?.content?.map((item) => item.text).join(" ")!,
);
}
export function assertFlagPair(
args: readonly string[],
flag: string,
value: string,
) {
const index = args.indexOf(flag);
assert.notEqual(index, -1, `missing ${flag}`);
assert.equal(args[index + 1], value);
}
export function nativeConfigOverrides(args: readonly string[]) {
return args.flatMap((arg, index) =>
arg === "--config" || arg === "-c" ? [args[index + 1]] : [],
);
}
export function assertConfigOverrides(
args: readonly string[],
values: Record<string, string | string[] | number | boolean | undefined>,
) {
const overrides = nativeConfigOverrides(args).map((value) =>
parseToml(value),
);
for (const [key, value] of Object.entries(values)) {
const supplied = overrides.map((config) =>
key
.split(".")
.reduce<unknown>(
(current, part) =>
(current as Record<string, unknown> | undefined)?.[part],
config,
),
);
assert.deepEqual(
supplied.findLast((item) => item !== undefined),
value,
key,
);
}
}