Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
340 changes: 340 additions & 0 deletions .claude/skills/desloppify/SKILL.md

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,22 @@ jobs:
echo "value=$VERSION" >> "$GITHUB_OUTPUT"
echo "prerelease=$HAS_SUFFIX" >> "$GITHUB_OUTPUT"

pack:
test:
needs: validate-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'

- name: Test
shell: bash
run: dotnet test Lazybones.Tests/Lazybones.Tests.csproj -c Release --nologo

pack:
needs: test
name: Pack ${{ matrix.rid }}
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -64,13 +78,13 @@ jobs:
framework: net10.0
mainExe: Lazybones
iconPath: icon.icns
extraVpkArgs: --bundleId com.malforge.standup
extraVpkArgs: --bundleId dev.malforge.lazybones
- os: macos-latest
rid: osx-x64
framework: net10.0
mainExe: Lazybones
iconPath: icon.icns
extraVpkArgs: --bundleId com.malforge.standup
extraVpkArgs: --bundleId dev.malforge.lazybones

steps:
- uses: actions/checkout@v6
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ desktop.ini

# Claude Code (per-machine permissions, never commit)
.claude/settings.local.json

# Desloppify (local code-health state)
.desloppify/
42 changes: 42 additions & 0 deletions Lazybones.Tests/Core/Mvvm/RelayCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Windows.Input;
using Lazybones.Core.Mvvm;
using Xunit;

namespace Lazybones.Tests.Core.Mvvm;

public class RelayCommandTests
{
[Fact]
public void Execute_invokes_the_supplied_action()
{
var fired = 0;
ICommand cmd = new RelayCommand(() => fired++);

cmd.Execute(parameter: null);
cmd.Execute(parameter: null);

Assert.Equal(2, fired);
}

[Fact]
public void CanExecute_always_returns_true()
{
ICommand cmd = new RelayCommand(() => { });
Assert.True(cmd.CanExecute(parameter: null));
Assert.True(cmd.CanExecute(parameter: "anything"));
}

[Fact]
public void CanExecuteChanged_subscribe_and_unsubscribe_are_noops()
{
// RelayCommand has no real CanExecute toggling — the event accessors
// are no-ops. This pins the contract so callers know not to expect
// dynamic enable/disable from this implementation.
ICommand cmd = new RelayCommand(() => { });
void Handler(object? s, System.EventArgs e) { }

cmd.CanExecuteChanged += Handler;
cmd.CanExecuteChanged -= Handler;
// No throw, no exception.
}
}
78 changes: 78 additions & 0 deletions Lazybones.Tests/Core/Mvvm/ViewModelBaseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.ComponentModel;
using Lazybones.Core.Mvvm;
using Xunit;

namespace Lazybones.Tests.Core.Mvvm;

public class ViewModelBaseTests
{
private sealed class Probe : ViewModelBase
{
private string _value = "";
public string Value
{
get => _value;
set => SetField(ref _value, value);
}

public void RaiseExternal(string name) => OnPropertyChanged(name);

public int RaiseOverrideCount { get; private set; }
public string? LastRaisedName { get; private set; }

protected override void RaisePropertyChanged(string? propertyName)
{
RaiseOverrideCount++;
LastRaisedName = propertyName;
base.RaisePropertyChanged(propertyName);
}
}

[Fact]
public void SetField_raises_PropertyChanged_when_value_differs()
{
var probe = new Probe();
string? received = null;
probe.PropertyChanged += (_, e) => received = e.PropertyName;

probe.Value = "hello";

Assert.Equal(nameof(Probe.Value), received);
}

[Fact]
public void SetField_skips_when_value_equal()
{
var probe = new Probe { Value = "x" };
var raised = false;
probe.PropertyChanged += (_, _) => raised = true;

probe.Value = "x";

Assert.False(raised);
}

[Fact]
public void OnPropertyChanged_passes_name_to_handler()
{
var probe = new Probe();
string? received = null;
probe.PropertyChanged += (_, e) => received = e.PropertyName;

probe.RaiseExternal("Explicit");

Assert.Equal("Explicit", received);
}

[Fact]
public void RaisePropertyChanged_is_overridable_subclass_sees_every_raise()
{
var probe = new Probe();
probe.Value = "a";
probe.Value = "b";
probe.RaiseExternal("Manual");

Assert.Equal(3, probe.RaiseOverrideCount);
Assert.Equal("Manual", probe.LastRaisedName);
}
}
176 changes: 176 additions & 0 deletions Lazybones.Tests/Core/State/AppStateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using System;
using System.IO;
using Lazybones.Core.State;
using Xunit;

namespace Lazybones.Tests.Core.State;

