nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: opencontainers/runc
Pull request #2957 (2021-05-21 14:19:38)

libctr/cg/systemd: export rangeToBits
It's both a useful function, and sufficiently complex to discourage copying

Signed-off-by: Peter Hunt <pehunt@redhat.com>


Patch:
diff --git a/libcontainer/cgroups/systemd/common.go b/libcontainer/cgroups/systemd/common.go
index 91c314e0..de69617e 100644
--- a/libcontainer/cgroups/systemd/common.go
+++ b/libcontainer/cgroups/systemd/common.go
@@ -476,7 +476,7 @@ func addCpuset(cm *dbusConnManager, props *[]systemdDbus.Property, cpus, mems st
 	}
 
 	if cpus != "" {
-		bits, err := rangeToBits(cpus)
+		bits, err := RangeToBits(cpus)
 		if err != nil {
 			return fmt.Errorf("resources.CPU.Cpus=%q conversion error: %w",
 				cpus, err)
@@ -485,7 +485,7 @@ func addCpuset(cm *dbusConnManager, props *[]systemdDbus.Property, cpus, mems st
 			newProp("AllowedCPUs", bits))
 	}
 	if mems != "" {
-		bits, err := rangeToBits(mems)
+		bits, err := RangeToBits(mems)
 		if err != nil {
 			return fmt.Errorf("resources.CPU.Mems=%q conversion error: %w",
 				mems, err)
diff --git a/libcontainer/cgroups/systemd/cpuset.go b/libcontainer/cgroups/systemd/cpuset.go
index 07098218..264f4c89 100644
--- a/libcontainer/cgroups/systemd/cpuset.go
+++ b/libcontainer/cgroups/systemd/cpuset.go
@@ -9,11 +9,11 @@ import (
 	"github.com/willf/bitset"
 )
 
-// rangeToBits converts a text representation of a CPU mask (as written to
+// RangeToBits converts a text representation of a CPU mask (as written to
 // or read from cgroups' cpuset.* files, e.g. "1,3-5") to a slice of bytes
 // with the corresponding bits set (as consumed by systemd over dbus as
 // AllowedCPUs/AllowedMemoryNodes unit property value).
-func rangeToBits(str string) ([]byte, error) {
+func RangeToBits(str string) ([]byte, error) {
 	bits := &bitset.BitSet{}
 
 	for _, r := range strings.Split(str, ",") {
diff --git a/libcontainer/cgroups/systemd/v2.go b/libcontainer/cgroups/systemd/v2.go
index 8abb0feb..a7a2264c 100644
--- a/libcontainer/cgroups/systemd/v2.go
+++ b/libcontainer/cgroups/systemd/v2.go
@@ -96,7 +96,7 @@ func unifiedResToSystemdProps(cm *dbusConnManager, res map[string]string) (props
 				newProp("CPUWeight", num))
 
 		case "cpuset.cpus", "cpuset.mems":
-			bits, err := rangeToBits(v)
+			bits, err := RangeToBits(v)
 			if err != nil {
 				return nil, fmt.Errorf("unified resource %q=%q conversion error: %w", k, v, err)
 			}


Test patch:
diff --git a/libcontainer/cgroups/systemd/cpuset_test.go b/libcontainer/cgroups/systemd/cpuset_test.go
index 7dda1e3c..3030cba9 100644
--- a/libcontainer/cgroups/systemd/cpuset_test.go
+++ b/libcontainer/cgroups/systemd/cpuset_test.go
@@ -40,7 +40,7 @@ func TestRangeToBits(t *testing.T) {
 	}
 
 	for _, tc := range testCases {
-		out, err := rangeToBits(tc.in)
+		out, err := RangeToBits(tc.in)
 		if err != nil {
 			if !tc.isErr {
 				t.Errorf("case %q: unexpected error: %v", tc.in, err)
Repository: opencontainers/runc
Pull request #3326 (2021-12-16 00:49:47)

ci: add go 1.18beta1
Release notes: https://go.dev/blog/go1.18beta1

This is just for CI.


Patch:
diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go
index 023d623f..e6c71ac3 100644
--- a/libcontainer/factory_linux.go
+++ b/libcontainer/factory_linux.go
@@ -338,7 +338,12 @@ func (l *LinuxFactory) StartInitialization() (err error) {
 
 	defer func() {
 		if e := recover(); e != nil {
-			err = fmt.Errorf("panic from initialization: %w, %v", e, string(debug.Stack()))
+			if e, ok := e.(error); ok {
+				err = fmt.Errorf("panic from initialization: %w, %s", e, debug.Stack())
+			} else {
+				//nolint:errorlint // here e is not of error type
+				err = fmt.Errorf("panic from initialization: %v, %s", e, debug.Stack())
+			}
 		}
 	}()
 


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 72f6eb37..e6aa0f89 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -21,7 +21,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        go-version: [1.16.x, 1.17.x]
+        go-version: [1.16.x, 1.17.x, 1.18.0-beta1]
         rootless: ["rootless", ""]
         race: ["-race", ""]
         criu: [""]
Repository: opencontainers/runc
Pull request #3451 (2022-04-07 18:33:49)

Allow mounting of /proc/sys/kernel/ns_last_pid
The `CAP_CHECKPOINT_RESTORE` linux capability provides the ability to update `/proc/sys/kernel/ns_last_pid`. However, because this "file" is under `/proc`, and by default both K8s and CRI-O specify that `/proc/sys` should be mounted as Read-Only, even with the capability specified, a process will not be able to write to `ns_last_pid`.

To get around this, a pod author can specify a volume mount and a host path to bind-mount `/proc/sys/kernel/ns_last_pid`. However, `runc` does not allow specifying mounts under `/proc`.

This PR adds `/proc/sys/kernel/ns_last_pid` to the `validProcMounts` string array to enable a pod author to mount `ns_last_pid` as read-write. The default remains unchanged; unless explicitly requested as a volume mount, `ns_last_pid` will remain read-only regardless of whether or not `CAP_CHECKPOINT_RESTORE` is specified.




Patch:
diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go
index 5290a45e..e8d8211b 100644
--- a/libcontainer/rootfs_linux.go
+++ b/libcontainer/rootfs_linux.go
@@ -554,6 +554,7 @@ func checkProcMount(rootfs, dest, source string) error {
 		"/proc/loadavg",
 		"/proc/slabinfo",
 		"/proc/net/dev",
+		"/proc/sys/kernel/ns_last_pid",
 	}
 	for _, valid := range validProcMounts {
 		path, err := filepath.Rel(filepath.Join(rootfs, valid), dest)


Test patch:
diff --git a/libcontainer/rootfs_linux_test.go b/libcontainer/rootfs_linux_test.go
index e3bfdc50..8709a5e4 100644
--- a/libcontainer/rootfs_linux_test.go
+++ b/libcontainer/rootfs_linux_test.go
@@ -38,6 +38,14 @@ func TestCheckMountDestFalsePositive(t *testing.T) {
 	}
 }
 
+func TestCheckMountDestNsLastPid(t *testing.T) {
+	dest := "/rootfs/proc/sys/kernel/ns_last_pid"
+	err := checkProcMount("/rootfs", dest, "/proc")
+	if err != nil {
+		t.Fatal("/proc/sys/kernel/ns_last_pid should not return an error")
+	}
+}
+
 func TestNeedsSetupDev(t *testing.T) {
 	config := &configs.Config{
 		Mounts: []*configs.Mount{
Repository: opencontainers/runc
Pull request #3468 (2022-05-04 22:06:29)

Remove tun/tap from the default device rules
Looking through git blame, this was added by commit 9fac18329
aka "Initial commit of runc binary", most probably by mistake.

Obviously, a container should not have access to tun/tap device, unless
it is explicitly specified in configuration.

Now, removing this might create a compatibility issue, but I see no
other choice.

Aside from the obvious misconfiguration, this should also fix the
annoying

> Apr 26 03:46:56 foo.bar systemd[1]: Couldn't stat device /dev/char/10:200: No such file or directory

messages from systemd on every container start, when runc uses systemd
cgroup driver, and the system runs an old (< v240) version of systemd
(the message was presumably eliminated by [1]).

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1945929

[1] https://github.com/systemd/systemd/pull/10996/commits/d5aecba6e0b7c73657c4cf544ce57289115098e7

rhatdan: LGTM

Patch:
diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go
index 5ae95c6c..83c7a2c3 100644
--- a/libcontainer/specconv/spec_linux.go
+++ b/libcontainer/specconv/spec_linux.go
@@ -302,16 +302,6 @@ var AllowedDevices = []*devices.Device{
 			Allow:       true,
 		},
 	},
-	// tuntap
-	{
-		Rule: devices.Rule{
-			Type:        devices.CharDevice,
-			Major:       10,
-			Minor:       200,
-			Permissions: "rwm",
-			Allow:       true,
-		},
-	},
 }
 
 type CreateOpts struct {


Test patch:
diff --git a/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go b/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go
index d2793358..25703be5 100644
--- a/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go
+++ b/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go
@@ -120,21 +120,14 @@ block-8:
         51: Mov32Imm dst: r0 imm: 1
         52: Exit
 block-9:
-// tuntap (c, 10, 200, rwm, allow)
+// /dev/pts (c, 136, wildcard, rwm, true)
         53: JNEImm dst: r2 off: -1 imm: 2 <block-10>
-        54: JNEImm dst: r4 off: -1 imm: 10 <block-10>
-        55: JNEImm dst: r5 off: -1 imm: 200 <block-10>
-        56: Mov32Imm dst: r0 imm: 1
-        57: Exit
+        54: JNEImm dst: r4 off: -1 imm: 136 <block-10>
+        55: Mov32Imm dst: r0 imm: 1
+        56: Exit
 block-10:
-// /dev/pts (c, 136, wildcard, rwm, true)
-        58: JNEImm dst: r2 off: -1 imm: 2 <block-11>
-        59: JNEImm dst: r4 off: -1 imm: 136 <block-11>
-        60: Mov32Imm dst: r0 imm: 1
-        61: Exit
-block-11:
-        62: Mov32Imm dst: r0 imm: 0
-        63: Exit
+        57: Mov32Imm dst: r0 imm: 0
+        58: Exit
 `
 	var devices []*devices.Rule
 	for _, device := range specconv.AllowedDevices {
Repository: opencontainers/runc
Pull request #3493 (2022-05-26 22:56:51)

[1.1] Allow mounting of /proc/sys/kernel/ns_last_pid
Backport of #3451.


Patch:
diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go
index 51660f5e..3cfd2bf1 100644
--- a/libcontainer/rootfs_linux.go
+++ b/libcontainer/rootfs_linux.go
@@ -577,6 +577,7 @@ func checkProcMount(rootfs, dest, source string) error {
 		"/proc/loadavg",
 		"/proc/slabinfo",
 		"/proc/net/dev",
+		"/proc/sys/kernel/ns_last_pid",
 	}
 	for _, valid := range validProcMounts {
 		path, err := filepath.Rel(filepath.Join(rootfs, valid), dest)


Test patch:
diff --git a/libcontainer/rootfs_linux_test.go b/libcontainer/rootfs_linux_test.go
index e3bfdc50..8709a5e4 100644
--- a/libcontainer/rootfs_linux_test.go
+++ b/libcontainer/rootfs_linux_test.go
@@ -38,6 +38,14 @@ func TestCheckMountDestFalsePositive(t *testing.T) {
 	}
 }
 
+func TestCheckMountDestNsLastPid(t *testing.T) {
+	dest := "/rootfs/proc/sys/kernel/ns_last_pid"
+	err := checkProcMount("/rootfs", dest, "/proc")
+	if err != nil {
+		t.Fatal("/proc/sys/kernel/ns_last_pid should not return an error")
+	}
+}
+
 func TestNeedsSetupDev(t *testing.T) {
 	config := &configs.Config{
 		Mounts: []*configs.Mount{
Repository: opencontainers/runc
Pull request #2763 (2021-01-23 14:55:24)

Fix int overflow in test on 32 bit system
For #941
Replaces #1821
Rewrite #1080
Closes #1821 

On master it still fails to compile the test on 32bit arch.
```
$ GOARCH=386 go test -v ./libcontainer/user/
# github.com/opencontainers/runc/libcontainer/user [github.com/opencontainers/runc/libcontainer/user.test]
libcontainer/user/user_test.go:448:38: constant 2147483648 overflows int
FAIL    github.com/opencontainers/runc/libcontainer/user [build failed]
FAIL
```


Patch:
diff --git a/libcontainer/user/user.go b/libcontainer/user/user.go
index 4b89dad7..a533bf5e 100644
--- a/libcontainer/user/user.go
+++ b/libcontainer/user/user.go
@@ -466,7 +466,7 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err
 		// we asked for a group but didn't find it. let's check to see
 		// if we wanted a numeric group
 		if !found {
-			gid, err := strconv.Atoi(ag)
+			gid, err := strconv.ParseInt(ag, 10, 64)
 			if err != nil {
 				return nil, fmt.Errorf("Unable to find group %s", ag)
 			}
@@ -474,7 +474,7 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err
 			if gid < minId || gid > maxId {
 				return nil, ErrRange
 			}
-			gidMap[gid] = struct{}{}
+			gidMap[int(gid)] = struct{}{}
 		}
 	}
 	gids := []int{}
diff --git a/libcontainer/utils/utils.go b/libcontainer/utils/utils.go
index 40ccfaa1..6966ac5e 100644
--- a/libcontainer/utils/utils.go
+++ b/libcontainer/utils/utils.go
@@ -6,7 +6,6 @@ import (
 	"os"
 	"path/filepath"
 	"strings"
-	"unsafe"
 
 	"golang.org/x/sys/unix"
 )
@@ -106,7 +105,3 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
 	}
 	return
 }
-
-func GetIntSize() int {
-	return int(unsafe.Sizeof(1))
-}


Test patch:
diff --git a/libcontainer/user/user_test.go b/libcontainer/user/user_test.go
index 058ce64a..23bf4667 100644
--- a/libcontainer/user/user_test.go
+++ b/libcontainer/user/user_test.go
@@ -7,8 +7,6 @@ import (
 	"strconv"
 	"strings"
 	"testing"
-
-	"github.com/opencontainers/runc/libcontainer/utils"
 )
 
 func TestUserParseLine(t *testing.T) {
@@ -440,15 +438,12 @@ this is just some garbage data
 			expected: nil,
 			hasError: true,
 		},
-	}
-
-	if utils.GetIntSize() > 4 {
-		tests = append(tests, foo{
+		{
 			// groups with too large id
-			groups:   []string{strconv.Itoa(1 << 31)},
+			groups:   []string{strconv.FormatInt(1<<31, 10)},
 			expected: nil,
 			hasError: true,
-		})
+		},
 	}
 
 	for _, test := range tests {
Repository: opencontainers/runc
Pull request #2816 (2021-02-22 07:47:15)

Fix memory stats for cache in fs2
In cgroup v2, the "cache" value from cgroup v1 is called "file" in v2.
There are no values called "cache" in v2.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/memcontrol.c?id=31caf8b2a847214be856f843e251fc2ed2cd1075#n1521


Patch:
diff --git a/libcontainer/cgroups/fs2/memory.go b/libcontainer/cgroups/fs2/memory.go
index 1c6913bf..81b28df7 100644
--- a/libcontainer/cgroups/fs2/memory.go
+++ b/libcontainer/cgroups/fs2/memory.go
@@ -88,7 +88,7 @@ func statMemory(dirPath string, stats *cgroups.Stats) error {
 		}
 		stats.MemoryStats.Stats[t] = v
 	}
-	stats.MemoryStats.Cache = stats.MemoryStats.Stats["cache"]
+	stats.MemoryStats.Cache = stats.MemoryStats.Stats["file"]
 
 	memoryUsage, err := getMemoryDataV2(dirPath, "")
 	if err != nil {
diff --git a/libcontainer/devices/devices.go b/libcontainer/devices/devices.go
index 11b51dca..5011f373 100644
--- a/libcontainer/devices/devices.go
+++ b/libcontainer/devices/devices.go
@@ -54,7 +54,7 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
 			Permissions: Permissions(permissions),
 		},
 		Path:     path,
-		FileMode: os.FileMode(mode &^ unix.S_IFMT),
+		FileMode: os.FileMode(mode),
 		Uid:      stat.Uid,
 		Gid:      stat.Gid,
 	}, nil
diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go
index 6d4042d0..6d646c58 100644
--- a/libcontainer/specconv/spec_linux.go
+++ b/libcontainer/specconv/spec_linux.go
@@ -698,7 +698,7 @@ next:
 				return nil, err
 			}
 			if d.FileMode != nil {
-				filemode = *d.FileMode &^ unix.S_IFMT
+				filemode = *d.FileMode
 			}
 			device := &devices.Device{
 				Rule: devices.Rule{


Test patch:
diff --git a/libcontainer/devices/devices_test.go b/libcontainer/devices/devices_test.go
index 3081bd06..02ebb4b6 100644
--- a/libcontainer/devices/devices_test.go
+++ b/libcontainer/devices/devices_test.go
@@ -82,13 +82,22 @@ func TestHostDevicesAllValid(t *testing.T) {
 		if device.Major == 0 {
 			t.Errorf("device entry %+v has zero major number", device)
 		}
+		// Devices should only have file modes that correspond to their type.
+		var expectedType os.FileMode
 		switch device.Type {
-		case BlockDevice, CharDevice:
+		case BlockDevice:
+			expectedType = unix.S_IFBLK
+		case CharDevice:
+			expectedType = unix.S_IFCHR
 		case FifoDevice:
 			t.Logf("fifo devices shouldn't show up from HostDevices")
 			fallthrough
 		default:
 			t.Errorf("device entry %+v has unexpected type %v", device, device.Type)
 		}
+		gotType := device.FileMode & unix.S_IFMT
+		if expectedType != gotType {
+			t.Errorf("device entry %+v has mismatched types (expected %#x, got %#x)", device, expectedType, gotType)
+		}
 	}
 }
Repository: opencontainers/runc
Pull request #4257 (2024-04-25 18:12:58)

[1.1] libcontainer: force apps to think fips is enabled/disabled for testing
This is a backport of https://github.com/opencontainers/runc/pull/4246 to release-1.1. Original description follows.

The motivation behind this change is to provide a flexible mechanism for containers within a Kubernetes cluster to opt out of `FIPS` mode when necessary. This change enables apps to simulate `FIPS` mode being enabled or disabled for testing. Users can control whether apps believe `FIPS` mode is on or off by manipulating `/proc/sys/crypto/fips_enabled`.


Patch:
diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go
index c701d6a2..52ad3ba1 100644
--- a/libcontainer/rootfs_linux.go
+++ b/libcontainer/rootfs_linux.go
@@ -602,6 +602,7 @@ func checkProcMount(rootfs, dest, source string) error {
 		"/proc/slabinfo",
 		"/proc/net/dev",
 		"/proc/sys/kernel/ns_last_pid",
+		"/proc/sys/crypto/fips_enabled",
 	}
 	for _, valid := range validProcMounts {
 		path, err := filepath.Rel(filepath.Join(rootfs, valid), dest)


Test patch:
diff --git a/libcontainer/rootfs_linux_test.go b/libcontainer/rootfs_linux_test.go
index 8709a5e4..223f75e8 100644
--- a/libcontainer/rootfs_linux_test.go
+++ b/libcontainer/rootfs_linux_test.go
@@ -46,6 +46,14 @@ func TestCheckMountDestNsLastPid(t *testing.T) {
 	}
 }
 
+func TestCheckCryptoFipsEnabled(t *testing.T) {
+	dest := "/rootfs/proc/sys/crypto/fips_enabled"
+	err := checkProcMount("/rootfs", dest, "/proc")
+	if err != nil {
+		t.Fatalf("/proc/sys/crypto/fips_enabled should not return an error: %v", err)
+	}
+}
+
 func TestNeedsSetupDev(t *testing.T) {
 	config := &configs.Config{
 		Mounts: []*configs.Mount{
Repository: opencontainers/runc
Pull request #4556 (2024-12-17 03:15:33)

[1.2] Re-add tun/tap to default device rules
Backport of #4555.

Since v1.2.0 was released, a number of users complained that the removal
of tun/tap device access from the default device ruleset is causing a
regression in their workloads.

Additionally, it seems that some upper-level orchestration tools
(Docker Swarm, Kubernetes) makes it either impossible or cumbersome
to supply additional device rules.

While it's probably not quite right to have /dev/net/tun in a default
device list, it was there from the very beginning, and users rely on it.
Let's keep it there for the sake of backward compatibility.

This reverts commit 2ce40b6.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(Cherry-pick of commit 394f4c3.)
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>


Patch:
diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go
index e7c6faae..95ada499 100644
--- a/libcontainer/specconv/spec_linux.go
+++ b/libcontainer/specconv/spec_linux.go
@@ -315,6 +315,23 @@ var AllowedDevices = []*devices.Device{
 			Allow:       true,
 		},
 	},
+	// The following entry for /dev/net/tun device was there from the
+	// very early days of Docker, but got removed in runc 1.2.0-rc1,
+	// causing a number of regressions for users (see
+	// https://github.com/opencontainers/runc/pull/3468).
+	//
+	// Some upper-level orcherstration tools makes it either impossible
+	// or cumbersome to supply additional device rules, so we have to
+	// keep this for the sake of backward compatibility.
+	{
+		Rule: devices.Rule{
+			Type:        devices.CharDevice,
+			Major:       10,
+			Minor:       200,
+			Permissions: "rwm",
+			Allow:       true,
+		},
+	},
 }
 
 type CreateOpts struct {


Test patch:
diff --git a/libcontainer/cgroups/devices/devicefilter_test.go b/libcontainer/cgroups/devices/devicefilter_test.go
index 3a415a71..23ad92ea 100644
--- a/libcontainer/cgroups/devices/devicefilter_test.go
+++ b/libcontainer/cgroups/devices/devicefilter_test.go
@@ -120,14 +120,21 @@ block-8:
         51: MovImm32 dst: r0 imm: 1
         52: Exit
 block-9:
-// /dev/pts (c, 136, wildcard, rwm, true)
+// tuntap (c, 10, 200, rwm, true)
         53: JNEImm dst: r2 off: -1 imm: 2 <block-10>
-        54: JNEImm dst: r4 off: -1 imm: 136 <block-10>
-        55: MovImm32 dst: r0 imm: 1
-        56: Exit
+        54: JNEImm dst: r4 off: -1 imm: 10 <block-10>
+        55: JNEImm dst: r5 off: -1 imm: 200 <block-10>
+        56: MovImm32 dst: r0 imm: 1
+        57: Exit
 block-10:
-        57: MovImm32 dst: r0 imm: 0
-        58: Exit
+// /dev/pts (c, 136, wildcard, rwm, true)
+	58: JNEImm dst: r2 off: -1 imm: 2 <block-11>
+        59: JNEImm dst: r4 off: -1 imm: 136 <block-11>
+        60: MovImm32 dst: r0 imm: 1
+        61: Exit
+block-11:
+        62: MovImm32 dst: r0 imm: 0
+        63: Exit
 `
 	var devices []*devices.Rule
 	for _, device := range specconv.AllowedDevices {
Repository: softwaremill/sttp-openai
Pull request #302 (2025-03-18 08:45:32)

issue-298: missing keys in dictionary: id


Patch:
diff --git a/core/src/main/scala/sttp/openai/requests/completions/chat/ChatRequestResponseData.scala b/core/src/main/scala/sttp/openai/requests/completions/chat/ChatRequestResponseData.scala
index 5e6ff55..f786792 100644
--- a/core/src/main/scala/sttp/openai/requests/completions/chat/ChatRequestResponseData.scala
+++ b/core/src/main/scala/sttp/openai/requests/completions/chat/ChatRequestResponseData.scala
@@ -17,8 +17,6 @@ object ChatRequestResponseData {
     *   The name and arguments of a function that should be called, as generated by the model.
     * @param audio
     *   If the audio output modality is requested, this object contains data about the audio response from the model. Learn more.
-    * @param id
-    *   The identifier of the chat message.
     */
   case class Message(
       content: String,
@@ -26,8 +24,7 @@ object ChatRequestResponseData {
       toolCalls: Seq[ToolCall] = Nil,
       role: Role,
       functionCall: Option[FunctionCall] = None,
-      audio: Option[Audio] = None,
-      id: String
+      audio: Option[Audio] = None
   )
 
   object Message {


Test patch:
diff --git a/core/src/test/scala/sttp/openai/fixtures/ChatFixture.scala b/core/src/test/scala/sttp/openai/fixtures/ChatFixture.scala
index 73e7d45..34d6044 100644
--- a/core/src/test/scala/sttp/openai/fixtures/ChatFixture.scala
+++ b/core/src/test/scala/sttp/openai/fixtures/ChatFixture.scala
@@ -190,8 +190,7 @@ object ChatFixture {
       |             "name": "Fish"
       |           }
       |         }
-      |        ],
-      |        "id": "chatcmpl-76FxnKOjnPkDVYTAQ1wK8iUNFJPvR"
+      |        ]
       |      },
       |      "finish_reason": "stop",
       |      "index": 0,
diff --git a/core/src/test/scala/sttp/openai/requests/completions/chat/ChatDataSpec.scala b/core/src/test/scala/sttp/openai/requests/completions/chat/ChatDataSpec.scala
index b39ad15..be92de8 100644
--- a/core/src/test/scala/sttp/openai/requests/completions/chat/ChatDataSpec.scala
+++ b/core/src/test/scala/sttp/openai/requests/completions/chat/ChatDataSpec.scala
@@ -60,7 +60,6 @@ class ChatDataSpec extends AnyFlatSpec with Matchers with EitherValues {
         Message(
           role = Assistant,
           content = "Hi there! How can I assist you today?",
-          id = "chatcmpl-76FxnKOjnPkDVYTAQ1wK8iUNFJPvR",
           audio = Some(
             Audio(
               id = "audio_id",
@@ -106,8 +105,7 @@ class ChatDataSpec extends AnyFlatSpec with Matchers with EitherValues {
     val message: Message = Message(
       role = Role.Assistant,
       content = "Hi there! How can I assist you today?",
-      toolCalls = toolCalls,
-      id = "chatcmpl-76FxnKOjnPkDVYTAQ1wK8iUNFJPvR"
+      toolCalls = toolCalls
     )
 
     val choices: Choices = Choices(