Conversation
|
Claude finished @tooky's task in 4m 27s —— View job PR Review:
|
|
Addressed the review feedback in 841836c: 1. TODO.md duplicate — Removed the unchecked duplicate Slice 3 line. 2. Parent
3. Flag registration duplication — Left as-is per the review (non-blocking). Three flags registered by hand is simpler than embedding 4. |
|
From Alex — feedback on This is a strong addition that directly addresses a gap we've been working around in the agentic SDLC demo. We run 10 control gates in CI, each calling How we'd use this immediately:
A few suggestions:
Implementation looks clean — good reuse of |
OPA is an implementation detail. The other commands say 'Rego policy' consistently — align all three evaluate subcommands to match. Addresses Dan's review comment on PR #743. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests for missing `package policy`, missing `allow` rule, and `allow = false` without a `violations` rule. Documents the expected error messages and behaviour through `evaluate input`. Addresses Dan's review comments on PR #743. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Show how to capture trail data with --show-input and extract .input with jq for local policy iteration. Clarify that the input file should contain the raw JSON object, not the --show-input wrapper. Addresses Alex's review suggestions on PR #743. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Avoid restating the short description; the second sentence now adds new information (file or stdin) rather than repeating. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
loadInputFromFile now delegates to loadInput after opening the file, eliminating the duplicated JSON unmarshal logic. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Remove duplicate Slice 3 entry in TODO.md - Broaden parent evaluate command description to cover both API-backed trail evaluation and local input evaluation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
OPA is an implementation detail. The other commands say 'Rego policy' consistently — align all three evaluate subcommands to match. Addresses Dan's review comment on PR #743. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests for missing `package policy`, missing `allow` rule, and `allow = false` without a `violations` rule. Documents the expected error messages and behaviour through `evaluate input`. Addresses Dan's review comments on PR #743. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Show how to capture trail data with --show-input and extract .input with jq for local policy iteration. Clarify that the input file should contain the raw JSON object, not the --show-input wrapper. Addresses Alex's review suggestions on PR #743. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the os.Stdin global with an injected io.Reader parameter, passed via Cobra's InOrStdin(). This makes the stdin path testable with controlled input via cmd.SetIn(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove flag registration duplication by embedding the shared struct. Hide flow and attestations flags that don't apply to evaluate input. Move RequireFlags out of addFlags so each command specifies its own required flags independently. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Avoids the double-allocation from io.ReadAll + json.Unmarshal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| name: "missing --input-file reads from stdin (empty stdin fails)", | ||
| cmd: "evaluate input --policy testdata/policies/allow-all.rego", | ||
| goldenRegex: `failed to parse input:`, | ||
| }, |
There was a problem hiding this comment.
The test at line 48–51 ("missing --input-file reads from stdin (empty stdin fails)") — since the terminal detection was added in Slice 5, does this test still exercise the loadInput error path, or does it now hit the term.IsTerminal check first? In CI the stdin is likely not a terminal so it should still reach loadInput, but the test name and golden regex (failed to parse input) might not match the actual error in all environments.
Consider adding a comment noting this assumption, or explicitly using cmd.SetIn() with an empty bytes.Buffer to guarantee the loadInput path is tested regardless of CI environment.
When --input-file is omitted and stdin is a terminal, return a clear error instead of silently blocking. Uses golang.org/x/term to detect the terminal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| name: "missing --input-file reads from stdin (empty stdin fails)", | ||
| cmd: "evaluate input --policy testdata/policies/allow-all.rego", | ||
| goldenRegex: `failed to parse input:`, | ||
| }, |
There was a problem hiding this comment.
Minor: This test implicitly relies on CI stdin not being a terminal. If CI ever allocates a PTY, it would hit the term.IsTerminal check instead of the loadInput error path. Consider explicitly providing an empty reader via a helper that calls cmd.SetIn(&bytes.Buffer{}) to guarantee this tests the loadInput path regardless of environment.
go mod tidy resolved conflict markers left from rebase and updated golang.org/x/term to v0.41.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Set root.SetIn(new(bytes.Buffer)) in executeCommandC so tests get an empty buffer as stdin rather than inheriting the process stdin. This ensures the empty-stdin test exercises loadInput reliably regardless of whether CI stdin is a terminal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| name: "deny without violations rule returns DENIED with no violation messages", | ||
| cmd: "evaluate input --input-file testdata/evaluate/trail-input.json --policy testdata/policies/deny-no-violations.rego", | ||
| goldenRegex: `RESULT:\s+DENIED`, | ||
| }, |
There was a problem hiding this comment.
Consider adding a test case for invalid.rego (the syntax-error fixture that already exists in testdata/policies/). This would round out the policy validation coverage alongside the no-package-policy, no-allow-rule, and deny-no-violations cases:
{
wantError: true,
name: "syntactically invalid policy returns error",
cmd: "evaluate input --input-file testdata/evaluate/trail-input.json --policy testdata/policies/invalid.rego",
goldenRegex: `failed to evaluate policy`,
},(Adjust the expected regex to match the actual error from evaluate.Evaluate for malformed Rego.)
Summary
kosli evaluate input— evaluate a local JSON file (or stdin) against a Rego policy, with no API dependencyPrompted by this discussion where we realised
kosli evaluate trailalways hits the API, so there's no way to iterate on policies locally. Dan raised conftest as the alternative, but our tooling should support this natively — Rego is our language choice, and local testing should be turnkey.In response to Alex's comparison of Rego vs pipeline controls — as more controls move into
kosli evaluate, a fast local feedback loop becomes essential.Usage
Test plan
go test -v -run TestEvaluateInputCommandTestSuite ./cmd/kosli/)loadInput(io.Reader)unit tests passmake lintcleankosli evaluate input --helpshows expected output--show-inputJSON against a policy🤖 Generated with Claude Code