fix(central-ui): Test Run banner says Notify is simulated; sandbox Send logs it (#151)
The Test Run banner in TemplateScriptDialog and SharedScriptForm claimed
External, Database and Notify all fire for real ("real emails"). Notify
is SandboxNotifyTarget, which returns a random GUID and sends nothing.
The banner now says External/Database are real and Notify is simulated,
pointing at Flow Debugger on a deployed instance for a real send. The
sandbox Send also writes a [sandbox] ... not delivered line to the
console pane. Notify.Status is unchanged (reports Unknown). Tests pin
the banner wording and the console line; Component-CentralUI.md notes
the simulated Notify.
This commit is contained in:
@@ -372,6 +372,6 @@ The explicit server-configured development auto-login mode preserves its synthet
|
|||||||
|
|
||||||
Test Run executes in a disposable `CentralUI.SandboxWorker` process. A process-wide admission gate permits at most four workers. Queueing, compilation, execution and gateway calls consume the requested deadline (1–10 seconds); cancellation kills the process tree and capacity is released only after confirmed exit. Console capture retains at most 32,000 characters with an explicit truncation marker; return JSON is limited to 32,000 bytes. Private IPC frames are limited to 1 MiB and stderr is drained without accumulation. Each worker has a 512 MiB managed-heap ceiling. The worker is a resource/lifetime boundary; the semantic script trust policy still gates compilation.
|
Test Run executes in a disposable `CentralUI.SandboxWorker` process. A process-wide admission gate permits at most four workers. Queueing, compilation, execution and gateway calls consume the requested deadline (1–10 seconds); cancellation kills the process tree and capacity is released only after confirmed exit. Console capture retains at most 32,000 characters with an explicit truncation marker; return JSON is limited to 32,000 bytes. Private IPC frames are limited to 1 MiB and stderr is drained without accumulation. Each worker has a 512 MiB managed-heap ceiling. The worker is a resource/lifetime boundary; the semantic script trust policy still gates compilation.
|
||||||
|
|
||||||
External calls, shared-script lookup and bound-instance operations use a parent broker. Configured SQL connections are recreated inside the worker using credentials passed only over its private pipe, preserving the existing SQL permissions and API. Termination prevents further calls and closes worker-owned sockets; it cannot undo SQL or remote work already accepted by another server. Timeout results do not retain a terminated worker's partial console buffer.
|
External calls, shared-script lookup and bound-instance operations use a parent broker. `Notify` is simulated, not brokered: `Notify.To(list).Send` returns a fake `NotificationId`, queues and sends nothing, and writes a `[sandbox] … not delivered` line to the console pane; `Notify.Status` reports `Unknown`. A real send needs a deployed instance (Deployment → Flow Debugger) (#151). Configured SQL connections are recreated inside the worker using credentials passed only over its private pipe, preserving the existing SQL permissions and API. Termination prevents further calls and closes worker-owned sockets; it cannot undo SQL or remote work already accepted by another server. Timeout results do not retain a terminated worker's partial console buffer.
|
||||||
|
|
||||||
The deadline terminates the child independently of gateway cancellation. If a broker provider ignores cancellation, the response waits for that operation to finish and its admission slot remains charged; this preserves the owning request scope and prevents unbounded abandoned operations.
|
The deadline terminates the child independently of gateway cancellation. If a broker provider ignores cancellation, the response waits for that operation to finish and its admission slot remains charged; this preserves the owning request scope and prevents unbounded abandoned operations.
|
||||||
|
|||||||
@@ -110,7 +110,8 @@
|
|||||||
where it rendered as a third card band. *@
|
where it rendered as a third card band. *@
|
||||||
<div class="alert alert-warning py-1 mb-3 small">
|
<div class="alert alert-warning py-1 mb-3 small">
|
||||||
<strong>Heads up:</strong>
|
<strong>Heads up:</strong>
|
||||||
<code>External</code>, <code>Database</code>, and <code>Notify</code> calls fire for real against central's configured systems — real HTTP, real SQL, real emails. Side effects are permanent.
|
<code>External</code> and <code>Database</code> calls fire for real against central's configured systems — real HTTP, real SQL. Side effects are permanent.
|
||||||
|
<code>Notify</code> is simulated: a fake <code>NotificationId</code> is returned and nothing is queued or sent — for a real send, run the script on a deployed instance from Deployment → Flow Debugger.
|
||||||
<code>CallShared</code> executes the named shared script (saved version) in the same sandbox.
|
<code>CallShared</code> executes the named shared script (saved version) in the same sandbox.
|
||||||
<code>Attributes</code> and <code>CallScript</code> still throw.
|
<code>Attributes</code> and <code>CallScript</code> still throw.
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+2
-1
@@ -164,7 +164,8 @@
|
|||||||
<strong>Heads up:</strong>
|
<strong>Heads up:</strong>
|
||||||
runs the script as typed (unsaved edits included) against the supplied
|
runs the script as typed (unsaved edits included) against the supplied
|
||||||
<code>Parameters</code>.
|
<code>Parameters</code>.
|
||||||
<code>External</code>, <code>Database</code>, and <code>Notify</code> calls fire for real against central's configured systems — real HTTP, real SQL, real emails. Side effects are permanent.
|
<code>External</code> and <code>Database</code> calls fire for real against central's configured systems — real HTTP, real SQL. Side effects are permanent.
|
||||||
|
<code>Notify</code> is simulated: a fake <code>NotificationId</code> is returned and nothing is queued or sent — for a real send, run the script on a deployed instance from Deployment → Flow Debugger.
|
||||||
<code>CallShared</code> executes the named shared script (saved version) in the same sandbox.
|
<code>CallShared</code> executes the named shared script (saved version) in the same sandbox.
|
||||||
<code>Instance</code>, <code>Attributes</code>, <code>Children</code>, <code>Parent</code>, and <code>CallScript</code> throw unless a bound instance is selected below — then they route to that live instance (attribute writes are permanent too).
|
<code>Instance</code>, <code>Attributes</code>, <code>Children</code>, <code>Parent</code>, and <code>CallScript</code> throw unless a bound instance is selected below — then they route to that live instance (attribute writes are permanent too).
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public class SandboxNotifyHelper
|
|||||||
/// <param name="listName">The notification list name.</param>
|
/// <param name="listName">The notification list name.</param>
|
||||||
/// <returns>A <see cref="SandboxNotifyTarget"/> for the specified list.</returns>
|
/// <returns>A <see cref="SandboxNotifyTarget"/> for the specified list.</returns>
|
||||||
public SandboxNotifyTarget To(string listName) =>
|
public SandboxNotifyTarget To(string listName) =>
|
||||||
new();
|
new(listName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Queries the delivery status of a previously-sent notification. The
|
/// Queries the delivery status of a previously-sent notification. The
|
||||||
@@ -149,20 +149,31 @@ public class SandboxNotifyHelper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SandboxNotifyTarget
|
public class SandboxNotifyTarget
|
||||||
{
|
{
|
||||||
|
private readonly string _listName;
|
||||||
|
|
||||||
/// <summary>Initializes a new instance of the SandboxNotifyTarget class.</summary>
|
/// <summary>Initializes a new instance of the SandboxNotifyTarget class.</summary>
|
||||||
internal SandboxNotifyTarget()
|
/// <param name="listName">The notification list name the script addressed.</param>
|
||||||
|
internal SandboxNotifyTarget(string listName)
|
||||||
{
|
{
|
||||||
|
_listName = listName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mirrors <c>NotifyTarget.Send</c> — returns a <c>NotificationId</c>. In
|
/// Mirrors <c>NotifyTarget.Send</c> — returns a <c>NotificationId</c>. In
|
||||||
/// the sandbox nothing is enqueued or delivered; a fake id is returned so
|
/// the sandbox nothing is enqueued or delivered; a fake id is returned so
|
||||||
/// the call type-checks identically to production.
|
/// the call type-checks identically to production, and a
|
||||||
|
/// <c>[sandbox]</c> line is written to the Test Run console pane so the
|
||||||
|
/// operator is not left waiting for a message that will never arrive
|
||||||
|
/// (Gitea #151).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="subject">The notification subject.</param>
|
/// <param name="subject">The notification subject.</param>
|
||||||
/// <param name="message">The notification message.</param>
|
/// <param name="message">The notification message.</param>
|
||||||
/// <param name="cancellationToken">Cancellation token.</param>
|
/// <param name="cancellationToken">Cancellation token.</param>
|
||||||
/// <returns>A task that resolves to a fake notification ID string (a random GUID).</returns>
|
/// <returns>A task that resolves to a fake notification ID string (a random GUID).</returns>
|
||||||
public Task<string> Send(string subject, string message, CancellationToken cancellationToken = default) =>
|
public Task<string> Send(string subject, string message, CancellationToken cancellationToken = default)
|
||||||
Task.FromResult(Guid.NewGuid().ToString("N"));
|
{
|
||||||
|
Console.Out.WriteLine(
|
||||||
|
$"[sandbox] Notify.To(\"{_listName}\").Send not delivered — Test Run does not send notifications");
|
||||||
|
return Task.FromResult(Guid.NewGuid().ToString("N"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Design;
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Design;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Regression tests for the Test Run side-effect warning. Test Run wires <c>External</c>,
|
/// Regression tests for the Test Run side-effect warning. Test Run wires <c>External</c>
|
||||||
/// <c>Database</c>, and <c>Notify</c> to central's real services, so a Test Run
|
/// and <c>Database</c> to central's real services, so a Test Run has
|
||||||
/// has production-equivalent side effects. The finding asked, at minimum, that
|
/// production-equivalent side effects; <c>Notify</c> is simulated (Gitea #151) and the
|
||||||
|
/// warning must say so rather than promise real emails. The finding asked, at minimum, that
|
||||||
/// this blast radius be surfaced to the user. The Test Run panels in
|
/// this blast radius be surfaced to the user. The Test Run panels in
|
||||||
/// <c>SharedScriptForm</c> and <c>TemplateEdit</c> carry a prominent
|
/// <c>SharedScriptForm</c> and <c>TemplateEdit</c> carry a prominent
|
||||||
/// <c>Real I/O</c> badge and an <c>alert-warning</c> block stating the side
|
/// <c>Real I/O</c> badge and an <c>alert-warning</c> block stating the side
|
||||||
@@ -47,6 +48,11 @@ public class TestRunWarningTests
|
|||||||
Assert.Contains("alert-warning", markup);
|
Assert.Contains("alert-warning", markup);
|
||||||
Assert.Contains("fire for real", markup);
|
Assert.Contains("fire for real", markup);
|
||||||
Assert.Contains("Side effects are permanent", markup);
|
Assert.Contains("Side effects are permanent", markup);
|
||||||
|
// Gitea #151: Notify is simulated in the sandbox — the banner must not claim
|
||||||
|
// real emails, and must point at Flow Debugger for a real send.
|
||||||
|
Assert.DoesNotContain("real emails", markup);
|
||||||
|
Assert.Contains("<code>Notify</code> is simulated", markup);
|
||||||
|
Assert.Contains("Flow Debugger", markup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Verifies that the API method form Test Run shows no real I/O badge because the inbound API has no side-effect surface.</summary>
|
/// <summary>Verifies that the API method form Test Run shows no real I/O badge because the inbound API has no side-effect surface.</summary>
|
||||||
|
|||||||
+23
@@ -674,6 +674,29 @@ public class ScriptAnalysisServiceTests
|
|||||||
Assert.Equal("\"Unknown\"", result.ReturnValueJson);
|
Assert.Equal("\"Unknown\"", result.ReturnValueJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gitea #151: the sandbox Notify.Send delivers nothing, so it must say so in the
|
||||||
|
/// Test Run console pane, and still return a fake NotificationId (a 32-hex GUID).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||||
|
[Fact]
|
||||||
|
public async Task RunInSandbox_NotifySend_WritesNotDeliveredLine_AndReturnsFakeId()
|
||||||
|
{
|
||||||
|
var result = await _svc.RunInSandboxAsync(
|
||||||
|
new SandboxRunRequest(
|
||||||
|
"return await Notify.To(\"ops\").Send(\"subj\", \"body\");",
|
||||||
|
Parameters: null,
|
||||||
|
TimeoutSeconds: null),
|
||||||
|
CancellationToken.None);
|
||||||
|
|
||||||
|
Assert.True(result.Success);
|
||||||
|
Assert.Contains(
|
||||||
|
"[sandbox] Notify.To(\"ops\").Send not delivered — Test Run does not send notifications",
|
||||||
|
result.ConsoleOutput);
|
||||||
|
var id = System.Text.Json.JsonSerializer.Deserialize<string>(result.ReturnValueJson!);
|
||||||
|
Assert.True(Guid.TryParseExact(id, "N", out _));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Verifies that the sandbox captures console output.</summary>
|
/// <summary>Verifies that the sandbox captures console output.</summary>
|
||||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user