Skip to content

Commit 8abfdea

Browse files
committed
fix(csharp): shared DecimalWire and MetaNetValidation helpers carry the auto-generated marker (#460)
1 parent 5d005d0 commit 8abfdea

6 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ here.**
2222

2323
### Fixed
2424

25+
- **C#: the two shared helpers now carry the `// <auto-generated/>` marker (#460).**
26+
`DecimalWire[.<Namespace>].g.cs` and `MetaNetValidation[.<Namespace>].g.cs` were the only
27+
emitted files without it, so a runner with no `GenStateDir` wrote them once and then logged
28+
`refusing to overwrite hand-written file` on every later run, leaving a stale copy (and the
29+
`@precision`/`@scale` input check inside it) behind. Regenerate once; the marker is the only
30+
change to the helpers' text.
2531
- The 1.1.0 entry's handler-code figure of 439 lines retired is corrected to about 460, as
2632
measured in one adopter's pull request.
2733

‎server/csharp/MetaObjects.Codegen.Tests/DecimalWireTests.cs‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,54 @@ public void Helpers_for_packages_bound_to_different_namespaces_get_distinct_file
539539
Assert.Contains("MetaNetValidation.Acme.Shipping.g.cs", paths);
540540
Compile(files);
541541
}
542+
543+
[Fact]
544+
public void Shared_helpers_carry_the_generated_marker_on_their_first_line()
545+
{
546+
var files = EmitFitness(out _);
547+
var helpers = files.Where(f =>
548+
f.Path.StartsWith("DecimalWire", StringComparison.Ordinal) ||
549+
f.Path.StartsWith("MetaNetValidation", StringComparison.Ordinal)).ToList();
550+
Assert.Contains(helpers, f => f.Path.StartsWith("DecimalWire", StringComparison.Ordinal));
551+
Assert.Contains(helpers, f => f.Path.StartsWith("MetaNetValidation", StringComparison.Ordinal));
552+
foreach (var f in helpers)
553+
Assert.Equal(CodegenRunner.GeneratedMarker, f.Content.Split('\n')[0].Replace("// ", ""));
554+
}
555+
556+
[Fact]
557+
public void Rerun_without_a_state_dir_rewrites_the_helpers_in_every_namespace()
558+
{
559+
// #460: with no GenStateDir the runner falls back to the marker rule, and the helpers
560+
// lacked the marker, so every run after the first refused to overwrite them.
561+
var dir = Path.Combine(Path.GetTempPath(), "mo-helper-marker-" + Guid.NewGuid().ToString("N"));
562+
try
563+
{
564+
var r = new MetaDataLoader().Load([
565+
new InMemoryStringSource(TwoNamespaceModel, id: "billing.json"),
566+
new InMemoryStringSource(SecondNamespaceModel, id: "shipping.json")]);
567+
Assert.Empty(r.Errors);
568+
var config = new GenConfig
569+
{
570+
OutDir = dir,
571+
Namespace = "Acme",
572+
PackageNamespaces = new() { ["acme::billing"] = "Acme.Billing", ["acme::shipping"] = "Acme.Shipping" },
573+
};
574+
string[] helpers =
575+
[
576+
"DecimalWire.Acme.Billing.g.cs", "DecimalWire.Acme.Shipping.g.cs",
577+
"MetaNetValidation.Acme.Billing.g.cs", "MetaNetValidation.Acme.Shipping.g.cs",
578+
];
579+
CodegenRunner.Run(config, r.Root, [new EntityGenerator()]);
580+
foreach (var h in helpers) File.WriteAllText(Path.Combine(dir, h), File.ReadAllText(Path.Combine(dir, h)) + "// stale\n");
581+
582+
var second = CodegenRunner.Run(config, r.Root, [new EntityGenerator()]);
583+
Assert.DoesNotContain(second.Warnings, w => w.Contains("refusing to overwrite", StringComparison.Ordinal));
584+
foreach (var h in helpers)
585+
{
586+
Assert.Contains(second.Files, f => f.Path == h && f.Status == "written");
587+
Assert.DoesNotContain("// stale", File.ReadAllText(Path.Combine(dir, h)), StringComparison.Ordinal);
588+
}
589+
}
590+
finally { try { Directory.Delete(dir, true); } catch { } }
591+
}
542592
}

‎server/csharp/MetaObjects.Codegen/Generators/EntityGenerator.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ private static void AppendNetConverterAttribute(StringBuilder sb, MetaField fiel
10491049
// the namespace swap. It lives HERE (not read from the HelperRuntime resource) so an
10501050
// ejected EntityGenerator stays self-contained, the way the MetaNetValidation text is.
10511051
private const string DecimalWireSourceTemplate = """
1052+
// <auto-generated/>
10521053
// DecimalWire — the wire form of a field.decimal (ADR-0019 Amendments 1 and 2, W1-W4).
10531054
//
10541055
// Output follows the project's `wire.decimals` setting (Amendment 2). Under `native`, the
@@ -1417,6 +1418,7 @@ private static void AppendDecimalConverterAttribute(StringBuilder sb, MetaField
14171418
private static EmittedFile EmitNetValidationFile(string ns, string fileName)
14181419
{
14191420
var sb = new StringBuilder();
1421+
sb.AppendLine("// <auto-generated/>");
14201422
sb.AppendLine("// Generated by MetaObjects entity-generator. Do not edit by hand.");
14211423
sb.AppendLine("#nullable enable");
14221424
sb.AppendLine("using System;");

‎server/csharp/MetaObjects.Codegen/Runtime/DecimalWire.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// <auto-generated/>
12
// DecimalWire — the wire form of a field.decimal (ADR-0019 Amendments 1 and 2, W1-W4).
23
//
34
// Output follows the project's `wire.decimals` setting (Amendment 2). Under `native`, the

‎server/csharp/MetaObjects.IntegrationTests/Generated/DecimalWire.g.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// <auto-generated/>
12
// DecimalWire — the wire form of a field.decimal (ADR-0019 Amendments 1 and 2, W1-W4).
23
//
34
// Output follows the project's `wire.decimals` setting (Amendment 2). Under `native`, the

‎server/csharp/MetaObjects.IntegrationTests/Generated/MetaNetValidation.g.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// <auto-generated/>
12
// Generated by MetaObjects entity-generator. Do not edit by hand.
23
#nullable enable
34
using System;

0 commit comments

Comments
 (0)