fix(s7): Counter raw-word note + reject Writable Timer/Counter + Timer time-base tests (bundle review)

This commit is contained in:
Joseph Doherty
2026-06-17 06:18:48 -04:00
parent 8cfb8e920e
commit 11e8e4302d
3 changed files with 94 additions and 4 deletions
@@ -176,4 +176,53 @@ public sealed class S7DriverScaffoldTests
drv.GetHealth().State.ShouldBe(DriverState.Faulted);
}
// ── Phase 4d bundle-review fix — Writable Timer/Counter guard ───────────────────────
//
// A Timer/Counter tag declared Writable=true must be rejected at init: without this guard
// the node is discovered as Operate-writable but every write returns BadNotSupported
// (EncodeScalarBlock throws). The guard fires before plc.OpenAsync, so the reserved-for-
// documentation host never receives traffic.
/// <summary>Verifies that a Timer tag declared Writable=true is rejected at init with a Writable message.</summary>
[Fact]
public async Task Initialize_rejects_Timer_tag_declared_Writable()
{
var opts = new S7DriverOptions
{
Host = "192.0.2.1",
Timeout = TimeSpan.FromMilliseconds(250),
Tags = [new S7TagDefinition("Timer5", "T5", S7DataType.Float64, Writable: true)],
};
using var drv = new S7Driver(opts, "s7-timer-writable");
var ex = await Should.ThrowAsync<NotSupportedException>(async () =>
await drv.InitializeAsync("{}", TestContext.Current.CancellationToken));
ex.Message.ShouldContain("Timer5");
ex.Message.ShouldContain("Writable", Case.Insensitive);
ex.Message.ShouldContain("read-only", Case.Insensitive);
drv.GetHealth().State.ShouldBe(DriverState.Faulted);
}
/// <summary>Verifies that a Counter tag declared Writable=true is rejected at init with a Writable message.</summary>
[Fact]
public async Task Initialize_rejects_Counter_tag_declared_Writable()
{
var opts = new S7DriverOptions
{
Host = "192.0.2.1",
Timeout = TimeSpan.FromMilliseconds(250),
Tags = [new S7TagDefinition("Counter3", "C3", S7DataType.Int32, Writable: true)],
};
using var drv = new S7Driver(opts, "s7-counter-writable");
var ex = await Should.ThrowAsync<NotSupportedException>(async () =>
await drv.InitializeAsync("{}", TestContext.Current.CancellationToken));
ex.Message.ShouldContain("Counter3");
ex.Message.ShouldContain("Writable", Case.Insensitive);
ex.Message.ShouldContain("read-only", Case.Insensitive);
drv.GetHealth().State.ShouldBe(DriverState.Faulted);
}
}