Reorganise by feature, rename to Novelly, add Aspire and a pre-push hook

The layered split into Domain/Application/Infrastructure/Api was forcing
organisation by layer: adding one capability meant touching four projects and
four folders that each held a slice of it. Those four projects are now one
feature-organised Novelly.Api, where each folder — Projects, Characters,
Chapters, Beats, Scenes, Tags, Agent — holds its entity, DTOs, service and
endpoints together. Common/ holds what genuinely crosses features (the patch
semantics, the two exception types, DraftStatus) and Data/ holds the DbContext
and migrations.

Six .NET projects become five: the three layer projects are gone, and
Novelly.AppHost and Novelly.ServiceDefaults are new.

- Namespaces move from NovelSoftware.* to Novelly.*, including the entity type
  names recorded in the EF model snapshots. The migration ids are untouched, so
  an existing novel.db still migrates cleanly — verified against a fresh file.
- Aspire orchestration mirrors the mic-check setup: the AppHost starts the API
  on :5080 and the Vite dev server on :5173, and the API picks up OpenTelemetry,
  health checks and service discovery from ServiceDefaults. /health and /alive
  now answer in development.
- A Husky pre-push hook runs scripts/ci/prepush.sh: build, test, then a web
  build. The scripts are plain bash so CI can run the same steps.
- The MCP server's env var is now NOVELLY_API_URL.

