-
Notifications
You must be signed in to change notification settings - Fork 18
test: add failing test for multiple JSON output #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -464,6 +464,38 @@ func Test_Output_outputWorkflowEntryPoint(t *testing.T) { | |
| assert.Equal(t, expectedOutput, setup.writer.String()) | ||
| }) | ||
|
|
||
| // This test demonstrates a bug: when multiple application/json items are passed with --json flag, | ||
| // only the first item is output. The PopWritersByMimetype function removes the writer after the | ||
| // first use, causing subsequent items to find no writer available. | ||
| t.Run("should output all application/json items when json flag is set", func(t *testing.T) { | ||
| setup := setupTest(t) | ||
| setup.config.Set(output_workflow.OUTPUT_CONFIG_KEY_JSON, true) | ||
| defer setup.config.Set(output_workflow.OUTPUT_CONFIG_KEY_JSON, nil) | ||
|
|
||
| workflowIdentifier := workflow.NewTypeIdentifier(WORKFLOWID_OUTPUT_WORKFLOW, "output") | ||
|
|
||
| jsonPayload1 := `{"project":"first-project","dependencies":["pkg-a","pkg-b"]}` | ||
| jsonPayload2 := `{"project":"second-project","dependencies":["pkg-c","pkg-d"]}` | ||
|
|
||
| data1 := workflow.NewData(workflowIdentifier, "application/json", []byte(jsonPayload1)) | ||
| data1.SetContentLocation("first-project/lock.file") | ||
|
|
||
| data2 := workflow.NewData(workflowIdentifier, "application/json", []byte(jsonPayload2)) | ||
| data2.SetContentLocation("second-project/lock.file") | ||
|
|
||
| output, err := outputWorkflowEntryPoint(setup.invocationContextMock, []workflow.Data{data1, data2}, setup.outputDestination) | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, []workflow.Data{}, output) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Should Fix] This assertion is a tautology that gives false confidence. — AI review
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion (non-blocking): — AI review |
||
|
|
||
| // BUG: Currently only the first JSON is output because PopWritersByMimetype | ||
| // removes the writer after the first item is processed. | ||
| // Expected: both JSON payloads should be in the output | ||
| outputStr := setup.writer.String() | ||
| assert.Contains(t, outputStr, "first-project", "First JSON payload should be in output") | ||
| assert.Contains(t, outputStr, "second-project", "Second JSON payload should be in output (BUG: this fails)") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] This is an ungated failing test — The bug it documents is real and well-diagnosed: Resolution (one required before merge): (a) land the production fix in this same PR so the test goes green on commit (preferred — a failing test should accompany its fix), or (b) — AI review |
||
| }) | ||
|
|
||
| t.Run("should print valid sarif json output", func(t *testing.T) { | ||
| setup := setupTest(t) | ||
| expectedSarif := "testdata/sarif-snyk-goof-ignores.json" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should-Fix: This adds a knowingly-failing test with no accompanying fix. Verified by running it:
assert.Contains(outputStr, "second-project")fails — writer output is{"project":"first-project",...}only. That fails the parentTest_Output_outputWorkflowEntryPointand makesgo test ./pkg/local_workflows/...exit non-zero. If this branch merges tomainon its own it red-lines CI for every consumer of the package until the fix lands.The bug it demonstrates is real and the root cause is correctly identified:
writerMapImpl.PopWritersByMimetype(output_workflow/writer.go) doesdelete(w.writers, mimeType), so the single JSON writer is consumed by the first item and the second finds none.Before merge, either land the production fix in the same PR/stack (test turns green), or quarantine with
t.Skip("<ticket>: multiple application/json items drop all but the first")referencing the bug, removed by the fix commit. If this PR is deliberately the RED step of a stack whose next commit carries the fix, this is acceptable — flagging so the decision is explicit.— AI review