fix(cli): reject extra inspect args and add stdin BATS coverage - #4014
Conversation
Follow-up to review feedback on #3937 (dspx-2604-08-streamio): - inspectDoc now sets Args = cobra.MaximumNArgs(1), so extra positional arguments (e.g. `otdfctl inspect a.tdf b.tdf`) are rejected instead of silently ignoring everything after the first path. - Add BATS coverage for piping a TDF into `inspect` via stdin, and for the new extra-args rejection, in otdfctl/e2e/encrypt-decrypt.bats. TestOpenSeekableSpoolsNonSeekableNamedFile in otdfctl/pkg/streamio was also flagged as using syscall.Mkfifo, which is not portable to Windows; it already guards with a runtime.GOOS == "windows" skip, so no change was needed there. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe ChangesInspect argument validation
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to The inspect command now rejects extra positional arguments while retaining single-input and stdin inspection behavior. The updated end-to-end coverage supports merge readiness with no remaining actionable risk. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit checks the inspect command, Comment |
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
c-r33d
left a comment
There was a problem hiding this comment.
Wouldn't you want ExactArgs(1) since it should just be 1 TDF?
0 args falls back to standard input |
Follow-up to review feedback on #3937 (
chore(cli): move streaming IO helpers into pkg, merged intomain).Changes
otdfctl/cmd/tdf/inspect.go:inspectDoc.Args = cobra.MaximumNArgs(1), sootdfctl inspect a.tdf b.tdfnow errors instead of silently ignoringb.tdf.otdfctl/e2e/encrypt-decrypt.bats: added a test piping a TDF intoinspectvia stdin, and a test asserting extra positional args now fail.Not changed
TestOpenSeekableSpoolsNonSeekableNamedFileinotdfctl/pkg/streamio/input_test.gowas also flagged (usessyscall.Mkfifo, not portable to Windows) — it already guards with aruntime.GOOS == "windows"skip, so no change was needed. Verified by running the test.Testing
go build ./.../go vet ./...— passgolangci-lint run ./otdfctl/cmd/tdf/...— 0 issuesbats --count e2e/encrypt-decrypt.bats— parses, 19 tests (up from 17)otdfctl inspect a.tdf b.tdfnow errors withaccepts at most 1 arg(s), received 2Note:
encrypt-decrypt.batshas a pre-existing file-levelskipinsetup_file(unrelated: namespaced subject-mapping API dependency), so the new BATS tests won't run in CI until that skip is lifted, same as all other tests in that file.Summary by CodeRabbit
Bug Fixes
inspectcommand now rejects requests containing more than one positional argument, providing clearer command-line validation.Tests