Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression tests and DMAPI fix #1675

Merged
merged 8 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<TgsCommonLibraryVersion>6.0.1</TgsCommonLibraryVersion>
<TgsApiLibraryVersion>11.1.2</TgsApiLibraryVersion>
<TgsClientVersion>12.1.2</TgsClientVersion>
<TgsDmapiVersion>6.5.3</TgsDmapiVersion>
<TgsInteropVersion>5.6.1</TgsInteropVersion>
<TgsDmapiVersion>6.5.4</TgsDmapiVersion>
<TgsInteropVersion>5.6.2</TgsInteropVersion>
<TgsHostWatchdogVersion>1.4.0</TgsHostWatchdogVersion>
<TgsContainerScriptVersion>1.2.1</TgsContainerScriptVersion>
<TgsMigratorVersion>1.0.2</TgsMigratorVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/DMAPI/tgs.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tgstation-server DMAPI

#define TGS_DMAPI_VERSION "6.5.3"
#define TGS_DMAPI_VERSION "6.5.4"

// All functions and datums outside this document are subject to change with any version and should not be relied on.

Expand Down
2 changes: 1 addition & 1 deletion src/DMAPI/tgs/core/core.dm
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@
/world/TgsSecurityLevel()
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
if(api)
api.SecurityLevel()
return api.SecurityLevel()
2 changes: 1 addition & 1 deletion src/DMAPI/tgs/v5/__interop_version.dm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"5.6.1"
"5.6.2"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;

using Newtonsoft.Json;

