feat(launcher): Campaign LA LA3 — AcDream.Launcher.Core profile store, composer, supervisor, status tailer
New AcDream.Launcher.Core (BCL-only, ProjectReference: AcDream.Platform
ONLY) plus tests/AcDream.Launcher.Core.Tests, both registered in
AcDream.slnx. This is the file-contract orchestrator core the Avalonia
launcher (LA4) will bind to — the game solution (Core/Runtime/App/
Headless) stays entirely out of this dependency graph, so the launcher
can never accidentally grow a game-protocol coupling.
- Profiles/: LauncherProfileStore owns launcher-profiles.json (spec §5
schema: version 1, servers[]/accounts[]/characters[]), strict
camelCase System.Text.Json (UnmappedMemberHandling.Disallow), typed
CRUD (add/edit/remove server; add/edit/remove account; edit character
settings), and MergeRoster (fold a reported roster into an account's
characters[] while preserving user-owned launchMode/plugins/
loginCommands, adding new rows with default guiSelect, and retaining
rows absent from the roster — they may be pending-delete). 0600 on
Linux via File.SetUnixFileMode after save.
- Launching/: SessionConfigComposer builds the pinned session-config
contract (Headless K1 shape + plugins/loginCommands/
loginCommandDelayMs/statusFile) from a profile character + install
record — character selector omitted entirely for guiSelect, policy
{id:"idle"} only for headless, credential always standardInput/
session. Passwords never enter this document (proven by a dedicated
test). LauncherProcessSupervisor spawns a host, feeds the password to
stdin then closes it, and exposes Starting/Running/Exited lifecycle;
Stop calls CloseMainWindow falling back to Kill after a timeout, both
reachable through an injectable ILauncherChildProcess/factory seam so
the state machine is unit-testable without real OS process timing.
- Status/: StatusEventParser decodes the v1 status.jsonl vocabulary
(started/connected/characterList/enteredWorld/pluginLoaded/
pluginFailed/disconnected/exited); an unrecognized "e" or a malformed
line degrades to a typed Unknown event rather than throwing.
StatusFileTailer incrementally reads new lines, tolerating a
not-yet-existing file and a partial trailing line (only advances its
read position past confirmed '\n' boundaries; a truncated tail is
simply re-read next poll, never parsed early).
- Integrity/: streaming SHA-256 + hex verify for later pak/download
checks (LA9/LA10).
Tests: 71 passed (profile CRUD + roster-merge matrix + strict-schema
rejection; composer golden-shape tests for gui/guiSelect/headless +
password-absence; supervisor tests against both an injected fake child
(state-machine determinism) and a real spawned `dotnet --version`
child (genuine cross-platform stdin/exit-code proof); tailer tests
incl. partial-line and not-yet-existing-file; SHA-256 tests). Verified
green on Windows (Release) and native WSL/Linux (Release) — the Linux
0600 test executes its real assertion body under WSL rather than
early-returning.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
cb6502c8a5
commit
37d74e4402
31 changed files with 3131 additions and 0 deletions
167
src/AcDream.Launcher.Core/Launching/SessionConfigComposer.cs
Normal file
167
src/AcDream.Launcher.Core/Launching/SessionConfigComposer.cs
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using AcDream.Launcher.Core.Profiles;
|
||||
using AcDream.Platform;
|
||||
|
||||
namespace AcDream.Launcher.Core.Launching;
|
||||
|
||||
/// <summary>The composed session-config document plus the two per-launch
|
||||
/// paths derived from the session id, per Campaign LA spec §6.</summary>
|
||||
public sealed record ComposedSessionConfig(
|
||||
string SessionId,
|
||||
string ConfigFilePath,
|
||||
string StatusFilePath,
|
||||
SessionConfigDocument Document);
|
||||
|
||||
/// <summary>
|
||||
/// Builds the per-launch <see cref="SessionConfigDocument"/> from a
|
||||
/// profile character + install record (Campaign LA spec §6). Passwords
|
||||
/// NEVER appear in the composed document — the credential is always the
|
||||
/// <c>standardInput</c> provider; the launcher feeds the password to the
|
||||
/// child process's stdin separately (<see cref="LauncherProcessSupervisor"/>).
|
||||
/// </summary>
|
||||
public static class SessionConfigComposer
|
||||
{
|
||||
internal static readonly JsonSerializerOptions SerializerOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Builds the document and the paths it would be written to under
|
||||
/// <c><CacheDirectory>/launcher/sessions/<sessionId>/</c>,
|
||||
/// without touching disk. <paramref name="sessionId"/> is caller-
|
||||
/// supplied so composition stays a pure function of its inputs
|
||||
/// (golden-file tests pass a fixed id).
|
||||
/// </summary>
|
||||
public static ComposedSessionConfig Compose(
|
||||
ServerProfile server,
|
||||
AccountProfile account,
|
||||
CharacterProfile character,
|
||||
LauncherInstallRecord install,
|
||||
ApplicationPathSet paths,
|
||||
string sessionId,
|
||||
int? loginCommandDelayMs = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(server);
|
||||
ArgumentNullException.ThrowIfNull(account);
|
||||
ArgumentNullException.ThrowIfNull(character);
|
||||
ArgumentNullException.ThrowIfNull(install);
|
||||
ArgumentNullException.ThrowIfNull(paths);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(sessionId);
|
||||
|
||||
string sessionDirectory = Path.Combine(
|
||||
paths.CacheDirectory,
|
||||
"launcher",
|
||||
"sessions",
|
||||
sessionId);
|
||||
string configFilePath = Path.Combine(sessionDirectory, "session.json");
|
||||
string statusFilePath = Path.Combine(sessionDirectory, "status.jsonl");
|
||||
|
||||
SessionCharacterSelector? selector = character.LaunchMode == LaunchMode.GuiSelect
|
||||
? null
|
||||
: BuildSelector(character);
|
||||
|
||||
SessionPolicyDescriptor? policy = character.LaunchMode == LaunchMode.Headless
|
||||
? new SessionPolicyDescriptor()
|
||||
: null;
|
||||
|
||||
var descriptor = new SessionDescriptor
|
||||
{
|
||||
Id = sessionId,
|
||||
Endpoint = new SessionEndpointDescriptor
|
||||
{
|
||||
Host = server.Host,
|
||||
Port = server.Port,
|
||||
},
|
||||
Account = account.Account,
|
||||
Character = selector,
|
||||
Policy = policy,
|
||||
Credential = new SessionCredentialDescriptor(),
|
||||
Plugins = character.Plugins.Count > 0 ? [.. character.Plugins] : null,
|
||||
LoginCommands = character.LoginCommands.Count > 0
|
||||
? [.. character.LoginCommands]
|
||||
: null,
|
||||
LoginCommandDelayMs = loginCommandDelayMs,
|
||||
StatusFile = statusFilePath,
|
||||
};
|
||||
|
||||
var document = new SessionConfigDocument
|
||||
{
|
||||
Process = new SessionProcessSettings
|
||||
{
|
||||
Paths = new SessionPathOverrides(),
|
||||
Content = new SessionContentDescriptor
|
||||
{
|
||||
DatDirectory = install.DatDirectory,
|
||||
PreparedAssetPath = install.PreparedAssetPath,
|
||||
},
|
||||
},
|
||||
Sessions = [descriptor],
|
||||
};
|
||||
|
||||
return new ComposedSessionConfig(
|
||||
sessionId,
|
||||
configFilePath,
|
||||
statusFilePath,
|
||||
document);
|
||||
}
|
||||
|
||||
/// <summary>Composes and writes <c>session.json</c> to
|
||||
/// <see cref="ComposedSessionConfig.ConfigFilePath"/>, creating the
|
||||
/// per-session directory. The status file itself is created by the
|
||||
/// launched host, not the launcher.</summary>
|
||||
public static ComposedSessionConfig ComposeAndWrite(
|
||||
ServerProfile server,
|
||||
AccountProfile account,
|
||||
CharacterProfile character,
|
||||
LauncherInstallRecord install,
|
||||
ApplicationPathSet paths,
|
||||
string sessionId,
|
||||
int? loginCommandDelayMs = null)
|
||||
{
|
||||
ComposedSessionConfig composed = Compose(
|
||||
server,
|
||||
account,
|
||||
character,
|
||||
install,
|
||||
paths,
|
||||
sessionId,
|
||||
loginCommandDelayMs);
|
||||
|
||||
string? directory = Path.GetDirectoryName(composed.ConfigFilePath);
|
||||
if (!string.IsNullOrEmpty(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
using FileStream stream = File.Create(composed.ConfigFilePath);
|
||||
JsonSerializer.Serialize(stream, composed.Document, SerializerOptions);
|
||||
|
||||
return composed;
|
||||
}
|
||||
|
||||
/// <summary>Serializes the composed document exactly as
|
||||
/// <see cref="ComposeAndWrite"/> would write it — used by golden-file
|
||||
/// tests that assert on the JSON text without touching disk.</summary>
|
||||
public static string Serialize(SessionConfigDocument document) =>
|
||||
JsonSerializer.Serialize(document, SerializerOptions);
|
||||
|
||||
private static SessionCharacterSelector BuildSelector(CharacterProfile character)
|
||||
{
|
||||
if (CharacterIdFormat.TryParse(character.Id, out uint id))
|
||||
{
|
||||
return new SessionCharacterSelector { Id = id };
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(character.Name))
|
||||
{
|
||||
return new SessionCharacterSelector { Name = character.Name };
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
"Character has neither a usable id nor a name to select by.");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue