aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--Dockerfile16
-rw-r--r--README.md43
-rw-r--r--docs/config.md134
-rw-r--r--docs/docker.md16
-rw-r--r--src/slskd/Application.cs2
-rw-r--r--src/slskd/Common/CommonExtensions.cs27
-rw-r--r--tests/slskd.Tests.Unit/Common/CommonExtensionsTests.cs523
8 files changed, 681 insertions, 82 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 66544b23..3ba5d450 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -8,7 +8,7 @@ By submitting a contribution to this project, you agree to the following:
* You have the legal right to make this contribution and to assign its copyright.
* You irrevocably assign all copyright and related rights in your contribution to the project maintainer(s).
-* You grant the project maintainer(s) the right to use, modify, distribute, and relicense your contribution under any license of their choosing.
+* You grant the project maintainer(s) (presently JP Dillingham) the right to use, modify, distribute, and relicense your contribution under any license of their choosing.
This application is currently released under the [AGPL 3.0](https://github.com/slskd/slskd/blob/master/LICENSE) license.
diff --git a/Dockerfile b/Dockerfile
index 6fbff9cc..94b3d4b5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -98,11 +98,10 @@ LABEL org.opencontainers.image.title=slskd \
WORKDIR /slskd
COPY --from=publish /slskd/dist/${TARGETPLATFORM} .
-# supports two modes:
-# 1. --user / user: (modern Docker) — container starts as non-root,
-# skips all usermod/chown, execs the app directly.
-# 2. PUID/PGID (legacy linuxserver style) — container starts as root,
-# mutates user, chowns /app if needed, drops privileges via gosu.
+# supports three modes:
+# 1. --user / user: (modern Docker) — container starts as non-root, skips all usermod/chown, execs the app directly.
+# 2. PUID/PGID (legacy linuxserver style) — container starts as root, mutates user, chowns /app if needed, drops privileges via gosu.
+# 3. neither --user nor at least one of PUID/PGID supplied - container and app run as root
COPY <<'SCRIPT' /entrypoint.sh
#!/bin/bash
set -e
@@ -129,6 +128,13 @@ if [ "$(id -u)" -ne 0 ]; then
exec "$@"
fi
+# no --user supplied, neither PUID nor PGID supplied, run as root (same behavior as < 0.25.0)
+#---------------------------------------------------------------------------------------
+if [ -z "${PUID}" ] && [ -z "${PGID}" ]; then
+ umask "$SLSKD_UMASK"
+ exec "$@"
+fi
+
# PUID/PGID mode; user has provided explicit user and group IDs to use
#---------------------------------------------------------------------------------------
PUID="${PUID:-1000}"
diff --git a/README.md b/README.md
index e23bea3f..95a4f1ee 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,8 @@ New features are added all the time!
### With Docker
+Choose Docker's built-in method of specifying a user for the container:
+
```shell
docker run -d \
-p 5030:5030 \
@@ -53,14 +55,49 @@ docker run -d \
-e SLSKD_REMOTE_CONFIGURATION=true \
-v <path/to/application/data>:/app \
--name slskd \
+ --user 1000:1000 \
+ slskd/slskd:latest
+```
+
+Or use the Linuxserver/*arr `PUID`/`PGID` method:
+
+```shell
+docker run -d \
+ -p 5030:5030 \
+ -p 5031:5031 \
+ -p 50300:50300 \
+ -e PUID=1000 \
+ -e PGID=1000 \
+ -e SLSKD_REMOTE_CONFIGURATION=true \
+ -v <path/to/application/data>:/app \
+ --name slskd \
slskd/slskd:latest
```
### With Docker-Compose
+Choose Docker's built-in method of specifying a user for the container:
+
+```yaml
+services:
+ slskd:
+ image: slskd/slskd
+ container_name: slskd
+ user: "1000:1000"
+ ports:
+ - "5030:5030"
+ - "5031:5031"
+ - "50300:50300"
+ environment:
+ - SLSKD_REMOTE_CONFIGURATION=true
+ volumes:
+ - <path/to/application/data>:/app
+ restart: always
```
----
-version: "2"
+
+Or use the Linuxserver/*arr `PUID`/`PGID` method:
+
+```yaml
services:
slskd:
image: slskd/slskd
@@ -70,6 +107,8 @@ services:
- "5031:5031"
- "50300:50300"
environment:
+ - PUID=1000
+ - PGID=1000
- SLSKD_REMOTE_CONFIGURATION=true
volumes:
- <path/to/application/data>:/app
diff --git a/docs/config.md b/docs/config.md
index 1b77a674..b4e8fa47 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -349,7 +349,7 @@ A change to slot limits requires an application restart to take effect, while sp
#### **YAML**
```yaml
-global:
+transfers:
upload:
slots: 20
speed_limit: 1000 # kibibytes
@@ -372,19 +372,20 @@ Note that while it's possible to set the `failures` option for `queued`, it has
#### **YAML**
```yaml
-global:
- limits:
- queued:
- files: 500
- megabytes: 5000
- daily:
- files: 1000
- megabytes: 10000
- failures: 200
- weekly:
- files: 5000
- megabytes: 50000
- failures: 1000
+transfers:
+ upload:
+ limits:
+ queued:
+ files: 500
+ megabytes: 5000
+ daily:
+ files: 1000
+ megabytes: 10000
+ failures: 200
+ weekly:
+ files: 5000
+ megabytes: 50000
+ failures: 1000
```
## Groups
@@ -408,18 +409,18 @@ upload:
strategy: roundrobin # roundrobin or firstinfirstout
slots: 10 # 1 to 2147483647
speed_limit: 100 # in KiB/s, 1 to 2147483647
-limits:
- queued:
- files: 500 # 1 to 2147483647
- megabytes: 5000 # 1 to 2147483647
- daily:
- files: 1000
- megabytes: 10000
- failures: 200 # 1 to 2147483647
- weekly:
- files: 5000
- megabytes: 50000
- failures: 1000
+ limits:
+ queued:
+ files: 500 # 1 to 2147483647
+ megabytes: 5000 # 1 to 2147483647
+ daily:
+ files: 1000
+ megabytes: 10000
+ failures: 200 # 1 to 2147483647
+ weekly:
+ files: 5000
+ megabytes: 50000
+ failures: 1000
```
## Built-In Groups
@@ -434,45 +435,46 @@ It is impossible to explicitly assign users to these built-in groups, but the pr
#### **YAML**
```yaml
-groups:
- default:
- upload:
- priority: 1
- strategy: roundrobin
- slots: 10
- speed_limit: 50000 # kibibytes
- limits:
- queued:
- files: 150
- megabytes: 1500
- daily:
- files: 2147483647 # effectively unlimited, weekly still applies
- megabytes: 2147483647
- weekly:
- files: 1500
- megabytes: 15000
- failures: 150
- leechers:
- thresholds:
- files: 1
- directories: 1
- upload:
- priority: 99
- strategy: roundrobin
- slots: 1
- speed_limit: 100
- limits:
- queued:
- files: 15
- megabytes: 150
- daily:
- files: 30
- megabytes: 300
- failures: 10
- weekly:
- files: 150
- megabytes: 1500
- failures: 30
+transfers:
+ groups:
+ default:
+ upload:
+ priority: 1
+ strategy: roundrobin
+ slots: 10
+ speed_limit: 50000 # kibibytes
+ limits:
+ queued:
+ files: 150
+ megabytes: 1500
+ daily:
+ files: 2147483647 # effectively unlimited, weekly still applies
+ megabytes: 2147483647
+ weekly:
+ files: 1500
+ megabytes: 15000
+ failures: 150
+ leechers:
+ thresholds:
+ files: 1
+ directories: 1
+ upload:
+ priority: 99
+ strategy: roundrobin
+ slots: 1
+ speed_limit: 100
+ limits:
+ queued:
+ files: 15
+ megabytes: 150
+ daily:
+ files: 30
+ megabytes: 300
+ failures: 10
+ weekly:
+ files: 150
+ megabytes: 1500
+ failures: 30
```
## User Blacklist
@@ -1097,7 +1099,7 @@ If unconfigured, the default timeout for requests is 5 seconds, and each request
#### **YAML**
```yaml
-integration:
+integrations:
webhooks:
my_basic_webhook_using_defaults:
on:
diff --git a/docs/docker.md b/docs/docker.md
index 0d105927..b5fc00ea 100644
--- a/docs/docker.md
+++ b/docs/docker.md
@@ -7,20 +7,28 @@ Next, you'll need to make a few choices:
* The HTTP and/or HTTPS ports for the slskd web UI (defaults 5030 and 5031)
* The port for incoming connections from the Soulseek network (default 50300)
* The directory for the slskd application data
+* How you'll specify the user the container will run as (important for downloaded file permissions!)
+
+Two methods for specifying a user:
+* Docker's built-in functionality; specify `--user` or `-u` in your `docker run` command, or add the `user:` key to your docker compose file
+* The Linuxserver/*arr `PUID`/`PGID` method of passing user and group ID values in environment variables
+
+Docker's built-in functionality is objectively superior; the container starts and runs as the user you specify, it never has root privileges. The `PUID`/`PGID` method starts the container as root, updates the built-in `slskd` user's user and group IDs to match the values you provided, and changes the owner of your mounted app directory to that user.
For most users, a quick start will be all that is needed:
```shell
docker run -d \
- -p <HTTP port>:5030 \
- -p <HTTPS port>:5031 \
- -p <listen port>:50300 \
+ -p 5030:5030 \
+ -p 5031:5031 \
+ -p 50300:50300 \
+ -e SLSKD_REMOTE_CONFIGURATION=true \
-v <path/to/application/data>:/app \
--name slskd \
slskd/slskd:latest
```
-This configuration, however, doesn't include any shared directories.
+This configuration, however, doesn't include any shared directories, and any files that are downloaded will be owned by root.
First, you need to map each share to the container as a volume. Then each local directory within the container needs to be added to the configuration. You may also need to specify the user and group ID that should run the container and own files created by slskd. The default is `root:root`, but Docker will accept any numeric values in the `UID:GID` format, such as `1000:1000` in this example.
diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs
index 814e01a3..e36a5539 100644
--- a/src/slskd/Application.cs
+++ b/src/slskd/Application.cs
@@ -1459,7 +1459,7 @@ namespace slskd
foreach (var (property, fqn, left, right) in diff)
{
- static bool HasAttribute<T>(PropertyInfo property) => property.CustomAttributes.Any(a => a.AttributeType == typeof(T));
+ static bool HasAttribute<T>(PropertyInfo property) => property?.CustomAttributes.Any(a => a.AttributeType == typeof(T)) ?? false;
var requiresRestart = HasAttribute<RequiresRestartAttribute>(property);
var requiresReconnect = HasAttribute<RequiresReconnectAttribute>(property);
diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs
index 88e6d3c8..77db91ef 100644
--- a/src/slskd/Common/CommonExtensions.cs
+++ b/src/slskd/Common/CommonExtensions.cs
@@ -111,20 +111,41 @@ namespace slskd
/// <returns>A list of differences between the two objects.</returns>
public static IEnumerable<(PropertyInfo Property, string FQN, object Left, object Right)> DiffWith(this object left, object right, string parentFqn = null)
{
- if (left?.GetType() != right?.GetType())
+ if (left is null || right is null)
{
- throw new InvalidCastException($"Unable to diff types {left?.GetType()} and {right?.GetType()}");
+ if (left is null == right is null)
+ {
+ return [];
+ }
+
+ return [(null, parentFqn ?? string.Empty, left, right)];
+ }
+
+ if (left.GetType() != right.GetType())
+ {
+ throw new InvalidCastException($"Unable to diff types {left.GetType()} and {right.GetType()}");
}
var differences = new List<(PropertyInfo Property, string FQN, object Left, object Right)>();
- foreach (var prop in left?.GetType().GetProperties())
+ foreach (var prop in left.GetType().GetProperties())
{
var leftVal = prop.GetValue(left);
var rightVal = prop.GetValue(right);
var propType = prop.PropertyType;
var fqn = string.IsNullOrEmpty(parentFqn) ? prop.Name : string.Join(".", parentFqn, prop.Name);
+ if (leftVal is null || rightVal is null)
+ {
+ if (leftVal is null == rightVal is null)
+ {
+ continue;
+ }
+
+ differences.Add((prop, fqn, leftVal, rightVal));
+ continue;
+ }
+
if (propType.IsArray || (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Dictionary<,>)))
{
if (leftVal.ToJson() != rightVal.ToJson())
diff --git a/tests/slskd.Tests.Unit/Common/CommonExtensionsTests.cs b/tests/slskd.Tests.Unit/Common/CommonExtensionsTests.cs
new file mode 100644
index 00000000..d22a3bbe
--- /dev/null
+++ b/tests/slskd.Tests.Unit/Common/CommonExtensionsTests.cs
@@ -0,0 +1,523 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Xunit;
+
+namespace slskd.Tests.Unit.Common;
+
+public class CommonExtensionsTests
+{
+ private class Simple
+ {
+ public int IntProp { get; set; }
+ public string StringProp { get; set; }
+ public bool BoolProp { get; set; }
+ public decimal DecimalProp { get; set; }
+ }
+
+ private class WithNullable
+ {
+ public int? NullableInt { get; set; }
+ public string StringProp { get; set; }
+ }
+
+ private class WithEnum
+ {
+ public DayOfWeek EnumProp { get; set; }
+ }
+
+ private class WithArray
+ {
+ public int[] ArrayProp { get; set; }
+ }
+
+ private class WithDictionary
+ {
+ public Dictionary<string, int> DictProp { get; set; }
+ }
+
+ private class Nested
+ {
+ public string Name { get; set; }
+ public Simple Inner { get; set; }
+ }
+
+ public class DiffWith_NullHandling
+ {
+ [Fact]
+ public void Both_Null_Returns_Empty()
+ {
+ object left = null;
+ object right = null;
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Left_Null_Right_NonNull_Returns_Difference()
+ {
+ object left = null;
+ object right = new Simple();
+
+ var result = left.DiffWith(right);
+
+ var (_, _, leftVal, rightVal) = Assert.Single(result);
+ Assert.Null(leftVal);
+ Assert.NotNull(rightVal);
+ }
+
+ [Fact]
+ public void Left_NonNull_Right_Null_Returns_Difference()
+ {
+ object left = new Simple();
+ object right = null;
+
+ var result = left.DiffWith(right);
+
+ var (_, _, leftVal, rightVal) = Assert.Single(result);
+ Assert.NotNull(leftVal);
+ Assert.Null(rightVal);
+ }
+
+ [Fact]
+ public void Left_Null_Right_NonNull_FQN_Is_ParentFqn()
+ {
+ object left = null;
+ object right = new Simple();
+
+ var result = left.DiffWith(right, "root");
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("root", fqn);
+ }
+
+ [Fact]
+ public void Left_Null_Right_NonNull_FQN_Is_Empty_When_No_ParentFqn()
+ {
+ object left = null;
+ object right = new Simple();
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal(string.Empty, fqn);
+ }
+
+ [Fact]
+ public void Right_Null_Left_NonNull_FQN_Is_Empty_When_No_ParentFqn()
+ {
+ object left = new Simple();
+ object right = null;
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal(string.Empty, fqn);
+ }
+
+ [Fact]
+ public void Mismatched_Types_Throws_InvalidCastException()
+ {
+ object left = new Simple();
+ object right = new WithNullable();
+
+ Assert.Throws<InvalidCastException>(() => left.DiffWith(right));
+ }
+
+ [Fact]
+ public void Left_Null_Right_NonNull_Any_Type_Returns_Difference()
+ {
+ object left = null;
+ object right = 42;
+
+ var result = left.DiffWith(right);
+
+ var (_, _, leftVal, rightVal) = Assert.Single(result);
+ Assert.Null(leftVal);
+ Assert.Equal(42, rightVal);
+ }
+
+ [Fact]
+ public void Right_Null_Left_NonNull_Any_Type_Returns_Difference()
+ {
+ object left = 42;
+ object right = null;
+
+ var result = left.DiffWith(right);
+
+ var (_, _, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal(42, leftVal);
+ Assert.Null(rightVal);
+ }
+ }
+
+ public class DiffWith_PrimitiveProperties
+ {
+ [Fact]
+ public void Identical_Objects_Returns_Empty()
+ {
+ var left = new Simple { IntProp = 1, StringProp = "a", BoolProp = true, DecimalProp = 1.5m };
+ var right = new Simple { IntProp = 1, StringProp = "a", BoolProp = true, DecimalProp = 1.5m };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Different_Int_Returns_Difference()
+ {
+ var left = new Simple { IntProp = 1 };
+ var right = new Simple { IntProp = 2 };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal("IntProp", fqn);
+ Assert.Equal(1, leftVal);
+ Assert.Equal(2, rightVal);
+ }
+
+ [Fact]
+ public void Different_String_Returns_Difference()
+ {
+ var left = new Simple { StringProp = "foo" };
+ var right = new Simple { StringProp = "bar" };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("StringProp", fqn);
+ }
+
+ [Fact]
+ public void Different_Bool_Returns_Difference()
+ {
+ var left = new Simple { BoolProp = true };
+ var right = new Simple { BoolProp = false };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("BoolProp", fqn);
+ }
+
+ [Fact]
+ public void Different_Decimal_Returns_Difference()
+ {
+ var left = new Simple { DecimalProp = 1.1m };
+ var right = new Simple { DecimalProp = 2.2m };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("DecimalProp", fqn);
+ }
+
+ [Fact]
+ public void Multiple_Differences_All_Returned()
+ {
+ var left = new Simple { IntProp = 1, StringProp = "a" };
+ var right = new Simple { IntProp = 2, StringProp = "b" };
+
+ var result = left.DiffWith(right);
+
+ Assert.Equal(2, result.Count());
+ }
+ }
+
+ public class DiffWith_NullableProperties
+ {
+ [Fact]
+ public void Both_Nullable_Null_No_Difference()
+ {
+ var left = new WithNullable { NullableInt = null };
+ var right = new WithNullable { NullableInt = null };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Left_Nullable_Null_Right_HasValue_Returns_Difference()
+ {
+ var left = new WithNullable { NullableInt = null };
+ var right = new WithNullable { NullableInt = 5 };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal("NullableInt", fqn);
+ Assert.Null(leftVal);
+ Assert.Equal(5, rightVal);
+ }
+
+ [Fact]
+ public void Right_Nullable_Null_Left_HasValue_Returns_Difference()
+ {
+ var left = new WithNullable { NullableInt = 5 };
+ var right = new WithNullable { NullableInt = null };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal("NullableInt", fqn);
+ Assert.Equal(5, leftVal);
+ Assert.Null(rightVal);
+ }
+
+ [Fact]
+ public void Both_Nullable_Same_Value_No_Difference()
+ {
+ var left = new WithNullable { NullableInt = 7 };
+ var right = new WithNullable { NullableInt = 7 };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void String_Null_Both_Sides_No_Difference()
+ {
+ var left = new WithNullable { StringProp = null };
+ var right = new WithNullable { StringProp = null };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void String_Null_Left_NonNull_Right_Returns_Difference()
+ {
+ var left = new WithNullable { StringProp = null };
+ var right = new WithNullable { StringProp = "hello" };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal("StringProp", fqn);
+ Assert.Null(leftVal);
+ Assert.Equal("hello", rightVal);
+ }
+ }
+
+ public class DiffWith_EnumProperties
+ {
+ [Fact]
+ public void Same_Enum_No_Difference()
+ {
+ var left = new WithEnum { EnumProp = DayOfWeek.Monday };
+ var right = new WithEnum { EnumProp = DayOfWeek.Monday };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Different_Enum_Returns_Difference()
+ {
+ var left = new WithEnum { EnumProp = DayOfWeek.Monday };
+ var right = new WithEnum { EnumProp = DayOfWeek.Friday };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal("EnumProp", fqn);
+ Assert.Equal(DayOfWeek.Monday, leftVal);
+ Assert.Equal(DayOfWeek.Friday, rightVal);
+ }
+ }
+
+ public class DiffWith_ArrayProperties
+ {
+ [Fact]
+ public void Same_Array_No_Difference()
+ {
+ var left = new WithArray { ArrayProp = [1, 2, 3] };
+ var right = new WithArray { ArrayProp = [1, 2, 3] };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Different_Array_Returns_Difference()
+ {
+ var left = new WithArray { ArrayProp = [1, 2, 3] };
+ var right = new WithArray { ArrayProp = [1, 2, 4] };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("ArrayProp", fqn);
+ }
+
+ [Fact]
+ public void Different_Array_Length_Returns_Difference()
+ {
+ var left = new WithArray { ArrayProp = [1, 2] };
+ var right = new WithArray { ArrayProp = [1, 2, 3] };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("ArrayProp", fqn);
+ }
+
+ [Fact]
+ public void Both_Arrays_Null_No_Difference()
+ {
+ var left = new WithArray { ArrayProp = null };
+ var right = new WithArray { ArrayProp = null };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Left_Array_Null_Right_NonNull_Returns_Difference()
+ {
+ var left = new WithArray { ArrayProp = null };
+ var right = new WithArray { ArrayProp = [1] };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal("ArrayProp", fqn);
+ Assert.Null(leftVal);
+ Assert.NotNull(rightVal);
+ }
+ }
+
+ public class DiffWith_DictionaryProperties
+ {
+ [Fact]
+ public void Same_Dictionary_No_Difference()
+ {
+ var left = new WithDictionary { DictProp = new Dictionary<string, int> { ["a"] = 1 } };
+ var right = new WithDictionary { DictProp = new Dictionary<string, int> { ["a"] = 1 } };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Different_Dictionary_Returns_Difference()
+ {
+ var left = new WithDictionary { DictProp = new Dictionary<string, int> { ["a"] = 1 } };
+ var right = new WithDictionary { DictProp = new Dictionary<string, int> { ["a"] = 2 } };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("DictProp", fqn);
+ }
+
+ [Fact]
+ public void Both_Dictionaries_Null_No_Difference()
+ {
+ var left = new WithDictionary { DictProp = null };
+ var right = new WithDictionary { DictProp = null };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Left_Dictionary_Null_Right_NonNull_Returns_Difference()
+ {
+ var left = new WithDictionary { DictProp = null };
+ var right = new WithDictionary { DictProp = new Dictionary<string, int> { ["a"] = 1 } };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("DictProp", fqn);
+ }
+ }
+
+ public class DiffWith_NestedObjects
+ {
+ [Fact]
+ public void Identical_Nested_Objects_Returns_Empty()
+ {
+ var left = new Nested { Name = "x", Inner = new Simple { IntProp = 1 } };
+ var right = new Nested { Name = "x", Inner = new Simple { IntProp = 1 } };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Different_Nested_Property_FQN_Is_Dotted()
+ {
+ var left = new Nested { Inner = new Simple { IntProp = 1 } };
+ var right = new Nested { Inner = new Simple { IntProp = 9 } };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("Inner.IntProp", fqn);
+ }
+
+ [Fact]
+ public void Both_Nested_Null_No_Difference()
+ {
+ var left = new Nested { Inner = null };
+ var right = new Nested { Inner = null };
+
+ var result = left.DiffWith(right);
+
+ Assert.Empty(result);
+ }
+
+ [Fact]
+ public void Left_Nested_Null_Right_NonNull_Returns_Difference()
+ {
+ var left = new Nested { Inner = null };
+ var right = new Nested { Inner = new Simple() };
+
+ var result = left.DiffWith(right);
+
+ var (_, fqn, leftVal, rightVal) = Assert.Single(result);
+ Assert.Equal("Inner", fqn);
+ Assert.Null(leftVal);
+ Assert.NotNull(rightVal);
+ }
+
+ [Fact]
+ public void ParentFqn_Prepended_To_Nested_FQN()
+ {
+ var left = new Nested { Inner = new Simple { IntProp = 1 } };
+ var right = new Nested { Inner = new Simple { IntProp = 2 } };
+
+ var result = left.DiffWith(right, "root");
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("root.Inner.IntProp", fqn);
+ }
+
+ [Fact]
+ public void Top_Level_Property_FQN_Includes_ParentFqn()
+ {
+ var left = new Simple { IntProp = 1 };
+ var right = new Simple { IntProp = 2 };
+
+ var result = left.DiffWith(right, "root");
+
+ var (_, fqn, _, _) = Assert.Single(result);
+ Assert.Equal("root.IntProp", fqn);
+ }
+ }
+}