AetherDb economy: Author takes the scratch root; TheTrialCopyIsRemoved audits its own, not the shared temp folder
The test counted aetherdb-economy-* directories in the machine's temp folder, which every parallel test running the command also writes to. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
85f1a933d4
commit
ee49f95843
2 changed files with 17 additions and 7 deletions
|
|
@ -178,10 +178,19 @@ public sealed class EconomyCommandTests
|
|||
public void TheTrialCopyIsRemoved()
|
||||
{
|
||||
using var f = EconomyFixture.Healthy();
|
||||
var before = Directory.GetDirectories(Path.GetTempPath(), "aetherdb-economy-*").Length;
|
||||
Author(f, false, out _, a => Good(f, a, "coal"));
|
||||
Author(f, true, out _, a => Good(f, a, "tar", lore: ""));
|
||||
Assert.Equal(before, Directory.GetDirectories(Path.GetTempPath(), "aetherdb-economy-*").Length);
|
||||
// A private scratch root: the temp folder is shared with every parallel test that runs the command, so counting it races.
|
||||
var scratchRoot = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "aetherdb-economy-audit-" + Guid.NewGuid().ToString("N"))).FullName;
|
||||
try
|
||||
{
|
||||
foreach (var apply in new[] { false, true })
|
||||
{
|
||||
Flush(f);
|
||||
var batch = new Lambda(a => Good(f, a, apply ? "tar" : "coal", lore: apply ? "" : "a good"));
|
||||
EconomyCommand.Author(f.CatalogPath, new EconomyBatch[] { batch }, apply, new StringWriter(), TestCatalog.Registry(), scratchRoot);
|
||||
}
|
||||
Assert.Empty(Directory.GetFileSystemEntries(scratchRoot));
|
||||
}
|
||||
finally { Directory.Delete(scratchRoot, true); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -107,15 +107,16 @@ public static class EconomyCommand
|
|||
// atomically, so a refusal leaves Aetheria.cc byte-identical. A batch is compiled code and is reviewed as code: it is trusted not
|
||||
// to touch the real file, and the command refuses by name if the file changed under it. Added, changed and unchanged are read by
|
||||
// comparing the original and the copy on disk. A shape fault the batches introduce (present after, absent before, by rule and
|
||||
// record) refuses; faults the catalog already held print and do not.
|
||||
public static int Author(string catalogPath, IReadOnlyList<EconomyBatch> batches, bool apply, TextWriter output, CultDocumentRegistry registry = null)
|
||||
// record) refuses; faults the catalog already held print and do not. The trial copy lives under scratchRoot (the temp folder unless a caller
|
||||
// that audits it names a private one).
|
||||
public static int Author(string catalogPath, IReadOnlyList<EconomyBatch> batches, bool apply, TextWriter output, CultDocumentRegistry registry = null, string scratchRoot = null)
|
||||
{
|
||||
if (apply && new FileInfo(catalogPath).IsReadOnly)
|
||||
{
|
||||
output.WriteLine("The batches are refused: Aetheria.cc is read-only. Clear the read-only flag, or check it out, and run again. The catalog is unchanged.");
|
||||
return 1;
|
||||
}
|
||||
var scratch = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "aetherdb-economy-" + Guid.NewGuid().ToString("N"))).FullName;
|
||||
var scratch = Directory.CreateDirectory(Path.Combine(scratchRoot ?? Path.GetTempPath(), "aetherdb-economy-" + Guid.NewGuid().ToString("N"))).FullName;
|
||||
try
|
||||
{
|
||||
var trial = Path.Combine(scratch, "Aetheria.cc");
|
||||
|
|
|
|||
Loading…
Reference in a new issue