Files
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

73 lines
3.4 KiB
C#

// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
using FluentAssertions;
using FrameLedger.Application.Persistence;
using FrameLedger.Application.Watch;
using FrameLedger.Domain.Consent;
namespace FrameLedger.Application.Tests.Watch;
/// <summary>The 1 Hz diff: exact path, unambiguous file-name fallback, unreadable matches nothing, gone is reported once.</summary>
public sealed class ProcessWatcherTests
{
private static GameRow Game(long id, string path) => new()
{
Id = id,
Name = Path.GetFileNameWithoutExtension(path),
Fingerprint = new ExecutableFingerprint { ExePath = path, SizeBytes = 1, MtimeUnixMs = 1 },
HookEnabled = false,
HookCrashCount = 0,
AddedAt = DateTimeOffset.UnixEpoch,
UpdatedAt = DateTimeOffset.UnixEpoch,
};
private static ProcessSnapshot Proc(int pid, string? path, int ppid = 1) =>
new(pid, ppid, path is null ? "unknown.exe" : Path.GetFileName(path), path, DateTimeOffset.UnixEpoch);
[Fact]
public void AnExactPathMatchAppearsOnceAndIsGoneOnce()
{
var watcher = new ProcessWatcher();
GameRow game = Game(1, @"C:\Games\Title\game.exe");
List<GameRow> watchlist = [game];
IReadOnlyList<WatchEvent> first = watcher.Poll([Proc(100, @"c:\games\title\GAME.EXE"), Proc(101, @"C:\Windows\explorer.exe")], watchlist);
IReadOnlyList<WatchEvent> second = watcher.Poll([Proc(100, @"c:\games\title\GAME.EXE")], watchlist);
IReadOnlyList<WatchEvent> third = watcher.Poll([], watchlist);
IReadOnlyList<WatchEvent> fourth = watcher.Poll([], watchlist);
TrackedProcessAppeared appeared = first.Should().ContainSingle().Subject.Should().BeOfType<TrackedProcessAppeared>().Subject;
appeared.Pid.Should().Be(100);
appeared.Game.Should().BeSameAs(game);
appeared.StalePath.Should().BeFalse("the paths differ only in case, which NTFS does not");
second.Should().BeEmpty("already reported");
third.Should().ContainSingle().Which.Should().BeOfType<TrackedProcessGone>().Which.Pid.Should().Be(100);
fourth.Should().BeEmpty();
}
[Fact]
public void AFileNameMatchIsStaleOnlyWhenExactlyOneRowCarriesThatName()
{
var watcher = new ProcessWatcher();
GameRow moved = Game(1, @"D:\Old\game.exe");
IReadOnlyList<WatchEvent> single = watcher.Poll([Proc(7, @"E:\New\game.exe")], [moved]);
TrackedProcessAppeared appeared = single.Should().ContainSingle().Subject.Should().BeOfType<TrackedProcessAppeared>().Subject;
appeared.StalePath.Should().BeTrue();
appeared.ImagePath.Should().Be(@"E:\New\game.exe", "the session is keyed on the path the process runs from");
var ambiguous = new ProcessWatcher();
IReadOnlyList<WatchEvent> none = ambiguous.Poll([Proc(8, @"E:\New\game.exe")], [moved, Game(2, @"F:\Other\game.exe")]);
none.Should().BeEmpty("two rows share the file name and guessing which one moved lands a session on the wrong row");
}
[Fact]
public void AProcessThatCouldNotBeOpenedMatchesNothingEvenByName()
{
var watcher = new ProcessWatcher();
IReadOnlyList<WatchEvent> events = watcher.Poll([Proc(9, null)], [Game(1, @"C:\Games\unknown.exe")]);
events.Should().BeEmpty("an image path we could not read is not an identity");
}
}