-
Notifications
You must be signed in to change notification settings - Fork 21
[test-improver] Improve tests for logger/jsonl_logger package #2915
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
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -438,12 +438,11 @@ func TestLogRPCMessageJSONLDirectionTypes(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Read and verify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content, err := os.ReadFile(logPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return // File might not exist yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(err, "Failed to read log file") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var entry JSONLRPCMessage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| json.Unmarshal(content, &entry) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err = json.Unmarshal(content, &entry) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(err, "Failed to parse JSONL entry") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| a.Equal(tt.expected["direction"], entry.Direction, "Direction should match") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| a.Equal(tt.expected["type"], entry.Type, "Type should match") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -621,3 +620,174 @@ func TestLogDifcFilteredItem_MultipleEntriesAuditTrail(t *testing.T) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.NotEmpty(line.Reason, "entry[%d] must have Reason", i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TestLogRPCMessageJSONLWithTags_AgentSecrecyTags verifies that agent secrecy tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // are written into the JSONL entry when provided, and that integrity is omitted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func TestLogRPCMessageJSONLWithTags_AgentSecrecyTags(t *testing.T) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require := require.New(t) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert := assert.New(t) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tmpDir := t.TempDir() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logDir := filepath.Join(tmpDir, "logs") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err := InitJSONLLogger(logDir, "test.jsonl") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| require.NoError(err, "InitJSONLLogger failed") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer CloseJSONLLogger() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| payload := []byte(`{"jsonrpc":"2.0","id":1}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secrecyTags := []string{"private:org/repo", "public"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LogRPCMessageJSONLWithTags(RPCDirectionInbound, RPCMessageResponse, "github", "tools/call", payload, nil, secrecyTags, nil) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+637
to
+640
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CloseJSONLLogger() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+635
to
+641
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer CloseJSONLLogger() | |
| payload := []byte(`{"jsonrpc":"2.0","id":1}`) | |
| secrecyTags := []string{"private:org/repo", "public"} | |
| LogRPCMessageJSONLWithTags(RPCDirectionInbound, RPCMessageResponse, "github", "tools/call", payload, nil, secrecyTags, nil) | |
| CloseJSONLLogger() | |
| payload := []byte(`{"jsonrpc":"2.0","id":1}`) | |
| secrecyTags := []string{"private:org/repo", "public"} | |
| LogRPCMessageJSONLWithTags(RPCDirectionInbound, RPCMessageResponse, "github", "tools/call", payload, nil, secrecyTags, nil) | |
| err = CloseJSONLLogger() | |
| require.NoError(err, "CloseJSONLLogger failed") |
Copilot
AI
Mar 31, 2026
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.
TestLogRPCMessageJSONLWithTags_TagsCopied doesn't currently prove that the implementation copies the tag slices: LogRPCMessageJSONLWithTags encodes the entry synchronously before returning, so mutating the caller slice after the call cannot affect the already-written file even without a defensive copy. Either remove this test or rework it to mutate concurrently while logging (and/or validate behavior under -race) so it would fail if the copy is removed.
| func TestLogRPCMessageJSONLWithTags_TagsCopied(t *testing.T) { | |
| require := require.New(t) | |
| assert := assert.New(t) | |
| tmpDir := t.TempDir() | |
| logDir := filepath.Join(tmpDir, "logs") | |
| err := InitJSONLLogger(logDir, "test.jsonl") | |
| require.NoError(err, "InitJSONLLogger failed") | |
| defer CloseJSONLLogger() | |
| payload := []byte(`{"jsonrpc":"2.0","id":1}`) | |
| secrecyTags := []string{"private:org/repo"} | |
| integrityTags := []string{"approved:org/repo"} | |
| LogRPCMessageJSONLWithTags(RPCDirectionInbound, RPCMessageResponse, "github", "tools/call", payload, nil, secrecyTags, integrityTags) | |
| CloseJSONLLogger() | |
| // Mutate the originals after the call. | |
| secrecyTags[0] = "MUTATED" | |
| integrityTags[0] = "MUTATED" | |
| logPath := filepath.Join(logDir, "test.jsonl") | |
| content, err := os.ReadFile(logPath) | |
| require.NoError(err, "Failed to read log file") | |
| var entry JSONLRPCMessage | |
| err = json.Unmarshal(content, &entry) | |
| require.NoError(err, "Failed to parse JSONL entry") | |
| // The logged values must reflect the originals at call time, not the mutation. | |
| assert.Equal([]string{"private:org/repo"}, entry.AgentSecrecy, "AgentSecrecy must be an independent copy") | |
| assert.Equal([]string{"approved:org/repo"}, entry.AgentIntegrity, "AgentIntegrity must be an independent copy") | |
| } |
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.
In this subtest,
requirewas created with the parentt(outsidet.Run) and is used here. If an assertion fails,FailNowwould be invoked on the parent test from the subtest goroutine, which can panic or misattribute failures. Instantiate a newrequire := require.New(t)inside the subtest (or userequire.NoError(t, ...)with the subtestt) for these checks.