Verified beyond the build: 44 tests pass, the web client builds, the API was
exercised over curl (project/chapter/beat/tag round trip, tag cross-reference,
503 on the agent without a key while conversation listing still returns 200),
the MCP server was driven over stdio JSON-RPC (26 tools, errors still surface
the API's own message rather than being flattened), and the AppHost was run to
confirm both resources come up and Vite proxies /api through to the API.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S56bfZMGe1hnhpWP4CjjNw
This commit is contained in:
James Wampler
2026-08-06 12:11:20 -07:00
co-authored by Claude Opus 5
parent 30e0c6926e
commit 725758ccd9
120 changed files with 811 additions and 421 deletions
+156
View File
@@ -0,0 +1,156 @@
using Microsoft.EntityFrameworkCore;
using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Common;
using Novelly.Api.Projects;
using Novelly.Api.Scenes;
namespace Novelly.Api.Tests;
[TestFixture]
public class ProjectDataTests : ServiceTestFixture
{
private async Task<Guid> NewProjectAsync() =>
(await Projects.CreateAsync(new CreateProjectRequest("The Salt Road"))).Id;
[Test]
public async Task Updating_leaves_omitted_fields_alone_and_clears_on_empty_string()
{
var id = (await Projects.CreateAsync(
new CreateProjectRequest("Draft", Genre: "Fantasy", Logline: "A cartographer goes to sea."))).Id;
var afterPartialUpdate = await Projects.UpdateAsync(id, new UpdateProjectRequest(Title: "The Salt Road"));
Assert.Multiple(() =>
{
Assert.That(afterPartialUpdate.Title, Is.EqualTo("The Salt Road"));
Assert.That(afterPartialUpdate.Genre, Is.EqualTo("Fantasy"));
Assert.That(afterPartialUpdate.Logline, Is.EqualTo("A cartographer goes to sea."));
});
var afterClear = await Projects.UpdateAsync(id, new UpdateProjectRequest(Genre: ""));
Assert.Multiple(() =>
{
Assert.That(afterClear.Genre, Is.Null);
Assert.That(afterClear.Logline, Is.EqualTo("A cartographer goes to sea."));
});
}
[Test]
public async Task Chapters_are_numbered_in_sequence_when_no_number_is_given()
{
var projectId = await NewProjectAsync();
var first = await Chapters.CreateAsync(projectId, new CreateChapterRequest("Landfall"));
var second = await Chapters.CreateAsync(projectId, new CreateChapterRequest("The Harbour"));
Assert.Multiple(() =>
{
Assert.That(first.Number, Is.EqualTo(1));
Assert.That(second.Number, Is.EqualTo(2));
});
}
[Test]
public async Task Word_count_is_recomputed_whenever_prose_changes()
{
var projectId = await NewProjectAsync();
var chapter = await Chapters.CreateAsync(projectId, new CreateChapterRequest("Landfall"));
var scene = await Scenes.CreateAsync(chapter.Id, new CreateSceneRequest(
"The dock at dawn", Prose: "Five words go right here"));
Assert.That(scene.WordCount, Is.EqualTo(5));
var rewritten = await Scenes.UpdateAsync(scene.Id, new UpdateSceneRequest(
Prose: "Now\nthere are seven words in total"));
Assert.That(rewritten.WordCount, Is.EqualTo(7));
var cleared = await Scenes.UpdateAsync(scene.Id, new UpdateSceneRequest(Prose: ""));
Assert.Multiple(() =>
{
Assert.That(cleared.Prose, Is.Null);
Assert.That(cleared.WordCount, Is.EqualTo(0));
});
}
[Test]
public async Task Scene_updates_that_omit_prose_leave_the_draft_untouched()
{
var projectId = await NewProjectAsync();
var chapter = await Chapters.CreateAsync(projectId, new CreateChapterRequest("Landfall"));
var scene = await Scenes.CreateAsync(chapter.Id, new CreateSceneRequest(
"The dock at dawn", Prose: "The tide came in slow."));
var updated = await Scenes.UpdateAsync(scene.Id, new UpdateSceneRequest(Status: DraftStatus.Revised));
Assert.Multiple(() =>
{
Assert.That(updated.Prose, Is.EqualTo("The tide came in slow."));
Assert.That(updated.WordCount, Is.EqualTo(5));
Assert.That(updated.Status, Is.EqualTo(DraftStatus.Revised));
});
}
[Test]
public async Task Deleting_a_project_takes_its_characters_chapters_and_scenes()
{
var projectId = await NewProjectAsync();
await Characters.CreateAsync(projectId, new CreateCharacterRequest("Ines"));
var chapter = await Chapters.CreateAsync(projectId, new CreateChapterRequest("Landfall"));
await Scenes.CreateAsync(chapter.Id, new CreateSceneRequest("The dock at dawn"));
await Projects.DeleteAsync(projectId);
using var verification = Db.CreateContext();
Assert.Multiple(async () =>
{
Assert.That(await verification.Projects.CountAsync(), Is.EqualTo(0));
Assert.That(await verification.Characters.CountAsync(), Is.EqualTo(0));
Assert.That(await verification.Chapters.CountAsync(), Is.EqualTo(0));
Assert.That(await verification.Scenes.CountAsync(), Is.EqualTo(0));
});
}
[Test]
public async Task Relating_characters_across_projects_is_refused()
{
var firstProject = await NewProjectAsync();
var secondProject = (await Projects.CreateAsync(new CreateProjectRequest("Other Book"))).Id;
var ines = await Characters.CreateAsync(firstProject, new CreateCharacterRequest("Ines"));
var stranger = await Characters.CreateAsync(secondProject, new CreateCharacterRequest("Stranger"));
Assert.That(
async () => await Characters.AddRelationshipAsync(
ines.Id, new CreateRelationshipRequest(stranger.Id, "sister")),
Throws.TypeOf<InvalidOperationException>().With.Message.Contains("same project"));
}
[Test]
public async Task Relationships_resolve_the_other_character_by_name()
{
var projectId = await NewProjectAsync();
var ines = await Characters.CreateAsync(projectId, new CreateCharacterRequest("Ines"));
var mara = await Characters.CreateAsync(projectId, new CreateCharacterRequest("Mara"));
var updated = await Characters.AddRelationshipAsync(
ines.Id, new CreateRelationshipRequest(mara.Id, "sister", "Estranged since the fire."));
Assert.Multiple(() =>
{
Assert.That(updated.Relationships, Has.Count.EqualTo(1));
Assert.That(updated.Relationships[0].RelatedCharacterName, Is.EqualTo("Mara"));
});
}
[Test]
public void Reading_a_missing_project_reports_not_found() =>
Assert.That(
async () => await Projects.GetAsync(Guid.NewGuid()),
Throws.TypeOf<NotFoundException>());
}