chore: import upstream snapshot with attribution
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { requestsStructuredCodeScanOutput } from '../../../src/codeScan/util/structuredOutputDetect';
|
||||
|
||||
const node = 'node';
|
||||
const cli = '/path/to/main.js';
|
||||
|
||||
function argv(...rest: string[]): string[] {
|
||||
return [node, cli, ...rest];
|
||||
}
|
||||
|
||||
describe('requestsStructuredCodeScanOutput', () => {
|
||||
it('returns false when the subcommand is not code-scans run', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv())).toBe(false);
|
||||
expect(requestsStructuredCodeScanOutput(argv('eval', '--json'))).toBe(false);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans'))).toBe(false);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'list', '--json'))).toBe(false);
|
||||
});
|
||||
|
||||
it('detects --json on code-scans run', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '.', '--json'))).toBe(true);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--json', '.'))).toBe(true);
|
||||
});
|
||||
|
||||
it('detects --format sarif and --format json (space-separated)', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format', 'sarif'))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format', 'json'))).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('detects -f sarif and -f json (short alias, space-separated)', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-f', 'sarif'))).toBe(true);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-f', 'json'))).toBe(true);
|
||||
});
|
||||
|
||||
it('detects --format=value and -f=value (equals form)', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format=sarif'))).toBe(
|
||||
true,
|
||||
);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format=json'))).toBe(true);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-f=sarif'))).toBe(true);
|
||||
});
|
||||
|
||||
it('detects -fsarif and -fjson (Commander combined short form)', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-fsarif'))).toBe(true);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-fjson'))).toBe(true);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-ftext'))).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for --format text (the default)', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format', 'text'))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format=text'))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-f', 'text'))).toBe(false);
|
||||
});
|
||||
|
||||
it('still detects --json after a non-structured --format text', () => {
|
||||
// Regression: an earlier implementation returned eagerly on --format and missed
|
||||
// a later --json. Matters because Commander allows redundant flags.
|
||||
expect(
|
||||
requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format', 'text', '--json')),
|
||||
).toBe(true);
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '-f=text', '--json'))).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('detects the latest format when multiple --format flags appear', () => {
|
||||
expect(
|
||||
requestsStructuredCodeScanOutput(
|
||||
argv('code-scans', 'run', '--format', 'text', '--format', 'sarif'),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
requestsStructuredCodeScanOutput(
|
||||
argv('code-scans', 'run', '--format=sarif', '--format=text'),
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("does not misinterpret a value-eating flag's argument as a structured-output flag", () => {
|
||||
// `--base --json` — the literal `--json` is the value of `--base`, not a real flag.
|
||||
expect(
|
||||
requestsStructuredCodeScanOutput(argv('code-scans', 'run', '.', '--base', '--json')),
|
||||
).toBe(false);
|
||||
expect(
|
||||
requestsStructuredCodeScanOutput(argv('code-scans', 'run', '.', '--config', '--format')),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('stops scanning at the conventional `--` positional separator', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '.', '--', '--json'))).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns false for a bare --format with no value', () => {
|
||||
expect(requestsStructuredCodeScanOutput(argv('code-scans', 'run', '--format'))).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user