From 174ac5c7601fa7c34307ea507f2791271dd2c18b Mon Sep 17 00:00:00 2001 From: Dominion Date: Wed, 14 Jun 2023 10:48:59 -0400 Subject: [PATCH] Populate `HeadInclude.dm` and `TailInclude.dm` on instance creation --- .../Components/StaticFiles/Configuration.cs | 33 ++++++++++++++++++- .../Live/Instance/ConfigurationTest.cs | 25 +++++++++++++- .../Live/Instance/InstanceTest.cs | 2 +- .../Live/Instance/RepositoryTest.cs | 1 + .../Live/TestLiveServer.cs | 4 +-- 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index 6e80a0c475..350d701880 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -57,6 +57,16 @@ namespace Tgstation.Server.Host.Components.StaticFiles /// const string CodeModificationsTailFile = "TailInclude.dm"; + /// + /// Default contents of . + /// + static readonly string DefaultHeadInclude = @$"// TGS AUTO GENERATED HeadInclude.dm{Environment.NewLine}// This file will be included BEFORE all code in your .dme IF a replacement .dme does not exist in this directory{Environment.NewLine}// Please note that changes need to be made available if you are hosting an AGPL licensed codebase{Environment.NewLine}// The presence file in its default state does not constitute a code change that needs to be published by licensing standards{Environment.NewLine}"; + + /// + /// Default contents of . + /// + static readonly string DefaultTailInclude = @$"// TGS AUTO GENERATED TailInclude.dm{Environment.NewLine}// This file will be included AFTER all code in your .dme IF a replacement .dme does not exist in this directory{Environment.NewLine}// Please note that changes need to be made available if you are hosting an AGPL licensed codebase{Environment.NewLine}// The presence file in its default state does not constitute a code change that needs to be published by licensing standards{Environment.NewLine}"; + /// /// Map of s to the filename of the event scripts they trigger. /// @@ -648,8 +658,29 @@ namespace Tgstation.Server.Host.Components.StaticFiles await ioManager.WriteAllBytes(staticIgnorePath, Array.Empty(), cancellationToken); } + async Task ValidateCodeModsFolder() + { + if (await ioManager.DirectoryExists(CodeModificationsSubdirectory, cancellationToken)) + return; + + await ioManager.CreateDirectory(CodeModificationsSubdirectory, cancellationToken); + await Task.WhenAll( + ioManager.WriteAllBytes( + ioManager.ConcatPath( + CodeModificationsSubdirectory, + CodeModificationsHeadFile), + Encoding.UTF8.GetBytes(DefaultHeadInclude), + cancellationToken), + ioManager.WriteAllBytes( + ioManager.ConcatPath( + CodeModificationsSubdirectory, + CodeModificationsTailFile), + Encoding.UTF8.GetBytes(DefaultTailInclude), + cancellationToken)); + } + await Task.WhenAll( - ioManager.CreateDirectory(CodeModificationsSubdirectory, cancellationToken), + ValidateCodeModsFolder(), ioManager.CreateDirectory(EventScriptsSubdirectory, cancellationToken), ValidateStaticFolder()); } diff --git a/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs index ac5ce72067..8a7c7013c1 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/ConfigurationTest.cs @@ -119,9 +119,32 @@ namespace Tgstation.Server.Tests.Live.Instance ); } + Task TestPregeneratedFilesExist(CancellationToken cancellationToken) => Task.Factory.StartNew( + _ => + { + var configDir = Path.Combine(instance.Path, "Configuration"); + var baseDir = Path.Combine(configDir, "CodeModifications"); + var path = Path.Combine(baseDir, "HeadInclude.dm"); + var result = File.Exists(path); + Assert.IsTrue(result); + path = Path.Combine(baseDir, "TailInclude.dm"); + result = File.Exists(path); + Assert.IsTrue(result); + var tgsIgnore = Path.Combine(configDir, "GameStaticFiles", ".tgsignore"); + result = File.Exists(tgsIgnore); + Assert.IsTrue(result); + }, + null, + cancellationToken, + TaskCreationOptions.LongRunning, + TaskScheduler.Current); + public Task RunPreWatchdog(CancellationToken cancellationToken) { - return Task.WhenAll(TestUploadDownloadAndDeleteDirectory(cancellationToken), SetupDMApiTests(cancellationToken)); + return Task.WhenAll( + TestUploadDownloadAndDeleteDirectory(cancellationToken), + SetupDMApiTests(cancellationToken), + TestPregeneratedFilesExist(cancellationToken)); } } } diff --git a/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs index 63b8798223..b30533f082 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/InstanceTest.cs @@ -26,7 +26,7 @@ namespace Tgstation.Server.Tests.Live.Instance this.serverPort = serverPort; } - public async Task RunTests(CancellationToken cancellationToken, bool highPrioDD, bool lowPrioDeployment) + public async Task RunTests(bool highPrioDD, bool lowPrioDeployment, CancellationToken cancellationToken) { var byondTest = new ByondTest(instanceClient.Byond, instanceClient.Jobs, fileDownloader, instanceClient.Metadata); var chatTest = new ChatTest(instanceClient.ChatBots, instanceManagerClient, instanceClient.Jobs, instanceClient.Metadata); diff --git a/tests/Tgstation.Server.Tests/Live/Instance/RepositoryTest.cs b/tests/Tgstation.Server.Tests/Live/Instance/RepositoryTest.cs index 05f3b90ec2..8fb677a8e4 100644 --- a/tests/Tgstation.Server.Tests/Live/Instance/RepositoryTest.cs +++ b/tests/Tgstation.Server.Tests/Live/Instance/RepositoryTest.cs @@ -40,6 +40,7 @@ namespace Tgstation.Server.Tests.Live.Instance async Task Rest() { + await Task.Yield(); await ApiAssert.ThrowsException(() => repositoryClient.Read(cancellationToken), ErrorCode.RepoCloning); Assert.IsNotNull(clone); Assert.AreEqual(cloneRequest.Origin, clone.Origin); diff --git a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs index b24538b125..47afd08b2b 100644 --- a/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs +++ b/tests/Tgstation.Server.Tests/Live/TestLiveServer.cs @@ -1052,9 +1052,9 @@ namespace Tgstation.Server.Tests.Live GetInstanceManager(), (ushort)server.Url.Port) .RunTests( - cancellationToken, server.HighPriorityDreamDaemon, - server.LowPriorityDeployments)); + server.LowPriorityDeployments, + cancellationToken)); await Task.WhenAll(rootTest, adminTest, instancesTest, instanceTests, usersTest);