Skip to content

Add --file-name-override flag to override group name for stdin input#1163

Open
NoNickeD wants to merge 3 commits intoopen-policy-agent:masterfrom
NoNickeD:add-group-flag
Open

Add --file-name-override flag to override group name for stdin input#1163
NoNickeD wants to merge 3 commits intoopen-policy-agent:masterfrom
NoNickeD:add-group-flag

Conversation

@NoNickeD
Copy link
Copy Markdown

Fixes #1095

This PR adds a --group flag to the conftest test command that allows overriding the group name for stdin input.

Problem: When using conftest with kustomize in loops, output shows generic 'FAIL - - main - message' making it hard to identify which component failed.

Solution: Add --group flag to specify custom group name for better traceability.

Usage:

kustomize build my/component | conftest test - -p policy --group my/component

Output:

  • Before: FAIL - - main - message
  • After: FAIL - my/component - main - message

Changes:

  • Add --group CLI flag to test command
  • Override FileName from '-' to custom group name when --group provided
  • Add unit tests for functionality

Enables better CI/CD traceability and GitHub annotations.

Copy link
Copy Markdown
Member

@jalseth jalseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for taking on this FR.

Thinking about this more, I think calling the flag "group" is a little too vague. What do you think about "file-name-override" instead?

cc @taraspos

Comment thread runner/test_test.go
NoNickeD added a commit to NoNickeD/conftest that referenced this pull request Sep 19, 2025
  - Renamed flag from 'group' to 'file-name-override' for clarity
  - Rewrote tests to use TestRunner.Run() method with proper test fixtures
  - Added comprehensive acceptance tests for the new flag
  - Fixed Rego v1 syntax in test policies
  - Added proper error handling and edge case testing

  Addresses review feedback from PR open-policy-agent#1163

Signed-off-by: nikos.nikolakakis <nonickedgr@gmail.com>
Copy link
Copy Markdown
Member

@jalseth jalseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a couple of minor changes. Thanks for the PR and sorry for the slow review cycle.

Comment thread runner/test_test.go Outdated
defer func() { os.Stdin = oldStdin }()

// Run the test
ctx := context.Background()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer t.Context() in tests.

Comment thread runner/test_test.go Outdated
}
}`
go func() {
defer w.Close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This defer isn't needed, you can w.Close() after the line below.

Comment thread runner/test_test.go Outdated
Failures: []output.Result{{Message: "test failure"}},
},
// Run with a regular file (not stdin)
ctx := context.Background()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer t.Context() in tests.

@jalseth
Copy link
Copy Markdown
Member

jalseth commented Nov 22, 2025

@NoNickeD friendly ping.

@jalseth
Copy link
Copy Markdown
Member

jalseth commented Nov 27, 2025

@NoNickeD It looks like the tests are failing. You may need to rebase against the latest changes.

NoNickeD added a commit to NoNickeD/conftest that referenced this pull request Dec 11, 2025
  - Renamed flag from 'group' to 'file-name-override' for clarity
  - Rewrote tests to use TestRunner.Run() method with proper test fixtures
  - Added comprehensive acceptance tests for the new flag
  - Fixed Rego v1 syntax in test policies
  - Added proper error handling and edge case testing

  Addresses review feedback from PR open-policy-agent#1163

Signed-off-by: nikos.nikolakakis <nonickedgr@gmail.com>
@jalseth
Copy link
Copy Markdown
Member

jalseth commented Feb 7, 2026

@NoNickeD can you rebase again? There were some changes to the required PR checks, and I don't think there's another way to trigger them to run.

nikos.nikolakakis and others added 3 commits February 8, 2026 07:38
- Add --group CLI flag to test command for custom group naming
- Override FileName from '-' to custom group name when --group is provided
- Enables better identification of policy violations in CI/CD workflows
- Add unit tests for group flag functionality

Fixes open-policy-agent#1095

Signed-off-by: nikos.nikolakakis <nonickedgr@gmail.com>
  - Renamed flag from 'group' to 'file-name-override' for clarity
  - Rewrote tests to use TestRunner.Run() method with proper test fixtures
  - Added comprehensive acceptance tests for the new flag
  - Fixed Rego v1 syntax in test policies
  - Added proper error handling and edge case testing

  Addresses review feedback from PR open-policy-agent#1163

Signed-off-by: nikos.nikolakakis <nonickedgr@gmail.com>
- Use t.Context() instead of context.Background()
- Remove unnecessary defer in goroutine, call w.Close() directly

Signed-off-by: nikos.nikolakakis <nonickedgr@gmail.com>
@NoNickeD
Copy link
Copy Markdown
Author

NoNickeD commented Feb 8, 2026

Done! Rebased on top of the latest master.

@jalseth jalseth changed the title Add --group flag to override group name for stdin input Add --file-name-override flag to override group name for stdin input Mar 1, 2026
@jalseth
Copy link
Copy Markdown
Member

jalseth commented Mar 13, 2026

@NoNickeD The tests are not passing. Please ensure the tests pass locally and then I will check again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow specifying custom group name when validating files from stdin

2 participants