public class AppStateTests : IDisposable
{
private readonly string _tempDir;
private readonly string _filePath;

public AppStateTests()
{
_tempDir = Path.Combine(Path.GetTempPath(), "Lazybones.Tests.AppState", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(_tempDir);
_filePath = Path.Combine(_tempDir, "state.json");
}

public void Dispose()
{
try { Directory.Delete(_tempDir, recursive: true); } catch { /* best-effort */ }
}

[Fact]
public void LoadFrom_returns_defaults_when_file_missing()
{
var state = AppState.LoadFrom(_filePath);

Assert.True(state.IsRunning);
Assert.False(state.IsStanding);
Assert.Equal(30, state.StandingTimeInMinutes);
Assert.Equal(120, state.SittingTimeInMinutes);
Assert.Equal(3, state.DailyCycleGoal);
Assert.False(state.HasAskedAboutStartup);
Assert.False(state.StartWithWindows);
Assert.Empty(state.UnlockedAchievementIds);
}

[Fact]
public void LoadFrom_returns_defaults_when_json_corrupt()
{
File.WriteAllText(_filePath, "{ not valid json");
var state = AppState.LoadFrom(_filePath);
Assert.True(state.IsRunning); // matches the default ctor
}

[Fact]
public void LoadFrom_returns_defaults_when_file_empty()
{
File.WriteAllText(_filePath, "");
var state = AppState.LoadFrom(_filePath);
Assert.True(state.IsRunning);
}

[Fact]
public void Round_trip_preserves_all_fields()
{
var original = new AppState
{
Left = 100,
Top = 200,
IsRunning = false,
ElapsedTimeInSeconds = 1234,
IsStanding = true,
StandingTimeInMinutes = 25,
SittingTimeInMinutes = 75,
DailyCycleGoal = 5,
HasAskedAboutStartup = true,
StartWithWindows = true,
UnlockedAchievementIds = new() { "first_stand", "quick_draw" }
};

original.SaveTo(_filePath);
var loaded = AppState.LoadFrom(_filePath);

Assert.Equal(original.Left, loaded.Left);
Assert.Equal(original.Top, loaded.Top);
Assert.Equal(original.IsRunning, loaded.IsRunning);
Assert.Equal(original.ElapsedTimeInSeconds, loaded.ElapsedTimeInSeconds);
Assert.Equal(original.IsStanding, loaded.IsStanding);
Assert.Equal(original.StandingTimeInMinutes, loaded.StandingTimeInMinutes);
Assert.Equal(original.SittingTimeInMinutes, loaded.SittingTimeInMinutes);
Assert.Equal(original.DailyCycleGoal, loaded.DailyCycleGoal);
Assert.Equal(original.HasAskedAboutStartup, loaded.HasAskedAboutStartup);
Assert.Equal(original.StartWithWindows, loaded.StartWithWindows);
Assert.Equal(original.UnlockedAchievementIds, loaded.UnlockedAchievementIds);
}

[Fact]
public void SaveTo_creates_missing_directories()
{
var nestedPath = Path.Combine(_tempDir, "nested", "deeper", "state.json");
new AppState { IsStanding = true }.SaveTo(nestedPath);
Assert.True(File.Exists(nestedPath));
}

[Fact]
public void SaveTo_overwrites_existing_file_atomically_without_temp_leftover()
{
new AppState { DailyCycleGoal = 1 }.SaveTo(_filePath);
new AppState { DailyCycleGoal = 9 }.SaveTo(_filePath);

var loaded = AppState.LoadFrom(_filePath);
Assert.Equal(9, loaded.DailyCycleGoal);
Assert.False(File.Exists(_filePath + ".tmp"));
}

[Fact]
public void ResolveDataDir_uses_custom_override_when_set()
{
var custom = Path.Combine(_tempDir, "custom-dir");
var result = AppState.ResolveDataDir(custom, appDataRoot: "/unused");
Assert.Equal(custom, result);
}

[Fact]
public void ResolveDataDir_uses_custom_override_even_when_appdata_is_present()
{
var custom = Path.Combine(_tempDir, "custom");
var appData = Path.Combine(_tempDir, "appdata");
Directory.CreateDirectory(Path.Combine(appData, "Malforge", "Lazybones"));

Assert.Equal(custom, AppState.ResolveDataDir(custom, appData));
}

[Fact]
public void ResolveDataDir_picks_new_dir_when_neither_exists_yet()
{
var appData = Path.Combine(_tempDir, "appdata");
var newDir = Path.Combine(appData, "Malforge", "Lazybones");
var result = AppState.ResolveDataDir(null, appData);
Assert.Equal(newDir, result);
}

[Fact]
public void ResolveDataDir_picks_new_dir_when_new_dir_already_exists_no_migration()
{
var appData = Path.Combine(_tempDir, "appdata");
var newDir = Path.Combine(appData, "Malforge", "Lazybones");
var oldDir = Path.Combine(appData, "Malforge", "StandUp");
Directory.CreateDirectory(newDir);
Directory.CreateDirectory(oldDir);

var result = AppState.ResolveDataDir(null, appData);

Assert.Equal(newDir, result);
Assert.True(Directory.Exists(oldDir), "Old dir must not be touched when new dir already exists.");
}

[Fact]
public void ResolveDataDir_migrates_old_dir_to_new_when_only_old_exists()
{
var appData = Path.Combine(_tempDir, "appdata");
var newDir = Path.Combine(appData, "Malforge", "Lazybones");
var oldDir = Path.Combine(appData, "Malforge", "StandUp");
Directory.CreateDirectory(oldDir);
File.WriteAllText(Path.Combine(oldDir, "history.jsonl"), "marker");

var result = AppState.ResolveDataDir(null, appData);

Assert.Equal(newDir, result);
Assert.True(Directory.Exists(newDir));
Assert.False(Directory.Exists(oldDir));
Assert.Equal("marker", File.ReadAllText(Path.Combine(newDir, "history.jsonl")));
}

[Fact]
public void ResolveDataDir_empty_override_falls_through_to_appdata_resolution()
{
var appData = Path.Combine(_tempDir, "appdata");
var newDir = Path.Combine(appData, "Malforge", "Lazybones");

Assert.Equal(newDir, AppState.ResolveDataDir("", appData));
}
}
Loading