Files
frameledger/tests/FrameLedger.Infrastructure.Tests/Watch/ToolhelpProcessSnapshotSourceTests.cs
poli0981andClaude Opus 5.5 ff949afc6f feat(legal): NOTICE with the GPLv3 section 7 additional terms, the licence header in every source file, and the documents for people who build, contribute or redistribute (D45, beta.12 PR-1) (#253)
- NOTICE: copyright, GPL-3.0-only, and three additional terms of the kinds section 7 permits - (b) preserve the
  notices and the attribution in the program's legal notices, (c) mark a modified version as different and do not
  call it "FrameLedger" alone, (e) no trademark rights in the name. Shipped as licenses\NOTICE.txt; release.yml
  refuses a published tree without it.
- Section 7 wants additional terms named in the source files: every first-party .cs .cpp .h .inl .ps1 .xaml file
  (1,053; src/native/third_party excluded) opens with the SPDX line and a pointer to NOTICE. tools/notice-check.ps1
  is the gate (six self-test cases, both directions; -Fix writes a missing header) and tools/resx-gen.ps1 generates
  the string accessors with the header.
- The native VERSIONINFO LegalCopyright said GPL-3.0-or-later; it now names the real licence.
- CONTRIBUTING.md, FORKING.md, CODE_OF_CONDUCT.md (Contributor Covenant 2.1 by reference), legal/TRADEMARKS.md.
- 12_BUILD gate list, CLAUDE.md layout and conventions.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 22:16:00 +07:00

54 lines
2.3 KiB
C#

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using System.Diagnostics;
using FluentAssertions;
using FrameLedger.Application.Watch;
using FrameLedger.Infrastructure.Io;
using FrameLedger.Infrastructure.Watch;
namespace FrameLedger.Infrastructure.Tests.Watch;
/// <summary>The snapshot against the one process this test can vouch for: itself, with a parent and a start time.</summary>
public sealed class ToolhelpProcessSnapshotSourceTests
{
[Fact]
public void ThisProcessIsInTheSnapshotWithItsNormalisedImagePathAndACreationTime()
{
IReadOnlyList<ProcessSnapshot> snapshot = new ToolhelpProcessSnapshotSource().Take();
snapshot.Should().NotBeEmpty();
ProcessSnapshot me = snapshot.Should().ContainSingle(p => p.Pid == Environment.ProcessId).Subject;
me.ImagePath.Should().Be(ExecutableIdentity.Normalise(Environment.ProcessPath!), "the watcher compares against consent records normalised the same way");
me.ImageName.Should().Be(Path.GetFileName(Environment.ProcessPath), "the name comes from the snapshot itself");
me.StartedAt.Should().NotBeNull();
me.StartedAt!.Value.Should().BeBefore(DateTimeOffset.UtcNow.AddSeconds(1)).And.BeAfter(DateTimeOffset.UtcNow.AddHours(-24));
me.ParentPid.Should().BeGreaterThan(0);
snapshot.Should().NotContain(p => p.Pid <= 4, "Idle and System are never listed");
}
[Fact]
public void AChildThisTestStartsIsADescendantOfThisProcess()
{
using var child = Process.Start(new ProcessStartInfo("cmd.exe", "/c ping -n 3 127.0.0.1 >nul") { UseShellExecute = false, CreateNoWindow = true })!;
try
{
IReadOnlyList<ProcessSnapshot> snapshot = new ToolhelpProcessSnapshotSource().Take();
ProcessTree.IsDescendant(snapshot, Environment.ProcessId, child.Id).Should().BeTrue();
ProcessSnapshot kid = snapshot.Single(p => p.Pid == child.Id);
kid.ParentPid.Should().Be(Environment.ProcessId);
kid.StartedAt.Should().NotBeNull();
}
finally
{
try
{
child.Kill(entireProcessTree: true);
}
catch (InvalidOperationException)
{
}
}
}
}