Restore golden-save host tests for slice 6 after later formats stopped loading historic files.
Phase 39 dropped GoldenSaveTests when format 2 saves became unstartable. Recheck restores the missing-field and seed-equals-id assertions against a stamped copy, and records the recheck. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace HSchool.AppHost.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Phase 25 goldens. The folders stay historic (format 2, no country): that shape must not start.
|
||||
/// Load tests stamp today's format, country and owner onto a copy so missing-field defaults and
|
||||
/// seed-equals-id still have a host assertion after later slices raised <c>CanStart</c>.
|
||||
/// </summary>
|
||||
[Collection(AppHostCollection.Name)]
|
||||
public class GoldenSaveTests(AppHostFixture fixture)
|
||||
{
|
||||
[Fact]
|
||||
public async Task HistoricFormat2Golden_LeavesTheSchoolUnstartedAndTheFileUntouched()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var directory = await SchoolApiTests.SavesDirectoryAsync(client);
|
||||
|
||||
try
|
||||
{
|
||||
InstallFolder(directory, "current");
|
||||
var path = Path.Combine(directory, "1.json");
|
||||
var before = File.ReadAllBytes(path);
|
||||
|
||||
using var reload = await client.PostAsync("/api/dev/reload-schools", content: null, TestContext.Current.CancellationToken);
|
||||
reload.EnsureSuccessStatusCode();
|
||||
|
||||
var state = await SchoolApiTests.GetSchoolsAsync(client);
|
||||
Assert.Empty(state.Schools);
|
||||
var broken = Assert.Single(state.Others);
|
||||
Assert.Equal(1, broken.Id);
|
||||
Assert.Equal("Золотая", broken.Name);
|
||||
Assert.Equal(1, broken.Seed);
|
||||
|
||||
using var people = await client.GetAsync(
|
||||
$"/api/schools/{broken.Id}/people?pageSize=1",
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.Equal(HttpStatusCode.NotFound, people.StatusCode);
|
||||
|
||||
Assert.Equal(before, File.ReadAllBytes(path));
|
||||
}
|
||||
finally
|
||||
{
|
||||
DeleteSchoolFiles(directory, 1);
|
||||
using var cleanup = await client.PostAsync("/api/dev/reload-schools", content: null, TestContext.Current.CancellationToken);
|
||||
cleanup.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SaveWithoutNativeLanguage_LoadsWithoutReshuffling()
|
||||
{
|
||||
using var client = fixture.App.CreateHttpClient("server");
|
||||
await SchoolApiTests.ResetAsync(client);
|
||||
var directory = await SchoolApiTests.SavesDirectoryAsync(client);
|
||||
|
||||
try
|
||||
{
|
||||
await InstallRunnableAsync(client, directory, "legacy-no-native", includeNative: false);
|
||||
|
||||
var state = await SchoolApiTests.GetSchoolsAsync(client);
|
||||
var school = Assert.Single(state.Schools);
|
||||
Assert.Equal(1, school.Id);
|
||||
Assert.Equal(1, school.Seed);
|
||||
Assert.Equal("Золотая", school.Name);
|
||||
|
||||
var people = await PeopleAsync(client, school.Id);
|
||||
Assert.Equal(ExpectedNames(), people.Select(row => row.FullName).OrderBy(name => name, StringComparer.Ordinal).ToArray());
|
||||
Assert.Contains(people, person => person.Roles.Contains("student"));
|
||||
Assert.Equal(new DateTime(2012, 3, 31, 6, 0, 0, DateTimeKind.Utc), school.GameTime);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DeleteSchoolFiles(directory, 1);
|
||||
using var cleanup = await client.PostAsync("/api/dev/reload-schools", content: null, TestContext.Current.CancellationToken);
|
||||
cleanup.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task InstallRunnableAsync(
|
||||
HttpClient client,
|
||||
string directory,
|
||||
string folder,
|
||||
bool includeNative)
|
||||
{
|
||||
InstallFolder(directory, folder);
|
||||
StampRunnable(Path.Combine(directory, "1.json"), includeNative);
|
||||
|
||||
using var reload = await client.PostAsync("/api/dev/reload-schools", content: null, TestContext.Current.CancellationToken);
|
||||
reload.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
private static void InstallFolder(string directory, string folder)
|
||||
{
|
||||
var source = Path.Combine(AppContext.BaseDirectory, "golden", folder);
|
||||
foreach (var file in Directory.EnumerateFiles(source))
|
||||
{
|
||||
File.Copy(file, Path.Combine(directory, Path.GetFileName(file)), overwrite: true);
|
||||
}
|
||||
}
|
||||
|
||||
private static void StampRunnable(string path, bool includeNative)
|
||||
{
|
||||
var node = JsonNode.Parse(File.ReadAllText(path))
|
||||
?? throw new InvalidOperationException($"Save {path} parsed to nothing.");
|
||||
node["format"] = 3;
|
||||
node["countryId"] = "Russia";
|
||||
node["climatePresetId"] = "TemperateContinental";
|
||||
node["owner"] = SchoolApiTests.TestUserName;
|
||||
node.AsObject().Remove("nameSetId");
|
||||
if (includeNative)
|
||||
{
|
||||
node["nativeLanguage"] = "RussianLanguage";
|
||||
}
|
||||
else
|
||||
{
|
||||
node.AsObject().Remove("nativeLanguage");
|
||||
}
|
||||
|
||||
File.WriteAllText(path, node.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
|
||||
}
|
||||
|
||||
private static void DeleteSchoolFiles(string directory, int id)
|
||||
{
|
||||
foreach (var name in new[] { $"{id}.json", $"{id}.people.json", $"{id}.timetable.json" })
|
||||
{
|
||||
var path = Path.Combine(directory, name);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<IReadOnlyList<PersonRow>> PeopleAsync(HttpClient client, int schoolId)
|
||||
{
|
||||
var page = await client.GetFromJsonAsync<PeoplePage>(
|
||||
$"/api/schools/{schoolId}/people?pageSize=100",
|
||||
TestContext.Current.CancellationToken);
|
||||
Assert.NotNull(page);
|
||||
return page.People
|
||||
.OrderBy(row => row.Id, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static string[] ExpectedNames()
|
||||
{
|
||||
var json = File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "golden", "current", "1.people.json"));
|
||||
using var document = JsonDocument.Parse(json);
|
||||
return document.RootElement.GetProperty("people")
|
||||
.EnumerateArray()
|
||||
.Select(person =>
|
||||
{
|
||||
var name = person.GetProperty("name");
|
||||
var surname = name.GetProperty("surname").GetString() ?? "";
|
||||
var given = name.GetProperty("given").GetString() ?? "";
|
||||
var patronymic = name.GetProperty("patronymic").GetString() ?? "";
|
||||
return string.Join(' ', new[] { surname, given, patronymic }.Where(part => part.Length > 0));
|
||||
})
|
||||
.OrderBy(full => full, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private sealed record PeoplePage(IReadOnlyList<PersonRow> People);
|
||||
|
||||
private sealed record PersonRow(string Id, string FullName, IReadOnlyList<string> Roles);
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
# Golden saves
|
||||
|
||||
`current/` is a school file of today's format. `legacy-no-native/` is the same school without
|
||||
`nativeLanguage`, so a missing field still has to mean "first language of the name set" rather
|
||||
than a new roll.
|
||||
`current/` and `legacy-no-native/` are historic format-2 school files (no `countryId`). They
|
||||
must not start as-is: later slices made `CanStart` require today's format and a country.
|
||||
`legacy-no-native/` is the same school without `nativeLanguage`, so a missing field still has
|
||||
to mean "first language of the name set" rather than a new roll — the host test stamps format,
|
||||
country and owner onto a copy rather than rewriting this folder.
|
||||
|
||||
These files live forever: a new save field must load `current/` and must not reshuffle
|
||||
`legacy-no-native/`. A real format change adds a new folder; it does not rewrite the old one.
|
||||
These files live forever: a real format change does not rewrite them. Load tests that need a
|
||||
running school copy the folder and stamp current fields in the test.
|
||||
|
||||
Phase 31 rewrote `current/1.people.json` because people are born dressed (`items` on each
|
||||
person, plus `Hauling`). `legacy-no-native/` is left as it was: no inventory, so load still
|
||||
@@ -14,6 +16,9 @@ has to dress them and must not reshuffle names.
|
||||
Phase 32 rewrote `current/1.people.json` again: `Warmth` plus `HeatLoving` / `ColdLoving` in
|
||||
the trait pool. `legacy-no-native/` stays historic.
|
||||
|
||||
`current/1.people.json` still names the abstract `Underwear` parent (later split into
|
||||
Briefs/Boxers/Panties). Stamping today's format onto that file does not start the school.
|
||||
|
||||
Regenerate after an intentional roster change (same commit):
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user