using Tgstation.Server.Api.Models;
using Tgstation.Server.Host.Components.Chat;
using Tgstation.Server.Host.Components.Deployment;
Expand Down Expand Up @@ -42,12 +44,14 @@ public sealed class RuntimeInformation : ChatUpdate
/// <summary>
/// The <see cref="DreamDaemonSecurity"/> level of the launch.
/// </summary>
public DreamDaemonSecurity? SecurityLevel { get; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
public DreamDaemonSecurity SecurityLevel { get; }

/// <summary>
/// The <see cref="DreamDaemonSecurity"/> level of the launch.
/// </summary>
public DreamDaemonVisibility? Visibility { get; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
public DreamDaemonVisibility Visibility { get; }

/// <summary>
/// The <see cref="TestMergeInformation"/>s in the launch.
Expand All @@ -70,8 +74,8 @@ public RuntimeInformation(
IDmbProvider dmbProvider,
Version serverVersion,
string instanceName,
DreamDaemonSecurity? securityLevel,
DreamDaemonVisibility? visibility,
DreamDaemonSecurity securityLevel,
DreamDaemonVisibility visibility,
ushort serverPort,
bool apiValidateOnly)
: base(chatTrackingContext?.Channels ?? throw new ArgumentNullException(nameof(chatTrackingContext)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ internal ReattachInformation(
Dmb = dmb ?? throw new ArgumentNullException(nameof(dmb));
ProcessId = process?.Id ?? throw new ArgumentNullException(nameof(process));
RuntimeInformation = runtimeInformation ?? throw new ArgumentNullException(nameof(runtimeInformation));
if (!runtimeInformation.SecurityLevel.HasValue)
throw new ArgumentException("runtimeInformation must have a valid SecurityLevel!", nameof(runtimeInformation));

AccessIdentifier = accessIdentifier ?? throw new ArgumentNullException(nameof(accessIdentifier));

LaunchSecurityLevel = runtimeInformation.SecurityLevel.Value;
LaunchVisibility = runtimeInformation.Visibility.Value;
LaunchSecurityLevel = runtimeInformation.SecurityLevel;
LaunchVisibility = runtimeInformation.Visibility;
Port = port;

runtimeInformationLock = new object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ public async Task<ISessionController> LaunchNew(
var runtimeInformation = CreateRuntimeInformation(
dmbProvider,
chatTrackingContext,
launchParameters,
launchParameters.SecurityLevel.Value,
launchParameters.Visibility.Value,
apiValidate);

var reattachInformation = new ReattachInformation(
Expand Down Expand Up @@ -430,7 +431,8 @@ public async Task<ISessionController> Reattach(
var runtimeInformation = CreateRuntimeInformation(
reattachInformation.Dmb,
chatTrackingContext,
null,
reattachInformation.LaunchSecurityLevel,
reattachInformation.LaunchVisibility,
false);
reattachInformation.SetRuntimeInformation(runtimeInformation);

Expand Down Expand Up @@ -626,21 +628,23 @@ async Task LogDDOutput(IProcess process, string outputFilePath, bool cliSupporte
/// </summary>
/// <param name="dmbProvider">The <see cref="IDmbProvider"/>.</param>
/// <param name="chatTrackingContext">The <see cref="IChatTrackingContext"/>.</param>
/// <param name="launchParameters">The <see cref="DreamDaemonLaunchParameters"/> if any.</param>
/// <param name="securityLevel">The <see cref="DreamDaemonSecurity"/> the server was launched with.</param>
/// <param name="visibility">The <see cref="DreamDaemonVisibility"/> the server was launched with.</param>
/// <param name="apiValidateOnly">The value of <see cref="RuntimeInformation.ApiValidateOnly"/>.</param>
/// <returns>A new <see cref="RuntimeInformation"/> class.</returns>
RuntimeInformation CreateRuntimeInformation(
IDmbProvider dmbProvider,
IChatTrackingContext chatTrackingContext,
DreamDaemonLaunchParameters launchParameters,
DreamDaemonSecurity securityLevel,
DreamDaemonVisibility visibility,
bool apiValidateOnly)
=> new (
chatTrackingContext,
dmbProvider,
assemblyInformationProvider.Version,
instance.Name,
launchParameters?.SecurityLevel,
launchParameters?.Visibility,
securityLevel,
visibility,
serverPortProvider.HttpApiPort,
apiValidateOnly);

Expand Down
7 changes: 2 additions & 5 deletions src/Tgstation.Server.Host/Models/ReattachInformationBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Globalization;

using Tgstation.Server.Api.Models;
Expand Down Expand Up @@ -31,14 +30,12 @@ public abstract class ReattachInformationBase : DMApiParameters
/// <summary>
/// The <see cref="DreamDaemonSecurity"/> level DreamDaemon was launched with.
/// </summary>
[Required]
public DreamDaemonSecurity? LaunchSecurityLevel { get; set; }
public DreamDaemonSecurity LaunchSecurityLevel { get; set; }

/// <summary>
/// The <see cref="DreamDaemonVisibility"/> DreamDaemon was launched with.
/// </summary>
[Required]
public DreamDaemonVisibility? LaunchVisibility { get; set; }
public DreamDaemonVisibility LaunchVisibility { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ReattachInformationBase"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ GitHubClient GetOrCreateClient(string accessToken)
rateLimitInfo.Reset.ToString("o"));
else
logger.LogDebug(
"Requested GitHub client has {remainingRequests} requests remaining after the usage {lastUse}. Limit resets at {resetTime}",
"Requested GitHub client has {remainingRequests} requests remaining after the usage at {lastUse}. Limit resets at {resetTime}",
rateLimitInfo.Remaining,
lastUsed,
rateLimitInfo.Reset.ToString("o"));
Expand Down
6 changes: 6 additions & 0 deletions tests/DMAPI/LongRunning/Test.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
dab()
TgsNew(new /datum/tgs_event_handler/impl, TGS_SECURITY_SAFE)

var/sec = TgsSecurityLevel()
if(isnull(sec))
FailTest("TGS Security level was null!")

log << "Running in security level: [sec]"

if(params["expect_chat_channels"])
var/list/channels = TgsChatChannelInfo()
if(!length(channels))
Expand Down
17 changes: 17 additions & 0 deletions tests/DMAPI/LongRunning/long_running_test_rooted.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Hand crafted DME, will not work if saved with DreamMaker

// BEGIN_INTERNALS
// END_INTERNALS

// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR

// BEGIN_PREFERENCES
// END_PREFERENCES

// BEGIN_INCLUDE
#include "tests/DMAPI/LongRunning/Config.dm"
#include "tests/DMAPI/test_prelude.dm"
#include "tests/DMAPI/LongRunning/Test.dm"
// END_INCLUDE
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ await configurationClient.Write(new ConfigurationFileRequest
await configurationClient.CreateDirectory(staticDir, cancellationToken);
}

public Task SetupDMApiTests(CancellationToken cancellationToken)
public Task SetupDMApiTests(bool includingRoot, CancellationToken cancellationToken)
{
// just use an I/O manager here
var ioManager = new DefaultIOManager();
Expand All @@ -104,6 +104,12 @@ public Task SetupDMApiTests(CancellationToken cancellationToken)
ioManager.ConcatPath(instance.Path, "Repository", "tests", "DMAPI"),
null,
cancellationToken),
includingRoot
? ioManager.CopyFile(
"../../../../DMAPI/LongRunning/long_running_test_rooted.dme",
ioManager.ConcatPath(instance.Path, "Repository", "long_running_test_rooted.dme"),
cancellationToken)
: Task.CompletedTask,
ioManager.CopyDirectory(
Enumerable.Empty<string>(),
null,
Expand Down Expand Up @@ -175,8 +181,8 @@ async Task SequencedApiTests(CancellationToken cancellationToken)
}

public Task RunPreWatchdog(CancellationToken cancellationToken) => Task.WhenAll(
SetupDMApiTests(false, cancellationToken),
SequencedApiTests(cancellationToken),
SetupDMApiTests(cancellationToken),
TestPregeneratedFilesExist(cancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public async Task RunTests(

await chatTask;
await dmTask;
await configTest.SetupDMApiTests(true, cancellationToken);
await byondTask;

await new WatchdogTest(
Expand Down Expand Up @@ -172,7 +173,7 @@ await Task.WhenAll(
dmUpdateRequest,
cloneRequest);

var configSetupTask = new ConfigurationTest(instanceClient.Configuration, instanceClient.Metadata).SetupDMApiTests(cancellationToken);
var configSetupTask = new ConfigurationTest(instanceClient.Configuration, instanceClient.Metadata).SetupDMApiTests(true, cancellationToken);

if (TestingUtils.RunningInGitHubActions
|| String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("TGS_TEST_GITHUB_TOKEN"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ async Task<DreamDaemonResponse> DeployTestDme(string dmeName, DreamDaemonSecurit
var refreshed = await instanceClient.DreamMaker.Update(new DreamMakerRequest
{
ApiValidationSecurityLevel = deploymentSecurity,
ProjectName = $"tests/DMAPI/{dmeName}",
ProjectName = dmeName.Contains("rooted") ? dmeName : $"tests/DMAPI/{dmeName}",
RequireDMApiValidation = requireApi,
Timeout = TimeSpan.FromMilliseconds(1),
}, cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion tests/Tgstation.Server.Tests/Live/TestLiveServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ await FailFast(
await WatchdogTest.TellWorldToReboot2(instanceClient, WatchdogTest.StaticTopicClient, mainDDPort, cancellationToken);

dd = await instanceClient.DreamDaemon.Read(cancellationToken);
Assert.AreEqual(WatchdogStatus.Online, dd.Status.Value);
Assert.AreEqual(WatchdogStatus.Online, dd.Status.Value); // if this assert fails, you likely have to crack open the debugger and read test_fail_reason.txt manually
Assert.IsNull(dd.StagedCompileJob);
Assert.AreEqual(initialStaged, dd.ActiveCompileJob.Id);

Expand Down
1 change: 1 addition & 0 deletions tgstation-server.sln
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LongRunning", "LongRunning"
tests\DMAPI\LongRunning\Config.dm = tests\DMAPI\LongRunning\Config.dm
tests\DMAPI\LongRunning\long_running_test.dme = tests\DMAPI\LongRunning\long_running_test.dme
tests\DMAPI\LongRunning\long_running_test_copy.dme = tests\DMAPI\LongRunning\long_running_test_copy.dme
tests\DMAPI\LongRunning\long_running_test_rooted.dme = tests\DMAPI\LongRunning\long_running_test_rooted.dme
tests\DMAPI\LongRunning\Test.dm = tests\DMAPI\LongRunning\Test.dm
EndProjectSection
EndProject
Expand Down